<?
session_start();
include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	th{background-color:steelblue;color:white}
td{font-size:12}
.right{text-align:right};
</style>
<center>
<h3>
TELCON <?PRINT $branch?><bR>
SPARE - SALES RETURN</H3>
<script>
 function fun(retno,jvno)
 {
   if(confirm('Do you want to delete retno:'+retno+' ?'))
    document.location='delreturnspare.php?retno='+retno+'&jvno='+jvno;
 }
</script>

<?
if($show&&$allbr=='y')
{
$df=$y.'-'.$m.'-'.$d;
$dto=$y1.'-'.$m1.'-'.$d1;
print 'From '.datetohtml($df).' to '.datetohtml($dto);
$res=mysqli_query($db,"select distinct brcode from salesreturn where entrydate>='$df' and entrydate<='$dto' order by brcode");
while($row1=mysqli_fetch_array($res))
{
 $t=0;
 print "<fieldset><legend>".getbrname($row1[0])."</legend>";

	print "<table border=0 cellpadding=3> <th>Ret No <th>Inv No <th>Inv Date<th>Customer  <th>Entry Date";
	print "<th>Item Code <th>Item Name <th>Ret Qty<th>Amount <th>Tax Amt <th>Cess <th>Total";
$sq="select * from salesreturn where brcode='$row1[0]' and entrydate>='$df' and entrydate<='$dto' order by retno";
$res1=mysqli_query($db,$sq)or die('Er1'.mysqli_error());
while($row=mysqli_fetch_array($res1))
{
print "<tr bgcolor='aliceblue'><td>$row[retno]</td><td>$row[invno]</td>";

if($row[invtype]=='JC')
$sq="select entrydate from jobcard where invno='$row[invno]' and brcode='$row1[0]'";
else
$sq="select entrydate from spareinvoice where invno='$row[invno]' and brcode='$row1[0]'";

$invdres=mysqli_query($db,$sq) or die('Err:'.mysqli_error());
$invdrow=mysqli_fetch_row($invdres);

print "<td>".datetohtml($invdrow[0])."</td>";
print "<td>$row[customer]</td><td>".datetohtml($row[entrydate])."</td>";
  print "<td>$row[partcode]</td><td>$row[partname]</td><td align=right>$row[qty]</td>";
  print "<td>$row[aprice]</td><td>$row[taxamt]</td><td>$row[cessamt]</td>";
 print "<td align=right>".putcoma($row[tot]+$row[cessamt])."</td>";
// print "<td><input type=button value='Del' onClick=fun('$row[retno]','$row[jvno]')></td>";
 print "</tr>";
$t+=($row[tot]+$row[cessamt]);
}
print "<tr><td colspan=11><center><b>Total</td><td align=right>".putComa($t)."</td>";
print "</tr>";
print "<th colspan=12></th>";
print "</table></fieldset>";

}
return;
} // end if
else if($show)
{
$df=$y.'-'.$m.'-'.$d;
$dto=$y1.'-'.$m1.'-'.$d1;
print 'From '.datetohtml($df).' to '.datetohtml($dto);
$res=mysqli_query($db,"select * from salesreturn where brcode='$brcode' and entrydate>='$df' and entrydate<='$dto' order by retno");
print "<table border=0 cellpadding=3> <th>Ret No <th>Inv No <th>Inv Date<th>Customer  <th>Entry Date";
print "<th>Item Code <th>Item Name <th>Ret Qty<th>Amount <th>Tax Amt <th>Cess <th>Total<th>Del";
while($row=mysqli_fetch_array($res))
{
  
print "<tr bgcolor='aliceblue'><td>$row[retno]</td><td>$row[invno]</td>";

if($row[invtype]=='JC')
$sq="select entrydate from jobcard where invno='$row[invno]' and brcode='$brcode'";
else
$sq="select entrydate from spareinvoice where invno='$row[invno]' and brcode='$brcode'";
$invdres=mysqli_query($db,$sq) or die('Err:'.mysqli_error());
$invdrow=mysqli_fetch_row($invdres);

print "<td>".datetohtml($invdrow[0])."</td>";
print "<td>$row[customer]</td><td>".datetohtml($row[entrydate])."</td>";
  print "<td>$row[partcode]</td><td>$row[partname]</td><td align=right>$row[qty]</td>";
  print "<td>$row[aprice]</td><td>$row[taxamt]</td><td>$row[cessamt]</td>";
 print "<td align=right>".putcoma($row[tot]+$row[cessamt])."</td>";
 print "<td><input type=button value='Del' onClick=fun('$row[retno]','$row[jvno]')></td></tr>";
$t+=($row[tot]+$row[cessamt]);
}
print "<tr><td colspan=9><center><b>Total</td><td align=right>".putComa($t)."</td>";
print "</tr>";
print "<th colspan=12></th>";
print "</table>";
return;
}
?>

<form action='<?print $PHP_SELF?>' name='f1'>
<table>
<tr><td bgcolor='steelblue' colspan=2><center><b><font color=white>PURCHASE REPORT</td></tr>
<tr><td>Date From </td><td>dd<input type=text name='d' size=2 value='<?print date("d");?>'>
			mm<input type=text name='m' size=2 value='<?print date("m");?>'>
			yy<input type=text name='y' size=4 value='<?print date("Y");?>'>
</td></tr>
<tr><td>Date To </td><td>dd<input type=text name='d1' size=2 value='<?print date("d");?>'>
			mm<input type=text name='m1' size=2 value='<?print date("m");?>'>
			yy<input type=text name='y1' size=4 value='<?print date("Y");?>'>
</td></tr>
<?
if($brcode=='ERA153')
{
 print "<tr><td colspan=2 bgcolor='silver'><input type=checkbox name='allbr' value='y'>Show all branch</td></tr>";
}?>

<th colspan=2><INPUT TYPE=SUBMIT VALUE='SHOW' name='show'></td></tr>
</table>
</form>
