<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
$invno=$_REQUEST['invno'];
$retno=$_REQUEST['retno'];
include("../opendb.php");
include("../test.php");
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);

if($invno)
	$re=mysqli_query($db,"select * from salesreturn where retno='$retno' and invno='$invno' and brcode='$brcode'")or die(mysqli_error($db));
else
	$re=mysqli_query($db,"select * from salesreturn where retno='$retno' and brcode='$brcode'")or die(mysqli_error($db));

$row=mysqli_fetch_array($re)or die("Fetch Error:".mysqli_error($db));

?>

<style>
th{font-size:13}
</style>
<style>
 td,body{font-family:'arial narrow';font-size:15;letter-spacing:1}
</style>

<center>

<table width=100% BORDER=0>
<tr><td>Sales Retrn  No :
<?
print '['.substr($brcode,0,3).']';
?>
 <?
if($row[invtype]=='JC')
print "JC-".$retno;
else
print "S-".$retno;
?>
</td><td align=right>Date : <?print datetohtml($row[entrydate])?> </td></tr>
<TR><TD COLSPAN=2 ALIGN=CENTER><b> PSN AUTOMOBILES P LTD </b><BR>
	 <?print $brrow[braddr]."<br>".$brrow[brcity]."<br><u> PH - ".$brrow[brphone]?></u>
<br>TIN: <?print $brrow[tin]?><br>CST: <?print $brrow[cstno]?><br>&nbsp;
</td></tr>
<TR><TD COLSPAN=2 ALIGN=CENTER> FORM <?print $row[invtype]?></td></tr>
<TR><TD COLSPAN=2 ALIGN=left> Customer : <?print $row[customer].'<br>'.$row[addr].'<br>TIN : '. $row[tin]?></td></tr>
</table>

<br>
<table border=0 WIDTH=90%>
<th width=15>NO.<th style="text-align:left">Location<th width=210 style="text-align:left">DESCRIPTION OF GOODS <TH width=40>QUANTITY <TH width=50>RATE <th width=80>AMOUNT  <TH>TAX  <th>CESS <TH>NET AMOUNT</TH>
<tr><td colspan=10><hr></td></tr>
<?
//$re1=mysqli_query($db,"select * from spareinvoice where invno='$invno' and invtype='$invtype' and brcode='$brcode'")or die('ERr'.mysqli_error($db));
 $sql="select * from salesreturn where retno='$retno' and brcode='$brcode'";
$re1=mysqli_query($db,$sql)or die('err:'.mysqli_error($db));

$i=1;
$tq=0;
$tp=0;
$cnt=1;
while($row1=mysqli_fetch_array($re1))
{
 print "<tr><td align=center width=15>".$cnt++."</td>";
 $locres=mysqli_query($db,"select location from sparelocmast where brcode='$brcode' and itemcode='$row1[partcode]'");
 $locrow=mysqli_fetch_row($locres);
print "<td>$locrow[0]</td>";
 PRINT "<td>$row1[partcode] ($row1[partname])</td><td align=right>$row1[qty]</td><td align=right>".putComa($row1[price])."</td>";
 print "<td align=right>".putComa($row1[qty]*$row1[price])."</td>";
 print "<td align=right>$row1[taxamt]</td>";
print " <td align=right>$row1[cessamt]</td>";
print "<td align=right>".putComa($row1[tot])."</td></tr>";
print "<tr><td colspan=10><hr></td></tr>";
$i++;
$tq+=$row1[qty];
$tp+=$row1[tot];
}

for($j=$i;$j<=16;$j++)
{
 print "<tr><td colspan=10>&nbsp;</td></tr>";
}

print "<tr><td colspan=110>";

print "<HR></tD></tR>";

print "<tr><td align=right>Total </td><td></td><td align=right>$tq Nos</td>";
print "<td colspan=9 align=right>".putComa($tp)."</td></tr>";

print "<tr><td colspan=160>";
for($j=0;$j<=100;$j++)
{
 print "=";
}
print "</td></tr>";

print "<tr><td colspan=2>Amount Chargeable (In Words)</td><td colspan=17 align=right>E. & O.E</td></tr>";
$tt= str_replace(',','',number_format($tp,2));

print "<tr><td colspan=4>".word($tt)." Only</td><td colspan=6>for PSN CONSTRUCTION EQUIPMENTS P LTD</tr>";
print "<tr><td colspan=9 align=center>(Goods once sold will not be taken back)</td></tr>";
print "<tr><td colspan=9 align=right>Authorised Signatory</td></tr>";
log_entry($brcode,$user,$REMOTE_ADDR,"Print spareinvoice:$invno , inv type: $invtype");
?>
</table>

