Added created_by

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-19 17:01:48 +01:00
parent 6699995972
commit 02a29c71ef
6 changed files with 25 additions and 2 deletions

View file

@ -97,6 +97,9 @@ class AssetMaintenancesController extends Controller
case 'status_label':
$maintenances = $maintenances->OrderStatusName($order);
break;
case 'created_by':
$maintenances = $maintenances->OrderByCreatedBy($order);
break;
default:
$maintenances = $maintenances->orderBy($sort, $order);
break;

View file

@ -92,6 +92,9 @@ class ConsumablesController extends Controller
case 'supplier':
$consumables = $consumables->OrderSupplier($order);
break;
case 'created_by':
$consumables = $consumables->OrderByCreatedBy($order);
break;
default:
// This array is what determines which fields should be allowed to be sorted on ON the table itself.
// These must match a column on the consumables table directly.

View file

@ -117,7 +117,7 @@ class LicensesController extends Controller
$licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
break;
case 'created_by':
$licenses = $licenses->OrderCreatedBy($order);
$licenses = $licenses->OrderByCreatedBy($order);
break;
default:
$allowed_columns =

View file

@ -65,6 +65,10 @@ class AssetMaintenancesTransformer
'asset_maintenance_time' => $assetmaintenance->asset_maintenance_time,
'completion_date' => Helper::getFormattedDateObject($assetmaintenance->completion_date, 'date'),
'user_id' => ($assetmaintenance->admin) ? ['id' => $assetmaintenance->admin->id, 'name'=> e($assetmaintenance->admin->getFullNameAttribute())] : null,
'created_by' => ($assetmaintenance->adminuser) ? [
'id' => (int) $assetmaintenance->adminuser->id,
'name'=> e($assetmaintenance->adminuser->present()->fullName()),
] : null,
'created_at' => Helper::getFormattedDateObject($assetmaintenance->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->updated_at, 'datetime'),
'is_warranty'=> $assetmaintenance->is_warranty,

View file

@ -174,7 +174,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
* @author A. Gianotto <snipe@snipe.net>
* @version v3.0
*/
public function admin()
public function adminuser()
{
return $this->belongsTo(\App\Models\User::class, 'user_id')
->withTrashed();
@ -278,4 +278,12 @@ class AssetMaintenance extends Model implements ICompanyableChild
->leftjoin('status_labels as maintained_asset_status', 'maintained_asset_status.id', '=', 'maintained_asset.status_id')
->orderBy('maintained_asset_status.name', $order);
}
/**
* Query builder scope to order on the user that created it
*/
public function scopeOrderByCreatedBy($query, $order)
{
return $query->leftJoin('users as admin_sort', 'asset_maintenances.created_by', '=', 'admin_sort.id')->select('asset_maintenances.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
}

View file

@ -451,4 +451,9 @@ class Consumable extends SnipeModel
{
return $query->leftJoin('suppliers', 'consumables.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order);
}
public function scopeOrderByCreatedBy($query, $order)
{
return $query->leftJoin('users as users_sort', 'consumables.created_by', '=', 'users_sort.id')->select('consumables.*')->orderBy('users_sort.first_name', $order)->orderBy('users_sort.last_name', $order);
}
}