<?
 session_start();
 $brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
 include("../opendb.php");
 include ("../test.php");
 $invno=$_REQUEST['invno'];
 $sql="select * from item_purchase_ret where retno='$invno'  and brcode='$brcode'";
 
 $re=mysqli_query($db,$sql);
 $rr=mysqli_fetch_array($re)or die('Err'.mysqli_error($db));
 if(mysqli_num_rows($re)<=0)
 {
  print "<center> <font color=red>Record does not exist";
  return;
 }
 $brre=mysqli_query($db,"select * from branch where brcode='$rr[brcode]'")or die('err2'.mysqli_error($db));
 $brr=mysqli_fetch_array($brre)or die('err3'.mysqli_error($db));

 $brre1=mysqli_query($db,"select * from branch where brcode='$brcode'")or die('err2'.mysqli_error($db));
 $brr1=mysqli_fetch_array($brre1)or die('err3'.mysqli_error($db));


$reps=mysqli_query($db,"select * from sup_master where supname='$rr[suplier]' ");
$prows=mysqli_fetch_array($reps);

?>
<center>
<style>
th,td,body{font-family:'arial narrow';letter-spacing:1;font-size:16}
</style>
<table border=1 width=90%>
<TABLE width=90% border=0>

<tr><td colspan=2 align=center><b>PSN AUTOMOTIVE MARKETING P LTD </b><BR>
<?print $brr1[braddr]?><br> <?print $brr1[brcity]?><br><?print $brr1[brstate]?><br>
<u>GSTIN :<?print $brr1[cstno]?></u><br>
<u>PH :<?print $brr1[brphone]?></u>
</td></tr></table><table border=1 width=90%>
<TR>
<td colspan=1><left> Party: <b><?print $rr[suplier]?> 
<BR>
<?print $prows[addr1]?><br> <?print $prows[city]?><br><?print $prows[stat]?><br>GSTIN :<?print $prows[cst]?>
</td>    
    <TD><b>Purchase Ret No: 
<?
print $invno;
?>

<br><b>Date: <?print datetohtml($rr[entrydate])?>
<br><b>
Purchase Bill No: <?print $rr[pbillno]?>
<br><b>Ref: <?print $rr[ref]?></td></tr>
<tr><td colspan=2 align=center><B>Purchase Return (Debit Note)</b><br></td></tr>
<tr>
</tr>
</table>
<br>
<table border=1 width=90% cellpadding=2>
<th> No <th>Partcode <th>Description of Goods <th>HSN/SAC <th>Quantity <th>Price <th>Dis<th>Aprice <th>Tax<th>Tax.Amt<th>Total
<?
$t=0;
$amt=0;
$i=1;
 $re1=mysqli_query($db,"select * from item_purchase_ret where retno='$invno'  and brcode='$brcode'");
 while($row=mysqli_fetch_array($re1))
{
  $hsn=gethsn($row[partcode]);
  print "<tr><td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td><td align=center>$hsn</td><td align=right>".($row[retqty])."</td><td align=right>$row[price]</td><td  align=right>$row[disc]</td><td align=right>$row[aprice]</td><td align=right>$row[tax]</td><td align=right>$row[taxamt]</td><td align=right>$row[tot]</td>";
 $t+=$row[retqty];
  $pt+=$row[price];
 $apt+=$row[aprice];
 $tata+=$row[taxamt];
 $tota+=$row[tot];
 
}
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 align=right><b>$pt </td><td align=right><b>0</td><td align=right><b>$apt </td><td align=right><b></td><td align=right><b>$tata</td><td align=right><b>".round($tota,0)."</td></tr>";
$jtot=round($tota,0);
?>
</table></center><br><br>
<table><tr>
	<td align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><?echo       word(round($jtot))?>  ONLY</b>
	 </td></tr></table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<table border=0 style='border:0px solid white; ' align=right width=90%>
	<tr><td  align=right></br>

			For PSN AUTOMOTIVE MARKETING P. LTD  <BR> <BR><BR> AUTHORISED SIGNATORY</td><td style='border:0px solid white; text-align:right;'>
	</td></tr></table></table>
<?
 function getLocation($cde,$br)
 {
  $sql="select location from sparelocmast where itemcode='$cde' and brcode='$br'";
  $locre=mysqli_query($db,$sql)or die(mysqli_error($db));
  $locrow=mysqli_fetch_array($locre);
  return $locrow[0];
 }
?>

