<?php















include 'connect.php';















$customer=$_GET['customer'];























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







		$sl1=mysql_fetch_array($sl);







		







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







		$re1=mysql_fetch_array($re);







				







		$obl=mysql_query("select * from debitor_ledger where customer='$customer'");







		$num=mysql_num_rows($obl);







		$obl1=mysql_fetch_array($obl);











		$credit=0;







		$debit=0;







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







		{







		$credit=$obl1['amount'];







		$debit=0;







		}







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







		{







		$credit=0;







		$debit=$obl1['amount'];







		}		







				



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







		$cnt1=mysql_fetch_array($cnt);		



		



		



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



		$return1=mysql_fetch_array($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>";



















?>