<?php
$cc=0;
if(isset($_POST["sdate"]) &&  isset($_POST["dat1"]) && isset($_POST["dat2"]))
{
 $sdate=$_POST["sdate"];
 $dat1=$_POST['dat1'];   
 $dat2=$_POST['dat2'];
  require_once"labClass.php";
  $con=new labClass();
 
  
  $rQ= $con->getStoreTransRBydate($dat1,$dat2);
  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++;
        ?>
    <tr>
    <td>
        <?php echo $cc;?>
    </td>
    <td> 
      <?php echo $p['iname'];?>
    </td> 
    <td> 
    <?php echo $p['eQty'];?> 
    </td>
    <td> 
      <?php 
     $tpprice=$tpprice+$p['ipprice']*$p['eQty'];
      echo $p['ipprice']*$p['eQty'];
      ?> 
    </td> 
    <td> 
    <?php
     $tsprice=$tsprice+$p['isprice']*$p['eQty'];
     echo $p['isprice']*$p['eQty'];?> 
    </td>
    <td>
      <?php
     $tprofit=$tprofit+($p['isprice']*$p['eQty'])-($p['ipprice']*$p['eQty']);
     echo ($p['isprice']*$p['eQty'])-($p['ipprice']*$p['eQty']);?> 
    </td>
    <td> 
    <?php echo $p['entryD'];?> 
    </td>
    
     <td> 
    <?php echo $p['timeAt'];?> 
    </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>