<?php 
 $cname=$_POST['cname'];
 $cc=0;
 $tPrice=0;     
 $ttprice=0;
 $tptde=0;     
 $tbal=0;
  require_once "labClass.php";
  
 $con = new labClass();
  ?>
  <div class="container-fluid" id="co"> 
  <small><h6><?php echo $cname;?>'S SALES INVOICE:</h6></small>
  

 <div class="container-fluid " id="dpl">
  <?php
 $chkp= $con-> getThisCusOrderRecByFrN($cname); 
     
if ($chkp->rowCount()>0) {

  $chp=$chkp->fetchAll();
  ?>
<table class="table" border="1"> 
   <thead class="bg-secondary" >
       
     
      <th>  
        <small><h6>INV.NO/C'S NAME</h6></small>
      </th>
       
      <th>  
        <small><h6>PATICULAR</h6></small>
      </th>
      <th>  
        <small><h6>PRICE/UNIT</h6></small>
      </th>
      <th>  
        <small><h6>QTY</h6></small>
      </th>
      <th>  
        <small><h6>TOTAL AMOUNT</h6></small>
      </th>
       <th>  
        <small><h6>DATE</h6></small>
      </th>
      
    </thead>
   <?php
    foreach ($chp as $key => $p) {
    $orderID=$p['orderID'];

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


        ?>
 <tbody>
 <tr>
    
 
     <td rowspan="<?php echo $nr+2; ?>" >  
     <sup id="orderID<?php echo $cc; ?>"><?php echo $p['orderID'];?></sup>.<?php $parts = explode('(', $p['cname']); echo $parts[0];?>
     </td>

    <td colspan="4" >
    </td>
   <td rowspan="<?php echo $nr+2; ?>">
    <?php echo $p['orderdate'];?> 
    </td>
    </tr>    
     <?php 
   
    if ($cp->rowCount()>0) {

    $ch=$cp->fetchAll();
     
      foreach ($ch as $key => $c) {
      ?>
          <tr>
            <td>  
            <?php echo $c['iname'];?>
            </td> 
            <td>
            <?php echo $c['isprice'];?>
            </td> 
            <td> 
               <?php echo $c['eQty'];?>    
            </td>
            <td>
              <?php echo $c['tprice'];?>  
            </td> 
         </tr>
       <?php
       $tPrice=$tPrice+$c['tprice'];
        } 
        ?> 
         <tr>
            <td colspan="3" align="right">
              Sub-total:  
            </td>
            <td>
               <?php echo $tPrice;?>  
            </td>
        </tr>
     <?php 
      } 
     ?>
    

<?php
$ttprice=$ttprice+$tPrice;
$tPrice=0;      
}

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

<?php

}
else{
    echo "No matching record!..";
}
?>
 </div>
 