<?
 session_start();
 include("../opendb.php");
 include ("../test.php");
if($show)
{
$dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;

 $re=mysqli_query($db,"select distinct(tr_no),to_branch,entrydate from sparetransout where brcode='$brcode' and trdate>='$dfrom' and trdate<='$dto' order by tr_no");
//$re=mysqli_query($db,"select distinct(invno),invtype,entrydate,customer,addr,tin from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' order by invno")or die(mysqli_error());

 
while($row1=mysqli_fetch_array($re))
 {

 $brre=mysqli_query($db,"select * from branch where brcode='$row1[to_branch]'")or die('err2'.mysqli_error());
 $brr=mysqli_fetch_array($brre)or die('err3'.mysqli_error());

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

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

<TABLE width=100% border=0>
<TR><TD>Stock Transfer No: 
<?
print '['.substr($brcode,0,3).']';
print $row1[tr_no];
?>

</td><td >Date: <?print datetohtml($row1[entrydate])?> <?print $brr1[brcity]?></td>
<tr><td></td>
<td> Customer:<b>PSN CONSTRUCTION EQUIPMENT PVT LTD-  <?print $brr[brname]?> BRANCH </b><br>

</td></tr>
</table>
<br>
<table border=1 width=90% cellpadding=2>
<th> No <th>Location <th>Part Code<th>Description of Goods <th>Quantity <th>Rate <th>Amount
<?
$t=0;
$amt=0;
$i=1;
 $re1=mysqli_query($db,"select * from sparetransout where tr_no='$row1[tr_no]' and brcode='$brcode' and trdate>='$dfrom' and trdate<='$dto' order by partcode");
 while($row=mysqli_fetch_array($re1))
{
  $loc=getLocation($row[partcode],$brcode);
  print "<tr><td>".$i++."</td><td>$loc</td><td>$row[partcode]</td><td>$row[partname]</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>

<?
?>
<table width=100%>

<?
}
}

 function getLocation($cde,$br)
 {
  $sql="select location from sparelocmast where itemcode='$cde' and brcode='$br'";
  $locre=mysqli_query($db,$sql)or die(mysqli_error());
  $locrow=mysqli_fetch_array($locre);
  return $locrow[0];
 }
?>

<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
	td{font-size:13}
.right{text-align:right};
</style>

<center>
<h3>SPARE TRANSFER (SHORT) REPORT -2</H3>
<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>
<tr><td>Date from </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>

<tr><td align=right>to </td><td>dd <input type=text name='d2' size=2 value='<?print date("d")?>'>
mm <input type=text name='m2' size=2 value='<?print date("m")?>'>
yy <input type=text name='y2' size=4 value='<?print date("Y")?>'>
</td></tr>
<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></td></tr>
</table>
</td></tr>
</table>
</form>




