<?php

require_once("../config/configDB.php"); 
//productID='".$_GET['pid']."' and


$pid= $_GET['pid'];
$result = mysqli_query($conn,"SELECT purchase_rate  FROM product_master WHERE   id='".$pid."'   ");

$query_purchase=mysqli_query($conn,"select sum(purchase_eqty) as pqty from purchasedetails where productID='".$pid."' and status=''");
while($row_pqty=mysqli_fetch_array($query_purchase))
{
$pqty=$row_pqty['pqty'];

}

$query_sales=mysqli_query($conn,"select sum(sale_eqty) as sqty from saledetails where productID='".$pid."' and status=''");
while($row_sqty=mysqli_fetch_array($query_sales))
{
$sqty=$row_sqty['sqty'];

}

$available_qty=$pqty-$sqty;

$aqty=number_format($available_qty,2,'.','');

$res = array(); 
		
while($row = mysqli_fetch_array($result)){
	
	


	array_push($res, array(
		"purchase_rate"=>($row['purchase_rate']),
		"availqty"=>$aqty,
        	) 
 		);
 	}
 	echo json_encode($res);

//echo "tesing".$_GET['key'];




?>