[FIX] 修正採購單大單位換算問題並建立 Git 開發規範
All checks were successful
ERP-Deploy-Production / deploy-production (push) Successful in 1m19s
All checks were successful
ERP-Deploy-Production / deploy-production (push) Successful in 1m19s
This commit is contained in:
@@ -133,6 +133,7 @@ class GoodsReceiptController extends Controller
|
||||
'id' => $po->id,
|
||||
'code' => $po->code,
|
||||
'status' => $po->status,
|
||||
'supplierId' => $po->vendor_id, // Alias for frontend
|
||||
'vendor_id' => $po->vendor_id,
|
||||
'vendor_name' => $po->vendor?->name ?? '',
|
||||
'warehouse_id' => $po->warehouse_id,
|
||||
@@ -140,15 +141,35 @@ class GoodsReceiptController extends Controller
|
||||
'items' => $po->items->map(function ($item) use ($products) {
|
||||
$product = $products->get($item->product_id);
|
||||
$remaining = max(0, $item->quantity - ($item->received_quantity ?? 0));
|
||||
|
||||
// 獲取單位名稱
|
||||
$baseUnitName = $product?->baseUnit?->name ?? '個';
|
||||
$largeUnitName = $product?->largeUnit?->name ?? '';
|
||||
|
||||
// 判斷當前採購使用的單位 (這需要從 PurchaseOrderItem 獲取 unit_id 並與產品的 large_unit_id 比較)
|
||||
$selectedUnit = 'base';
|
||||
if ($item->unit_id && $product && $item->unit_id == $product->large_unit_id) {
|
||||
$selectedUnit = 'large';
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'productId' => $item->product_id, // Alias for frontend
|
||||
'product_id' => $item->product_id,
|
||||
'productName' => $product?->name ?? '', // Alias for frontend
|
||||
'product_name' => $product?->name ?? '',
|
||||
'product_code' => $product?->code ?? '',
|
||||
'unit' => $product?->baseUnit?->name ?? '個',
|
||||
'unit' => $product?->baseUnit?->name ?? '個', // 預設顯示文字
|
||||
'selectedUnit' => $selectedUnit,
|
||||
'base_unit_id' => $product?->base_unit_id,
|
||||
'base_unit_name' => $baseUnitName,
|
||||
'large_unit_id' => $product?->large_unit_id,
|
||||
'large_unit_name' => $largeUnitName,
|
||||
'conversion_rate' => $product?->conversion_rate ?? 1,
|
||||
'quantity' => $item->quantity,
|
||||
'received_quantity' => $item->received_quantity ?? 0,
|
||||
'remaining' => $remaining,
|
||||
'unitPrice' => $item->unit_price, // Alias for frontend
|
||||
'unit_price' => $item->unit_price,
|
||||
];
|
||||
})->filter(fn($item) => $item['remaining'] > 0)->values(),
|
||||
@@ -209,12 +230,24 @@ class GoodsReceiptController extends Controller
|
||||
$product = $products->get($item->product_id);
|
||||
$poItem = $poItems->get($item->purchase_order_item_id);
|
||||
|
||||
// 判斷單位
|
||||
$selectedUnit = 'base';
|
||||
if ($poItem && $product && $poItem->unit_id && $poItem->unit_id == $product->large_unit_id) {
|
||||
$selectedUnit = 'large';
|
||||
}
|
||||
|
||||
return [
|
||||
'product_id' => $item->product_id,
|
||||
'purchase_order_item_id' => $item->purchase_order_item_id,
|
||||
'product_name' => $product?->name ?? '',
|
||||
'product_code' => $product?->code ?? '',
|
||||
'unit' => $product?->baseUnit?->name ?? '個',
|
||||
'unit' => $poItem && $selectedUnit === 'large' ? ($product?->largeUnit?->name ?? '') : ($product?->baseUnit?->name ?? '個'),
|
||||
'selectedUnit' => $selectedUnit,
|
||||
'base_unit_id' => $product?->base_unit_id,
|
||||
'base_unit_name' => $product?->baseUnit?->name ?? '個',
|
||||
'large_unit_id' => $product?->large_unit_id,
|
||||
'large_unit_name' => $product?->largeUnit?->name ?? '',
|
||||
'conversion_rate' => $product?->conversion_rate ?? 1,
|
||||
'quantity_ordered' => $poItem ? $poItem->quantity : null,
|
||||
'quantity_received_so_far' => $poItem ? ($poItem->received_quantity ?? 0) : null,
|
||||
'quantity_received' => (float) $item->quantity_received,
|
||||
@@ -237,6 +270,7 @@ class GoodsReceiptController extends Controller
|
||||
'id' => $po->id,
|
||||
'code' => $po->code,
|
||||
'status' => $po->status,
|
||||
'supplierId' => $po->vendor_id,
|
||||
'vendor_id' => $po->vendor_id,
|
||||
'vendor_name' => $po->vendor?->name ?? '',
|
||||
'warehouse_id' => $po->warehouse_id,
|
||||
@@ -244,15 +278,30 @@ class GoodsReceiptController extends Controller
|
||||
'items' => $po->items->map(function ($item) use ($productsForPOs) {
|
||||
$product = $productsForPOs->get($item->product_id);
|
||||
$remaining = max(0, $item->quantity - ($item->received_quantity ?? 0));
|
||||
|
||||
$selectedUnit = 'base';
|
||||
if ($item->unit_id && $product && $item->unit_id == $product->large_unit_id) {
|
||||
$selectedUnit = 'large';
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'productId' => $item->product_id,
|
||||
'product_id' => $item->product_id,
|
||||
'productName' => $product?->name ?? '',
|
||||
'product_name' => $product?->name ?? '',
|
||||
'product_code' => $product?->code ?? '',
|
||||
'unit' => $product?->baseUnit?->name ?? '個',
|
||||
'unit' => $item->unit_id && $product && $item->unit_id == $product->large_unit_id ? ($product?->largeUnit?->name ?? '') : ($product?->baseUnit?->name ?? '個'),
|
||||
'selectedUnit' => $selectedUnit,
|
||||
'base_unit_id' => $product?->base_unit_id,
|
||||
'base_unit_name' => $product?->baseUnit?->name ?? '個',
|
||||
'large_unit_id' => $product?->large_unit_id,
|
||||
'large_unit_name' => $product?->largeUnit?->name ?? '',
|
||||
'conversion_rate' => $product?->conversion_rate ?? 1,
|
||||
'quantity' => $item->quantity,
|
||||
'received_quantity' => $item->received_quantity ?? 0,
|
||||
'remaining' => $remaining,
|
||||
'unitPrice' => $item->unit_price,
|
||||
'unit_price' => $item->unit_price,
|
||||
];
|
||||
})->filter(fn($item) => $item['remaining'] > 0)->values(),
|
||||
|
||||
Reference in New Issue
Block a user