Files
firefly-iii/app/Http/Controllers/Transaction/EditController.php

98 lines
3.2 KiB
PHP
Raw Normal View History

2019-06-01 20:38:18 +02:00
<?php
/**
* EditController.php
2020-01-31 07:32:04 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/
2019-08-17 12:09:03 +02:00
declare(strict_types=1);
2019-06-01 20:38:18 +02:00
namespace FireflyIII\Http\Controllers\Transaction;
2021-03-28 11:46:23 +02:00
2019-06-01 20:38:18 +02:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Contracts\View\Factory;
2021-03-28 11:46:23 +02:00
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
2019-06-01 20:38:18 +02:00
/**
* Class EditController
*/
class EditController extends Controller
{
/**
2019-07-20 06:47:34 +02:00
* EditController constructor.
*
2019-07-20 06:47:34 +02:00
* @codeCoverageIgnore
2019-06-01 20:38:18 +02:00
*/
public function __construct()
{
parent::__construct();
// some useful repositories:
$this->middleware(
2019-07-20 06:47:34 +02:00
static function ($request, $next) {
2019-06-01 20:38:18 +02:00
2022-03-29 14:58:06 +02:00
app('view')->share('title', (string) trans('firefly.transactions'));
2020-05-01 06:24:24 +02:00
app('view')->share('mainTitleIcon', 'fa-exchange');
2019-06-01 20:38:18 +02:00
return $next($request);
}
);
}
2021-03-28 11:46:23 +02:00
2019-06-01 20:38:18 +02:00
/**
* @param TransactionGroup $transactionGroup
*
2021-03-28 11:46:23 +02:00
* @return Factory|View|RedirectResponse|Redirector
2019-06-01 20:38:18 +02:00
*/
public function edit(TransactionGroup $transactionGroup)
{
2019-10-06 20:09:27 +02:00
app('preferences')->mark();
2019-08-17 08:29:35 +02:00
if (!$this->isEditableGroup($transactionGroup)) {
return $this->redirectGroupToAccount($transactionGroup);
2019-08-17 08:29:35 +02:00
}
2019-06-01 20:38:18 +02:00
/** @var AccountRepositoryInterface $repository */
2022-03-29 14:58:06 +02:00
$repository = app(AccountRepositoryInterface::class);
2019-06-01 20:38:18 +02:00
$allowedOpposingTypes = config('firefly.allowed_opposing_types');
2022-03-29 14:58:06 +02:00
$accountToTypes = config('firefly.account_to_transaction');
$expectedSourceTypes = config('firefly.expected_source_types');
$allowedSourceDests = config('firefly.source_dests');
2020-07-19 17:24:29 +02:00
//
$defaultCurrency = app('amount')->getDefaultCurrency();
$cash = $repository->getCashAccount();
2022-04-12 18:19:30 +02:00
$previousUrl = $this->rememberPreviousUrl('transactions.edit.url');
2021-10-03 06:05:11 +02:00
$parts = parse_url($previousUrl);
2020-07-19 17:24:29 +02:00
$search = sprintf('?%s', $parts['query'] ?? '');
2021-10-03 06:05:11 +02:00
$previousUrl = str_replace($search, '', $previousUrl);
2021-03-28 11:46:23 +02:00
return view(
2020-07-19 17:24:29 +02:00
'transactions.edit',
compact(
'cash', 'allowedSourceDests', 'expectedSourceTypes', 'transactionGroup', 'allowedOpposingTypes', 'accountToTypes', 'defaultCurrency',
2021-10-03 06:05:11 +02:00
'previousUrl'
2020-07-19 17:24:29 +02:00
)
);
2019-06-01 20:38:18 +02:00
}
2019-08-17 12:09:03 +02:00
}