From 5fe999eb0293dfd51e5db4f2c2ded4db7f7121f8 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 17 Feb 2022 14:34:33 -0800 Subject: [PATCH] Shored up the date math, updated the explanation Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 20 +++++++++----------- resources/lang/en/admin/settings/general.php | 3 ++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 0b8385b9f4..1b85f0eeeb 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -627,26 +627,24 @@ class SettingsController extends Controller if ($request->input('audit_interval') != $setting->audit_interval) { // Be careful - this could be a negative number - $audit_diff_months = ($setting->audit_interval - (int)$request->input('audit_interval')); + $audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval)); - \Log::error('we need to update audit dates'); - \Log::error('Audit difference: '.$audit_diff_months); + \Log::debug('We need to update audit dates. Interval is changing from '.$setting->audit_interval.' to '.$request->input('audit_interval')); + \Log::debug('Audit difference: '.$audit_diff_months); - $assets = Asset::whereNotNull('next_audit_date')->take(10)->get(); + $assets = Asset::whereNotNull('next_audit_date')->get(); foreach ($assets as $asset) { if ($asset->next_audit_date != '') { - $old_next_audit = Carbon::parse($asset->next_audit_date); - \Log::error('Old audit date: '.$old_next_audit); - \Log::error('Adding '.$audit_diff_months.' months'); + $old_next_audit = new \DateTime($asset->next_audit_date); + \Log::debug('Old audit date: '.$old_next_audit->format('Y-m-d')); + \Log::debug('Adding '.$audit_diff_months.' months'); - $new_next_audit = $old_next_audit->addMonths($audit_diff_months)->format('Y-m-d'); + $asset->next_audit_date = $old_next_audit->modify($audit_diff_months.' month')->format('Y-m-d'); - \Log::error('New audit date: '.$new_next_audit); - - $asset->next_audit_date = $new_next_audit; + \Log::debug('New audit date: '.$asset->next_audit_date->format('Y-m-d')); $asset->forceSave(); } diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index d5044c3811..6b8755dd59 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -2,6 +2,7 @@ return [ 'ad' => 'Active Directory', + 'update_null_audits' => 'Also update audit dates on assets without a current next audit date set based on purchase date (if present)', 'ad_domain' => 'Active Directory domain', 'ad_domain_help' => 'This is sometimes the same as your email domain, but not always.', 'ad_append_domain_label' => 'Append domain name', @@ -21,7 +22,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',