<?php
include'connection.php';
if(!$_SESSION['Userid']){
	Header("location:index.php");
	exit();
}
 $fname=$_SESSION['Fname'];
 $lname=$_SESSION['Lname'];
 $userid=$_SESSION['Userid'];
 $unames=$_SESSION['Uname'];
	$cna=$_SESSION['Cna'];
	$buto='';

?>
<!DOCTYPE html>
<html class=""><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
    <title>   <?php echo $cna ?>    </title>
<script language="JavaScript" type="text/javascript">
	function printpage()
  {  
window.print();
  }
function closeWindow() {
setTimeout(function() {
window.close();
}, 200000);
}

window.onload = closeWindow();
</script>

<script type="text/javascript">
    // Specify the normal table row background color
    //   and the background color for when the mouse 
    //   hovers over the table row.

    var TableBackgroundNormalColor = "#ffffff";
    var TableBackgroundMouseoverColor = "#9999ff";

    // These two functions need no customization.
    function ChangeBackgroundColor(row) {
        row.style.backgroundColor = TableBackgroundMouseoverColor;
    }

    function RestoreBackgroundColor(row) {
        row.style.backgroundColor = TableBackgroundNormalColor;
    }
</script>

<script type="text/javascript">
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>

 <script src="style/jquery-ui.js" type="text/javascript"></script>
  <script src="style/jquery.min.js"></script>
  <script src="style/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="style/jquery-ui.css">

<style type="text/css">
@media print {
  .DONTPrint{ display:none }
  .DOCheck{ display:table}
			}
			
			
    @media screen {
        div.divFooter {
            display: none;
        }
    }
</style>

<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 2px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
	height: 20px;
}
table.gridtable td {
	border-width: 1px;
	padding: 2px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
table.gridtable tr:hover td { 
background-color: #dedede;
}
</style>

<link rel="shortcut icon" type="image/png" href="imgs/logo.png"/>
</head>
<body bgcolor="#COCOCO">
<center>
		<?php
		$loge=$_SESSION['Loge'];
		$hed=mysqli_query($conn, "SELECT *FROM company");
			$rd=mysqli_fetch_assoc($hed);{
				$N1x=$rd['Cname'];
				$N3x=$rd['Address'];
				$N5x=$rd['Tax'];
				$N6x=$rd['Phone1'];
				$N7x=$rd['Phone2'];
				$N8x=$rd['Email'];
				$N9x=$rd['Email'];
				$N10x=$rd['Website'];
				$Date=$rd['Date'];
			}
?><div class='divFooter'>
<IMG SRC="imgs/headers.jpg" WIDTH="100%" HEIGHT="90" BORDER="0" ALT=""></div>
<br><script>
function goBack() {
  window.history.back();
}
</script>

<?php
	if(isset($_POST['opens']))
		{
			$rowid=$_POST['rowid'];
			$date=$_POST['date'];
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$pago=$_POST['pago'];
			$user=$_POST['user'];
			$dst=$_POST['dst'];
			$ref=$_POST['ref'];
			$ite=$_POST['ite'];
			$p=$_POST['p'];
			$t=1;
		}
			$due=date('l jS M Y', strtotime($date)); 
			
	$top=mysqli_query($conn, "SELECT *FROM `suppliers` WHERE `Supplier`='$dst' ORDER BY `Supplier` ASC");
			$rop=mysqli_fetch_assoc($top);
				$adds=$rop['Address'];
				$tess=$rop['Telephone'];
				$emes=$rop['Email'];
	
	echo"<div class='DONTPrint'><table width=80% border=0><tr>
	<td><a href='$pago'><font face='Agency FB' color='blue' size='3'> BACK </a></td><td><div align=right><a href='#' onclick='javascript:printpage();window.close()'><font face='Agency FB' color='blue' size='3'> PRINT </a></td></tr></table></div>

	        <table width='98%' class='gridtable'>
	<tr style='height:30px;'><th width='5%' style='border: 0px dotted #99cccc; font-size:24px; background-color:transparent;'><b><u> FUEL PURCHASE ORDER </u></b></th></tr></table><br>
	
	<div style='padding-left:20px; float:left; 
	text-align:left; margin-bottom:10px;'>
	<u><b>SUPPLIER'S NAME</b></u>: $dst <br>
	&nbsp;<u><b>POINT OF FUELING</b></u>: $ref </div>
	
	
	<table width='92%'><tr><td align='left'><b><u>DATE</u>:</b> $due </td>
 <td align='right'><b><u>F.P.O No</u>:</b> 0$rowid </td></tr></table>";

	print("<table width='98%' class='gridtable' id='excel-table'>
			<tr style='height:20px;'>
			<th width='2%' style='font-size:12px;'> No </th>
			<th style='font-size:12px;'> PLATE&nbsp;No </th>
			<th style='font-size:12px;'> DRIVERS'&nbsp;NAME </th>
			<th style='font-size:12px;'> DESTINATION </th>
	    <th width='8%' style='font-size:12px;'> QTY&nbsp;(Lts) </th>
	        <th style='font-size:12px;'> COMMENT </th></tr>");

		$n=1;			$tot=0;
$roome=mysqli_query($conn, "SELECT `stouse`.`Number`, `stouse`.`Date`, `vehicles`.`Plate`, `vehicles`.`Driver`, `stouse`.`Quantity`, `stouse`.`Price`, `stouse`.`Comment`, `stouse`.`Trip` FROM `stouse` INNER JOIN `vehicles` ON `stouse`.`Item`=`vehicles`.`Number` WHERE `stouse`.`Status`='0' AND `stouse`.`Voucher`='$rowid' AND `stouse`.`Action`='PURCHASE' ORDER BY `stouse`.`Number` ASC");
					while($rom=mysqli_fetch_assoc($roome)){	
						$item=$rom['Plate'];
						$drive=$rom['Driver'];
						$qty=$rom['Quantity'];
						$com=$rom['Comment'];
						$date=$rom['Date'];
			$doix=mysqli_query($conn, "SELECT `Number`, `Location`, `Final` FROM `trips` WHERE `Date`<='$date' AND `Plate`='$item' ORDER BY `Number` DESC LIMIT 1");
			$roix=mysqli_fetch_assoc($doix);
				$deso=$roix['Location'];
				$fina=$roix['Final'];
				$tipo=$roix['Number'];
				
				if(!$rom['Trip'])
$doi=mysqli_query($conn, "UPDATE `stouse` SET `Trip`='$tipo' WHERE `Number`='$nuos' ORDER BY `Number` ASC LIMIT 1");
				
						$to+=$qty;
			$too=number_format($to);				$qto=number_format($qty);
echo"<tr><td style='font-size:11px; text-align:right'>&nbsp;$n&nbsp;&nbsp;</td>
<td style='font-size:11px; text-align:center;'> $item </td>
<td style='font-size:11px; text-align:left;'> $drive </td>
<td style='font-size:11px; text-align:left;'> $deso-$fina </td>
<td style='font-size:11px; text-align:right;'> $qto</td>
<td style='font-size:11px; text-align:left;'> $com </td></tr>";
		$n++;				
					}
		$toto=number_format($tot);
?>			
<tr><th style='font-size:12px; text-align:left; padding-left:35px;' colspan='5'><b> TOTAL QUANTITY (LTS) <label style="font-size:12px; text-align:right; float:right"><b><?php echo $too ?>&nbsp;</th><th> </th></tr>
	</table><br><br>
	
                		
		<div class="divFooter">
	<table width='100%' style='font-size:11px;'>
	    <tr><td width='33%'> Prepared by: <br><br><br>
	<hr style='width:90%; float:left;'><br><?php echo $user ?><br><br>
	Fleet Manager
	</td>
	
	<td>Verified by: <br><br><br>
	<hr style='width:90%; float:left;'><br> .............. ........ <br><br> Director of Finance </td>
	
	<td width='33%'> Approved by: <br><br><br>
	<hr style='width:90%; float:left;'><br> ................. .......... <br><br> Managing Director</td>
	</tr></table><br></div>

	    <?php
	echo"<div class='DONTPrint'><HR WIDTH=98%><table width=80% border=0><tr>
	<td width='33%'><a href='$pago'><font face='Agency FB' color='blue' size='3'> BACK </a></td>";
	?>
	<td><center><a href="#" id="button1" class="hidden-print" title='Export to Excel' data-toggle='tooltip' data-placement='top' onclick="tableToExcel('excel-table', 'Excel Table')"><font face='Agency FB' color='blue' size='3'> Export to Excel</a></center></td>
	
	<?php
	echo"<td width='33%'><div align=right><a href='#' onclick='javascript:printpage();window.close()'><font face='Agency FB' color='blue' size='3'> PRINT </a></td></tr></table><br><br></div>";
	?>
	
		<div class="divFooter"><IMG SRC="imgs/footer.jpg" WIDTH="100%" HEIGHT="60" BORDER="0" ALT=""></div>
            
      </body>
</html>
