<?php

require_once("../config/configDB.php"); 

$spareid    = $_GET['spareid'];

$resultSpareQty = mysqli_query($conn,"SELECT sum(isd.spareqty) as spareqty   FROM internalpro_spare_dtl as isd WHERE isd.spareID='".$spareid."' and  isd.isdelete=1  ");

$SpareQty    = mysqli_fetch_array($resultSpareQty,MYSQLI_ASSOC);

$ASpareQty   = ($SpareQty['spareqty']>0) ? $SpareQty['spareqty'] : 0;


$resultSpareQtywo = mysqli_query($conn,"SELECT sum(purchase_eqty) as wospareqty   FROM purchasedetailswo  WHERE productID='".$spareid."' and status=''  ");

$SpareQtywo    = mysqli_fetch_array($resultSpareQtywo,MYSQLI_ASSOC);

$ASpareQtywo   = ($SpareQtywo['wospareqty']>0) ? $SpareQtywo['wospareqty'] : 0;



$result = mysqli_query($conn,"SELECT sum(psd.purchase_eqty) as spareqty   FROM purchasedetails as psd WHERE psd.productID='".$spareid."' and  psd.status=''  ");

$res = array();		
while($row = mysqli_fetch_array($result)){
    $AAspareQty  = ($row['spareqty']+$ASpareQtywo)-$ASpareQty; 
    array_push($res, array(
        "spareqty"=>$AAspareQty
    ));
}

echo json_encode($res);

//$row_cc = mysqli_fetch_array($sql);
//$rowcc=mysqli_fetch_array($sql,MYSQLI_ASSOC);
//echo $rowcc;
// $res = array();		
// while($row = mysqli_fetch_array($result)){
// 	$sql = mysqli_query($conn,"SELECT sum(amount) as amount  FROM collection_customer WHERE customerID='".$cid."' and saleID='".$row['saleBillNo']."' ");
// 	$row_cc = mysqli_fetch_array($sql);
// 	if($row_cc['amount'] < $row['tamount'] ) {
// 		array_push($res, array(
// 				"saleBillNo"=>($row['saleBillNo'])
//         	) 
// 		);
// 	}
// }
// 	echo json_encode($res);

?>