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,11 +227,18 @@ 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,11 +200,18 @@ 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();
|
||||
|
||||
@@ -82,6 +82,21 @@ class TransferOrderController extends Controller
|
||||
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')) {
|
||||
$this->transferService->updateItems($order, [[
|
||||
@@ -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) {
|
||||
|
||||
@@ -131,6 +131,18 @@ const fieldLabels: Record<string, string> = {
|
||||
recipe_id: '生產配方',
|
||||
recipe_name: '配方名稱',
|
||||
yield_quantity: '預期產量',
|
||||
// 庫存單據通用欄位
|
||||
doc_no: '單據編號',
|
||||
snapshot_date: '快照日期',
|
||||
completed_at: '完成日期',
|
||||
posted_at: '過帳日期',
|
||||
from_warehouse_id: '來源倉庫',
|
||||
from_warehouse_name: '來源倉庫名稱',
|
||||
to_warehouse_id: '目的地倉庫',
|
||||
to_warehouse_name: '目的地倉庫名稱',
|
||||
reason: '原因',
|
||||
count_doc_id: '盤點單 ID',
|
||||
count_doc_no: '盤點單號',
|
||||
};
|
||||
|
||||
// 狀態翻譯對照表
|
||||
@@ -145,6 +157,9 @@ const statusMap: Record<string, string> = {
|
||||
completed: '已完成',
|
||||
closed: '已結案',
|
||||
partial: '部分收貨',
|
||||
// 庫存單據狀態
|
||||
counting: '盤點中',
|
||||
posted: '已過帳',
|
||||
// 生產工單狀態
|
||||
planned: '已計畫',
|
||||
in_progress: '生產中',
|
||||
|
||||
Reference in New Issue
Block a user