<?php 
session_start();
include('../includes/dbcon.php');

$str=" ";

$data = array();

$edate=date("Y-m-d");
$userid=$_SESSION['rm_id'];

if (isset($_POST['cus_id'])) {
	//$cus_id=1;
 	$cus_id = trim($_POST['cus_id']);
 	//$loc_id=$_SESSION['loc_id_bill'];

	        	$sqlsp=mysqli_query($con,"SELECT *,IFNULL((SELECT SUM(applyamount)FROM sedetail
WHERE sedetail.docid=seheader.docid AND seheader.party_id=sedetail.party_id AND
 docid IN (SELECT docid FROM seheader WHERE cancel<>1 AND docdate<= '$edate' )
 AND Refdocno IN (SELECT docid FROM seheader AS sh2 WHERE cancel<>1 AND docdate<= '$edate' )
 ),0) 
  AS app,
  (seheader.amount-
  IFNULL((SELECT SUM(applyamount)FROM sedetail
WHERE sedetail.docid=seheader.docid AND seheader.party_id=sedetail.party_id AND
 docid IN (SELECT docid FROM seheader WHERE cancel<>1 AND docdate<= '$edate' )
 AND Refdocno IN (SELECT docid FROM seheader AS sh2 WHERE cancel<>1 AND docdate<= '$edate' )
 ),0) )
  AS bal
 FROM seheader
 WHERE seheader.cancel<>1 AND seheader.party_id=$cus_id and seheader.amount>0 ")or die(mysqli_error($con));
	        	$count=mysqli_num_rows($sqlsp);	
	        	if ($count>0) {
	        		while($rowsp=mysqli_fetch_array($sqlsp)){			
					 $data[]=$rowsp;				
				   }	

				    echo json_encode($data);
	        	}//	if ($count>0) {
exit();
	        	 //echo 'hello';
	  


} ///// if (isset($_POST['category'])) {

?>