From af1857b6eebc6e4dbf7822a04ea32455a5b37106 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Date: Thu, 18 Jul 2019 16:08:55 -0500 Subject: [PATCH] Fix for the issue when the user tries to query assets due for audit without appropiate configuration [ch9625] (#7273) * Added propper routes to the controller * Logic to handle the not setted ->audit_warning_days variable * Change the variable name for more clarity * Got rid of the unnecesary if sentence in sake of brevity * Adding the null coalesce operator so it can properly handle when the setting is null --- app/Models/Asset.php | 4 +++- routes/web/hardware.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 68f12af20f..dbff25e8d8 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1068,8 +1068,10 @@ class Asset extends Depreciable public function scopeDueOrOverdueForAudit($query, $settings) { + $interval = $settings->audit_warning_days ?? 0; + return $query->whereNotNull('assets.next_audit_date') - ->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $settings->audit_warning_days DAY) <= '".Carbon::now()."'") + ->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $interval DAY) <= '".Carbon::now()."'") ->where('assets.archived', '=', 0) ->NotArchived(); } diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 495b08086e..1eeed11ccf 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -31,12 +31,12 @@ Route::group( Route::get('audit/due', [ 'as' => 'assets.audit.due', - 'uses' => 'AssetsController@dueForAudit' + 'uses' => 'Assets\AssetsController@dueForAudit' ]); Route::get('audit/overdue', [ 'as' => 'assets.audit.overdue', - 'uses' => 'AssetsController@overdueForAudit' + 'uses' => 'Assets\AssetsController@overdueForAudit' ]); Route::get('audit/{id}', [