Skip to content

Commit 10a2d59

Browse files
authored
Merge pull request #27 from Godmartinz/checkin_non_reassignable_license_cleanup
adds bulk check in of unreassinable licenses, cleans up methods used for counting.
2 parents ca259ee + 34e8360 commit 10a2d59

File tree

7 files changed

+39
-55
lines changed

7 files changed

+39
-55
lines changed

app/Http/Controllers/Api/LicenseSeatsController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a
139139

140140
if ($is_checkin) {
141141
if(!$licenseSeat->license->reassignable){
142-
$licenseSeat->notes .= "\n" .trans('admin/licenses/message.checkin.not_reassignable') . ".";
143142
$licenseSeat->unreassignable_seat = true;
144143
$licenseSeat->save();
145144
}

app/Http/Controllers/Licenses/LicenseCheckinController.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ public function store(Request $request, $seatId = null, $backTo = null)
9797
$licenseSeat->notes = $request->input('notes');
9898
if (! $licenseSeat->license->reassignable) {
9999
$licenseSeat->unreassignable_seat = true;
100-
$licenseSeat->notes .= "\n" . trans('admin/licenses/message.checkin.not_reassignable') . '.';
101-
102100
}
103101

104102
session()->put(['redirect_option' => $request->get('redirect_option')]);
@@ -131,21 +129,17 @@ public function bulkCheckin(Request $request, $licenseId) {
131129
$license = License::findOrFail($licenseId);
132130
$this->authorize('checkin', $license);
133131

134-
if (! $license->reassignable) {
135-
// Not allowed to checkin
136-
Session::flash('error', 'License not reassignable.');
137-
138-
return redirect()->back()->withInput();
139-
}
140-
141132
$licenseSeatsByUser = LicenseSeat::where('license_id', '=', $licenseId)
142133
->whereNotNull('assigned_to')
143-
->with('user')
134+
->with('user', 'license')
144135
->get();
145136

137+
$license = $licenseSeatsByUser->first()?->license;
146138
foreach ($licenseSeatsByUser as $user_seat) {
147139
$user_seat->assigned_to = null;
148-
140+
if ($license && ! $license->reassignable) {
141+
$user_seat->unreassignable_seat = true;
142+
}
149143
if ($user_seat->save()) {
150144
Log::debug('Checking in '.$license->name.' from user '.$user_seat->username);
151145
$user_seat->logCheckin($user_seat->user, trans('admin/licenses/general.bulk.checkin_all.log_msg'));
@@ -160,7 +154,9 @@ public function bulkCheckin(Request $request, $licenseId) {
160154
$count = 0;
161155
foreach ($licenseSeatsByAsset as $asset_seat) {
162156
$asset_seat->asset_id = null;
163-
157+
if ($license && ! $license->reassignable) {
158+
$asset_seat->unreassignable_seat = true;
159+
}
164160
if ($asset_seat->save()) {
165161
Log::debug('Checking in '.$license->name.' from asset '.$asset_seat->asset_tag);
166162
$asset_seat->logCheckin($asset_seat->asset, trans('admin/licenses/general.bulk.checkin_all.log_msg'));

app/Http/Controllers/Licenses/LicensesController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,16 @@ public function show($licenseId = null)
249249

250250
$users_count = User::where('autoassign_licenses', '1')->count();
251251

252-
[$checkedout_seats_count, $total_seats_count, $available_seats_count, $unreassignable_seats_count] = LicenseSeat::usedSeatCount($license);
252+
$total_seats_count = (int) $license->totalSeatsByLicenseID();
253+
$available_seats_count = $license->availCount()->count();
254+
$unreassignable_seats_count = License::unReassignableCount($license);
255+
256+
if(!$license->reassignable){
257+
$checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count );
258+
}
259+
else {
260+
$checkedout_seats_count = ($total_seats_count - $available_seats_count);
261+
}
253262

254263
$this->authorize('view', $license);
255264
return view('licenses.view', compact('license'))

app/Http/Transformers/LicensesTransformer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Helpers\Helper;
66
use App\Models\License;
7-
use App\Models\LicenseSeat;
87
use Illuminate\Support\Facades\Gate;
98
use Illuminate\Database\Eloquent\Collection;
109

@@ -38,7 +37,7 @@ public function transformLicense(License $license)
3837
'notes' => Helper::parseEscapedMarkedownInline($license->notes),
3938
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
4039
'seats' => (int) $license->seats,
41-
'free_seats_count' => (int) $license->free_seats_count - LicenseSeat::unReassignableCount($license),
40+
'free_seats_count' => (int) $license->free_seats_count - License::unReassignableCount($license),
4241
'min_amt' => ($license->min_amt) ? (int) ($license->min_amt) : null,
4342
'license_name' => ($license->license_name) ? e($license->license_name) : null,
4443
'license_email' => ($license->license_email) ? e($license->license_email) : null,

app/Models/License.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ public function availCount()
533533
return $this->licenseSeatsRelation()
534534
->whereNull('asset_id')
535535
->whereNull('assigned_to')
536+
->where('unreassignable_seat', '=', false)
536537
->whereNull('deleted_at');
537538
}
538539

@@ -582,19 +583,34 @@ public function getAssignedSeatsCountAttribute()
582583

583584
return 0;
584585
}
585-
586+
/**
587+
* Calculates the number of unreassignable seats
588+
*
589+
* @author G. Martinez
590+
* @since [v7.1.15]
591+
*/
592+
public static function unReassignableCount($license) : int
593+
{
594+
$count = 0;
595+
if (!$license->reassignable) {
596+
$count = licenseSeat::query()->where('unreassignable_seat', '=', true)
597+
->where('license_id', '=', $license->id)
598+
->count();
599+
}
600+
return $count;
601+
}
586602
/**
587603
* Calculates the number of remaining seats
588604
*
589605
* @author A. Gianotto <[email protected]>
590606
* @since [v1.0]
591607
* @return int
592608
*/
593-
public function remaincount()
609+
public function remaincount() : int
594610
{
595611
$total = $this->licenseSeatsCount;
596612
$taken = $this->assigned_seats_count;
597-
$unreassignable = LicenseSeat::unReassignableCount($this);
613+
$unreassignable = self::unReassignableCount($this);
598614
$diff = ($total - $taken - $unreassignable);
599615

600616
return (int) $diff;

app/Models/LicenseSeat.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Models;
44

5-
use App\Helpers\Helper;
65
use App\Models\Traits\Acceptable;
76
use App\Notifications\CheckinLicenseNotification;
87
use App\Notifications\CheckoutLicenseNotification;
@@ -117,33 +116,6 @@ public function location()
117116

118117
return false;
119118
}
120-
public static function usedSeatCount($license): array {
121-
$total_seats_count = (int) $license->totalSeatsByLicenseID();
122-
$available_seats_count = $license->availCount()->count();
123-
$unreassignable_seats_count = self::unReassignableCount($license);
124-
if(!$license->reassignable){
125-
$checkedout_seats_count = ($total_seats_count - $available_seats_count - $unreassignable_seats_count );
126-
}
127-
else {
128-
$checkedout_seats_count = ($total_seats_count - $available_seats_count);
129-
}
130-
return [
131-
$checkedout_seats_count,
132-
$total_seats_count,
133-
$available_seats_count,
134-
$unreassignable_seats_count,
135-
];
136-
}
137-
public static function unReassignableCount($license)
138-
{
139-
140-
if (!$license->reassignable) {
141-
$count = static::query()->where('unreassignable_seat', '=', true)
142-
->where('license_id', '=', $license->id)
143-
->count();
144-
return $count;
145-
}
146-
}
147119

148120
/**
149121
* Query builder scope to order on department

resources/views/licenses/view.blade.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<x-icon type="seats" class="fa-2x" />
3333
</span>
3434
<span class="hidden-xs hidden-sm">{{ trans('admin/licenses/form.seats') }}</span>
35-
<span class="badge badge-secondary">{{ number_format($license->availCount()->count() - number_format($unreassignable_seats_count) ) }} / {{ number_format($license->seats)}}</span>
35+
<span class="badge badge-secondary">{{ number_format($license->availCount()->count()) }} / {{ number_format($license->seats)}}</span>
3636

3737
</a>
3838
</li>
@@ -573,13 +573,6 @@ class="table table-striped snipe-table"
573573
{{ trans('admin/licenses/general.bulk.checkin_all.button') }}
574574
</a>
575575
</span>
576-
@elseif (! $license->reassignable)
577-
<span data-tooltip="true" title=" {{ trans('admin/licenses/general.bulk.checkin_all.disabled_tooltip_reassignable') }}">
578-
<a href="#" class="btn btn-primary bg-purple btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 25px;">
579-
<x-icon type="checkin" />
580-
{{ trans('admin/licenses/general.bulk.checkin_all.button') }}
581-
</a>
582-
</span>
583576
@else
584577
<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;">
585578
<x-icon type="checkin" />

0 commit comments

Comments
 (0)