// ** MUI Imports import Paper from '@mui/material/Paper' import Table from '@mui/material/Table' import TableRow from '@mui/material/TableRow' import TableHead from '@mui/material/TableHead' import TableBody from '@mui/material/TableBody' import TableCell from '@mui/material/TableCell' import TableContainer from '@mui/material/TableContainer' interface Row { desc: string qty: number unit: number price: number } const TAX_RATE = 0.07 const ccyFormat = (num: number) => { return `${num.toFixed(2)}` } const priceRow = (qty: number, unit: number) => { return qty * unit } const createRow = (desc: string, qty: number, unit: number) => { const price = priceRow(qty, unit) return { desc, qty, unit, price } } const subtotal = (items: readonly Row[]) => { return items.map(({ price }) => price).reduce((sum, i) => sum + i, 0) } const rows = [ createRow('Paperclips (Box)', 100, 1.15), createRow('Paper (Case)', 10, 45.99), createRow('Waste Basket', 2, 17.99) ] const invoiceSubtotal = subtotal(rows) const invoiceTaxes = TAX_RATE * invoiceSubtotal const invoiceTotal = invoiceTaxes + invoiceSubtotal const TableSpanning = () => { return ( Details Price Desc Qty. Unit Sum {rows.map(row => ( {row.desc} {row.qty} {row.unit} {ccyFormat(row.price)} ))} Subtotal {ccyFormat(invoiceSubtotal)} Tax {`${(TAX_RATE * 100).toFixed(0)} %`} {ccyFormat(invoiceTaxes)} Total {ccyFormat(invoiceTotal)}
) } export default TableSpanning