<?php 
if(isset($_POST["orno"]))
{
 $cc=0;
  $tPrice=0;     
  $ttprice=0;
  $orderID=$_POST["orno"];
  require_once "labClass.php";
 $con = new labClass();
  ?>
 <div class="container-fluid " id="dpl">
  <?php
 $chkp= $con->getThisOrder($orderID); 
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) {
     
    $cc++;  
        ?>
 <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 
   
    $cp= $con->getThisInvItemList($orderID);
    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);$tPrice=0;?>  
            </td>
        </tr>
 
     <?php 
      } 
     ?>
</table>

<small>PAYMENT DETAIL:</small>
<table class="table">    
        <th>  
           <small><h6>Date paid</h6></small>
         </th>
         <th>  
           <small><h6>paid amount</h6></small>
          </th>
          <th>  
            <small><h6>Aproved by</h6></small>
           </th>
           <th>  
             <small><h6>Means of pay</h6></small>
          </th>


   <?php 
   $ch=$con->getDebitsPayLists($orderID);
    if ($ch->rowCount()>0) {

    $h=$ch->fetchAll();
     
    foreach ($h as $key => $r) {
      ?>
         <tr>
            <td>  
            <?php echo $r['datePaid'];?>
            </td> 
            <td align="right">
            <?php echo number_format($r['paidAmount'],2);?>
            </td> 
            <td align="right"> 
               <?php echo $r['timeP'];?>    
            </td>
            <td align="right">
              <?php echo $r['pOpt'];?>  
            </td>
              
         </tr>
         
 
       <?php
       $tPrice=$tPrice+$r['paidAmount'];
        } 
        ?>

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


     ?>
     <tr>
            <td colspan="5">
              No payment recorded!..  
            </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 payment!..";
}
?>
</div>
 