A free open source IT asset/license management system
allows checkin of unreassignable license seats
Godfrey M8a0ed496235b
diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.phpindex 373a167642..f70c01bfd3 100644--- a/app/Http/Controllers/Licenses/LicenseCheckinController.php+++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php@@ -69,12 +69,7 @@ class LicenseCheckinController extends Controller$this->authorize('checkout', $license);- if (! $license->reassignable) {- // Not allowed to checkin- Session::flash('error', trans('admin/licenses/message.checkin.not_reassignable') . '.');- return redirect()->back()->withInput();- }// Declare the rules for the form validation$rules = [@@ -100,13 +95,16 @@ class LicenseCheckinController extends Controller$licenseSeat->assigned_to = null;$licenseSeat->asset_id = null;$licenseSeat->notes = $request->input('notes');+ if (! $license->reassignable) {+ $licenseSeat->notes .= "\n" . trans('admin/licenses/message.checkin.not_reassignable') . '.';+ }session()->put(['redirect_option' => $request->get('redirect_option')]);// Was the asset updated?if ($licenseSeat->save()) {- event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $request->input('notes')));+ event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $licenseSeat->notes));return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.checkin.success'));diff --git a/app/Http/Transformers/LicenseSeatsTransformer.php b/app/Http/Transformers/LicenseSeatsTransformer.phpindex 7ae68e9e44..742fc865e1 100644--- a/app/Http/Transformers/LicenseSeatsTransformer.php+++ b/app/Http/Transformers/LicenseSeatsTransformer.php@@ -2,6 +2,7 @@namespace App\Http\Transformers;+use App\Models\Actionlog;use App\Models\License;use App\Models\LicenseSeat;use Illuminate\Support\Facades\Gate;@@ -48,6 +49,7 @@ class LicenseSeatsTransformer'reassignable' => (bool) $seat->license->reassignable,'notes' => e($seat->notes),'user_can_checkout' => (($seat->assigned_to == '') && ($seat->asset_id == '')),+ 'disabled' => $this->unReassignable($seat),];if ($seat_count != 0) {@@ -66,4 +68,17 @@ 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/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.phpindex b297a4f720..f5b490fa14 100644--- a/app/Listeners/CheckoutableListener.php+++ b/app/Listeners/CheckoutableListener.php@@ -156,7 +156,7 @@ class CheckoutableListener$ccEmails = array_filter($adminCcEmailsArray);$mailable = $this->getCheckinMailType($event);$notifiable = $this->getNotifiables($event);- if ($event->checkedOutTo->locale){+ if ($event->checkedOutTo?->locale){$mailable->locale($event->checkedOutTo->locale);}// Send email notificationsdiff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.phpindex 4256c2c686..faac314e87 100644--- a/app/Presenters/LicensePresenter.php+++ b/app/Presenters/LicensePresenter.php@@ -284,6 +284,15 @@ class LicensePresenter extends Presenter'title' => trans('general.notes'),'formatter' => 'notesFormatter'],+ [+ 'field' => 'reassignable',+ 'searchable' => false,+ 'sortable' => false,+ 'visible' => true,+ 'title' => trans('admin/licenses/form.reassignable'),+ 'formatter' => 'trueFalseFormatter',+ 'class' => 'text-center',+ ],['field' => 'checkincheckout','searchable' => false,diff --git a/resources/lang/en-US/admin/licenses/message.php b/resources/lang/en-US/admin/licenses/message.phpindex 74e1d7af5a..3cda5e00e5 100644--- a/resources/lang/en-US/admin/licenses/message.php+++ b/resources/lang/en-US/admin/licenses/message.php@@ -50,7 +50,7 @@ return array('checkin' => array('error' => 'There was an issue checking in the license. Please try again.',- 'not_reassignable' => 'License not reassignable',+ 'not_reassignable' => 'Seat has been used.','success' => 'The license was checked in successfully'),diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex 099640f0b6..51e9c7299b 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -431,13 +431,16 @@// Checkouts need the license ID, checkins need the specific seat IDfunction licenseSeatInOutFormatter(value, row) {+ if(row.disabled) {+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple disabled" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkout') }}</a>';+ } else// The user is allowed to check the license seat out and it's availableif ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && ((!row.asset_id) && (!row.assigned_to))) {return '<a href="{{ config('app.url') }}/licenses/' + row.license_id + '/checkout/'+row.id+'" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';- } else {- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';}-+ else {+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';+ }}function genericCheckinCheckoutFormatter(destination) {