diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 62c2bb1372..1a90a92afd 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -1,5 +1,6 @@ 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); } diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index 29b6dd02cb..16ab897861 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -31,7 +31,7 @@ class GoogleChartController extends BaseController $this->_chart->addColumn('Day of month', 'date'); $this->_chart->addColumn('Balance for ' . $account->name, 'number'); - $start = Session::get('start'); + $start = Session::get('start',Carbon::now()->startOfMonth()); $end = Session::get('end'); $count = $account->transactions()->count(); @@ -79,14 +79,14 @@ class GoogleChartController extends BaseController switch ($view) { default: case 'session': - $start = Session::get('start'); + $start = Session::get('start',Carbon::now()->startOfMonth()); $end = Session::get('end'); break; case 'all': $first = $account->transactionjournals()->orderBy('date', 'DESC')->first(); $last = $account->transactionjournals()->orderBy('date', 'ASC')->first(); if (is_null($first)) { - $start = Session::get('start'); + $start = Session::get('start',Carbon::now()->startOfMonth()); } else { $start = clone $first->date; } @@ -161,7 +161,7 @@ class GoogleChartController extends BaseController ['transactionjournal', 'transactionjournal.transactions', 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories'] )->before(Session::get('end'))->after( - Session::get('start') + Session::get('start',Carbon::now()->startOfMonth()) )->get(); /** @var Transaction $transaction */ @@ -235,7 +235,7 @@ class GoogleChartController extends BaseController /* * Loop the date, then loop the accounts, then add balance. */ - $start = Session::get('start'); + $start = Session::get('start',Carbon::now()->startOfMonth()); $end = Session::get('end'); $current = clone $start; @@ -281,14 +281,14 @@ class GoogleChartController extends BaseController * Is there a repetition starting on this particular date? We can use that. */ /** @var \LimitRepetition $repetition */ - $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start')); + $repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start',Carbon::now()->startOfMonth())); /* * If there is, use it. Otherwise, forget it. */ if (is_null($repetition)) { // use the session start and end for our search query - $searchStart = Session::get('start'); + $searchStart = Session::get('start',Carbon::now()->startOfMonth()); $searchEnd = Session::get('end'); // the limit is zero: $limit = 0; @@ -315,7 +315,7 @@ class GoogleChartController extends BaseController * Finally, get all transactions WITHOUT a budget and add those as well. * (yes this method is oddly specific). */ - $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start'), Session::get('end')); + $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start',Carbon::now()->startOfMonth()), Session::get('end')); $sum = $noBudgetSet->sum('amount') * -1; $chart->addRow('No budget', 0, $sum); @@ -343,7 +343,7 @@ class GoogleChartController extends BaseController /* * Get the journals: */ - $journals = $tj->getInDateRange(Session::get('start'), Session::get('end')); + $journals = $tj->getInDateRange(Session::get('start',Carbon::now()->startOfMonth()), Session::get('end')); /** @var \TransactionJournal $journal */ foreach ($journals as $journal) { @@ -627,7 +627,7 @@ class GoogleChartController extends BaseController /* * In the current session range? */ - if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start')) { + if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start',Carbon::now()->startOfMonth())) { /* * Lets see if we've already spent money on this recurring transaction (it hath recurred). */ diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 9617608efc..217068e007 100644 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -1,4 +1,5 @@ countAssetAccounts(); - $start = Session::get('start'); - $end = Session::get('end'); + $start = Session::get('start', Carbon::now()->startOfMonth()); + $end = Session::get('end', Carbon::now()->endOfMonth()); // get the preference for the home accounts to show: diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.php index dfaf035df3..70154a8072 100644 --- a/app/database/seeds/TestContentSeeder.php +++ b/app/database/seeds/TestContentSeeder.php @@ -37,7 +37,7 @@ class TestContentSeeder extends Seeder $billsBudget = Budget::create(['user_id' => $user->id, 'name' => 'Bills']); // create two categories: - $dailyGroceries = Category::create(['user_id' => $user->id, 'name' => 'Daily groceries']); + $dailyGroceries = Category::create(['user_id' => $user->id, 'name' => 'DailyGroceries']); $lunch = Category::create(['user_id' => $user->id, 'name' => 'Lunch']); $house = Category::create(['user_id' => $user->id, 'name' => 'House']); diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php index 3e26eb3aaf..5ccd858ec3 100644 --- a/app/lib/FireflyIII/Database/Account.php +++ b/app/lib/FireflyIII/Database/Account.php @@ -580,8 +580,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface ->orderBy('date', 'DESC'); if ($range == 'session') { - $query->before(\Session::get('end')); - $query->after(\Session::get('start')); + $query->before(\Session::get('end', \Carbon\Carbon::now()->startOfMonth())); + $query->after(\Session::get('start', \Carbon\Carbon::now()->startOfMonth())); } $count = $query->count(); $set = $query->take($limit)->offset($offset)->get(['transaction_journals.*']); diff --git a/app/views/budgets/income.blade.php b/app/views/budgets/income.blade.php index d5b70c4f93..d215db7269 100644 --- a/app/views/budgets/income.blade.php +++ b/app/views/budgets/income.blade.php @@ -4,7 +4,7 @@