<?php
$cc=0;
if(isset($_POST["sdate"]))
{
  $sdate=$_POST["sdate"];
  require_once"labClass.php";
  $con=new labClass();
 
  ?>  
  <div class="container-fluid" id="co">
  <img src="assets/logo.png" width="100%" height="80px">
  <small><h6>PURCHASES REPORTS:</h6></small>
 

 <div class="container-fluid " id="dpl">
 <?php
  $rQ= $con->getPurchaseR($sdate);
  if ($rQ->rowCount()>0) {
  $chp=$rQ->fetchAll();
 ?>
  <table class="table table-bordered table-striped">
  <thead class="bg-secondary">
      <th>  
        <small><h6>S/N</h6></small>
      </th>
      <th>  
        <small><h6>ITEM NAME</h6></small>
      </th>
      <th>  
        <small><h6>QUANTITY</h6></small>
      </th>
      <th>  
        <small><h6>P. PRICE</h6></small>
      </th>
      <th>  
        <small><h6>S. PRICE</h6></small>
      </th>
      <th>  
        <small><h6>PROFIT</h6></small>
      </th>
      <th>
        <small><h6>DATE.</h6></small>
      </th>
      <th>
        <small><h6>TIME</h6></small>
      </th>
    </thead>
  <tbody>
   
  <?php
 $tpprice=0;
 $tsprice=0;
 $tprofit=0;
 foreach ($chp as $key => $p) {
       
       
        $cc++;
        ?>
        
         
       <input type="hidden" name="itemD<?php echo $cc;?>" id="itemD<?php echo $cc;?>" value="<?php echo $p['itemID'];?>"/>
      <input type="hidden" name="recID<?php echo $cc;?>" id="recID<?php echo $cc;?>" value="<?php echo $p['recID'];?>"/>
        <input type="hidden" name="inam<?php echo $cc;?>" id="inam<?php echo $cc;?>" value="<?php echo $p['iname'];?>"/>
        <input type="hidden" name="tim<?php echo $cc;?>" id="tim<?php echo $cc;?>" value="<?php echo $p['timeAt'];?>"/>
        <input type="hidden" name="pOpt<?php echo $cc;?>" id="pOpt<?php echo $cc;?>" value="<?php echo $p['pOpt'];?>"/>
         <input type="hidden" name="qtyt<?php echo $cc;?>" id="qty<?php echo $cc;?>" value="<?php echo $p['eQty'];?>"/>
       
    <tr>
    <td>
        <?php echo $cc;?>
    </td>
    <td>
        <sup id="rdn<?php echo $cc;?>" ></sup>
      <?php echo $p['iname'];?>
    </td> 
    <td> 
    <?php echo $p['eQty'];?> 
    </td>
    <td align="right"> 
      <?php 
      $tpprice=$tpprice+$p['ipprice']*$p['eQty'];
      echo  number_format($p['isprice'],2);
      ?> 
    </td> 
    <td align="right"> 
    <?php
     $tsprice=$tsprice+$p['isprice']*$p['eQty'];
     echo number_format($p['isprice']*$p['eQty'],2);?> 
    </td>
 
    <td>
        <input type="date" name="ds<?php echo $cc;?>" id="ds<?php echo $cc;?>" value="<?php echo $p['entryD'];?>"/> 
     
    </td>
    
     <td> 
    <?php echo $p['timeAt'];?> 
    </td>
    
     <td> 
        <input type="submit" name="add<?php echo $cc;?>" id="add<?php echo $cc;?>" value="Delete" id="submit" onclick=" var user=$('#user').val(); var iname=$('#inam<?php echo $cc;?>').val(); var tim=$('#tim<?php echo $cc;?>').val();  var ds=$('#ds<?php echo $cc;?>').val();  var qty =$('#qty<?php echo $cc;?>').val();var recID =$('#recID<?php echo $cc;?>').val(); var itemID =$('#itemD<?php echo $cc;?>').val(); if(itemID!=''&& recID!=''&& ds!='' && qty!=''&& iname!=''&& user!='' ) { $.post('pharmDelPurchasePro.php',{user:user,itemID:itemID,recID:recID,qty:qty,ds:ds,tim:tim,iname:iname},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Valide item detail required!..';}" />
  </td>
   
  </tr>
<?php
}
  $cc=0;
?>

 <tr>
  <td colspan="3" align="right">Total:</td>
    <td>
     <?php echo $tpprice;?>
  </td>
  <td>
      <?php echo $tsprice;?>
  </td>
  <td>
      <?php echo $tprofit;?>
  </td>
  <td></td>
 </tr>
</tbody>
</table>

<div>
   <button type="submit" class="btn btn-primary" value="Print" style="width:10%; height:30px;" onclick="printPageArea();">Print </button>
</div>
<?php
}
else{
?>
<small><h6 class="text-danger">No matching record!..</h6></small>
<?php
}
}
else{
?>
<small><h6 class="text-danger">Valide date required!..</h6></small>
<?php
}
?>
</div>
</div>

<script type="text/javascript">
  function printPageArea(){
    var printContent = document.getElementById('co').innerHTML;
    var originalContent = document.body.innerHTML;
    document.body.innerHTML = printContent;
    window.print();
    document.body.innerHTML = originalContent;
}

</script>