From ae16a2b14f524255775207e4b3f13e806d5b63e3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 2 Jan 2015 18:48:06 +0100 Subject: [PATCH] Routes and views for transactions without a budget / category [skip ci] --- app/controllers/BudgetController.php | 14 +++++++++- app/controllers/CategoryController.php | 14 ++++++++++ app/controllers/GoogleChartController.php | 2 +- app/lib/FireflyIII/Database/Budget/Budget.php | 28 ++++++++++++++++--- .../Database/Budget/BudgetInterface.php | 11 +++++++- .../FireflyIII/Database/Category/Category.php | 20 +++++++++++++ app/routes.php | 2 ++ app/views/budgets/index.blade.php | 12 ++++++++ app/views/budgets/noBudget.blade.php | 24 ++++++++++++++++ app/views/categories/noCategory.blade.php | 24 ++++++++++++++++ 10 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 app/views/budgets/noBudget.blade.php create mode 100644 app/views/categories/noCategory.blade.php diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index c2888d1eab..500ed85573 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -124,6 +124,19 @@ class BudgetController extends BaseController return View::make('budgets.index', compact('budgetMaximum', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); } + /** + * @return \Illuminate\View\View + */ + public function noBudget() + { + $start = \Session::get('start', Carbon::now()->startOfMonth()); + $end = \Session::get('end', Carbon::now()->startOfMonth()); + $list = $this->_repository->journalsNoBudget($start, $end); + $subTitle = 'Transactions without a budget in ' . $start->format('F Y'); + + return View::make('budgets.noBudget', compact('list', 'subTitle')); + } + /** * @return \Illuminate\Http\RedirectResponse */ @@ -189,7 +202,6 @@ class BudgetController extends BaseController return Redirect::route('budgets.create')->withInput(); } - /** * @param Budget $budget * diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php index 9994e30e2d..8459b4c40f 100644 --- a/app/controllers/CategoryController.php +++ b/app/controllers/CategoryController.php @@ -1,4 +1,5 @@ with('subTitle', 'Create a new category'); } + /** + * @return \Illuminate\View\View + */ + public function noCategory() + { + $start = \Session::get('start', Carbon::now()->startOfMonth()); + $end = \Session::get('end', Carbon::now()->startOfMonth()); + $list = $this->_repository->journalsNoCategory($start, $end); + $subTitle = 'Transactions without a category in ' . $start->format('F Y'); + + return View::make('categories.noCategory', compact('list', 'subTitle')); + } + /** * @param Category $category * diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index 8edd0fe797..f413c9c5a3 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -155,7 +155,7 @@ class GoogleChartController extends BaseController } } - $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange($this->_start, $this->_end); + $noBudgetSet = $bdt->expenseNoBudget($this->_start, $this->_end); $sum = $noBudgetSet->sum('amount') * -1; $this->_chart->addRow('No budget', 0, $sum); $this->_chart->generate(); diff --git a/app/lib/FireflyIII/Database/Budget/Budget.php b/app/lib/FireflyIII/Database/Budget/Budget.php index 070a39adc2..848a93f59b 100644 --- a/app/lib/FireflyIII/Database/Budget/Budget.php +++ b/app/lib/FireflyIII/Database/Budget/Budget.php @@ -10,7 +10,7 @@ use FireflyIII\Exception\NotImplementedException; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use Illuminate\Database\Query\Builder; +use Illuminate\Database\Query\Builder as QueryBuilder; /** * Class Budget @@ -258,7 +258,7 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf * * @return Collection */ - public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end) + public function expenseNoBudget(Carbon $start, Carbon $end) { // Add expenses that have no budget: return $this->getUser() @@ -269,8 +269,8 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf ->select('transaction_journals.id') ->from('transaction_journals') ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')); + ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00')); } ) ->before($end) @@ -280,6 +280,26 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf ->get(); } + /** + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function journalsNoBudget(Carbon $start, Carbon $end) + { + $set = $this->getUser() + ->transactionjournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('budget_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date') + ->get(['transaction_journals.*']); + + return $set; + } + /** * @param \Budget $budget * @param Carbon $date diff --git a/app/lib/FireflyIII/Database/Budget/BudgetInterface.php b/app/lib/FireflyIII/Database/Budget/BudgetInterface.php index f001cdd7a3..b81b786c85 100644 --- a/app/lib/FireflyIII/Database/Budget/BudgetInterface.php +++ b/app/lib/FireflyIII/Database/Budget/BudgetInterface.php @@ -26,6 +26,15 @@ interface BudgetInterface * * @return Collection */ - public function transactionsWithoutBudgetInDateRange(Carbon $start, Carbon $end); + public function expenseNoBudget(Carbon $start, Carbon $end); + + /** + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function journalsNoBudget(Carbon $start, Carbon $end); + } diff --git a/app/lib/FireflyIII/Database/Category/Category.php b/app/lib/FireflyIII/Database/Category/Category.php index a928c2d34e..873ac9c312 100644 --- a/app/lib/FireflyIII/Database/Category/Category.php +++ b/app/lib/FireflyIII/Database/Category/Category.php @@ -175,6 +175,26 @@ class Category implements CUDInterface, CommonDatabaseCallsInterface } + /** + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function journalsNoCategory(Carbon $start, Carbon $end) + { + $set = $this->getUser() + ->transactionjournals() + ->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->whereNull('category_transaction_journal.id') + ->before($end) + ->after($start) + ->orderBy('transaction_journals.date') + ->get(['transaction_journals.*']); + + return $set; + } + /** * @param \Category $category * @param Carbon $date diff --git a/app/routes.php b/app/routes.php index 9513bb3e20..fdbe6b1bce 100644 --- a/app/routes.php +++ b/app/routes.php @@ -196,6 +196,7 @@ Route::group( Route::get('/budgets/edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']); Route::get('/budgets/delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']); Route::get('/budgets/show/{budget}/{limitrepetition?}', ['uses' => 'BudgetController@show', 'as' => 'budgets.show']); + Route::get('/budgets/list/noBudget', ['uses' => 'BudgetController@noBudget','as' => 'budgets.noBudget']); // category controller: Route::get('/categories', ['uses' => 'CategoryController@index', 'as' => 'categories.index']); @@ -203,6 +204,7 @@ Route::group( Route::get('/categories/edit/{category}', ['uses' => 'CategoryController@edit', 'as' => 'categories.edit']); Route::get('/categories/delete/{category}', ['uses' => 'CategoryController@delete', 'as' => 'categories.delete']); Route::get('/categories/show/{category}', ['uses' => 'CategoryController@show', 'as' => 'categories.show']); + Route::get('/categories/list/noCategory', ['uses' => 'CategoryController@noCategory','as' => 'categories.noBudget']); // currency controller Route::get('/currency', ['uses' => 'CurrencyController@index', 'as' => 'currency.index']); diff --git a/app/views/budgets/index.blade.php b/app/views/budgets/index.blade.php index 2b5f62be48..5221602386 100644 --- a/app/views/budgets/index.blade.php +++ b/app/views/budgets/index.blade.php @@ -51,6 +51,18 @@
@include('partials.date_nav') + +
diff --git a/app/views/budgets/noBudget.blade.php b/app/views/budgets/noBudget.blade.php new file mode 100644 index 0000000000..dea483315f --- /dev/null +++ b/app/views/budgets/noBudget.blade.php @@ -0,0 +1,24 @@ +@extends('layouts.default') +@section('content') +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }} +
+
+ + @include('partials.date_nav') +
+
+
+
+
+
+ {{{$subTitle}}} +
+
+ @include('list.journals-full',['journals' => $list]) +
+
+
+
+ + +@stop diff --git a/app/views/categories/noCategory.blade.php b/app/views/categories/noCategory.blade.php new file mode 100644 index 0000000000..dea483315f --- /dev/null +++ b/app/views/categories/noCategory.blade.php @@ -0,0 +1,24 @@ +@extends('layouts.default') +@section('content') +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }} +
+
+ + @include('partials.date_nav') +
+
+
+
+
+
+ {{{$subTitle}}} +
+
+ @include('list.journals-full',['journals' => $list]) +
+
+
+
+ + +@stop