<?
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");
?>
<title>Spare Transfer Out </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 trfrtype='agt' and to_branch='$brcode' and jvno > 0 group by b.brcode";
  
  //print $sql;
  $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,grno,grdate from sparetransout where brcode='$row[1]' and to_branch='$brcode' and trfrtype='agt' and received='N' and jvno > 0 order by tr_no";
    //print $ssq;
    $res=mysqli_query($db,$ssq)or die(mysqli_error($db));
    $cnt=0;
    while($row1=mysqli_fetch_array($res))
    {
        $dd=$row1[2];
		$ddd=explode('-',$dd);
        
    print "<br>\n<form action='svtransinagt.php'>\n<input type=hidden name='frmbr' value='$row[1]'>";
    print "\n<table border=1 width=100%>";
      $ss="select sum(qty*amount),sum(taxamt),sum(gramount) from  sparetransout where tr_no ='$row1[0]' and brcode='$row[1]' and trfrtype='agt' and to_branch='$brcode' and received='N' and jvno > 0";
      $ree=mysqli_query($db,$ss) or die('err'.mysqli_error($db));
      $rrr=mysqli_fetch_array($ree);

       $s="select * from  sparetransout where tr_no ='$row1[0]' and brcode='$row[1]' and to_branch='$brcode' and trfrtype='agt' and received='N' and jvno > 0";
       $bigrnamt=round($rrr[0],2);
     print "\n<th colspan=14><h3>Transfer No : <input type=text name='tr_no' value='$row1[0]' size=10 readonly>GRN No : <input type=text name='grr' value='$row1[1]' size=10 readonly>Amount: <input type=text name='amt' value='$bigrnamt' size=10 readonly>Tax Amount: <input type=text name='tamt' value='$rrr[1]' size=10 readonly>Pur.Reg Amount: <input type=text name='gramt' value='$rrr[2]' size=10 readonly></th>";
    ?>
     <tr><td colspan=10>
        <table>
         <tr><td>Date</td><td>: dd <input type=text name='d' readonly value='<?print $ddd[2] ?>' size=2>
	 mm <input type=text name='m' readonly value='<?print $ddd[1] ?>' size=2>
	 yy <input type=text name='y' readonly value='<?print $ddd[0]?>' size=4></td>
</tr>
<?
if($level==5)
{
?>
<tr><td>
Entry Date </td><td>: dd <input type=text name='d1' readonly value='<?print $ddd[2]?>' size=2>
	 mm <input type=text name='m1' readonly value='<?print $ddd[1]?>' size=2>
	 yy <input type=text name='y1' readonly value='<?print $ddd[0] ?>' size=4>
</tr></td>

<?
}
else
{?>
<tr><td>
Entry Date </td><td>: dd <input type=text name='d1' readonly value='<?print $ddd[2] ?>' size=2>
	 mm <input type=text name='m1'  readonly value='<?print $ddd[1]?>' size=2>
	 yy <input type=text name='y1'  readonly value='<?print $ddd[0]?>' 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[saprefno]</td>";
      print "\n<td align=right>".($sparerow['qty']+$sparerow['telcqty'])."</td></tr>";
     }
  if($cnt!=1)
{
	print "<tr><th colspan=10><input type=submit value='Accept Transfer'></th></tr>";
}
$cnt=1;
   print "\n</table>\n </form>\n";
    }
 print "</fieldset>\n<br>&nbsp;";

 }
}
?>
