<?php
if(isset($_POST["pOpt"]) &&isset($_POST["bal"]) && isset($_POST["orno"]) && isset($_POST["user"]) && isset($_POST["cbal"]) &&    isset($_POST["sdate"]))
{ 
////
    $cash= $_POST['bal'];
    $orderID= $_POST['orno'];  
    $cbal= $_POST['cbal'];
    $pOpt= $_POST['pOpt'];
    $user= $_POST['user'];
    $sdate= $_POST['sdate'];
    if($cbal==$cash)
    {
      $pst="PAID";
    }
    else{
       $pst="NOT PAID"; 
    } 
  //CHECKING ENDS HER
    require_once"labClass.php";
    $con=new labClass();
    $Qc= $con->getThisPOrder($orderID);
      //print_r($Qc->ErrorInfo());
    if($Qc->rowCount()>0)
     {
      $p= $con->getThisPOrder($orderID)->fetch();
      $ptd=$p["paidtodate"]+$cash;
      $obal=$p["balance"];
      $cus=$p["cname"];
      $nbal=$obal-$cash;       
      if(($ptd>0) && ($nbal>=0)) 
       { 
       $rQc= $con->updatePOrder($orderID,$nbal,$ptd,$pst);
       //print_r($rQc);
       if($rQc->rowCount()>0)
        {
        $rc= $con->cPdebitPRec($orderID,$cus,$cash,$sdate,$user,$pOpt);
        //print_r($rc->ErrorInfo());
        if($rc->rowCount()>0)
        {
        ?>
          <h6 class="text-success">Save!..</h6>
         <?php
         }
        else{
          ?>
          <h6 class="text-danger">Technical error!..</h6>
          <?php
           }
        }
  else{
       ?>
       <h6 class="text-danger">Upadate failed!..</h6>
       <?php
       }
       }
  else{
       ?>
       <h6 class="text-danger">Invalid balance submit!..</h6>
       <?php
       }
      }
  else{
       ?>
       <h6 class="text-danger">Invalid order number!..</h6>
       <?php
       }
     }
  else{
       ?>
       <h6 class="text-danger">All field required!..</h6>
       <?php
       }
?>