mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
Code for #2397
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user