[FIX] 補貨單完成邏輯與機台庫存去耦,防範重複累加 Bug
1. 移除補貨單狀態進入已完成 (STATUS_COMPLETED) 時自動對機台貨道庫存進行累加的舊邏輯。 2. 移除伴隨上述更新所產生的機台補貨流水帳紀錄 (MachineStockMovement)。 3. 使機台實體庫存回歸以機台端上報 (B009/B018) 及手動貨道校正為唯一事實來源,防範因先上報後結案產生的重複累加及時間差空轉售罄客訴風險。
This commit is contained in:
parent
964c62efb6
commit
f34a7bf9bc
@ -1126,36 +1126,8 @@ class WarehouseController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delivering → completed:增加機台貨道庫存並記錄異動
|
// delivering → completed:更新完成時間(去耦機台庫存累加,由機台端上報決定)
|
||||||
if ($newStatus === ReplenishmentOrder::STATUS_COMPLETED) {
|
if ($newStatus === ReplenishmentOrder::STATUS_COMPLETED) {
|
||||||
foreach ($replenishmentOrder->items as $item) {
|
|
||||||
$slot = MachineSlot::where('machine_id', $replenishmentOrder->machine_id)
|
|
||||||
->where('slot_no', $item->slot_no)
|
|
||||||
->lockForUpdate()
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($slot) {
|
|
||||||
$beforeQty = $slot->stock;
|
|
||||||
$slot->increment('stock', $item->quantity);
|
|
||||||
$slot->refresh();
|
|
||||||
|
|
||||||
MachineStockMovement::create([
|
|
||||||
'company_id' => $replenishmentOrder->company_id,
|
|
||||||
'machine_id' => $replenishmentOrder->machine_id,
|
|
||||||
'product_id' => $item->product_id,
|
|
||||||
'slot_no' => $item->slot_no,
|
|
||||||
'type' => MachineStockMovement::TYPE_REPLENISHMENT,
|
|
||||||
'quantity' => $item->quantity,
|
|
||||||
'before_qty' => $beforeQty,
|
|
||||||
'after_qty' => $slot->stock,
|
|
||||||
'reference_type' => ReplenishmentOrder::class,
|
|
||||||
'reference_id' => $replenishmentOrder->id,
|
|
||||||
'note' => '補貨單完成入庫 #' . $replenishmentOrder->order_no,
|
|
||||||
'created_by' => Auth::id(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$replenishmentOrder->completed_at = now();
|
$replenishmentOrder->completed_at = now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user