From 44dbbeb608fe2cf8eb6dd514577ebc86f88da7e7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 24 Jul 2024 14:17:49 -0700 Subject: [PATCH] Add accessory and consumable specific checkin methods --- .../Controllers/Users/BulkUsersController.php | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index b0683e2cbc..fab13f3fa3 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -16,6 +16,7 @@ use App\Models\Consumable; use App\Models\User; use Carbon\Carbon; use Illuminate\Http\Request; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Password; @@ -229,9 +230,9 @@ class BulkUsersController extends Controller $this->logItemCheckinAndDelete($assets, Asset::class); - $this->logItemCheckinAndDelete($accessories, Accessory::class); + $this->logAccessoriesCheckin($accessories); $this->logItemCheckinAndDelete($licenses, License::class); - $this->logItemCheckinAndDelete($consumables, Consumable::class); + $this->logConsumablesCheckin($consumables); Asset::whereIn('id', $assets->pluck('id'))->update([ @@ -279,7 +280,7 @@ class BulkUsersController extends Controller if ($itemType == License::class){ $item_id = $item->license_id; } - + $logAction->item_id = $item_id; // We can't rely on get_class here because the licenses/accessories fetched above are not eloquent models, but simply arrays. $logAction->item_type = $itemType; @@ -291,6 +292,34 @@ class BulkUsersController extends Controller } } + private function logAccessoriesCheckin(Collection $accessories): void + { + foreach ($accessories as $accessory) { + $logAction = new Actionlog(); + $logAction->item_id = $accessory->accessory_id; + $logAction->item_type = Accessory::class; + $logAction->target_id = $accessory->assigned_to; + $logAction->target_type = User::class; + $logAction->user_id = Auth::id(); + $logAction->note = 'Bulk checkin items'; + $logAction->logaction('checkin from'); + } + } + + private function logConsumablesCheckin(Collection $consumables): void + { + foreach ($consumables as $consumable) { + $logAction = new Actionlog(); + $logAction->item_id = $consumable->consumable_id; + $logAction->item_type = Consumable::class; + $logAction->target_id = $consumable->assigned_to; + $logAction->target_type = User::class; + $logAction->user_id = Auth::id(); + $logAction->note = 'Bulk checkin items'; + $logAction->logaction('checkin from'); + } + } + /** * Save bulk-edited users *