Skip to content

A free open source IT asset/license management system

Added scope for both overdue and upcoming

snipee4a298ca2a7a
diff --git a/app/Console/Commands/SendUpcomingAuditReport.php b/app/Console/Commands/SendUpcomingAuditReport.php
index b5eaaabba8..bac5a21698 100644
--- a/app/Console/Commands/SendUpcomingAuditReport.php
+++ b/app/Console/Commands/SendUpcomingAuditReport.php
@@ -58,7 +58,7 @@ class SendUpcomingAuditReport extends Command
// Assets due for auditing
$assets = Asset::whereNotNull('next_audit_date')
- ->dueForAudit($settings)
+ ->DueOrOverdueForAudit($settings)
->orderBy('last_audit_date', 'asc')->get();
if ($assets->count() > 0) {
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index 16c3fabfee..499ff8b748 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -153,7 +153,7 @@ class AssetsController extends Controller
switch ($audit) {
case 'due':
- $assets->DueForAudit($settings);
+ $assets->DueOrOverdueForAudit($settings);
break;
case 'overdue':
$assets->overdueForAudit($settings);
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index fe5cfe65d7..e3233a3e58 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -850,6 +850,29 @@ class Asset extends Depreciable
->NotArchived();
}
+ /**
+ * Query builder scope for Assets that are due for auditing OR overdue, based on the assets.next_audit_date
+ * and settings.audit_warning_days.
+ *
+ * This is/will be used in the artisan command snipeit:upcoming-audits and also
+ * for an upcoming API call for retrieving a report on assets that will need to be audited.
+ *
+ * @author A. Gianotto <[email protected]>
+ * @since v4.5.17
+ * @param Setting $settings
+ *
+ * @return \Illuminate\Database\Query\Builder Modified query builder
+ */
+
+ public function scopeDueOrOverdueForAudit($query, $settings)
+ {
+ return $query->whereNotNull('assets.next_audit_date')
+ ->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $settings->audit_warning_days DAY) <= '".Carbon::now()."'")
+ ->where('assets.archived', '=', 0)
+ ->NotArchived();
+ }
+
+
/**
* Query builder scope for Archived assets
*
diff --git a/resources/views/notifications/markdown/upcoming-audits.blade.php b/resources/views/notifications/markdown/upcoming-audits.blade.php
index f294ae6e53..de6e2a89c7 100644
--- a/resources/views/notifications/markdown/upcoming-audits.blade.php
+++ b/resources/views/notifications/markdown/upcoming-audits.blade.php
@@ -9,7 +9,7 @@
@php
$next_audit_date = \App\Helpers\Helper::getFormattedDateObject($asset->next_audit_date, 'date', false);
$last_audit_date = \App\Helpers\Helper::getFormattedDateObject($asset->last_audit_date, 'date', false);
-$diff = Carbon::parse($next_audit_date)->diffInDays(Carbon::now());
+$diff = Carbon::parse(Carbon::now())->diffInDays($next_audit_date, false);
$icon = ($diff <= 7) ? '🚨' : (($diff <= 14) ? '⚠️' : ' ');
@endphp
|{{ $icon }}| [{{ $asset->present()->name }}]({{ route('hardware.show', $asset->id) }}) | {{ $last_audit_date }}| {{ $next_audit_date }} | {{ $diff }} | {{ ($asset->supplier ? e($asset->supplier->name) : '') }}|{{ ($asset->assignedTo ? $asset->assignedTo->present()->name() : '') }}