From 7cc8539298ce52876e619ff50eee294266048bc3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 19 Apr 2018 18:27:39 +0200 Subject: [PATCH] Fix for #1349, thanks to @NyKoF --- app/Import/Storage/ImportStorage.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php index 0e75e0fce1..e53c707ea2 100644 --- a/app/Import/Storage/ImportStorage.php +++ b/app/Import/Storage/ImportStorage.php @@ -210,9 +210,14 @@ class ImportStorage $source = $assetAccount; $destination = $opposingAccount; + // switch account arounds when the transaction type is a deposit. if ($transactionType === TransactionType::DEPOSIT) { - $destination = $assetAccount; - $source = $opposingAccount; + [$destination, $source] = [$source, $destination]; + } + // switch accounts around when the amount is negative and it's a transfer. + // credits to @NyKoF + if($transactionType === TransactionType::TRANSFER && -1 === bccomp($amount, '0')) { + [$destination, $source] = [$source, $destination]; } Log::debug( sprintf('Will make #%s (%s) the source and #%s (%s) the destination.', $source->id, $source->name, $destination->id, $destination->name) @@ -248,7 +253,7 @@ class ImportStorage [ 'description' => null, 'amount' => $amount, - 'currency_id' => (int)$currencyId, + 'currency_id' => $currencyId, 'currency_code' => null, 'foreign_amount' => $foreignAmount, 'foreign_currency_id' => $foreignCurrencyId,