A free open source IT asset/license management system
removed unused models, castged unreassignable_seat, clean up in general
Godfrey M2143952a1eac
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 26301c1010..8f653ff353 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -2,7 +2,6 @@namespace App\Helpers;use App\Models\Accessory;-use App\Models\Actionlog;use App\Models\Asset;use App\Models\AssetModel;use App\Models\Component;@@ -10,7 +9,6 @@ use App\Models\Consumable;use App\Models\CustomField;use App\Models\CustomFieldset;use App\Models\Depreciation;-use App\Models\LicenseSeat;use App\Models\Setting;use App\Models\Statuslabel;use App\Models\License;@@ -1531,14 +1529,5 @@ class Helper}return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'));}- public static function unReassignableCount($license)- {- if (!$license->reassignable) {- $count = LicenseSeat::where('unreassignable_seat', '=', true)- ->where('license_id', '=', $license->id)- ->count();- return $count;- }- }}diff --git a/app/Http/Controllers/Api/LicenseSeatsController.php b/app/Http/Controllers/Api/LicenseSeatsController.phpindex 38f8babf9d..08b42b5a21 100644--- a/app/Http/Controllers/Api/LicenseSeatsController.php+++ b/app/Http/Controllers/Api/LicenseSeatsController.php@@ -138,11 +138,12 @@ class LicenseSeatsController extends Controllerif ($licenseSeat->save()) {if ($is_checkin) {- $licenseSeat->logCheckin($target, $request->input('note'));if(!$licenseSeat->license->reassignable){+ $licenseSeat->notes .= "\n" .trans('admin/licenses/message.checkin.not_reassignable') . ".";$licenseSeat->unreassignable_seat = true;$licenseSeat->save();}+ $licenseSeat->logCheckin($target, $licenseSeat->notes);return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));}diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.phpindex 8ddac020b5..54a8cb2764 100755--- a/app/Http/Controllers/Licenses/LicensesController.php+++ b/app/Http/Controllers/Licenses/LicensesController.php@@ -248,15 +248,8 @@ class LicensesController extends Controller}$users_count = User::where('autoassign_licenses', '1')->count();- $total_seats_count = (int) $license->totalSeatsByLicenseID();- $available_seats_count = $license->availCount()->count();- $unreassignable_seats_count = Helper::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);- }++ [$checkedout_seats_count, $total_seats_count, $available_seats_count, $unreassignable_seats_count] = LicenseSeat::usedSeatCount($license);$this->authorize('view', $license);return view('licenses.view', compact('license'))diff --git a/app/Http/Transformers/LicenseSeatsTransformer.php b/app/Http/Transformers/LicenseSeatsTransformer.phpindex e882e74a88..9868876295 100644--- a/app/Http/Transformers/LicenseSeatsTransformer.php+++ b/app/Http/Transformers/LicenseSeatsTransformer.php@@ -2,12 +2,10 @@namespace App\Http\Transformers;-use App\Models\Actionlog;use App\Models\License;use App\Models\LicenseSeat;use Illuminate\Support\Facades\Gate;use Illuminate\Database\Eloquent\Collection;-class LicenseSeatsTransformer{public function transformLicenseSeats(Collection $seats, $total)@@ -68,17 +66,4 @@ class LicenseSeatsTransformerreturn $array;}-// private function unReassignable($seat)-// {-// if (!$seat->license->reassignable) {-// $exists = Actionlog::where('action_type', '=', 'checkin from')-// ->where('item_id', '=', $seat->license->id)-// ->where('updated_at', '=', $seat->updated_at)-// ->exists();-// if($exists) {-// return true;-// }-// return false;-// }-// }}diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.phpindex 6ae57e6292..86940a8dec 100644--- a/app/Http/Transformers/LicensesTransformer.php+++ b/app/Http/Transformers/LicensesTransformer.php@@ -4,6 +4,7 @@ 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;@@ -37,7 +38,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 - Helper::unReassignableCount($license),+ 'free_seats_count' => (int) $license->free_seats_count - LicenseSeat::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 0b5eed097a..e082e6c2a0 100755--- a/app/Models/License.php+++ b/app/Models/License.php@@ -594,7 +594,7 @@ class License extends Depreciable{$total = $this->licenseSeatsCount;$taken = $this->assigned_seats_count;- $unreassignable = Helper::unReassignableCount($this);+ $unreassignable = LicenseSeat::unReassignableCount($this);$diff = ($total - $taken - $unreassignable);return (int) $diff;diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.phpindex 397a141468..f491e19c25 100755--- a/app/Models/LicenseSeat.php+++ b/app/Models/LicenseSeat.php@@ -2,6 +2,7 @@namespace App\Models;+use App\Helpers\Helper;use App\Models\Traits\Acceptable;use App\Notifications\CheckinLicenseNotification;use App\Notifications\CheckoutLicenseNotification;@@ -21,6 +22,9 @@ class LicenseSeat extends SnipeModel implements ICompanyableChildprotected $guarded = 'id';protected $table = 'license_seats';+ protected $casts = [+ 'unreassignable_seat' => 'boolean',+ ];/*** The attributes that are mass assignable.@@ -113,6 +117,33 @@ 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/database/migrations/2025_01_15_190348_adds_unavailable_to_license_seats_tables.php b/database/migrations/2025_01_15_190348_adds_unavailable_to_license_seats_tables.phpindex 9aec0343ac..40c8ad5367 100644--- a/database/migrations/2025_01_15_190348_adds_unavailable_to_license_seats_tables.php+++ b/database/migrations/2025_01_15_190348_adds_unavailable_to_license_seats_tables.php@@ -1,9 +1,6 @@<?php-namespace App\Models\LicenseSeat;-use App\Models\LicenseSeat;use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;-use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Schema;return new class extends Migrationdiff --git a/tests/Feature/Checkins/Ui/LicenseCheckinTest.php b/tests/Feature/Checkins/Ui/LicenseCheckinTest.phpindex 3c00d37071..5cd906fa35 100644--- a/tests/Feature/Checkins/Ui/LicenseCheckinTest.php+++ b/tests/Feature/Checkins/Ui/LicenseCheckinTest.php@@ -32,7 +32,7 @@ class LicenseCheckinTest extends TestCase$licenseSeat->refresh();- $this->assertEquals(1, $licenseSeat->unreassignable_seat);+ $this->assertEquals(true, $licenseSeat->unreassignable_seat);}public function testCannotCheckinLicenseThatIsNotAssigned()