diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index 2f14a72829..6e6b67c78b 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -306,8 +306,8 @@ class LicensesController extends Controller return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.asset_does_not_exist')); } - if (($target->assigned_to!='') && (($target->assigned_to!=$assigned_to)) && ($target!='')) { - return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset')); + if (($request->has('assigned_to')) && ($request->has('asset_id'))) { + return redirect()->back()->withInput()->with('error', trans('admin/licenses/message.select_asset_or_person')); } } diff --git a/app/Http/Transformers/LicensesTransformer.php b/app/Http/Transformers/LicensesTransformer.php index 8dad4b160e..92b3e4a5d6 100644 --- a/app/Http/Transformers/LicensesTransformer.php +++ b/app/Http/Transformers/LicensesTransformer.php @@ -33,8 +33,9 @@ class LicensesTransformer 'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null, 'notes' => e($license->notes), 'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), - 'total_seats' => (int) $license->total_seats, - 'remaining_qty' => $license->remaincount(), + 'total_seats' => (int) $license->seats, + 'next_seat' => ($license->freeSeat()) ? (int) $license->freeSeat()->id : null, + 'remaining_qty' => (int) $license->remaincount(), 'min_qty' => $license->remaincount(), 'license_name' => e($license->license_name), 'license_email' => e($license->license_email), diff --git a/app/Models/License.php b/app/Models/License.php index ca2c9c7281..91a150198d 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -332,14 +332,17 @@ class License extends Depreciable return $this->belongsTo('\App\Models\Supplier', 'supplier_id'); } + /* + * Get the next available free seat - used by + * the API to populate next_seat + */ public function freeSeat() { - $seat = LicenseSeat::where('license_id', '=', $this->id) + return $this->licenseseats() ->whereNull('deleted_at') ->whereNull('assigned_to') ->whereNull('asset_id') ->first(); - return $seat->id; } public static function getExpiringLicenses($days = 60) diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index da9899ec02..5e13bb8a87 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -43,20 +43,23 @@ trait Loggable $log->target_type = get_class($target); $log->target_id = $target->id; - $class = get_class($target); - if ($class == Location::class) { + $target_class = get_class($target); + + // Figure out what the target is + if ($target_class == Location::class) { // We can checkout to a location $log->location_id = $target->id; - } else if ($class== Asset::class) { + } elseif ($target_class== Asset::class) { $log->location_id = $target->rtd_location_id; } else { $log->location_id = $target->location_id; } + $log->note = $note; $log->logaction('checkout'); $params = [ - 'item' => $this, + 'item' => $log->item, 'target' => $target, 'admin' => $log->user, 'note' => $note, diff --git a/app/Presenters/LicensePresenter.php b/app/Presenters/LicensePresenter.php index 2a7f8c0526..5bbdb16cca 100644 --- a/app/Presenters/LicensePresenter.php +++ b/app/Presenters/LicensePresenter.php @@ -146,6 +146,16 @@ class LicensePresenter extends Presenter return (string)link_to_route('licenses.show', $this->name, $this->id); } + /** + * Link to this licenses Name + * @return string + */ + public function fullName() + { + return 'poop'; + } + + /** * Link to this licenses serial * @return string diff --git a/resources/lang/en/admin/licenses/message.php b/resources/lang/en/admin/licenses/message.php index d5dbfe77b9..3e7ee486c7 100644 --- a/resources/lang/en/admin/licenses/message.php +++ b/resources/lang/en/admin/licenses/message.php @@ -7,6 +7,7 @@ return array( 'asset_does_not_exist' => 'The asset you are trying to associate with this license does not exist.', 'owner_doesnt_match_asset' => 'The asset you are trying to associate with this license is owned by somene other than the person selected in the assigned to dropdown.', 'assoc_users' => 'This license is currently checked out to a user and cannot be deleted. Please check the license in first, and then try deleting again. ', + 'select_asset_or_person' => 'You must select an asset or a user, but not both.', 'create' => array( diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 4ea74216ed..e579c666ca 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -215,7 +215,13 @@ $('.snipe-table').bootstrapTable({ // The user is allowed to check items out, AND the item is deployable if ((row.available_actions.checkout == true) && (row.user_can_checkout == true) && (!row.assigned_to)) { - return '{{ trans('general.checkout') }}'; + // case for licenses + if (row.next_seat) { + return '{{ trans('general.checkout') }}'; + } else { + return '{{ trans('general.checkout') }}'; + } + // The user is allowed to check items out, but the item is not deployable } else if (((row.user_can_checkout == false)) && (row.available_actions.checkout == true) && (!row.assigned_to)) {