Fixes #4001 - license checkout not working

This commit is contained in:
snipe 2017-09-25 21:40:43 -07:00
parent 26203801f6
commit f2ee7dcabb
7 changed files with 35 additions and 11 deletions

View file

@ -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'));
}
}

View file

@ -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),

View file

@ -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)

View file

@ -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,

View file

@ -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

View file

@ -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(

View file

@ -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 '<a href="{{ url('/') }}/' + destination + '/' + row.id + '/checkout" class="btn btn-sm btn-primary" data-tooltip="true" title="Check this item out to a user">{{ trans('general.checkout') }}</a>';
// case for licenses
if (row.next_seat) {
return '<a href="{{ url('/') }}/' + destination + '/' + row.next_seat + '/checkout" class="btn btn-sm btn-primary" data-tooltip="true" title="Check this item out to a user">{{ trans('general.checkout') }}</a>';
} else {
return '<a href="{{ url('/') }}/' + destination + '/' + row.id + '/checkout" class="btn btn-sm btn-primary" data-tooltip="true" title="Check this item out to a user">{{ trans('general.checkout') }}</a>';
}
// 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)) {