<?php

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

$cid    = $_GET['cid'];

$result = mysqli_query($conn,"SELECT sh.invoice_no as purchaseBillNo,sh.tamount  FROM purchaseheader as sh     
WHERE sh.supplier_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 supplier_payment WHERE supplierID='".$cid."' and purchaseID='".$row['purchaseBillNo']."' and status=''  ");

	$row_cc = mysqli_fetch_array($sql);

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

?>