2016-10-29 08:14:33 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ConvertController.php
|
2020-01-31 00:32:04 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-10-29 08:14:33 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-29 08:14:33 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05: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 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 01:40:00 -05:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:37:26 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05: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-10-29 08:14:33 -05:00
|
|
|
*/
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
2016-10-29 08:14:33 -05:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Transaction;
|
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
use Carbon\Carbon;
|
2020-03-17 09:01:00 -05:00
|
|
|
use Exception;
|
2019-03-30 05:03:39 -05:00
|
|
|
use FireflyIII\Events\UpdatedTransactionGroup;
|
2016-10-30 00:14:07 -05:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2016-10-29 08:14:33 -05:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2019-07-05 12:43:16 -05:00
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use FireflyIII\Models\AccountType;
|
|
|
|
use FireflyIII\Models\TransactionGroup;
|
2016-10-29 08:14:33 -05:00
|
|
|
use FireflyIII\Models\TransactionJournal;
|
|
|
|
use FireflyIII\Models\TransactionType;
|
2019-07-05 12:43:16 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2016-10-30 00:14:07 -05:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2019-07-05 12:43:16 -05:00
|
|
|
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
2018-08-09 09:13:13 -05:00
|
|
|
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
2019-08-17 01:29:35 -05:00
|
|
|
use FireflyIII\Support\Http\Controllers\UserNavigation;
|
2019-07-05 12:43:16 -05:00
|
|
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
|
|
|
use FireflyIII\Validation\AccountValidator;
|
2020-03-17 09:01:00 -05:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2016-10-29 08:14:33 -05:00
|
|
|
use Illuminate\Http\Request;
|
2020-03-17 09:01:00 -05:00
|
|
|
use Illuminate\Routing\Redirector;
|
2018-07-01 02:27:22 -05:00
|
|
|
use Log;
|
2016-10-29 08:14:33 -05:00
|
|
|
use View;
|
|
|
|
|
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class ConvertController.
|
2019-07-13 13:57:06 -05:00
|
|
|
*
|
|
|
|
* TODO when converting to a split transfer, all sources and destinations must be the same.
|
2016-10-29 08:14:33 -05:00
|
|
|
*/
|
|
|
|
class ConvertController extends Controller
|
|
|
|
{
|
2019-08-17 01:29:35 -05:00
|
|
|
use ModelInformation, UserNavigation;
|
2018-08-09 09:13:13 -05:00
|
|
|
|
2018-07-20 13:53:48 -05:00
|
|
|
/** @var JournalRepositoryInterface Journals and transactions overview */
|
2018-02-25 12:09:05 -06:00
|
|
|
private $repository;
|
|
|
|
|
2016-10-29 08:14:33 -05:00
|
|
|
/**
|
|
|
|
* ConvertController constructor.
|
2020-03-17 09:01:00 -05:00
|
|
|
*
|
2019-07-05 12:43:16 -05:00
|
|
|
* @codeCoverageIgnore
|
2016-10-29 08:14:33 -05:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
// some useful repositories:
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2018-02-25 12:09:05 -06:00
|
|
|
$this->repository = app(JournalRepositoryInterface::class);
|
2016-10-29 08:14:33 -05:00
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
app('view')->share('title', (string) trans('firefly.transactions'));
|
2017-12-16 12:46:36 -06:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-exchange');
|
2016-10-29 08:14:33 -05:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-08 05:08:53 -05:00
|
|
|
|
2016-10-29 08:14:33 -05:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Show overview of a to be converted transaction.
|
|
|
|
*
|
2020-03-17 09:01:00 -05:00
|
|
|
* @param TransactionType $destinationType
|
2019-07-05 12:43:16 -05:00
|
|
|
* @param TransactionGroup $group
|
2016-10-29 08:14:33 -05:00
|
|
|
*
|
2020-03-17 09:01:00 -05:00
|
|
|
* @throws Exception
|
2020-03-25 01:03:23 -05:00
|
|
|
*
|
|
|
|
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2016-10-29 08:14:33 -05:00
|
|
|
*/
|
2019-07-05 12:43:16 -05:00
|
|
|
public function index(TransactionType $destinationType, TransactionGroup $group)
|
2016-10-29 08:14:33 -05:00
|
|
|
{
|
2019-08-17 01:29:35 -05:00
|
|
|
if (!$this->isEditableGroup($group)) {
|
|
|
|
return $this->redirectGroupToAccount($group); // @codeCoverageIgnore
|
|
|
|
}
|
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
/** @var TransactionGroupTransformer $transformer */
|
|
|
|
$transformer = app(TransactionGroupTransformer::class);
|
|
|
|
|
|
|
|
/** @var TransactionJournal $first */
|
|
|
|
$first = $group->transactionJournals()->first();
|
|
|
|
$sourceType = $first->transactionType;
|
|
|
|
|
|
|
|
$groupTitle = $group->title ?? $first->description;
|
|
|
|
$groupArray = $transformer->transformObject($group);
|
2020-03-17 09:01:00 -05:00
|
|
|
$subTitle = (string) trans('firefly.convert_to_' . $destinationType->type, ['description' => $groupTitle]);
|
2019-07-05 12:43:16 -05:00
|
|
|
$subTitleIcon = 'fa-exchange';
|
|
|
|
|
|
|
|
// get a list of asset accounts and liabilities and stuff, in various combinations:
|
|
|
|
$validDepositSources = $this->getValidDepositSources();
|
|
|
|
$validWithdrawalDests = $this->getValidWithdrawalDests();
|
|
|
|
$liabilities = $this->getLiabilities();
|
|
|
|
$assets = $this->getAssetAccounts();
|
|
|
|
|
|
|
|
// old input variables:
|
|
|
|
$preFilled = [
|
|
|
|
'source_name' => old('source_name'),
|
|
|
|
];
|
2016-10-29 08:14:33 -05:00
|
|
|
|
2018-07-20 07:34:56 -05:00
|
|
|
if ($sourceType->type === $destinationType->type) { // cannot convert to its own type.
|
2018-07-01 02:27:22 -05:00
|
|
|
Log::debug('This is already a transaction of the expected type..');
|
2020-03-17 09:01:00 -05:00
|
|
|
session()->flash('info', (string) trans('firefly.convert_is_already_type_' . $destinationType->type));
|
2016-10-29 08:14:33 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
return redirect(route('transactions.show', [$group->id]));
|
2016-10-29 08:14:33 -05:00
|
|
|
}
|
2016-10-29 10:30:55 -05:00
|
|
|
|
2016-10-29 08:14:33 -05:00
|
|
|
return view(
|
2020-03-17 09:01:00 -05:00
|
|
|
'transactions.convert',
|
|
|
|
compact(
|
|
|
|
'sourceType',
|
|
|
|
'destinationType',
|
|
|
|
'group',
|
|
|
|
'groupTitle',
|
|
|
|
'groupArray',
|
|
|
|
'assets',
|
|
|
|
'validDepositSources',
|
|
|
|
'liabilities',
|
|
|
|
'validWithdrawalDests',
|
|
|
|
'preFilled',
|
|
|
|
'subTitle',
|
|
|
|
'subTitleIcon'
|
|
|
|
)
|
2016-10-29 08:14:33 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-29 10:30:55 -05:00
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Do the conversion.
|
|
|
|
*
|
2020-03-17 09:01:00 -05:00
|
|
|
* @param Request $request
|
|
|
|
* @param TransactionType $destinationType
|
2019-07-05 12:43:16 -05:00
|
|
|
* @param TransactionGroup $group
|
2016-10-30 00:14:07 -05:00
|
|
|
*
|
2017-12-17 07:30:53 -06:00
|
|
|
* @throws FireflyException
|
2020-03-17 09:01:00 -05:00
|
|
|
* @return RedirectResponse|Redirector
|
|
|
|
*
|
2016-10-29 10:30:55 -05:00
|
|
|
*/
|
2019-07-05 12:43:16 -05:00
|
|
|
public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group)
|
2016-10-29 08:14:33 -05:00
|
|
|
{
|
2019-08-17 01:29:35 -05:00
|
|
|
if (!$this->isEditableGroup($group)) {
|
|
|
|
return $this->redirectGroupToAccount($group); // @codeCoverageIgnore
|
|
|
|
}
|
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
/** @var TransactionJournal $journal */
|
|
|
|
foreach ($group->transactionJournals as $journal) {
|
|
|
|
// catch FF exception.
|
|
|
|
try {
|
|
|
|
$this->convertJournal($journal, $destinationType, $request->all());
|
|
|
|
} catch (FireflyException $e) {
|
|
|
|
session()->flash('error', $e->getMessage());
|
|
|
|
|
|
|
|
return redirect()->route('transactions.convert.index', [strtolower($destinationType->type), $group->id])->withInput();
|
|
|
|
}
|
2016-11-22 12:10:17 -06:00
|
|
|
}
|
2019-07-13 13:57:06 -05:00
|
|
|
|
|
|
|
// correct transfers:
|
|
|
|
$group->refresh();
|
|
|
|
$this->correctTransfer($group);
|
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
session()->flash('success', (string) trans('firefly.converted_to_' . $destinationType->type));
|
2019-07-05 12:43:16 -05:00
|
|
|
event(new UpdatedTransactionGroup($group));
|
2016-11-22 12:10:17 -06:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
return redirect(route('transactions.show', [$group->id]));
|
|
|
|
}
|
2016-10-29 10:30:55 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
/**
|
2020-03-17 09:01:00 -05:00
|
|
|
* @param TransactionJournal $journal
|
|
|
|
* @param TransactionType $transactionType
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @throws FireflyException
|
|
|
|
* @return TransactionJournal
|
|
|
|
*/
|
|
|
|
private function convertJournal(TransactionJournal $journal, TransactionType $transactionType, array $data): TransactionJournal
|
|
|
|
{
|
|
|
|
/** @var AccountValidator $validator */
|
|
|
|
$validator = app(AccountValidator::class);
|
|
|
|
$validator->setUser(auth()->user());
|
|
|
|
$validator->setTransactionType($transactionType->type);
|
|
|
|
|
|
|
|
$sourceId = $data['source_id'][$journal->id] ?? null;
|
|
|
|
$sourceName = $data['source_name'][$journal->id] ?? null;
|
|
|
|
$destinationId = $data['destination_id'][$journal->id] ?? null;
|
|
|
|
$destinationName = $data['destination_name'][$journal->id] ?? null;
|
|
|
|
|
|
|
|
// double check its not an empty string.
|
|
|
|
$sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId;
|
2020-04-18 23:00:11 -05:00
|
|
|
$sourceName = '' === $sourceName ? null : (string) $sourceName;
|
2020-03-17 09:01:00 -05:00
|
|
|
$destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId;
|
2020-04-18 23:00:11 -05:00
|
|
|
$destinationName = '' === $destinationName ? null : (string) $destinationName;
|
2020-03-31 00:04:00 -05:00
|
|
|
$validSource = $validator->validateSource($sourceId, $sourceName, null);
|
|
|
|
$validDestination = $validator->validateDestination($destinationId, $destinationName, null);
|
2020-03-17 09:01:00 -05:00
|
|
|
|
|
|
|
if (false === $validSource) {
|
|
|
|
throw new FireflyException(sprintf(trans('firefly.convert_invalid_source'), $journal->id));
|
|
|
|
}
|
|
|
|
if (false === $validDestination) {
|
|
|
|
throw new FireflyException(sprintf(trans('firefly.convert_invalid_destination'), $journal->id));
|
|
|
|
}
|
|
|
|
|
2020-03-31 00:39:57 -05:00
|
|
|
// TODO typeOverrule: the account validator may have another opinion on the transaction type.
|
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
$update = [
|
|
|
|
'source_id' => $sourceId,
|
|
|
|
'source_name' => $sourceName,
|
|
|
|
'destination_id' => $destinationId,
|
|
|
|
'destination_name' => $destinationName,
|
|
|
|
'type' => $transactionType->type,
|
|
|
|
];
|
|
|
|
/** @var JournalUpdateService $service */
|
|
|
|
$service = app(JournalUpdateService::class);
|
|
|
|
$service->setTransactionJournal($journal);
|
|
|
|
$service->setData($update);
|
|
|
|
$service->update();
|
|
|
|
$journal->refresh();
|
|
|
|
|
|
|
|
return $journal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param TransactionGroup $group
|
|
|
|
*/
|
|
|
|
private function correctTransfer(TransactionGroup $group): void
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
2019-07-05 12:43:16 -05:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getAssetAccounts(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
|
|
|
$accountList = $repository->getActiveAccountsByType([AccountType::ASSET]);
|
|
|
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
|
|
|
$grouped = [];
|
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
|
|
|
$balance = app('steam')->balance($account, new Carbon);
|
|
|
|
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
2020-03-17 09:01:00 -05:00
|
|
|
$role = (string) $repository->getMetaValue($account, 'account_role');
|
2019-07-05 12:43:16 -05:00
|
|
|
if ('' === $role) {
|
|
|
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
|
|
|
}
|
2016-10-29 10:30:55 -05:00
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
$key = (string) trans('firefly.opt_group_' . $role);
|
2019-07-05 12:43:16 -05:00
|
|
|
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
2016-10-29 10:30:55 -05:00
|
|
|
}
|
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
return $grouped;
|
|
|
|
}
|
2016-10-29 10:30:55 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
/**
|
2020-03-17 09:01:00 -05:00
|
|
|
* @throws Exception
|
2019-07-05 12:43:16 -05:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getLiabilities(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
|
|
|
$accountList = $repository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
|
|
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
|
|
|
$grouped = [];
|
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
|
|
|
$balance = app('steam')->balance($account, new Carbon);
|
|
|
|
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
2019-07-13 13:57:06 -05:00
|
|
|
$role = 'l_' . $account->accountType->type;
|
2020-03-17 09:01:00 -05:00
|
|
|
$key = (string) trans('firefly.opt_group_' . $role);
|
2019-07-05 12:43:16 -05:00
|
|
|
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
2016-10-29 10:30:55 -05:00
|
|
|
}
|
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
return $grouped;
|
|
|
|
}
|
2016-10-30 00:14:07 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getValidDepositSources(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
|
|
|
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
|
|
|
$accountList = $repository
|
|
|
|
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
|
|
|
$grouped = [];
|
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
2020-03-17 09:01:00 -05:00
|
|
|
$role = (string) $repository->getMetaValue($account, 'account_role');
|
2019-07-05 12:43:16 -05:00
|
|
|
$name = $account->name;
|
|
|
|
if ('' === $role) {
|
|
|
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
|
|
|
}
|
2016-10-29 10:30:55 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
// maybe it's a liability thing:
|
|
|
|
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
|
|
|
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
|
|
|
}
|
|
|
|
if (AccountType::CASH === $account->accountType->type) {
|
2019-07-13 13:57:06 -05:00
|
|
|
// @codeCoverageIgnoreStart
|
2019-07-05 12:43:16 -05:00
|
|
|
$role = 'cash_account';
|
|
|
|
$name = sprintf('(%s)', trans('firefly.cash'));
|
2019-07-13 13:57:06 -05:00
|
|
|
// @codeCoverageIgnoreEnd
|
2019-07-05 12:43:16 -05:00
|
|
|
}
|
|
|
|
if (AccountType::REVENUE === $account->accountType->type) {
|
2019-07-13 13:57:06 -05:00
|
|
|
$role = 'revenue_account'; // @codeCoverageIgnore
|
2019-07-05 12:43:16 -05:00
|
|
|
}
|
2018-12-31 01:11:57 -06:00
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
$key = (string) trans('firefly.opt_group_' . $role);
|
2019-07-05 12:43:16 -05:00
|
|
|
$grouped[$key][$account->id] = $name;
|
2016-10-30 00:14:07 -05:00
|
|
|
}
|
2016-10-29 10:30:55 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
return $grouped;
|
|
|
|
}
|
2018-09-13 13:01:41 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getValidWithdrawalDests(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
|
|
|
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
|
|
|
$accountList = $repository
|
|
|
|
->getActiveAccountsByType([AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
|
|
|
$grouped = [];
|
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
2020-03-17 09:01:00 -05:00
|
|
|
$role = (string) $repository->getMetaValue($account, 'account_role');
|
2019-07-05 12:43:16 -05:00
|
|
|
$name = $account->name;
|
|
|
|
if ('' === $role) {
|
|
|
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
|
|
|
}
|
2018-09-13 13:01:41 -05:00
|
|
|
|
2019-07-05 12:43:16 -05:00
|
|
|
// maybe it's a liability thing:
|
|
|
|
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
|
|
|
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
|
|
|
}
|
|
|
|
if (AccountType::CASH === $account->accountType->type) {
|
2019-07-13 13:57:06 -05:00
|
|
|
// @codeCoverageIgnoreStart
|
2019-07-05 12:43:16 -05:00
|
|
|
$role = 'cash_account';
|
|
|
|
$name = sprintf('(%s)', trans('firefly.cash'));
|
2019-07-13 13:57:06 -05:00
|
|
|
// @codeCoverageIgnoreEnd
|
2019-07-05 12:43:16 -05:00
|
|
|
}
|
|
|
|
if (AccountType::EXPENSE === $account->accountType->type) {
|
2019-07-13 13:57:06 -05:00
|
|
|
$role = 'expense_account'; // @codeCoverageIgnore
|
2019-07-05 12:43:16 -05:00
|
|
|
}
|
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
$key = (string) trans('firefly.opt_group_' . $role);
|
2019-07-05 12:43:16 -05:00
|
|
|
$grouped[$key][$account->id] = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
}
|
2016-12-22 12:42:45 -06:00
|
|
|
}
|