This commit is contained in:
James Cole 2019-08-11 17:32:00 +02:00
parent cc243f9fb7
commit 1d2c834b2c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 13 additions and 16 deletions

View File

@ -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(
[

View File

@ -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);

View File

@ -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(

View File

@ -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;