Added user company to checked out licenses

This commit is contained in:
snipe
2025-11-03 12:45:33 +00:00
parent 61895011fb
commit 46d1c14e1a
4 changed files with 37 additions and 12 deletions
@@ -26,11 +26,11 @@ class LicenseSeatsController extends Controller
if ($license = License::find($licenseId)) {
$this->authorize('view', $license);
$seats = LicenseSeat::with('license', 'user', 'asset', 'user.department')
$seats = LicenseSeat::with('license', 'user', 'asset', 'user.department', 'user.company', 'asset.company')
->where('license_seats.license_id', $licenseId);
if ($request->input('status') == 'available') {
$seats->whereNull('license_seats.assigned_to');
$seats->whereNull('license_seats.assigned_to')->whereNull('license_seats.asset_id');
}
if ($request->input('status') == 'assigned') {
@@ -40,8 +40,10 @@ class LicenseSeatsController extends Controller
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
if ($request->input('sort') == 'department') {
if ($request->input('sort') == 'assigned_user.department') {
$seats->OrderDepartments($order);
} elseif ($request->input('sort') == 'assigned_user.company') {
$seats->OrderCompany($order);
} else {
$seats->orderBy('updated_at', $order);
}
@@ -83,7 +85,7 @@ class LicenseSeatsController extends Controller
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
}
// 2. does the seat belong to the specified license?
if (! $license = $licenseSeat->license()->first() || $license->id != intval($licenseId)) {
if (! $licenseSeat = $licenseSeat->license()->first() || $licenseSeat->id != intval($licenseId)) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
}
@@ -36,6 +36,12 @@ class LicenseSeatsTransformer
'name' => e($seat->user->department->name),
] : null,
'company'=> ($seat->user->company) ?
[
'id' => (int) $seat->user->company->id,
'name' => e($seat->user->company->name),
] : null,
'created_at' => Helper::getFormattedDateObject($seat->created_at, 'datetime'),
] : null,
'assigned_asset' => ($seat->asset) ? [
+12 -5
View File
@@ -153,17 +153,24 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
}
public function scopeOrderCompany($query, $order)
{
return $query->leftJoin('users as license_seat_users', 'license_seats.assigned_to', '=', 'license_seat_users.id')
->leftJoin('companies as license_user_company', 'license_user_company.id', '=', 'license_seat_users.company_id')
->whereNotNull('license_seats.assigned_to')
->orderBy('license_user_company.name', $order);
}
public function scopeByAssigned($query)
{
return $query->where(
function ($query) {
$query->whereNotNull('assigned_to')
->orWhere(
function ($query) {
$query->whereNotNull('asset_id');
}
);
->orWhereNotNull('asset_id');
}
);
+13 -3
View File
@@ -248,10 +248,20 @@ class LicensePresenter extends Presenter
'title' => trans('admin/users/table.email'),
'visible' => true,
'formatter' => 'emailFormatter',
], [
'field' => 'department',
],
[
'field' => 'assigned_user.company',
'searchable' => false,
'sortable' => true,
'sortable' => false,
'switchable' => true,
'title' => trans('general.company'),
'visible' => true,
'formatter' => 'companiesLinkObjFormatter',
],
[
'field' => 'assigned_user.department',
'searchable' => false,
'sortable' => false,
'switchable' => true,
'title' => trans('general.department'),
'visible' => false,