<?php

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

$saleid    = $_GET['purchaseid'];

$result = mysqli_query($conn,"SELECT sum(tamount) as pamount FROM purchaseheader    WHERE invoice_no='".$saleid."' and status=''  ");

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);

$sql = mysqli_query($conn,"SELECT sum(amount) as amount  FROM supplier_payment WHERE purchaseID='".$saleid."' and status=''  ");

//$row_cc = mysqli_fetch_array($sql);
$rowcc=mysqli_fetch_array($sql,MYSQLI_ASSOC);
//echo $rowcc;

$res = array();		
//while($row = mysqli_fetch_array($result)){
		
	$famount = round($row['pamount']-$rowcc['amount']);
	//$famount = $row['pamount'];
	array_push($res, array(
				"pbillamount"=>($famount)
        	) 
 		);
//}
	echo json_encode($res);

?>