feat: 優化採購單操作紀錄與統一刪除確認 UI

- 優化採購單更新與刪除的活動紀錄邏輯 (PurchaseOrderController)
  - 整合更新異動為單一紀錄,包含品項差異
  - 刪除時記錄當下品項快照
- 統一採購單刪除確認介面,使用 AlertDialog 取代原生 confirm (PurchaseOrderActions)
- Refactor: 將 ActivityDetailDialog 移至 Components/ActivityLog 並優化樣式與大數據顯示
- 調整 UI 文字:將「總金額」統一為「小計」
- 其他模型與 Controller 的活動紀錄支援更新
This commit is contained in:
2026-01-19 15:32:41 +08:00
parent 18edb3cb69
commit a8091276b8
20 changed files with 1114 additions and 482 deletions

View File

@@ -27,6 +27,25 @@ class VendorProductController extends Controller
'last_price' => $validated['last_price'] ?? null
]);
// 記錄操作
$product = \App\Models\Product::find($validated['product_id']);
activity()
->performedOn($vendor)
->withProperties([
'attributes' => [
'product_name' => $product->name,
'last_price' => $validated['last_price'] ?? null,
],
'sub_subject' => '供貨商品',
'snapshot' => [
'name' => "{$vendor->name}-{$product->name}", // 顯示例如:台積電-紅糖
'vendor_name' => $vendor->name,
'product_name' => $product->name,
]
])
->event('created')
->log('新增供貨商品');
return redirect()->back()->with('success', '供貨商品已新增');
}
@@ -39,10 +58,34 @@ class VendorProductController extends Controller
'last_price' => 'nullable|numeric|min:0',
]);
// 獲取舊價格
$old_price = $vendor->products()->where('product_id', $productId)->first()?->pivot?->last_price;
$vendor->products()->updateExistingPivot($productId, [
'last_price' => $validated['last_price'] ?? null
]);
// 記錄操作
$product = \App\Models\Product::find($productId);
activity()
->performedOn($vendor)
->withProperties([
'old' => [
'last_price' => $old_price,
],
'attributes' => [
'last_price' => $validated['last_price'] ?? null,
],
'sub_subject' => '供貨商品',
'snapshot' => [
'name' => "{$vendor->name}-{$product->name}",
'vendor_name' => $vendor->name,
'product_name' => $product->name,
]
])
->event('updated')
->log('更新供貨商品價格');
return redirect()->back()->with('success', '供貨資訊已更新');
}
@@ -51,8 +94,31 @@ class VendorProductController extends Controller
*/
public function destroy(Vendor $vendor, $productId)
{
// 記錄操作 (需在 detach 前獲取資訊)
$product = \App\Models\Product::find($productId);
$old_price = $vendor->products()->where('product_id', $productId)->first()?->pivot?->last_price;
$vendor->products()->detach($productId);
if ($product) {
activity()
->performedOn($vendor)
->withProperties([
'old' => [
'product_name' => $product->name,
'last_price' => $old_price,
],
'sub_subject' => '供貨商品',
'snapshot' => [
'name' => "{$vendor->name}-{$product->name}",
'vendor_name' => $vendor->name,
'product_name' => $product->name,
]
])
->event('deleted')
->log('移除供貨商品');
}
return redirect()->back()->with('success', '供貨商品已移除');
}
}