<?
session_start();
include ("../opendb.php");

session_register("warno1");
$warno1=$warno2;
?>
<script> 
 parent.main23.document.location='invtempwared.php'
</script>

<body bgcolor=ivory>

<BASE TARGET=main23>
<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>

<script>
var pna=[];
var qty=[];
var hand=[];
var price=[];
var disc=[];

function validqty()
{
if(parseFloat(document.f1.psnqty.value)<=0&&parseFloat(document.f1.telcqty.value)<=0)
{
alert('Insufficient Quantity');
document.f1.psnqty.value=0;
document.f1.psnqty.focus();
return;
}
}
function getname()
{
 if(document.f1.partcode.selectedIndex<=0)
 {
 document.f1.prtname.value="";
 document.f1.price.value="";
 document.f1.psnqty.value="0";
 document.f1.telcqty.value="0";
 }
 else{
 document.f1.psnqty.value="0";
 document.f1.telcqty.value="0";
 document.f1.prtname.value=pna[document.f1.partcode.selectedIndex];
 document.f1.price.value=price[document.f1.partcode.selectedIndex];
 }
}
function valid()
{
if(document.f1.price.value.length<=0||document.f1.price.value<=0)
{
alert('Invalid Price');
document.f1.price.value=0;
document.f1.price.focus();
return false;
}

 if(document.f1.partcode.selectedIndex<=0)
 {
  alert('Invalid Item code');
  return false;
 }
if(parseFloat(document.f1.psnqty.value)<=0&&parseFloat(document.f1.telcqty.value)<=0)
{
alert('Insufficient Quantity');
document.f1.psnqty.value=0;
document.f1.psnqty.focus();
return false;
}
if(parseFloat(document.f1.psnqty.value)<=0 && parseFloat(document.f1.telcqty.value)<=0)
{
alert('Invalid Quantity');
document.f1.psnqty.value=0;
document.f1.psnqty.focus();
return false;
}
/*
var x=document.getElementById("mselect")
 document.f1.partcode1.value=x.options[x.selectedIndex].text
x.remove(x.selectedIndex)
*/
}

function calcprice()
{
 var q=parseFloat(document.f1.psnqty.value); //+parseFloat(document.f1.telcqty.value);
 var pr=parseFloat(document.f1.price.value);
 var tot=q*pr;
 document.f1.totamt.value=tot;
}

</script>
<?
$tbl="spareinvwar".$brcode;
?>


<body bgcolor='ivory'>
<center>

<form name='f1' action='invtempwar.php' onSubmit='return valid()'>
<input type=hidden name='partcode1'>
<table cellspacing=4>
<th colspan=10><h3>WARRANTY SPARE TRANSFER EDIT - War No.<input type=text name='warno' value='<?print $warno1?>' size=5></h3></th>
<tr>
<td>Part Code</td><td><select name='partcode' id='mselect' onChange=getname();><option></option>
<?
$i=1;
$re=mysqli_query($db,"select * from partmaster");
while($row=mysqli_fetch_array($re))
{
 print "<option value='$row[0]'>$row[0]</option>";
 print "\n<script> pna[$i]='$row[partname]'; qty[$i]='$row[supqty]';</script>";
  $disres=mysqli_query($db,"select lstprice,discount from spareprmast where partcode='$row[0]' order by effectfrom desc");
   $disrow=mysqli_fetch_array($disres);
 print "<script>price[$i]='$disrow[0]'; </script>";

 $i++;
}
?>
</select></td><td>Part Name </td><td COLSPAN=3><input type=text readonly  name='prtname' size=30></td></tr>
<tr><td>PSN Qty</td><td><input type=text name='psnqty' size=6 onChange='calcprice()'>
Telcon Qty <input type=text name='telcqty' size=6 onChange='calcprice()' value='0'>
</td>
  <td>Price </td><td><input type=text readonly name='price' size=10>
Total Amount <input type=text name='totamt'  size=10 class=right>
</td>
<tr><td colspan=6 align=center bgcolor='steelblue'><input type=submit value='Add' name='add'>
<input type=button value='Cancel' onClick='javascript:parent.window.close()'>
</td></tr>
</table>
</form>
