A free open source IT asset/license management system
Use new translations for logs
snipef21d9c27e6ae
diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.phpindex b3f02b880b..50e20c7985 100644--- a/app/Http/Controllers/Licenses/LicenseCheckinController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php@@ -128,20 +128,37 @@ class LicenseCheckinController extends Controller$license = License::findOrFail($licenseId);$this->authorize('checkin', $license);- $licenseSeats = LicenseSeat::where('license_id', '=', $licenseId)+ $licenseSeatsByUser = LicenseSeat::where('license_id', '=', $licenseId)->whereNotNull('assigned_to')->with('user')->get();- foreach ($licenseSeats as $seat) {- $seat->assigned_to = null;+ foreach ($licenseSeatsByUser as $user_seat) {+ $user_seat->assigned_to = null;- if ($seat->save()) {- $seat->logCheckin($seat->user, 'Checked in via bulk checkin on license page');+ if ($user_seat->save()) {+ \Log::debug('Checking in '.$license->name.' from user '.$user_seat->username);+ $user_seat->logCheckin($user_seat->user, trans('admin/licenses/general.bulk.checkin_all.log_msg'));}}- return redirect()->back()->with('success', 'All licenses checked in successfully!');+ $licenseSeatsByAsset = LicenseSeat::where('license_id', '=', $licenseId)+ ->whereNotNull('asset_id')+ ->with('asset')+ ->get();++ $count = 0;+ foreach ($licenseSeatsByAsset as $asset_seat) {+ $asset_seat->asset_id = null;++ if ($asset_seat->save()) {+ \Log::debug('Checking in '.$license->name.' from asset '.$asset_seat->asset_tag);+ $asset_seat->logCheckin($asset_seat->asset, trans('admin/licenses/general.bulk.checkin_all.log_msg'));+ $count++;+ }+ }++ return redirect()->back()->with('success', trans_choice('admin/licenses/general.bulk.checkin_all.success', 2, ['count' => $count] ));}diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.phpindex 0581e8ddac..4eb108afc9 100644--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php@@ -139,23 +139,24 @@ class LicenseCheckoutController extends Controllerpublic function bulkCheckout($licenseId) {- \Log::debug('checking out '.$licenseId.' via bulk');+ \Log::debug('Checking out '.$licenseId.' via bulk');$license = License::findOrFail($licenseId);$this->authorize('checkin', $license);+ $avail_count = $license->getAvailSeatsCountAttribute();$users = User::whereNull('deleted_at')->where('autoassign_licenses', '=', 1)->with('licenses')->get();- \Log::debug($users->count().' will be assigned');+ \Log::debug($avail_count.' will be assigned');- if ($users->count() > $license->getAvailSeatsCountAttribute()) {+ if ($users->count() > $avail_count) {\Log::debug('You do not have enough free seats to complete this task, so we will check out as many as we can. ');}// If the license is valid, check that there is an available seatif ($license->availCount()->count() < 1) {- return redirect()->back()->with('error', 'No more available seats');+ return redirect()->back()->with('error', trans('admin/licenses/general.bulk.checkout_all.error_no_seats'));}- $avail_count = $license->availCount()->count();+$assigned_count = 0;foreach ($users as $user) {@@ -173,18 +174,18 @@ class LicenseCheckoutController extends Controllerif ($licenseSeat->save()) {$avail_count--;- $assigned_count--;- \Log::debug('License seat '.$licenseSeat.' is now assigned to '.$licenseSeat->assigned_to);- $licenseSeat->logCheckout('Checked out bulk license checkout in license GUI', $user);- \Log::debug('License '.$licenseId.' seat '.$licenseSeat->id.' checked out to '.$user->username);+ $assigned_count++;+ $licenseSeat->logCheckout(trans('admin/licenses/general.bulk.checkout_all.log_msg'), $user);+ \Log::debug('License '.$license->name.' seat '.$licenseSeat->id.' checked out to '.$user->username);}if ($avail_count == 0) {- return redirect()->back()->with('warning', $assigned_count.' users were assigned this asset, but we ran out of open seats.');+ return redirect()->back()->with('warning', trans('admin/licenses/general.bulk.checkout_all.warn_not_enough_seats', ['count' => $assigned_count]));}}- return redirect()->back()->with('success', 'Licenses checked out successfully to '.$assigned_count.' users!');+ return redirect()->back()->with('success', trans_choice('admin/licenses/general.bulk.checkout_all.success', 2, ['count' => $assigned_count] ));+}}