 <?php
 //echo  $time=Date("H:i:sa").": By ";
 //echo "Full path: " . __FILE__;
//exit;
 // echo shell_exec("which php");
 ini_set('display_errors', 1);
error_reporting(E_ALL);
 
  
  $rc=0;
  $tPrice=0;     
  $ttprice=0;
  $ttInv=0; 
  $user=$_POST['user'];
  $cname=$_POST['cname'];
  require_once "labClass.php";
  
 $con = new labClass();
  ?>
 
 
 
<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
   
    $cp= $con->getThispOrderCbyIn($cname);
    
    if ($cp->rowCount()>0) {

    $ch=$cp->fetchAll();
     
      foreach ($ch as $key => $c) {
         $rc++;
       
    $orderID=$c['orderID'];
     $p=$con->getThisPOrder($orderID)->fetch();
   
        ?>
 <tbody>
 <tr>
    <td>
    <?php echo $p['orderdate'];?> 
    </td>
 
     <td>  
     <sup   id="orno<?php echo $rc; ?>"><?php echo $p['orderID'];?></sup>
     
     </td>

      <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_all('/\((\d+)\)/', $text, $matches)) {
                  $numbers = $matches[1]; // all numbers inside ()
                  $sum = array_sum($numbers); 
                  
                 $quantity = (int) $sum;
                 if ($c['eQty']>$quantity)
                 {
                     echo "rcv:".$quantity;
                 }
                }
                }
                ?>
            </td>
    
    <div id="ds"></div>
    
     
   
          
            
            
           

            <td>
              <sup id="rd<?php echo $rc; ?>"></sup>
               <?php if ($c['confrecv']!=NULL) 
                { 
                
                $text=$c['confrecv'];
                 if (preg_match_all('/\((\d+)\)/', $text, $matches)) {
                  $numbers = $matches[1]; // all numbers inside ()
                  $sum = array_sum($numbers); 
                  
                 $quantity = (int) $sum;
                 if ($c['eQty']>$quantity)
                 {
                 ?>
                 Add to:
                  
                  <select class="form-control" name="" id="sOpt<?php echo $rc; ?>">
                   <option value="">Select</option>
                  <option value="SHOP">SHOP</option>
                   <option value="STORE">STORE</option> 
                 </select>
                 <input type="hidden"  id="confrv<?php echo $rc; ?>" name="confrv<?php echo $rc; ?>"  value="<?php echo $text; ?>" >
                 
                 <input type="hidden"  id="pQty<?php echo $rc;?>" name="pQty<?php echo $rc;?>"  value="<?php echo $quantity; ?>" >
                 
                 <input type="number" onkeypress="$('#sbq<?php echo $rc;?>').show();" style="width:100%;" class="form-control" id="recvq<?php echo $rc;?>" name="recvq<?php echo $rc;?>"  value="" >
                   <input type="Submit" onclick="var inam =document.getElementById('in<?php echo $rc;?>').innerHTML;var orderID =document.getElementById('orno<?php echo $rc;?>').innerHTML;var recvq=$('#recvq<?php echo $rc;?>').val();var sOpt=$('#sOpt<?php echo $rc;?>').val();var pQty=$('#pQty<?php echo $rc;?>').val(); var user=$('#user').val();var confrv=$('#confrv<?php echo $rc;?>').val(); var sdate=$('#sdate').val(); var ord=$('#ord<?php echo $rc;?>').val();    
                     if(sOpt!=''&&  orderID!=''&&   inam!='' && recvq!=''&& sdate!='' && user!='') {
                      
                     
                         $.post('pharmupdatePInvProLPO.php',{confrv:confrv,pQty:pQty,sOpt:sOpt,orderID:orderID,recvq:recvq,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" >
                 
                 
                  <?php    
                 }
                 else 
                  {
                       echo $c['confrecv'];
                  } 
                } 
                
                }
                else
                 {
                  ?>
                  Add to:
                   
                  
                  <select class="form-control" name="sOpt<?php echo $rc; ?>" id="sOpt<?php echo $rc; ?>">
                   <option value="">Select</option>
                  <option value="SHOP">SHOP</option>
                   <option value="STORE">STORE</option> 
                 </select>
                 <input type="number" onkeypress="$('#sbq<?php echo $rc; ?>').show();" style="width:100%;" class="form-control" id="recvq<?php echo $rc;?>" name="recvq<?php echo $rc; ?>"   value="" >
                   <input type="Submit" onclick="var inam =document.getElementById('in<?php echo $rc;?>').innerHTML;var orderID =document.getElementById('orno<?php echo $rc;?>').innerHTML; var ord=$('#ord<?php echo $rc;?>').val();
                     var recvq=$('#recvq<?php echo $rc;?>').val();var sOpt=$('#sOpt<?php echo $rc;?>').val();var pQty=0; var user=$('#user').val();var confrv=''; var sdate=$('#sdate').val();
                     
                     if(sOpt!=''&& orderID!=''   && inam!='' && recvq!=''&& sdate!='' && user!='') {
                     
                       
                     $.post('pharmupdatePInvProLPO.php',{confrv:confrv,pQty:pQty,sOpt:sOpt,orderID:orderID,recvq:recvq,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='Incomplete submission!..';}" style="width:50px; display:none;"  id="sbq<?php echo $rc; ?>" name="sbq<?php echo $rc; ?>"  value="Save" >
                   <?php
                } 
               ?>
             </td>
             <td>
    <?php if ($p['recvby']!=NULL) 
    {
       echo $p['invdate'];
    }else{
    ?>
    <input type="date" style="width:100%;" class="form-control" id="dt<?php echo $rc; ?>" name="dt<?php echo $rc; ?>"  value="<?php echo Date("Y-m-d");?>" >

    <sup id="rdn<?php echo $rc; ?>"></sup>
    <?php
    } 
    ?>
    </td>
              <td>
            <?php echo $p['receivedF']." : ".$p['cname'];?>
            </td>
            
            <td> 
   
    <?php if ($p['recvby']!="") 
        {
       echo $p['recvby'];
         }else{
        ?>
    
         <input type="text" style="width:100%;" onkeypress="$('#sb<?php echo $rc; ?>').show();" class="form-control" id="confby<?php echo $rc; ?>" name="confby<?php echo $rc; ?>"  value="<?php echo $user; ?>" >
 


          <input type="Submit" onclick="var orderID =document.getElementById('orno<?php echo $rc;?>').innerHTML;var confby=$('#confby<?php echo $rc;?>').val();  var dat=$('#dt<?php echo $rc;?>').val();    
            if(orderID!='' && confby!=''   && dat!='') {
            
            $.post('pharmUpdateRecvPInvPro.php',{orderID:orderID,confby:confby,dat:dat},function(data){$('#rdn<?php echo $rc;?>').html(data).show();});document.getElementById('confby<?php echo $rc;?>').disabled=true;document.getElementById('dt<?php echo $rc;?>').disabled=true;$('#sb<?php echo $rc; ?>').show();
             
            
            } else{document.getElementById('rdn<?php echo $rc;?>').innerHTML='All field required!..';}" style="width:50px;"  id="sb<?php echo $rc; ?>" name="sb<?php echo $rc; ?>"  value="Save" >
    <?php
    } 
    ?>
    </td>
                   </tr>
                   <?php 
                       } 
                       
                    }       

$cc=0; 
?>
 
</tbody>
</table> 

 
  