<?php 
  $cc=0;
  $rc=0;
  $tPrice=0;     
  $ttprice=0;
  $ttInv=0;
  $dat1=$_POST['dat1'];
  $dat2=$_POST['dat2'];
  $user=$_POST['user'];
  require_once "labClass.php";
  
 $con = new labClass();
 
  $status="NOT PAID";
 $chkp= $con->getCompDbtPorderRecBydate($dat1,$dat2); 
  print_r($chkp->ErrorInfo()); 
if ($chkp->rowCount()>0) {

  $chp=$chkp->fetchAll();
  ?>
<table class="table table-bordered" border="1"> 
   <thead class="bg-secondary" >
       
      <th>  
        <small><h6>ORDER DATE</h6></small>
      </th>
      <th>  
        <small><h6>ORDER NO/C.NAME</h6></small>
      </th>
       
      <th>  
        <small><h6>PATICULAR</h6></small>
      </th>
      
      <th>  
        <small><h6>QTY</h6></small>
      </th>
      <th>  
        <small><h6>CONFIRM RECV QTY</h6></small>
      </th>
       
       <th>  
        <small><h6>ORDER VALUE</h6></small>
      </th>
      <th>  
        <small><h6>PAID TO DATE</h6></small>
      </th>
      <th>  
        <small><h6>BALANCE</h6></small>
      </th>
      
    </thead>
   <?php
    foreach ($chp as $key => $p) {
    $orderID=$p['orderID'];

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


        ?>
 <tbody>
 <tr>
    <td rowspan="<?php echo $nr+2; ?>">
    <?php echo $p['orderdate'];?> 
    </td>
 
     <td rowspan="<?php echo $nr+2; ?>" >  
     <sup id="orno<?php echo $cc; ?>"><?php echo $p['orderID'];?></sup>.
     <?php echo $p['cname'];?>
     </td>

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

    $ch=$cp->fetchAll();
     
      foreach ($ch as $key => $c) {
         $rc++;
      ?>
          <tr>
            <td>
                 
            <sup id="in<?php echo $rc;?>"><?php echo $c['iname'];?></sup>
            </td> 
            
            <td> 
               <?php echo $c['eQty'];?><br/> 
                 <?php if ($c['confrecv']!=NULL) 
                { 
                
                $text=$c['confrecv'];
                if (preg_match('/Qty:\((\d+)\)/', $text, $matches)) 
                {
                 $quantity = (int) $matches[1];
                 if ($c['eQty']>$quantity)
                 {
                     echo "rcv:".$quantity;
                 }
                }
                }
                ?>
            </td>

            <td>
              </td>
              
                   </tr>
                   <?php 
                       } 
                       
                    }       
}
$cc=0; 
?>
 
</tbody>
</table> 

<?php

}
?>
 