<html>
<head>
<title>
Parent Window
</title>

</head>
<body>
<?php
include("connect.php");
$poNo = $_GET['po'];
$result2 = mysql_query("SELECT * FROM purchaseorder WHERE poNo = '$poNo'");

$row2 = mysql_fetch_array($result2);

$supID = $row2['supID'];
$result3 = mysql_query("SELECT * FROM supplier WHERE supID = '$supID'");

$row3 = mysql_fetch_array($result3);

echo "<fieldset style='width:100%'>";
echo "<legend>Purchase Order - $poNo</legend>";
echo "<br/>";
echo "<table width='100%' border='0'>";
echo "<tr>";
echo "<td width='15%'><b>Supplier: </b></td>";
echo "<td colspan='5'>$row3[supName]</td>";

echo "<td width='15%'><b>Purchase Order ID: </b></td>";
echo "<td width='25%'>$poNo</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Address: </b></td>";
echo "<td colspan='5'>$row3[supAddress]</td>";

echo "<td><b>Date: </b></td>";
echo "<td>".$row2["poDate"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Contact No: </b></td>";
echo "<td colspan='5'>".$row3["supPhone"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Email: </b></td>";
echo "<td colspan='5'>".$row3["supEmail"]."</td>";
echo "</tr>";

echo "</table>";
?>

<br/>

<table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr>
<form method="post" name="form" action="addrinv.php">
<a href="JavaScript:void(0);" NAME="My Window Name" title="My title here"
onclick="window.open('child.php?po=<?php print($poNo)?>')";><img src="Picture/add.gif" width="35" height="35" alt="Select Item">Select Item</a>
</form>
</td></tr> </table>

<div id="bookmenu">
<?php
include("connect.php");
$result4 = mysql_query("SELECT * FROM poitem WHERE poNo = '$poNo'");


$num_results = $result4->num_rows;

echo "<p>Number of Book(s) : ".$num_results."</p>";

echo "<form name='poform' method='post' action='updatestock.php'>";
echo "<table border='1' cellspacing='0' cellpadding='5' bordercolor='white' width='100%' align=''>";
echo "<tr bgcolor='black' style='color:white'>";
echo "<th width='10%'>No</th>";
echo "<th width='15%'>ISBN</th>";
echo "<th width='25%'>Description</th>";
echo "<th width='15%'>Unit Price</th>";
echo "<th width='10%'>Quantity</th>";
echo "<th width='15%'>Total</th>";
echo "<th width='10%'>Delete</th>";
echo "</tr>";

for ($i=0; $i <$num_results; $i++)
{
	$total = 0;
	$totalq = 0;
	
	$row4 = mysql_fetch_array($result4);
	echo "<tr>";
	echo "<td>".($i+1)."</td>";
	echo "<td><input type='hidden' name='ISBN".$i."' value='$row4[poItem]'>".$row4['poItem']."</td>";
	
	$ISBN = $row4['poItem'];
	$result5 = mysql_query("SELECT itemName FROM item WHERE ISBN = '$ISBN'");
	
	$row5 = mysql_fetch_array($result5);
	
	echo "<td>".$row5['itemName']."</td>";
	echo "<td>RM <input type='text' name='price{$i}' size='10' value='0' onchange='multiply(quantity{$i}.value, price{$i}.value, subtotal{$i}, total, subtotal{$i}.value, total.value, qtotal, qtotal.value, oldquantity{$i}, oldquantity{$i}.value);'></td>";
	echo "<td><input type='text' name='quantity{$i}' size='10' value='0' onchange='multiply(quantity{$i}.value, price{$i}.value, subtotal{$i}, total, subtotal{$i}.value, total.value, qtotal, qtotal.value, oldquantity{$i}, oldquantity{$i}.value);'></td>";
	echo "<td>RM <input type='hidden' name='oldquantity{$i}' value='0'><input type='text' name='subtotal{$i}' value='0.00' size='10' onblur='plus(subtotal{$i}.value,total,hiddentotal{$i},total.value);' readonly></td>";
	?>
	<script language="javascript" type="text/javascript">
	function multiply(q,p,s,t,l,v,y,a,h,x){
	
	var c = s;
	c.value=((q*p).toFixed(2));
	
	var d = t;
	d.value = ((v-l+(q*p)).toFixed(2));
	
	var e = y;
	e.value = parseInt(a)+parseInt(q)-parseInt(x);
	
	var f = h;
	f.value = q;
	}
	</script>
	
	<script language="javascript" type="text/javascript">
	function plus(l,t,h,v){
	var a = t;
	a.value=v-h+l;
	alert(a);
	}
	</script>
	<?php
	echo "<td><a href='removeupdate.php?ISBN=$ISBN&poNo=".$poNo."'><img src='Picture/delete.gif' width='25' height='25' alt='Delete'></td>";
	echo "</tr>";
}


if($num_results!=0){
echo "<tr>";
	echo "<th colspan='4'>Total</th>";
	echo "<th><input type='text' name='qtotal' size='10' value='0' readonly></th>";
	echo "<th colspan='2' align='left'>RM ";
	echo "<input type='text' name='total' size='10' value='0.00' readonly>";
	echo "</th>";
echo "</tr>";	

echo "<tr>";
echo "<td colspan='7'><center><input type='hidden' name='counter' value='$i'><input type='hidden' name='poNo' value='$poNo'><input type='submit' name='Submit' value='Submit'></center></td>";
echo "</tr>";
}else{
echo "<tr>";
echo "<td colspan='7'><center>Click Select Item button to choose item</center></td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";

?>
</div>
</body>
</html>