<?
 session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<H3>CREDIT NOTE REGISTER</H3>
<form action='<?print $PHP_SELF?>'>
<table bgcolor='silver'>
<tr><td> Date from </td><td>dd<input type=text name='d' size=2 value='<?print date("d",time())?>'>
				mm<input type=text name='m' size=2 value='<?print date("m",time())?>'>
				yy<input type=text name='y' size=4 value='<?print date("Y",time())?>'>
			</td></tr>

<tr><td> To </td><td>dd<input type=text name='d1' size=2 value='<?print date("d",time())?>'>
				mm<input type=text name='m1' size=2 value='<?print date("m",time())?>'>
				yy<input type=text name='y1' size=4 value='<?print date("Y",time())?>'>
			</td>
</tr>
<tr><td colspan=2 align=center><input type=submit name='show' value='Show'>
<input type=submit value='Print' name='prn'></td></tr>
</table>
</form>
<?

if($prn)
{
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
       print "<script> window.open('prncrnotereg.php?df=$df&dt=$dt');</script>";
}


 if($show)
  {
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
$sql="select a.custname,b.ret_num,b.date, b.da, b.sale_invoice,b.netamt,b.tax,b.taxp,b.amt2 from cust_master a,crnote b where b.brcode='$brcode' and b.retfrom=a.code and date>='$df' and date<='$dt'";
   $result=mysqli_query($db,$sql) or die(mysqli_error());
   if(mysqli_num_rows($result)>0)
   {
?>
<table bgcolor=silver cellspacing=1 cellpadding=3 width=100%>
<th>Cr.No<th>Customer <th>Date <th>DA <th>Sale Invoice <th>Net Amount <th>Tax <th>Tax% <th>Before Tax
<?
$tnet=0;
$ttax=0;
$bt=0;
  while($row=mysqli_fetch_array($result))
 {
 print "<tr bgcolor=white><td>$row[1]</td><td>$row[0]</td><td>".datetohtml($row[2])."</td><td>$row[3]</td><td>$row[4]</td>";
print "<td align=right>$row[5]</td><td align=right>$row[6]</td><td align=right>$row[7]</td><td align=right>$row[8]</td></tr>";
 $bt+=$row[8];
 $ttax+=$row[6];
 $tnet+=$row[5];
 }
 print "<tr bgcolor=white><td colspan=5 align=center><b>Total</td><td align=right><b>".putComa($tnet)."</td>";
 print "<td align=right><b>".putComa($ttax)."</td><td>&nbsp;</td><td align=right><b>".putComa($bt)."</td></tr>";

 print "</table>";
}


}
?>
