[FIX] 修正採購單大單位換算問題並建立 Git 開發規範
All checks were successful
ERP-Deploy-Production / deploy-production (push) Successful in 1m19s

This commit is contained in:
2026-03-05 08:46:26 +08:00
parent f543b98d0f
commit a898873211
6 changed files with 178 additions and 22 deletions

View File

@@ -162,19 +162,25 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
}, [isNonStandard, selectedVendor]);
// 選擇採購單
const handleSelectPO = (po: PendingPO) => {
const handleSelectPO = (po: any) => {
setSelectedPO(po);
// 將採購單項目轉換為進貨單項目,預填剩餘可收貨量
const pendingItems = po.items.map((item) => ({
product_id: item.product_id,
const pendingItems = po.items.map((item: any) => ({
product_id: item.productId,
purchase_order_item_id: item.id,
product_name: item.product_name,
product_code: item.product_code,
unit: item.unit,
product_name: item.productName,
product_code: item.product_code || '',
unit: item.selectedUnit === 'large' ? item.large_unit_name : item.base_unit_name,
selectedUnit: item.selectedUnit,
base_unit_id: item.base_unit_id,
base_unit_name: item.base_unit_name,
large_unit_id: item.large_unit_id,
large_unit_name: item.large_unit_name,
conversion_rate: item.conversion_rate,
quantity_ordered: item.quantity,
quantity_received_so_far: item.received_quantity,
quantity_received: item.remaining, // 預填剩餘量
unit_price: item.unit_price,
quantity_received_so_far: item.received_quantity || 0,
quantity_received: (item.quantity - (item.received_quantity || 0)).toString(), // 預填剩餘量
unit_price: item.unitPrice,
batch_number: '',
batchMode: 'new',
originCountry: 'TW',
@@ -184,7 +190,7 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
setData((prev) => ({
...prev,
purchase_order_id: po.id.toString(),
vendor_id: po.vendor_id.toString(),
vendor_id: po.supplierId.toString(),
warehouse_id: po.warehouse_id ? po.warehouse_id.toString() : prev.warehouse_id,
items: pendingItems,
}));
@@ -777,14 +783,21 @@ export default function GoodsReceiptCreate({ warehouses, pendingPurchaseOrders,
{/* Received Quantity */}
<TableCell>
<Input
type="number"
step="any"
min="0"
value={item.quantity_received}
onChange={(e) => updateItem(index, 'quantity_received', e.target.value)}
className={`w-full text-right ${errors && (errors as any)[errorKey] ? 'border-red-500' : ''}`}
/>
<div className="flex flex-col gap-1">
<Input
type="number"
step="any"
min="0"
value={item.quantity_received}
onChange={(e) => updateItem(index, 'quantity_received', e.target.value)}
className={`w-full text-right ${errors && (errors as any)[errorKey] ? 'border-red-500' : ''}`}
/>
{item.selectedUnit === 'large' && item.conversion_rate > 1 && (
<div className="text-[10px] text-primary-main text-right font-medium">
= {(parseFloat(item.quantity_received) * item.conversion_rate).toLocaleString()} {item.base_unit_name}
</div>
)}
</div>
{(errors as any)[errorKey] && (
<p className="text-xs text-red-500 mt-1">{(errors as any)[errorKey]}</p>
)}