<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
$df=$_REQUEST['df'];
$dt=$_REQUEST['dt'];
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:14}
th{background-color:c1d799}
.mnu{margin-left:5}
</style>
<center>
<H3>
<?print $branch?> <br>
SALES RETURN REGISTER<br>
From <?print datetohtml($df).' To '.datetohtml($dt)?>
</H3>

<?
$tnet=0;
$ttax=0;
$tb=0;

$i=1;
   $result=mysqli_query($db,"select * from veh_salereturn 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>Customer<th>GSTIN</th> <th>Ret NO.<th>Ret Date <th>Sale_invoice <th>Inv Date <th>DA <th>Config <th>Before Tax
<th>Tax% <th>CGST Amt<th>SGST Amt</th><th>Net Amount
<?
while($row=mysqli_fetch_array($result))
{
    $cus_result=mysqli_query($db,"select custname,tin from cust_master where code='$row[retfrom]'")or die(mysqli_error());
    $cus_row=mysqli_fetch_row($cus_result);
    $invdtres=mysqli_query($db,"select invdate from veh_invoice where da='$row[da]' and brcode='$brcode'");
    $invdtrow=mysqli_fetch_array($invdtres);
    print "\n<tr bgcolor=white><td>".$i++."</td><td>$cus_row[0]</td><td>$cus_row[1]</td><td>$row[ret_num]</td>";
    print "<td>".datetohtml($row[date])."</td>";
    print "<td>$row[sale_invoice]</td>";
    print "<td>".datetohtml($invdtrow[0])."</td>";
    print "<td>$row[da]</td><td>$row[mcode]</td<td>$row[config]</td>";
    $mcgstamt = $row[tax]/2;
    $msgstamt = $row[tax]/2;
    print "<td align=right>$row[amt2]</td><td align=right>$row[taxp]</td><td align=right>$mcgstamt</td><td align=right>$msgstamt</td>";
    print "<td align=right>$row[netamt]</td></tr>";
    $tnet+=$row[netamt];
    $ttax+=$row[tax];
    $tb+=$row[amt2];
}
print "<tr><td colspan=9 align=center><b>Total</td><td align=right><b>".putcoma($tb)."</td>";
print "<td>&nbsp;</td><td align=right><b>&nbsp;".putComa($ttax/2)."</td><td align=right><b>&nbsp;".putComa($ttax/2)."</td>";
print "<td align=right><b>".putComa($tnet)."</td></tr>";
}
?>
</table>
<br>
