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


$staffID=$_GET['staffID'];

if($_SESSION['staff']!= null)
{
?>
	
<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>
</center>
<center>
<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset style="margin:0 5 0 0">
<legend><img src="Picture/bill.gif" width="30" height="30">Manage Bill</legend>
<table>
<tr>
<td valign="top">
<a href="onlineorderlist.php"><img src="Picture/onlineorder.gif" width="30" height="30" alt="manage online order"><a href="onlineorderlist.php">Online Order</a><br/>
<br/>
<a href="salesorder.php"><img src="Picture/salesorder.gif" width="30" height="30" alt="manage sales order"><a href="salesorder.php">Sales Order</a><br/>
<br/>
<a href="deliveryorderlist.php"><img src="Picture/do.gif" width="30" height="30" alt="manage delivery order"><a href="deliveryorderlist.php">Delivery Order</a><br/>
<br/>
<a href="invlist.php"><img src="Picture/invoice.gif" width="30" height="30" alt="manage invoice"><a href="invlist.php">invoice</a>
</td>
</tr>
</table>
</fieldset>
</td>
<td width="75%">

<?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 = mysql_num_rows($result2);

echo "<div id='bill'>";
echo "<h3>Sales Order View - $soNo</h3>";
echo "<form name='salesorderform' method='post' action='salesorderedit.php'>";

echo "<fieldset style='width:90%'>";
echo "<legend>Sales Order - $soNo</legend>";
echo "<br/>";
echo "<table width='100%' border='0'>";
echo "<tr>";
echo "<td width='15%'><b>Buyer Name: </b></td>";
echo "<td colspan='5'>$row[custName]</td>";

echo "<td width='15%'><b>Sales Order ID: </b></td>";
echo "<td width='25%'><input type='hidden' name='soNo' value='$row[soNo]'>$row[soNo]</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Address: </b></td>";
echo "<td colspan='5'>$row[soAddress],<br/>$row[soCode], $row[soCity], $row[soState]</td>";

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

echo "<tr>";
echo "<td><b>Contact No: </b></td>";
echo "<td colspan='2'>".$row["soTel"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Email: </b></td>";
echo "<td colspan='2'>".$row["soEmail"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><b>Paying Method: </b></td>";
echo "<td colspan='6'>".$row["soPay"]."</td>";
echo "</tr>";

echo "</table>";

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


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

echo "<div id='main2'>";
echo "<tr>";
echo "<th colspan='6'><center>Sales Order Item List</center></th>";
echo "</tr>";

echo "<tr>";
echo "<th>No</th>";
echo "<th>ISBN</th>";
echo "<th>Item Description</th>";
echo "<th>Quantity</th>";
echo "<th>Price</th>";
echo "<th>Subtotal</th>";
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'>";
	echo "<th colspan='3'>Total</th>";
	echo "<th>";
	echo "<center>";
	printf($soquantity);
	echo "</center>";
	echo "</th>";
	echo "<td></td>";
	echo "<th>RM";
	printf("%10.2f",$total);
	echo "</th>";
	echo "</tr>";

echo "<tr bgcolor='gray'>";
echo "<th colspan='3'>Shipping Method</th>";
echo "<th>";
echo "<center>";
echo $row["soShip"];
echo "</center>";
echo "</th>";

$shipType =  $row["soShip"];

$result3 = mysql_query("SELECT * FROM ship WHERE shipType = '$shipType'");


$row3 = mysql_fetch_array($result3);

echo "<td>";
echo "</td>";
echo "<th>RM ";
printf("%10.2f",$row3["shipCost"]);
echo "</th>";
echo "</tr>";

echo "<tr bgcolor='gray'>";
echo "<th colspan='3'>Grandtotal</th>";
echo "<th>";
echo "<center>";
printf($soquantity);
echo "</center>";
echo "</th>";
echo "<td>";
echo "</td>";
echo "<th>RM ";
$ship = $row3["shipCost"];
$grandtotal = $total + $ship;
	
printf("%10.2f",$grandtotal);
echo "</th>";
echo "</tr>";
	
echo "<tr>";
	echo "<input type='hidden' name='soNo' value='".$row["soNo"]."'/>";
	echo "<td colspan='6' align='center'>	
	<input type='submit' name='Submit' value='Delivery Order'>";
	//<input type='submit' name='Edit' value='Edit Order'>
	echo "<input type='submit' name='Delete' value='Delete'>
	<input type='submit' name='Back' value='Back'>
	<input type='submit' name='PrintPreview' value='PrintPreview'>";
	echo "</tr>";
echo "</table>";
echo "</fieldset>";
echo "</form>";
?>

</td>
</tr>
</table>
</div>
</center>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>
<hr/>

<center>
<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved.
<br/>
Website:<a href="../bookstore" target="_blank">www.dailybook.com.my
</div>
</center>

</body>
</html>