mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Proper recalculation of balance [skip ci]
This commit is contained in:
parent
889598a4c8
commit
d8bafb349d
@ -27,6 +27,7 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Support\Models\AccountBalanceCalculator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@ -50,6 +51,7 @@ class FixUnevenAmount extends Command
|
||||
$this->convertOldStyleTransfers();
|
||||
$this->fixUnevenAmounts();
|
||||
$this->matchCurrencies();
|
||||
AccountBalanceCalculator::recalculateAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ class CorrectAccountBalance extends Command
|
||||
|
||||
return 0;
|
||||
}
|
||||
$this->correctBalanceAmounts();
|
||||
$this->friendlyWarning('This command has been disabled.');
|
||||
$this->markAsExecuted();
|
||||
|
||||
// $this->correctBalanceAmounts();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -168,6 +168,7 @@ class JournalUpdateService
|
||||
app('preferences')->mark();
|
||||
|
||||
$this->transactionJournal->refresh();
|
||||
Log::debug('Done with update journal routine');
|
||||
}
|
||||
|
||||
private function hasValidAccounts(): bool
|
||||
@ -657,11 +658,14 @@ class JournalUpdateService
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$origSourceTransaction = $this->getSourceTransaction();
|
||||
$origSourceTransaction->amount = app('steam')->negative($amount);
|
||||
$origSourceTransaction->balance_dirty = true;
|
||||
$origSourceTransaction->save();
|
||||
$destTransaction = $this->getDestinationTransaction();
|
||||
$destTransaction->amount = app('steam')->positive($amount);
|
||||
$destTransaction->balance_dirty = true;
|
||||
$destTransaction->save();
|
||||
// refresh transactions.
|
||||
$this->sourceTransaction->refresh();
|
||||
@ -716,7 +720,6 @@ class JournalUpdateService
|
||||
}
|
||||
|
||||
|
||||
|
||||
$dest->save();
|
||||
|
||||
app('log')->debug(
|
||||
@ -751,8 +754,5 @@ class JournalUpdateService
|
||||
$this->destinationTransaction->refresh();
|
||||
}
|
||||
|
||||
private function collectCurrency(): TransactionCurrency
|
||||
{
|
||||
|
||||
}
|
||||
private function collectCurrency(): TransactionCurrency {}
|
||||
}
|
||||
|
@ -31,6 +31,14 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
/**
|
||||
* Class AccountBalanceCalculator
|
||||
*
|
||||
* This class started as a piece of code to create and calculate "account balance" objects, but they
|
||||
* are at the moment unused. Instead, each transaction gets a before/after balance and an indicator if this
|
||||
* balance is up-to-date. This class now contains some methods to recalculate those amounts.
|
||||
*/
|
||||
class AccountBalanceCalculator
|
||||
{
|
||||
private function __construct()
|
||||
@ -39,36 +47,25 @@ class AccountBalanceCalculator
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate all balances for a given account.
|
||||
*
|
||||
* Je moet toch altijd wel alles doen want je weet niet waar een transaction journal invloed op heeft.
|
||||
* Dus dit aantikken per transaction journal is zinloos, beide accounts moeten gedaan worden.
|
||||
* Recalculate all balances.
|
||||
*/
|
||||
public static function recalculateAll(): void
|
||||
{
|
||||
$object = new self();
|
||||
//$object->recalculateLatest(null);
|
||||
$object->optimizedCalculation(new Collection());
|
||||
// $object->recalculateJournals(null, null);
|
||||
}
|
||||
|
||||
public static function recalculateForJournal(TransactionJournal $transactionJournal): void
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
$object = new self();
|
||||
|
||||
// new optimized code, currently UNUSED:
|
||||
// recalculate everything ON or AFTER the moment of this transaction.
|
||||
// Transaction
|
||||
// ::leftjoin('transaction_journals','transaction_journals.id','=','transactions.transaction_journal_id')
|
||||
// ->where('transaction_journals.user_id', $transactionJournal->user_id)
|
||||
// ->where('transaction_journals.date', '>=', $transactionJournal->date)
|
||||
// ->update(['transactions.balance_dirty' => true]);
|
||||
// $object->optimizedCalculation(new Collection());
|
||||
|
||||
// recalculate the involved accounts:
|
||||
$accounts = new Collection;
|
||||
foreach($transactionJournal->transactions as $transaction) {
|
||||
$object->recalculateLatest($transaction->account);
|
||||
//$object->recalculateJournals($transaction->account, $transactionJournal);
|
||||
$accounts->push($transaction->account);
|
||||
}
|
||||
$object->optimizedCalculation($accounts);
|
||||
}
|
||||
|
||||
private function getAccountBalanceByAccount(int $account, int $currency): AccountBalance
|
||||
|
Loading…
Reference in New Issue
Block a user