<?
session_start();

include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	th{background-color:#6595A1;color:white}
.right{text-align:right}
</style>
<script>
 function valid()
 {
   if(confirm('Do you want to save?'))
    return true;
   else
    return false;
 }
function chkqty(x)
{
 var psnqtyele=x;
 var recqtyele='recqty'+x;
 pval=parseFloat(document.getElementById(psnqtyele).value);
 recval=parseFloat(document.getElementById(recqtyele).value);
 if(recval>pval)
  {
    alert('Invalid Quantity');
	document.getElementById(recqtyele).value=0;
  }
}
</script>

<center>
<BODY BGCOLOR='IVORY'>
<TABLE WIDTH=100%>
<TR><TD BGCOLOR='orange'><CENTER>
<h3 style="color:white">WARRANTY STOCK TRANSFER OUT (TELCON QUANTITY)</H3>
</TD></TR>
</TABLE>
<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[0]'>$br1[0]</option>";
}
?>
</select></td>
<td><input type=submit value='Show' name='show'></td></tr>
</table>
</form>
<HR>
<?
 $sq="select distinct warno,cust,msno,brcode,sum(psnqty),date from sparetrinwartel where frombr='$br' and brcode='$brcode' group by warno,brcode";

$res=mysqli_query($db,$sq)or die('Err1'.mysqli_eror());
if(mysqli_num_rows($res)>0)
{
while($ro=mysqli_fetch_array($res))
{
?>
<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>$br</font>";
//; [<a href='edsptrinwar.php?warno1=$ro[0]&br=$ro[brcode]' target='ed' style='color:blue'>Edit/View More</a>]" ?>
</legend>
<form action='svsparetroutwarTQ.php' onSubmit="return valid()">
<input type=hidden name='warno' value='<?print $ro[0]?>'> 
<input type=hidden name='frombr' value='<?print $br?>'> 
<input type=hidden name='msno' value='<?print $ro[msno]?>'> 
<input type=hidden name='cust' value='<?print $ro[cust]?>'>

<table border=0 width=100%>
<tr><td colspan=9 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')?>'>
 Trans date <?print datetohtml($ro[date])?></td></tr>
<tr><td colspan=2>STO No </td><td><?print $ro[stono]?></td></tr>
<th>No <th>Part Code <th>Part Name <th>Tel Qty <th>Out 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

<?
 $s1="select * from sparetrinwartel where warno='$ro[0]' and frombr='$br'";
 $res1=mysqli_query($db,$s1);
$i=1;
  while($row=mysqli_fetch_array($res1))
 {
$sq="select psnqty,sum(recqty) from sparetroutwartel where warno='$ro[0]' and frombr='$br' and partcode='$row[1]' group by partcode";

$inres=mysqli_query($db,$sq);//or die('Err:'.mysqli_error());
$inrow=mysqli_fetch_array($inres);

  if($inrow[1]<$inrow[0]||mysqli_num_rows($inres)<=0)
  {
   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 "\n<td align=right><input type=text readonly name='psnqty[]' id='$i' value='".($row[psnqty]-$inrow[1])."' size=4></td>";

print "\n<td align=right><input type=text name='recqty[]' id='recqty$i' value='0' size=4 onChange=chkqty($i);></td>";

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

 
print "<td><input type=text readonly name='amount[]' value='$row[amount]' size=8></td>";

   print "<td align=right>".datetohtml($row[date])."</td>";

   print "<td><center><input type=text name='stono[]' size=10 title='Enter for closing only' style={background-color:pink} value='$row[stono]'></td>";
   print "<td><center><input type=text name='preqno[]' size=10 value='$row[preqno]'></td>";
   print "<td><center><input type=text name='invno[]' size=10 value='$row[invno]'></td>";
   print "<td><center><input type=text name='servord[]' size=10 value='$row[servord]'></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 value='$row[stat]'></td>";
 }// end if
else
print "record not found";
}

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

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

