First fixes for level 7.

This commit is contained in:
James Cole
2025-01-04 19:12:04 +01:00
parent d2b6829574
commit 23178614d5
4 changed files with 33 additions and 16 deletions

View File

@@ -36,7 +36,7 @@ class RemovesEmptyJournals extends Command
protected $description = 'Delete empty and uneven transaction journals.'; protected $description = 'Delete empty and uneven transaction journals.';
protected $signature = 'correction:empty-journals'; protected $signature = 'correction:empty-journals';
/** /**
* Execute the console command. * Execute the console command.
@@ -55,8 +55,8 @@ class RemovesEmptyJournals extends Command
private function deleteUnevenJournals(): void private function deleteUnevenJournals(): void
{ {
$set = Transaction::whereNull('deleted_at') $set = Transaction::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id') ->groupBy('transactions.transaction_journal_id')
->get([\DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']) // @phpstan-ignore-line ->get([\DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']) // @phpstan-ignore-line
; ;
$total = 0; $total = 0;
@@ -87,14 +87,15 @@ class RemovesEmptyJournals extends Command
{ {
$count = 0; $count = 0;
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') $set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id') ->groupBy('transaction_journals.id')
->whereNull('transactions.transaction_journal_id') ->whereNull('transactions.transaction_journal_id')
->get(['transaction_journals.id']) ->get(['transaction_journals.id']);
;
foreach ($set as $entry) { foreach ($set as $entry) {
try { try {
TransactionJournal::find($entry->id)->delete(); /** @var TransactionJournal|null $journal */
$journal = TransactionJournal::find($entry->id);
$journal?->delete();
} catch (QueryException $e) { } catch (QueryException $e) {
app('log')->info(sprintf('Could not delete entry: %s', $e->getMessage())); app('log')->info(sprintf('Could not delete entry: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());

View File

@@ -264,7 +264,9 @@ class ForcesDecimalSize extends Command
$pow = 10 ** $currency->decimal_places; $pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12); $correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct)); $this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
Account::find($account->id)->update([$field => $correct]); /** @var Account|null $updateAccount */
$updateAccount = Account::find($account->id);
$updateAccount?->update([$field => $correct]);
} }
} }
} }
@@ -313,7 +315,9 @@ class ForcesDecimalSize extends Command
$pow = 10 ** $currency->decimal_places; $pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12); $correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct)); $this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct));
$class::find($item->id)->update([$field => $correct]); /** @var Model|null $model */
$model = $class::find($item->id);
$model?->update([$field => $correct]);
} }
} }
} }
@@ -365,7 +369,9 @@ class ForcesDecimalSize extends Command
$this->friendlyWarning( $this->friendlyWarning(
sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct) sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
); );
PiggyBankEvent::find($item->id)->update([$field => $correct]); /** @var PiggyBankEvent|null $event */
$event = PiggyBankEvent::find($item->id);
$event?->update([$field => $correct]);
} }
} }
} }
@@ -418,7 +424,9 @@ class ForcesDecimalSize extends Command
$this->friendlyWarning( $this->friendlyWarning(
sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct) sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
); );
PiggyBankRepetition::find($item->id)->update([$field => $correct]); /** @var PiggyBankRepetition|null $repetition */
$repetition = PiggyBankRepetition::find($item->id);
$repetition->update([$field => $correct]);
} }
} }
} }
@@ -467,7 +475,9 @@ class ForcesDecimalSize extends Command
$pow = 10 ** $currency->decimal_places; $pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12); $correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)); $this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
PiggyBank::find($item->id)->update([$field => $correct]); /** @var PiggyBank|null $piggyBank */
$piggyBank = PiggyBank::find($item->id);
$piggyBank?->update([$field => $correct]);
} }
} }
} }
@@ -500,7 +510,9 @@ class ForcesDecimalSize extends Command
$pow = (float) 10 ** $currency->decimal_places; $pow = (float) 10 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12); $correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)); $this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct));
Transaction::find($item->id)->update(['amount' => $correct]); /** @var Transaction|null $transaction */
$transaction = Transaction::find($item->id);
$transaction?->update(['amount' => $correct]);
} }
// select all transactions with this FOREIGN currency and issue. // select all transactions with this FOREIGN currency and issue.
@@ -530,7 +542,9 @@ class ForcesDecimalSize extends Command
$this->friendlyWarning( $this->friendlyWarning(
sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct) sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)
); );
Transaction::find($item->id)->update(['foreign_amount' => $correct]); /** @var Transaction|null $transaction */
$transaction = Transaction::find($item->id);
$transaction?->update(['foreign_amount' => $correct]);
} }
} }

View File

@@ -53,9 +53,11 @@ class BudgetLimitHandler
private function updateAvailableBudget(BudgetLimit $budgetLimit): void private function updateAvailableBudget(BudgetLimit $budgetLimit): void
{ {
Log::debug(sprintf('Now in updateAvailableBudget(limit #%d)', $budgetLimit->id)); Log::debug(sprintf('Now in updateAvailableBudget(limit #%d)', $budgetLimit->id));
/** @var Budget|null $budget */
$budget = Budget::find($budgetLimit->budget_id); $budget = Budget::find($budgetLimit->budget_id);
if (null === $budget) { if (null === $budget) {
Log::warning('Budget is null, probably deleted, find deleted version.'); Log::warning('Budget is null, probably deleted, find deleted version.');
/** @var Budget|null $budget */
$budget = Budget::withTrashed()->find($budgetLimit->budget_id); $budget = Budget::withTrashed()->find($budgetLimit->budget_id);
} }
if (null === $budget) { if (null === $budget) {

View File

@@ -37,7 +37,7 @@ return [
| |
*/ */
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', '')), 'stateful' => explode(',', (string) env('SANCTUM_STATEFUL_DOMAINS', '')),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------