<?
 session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}
include("opendmsdb.php");
include("../test.php");
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<style type="text/css" media="print">
.dontprintme { display: none; }
</style>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:14}
th{background-color:c1d799;font-size:14}
.mnu{margin-left:5}
</style>
<center>
<table width=100% bgcolor='lightsteelblue'>
<tr><td align=center><h3><?print $branch?> <br>AGE WISE DEBTORS LIST </TD></tr>
</table>
<br>
<table border=0 width=90%>
<tr><td align=center valign=top>

<table border=1> 
<th colspan=8>SUMMARY</th>
<TR>
<TH>BRANCH</TH><TH>TOTAL <TH>< 30 <TH>30-60 <TH>60-90 <TH>> 90
<?
$br=mysqli_query($db,"select distinct a.brcode,b.brname,date_format(a.upddate,'%W %d %M %Y %r') from debt2 a, branch b where a.brcode=b.brcode") or die(mysqli_error());
while($brrow=mysqli_fetch_array($br))
{
 $sq="select sum(total),sum(ls30),sum(30-60),sum(60-90),sum(gr90)  from debt2 where brcode='$brrow[0]'";
  $res=mysqli_query($db,$sq) or die('err'.mysqli_error());
$t1=$t2=0;
  print "<tr><td rowspan=2 align=center><b>$brrow[1]</B><br>As on ".$brrow[2]."</td>";
   while($row=mysqli_fetch_array($res))
    {
      print "<tr><td align=right>$row[0]</td><td align=right>$row[1]</td><td align=right>$row[2]</td>";
      print "<td align=right>$row[3]</td><td align=right>$row[4]</td>";
      $t1+=$row[1];
      $t2+=$row[2];
      $t3+=$row[3];
      $t4+=$row[4];
      $t5+=$row[5];
    }
//  print "<tr bgcolor='c1d799'><td>&nbsp;</td><td align=RIGHT>".putcoma($t1)."</td><td align=RIGHT>".putcoma($t2)."</td> <td align=RIGHT>".putcoma($t3)."</td><td align=RIGHT>".putcoma($t4)."</td><td align=RIGHT>".putcoma($t5)."</td></tr>";
}
?>
</table>




</td><td align=center valign=top>
<form action="<?print $PHP_SELF?>">
<table class=dontprintme bgcolor='c1d799' width=99%>
<tr><td align=center colspan=2><h3>AGE WISE DEBTORS LIST</TD></tr>
<tr bgcolor=white><td align=center>Select Branch </td><td> <select name='brn'>
<?
$br=mysqli_query($db,"select distinct a.brcode,b.brname,date_format(a.upddate,'%d %M %Y') from debt2 a, branch b where a.brcode=b.brcode") or die(mysqli_error());
while($brrow=mysqli_fetch_array($br))
{
 print "<option value='$brrow[0]'>$brrow[1]</option>";
}
?>
</select></td></tr>
<tr><td colspan=2 align=center><input type=submit value='Show' name='show'>
<input type=button value='Close this window' onClick=window.close()>
</td></tr>
</table>
</form>
</td></tr>
</table>

<?
if($show)
{
$res=mysqli_query($db,"select *,date_format(upddate,'%W %d %M %Y at %r') from debt2 where brcode='$brn'");
if(mysqli_num_rows($res)>0)
{
$row=mysqli_fetch_row($res);
$row=mysqli_fetch_array($res);
 $bres=mysqli_query($db,"select brname from branch where brcode='$brn'");
  $b_row=mysqli_fetch_row($bres);

?>
<table width=100% bgcolor='lightsteelblue'>
<tr><td align=center><h3>AGE WISE DEBTORS LIST OF <?PRINT $b_row[0]?></TD></tr>
<tr><td align=center> As on <?print $row[10]?>
</table>
<br>
<?
 print "<table cellpadding=3> <th> No. <th>Debtors <th>total <th>< 30 <th> 30-60 <th>60-90 <th>> 90";
 $i=1;
 $t1=$t2=$t3=$t4=$t5=0;
do
{
 if($i%2==0)
   print "<tr bgcolor='aliceblue'> ";
 else
   print "<tr>";
 print "<td align=center>".$i++."</td><td>$row[1]</td><td align=right>$row[2]</td>";
 print "<td align=right>$row[3]</td> <td align=right>$row[4]</td><td align=right>$row[5]</td>";
 print "<td align=right>$row[6]</td>";
 $t1+=$row[1];
 $t2+=$row[2];
 $t3+=$row[3];
 $t4+=$row[4];
 $t5+=$row[5];
}while($row=mysqli_fetch_row($res));
//print "<tr bgcolor='lightsteelblue'><td colspan=2 align=center><b>Total </td><td align=right>".putComa($t1)."</td>";
//print "<td align=right>".putComa($t2)."</td><td align=right>".putComa($t3)."</td><td align=right>".putComa($t4)."</td>";
//print "<td align=right>".putComa($t5)."</td>";
print "</table>";
}
} // c1d799 end if show edf6dd
?>
