<?php
     // *************** Create purchase **********************
	    echo"<div class='modal fade' id='Modaldis' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document' style='width:70%;'>
  <div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'>CREATE NEW FUEL PURCHASE 
        <span class='pull-right'>  </span></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left'><div class='row'>

    <div class='col-md-12 text-left' style='height:380px; overflow-x:auto;'>";
        
        $a=1;
    
    $dos=mysqli_query($conn, "SELECT `vehicles`.`Number`, `vehicles`.`Plate`, `vehicles`.`Locate`, `vehicles`.`Trip` FROM `vehicles` WHERE `vehicles`.`Status`='0' AND `vehicles`.`Trip`='0' GROUP BY `vehicles`.`Plate` ORDER BY `vehicles`.`Plate` ASC");
		while($ros=mysqli_fetch_assoc($dos)){
			$numb=$ros['Number'];
			$plate=$ros['Plate'];
			$bd=$ros['Locate'];
			if($bd)
			$bor="border:1px solid red;";
			else
			$bor="";
	    
	    if($ros['Trip']=='0')
		$bor="border:1px solid blue;";
	echo"<label class='btn btn-default active' for='my$a' style='width:110px; $bor' title='$bd' data-toggle='tooltip' data-placement='top'>
	        <input type='hidden' name='pla$a' value='$plate'>
	        <input type='hidden' name='indo$a' value='0'>
          <input id='my$a' type='checkbox' value='$numb' name='plate$a' style='border:0px; height:12px;'> $plate </label>";
                 $a++;
		}
    
    echo"<div class='row'><hr></div>";
    
    $dos=mysqli_query($conn, "SELECT `vehicles`.`Number`, `vehicles`.`Plate`, `vehicles`.`Locate`, `vehicles`.`Trip` FROM `vehicles` INNER JOIN `trage` ON `vehicles`.`Plate` = `trage`.`Plate` WHERE `vehicles`.`Status`='0' AND `vehicles`.`Locate`='' AND `vehicles`.`Loading`='0' AND `trage`.`Action`='MILEAGE' AND `trage`.`Fuel`='0' GROUP BY `vehicles`.`Plate` ORDER BY `vehicles`.`Plate` ASC");
		while($ros=mysqli_fetch_assoc($dos)){
			$numb=$ros['Number'];
			$plate=$ros['Plate'];
			$bd=$ros['Locate'];
			if($bd)
			$bor="border:1px solid red;";
			else
			$bor="";
			
	$sedes=mysqli_query($conn, "SELECT `Destination` FROM `trips` WHERE `Vehicle`='$numb' AND `Status`='0' ORDER BY `ETD` DESC LIMIT 1");
	$redes=mysqli_fetch_assoc($sedes);
	    $dstn=$redes['Destination'];
			
	$seqa=mysqli_query($conn, "SELECT `Quantity` FROM `consumption` WHERE `Vehicle`='$numb' AND `Status`='0' ORDER BY `Number` DESC LIMIT 1");
	        $rea=mysqli_fetch_assoc($seqa);
	             $qto=number_format($rea['Quantity']);
	             $lts="L";
	    
	    if($ros['Trip']=='0')
		$bor="border:1px solid blue;";
	echo"<label class='btn btn-default active' for='my$a' style='width:110px; $bor' title='Last: $qto$lts          Destination: $dstn' data-toggle='tooltip' data-placement='top'><input type='hidden' name='pla$a' value='$plate'>
	        <input type='hidden' name='indo$a' value='0'>
          <input id='my$a' type='checkbox' value='$numb' name='plate$a' style='border:0px; height:12px;'> $plate </label>";
                 $a++;
		}
    
        
    echo"<div class='row'><hr></div>";
    
    $dos=mysqli_query($conn, "SELECT `vehicles`.`Number`, `vehicles`.`Plate`, `vehicles`.`Locate`, `vehicles`.`Trip` FROM `vehicles` WHERE `vehicles`.`Status`='0' AND `vehicles`.`Depane`='1' GROUP BY `vehicles`.`Plate` ORDER BY `vehicles`.`Plate` ASC");
		while($ros=mysqli_fetch_assoc($dos)){
			$numb=$ros['Number'];
			$plate=$ros['Plate'];
			$bd=$ros['Locate'];
			$bor="border:1px solid red;";
	    
	echo"<label class='btn btn-default active' for='mai$a' style='width:110px; $bor' title='$bd' data-toggle='tooltip' data-placement='top' $dsi>
	        <input type='hidden' name='pla$a' value='$plate'>
	        <input type='hidden' name='indo$a' value='1'>
          <input id='mai$a' type='checkbox' value='$numb' name='plate$a' style='border:0px; height:12px;' $dsi> $plate </label>";
                 $a++;
		}
		
		
    echo"</div></div></div><div class='row'> </div>
	    
	            <input type='hidden' name='a' value='$a'>	
	<div class='modal-header' style='padding-top:15px; height:50px;'>
	
	<div class='col-md-4' style='padding-left:40px;'>
	<input type='checkbox' name='checkall' id='checkall' style='height:22px; width:24px; margin-top:0px;' onClick='check_uncheck_checkbox(this.checked);'> &nbsp; <button type='button' class='btn btn-secondary' id='d1'></button></div>
	
	 <div class='col-md-2 input-group' style='margin-top:-5px;'><input name='qty' class='form-control text-center' type='text' onkeyup='format(this);' onkeypress='return isNumberKey(event)' style='width:60%' value='$qty' required><select class='form-control input-group-addon' style='width:40%; color:blue; padding-left:2px; padding-right:2px;'><option value=''> Liters </option></select></div>
    
    <div class='col-md-3' style='margin-top:-5px;'><select class='form-control' name='stat' title='Gas Station' data-toggle='tooltip' data-placement='top' required><option value='' selected='selected'>Select Station</option>";
		
	$doi=mysqli_query($conn, "SELECT `Number`, `Name`, `Currency`, `Price` FROM `station` WHERE `Name`!='' ORDER BY `Name` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
			    $nuo=$roi['Number'];
				$fna=$roi['Name'];
				$pri=number_format($roi['Price'], 2);
				$cus=$roi['Currency'];
			echo"<option value='$nuo'> $fna @ $pri$cus </option>";
			}
		
		   echo"</select></div>
    
                <div class='col-md-3 text-right'>
		<button type='button' class='btn btn-xs btn-danger' data-dismiss='modal' style='width:80px; height:28px;'> CANCEL </button>
        <button type='submit' name='adve' class='btn btn-xs btn-success' style='width:80px; height:28px;'> ADD </button></div>
      </div></form>
  </div></div>
</div>";

?>