Skip to content

A free open source IT asset/license management system

implemented specific seat checkout (#5887)

Azerothian66c3f5432dd2
diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php
index 04ee93d061..98a946197c 100755
--- a/app/Http/Controllers/LicensesController.php
+++ b/app/Http/Controllers/LicensesController.php
@@ -265,31 +265,40 @@ class LicensesController extends Controller
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
* @param Request $request
+ * @param int $licenseId
* @param int $seatId
* @return \Illuminate\Http\RedirectResponse
*/
- public function postCheckout(Request $request, $licenseId)
+ public function postCheckout(Request $request, $licenseId, $seatId = null)
{
// Check that the license is valid
- if ($license = License::where('id',$licenseId)->first()) {
-
+ if ($license = License::where('id', $licenseId)->first()) {
+
// If the license is valid, check that there is an available seat
if ($license->getAvailSeatsCountAttribute() < 1) {
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
}
-
- // Get the next available seat for this license
- $next = $license->freeSeat();
-
- if (!$next) {
- return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
+ if (!$seatId) {
+ // Get the next available seat for this license
+ $next = $license->freeSeat();
+ if (!$next) {
+ return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
+ }
+ if (!$licenseSeat = LicenseSeat::where('id', '=', $next->id)->first()) {
+ return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
+ }
+ } else {
+ $licenseSeat = LicenseSeat::where('id', '=', $seatId)->first();
+ if (!$licenseSeat) {
+ return redirect()->route('licenses.index')->with('error', 'License seat is not available for checkout');
+ }
}
+
- if (!$licenseSeat = LicenseSeat::where('id', '=', $next->id)->first()) {
- return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
- }
+
+
$this->authorize('checkout', $license);
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index c2cb62d851..291ebc5311 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -277,7 +277,7 @@
function licenseSeatInOutFormatter(value, row) {
// 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 '<a href="{{ url('/') }}/licenses/' + row.license_id + '/checkout" class="btn btn-sm bg-maroon" data-tooltip="true" title="Check this item out">{{ trans('general.checkout') }}</a>';
+ return '<a href="{{ url('/') }}/licenses/' + row.license_id + '/checkout/'+row.id+'" class="btn btn-sm bg-maroon" data-tooltip="true" title="Check this item out">{{ trans('general.checkout') }}</a>';
} else {
return '<a href="{{ url('/') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check in this license seat.">{{ trans('general.checkin') }}</a>';
}
diff --git a/routes/web/licenses.php b/routes/web/licenses.php
index d6409fa201..2117d5229d 100644
--- a/routes/web/licenses.php
+++ b/routes/web/licenses.php
@@ -11,12 +11,12 @@ Route::group([ 'prefix' => 'licenses', 'middleware' => ['auth'] ], function () {
'as' => 'licenses.freecheckout',
'uses' => 'LicensesController@getFreeLicense'
]);
- Route::get('{licenseId}/checkout', [
+ Route::get('{licenseId}/checkout/{seatId?}', [
'as' => 'licenses.checkout',
'uses' => 'LicensesController@getCheckout'
]);
Route::post(
- '{licenseId}/checkout',
+ '{licenseId}/checkout/{seatId?}',
[ 'as' => 'licenses.checkout', 'uses' => 'LicensesController@postCheckout' ]
);
Route::get('{licenseId}/checkin/{backto?}', [