<?php

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

$cid    = $_GET['cid'];

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

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);

$sql = mysqli_query($conn,"SELECT sum(received_amount) as amount  FROM supplier_payment_header WHERE supplierID='".$cid."' 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']);
	array_push($res, array(
				"pamount"=>($famount)
        	) 
 		);
//}
	echo json_encode($res);

?>