<?
 session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}

?>
<style>
 td{font-family:verdana;font-size:14;color:black;}
 th{font-family:verdana;font-size:14;color:white;background-color:#5b5858}
 body{background-color:ivory;}
 select
  {border-style:ridge;
   border-color:black;
   height:25px;
   border-size=1;
   font-family:verdana;
   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>
<?
 $df=$y."-".$m."-".$d;
 $dt=$y1."-".$m1."-".$d1;
?>
<script>
function show()
{
window.open("prncbook.php?df=<?print$df?>&dt=<?print$dt?>");
}
</script>
<center>
<table width=100%>
<tr><td align=right><a href='javascript:show()'><img src='Type001.gif' border=0><br>Print</a></td></tr>
</table>
 
<font face=verdana size=4>
Cash Book
<table bgcolor=black cellpadding=1 cellspacing=1 width=100%>
<tr bgcolor='silver'><td width=90><center><b>Date</td> <td width=80><center><b>Voucher </td> <td><center><b>Ledger</td> <td width=100><center><b>Receipt</td><td width=100><center><b> Payment</td> <td><center><b>Narration</td>

<?
 include("../opendb.php");
 include("../test.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($db));
$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($db));

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

$tr=0;
$tp=0;

if($opbal>0)
{
print "<tr bgcolor=white><td></td><td colspan=2>To Opening Balance</td><td align=right>".putComa($opbal)."</td><td></td><td></td></tr>";
}
else
{
print "<tr bgcolor=white><td></td><td colspan=2>To Opening Balance</td><td align=right><font color=red>".putComa($opbal)."</td><td></td><td></td></tr>";
}
$sq="select distinct jvno from journal2 where date='$row1[date]'";
     $se=mysqli_query($db,$sq)or die(mysqli_error($db));
print 'num:'. mysqli_num_rows($se);
   while($prt_row=mysqli_fetch_array($se))
  {print 'row:'. $prt_row[0];
  if($row[type]=='Dr')
  {
   print "<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'><td>". datetohtml($prt_row[date])."</td><td>($prt_row[against]) </td><td> $prt_row[partic]</td><td align=right></td><td align=right>".putComa($prt_row[dramt])."</td> <td>$row[narr]</td><td align=center><input type=button value='Del' onClick=document.location='deldat.php?code=$row[0]'></td></tr>";
  $tp+=$row[dramt];
  }
else if($row[type]=='Cr')
  {
 print "<tr bgcolor='#fffcd6' onMouseOver=bgColor='#f7dbd4'; onMouseOut=bgColor='#fffcd6'><td>".datetohtml($prt_row[date])."</td><td>($row[against]) </td><td> $prt_row[partic]</td><td align=right>".putComa($prt_row[cramt])."</td><td align=right></td> <td>$prt_row[narr]</td> <td align=center><input type=button value='Del' onClick=document.location='deldat.php?code=$row[0]'></td></tr>";
  $tr+=$row[cramt];
  }
$closebal=($tr+$opbal)-$tp;
$closebal=number_format($closebal,2,'','');

} // end while

if($closebal>0)
{
print "<tr bgcolor=silver><td colspan=3 align=center><font color=green><b>by Closing Balance</td><td></td><td align=right><font color=green>".putComa(abs($closebal))."</td><td></td>";
}
else
{
print "<tr bgcolor=silver><td colspan=3 align=center><font color=green><b>by Closing Balance</td><td></td><td align=right><font color='red'>(".putComa(abs($closebal)).")</td><td></td>";
}

print "<tr bgcolor=silver><td colspan=3><td align=right><font color=green>".putComa($tp+$closebal)."<br><hr></td><td align=right> <font color=green>".putComa($tp+$closebal)."<br><hr></td><td></td></tr>";
$opbal=$closebal;

} // end while
?>

