mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This commit is contained in:
parent
94a3bb0443
commit
eed3902cb7
@ -54,7 +54,7 @@ class CorrectsNativeAmounts extends Command
|
|||||||
|
|
||||||
protected $description = 'Recalculate native amounts for all objects.';
|
protected $description = 'Recalculate native amounts for all objects.';
|
||||||
|
|
||||||
protected $signature = 'correction:recalculate-native-amounts';
|
protected $signature = 'correction:recalculate-native-amounts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
@ -102,7 +102,14 @@ class CorrectsNativeAmounts extends Command
|
|||||||
{
|
{
|
||||||
$set = $userGroup->accounts()->where(function (EloquentBuilder $q): void {
|
$set = $userGroup->accounts()->where(function (EloquentBuilder $q): void {
|
||||||
$q->whereNotNull('virtual_balance');
|
$q->whereNotNull('virtual_balance');
|
||||||
$q->orWhere('virtual_balance', '!=', '');
|
|
||||||
|
// this needs a different piece of code for postgres.
|
||||||
|
if ('pgsql' === config('database.default')) {
|
||||||
|
$q->orWhere(DB::raw('CAST(virtual_balance AS TEXT)'), '!=', '');
|
||||||
|
}
|
||||||
|
if ('pgsql' !== config('database.default')) {
|
||||||
|
$q->orWhere('virtual_balance', '!=', '');
|
||||||
|
}
|
||||||
})->get();
|
})->get();
|
||||||
|
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
@ -114,13 +121,13 @@ class CorrectsNativeAmounts extends Command
|
|||||||
|
|
||||||
private function recalculatePiggyBanks(UserGroup $userGroup, TransactionCurrency $currency): void
|
private function recalculatePiggyBanks(UserGroup $userGroup, TransactionCurrency $currency): void
|
||||||
{
|
{
|
||||||
$converter = new ExchangeRateConverter();
|
$converter = new ExchangeRateConverter();
|
||||||
$converter->setUserGroup($userGroup);
|
$converter->setUserGroup($userGroup);
|
||||||
$converter->setIgnoreSettings(true);
|
$converter->setIgnoreSettings(true);
|
||||||
$repository = app(PiggyBankRepositoryInterface::class);
|
$repository = app(PiggyBankRepositoryInterface::class);
|
||||||
$repository->setUserGroup($userGroup);
|
$repository->setUserGroup($userGroup);
|
||||||
$set = $repository->getPiggyBanks();
|
$set = $repository->getPiggyBanks();
|
||||||
$set = $set->filter(
|
$set = $set->filter(
|
||||||
static function (PiggyBank $piggyBank) use ($currency) {
|
static function (PiggyBank $piggyBank) use ($currency) {
|
||||||
return $currency->id !== $piggyBank->transaction_currency_id;
|
return $currency->id !== $piggyBank->transaction_currency_id;
|
||||||
}
|
}
|
||||||
@ -216,23 +223,21 @@ class CorrectsNativeAmounts extends Command
|
|||||||
{
|
{
|
||||||
// custom query because of the potential size of this update.
|
// custom query because of the potential size of this update.
|
||||||
$set = DB::table('transactions')
|
$set = DB::table('transactions')
|
||||||
->join('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
->join('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
->where('transaction_journals.user_group_id', $userGroup->id)
|
->where('transaction_journals.user_group_id', $userGroup->id)
|
||||||
|
->where(function (DatabaseBuilder $q1) use ($currency): void {
|
||||||
->where(function (DatabaseBuilder $q1) use ($currency): void {
|
$q1->where(function (DatabaseBuilder $q2) use ($currency): void {
|
||||||
$q1->where(function (DatabaseBuilder $q2) use ($currency): void {
|
$q2->whereNot('transactions.transaction_currency_id', $currency->id)->whereNull('transactions.foreign_currency_id');
|
||||||
$q2->whereNot('transactions.transaction_currency_id', $currency->id)->whereNull('transactions.foreign_currency_id');
|
})->orWhere(function (DatabaseBuilder $q3) use ($currency): void {
|
||||||
})->orWhere(function (DatabaseBuilder $q3) use ($currency): void {
|
$q3->whereNot('transactions.transaction_currency_id', $currency->id)->whereNot('transactions.foreign_currency_id', $currency->id);
|
||||||
$q3->whereNot('transactions.transaction_currency_id', $currency->id)->whereNot('transactions.foreign_currency_id', $currency->id);
|
});
|
||||||
});
|
})
|
||||||
})
|
|
||||||
// ->where(static function (DatabaseBuilder $q) use ($currency): void {
|
// ->where(static function (DatabaseBuilder $q) use ($currency): void {
|
||||||
// $q->whereNot('transactions.transaction_currency_id', $currency->id)
|
// $q->whereNot('transactions.transaction_currency_id', $currency->id)
|
||||||
// ->whereNot('transactions.foreign_currency_id', $currency->id)
|
// ->whereNot('transactions.foreign_currency_id', $currency->id)
|
||||||
// ;
|
// ;
|
||||||
// })
|
// })
|
||||||
->get(['transactions.id'])
|
->get(['transactions.id']);
|
||||||
;
|
|
||||||
TransactionObserver::$recalculate = false;
|
TransactionObserver::$recalculate = false;
|
||||||
foreach ($set as $item) {
|
foreach ($set as $item) {
|
||||||
// here we are.
|
// here we are.
|
||||||
|
Loading…
Reference in New Issue
Block a user