diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index a0851867e2..91fa4d569d 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -8,6 +8,7 @@ use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\SettingsSamlRequest; use App\Http\Requests\SetupUserRequest; use App\Models\Setting; +use App\Models\Asset; use App\Models\User; use App\Notifications\FirstAdminNotification; use App\Notifications\MailTest; @@ -621,6 +622,26 @@ class SettingsController extends Controller return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } + // Check if the audit interval has changed - if it has, we want to update ALL of the assets audit dates + if ($request->input('audit_interval') != $setting->audit_interval) { + + // Be careful - this could be a negative number + $audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval)); + + // Grab all of the assets that have an existing next_audit_date + $assets = Asset::whereNotNull('next_audit_date')->get(); + + // Update all of the assets' next_audit_date values + foreach ($assets as $asset) { + + if ($asset->next_audit_date != '') { + $old_next_audit = new \DateTime($asset->next_audit_date); + $asset->next_audit_date = $old_next_audit->modify($audit_diff_months.' month')->format('Y-m-d'); + $asset->forceSave(); + } + } + } + $alert_email = rtrim($request->input('alert_email'), ','); $alert_email = trim($alert_email); $admin_cc_email = rtrim($request->input('admin_cc_email'), ','); diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index d5044c3811..ef6878cf52 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -21,7 +21,7 @@ return [ 'allow_user_skin_help_text' => 'Checking this box will allow a user to override the UI skin with a different one.', 'asset_ids' => 'Asset IDs', 'audit_interval' => 'Audit Interval', - 'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months.', + 'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months that you use. If you update this value, all of the "next audit dates" for assets with an upcoming audit date.', 'audit_warning_days' => 'Audit Warning Threshold', 'audit_warning_days_help' => 'How many days in advance should we warn you when assets are due for auditing?', 'auto_increment_assets' => 'Generate auto-incrementing asset tags',