refactor(modular): 完成第二階段儀表板解耦與模型清理
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 1m1s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-27 08:59:45 +08:00
parent ac6a81b3d2
commit 0e51992cb4
13 changed files with 140 additions and 52 deletions

View File

@@ -40,6 +40,11 @@ class InventoryService implements InventoryServiceInterface
return Product::whereIn('id', $ids)->get();
}
public function getProductsByName(string $name)
{
return Product::where('name', 'like', "%{$name}%")->get();
}
public function getWarehouse(int $id)
{
return Warehouse::find($id);
@@ -182,4 +187,24 @@ class InventoryService implements InventoryServiceInterface
]);
});
}
public function getDashboardStats(): array
{
// 庫存總表 join 安全庫存表,計算低庫存
$lowStockCount = DB::table('warehouse_product_safety_stocks as ss')
->join(DB::raw('(SELECT warehouse_id, product_id, SUM(quantity) as total_qty FROM inventories WHERE deleted_at IS NULL GROUP BY warehouse_id, product_id) as inv'),
function ($join) {
$join->on('ss.warehouse_id', '=', 'inv.warehouse_id')
->on('ss.product_id', '=', 'inv.product_id');
})
->whereRaw('inv.total_qty <= ss.safety_stock')
->count();
return [
'productsCount' => Product::count(),
'warehousesCount' => Warehouse::count(),
'lowStockCount' => $lowStockCount,
'totalInventoryQuantity' => Inventory::sum('quantity'),
];
}
}