<?
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>
<?
$brre=mysqli_query($db,"select brcode,brname from branch where brcode='$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%>";
 print "<th>Particulars <th>Dr <th>Cr";
 $res=mysqli_query($db,"select led from ledger where brcode='$brrow[0]' and grp='Sundry Debtors'");
 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>";
   if($dif>0)
    { print "<td align=right width=95>".putComa(round($dif,2))."</td><td>&nbsp;</td></tr>";
      $tdr+=$dif;
    }
   else
     {
       print "<td>&nbsp;</td><td align=right width=95>".putComa(round(abs($dif),2))."</td></tr>";
       $tcr+=$dif;
     }
    //$tdiff+=$dif;
  }
 }
  print "<tr><td><center><b>Total</td><td align=right><b>".putComa($tdr)."</td>";
  print "<td align=right><b>".putComa(abs($tcr))."</tr>";
  print "</table></fieldset><br>";

}
  
