From ecac4718fe3c2961a4e693f2038657b90cae98dc Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 13 Jul 2023 16:02:47 -0600 Subject: [PATCH 1/2] Add date casting to the SQL query, so the BETWEEN range doesn't care about time of day in custom report datetimes --- app/Http/Controllers/ReportsController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 4fa7990a22..2e05b0ae70 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -639,10 +639,10 @@ class ReportsController extends Controller } if (($request->filled('created_start')) && ($request->filled('created_end'))) { - $assets->whereBetween('assets.created_at', [$request->input('created_start'), $request->input('created_end')]); + $assets->whereBetween(\DB::raw('DATE(assets.created_at)'), [$request->input('created_start'), $request->input('created_end')]); } if (($request->filled('checkout_date_start')) && ($request->filled('checkout_date_end'))) { - $assets->whereBetween('assets.last_checkout', [$request->input('checkout_date_start'), $request->input('checkout_date_end')]); + $assets->whereBetween(\DB::raw('DATE(assets.last_checkout)'), [$request->input('checkout_date_start'), $request->input('checkout_date_end') ]); } if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) { @@ -650,7 +650,7 @@ class ReportsController extends Controller } if (($request->filled('last_audit_start')) && ($request->filled('last_audit_end'))) { - $assets->whereBetween('assets.last_audit_date', [$request->input('last_audit_start'), $request->input('last_audit_end')]); + $assets->whereBetween(\DB::raw('DATE(assets.last_audit_date)'), [$request->input('last_audit_start'), $request->input('last_audit_end')]); } if (($request->filled('next_audit_start')) && ($request->filled('next_audit_end'))) { From cb4ed92639d1510e4ea8be7337fe0753f3e724e8 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 20 Jul 2023 16:17:06 -0600 Subject: [PATCH 2/2] Use Carbon date objects instead of casting using DB::raw() --- app/Http/Controllers/ReportsController.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 2e05b0ae70..11b829f3be 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -639,10 +639,16 @@ class ReportsController extends Controller } if (($request->filled('created_start')) && ($request->filled('created_end'))) { - $assets->whereBetween(\DB::raw('DATE(assets.created_at)'), [$request->input('created_start'), $request->input('created_end')]); + $created_start = \Carbon::parse($request->input('created_start'))->startOfDay(); + $created_end = \Carbon::parse($request->input('created_end'))->endOfDay(); + + $assets->whereBetween('assets.created_at', [$created_start, $created_end]); } if (($request->filled('checkout_date_start')) && ($request->filled('checkout_date_end'))) { - $assets->whereBetween(\DB::raw('DATE(assets.last_checkout)'), [$request->input('checkout_date_start'), $request->input('checkout_date_end') ]); + $checkout_start = \Carbon::parse($request->input('checkout_date_start'))->startOfDay(); + $checkout_end = \Carbon::parse($request->input('checkout_date_end'))->endOfDay(); + + $assets->whereBetween('assets.last_checkout', [$checkout_start, $checkout_end]); } if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) { @@ -650,7 +656,10 @@ class ReportsController extends Controller } if (($request->filled('last_audit_start')) && ($request->filled('last_audit_end'))) { - $assets->whereBetween(\DB::raw('DATE(assets.last_audit_date)'), [$request->input('last_audit_start'), $request->input('last_audit_end')]); + $last_audit_start = \Carbon::parse($request->input('last_audit_start'))->startOfDay(); + $last_audit_end = \Carbon::parse($request->input('last_audit_end'))->endOfDay(); + + $assets->whereBetween('assets.last_audit_date', [$last_audit_start, $last_audit_end]); } if (($request->filled('next_audit_start')) && ($request->filled('next_audit_end'))) {