<?php
if( isset($_POST["dat1"]) && isset($_POST["dat2"]))
{
  $cc=0;
  $tPrice=0;     
  $ttprice=0;

 $status=$_POST["stock"];
 $sdate=$_POST["sdate"];
 $dat1=$_POST['dat1'];   
 $dat2=$_POST['dat2'];
  require_once"labClass.php";
  $con=new labClass();
  if ($status=="BOTH" || $status=="" ) 
  {
    
   $chkp= $con->getInVRecBydt($dat1,$dat2);
    
    //print_r($chkp->ErrorInfo()) ;
  }
 else  
  {
    
  $chkp= $con->getThisCusOrderRecBydate($status,$dat1,$dat2);

  } 
     
if ($chkp->rowCount()>0) {

  $chp=$chkp->fetchAll();
  ?>
<table class="table" border="1"> 
   <thead class="bg-secondary" >
       
      <th>  
        <small><h6>DATE</h6></small>
      </th>
      <th>  
        <small><h6>INV. NO/C'S NAME</h6></small>
      </th>
       
      <th>  
        <small><h6>TOTAL PAYABLE</h6></small>
      </th>
      <th>  
        <small><h6>PAID TO DATE</h6></small>
      </th>
      <th>  
        <small><h6>BALANCE TO DATE</h6></small>
      </th>
       <th>  
        <small><h6>PAY STATUS</h6></small>
      </th>
      
    </thead>
   <?php
    foreach ($chp as $key => $p) {
    $orderID=$p['orderID'];

    $cp= $con->getThisInvItemList($orderID);
    $cc++; 
    $nr=$cp->rowCount();


        ?>
 <tbody>
 <tr>
   
 <td>
    <?php echo $p['orderdate'];?> 
    </td>
     <td>  
     <?php echo $p['orderID']."."; $parts = explode('(', $p['cname']); echo $parts[0];?> 
     </td>
       <td align="right">
    <?php echo number_format($p['payableA'],2);?> 
    </td>
    <td align="right">
    <?php echo number_format($p['paidtodate'],2);?> 
    </td>
    <td align="right">
    <?php echo number_format($p['balance'],2);?> 
    </td>
      <td>
    <?php echo $p['pstatus'];?> 
    </td>
    </tr> 
     <tr>
    <td colspan="2">  
    </td>
     <td colspan="3">
       <table class="table">    
        <th>  
           <small><h6>Item name</h6></small>
         </th>
         <th>  
           <small><h6>Price</h6></small>
          </th>
          <th>  
            <small><h6>Qty</h6></small>
           </th>
           <th>  
             <small><h6>Total</h6></small>
          </th>


   <?php 
   
    if ($cp->rowCount()>0) {

    $ch=$cp->fetchAll();
     
    foreach ($ch as $key => $c) {
      ?>
         <tr>
             <td>  
            <?php echo $c['iname'];?>
            </td> 
            <td align="right">
            <?php echo number_format($c['isprice'],2);?>
            </td> 
            <td align="right"> 
               <?php echo $c['eQty'];?>    
            </td>
            <td align="right">
              <?php echo number_format($c['tprice'],2);?>  
            </td>
              
         </tr>
         
 
       <?php
       $tPrice=$tPrice+$c['isprice']*$c['eQty'];
        } 
        ?>

         <tr>
            <td colspan="3" align="right">
              Sub-total:  
            </td>
            <td align="right">
               <?php echo number_format($tPrice,2);?>  
            </td>
        </tr>
 
     <?php 
      } 
     ?>




</table>

</td>
<td>  
</td>
</tr>
<?php
$ttprice=$ttprice+$tPrice;
$tPrice=0;      
}
$cc=0; 
?>
<tr><td colspan="4" align="right">Total:</td><td><?php echo number_format($ttprice,2);?></td></tr>
</tbody>
</table> 
<?php

}
else{
  echo "No matching report!";
}
}
else{
  echo "Invzlid date!";
}
?>