Example #1
0
 /**
  * Get the fuel cost, given the airport and the amount of fuel
  *
  * @param int $$fuel_amount Amount of fuel used
  * @param string $apt_icao ICAO of the airport to calculate fuel price
  * @return int Total cost of the fuel
  *
  */
 public static function getFuelPrice($fuel_amount, $apt_icao = '')
 {
     /* A few steps:
        Check the local cache, if it's not there, or older
        than three days, reach out to the API, if not there,
        then use the localized price
        */
     if ($apt_icao != '') {
         $price = FuelData::GetFuelPrice($apt_icao);
     } else {
         $price = Config::Get('FUEL_DEFAULT_PRICE');
     }
     $total = $fuel_amount * $price + Config::Get('FUEL_SURCHARGE') / 100 * $fuel_amount;
     return $total;
 }
Example #2
0
 public function getfuelprice()
 {
     if (Config::Get('FUEL_GET_LIVE_PRICE') == false) {
         echo '<span style="color: red">Live fuel pricing is disabled!</span>';
         return;
     }
     $icao = $_GET['icao'];
     $price = FuelData::get_from_server($icao);
     if (is_bool($price) && $price === false) {
         echo '<span style="color: red">Live fuel pricing is not available for this airport</span>';
         return;
     }
     echo '<span style="color: #33CC00">OK! Found - current price: <strong>' . $price . '</strong></span>';
 }
Example #3
0
 /**
  * Check the finances for a PIREP
  * 
  * @return void
  */
 protected function checkPIREPFinances($pirep_test, $pirepdata)
 {
     # Fuel prices
     $fuelCost = FuelData::getFuelPrice($pirep_test['depicao']);
     $this->assertEquals($fuelCost, $pirepdata->fuelunitcost, 'FUEL UNIT COST');
     $this->assertEquals($pirep_test['fuelused'], $pirepdata->fuelused, 'FUEL USED');
     # Figure out what fuel should cost, + the surcharge amount
     $fuelShouldCost = $pirep_test['fuelused'] * $fuelCost;
     $fuelShouldCost += Config::Get('FUEL_SURCHARGE') / 100 * $pirep_test['fuelused'] * $fuelCost;
     $this->assertEquals($fuelShouldCost, $pirepdata->fuelprice, 'FUEL SHOULD COST');
     # Check revenue...
     $revenue = $pirepdata->load * $pirepdata->price;
     $this->assertEquals($revenue, $pirepdata->gross, 'GROSS REVENUE');
 }
Example #4
0
 /**
  * Populate the PIREP with the fianancial info needed
  * 
  * @param mixed $pirep Either a PIREP ID or the row
  * @param bool $reset_fuel Reset the fuel costs or not?
  * @return
  */
 public static function populatePIREPFinance($pirep, $reset_fuel = false)
 {
     if (!is_object($pirep) && is_numeric($pirep)) {
         $pirep = PIREPData::getReportDetails($pirep);
         if (!$pirep) {
             self::$lasterror = 'PIREP does not exist';
             return false;
         }
     }
     # Set the PIREP ID
     $pirepid = $pirep->pirepid;
     $sched = SchedulesData::getScheduleByFlight($pirep->code, $pirep->flightnum, '');
     if (!$sched) {
         self::$lasterror = 'Schedule does not exist. Please update this manually.';
         return false;
     }
     $pilot = PilotData::getPilotData($pirep->pilotid);
     # Get the load factor for this flight
     if ($pirep->load == '' || $pirep->load == 0) {
         $pirep->load = FinanceData::getLoadCount($pirep->aircraft, $sched->flighttype);
     }
     // Fix for bug #62, check the airport fuel price as 0 for live
     //$depapt = OperationsData::getAirportInfo($pirep->depicao);
     if ($pirep->fuelunitcost == '' || $pirep->fuelunitcost == 0 || $reset_fuel == true) {
         $pirep->fuelunitcost = FuelData::getFuelPrice($pirep->depicao);
     }
     # Check the fuel
     if ($pirep->fuelprice != '' || $reset_fuel == true) {
         $pirep->fuelprice = FinanceData::getFuelPrice($pirep->fuelused, $pirep->depicao);
     }
     # Get the expenses for a flight
     $total_ex = 0;
     $expense_list = '';
     /* Account for any fixed-cost percentages */
     $allexpenses = FinanceData::getFlightExpenses();
     if (is_array($allexpenses)) {
         foreach ($allexpenses as $ex) {
             $total_ex += $ex->cost;
         }
     }
     /* Account for any per-flight %age expenses */
     $all_percent_expenses = FinanceData::getFlightPercentExpenses();
     $gross = floatval($sched->price) * floatval($pirep->load);
     if (is_array($all_percent_expenses)) {
         foreach ($all_percent_expenses as $ex) {
             $cost = str_replace('%', '', $ex->cost);
             $percent = $cost / 100;
             $total = $gross * $percent;
             $total_ex += $total;
         }
     }
     /*  Set the pilotpay here - if it was a per-schedule payment,
         then set the pilot pay to that, otherwise, set it to the
         total amount paid... */
     # Handle pilot pay
     if (!empty($sched->payforflight)) {
         $pilot->payrate = $sched->payforflight;
         $payment_type = PILOT_PAY_SCHEDULE;
     } else {
         $payment_type = PILOT_PAY_HOURLY;
     }
     $data = array('price' => $sched->price, 'load' => $pirep->load, 'fuelprice' => $pirep->fuelprice, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'flighttime' => $pirep->flighttime);
     $revenue = self::getPIREPRevenue($data, $payment_type);
     /* Now update the PIREP */
     $fields = array('price' => $sched->price, 'load' => $pirep->load, 'gross' => $gross, 'fuelprice' => $pirep->fuelprice, 'fuelunitcost' => $pirep->fuelunitcost, 'expenses' => $total_ex, 'pilotpay' => $pilot->payrate, 'paytype' => $payment_type, 'revenue' => $revenue);
     if (isset($data['load']) && $data['load'] != '') {
         $fields['load'] = $data['load'];
     }
     return self::editPIREPFields($pirepid, $fields);
 }