fix(inventory): 修復 Controller 語法錯誤並補齊操作記錄

This commit is contained in:
2026-02-04 13:25:49 +08:00
parent a8b88b3375
commit f4f597e96d
3 changed files with 38 additions and 62 deletions

View File

@@ -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', '盤調單已刪除');
}