<?php
if($_POST["itemID"] && $_POST["iname"] && $_POST["user"] && $_POST["recID"] && $_POST["pOpt"]&& $_POST["qty"]&& $_POST["tim"]  && $_POST["ds"])
{ 
   // user:user,itemID:itemID,recID:recID,pOpt:pOpt,ds:ds,tim:tim,iname:iname
     $qty= $_POST['qty'];
     $pOpt= $_POST['pOpt'];
     $recID= $_POST['recID'];
     $user= $_POST['user'];
     $iname= $_POST['iname'];
     $ds= $_POST['ds'];
     $itemID= $_POST['itemID'];
     $tim= $_POST['tim']; 
     $us=$tim."(Edt:".$user.")";
  //CHECKING ENDS HER
  require_once"labClass.php";
  $con=new labClass();
  $rt= $con->getThisSellBID($tim,$recID,$itemID,$iname);
  if($rt->rowCount()>0)
    { $rt=$rt->fetch(); 
        $tPrice=$qty*$rt['isprice'];
         $sdate=$rt['entryD'];
        if( $pOpt!="Unspecified"){
    
        $Qr= $con->delSellD($ds,$pOpt,$tim,$iname,$itemID,$recID);
        if($Qr->rowCount()>0)
        {
         $Q= $con->getThisItemBID($itemID,$iname);
         if($Q->rowCount()){
           $it=$Q->fetch();
           $tQty=$qty+$it['iqty'];
           $r= $con->updateItemQ($iname,$tQty,$itemID);
            
         
                     
                      
              //////////////////////////////
                $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">Deleted!..</h6>
                          <?php
                       }
                       else{
                          ?>
                          <h6 class="text-danger">Transaction update failed!..</h6>
                         <?php
                           }
                      }
                       else{
                          
                            ?>
                            <h6 class="text-danger">Transaction not found!..</h6>
                           <?php
                            
                       }
               //////////////   
                     
                     
                     
               
               
       }
  else{
       ?>
        <h6 class="text-danger">Item not found!..</h6>
       <?php
       }
         
        }
  else{
       ?>
        <h6 class="text-danger">Item error occurred!..</h6>
       <?php
       }
       
    }
   else{
       ?>
        <h6 class="text-danger">Item in a debit list!..</h6>
       <?php
       }
       
       ////unspecified--els end
    }
   else{
       ?>
        <h6 class="text-danger">Item does not exist!..</h6>
       <?php
       }
       }
  else{
       ?>
       <h6 class="text-danger">All field required!..</h6>
       <?php
       }
?>