diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 2e0758a4cf..c947e3612b 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -269,7 +269,7 @@ class AccountController extends Controller
'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
$chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d')]);
- $periods = $this->periodEntries($account);
+ $periods = $this->getPeriodOverview($account);
}
// prep for current period
@@ -280,7 +280,7 @@ class AccountController extends Controller
'firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $start->formatLocalized($this->monthAndDayFormat),
'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
- $periods = $this->periodEntries($account);
+ $periods = $this->getPeriodOverview($account);
}
$accountType = $account->accountType->type;
@@ -316,7 +316,9 @@ class AccountController extends Controller
}
- return view('accounts.show', compact('account','moment', 'accountType', 'periods', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
+ return view(
+ 'accounts.show', compact('account', 'moment', 'accountType', 'periods', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri')
+ );
}
/**
@@ -404,7 +406,7 @@ class AccountController extends Controller
*
* @return Collection
*/
- private function periodEntries(Account $account): Collection
+ private function getPeriodOverview(Account $account): Collection
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
@@ -441,7 +443,14 @@ class AccountController extends Controller
$earned = $tasker->amountInInPeriod(new Collection([$account]), $assets, $end, $currentEnd);
$dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range);
- $entries->push([$dateStr, $dateName, $spent, $earned, clone $end]);
+ $entries->push(
+ [
+ 'string' => $dateStr,
+ 'name' => $dateName,
+ 'spent' => $spent,
+ 'earned' => $earned,
+ 'date' => clone $end]
+ );
$end = Navigation::subtractPeriod($end, $range, 1);
}
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index e82386126d..5f5a3f1cc5 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -220,14 +220,14 @@ class BudgetController extends Controller
'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
- $periods = $this->noBudgetPeriodEntries();
+ $periods = $this->getPeriodOverview();
}
// prep for current period
if (strlen($moment) === 0) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
- $periods = $this->noBudgetPeriodEntries();
+ $periods = $this->getPeriodOverview();
$subTitle = trans(
'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -500,7 +500,7 @@ class BudgetController extends Controller
/**
* @return Collection
*/
- private function noBudgetPeriodEntries(): Collection
+ private function getPeriodOverview(): Collection
{
$repository = app(JournalRepositoryInterface::class);
$first = $repository->first();
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index b625c634b8..e67e71e1b1 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -180,14 +180,14 @@ class CategoryController extends Controller
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
- $periods = $this->noCategoryPeriodEntries();
+ $periods = $this->getNoCategoryPeriodOverview();
}
// prep for current period
if (strlen($moment) === 0) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
- $periods = $this->noCategoryPeriodEntries();
+ $periods = $this->getNoCategoryPeriodOverview();
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -231,18 +231,16 @@ class CategoryController extends Controller
}
/**
- * @param Request $request
- * @param JournalCollectorInterface $collector
- * @param Category $category
- * @param string $moment
+ * @param Request $request
+ * @param CategoryRepositoryInterface $repository
+ * @param Category $category
+ * @param string $moment
*
* @return View
*/
- public function show(Request $request, JournalCollectorInterface $collector, Category $category, string $moment = '')
+ public function show(Request $request, CategoryRepositoryInterface $repository, Category $category, string $moment = '')
{
// default values:
- /** @var CategoryRepositoryInterface $repository */
- $repository = app(CategoryRepositoryInterface::class);
$subTitle = $category->name;
$subTitleIcon = 'fa-bar-chart';
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
@@ -271,21 +269,21 @@ class CategoryController extends Controller
['name' => $category->name,
'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
- $periods = $this->periodEntries($category);
+ $periods = $this->getPeriodOverview($category);
}
// prep for current period
if (strlen($moment) === 0) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
- $periods = $this->periodEntries($category);
+ $periods = $this->getPeriodOverview($category);
$subTitle = trans(
'firefly.journals_in_period_for_category',
['name' => $category->name,'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
}
// grab journals, but be prepared to jump a period back to get the right ones:
- Log::info('Now at transaction loop start.');
+ Log::info('Now at category loop start.');
while ($count === 0 && $loop < 3) {
$loop++;
Log::info('Count is zero, search for journals.');
@@ -427,7 +425,7 @@ class CategoryController extends Controller
/**
* @return Collection
*/
- private function noCategoryPeriodEntries(): Collection
+ private function getNoCategoryPeriodOverview(): Collection
{
$repository = app(JournalRepositoryInterface::class);
$first = $repository->first();
@@ -504,7 +502,7 @@ class CategoryController extends Controller
*
* @return Collection
*/
- private function periodEntries(Category $category): Collection
+ private function getPeriodOverview(Category $category): Collection
{
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index a8b5a4d50a..f348445c18 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -14,15 +14,14 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
-use Exception;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Http\Requests\TagFormRequest;
use FireflyIII\Models\Tag;
-use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
+use Log;
use Navigation;
use Preferences;
use Session;
@@ -228,95 +227,145 @@ class TagController extends Controller
*
* @return View
*/
- public function show(Request $request, JournalCollectorInterface $collector, Tag $tag)
+ public function show(Request $request, TagRepositoryInterface $repository, Tag $tag, string $moment = '')
{
- $start = clone session('start', Carbon::now()->startOfMonth());
- $end = clone session('end', Carbon::now()->endOfMonth());
+ // default values:
$subTitle = $tag->tag;
$subTitleIcon = 'fa-tag';
- $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
+ $page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
- $periods = $this->getPeriodOverview($tag);
+ $count = 0;
+ $loop = 0;
+ $range = Preferences::get('viewRange', '1M')->data;
+ $start = null;
+ $end = null;
+ $periods = new Collection;
- // 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;
-
- 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);
+ // prep for "all" view.
+ if ($moment === 'all') {
+ $subTitle = trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]);
+ $start = $repository->firstUseDate($tag);
+ $end = new Carbon;
}
- $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);
+ // prep for "specific date" view.
+ if (strlen($moment) > 0 && $moment !== 'all') {
+ $start = new Carbon($moment);
+ $end = Navigation::endOfPeriod($start, $range);
+ $subTitle = trans(
+ 'firefly.journals_in_period_for_tag',
+ ['tag' => $tag->tag,
+ 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
+ );
+ $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;
+ // prep for current period
+ if (strlen($moment) === 0) {
+ $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
+ $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
+ $periods = $this->getPeriodOverview($tag);
+ $subTitle = trans(
+ 'firefly.journals_in_period_for_tag',
+ ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
+ );
+ }
+ // grab journals, but be prepared to jump a period back to get the right ones:
+ Log::info('Now at tag loop start.');
+ while ($count === 0 && $loop < 3) {
+ $loop++;
+ Log::info('Count is zero, search for journals.');
+ /** @var JournalCollectorInterface $collector */
+ $collector = app(JournalCollectorInterface::class);
+ $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
+ ->setTag($tag)->withBudgetInformation()->withCategoryInformation();
+ $journals = $collector->getPaginatedJournals();
+ $journals->setPath('tags/show/' . $tag->id);
+ $count = $journals->getCollection()->count();
+ if ($count === 0) {
+ $start->subDay();
+ $start = Navigation::startOfPeriod($start, $range);
+ $end = Navigation::endOfPeriod($start, $range);
+ Log::info(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d')));
}
- );
+ }
- return view('tags.show', compact('tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end'));
+ // fix title:
+ if (((strlen($moment) > 0 && $moment !== 'all') || strlen($moment) === 0) && $count > 0) {
+ $subTitle = trans(
+ 'firefly.journals_in_period_for_tag',
+ ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
+ );
+ }
+ $sum = '0';
+
+ return view('tags.show', compact('tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end', 'moment'));
}
+ // /**
+ // * @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;
+ //
+ // 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;
+ // $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 TagFormRequest $request
*
@@ -396,11 +445,11 @@ class TagController extends Controller
// get expenses and what-not in this period and this tag.
$arr = [
- 'date_string' => $end->format('Y-m-d'),
- 'date_name' => Navigation::periodShow($end, $range),
- 'date' => $end,
- 'spent' => $this->repository->spentInperiod($tag, $end, $currentEnd),
- 'earned' => $this->repository->earnedInperiod($tag, $end, $currentEnd),
+ 'string' => $end->format('Y-m-d'),
+ 'name' => Navigation::periodShow($end, $range),
+ 'date' => clone $end,
+ 'spent' => $this->repository->spentInperiod($tag, $end, $currentEnd),
+ 'earned' => $this->repository->earnedInperiod($tag, $end, $currentEnd),
];
$collection->push($arr);
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index 01066d5b8b..8159fe6b01 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -92,14 +92,14 @@ class TransactionController extends Controller
'firefly.title_' . $what . '_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
);
- $periods = $this->getPeriodEntries($what);
+ $periods = $this->getPeriodOverview($what);
}
// prep for current period
if (strlen($moment) === 0) {
$start = clone session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = clone session('end', Navigation::endOfPeriod(new Carbon, $range));
- $periods = $this->getPeriodEntries($what);
+ $periods = $this->getPeriodOverview($what);
$subTitle = trans(
'firefly.title_' . $what . '_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -193,7 +193,7 @@ class TransactionController extends Controller
* @return Collection
* @throws FireflyException
*/
- private function getPeriodEntries(string $what): Collection
+ private function getPeriodOverview(string $what): Collection
{
$repository = app(JournalRepositoryInterface::class);
$first = $repository->first();
diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig
index b4fe840ed1..39a1729876 100644
--- a/resources/views/accounts/show.twig
+++ b/resources/views/accounts/show.twig
@@ -103,25 +103,25 @@
{% if periods.count > 0 %}
- {% for entry in periods %}
- {% if (entry[2] != 0 or entry[3] != 0) or (accountType == 'Asset account') %}
-
+ {% for period in periods %}
+ {% if (period.spent != 0 or period.earned != 0) or (accountType == 'Asset account') %}
+
- {% if entry[2] != 0 or (accountType == 'Asset account') %}
+ {% if period.spent != 0 or (accountType == 'Asset account') %}
| {{ 'spent'|_ }} |
- {{ entry[2]|formatAmount }} |
+ {{ period.spent|formatAmount }} |
{% endif %}
- {% if entry[3] != 0 or (accountType == 'Asset account') %}
+ {% if period.earned != 0 or (accountType == 'Asset account') %}
| {{ 'earned'|_ }} |
- {{ entry[3]|formatAmount }} |
+ {{ period.earned|formatAmount }} |
{% endif %}
diff --git a/resources/views/budgets/no-budget.twig b/resources/views/budgets/no-budget.twig
index 66b6dbec6a..2509c7eb22 100644
--- a/resources/views/budgets/no-budget.twig
+++ b/resources/views/budgets/no-budget.twig
@@ -40,21 +40,21 @@
{% if periods.count > 0 %}
- {% for entry in periods %}
-
+ {% for period in periods %}
+
| {{ 'transactions'|_ }} |
- {{ entry.count }} |
+ {{ period.count }} |
| {{ 'spent'|_ }} |
- {{ entry.sum|formatAmount }} |
+ {{ period.sum|formatAmount }} |
diff --git a/resources/views/categories/no-category.twig b/resources/views/categories/no-category.twig
index f6660a08b7..601c371a62 100644
--- a/resources/views/categories/no-category.twig
+++ b/resources/views/categories/no-category.twig
@@ -40,29 +40,29 @@
{% if periods.count > 0 %}
- {% for entry in periods %}
-
+ {% for period in periods %}
+
| {{ 'transactions'|_ }} |
- {{ entry.count }} |
+ {{ period.count }} |
| {{ 'spent'|_ }} |
- {{ entry.spent|formatAmount }} |
+ {{ period.spent|formatAmount }} |
| {{ 'earned'|_ }} |
- {{ entry.earned|formatAmount }} |
+ {{ period.earned|formatAmount }} |
| {{ 'transferred'|_ }} |
- {{ entry.transferred|formatAmountPlain }} |
+ {{ period.transferred|formatAmountPlain }} |
diff --git a/resources/views/tags/show.twig b/resources/views/tags/show.twig
index 460247a426..75845f6132 100644
--- a/resources/views/tags/show.twig
+++ b/resources/views/tags/show.twig
@@ -1,7 +1,7 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
- {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, tag) }}
+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, tag, moment, start, end) }}
{% endblock %}
{% block content %}
@@ -75,15 +75,15 @@
- {% if periods %}
+ {% if periods.count > 0 %}
{% endif %}