Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Optimized some views and fixed tests for #595
James Cole0c52d54d7d6d
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.phpindex 9d79bfd7cf..8205914831 100644--- a/app/Http/Controllers/BudgetController.php+++ b/app/Http/Controllers/BudgetController.php@@ -22,6 +22,7 @@ use FireflyIII\Http\Requests\BudgetIncomeRequest;use FireflyIII\Models\AccountType;use FireflyIII\Models\Budget;use FireflyIII\Models\BudgetLimit;+use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;@@ -215,7 +216,10 @@ class BudgetController extends Controllerif (strlen($moment) > 0 && $moment !== 'all') {$start = new Carbon($moment);$end = Navigation::endOfPeriod($start, $range);- $subTitle = trans('firefly.without_budget_between', ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]);+ $subTitle = trans(+ 'firefly.without_budget_between',+ ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]+ );$periods = $this->noBudgetPeriodEntries();}@@ -242,7 +246,8 @@ class BudgetController extends ControllerLog::info('Count is zero, search for journals.');/** @var JournalCollectorInterface $collector */$collector = app(JournalCollectorInterface::class);- $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutBudget()->withOpposingAccount();+ $collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)+ ->withoutBudget()->withOpposingAccount();$journals = $collector->getPaginatedJournals();$journals->setPath('/budgets/list/no-budget');$count = $journals->getCollection()->count();@@ -256,7 +261,10 @@ class BudgetController extends Controller// fix title:if ((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) {- $subTitle = trans('firefly.without_budget_between', ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]);+ $subTitle = trans(+ 'firefly.without_budget_between',+ ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]+ );}return view('budgets.no-budget', compact('journals', 'subTitle', 'moment', 'periods', 'start', 'end'));@@ -520,11 +528,21 @@ class BudgetController extends Controller// count journals without budget in this period:/** @var JournalCollectorInterface $collector */$collector = app(JournalCollectorInterface::class);- $collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutBudget()->withOpposingAccount();- $journals = $collector->getJournals()->count();+ $collector->setAllAssetAccounts()->setRange($end, $currentEnd)->withoutBudget()->withOpposingAccount()->setTypes([TransactionType::WITHDRAWAL]);+ $set = $collector->getJournals();+ $sum = $set->sum('transaction_amount');+ $journals = $set->count();$dateStr = $end->format('Y-m-d');$dateName = Navigation::periodShow($end, $range);- $entries->push([$dateStr, $dateName, $journals, clone $end]);+ $entries->push(+ [+ 'string' => $dateStr,+ 'name' => $dateName,+ 'count' => $journals,+ 'sum' => $sum,+ 'date' => clone $end,+ ]+ );$end = Navigation::subtractPeriod($end, $range, 1);}$cache->store($entries);diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.phpindex 1d79655dd1..6ef2d16b4b 100644--- a/app/Http/breadcrumbs.php+++ b/app/Http/breadcrumbs.php@@ -91,7 +91,7 @@ Breadcrumbs::register(Breadcrumbs::register('accounts.delete', function (BreadCrumbGenerator $breadcrumbs, Account $account) {- $breadcrumbs->parent('accounts.show', $account);+ $breadcrumbs->parent('accounts.show', $account, '', new Carbon, new Carbon);$breadcrumbs->push(trans('firefly.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id]));});@@ -99,7 +99,7 @@ Breadcrumbs::register(Breadcrumbs::register('accounts.edit', function (BreadCrumbGenerator $breadcrumbs, Account $account) {- $breadcrumbs->parent('accounts.show', $account);+ $breadcrumbs->parent('accounts.show', $account, '', new Carbon, new Carbon);$what = config('firefly.shortNamesByFullName.' . $account->accountType->type);$breadcrumbs->push(trans('firefly.edit_' . $what . '_account', ['name' => e($account->name)]), route('accounts.edit', [$account->id]));diff --git a/resources/views/accounts/delete.twig b/resources/views/accounts/delete.twigindex 7203d40a25..97a6fab792 100644--- a/resources/views/accounts/delete.twig+++ b/resources/views/accounts/delete.twig@@ -1,7 +1,9 @@{% extends "./layout/default" %}{% block breadcrumbs %}- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute().getName(), account) }}++ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, account) }}+ {{ Route.getCurrentRoute.getName }}{% endblock %}{% block content %}diff --git a/resources/views/budgets/no-budget.twig b/resources/views/budgets/no-budget.twigindex 20166e601d..1b169a6270 100644--- a/resources/views/budgets/no-budget.twig+++ b/resources/views/budgets/no-budget.twig@@ -41,16 +41,20 @@{% if periods.count > 0 %}<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">{% for entry in periods %}- <div class="box {% if entry[3] == start %}box-solid box-primary{% endif %}">+ <div class="box {% if entry.date == start %}box-solid box-primary{% endif %}"><div class="box-header with-border">- <h3 class="box-title"><a href="{{ route('budgets.no-budget',[entry[0]]) }}">{{ entry[1] }}</a>+ <h3 class="box-title"><a href="{{ route('budgets.no-budget',[entry.string]) }}">{{ entry.name }}</a></h3></div><div class="box-body no-padding"><table class="table table-hover"><tr><td style="width:33%;">{{ 'transactions'|_ }}</td>- <td style="text-align: right;">{{ entry[2] }}</td>+ <td style="text-align: right;">{{ entry.count }}</td>+ </tr>+ <tr>+ <td style="width:33%;">{{ 'sum'|_ }}</td>+ <td style="text-align: right;">{{ entry.sum|formatAmount }}</td></tr></table></div>diff --git a/routes/web.php b/routes/web.phpindex 2d94859db5..6abaca3534 100755--- a/routes/web.php+++ b/routes/web.php@@ -86,7 +86,6 @@ Route::group(Route::get('create/{what}', ['uses' => 'AccountController@create', 'as' => 'create'])->where('what', 'revenue|asset|expense');Route::get('edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'edit']);Route::get('delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'delete']);-Route::get('show/{account}/{moment?}', ['uses' => 'AccountController@show', 'as' => 'show']);Route::post('store', ['uses' => 'AccountController@store', 'as' => 'store']);diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.phpindex 50f4ece96f..aeec1e506b 100644--- a/tests/Feature/Controllers/AccountControllerTest.php+++ b/tests/Feature/Controllers/AccountControllerTest.php@@ -158,8 +158,8 @@ class AccountControllerTest extends TestCase$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');$repository = $this->mock(AccountRepositoryInterface::class);- $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date);- $repository->shouldReceive('getAccountsByType')->andReturn(new Collection);+ $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();+ $repository->shouldReceive('getAccountsByType')->andReturn(new Collection)->once();$transaction = factory(Transaction::class)->make();$collector = $this->mock(JournalCollectorInterface::class);@@ -190,7 +190,7 @@ class AccountControllerTest extends TestCase$transaction = factory(Transaction::class)->make();$collector = $this->mock(JournalCollectorInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);- $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);+ $journalRepos->shouldReceive('first')->twice()->andReturn(new TransactionJournal);$collector->shouldReceive('setAccounts')->andReturnSelf();$collector->shouldReceive('setRange')->andReturnSelf();$collector->shouldReceive('setLimit')->andReturnSelf();@@ -202,10 +202,6 @@ class AccountControllerTest extends TestCase$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');- $repository = $this->mock(AccountRepositoryInterface::class);- $repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon)->once();- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->once()->andReturn(new Collection);-$this->be($this->user());$this->changeDateRange($this->user(), $range);$response = $this->get(route('accounts.show', [1, 'all']));@@ -253,14 +249,14 @@ class AccountControllerTest extends TestCase$tasker = $this->mock(AccountTaskerInterface::class);$repository = $this->mock(AccountRepositoryInterface::class);- $repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon);+ $repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon)->once();$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->once()->andReturn(new Collection);$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');$this->be($this->user());$this->changeDateRange($this->user(), $range);- $response = $this->get(route('accounts.show.date', [1, '2016-01-01']));+ $response = $this->get(route('accounts.show', [1, '2016-01-01']));$response->assertStatus(200);// has bread crumb$response->assertSee('<ol class="breadcrumb">');@@ -293,7 +289,7 @@ class AccountControllerTest extends TestCase$this->be($this->user());$this->changeDateRange($this->user(), $range);- $response = $this->get(route('accounts.show.date', [1, '2016-01-01']));+ $response = $this->get(route('accounts.show', [1, '2016-01-01']));$response->assertStatus(200);// has bread crumb$response->assertSee('<ol class="breadcrumb">');diff --git a/tests/Feature/Controllers/BudgetControllerTest.php b/tests/Feature/Controllers/BudgetControllerTest.phpindex fca3c8dc29..2e7fe63d5e 100644--- a/tests/Feature/Controllers/BudgetControllerTest.php+++ b/tests/Feature/Controllers/BudgetControllerTest.php@@ -159,7 +159,9 @@ class BudgetControllerTest extends TestCase$collector->shouldReceive('getJournals')->andReturn(new Collection);$collector->shouldReceive('setLimit')->andReturnSelf();$collector->shouldReceive('setPage')->andReturnSelf();+ $collector->shouldReceive('setTypes')->andReturnSelf();$collector->shouldReceive('withoutBudget')->andReturnSelf();+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf();$collector->shouldReceive('withCategoryInformation')->andReturnSelf();$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));@@ -190,8 +192,11 @@ class BudgetControllerTest extends TestCase$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();$collector->shouldReceive('setRange')->andReturnSelf();$collector->shouldReceive('setLimit')->andReturnSelf();+ $collector->shouldReceive('setTypes')->andReturnSelf();$collector->shouldReceive('setPage')->andReturnSelf();+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf();$collector->shouldReceive('withoutBudget')->andReturnSelf();+ $collector->shouldReceive('setTypes')->andReturnSelf();$collector->shouldReceive('withCategoryInformation')->andReturnSelf();$collector->shouldReceive('getJournals')->andReturn(new Collection);$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));@@ -226,6 +231,8 @@ class BudgetControllerTest extends TestCase$collector->shouldReceive('getJournals')->andReturn(new Collection);$collector->shouldReceive('setLimit')->andReturnSelf();$collector->shouldReceive('setPage')->andReturnSelf();+ $collector->shouldReceive('withOpposingAccount')->andReturnSelf();+ $collector->shouldReceive('setTypes')->andReturnSelf();$collector->shouldReceive('withoutBudget')->andReturnSelf();$collector->shouldReceive('withCategoryInformation')->andReturnSelf();$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));