| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wcfs/NAOPOS/src/components/ |
Upload File : |
import { SaleRecord } from "@/types/sales";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {
Table,
TableBody,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { Banknote, CreditCard } from "lucide-react";
import { buildEndOfDayReport } from "@/lib/reporting";
interface SalesReportProps {
open: boolean;
onClose: () => void;
sales: SaleRecord[];
onClearSales: () => void | Promise<void>;
}
const SalesReport = ({
open,
onClose,
sales,
onClearSales,
}: SalesReportProps) => {
const report = buildEndOfDayReport(sales);
const grandTotal = report.totalSales + report.totalTax;
return (
<Dialog open={open} onOpenChange={onClose}>
<DialogContent className="max-h-[85vh] overflow-y-auto border-border bg-card sm:max-w-4xl">
<DialogHeader>
<DialogTitle className="text-lg font-extrabold text-foreground">
End of Day Report
</DialogTitle>
<p className="text-sm text-muted-foreground">
Business date: {report.businessDate}
</p>
</DialogHeader>
<div className="grid grid-cols-3 gap-3">
<div className="rounded-xl border border-border bg-background p-3 text-center">
<p className="text-xs font-semibold text-muted-foreground">
Grand Total
</p>
<p className="font-mono text-xl font-extrabold text-foreground">
${grandTotal.toFixed(2)}
</p>
<p className="text-xs text-muted-foreground">
{report.totalTransactions} transactions
</p>
</div>
<div className="rounded-xl border border-success/20 bg-success/10 p-3 text-center">
<div className="mb-1 flex items-center justify-center gap-1">
<Banknote className="h-4 w-4 text-success" />
<p className="text-xs font-semibold text-muted-foreground">Cash</p>
</div>
<p className="font-mono text-xl font-extrabold text-foreground">
${report.cashTotal.toFixed(2)}
</p>
</div>
<div className="rounded-xl border border-primary/20 bg-primary/10 p-3 text-center">
<div className="mb-1 flex items-center justify-center gap-1">
<CreditCard className="h-4 w-4 text-primary" />
<p className="text-xs font-semibold text-muted-foreground">
Credit
</p>
</div>
<p className="font-mono text-xl font-extrabold text-foreground">
${report.creditTotal.toFixed(2)}
</p>
</div>
</div>
<div className="grid grid-cols-2 gap-3">
<div className="rounded-xl border border-border bg-background p-3 text-center">
<p className="text-xs font-semibold text-muted-foreground">
Pre-Tax Sales
</p>
<p className="font-mono text-lg font-extrabold text-foreground">
${report.totalSales.toFixed(2)}
</p>
</div>
<div className="rounded-xl border border-border bg-background p-3 text-center">
<p className="text-xs font-semibold text-muted-foreground">
Total Tax Collected
</p>
<p className="font-mono text-lg font-extrabold text-foreground">
${report.totalTax.toFixed(2)}
</p>
</div>
</div>
{report.categoryBreakdown.length > 0 ? (
<div className="overflow-hidden rounded-xl border border-border">
<Table>
<TableHeader>
<TableRow className="bg-secondary/50">
<TableHead className="text-xs font-bold">Category</TableHead>
<TableHead className="text-right text-xs font-bold">
Cash Sales
</TableHead>
<TableHead className="text-right text-xs font-bold">
Cash Tax
</TableHead>
<TableHead className="text-right text-xs font-bold">
Credit Sales
</TableHead>
<TableHead className="text-right text-xs font-bold">
Credit Tax
</TableHead>
<TableHead className="text-right text-xs font-bold">
Grand Total
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{report.categoryBreakdown.map((entry) => (
<TableRow key={entry.category}>
<TableCell className="text-sm font-semibold">
{entry.category}
</TableCell>
<TableCell className="text-right font-mono text-sm">
${entry.cashSales.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm">
${entry.cashTax.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm">
${entry.creditSales.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm">
${entry.creditTax.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm font-bold">
${entry.grandTotal.toFixed(2)}
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell className="text-sm font-bold">Total</TableCell>
<TableCell className="text-right font-mono text-sm font-bold">
$
{report.categoryBreakdown
.reduce((sum, row) => sum + row.cashSales, 0)
.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm font-bold">
$
{report.categoryBreakdown
.reduce((sum, row) => sum + row.cashTax, 0)
.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm font-bold">
$
{report.categoryBreakdown
.reduce((sum, row) => sum + row.creditSales, 0)
.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm font-bold">
$
{report.categoryBreakdown
.reduce((sum, row) => sum + row.creditTax, 0)
.toFixed(2)}
</TableCell>
<TableCell className="text-right font-mono text-sm font-bold">
${grandTotal.toFixed(2)}
</TableCell>
</TableRow>
</TableFooter>
</Table>
</div>
) : (
<div className="py-8 text-center text-muted-foreground">
<p className="text-sm">No sales recorded today</p>
</div>
)}
<div className="grid grid-cols-2 gap-2 pt-2">
<button
onClick={onClose}
className="rounded-xl bg-secondary py-3 text-sm font-bold text-secondary-foreground transition-all hover:bg-border"
>
Close
</button>
{sales.length > 0 && (
<button
onClick={async () => {
if (
confirm("Clear all sales data for this business day?")
) {
await onClearSales();
onClose();
}
}}
className="rounded-xl border border-destructive/20 bg-destructive/10 py-3 text-sm font-bold text-destructive transition-all hover:bg-destructive hover:text-destructive-foreground"
>
Clear & Start New Day
</button>
)}
</div>
</DialogContent>
</Dialog>
);
};
export default SalesReport;