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
This commit is contained in:
Ivan Nieto 2019-07-18 16:08:55 -05:00 committed by snipe
parent 4c61d330e6
commit af1857b6ee
2 changed files with 5 additions and 3 deletions

View file

@ -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();
}

View file

@ -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}', [