<?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>

<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>
</head>
<body>
<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'];
			}


    $t=$lim=1;
		
		$bulk=$_SESSION['Bulk'];
	$conde="AND (`trips`.`Bulk` = '$bulk')";
$doi=mysqli_query($conn, "SELECT `vehicles`.`Locate`, `trips`.`Plate`, `trips`.`Date`, `trips`.`Bulk` FROM `vehicles` INNER JOIN `trips` ON `vehicles`.`Tripo` = `trips`.`Number` WHERE `vehicles`.`Status`='0' AND `vehicles`.`Locate`='' $conde GROUP BY `trips`.`Bulk` ORDER BY `trips`.`Date` ASC LIMIT $lim");
	            
           while($roi=mysqli_fetch_assoc($doi)){
               $loke=$roi['Locate'];
               $dte=$roi['Date'];
               $inra=number_format($roi['Rate'], 2);
               $bulko=$roi['Bulk'];
               
    $doze=mysqli_query($conn, "SELECT `Custo`, `Customer`, SUM(`Amount`*`Rate`) AS `Amo` FROM `income` WHERE `Bulk`='$bulko' ORDER BY `Number` ASC");
		$roze=mysqli_fetch_assoc($doze);
            $acco=$roze['Customer'];
            $inam=number_format($roze['Amo']);
			$cust=$roze['Custo'];
               
    $do=mysqli_query($conn, "SELECT `vehicles`.* FROM `vehicles` WHERE `vehicles`.`Status`='0' AND `vehicles`.`Bulk`='$bulko' ORDER BY `Number` ASC LIMIT 1000");	
            $fo=mysqli_num_rows($do);
            
			$stn="style='padding:0px; border:1px solid #000000;'";
    echo" &nbsp; <br> &nbsp; <br> &nbsp; <br> &nbsp; <br> &nbsp; <br> &nbsp; <br> &nbsp; <br> &nbsp; <br> &nbsp; <br>
	 
	<table width='100%' style='border:1px solid #000000' border='0'>     
        <tr role='row'><th width='1%'> No </th>
        <th $stn><div align='center'> TRUCK&nbsp;ID </th>
        <th $stn><div align='center'> TRAILER&nbsp;ID </th>
		<th $stn><div align='center'> DRIVER'S NAME </th>
		<th $stn><div align='center'> DRIVING LICENSE </th>
		<th $stn><div align='center'> PC/LP </th>
		<th $stn><div align='center'> TELEPHONE </th></tr>";

	$n=1;				$tm=$tf=0;                  $dris=array();
		while($ro=mysqli_fetch_assoc($do)){
			$code=$ro['Number'];
			$make=$ro['Make'];
			$mode=$ro['Chassis1'];
			$chassis=$ro['Chassis2'];
			$year=$ro['Year'];

			$fuel=$ro['Fuel'];
			$vid=$ro['Plate'];
			$tre=$ro['Trailer'];
			$bul=$ro['Bulk'];
			$trip=$ro['Trip'];
			
		$seti=mysqli_query($conn, "SELECT *FROM `trips` WHERE `Vehicle`='$code' AND `Bulk`='$bulko' ORDER BY `Number` DESC LIMIT 1");
			    $reti=mysqli_fetch_assoc($seti);
			    $trino=$reti['Number'];
			    $desto=$reti['Destination'];
			    $locoo=$reti['Location'];
			    $fino=$reti['Final'];
			    $disto=$reti['Distance'];
			    $capo=$reti['Capacity'];
			    $etao=$reti['ETA'];
			    $etdo=$reti['ETD'];
			    $descro=$reti['Description'];
			    $source=$reti['Driver'];
			    $dris[$n]=$source;
			
		$sete=mysqli_query($conn, "SELECT `Idno`, `Contact1`, `Contact2` FROM `employees` WHERE `Fullname`='$source' AND `Fullname`!='' ORDER BY `Eid` DESC LIMIT 1");
		    if($fete=mysqli_num_rows($sete)){
			    $rete=mysqli_fetch_assoc($sete);
			        $tle=$rete['Contact1'];
			        $pcl=$rete['Contact2'];
			        $idno=$rete['Idno'];
		    }
		    else{
		        $tle=$pcl=$idno="";
		    }

		print("<tr><td $stn><div align='center'> $n </td>
		<td $stn><div align='center'> $vid </td>
		<td $stn><div align='center'> $tre </td><td $stn> $source </td>
			  <td CLASS='text-center' $stn> '$idno </td>
			  <td $stn><div align='left'> $pcl </td>
						<td $stn><div align='center'> '$tle </td></tr>");
				$n++; 
						}
				
			echo"</table>";
           }
	
                ?>
                </body>
        </html>