<?php
   $cc=0;
 
if( isset($_POST["patientID"]) && isset($_POST["tDate"]))

{
  $patientID= $_POST['patientID'];
  $tDate= $_POST['tDate'];   
  require_once"labClass.php";

  $con=new labClass();

  $rQ= $con->getPatientCheckUpByDate($patientID,$tDate);

              // print_r($rQ->ErrorInfo());
  if ($rQ->rowCount()>0) {

    $chp=$rQ->fetchAll();
    $pn= $con->getThisPatientD($patientID);
    if ($pn->rowCount()>0) {
    $n=$pn->fetch();
      ?> 
  <small>PATIENT NAME:<h6 class="text-primary"><?php echo $n['fname']." ". $n['mname']." ".$n['lname'];?></h6></small>
  <div class="container-fluid">
  <small><h6>MEDICAL CHECKUP LIST:</h6></small> 
  <table class="table table-bordered table-striped">
  <thead class="bg-secondary">
   <th>  
        <small><h6>S/N-MEDICAL TEST</h6></small>
      </th>
      
       <th>
        <small><h6>P/STATUS</h6></small>
      </th>
       <th>
        <small><h6>TEST PRICE</h6></small>
      </th>
       <th>
        <small><h6>DISCOUNT</h6></small>
      </th>
       <th>
        <small><h6>REASON</h6></small>
      </th>
        <th>
        <small><h6>CONFIRM P.</h6></small>
      </th>
    </thead>
  <tbody>
   
  <?php
 $ttPrice=0;
  
 foreach ($chp as $key => $p) {

       $recordID=$p['recordID'];
    
       $cc++; 
      
       $ttPrice=$ttPrice+$p['billAmount'];
        ?>


 <tr>
      
     <td colspan="4">
       <sup id="rdn<?php echo $cc;?>" class="text-danger" ></sup>
     </td>
   </tr> 
  <tr>
  
 
  
   <td style="width:45%;">

       <input type="hidden" name="recordID<?php echo $cc;?>" id="recordID<?php echo $cc;?>" value="<?php echo $p['recordID'];?>"/>
     

      <?php
          echo $cc;
       ?>  
         .<textarea style="height:30px; width:95%;" disabled="true" name="tname<?php echo $cc;?>" id="tname<?php echo $cc;?>"><?php echo $p['mTest'];?></textarea><br/>
         
  
  </td>
  

     <td>
        <input type="text" style="width:100%;" disabled="true" name="pStatus<?php echo $cc;?>" id="pStatus<?php echo $cc;?>"  value="<?php echo $p['pStatus'];?>" />
  </td> 

  <td>
        <input type="text" style="width:100%;" disabled="true" name="tPrice<?php echo $cc;?>" id="tPrice<?php echo $cc;?>"  value="<?php echo $p['billAmount'];?>" />
  </td> 


   <td>
        <input type="number" style="width:100%;" name="dsPrice<?php echo $cc;?>" id="dsPrice<?php echo $cc;?>"  value="" />
  </td>
  <td style="width:20%;">
        <input type="text" style="width:100%;" name="dsReason<?php echo $cc;?>" id="dsReason<?php echo $cc;?>"  value="" />
  </td>



    
  <td >
    

        <input type="submit" name="postUpdate<?php echo $cc;?>" id="postUpdate<?php echo $cc;?>"value="PAY" id="submit" onclick="var dsReason=$('#dsReason<?php echo $cc;?>').val();var dsPrice=$('#dsPrice<?php echo $cc;?>').val();var dPrice=$('#tPrice<?php echo $cc;?>').val();  var tname=$('#tname<?php echo $cc;?>').val();var sdate=$('#sdate').val();var user=$('#user').val();var recordID=$('#recordID<?php echo $cc;?>').val(); var patientID =$('#pID').val();if(sdate!='' && patientID!='' && dsReason!='' && dsPrice!='' && recordID!=''&& dPrice!='' && tname!='') {var tPrice=0;tPrice=parseInt(dPrice)-parseInt(dsPrice); if(tPrice > 0){$.post('saveBillDisPro.php',{sdate:sdate,tPrice:tPrice,dsReason:dsReason,dsPrice:dsPrice,patientID:patientID,recordID:recordID,tname:tname,user:user},function(data){$('#rdn<?php echo $cc;?>').html(data).show();});} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='Invalid dicount amount!..';}} else{document.getElementById('rdn<?php echo $cc;?>').innerHTML='The problem occured, make sure you entered patient ID!..';}" />
  </td>
    
  </tr>

 
  <?php
 
}
  $cc=0;
?>
<tr>
  <td colspan="2" 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></td>
 </tr>
</tbody>
</table>
</div>
<?php
}
else{
  echo "Invalid patientID!..";
}
}
else{
  echo "No medical bill for the patient!.";
}
         
}
//echo "out";

?>