<?
session_start();

include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	th{background-color:steelblue;color:white}
.right{text-align:right}
</style>
<script>
 function valid()
 {
   if(confirm('Do you want to save?'))
    return true;
   else
    return false;
 }
</script>

<center>
<h3>STOCK TRANSFER IN (WARRANTY)</H3>
<form action='<?print $PHP_SELF?>'>
<table>
<tr><td>Select Branch:</td><td>
<select name='br'>
<?
$brr=mysqli_query($db,"select brname,brcode from branch order by brname");
while($br1=mysqli_fetch_array($brr))
{
 print "<option value='$br1[1]'>$br1[0]</option>";
}
?>
</select></td>
<td><input type=submit value='Show' name='show'></td></tr>
</table>
</form>
<HR>
<?
if($show)
{
 $brres1=mysqli_query($db,"select brname from branch where brcode='$br'");
  $brrow1=mysqli_fetch_array($brres1);

$sql="select distinct(warno),cust,msno,brcode,cssno,notifno from warsparetransout where tobr='SER516' and brcode='$br' and warno not in (select warno from sparetrinwar where frombr='$brrow1[brname]')";


$res=mysqli_query($db,$sql)or die(mysqli_error());
if(mysqli_num_rows($res)>0)
{
while($ro=mysqli_fetch_array($res))
{
  $brres=mysqli_query($db,"select brname from branch where brcode='$ro[brcode]'");
  $brrow=mysqli_fetch_array($brres);
?>
<fieldset width=110%> <legend> Warranty No : <b><?print $ro[0]?> </b>
Customer : <font color=blue><?print $ro[cust]."</font> MSNO :<font color=blue>".$ro[msno]."</font> From Branch: <font color=red>$brrow[0]</font> [<a href='edsptrinwar.php?warno1=$ro[0]&br=$ro[brcode]' target='ed' style='color:blue'>Edit/View More</a>]" ?></legend>
<form action='svsparetrinwar.php' onSubmit="return valid()">
<input type=hidden name='warno' value='<?print $ro[0]?>'> 
<input type=hidden name='frombr' value='<?print $brrow[0]?>'> 
<input type=hidden name='msno' value='<?print $ro[msno]?>'> 
<input type=hidden name='cust' value='<?print $ro[cust]?>'>
<input type=hidden name='brcde' value='<?print $ro[brcode]?>'>

<table border=0 width=100%>
<tr><td colspan=5 bgcolor=yellow>Entrydate dd <input type=text name=ed size=2 value='<?print date('d')?>'>
mm <input type=text name=em size=2 value='<?print date('m')?>'>
yy <input type=text name=ey size=4 value='<?print date('Y')?>'>
</td></tr>
<tr><td colspan=2>CSS No </td><td><?print $ro[cssno]?></td></tr>
<tr><td colspan=2>Notif No </td><td><?print $ro[notifno]?></td></tr>
<th>No <th>Part Code <th>Part Name <th>PSN Qty <th>Tel Qty <th>Rec Qty<th>Acc Qty<th>Price <th> Date
<th><font color='dark brown'><b>*</b></font> STO No.
<th><font color='dark brown'><b>*</b></font> Preq No. <th>Inv No. <th>Serv Ord<th>Inv Date <th>Status

<?
 $res1=mysqli_query($db,"select * from warsparetransout where warno='$ro[0]' and brcode='$ro[brcode]'");
$i=1;
  while($row=mysqli_fetch_array($res1))
 {
  print "\n<tr><td>".$i++."</td><td><input type=text name='partcode[]' value='$row[1]' size=10>";
  print "</td><td><input type=text name='partname[]' value='$row[2]'></td>";
  print "<td align=right><input type=text readonly name='psnqty[]' value='$row[psnqty]' size=4></td>";
   print "<td align=right>$row[telcqty]</td>";
print "<td align=right><input type=text readonly name='recqty[]' value='$row[psnqty]' size=4></td>";

  $reqres=mysqli_query($db,"select sum(recqty) from sparetrinwar where warno='$ro[0]' and partcode='$row[partcode]' and frombr='$brrow[0]'")or die(mysqli_error());
   $reqrow=mysqli_fetch_row($reqres);
   if($reqrow[0]>0)
     $acc=$reqrow[0];
   else
     $acc=0;
print "<td align=right><b>$acc</td>";

 
print "<td align=right>$row[price]</td>";

   print "<td align=right>".datetohtml($row[date])."</td>";
if(strlen($row[stono])>0)
{   print "<td><center><input type=text name='stono[]' size=10 value='$row[stono]'title='Enter for closing only' style={background-color:pink}></td>";
}
else
{   print "<td><center><input type=text name='stono[]' size=10 value='0'title='Enter for closing only' style={background-color:pink}></td>";
}

   print "<td><center><input type=text name='preqno[]' size=10></td>";
   print "<td><center><input type=text name='invno[]' size=10></td>";
   print "<td><center><input type=text name='servord[]' size=10></td>";

   print "<td><center>dmy<input type=text name='invdate[]' size=10 value='".date("d-m-Y")."'</td>";
   print "<td><center><input type=text name='stat[]' size=10></td>";

}
  print "<tr><th colspan=12> <input type=submit value='Save this warranty data'></th>";

print "</table></form> </fieldset><br>";
}
}
}
?>

