<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");

?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	th{background-color:steelblue;color:white}
.right{text-align:right};
</style>
<center>
<p align=center style="background-color:#9A8E64; height:60"><br>
<font color='#FFFFE6' size=3><b>BRANCH WISE DEBTORS SUMMARY</b>
<br>AS ON <?print date("d-m-Y")?></font>
</p>
<?
if($show)
{
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;

$brre=mysqli_query($db,"select distinct brcode,brname from branch order by brcode");
while($brrow=mysqli_fetch_array($brre))
{
 $tdiff=0;
 print "<fieldset><legend><font color=#9A8E64>Branch:</font> $brrow[1]</legend>";
 print "<table border=0 cellspacing=1 cellpadding=3 bgcolor='#BBAD7A' width=90%>";
 $res=mysqli_query($db,"select count(*) from saleorder_spare where brcode='$brrow[0]'");
 while($ro=mysqli_fetch_array($res))
 {
  $jvop=mysqli_query($db,"select op from ledger where led='$ro[0]' and brcode='$brrow[0]'");
  $jvrow=mysqli_fetch_array($jvop);
  $op=$jvrow[0];
  $sumres=mysqli_query($db,"select sum(dramt)-sum(cramt) from journal2 where partic='$ro[0]' and brcode='$brrow[0]'");
  $sumrow=mysqli_fetch_row($sumres);
  $dif=$op+$sumrow[0];
  if($dif>0)
  {
    print "<tr bgcolor=white><td><a href='../accounts/vmledger-era.php?cd=$ro[led]&bcode=$brrow[0]'>$ro[led]</a></td><td align=right width=95>$dif</td></tr>";
    $tdiff+=$dif;
  }
 }
  print "<tr><td><center><b>Total</td><td align=right><b>".putComa($tdiff)."</td></tr>";
  print "</table></fieldset><br>";

}
}
?> 
<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>
<tr><td>Date from </td><td>dd <input type=text name='d1' size=2 value='<?print date("d")?>'>
mm <input type=text name='m1' size=2 value='<?print date("m")?>'>
yy <input type=text name='y1' size=4 value='<?print date("Y")?>'></td></tr>

<tr><td align=right>to </td><td>dd <input type=text name='d2' size=2 value='<?print date("d")?>'>
mm <input type=text name='m2' size=2 value='<?print date("m")?>'>
yy <input type=text name='y2' size=4 value='<?print date("Y")?>'>
</td></tr>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></td></tr>
</table>
</td></tr>
</table>
</form>

