<?php
 
if(isset($_POST["n"]) && isset($_POST["pOpt"]) && isset($_POST["orderID"]) && isset($_POST["itemID"]) && isset($_POST["iname"]) && isset($_POST["user"]) && isset($_POST["rate"]) && isset($_POST["tsprice"]) && isset($_POST["tprice"])&& isset($_POST["cash"]) && isset($_POST["cus"]) && isset($_POST["eQty"]) && isset($_POST["pst"]) && isset($_POST["sdate"]))
{ 
  echo  $sn= $_POST['n'];
    $tsprice= $_POST['tsprice'];
    $cash= $_POST['cash'];
    $pst= $_POST['pst'];
    if($cash==$tsprice)
    {
      $pst="PAID";
    }
    $ptd=$cash;
    $bal=$tsprice-$cash;
    $user= $_POST['user'];
    $pOpt= $_POST['pOpt'];
    $ipprice= $_POST['rate'];
    $tprice= $_POST['tprice'];
    $user= $_POST['user'];
    $cus= $_POST['cus'];
	  $iname= $_POST['iname'];
    $nQty= $_POST['eQty'];
    $itemID= $_POST['itemID'];
    $orderID= $_POST['orderID']; 
    $sdate= $_POST['sdate']; 
  
    require_once"labClass.php";
    $con=new labClass();

  $Q= $con->getThisItemBID($itemID,$iname);
  if($Q->rowCount()>0)
    {

   $n=$Q->fetch();
   //$tQty=$n["iqty"]-$nQty;
   $isprice=$n["isprice"];
   //$rQ= $con->itemSellEntry($itemID,$iname,$ipprice,$isprice,$nQty,$sdate,$user);
   //$Qr= $con->updateItemQ($iname,$tQty,$itemID);
   $rQ= $con->porderItem($orderID,$itemID,$iname,$tprice,$ipprice,$nQty,$sdate,$user,$pOpt);
  
   if($rQ->rowCount()>0)
      {
       //echo "PASS";
      

      $Qc= $con->getThisPOrder($orderID);
      //print_r($Qc->ErrorInfo());
       if($sn==1)
        {
          $rQc= $con->regPOrder($orderID,$cus,$bal,$ptd,$tsprice,$pst,$sdate);
             if(($ptd>0) && ($ptd<$tsprice)) 
             { 
              //$rc= $con->debitPRec($orderID,$cus,$ptd,$sdate,$user);
             }
       $rQ= $con->clearPOrderTemp();
       require_once "pharmPurchaseOrderLPO.php";
         }
        }
        }
   }
   //echo "2.finish";
?>