<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="../jscript/calendar.js"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>  

<?php
include('../include/session.php');
require_once('../include/tc_calendar.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$fuel_id = $_GET['fuel_id'];

$table_name = $_SESSION['db_prefix']."_fuel_supply";
$fuel_query = "SELECT * FROM $table_name WHERE fuel_id = '".$fuel_id."'  ";
$fuel_result = mySQL_query($fuel_query);
$fuel_num = mysql_num_rows($fuel_result);
$supply_date = mysql_result($fuel_result, 0, "supply_date");
$vehicle_id = mysql_result($fuel_result, 0, "vehicle_id");
$fuel = mysql_result($fuel_result, 0, "fuel");
$fuel_price = mysql_result($fuel_result, 0, "price");
$qty_supplied = mysql_result($fuel_result, 0, "qty_supplied");
$reference = mysql_result($fuel_result, 0, "reference");
$mileage = mysql_result($fuel_result, 0, "mileage");
$driver = mysql_result($fuel_result, 0, "driver");
$supplier = mysql_result($fuel_result, 0, "supplier");
$notes = mysql_result($fuel_result, 0, "notes");
$oil_qty = mysql_result($fuel_result, 0, "oil_qty");
$oil_price = mysql_result($fuel_result, 0, "oil_price");
$other = mysql_result($fuel_result, 0, "other");
$other_price = mysql_result($fuel_result, 0, "other_price");
  

$d = date("d", strtotime($supply_date));
$m = date("m", strtotime($supply_date));
$y = date("Y", strtotime($supply_date));

$table_name = $_SESSION['db_prefix']."_vehicle";
$vehicle_query = "SELECT vehicle_id, registration_no, make, model, fuel FROM $table_name WHERE vehicle_id ='".$vehicle_id."' ";
$vehicle_result = mySQL_query($vehicle_query);
$vehicle_num = mysql_num_rows($vehicle_result);  
$vehicle_name = mysql_result($vehicle_result, 0, "registration_no").' '.mysql_result($vehicle_result, 0, "make").' '.mysql_result($vehicle_result, 0, "model");
$fuel = mysql_result($vehicle_result, 0, "fuel"); 

$table_name2 = $_SESSION['db_prefix']."_employee";
$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$driver."' ";
$employee_result = mySQL_query($employee_query);
$employee_num = mysql_num_rows($employee_result);  
$emp_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name");   

$table_name = $_SESSION['db_prefix']."_employee";
$select_query = "SELECT emp_id, emp_first_name, emp_last_name FROM $table_name";
  $arrId2 = array ();
  $arrName2 = array ();
  $select_result = execsql($select_query);
  $select_num = mysql_num_rows($select_result);
  $a = 0;
  while ($a < $select_num) {
    $arrId2[$a] = mysql_result($select_result, $a, "emp_id");
    $arrName2[$a] = mysql_result($select_result, $a, "emp_first_name").' '.mysql_result($select_result, $a, "emp_last_name");
    $a++;
  }  

$table_name = $_SESSION['db_prefix']."_list_fuel_provider";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
  $arrId1 = array ();
  $arrName1 = array ();
  $position_result = execsql($position_query);
  if ($position_result!="") {
  $position_num = mysql_num_rows($position_result);
  $b = 0;
  while ($b < $position_num) {
    $arrId1[$b] = mysql_result($position_result, $b, "item_name");
    $arrName1[$b] = mysql_result($position_result, $b, "item_name");
    $b++;
  }
  }  

?>
</head>



<?php
include ("../navigation/header.php");
$page_name = "Transport-fuel";
include ("../navigation/access.php");
if ($permission_num==1) {
  include ("../navigation/transport_sidebar.php");
?>

<body>

<div class="main_frame"  style="height:auto; min-height:570px;">

<div class="page_head_frame">
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Fuel recording</label></td>
            </tr>
        </table>
      </div>
<form action="edit_fuel_rec_save.php" method="post"> 
        <div class="page_middle_frame">
          <div class="hidden_frame" id="hidden_frame">
<div class="page_inside_frame">
  Fuel for:&nbsp;&nbsp; <label class="label_caption_green"> <?php echo $vehicle_name; ?></label>
  <br><br>
  <table width="645"  id="table_display">
    <tr>
      <td width="158" height="29">Fuel supply  date:</td>
      <td colspan="2"><?php 
          //instantiate class and set properties
    $myCalendar = new tc_calendar("supply_date", true);
    $myCalendar->setIcon("../images/iconCalendar.gif");
    $myCalendar->setDate($d, $m, $y);
    $myCalendar->setYearInterval(2015, 2099);
    //output the calendar
    $myCalendar->writeScript();
?></td>
      <td>Supply no: <?php echo $fuel_id ?>
        <input name="fuel_id_text" type="hidden" value="<?php echo $fuel_id ?>"></td>
      </tr>
    <tr>
      <td height="43">Fuel type:</td>
      <td>&nbsp;
        <select name="fuel_select" id="fuel_select">
          <option value="diesel">diesel</option>
          <option value="petrol">petrol</option>
          <option value="<?php echo $fuel ?>" selected="selected"><?php echo $fuel ?></option>
        </select>        
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
      <td>km reading:</td>
      <td><input name="mileage_text" type="text" value="<?php echo $mileage ?>"onkeypress="return numbersonly(this, event)" onfocus = "this.select();">&nbsp;km</td>
      </tr>
    <tr>
      <td height="43">Qty:</td>
      <td width="164"><input name="qty_text" type="text" class="text50" value="<?php echo $qty_supplied ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();">&nbsp;ltr</td>
      <td width="93">Price fuel:</td>
      <td width="210"> P 
        <input name="price_text" type="text" class="text50" id="price_text" value="<?php echo $fuel_price ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();">&nbsp;/ltr</td>
    </tr>
    <tr>
      <td height="43">Oil:</td>
      <td><input name="oil_qty_text" type="text" class="text50" value="<?php echo $oil_qty ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();">&nbsp;ltr.</td>
      <td>Price oil: (total)</td>
      <td>P&nbsp;
<input name="oil_price_text" type="text" class="text50" value="<?php echo $oil_price ?>" onKeyPress="return isNumberKey(event)"onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();">&nbsp;</td>
    </tr>
    <tr>
      <td height="43">Other:</td>
      <td><input name="other_text" type="text" class="text100" value="<?php echo $other ?>" maxlength="20"  onfocus = "this.select();"></td>
      <td>Price: (total)</td>
      <td>P&nbsp;
        <input name="other_price_text" type="text" class="text50" value="<?php echo $other_price ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')"  onfocus = "this.select();">
        &nbsp;<?php echo 'P '.$other_price ?>&nbsp;</td>
    </tr>
    <tr>
      <td height="43">Provider:</td>
      <td colspan="3"><select name="provider_select" class="select200"  id="provider_select" >
        <option value="<?php echo $supplier ?>" selected="selected"><?php echo $supplier?></option>
        <?php
          for ($j = 0; $j < count($arrId1); $j++) {
        echo "<option value=" . "\"" . $arrId1[$j] . "\"" . ">" . $arrName1[$j] . "</option>";
  }
?>
      </select>        
        &nbsp;</td>
    </tr>
    <tr>
      <td height="43">Fuel book no:</td>
      <td><input name="reference_text" type="text" value="<?php echo $reference ?>"  onfocus = "this.select();">&nbsp;</td>
      <td>Received by:</td>
      <td><select name="received_select" class="select200"  id="received_select" >
        <option value="<?php echo $driver ?>" selected="selected"><?php echo $emp_name ?></option>
        <?php
          for ($j = 0; $j < count($arrId2); $j++) {
        echo "<option value=" . "\"" . $arrId2[$j] . "\"" . ">" . $arrName2[$j] . "</option>";
  }
?>
      </select> </td>
    </tr>
    <tr>
      <td height="58">Notes:</td>
      <td colspan="3"><textarea name="notes_text" cols="50" rows="3" class="text_box" id="notes_text"><?php echo $notes ?></textarea></td>
      </tr>
</table> 
</div>

<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="fuel_id_text" id="fuel_id_text" value="<?php echo $fuel_id?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../transport/transport_main.php?date=0');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onClick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>
</div>
</div> 
</form>
   
</div>





<?php } else {
    $_SESSION['denied_return'] = "transport/transport_main.php?date=";  
    include ("../navigation/transport_sidebar.php");?>
  <body onLoad="accessdenied(); return false">  
  </body>
<?php }
?>


<?php include ('../navigation/side_bar.php'); ?>
</body>
</html>