<?php
if($_POST["itemID"] && $_POST["iname"] && $_POST["user"] && $_POST["recID"] &&   $_POST["qty"]&& $_POST["tim"]  && $_POST["ds"])
{ 
   // user:user,itemID:itemID,recID:recID,pOpt:pOpt,ds:ds,tim:tim,iname:iname
     $qty= $_POST['qty']; 
     $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();
  $Q= $con->getThisPurchBID($tim,$recID,$itemID,$iname);
  if($Q->rowCount()>0)
    {
        if( $pOpt!="Unspecified"){
    
        $Qr= $con->delPurchD($ds,$tim,$iname,$itemID,$recID);
        if($Qr->rowCount()>0)
      {
          //======
          
       $Q= $con->getThisItemBID($itemID,$iname);
       if($Q->rowCount()){
           $it=$Q->fetch();
           if($qty>$it['iqty']){
               
           $tQty=0;
           }
           else{
               
           $tQty=$it['iqty']-$qty;
           }
           
           $r= $con->updateItemQ($iname,$tQty,$itemID);
          ////////////////
        /* if( $pOpt=="Unspecified"){
             
              $Qq= $con->getThisItmInvLstBID($tim,$itemID,$iname);
              if($Qq->rowCount()>0)
               {
                   //------------
                $gr=$Qq->fetch();
                $orderID=$gr['orderID'];
                $cr= $con->updateInvItmListD($ds,$us,$iname,$itemID,$orderID);
                if($cr->rowCount()>0)
                  {
                     $crc= $con->updateOrderD($ds,$orderID); */ 
                 ?>
                 <h6 class="text-success">Deleted!..</h6>
               <?php
                  /*}
                  
                 ///// 
               }
               else{
       ?>
        <h6 class="text-danger">Invoice not found!..</h6>
       <?php
       }
       
               
               //------
          }else{
           ?>
           <h6 class="text-success">Save!..</h6>
          <?php
             }*/
          /////////////////
       }
  else{
       ?>
        <h6 class="text-danger">Item not found!..</h6>
       <?php
       }
          //==========
          
          
          
          
        }
  else{
       ?>
        <h6 class="text-danger">Item error occurred!..</h6>
       <?php
       }
       //}-------unspecified---else
    }
   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
       }
?>