<html>

<title>ppInvoice</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" />


<style type="text/css" media="print, projection">
   .printnone {display:none}
</style>

</head>

<body>
<div class="print">
<td>
<?php
include("connect.php");



$invNo=$_GET['invNo'];

$result = mysql_query("SELECT * FROM invoice WHERE invNo = '$invNo'");

$row = mysql_fetch_array($result);

$result2 = mysql_query("SELECT * FROM invitem WHERE invNo = '$invNo'");

$num_results = mysql_num_rows($result2);

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

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

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

echo "<tr>";
echo "<td>$row[invAddress],<br/>$row[invCode], $row[invCity], <br/>$row[invState]<br/>Tel: $row[invTel]</td>";
echo "<td>DO ID: <br/>SO ID: </td>";
echo "<td align='right'>$row[doNo] <br/>$row[soNo]</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>Invoice 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);
	$invQ = $row2["invQuantity"]; 
	$invP = $row2["invPrice"];
	$subtotal = $invQ * $invP;
	$total = $total + $subtotal;
	
	$invquantity = $invquantity + $invQ;
if($row2['invItem'] != ""){	
	echo "<tr>";
	echo "<td>".($i + 1)."</td>";
	echo "<td>".$row2["invItem"]."</td>";
	echo "<td>";
	
	$result3 = mysql_query("SELECT itemName FROM item WHERE ISBN = $row2[invItem]");
	
	$row3 = mysql_fetch_array($result3);
	echo "$row3[itemName]";
	echo "</td>";
	echo "<td align='center'>".$row2["invQuantity"]."</td>";
	echo "<td align='center'>RM ";
	printf("%10.2f",$row2["invPrice"]);
	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'>Total</th>";
	echo "<th>";
	echo "<center>";
	printf($invquantity);
	echo "</center>";
	echo "</th>";
	echo "<td><br/></td>";
	echo "<th align='right'>RM";
	printf("%10.2f",$total);
	echo "</th>";
	echo "</tr>";

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

$shipType =  $row["invShip"];

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


$row3 = mysql_fetch_array($result3);

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

echo "<tr bgcolor='gray'>";
echo "<th colspan='3' align='left'>Grandtotal</th>";
echo "<th>";
echo "<center>";
printf($invquantity);
echo "</center>";
echo "</th>";
echo "<td><br/>";
echo "</td>";
echo "<th align='right'>RM ";
$ship = $row3["shipCost"];
$grandtotal = $total + $ship;
	
printf("%10.2f",$grandtotal);
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'>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>";
echo "</div>";	
	echo "<form name='invform' method='GET' action='invstatus.php'>";
	echo "<input type='hidden' name='invNo' value='".$row["invNo"]."'/>";
	echo "</td>";
	echo "</tr>";
echo "</table>";
echo "</form>";
?>
</div>
</body>

</html>
