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

@@ -33,6 +33,8 @@ class ActivityLogController extends Controller
'App\Models\Category' => '商品分類',
'App\Models\Unit' => '單位',
'App\Models\PurchaseOrder' => '採購單',
'App\Models\Warehouse' => '倉庫',
'App\Models\Inventory' => '庫存',
];
$eventMap = [

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([

View File

@@ -56,6 +56,9 @@ class TransferOrderController extends Controller
// 3. 執行庫存轉移 (扣除來源)
$oldSourceQty = $sourceInventory->quantity;
$newSourceQty = $oldSourceQty - $validated['quantity'];
// 設定活動紀錄原因
$sourceInventory->activityLogReason = "撥補出庫 至 {$targetWarehouse->name}";
$sourceInventory->update(['quantity' => $newSourceQty]);
// 記錄來源異動
@@ -72,6 +75,9 @@ class TransferOrderController extends Controller
// 4. 執行庫存轉移 (增加目標)
$oldTargetQty = $targetInventory->quantity;
$newTargetQty = $oldTargetQty + $validated['quantity'];
// 設定活動紀錄原因
$targetInventory->activityLogReason = "撥補入庫 來自 {$sourceWarehouse->name}";
$targetInventory->update(['quantity' => $newTargetQty]);
// 記錄目標異動