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

<title>Print Preview of Purchase 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");



$poNo=$_GET['poNo'];

$result = mysql_query("SELECT * FROM purchaseorder WHERE poNo = '$poNo'");

$row = mysql_fetch_array($result);

$result2 = mysql_query("SELECT * FROM poitem WHERE poNo = '$poNo'");

$num_results = mysql_num_rows($result2);

$sup = $row['supName'];

$result3 = mysql_query("SELECT * FROM supplier WHERE supName = '$sup'");

$row3 = mysql_fetch_array($result3);

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>Purchase Order</b></center></p>";
echo "<form name='poviewform' 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>Purchase Order ID: </b></td>";
echo "<td width='18%' align='right'>$row[poNo]</td>";
echo "</tr>";

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

echo "<tr>";
echo "<td>$row[supName]<br/>$row3[supAddress]<br/>Tel: $row3[supPhone]</td>";
echo "<td><br/></td>";
echo "<td align='right'><br/></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>Purchase Order Item List</center></th>";
echo "</tr>";

echo "<tr>";
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);
	$poQ = $row2["poQuantity"]; 
	$poP = $row2["poPrice"];
	$subtotal = $poQ * $poP;
	$total = $total + $subtotal;
	
	$poquantity = $poquantity + $poQ;
if($row2['poItem'] != ""){	
	echo "<tr>";
	echo "<td>".($i + 1)."</td>";
	echo "<td>".$row2["poItem"]."</td>";
	echo "<td>";
	
	$result3 = mysql_query("SELECT itemName FROM item WHERE ISBN = $row2[poItem]");
	
	$row3 = mysql_fetch_array($result3);
	echo "$row3[itemName]";
	echo "</td>";
	echo "<td align='center'>".$row2["poQuantity"]."</td>";
	echo "<td align='center'>RM ";
	printf("%10.2f",$row2["poPrice"]);
	echo "</td>";
	echo "<td align='right'>RM";
	printf("%10.2f",$subtotal);
	echo "</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'>Grand Total</th>";
	echo "<th>";
	echo "<center>";
	printf($poquantity);
	echo "</center>";
	echo "</th>";
	echo "<td><br/></td>";
	echo "<th align='right'>RM";
	printf("%10.2f",$total);
	echo "</th>";
	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'><br/></td>";
echo "<td width='50%' height='30' align='center'>Approved</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='hidden' name='poNo' value='".$row["poNo"]."'/>
	<input type='submit' name='Back' value='Back'>
	<input type='button' value='Print' onClick='window.print()'/>";
echo "</form>";
echo "</div>";	
	echo "<form name='poform' method='GET' action='postatus.php'>";
	echo "<input type='hidden' name='poNo' value='".$row["poNo"]."'/>";
	echo "</td>";
	echo "</tr>";
echo "</table>";
echo "</form>";
?>




</html>
