feat: 優化操作紀錄顯示與邏輯 (恢復描述欄位、支援來源標記、改進快照)
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 45s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-19 11:47:10 +08:00
parent 74417e2e31
commit 18edb3cb69
10 changed files with 333 additions and 74 deletions

View File

@@ -103,7 +103,8 @@ class InventoryController extends Controller
return \Illuminate\Support\Facades\DB::transaction(function () use ($validated, $warehouse) {
foreach ($validated['items'] as $item) {
// 取得或建立庫存紀錄
$inventory = $warehouse->inventories()->firstOrCreate(
// 取得或初始化庫存紀錄
$inventory = $warehouse->inventories()->firstOrNew(
['product_id' => $item['productId']],
['quantity' => 0, 'safety_stock' => null]
);
@@ -111,8 +112,9 @@ class InventoryController extends Controller
$currentQty = $inventory->quantity;
$newQty = $currentQty + $item['quantity'];
// 更新庫存
$inventory->update(['quantity' => $newQty]);
// 更新庫存並儲存 (新紀錄: Created, 舊紀錄: Updated)
$inventory->quantity = $newQty;
$inventory->save();
// 寫入異動紀錄
$inventory->transactions()->create([