mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Remove static references
This commit is contained in:
@@ -53,13 +53,13 @@ trait ModifiesPiggyBanks
|
||||
*/
|
||||
public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void
|
||||
{
|
||||
Log::debug(sprintf('addAmountToRepetition: %s', $amount));
|
||||
app('log')->debug(sprintf('addAmountToRepetition: %s', $amount));
|
||||
if (-1 === bccomp($amount, '0')) {
|
||||
Log::debug('Remove amount.');
|
||||
app('log')->debug('Remove amount.');
|
||||
$this->removeAmount($repetition->piggyBank, bcmul($amount, '-1'), $journal);
|
||||
}
|
||||
if (1 === bccomp($amount, '0')) {
|
||||
Log::debug('Add amount.');
|
||||
app('log')->debug('Add amount.');
|
||||
$this->addAmount($repetition->piggyBank, $amount, $journal);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ trait ModifiesPiggyBanks
|
||||
$repetition->currentamount = bcsub($repetition->currentamount, $amount);
|
||||
$repetition->save();
|
||||
|
||||
Log::debug('addAmount [a]: Trigger change for negative amount.');
|
||||
app('log')->debug('addAmount [a]: Trigger change for negative amount.');
|
||||
event(new ChangedAmount($piggyBank, bcmul($amount, '-1'), $journal, null));
|
||||
|
||||
return true;
|
||||
@@ -103,7 +103,7 @@ trait ModifiesPiggyBanks
|
||||
$repetition->currentamount = bcadd($currentAmount, $amount);
|
||||
$repetition->save();
|
||||
|
||||
Log::debug('addAmount [b]: Trigger change for positive amount.');
|
||||
app('log')->debug('addAmount [b]: Trigger change for positive amount.');
|
||||
event(new ChangedAmount($piggyBank, $amount, $journal, null));
|
||||
|
||||
return true;
|
||||
@@ -131,11 +131,11 @@ trait ModifiesPiggyBanks
|
||||
$compare = bccomp($amount, $maxAmount);
|
||||
$result = $compare <= 0;
|
||||
|
||||
Log::debug(sprintf('Left on account: %s on %s', $leftOnAccount, $today->format('Y-m-d')));
|
||||
Log::debug(sprintf('Saved so far: %s', $savedSoFar));
|
||||
Log::debug(sprintf('Left to save: %s', $leftToSave));
|
||||
Log::debug(sprintf('Maximum amount: %s', $maxAmount));
|
||||
Log::debug(sprintf('Compare <= 0? %d, so %s', $compare, var_export($result, true)));
|
||||
app('log')->debug(sprintf('Left on account: %s on %s', $leftOnAccount, $today->format('Y-m-d')));
|
||||
app('log')->debug(sprintf('Saved so far: %s', $savedSoFar));
|
||||
app('log')->debug(sprintf('Left to save: %s', $leftToSave));
|
||||
app('log')->debug(sprintf('Maximum amount: %s', $maxAmount));
|
||||
app('log')->debug(sprintf('Compare <= 0? %d, so %s', $compare, var_export($result, true)));
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -202,11 +202,11 @@ trait ModifiesPiggyBanks
|
||||
$repetition->save();
|
||||
|
||||
if (-1 === bccomp($difference, '0')) {
|
||||
Log::debug('addAmount [c]: Trigger change for negative amount.');
|
||||
app('log')->debug('addAmount [c]: Trigger change for negative amount.');
|
||||
event(new ChangedAmount($piggyBank, $difference, null, null));
|
||||
}
|
||||
if (1 === bccomp($difference, '0')) {
|
||||
Log::debug('addAmount [d]: Trigger change for positive amount.');
|
||||
app('log')->debug('addAmount [d]: Trigger change for positive amount.');
|
||||
event(new ChangedAmount($piggyBank, $difference, null, null));
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ trait ModifiesPiggyBanks
|
||||
$current = 1;
|
||||
foreach ($set as $piggyBank) {
|
||||
if ((int)$piggyBank->order !== $current) {
|
||||
Log::debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||
app('log')->debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||
$piggyBank->order = $current;
|
||||
$piggyBank->save();
|
||||
}
|
||||
@@ -313,13 +313,13 @@ trait ModifiesPiggyBanks
|
||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
||||
{
|
||||
$oldOrder = (int)$piggyBank->order;
|
||||
//Log::debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
//app('log')->debug(sprintf('Will move piggy bank #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
if ($newOrder > $oldOrder) {
|
||||
$this->user->piggyBanks()->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||
->decrement('piggy_banks.order');
|
||||
$piggyBank->order = $newOrder;
|
||||
Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
app('log')->debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
@@ -329,7 +329,7 @@ trait ModifiesPiggyBanks
|
||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||
->increment('piggy_banks.order');
|
||||
$piggyBank->order = $newOrder;
|
||||
Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
app('log')->debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -66,12 +66,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function findPiggyBank(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
|
||||
{
|
||||
Log::debug('Searching for piggy information.');
|
||||
app('log')->debug('Searching for piggy information.');
|
||||
|
||||
if (null !== $piggyBankId) {
|
||||
$searchResult = $this->find((int)$piggyBankId);
|
||||
if (null !== $searchResult) {
|
||||
Log::debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
|
||||
app('log')->debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
@@ -79,12 +79,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
if (null !== $piggyBankName) {
|
||||
$searchResult = $this->findByName((string)$piggyBankName);
|
||||
if (null !== $searchResult) {
|
||||
Log::debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
|
||||
app('log')->debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
}
|
||||
Log::debug('Found nothing');
|
||||
app('log')->debug('Found nothing');
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
|
||||
{
|
||||
Log::debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
||||
app('log')->debug(sprintf('Now in getExactAmount(%d, %d, %d)', $piggyBank->id, $repetition->id, $journal->id));
|
||||
|
||||
$operator = null;
|
||||
$currency = null;
|
||||
@@ -198,7 +198,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
$piggyBankCurrency = $accountRepos->getAccountCurrency($piggyBank->account) ?? $defaultCurrency;
|
||||
|
||||
Log::debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
||||
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBankCurrency->code));
|
||||
|
||||
/** @var Transaction $source */
|
||||
$source = $journal->transactions()->with(['account'])->where('amount', '<', 0)->first();
|
||||
@@ -209,17 +209,17 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
if ($source->account_id === $piggyBank->account_id) {
|
||||
$operator = 'negative';
|
||||
$currency = $accountRepos->getAccountCurrency($source->account) ?? $defaultCurrency;
|
||||
Log::debug(sprintf('Currency will draw money out of piggy bank. Source currency is %s', $currency->code));
|
||||
app('log')->debug(sprintf('Currency will draw money out of piggy bank. Source currency is %s', $currency->code));
|
||||
}
|
||||
|
||||
// matches destination, which means amount will be added to piggy.
|
||||
if ($destination->account_id === $piggyBank->account_id) {
|
||||
$operator = 'positive';
|
||||
$currency = $accountRepos->getAccountCurrency($destination->account) ?? $defaultCurrency;
|
||||
Log::debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
|
||||
app('log')->debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
|
||||
}
|
||||
if (null === $operator || null === $currency) {
|
||||
Log::debug('Currency is NULL and operator is NULL, return "0".');
|
||||
app('log')->debug('Currency is NULL and operator is NULL, return "0".');
|
||||
|
||||
return '0';
|
||||
}
|
||||
@@ -227,46 +227,46 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
// which amount from the transaction matches?
|
||||
$amount = null;
|
||||
if ((int)$source->transaction_currency_id === (int)$currency->id) {
|
||||
Log::debug('Use normal amount');
|
||||
app('log')->debug('Use normal amount');
|
||||
$amount = app('steam')->$operator($source->amount);
|
||||
}
|
||||
if ((int)$source->foreign_currency_id === (int)$currency->id) {
|
||||
Log::debug('Use foreign amount');
|
||||
app('log')->debug('Use foreign amount');
|
||||
$amount = app('steam')->$operator($source->foreign_amount);
|
||||
}
|
||||
if (null === $amount) {
|
||||
Log::debug('No match on currency, so amount remains null, return "0".');
|
||||
app('log')->debug('No match on currency, so amount remains null, return "0".');
|
||||
|
||||
return '0';
|
||||
}
|
||||
|
||||
Log::debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
||||
app('log')->debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount));
|
||||
$room = bcsub((string)$piggyBank->targetamount, (string)$repetition->currentamount);
|
||||
$compare = bcmul($repetition->currentamount, '-1');
|
||||
|
||||
if (bccomp((string)$piggyBank->targetamount, '0') === 0) {
|
||||
// amount is zero? then the "room" is positive amount of we wish to add or remove.
|
||||
$room = app('steam')->positive($amount);
|
||||
Log::debug(sprintf('Room is now %s', $room));
|
||||
app('log')->debug(sprintf('Room is now %s', $room));
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
app('log')->debug(sprintf('Will add/remove %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
|
||||
// if the amount is positive, make sure it fits in piggy bank:
|
||||
if (1 === bccomp($amount, '0') && bccomp($room, $amount) === -1) {
|
||||
// amount is positive and $room is smaller than $amount
|
||||
Log::debug(sprintf('Room in piggy bank for extra money is %f', $room));
|
||||
Log::debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
Log::debug(sprintf('New amount is %f', $room));
|
||||
app('log')->debug(sprintf('Room in piggy bank for extra money is %f', $room));
|
||||
app('log')->debug(sprintf('There is NO room to add %f to piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
app('log')->debug(sprintf('New amount is %f', $room));
|
||||
|
||||
return $room;
|
||||
}
|
||||
|
||||
// amount is negative and $currentamount is smaller than $amount
|
||||
if (bccomp($amount, '0') === -1 && 1 === bccomp($compare, $amount)) {
|
||||
Log::debug(sprintf('Max amount to remove is %f', $repetition->currentamount));
|
||||
Log::debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
Log::debug(sprintf('New amount is %f', $compare));
|
||||
app('log')->debug(sprintf('Max amount to remove is %f', $repetition->currentamount));
|
||||
app('log')->debug(sprintf('Cannot remove %f from piggy bank #%d ("%s")', $amount, $piggyBank->id, $piggyBank->name));
|
||||
app('log')->debug(sprintf('New amount is %f', $compare));
|
||||
|
||||
return $compare;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user