feat: change default machine inventory sorting to stock fill rate (ascending)
This commit is contained in:
parent
053c41d642
commit
f06353d542
@ -573,7 +573,8 @@ class WarehouseController extends Controller
|
||||
{
|
||||
$query = Machine::with(['slots' => fn($q) => $q->with('product:id,name,image_url')->orderByRaw('CAST(slot_no AS UNSIGNED) ASC')])
|
||||
->withCount('slots as total_slots')
|
||||
->withSum('slots as total_stock', 'stock');
|
||||
->withSum('slots as total_stock', 'stock')
|
||||
->withSum('slots as total_capacity', 'max_stock');
|
||||
|
||||
if ($search = $request->input('search')) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
@ -582,7 +583,9 @@ class WarehouseController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$machines = $query->orderBy('name')
|
||||
// 預設按庫存率由低到高排序 (補貨優先),在庫存率相同時再按名稱排序
|
||||
$machines = $query->orderByRaw('CASE WHEN total_capacity > 0 THEN (total_stock / total_capacity) ELSE 1 END ASC')
|
||||
->orderBy('name')
|
||||
->paginate($request->input('per_page', 10))
|
||||
->withQueryString();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user