<link href="../css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>
<body >
<?
session_start();

if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
?>
<title>Spare Transfer Out </title>
<center>
<h3>SPARE TRANSFER IN</H3>
</CENTER>

<?
$res=mysqli_query($db,"select max(tr_no) from sparetransin where brcode='$brcode'");
$prowr=mysqli_fetch_row($res);
$t=($prowr[0]+1);


 $sql="select a.brname,a.brcode from productiondb.branch a,productiondb.sparetransout b where b.brcode=a.brcode and b.received='N' and to_branch='$brcode' group by b.brcode";

 $re=mysqli_query($db,$sql) or die('err'.mysqli_error());
 if(mysqli_num_rows($re)>0)
 {
  while($row=mysqli_fetch_array($re))
  {
    print "<center><Fieldset> <legend> Transfer in from $row[0]</legend>";
   $ssq="select distinct tr_no from productiondb.sparetransout where brcode='$row[1]' and to_branch='$brcode' and received='N' order by tr_no";
   $res=mysqli_query($db,$ssq)or die(mysqli_error());
$cnt=0;
    while($row1=mysqli_fetch_array($res))
    {
    print "<br>\n<form action='svtransin.php'>\n<input type=hidden name='frmbr' value='$row[1]'>";
    print "\n<table border=1 width=100%>";

       $s="select * from  productiondb.sparetransout where tr_no ='$row1[0]' and brcode='$row[1]' and 
       to_branch='$brcode' and received='N'";

if($user=='superuser')
{

     print "\n<th colspan=15><h3>Transfer No : <input type=text name='tr_no' value='$row1[0]' size=5 >Transfer In No : <input type=text name='tr_no2' value='$t' size=5 ></th>";
 }
else
{

     print "\n<th colspan=15><h3>Transfer No : <input type=text name='tr_no' value='$row1[0]' size=5 readonly></th>";
 }
 

  ?>
     <tr><td colspan=10>
        <table>
         <tr><td>Date</td><td>: dd <input type=text name='d' value='<?print date("d")?>' size=2>
	 mm <input type=text name='m' value='<?print date("m")?>' size=2>
	 yy <input type=text name='y' value='<?print date("Y")?>' size=4></td>
</tr>
<?
if($level==5)
{
?>
<tr><td>
Entry Date </td><td>: dd <input type=text name='d1' value='<?print date("d")?>' size=2>
	 mm <input type=text name='m1' value='<?print date("m")?>' size=2>
	 yy <input type=text name='y1' value='<?print date("Y")?>' size=4>
</tr></td>

<?
}
else
{?>
<tr><td>
Entry Date </td><td>: dd <input type=text name='d1'  value='<?print date("d")?>' size=2>
	 mm <input type=text name='m1'   value='<?print date("m")?>' size=2>
	 yy <input type=text name='y1'   value='<?print date("Y")?>' size=4>
</tr></td>
<?
}
?>
</table>
<?
	print "<tr><th>No<th>Trans Date <th>Part Code <th>Part Name <th>P ord <br>No. <th>Qty<th>Rate<th>Total";
$tot=0;
$qty=0;
      $res2=mysqli_query($db,$s)or die(mysqli_error());
     $i=1;
      while($sparerow=mysqli_fetch_array($res2))
     {
$sub=$sparerow[qty]*$sparerow[amount];
$qty+=$sparerow[qty];
$tot+=$sub;

      print "\n<tr><td>".$i++."</td><td>$sparerow[trdate]</td><td>$sparerow[3]</td>";
      print "\n<td>$sparerow[4]</td><td><center>$sparerow[pord_no]</td>";
      print "\n<td align=right>".($sparerow[qty])."</td>";
      print "\n<td align=right>".($sparerow[amount])."</td>";
      print "\n<td align=right>".($sub)."</td></tr>";

     }
	print "<tr><th colspan=5><th>$qty<th><th>$tot<th></th></tr>";

  if($cnt!=1)
{
	print "<tr><th colspan=10><input type=submit value='Accept Transfer'> <input type=button value='Cancel' onClick=document.location='../blank.html'></th></tr>";
}
$cnt=1;
   print "\n</table>\n </form>\n";
    }
 print "</fieldset>\n<br>&nbsp;";

 }
}
?>
