"use client" import { ShoppingCartIcon } from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/shared/components/ui/table" import { formatCurrency } from "@/shared/utils/formatters" type ExpenseItem = { id?: number expense_id?: number expense_item_id?: number quantity?: number | string rate?: string | number description?: string | null expense_item?: { id?: number item_name?: string name?: string item_code?: string sku?: string } } type ExpenseItemsSectionProps = { items?: ExpenseItem[] discountType?: string | null subTotal?: number | null discountAmount?: number | null taxAmount?: number | null total?: number | null taxLabel?: string | null } export function ExpenseItemsSection({ items, discountType, subTotal, discountAmount, taxAmount, total, taxLabel, }: ExpenseItemsSectionProps) { if (!items || items.length === 0) return null return ( Expense Items ({items.length})
Item Description Qty Rate Amount {items.map((item) => { const qty = Number(item.quantity || 0) const rate = Number(item.rate || 0) const amount = qty * rate const name = item.expense_item?.item_name || item.expense_item?.name || "—" return (
{name}
{(item.expense_item?.sku || item.expense_item?.item_code) && (
{item.expense_item?.sku || item.expense_item?.item_code}
)}
{item.description || "—"} {qty.toLocaleString()} {formatCurrency(rate)} {formatCurrency(amount)}
) })}
{/* ── Totals summary ── */}
{subTotal != null && (
Subtotal {formatCurrency(subTotal)}
)} {discountAmount != null && discountAmount > 0 && discountType !== "no" && (
Discount − {formatCurrency(discountAmount)}
)} {taxAmount != null && taxAmount > 0 && (
{taxLabel || "Tax"} {formatCurrency(taxAmount)}
)} {total != null && (
Total {formatCurrency(total)}
)}
) }