<?
include_once('includes/top.php');
$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");
?>
<title>Spare Transfer In</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
.right{text-align:right};
</style>
<center>
<h3>SPARE TRANSFER IN</H3>
</CENTER>

<?
 $sql="select a.brname,a.brcode from branch a,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($db));
 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 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($db));
$cnt=0;
    while($row1=mysqli_fetch_array($res))
    {
    print "<br>\n<form action='svtransin.php' method='POST'>\n<input type=hidden name='frmbr' value='$row[1]'>";
    print "\n<table border=1 width=100%>";

       $s="select * from  sparetransout where tr_no ='$row1[0]' and brcode='$row[1]' and 
       to_branch='$brcode' and received='N'";
     print "\n<th colspan=15><h3>Transfer No : <input type=text name='tr_no' value='$row1[0]' size=5 readonly>SAP Ref No.<input type=text name='refno' value='$row1[0]' readonly size=30></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' readonly value='<?print date("d")?>' size=2>
	 mm <input type=text name='m1'  readonly value='<?print date("m")?>' size=2>
	 yy <input type=text name='y1'  readonly 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";

      $res2=mysqli_query($db,$s)or die(mysqli_error($db));
     $i=1;
      while($sparerow=mysqli_fetch_array($res2))
     {
      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]+$sparerow[telcqty])."</td><td><center>$sparerow[saprefno]</td></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;";

 }
}
?>