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