2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2024-11-25 04:18:55 +01:00
|
|
|
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* ShowController.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-05-20 12:27:31 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
2018-07-14 11:45:05 +02:00
|
|
|
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2016-05-20 08:57:45 +02:00
|
|
|
|
2018-07-14 11:45:05 +02:00
|
|
|
namespace FireflyIII\Http\Controllers\Account;
|
2015-02-07 23:19:28 +01:00
|
|
|
|
2015-02-09 07:23:39 +01:00
|
|
|
use Carbon\Carbon;
|
2022-12-29 19:41:57 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2019-05-29 18:28:28 +02:00
|
|
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
2018-07-14 11:45:05 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2015-02-14 14:25:29 +01:00
|
|
|
use FireflyIII\Models\Account;
|
2016-11-21 20:23:25 +01:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2024-12-22 19:42:06 +01:00
|
|
|
use FireflyIII\Support\Facades\Steam;
|
2018-08-11 06:39:29 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
2021-03-28 11:46:23 +02:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2016-12-28 13:02:56 +01:00
|
|
|
use Illuminate\Http\Request;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Routing\Redirector;
|
2016-05-06 10:32:26 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2021-03-28 11:46:23 +02:00
|
|
|
use Illuminate\View\View;
|
2015-06-03 21:25:11 +02:00
|
|
|
|
2015-02-07 23:19:28 +01:00
|
|
|
/**
|
2018-07-14 11:45:05 +02:00
|
|
|
* Class ShowController
|
2015-02-07 23:19:28 +01:00
|
|
|
*/
|
2018-07-14 11:45:05 +02:00
|
|
|
class ShowController extends Controller
|
2015-02-07 23:19:28 +01:00
|
|
|
{
|
2021-04-06 17:00:16 +02:00
|
|
|
use PeriodOverview;
|
2018-08-09 17:32:28 +02:00
|
|
|
|
2023-01-03 06:48:53 +01:00
|
|
|
private AccountRepositoryInterface $repository;
|
2018-01-14 10:48:17 +01:00
|
|
|
|
2015-02-11 07:35:10 +01:00
|
|
|
/**
|
2018-07-20 20:53:48 +02:00
|
|
|
* ShowController constructor.
|
2015-02-11 07:35:10 +01:00
|
|
|
*/
|
2015-02-07 23:19:28 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2015-04-28 15:26:30 +02:00
|
|
|
parent::__construct();
|
2016-10-29 07:44:46 +02:00
|
|
|
|
2019-09-04 07:51:31 +02:00
|
|
|
app('view')->share('showCategory', true);
|
|
|
|
|
2016-10-29 07:44:46 +02:00
|
|
|
// translations:
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2017-12-16 19:46:36 +01:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
2024-12-22 08:43:12 +01:00
|
|
|
app('view')->share('title', (string) trans('firefly.accounts'));
|
2016-10-29 07:44:46 +02:00
|
|
|
|
2023-01-03 06:48:53 +01:00
|
|
|
$this->repository = app(AccountRepositoryInterface::class);
|
2018-01-14 10:48:17 +01:00
|
|
|
|
2016-10-29 07:44:46 +02:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
2015-02-07 23:19:28 +01:00
|
|
|
}
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2015-02-21 12:16:41 +01:00
|
|
|
/**
|
2017-09-16 09:24:48 +02:00
|
|
|
* Show an account.
|
2017-10-05 11:49:06 +02:00
|
|
|
*
|
2023-12-20 19:35:52 +01:00
|
|
|
* @return Factory|Redirector|RedirectResponse|View
|
2018-03-19 19:39:02 +01:00
|
|
|
*
|
2022-12-29 19:41:57 +01:00
|
|
|
* @throws FireflyException
|
2023-12-22 07:58:35 +01:00
|
|
|
* */
|
2024-03-18 20:25:30 +01:00
|
|
|
public function show(Request $request, Account $account, ?Carbon $start = null, ?Carbon $end = null)
|
2015-02-21 12:16:41 +01:00
|
|
|
{
|
2024-01-01 14:43:56 +01:00
|
|
|
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
|
2020-07-12 17:34:06 +02:00
|
|
|
|
2019-08-17 08:29:35 +02:00
|
|
|
if (!$this->isEditableAccount($account)) {
|
2021-09-18 10:26:12 +02:00
|
|
|
return $this->redirectAccountToAccount($account);
|
2018-08-22 21:18:15 +02:00
|
|
|
}
|
|
|
|
|
2023-12-10 06:45:59 +01:00
|
|
|
$start ??= session('start');
|
2024-01-01 14:43:56 +01:00
|
|
|
$end ??= session('end');
|
2019-06-23 05:53:01 +02:00
|
|
|
|
2025-01-04 07:10:37 +01:00
|
|
|
/** @var Carbon $start */
|
|
|
|
/** @var Carbon $end */
|
2024-12-25 11:59:15 +01:00
|
|
|
if ($end->lt($start)) {
|
2021-09-18 10:26:12 +02:00
|
|
|
[$start, $end] = [$end, $start];
|
2018-02-09 19:11:55 +01:00
|
|
|
}
|
2019-12-30 12:12:08 +01:00
|
|
|
$location = $this->repository->getLocation($account);
|
2020-03-19 18:20:23 +01:00
|
|
|
$attachments = $this->repository->getAttachments($account);
|
2020-09-11 07:12:33 +02:00
|
|
|
$today = today(config('app.timezone'));
|
2019-06-23 11:13:36 +02:00
|
|
|
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
2024-12-22 08:43:12 +01:00
|
|
|
$page = (int) $request->get('page');
|
|
|
|
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
2024-12-26 05:25:46 +01:00
|
|
|
$accountCurrency = $this->repository->getAccountCurrency($account);
|
2024-12-30 10:51:34 +01:00
|
|
|
$currency = $accountCurrency ?? $this->defaultCurrency;
|
2022-03-27 20:24:13 +02:00
|
|
|
$fStart = $start->isoFormat($this->monthAndDayFormat);
|
|
|
|
$fEnd = $end->isoFormat($this->monthAndDayFormat);
|
2024-12-22 08:43:12 +01:00
|
|
|
$subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
|
2022-04-12 18:19:30 +02:00
|
|
|
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
2019-06-23 11:13:36 +02:00
|
|
|
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
|
|
|
|
$periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end);
|
2018-03-25 18:26:35 +02:00
|
|
|
|
2021-09-25 05:32:15 +02:00
|
|
|
// if layout = v2, overrule the page title.
|
2024-04-08 07:45:58 +02:00
|
|
|
if ('v1' !== config('view.layout')) {
|
2024-12-22 08:43:12 +01:00
|
|
|
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
2021-09-25 05:32:15 +02:00
|
|
|
}
|
|
|
|
|
2019-05-29 18:28:28 +02:00
|
|
|
/** @var GroupCollectorInterface $collector */
|
2024-01-01 14:43:56 +01:00
|
|
|
$collector = app(GroupCollectorInterface::class);
|
2019-05-29 18:28:28 +02:00
|
|
|
$collector
|
|
|
|
->setAccounts(new Collection([$account]))
|
|
|
|
->setLimit($pageSize)
|
2019-09-04 07:51:31 +02:00
|
|
|
->setPage($page)->withAccountInformation()->withCategoryInformation()
|
2023-12-20 19:35:52 +01:00
|
|
|
->setRange($start, $end)
|
|
|
|
;
|
2023-07-18 06:30:45 +02:00
|
|
|
|
|
|
|
// this search will not include transaction groups where this asset account (or liability)
|
|
|
|
// is just part of ONE of the journals. To force this:
|
|
|
|
$collector->setExpandGroupSearch(true);
|
|
|
|
|
2024-01-01 14:43:56 +01:00
|
|
|
$groups = $collector->getPaginatedGroups();
|
2020-12-11 05:17:32 +01:00
|
|
|
|
2019-05-29 18:28:28 +02:00
|
|
|
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));
|
2024-01-01 14:43:56 +01:00
|
|
|
$showAll = false;
|
2024-12-26 05:25:46 +01:00
|
|
|
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency);
|
2018-08-22 21:18:15 +02:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view(
|
2018-03-25 18:26:35 +02:00
|
|
|
'accounts.show',
|
2018-08-22 21:18:15 +02:00
|
|
|
compact(
|
2020-03-17 15:01:00 +01:00
|
|
|
'account',
|
|
|
|
'showAll',
|
|
|
|
'objectType',
|
|
|
|
'currency',
|
|
|
|
'today',
|
|
|
|
'periods',
|
|
|
|
'subTitleIcon',
|
|
|
|
'groups',
|
2020-03-19 18:20:23 +01:00
|
|
|
'attachments',
|
2020-03-17 15:01:00 +01:00
|
|
|
'subTitle',
|
|
|
|
'start',
|
|
|
|
'end',
|
2022-04-12 18:19:30 +02:00
|
|
|
'chartUrl',
|
2020-03-17 15:01:00 +01:00
|
|
|
'location',
|
2024-12-25 11:59:15 +01:00
|
|
|
'balances'
|
2018-08-22 21:18:15 +02:00
|
|
|
)
|
2018-03-25 18:26:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an account.
|
|
|
|
*
|
2023-12-20 19:35:52 +01:00
|
|
|
* @return Factory|Redirector|RedirectResponse|View
|
2020-03-17 15:01:00 +01:00
|
|
|
*
|
2022-12-29 19:41:57 +01:00
|
|
|
* @throws FireflyException
|
2023-12-22 07:58:35 +01:00
|
|
|
* */
|
2018-03-25 18:26:35 +02:00
|
|
|
public function showAll(Request $request, Account $account)
|
|
|
|
{
|
2019-08-17 08:29:35 +02:00
|
|
|
if (!$this->isEditableAccount($account)) {
|
2021-09-18 10:26:12 +02:00
|
|
|
return $this->redirectAccountToAccount($account);
|
2018-03-25 18:26:35 +02:00
|
|
|
}
|
2024-12-26 10:24:39 +01:00
|
|
|
$location = $this->repository->getLocation($account);
|
|
|
|
$isLiability = $this->repository->isLiability($account);
|
|
|
|
$attachments = $this->repository->getAttachments($account);
|
|
|
|
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
|
|
|
|
$end = today(config('app.timezone'));
|
|
|
|
$today = today(config('app.timezone'));
|
2024-12-26 08:53:16 +01:00
|
|
|
$accountCurrency = $this->repository->getAccountCurrency($account);
|
2024-12-26 10:24:39 +01:00
|
|
|
$start = $this->repository->oldestJournalDate($account) ?? today(config('app.timezone'))->startOfMonth();
|
|
|
|
$subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type);
|
|
|
|
$page = (int) $request->get('page');
|
|
|
|
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
2024-12-30 10:51:34 +01:00
|
|
|
$currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency;
|
2024-12-26 10:24:39 +01:00
|
|
|
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
|
|
|
$periods = new Collection();
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2019-05-30 12:31:19 +02:00
|
|
|
/** @var GroupCollectorInterface $collector */
|
2024-12-26 10:24:39 +01:00
|
|
|
$collector = app(GroupCollectorInterface::class);
|
2019-09-04 07:51:31 +02:00
|
|
|
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation();
|
2023-08-01 06:24:26 +02:00
|
|
|
|
|
|
|
// this search will not include transaction groups where this asset account (or liability)
|
|
|
|
// is just part of ONE of the journals. To force this:
|
|
|
|
$collector->setExpandGroupSearch(true);
|
|
|
|
|
2024-12-26 10:24:39 +01:00
|
|
|
$groups = $collector->getPaginatedGroups();
|
2019-05-30 12:31:19 +02:00
|
|
|
$groups->setPath(route('accounts.show.all', [$account->id]));
|
2024-12-26 10:24:39 +01:00
|
|
|
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
|
|
|
$showAll = true;
|
|
|
|
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency);
|
2017-01-08 10:19:10 +01:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view(
|
2017-04-16 22:15:05 +02:00
|
|
|
'accounts.show',
|
2019-12-30 12:12:08 +01:00
|
|
|
compact(
|
2020-03-17 15:01:00 +01:00
|
|
|
'account',
|
|
|
|
'showAll',
|
|
|
|
'location',
|
|
|
|
'objectType',
|
|
|
|
'isLiability',
|
2020-03-19 18:23:34 +01:00
|
|
|
'attachments',
|
2020-03-17 15:01:00 +01:00
|
|
|
'currency',
|
|
|
|
'today',
|
2022-04-12 18:19:30 +02:00
|
|
|
'chartUrl',
|
2020-03-17 15:01:00 +01:00
|
|
|
'periods',
|
|
|
|
'subTitleIcon',
|
|
|
|
'groups',
|
|
|
|
'subTitle',
|
|
|
|
'start',
|
|
|
|
'end',
|
2024-12-26 08:53:16 +01:00
|
|
|
'balances'
|
2019-12-30 12:12:08 +01:00
|
|
|
)
|
2017-03-18 08:09:14 +01:00
|
|
|
);
|
2016-05-15 15:08:59 +02:00
|
|
|
}
|
2018-07-22 20:32:02 +02:00
|
|
|
}
|