<?php
if (isset($_POST['itemname']) && isset($_POST['owniD']) && isset($_POST['shopid']) && isset($_POST['dateBought']) && isset($_POST['quantity']) && isset($_POST['cquantity']) && isset($_POST['scost']) &&  isset($_POST['currency']) && isset($_POST['itemcost']) &&   isset($_POST['itemid'])) {
  
    require("../buda_myStock_class.php");
    $mcon = new  buda_myStock_class();
    $itemid=$_POST['itemid'];
    $ownID=$_POST['owniD'];
    $currency=$_POST['currency'];
    $shopid=$_POST['shopid'];
    $itemcost=$_POST['itemcost']; 
    $dateBought=$_POST['dateBought'];
    $scost=$_POST['scost'];
    $cquantity=$_POST['cquantity'];
    $quantity=$_POST['quantity'];
    
    $itemname=$_POST['itemname'];
 //if($mcon->vitemcost($itemcost,$currency) && $mcon->vscost($scost,$currency) && $mcon->vQuantity($quantity))
    //  {
        ?>
         <center>
         <div>
        
        <?php 
        $chk= $mcon->getThisShopItemPrice($itemid,$shopid,$ownID);
        if ($chk->rowCount()>0){
         $stockID = Date("Ymdhis");
         $r= $mcon->updateThisItemQuantity($cquantity,$itemid,$shopid,$ownID);
         if($r->rowCount()>0)
         { 
           $a=$mcon-> saleMyStock($stockID,$ownID,$itemid, $itemcost, $shopid, $currency,$scost,$dateBought,$quantity,$itemname);
          if($a->rowCount()>0){
          echo "Successful!..";
           $itemcost ="";
           $currency=""; 
           $scost="";
           $quantity="";
           $dateBought="";
           $itemname="";
          }
          else{
              
          echo "Submission error 1!..";
          $u=$a->ErrorInfo();
          print_r($u);
          }
         }else{
          echo "Submission error!..";
          $u=$r->ErrorInfo();
          print_r($u);//"Error occurred while saving data!..";
              }
          }else{
            echo "Item ready exist!..";
          }
        ?> 
       </div>
       </center> 

        <?php
    /*
      }
      else{

        //////////////
        ?>
         <center>
         <div>
         <sup> <?php
              echo  $mcon->eitemcost($itemcost,$currency)."<p/>";
              echo  $mcon->escost($scost,$currency)."<p/>"; 
              echo  $mcon->vQuantity($quantity)."<p/>";
    
             ?>
       </sup>
       </div>
       </center> 

        <?php
        /////////////

      }
      */
    }else
    {
      echo "Incomplete Submission!..";
    }
?>