<?php
 
 
//require_once("header.php");
 ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if( isset($_POST["qty"]) &&  isset($_POST["recID"]) && isset($_POST["iname"]) && isset($_POST["cname"])  && isset($_POST["depo"]) && isset($_POST["depon"])  && isset($_POST["sdate"])  &&   isset($_POST["user"]))

{ 
    $qty= $_POST['qty'];
     $iname= $_POST['iname'];
	 $cname= $_POST['cname']."(".$iname."):".$_POST["qty"];
	 $depo=$_POST['depo'];  
	 $depon=$_POST['depon']* $qty;
	 $bal=$depo-$depon;
     $user=$_POST['user'];
     $sdate=$_POST['sdate'];    
     $recID=$_POST['recID'];
     ///$rg=Date("Ymdhis").substr(10,2);
   ///$reg=md5(substr($rg,1,11));
     $regdate=Date("Y-m-d");
  //CHECKING ENDS HERE
     require_once "labClass.php";
     $con = new labClass();
     $con->updateAddDp($bal,$recID);
     $e= $con->withDraw($recID,$cname,$depon,$sdate,$user);
    // print_r($e->ErrorInfo());
     $Q= $con->getThisItem($iname);
  if($Q->rowCount()>0)
    {
   $in=$Q->fetch();
   $tQty=$in['iqty']-$_POST["qty"];
   
          $itemID=$in['itemID'];
          $tim=Date("h:i:sa"); 
          $ipprice=$in['ipprice'];
          $isprice= $depon/$qty;
          $nQty=$qty;
          $pOpt="DEPOSIT";
           $rQ= $con->itemSellEntry($itemID,$tim,$iname,$ipprice,$isprice,$nQty,$sdate,$user,$pOpt);
           if($rQ->rowCount()>0)
      {
       ///itemID:itemID,iqty:iqty,nQty:nQty,isprice:isprice,ipprice:ipprice,iname:iname,tQty:tQty
        $Qr= $con->updateItemExBmoney($iname,$tQty);
        if($Qr->rowCount()>0)
      {
                ?>
                <h6 class="text-success">Withdraw successfull !..</h6>
                <?php
              
               // require_once "excwithdrawrf.php";

               }
           }else{
               echo "Invalid amount!..";
           }
       }else{
               echo "Update failed!..";
      }
      
             
          //require_once "empRegForm.php";
                 
          }
          else{
            echo "All field required!..";
          }
   
 




?>