

<?php  
require_once("config/configDB.php"); 
require "financial_year_calculation.php";
$accountyear    = $financialYearStart."-".$financialYearEnd;

if(!isset($_SESSION))  { session_start(); }
if(isset($_POST["prate"]))  
 {  
	if($_POST["prate"]!=""){
      $output = '';  
	  $prate=$_POST["prate"];
	   $pid=$_POST["productid"];
	  
	  $query_gst = "SELECT sum(purchase_eqty) as qty from purchasedetails where productID = '$pid' and purchase_prate='$prate' and status='' "; 
	 
      $exec_gst = mysqli_query($conn,$query_gst) or die ("Error in Query".mysqli_error());
      $row_gst = mysqli_fetch_array($exec_gst);
	  $purchase_qty=$row_gst['qty'];
	  
	  
	  
	  $query_return = "SELECT sum(sale_eqty) as saleqty from saledetails where productID = '$pid' and sale_prate='$prate' and status='' "; 
	 
      $exec_return = mysqli_query($conn,$query_return) or die ("Error in Query".mysqli_error());
      $row_return = mysqli_fetch_array($exec_return);
	  $sale_qty=$row_return['saleqty'];
	  
	  
	  
	   $query_out = "SELECT sum(sale_eqty) as returnqty from tray_return_details where productID = '$pid' and sale_prate='$prate' and status='' "; 
	 
      $exec_out = mysqli_query($conn,$query_out) or die ("Error in Query".mysqli_error());
      $row_out = mysqli_fetch_array($exec_out);
	  $retrun_qty=$row_out['returnqty'];
	  
	 $available_qty1=$purchase_qty-($sale_qty);
	 
	 $available_qty=$available_qty1+$retrun_qty;
	
		
 $output = $available_qty.'||';
	}  
 }
echo $output;  
 ?>  

