update material index
This commit is contained in:
@@ -10,6 +10,60 @@ use DB;
|
||||
|
||||
class MaterialService
|
||||
{
|
||||
public function list(array $filters = [])
|
||||
{
|
||||
$serialized = TechnicianMaterial::query()
|
||||
->select([
|
||||
'id',
|
||||
'user_id',
|
||||
'barcode_id',
|
||||
'inventory_item_id',
|
||||
'material_name',
|
||||
'serial_number',
|
||||
'status',
|
||||
'assigned_at',
|
||||
'assigned_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
DB::raw('NULL as unit'),
|
||||
DB::raw('NULL as qty_received'),
|
||||
DB::raw('NULL as qty_used'),
|
||||
DB::raw('NULL as qty_remaining'),
|
||||
DB::raw("'serialized' as type"),
|
||||
]);
|
||||
|
||||
$consumable = TechnicianConsumable::query()
|
||||
->select([
|
||||
'id',
|
||||
'user_id',
|
||||
'barcode_id',
|
||||
'inventory_item_id',
|
||||
'material_name',
|
||||
DB::raw('NULL as serial_number'),
|
||||
'status',
|
||||
'assigned_at',
|
||||
'assigned_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'unit',
|
||||
'qty_received',
|
||||
'qty_used',
|
||||
'qty_remaining',
|
||||
DB::raw("'consumable' as type"),
|
||||
]);
|
||||
|
||||
if (!empty($filters['user_id'])) {
|
||||
$serialized->where('user_id', $filters['user_id']);
|
||||
$consumable->where('user_id', $filters['user_id']);
|
||||
}
|
||||
|
||||
$query = $serialized->unionAll($consumable);
|
||||
|
||||
return DB::query()
|
||||
->fromSub($query, 'materials')
|
||||
->orderByDesc('created_at')
|
||||
->paginate($filters['per_page'] ?? 15);
|
||||
}
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ASSIGN MATERIAL (AUTO DETECT TYPE)
|
||||
|
||||
Reference in New Issue
Block a user