<?php
 
if( isset($_POST["pOpt"]) && isset($_POST["user"])  && isset($_POST["tprice"])  && isset($_POST["sdate"]))
{ 
 require_once"labClass.php";
 $con=new labClass();
 $sdate= $_POST['sdate'];
 $pOpt="CASH";
 $k= $con->getMuamalaCash($pOpt,$sdate);
 if($k->rowCount()>0)
      {
   $cs=$k->fetch() ;
   if($cs['statusB']=="Saved"){
       
    $pOpt= $_POST['pOpt'];
    
    $tPrice= $_POST['tprice']; 
    $user= $_POST['user'];   
   
    $rQc= $con->miamala($pOpt,$user,$tPrice,$sdate);
    if($pOpt=="CASH" || $pOpt=="M-PESA" )
    {
        $recID=1;
        $r= $con->getBalance($recID)->fetch();
        $bal=$r['cbalance']+$tPrice;
        $u= $con->updateBalance($recID,$bal);
    }
    
    //////////////////////////////
        $pOpt="CASH";
        $e= $con->getMuamalaCash($pOpt,$sdate);
          if($e->rowCount()>0)
           {
          $nn=$e->fetch();
          $tPrice= $nn['amount']-$tPrice;
          $r= $con->updateToDayCash($tPrice,$pOpt,$sdate);
              if($Qr->rowCount()>0)
               {
                ///$rQc= $con->miamala($pOpt,$user,$tPrice,$sdate);
                  ?>
                   <h6 class="text-success">Save!..</h6>
                  <?php
               }
               else{
                  ?>
                  <h6 class="text-danger">Transaction update failed!..</h6>
                 <?php
                   }
              }
           else{
              ?>
                  <h6 class="text-danger">Transaction not found!..</h6>
              <?php
               }
    //////////////
              ?>
           <h6 class="text-success">Save!..</h6>
         <?php
}
else{
   echo "Transaction closed up can't delete!";

}
}
else{
    echo "Transaction not found!";
}
        
   }
   else{
       echo "All field required!.";
   }
   //echo "2.finish";
?>