feat(production): 優化生產單 BOM 原物料選取邏輯,支援商品 -> 倉庫 -> 批號連動與 API 分佈查詢
This commit is contained in:
@@ -269,6 +269,33 @@ class ProductionOrderController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得商品在各倉庫的庫存分佈
|
||||
*/
|
||||
public function getProductWarehouses($productId)
|
||||
{
|
||||
$inventories = \App\Modules\Inventory\Models\Inventory::with(['warehouse', 'product.baseUnit'])
|
||||
->where('product_id', $productId)
|
||||
->where('quantity', '>', 0)
|
||||
->get();
|
||||
|
||||
$data = $inventories->map(function ($inv) {
|
||||
return [
|
||||
'id' => $inv->id, // Inventory ID
|
||||
'warehouse_id' => $inv->warehouse_id,
|
||||
'warehouse_name' => $inv->warehouse->name ?? '未知倉庫',
|
||||
'batch_number' => $inv->batch_number,
|
||||
'quantity' => $inv->quantity,
|
||||
'expiry_date' => $inv->expiry_date ? $inv->expiry_date->format('Y-m-d') : null,
|
||||
'unit_name' => $inv->product->baseUnit->name ?? '',
|
||||
'base_unit_id' => $inv->product->base_unit_id ?? null,
|
||||
'conversion_rate' => $inv->product->conversion_rate ?? 1,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 編輯生產單
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user