<?php
if($_POST["pOpt"] && $_POST["tim"] && $_POST["itemID"] && $_POST["iname"] && $_POST["user"] && $_POST["ipprice"] && $_POST["isprice"] && $_POST["sdate"])
{ 
//&& $_POST["tQty"]>0 && $_POST["nQty"]>0
    $tim= $_POST['tim'];
    $pOpt= $_POST['pOpt'];
    $isprice= $_POST['isprice'];
    $ipprice= $_POST['ipprice'];
    $user= $_POST['user'];
    $iname= $_POST['iname'];
    $nQty= $_POST['nQty'];
    $itemID= $_POST['itemID'];
    $tQty= $_POST['tQty'];
    $sdate= $_POST['sdate']; 
  //CHECKING ENDS HER
  require_once"labClass.php";
  $con=new labClass();
  $Q= $con->getThisItemBID($itemID,$iname);
  if($Q->rowCount()>0)
    {
   $rQ= $con->itemSellEntry($itemID,$tim,$iname,$ipprice,$isprice,$nQty,$sdate,$user,$pOpt);
   //print_r($rQ);
   if($rQ->rowCount()>0)
      {
       ///itemID:itemID,iqty:iqty,nQty:nQty,isprice:isprice,ipprice:ipprice,iname:iname,tQty:tQty
        $Qr= $con->updateItemQ($iname,$tQty,$itemID);
        
        ///////////////////
        if($Qr->rowCount()>0)
          {
          $tPrice=$_POST['isprice']*$nQty;
          $e= $con->getMuamalaCash($pOpt,$sdate);
          if($e->rowCount()>0)
           {
          $nn=$e->fetch();
          $tPrice= $tPrice+$nn['amount'];
          $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{
                 $rc= $con->miamala($pOpt,$user,$tPrice,$sdate);
                  if($Qr->rowCount()>0)
                   {
                    ?>
                      <h6 class="text-success">Save!..</h6>
                    <?php
                    }
                 else{
                    ?>
                    <h6 class="text-danger">Failed to register transaction!..</h6>
                   <?php
                    }
        }
        ///////////////////
        }
  else{
       ?>
        <h6 class="text-danger">Item error occurred!..</h6>
       <?php
       }
       }
    }
  else{
       ?>
        <h6 class="text-danger">Item does not exist!..</h6>
       <?php
       }
       }
  else{
       ?>
       <h6 class="text-danger">All field required!..</h6>
       <?php
       }
?>