<?
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>PURCHASE RETURN 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 name='print' value='Print'>
</td></tr>
</table>
</form>

<?
$print = $_REQUEST['print'];
if($print)
{
    $y = $_REQUEST['y'];
    $m = $_REQUEST['m'];
    $d = $_REQUEST['d'];
    $y1 = $_REQUEST['y1'];
    $m1 = $_REQUEST['m1'];
    $d1 = $_REQUEST['d1'];    
    $df=$y.'-'.$m.'-'.$d;
    $dt=$y1.'-'.$m1.'-'.$d1;
  print "<script> window.open('prnpurretreg.php?df=$df&dt=$dt'); </script>";
 return;
}
$show = $_REQUEST['show'];
if($show)
{
    $y = $_REQUEST['y'];
    $m = $_REQUEST['m'];
    $d = $_REQUEST['d'];
    $y1 = $_REQUEST['y1'];
    $m1 = $_REQUEST['m1'];
    $d1 = $_REQUEST['d1'];    

   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
   $result=mysqli_query($db,"select * from veh_purchreturn where date>='$df' and date<='$dt' and brcode='$brcode'") or die(mysqli_error());
   if(mysqli_num_rows($result)>0)
   {
        ?>
        <table bgcolor=silver cellspacing=1 cellpadding=1>
        <th>No.<th>To <th>Ret NO.<th>Date<th>Pur_invoice <th>DA <th>MCode <th>Config<th>Chasis No. 
        <th>Before Tax <th>IGST% <th>IGST Amt <th>Total Amt.
        <?
        $i=1;
        while($row=mysqli_fetch_array($result))
        {
            $pres=mysqli_query($db,"select entrydate,chasis from veh_purchase where da='$row[da]' and brcode='$brcode'");
            $prow=mysqli_fetch_array($pres);
            if(mysqli_num_rows($pres)<=0)
                $dt='1-4-2008(OP)';
            else
                $dt=datetohtml($prow[0]);
            if($row['ret_num']=='3751562400004')
                $text= 'OUTWARD SUPPLY';
            else
                $text= 'INWARD SUPPLY';
            print "<tr bgcolor=white><td>".$i++."</td><td>$row[retto]</td><td>$row[ret_num]</td><td>".datetohtml($row['date'])."</td><td>$row[pur_invoice]</td>";
            print "<td>$row[da]</td><td>$row[mcode]</td><td>$row[config]</td><td>$text</td>";
            print "<td align=right>$row[amt2]</td><td align=right>$row[taxp]</td><td align=right>$row[tax]</td><td align=right>$row[netamt]</td></tr>";
        }
    }
    else
        print "<font color=red size=3>Record does note exist";
}
?>
</table>
<br>


