Shored up the date math, updated the explanation

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-02-17 14:34:33 -08:00
parent ea429d650e
commit 5fe999eb02
2 changed files with 11 additions and 12 deletions

View file

@ -627,26 +627,24 @@ class SettingsController extends Controller
if ($request->input('audit_interval') != $setting->audit_interval) { if ($request->input('audit_interval') != $setting->audit_interval) {
// Be careful - this could be a negative number // 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::debug('We need to update audit dates. Interval is changing from '.$setting->audit_interval.' to '.$request->input('audit_interval'));
\Log::error('Audit difference: '.$audit_diff_months); \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) { foreach ($assets as $asset) {
if ($asset->next_audit_date != '') { if ($asset->next_audit_date != '') {
$old_next_audit = Carbon::parse($asset->next_audit_date); $old_next_audit = new \DateTime($asset->next_audit_date);
\Log::error('Old audit date: '.$old_next_audit); \Log::debug('Old audit date: '.$old_next_audit->format('Y-m-d'));
\Log::error('Adding '.$audit_diff_months.' months'); \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); \Log::debug('New audit date: '.$asset->next_audit_date->format('Y-m-d'));
$asset->next_audit_date = $new_next_audit;
$asset->forceSave(); $asset->forceSave();
} }

View file

@ -2,6 +2,7 @@
return [ return [
'ad' => 'Active Directory', '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' => 'Active Directory domain',
'ad_domain_help' => 'This is sometimes the same as your email domain, but not always.', 'ad_domain_help' => 'This is sometimes the same as your email domain, but not always.',
'ad_append_domain_label' => 'Append domain name', '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.', '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', 'asset_ids' => 'Asset IDs',
'audit_interval' => 'Audit Interval', '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' => 'Audit Warning Threshold',
'audit_warning_days_help' => 'How many days in advance should we warn you when assets are due for auditing?', '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', 'auto_increment_assets' => 'Generate auto-incrementing asset tags',