diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php index 7df97145b9..b6ce8a58bd 100644 --- a/app/controllers/ChartController.php +++ b/app/controllers/ChartController.php @@ -388,31 +388,32 @@ class ChartController extends BaseController ] ]; - - /* - * Get all budgets. - */ + // Get all budgets. $budgets = \Auth::user()->budgets()->orderBy('name', 'ASC')->get(); $budgetIds = []; /** @var \Budget $budget */ foreach ($budgets as $budget) { $budgetIds[] = $budget->id; - /* - * Does the budget have a limit starting on $start? - */ - $rep = \LimitRepetition:: + + // Does the budget have a limit starting on $start? + $rep = \LimitRepetition:: leftJoin('limits', 'limit_repetitions.limit_id', '=', 'limits.id')->leftJoin( 'components', 'limits.component_id', '=', 'components.id' )->where('limit_repetitions.startdate', $start->format('Y-m-d'))->where( 'components.id', $budget->id )->first(['limit_repetitions.*']); - $limit = is_null($rep) ? 0.0 : floatval($rep->amount); - $id = is_null($rep) ? null : $rep->id; - $parameter = is_null($rep) ? 'useSession=true' : ''; - /* - * Date range to check for expenses made? - */ + if (is_null($rep)) { + $limit = 0.0; + $id = null; + $parameter = 'useSession=true'; + } else { + $limit = floatval($rep->amount); + $id = $rep->id; + $parameter = ''; + } + + // Date range to check for expenses made? if (is_null($rep)) { // use the session start and end for our search query $expenseStart = Session::get('start'); @@ -423,17 +424,10 @@ class ChartController extends BaseController $expenseStart = $rep->startdate; $expenseEnd = $rep->enddate; } - /* - * How much have we spent on this budget? - */ - $expenses = $budget->transactionjournals()->before($expenseEnd)->after($expenseStart)->lessThan(0)->sum( - 'amount' - ); - $expenses = floatval($expenses) * -1; + // How much have we spent on this budget? + $expenses = floatval($budget->transactionjournals()->before($expenseEnd)->after($expenseStart)->lessThan(0)->sum('amount')) * -1; - /* - * Append to chart: - */ + // Append to chart: if ($limit > 0 || $expenses > 0) { $data['labels'][] = $budget->name; $data['series'][0]['data'][] = [ @@ -446,9 +440,7 @@ class ChartController extends BaseController ]; } } - /* - * Add expenses that have no budget: - */ + // Add expenses that have no budget: $set = \Auth::user()->transactionjournals()->whereNotIn( 'transaction_journals.id', function ($query) use ($start, $end) { $query->select('transaction_journals.id')->from('transaction_journals') @@ -462,11 +454,8 @@ class ChartController extends BaseController ->where('components.class', 'Budget'); } )->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->sum('amount'); - /* - * This can be debugged by using get(['transaction_journals.*','transactions.amount']); - * - * - */ + + // This can be debugged by using get(['transaction_journals.*','transactions.amount']); $data['labels'][] = 'No budget'; $data['series'][0]['data'][] = [ 'y' => 0, diff --git a/app/lib/Firefly/Exception/ValidationException.php b/app/lib/Firefly/Exception/ValidationException.php index 415a7119f3..95d464a640 100644 --- a/app/lib/Firefly/Exception/ValidationException.php +++ b/app/lib/Firefly/Exception/ValidationException.php @@ -1,11 +1,4 @@