A free open source IT asset/license management system
moves counts to licenses, allows bulk check in of unreassignable licenses
Godfrey M34e8360b1060
diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.phpindex 08b42b5a21..0f752cbb83 100644--- a/app/Http/Controllers/Api/LicenseSeatsController.php+++ b/app/Http/Controllers/Api/LicenseSeatsController.php@@ -139,7 +139,6 @@ class LicenseSeatsController extends Controllerif ($is_checkin) {if(!$licenseSeat->license->reassignable){- $licenseSeat->notes .= "\n" .trans('admin/licenses/message.checkin.not_reassignable') . ".";$licenseSeat->unreassignable_seat = true;$licenseSeat->save();}diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.phpindex 8bd3e34f11..30fcd1cffd 100644--- a/app/Http/Controllers/Licenses/LicenseCheckinController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php@@ -97,8 +97,6 @@ class LicenseCheckinController extends Controller$licenseSeat->notes = $request->input('notes');if (! $licenseSeat->license->reassignable) {$licenseSeat->unreassignable_seat = true;- $licenseSeat->notes .= "\n" . trans('admin/licenses/message.checkin.not_reassignable') . '.';-}session()->put(['redirect_option' => $request->get('redirect_option')]);@@ -131,21 +129,17 @@ class LicenseCheckinController extends Controller$license = License::findOrFail($licenseId);$this->authorize('checkin', $license);- if (! $license->reassignable) {- // Not allowed to checkin- Session::flash('error', 'License not reassignable.');-- return redirect()->back()->withInput();- }-$licenseSeatsByUser = LicenseSeat::where('license_id', '=', $licenseId)->whereNotNull('assigned_to')- ->with('user')+ ->with('user', 'license')->get();+ $license = $licenseSeatsByUser->first()?->license;foreach ($licenseSeatsByUser as $user_seat) {$user_seat->assigned_to = null;-+ if ($license && ! $license->reassignable) {+ $user_seat->unreassignable_seat = true;+ }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'));@@ -160,7 +154,9 @@ class LicenseCheckinController extends Controller$count = 0;foreach ($licenseSeatsByAsset as $asset_seat) {$asset_seat->asset_id = null;-+ if ($license && ! $license->reassignable) {+ $asset_seat->unreassignable_seat = true;+ }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'));diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.phpindex 54a8cb2764..7ef6eeb30b 100755--- a/app/Http/Controllers/Licenses/LicensesController.php+++ b/app/Http/Controllers/Licenses/LicensesController.php@@ -249,7 +249,16 @@ class LicensesController extends Controller$users_count = User::where('autoassign_licenses', '1')->count();- [$checkedout_seats_count, $total_seats_count, $available_seats_count, $unreassignable_seats_count] = LicenseSeat::usedSeatCount($license);+ $total_seats_count = (int) $license->totalSeatsByLicenseID();+ $available_seats_count = $license->availCount()->count();+ $unreassignable_seats_count = License::unReassignableCount($license);++ if(!$license->reassignable){+ $checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count );+ }+ else {+ $checkedout_seats_count = ($total_seats_count - $available_seats_count);+ }$this->authorize('view', $license);return view('licenses.view', compact('license'))diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.phpindex 86940a8dec..3be7b256da 100644--- a/app/Http/Transformers/LicensesTransformer.php+++ b/app/Http/Transformers/LicensesTransformer.php@@ -4,7 +4,6 @@ namespace App\Http\Transformers;use App\Helpers\Helper;use App\Models\License;-use App\Models\LicenseSeat;use Illuminate\Support\Facades\Gate;use Illuminate\Database\Eloquent\Collection;@@ -38,7 +37,7 @@ class LicensesTransformer'notes' => Helper::parseEscapedMarkedownInline($license->notes),'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),'seats' => (int) $license->seats,- 'free_seats_count' => (int) $license->free_seats_count - LicenseSeat::unReassignableCount($license),+ 'free_seats_count' => (int) $license->free_seats_count - License::unReassignableCount($license),'min_amt' => ($license->min_amt) ? (int) ($license->min_amt) : null,'license_name' => ($license->license_name) ? e($license->license_name) : null,'license_email' => ($license->license_email) ? e($license->license_email) : null,diff --git a/app/Models/License.php b/app/Models/License.phpindex e082e6c2a0..490a8401a4 100755--- a/app/Models/License.php+++ b/app/Models/License.php@@ -533,6 +533,7 @@ class License extends Depreciablereturn $this->licenseSeatsRelation()->whereNull('asset_id')->whereNull('assigned_to')+ ->where('unreassignable_seat', '=', false)->whereNull('deleted_at');}@@ -582,7 +583,22 @@ class License extends Depreciablereturn 0;}-+ /**+ * Calculates the number of unreassignable seats+ *+ * @author G. Martinez+ * @since [v7.1.15]+ */+ public static function unReassignableCount($license) : int+ {+ $count = 0;+ if (!$license->reassignable) {+ $count = licenseSeat::query()->where('unreassignable_seat', '=', true)+ ->where('license_id', '=', $license->id)+ ->count();+ }+ return $count;+ }/*** Calculates the number of remaining seats*@@ -590,11 +606,11 @@ class License extends Depreciable* @since [v1.0]* @return int*/- public function remaincount()+ public function remaincount() : int{$total = $this->licenseSeatsCount;$taken = $this->assigned_seats_count;- $unreassignable = LicenseSeat::unReassignableCount($this);+ $unreassignable = self::unReassignableCount($this);$diff = ($total - $taken - $unreassignable);return (int) $diff;diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.phpindex f491e19c25..6243d7d020 100755--- a/app/Models/LicenseSeat.php+++ b/app/Models/LicenseSeat.php@@ -2,7 +2,6 @@namespace App\Models;-use App\Helpers\Helper;use App\Models\Traits\Acceptable;use App\Notifications\CheckinLicenseNotification;use App\Notifications\CheckoutLicenseNotification;@@ -117,33 +116,6 @@ class LicenseSeat extends SnipeModel implements ICompanyableChildreturn false;}- public static function usedSeatCount($license): array {- $total_seats_count = (int) $license->totalSeatsByLicenseID();- $available_seats_count = $license->availCount()->count();- $unreassignable_seats_count = self::unReassignableCount($license);- if(!$license->reassignable){- $checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count );- }- else {- $checkedout_seats_count = ($total_seats_count - $available_seats_count);- }- return [- $checkedout_seats_count,- $total_seats_count,- $available_seats_count,- $unreassignable_seats_count,- ];- }- public static function unReassignableCount($license)- {-- if (!$license->reassignable) {- $count = static::query()->where('unreassignable_seat', '=', true)- ->where('license_id', '=', $license->id)- ->count();- return $count;- }- }/*** Query builder scope to order on departmentdiff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.phpindex 7af8676156..cc2f10b980 100755--- a/resources/views/licenses/view.blade.php+++ b/resources/views/licenses/view.blade.php@@ -32,7 +32,7 @@<x-icon type="seats" class="fa-2x" /></span><span class="hidden-xs hidden-sm">{{ trans('admin/licenses/form.seats') }}</span>- <span class="badge badge-secondary">{{ number_format($license->availCount()->count() - number_format($unreassignable_seats_count) ) }} / {{ number_format($license->seats)}}</span>+ <span class="badge badge-secondary">{{ number_format($license->availCount()->count()) }} / {{ number_format($license->seats)}}</span></a></li>@@ -573,13 +573,6 @@{{ trans('admin/licenses/general.bulk.checkin_all.button') }}</a></span>- @elseif (! $license->reassignable)- <span data-tooltip="true" title=" {{ trans('admin/licenses/general.bulk.checkin_all.disabled_tooltip_reassignable') }}">- <a href="#" class="btn btn-primary bg-purple btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 25px;">- <x-icon type="checkin" />- {{ trans('admin/licenses/general.bulk.checkin_all.button') }}- </a>- </span>@else<a href="#" class="btn btn-primary bg-purple btn-sm btn-social btn-block hidden-print" style="margin-bottom: 25px;" data-toggle="modal" data-tooltip="true" data-target="#checkinFromAllModal" data-content="{{ trans('general.sure_to_delete') }} data-title="{{ trans('general.delete') }}" onClick="return false;"><x-icon type="checkin" />