<?php















include 'connect.php';















$customer=$_GET['customer'];























		$sl=mysqli_query($conn,"select sum(total) as amount from invoice where customer='$customer'");







		$sl1=mysqli_fetch_assoc($sl);







		







		$re=mysqli_query($conn,"select sum(amount) as amount from receipt where customer='$customer'");







		$re1=mysqli_fetch_assoc($re);







				







		$obl=mysqli_query($conn,"select * from debitor_ledger where customer='$customer'");







		$num=mysqli_num_rows($obl);







		$obl1=mysqli_fetch_assoc($obl);











		$credit=0;







		$debit=0;







		if($obl1['paymenttype']=='credit')







		{







		$credit=$obl1['amount'];







		$debit=0;







		}







		elseif($obl1['paymenttype']=='debit')







		{







		$credit=0;







		$debit=$obl1['amount'];







		}		







				



		$cnt=mysqli_query($conn,"select sum(amount) as amount from credit_note where customer='$customer'");







		$cnt1=mysqli_fetch_assoc($cnt);		



		



		



		$return=mysqli_query($conn,"select sum(total) as total from sales_return where customer='$customer'");



		$return1=mysqli_fetch_assoc($return);



				







		$cre=$sl1['amount']+$credit;







		$deb=$re1['amount']+$debit+$cnt1['amount']+$return1['total'];







				







		/*if($cbl!=0)







		{*/







		







		if($deb!='0' && $deb!='')







		{







		$deb=number_format($deb,0,'.','').'.00';







		}







		else







		{







		$deb='';







		}







		







		if($cre!='0' && $cre!='')







		{







		$cre=number_format($cre,0,'.','').'.00';







		}







		else







		{







		$cre='';







		}		







		







		$cbl=$cre-$deb;























echo"<div id='bal'>".number_format($cbl,2,'.','')."</div>";



















?>