<?php

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


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



$query_purchase=mysqli_query($conn,"select sum(trd.sale_eqty) as rqty from tray_return_details as trd inner join tray_return_header as trh on trh.id=trd.saleheader_id where trd.productID='".$pid."' and trd.status=''  and trh.status='' and trh.customer_id='".$cid."'");
while($row_pqty=mysqli_fetch_array($query_purchase))
{
$pqty=$row_pqty['rqty'];

}

$query_sales=mysqli_query($conn,"select sum(sd.sale_eqty) as sqty from saledetails sd inner join saleheader as sh on sh.id=sd.saleheader_id where sd.productID='".$pid."' and sd.status='' and sh.status='' and sh.customer_id='".$cid."'");
while($row_sqty=mysqli_fetch_array($query_sales))
{
$sqty=$row_sqty['sqty'];

}

$available_qty=$sqty-$pqty;

$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'];




?>