feat(inventory): 完善庫存盤調更新與日誌邏輯,新增「無需盤調」狀態判定
1. 修正 AdjustDocController 缺失 update 方法導致的錯誤。 2. 修正 ActivityDetailDialog 前端 map 渲染 undefined 的 TypeError。 3. 優化盤調單「過帳」日誌,現在會同步包含當時的商品明細快照。 4. 實作盤點單「無需盤調」(no_adjust) 自動判定邏輯: - 當盤點數量與庫存完全一致時,自動標記為 no_adjust 結案。 - 更新前端標籤樣式與操作按鈕對應邏輯。 - 限制 no_adjust 單據不可重複建立盤調單。 5. 統一盤點單與盤調單的日誌配置,優化 ID 轉名稱顯示。
This commit is contained in:
@@ -146,7 +146,9 @@ const fieldLabels: Record<string, string> = {
|
||||
created_by: '建立者',
|
||||
updated_by: '更新者',
|
||||
completed_by: '完成者',
|
||||
posted_by: '過帳者',
|
||||
counted_qty: '盤點數量',
|
||||
adjust_qty: '調整數量',
|
||||
};
|
||||
|
||||
// 狀態翻譯對照表
|
||||
@@ -164,6 +166,8 @@ const statusMap: Record<string, string> = {
|
||||
// 庫存單據狀態
|
||||
counting: '盤點中',
|
||||
posted: '已過帳',
|
||||
no_adjust: '無需盤調',
|
||||
adjusted: '已盤調',
|
||||
// 生產工單狀態
|
||||
planned: '已計畫',
|
||||
in_progress: '生產中',
|
||||
@@ -492,7 +496,7 @@ export default function ActivityDetailDialog({ open, onOpenChange, activity }: P
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{/* 更新項目 */}
|
||||
{activity.properties.items_diff.updated.map((item: any, idx: number) => (
|
||||
{activity.properties.items_diff.updated?.map((item: any, idx: number) => (
|
||||
<TableRow key={`upd-${idx}`} className="bg-blue-50/10 hover:bg-blue-50/20">
|
||||
<TableCell className="font-medium">{item.product_name}</TableCell>
|
||||
<TableCell className="text-center">
|
||||
@@ -500,41 +504,46 @@ export default function ActivityDetailDialog({ open, onOpenChange, activity }: P
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
<div className="space-y-1">
|
||||
{item.old.quantity !== item.new.quantity && (
|
||||
{item.old?.quantity !== item.new?.quantity && item.old?.quantity !== undefined && (
|
||||
<div>數量: <span className="text-gray-500 line-through">{item.old.quantity}</span> → <span className="text-blue-700 font-bold">{item.new.quantity}</span></div>
|
||||
)}
|
||||
{item.old.counted_qty !== item.new.counted_qty && (
|
||||
{item.old?.counted_qty !== item.new?.counted_qty && item.old?.counted_qty !== undefined && (
|
||||
<div>盤點量: <span className="text-gray-500 line-through">{item.old.counted_qty ?? '未盤'}</span> → <span className="text-blue-700 font-bold">{item.new.counted_qty ?? '未盤'}</span></div>
|
||||
)}
|
||||
{item.old.unit_name !== item.new.unit_name && (
|
||||
{item.old?.adjust_qty !== item.new?.adjust_qty && (
|
||||
<div>調整量: <span className="text-gray-500 line-through">{item.old?.adjust_qty ?? '0'}</span> → <span className="text-blue-700 font-bold">{item.new?.adjust_qty ?? '0'}</span></div>
|
||||
)}
|
||||
{item.old?.unit_name !== item.new?.unit_name && item.old?.unit_name !== undefined && (
|
||||
<div>單位: <span className="text-gray-500 line-through">{item.old.unit_name || '-'}</span> → <span className="text-blue-700 font-bold">{item.new.unit_name || '-'}</span></div>
|
||||
)}
|
||||
{item.old.subtotal !== item.new.subtotal && (
|
||||
{item.old?.subtotal !== item.new?.subtotal && item.old?.subtotal !== undefined && (
|
||||
<div>小計: <span className="text-gray-500 line-through">${item.old.subtotal}</span> → <span className="text-blue-700 font-bold">${item.new.subtotal}</span></div>
|
||||
)}
|
||||
{item.old.notes !== item.new.notes && (
|
||||
<div>備註: <span className="text-gray-500 line-through">{item.old.notes || '-'}</span> → <span className="text-blue-700 font-bold">{item.new.notes || '-'}</span></div>
|
||||
{item.old?.notes !== item.new?.notes && (
|
||||
<div>備註: <span className="text-gray-500 line-through">{item.old?.notes || '-'}</span> → <span className="text-blue-700 font-bold">{item.new?.notes || '-'}</span></div>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
)) || null}
|
||||
|
||||
{/* 新增項目 */}
|
||||
{activity.properties.items_diff.added.map((item: any, idx: number) => (
|
||||
{activity.properties.items_diff.added?.map((item: any, idx: number) => (
|
||||
<TableRow key={`add-${idx}`} className="bg-green-50/10 hover:bg-green-50/20">
|
||||
<TableCell className="font-medium">{item.product_name}</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<Badge variant="outline" className="bg-green-50 text-green-700 border-green-200">新增</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
數量: {item.quantity} {item.unit_name} / 小計: ${item.subtotal}
|
||||
{item.quantity !== undefined ? `數量: ${item.quantity} ${item.unit_name || ''} / ` : ''}
|
||||
{item.adjust_qty !== undefined ? `調整量: ${item.adjust_qty} / ` : ''}
|
||||
{item.subtotal !== undefined ? `小計: $${item.subtotal}` : ''}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
)) || null}
|
||||
|
||||
{/* 移除項目 */}
|
||||
{activity.properties.items_diff.removed.map((item: any, idx: number) => (
|
||||
{activity.properties.items_diff.removed?.map((item: any, idx: number) => (
|
||||
<TableRow key={`rem-${idx}`} className="bg-red-50/10 hover:bg-red-50/20">
|
||||
<TableCell className="font-medium text-gray-400 line-through">{item.product_name}</TableCell>
|
||||
<TableCell className="text-center">
|
||||
@@ -544,7 +553,7 @@ export default function ActivityDetailDialog({ open, onOpenChange, activity }: P
|
||||
原紀錄: {item.quantity} {item.unit_name}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
)) || null}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user