Documentation Index
Fetch the complete documentation index at: https://mintlify.com/CodecraftBySyed/Mini-POS-System/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Reports component (reports.js) provides sales analytics and reporting functionality. It allows users to view sales data within date ranges, export reports as CSV files, and print reports as PDF documents.
Responsibilities
- Filter sales by date range
- Display sales summary (count and total)
- Render sales data in tabular format
- Export sales data as CSV
- Print sales reports as PDF
- Calculate grand totals
DOM Elements
#fromDate- Date input for start date#toDate- Date input for end date#exportCsv- Button to export CSV#printPdf- Button to print PDF#reportSummary- Summary text showing count and total#reportTable- Container for sales table#print-area- Hidden print area for PDF generation
Functions
setDefaultDates()
Sets both date inputs to today’s date as the default filter.tableHTML(rows)
Generates HTML table markup for sales data with grand total row.Array of sale objects to display
string - HTML table markup or empty state message
Empty State:
- ID: Sale transaction ID
- Date: Transaction date and time (localized)
- Items: Total quantity of items in the sale
- Total: Sale total amount in rupees
loadReport()
Fetches and displays sales data for the selected date range. Returns:Promise<Array<Sale>> - Array of sales in range
- Reads date range from input fields (with fallback defaults)
- Adjusts end date to include full day (23:59:59.999)
- Fetches sales within range from database
- Calculates grand total
- Updates summary text
- Renders table with sales data
- Returns sales array for export functions
Export Functions
CSV Export
Generates and downloads a CSV file with sales data.sales-report-YYYY-MM-DD-to-YYYY-MM-DD.csv
PDF Print
Generates a printable report and opens the browser print dialog.- Loads report data
- Shows hidden print area
- Injects report HTML with header and table
- Triggers browser print dialog
- Hides print area after 100ms
- Report title: “Sales Report”
- Date range: “Period: YYYY-MM-DD to YYYY-MM-DD”
- Full sales table with grand total
Event Handlers
Auto-reload on Date Change
Automatically refreshes the report when date inputs change:Dependencies
Database module providing
getSalesInRange(from, to) functionShared utilities providing
money(n) formatting functionData Structure
Sale Object:Auto-Execution
On module load:User Workflows
View Today’s Sales
- Component loads with today’s date pre-filled
- Report automatically displays today’s transactions
- Summary shows transaction count and total revenue
View Custom Date Range
- User selects start date in “From” field
- User selects end date in “To” field
- Report automatically updates on each change
- Table shows all sales within the range
- Grand total row sums all visible transactions
Export to CSV
- User sets desired date range
- User clicks “Export CSV” button
- If sales exist, CSV file downloads automatically
- Filename includes date range
- CSV can be opened in Excel or Google Sheets
Print to PDF
- User sets desired date range
- User clicks “Print PDF” button
- If sales exist, print dialog opens
- User can save as PDF or print to printer
- Report includes header with date range and full table
Date Range Handling
Default Range:- Both dates set to today
- Shows only today’s sales
- Missing “From” defaults to
1970-01-01 - Missing “To” defaults to
2999-12-31 - Ensures report still runs if dates are cleared