<?php
 
if(isset($_POST["sdate"]) &&isset($_POST["tPrice"]) && isset($_POST["user"]) && isset($_POST["tname"]) && isset($_POST["recordID"]) && isset($_POST["patientID"]))

{
    $regDate= $_POST['sdate'];
    $sdate= $_POST['sdate'];
    $tname= $_POST['tname'];
    $iname=$tname;
    $recordID=$_POST['recordID'];   
    $tPrice= $_POST['tPrice'];
    $billOp= "Cash"; 
    $amount=$tPrice; 
    $patientID= $_POST['patientID'];
    $user= $_POST['user'];                                                     //CHECKING ENDS HERE
 
    $pStatus ="Billed:By: ".$_POST["user"];
    require_once"labClass.php";

    $con=new labClass(); 
    $sd= $con->getServID($patientID,$regDate);
      if($sd->rowCount()>0)
      {
        $g=$sd->fetch();
        $sID=$g['sID'];
      }
      else{
        $sB= $con->getBillID();
        $sID=$sB->rowCount()+1;
      }
     $tn= $con-> getThisMT($tname)->fetch();
     $cat=$tn['cat'];
     $rQ= $con->updateMtestBillD($sID,$pStatus,$recordID,$patientID,$tname,$tPrice); 
    //print_r($rQ);
    $tn= $con-> getThisMT($tname)->fetch();
     $sCat=$tn['cat'];
       
    //print_r($rQ->ErrorInfo());
    if($rQ->rowCount()>0)
          {
              $bt= $con->billInvestigation($sCat,$sID,$sdate,$iname,$user, $billOp,$amount,$patientID);

                if($bt->rowCount()>0)
                {
                ?>
                <h6 class="text-success">Saved!..</h6>
                <?php
                }else
                {
                ?>
                <h6 class="text-danger">Saving failed!..</h6>
              <?php
               }
          }
    else{
       ?>
        <h6 class="text-danger">Invalid patient ID!..</h6>
       <?php
       }
   echo "out";
  
}
 

?>