Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code for #2397
James Cole1d2c834b2ced
diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.phpindex d185e4c975..9910177ee9 100644--- a/app/Factory/TransactionJournalFactory.php+++ b/app/Factory/TransactionJournalFactory.php@@ -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([diff --git a/app/Support/Import/Routine/File/AssetAccountMapper.php b/app/Support/Import/Routine/File/AssetAccountMapper.phpindex 4c0e472b35..fa4ead0ad3 100644--- a/app/Support/Import/Routine/File/AssetAccountMapper.php+++ b/app/Support/Import/Routine/File/AssetAccountMapper.php@@ -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);diff --git a/app/Support/Import/Routine/File/ImportableConverter.php b/app/Support/Import/Routine/File/ImportableConverter.phpindex 69025d24f3..b762741bd9 100644--- a/app/Support/Import/Routine/File/ImportableConverter.php+++ b/app/Support/Import/Routine/File/ImportableConverter.php@@ -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(diff --git a/app/Support/Import/Routine/File/OpposingAccountMapper.php b/app/Support/Import/Routine/File/OpposingAccountMapper.phpindex 36fe9e5dd6..817f45d54b 100644--- a/app/Support/Import/Routine/File/OpposingAccountMapper.php+++ b/app/Support/Import/Routine/File/OpposingAccountMapper.php@@ -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;