<?php

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

$explosiveid    = $_GET['explosiveid'];

$resultexplosiveQty = mysqli_query($conn,"SELECT sum(isd.explosiveqty) as explosiveqty   FROM internalpro_explosive_dtl as isd WHERE isd.explosiveID='".$explosiveid."' and  isd.isdelete=1  ");

$explosiveQty    = mysqli_fetch_array($resultexplosiveQty,MYSQLI_ASSOC);

$AexplosiveQty   = ($explosiveQty['explosiveqty']>0) ? $explosiveQty['explosiveqty'] : 0;


$returnexplosiveQty = mysqli_query($conn,"SELECT sum(isd.explosivereturnqty) as explosivereturnqty   FROM explosive_return_dtl as isd WHERE isd.explosiveID='".$explosiveid."' and  isd.isdelete=1  ");

$returnQty    = mysqli_fetch_array($returnexplosiveQty,MYSQLI_ASSOC);

$AreturnexplosiveQty   = ($returnQty['explosivereturnqty']>0) ? $returnQty['explosivereturnqty'] : 0;




$result = mysqli_query($conn,"SELECT sum(psd.explosiveqty) as explosiveqty   FROM purchase_explosiveinvoice_dtl as psd WHERE psd.explosiveID='".$explosiveid."' and  psd.isdelete=1  ");

$res = array();		
while($row = mysqli_fetch_array($result)){
    $AAexplosiveQty  = $row['explosiveqty'] - $AexplosiveQty ; 
    array_push($res, array(
        "explosiveqty"=>$AAexplosiveQty
    ));
}

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);

?>