<?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->getDispenseRBydate($dat1,$dat2);
  if ($rQ->rowCount()>0) {
  $chp=$rQ->fetchAll();
  ?>  
  <table class="table table-bordered table-striped">
  <thead class="bg-secondary">
   <th>  
        <small><h6>PATIENT ID</h6></small>
      </th>
      <th>  
        <small><h6>PATIENT NAME</h6></small>
      </th>
      <th>  
        <small><h6>AGE</h6></small>
      </th>
      <th>  
        <small><h6>GENDER</h6></small>
      </th>
      <th>  
        <small><h6>MEDICINE</h6></small>
      </th>

      <th>  
        <small><h6>DOSAGE</h6></small>
      </th>
       <th>  
        <small><h6>QUANTITY</h6></small>
      </th>
      <th>  
        <small><h6>BILL AMOUNT</h6></small>
      </th>
      <th>
        <small><h6>B. STATUS</h6></small>
      </th>
      
       
        <th>
        <small><h6>DATE.</h6></small>
      </th>
      <th>
        <small><h6>RECOMMENDEE</h6></small>
      </th>
    </thead>
  <tbody>
   
  <?php
 $ttPrice=0;
 foreach ($chp as $key => $p) {

       $patientID=$p['patientID'];
    
  
 
       $ttPrice=$ttPrice+$p['dprice'];
       $cc++; 
      $pn= $con->getThisPatientD($patientID)->fetch();
        ?>


    <tr>
    <td>
        <?php echo $p['patientID'];?>
    </td>
    <td> 
      <?php echo $pn['fname']." ". $pn['mname']." ".$pn['lname'];?>
    </td> 
    <td> 
      <?php echo $pAge= date('Y',strtotime($sdate))-date('Y',strtotime($pn['dob']));
      ?> 
    </td> 
    <td> 
    <?php echo $pn['gender'];?> 
    </td> 
    <td> 
    <?php echo $p['drugname'];?> 
    </td>
    <td> 
    <?php echo $p['dosage'];?> 
    </td>
     <td> 
    <?php echo $p['qty'];?> 
    </td>
    <td> 
    <?php echo $p['dprice'];?> 
    </td>
    <td>
    <?php echo $p['payStatus'];?>
    </td> 
    <td>
    <?php echo $p['dateAt'];?> 
    </td>
    <td>
    <?php echo $p['drN'];?> 
    </td> 
  </tr>
<?php
}
  $cc=0;
?>
 <tr>
  <td colspan="7" align="right">Total:</td>
  <td>
     <input type="text" style="width:100%;" disabled="true" name="ttPrice<?php echo $cc;?>" id="ttPrice<?php echo $cc;?>"  value="<?php echo $ttPrice;?>" />
  </td>
  <td colspan="2"></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
}
?>
 