<?
 session_start();
 $brcode = $_SESSION['brcode'];
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>DEBIT 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>
<?
$prn = $_REQUEST['prn'];
$show = $_REQUEST['show'];
if($prn)
{
    $d = $_REQUEST['d'];
    $m = $_REQUEST['m'];
    $y = $_REQUEST['y'];
    $d1 = $_REQUEST['d1'];
    $m1 = $_REQUEST['m1'];
    $y1 = $_REQUEST['y1'];
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
    //   print "<script> window.open('prncrnotereg.php?df=$df&dt=$dt');</script>";
}
if($show)
{
    $d = $_REQUEST['d'];
    $m = $_REQUEST['m'];
    $y = $_REQUEST['y'];
    $d1 = $_REQUEST['d1'];
    $m1 = $_REQUEST['m1'];
    $y1 = $_REQUEST['y1'];
   	$df=$y.'-'.$m.'-'.$d;
   	$dt=$y1.'-'.$m1.'-'.$d1;
	$sql="select date,dbno,partic,cramt,narr,dbto,recv_date,recv_rem,recv_amt,status from dbnote where cramt > 0 and brcode='$brcode' and date>='$df' and date<='$dt' order by dbno"; 
   	$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>SL No<th>Date<th>DB.No<th>Ledger Name <th>Amount<th>Narration <th>Segment<th>Recieve Date<th>Remitance<th>Recieve Amount<th>Status 
		<?
		$mtot=0;
		$ctr=1;
		while($row=mysqli_fetch_array($result))
 		{
 			print "<tr bgcolor=white><td align='right'>".$ctr++."</td><td>".datetohtml($row[0])."</td><td>$row[1]</td><td>$row[2]</td><td align='right'>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td><td>$row[9]</td></tr>";
 			$mtot+=$row[3];
 		}
 		print "<tr bgcolor=white><td></td><td></td><td></td><td align='center'><b>T O T A L</td><td align='right'><b>$mtot</td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
 		print "</table>";
	}
}
?>