<?
 session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}
 include("test.php");
?>
<style>
 body,td{font-family:arial;font-size:13;color:black;}
 body{background-color:white;}
 select
  {border-style:ridge;
   border-color:black;
   height:25px;
   border-size=1;
   font-family:fixed;
   color:black;
  }
 input
  {border-style:ridge;
   border-color:#22437f;
   background-color:white;
   height:25px;
   font-weight:bold;
   border-size=1;
   font-family:sans-serif;
   color:BLACK;
  }
</style>
<center>
 
<? print $branch?><br>
Cash Book for the period of <?print datetoHtml($df)." To ".datetoHtml($dt)?>
<table bgcolor=ivory cellpadding=1 cellspacing=1 width=100%  border=0>


<tr bgcolor='white' ><td width=25></td><td width=90 border=1><center><b>Date</td> <td width=200><center><b>Ledger</td> <td width=120><center><b>Receipt</td><td width=120><b> Payment</td><td width=25></td> <td width=295><b>Narration</td>
</tr>
<hr>
</table>
<hr>
<table bgcolor=ivory cellpadding=1 cellspacing=1 width=100% >



<?
 include("opendb.php");


$bal=mysqli_query($db,"select op from ledger where led='Cash' and brcode='$brcode'");
$opbalance=mysqli_fetch_row($bal);
$res=mysqli_query($db,"select acfrom from acperiod");
$r1=mysqli_fetch_row($res);
$ssq="select sum(dramt)-sum(cramt) from journal2 where brcode='$brcode' and date>='$r1[0]' and date<'$df' and (partic='Cash')";

$res2=mysqli_query($db,$ssq)or die('jour err:'.mysqli_error());
$r2=mysqli_fetch_row($res2);

$opbal=($opbalance[0]+$r2[0]);
$result1=mysqli_query($db,"select distinct date from journal2 where brcode='$brcode' and date>='$df' and date<='$dt' and partic='Cash' order by date")or die(mysqli_error());

$head=1;
while($row1=mysqli_fetch_array($result1))
{

if($opbal>0)
{
print "<tr bgcolor=white><td></td><td></td><td colspan=4><font size=2><b>To Opening Balance</td><td align=right><font size=1><b>".putComa($opbal)."</td><td></td></tr>";
}
else
{
print "<tr bgcolor=white><td></td><td></td><td></td><td colspan=4><font size=2><b>To Opening Balance</td><td></td><td align=right><font size=1><b>".putComa($opbal)."</td><td></td></tr>";
}
$sq="select distinct jvno from journal2 where date='$row1[date]' and partic='Cash' and brcode='$brcode'";
     $se=mysqli_query($db,$sq)or die(mysqli_error());
$tr=0;
$tp=0;
   while($prt_row=mysqli_fetch_array($se))
    {

  	$fnl=mysqli_query($db,"select * from journal2 where jvno='$prt_row[0]' and brcode='$brcode'");
          while($fnl_row=mysqli_fetch_array($fnl))
          {
               if($fnl_row[partic]!='Cash') // && $fnl_row[type]=='Dr'
		{
                 print "<tr bgcolor=white><td width=1></td><td width=2 align=right>|</td><td width=50 align=right ><font size=1>".datetohtml($fnl_row[date])."</td>&nbsp;<td width=2><center>|</td><td width=200><font size=1>$fnl_row[partic]</td><td width=15><center>|</center></td>";
                print "<td width=60 align=right><font size=1>".nozero($fnl_row[cramt])."</td><td width=2><center>|</td><td width=60 align=right><font size=1>".nozero($fnl_row[dramt])."</td>";
		print "<td width=15><center>|</center></td><td width=180 align=LEFT><font size=1>$fnl_row[narr]</td><td>|</td></tr>";
			if($fnl_row[type]=='Dr') $tp+=$fnl_row[dramt]; else $tr+=$fnl_row[cramt];

$closebal=($tr+$opbal)-$tp;
                 }
          }

    }

if($closebal>0)
{
print "<tr ><td colspan=7 align=center><font size=1><b>by Closing Balance</td><td><center>|</td><td align=right><font size=1><b>".putComa(abs($closebal))."</td><td><center>|</td><td></td>";
}
else
{
print "<tr ><td colspan=7 align=center><font size=1><b>by Closing Balance</td><td><center>|</td><td align=right><font size=1><b>(".putComa(abs($closebal)).")</td><td><center>|</td><td></td>";
}

print "<tr bgcolor=white><td colspan=6><td align=right><font size=1><b>".putComa($tp+$closebal)."<br><hr></td><td><center>|</td><td align=right><font size=1><b>".putComa($tp+$closebal)."<br><hr></td><td><center>|</td><td></td></tr>";
$opbal=$closebal;
	
}
?>

