[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

@@ -266,10 +266,24 @@ class GoodsReceiptService implements \App\Modules\Inventory\Contracts\GoodsRecei
default => '進貨入庫',
};
$quantityToRecord = $grItem->quantity_received;
// 單位換算邏輯:僅針對標準採購且有連結 PO Item 時
if ($goodsReceipt->type === 'standard' && $grItem->purchase_order_item_id) {
$poItem = \App\Modules\Procurement\Models\PurchaseOrderItem::find($grItem->purchase_order_item_id);
$product = $this->inventoryService->getProduct($grItem->product_id);
if ($poItem && $product && $poItem->unit_id && $product->large_unit_id && $poItem->unit_id == $product->large_unit_id) {
// 如果使用的是大單位,則換算為基本單位數量
$quantityToRecord = $grItem->quantity_received * ($product->conversion_rate ?: 1);
Log::info("Goods Receipt [{$goodsReceipt->code}] converted quantity for product [{$product->id}]: {$grItem->quantity_received} large unit -> {$quantityToRecord} base unit.");
}
}
$this->inventoryService->createInventoryRecord([
'warehouse_id' => $goodsReceipt->warehouse_id,
'product_id' => $grItem->product_id,
'quantity' => $grItem->quantity_received,
'quantity' => $quantityToRecord,
'unit_cost' => $grItem->unit_price,
'batch_number' => $grItem->batch_number,
'expiry_date' => $grItem->expiry_date,
@@ -282,6 +296,7 @@ class GoodsReceiptService implements \App\Modules\Inventory\Contracts\GoodsRecei
// 2. Update PO if linked and type is standard
if ($goodsReceipt->type === 'standard' && $goodsReceipt->purchase_order_id && $grItem->purchase_order_item_id) {
// 更新採購單的實收數量 (維持原始單位數量,以便與採購數量比較)
$this->procurementService->updateReceivedQuantity(
$grItem->purchase_order_item_id,
$grItem->quantity_received