"use client" import { Wrench } 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, formatNumber } from "@/shared/utils/formatters" type BillPart = { id: number bill_id: number part_id: number quantity: string | number rate: string | number description?: string part?: { id?: number; name?: string; part_number?: string } } type BillPartsSectionProps = { parts?: BillPart[] } export function BillPartsSection({ parts = [] }: BillPartsSectionProps) { if (!parts || parts.length === 0) return null const subtotal = parts.reduce((sum, part) => { const qty = parseFloat(String(part.quantity)) const rate = parseFloat(String(part.rate)) return sum + (qty * rate) }, 0) return ( Parts
Part Description Quantity Rate Amount {parts.map((part) => { const qty = parseFloat(String(part.quantity)) const rate = parseFloat(String(part.rate)) const amount = qty * rate return ( {part.part?.name || `Part #${part.part_id}`} {part.description || "—"} {formatNumber(qty)} {formatCurrency(rate)} {formatCurrency(amount)} ) })} Subtotal {formatCurrency(subtotal)}
) }