<?php
 $cc=0;
 
 
  require_once"labClass.php";
  echo $patientID=$_POST['patientID'];
  echo $tDate=$_POST['tDate'];
  $con=new labClass();
 
 if(isset($_POST["patientID"]) && isset($_POST["tDate"])){
  $patientID=$_POST['patientID'];
  $tDate=$_POST['tDate'];
  $fn="";
  $mn="";
  $ln="";
  $gn="";
  $pAge="";
  $np=$con->getThisPatientD($patientID);
  if($np->rowCount()>0)
  {
  $pn=$np->fetch();

  $regdate=Date("Y-m-d");
  $pAge= date('Y',strtotime($regdate))-date('Y',strtotime($pn['dob']));
  $fn=$pn['fname'];
  $mn=$pn['mname'];
  $ln=$pn['lname'];
  $gn=$pn['gender'];
  }
    
 
      ?>  
  <div class="container-fluid" id="co">
    <img src="assets/phead.PNG" width="100%" height="80px">
  <small><h6>
    <?php echo $fn." ". $mn." ".$ln. "'s ";?>MEDICAL CHECKUP REPORTS:</h6></small>
 <br><?php echo "Gender:" .$gn?><br> 
 <?php 
  echo "Age:". $pAge;
   ?> <br><?php echo "ID:".$patientID;?><br> 
 <table class="table"><tr>
    <td style="width:15%;">Sort by date range:</td><td style="width:10%;" ><input type="date" style="width:200px;" class="form-control" id="dat1" name="dat1"  value="<?php echo Date("Y-m-d");?>" >
        </td>
        <td>
          and:</td><td style="width:10%;">
          <input type="date" style="width:200px;" class="form-control" id="dat2" name="dat2" value="<?php echo Date("Y-m-d");?>">
       

        </td>
        <td style="width:10%;">  
        <button type="submit" class="btn btn-primary" style="width:100%; height:40px;" onclick="var dat1 = $('#dat1').val(); var patientID = $('#pID').val(); var dat2 = $('#dat2').val(); $.post('patientCheckUpReportsByDate.php',{dat1:dat1,dat2:dat2,patientID:patientID},function(data){$('#dpl').html(data).show();});">Generate</button>
 
</td>
       
</tr>

</table>

<div class="container-fluid" id="dpl" >

  <table class="table table-bordered table-striped">
  <thead class="bg-secondary">
   
      <th>  
        <small><h6>MEDICAL TEST</h6></small>
      </th>

      <th>  
        <small><h6>TESTING STATUS</h6></small>
      </th>

      <th>  
        <small><h6>R. DESCRIPTION</h6></small>
      </th>
      <th>  
        <small><h6>BILL AMOUNT</h6></small>
      </th>
      <th>
        <small><h6>B. STATUS</h6></small>
      </th>
      
       
      <th>
        <small><h6>CHECK UP DATE.</h6></small>
      </th>
    </thead>
  <tbody>
   
  <?php
 $ttPrice=0;

 $rQ= $con->getPatientCheckUpReports($patientID,$tDate);
 
 if ($rQ->rowCount()>0) {

  $chp=$rQ->fetchAll();
    
      
 foreach ($chp as $key => $p) {
 
     
$ttPrice=$ttPrice+$p['billAmount'];
$cc++;  
        ?>


    <tr>  
       <td> 
         <?php echo $p['mTest'];?> 
       
      </td>
       <td> 

         <?php echo $p['checkingStatus'];?> 
       
      </td>
      <td> 

         <?php echo $p['rDescrip'];?> 
       
      </td>
       <td> 

         <?php echo $p['billAmount'];?> 
       
      </td>
      

     <td>
        <?php echo $p['pStatus'];?>
     </td> 
    
     
     
      <td>
        <?php echo $p['tDate'];?> 
      </td> 
  </tr>

 
  <?php
 
}
  $cc=0;
} 

?>
 <tr>
  <td colspan="3" align="right">Total:</td>
  <td>
     <input type="text" style="width:100%;" disabled="true" name="ttPrice" id="ttPrice<?php echo $cc;?>"  value="<?php echo $ttPrice;?>" />
  </td>
  <td colspan="2"></td>
 </tr>
</tbody>
</table>
</div>

    <!--<img src="assets/pfooter.PNG" width="100%" height="80px">-->
</div>
<div>
   <button type="submit" class="btn btn-primary" value="Print" style="width:10%; height:30px;" onclick="printPageArea();">Print </button>
</div>
<?php
}
else{
    echo "All filed required!..";
    }

?>
<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>