From ccfc75852aefe0e2ea175356093a4aaecc9279ac Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Tue, 5 Aug 2025 11:02:26 +0200 Subject: [PATCH] Fix #10702 --- .../Chart/CategoryReportController.php | 2 -- app/Support/Navigation.php | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryReportController.php b/app/Http/Controllers/Chart/CategoryReportController.php index e02288a458..34eb15e4bf 100644 --- a/app/Http/Controllers/Chart/CategoryReportController.php +++ b/app/Http/Controllers/Chart/CategoryReportController.php @@ -210,7 +210,6 @@ class CategoryReportController extends Controller $spent = $this->opsRepository->listExpenses($start, $end, $accounts, new Collection([$category])); $earned = $this->opsRepository->listIncome($start, $end, $accounts, new Collection([$category])); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end); - // loop expenses. foreach ($spent as $currency) { // add things to chart Data for each currency: @@ -286,7 +285,6 @@ class CategoryReportController extends Controller $currentStart = clone $currentEnd; $currentStart->addDay()->startOfDay(); } - return $return; } diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 7b607be819..13296c054c 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -565,11 +565,12 @@ class Navigation public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string { $locale = app('steam')->getLocale(); - if ($start->diffInMonths($end, true) > 1) { + $diff = $start->diffInMonths($end, true); + if ($diff >= 1.001) { return (string) trans('config.month_js', [], $locale); } - if ($start->diffInMonths($end, true) > 12) { + if ($diff >= 12.001) { return (string) trans('config.year_js', [], $locale); } @@ -582,11 +583,12 @@ class Navigation */ public function preferredEndOfPeriod(Carbon $start, Carbon $end): string { - if ((int) $start->diffInMonths($end, true) > 1 && (int) $start->diffInMonths($end, true) <= 12) { + $diff = $start->diffInMonths($end, true); + if ($diff >= 1.001) { return 'endOfMonth'; } - if ((int) $start->diffInMonths($end, true) > 12) { + if ($diff >= 12.001) { return 'endOfYear'; } @@ -599,11 +601,12 @@ class Navigation */ public function preferredRangeFormat(Carbon $start, Carbon $end): string { - if ((int) $start->diffInMonths($end, true) > 1 && (int) $start->diffInMonths($end, true) <= 12) { + $diff = $start->diffInMonths($end, true); + if ($diff >= 1.001) { return '1M'; } - if ((int) $start->diffInMonths($end, true) > 12) { + if ($diff >= 12.001) { return '1Y'; } @@ -616,11 +619,12 @@ class Navigation */ public function preferredSqlFormat(Carbon $start, Carbon $end): string { - if ((int) $start->diffInMonths($end, true) > 1 && (int) $start->diffInMonths($end, true) <= 12) { + $diff = $start->diffInMonths($end, true); + if ($diff >= 1.001) { return '%Y-%m'; } - if ((int) $start->diffInMonths($end, true) > 12) { + if ($diff >= 12.001) { return '%Y'; }