<?php
if(basename($_SERVER['PHP_SELF']) == 'addrepo.php') 
  $cm=" class='current'";
include'header.php';
$datos=$Date;

$dato = strtotime("-15 days", strtotime("$Date"));
        $dato = date ("Y-m-d", $dato);
        
$custo=$conde='';
$condi='';
$p=0;

// search for an item to be added to the chart
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$p=1;
		}

	
	    if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";

			if($custo)
				$conde="AND `Item`='$custo'";

			?>
			
<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h3 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
         Stations Report
          </h3>
                 </div>
     
        <div class="row">
  <div class="col-lg-2 hidden-print">
   
  <ul class="list-group">   

    <li class="list-group-item">
	  <a href="starepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Stations Report
                </p>
              </a></li>    

    <li class="list-group-item">
	  <a href="purepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Purchase Report
                </p>
              </a></li>     

    <li class="list-group-item active">
	  <a href="addrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Additional Report
                </p>
              </a></li>   
                         
            </ul>
  </div>
                    
           
           
    <form action="" method="post" class="form-horizontal "> 
        <div class="col-lg-10">
                  <div class="row">

				  <div class="col-lg-3"> </div>         

                     <div class="col-lg-3">
			
			<select class="form-control" name="custo">
			 	<option value='' selected='selected'>Select Vehicle</option>
			 <?php
	$doi=mysqli_query($conn, "SELECT `vehicles`.`Plate`, `trips`.`Vehicle` FROM `trips` INNER JOIN `vehicles` ON `vehicles`.`Number` = `trips`.`Vehicle` GROUP BY `trips`.`Vehicle` ORDER BY `trips`.`Vehicle` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$veh=$roi['Vehicle'];
				$fna=$roi['Plate'];
				if($veh==$custo)
					$sle="selected";
				else
					$sle='';
			echo"<option value='$veh' $sle> $fna </option>";
			}
			?>    
                            </select>
			
					   </div>
							
                       <div class="col-lg-6 hidden-print">
            <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-4"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                      
                       
                       <div class="col-lg-3">
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div> 
                      
                     
                  
            </form> 
             
               
            </div>
             <?php
		$n=1;			$tot=0;
$do=mysqli_query($conn, "SELECT `Date`, `Item`, `Trip`, `Quantity`, `Comment` FROM `stouse` WHERE `Status`='0' AND `Date` BETWEEN '$dato' AND '$datos' AND `Action`='PURCHASE' AND `Closing`!='0' AND `Trip`!='0' $conde GROUP BY `Trip` ORDER BY `Number` ASC");

$fo=mysqli_num_rows($do);
					?>
					<div class="divFooter"><center><u><b>ADDITIONAL FUEL REPORT <?php echo"$mpri"; ?></b></u></center></div>
		 <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span>
			 
			  <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="exportTableToExcel('tblData')" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

			 <table class="table table-striped table-hover" id="tblData">     
                    <thead><tr role="row">
			<th width='3%'> No </th>
			<th width='8%' class="text-center"> DATE </th>
			<th width='6%'> VEHICLE&nbsp;ID </th>
			<th width='15%'> DESTINATION </th>
	        <th width='5%'> LOADED </th>
	        <th class="text-center"> COMMENT </th>
	        <th width='5%'> QTY&nbsp;(Lts) </th></tr></thead>
                                        <tbody>
					<?php
		while($ro=mysqli_fetch_assoc($do)){	
			$item=$ro['Item'];
			$tipo=$ro['Trip'];
			
						$qty=$ro['Quantity'];
						$com=$ro['Comment'];
						$date=$ro['Date'];
	$doix=mysqli_query($conn, "SELECT `Location`, `Final`, `Plate` FROM `trips` WHERE `Number`='$tipo' AND `Vehicle`='$item' ORDER BY `Number` DESC LIMIT 1");
			$roix=mysqli_fetch_assoc($doix);
				$deso=$roix['Location'];
				$fina=$roix['Final'];
				$plat=$roix['Plate'];
				
	$sdo=mysqli_query($conn, "SELECT SUM(`Quantity`) AS `Qty` FROM `stouse` WHERE `Item`='$item' AND `Trip`='$tipo' AND `Closing`='0' AND `Action`='PURCHASE' AND `Status`='0'");
	$rdo=mysqli_fetch_assoc($sdo);
	    $load=$rdo['Qty'];
	    $loado=number_format($load);
				
					$to+=$qty;
			$too=number_format($to);				$qto=number_format($qty);
echo"<tr><td style='padding:0px; text-align:right'>&nbsp;$n&nbsp;&nbsp;</td><td style='padding:0px; text-align:center;'> $date </td><td style='padding:0px; text-align:center;'> $plat </td><td style='padding:0px; text-align:left;'> $deso-$fina </td><td style='padding:0px; text-align:right;'> $loado</td>
<td style='padding:0px 0px 0px 5px; text-align:left;'> $com </td><td style='padding:0px; text-align:right;'> $qto</td></tr>";
		$n++;				
					}
		
		$toto=number_format($tot);
?>			
<tr><th style="text-align:left; padding-left:35px; padding-right:0px;" colspan='7'><b> TOTAL QUANTITY (LTS) <label style="text-align:right; float:right;"><b><?php echo $too ?>&nbsp;</th><th> </th></tr></table><br><br>
                                      
                
              </div>
            </div></div>
                  </div>                  
                <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-printer"></i></a></span> 
			 
			    <span class="pull-right hidden-print">
			 &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="exportTableToExcel('tblData')" class="hidden-print" title='Export to excell' data-toggle='tooltip' data-placement='top'><i class="lnr lnr-line-spacing"></i></a></span>
      
   </div></div></div>  
   <?php
   include'footer.php';
   ?>