<?php
if($_POST["Back"] == "Back")
{
$doNo=$_POST['doNo'];	
		echo "<script language='javascript'>window.location='deliveryorderview.php?doNo=$doNo'</script>"; 
}
?>
<html>

<title>Print Preview of Delivery Order</title>

<head>

<!--include css file-->
<link href="salaryprint.css" rel="stylesheet" type="text/css"/>
<link href="bookstaffprint.css" rel="stylesheet" type="text/css" media="print, projection" />

<!--Hide Function When Print-->
<style type="text/css" media="print, projection">
.printnone {display:none}
</style>

</head>

<body>

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



$doNo=$_GET['doNo'];

$result = mysql_query("SELECT * FROM deliveryorder WHERE doNo = '$doNo'");

$row = mysql_fetch_array($result);

$result2 = mysql_query("SELECT * FROM doitem WHERE doNo = '$doNo'");

$num_results = $result2->num_rows;


echo "<div id='bill'>";
echo "<center><h2>Daily Bookstore<br/></h2></center>";
echo "<center><h6>8 Jalan 7/118B, Taman Bukit Indah, 81200 Johor, Malaysia. Tel: 07-556 8960 Fax: 07-556 8970 Email: dailybook@hotmail.com</h6></center>";
echo "<center><p><b>DELIVERY ORDER</b></center></p>";
echo "<form name='deliveryorderform' method='post'>";

echo "<table border='0' cellspacing='0' cellpadding='5' bordercolor='black' width='100%' align='center'>";

echo "<tr>";
echo "<td width='60%'><b>To:</b></td>";
echo "<td width='22%'><b>Delivery Order ID: </b></td>";
echo "<td width='18%' align='right'><input type='hidden' name='doNo' value='$row[doNo]'>$row[doNo]</td>";
echo "</tr>";

echo "<tr>";
echo "<td>$row[custName]</td>";
echo "<td><b>Date: </b></td>";
echo "<td align='right'>".$row["doDate"]."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>$row[doAddress],<br/>$row[doCode], $row[doCity], <br/>$row[doState]<br/>Tel: $row[doTel]</td>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "</tr>";

echo "</table>";

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

echo "<table border='1' cellspacing='0' cellpadding='5' bordercolor='white' width='100%'>";
echo "<tr>";
echo "<th colspan='6'><center>Delivery Order Item List</center></th>";
echo "</tr>";

echo "<tr border='1'>";
echo "<th>No</th>";
echo "<th>ISBN</th>";
echo "<th>Item Description</th>";
echo "<th>Unit</th>";
echo "<th>Price</th>";
echo "<th>Subtotal</th>";
echo "</tr>";
for($i=0; $i <12; $i++)
{

	$row2 = mysql_fetch_array($result2);
	$doQ = $row2["doQuantity"]; 

	$doquantity = $doquantity + $doQ;
if($row2['doItem'] != ""){
	echo "<tr>";
	echo "<td>".($i + 1)."</td>";
	echo "<td>".$row2["doItem"]."</td>";
	echo "<td width='40%'>";
	
	$result3 = mysql_query("SELECT itemName FROM item WHERE ISBN = $row2[doItem]");
	
	$row3 = mysql_fetch_array($result3);

	echo "$row3[itemName]";
	echo "</td>";
	echo "<td align='center'>".$row2["doQuantity"]."</td>";
	echo "<td><br/></td>";
	echo "<td><br/></td>";
	echo "</tr>";
}else{
echo "<tr>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "</tr>";
}
}
echo "<tr bgcolor='gray'>";
	echo "<th colspan='3' align='left'>Total</th>";
	echo "<td><br/></td>";

	echo "</th>";
	echo "<td><br/></td>";
	echo "<td><br/></td>";
	echo "</tr>";

echo "<tr bgcolor='gray'>";
echo "<th colspan='3' align='left'>Shipping Method</th>";
echo "<td><br/></td>";
echo "<center>";

echo "</center>";
echo "</th>";

$shipType =  $row["doShip"];

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


$row3 = mysql_fetch_array($result3);

echo "<td><br/></td>";
echo "<td><br/></td>";
echo "</tr>";

echo "<tr bgcolor='gray'>";
echo "<th colspan='3' align='left'>Grandtotal</th>";
echo "<th>";
echo "<center>";
printf($doquantity);
echo "</center>";
echo "</th>";
echo "<td><br/></td>";
echo "<td><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='6'>";
echo "<table width='100%'>";
echo "<tr>";
echo "<td width='50%' height='50' align='center'><br/></td>";
echo "<td width='50%' height='50' align='center'><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td width='50%' height='30' align='center'>Company Stamp</td>";
echo "<td width='50%' height='30' align='center'>Receiver Signature</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";

echo "<div class='printnone'>";
echo "</div>";
echo "<tr>";
	echo "<td colspan='6' align='center'>
	<input type='submit' name='Back' value='Back'>
	<input type='button' value='Print' onClick='window.print()'/>";
echo "</form>";


?>
</body>




</html>
