diff --git a/app/Console/Commands/ResetDemoAccountCommand.php b/app/Console/Commands/ResetDemoAccountCommand.php index 1bf78583..604a3653 100644 --- a/app/Console/Commands/ResetDemoAccountCommand.php +++ b/app/Console/Commands/ResetDemoAccountCommand.php @@ -276,7 +276,7 @@ class ResetDemoAccountCommand extends Command $balances = []; for ($i = 0; $i <= 12; $i++) { - $date = now()->subMonths($i)->endOfMonth(); + $date = now()->subMonthsNoOverflow($i)->endOfMonth(); if ($i === 0) { $date = now(); diff --git a/app/Http/Controllers/Api/CashflowAnalyticsController.php b/app/Http/Controllers/Api/CashflowAnalyticsController.php index 99dfe7a1..ed24ac44 100644 --- a/app/Http/Controllers/Api/CashflowAnalyticsController.php +++ b/app/Http/Controllers/Api/CashflowAnalyticsController.php @@ -67,7 +67,7 @@ class CashflowAnalyticsController extends Controller $userId = $request->user()->id; $end = Carbon::now()->endOfMonth(); - $start = Carbon::now()->subMonths($months - 1)->startOfMonth(); + $start = Carbon::now()->subMonthsNoOverflow($months - 1)->startOfMonth(); $data = []; $current = $start->copy(); diff --git a/tests/Feature/AccountControllerTest.php b/tests/Feature/AccountControllerTest.php index 98fb1cad..366b7113 100644 --- a/tests/Feature/AccountControllerTest.php +++ b/tests/Feature/AccountControllerTest.php @@ -167,7 +167,7 @@ test('account balance evolution returns data for single account', function () { ]); $response = $this->getJson('/api/dashboard/account/'.$account->id.'/balance-evolution?'.http_build_query([ - 'from' => now()->subMonths(2)->startOfMonth()->toDateString(), + 'from' => now()->subMonthsNoOverflow(2)->startOfMonth()->toDateString(), 'to' => now()->endOfMonth()->toDateString(), ])); diff --git a/tests/Feature/CashflowAnalyticsTest.php b/tests/Feature/CashflowAnalyticsTest.php index 2dec35bb..bc6432bb 100644 --- a/tests/Feature/CashflowAnalyticsTest.php +++ b/tests/Feature/CashflowAnalyticsTest.php @@ -223,14 +223,14 @@ test('cashflow trend returns monthly data for specified months', function () { 'account_id' => $account->id, 'category_id' => $incomeCategory->id, 'amount' => 100000 + ($i * 10000), - 'transaction_date' => now()->subMonths($i), + 'transaction_date' => now()->subMonthsNoOverflow($i), ]); Transaction::factory()->create([ 'user_id' => $this->user->id, 'account_id' => $account->id, 'category_id' => $expenseCategory->id, 'amount' => -(50000 + ($i * 5000)), - 'transaction_date' => now()->subMonths($i), + 'transaction_date' => now()->subMonthsNoOverflow($i), ]); } diff --git a/tests/Feature/DashboardAnalyticsTest.php b/tests/Feature/DashboardAnalyticsTest.php index 108d72f7..78c2c3a1 100644 --- a/tests/Feature/DashboardAnalyticsTest.php +++ b/tests/Feature/DashboardAnalyticsTest.php @@ -211,7 +211,7 @@ test('net worth evolution returns monthly data points with per-account balances' ]); $response = $this->getJson('/api/dashboard/net-worth-evolution?'.http_build_query([ - 'from' => now()->subMonths(2)->startOfMonth()->toDateString(), + 'from' => now()->subMonthsNoOverflow(2)->startOfMonth()->toDateString(), 'to' => now()->endOfMonth()->toDateString(), ]));