<?php
if (isset($_POST['owniD']) &&isset($_POST['shopid']) &&  isset($_POST['quantity']) && isset($_POST['itemid'])) {
    require("buda_myStock_class.php");
    $myAgrocon = new  buda_myStock_class();
    $itemid=$_POST['itemid'];
    $ownID=$_POST['owniD'];
    $customerid=$_POST['owniD'];
    $shopid=$_POST['shopid'];
    $quantity=$_POST['quantity']; 
    $batchID=$_POST['batchID'];
    $cost=$_POST['cost'];

 if($myAgrocon->vQuantity($quantity))
      {
        ?>
         <center>
         <div>
        
        <?php 
        //$chk= $myAgrocon->getThisShopItemPrice($itemid,$shopid,$ownID);
       // if ($chk->rowCount()<=0){
         //$stockID = Date("Ymdhis");
        $code="BUDA89HJ";
         $r= $myAgrocon->addOrder($shopid,$itemid,$code,$customerid,$quantity,$cost,$batchID);//createMyStock($stockID,$ownID,$itemid, $itemcost, $shopid, $currency);
         if($r->rowCount()>0)
         { 
          echo "Successful!..";
           $quantity ="";
         
           ?> 
       </div>
       </center> 

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

           /////////GET CURRENT ////////
           /////////////////////////
         $cc=$myAgrocon->getMyCurrentOrder($ownID,$shopid);
      if ($cc->rowCount()>0) {
         $bC=$cc->fetch();
         $batch=$bC['batchID'];
         $Q=$myAgrocon->getMyCurrentBatch($ownID,$shopid,$batchID)->fetch();
         $Qty=$Q['quantity'];
         $value=$Q['value'];
      }
      else{
        $Qty=0;
        $value=0;
        $batch=substr(Date("Ymdhis"),2);
      }
      ?>
       
      <ul>
        <li style="">
          Current order:<br/>
          Qty:<input type="submit" class="spos" name="qty" id="qty" value="<?php echo $Qty;?>">
          Value:<input type="submit" class="spos" name="value" id="value" value="<?php echo $value;?>">
          <form action="itemInbatchViewOtherIn" method="post">
          <input type="hidden" name="shopid" id="shopid" value="<?php echo $shopid;?>">
          <input type="hidden" name="batchID" id="batchID" value="<?php echo $batch;?>">
           <input type="hidden" name="owniD" id="owniD" value="<?php echo $ownID;?>">
           <input type="submit" name="post" class="spos" id="post" value="View detail">
           </form>
        </li>
      </ul>
      <!---CURRENT -->


       <?php  
         }else{
          echo "Submission error!..";
          $u=$r->ErrorInfo();
          print_r($u);//"Error occurred while saving data!..";
              }
         // }else{
           // echo "Item ready exist!..";
          //}
      
      }
      else{

        //////////////
        ?>
         <center>
         <div>
         <sup> <?php
              echo  $myAgrocon->eQuantity($quantity)."<p/>"; 
    
             ?>
       </sup>
       </div>
       </center> 

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

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