<?php

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

$cid    = $_GET['cid'];

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

//$row = mysqli_fetch_array($result,MYSQLI_ASSOC);



//$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']."' and status='' ");

	$row_cc = mysqli_fetch_array($sql);

	if($row_cc['amount'] < $row['tamount'] ) {
	
		array_push($res, array(
				"saleBillNo"=>($row['saleBillNo'])
        	) 
		);
	}
}
	echo json_encode($res);

?>