diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index bdb3160ea7..93d8236629 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -226,24 +226,71 @@ class TagController extends Controller * * @return View */ - public function show(Request $request, JournalCollectorInterface $collector, Tag $tag, string $moment = '') + public function show(Request $request, JournalCollectorInterface $collector, Tag $tag) + { + $start = clone session('start', Carbon::now()->startOfMonth()); + $end = clone session('end', Carbon::now()->endOfMonth()); + $subTitle = $tag->tag; + $subTitleIcon = 'fa-tag'; + $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page')); + $pageSize = intval(Preferences::get('transactionPageSize', 50)->data); + $periods = $this->getPeriodOverview($tag); + + // use collector: + $collector->setAllAssetAccounts() + ->setLimit($pageSize)->setPage($page)->setTag($tag)->withOpposingAccount()->disableInternalFilter() + ->withBudgetInformation()->withCategoryInformation()->setRange($start, $end); + $journals = $collector->getPaginatedJournals(); + $journals->setPath('tags/show/' . $tag->id); + + $sum = $journals->sum( + function (Transaction $transaction) { + return $transaction->transaction_amount; + } + ); + + return view('tags.show', compact('tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end')); + } + + /** + * @param Request $request + * @param JournalCollectorInterface $collector + * @param Tag $tag + * + * @return View + */ + public function showAll(Request $request, JournalCollectorInterface $collector, Tag $tag) + { + $subTitle = $tag->tag; + $subTitleIcon = 'fa-tag'; + $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page')); + $pageSize = intval(Preferences::get('transactionPageSize', 50)->data); + $collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page)->setTag($tag) + ->withOpposingAccount()->disableInternalFilter() + ->withBudgetInformation()->withCategoryInformation(); + $journals = $collector->getPaginatedJournals(); + $journals->setPath('tags/show/' . $tag->id . '/all'); + + $sum = $journals->sum( + function (Transaction $transaction) { + return $transaction->transaction_amount; + } + ); + + return view('tags.show', compact('tag', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end')); + + } + + public function showByDate(Request $request, JournalCollectorInterface $collector, Tag $tag, string $date) { $range = Preferences::get('viewRange', '1M')->data; - $start = new Carbon; - $end = new Carbon; - if (strlen($moment) > 0) { - try { - $start = new Carbon($moment); - $end = Navigation::endOfPeriod($start, $range); - } catch (Exception $e) { - $start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range); - $end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range); - } - } - if (strlen($moment) === 0) { - $start = clone session('start', Carbon::now()->startOfMonth()); - $end = clone session('end', Carbon::now()->endOfMonth()); + try { + $start = new Carbon($date); + $end = Navigation::endOfPeriod($start, $range); + } catch (Exception $e) { + $start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range); + $end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range); } $subTitle = $tag->tag; @@ -254,7 +301,7 @@ class TagController extends Controller // use collector: $collector->setAllAssetAccounts() - ->setLimit($pageSize)->setPage($page)->setTag($tag) + ->setLimit($pageSize)->setPage($page)->setTag($tag)->withOpposingAccount()->disableInternalFilter() ->withBudgetInformation()->withCategoryInformation()->setRange($start, $end); $journals = $collector->getPaginatedJournals(); $journals->setPath('tags/show/' . $tag->id); diff --git a/resources/views/tags/show.twig b/resources/views/tags/show.twig index 720934948e..460247a426 100644 --- a/resources/views/tags/show.twig +++ b/resources/views/tags/show.twig @@ -75,13 +75,15 @@ -
-
-

{{ 'showEverything'|_ }}

+ {% if periods %} + -
+ {% endif %}
-
+

{{ 'transactions'|_ }}

@@ -100,45 +102,82 @@
+ + {% if periods %} +

+ + + {{ 'show_all_no_filter'|_ }} + +

+ {% else %} +

+ + + {{ 'show_the_current_period_and_overview'|_ }} + +

+ {% endif %} + {% include 'list/journals-tasker' %} + + {% if periods %} +

+ + + {{ 'show_all_no_filter'|_ }} + +

+ {% else %} +

+ + + {{ 'show_the_current_period_and_overview'|_ }} + +

+ {% endif %}
-
- {% for period in periods %} - {% if period.spent != 0 or period.earned != 0 %} -
-
-

{{ period.date_name }} -

+ {% if periods %} +
+ {% for period in periods %} + {% if period.spent != 0 or period.earned != 0 %} +
+ +
+ + {% if period.spent != 0 %} + + + + + {% endif %} + {% if period.earned != 0 %} + + + + + {% endif %} +
{{ 'spent'|_ }}{{ period.spent|formatAmount }}
{{ 'earned'|_ }}{{ period.earned|formatAmount }}
+
-
- - {% if period.spent != 0 %} - - - - - {% endif %} - {% if period.earned != 0 %} - - - - - {% endif %} -
{{ 'spent'|_ }}{{ period.spent|formatAmount }}
{{ 'earned'|_ }}{{ period.earned|formatAmount }}
-
-
- {% endif %} + {% endif %} - {% endfor %} -
+ {% endfor %} +
+ {% endif %}
-
-
-

{{ 'showEverything'|_ }}

+ {% if periods %} + -
+ {% endif %} {% endblock %} {% block scripts %} diff --git a/routes/web.php b/routes/web.php index c446a58ff9..92a108e5fe 100755 --- a/routes/web.php +++ b/routes/web.php @@ -601,7 +601,9 @@ Route::group( Route::get('', ['uses' => 'TagController@index', 'as' => 'index']); Route::get('create', ['uses' => 'TagController@create', 'as' => 'create']); - Route::get('show/{tag}/{date?}', ['uses' => 'TagController@show', 'as' => 'show']); + Route::get('show/{tag}/all', ['uses' => 'TagController@showAll', 'as' => 'show.all']); + Route::get('show/{tag}/{date}', ['uses' => 'TagController@showByDate', 'as' => 'show.date']); + Route::get('show/{tag}', ['uses' => 'TagController@show', 'as' => 'show']); Route::get('edit/{tag}', ['uses' => 'TagController@edit', 'as' => 'edit']); Route::get('delete/{tag}', ['uses' => 'TagController@delete', 'as' => 'delete']);