mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Expand code and some refactoring for #595
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user