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

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

$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>Received Invoice - $rinvNo</legend>";
echo "<br/>";
echo "<table width='100%' border='0'>";
echo "<tr>";
echo "<td width='15%'><b>Supplier: </b></td>";
echo "<td colspan='5'>$row2[supName]</td>";

echo "<td width='15%'><b>Ref PO: </b></td>";
echo "<td width='25%'>$row2[poNo0] ";
echo "".$row2['poNo1']." ";
echo "".$row2['poNo2']."";
echo "</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["rinvDate"]."</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/>
<div id="bookmenu">
<?php
include("connect.php");
$result4 = mysql_query("SELECT * FROM receivedinvitem WHERE invNo = '$rinvNo' ORDER BY poNo");


$num_results = mysql_num_rows($result4);

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

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

for ($i=0; $i <$num_results; $i++)
{
	
	$row4 = mysql_fetch_array($result4);
	echo "<tr>";
	echo "<td>".($i+1)."</td>";
	echo "<td><input type='hidden' name='ISBN".$i."' value='$row4[ISBN]'>".$row4['ISBN']."</td>";
	
	$ISBN = $row4['ISBN'];
	$result5 = mysql_query("SELECT itemName FROM item WHERE ISBN = '$ISBN'");
	
	$row5 = mysql_fetch_array($result5);
	
	$q = $row4['quantity'];
	
	echo "<td>".$row5['itemName']."</td>";
	echo "<td><center>".$row4['poNo']."</center></td>";
	echo "<td><center>".$row4['quantity']."</center></td>";
	echo "<td><input type='text' name='quantity{$i}' size='10' value='$row4[quantity]' onchange='multiply(quantity{$i}.value, qtotal, qtotal.value, oldquantity{$i}, oldquantity{$i}.value);'></td>";
	echo "<input type='hidden' name='oldquantity{$i}' value='$row4[quantity]'>";
	?>
	<script language="javascript" type="text/javascript">
	<!--quantity{$i}.value, qtotal, qtotal.value, oldquantity{$i}, oldquantity{$i}.value!-->
	function multiply(q,y,z,h,x){
	
	var e = y;
	e.value = parseInt(z)+parseInt(q)-parseInt(x);
	
	var f = h;
	f.value = q;
	}
	</script>
	
	<?php
	echo "<td><center><a href='removerestock.php?ISBN=$ISBN&&invNo=$rinvNo&&poNo=$poNo&&q=$q'><img src='Picture/delete.gif' width='25' height='25' alt='Delete'></a></center></td>";
	echo "</tr>";
}


if($num_results!=0){
echo "<tr>";
	echo "<th colspan='5'>Total</th>";
	echo "<th><input type='text' name='qtotal' size='10' value='$row2[qtotal]' readonly></th>";
	echo "<th colspan='1' align='left'>";
	echo "</th>";
echo "</tr>";	

echo "<tr>";
echo "<td colspan='7'><center><input type='hidden' name='counter' value='$i'><input type='hidden' name='invNo' value='$rinvNo'><input type='submit' name='Submit' value='Submit'><input type='submit' name='Cancel' value='Cancel'></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>