whereNotNull('revaluation_percentage') ->where('revaluation_percentage', '!=', 0) ->with('account') ->get(); $applied = 0; $skipped = 0; foreach ($details as $detail) { $account = $detail->account; if (! $account) { $skipped++; continue; } $latestBalance = $account->balances() ->orderByDesc('balance_date') ->first(); if (! $latestBalance) { $skipped++; continue; } $annualRate = (float) $detail->revaluation_percentage / 100; $monthlyMultiplier = (1 + $annualRate) ** (1 / 12); $newBalance = (int) round($latestBalance->balance * $monthlyMultiplier); $account->balances()->updateOrCreate( ['balance_date' => now()->toDateString()], ['balance' => $newBalance], ); $applied++; } $this->info("Revaluation applied to {$applied} account(s), skipped {$skipped}."); return self::SUCCESS; } }