<?php
if(isset($_POST["cname"]) &&  isset($_POST["dat1"]) && isset($_POST["dat2"]))
{
   $cc=0;
  $tPrice=0;     
  $ttprice=0;
 $cname=$_POST["cname"];
 $dat1=$_POST['dat1'];   
 $dat2=$_POST['dat2'];
  require_once"labClass.php";
  $con=new labClass();
 $chkp= $con->getThisCusPorderRecBydate($cname,$dat1,$dat2); 
     
if ($chkp->rowCount()>0) {

  $chp=$chkp->fetchAll();
  ?>
<table class="table" border="1"> 
   <thead class="bg-secondary" >
       
      <th>  
        <small><h6>ORDER DATE</h6></small>
      </th>
      <th>  
        <small><h6>LPO 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>LPO AMOUNT</h6></small>
      </th>
       <th>  
        <small><h6>INVOICE DATE</h6></small>
      </th>
      <th>  
        <small><h6>INVOICE NO</h6></small>
      </th>
      <th>  
        <small><h6>INVOICE AMOUNT</h6></small>
      </th>
    </thead>
   <?php
    foreach ($chp as $key => $p) {
    $orderID=$p['orderID'];

    $cp= $con->getThispOrderItemList($orderID);
    $cc++; 
    $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'];?> 
     </td>

    <td colspan="4" >
    </td>
   <td rowspan="<?php echo $nr+2; ?>">
    <?php if ($p['invamount']>0) 
    {
       echo $p['invdate'];
    }else{
    ?>
    <input type="date" style="width:100%;" class="form-control" id="dt<?php echo $cc; ?>" name="dt<?php echo $cc; ?>"  value="<?php echo Date("Y-m-d");?>" >

    <sup id="rdn<?php echo $cc; ?>"></sup>
    <?php
    } 
    ?>
    </td>
    <td rowspan="<?php echo $nr+2; ?>">
   <?php if ($p['invamount']>0) 
    {
       echo $p['invno'];
    }else{
    ?>
    <input type="text" style="width:100%;" class="form-control" id="inv<?php echo $cc; ?>" name="inv<?php echo $cc; ?>"  value="" >
    <?php
    } 
    ?>

    </td>
    <td rowspan="<?php echo $nr+2; ?>"> 
      <?php if ($p['invamount']>0) 
    {
       echo $p['invamount'];
    }else{
    ?>
    
      <input type="number" onkeypress="$('#sb<?php echo $cc; ?>').show();" style="width:100%;" class="form-control" id="amount<?php echo $cc; ?>" name="amount<?php echo $cc; ?>"  value="" >
     <input type="Submit" onclick="var orderID =document.getElementById('orno<?php echo $cc;?>').innerHTML;var invno=$('#inv<?php echo $cc;?>').val(); var amount=$('#amount<?php echo $cc;?>').val();var dat=$('#dt<?php echo $cc;?>').val();    
         if(orderID!='' && invno!=''&& amount!='' && dat!='') {$.post('pharmupdatePInvProLPO.php',{orderID:orderID,invno:invno,amount:amount,dat:dat},function(data){$('#rdn<?php echo $cc; ?>').html(data).show();});document.getElementById('inv<?php echo $cc;?>').disabled=true;document.getElementById('dt<?php echo $cc;?>').disabled=true;document.getElementById('amount<?php echo $cc;?>').disabled=true;$('#sb<?php echo $cc; ?>').show();} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='All field required!..';}" style="width:50px; display:none;"  id="sb<?php echo $cc; ?>" name="sb<?php echo $cc; ?>"  value="Save" >
    <?php
    } 
    ?>
    </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="5" align="right">Total:</td><td><?php echo $ttprice;?></td><td> </td><td> </td><td> </td></tr>
</tbody>
</table> 

<?php

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