2016-10-29 15:14:33 +02:00
|
|
|
<?php
|
2022-12-29 19:42:26 +01:00
|
|
|
|
2016-10-29 15:14:33 +02:00
|
|
|
/**
|
|
|
|
* ConvertController.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-10-29 15:14:33 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-29 15:14:33 +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-10-29 15:14:33 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2016-10-29 15:14:33 +02:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Transaction;
|
|
|
|
|
2024-12-22 08:43:12 +01:00
|
|
|
use Exception;
|
2025-01-03 09:15:52 +01:00
|
|
|
use FireflyIII\Enums\AccountTypeEnum;
|
2025-01-03 09:05:56 +01:00
|
|
|
use FireflyIII\Enums\TransactionTypeEnum;
|
2019-03-30 11:03:39 +01:00
|
|
|
use FireflyIII\Events\UpdatedTransactionGroup;
|
2016-10-30 06:14:07 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2016-10-29 15:14:33 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2019-07-05 19:43:16 +02:00
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use FireflyIII\Models\AccountType;
|
|
|
|
use FireflyIII\Models\TransactionGroup;
|
2016-10-29 15:14:33 +02:00
|
|
|
use FireflyIII\Models\TransactionJournal;
|
|
|
|
use FireflyIII\Models\TransactionType;
|
2019-07-05 19:43:16 +02:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
|
|
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
2024-12-22 19:42:06 +01:00
|
|
|
use FireflyIII\Support\Facades\Steam;
|
2018-08-09 16:13:13 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
2019-07-05 19:43:16 +02:00
|
|
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
|
|
|
use FireflyIII\Validation\AccountValidator;
|
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-10-29 15:14:33 +02:00
|
|
|
use Illuminate\Http\Request;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Routing\Redirector;
|
2023-05-29 13:56:55 +02:00
|
|
|
use Illuminate\View\View;
|
2016-10-29 15:14:33 +02:00
|
|
|
|
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class ConvertController.
|
2019-07-13 20:57:06 +02:00
|
|
|
*
|
2022-10-30 11:43:17 +01:00
|
|
|
* TODO when converting a split transfer, all sources and destinations must be the same.
|
2016-10-29 15:14:33 +02:00
|
|
|
*/
|
|
|
|
class ConvertController extends Controller
|
|
|
|
{
|
2021-04-06 17:00:16 +02:00
|
|
|
use ModelInformation;
|
2018-08-09 16:13:13 +02:00
|
|
|
|
2020-10-13 06:35:33 +02:00
|
|
|
private AccountRepositoryInterface $accountRepository;
|
2018-02-25 19:09:05 +01:00
|
|
|
|
2016-10-29 15:14:33 +02:00
|
|
|
/**
|
|
|
|
* ConvertController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
// some useful repositories:
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2020-10-13 06:35:33 +02:00
|
|
|
$this->accountRepository = app(AccountRepositoryInterface::class);
|
2024-06-15 09:38:19 +02:00
|
|
|
app('view')->share('title', (string) trans('firefly.transactions'));
|
2017-12-16 19:46:36 +01:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-exchange');
|
2016-10-29 15:14:33 +02:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2016-10-29 15:14:33 +02:00
|
|
|
/**
|
2018-07-22 08:10:16 +02:00
|
|
|
* Show overview of a to be converted transaction.
|
|
|
|
*
|
2023-12-20 19:35:52 +01:00
|
|
|
* @return Factory|Redirector|RedirectResponse|View
|
2020-03-25 07:03:23 +01:00
|
|
|
*
|
2023-12-20 19:35:52 +01:00
|
|
|
* @throws \Exception
|
2016-10-29 15:14:33 +02:00
|
|
|
*/
|
2019-07-05 19:43:16 +02:00
|
|
|
public function index(TransactionType $destinationType, TransactionGroup $group)
|
2016-10-29 15:14:33 +02:00
|
|
|
{
|
2019-08-17 08:29:35 +02:00
|
|
|
if (!$this->isEditableGroup($group)) {
|
2021-09-18 10:26:12 +02:00
|
|
|
return $this->redirectGroupToAccount($group);
|
2019-08-17 08:29:35 +02:00
|
|
|
}
|
|
|
|
|
2019-07-05 19:43:16 +02:00
|
|
|
/** @var TransactionGroupTransformer $transformer */
|
2024-06-15 13:07:23 +02:00
|
|
|
$transformer = app(TransactionGroupTransformer::class);
|
2019-07-05 19:43:16 +02:00
|
|
|
|
|
|
|
/** @var TransactionJournal $first */
|
2024-06-15 13:07:23 +02:00
|
|
|
$first = $group->transactionJournals()->first();
|
|
|
|
$sourceType = $first->transactionType;
|
2019-07-05 19:43:16 +02:00
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
$groupTitle = $group->title ?? $first->description;
|
|
|
|
$groupArray = $transformer->transformObject($group);
|
|
|
|
$subTitle = (string) trans('firefly.convert_to_'.$destinationType->type, ['description' => $groupTitle]);
|
|
|
|
$subTitleIcon = 'fa-exchange';
|
2019-07-05 19:43:16 +02:00
|
|
|
|
|
|
|
// 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:
|
2024-06-15 13:07:23 +02:00
|
|
|
$preFilled = [
|
2019-07-05 19:43:16 +02:00
|
|
|
'source_name' => old('source_name'),
|
|
|
|
];
|
2016-10-29 15:14:33 +02:00
|
|
|
|
2018-07-20 14:34:56 +02:00
|
|
|
if ($sourceType->type === $destinationType->type) { // cannot convert to its own type.
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug('This is already a transaction of the expected type..');
|
2024-06-15 13:07:23 +02:00
|
|
|
session()->flash('info', (string) trans('firefly.convert_is_already_type_'.$destinationType->type));
|
2016-10-29 15:14:33 +02:00
|
|
|
|
2019-07-05 19:43:16 +02:00
|
|
|
return redirect(route('transactions.show', [$group->id]));
|
2016-10-29 15:14:33 +02:00
|
|
|
}
|
2016-10-29 17:30:55 +02:00
|
|
|
|
2022-01-29 14:11:12 +01:00
|
|
|
return view(
|
2020-03-17 15:01:00 +01:00
|
|
|
'transactions.convert',
|
|
|
|
compact(
|
|
|
|
'sourceType',
|
|
|
|
'destinationType',
|
|
|
|
'group',
|
|
|
|
'groupTitle',
|
|
|
|
'groupArray',
|
|
|
|
'assets',
|
|
|
|
'validDepositSources',
|
|
|
|
'liabilities',
|
|
|
|
'validWithdrawalDests',
|
|
|
|
'preFilled',
|
|
|
|
'subTitle',
|
|
|
|
'subTitleIcon'
|
|
|
|
)
|
2016-10-29 15:14:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
private function getValidDepositSources(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
2025-01-03 09:15:52 +01:00
|
|
|
$liabilityTypes = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value];
|
2023-06-21 12:34:58 +02:00
|
|
|
$accountList = $this->accountRepository
|
2025-01-03 09:15:52 +01:00
|
|
|
->getActiveAccountsByType([AccountTypeEnum::REVENUE->value, AccountTypeEnum::CASH->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value])
|
2024-06-15 13:07:23 +02:00
|
|
|
;
|
2023-06-21 12:34:58 +02:00
|
|
|
$grouped = [];
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
2024-06-15 13:07:23 +02:00
|
|
|
$role = (string) $this->accountRepository->getMetaValue($account, 'account_role');
|
|
|
|
$name = $account->name;
|
2023-06-21 12:34:58 +02:00
|
|
|
if ('' === $role) {
|
|
|
|
$role = 'no_account_type';
|
|
|
|
}
|
|
|
|
|
|
|
|
// maybe it's a liability thing:
|
|
|
|
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
2024-06-15 13:07:23 +02:00
|
|
|
$role = 'l_'.$account->accountType->type;
|
2023-06-21 12:34:58 +02:00
|
|
|
}
|
2025-01-03 09:15:52 +01:00
|
|
|
if (AccountTypeEnum::CASH->value === $account->accountType->type) {
|
2023-06-21 12:34:58 +02:00
|
|
|
$role = 'cash_account';
|
|
|
|
$name = sprintf('(%s)', trans('firefly.cash'));
|
|
|
|
}
|
2025-01-03 09:15:52 +01:00
|
|
|
if (AccountTypeEnum::REVENUE->value === $account->accountType->type) {
|
2023-06-21 12:34:58 +02:00
|
|
|
$role = 'revenue_account';
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
$key = (string) trans('firefly.opt_group_'.$role);
|
2023-06-21 12:34:58 +02:00
|
|
|
$grouped[$key][$account->id] = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getValidWithdrawalDests(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
2025-01-03 09:15:52 +01:00
|
|
|
$liabilityTypes = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value];
|
2023-06-21 12:34:58 +02:00
|
|
|
$accountList = $this->accountRepository->getActiveAccountsByType(
|
2025-01-03 09:15:52 +01:00
|
|
|
[AccountTypeEnum::EXPENSE->value, AccountTypeEnum::CASH->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]
|
2023-06-21 12:34:58 +02:00
|
|
|
);
|
|
|
|
$grouped = [];
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
2024-06-15 13:07:23 +02:00
|
|
|
$role = (string) $this->accountRepository->getMetaValue($account, 'account_role');
|
|
|
|
$name = $account->name;
|
2023-06-21 12:34:58 +02:00
|
|
|
if ('' === $role) {
|
|
|
|
$role = 'no_account_type';
|
|
|
|
}
|
|
|
|
|
|
|
|
// maybe it's a liability thing:
|
|
|
|
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
2024-06-15 13:07:23 +02:00
|
|
|
$role = 'l_'.$account->accountType->type;
|
2023-06-21 12:34:58 +02:00
|
|
|
}
|
2025-01-03 09:15:52 +01:00
|
|
|
if (AccountTypeEnum::CASH->value === $account->accountType->type) {
|
2023-06-21 12:34:58 +02:00
|
|
|
$role = 'cash_account';
|
|
|
|
$name = sprintf('(%s)', trans('firefly.cash'));
|
|
|
|
}
|
2025-01-03 09:15:52 +01:00
|
|
|
if (AccountTypeEnum::EXPENSE->value === $account->accountType->type) {
|
2023-06-21 12:34:58 +02:00
|
|
|
$role = 'expense_account';
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
$key = (string) trans('firefly.opt_group_'.$role);
|
2023-06-21 12:34:58 +02:00
|
|
|
$grouped[$key][$account->id] = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-20 19:35:52 +01:00
|
|
|
* @throws \Exception
|
2023-06-21 12:34:58 +02:00
|
|
|
*/
|
|
|
|
private function getLiabilities(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
2025-01-03 09:15:52 +01:00
|
|
|
$accountList = $this->accountRepository->getActiveAccountsByType([AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
|
2024-12-30 15:35:26 +01:00
|
|
|
$grouped = [];
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
2024-12-22 19:42:06 +01:00
|
|
|
$balance = Steam::finalAccountBalance($account, today()->endOfDay())['balance'];
|
2024-12-30 10:51:34 +01:00
|
|
|
$currency = $this->accountRepository->getAccountCurrency($account) ?? $this->defaultCurrency;
|
2024-06-15 13:07:23 +02:00
|
|
|
$role = 'l_'.$account->accountType->type;
|
|
|
|
$key = (string) trans('firefly.opt_group_'.$role);
|
|
|
|
$grouped[$key][$account->id] = $account->name.' ('.app('amount')->formatAnything($currency, $balance, false).')';
|
2023-06-21 12:34:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-20 19:35:52 +01:00
|
|
|
* @throws \Exception
|
2023-06-21 12:34:58 +02:00
|
|
|
*/
|
|
|
|
private function getAssetAccounts(): array
|
|
|
|
{
|
|
|
|
// make repositories
|
2025-01-03 09:15:52 +01:00
|
|
|
$accountList = $this->accountRepository->getActiveAccountsByType([AccountTypeEnum::ASSET->value]);
|
2024-12-30 15:35:26 +01:00
|
|
|
$grouped = [];
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
// group accounts:
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($accountList as $account) {
|
2024-12-22 19:42:06 +01:00
|
|
|
$balance = Steam::finalAccountBalance($account, today()->endOfDay())['balance'];
|
2024-12-30 10:51:34 +01:00
|
|
|
$currency = $this->accountRepository->getAccountCurrency($account) ?? $this->defaultCurrency;
|
2024-06-15 13:07:23 +02:00
|
|
|
$role = (string) $this->accountRepository->getMetaValue($account, 'account_role');
|
2023-06-21 12:34:58 +02:00
|
|
|
if ('' === $role) {
|
|
|
|
$role = 'no_account_type';
|
|
|
|
}
|
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
$key = (string) trans('firefly.opt_group_'.$role);
|
|
|
|
$grouped[$key][$account->id] = $account->name.' ('.app('amount')->formatAnything($currency, $balance, false).')';
|
2023-06-21 12:34:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $grouped;
|
|
|
|
}
|
|
|
|
|
2024-02-22 20:11:09 +01:00
|
|
|
/**
|
|
|
|
* Do the conversion.
|
|
|
|
*
|
|
|
|
* @return Redirector|RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group)
|
|
|
|
{
|
|
|
|
if (!$this->isEditableGroup($group)) {
|
|
|
|
return $this->redirectGroupToAccount($group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// correct transfers:
|
|
|
|
$group->refresh();
|
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
session()->flash('success', (string) trans('firefly.converted_to_'.$destinationType->type));
|
2024-02-22 20:11:09 +01:00
|
|
|
event(new UpdatedTransactionGroup($group, true, true));
|
|
|
|
|
|
|
|
return redirect(route('transactions.show', [$group->id]));
|
|
|
|
}
|
|
|
|
|
2016-10-29 17:30:55 +02:00
|
|
|
/**
|
2020-10-13 06:35:33 +02:00
|
|
|
* @throws FireflyException
|
2020-03-17 15:01:00 +01:00
|
|
|
*/
|
|
|
|
private function convertJournal(TransactionJournal $journal, TransactionType $transactionType, array $data): TransactionJournal
|
|
|
|
{
|
|
|
|
/** @var AccountValidator $validator */
|
2024-06-15 13:07:23 +02:00
|
|
|
$validator = app(AccountValidator::class);
|
2020-03-17 15:01:00 +01:00
|
|
|
$validator->setUser(auth()->user());
|
|
|
|
$validator->setTransactionType($transactionType->type);
|
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
$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;
|
2020-03-17 15:01:00 +01:00
|
|
|
|
2024-06-15 09:38:19 +02:00
|
|
|
// double check it's not an empty string.
|
|
|
|
$sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId;
|
|
|
|
$sourceName = '' === $sourceName ? null : (string) $sourceName;
|
|
|
|
$destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId;
|
|
|
|
$destinationName = '' === $destinationName ? null : (string) $destinationName;
|
2023-12-20 19:35:52 +01:00
|
|
|
$validSource = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
|
|
|
$validDestination = $validator->validateDestination(['id' => $destinationId, 'name' => $destinationName]);
|
2020-03-17 15:01:00 +01: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));
|
|
|
|
}
|
|
|
|
|
2022-10-30 11:43:17 +01:00
|
|
|
// TODO typeOverrule: the account validator may have another opinion on the transaction type.
|
2020-03-31 07:39:57 +02:00
|
|
|
|
2024-06-15 13:07:23 +02:00
|
|
|
$update = [
|
2020-03-17 15:01:00 +01:00
|
|
|
'source_id' => $sourceId,
|
|
|
|
'source_name' => $sourceName,
|
|
|
|
'destination_id' => $destinationId,
|
|
|
|
'destination_name' => $destinationName,
|
|
|
|
'type' => $transactionType->type,
|
|
|
|
];
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2024-06-15 09:38:19 +02:00
|
|
|
// also set the currency to the currency of the source account, in case you're converting a deposit into a transfer.
|
2025-01-03 09:09:15 +01:00
|
|
|
if (TransactionTypeEnum::TRANSFER->value === $transactionType->type && TransactionTypeEnum::DEPOSIT->value === $journal->transactionType->type) {
|
2024-06-15 09:38:19 +02:00
|
|
|
$source = $this->accountRepository->find((int) $sourceId);
|
|
|
|
$sourceCurrency = $this->accountRepository->getAccountCurrency($source);
|
|
|
|
$dest = $this->accountRepository->find((int) $destinationId);
|
|
|
|
$destCurrency = $this->accountRepository->getAccountCurrency($dest);
|
|
|
|
if (null !== $sourceCurrency && null !== $destCurrency && $sourceCurrency->code !== $destCurrency->code) {
|
|
|
|
$update['currency_id'] = $sourceCurrency->id;
|
|
|
|
$update['foreign_currency_id'] = $destCurrency->id;
|
|
|
|
$update['foreign_amount'] = '1'; // not the best solution but at this point the amount is hard to get.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 15:01:00 +01:00
|
|
|
/** @var JournalUpdateService $service */
|
2024-06-15 13:07:23 +02:00
|
|
|
$service = app(JournalUpdateService::class);
|
2020-03-17 15:01:00 +01:00
|
|
|
$service->setTransactionJournal($journal);
|
|
|
|
$service->setData($update);
|
|
|
|
$service->update();
|
|
|
|
$journal->refresh();
|
|
|
|
|
|
|
|
return $journal;
|
|
|
|
}
|
2016-12-22 19:42:45 +01:00
|
|
|
}
|