From 4b66ca6ac547fb00f6eca8faccd436fc4dd97b16 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 15:27:15 -0700 Subject: [PATCH] Added method to bulk checkin (much simpler than checking out) Signed-off-by: snipe --- .../Licenses/LicenseCheckinController.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.php index d1c7607493..b3f02b880b 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckinController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php @@ -123,7 +123,25 @@ class LicenseCheckinController extends Controller * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function bulkCheckin() { + public function bulkCheckin(Request $request, $licenseId) { + + $license = License::findOrFail($licenseId); + $this->authorize('checkin', $license); + + $licenseSeats = LicenseSeat::where('license_id', '=', $licenseId) + ->whereNotNull('assigned_to') + ->with('user') + ->get(); + + foreach ($licenseSeats as $seat) { + $seat->assigned_to = null; + + if ($seat->save()) { + $seat->logCheckin($seat->user, 'Checked in via bulk checkin on license page'); + } + } + + return redirect()->back()->with('success', 'All licenses checked in successfully!'); }