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

$sql_opening = mysqli_query($conn,"SELECT opening_balance  FROM customer_master WHERE id='".$cid."'  ");

//$row_cc = mysqli_fetch_array($sql);
$row_opening=mysqli_fetch_array($sql_opening,MYSQLI_ASSOC);



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

?>