<?
 session_start();
 $brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.php'; </script>";
 return;
}
 include("../opendb.php");
 include ("../test.php");
 $tr_no=
 $tr_no=$_REQUEST['tr_no'];
 $re=mysql_query("select * from sparetransout where tr_no='$tr_no' and brcode='$brcode' order by partcode");
 //$sql="select * from sparetransout where tr_no='$tr_no' and brcode='$brcode' order by partcode";
 //echo $sql;
 
 $rr=mysql_fetch_array($re);
 if(mysql_num_rows($re)<=0)
 {
  print "<center> <font color=red>Record does not exist";
  return;
 }
 $brre=mysql_query("select * from branch where brcode='$rr[to_branch]'")or die('err2'.mysql_error());
 $brr=mysql_fetch_array($brre)or die('err3'.mysql_error());

 $brre1=mysql_query("select * from branch where brcode='$brcode'")or die('err2'.mysql_error());
 $brr1=mysql_fetch_array($brre1)or die('err3'.mysql_error());

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

<TABLE width=100% border=0>
<tr><td colspan=2 align=center>
GSTIN <?print $brr1[tin]?><br>
<b>NIRMALA AUTOMOBILES (P) Ltd</b><br>
<?print $brr1[braddr]?><br> <?print $brr1[brcity]?><br><?print $brr1[brstate]?><br>
<u>PH :<?print $brr1[brphone]?></u>
</td></tr>
<tr><td>Ph:09744213900</td><td align=right>Email :sumesh.napl@gmail.com Website:www.kubota.com
<br>
<TR><TD><br>Stock Transfer No: 
<?
if($brcode=="HUBHOS")
{
	print '[HOS]';
}
elseif($brcode=="HUBCHI")
{
	print '[CHI]';
}
elseif($brcode=="HUBEKA")
{
	print '[IKL]';
}
else
{
print '['.substr($brcode,0,3).']';
}
print $tr_no;
?>
</td><td align=right>Date: <?print datetohtml($rr[entrydate])?><br></td></tr>

<tr><td colspan=2 align=center><B>Stock Transfer </b><br></td></tr>
<tr><td></td>
<td> Customer:<b>NIRMALA AUTOMOBILES P LTD  <?print $brr[brname]?> BRANCH </b><br>
<blockquote><?print $brr[braddr]?><br> <?print $brr[brcity]?><br><?print $brr[brstate]?><br>
Phone:<?print $brr[brphone]?><br>
GSTIN: <?print $brr[tin]?><br>
CST: <?print $brr[cstno]?>
</td></tr>
</table>
<br>
<table border=1 width=90% cellpadding=2>
<th> No <th>HSN Code <th>Part Code<th>Description of Goods <th>Quantity <th>Rate <th>Amount
<?
$t=0;
$amt=0;
$i=1;
 $re1=mysql_query("select * from sparetransout where tr_no='$tr_no' and brcode='$brcode' and to_branch='$rr[to_branch]' order by partcode");
 while($row=mysql_fetch_array($re1))
{
  $loc=getLocation($row[partcode],$brcode);
  
$pname=getpartname($row[partcode]);
  print "<tr><td>".$i++."</td><td>$loc</td><td>$row[partcode]</td><td>$pname</td><td align=right>".($row[qty]+$row[telcqty])."</td><td align=right>".putComa($row[amount])."</td>";
 $qty=($row[qty]+$row[telcqty]);
  print "<td align=right>".putComa($row[amount]*$qty)."</tr>";
  $t+=$qty;
  $aamount=$row[amount]*$qty;
  $amt+=$aamount;
}
print "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align=right><b>Total </td><td align=right><b>$t Nos</td><td>&nbsp;</td><td align=right><b>".putComa($amt)."</td></tr>";
?>
</table>
</center><br>
Amount chargeable (in words)
Rs <?print word($amt)?> ONLY
<?
?>
<table width=100%>
<tr><td>Company's GSTIN : <?print $brr1[tin]?></td></tr>
<tr><td>Company's CST No :<?print $brr1[cstno]?></td></tr>
<tr><td colspan=2 align=right>Print Date :<?print date("d-m-Y g:i:s A")?><br>by <?print $user?>
<tr><td>Declaration</td><td align=right>for NIRMALA AUTOMOBILES P LTD</td></tr>
<tr><td colspan=2> We declare that this invoice shows the actual price of the goods described and <br>that all particulars are true and correct</td> </tr>
<tr><td colspan=2 align=right>Authorised Signatory</td></tr>

<?
 function getLocation($cde,$br)
 {
  //$sql="select location from partmaster where itemcode='$cde' and brcode='$br'";
  $sql="select location from partmaster where partcode='$cde'";
  $locre=mysql_query($sql)or die(mysql_error());
  $locrow=mysql_fetch_array($locre);
  return $locrow[0];
 }
?>

