From 27bc7a847bee4d498661cde7e63aa839baabf9d7 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:01:11 +0100 Subject: [PATCH 01/43] Updated routes Signed-off-by: snipe --- routes/api.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/routes/api.php b/routes/api.php index 842e6210df39..082651a7e906 100644 --- a/routes/api.php +++ b/routes/api.php @@ -496,13 +496,22 @@ )->name('api.assets.show.byserial') ->where('any', '.*'); - Route::get('audit/{audit}', + // Get assets that are due or overdue for audit + Route::get('audit/{status}', [ Api\AssetsController::class, 'index' ] )->name('api.asset.to-audit'); + // Get assets that are due or overdue for checkin + Route::get('checkins/{status}', + [ + Api\AssetsController::class, + 'index' + ] + )->name('api.asset.to-checkin'); + Route::post('audit', [ Api\AssetsController::class, From bfc30794c5429e913e4cca2f68023090534af248 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:01:22 +0100 Subject: [PATCH 02/43] Updated badge styling Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index a1a4bc30cc7e..b74c6763ffb5 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -437,6 +437,9 @@ class="caret"> {{ trans('general.list_all') }} + + {{ (isset($total_assets)) ? $total_assets : '' }} + @@ -447,7 +450,8 @@ class="caret"> - {{ $status_nav->name }} ({{ $status_nav->asset_count }}) + {{ $status_nav->name }} + {{ $status_nav->asset_count }}) @endforeach @endif @@ -457,7 +461,7 @@ class="caret"> {{ trans('general.all') }} {{ trans('general.deployed') }} - ({{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }}) + {{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }} @@ -465,7 +469,7 @@ class="caret"> {{ trans('general.all') }} {{ trans('general.ready_to_deploy') }} - ({{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }}) + {{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }} class="far fa-circle text-orange fa-fw"> {{ trans('general.all') }} {{ trans('general.pending') }} - ({{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }}) + {{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }} class="fas fa-times text-red fa-fw"> {{ trans('general.all') }} {{ trans('general.undeployable') }} - ({{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }}) + {{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }} class="fas fa-times text-red fa-fw"> {{ trans('general.all') }} {{ trans('general.byod') }} - ({{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }}) + {{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }} class="fas fa-times text-red fa-fw"> {{ trans('general.all') }} {{ trans('admin/hardware/general.archived') }} - ({{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }}) + {{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }} {{ trans('general.audit_due') }} + {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }} {{ trans('general.audit_overdue') }} + {{ (isset($total_overdue_for_audit)) ? $total_overdue_for_audit : '' }} @endcan From 2484a9db2c58141b64b8e6e5879adcfcce082141 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:01:29 +0100 Subject: [PATCH 03/43] Added tests Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 78 ++++++++++++++++++++- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 3175db6953b6..3aa90840eb2b 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -7,10 +7,10 @@ use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Tests\TestCase; - +use Carbon; class AssetIndexTest extends TestCase { - public function testAssetIndexReturnsExpectedAssets() + public function testAssetApiIndexReturnsExpectedAssets() { Asset::factory()->count(3)->create(); @@ -30,7 +30,79 @@ public function testAssetIndexReturnsExpectedAssets() ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); } - public function testAssetIndexAdheresToCompanyScoping() + public function testAssetApiIndexReturnsDisplayUpcomingAuditsDueToday() + { + $assets = Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); + + //dd($assets); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.asset.to-audit', ['status' => 'due'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + + } + + public function testAssetApiIndexReturnsOverdueForAudit() + { + Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->subDays(1)->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.asset.to-audit', ['status' => 'overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + + + public function testAssetApiIndexReturnsDueForExpectedCheckinToday() + { + Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.asset.to-checkin', ['status' => 'due']) + ) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + + public function testAssetApiIndexReturnsOverdueForExpectedCheckin() + { + Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 3); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson(route('api.asset.to-checkin', ['status' => 'overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + + public function testAssetApiIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create(); From 14b6a75507aef2a0d1e0a3d7aff063dfe4ba5f54 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:01:38 +0100 Subject: [PATCH 04/43] Updated routes Signed-off-by: snipe --- resources/views/hardware/audit-due.blade.php | 4 ++-- resources/views/hardware/audit-overdue.blade.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/hardware/audit-due.blade.php b/resources/views/hardware/audit-due.blade.php index 0232facd77b6..3d3674c15bb0 100644 --- a/resources/views/hardware/audit-due.blade.php +++ b/resources/views/hardware/audit-due.blade.php @@ -6,7 +6,7 @@ {{ $company->name }} @endif - {{ trans('general.audit_due') }} + {{ trans('general.audit_due_days', ['days' => $settings->audit_warning_days]) }} @stop @@ -49,7 +49,7 @@ data-bulk-form-id="#assetsBulkForm" id="assetsAuditListingTable" class="table table-striped snipe-table" - data-url="{{ route('api.asset.to-audit', ['audit' => 'due']) }}" + data-url="{{ route('api.asset.to-audit', ['status' => 'due']) }}" data-export-options='{ "fileName": "export-assets-due-audit-{{ date('Y-m-d') }}", "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] diff --git a/resources/views/hardware/audit-overdue.blade.php b/resources/views/hardware/audit-overdue.blade.php index ddd477fb2316..1b9aafd46b31 100644 --- a/resources/views/hardware/audit-overdue.blade.php +++ b/resources/views/hardware/audit-overdue.blade.php @@ -47,7 +47,7 @@ data-bulk-form-id="#assetsBulkForm" id="assetsAuditListingTable" class="table table-striped snipe-table" - data-url="{{ route('api.asset.to-audit', ['audit' => 'overdue']) }}" + data-url="{{ route('api.asset.to-audit', ['status' => 'overdue']) }}" data-export-options='{ "fileName": "export-assets-due-audit-{{ date('Y-m-d') }}", "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] From 2e92ee8eee228d9a365ae4b4db392e6a44603f3d Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:02:23 +0100 Subject: [PATCH 05/43] Switch to whereBetween so tests run on sqlite Signed-off-by: snipe --- app/Models/Asset.php | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 1f4079e49138..dd89efedad82 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1163,10 +1163,15 @@ public function scopeNotArchived($query) public function scopeDueForAudit($query, $settings) { $interval = $settings->audit_warning_days ?? 0; + $today = Carbon::now(); + $interval_date = $today->copy()->addDays($interval)->format('Y-m-d'); + + \Log::debug($interval); + \Log::debug($today); + \Log::debug($interval_date); return $query->whereNotNull('assets.next_audit_date') - ->where('assets.next_audit_date', '>=', Carbon::now()) - ->whereRaw("DATE_SUB(assets.next_audit_date, INTERVAL $interval DAY) <= '".Carbon::now()."'") + ->whereBetween('assets.next_audit_date', [$today->format('Y-m-d'), $interval_date]) ->where('assets.archived', '=', 0) ->NotArchived(); } @@ -1188,7 +1193,7 @@ public function scopeDueForAudit($query, $settings) public function scopeOverdueForAudit($query) { return $query->whereNotNull('assets.next_audit_date') - ->where('assets.next_audit_date', '<', Carbon::now()) + ->where('assets.next_audit_date', '<', Carbon::now()->format('Y-m-d')) ->where('assets.archived', '=', 0) ->NotArchived(); } @@ -1209,10 +1214,47 @@ public function scopeOverdueForAudit($query) public function scopeDueOrOverdueForAudit($query, $settings) { + $interval = $settings->audit_warning_days ?? 0; + $today = Carbon::now(); + $interval_date = $today->copy()->addDays($interval); return $query->whereNotNull('assets.next_audit_date') - ->whereRaw('DATE_SUB('.DB::getTablePrefix()."assets.next_audit_date, INTERVAL $interval DAY) <= '".Carbon::now()."'") + ->where('assets.next_audit_date', '<=', $interval_date); + } + + + /** + * Query builder scope for Assets that are OVERDUE for checkin, based on the assets.next_audit_date + * and settings.audit_warning_days. It checks to see if assets.expected_checkin is before now + * + * @author A. Gianotto + * @since v6.4.0 + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + + public function scopeOverdueForCheckin($query) + { + return $query->whereNotNull('assets.expected_checkin') + ->where('assets.expected_checkin', '<', Carbon::now()->format('Y-m-d')) + ->where('assets.archived', '=', 0) + ->NotArchived(); + } + + /** + * Query builder scope for Assets that are due for checkin OR overdue, based on the assets.next_audit_date + * and settings.audit_warning_days. + * + * @author A. Gianotto + * @since v6.4.0 + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + + public function scopeDueOrOverdueForCheckin($query, $settings) + { + + return $query->whereNotNull('assets.expected_checkin') + ->where('assets.expected_checkin', '<', Carbon::now()->format('Y-m-d')) ->where('assets.archived', '=', 0) ->NotArchived(); } From 2888dd6fd812e631ff574d4fe30338ebbe0e681e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:02:37 +0100 Subject: [PATCH 06/43] Added translation Signed-off-by: snipe --- resources/lang/en-US/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index dc44b22b2ae6..f5eb125d581f 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -313,6 +313,7 @@ 'token_expired' => 'Your form session has expired. Please try again.', 'login_enabled' => 'Login Enabled', 'audit_due' => 'Due for Audit', + 'audit_due_days' => 'Assets Due for Audit Within :days Days', 'audit_overdue' => 'Overdue for Audit', 'accept' => 'Accept :asset', 'i_accept' => 'I accept', From dfaf01e8aadcaebd0f77b82927570c802fbd70ab Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:02:47 +0100 Subject: [PATCH 07/43] Updated asset counters Signed-off-by: snipe --- app/Http/Middleware/AssetCountForSidebar.php | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/Http/Middleware/AssetCountForSidebar.php b/app/Http/Middleware/AssetCountForSidebar.php index 5d9656f5c10e..0088f93871df 100644 --- a/app/Http/Middleware/AssetCountForSidebar.php +++ b/app/Http/Middleware/AssetCountForSidebar.php @@ -5,6 +5,7 @@ use App\Models\Asset; use Auth; use Closure; +use App\Models\Setting; class AssetCountForSidebar { @@ -24,6 +25,13 @@ public function handle($request, Closure $next) \Log::debug($e); } + try { + $total_assets = Asset::RTD()->count(); + view()->share('total_assets', $total_assets); + } catch (\Exception $e) { + \Log::debug($e); + } + try { $total_deployed_sidebar = Asset::Deployed()->count(); view()->share('total_deployed_sidebar', $total_deployed_sidebar); @@ -59,6 +67,27 @@ public function handle($request, Closure $next) \Log::debug($e); } + try { + $settings = Setting::getSettings(); + view()->share('settings', $settings); + } catch (\Exception $e) { + \Log::debug($e); + } + + try { + $total_due_for_audit = Asset::DueForAudit($settings)->count(); + view()->share('total_due_for_audit', $total_due_for_audit); + } catch (\Exception $e) { + \Log::debug($e); + } + + try { + $total_overdue_for_audit = Asset::OverdueForAudit($settings)->count(); + view()->share('total_overdue_for_audit', $total_overdue_for_audit); + } catch (\Exception $e) { + \Log::debug($e); + } + return $next($request); } } From bf058bd5c6e07dae1cb4020fe4ce150ca8f9013b Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 14:02:56 +0100 Subject: [PATCH 08/43] Use updated scopes Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 57307acbb38f..47ef7232f7f5 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -159,10 +159,13 @@ public function index(Request $request, $audit = null) if (Gate::allows('audit', Asset::class)) { switch ($audit) { case 'due': - $assets->DueOrOverdueForAudit($settings); + $assets->DueForAudit($settings); break; case 'overdue': - $assets->overdueForAudit($settings); + $assets->OverdueForAudit($settings); + break; + case 'duooroverdue': + $assets->DueOrOverdueForAudit($settings); break; } } From 4b6d236eb7362b959663c06a2dea315b8baf0e40 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 15:44:06 +0100 Subject: [PATCH 09/43] Added class for sidebar menu badges Signed-off-by: snipe --- public/css/build/app.css | 5 +++++ public/css/build/overrides.css | 5 +++++ public/css/dist/all.css | 10 ++++++++++ public/mix-manifest.json | 6 +++--- resources/assets/less/mixins.less | 2 +- resources/assets/less/overrides.less | 8 +++++++- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/public/css/build/app.css b/public/css/build/app.css index 6b9729d7e2b1..e527c35aa0fb 100644 --- a/public/css/build/app.css +++ b/public/css/build/app.css @@ -1154,4 +1154,9 @@ input[type="radio"]:checked::before { .datepicker.dropdown-menu { z-index: 1030 !important; } +.sidebar-menu > li .badge { + margin-top: 0px; + filter: brightness(70%); + font-size: 70%; +} diff --git a/public/css/build/overrides.css b/public/css/build/overrides.css index e879341cf18a..fe8cb67e84ff 100644 --- a/public/css/build/overrides.css +++ b/public/css/build/overrides.css @@ -787,4 +787,9 @@ input[type="radio"]:checked::before { .datepicker.dropdown-menu { z-index: 1030 !important; } +.sidebar-menu > li .badge { + margin-top: 0px; + filter: brightness(70%); + font-size: 70%; +} diff --git a/public/css/dist/all.css b/public/css/dist/all.css index 834ade82e41c..e3032d545244 100644 --- a/public/css/dist/all.css +++ b/public/css/dist/all.css @@ -22654,6 +22654,11 @@ input[type="radio"]:checked::before { .datepicker.dropdown-menu { z-index: 1030 !important; } +.sidebar-menu > li .badge { + margin-top: 0px; + filter: brightness(70%); + font-size: 70%; +} .select2-container { @@ -23927,4 +23932,9 @@ input[type="radio"]:checked::before { .datepicker.dropdown-menu { z-index: 1030 !important; } +.sidebar-menu > li .badge { + margin-top: 0px; + filter: brightness(70%); + font-size: 70%; +} diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 32e9266e111d..548cc78dd507 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,8 +1,8 @@ { "/js/build/app.js": "/js/build/app.js?id=ea5f3edebafdb29b616d23fa89106080", "/css/dist/skins/skin-blue.css": "/css/dist/skins/skin-blue.css?id=f677207c6cf9678eb539abecb408c374", - "/css/build/overrides.css": "/css/build/overrides.css?id=3f1125ebfd37987dd0d6e2bf18bb41ce", - "/css/build/app.css": "/css/build/app.css?id=ca42da2140f0b5be6c2d0fa84ae90108", + "/css/build/overrides.css": "/css/build/overrides.css?id=be3c0a217bc6c0e0744f75faed784887", + "/css/build/app.css": "/css/build/app.css?id=a168b0a799aa800ee926bffa1b1a434a", "/css/build/AdminLTE.css": "/css/build/AdminLTE.css?id=dc383f8560a8d4adb51d44fb4043e03b", "/css/dist/skins/skin-orange.css": "/css/dist/skins/skin-orange.css?id=6f0563e726c2fe4fab4026daaa5bfdf2", "/css/dist/skins/skin-orange-dark.css": "/css/dist/skins/skin-orange-dark.css?id=620b684d9dd9d3bb5fdda00a3a2467c3", @@ -18,7 +18,7 @@ "/css/dist/skins/skin-green.css": "/css/dist/skins/skin-green.css?id=0a82a6ae6bb4e58fe62d162c4fb50397", "/css/dist/skins/skin-contrast.css": "/css/dist/skins/skin-contrast.css?id=da6c7997d9de2f8329142399f0ce50da", "/css/dist/skins/skin-red.css": "/css/dist/skins/skin-red.css?id=44bf834f2110504a793dadec132a5898", - "/css/dist/all.css": "/css/dist/all.css?id=0836d3b034a9b1de17d797ff35f1983e", + "/css/dist/all.css": "/css/dist/all.css?id=628956bb260b760b56216f01d1d71fd8", "/css/dist/signature-pad.css": "/css/dist/signature-pad.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/dist/signature-pad.min.css": "/css/dist/signature-pad.min.css?id=6a89d3cd901305e66ced1cf5f13147f7", "/css/webfonts/fa-brands-400.ttf": "/css/webfonts/fa-brands-400.ttf?id=69e5d8e4e818f05fd882cceb758d1eba", diff --git a/resources/assets/less/mixins.less b/resources/assets/less/mixins.less index b6ff57a4e958..ff801d415ecd 100755 --- a/resources/assets/less/mixins.less +++ b/resources/assets/less/mixins.less @@ -131,7 +131,7 @@ //Hover and active states &:hover > a, &.active > a { color: @sidebar-dark-hover-color; - background: @link-hover-border-color; + background: @sidebar-dark-hover-bg; border-left-color: @link-hover-border-color; } //First Level Submenu diff --git a/resources/assets/less/overrides.less b/resources/assets/less/overrides.less index 69bd32a3e73d..31e85ca26eee 100644 --- a/resources/assets/less/overrides.less +++ b/resources/assets/less/overrides.less @@ -900,4 +900,10 @@ input[type="radio"]:checked::before { } .datepicker.dropdown-menu { z-index: 1030 !important; -} \ No newline at end of file +} + +.sidebar-menu > li .badge { + margin-top: 0px; + filter: brightness(70%); + font-size: 70%; +} From bd8737d986856bf39697d626c67244882db702d1 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 15:44:21 +0100 Subject: [PATCH 10/43] Changed sidenav badge class Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index b74c6763ffb5..60132b3789aa 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -437,7 +437,7 @@ class="caret"> {{ trans('general.list_all') }} - + {{ (isset($total_assets)) ? $total_assets : '' }} @@ -461,7 +461,7 @@ class="caret"> {{ trans('general.all') }} {{ trans('general.deployed') }} - {{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }} + {{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }} @@ -469,7 +469,7 @@ class="caret"> {{ trans('general.all') }} {{ trans('general.ready_to_deploy') }} - {{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }} + {{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }} class="far fa-circle text-orange fa-fw"> {{ trans('general.all') }} {{ trans('general.pending') }} - {{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }} + {{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }} class="fas fa-times text-red fa-fw"> {{ trans('general.all') }} {{ trans('general.undeployable') }} - {{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }} + {{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }} class="fas fa-times text-red fa-fw"> {{ trans('general.all') }} {{ trans('general.byod') }} - {{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }} + {{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }} class="fas fa-times text-red fa-fw"> {{ trans('general.all') }} {{ trans('admin/hardware/general.archived') }} - {{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }} + {{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }} {{ trans('general.audit_due') }} - {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }} + {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }} {{ trans('general.audit_overdue') }} - {{ (isset($total_overdue_for_audit)) ? $total_overdue_for_audit : '' }} + {{ (isset($total_overdue_for_audit)) ? $total_overdue_for_audit : '' }} @endcan From 2d112f227a87b39a935d866b46bcc9dd89a6c906 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 15:44:37 +0100 Subject: [PATCH 11/43] Call the asset factory directly Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 3aa90840eb2b..f949f02487d0 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -32,9 +32,7 @@ public function testAssetApiIndexReturnsExpectedAssets() public function testAssetApiIndexReturnsDisplayUpcomingAuditsDueToday() { - $assets = Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); - - //dd($assets); + Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); $this->assertTrue(Asset::count() === 3); From 9e440527094e31f14e1397e67df379b32a6e9fd3 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 15:46:58 +0100 Subject: [PATCH 12/43] Switch to plural route name for API endpoint Signed-off-by: snipe --- routes/api.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/routes/api.php b/routes/api.php index 082651a7e906..06073b4dcafe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -496,7 +496,7 @@ )->name('api.assets.show.byserial') ->where('any', '.*'); - // Get assets that are due or overdue for audit + // LEGACY URL - Get assets that are due or overdue for audit Route::get('audit/{status}', [ Api\AssetsController::class, @@ -504,8 +504,16 @@ ] )->name('api.asset.to-audit'); - // Get assets that are due or overdue for checkin - Route::get('checkins/{status}', + // Get assets that are due or overdue for audit + Route::get('audits/{status}', + [ + Api\AssetsController::class, + 'index' + ] + )->name('api.assets.to-audit'); + + // Get assets that are due or overdue for checkin + Route::get('checkins/{status}', [ Api\AssetsController::class, 'index' From de6d71cc3b360188c993c9999ddbb457790dcab7 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 15:47:19 +0100 Subject: [PATCH 13/43] Use plural api endpoints in blades Signed-off-by: snipe --- resources/views/hardware/audit-due.blade.php | 2 +- resources/views/hardware/audit-overdue.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/hardware/audit-due.blade.php b/resources/views/hardware/audit-due.blade.php index 3d3674c15bb0..9c0793ab68d1 100644 --- a/resources/views/hardware/audit-due.blade.php +++ b/resources/views/hardware/audit-due.blade.php @@ -49,7 +49,7 @@ data-bulk-form-id="#assetsBulkForm" id="assetsAuditListingTable" class="table table-striped snipe-table" - data-url="{{ route('api.asset.to-audit', ['status' => 'due']) }}" + data-url="{{ route('api.assets.to-audit', ['status' => 'due']) }}" data-export-options='{ "fileName": "export-assets-due-audit-{{ date('Y-m-d') }}", "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] diff --git a/resources/views/hardware/audit-overdue.blade.php b/resources/views/hardware/audit-overdue.blade.php index 1b9aafd46b31..87ffefe1873e 100644 --- a/resources/views/hardware/audit-overdue.blade.php +++ b/resources/views/hardware/audit-overdue.blade.php @@ -47,7 +47,7 @@ data-bulk-form-id="#assetsBulkForm" id="assetsAuditListingTable" class="table table-striped snipe-table" - data-url="{{ route('api.asset.to-audit', ['status' => 'overdue']) }}" + data-url="{{ route('api.assets.to-audit', ['status' => 'overdue']) }}" data-export-options='{ "fileName": "export-assets-due-audit-{{ date('Y-m-d') }}", "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] From fe4dd23d3904b9ad5c5b4cc007ae7af06d0f3d98 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 15:49:12 +0100 Subject: [PATCH 14/43] =?UTF-8?q?Removed=20=E2=80=9Call=E2=80=9D=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 60132b3789aa..5de011ce1b98 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -459,7 +459,6 @@ class="caret"> - {{ trans('general.all') }} {{ trans('general.deployed') }} {{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }} @@ -467,7 +466,6 @@ class="caret"> - {{ trans('general.all') }} {{ trans('general.ready_to_deploy') }} {{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }} @@ -475,7 +473,6 @@ class="caret"> - {{ trans('general.all') }} {{ trans('general.pending') }} {{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }} @@ -483,7 +480,6 @@ class="far fa-circle text-orange fa-fw"> - {{ trans('general.all') }} {{ trans('general.undeployable') }} {{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }} @@ -491,7 +487,6 @@ class="fas fa-times text-red fa-fw"> - {{ trans('general.all') }} {{ trans('general.byod') }} {{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }} @@ -499,7 +494,6 @@ class="fas fa-times text-red fa-fw"> - {{ trans('general.all') }} {{ trans('admin/hardware/general.archived') }} {{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }} From 4b4e3badb75a97dfb92a2a04765988b6aaa9efd1 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:53:36 +0100 Subject: [PATCH 15/43] Removed hardware audit overdue blade Signed-off-by: snipe --- .../views/hardware/audit-overdue.blade.php | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 resources/views/hardware/audit-overdue.blade.php diff --git a/resources/views/hardware/audit-overdue.blade.php b/resources/views/hardware/audit-overdue.blade.php deleted file mode 100644 index 87ffefe1873e..000000000000 --- a/resources/views/hardware/audit-overdue.blade.php +++ /dev/null @@ -1,69 +0,0 @@ -@extends('layouts/default') - -@section('title0') - - @if ((Request::get('company_id')) && ($company)) - {{ $company->name }} - @endif - - {{ trans('general.audit_overdue') }} - -@stop - -{{-- Page title --}} -@section('title') - @yield('title0') @parent -@stop - - -{{-- Page content --}} -@section('content') - -
-
-
-
- @include('partials.asset-bulk-actions') -
-
- - -
- -
-
- {{ Form::close() }} -
-
-
-
-@stop - -@section('moar_scripts') - @include('partials.bootstrap-table') - -@stop From 6dc9ccffcdd388e50262489d13ab49a42c639f08 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:56:57 +0100 Subject: [PATCH 16/43] Refactor api for handling audit/expected checkins Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 54 ++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 47ef7232f7f5..269735be07e2 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -59,7 +59,7 @@ class AssetsController extends Controller * @since [v4.0] * @return \Illuminate\Http\JsonResponse */ - public function index(Request $request, $audit = null) + public function index(Request $request, $action = null, $upcoming_status = null) { $filter_non_deprecable_assets = false; @@ -155,20 +155,46 @@ public function index(Request $request, $audit = null) $assets->TextSearch($request->input('search')); } - // This is used by the audit reporting routes - if (Gate::allows('audit', Asset::class)) { - switch ($audit) { - case 'due': - $assets->DueForAudit($settings); - break; - case 'overdue': - $assets->OverdueForAudit($settings); - break; - case 'duooroverdue': - $assets->DueOrOverdueForAudit($settings); - break; + + /** + * Handle due and overdue audits and checkin dates + */ + switch ($action) { + case 'audits': + + \Log::debug('audits'); + switch ($upcoming_status) { + case 'due': + $assets->DueForAudit($settings); + break; + case 'overdue': + $assets->OverdueForAudit($settings); + break; + case 'due-or-overdue': + $assets->DueOrOverdueForAudit($settings); + break; + } + break; + + case 'checkins': + + switch ($upcoming_status) { + case 'due': + $assets->DueForCheckin($settings); + break; + case 'overdue': + $assets->OverdueForCheckin($settings); + break; + case 'due-or-overdue': + $assets->DueOrOverdueForCheckin($settings); + break; + } + break; } - } + + /** + * End handling due and overdue audits and checkin dates + */ // This is used by the sidenav, mostly From 9167f8a3ba6313e50886b2ec86030962d7d7ffe9 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:57:07 +0100 Subject: [PATCH 17/43] Cleaned up tests Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index f949f02487d0..2c6f26071f3e 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -30,7 +30,7 @@ public function testAssetApiIndexReturnsExpectedAssets() ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); } - public function testAssetApiIndexReturnsDisplayUpcomingAuditsDueToday() + public function testAssetApiIndexReturnsDisplayUpcomingAuditsDue() { Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); @@ -38,14 +38,13 @@ public function testAssetApiIndexReturnsDisplayUpcomingAuditsDueToday() $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( - route('api.asset.to-audit', ['status' => 'due'])) + route('api.assets.list-upcoming', ['action' => 'audits', 'upcoming_status' => 'due'])) ->assertOk() ->assertJsonStructure([ 'total', 'rows', ]) ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); - } public function testAssetApiIndexReturnsOverdueForAudit() @@ -56,7 +55,7 @@ public function testAssetApiIndexReturnsOverdueForAudit() $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( - route('api.asset.to-audit', ['status' => 'overdue'])) + route('api.assets.list-upcoming', ['action' => 'audits', 'upcoming_status' => 'overdue'])) ->assertOk() ->assertJsonStructure([ 'total', @@ -66,7 +65,8 @@ public function testAssetApiIndexReturnsOverdueForAudit() } - public function testAssetApiIndexReturnsDueForExpectedCheckinToday() + + public function testAssetApiIndexReturnsDueForExpectedCheckin() { Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->format('Y-m-d')]); @@ -74,7 +74,7 @@ public function testAssetApiIndexReturnsDueForExpectedCheckinToday() $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( - route('api.asset.to-checkin', ['status' => 'due']) + route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'due']) ) ->assertOk() ->assertJsonStructure([ @@ -91,7 +91,7 @@ public function testAssetApiIndexReturnsOverdueForExpectedCheckin() $this->assertTrue(Asset::count() === 3); $this->actingAsForApi(User::factory()->superuser()->create()) - ->getJson(route('api.asset.to-checkin', ['status' => 'overdue'])) + ->getJson(route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'overdue'])) ->assertOk() ->assertJsonStructure([ 'total', From 651001bf6e992686cc651731c00ccdf5f830acef Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:58:15 +0100 Subject: [PATCH 18/43] Removed duplicate routes Signed-off-by: snipe --- routes/web/hardware.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index d4f289228107..7833f0fdaa64 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -50,26 +50,10 @@ function () { [AssetsController::class, 'dueForAudit'] )->name('assets.audit.due'); - Route::get('audit/overdue', - [AssetsController::class, 'overdueForAudit'] - )->name('assets.audit.overdue'); - - Route::get('audit/due', - [AssetsController::class, 'dueForAudit'] - )->name('assets.audit.due'); - - Route::get('audit/overdue', - [AssetsController::class, 'overdueForAudit'] - )->name('assets.audit.overdue'); - - Route::get('audit/due', - [AssetsController::class, 'dueForAudit'] - )->name('assets.audit.due'); - - Route::get('audit/overdue', - [AssetsController::class, 'overdueForAudit'] - )->name('assets.audit.overdue'); - + Route::get('checkins/due', + [AssetsController::class, 'dueForCheckin'] + )->name('assets.checkins.due'); + Route::get('audit/{id}', [AssetsController::class, 'audit'] )->name('asset.audit.create'); From fbe9daace6e73dd2cb2e9ed4952485bb852421b2 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:58:29 +0100 Subject: [PATCH 19/43] Use pattern in API route Signed-off-by: snipe --- routes/api.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/routes/api.php b/routes/api.php index 06073b4dcafe..8adb0af61920 100644 --- a/routes/api.php +++ b/routes/api.php @@ -504,21 +504,18 @@ ] )->name('api.asset.to-audit'); - // Get assets that are due or overdue for audit - Route::get('audits/{status}', - [ - Api\AssetsController::class, - 'index' - ] - )->name('api.assets.to-audit'); - // Get assets that are due or overdue for checkin - Route::get('checkins/{status}', + + // This gets the "due or overdue" API endpoints for audits and checkins + Route::get('{action}/{upcoming_status}', [ Api\AssetsController::class, 'index' ] - )->name('api.asset.to-checkin'); + )->name('api.assets.list-upcoming') + ->where(['action' => 'audits|checkins', 'upcoming_status' => 'due|overdue|due-or-overdue']); + + Route::post('audit', [ From c661d732b342072c4bcf364d6e30bca1833cdd32 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:58:44 +0100 Subject: [PATCH 20/43] Refactored sidenav links for audit Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 5de011ce1b98..f7b610881f8b 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -512,12 +512,15 @@ class="fas fa-check text-blue fa-fw"> {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }} - - - {{ trans('general.audit_overdue') }} - {{ (isset($total_overdue_for_audit)) ? $total_overdue_for_audit : '' }} - - + @endcan + + @can('checkin', \App\Models\Asset::class) + + + {{ trans('general.checkin_due') }} + {{ (isset($total_overdue_for_checkin)) ? $total_overdue_for_checkin : '' }} + + @endcan
  •  
  • From 9c8411c7ff4bc51e3b1c4dbf0d494db832538ee3 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:58:56 +0100 Subject: [PATCH 21/43] Added checkin due blade Signed-off-by: snipe --- .../views/hardware/checkin-due.blade.php | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 resources/views/hardware/checkin-due.blade.php diff --git a/resources/views/hardware/checkin-due.blade.php b/resources/views/hardware/checkin-due.blade.php new file mode 100644 index 000000000000..f8c9fdd964a8 --- /dev/null +++ b/resources/views/hardware/checkin-due.blade.php @@ -0,0 +1,142 @@ +@extends('layouts/default') + +@section('title0') + + @if ((Request::get('company_id')) && ($company)) + {{ $company->name }} + @endif + + {{ trans_choice('general.checkin_due_days', $settings->audit_warning_days, ['days' => $settings->audit_warning_days]) }} + +@stop + +{{-- Page title --}} +@section('title') + @yield('title0') @parent +@stop + + +{{-- Page content --}} +@section('content') + {{-- Page content --}} +
    +
    + + + + +
    +
    + +@stop + +@section('moar_scripts') + @include('partials.bootstrap-table') +@stop From 76129e90118a6fedf8c2c68e4709e3781df8808b Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 18:59:13 +0100 Subject: [PATCH 22/43] Use trans_choice for title Signed-off-by: snipe --- resources/views/hardware/audit-due.blade.php | 109 +++++++++++++++---- 1 file changed, 90 insertions(+), 19 deletions(-) diff --git a/resources/views/hardware/audit-due.blade.php b/resources/views/hardware/audit-due.blade.php index 9c0793ab68d1..ccc62ae49a9f 100644 --- a/resources/views/hardware/audit-due.blade.php +++ b/resources/views/hardware/audit-due.blade.php @@ -6,7 +6,7 @@ {{ $company->name }} @endif - {{ trans('general.audit_due_days', ['days' => $settings->audit_warning_days]) }} + {{ trans_choice('general.audit_due_days', $settings->audit_warning_days, ['days' => $settings->audit_warning_days]) }} @stop @@ -18,23 +18,51 @@ {{-- Page content --}} @section('content') - + {{-- Page content --}}
    -
    -
    - @include('partials.asset-bulk-actions') + +
    - {{ Form::close() }} -
    -
    - - + @stop @section('moar_scripts') @include('partials.bootstrap-table') - @stop From d40604b574d6ce214cdcc72ca2393afa70a50b0f Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:01:05 +0100 Subject: [PATCH 23/43] Removed debugging, added date cast Signed-off-by: snipe --- app/Models/Asset.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index dd89efedad82..a6502d53d6fc 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -74,9 +74,9 @@ public function declinedCheckout(User $declinedBy, $signature) 'eol_explicit' => 'boolean', 'last_checkout' => 'datetime', 'last_checkin' => 'datetime', - 'expected_checkin' => 'date', + 'expected_checkin' => 'datetime:m-d-Y', 'last_audit_date' => 'datetime', - 'next_audit_date' => 'date', + 'next_audit_date' => 'datetime:m-d-Y', 'model_id' => 'integer', 'status_id' => 'integer', 'company_id' => 'integer', @@ -1166,10 +1166,6 @@ public function scopeDueForAudit($query, $settings) $today = Carbon::now(); $interval_date = $today->copy()->addDays($interval)->format('Y-m-d'); - \Log::debug($interval); - \Log::debug($today); - \Log::debug($interval_date); - return $query->whereNotNull('assets.next_audit_date') ->whereBetween('assets.next_audit_date', [$today->format('Y-m-d'), $interval_date]) ->where('assets.archived', '=', 0) @@ -1233,6 +1229,26 @@ public function scopeDueOrOverdueForAudit($query, $settings) * @return \Illuminate\Database\Query\Builder Modified query builder */ + public function scopeDueForCheckinToday($query) + { + return $query->whereNotNull('assets.expected_checkin') + ->where('assets.expected_checkin', '=', Carbon::now()->format('Y-m-d')) + ->where('assets.archived', '=', 0) + ->NotArchived(); + } + + public function scopeDueForCheckin($query, $settings) + { + $interval = $settings->audit_warning_days ?? 0; + $today = Carbon::now(); + $interval_date = $today->copy()->addDays($interval)->format('Y-m-d'); + + return $query->whereNotNull('assets.expected_checkin') + ->whereBetween('assets.expected_checkin', [$today->format('Y-m-d'), $interval_date]) + ->where('assets.archived', '=', 0) + ->NotArchived(); + } + public function scopeOverdueForCheckin($query) { return $query->whereNotNull('assets.expected_checkin') @@ -1254,7 +1270,7 @@ public function scopeDueOrOverdueForCheckin($query, $settings) { return $query->whereNotNull('assets.expected_checkin') - ->where('assets.expected_checkin', '<', Carbon::now()->format('Y-m-d')) + ->where('assets.expected_checkin', '<=', Carbon::now()->format('Y-m-d')) ->where('assets.archived', '=', 0) ->NotArchived(); } From 2117f61e8c04c0d81579932903a7ef9141da8916 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:01:15 +0100 Subject: [PATCH 24/43] More view sharing for sidebar Signed-off-by: snipe --- app/Http/Middleware/AssetCountForSidebar.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Http/Middleware/AssetCountForSidebar.php b/app/Http/Middleware/AssetCountForSidebar.php index 0088f93871df..a0b14f8a0b6c 100644 --- a/app/Http/Middleware/AssetCountForSidebar.php +++ b/app/Http/Middleware/AssetCountForSidebar.php @@ -88,6 +88,20 @@ public function handle($request, Closure $next) \Log::debug($e); } + try { + $total_due_for_checkin = Asset::DueForCheckin($settings)->count(); + view()->share('total_due_for_checkin', $total_due_for_checkin); + } catch (\Exception $e) { + \Log::debug($e); + } + + try { + $total_overdue_for_checkin = Asset::OverdueForCheckin($settings)->count(); + view()->share('total_overdue_for_checkin', $total_overdue_for_checkin); + } catch (\Exception $e) { + \Log::debug($e); + } + return $next($request); } } From 3f04afee5c6979f7c8a55e90d80f56f221930752 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:01:26 +0100 Subject: [PATCH 25/43] Removed unused method Signed-off-by: snipe --- app/Http/Controllers/Assets/AssetsController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 6054718e6be2..ac755fd389cb 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -854,11 +854,11 @@ public function dueForAudit() return view('hardware/audit-due'); } - public function overdueForAudit() + public function dueForCheckin() { - $this->authorize('audit', Asset::class); + $this->authorize('checkin', Asset::class); - return view('hardware/audit-overdue'); + return view('hardware/checkin-due'); } From 8356b57fb4523d8425884e95d6b9f674bc062659 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:01:34 +0100 Subject: [PATCH 26/43] Added translations Signed-off-by: snipe --- resources/lang/en-US/general.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index f5eb125d581f..0b6f613399d3 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -313,7 +313,10 @@ 'token_expired' => 'Your form session has expired. Please try again.', 'login_enabled' => 'Login Enabled', 'audit_due' => 'Due for Audit', - 'audit_due_days' => 'Assets Due for Audit Within :days Days', + 'audit_due_days' => 'Assets Due for Audit Within :days Day|Assets Due for Audit Within :days Days', + 'checkin_due' => 'Due for Checkin', + 'checkin_overdue' => 'Overdue for Checkin', + 'checkin_due_days' => 'Assets Due for Checkin Within :days Day|Assets Due for Checkin Within :days Days', 'audit_overdue' => 'Overdue for Audit', 'accept' => 'Accept :asset', 'i_accept' => 'I accept', From 87de67e4a96cd61e1ccb23a68951f36226efe8b8 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:06:26 +0100 Subject: [PATCH 27/43] Fixed test for checkin Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 2c6f26071f3e..961ba7f4b306 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -68,7 +68,7 @@ public function testAssetApiIndexReturnsOverdueForAudit() public function testAssetApiIndexReturnsDueForExpectedCheckin() { - Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->format('Y-m-d')]); + Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->format('Y-m-d')]); $this->assertTrue(Asset::count() === 3); @@ -86,7 +86,7 @@ public function testAssetApiIndexReturnsDueForExpectedCheckin() public function testAssetApiIndexReturnsOverdueForExpectedCheckin() { - Asset::factory()->count(3)->create(['expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); + Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); $this->assertTrue(Asset::count() === 3); From 52d6a8990af4cca2fac685cef42d11b5b6717ac0 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:06:46 +0100 Subject: [PATCH 28/43] Check that the asset is not already checked in Signed-off-by: snipe --- app/Models/Asset.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index a6502d53d6fc..98f3dcc065f5 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1246,6 +1246,7 @@ public function scopeDueForCheckin($query, $settings) return $query->whereNotNull('assets.expected_checkin') ->whereBetween('assets.expected_checkin', [$today->format('Y-m-d'), $interval_date]) ->where('assets.archived', '=', 0) + ->whereNotNull('assets.assigned_to') ->NotArchived(); } @@ -1254,6 +1255,7 @@ public function scopeOverdueForCheckin($query) return $query->whereNotNull('assets.expected_checkin') ->where('assets.expected_checkin', '<', Carbon::now()->format('Y-m-d')) ->where('assets.archived', '=', 0) + ->whereNotNull('assets.assigned_to') ->NotArchived(); } @@ -1272,6 +1274,7 @@ public function scopeDueOrOverdueForCheckin($query, $settings) return $query->whereNotNull('assets.expected_checkin') ->where('assets.expected_checkin', '<=', Carbon::now()->format('Y-m-d')) ->where('assets.archived', '=', 0) + ->whereNotNull('assets.assigned_to') ->NotArchived(); } From 860764a436052f443caec9a59e1dae79d034f662 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:12:21 +0100 Subject: [PATCH 29/43] Use totals for sidebar Signed-off-by: snipe --- app/Http/Middleware/AssetCountForSidebar.php | 3 +++ resources/views/layouts/default.blade.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/AssetCountForSidebar.php b/app/Http/Middleware/AssetCountForSidebar.php index a0b14f8a0b6c..f55b72e0dd58 100644 --- a/app/Http/Middleware/AssetCountForSidebar.php +++ b/app/Http/Middleware/AssetCountForSidebar.php @@ -102,6 +102,9 @@ public function handle($request, Closure $next) \Log::debug($e); } + view()->share('total_due_and_overdue_for_checkin', ($total_due_for_checkin + $total_overdue_for_checkin)); + view()->share('total_due_and_overdue_for_audit', ($total_due_for_audit + $total_overdue_for_audit)); + return $next($request); } } diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index f7b610881f8b..25f45cbd0d1f 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -509,7 +509,7 @@ class="fas fa-check text-blue fa-fw"> {{ trans('general.audit_due') }} - {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }} + {{ (isset($total_due_and_overdue_for_audit)) ? $total_due_and_overdue_for_audit : '' }} @endcan @@ -518,7 +518,7 @@ class="fas fa-check text-blue fa-fw"> {{ trans('general.checkin_due') }} - {{ (isset($total_overdue_for_checkin)) ? $total_overdue_for_checkin : '' }} + {{ (isset($total_due_and_overdue_for_checkin)) ? $total_due_and_overdue_for_checkin : '' }} @endcan From 50d8b02f8b847e4e5235b2e178dc6f5107016d8c Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:23:27 +0100 Subject: [PATCH 30/43] Removed unused scope Signed-off-by: snipe --- app/Models/Asset.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 98f3dcc065f5..b3972b1c872b 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1221,22 +1221,14 @@ public function scopeDueOrOverdueForAudit($query, $settings) /** - * Query builder scope for Assets that are OVERDUE for checkin, based on the assets.next_audit_date - * and settings.audit_warning_days. It checks to see if assets.expected_checkin is before now + * Query builder scope for Assets that are DUE for checkin, based on the assets.expected_checkin + * and settings.audit_warning_days. It checks to see if assets.expected_checkin is now * * @author A. Gianotto * @since v6.4.0 * @return \Illuminate\Database\Query\Builder Modified query builder */ - public function scopeDueForCheckinToday($query) - { - return $query->whereNotNull('assets.expected_checkin') - ->where('assets.expected_checkin', '=', Carbon::now()->format('Y-m-d')) - ->where('assets.archived', '=', 0) - ->NotArchived(); - } - public function scopeDueForCheckin($query, $settings) { $interval = $settings->audit_warning_days ?? 0; From fc61a4b88d83b50e5fb2cddf90d7477a24665f44 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 19:50:58 +0100 Subject: [PATCH 31/43] Fixed badge HTML Signed-off-by: snipe --- resources/views/hardware/audit-due.blade.php | 4 ++-- resources/views/hardware/checkin-due.blade.php | 4 ++-- resources/views/hardware/view.blade.php | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/resources/views/hardware/audit-due.blade.php b/resources/views/hardware/audit-due.blade.php index ccc62ae49a9f..58a944e4a9f0 100644 --- a/resources/views/hardware/audit-due.blade.php +++ b/resources/views/hardware/audit-due.blade.php @@ -31,7 +31,7 @@ - {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }} + {{ (isset($total_due_for_audit)) ? $total_due_for_audit : '' }}
  • @@ -39,7 +39,7 @@ - {{ (isset($total_overdue_for_audit)) ? $total_overdue_for_audit : '' }} + {{ (isset($total_overdue_for_audit)) ? $total_overdue_for_audit : '' }}
  • diff --git a/resources/views/hardware/checkin-due.blade.php b/resources/views/hardware/checkin-due.blade.php index f8c9fdd964a8..d764a5178eb0 100644 --- a/resources/views/hardware/checkin-due.blade.php +++ b/resources/views/hardware/checkin-due.blade.php @@ -31,7 +31,7 @@ - {{ (isset($total_due_for_checkin)) ? $total_due_for_checkin : '' }} + {{ (isset($total_due_for_checkin)) ? $total_due_for_checkin : '' }}
  • @@ -39,7 +39,7 @@ - {{ (isset($total_overdue_for_checkin)) ? $total_overdue_for_checkin : '' }} + {{ (isset($total_overdue_for_checkin)) ? $total_overdue_for_checkin : '' }}
  • diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index a83b006c566b..dfb1513936fd 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -51,7 +51,7 @@ @@ -62,7 +62,7 @@ @@ -73,7 +73,7 @@ @@ -96,7 +96,7 @@ @@ -107,7 +107,7 @@ @@ -119,7 +119,7 @@ From 494ec5cd9c6aa4fed84b4328c2d2351b565ae719 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 20:59:04 +0100 Subject: [PATCH 32/43] Added tests for due-or-overdue Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index 961ba7f4b306..b53fb02fde78 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -65,6 +65,25 @@ public function testAssetApiIndexReturnsOverdueForAudit() } + public function testAssetApiIndexReturnsDueOrOverdueForAudit() + { + Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); + Asset::factory()->count(2)->create(['next_audit_date' => Carbon::now()->subDays(1)->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 5); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.assets.list-upcoming', ['action' => 'audits', 'upcoming_status' => 'due-or-overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 5)->etc()); + } + + public function testAssetApiIndexReturnsDueForExpectedCheckin() { @@ -100,6 +119,23 @@ public function testAssetApiIndexReturnsOverdueForExpectedCheckin() ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); } + public function testAssetApiIndexReturnsDueOrOverdueForExpectedCheckin() + { + Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); + Asset::factory()->count(2)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->format('Y-m-d')]); + + $this->assertTrue(Asset::count() === 5); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson(route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'due-or-overdue'])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 5)->etc()); + } + public function testAssetApiIndexAdheresToCompanyScoping() { [$companyA, $companyB] = Company::factory()->count(2)->create(); From bfd0530597ad3e4869e89523f2b6dce5affb1a44 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 20:59:13 +0100 Subject: [PATCH 33/43] Fixed notification Signed-off-by: snipe --- .../notifications/markdown/report-expected-checkins.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/notifications/markdown/report-expected-checkins.blade.php b/resources/views/notifications/markdown/report-expected-checkins.blade.php index 3715188d42f3..08b81350e411 100644 --- a/resources/views/notifications/markdown/report-expected-checkins.blade.php +++ b/resources/views/notifications/markdown/report-expected-checkins.blade.php @@ -10,7 +10,7 @@ @php $checkin = Helper::getFormattedDateObject($asset->expected_checkin, 'date'); @endphp -| [{{ $asset->present()->name }}]({{ route('hardware.show', ['hardware' => $asset->id]) }}) | [{{ $asset->assigned->present()->fullName }}]({{ route($asset->targetShowRoute().'.show', [$asset->assigned->id]) }}) | {{ $checkin['formatted'] }} +| [{{ $asset->present()->name }}]({{ route('hardware.show', ['hardware' => $asset->id]) }}) | [{{ $asset->assignedTo->present()->fullName }}]({{ route($asset->targetShowRoute().'.show', [$asset->assignedTo->id]) }}) | {{ $checkin['formatted'] }} @endforeach @endcomponent From 839db8ef4479f953bf51d7111440b214bf59b2f0 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 20:59:27 +0100 Subject: [PATCH 34/43] Refactored due-or-overdue methods Signed-off-by: snipe --- app/Models/Asset.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index b3972b1c872b..a700a0f36514 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1211,12 +1211,11 @@ public function scopeOverdueForAudit($query) public function scopeDueOrOverdueForAudit($query, $settings) { - $interval = $settings->audit_warning_days ?? 0; - $today = Carbon::now(); - $interval_date = $today->copy()->addDays($interval); - - return $query->whereNotNull('assets.next_audit_date') - ->where('assets.next_audit_date', '<=', $interval_date); + return $query->where(function ($query) { + $query->OverdueForAudit(); + })->orWhere(function ($query) use ($settings) { + $query->DueForAudit($settings); + }); } @@ -1252,8 +1251,7 @@ public function scopeOverdueForCheckin($query) } /** - * Query builder scope for Assets that are due for checkin OR overdue, based on the assets.next_audit_date - * and settings.audit_warning_days. + * Query builder scope for Assets that are due for checkin OR overdue * * @author A. Gianotto * @since v6.4.0 @@ -1262,12 +1260,11 @@ public function scopeOverdueForCheckin($query) public function scopeDueOrOverdueForCheckin($query, $settings) { - - return $query->whereNotNull('assets.expected_checkin') - ->where('assets.expected_checkin', '<=', Carbon::now()->format('Y-m-d')) - ->where('assets.archived', '=', 0) - ->whereNotNull('assets.assigned_to') - ->NotArchived(); + return $query->where(function ($query) { + $query->OverdueForCheckin(); + })->orWhere(function ($query) use ($settings) { + $query->DueForCheckin($settings); + }); } From a398496dd44e9a98feb5e668078f96a93ae968d8 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 21:01:27 +0100 Subject: [PATCH 35/43] Added comments Signed-off-by: snipe --- app/Models/Asset.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index a700a0f36514..c5373a04e218 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1241,6 +1241,13 @@ public function scopeDueForCheckin($query, $settings) ->NotArchived(); } + /** + * Query builder scope for Assets that are overdue for checkin OR overdue + * + * @author A. Gianotto + * @since v6.4.0 + * @return \Illuminate\Database\Query\Builder Modified query builder + */ public function scopeOverdueForCheckin($query) { return $query->whereNotNull('assets.expected_checkin') @@ -1257,7 +1264,6 @@ public function scopeOverdueForCheckin($query) * @since v6.4.0 * @return \Illuminate\Database\Query\Builder Modified query builder */ - public function scopeDueOrOverdueForCheckin($query, $settings) { return $query->where(function ($query) { From 103809b65f1c59c999cb36e6a687ba1397a9cd55 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 21:01:43 +0100 Subject: [PATCH 36/43] Removed debugging Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 269735be07e2..2556b483ca7a 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -162,7 +162,6 @@ public function index(Request $request, $action = null, $upcoming_status = null) switch ($action) { case 'audits': - \Log::debug('audits'); switch ($upcoming_status) { case 'due': $assets->DueForAudit($settings); @@ -177,13 +176,12 @@ public function index(Request $request, $action = null, $upcoming_status = null) break; case 'checkins': - switch ($upcoming_status) { case 'due': $assets->DueForCheckin($settings); break; case 'overdue': - $assets->OverdueForCheckin($settings); + $assets->OverdueForCheckin(); break; case 'due-or-overdue': $assets->DueOrOverdueForCheckin($settings); From fe147adec3775381de15ad8554012b328cc56962 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 21:10:54 +0100 Subject: [PATCH 37/43] Refactor checkin alert Signed-off-by: snipe --- .../Commands/SendExpectedCheckinAlerts.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php index 34e9609ce5eb..409d3de3ef71 100644 --- a/app/Console/Commands/SendExpectedCheckinAlerts.php +++ b/app/Console/Commands/SendExpectedCheckinAlerts.php @@ -42,26 +42,32 @@ public function __construct() */ public function handle() { + $interval = $settings->audit_warning_days ?? 0; + $today = Carbon::now(); + $interval_date = $today->copy()->addDays($interval); + $settings = Setting::getSettings(); - $whenNotify = Carbon::now(); - $assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get(); + $assets = Asset::whereNull('deleted_at')->DueOrOverdueForCheckin($settings)->orderBy('assets.expected_checkin', 'desc')->get(); + + $this->info($assets->count().' assets must be checked in on or before '.$interval_date.' is deadline'); - $this->info($whenNotify.' is deadline'); - $this->info($assets->count().' assets'); foreach ($assets as $asset) { - if ($asset->assigned && $asset->checkedOutToUser()) { - Log::info('Sending ExpectedCheckinNotification to ' . $asset->assigned->email); - $asset->assigned->notify((new ExpectedCheckinNotification($asset))); + if ($asset->assignedTo && (isset($asset->assignedTo->email)) && ($asset->assignedTo->email!='') && $asset->checkedOutToUser()) { + $this->info('Sending User ExpectedCheckinNotification to: '.$asset->assignedTo->email); + $asset->assignedTo->notify((new ExpectedCheckinNotification($asset))); } } if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) { // Send a rollup to the admin, if settings dictate - $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item) { return new AlertRecipient($item); }); + + $this->info('Sending Admin ExpectedCheckinNotification to: '.$recipients); \Notification::send($recipients, new ExpectedCheckinAdminNotification($assets)); + } } } From 848e1fe1f66227dc54a75eb803d9d33b9e956184 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 26 Apr 2024 21:26:00 +0100 Subject: [PATCH 38/43] Refactored audit alerts Signed-off-by: snipe --- .../Commands/SendExpectedCheckinAlerts.php | 3 +- .../Commands/SendUpcomingAuditReport.php | 44 ++++++------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php index 409d3de3ef71..665dca4df4ed 100644 --- a/app/Console/Commands/SendExpectedCheckinAlerts.php +++ b/app/Console/Commands/SendExpectedCheckinAlerts.php @@ -9,7 +9,6 @@ use App\Notifications\ExpectedCheckinNotification; use Carbon\Carbon; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Log; class SendExpectedCheckinAlerts extends Command { @@ -65,7 +64,7 @@ public function handle() return new AlertRecipient($item); }); - $this->info('Sending Admin ExpectedCheckinNotification to: '.$recipients); + $this->info('Sending Admin ExpectedCheckinNotification to: '.$settings->alert_email); \Notification::send($recipients, new ExpectedCheckinAdminNotification($assets)); } diff --git a/app/Console/Commands/SendUpcomingAuditReport.php b/app/Console/Commands/SendUpcomingAuditReport.php index e9cba106c6c2..fc06785cfeb5 100644 --- a/app/Console/Commands/SendUpcomingAuditReport.php +++ b/app/Console/Commands/SendUpcomingAuditReport.php @@ -3,10 +3,8 @@ namespace App\Console\Commands; use App\Models\Asset; -use App\Models\License; -use App\Models\Recipients; +use App\Models\Recipients\AlertRecipient; use App\Models\Setting; -use App\Notifications\ExpiringAssetsNotification; use App\Notifications\SendUpcomingAuditNotification; use Carbon\Carbon; use DB; @@ -45,40 +43,26 @@ public function __construct() */ public function handle() { + + $interval = $settings->audit_warning_days ?? 0; + $today = Carbon::now(); + $interval_date = $today->copy()->addDays($interval); + $settings = Setting::getSettings(); + $assets = Asset::whereNull('deleted_at')->DueOrOverdueForAudit($settings)->orderBy('assets.next_audit_date', 'desc')->get(); + $this->info($assets->count().' assets must be audited in on or before '.$interval_date.' is deadline'); - if (($settings->alert_email != '') && ($settings->audit_warning_days) && ($settings->alerts_enabled == 1)) { + if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) { // Send a rollup to the admin, if settings dictate - $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { - return new \App\Models\Recipients\AlertRecipient($item); + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item) { + return new AlertRecipient($item); }); - // Assets due for auditing + $this->info('Sending Admin SendUpcomingAuditNotification to: '.$settings->alert_email); + \Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days)); - $assets = Asset::whereNotNull('next_audit_date') - ->DueOrOverdueForAudit($settings) - ->orderBy('last_audit_date', 'asc')->get(); - - if ($assets->count() > 0) { - $this->info(trans_choice('mail.upcoming-audits', $assets->count(), - ['count' => $assets->count(), 'threshold' => $settings->audit_warning_days])); - \Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days)); - $this->info('Audit report sent to '.$settings->alert_email); - } else { - $this->info('No assets to be audited. No report sent.'); - } - } elseif ($settings->alert_email == '') { - $this->error('Could not send email. No alert email configured in settings'); - } elseif (! $settings->audit_warning_days) { - $this->error('No audit warning days set in Admin Notifications. No mail will be sent.'); - } elseif ($settings->alerts_enabled != 1) { - $this->info('Alerts are disabled in the settings. No mail will be sent'); - } else { - $this->error('Something went wrong. :( '); - $this->error('Admin Notifications Email Setting: '.$settings->alert_email); - $this->error('Admin Audit Warning Setting: '.$settings->audit_warning_days); - $this->error('Admin Alerts Emnabled: '.$settings->alerts_enabled); } + } } From 53cadf80fa64a669548dbbd3f275154316dc6524 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 May 2024 12:24:31 +0100 Subject: [PATCH 39/43] Removed assertions for factories Signed-off-by: snipe --- tests/Feature/Api/Assets/AssetIndexTest.php | 23 ++++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php index b53fb02fde78..0a21e13f26a9 100644 --- a/tests/Feature/Api/Assets/AssetIndexTest.php +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -7,7 +7,7 @@ use App\Models\User; use Illuminate\Testing\Fluent\AssertableJson; use Tests\TestCase; -use Carbon; +use Carbon\Carbon; class AssetIndexTest extends TestCase { public function testAssetApiIndexReturnsExpectedAssets() @@ -34,7 +34,6 @@ public function testAssetApiIndexReturnsDisplayUpcomingAuditsDue() { Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); - $this->assertTrue(Asset::count() === 3); $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( @@ -50,9 +49,7 @@ public function testAssetApiIndexReturnsDisplayUpcomingAuditsDue() public function testAssetApiIndexReturnsOverdueForAudit() { Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->subDays(1)->format('Y-m-d')]); - - $this->assertTrue(Asset::count() === 3); - + $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( route('api.assets.list-upcoming', ['action' => 'audits', 'upcoming_status' => 'overdue'])) @@ -69,9 +66,7 @@ public function testAssetApiIndexReturnsDueOrOverdueForAudit() { Asset::factory()->count(3)->create(['next_audit_date' => Carbon::now()->format('Y-m-d')]); Asset::factory()->count(2)->create(['next_audit_date' => Carbon::now()->subDays(1)->format('Y-m-d')]); - - $this->assertTrue(Asset::count() === 5); - + $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( route('api.assets.list-upcoming', ['action' => 'audits', 'upcoming_status' => 'due-or-overdue'])) @@ -88,9 +83,7 @@ public function testAssetApiIndexReturnsDueOrOverdueForAudit() public function testAssetApiIndexReturnsDueForExpectedCheckin() { Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->format('Y-m-d')]); - - $this->assertTrue(Asset::count() === 3); - + $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'due']) @@ -106,9 +99,7 @@ public function testAssetApiIndexReturnsDueForExpectedCheckin() public function testAssetApiIndexReturnsOverdueForExpectedCheckin() { Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); - - $this->assertTrue(Asset::count() === 3); - + $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson(route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'overdue'])) ->assertOk() @@ -123,9 +114,7 @@ public function testAssetApiIndexReturnsDueOrOverdueForExpectedCheckin() { Asset::factory()->count(3)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->subDays(1)->format('Y-m-d')]); Asset::factory()->count(2)->create(['assigned_to' => '1', 'expected_checkin' => Carbon::now()->format('Y-m-d')]); - - $this->assertTrue(Asset::count() === 5); - + $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson(route('api.assets.list-upcoming', ['action' => 'checkins', 'upcoming_status' => 'due-or-overdue'])) ->assertOk() From 8c65880504cfad92cf176a2acfed1b461c47df41 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 May 2024 12:35:41 +0100 Subject: [PATCH 40/43] Changed badge to span in default blade Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 25f45cbd0d1f..c22118161e46 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -437,9 +437,9 @@ class="caret"> {{ trans('general.list_all') }} - + {{ (isset($total_assets)) ? $total_assets : '' }} - + @@ -451,7 +451,7 @@ class="caret"> {{ $status_nav->name }} - {{ $status_nav->asset_count }}) + {{ $status_nav->asset_count }}) @endforeach @endif @@ -460,42 +460,42 @@ class="caret"> {{ trans('general.deployed') }} - {{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }} + {{ (isset($total_deployed_sidebar)) ? $total_deployed_sidebar : '' }} {{ trans('general.ready_to_deploy') }} - {{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }} + {{ (isset($total_rtd_sidebar)) ? $total_rtd_sidebar : '' }} {{ trans('general.pending') }} - {{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }} + {{ (isset($total_pending_sidebar)) ? $total_pending_sidebar : '' }} {{ trans('general.undeployable') }} - {{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }} + {{ (isset($total_undeployable_sidebar)) ? $total_undeployable_sidebar : '' }} {{ trans('general.byod') }} - {{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }} + {{ (isset($total_byod_sidebar)) ? $total_byod_sidebar : '' }} {{ trans('admin/hardware/general.archived') }} - {{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }} + {{ (isset($total_archived_sidebar)) ? $total_archived_sidebar : '' }} {{ trans('general.audit_due') }} - {{ (isset($total_due_and_overdue_for_audit)) ? $total_due_and_overdue_for_audit : '' }} + {{ (isset($total_due_and_overdue_for_audit)) ? $total_due_and_overdue_for_audit : '' }} @endcan @@ -518,7 +518,7 @@ class="fas fa-check text-blue fa-fw"> {{ trans('general.checkin_due') }} - {{ (isset($total_due_and_overdue_for_checkin)) ? $total_due_and_overdue_for_checkin : '' }} + {{ (isset($total_due_and_overdue_for_checkin)) ? $total_due_and_overdue_for_checkin : '' }} @endcan From f893b2312942d7e85e26d79f9794849a18d9d2e8 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 May 2024 12:35:52 +0100 Subject: [PATCH 41/43] Refactored title blade areas Signed-off-by: snipe --- resources/views/hardware/audit-due.blade.php | 13 ++----------- resources/views/hardware/checkin-due.blade.php | 13 +------------ 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/resources/views/hardware/audit-due.blade.php b/resources/views/hardware/audit-due.blade.php index 58a944e4a9f0..0ee17ec23d07 100644 --- a/resources/views/hardware/audit-due.blade.php +++ b/resources/views/hardware/audit-due.blade.php @@ -1,21 +1,12 @@ @extends('layouts/default') -@section('title0') - - @if ((Request::get('company_id')) && ($company)) - {{ $company->name }} - @endif - - {{ trans_choice('general.audit_due_days', $settings->audit_warning_days, ['days' => $settings->audit_warning_days]) }} - -@stop - {{-- Page title --}} @section('title') - @yield('title0') @parent + {{ trans_choice('general.audit_due_days', $settings->audit_warning_days, ['days' => $settings->audit_warning_days]) }} @stop + {{-- Page content --}} @section('content') {{-- Page content --}} diff --git a/resources/views/hardware/checkin-due.blade.php b/resources/views/hardware/checkin-due.blade.php index d764a5178eb0..6ed7cf42c575 100644 --- a/resources/views/hardware/checkin-due.blade.php +++ b/resources/views/hardware/checkin-due.blade.php @@ -1,21 +1,10 @@ @extends('layouts/default') -@section('title0') - - @if ((Request::get('company_id')) && ($company)) - {{ $company->name }} - @endif - - {{ trans_choice('general.checkin_due_days', $settings->audit_warning_days, ['days' => $settings->audit_warning_days]) }} - -@stop - {{-- Page title --}} @section('title') - @yield('title0') @parent + {{ trans_choice('general.checkin_due_days', $settings->audit_warning_days, ['days' => $settings->audit_warning_days]) }} @stop - {{-- Page content --}} @section('content') {{-- Page content --}} From 4224bc0c43c906980985c3786a724dc9e330cb97 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 May 2024 12:36:57 +0100 Subject: [PATCH 42/43] Removed extra settings param Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 2 +- app/Http/Middleware/AssetCountForSidebar.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 2556b483ca7a..b234e9cbf1f6 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -167,7 +167,7 @@ public function index(Request $request, $action = null, $upcoming_status = null) $assets->DueForAudit($settings); break; case 'overdue': - $assets->OverdueForAudit($settings); + $assets->OverdueForAudit(); break; case 'due-or-overdue': $assets->DueOrOverdueForAudit($settings); diff --git a/app/Http/Middleware/AssetCountForSidebar.php b/app/Http/Middleware/AssetCountForSidebar.php index f55b72e0dd58..2bc3f950f96e 100644 --- a/app/Http/Middleware/AssetCountForSidebar.php +++ b/app/Http/Middleware/AssetCountForSidebar.php @@ -82,7 +82,7 @@ public function handle($request, Closure $next) } try { - $total_overdue_for_audit = Asset::OverdueForAudit($settings)->count(); + $total_overdue_for_audit = Asset::OverdueForAudit()->count(); view()->share('total_overdue_for_audit', $total_overdue_for_audit); } catch (\Exception $e) { \Log::debug($e); @@ -96,7 +96,7 @@ public function handle($request, Closure $next) } try { - $total_overdue_for_checkin = Asset::OverdueForCheckin($settings)->count(); + $total_overdue_for_checkin = Asset::OverdueForCheckin()->count(); view()->share('total_overdue_for_checkin', $total_overdue_for_checkin); } catch (\Exception $e) { \Log::debug($e); From eb9a654cc3c1bb745cdb03d326cea883285e3c99 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 May 2024 12:37:41 +0100 Subject: [PATCH 43/43] Moved settings call higher Signed-off-by: snipe --- app/Console/Commands/SendExpectedCheckinAlerts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php index 665dca4df4ed..e042e8b08819 100644 --- a/app/Console/Commands/SendExpectedCheckinAlerts.php +++ b/app/Console/Commands/SendExpectedCheckinAlerts.php @@ -41,11 +41,11 @@ public function __construct() */ public function handle() { + $settings = Setting::getSettings(); $interval = $settings->audit_warning_days ?? 0; $today = Carbon::now(); $interval_date = $today->copy()->addDays($interval); - - $settings = Setting::getSettings(); + $assets = Asset::whereNull('deleted_at')->DueOrOverdueForCheckin($settings)->orderBy('assets.expected_checkin', 'desc')->get(); $this->info($assets->count().' assets must be checked in on or before '.$interval_date.' is deadline');