Overview
The Dashboard component (dashboard.js) is the main landing page that provides an overview of the POS system’s key metrics and recent transaction history. It displays today’s sales, total sales, transaction counts, and product inventory status.
Responsibilities
- Calculate and display today’s sales revenue
- Show cumulative sales statistics
- Display total transaction count
- Show total products in inventory
- Render the 5 most recent transactions
DOM Elements
The dashboard interacts with the following DOM elements:#todaySales- Display today’s total revenue#totalSales- Display cumulative revenue#totalTransactions- Display transaction count#totalProducts- Display product count#recentTransactions- Container for recent transaction list
Functions
loadDashboard()
Main function that loads and renders all dashboard statistics.- Fetches all products and sales from the database
- Filters sales for today (since midnight)
- Calculates today’s total revenue
- Calculates all-time total revenue
- Updates all stat elements in the DOM
- Renders the last 5 transactions in reverse chronological order
- Sale ID
- Date and time (formatted)
- Total amount (formatted with
money()helper) - Item count
Dependencies
Database module providing
getProducts() and getAllSales() functionsShared utilities module providing the
money() formatting function