feat: 整合門市領料日誌、API 文件存取、修改庫存與併發編號問題、供應商商品內聯編輯及日誌 UI 優化
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 1m0s

This commit is contained in:
2026-03-02 16:42:12 +08:00
parent 7dac2d1f77
commit 0a955fb993
33 changed files with 1424 additions and 853 deletions

View File

@@ -181,11 +181,11 @@ class InventoryService implements InventoryServiceInterface
// 更新其他可能變更的欄位 (如最後入庫日)
$inventory->arrival_date = $data['arrival_date'] ?? $inventory->arrival_date;
$inventory->save();
$inventory->saveQuietly();
} else {
// 若不存在,則建立新紀錄
$unitCost = $data['unit_cost'] ?? 0;
$inventory = Inventory::create([
$inventory = new Inventory([
'warehouse_id' => $data['warehouse_id'],
'product_id' => $data['product_id'],
'quantity' => $data['quantity'],
@@ -199,9 +199,10 @@ class InventoryService implements InventoryServiceInterface
'quality_status' => $data['quality_status'] ?? 'normal',
'source_purchase_order_id' => $data['source_purchase_order_id'] ?? null,
]);
$inventory->saveQuietly();
}
\App\Modules\Inventory\Models\InventoryTransaction::create([
$transaction = new \App\Modules\Inventory\Models\InventoryTransaction([
'inventory_id' => $inventory->id,
'type' => '入庫',
'quantity' => $data['quantity'],
@@ -214,6 +215,7 @@ class InventoryService implements InventoryServiceInterface
'user_id' => auth()->id(),
'actual_time' => now(),
]);
$transaction->saveQuietly();
return $inventory;
});
@@ -225,13 +227,12 @@ class InventoryService implements InventoryServiceInterface
$inventory = Inventory::lockForUpdate()->findOrFail($inventoryId);
$balanceBefore = $inventory->quantity;
$inventory->decrement('quantity', $quantity); // decrement 不會自動觸發 total_value 更新
// 需要手動更新總價值
$inventory->refresh();
// 手動更新以配合 saveQuietly 消除日誌
$inventory->quantity -= $quantity;
$inventory->total_value = $inventory->quantity * $inventory->unit_cost;
$inventory->save();
$inventory->saveQuietly();
\App\Modules\Inventory\Models\InventoryTransaction::create([
$transaction = new \App\Modules\Inventory\Models\InventoryTransaction([
'inventory_id' => $inventory->id,
'type' => '出庫',
'quantity' => -$quantity,
@@ -244,6 +245,7 @@ class InventoryService implements InventoryServiceInterface
'user_id' => auth()->id(),
'actual_time' => now(),
]);
$transaction->saveQuietly();
});
}
@@ -825,7 +827,8 @@ class InventoryService implements InventoryServiceInterface
}
if (abs($changeQty) > 0.0001) {
$inventory->transactions()->create([
$transaction = new \App\Modules\Inventory\Models\InventoryTransaction([
'inventory_id' => $inventory->id,
'type' => $chineseType,
'quantity' => $changeQty,
'unit_cost' => $inventory->unit_cost,
@@ -835,6 +838,7 @@ class InventoryService implements InventoryServiceInterface
'actual_time' => now(),
'user_id' => auth()->id(),
]);
$transaction->saveQuietly();
}
});
}