From f4f597e96dc2511f8e3650892816f1a5208e267d Mon Sep 17 00:00:00 2001 From: sky121113 Date: Wed, 4 Feb 2026 13:25:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(inventory):=20=E4=BF=AE=E5=BE=A9=20Controll?= =?UTF-8?q?er=20=E8=AA=9E=E6=B3=95=E9=8C=AF=E8=AA=A4=E4=B8=A6=E8=A3=9C?= =?UTF-8?q?=E9=BD=8A=E6=93=8D=E4=BD=9C=E8=A8=98=E9=8C=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AdjustDocController.php | 50 ++----------------- .../Controllers/CountDocController.php | 21 ++------ .../Controllers/TransferOrderController.php | 29 +++++++++++ 3 files changed, 38 insertions(+), 62 deletions(-) diff --git a/app/Modules/Inventory/Controllers/AdjustDocController.php b/app/Modules/Inventory/Controllers/AdjustDocController.php index ee9ae2c..2cf59e1 100644 --- a/app/Modules/Inventory/Controllers/AdjustDocController.php +++ b/app/Modules/Inventory/Controllers/AdjustDocController.php @@ -179,54 +179,12 @@ class AdjustDocController extends Controller ]); } - public function update(Request $request, InventoryAdjustDoc $doc) + public function destroy(InventoryAdjustDoc $doc) { if ($doc->status !== 'draft') { - return redirect()->back()->with('error', '只能修改草稿狀態的單據'); + return redirect()->back()->with('error', '只能刪除草稿狀態的單據'); } - // 提交 (items 更新 或 過帳) - if ($request->input('action') === 'post') { - $this->adjustService->post($doc, auth()->id()); - - // 記錄活動 - activity() - ->performedOn($doc) - ->causedBy(auth()->user()) - ->event('posted') - ->withProperties([ - 'attributes' => ['status' => 'posted'], - 'old' => ['status' => 'draft'], - 'snapshot' => [ - 'doc_no' => $doc->doc_no, - 'warehouse_name' => $doc->warehouse?->name, - ] - ]) - ->log('posted'); - - return redirect()->route('inventory.adjust.index') - ->with('success', '盤調單已過帳生效'); - } - - // 僅儲存資料 - $validated = $request->validate([ - 'items' => 'array', - 'items.*.product_id' => 'required|exists:products,id', - 'items.*.adjust_qty' => 'required|numeric', // 可以是負數 - 'items.*.batch_number' => 'nullable|string', - 'items.*.notes' => 'nullable|string', - ]); - - if ($request->has('items')) { - $this->adjustService->updateItems($doc, $validated['items']); - } - - // 更新表頭 - $doc->update($request->only(['reason', 'remarks'])); - - return redirect()->back()->with('success', '儲存成功'); - } - // 記錄活動 activity() ->performedOn($doc) @@ -239,10 +197,10 @@ class AdjustDocController extends Controller ] ]) ->log('deleted'); - + $doc->items()->delete(); $doc->delete(); - + return redirect()->route('inventory.adjust.index') ->with('success', '盤調單已刪除'); } diff --git a/app/Modules/Inventory/Controllers/CountDocController.php b/app/Modules/Inventory/Controllers/CountDocController.php index 266f0e9..a1c2842 100644 --- a/app/Modules/Inventory/Controllers/CountDocController.php +++ b/app/Modules/Inventory/Controllers/CountDocController.php @@ -183,23 +183,12 @@ class CountDocController extends Controller return redirect()->back()->with('success', '暫存成功'); } - public function reopen(InventoryCountDoc $doc) + public function destroy(InventoryCountDoc $doc) { - if ($doc->status !== 'completed') { - return redirect()->back()->with('error', '只有已核准的盤點單可以取消核准'); + if ($doc->status === 'completed') { + return redirect()->back()->with('error', '已完成的盤點單無法刪除'); } - // TODO: Move logic to Service if complex - $doc->update([ - 'status' => 'counting', // Revert to counting (draft) - 'completed_at' => null, - 'completed_by' => null, - ]); - - return redirect()->route('inventory.count.show', [$doc->id]) - ->with('success', '已取消核准,單據回復為盤點中狀態'); - } - // 記錄活動 activity() ->performedOn($doc) @@ -212,10 +201,10 @@ class CountDocController extends Controller ] ]) ->log('deleted'); - + $doc->items()->delete(); $doc->delete(); - + return redirect()->route('inventory.count.index') ->with('success', '盤點單已刪除'); } diff --git a/app/Modules/Inventory/Controllers/TransferOrderController.php b/app/Modules/Inventory/Controllers/TransferOrderController.php index c4e7484..f8c3dd6 100644 --- a/app/Modules/Inventory/Controllers/TransferOrderController.php +++ b/app/Modules/Inventory/Controllers/TransferOrderController.php @@ -226,6 +226,20 @@ class TransferOrderController extends Controller $order->update($request->only(['remarks'])); + // 記錄暫存活動 + activity() + ->performedOn($order) + ->causedBy(auth()->user()) + ->event('updated') + ->withProperties([ + 'snapshot' => [ + 'doc_no' => $order->doc_no, + 'from_warehouse_name' => $order->fromWarehouse?->name, + 'to_warehouse_name' => $order->toWarehouse?->name, + ] + ]) + ->log('updated_items'); + return redirect()->back()->with('success', '儲存成功'); } @@ -234,6 +248,21 @@ class TransferOrderController extends Controller if ($order->status !== 'draft') { return redirect()->back()->with('error', '只能刪除草稿狀態的單據'); } + + // 記錄活動 + activity() + ->performedOn($order) + ->causedBy(auth()->user()) + ->event('deleted') + ->withProperties([ + 'snapshot' => [ + 'doc_no' => $order->doc_no, + 'from_warehouse_name' => $order->fromWarehouse?->name, + 'to_warehouse_name' => $order->toWarehouse?->name, + ] + ]) + ->log('deleted'); + $order->items()->delete(); $order->delete();