Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe
2025-05-29 22:18:50 +01:00
10 changed files with 316 additions and 33 deletions

View File

@@ -99,8 +99,11 @@ class SendAcceptanceReminder extends Command
foreach ($no_email_list as $user) {
$rows[] = [$user['id'], $user['name']];
}
$this->info("The following users do not have an email address:");
$this->table($headers, $rows);
if (!empty($rows)) {
$this->info("The following users do not have an email address:");
$this->table($headers, $rows);
}
return 0;
}

View File

@@ -87,7 +87,8 @@ class LocationsController extends Controller
->withCount('accessories as accessories_count')
->withCount('rtd_assets as rtd_assets_count')
->withCount('children as children_count')
->withCount('users as users_count');
->withCount('users as users_count')
->with('adminuser');
// Only scope locations if the setting is enabled
if (Setting::getSettings()->scope_locations_fmcs) {

View File

@@ -24,10 +24,15 @@ class SuppliersController extends Controller
public function index(Request $request): array
{
$this->authorize('view', Supplier::class);
$allowed_columns = ['
id',
$allowed_columns = [
'id',
'name',
'address',
'address2',
'city',
'state',
'country',
'zip',
'phone',
'contact',
'fax',
@@ -39,21 +44,24 @@ class SuppliersController extends Controller
'components_count',
'consumables_count',
'url',
'notes',
];
$suppliers = Supplier::select(
['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes', 'url'])
['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'created_by', 'updated_at', 'deleted_at', 'image', 'notes', 'url', 'zip'])
->withCount('assets as assets_count')
->withCount('licenses as licenses_count')
->withCount('accessories as accessories_count')
->withCount('components as components_count')
->withCount('consumables as consumables_count');
->withCount('consumables as consumables_count')
->with('adminuser');
if ($request->filled('search')) {
$suppliers = $suppliers->TextSearch($request->input('search'));
$suppliers->TextSearch($request->input('search'));
}
if ($request->filled('name')) {
$suppliers->where('name', '=', $request->input('name'));
}
@@ -100,7 +108,15 @@ class SuppliersController extends Controller
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
$suppliers->orderBy($sort, $order);
switch ($request->input('sort')) {
case 'created_by':
$suppliers->OrderByCreatedByName($order);
break;
default:
$suppliers->orderBy($sort, $order);
break;
}
$total = $suppliers->count();
$suppliers = $suppliers->skip($offset)->take($limit)->get();

View File

@@ -57,6 +57,10 @@ class LocationsTransformer
'ldap_ou' => ($location->ldap_ou) ? e($location->ldap_ou) : null,
'notes' => Helper::parseEscapedMarkedownInline($location->notes),
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
'created_by' => $location->adminuser ? [
'id' => (int) $location->adminuser->id,
'name'=> e($location->adminuser->present()->fullName),
]: null,
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
'parent' => ($location->parent) ? [
'id' => (int) $location->parent->id,

View File

@@ -45,6 +45,10 @@ class SuppliersTransformer
'components_count' => (int) $supplier->components_count,
'notes' => ($supplier->notes) ? Helper::parseEscapedMarkedownInline($supplier->notes) : null,
'created_at' => Helper::getFormattedDateObject($supplier->created_at, 'datetime'),
'created_by' => $supplier->adminuser ? [
'id' => (int) $supplier->adminuser->id,
'name'=> e($supplier->adminuser->present()->fullName),
]: null,
'updated_at' => Helper::getFormattedDateObject($supplier->updated_at, 'datetime'),
];

View File

@@ -135,6 +135,17 @@ class Location extends SnipeModel
return $this->hasMany(\App\Models\User::class, 'location_id');
}
/**
* Establishes the location -> admin user relationship
*
* @author A. Gianotto <snipe@snipe.net>
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function adminuser()
{
return $this->belongsTo(\App\Models\User::class, 'created_by');
}
/**
* Find assets with this location as their location_id
*
@@ -374,4 +385,13 @@ class Location extends SnipeModel
{
return $query->leftJoin('companies as company_sort', 'locations.company_id', '=', 'company_sort.id')->orderBy('company_sort.name', $order);
}
/**
* Query builder scope to order on the user that created it
*/
public function scopeOrderByCreatedByName($query, $order)
{
return $query->leftJoin('users as admin_sort', 'locations.created_by', '=', 'admin_sort.id')->select('locations.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
}

View File

@@ -48,7 +48,7 @@ class Supplier extends SnipeModel
*
* @var array
*/
protected $searchableAttributes = ['name'];
protected $searchableAttributes = ['name', 'notes', 'phone', 'fax', 'url', 'email', 'contact', 'address', 'address2', 'city', 'state', 'country', 'zip'];
/**
* The relations and their attributes that should be included when searching the model.
@@ -128,6 +128,18 @@ class Supplier extends SnipeModel
return $this->hasMany(\App\Models\Consumable::class, 'supplier_id');
}
/**
* Establishes the supplier -> admin user relationship
*
* @author A. Gianotto <snipe@snipe.net>
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function adminuser()
{
return $this->belongsTo(\App\Models\User::class, 'created_by');
}
/**
* Establishes the supplier -> asset maintenances relationship
*
@@ -197,4 +209,13 @@ class Supplier extends SnipeModel
return $url;
}
/**
* Query builder scope to order on the user that created it
*/
public function scopeOrderByCreatedByName($query, $order)
{
return $query->leftJoin('users as admin_sort', 'suppliers.created_by', '=', 'admin_sort.id')->select('suppliers.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
}

View File

@@ -208,7 +208,16 @@ class LocationPresenter extends Presenter
'title' => trans('general.created_at'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
], [
],
[
'field' => 'created_by',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_by'),
'visible' => false,
'formatter' => 'usersLinkObjFormatter',
],[
'field' => 'actions',
'searchable' => false,
'sortable' => false,

View File

@@ -0,0 +1,226 @@
<?php
namespace App\Presenters;
/**
* Class LocationPresenter
*/
class SupplierPresenter extends Presenter
{
/**
* Json Column Layout for bootstrap table
*/
public static function dataTableLayout()
{
$layout = [
[
'field' => 'id',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.id'),
'visible' => false,
],
[
'field' => 'name',
'searchable' => true,
'sortable' => true,
'switchable' => false,
'title' => trans('general.name'),
'visible' => true,
'formatter' => 'suppliersLinkFormatter',
], [
'field' => 'image',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.image'),
'visible' => true,
'formatter' => 'imageFormatter',
],
[
'field' => 'assets_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.assets'),
'titleTooltip' => trans('general.assets'),
'visible' => true,
'class' => 'css-barcode',
], [
'field' => 'accessories_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.accessories'),
'titleTooltip' => trans('general.accessories'),
'visible' => true,
'class' => 'css-accessory',
],
[
'field' => 'licenses_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.licenses'),
'titleTooltip' => trans('general.licenses'),
'visible' => true,
'class' => 'css-license',
], [
'field' => 'components_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.components'),
'titleTooltip' => trans('general.components'),
'visible' => true,
'class' => 'css-component',
], [
'field' => 'consumables_count',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.consumables'),
'titleTooltip' => trans('general.consumables'),
'visible' => true,
'class' => 'css-consumable',
], [
'field' => 'url',
'searchable' => false,
'sortable' => true,
'switchable' => true,
'title' => trans('general.url'),
'visible' => true,
'formatter' => 'externalLinkFormatter',
], [
'field' => 'address',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/locations/table.address'),
'visible' => true,
], [
'field' => 'address2',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/locations/table.address2'),
'visible' => false,
], [
'field' => 'city',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/locations/table.city'),
'visible' => true,
], [
'field' => 'state',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/locations/table.state'),
'visible' => true,
], [
'field' => 'zip',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/locations/table.zip'),
'visible' => false,
], [
'field' => 'country',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/locations/table.country'),
'visible' => false,
], [
'field' => 'phone',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/users/table.phone'),
'visible' => false,
'formatter' => 'phoneFormatter',
], [
'field' => 'fax',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('admin/suppliers/table.fax'),
'visible' => false,
'formatter' => 'phoneFormatter',
], [
'field' => 'notes',
'searchable' => true,
'sortable' => true,
'visible' => false,
'title' => trans('general.notes'),
], [
'field' => 'created_at',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_at'),
'visible' => false,
'formatter' => 'dateDisplayFormatter',
], [
'field' => 'created_by',
'searchable' => true,
'sortable' => true,
'switchable' => true,
'title' => trans('general.created_by'),
'visible' => false,
'formatter' => 'usersLinkObjFormatter',
], [
'field' => 'actions',
'searchable' => false,
'sortable' => false,
'switchable' => false,
'title' => trans('table.actions'),
'visible' => true,
'formatter' => 'suppliersActionsFormatter',
],
];
return json_encode($layout);
}
/**
* Link to this supplier name
* @return string
*/
public function nameUrl()
{
return (string) link_to_route('suppliers.show', $this->name, $this->id);
}
/**
* Getter for Polymorphism.
* @return mixed
*/
public function name()
{
return $this->model->name;
}
/**
* Url to view this item.
* @return string
*/
public function viewUrl()
{
return route('suppliers.show', $this->id);
}
public function glyph()
{
return '<x-icon type="suppliers" />';
}
public function fullName()
{
return $this->name;
}
}

View File

@@ -21,6 +21,7 @@
<div class="box box-default">
<div class="box-body">
<table
data-columns="{{ \App\Presenters\SupplierPresenter::dataTableLayout() }}"
data-cookie-id-table="suppliersTable"
data-pagination="true"
data-id-table="suppliersTable"
@@ -38,28 +39,6 @@
"fileName": "export-suppliers-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
<thead>
<tr>
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('admin/suppliers/table.id') }}</th>
<th data-formatter="imageFormatter" data-sortable="true" data-field="image" data-visible="false" data-searchable="false">{{ trans('general.image') }}</th>
<th data-sortable="true" data-field="name" data-formatter="suppliersLinkFormatter">{{ trans('admin/suppliers/table.name') }}</th>
<th data-sortable="true" data-field="address">{{ trans('admin/suppliers/table.address') }}</th>
<th data-searchable="true" data-sortable="true" data-field="contact">{{ trans('admin/suppliers/table.contact') }}</th>
<th data-searchable="true" data-sortable="true" data-field="email" data-formatter="emailFormatter">{{ trans('admin/suppliers/table.email') }}</th>
<th data-searchable="true" data-sortable="true" data-field="phone" data-formatter="phoneFormatter">{{ trans('admin/suppliers/table.phone') }}</th>
<th data-searchable="true" data-sortable="true" data-field="fax" data-visible="false">{{ trans('admin/suppliers/table.fax') }}</th>
<th data-sortable="true" data-field="url" data-visible="false" data-formatter="externalLinkFormatter">{{ trans('general.url') }}</th>
<th data-searchable="false" data-sortable="true" data-field="assets_count">{{ trans('admin/suppliers/table.assets') }}</th>
<th data-searchable="false" data-sortable="true" data-field="accessories_count">{{ trans('general.accessories') }}</th>
<th data-searchable="false" data-sortable="true" data-field="licenses_count">{{ trans('admin/suppliers/table.licenses') }}</th>
<th data-searchable="false" data-sortable="true" data-field="components_count">{{ trans('general.components') }}</th>
<th data-searchable="false" data-sortable="true" data-field="consumables_count">{{ trans('general.consumables') }}</th>
<th data-searchable="true" data-sortable="true" data-field="notes">{{ trans('general.notes') }}</th>
<th data-searchable="true" data-sortable="true" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.created_at') }}</th>
<th data-searchable="true" data-sortable="true" data-field="created_by" data-formatter="usersLinkObjFormatter">{{ trans('general.created_by') }}</th>
<th data-switchable="false" data-formatter="suppliersActionsFormatter" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr>
</thead>
</table>
</div>
</div>