feat(inventory): 強化調撥單功能,支援販賣機貨道欄位、開放商品重複加入及優化過帳庫存檢核
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 59s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-02-09 16:52:35 +08:00
parent 65eb1a1b64
commit 613eb555ba
10 changed files with 745 additions and 175 deletions

View File

@@ -63,6 +63,7 @@ class TransferService
'product_id' => $data['product_id'],
'batch_number' => $data['batch_number'] ?? null,
'quantity' => $data['quantity'],
'position' => $data['position'] ?? null,
'notes' => $data['notes'] ?? null,
]);
// Eager load product for name
@@ -72,17 +73,20 @@ class TransferService
if ($oldItemsMap->has($key)) {
$oldItem = $oldItemsMap->get($key);
// 檢查數值是否有變動
if ((float)$oldItem->quantity !== (float)$data['quantity'] ||
$oldItem->notes !== ($data['notes'] ?? null)) {
if ((float)$oldItem->quantity !== (float)$data['quantity'] ||
$oldItem->notes !== ($data['notes'] ?? null) ||
$oldItem->position !== ($data['position'] ?? null)) {
$diff['updated'][] = [
'product_name' => $item->product->name,
'old' => [
'quantity' => (float)$oldItem->quantity,
'position' => $oldItem->position,
'notes' => $oldItem->notes,
],
'new' => [
'quantity' => (float)$data['quantity'],
'position' => $item->position,
'notes' => $item->notes,
]
];
@@ -148,8 +152,10 @@ class TransferService
->first();
if (!$sourceInventory || $sourceInventory->quantity < $item->quantity) {
$availableQty = $sourceInventory->quantity ?? 0;
$shortageQty = $item->quantity - $availableQty;
throw ValidationException::withMessages([
'items' => ["商品 {$item->product->name} (批號: {$item->batch_number}) 在來源倉庫存不足"],
'items' => ["商品 {$item->product->name} (批號: {$item->batch_number}) 在來源倉庫存不足。現有庫存:{$availableQty},尚欠:{$shortageQty}"],
]);
}
@@ -182,6 +188,7 @@ class TransferService
'warehouse_id' => $order->to_warehouse_id,
'product_id' => $item->product_id,
'batch_number' => $item->batch_number,
'location' => $item->position, // 同步貨道至庫存位置
],
[
'quantity' => 0,