Default value for when session is empty.

This commit is contained in:
James Cole
2014-12-13 13:07:32 +01:00
parent d3cda8811d
commit 9ab0a83f7c
8 changed files with 28 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
<?php
use Carbon\Carbon;
use FireflyIII\Database\Budget as BudgetRepository;
use FireflyIII\Shared\Preferences\PreferencesInterface as Pref;
@@ -43,7 +44,7 @@ class BudgetController extends BaseController
public function amount(Budget $budget)
{
$amount = intval(Input::get('amount'));
$date = Session::get('start');
$date = Session::get('start',Carbon::now()->startOfMonth());
$limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount);
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition->id]);
@@ -111,16 +112,16 @@ class BudgetController extends BaseController
$budgets->each(
function (Budget $budget) {
/** @noinspection PhpUndefinedFieldInspection */
$budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start'));
$budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start',Carbon::now()->startOfMonth()));
/** @noinspection PhpUndefinedFieldInspection */
$budget->currentRep = $budget->limitrepetitions()->where('limit_repetitions.startdate', \Session::get('start')->format('Y-m-d'))->first(
$budget->currentRep = $budget->limitrepetitions()->where('limit_repetitions.startdate', \Session::get('start',Carbon::now()->startOfMonth())->format('Y-m-d'))->first(
['limit_repetitions.*']
);
}
);
$spent = $budgets->sum('spent');
$amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start')->format('FY'), 1000)->data;
$amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start',Carbon::now()->startOfMonth())->format('FY'), 1000)->data;
$overspent = $spent > $amount;
$spentPCT = $overspent ? ceil($amount / $spent * 100) : ceil($spent / $amount * 100);
@@ -132,7 +133,7 @@ class BudgetController extends BaseController
*/
public function postUpdateIncome()
{
$this->_preferences->set('budgetIncomeTotal' . Session::get('start')->format('FY'), intval(Input::get('amount')));
$this->_preferences->set('budgetIncomeTotal' . Session::get('start',Carbon::now()->startOfMonth())->format('FY'), intval(Input::get('amount')));
return Redirect::route('budgets.index');
}
@@ -151,7 +152,7 @@ class BudgetController extends BaseController
$hideBudget = true; // used in transaction list.
$journals = $this->_repository->getJournals($budget, $repetition);
$limits = $repetition ? $budget->limits()->orderBy('startdate', 'DESC')->get() : [$repetition->limit];
$limits = $repetition ? [$repetition->limit] : $budget->limits()->orderBy('startdate', 'DESC')->get();
$subTitle = $repetition ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name);
return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget'));
@@ -243,7 +244,7 @@ class BudgetController extends BaseController
*/
public function updateIncome()
{
$budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start')->format('FY'), 1000);
$budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start',Carbon::now()->startOfMonth())->format('FY'), 1000);
return View::make('budgets.income')->with('amount', $budgetAmount);
}