export interface Transaction { id: string; type: string; quantity: number; balanceAfter: number; reason: string | null; userName: string; actualTime: string; batchNumber?: string; // 商品層級查詢時顯示批號 slot?: string; // 貨道資訊 } interface TransactionTableProps { transactions: Transaction[]; showBatchNumber?: boolean; // 是否顯示批號欄位 } export default function TransactionTable({ transactions, showBatchNumber = false }: TransactionTableProps) { if (transactions.length === 0) { return (
暫無異動紀錄
); } // 自動偵測是否需要顯示批號(如果任一筆記錄有 batchNumber) const shouldShowBatchNumber = showBatchNumber || transactions.some(tx => tx.batchNumber); // 自動偵測是否需要顯示貨道(如果任一筆記錄有 slot) const shouldShowSlot = transactions.some(tx => tx.slot); return (
{shouldShowBatchNumber && } {shouldShowSlot && } {transactions.map((tx, index) => ( {shouldShowBatchNumber && ( )} {shouldShowSlot && ( )} ))}
# 時間批號類型 變動數量 結餘貨道經手人 原因/備註
{index + 1} {tx.actualTime}{tx.batchNumber || '-'} 0 ? 'bg-green-100 text-green-800' : tx.quantity < 0 ? 'bg-red-100 text-red-800' : 'bg-gray-100 text-gray-800' }`}> {tx.type} 0 ? 'text-green-600' : tx.quantity < 0 ? 'text-red-600' : '' }`}> {tx.quantity > 0 ? '+' : ''}{tx.quantity} {tx.balanceAfter}{tx.slot || '-'}{tx.userName} {tx.reason || '-'}
); }