2018-07-14 15:22:21 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ShowController.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-07-14 15:22:21 +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.
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-07-14 15:22:21 +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.
|
2018-07-14 15:22:21 +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/>.
|
2018-07-14 15:22:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Budget;
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2018-07-14 15:22:21 +02:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2019-05-30 12:31:19 +02:00
|
|
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
2018-07-14 15:22:21 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
|
|
|
use FireflyIII\Models\Budget;
|
|
|
|
use FireflyIII\Models\BudgetLimit;
|
|
|
|
use FireflyIII\Models\TransactionType;
|
2020-03-19 18:28:02 +01:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
2018-07-14 15:22:21 +02:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2018-12-31 07:58:13 +01:00
|
|
|
use FireflyIII\Support\Http\Controllers\AugumentData;
|
2018-08-11 06:39:29 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
2018-07-14 15:22:21 +02:00
|
|
|
use Illuminate\Http\Request;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\View\View;
|
2022-12-29 19:41:57 +01:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2018-07-14 15:22:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class ShowController
|
|
|
|
*/
|
|
|
|
class ShowController extends Controller
|
|
|
|
{
|
2022-10-30 14:24:19 +01:00
|
|
|
use AugumentData;
|
2023-11-04 14:18:49 +01:00
|
|
|
use PeriodOverview;
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2021-04-06 17:00:16 +02:00
|
|
|
protected JournalRepositoryInterface $journalRepos;
|
2021-09-18 10:26:12 +02:00
|
|
|
private BudgetRepositoryInterface $repository;
|
2020-03-19 18:28:02 +01:00
|
|
|
|
2018-07-14 15:22:21 +02:00
|
|
|
/**
|
2018-07-21 08:06:24 +02:00
|
|
|
* ShowController constructor.
|
2019-06-23 11:13:36 +02:00
|
|
|
*
|
2023-02-12 07:15:06 +01:00
|
|
|
|
2018-07-14 15:22:21 +02:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2019-09-04 07:51:31 +02:00
|
|
|
app('view')->share('showCategory', true);
|
2018-07-14 15:22:21 +02:00
|
|
|
parent::__construct();
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2022-12-29 19:41:57 +01:00
|
|
|
app('view')->share('title', (string)trans('firefly.budgets'));
|
2020-05-01 17:29:50 -03:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
2019-06-23 11:13:36 +02:00
|
|
|
$this->journalRepos = app(JournalRepositoryInterface::class);
|
2021-03-28 11:46:23 +02:00
|
|
|
$this->repository = app(BudgetRepositoryInterface::class);
|
2018-07-14 15:22:21 +02:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-21 08:06:24 +02:00
|
|
|
* Show transactions without a budget.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Request $request
|
|
|
|
* @param Carbon|null $start
|
|
|
|
* @param Carbon|null $end
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2020-03-17 15:01:00 +01:00
|
|
|
* @return Factory|View
|
2021-09-18 10:21:29 +02:00
|
|
|
* @throws FireflyException
|
2022-12-29 19:41:57 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
2018-07-14 15:22:21 +02:00
|
|
|
*/
|
2022-12-31 06:57:05 +01:00
|
|
|
public function noBudget(Request $request, Carbon $start = null, Carbon $end = null)
|
2018-07-14 15:22:21 +02:00
|
|
|
{
|
2018-07-14 17:23:44 +02:00
|
|
|
/** @var Carbon $start */
|
|
|
|
$start = $start ?? session('start');
|
|
|
|
/** @var Carbon $end */
|
|
|
|
$end = $end ?? session('end');
|
|
|
|
$subTitle = trans(
|
|
|
|
'firefly.without_budget_between',
|
2022-03-27 20:24:13 +02:00
|
|
|
['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)]
|
2018-07-14 17:23:44 +02:00
|
|
|
);
|
2019-06-23 11:13:36 +02:00
|
|
|
|
|
|
|
// get first journal ever to set off the budget period overview.
|
|
|
|
$first = $this->journalRepos->firstNull();
|
|
|
|
$firstDate = null !== $first ? $first->date : $start;
|
|
|
|
$periods = $this->getNoBudgetPeriodOverview($firstDate, $end);
|
2022-12-29 19:41:57 +01:00
|
|
|
$page = (int)$request->get('page');
|
|
|
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2019-05-30 12:31:19 +02:00
|
|
|
/** @var GroupCollectorInterface $collector */
|
|
|
|
$collector = app(GroupCollectorInterface::class);
|
|
|
|
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
2019-09-04 07:51:31 +02:00
|
|
|
->withoutBudget()->withAccountInformation()->withCategoryInformation();
|
2019-05-30 12:31:19 +02:00
|
|
|
$groups = $collector->getPaginatedGroups();
|
|
|
|
$groups->setPath(route('budgets.no-budget'));
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view('budgets.no-budget', compact('groups', 'subTitle', 'periods', 'start', 'end'));
|
2018-07-14 17:23:44 +02:00
|
|
|
}
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2018-07-14 17:23:44 +02:00
|
|
|
/**
|
2018-07-21 08:06:24 +02:00
|
|
|
* Shows ALL transactions without a budget.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Request $request
|
2018-07-14 17:23:44 +02:00
|
|
|
*
|
2020-03-17 15:01:00 +01:00
|
|
|
* @return Factory|View
|
2022-12-29 19:41:57 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
2018-07-14 17:23:44 +02:00
|
|
|
*/
|
2019-06-23 11:13:36 +02:00
|
|
|
public function noBudgetAll(Request $request)
|
2018-07-14 17:23:44 +02:00
|
|
|
{
|
2022-12-29 19:41:57 +01:00
|
|
|
$subTitle = (string)trans('firefly.all_journals_without_budget');
|
2019-06-23 11:13:36 +02:00
|
|
|
$first = $this->journalRepos->firstNull();
|
2022-10-30 14:24:19 +01:00
|
|
|
$start = null === $first ? new Carbon() : $first->date;
|
2020-09-11 07:12:11 +02:00
|
|
|
$end = today(config('app.timezone'));
|
2022-12-29 19:41:57 +01:00
|
|
|
$page = (int)$request->get('page');
|
|
|
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2019-05-30 12:31:19 +02:00
|
|
|
/** @var GroupCollectorInterface $collector */
|
|
|
|
$collector = app(GroupCollectorInterface::class);
|
|
|
|
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
2019-09-04 07:51:31 +02:00
|
|
|
->withoutBudget()->withAccountInformation()->withCategoryInformation();
|
2019-05-30 12:31:19 +02:00
|
|
|
$groups = $collector->getPaginatedGroups();
|
2022-02-21 16:48:16 +01:00
|
|
|
$groups->setPath(route('budgets.no-budget-all'));
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view('budgets.no-budget', compact('groups', 'subTitle', 'start', 'end'));
|
2018-07-14 15:22:21 +02:00
|
|
|
}
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2018-07-14 15:22:21 +02:00
|
|
|
/**
|
2018-07-21 08:06:24 +02:00
|
|
|
* Show a single budget.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Request $request
|
|
|
|
* @param Budget $budget
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2020-03-17 15:01:00 +01:00
|
|
|
* @return Factory|View
|
2022-12-29 19:41:57 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
2018-07-14 15:22:21 +02:00
|
|
|
*/
|
|
|
|
public function show(Request $request, Budget $budget)
|
|
|
|
{
|
2021-04-27 06:23:16 +02:00
|
|
|
/** @var Carbon $allStart */
|
2023-02-11 07:36:45 +01:00
|
|
|
$allStart = session('first', today(config('app.timezone'))->startOfYear());
|
2021-03-28 11:46:23 +02:00
|
|
|
$allEnd = today();
|
2022-12-29 19:41:57 +01:00
|
|
|
$page = (int)$request->get('page');
|
|
|
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
2021-03-28 11:46:23 +02:00
|
|
|
$limits = $this->getLimits($budget, $allStart, $allEnd);
|
|
|
|
$repetition = null;
|
2020-03-19 18:28:02 +01:00
|
|
|
$attachments = $this->repository->getAttachments($budget);
|
2018-07-14 15:22:21 +02:00
|
|
|
|
|
|
|
// collector:
|
2019-05-30 12:31:19 +02:00
|
|
|
/** @var GroupCollectorInterface $collector */
|
|
|
|
$collector = app(GroupCollectorInterface::class);
|
2020-09-11 07:12:11 +02:00
|
|
|
$collector->setRange($allStart, $allEnd)->setBudget($budget)
|
2020-03-17 15:01:00 +01:00
|
|
|
->withAccountInformation()
|
|
|
|
->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation();
|
2019-05-30 12:31:19 +02:00
|
|
|
$groups = $collector->getPaginatedGroups();
|
|
|
|
$groups->setPath(route('budgets.show', [$budget->id]));
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2022-12-29 19:41:57 +01:00
|
|
|
$subTitle = (string)trans('firefly.all_journals_for_budget', ['name' => $budget->name]);
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view('budgets.show', compact('limits', 'attachments', 'budget', 'repetition', 'groups', 'subTitle'));
|
2018-07-14 15:22:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-21 08:06:24 +02:00
|
|
|
* Show a single budget by a budget limit.
|
|
|
|
*
|
2023-06-21 12:34:58 +02:00
|
|
|
* @param Request $request
|
|
|
|
* @param Budget $budget
|
|
|
|
* @param BudgetLimit $budgetLimit
|
2018-07-14 15:22:21 +02:00
|
|
|
*
|
2020-03-17 15:01:00 +01:00
|
|
|
* @return Factory|View
|
2021-03-28 11:46:23 +02:00
|
|
|
* @throws FireflyException
|
2022-12-29 19:41:57 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
2018-07-14 15:22:21 +02:00
|
|
|
*/
|
|
|
|
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
|
|
|
|
{
|
|
|
|
if ($budgetLimit->budget->id !== $budget->id) {
|
2021-09-18 10:26:12 +02:00
|
|
|
throw new FireflyException('This budget limit is not part of this budget.');
|
2018-07-14 15:22:21 +02:00
|
|
|
}
|
|
|
|
|
2022-12-29 19:41:57 +01:00
|
|
|
$page = (int)$request->get('page');
|
|
|
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
2018-07-14 15:22:21 +02:00
|
|
|
$subTitle = trans(
|
|
|
|
'firefly.budget_in_period',
|
|
|
|
[
|
2020-03-17 15:01:00 +01:00
|
|
|
'name' => $budget->name,
|
2022-03-27 20:24:13 +02:00
|
|
|
'start' => $budgetLimit->start_date->isoFormat($this->monthAndDayFormat),
|
|
|
|
'end' => $budgetLimit->end_date->isoFormat($this->monthAndDayFormat),
|
2019-09-15 06:56:20 +02:00
|
|
|
'currency' => $budgetLimit->transactionCurrency->name,
|
2018-07-14 15:22:21 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// collector:
|
2019-05-30 12:31:19 +02:00
|
|
|
/** @var GroupCollectorInterface $collector */
|
|
|
|
$collector = app(GroupCollectorInterface::class);
|
|
|
|
|
2020-07-01 19:43:53 +02:00
|
|
|
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->withAccountInformation()
|
2019-09-04 07:51:31 +02:00
|
|
|
->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation();
|
2019-05-30 12:31:19 +02:00
|
|
|
$groups = $collector->getPaginatedGroups();
|
2023-10-14 07:03:18 +02:00
|
|
|
$groups->setPath(route('budgets.show.limit', [$budget->id, $budgetLimit->id]));
|
2018-07-27 04:46:21 +02:00
|
|
|
/** @var Carbon $start */
|
2023-02-11 07:36:45 +01:00
|
|
|
$start = session('first', today(config('app.timezone'))->startOfYear());
|
2021-03-28 11:46:23 +02:00
|
|
|
$end = today(config('app.timezone'));
|
2020-03-19 18:28:02 +01:00
|
|
|
$attachments = $this->repository->getAttachments($budget);
|
2021-03-28 11:46:23 +02:00
|
|
|
$limits = $this->getLimits($budget, $start, $end);
|
2018-07-14 15:22:21 +02:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view('budgets.show', compact('limits', 'attachments', 'budget', 'budgetLimit', 'groups', 'subTitle'));
|
2018-07-14 15:22:21 +02:00
|
|
|
}
|
2018-07-22 20:32:02 +02:00
|
|
|
}
|