<?php

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

$cid    = $_GET['cid'];

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

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);

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

?>