<?php
session_start();
$username = $_SESSION['staff'];


$staffID=$_GET['staffID'];

if($_SESSION['staff']!= null)
{
?>
	
<html>
<head>
<title>Bookstore - Sales Order Management</title>
</head>
<body style="background:lightyellow">

<table width="100%">
<tr>
<td rowspan="2" align="center" valign="center" alt="天天书局" title="天天书局" ><img src="Logo.gif" width="110" height="110"></td>

<td width="25%"></td>
<td width="25%"></td>

<td>
<form method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8 >
<input type=hidden name=oe value=UTF-8 target="_blank">
<table bgcolor="#FFFFFF" target="_blank">
<tr>
<td>
<a href="http://www.google.com">
<img src="GoogleLogo.jpg" border="0" alt="Google" align="absmiddle" title="Google" >
</a>
<input type=text name=q size=25 maxlength=255 value="">
<input type=submit name=btnG value="Google Search">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

<?php
session_start();
$username = $_SESSION['staff'];
if($_SESSION['staff']!= null)
{
echo "<span style='color:black;font-weight:bold'>".$username."</span>";
echo "<a href='logout.php'>(Logout)</a>";
}else{
echo "<span style='color:black;font-weight:bold'>You haven't login.</span>";
echo "<a href='index.php'>(Login)</a>";
}
?>

<hr/>

<table align="right">
<tr>
<td><center>
<a href="index.php"><h4>Home Page</h4></a>
<a href="addbook.php"><h4>Add Book</h4></a>
<a href="addstaff.php"><h4>Add Staff</h4></a>
<a href="stafflist.php"><h4>Staff List</h4></a>
<a href="onlineorderlist.php"><h4>Online Order List</h4></a>
<a href="salesorder.php"><h4>Sales Order List</h4></a>
</center></td>
</tr>
</table>

<?php
include("connect.php");



$soNo=$_GET['soNo'];

$result = mysql_query("SELECT * FROM salesorder WHERE soNo = '$soNo'");

$row = mysql_fetch_array($result);

$result2 = mysql_query("SELECT * FROM soitem WHERE soNo = '$soNo'");

$num_results = $result2->num_rows;

echo "<form name='salesorderform' method='post' action='salesorderedit.php'>";

echo "<fieldset style='width:70%'>";
echo "<legend>Sales Order - $soNo</legend>";
echo "<br/>";
echo "<table width='100%' border='0'>";
echo "<tr>";
echo "<td width='15%'>Order ID: </td>";
echo "<td>$soNo</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Buyer Name: </td>";
echo "<td>".$row["custName"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Address: </td>";
echo "<td>".$row["soAddress"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Submit Date: </td>";
echo "<td>".$row["soDate"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Contact No: </td>";
echo "<td>".$row["soTel"]."</td>";
echo "</tr>";
echo "</table>";

echo "<br/><br/>";

echo "<table border='1' align='left' cellspacing='0' cellpadding='5' bordercolor='white' width='100%'>";

echo "<tr>";
echo "<td colspan='6' bgcolor='gray'>Order Item List</td>";
echo "</tr>";

echo "<tr bgcolor='gray' style='color:black'>";
echo "<td>No</td>";
echo "<td>ISBN</td>";
echo "<td>Item Description</td>";
echo "<td>Quantity</td>";
echo "<td>Price</td>";
echo "<td>Subtotal</td>";
echo "</tr>";

for($i=0; $i <$num_results; $i++)
{
	$row2 = mysql_fetch_array($result2);
	$soQ = $row2["soQuantity"]; 
	$soP = $row2["soPrice"];
	$subtotal = $soQ * $soP;
	$total = $total + $subtotal;
	
	$soquantity = $soquantity + $soQ;
	
	echo "<tr>";
	echo "<td>".($i + 1)."</td>";
	echo "<td>".$row2["soItem"]."</td>";
	echo "<td>";
	
	$result3 = mysql_query("SELECT itemName FROM item WHERE ISBN = $row2[soItem]";
	
	$row3 = mysql_fetch_array($result3);
	echo "$row3[itemName]";
	echo "</td>";
	echo "<td align='center'>".$row2["soQuantity"]."</td>";
	echo "<td align='center'>RM ";
	printf("%10.2f",$row2["soPrice"]);
	echo "</td>";
	echo "<td>RM";
	printf("%10.2f",$subtotal);
	echo "</td>";
	echo "</tr>";
}
echo "<tr bgcolor='gray' style='color:black'>";
	echo "<td colspan='3'>Total</td>";
	echo "<td align='center'>";
	printf($soquantity);
	echo "</td>";
	echo "<td></td>";
	echo "<td>RM";
	printf("%10.2f",$total);
	echo "</td>";
	echo "</tr>";

echo "<tr>";
	echo "<td colspan='6' align='center'>	
	<input type='submit' name='Submit' value='Submit Order'>
	<input type='submit' name='Back' value='Back'>";
	echo "</tr>";
echo "</table>";
echo "</fieldset>";
echo "</form>";
?>

</body>
</html>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>