<?php
  
 
if($_POST["regDate"] &&$_POST["drCat"] && $_POST["billOp"] && $_POST["patientID"] && $_POST["drN"] && $_POST["cashP"] && $_POST["nhifP"])

{
   $patientID= $_POST['patientID'];
   $billOp= $_POST['billOp'];
	 $drN= $_POST['drN'];
   $regDate= $_POST['regDate'];
   $user=$_POST['user'];
   $drCat=$_POST['drCat'];     
   

   if ($_POST['billOp']=="NHIF") {

      $amount=$_POST['nhifP'];
    } 
    else{
       $amount=$_POST['cashP'];
    }
  //CHECKING ENDS HER
  require_once"labClass.php";
  $con=new labClass();
  $Q= $con->getThisPatientD($patientID);
  if($Q->rowCount()>0)
    {
      $sd= $con->getServID($patientID,$regDate);
      if($sd->rowCount()>0)
      {
        $g=$sd->fetch();
        $sID=$g['sID'];
      }
      else{
        $sB= $con->getBillID();
        $sID=$sB->rowCount()+1;
      }
      $rrQ= $con->getServExist($patientID,$regDate,$drCat);
      //print_r($rrQ->ErrorInfo());
     // echo $rrQ->rowCount();
      if($rrQ->rowCount()>0)
                {
                $amount=0;//$_POST['cashP'];
                }
      
   //echo $day2=date('Y-m-d',strtotime($regDate.'-7 days'));
   
      $rQ= $con->billConsultantFee($sID,$regDate,$drCat,$user, $drN, $billOp,$amount,$patientID);
                if($rrQ->rowCount()>0)
                {
                ?>
                <h6 class="text-success">Sent!..</h6>
                <?php
                }
    }
  else{
       ?>
                <h6 class="text-danger">Invalid patient ID!..</h6>
       <?php
       }
  
  }
?>