feat: API調整訂單與販賣機訂單同步強制使用warehouse_code,更新API對接文件,及優化生產與配方模組UI顯示
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 55s
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 55s
This commit is contained in:
@@ -67,21 +67,46 @@ class ProductionOrderController extends Controller
|
||||
if (!in_array((int)$perPage, [10, 20, 50, 100])) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
$productionOrders = $query->paginate($perPage)->withQueryString();
|
||||
$productionOrders = $query->with('items')->paginate($perPage)->withQueryString();
|
||||
|
||||
// --- 手動資料水和 (Manual Hydration) ---
|
||||
$productIds = $productionOrders->pluck('product_id')->unique()->filter()->toArray();
|
||||
$warehouseIds = $productionOrders->pluck('warehouse_id')->unique()->filter()->toArray();
|
||||
$userIds = $productionOrders->pluck('user_id')->unique()->filter()->toArray();
|
||||
$productIds = collect();
|
||||
$warehouseIds = collect();
|
||||
$userIds = collect();
|
||||
$inventoryIds = collect();
|
||||
|
||||
$products = $this->inventoryService->getProductsByIds($productIds)->keyBy('id');
|
||||
$warehouses = $this->inventoryService->getAllWarehouses()->whereIn('id', $warehouseIds)->keyBy('id');
|
||||
$users = $this->coreService->getUsersByIds($userIds)->keyBy('id');
|
||||
foreach ($productionOrders as $order) {
|
||||
$productIds->push($order->product_id);
|
||||
$warehouseIds->push($order->warehouse_id);
|
||||
$userIds->push($order->user_id);
|
||||
if ($order->items) {
|
||||
$inventoryIds = $inventoryIds->merge($order->items->pluck('inventory_id'));
|
||||
}
|
||||
}
|
||||
|
||||
$productionOrders->getCollection()->transform(function ($order) use ($products, $warehouses, $users) {
|
||||
$products = $this->inventoryService->getProductsByIds($productIds->unique()->filter()->toArray())->keyBy('id');
|
||||
$warehouses = $this->inventoryService->getAllWarehouses()->whereIn('id', $warehouseIds->unique()->filter()->toArray())->keyBy('id');
|
||||
$users = $this->coreService->getUsersByIds($userIds->unique()->filter()->toArray())->keyBy('id');
|
||||
$inventories = $this->inventoryService->getInventoriesByIds($inventoryIds->unique()->filter()->toArray())->keyBy('id');
|
||||
|
||||
$productionOrders->getCollection()->transform(function ($order) use ($products, $warehouses, $users, $inventories) {
|
||||
$order->product = $products->get($order->product_id);
|
||||
$order->warehouse = $warehouses->get($order->warehouse_id);
|
||||
$order->user = $users->get($order->user_id);
|
||||
|
||||
$totalCost = 0;
|
||||
if ($order->items) {
|
||||
foreach ($order->items as $item) {
|
||||
$inventory = $inventories->get($item->inventory_id);
|
||||
if ($inventory) {
|
||||
$totalCost += $item->quantity_used * ($inventory->unit_cost ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
$order->estimated_total_cost = $totalCost;
|
||||
$order->estimated_unit_cost = $order->output_quantity > 0 ? $totalCost / $order->output_quantity : 0;
|
||||
unset($order->items);
|
||||
|
||||
return $order;
|
||||
});
|
||||
|
||||
@@ -231,7 +256,9 @@ class ProductionOrderController extends Controller
|
||||
'unit_name' => $inv->product->baseUnit->name ?? '',
|
||||
'base_unit_id' => $inv->product->base_unit_id ?? null,
|
||||
'large_unit_id' => $inv->product->large_unit_id ?? null,
|
||||
'purchase_unit_id' => $inv->product->purchase_unit_id ?? null,
|
||||
'conversion_rate' => $inv->product->conversion_rate ?? 1,
|
||||
'unit_cost' => (float) $inv->unit_cost,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -258,7 +285,10 @@ class ProductionOrderController extends Controller
|
||||
'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,
|
||||
'large_unit_id' => $inv->product->large_unit_id ?? null,
|
||||
'purchase_unit_id' => $inv->product->purchase_unit_id ?? null,
|
||||
'conversion_rate' => $inv->product->conversion_rate ?? 1,
|
||||
'unit_cost' => (float) $inv->unit_cost,
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user