
<div  class="mt-4 p-5 bg-white text-dark rounded">
<table style="width:100%; margin-top:10px;">
  <tr>
    <td style="width:70%; vertical-align:top;">
      <label for="tname" class="form-label">Search/Sort by: Name:</label><br>
      <input type="text" onkeyup="submision()" class="form-control" id="tname"
             style="width:100%; height:35px; border-radius:12px;"
             placeholder="Test name" name="tname" required>
    </td>
    <td style="width:30%; vertical-align:bottom; text-align:center;">
      <label for="button" class="form-label">&nbsp;</label><br>
      <button type="submit" class="btn btn-primary" value="Print"
              style="width:60%; height:40px;" onclick="printPageArea();">
        Print
      </button>
    </td>
  </tr>
</table>
 
<div id="dispR">
<div class="container text-center mt-3 mb-4 p-3 border rounded shadow-sm bg-white text-primary" style="color:blue;">
  <div>
    <h5 class="fw-bold">Ms: KWIZERA INVESTMENT COMPANY</h5>
  </div>
  <div>
    <p class="mb-1">P.O. BOX -</p>
  </div>
  <div>
    <p class="mb-1">STREET: KATORO</p>
  </div>
  <div>
    <p class="mb-1">GEITA - TANZANIA</p>
  </div>
  <div>
    <p class="mb-1">PHONE: <strong>0758 087 092</strong></p>
  </div>
  <div>
    <p class="mb-0">TIN: <strong>175-011-498</strong></p>
  </div>
   <div>
    <h6 class="fw-bold text-uppercase">Current Stock Report</h6>
  </div>
  
</div>

 
 

<?php 
 $cc=0;
 require_once "labClass.php";
 $con = new labClass();
 $chkp= $con->getDrugList();//getItemDistinct();     
 if ($chkp->rowCount()>0) {
  $chp=$chkp->fetchAll();
  
  ?>
  
<table class="table table-bordered"> 
<th style="color:blue;">
  <small><h6>S/N</h6></small>
</th>
<th width="70%" style="color:blue;">
  <small><h6>ITEM NAME</h6></small>
</th>
<th style="color:blue;">
  <small><h6>STOCK(QTY)</h6></small>
</th>
<th align="right" style="color:blue;">
  <small><h6>PURCHASES PRICE (RATE)</h6></small>
</th>
<th align="right" style="color:blue;">
  <small><h6>WHOLE SALES PRICE (RATE)</h6></small>
</th>
<th align="right" style="color:blue;">
  <small><h6>RETAIL SALES PRICE (RATE)</h6></small>
</th>
<th align="right" style="color:blue;">
  <small><h6>PURCHASE PRICE (TOTAL)</h6></small>
</th>
<th align="right" style="color:blue;">
  <small><h6>WHOLES SALES PRICE (TOTAL)</h6></small>
</th>
<th align="right" style="color:blue;">
  <small><h6>RETAIL SALES PRICE (TOTAL)</h6></small>
</th>
<th style="color:blue;">
  <small><h6>PROFIT</h6></small>
</th>

      <!--<th>
        <small><h6>EXPIRED DATE</h6></small>
       
      </th>-->
       
<?php
 $tqty=0;
 $tpp=0;
 $twp=0;
 $tsp=0;
 $tpprice=0;
 $tsprice=0;
 $twprice=0;
 $tprofit=0;
 foreach ($chp as $key => $p) {
    $itemID=$p['itemID'];
    
      $cc++; 
      
   /* $wsprice= $p['wsprice'];
    $isprice= $p['isprice'];
    $ipprice= $p['ipprice'];
    $icat= $p['icat'];
    $iname= $p['iname'];
    $iQty= $p['iqty'];
    $expd= Date("Y-m-d");  
   
   $rQ= $con->itemReg($iname,$icat,$ipprice,$wsprice,$isprice,$iQty,$expd);
     if ($rQ->rowCount()>0) 
     {
       echo "Yes" ; 
     }
     else{
         echo "No";
     }
     print_r($rQ->ErrorInfo());*/
     
        ?>
 
  <tr>
   <td width="5%" class="text-primary">
  <?php echo $cc; ?>  
   </td>
   <td width="60%">
               <?php echo $p['iname'];?>
  </td>
  <td align="right">
   <?php echo $p['iqty'];
   $tqty=$tqty+$p['iqty'];
  
   ?>
  </td> 
  <td align="right"> 
      <?php  
      echo number_format($p['ipprice'],2);
      $tpp=$tpp+$p['ipprice'];
 
      ?> 
  </td>
  <td align="right"> 
    <?php 
     echo number_format($p['wsprice'],2);
     $twp=$twp+$p['wsprice'];
  
 
     ?> 
  </td> 
  <td align="right"> 
    <?php 
     echo number_format($p['isprice'],2);
     $tsp=$tsp+$p['isprice'];
 
     ?> 
  </td>
  <td align="right"> 
      <?php 
     $tpprice=$tpprice+$p['ipprice']*$p['iqty'];
     echo number_format($p['ipprice']*$p['iqty'],2);
  
      ?> 
  </td>
  <td align="right"> 
    <?php
     $twprice=$twprice+$p['wsprice']*$p['iqty'];
     echo number_format($p['wsprice']*$p['iqty'],2);?> 
  </td> 
  <td align="right"> 
    <?php
     $tsprice=$tsprice+$p['isprice']*$p['iqty'];
     echo number_format($p['isprice']*$p['iqty'],2);?> 
  </td>
  <td align="right">
      <?php
     $tprofit=$tsprice + $tpprice;//$tprofit+($p['isprice']*$p['iqty'])-($p['ipprice']*$p['iqty']);
     echo number_format(($p['isprice']*$p['iqty'])-($p['ipprice']*$p['iqty']),2);?> 
  </td>
  <!--<td> 
    <?php //echo $p['expd'];?> 
  </td>-->
  
</tr> 
 
  <?php
}
$cc=0;
 ?>
 <tr>
  <td align="right" colspan="2">Total:</td>
    <td align="right">
     <?php echo number_format($tqty,0);?>
  </td>
    <td align="right">
     <?php echo number_format($tpp,0);?>
  </td>
    <td align="right">
     <?php echo number_format($twp,0);?>
  </td>
    <td align="right">
     <?php echo number_format($tsp,0);?>
  </td>
    <td align="right">
     <?php echo number_format($tpprice,0);?>
  </td>
    <td align="right">
     <?php echo number_format($twprice,0);?>
  </td>
  <td align="right">
      <?php echo number_format($tsprice,0);?>
  </td>
  <td align="right">
      <?php echo number_format($tsprice - $tpprice,0);?>
  </td>
 </tr></table 
 <?php
}
?>
 </div>
 </div>
 
 <script>
  function submision(){
    
    var searchValue=$('#tname').val();
   
    $('#dispR').empty();
    $.post('pharmCrrStockSearch.php',{searchValue:searchValue},function(data){
      $('#dispR').html(data);

    });
    } 
  function printPageArea(){
    var printContent = document.getElementById('dispR').innerHTML;
    var originalContent = document.body.innerHTML;
    document.body.innerHTML = printContent;
    window.print();
    document.body.innerHTML = originalContent;
}

  
 
</script>