mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 09:51:40 +00:00
Fix #3745
This commit is contained in:
@@ -43,6 +43,7 @@ use Storage;
|
|||||||
class PiggyBankRepository implements PiggyBankRepositoryInterface
|
class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||||
{
|
{
|
||||||
use ModifiesPiggyBanks;
|
use ModifiesPiggyBanks;
|
||||||
|
|
||||||
/** @var User */
|
/** @var User */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
@@ -157,6 +158,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
Log::debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
Log::debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
||||||
|
|
||||||
$operator = null;
|
$operator = null;
|
||||||
|
$currency = null;
|
||||||
/** @var JournalRepositoryInterface $journalRepost */
|
/** @var JournalRepositoryInterface $journalRepost */
|
||||||
$journalRepost = app(JournalRepositoryInterface::class);
|
$journalRepost = app(JournalRepositoryInterface::class);
|
||||||
$journalRepost->setUser($this->user);
|
$journalRepost->setUser($this->user);
|
||||||
@@ -171,9 +173,9 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
Log::debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
Log::debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
||||||
|
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $journal->transactions()->with(['Account'])->where('amount', '<', 0)->first();
|
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||||
/** @var Transaction $destination */
|
/** @var Transaction $destination */
|
||||||
$destination = $journal->transactions()->with(['Account'])->where('amount', '>', 0)->first();
|
$destination = $journal->transactions()->with(['account'])->where('amount', '>', 0)->first();
|
||||||
|
|
||||||
// matches source, which means amount will be removed from piggy:
|
// matches source, which means amount will be removed from piggy:
|
||||||
if ($source->account_id === $piggyBank->account_id) {
|
if ($source->account_id === $piggyBank->account_id) {
|
||||||
@@ -189,21 +191,23 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
Log::debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
|
Log::debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
|
||||||
}
|
}
|
||||||
if (null === $operator || null === $currency) {
|
if (null === $operator || null === $currency) {
|
||||||
|
Log::debug('Currency is NULL and operator is NULL, return "0".');
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
// currency of the account + the piggy bank currency are almost the same.
|
// currency of the account + the piggy bank currency are almost the same.
|
||||||
// which amount from the transaction matches?
|
// which amount from the transaction matches?
|
||||||
// $currency->id === $piggyBankCurrency->id
|
// $currency->id === $piggyBankCurrency->id
|
||||||
$amount = null;
|
$amount = null;
|
||||||
if ($source->transaction_currency_id === $currency->id) {
|
if ((int)$source->transaction_currency_id === (int)$currency->id) {
|
||||||
Log::debug('Use normal amount');
|
Log::debug('Use normal amount');
|
||||||
$amount = app('steam')->$operator($source->amount);
|
$amount = app('steam')->$operator($source->amount);
|
||||||
}
|
}
|
||||||
if ($source->foreign_currency_id === $currency->id) {
|
if ((int)$source->foreign_currency_id === (int)$currency->id) {
|
||||||
Log::debug('Use foreign amount');
|
Log::debug('Use foreign amount');
|
||||||
$amount = app('steam')->$operator($source->foreign_amount);
|
$amount = app('steam')->$operator($source->foreign_amount);
|
||||||
}
|
}
|
||||||
if (null === $amount) {
|
if (null === $amount) {
|
||||||
|
Log::debug('No match on currency, so amount remains null, return "0".');
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +273,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Also add amount in name.
|
* Also add amount in name.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user