<?php







include 'connect.php';







$supplier=$_GET['supplier'];







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



		$sl1=mysql_fetch_array($sl);



		



		$re=mysql_query("select sum(amount) as amount from payment where supplier='$supplier'");



		$re1=mysql_fetch_array($re);



		



		$obl=mysql_query("select * from creditor_ledger where supplier='$supplier'");



		$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'];



		}



		$adjs=0;

		$loi=mysql_query("select * from purchase where supplier='$supplier'");

		while($loi1=mysql_fetch_array($loi))

		{

			$adjs=$adjs+$loi1['adjustment'];

		}





		//echo"$credit & $debit";

		

		

		$dnt=mysql_query("select sum(amount) as amount from debit_note where supplier='$supplier'");



		$dnt1=mysql_fetch_array($dnt);



		



		$deb=$sl1['amount']+$debit+$adjs;



		$cre=$re1['amount']+$credit+$dnt1['amount'];



		



		$cbl=$sl1['amount']+$adjs-$re1['amount']-$dnt1['amount']-$credit+$debit;



		



		/*if($cbl!=0)



		{*/



		



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



		{



		$deb=number_format($deb,2,'.','');



		}



		else



		{



		$deb='';



		}



		



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



		{



		$cre=number_format($cre,2,'.','');



		}



		else



		{



		$cre='';



		}







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











?>