<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}
include("../opendb.php");
include("../test.php");
$bnk=$_REQUEST['bnk'];
$df=$_REQUEST['df'];
$dto=$_REQUEST['dto'];
?>
<style>
body,td 
{
    margin: 0 auto;
	font-family: Arial, Verdana, Sans-Serif;
	font-size: 0.8em;
}

 th{font-family:verdana;font-size:11;color:white;background-color:#5b5858}
 body{background-color:ivory}
</style>
<center>
<?
 $res=mysqli_query($db,"select * from journal2 where partic='$bnk' and brcode='$brcode' and dramt>0 and cramt=0 and date>='$df' and date<='$dto' and jvno not in(select jvno from breco where brcode='$brcode' and bank='$bnk')order by date")or die(mysqli_error());
print "<table border=1><th colspan=5>BANK RECONCILIATION <BR>$bnk<br>From ".datetohtml($df)." to ".datetohtml($dto)." (Not reconciled)";
$td=0;
$tc=0;
while($row=mysqli_fetch_array($res))
{
 print "<tr><td>".datetohtml($row[date])."<td>$row[narr]</td><td>$row[against] : $row[no]</td><td align=right>"
.nozero($row[dramt])."&nbsp;</td><td align=right>".nozero($row[cramt])."&nbsp;</td></tr>";
 $td+=$row[dramt];
 $tc+=$row[cramt];
}

 $res=mysqli_query($db,"select * from journal2 where partic='$bnk' and brcode='$brcode' and dramt=0 and cramt>0 and date>='$df' and date<='$dto' and jvno not in(select jvno from breco where brcode='$brcode' and bank='$bnk')order by date")or die(mysqli_error());

$tc=0;
while($row=mysqli_fetch_array($res))
{
 print "<tr><td>".datetohtml($row[date])."<td>$row[narr]</td><td>$row[against] : $row[no]</td><td align=right>0.00&nbsp;</td><td align=right>".nozero($row[cramt])."&nbsp;</td></tr>";
 $td+=$row[dramt];
 $tc+=$row[cramt];
}
print "<tr><td colspan=3 align=center><b>Total</td><td align=right>".putComa($td).
"</td><td align=right>".putComa($tc)."</td>";
?>
</table>
<br>&nbsp;

<?
 $sq="select * from ledger where  brcode='$brcode' and led='$bnk' ";

$result=mysqli_query($db,$sq)or die(mysqli_error());

$row=mysqli_fetch_array($result);
{$bal=0;


$balres=mysqli_query($db,"select sum(dramt)-sum(cramt) from journal2 where brcode='$brcode' and partic='$row[0]' and date>='$df' and date<='$dto'");
 $balrow=mysqli_fetch_row($balres);
 if($row[drcr]=='Dr')
 {$bal=($balrow[0]+$row[2])-$balrow[1]; //print '<br>bal'.$row[2];
 }
 else
{
 $bal=$balrow[1]+$row[2]-$balrow[0];
}
}
 $stat=$bal-$td+$tc;
print "<table border=1><th colspan=5>Summary <BR>$bnk<br>From ".datetohtml($df)." to ".datetohtml($dto)." ";
print "<tr><td>Balance as our Book</td><td align=right>".number_format($bal,2)."</td></tr>";
print "<tr><td>Deposit but not cleared</td><td align=right>".number_format($td,2)."</td></tr>";
print "<tr><td>Issued but not cleared</td><td align=right>".number_format($tc,2)."</td></tr>";
print "<tr><td>Balance as per Bank Statement</td><td align=right>".number_format($stat,2)."</td></tr>";
?>
