Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

2.4 KB
Raw Blame
import {useParams} from "react-router";
import {useGetEvent} from "../../../../../queries/useGetEvent.ts";
import {formatCurrency} from "../../../../../utilites/currency.ts";
import {formatDateWithLocale} from "../../../../../utilites/dates.ts";
import ReportTable from "../../../../common/ReportTable";

export const DailySalesReport = () => {
    const {eventId} = useParams();
    const eventQuery = useGetEvent(eventId);
    const event = eventQuery.data;

    if (!event) {
        return null;
    }

    const columns = [
        {
            key: 'date' as const,
            label: 'Date',
            sortable: true,
            render: (value: string) => formatDateWithLocale(value, 'shortDate', event?.timezone)
        },
        {
            key: 'sales_total_gross' as const,
            label: 'Sales Total Gross',
            sortable: true,
            render: (value: string) => formatCurrency(value, event?.currency)
        },
        {
            key: 'total_tax' as const,
            label: 'Total Tax',
            sortable: true,
            render: (value: string) => formatCurrency(value, event?.currency)
        },
        {
            key: 'sales_total_before_additions' as const,
            label: 'Net Sales',
            sortable: true,
            render: (value: string) => formatCurrency(value, event?.currency)
        },
        {
            key: 'products_sold' as const,
            label: 'Products Sold',
            sortable: true
        },
        {
            key: 'orders_created' as const,
            label: 'Completed Orders',
            sortable: true
        },
        {
            key: 'total_fee' as const,
            label: 'Total Fee',
            sortable: true,
            render: (value: string) => formatCurrency(value, event?.currency)
        },
        {
            key: 'total_refunded' as const,
            label: 'Total Refunded',
            sortable: true,
            render: (value: string) => formatCurrency(value, event?.currency)
        },
        {
            key: 'total_views' as const,
            label: 'Total Views',
            sortable: true
        }
    ];

    return (
        <ReportTable
            title="Daily Sales Report"
            columns={columns}
            isLoading={eventQuery.isLoading}
            downloadFileName="daily_sales_report.csv"
            showDateFilter={true}
            event={event}
        />
    );
};