feat(inventory): 實作盤點、盤調與調撥操作紀錄,並支援前端本地化顯示
This commit is contained in:
@@ -76,6 +76,22 @@ class AdjustDocController extends Controller
|
||||
}
|
||||
|
||||
$doc = $this->adjustService->createFromCountDoc($countDoc, auth()->id());
|
||||
|
||||
// 記錄活動
|
||||
activity()
|
||||
->performedOn($doc)
|
||||
->causedBy(auth()->user())
|
||||
->event('created')
|
||||
->withProperties([
|
||||
'attributes' => $doc->toArray(),
|
||||
'snapshot' => [
|
||||
'doc_no' => $doc->doc_no,
|
||||
'warehouse_name' => $doc->warehouse?->name,
|
||||
'count_doc_no' => $countDoc->doc_no,
|
||||
]
|
||||
])
|
||||
->log('created_from_count');
|
||||
|
||||
return redirect()->route('inventory.adjust.show', [$doc->id])
|
||||
->with('success', '已從盤點單生成盤調單');
|
||||
}
|
||||
@@ -172,6 +188,22 @@ class AdjustDocController extends Controller
|
||||
// 提交 (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', '盤調單已過帳生效');
|
||||
}
|
||||
@@ -195,12 +227,19 @@ class AdjustDocController extends Controller
|
||||
return redirect()->back()->with('success', '儲存成功');
|
||||
}
|
||||
|
||||
public function destroy(InventoryAdjustDoc $doc)
|
||||
{
|
||||
if ($doc->status !== 'draft') {
|
||||
return redirect()->back()->with('error', '只能刪除草稿狀態的單據');
|
||||
}
|
||||
|
||||
// 記錄活動
|
||||
activity()
|
||||
->performedOn($doc)
|
||||
->causedBy(auth()->user())
|
||||
->event('deleted')
|
||||
->withProperties([
|
||||
'snapshot' => [
|
||||
'doc_no' => $doc->doc_no,
|
||||
'warehouse_name' => $doc->warehouse?->name,
|
||||
]
|
||||
])
|
||||
->log('deleted');
|
||||
|
||||
$doc->items()->delete();
|
||||
$doc->delete();
|
||||
|
||||
|
||||
@@ -200,12 +200,19 @@ class CountDocController extends Controller
|
||||
->with('success', '已取消核准,單據回復為盤點中狀態');
|
||||
}
|
||||
|
||||
public function destroy(InventoryCountDoc $doc)
|
||||
{
|
||||
if ($doc->status === 'completed') {
|
||||
return redirect()->back()->with('error', '已完成的盤點單無法刪除');
|
||||
}
|
||||
|
||||
// 記錄活動
|
||||
activity()
|
||||
->performedOn($doc)
|
||||
->causedBy(auth()->user())
|
||||
->event('deleted')
|
||||
->withProperties([
|
||||
'snapshot' => [
|
||||
'doc_no' => $doc->doc_no,
|
||||
'warehouse_name' => $doc->warehouse?->name,
|
||||
]
|
||||
])
|
||||
->log('deleted');
|
||||
|
||||
$doc->items()->delete();
|
||||
$doc->delete();
|
||||
|
||||
|
||||
@@ -81,6 +81,21 @@ class TransferOrderController extends Controller
|
||||
$remarks,
|
||||
auth()->id()
|
||||
);
|
||||
|
||||
// 記錄活動
|
||||
activity()
|
||||
->performedOn($order)
|
||||
->causedBy(auth()->user())
|
||||
->event('created')
|
||||
->withProperties([
|
||||
'attributes' => $order->toArray(),
|
||||
'snapshot' => [
|
||||
'doc_no' => $order->doc_no,
|
||||
'from_warehouse_name' => $order->fromWarehouse?->name,
|
||||
'to_warehouse_name' => $order->toWarehouse?->name,
|
||||
]
|
||||
])
|
||||
->log('created');
|
||||
|
||||
// 如果請求包含單筆商品資訊
|
||||
if ($request->has('product_id')) {
|
||||
@@ -95,6 +110,23 @@ class TransferOrderController extends Controller
|
||||
if ($request->input('instant_post') === true) {
|
||||
try {
|
||||
$this->transferService->post($order, auth()->id());
|
||||
|
||||
// 記錄過帳活動
|
||||
activity()
|
||||
->performedOn($order)
|
||||
->causedBy(auth()->user())
|
||||
->event('posted')
|
||||
->withProperties([
|
||||
'attributes' => ['status' => 'posted'],
|
||||
'old' => ['status' => 'draft'],
|
||||
'snapshot' => [
|
||||
'doc_no' => $order->doc_no,
|
||||
'from_warehouse_name' => $order->fromWarehouse?->name,
|
||||
'to_warehouse_name' => $order->toWarehouse?->name,
|
||||
]
|
||||
])
|
||||
->log('posted');
|
||||
|
||||
return redirect()->back()->with('success', '撥補成功,庫存已更新');
|
||||
} catch (\Exception $e) {
|
||||
// 如果過帳失敗,雖然單據已建立,但應回報錯誤
|
||||
@@ -156,6 +188,23 @@ class TransferOrderController extends Controller
|
||||
if ($request->input('action') === 'post') {
|
||||
try {
|
||||
$this->transferService->post($order, auth()->id());
|
||||
|
||||
// 記錄活動
|
||||
activity()
|
||||
->performedOn($order)
|
||||
->causedBy(auth()->user())
|
||||
->event('posted')
|
||||
->withProperties([
|
||||
'attributes' => ['status' => 'posted'],
|
||||
'old' => ['status' => 'draft'],
|
||||
'snapshot' => [
|
||||
'doc_no' => $order->doc_no,
|
||||
'from_warehouse_name' => $order->fromWarehouse?->name,
|
||||
'to_warehouse_name' => $order->toWarehouse?->name,
|
||||
]
|
||||
])
|
||||
->log('posted');
|
||||
|
||||
return redirect()->route('inventory.transfer.index')
|
||||
->with('success', '調撥單已過帳完成');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user