<?php 
  $cc=0;
  $rc=0;
  $tPrice=0;     
  $ttprice=0;
  $ttInv=0;
  $sdate=$_POST["sdate"];
  $dat1=$_POST['dat1'];   
  $dat2=$_POST['dat2'];
  require_once "labClass.php";
  
 $con = new labClass();
  
 $chkp= $con->getPorderRecBydate($dat1,$dat2); 
     
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</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>RECEIVED DATE</h6></small>
      </th>
      <th>  
        <small><h6>RECEIVE FROM</h6></small>
      </th>
      <th>  
        <small><h6>VERIFIED BY</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>
      <input type="Submit" onclick="var inam =document.getElementById('in<?php echo $rc;?>').innerHTML;var orderID =document.getElementById('orno<?php echo $cc;?>').innerHTML;  var sdate=$('#sdate').val();    
                     if(orderID!='' && sdate!='' && user!='') {$.post('editDelpurchAllorder.php',{orderID:orderID,user:user,sdate:sdate},function(data){$('#rd<?php echo $rc; ?>').html(data).show();});$('#sbq<?php echo $rc; ?>').hide();} else{document.getElementById('rd<?php echo $rc;?>').innerHTML='All field required!..';}" style="width:50px;"  id="sbq<?php echo $rc; ?>" name="sbq<?php echo $rc; ?>"  value="Delete" >
     </td>

    <td colspan="3" >
    </td>
   <td rowspan="<?php echo $nr+2; ?>">
    <?php if ($p['recvby']!=NULL) 
    {
       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 echo $p['receivedF'];?>
    </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>
              <sup id="rd<?php echo $rc; ?>"></sup>
               <textarea style="background-color:white; height:30px; width:95%;"   name="confrv<?php echo $rc; ?>" id="confrv<?php echo $rc; ?>" onkeypress="$('#sbq<?php echo $rc; ?>').show();"><?php echo $c['confrecv'];?></textarea>
               
                   <input type="Submit" onclick="var inam =document.getElementById('in<?php echo $rc;?>').innerHTML;var orderID =document.getElementById('orno<?php echo $cc;?>').innerHTML;  var user=$('#user').val();var confrv=$('#confrv<?php echo $rc;?>').val(); var sdate=$('#sdate').val();    
                     if(orderID!=''&& inam!='' && sdate!='' && user!='') {$.post('editDelpurchorderPro.php',{confrv:confrv, orderID:orderID, inam:inam,user:user,sdate:sdate},function(data){$('#rd<?php echo $rc; ?>').html(data).show();});$('#sbq<?php echo $rc; ?>').hide();} else{document.getElementById('rd<?php echo $rc;?>').innerHTML='All field required!..';}" style="width:50px; display:none;"  id="sbq<?php echo $rc; ?>" name="sbq<?php echo $rc; ?>"  value="Save" >
                 
                 
                 
             </td>
           
               <td>
                     <?php if ($c['confrecv']!=NULL) 
                { ?>
              <sup id="d<?php echo $rc; ?>"></sup>
                
               
                   <input type="Submit" onclick="var inam =document.getElementById('in<?php echo $rc;?>').innerHTML;var orderID =document.getElementById('orno<?php echo $cc;?>').innerHTML;  var user=$('#user').val();var confrv=$('#confrv<?php echo $rc;?>').val(); var sdate=$('#sdate').val();    
                     if(orderID!=''&& inam!='' && sdate!='' && user!='') {$.post('eDelpurchorderPro.php',{confrv:confrv, orderID:orderID, inam:inam,user:user,sdate:sdate},function(data){$('#rd<?php echo $rc; ?>').html(data).show();});$('#bq<?php echo $rc; ?>').hide();} else{document.getElementById('d<?php echo $rc;?>').innerHTML='All field required!..';}" style="width:70px;"  id="bq<?php echo $rc; ?>" name="bq<?php echo $rc; ?>"  value="DELETE" >
                 
                   <?php } ?>
                 
             </td>
              
                   </tr>
                   <?php 
                       } 
                       
                    }       
}
$cc=0; 
?>
 
</tbody>
</table> 

<?php

}
?>
 </div>
 