Hello Guys,
I need to fix this error in the monthly statistics of the airline. The module works well but I have noticed that since there are no statistics in this month for some reason it throws the error: Warning: Creating default object from empty value in /home/level/public_html/phpvms/core/common/FinanceData.class. php on line 107.
I have not modified anything and it only throws the error in the statistics of this month. In the statistics of the previous months it does not. ( Statistics for June )
I looked FinanceData.class.php and basically I don’t know what to do to fix that. This is the code:
\<?php /\*\* \* phpVMS - Virtual Airline Administration Software \* Copyright (c) 2008 Nabeel Shahzad \* For more information, visit www.phpvms.net \* Forums: http://www.phpvms.net/forum \* Documentation: http://www.phpvms.net/docs \* \* phpVMS is licenced under the following license: \* Creative Commons Attribution Non-commercial Share Alike (by-nc-sa) \* View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/ \* \* @author Nabeel Shahzad \* @copyright Copyright (c) 2008, Nabeel Shahzad \* @link http://www.phpvms.net \* @license http://creativecommons.org/licenses/by-nc-sa/3.0/ \*/ class FinanceData extends CodonData { public static $lasterror; public static function formatMoney($number) { $isneg = false; if ($number \< 0) { $isneg = true; } # $ 50.00 - If positive # ($ -50.00) - If negative $number = Config::Get('MONEY\_UNIT') . ' ' . number\_format($number, 2, '.', ', '); if ($isneg == true) $number = '(' . $number . ')'; return $number; } /\*\* \* 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); # Surcharge amount $total += ((Config::Get('FUEL\_SURCHARGE') / 100) \* $fuel\_amount) \* $price; return $total; } /\*\* \* This populates the expenses for a monthly-listing from \* PIREPData::getIntervalDatabyMonth(array(), months). This goes \* monthly. Pass in just one month returned by that array. \* \* This will add a index called 'expenses' which will contain \* all of the expenses for that month \* \* @param mixed $month\_info This is a description \* @return mixed This is the return value description \* \*/ public static function calculateFinances($month\_info) { $pilot\_pay = LedgerData::getTotalForMonth($month\_info-\>timestamp); /\* Where the bulk of our work is done for expenses \*/ $running\_total = 0; $expenses = self::getExpensesForMonth($month\_info-\>timestamp); foreach ($expenses as $ex) { $ex-\>type = strtolower($ex-\>type); if($ex-\>type == 'm') { $ex-\>total = $ex-\>cost; } elseif($ex-\>type == 'f') { /\* per-flight expense \*/ $ex-\>total = $month\_info-\>total \* $ex-\>cost; } elseif($ex-\>type == 'p') { /\* percent of gross per month \*/ $ex-\>total = $month\_info-\>gross \* ($ex-\>cost / 100); } elseif($ex-\>type == 'g') { /\* perfect revenue, per flight \*/ $ex-\>total = $month\_info-\>gross \* ($ex-\>cost / 100); } $running\_total += $ex-\>total; } $month\_info-\>expenses = $expenses; $month\_info-\>expenses\_total = $running\_total; $month\_info-\>pilotpay = $pilot\_pay; $month\_info-\>revenue = $month\_info-\>gross - $month\_info-\>fuelprice - $month\_info-\>pilotpay - $running\_total; return $month\_info; } /\*\* \* FinanceData::getExpensesForMonth() \* \* @param mixed $timestamp \* @return \*/ public static function getExpensesForMonth($timestamp) { $time = date('Ym', $timestamp); # If it's the current month, just return the latest expenses if ($time == date('Ym')) { return self::getAllExpenses(); } $sql = 'SELECT \* FROM ' . TABLE\_PREFIX . 'expenselog WHERE `dateadded`=' . $time; $ret = DB::get\_results($sql); if(!$ret) { return array(); } return $ret; } /\*\* \* FinanceData::setExpensesforMonth() \* \* @param mixed $timestamp \* @return \*/ public static function setExpensesforMonth($timestamp) { $all\_expenses = self::getAllExpenses(); if(!$all\_expenses || count($all\_expenses) == 0) { return true; } # Remove expenses first self::removeExpensesforMonth($timestamp); $time = date('Ym', $timestamp); foreach ($all\_expenses as $expense) { $sql = 'INSERT INTO ' . TABLE\_PREFIX . "expenselog (`dateadded`, `name`, `type`, `cost`) VALUES ('{$time}', '{$expense-\>name}', '{$expense-\>type}', '{$expense-\>cost}');"; DB::query($sql); } } /\*\* \* Populates any expenses which are missing from the table \* Goes month by month \* \*/ public static function updateAllExpenses() { $times = StatsData::GetMonthsSinceStart(); foreach ($times as $timestamp) { $exp = self::getExpensesForMonth($timestamp); if (!$exp) { self::setExpensesforMonth($timestamp); } } } /\*\* \* Re-populates all expenses, deleteing all the old ones \* \* @return mixed This is the return value description \* \*/ public static function populateAllExpenses() { $times = StatsData::GetMonthsSinceStart(); foreach ($times as $timestamp) { self::setExpensesforMonth($timestamp); } } /\*\* \* FinanceData::removeExpensesforMonth() \* \* @param mixed $timestamp \* @return void \*/ public static function removeExpensesforMonth($timestamp) { $time = date('Ym', $timestamp); $sql = 'DELETE FROM ' . TABLE\_PREFIX . 'expenselog WHERE `dateadded`=' . $time; DB::query($sql); } /\*\* \* Get a list of all the expenses \*/ public static function getAllExpenses() { $sql = 'SELECT \* FROM ' . TABLE\_PREFIX . 'expenses'; $res = DB::get\_results($sql); if(!$res) { return array(); } return $res; } /\*\* \* Get an expense details based on ID \*/ public static function getExpenseDetail($id) { $sql = 'SELECT \* FROM ' . TABLE\_PREFIX . 'expenses WHERE `id`=' . $id; return DB::get\_row($sql); } /\*\* \* Get an expense by the name (mainly to check for \* duplicates) \*/ public static function getExpenseByName($name) { $sql = 'SELECT \* FROM ' . TABLE\_PREFIX . 'expenses WHERE `name`=' . $name; return DB::get\_row($sql); } /\*\* \* Get all of the expenses for a flight \*/ public static function getFlightExpenses() { $sql = "SELECT \* FROM " . TABLE\_PREFIX . "expenses WHERE `type`='F'"; return DB::get\_results($sql); } /\*\* \* Get any percentage expenses per flight \* \*/ public static function getFlightPercentExpenses() { $sql = "SELECT \* FROM " . TABLE\_PREFIX . "expenses WHERE `type`='G'"; return DB::get\_results($sql); } /\*\* \* Add an expense \*/ public static function addExpense($name, $cost, $type) { if ($name == '' || $cost == '') { self::$lasterror = 'Name and cost must be entered'; return false; } $name = DB::escape($name); $cost = DB::escape($cost); $type = strtoupper($type); if ($type == '') $type = 'M'; // Default as monthly $sql = 'INSERT INTO ' . TABLE\_PREFIX . "expenses (`name`, `cost`, `type`) VALUES('$name', '$cost', '$type')"; DB::query($sql); if (DB::errno() != 0) return false; return true; } /\*\* \* Edit a certain expense \*/ public static function editExpense($id, $name, $cost, $type) { if ($name == '' || $cost == '') { self::$lasterror = 'Name and cost must be entered'; return false; } $name = DB::escape($name); $cost = DB::escape($cost); $type = strtoupper($type); if ($type == '') $type = 'M'; // Default as monthly $sql = 'UPDATE ' . TABLE\_PREFIX . "expenses SET `name`='$name', `cost`='$cost', `type`='$type' WHERE `id`=$id"; DB::query($sql); if (DB::errno() != 0) return false; return true; } /\*\* \* Delete an expense \*/ public static function removeExpense($id) { $sql = 'DELETE FROM ' . TABLE\_PREFIX . 'expenses WHERE `id`=' . $id; DB::query($sql); } /\*\* \* Get the active load count based on the load factor \* based on the flight type: P(assenger), C(argo), H(Charter) \*/ public static function getLoadCount($aircraft\_id, $flighttype = 'P') { $flighttype = strtoupper($flighttype); # Calculate our load factor for this flight # Charter flights always will have a 100% capacity if ($flighttype == 'H') { $load = 100; } else { # Not a charter $loadfactor = intval(Config::Get('LOAD\_FACTOR')); $load = rand($loadfactor - LOAD\_VARIATION, $loadfactor + LOAD\_VARIATION); # Don't allow a load of more than 95% if ($load \> 95) $load = 95; elseif ($load \<= 0) $load = 92; # Use ATA standard of 72% } /\* \* Get the maximum allowed based on the aircraft flown \*/ $aircraft = OperationsData::GetAircraftInfo($aircraft\_id); if (!$aircraft) # Aircraft doesn't exist { if ($flighttype == 'C') # Check cargo if cargo flight $count = Config::Get('DEFAULT\_MAX\_CARGO\_LOAD'); else $count = Config::Get('DEFAULT\_MAX\_PAX\_LOAD'); } else { if ($flighttype == 'C') # Check cargo if cargo flight $count = $aircraft-\>maxcargo; else $count = $aircraft-\>maxpax; } $load = ($load / 100); $currload = ceil($count \* $load); return $currload; } }
Thank you so much.