diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.php
index 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.php
index 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 LicenseSeatsTransformer
return $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.php
index 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 notifications
diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php
index 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.php
index 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.php
index 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 ID
function licenseSeatInOutFormatter(value, row) {
+ if(row.disabled) {
+ return '{{ trans('general.checkout') }}';
+ } else
// The user is allowed to check the license seat out and it's available
if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && ((!row.asset_id) && (!row.assigned_to))) {
return '{{ trans('general.checkout') }}';
- } else {
- return '{{ trans('general.checkin') }}';
}
-
+ else {
+ return '{{ trans('general.checkin') }}';
+ }
}
function genericCheckinCheckoutFormatter(destination) {