mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This commit is contained in:
parent
b2c3ee9779
commit
46b780758e
@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers\Transaction;
|
namespace FireflyIII\Http\Controllers\Transaction;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use FireflyIII\Events\UpdatedTransactionGroup;
|
use FireflyIII\Events\UpdatedTransactionGroup;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
@ -140,8 +139,7 @@ class ConvertController extends Controller
|
|||||||
// make repositories
|
// make repositories
|
||||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||||
$accountList = $this->accountRepository
|
$accountList = $this->accountRepository
|
||||||
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE])
|
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||||
;
|
|
||||||
$grouped = [];
|
$grouped = [];
|
||||||
|
|
||||||
// group accounts:
|
// group accounts:
|
||||||
@ -306,7 +304,7 @@ class ConvertController extends Controller
|
|||||||
$destinationId = $data['destination_id'][$journal->id] ?? null;
|
$destinationId = $data['destination_id'][$journal->id] ?? null;
|
||||||
$destinationName = $data['destination_name'][$journal->id] ?? null;
|
$destinationName = $data['destination_name'][$journal->id] ?? null;
|
||||||
|
|
||||||
// double check its not an empty string.
|
// double check it's not an empty string.
|
||||||
$sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId;
|
$sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId;
|
||||||
$sourceName = '' === $sourceName ? null : (string) $sourceName;
|
$sourceName = '' === $sourceName ? null : (string) $sourceName;
|
||||||
$destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId;
|
$destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId;
|
||||||
@ -331,6 +329,20 @@ class ConvertController extends Controller
|
|||||||
'type' => $transactionType->type,
|
'type' => $transactionType->type,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// also set the currency to the currency of the source account, in case you're converting a deposit into a transfer.
|
||||||
|
if (TransactionType::TRANSFER === $transactionType->type && TransactionType::DEPOSIT === $journal->transactionType->type) {
|
||||||
|
$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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @var JournalUpdateService $service */
|
/** @var JournalUpdateService $service */
|
||||||
$service = app(JournalUpdateService::class);
|
$service = app(JournalUpdateService::class);
|
||||||
$service->setTransactionJournal($journal);
|
$service->setTransactionJournal($journal);
|
||||||
|
Loading…
Reference in New Issue
Block a user