/** * 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'); }
/** * 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); }