mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #2397
This commit is contained in:
parent
cc243f9fb7
commit
1d2c834b2c
@ -261,7 +261,7 @@ class TransactionJournalFactory
|
||||
$sourceForeignCurrency = $foreignCurrency;
|
||||
$destForeignCurrency = $foreignCurrency;
|
||||
|
||||
if ('Withdrawal' === $type->type) {
|
||||
if (TransactionType::WITHDRAWAL === $type->type) {
|
||||
// make sure currency is correct.
|
||||
$currency = $this->getCurrency($currency, $sourceAccount);
|
||||
// make sure foreign currency != currency.
|
||||
@ -273,7 +273,7 @@ class TransactionJournalFactory
|
||||
$sourceForeignCurrency = $foreignCurrency;
|
||||
$destForeignCurrency = $foreignCurrency;
|
||||
}
|
||||
if ('Deposit' === $type->type) {
|
||||
if (TransactionType::DEPOSIT === $type->type) {
|
||||
// make sure currency is correct.
|
||||
$currency = $this->getCurrency($currency, $destinationAccount);
|
||||
// make sure foreign currency != currency.
|
||||
@ -298,11 +298,6 @@ class TransactionJournalFactory
|
||||
$destForeignCurrency = $currency;
|
||||
}
|
||||
|
||||
// if transfer, switch accounts:
|
||||
if (TransactionType::TRANSFER === $type->type) {
|
||||
[$sourceAccount, $destinationAccount] = [$destinationAccount, $sourceAccount];
|
||||
}
|
||||
|
||||
/** Create a basic journal. */
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
|
@ -64,7 +64,7 @@ class AssetAccountMapper
|
||||
*/
|
||||
public function map(?int $accountId, array $data): Account
|
||||
{
|
||||
Log::debug('Now in AssetAccountMapper::map()');
|
||||
Log::debug(sprintf('Now in AssetAccountMapper::map(%d)', $accountId), $data);
|
||||
if ((int)$accountId > 0) {
|
||||
// find asset account with this ID:
|
||||
$result = $this->repository->findNull($accountId);
|
||||
|
@ -112,15 +112,11 @@ class ImportableConverter
|
||||
|
||||
$source = $this->assetMapper->map($importable->accountId, $importable->getAccountData());
|
||||
$destination = $this->opposingMapper->map($importable->opposingId, $amount, $importable->getOpposingAccountData());
|
||||
$currency = $this->currencyMapper->map($importable->currencyId, $importable->getCurrencyData());
|
||||
$foreignCurrency = $this->currencyMapper->map($importable->foreignCurrencyId, $importable->getForeignCurrencyData());
|
||||
|
||||
Log::debug(sprintf('"%s" (#%d) is source and "%s" (#%d) is destination.', $source->name, $source->id, $destination->name, $destination->id));
|
||||
|
||||
|
||||
// amount is positive? Then switch:
|
||||
// if the amount is positive, switch source and destination (account and opposing account)
|
||||
if (1 === bccomp($amount, '0')) {
|
||||
[$destination, $source] = [$source, $destination];
|
||||
$source = $this->opposingMapper->map($importable->opposingId, $amount, $importable->getOpposingAccountData());
|
||||
$destination = $this->assetMapper->map($importable->accountId, $importable->getAccountData());
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'%s is positive, so "%s" (#%d) is now source and "%s" (#%d) is now destination.',
|
||||
@ -129,6 +125,12 @@ class ImportableConverter
|
||||
);
|
||||
}
|
||||
|
||||
$currency = $this->currencyMapper->map($importable->currencyId, $importable->getCurrencyData());
|
||||
$foreignCurrency = $this->currencyMapper->map($importable->foreignCurrencyId, $importable->getForeignCurrencyData());
|
||||
|
||||
Log::debug(sprintf('"%s" (#%d) is source and "%s" (#%d) is destination.', $source->name, $source->id, $destination->name, $destination->id));
|
||||
|
||||
|
||||
if ($destination->id === $source->id) {
|
||||
throw new FireflyException(
|
||||
sprintf(
|
||||
|
@ -49,7 +49,7 @@ class OpposingAccountMapper
|
||||
*/
|
||||
public function map(?int $accountId, string $amount, array $data): Account
|
||||
{
|
||||
Log::debug('Now in OpposingAccountMapper::map()');
|
||||
Log::debug(sprintf('Now in OpposingAccountMapper::map(%d, "%s")', $accountId, $amount), $data);
|
||||
// default assumption is we're looking for an expense account.
|
||||
$expectedType = AccountType::EXPENSE;
|
||||
$result = null;
|
||||
|
Loading…
Reference in New Issue
Block a user