Skip to content

Admin Dashboard Charts ​

Flow ID: SY-21 | Module(s): application (core) | Complexity: Medium Last Updated: 2026-09-14

Business Context ​

The admin dashboard provides real-time and period-based business intelligence charts for store administrators. When an admin logs in, the dashboard home page loads a set of AJAX-powered charts showing key performance metrics: daily turnover, order counts, payment method distribution, popular products, vendor performance, category performance, and live operational stats.

All chart data endpoints are AJAX-only (checking is_ajax_request()) and return JSON for rendering by the frontend JavaScript charting library. The dashboard supports date range filtering to analyze specific periods.


API Reference ​

REST Endpoints ​

No REST API. Dashboard charts are served via legacy AJAX endpoints.

Legacy Admin Routes ​

RouteControllerMethodHTTPDescription
adminrun/eshopAdminChartsAdminruneshopAdminChartsPOST (AJAX)Main charts: turnover, orders, payment methods, popular products
adminrun/dashboardLiveAdminrundashboardLivePOST (AJAX)Live dashboard stats (today's orders, revenue, customers)
adminrun/vendorschartAdminrunvendorschartPOST (AJAX)Vendor sales comparison (current vs. previous year)
adminrun/productschartAdminrunproductschartPOST (AJAX)Product-level sales breakdown
adminrun/vendorproductschartAdminrunvendorproductschartPOST (AJAX)Products within a specific vendor
adminrun/categorieschartAdminruncategorieschartPOST (AJAX)Category-level sales breakdown
adminrun/categoriesproductschartAdminruncategoriesproductschartPOST (AJAX)Products within a specific category

All endpoints accept POST parameters: date_start, date_end. If not provided, default to current month (from 1st of month to today).


Code Flow ​

Main Charts (eshopAdminCharts) ​

  1. Dashboard page loads and fires an AJAX POST to adminrun/eshopAdminCharts.
  2. eshopAdminCharts() validates the request is AJAX.
  3. Merges results from four sub-methods:
    • turnoversWithVatChart(): Groups orders by day, sums total_vat per day. Returns { labels: ["2026-04-01",...], total: [1234.56,...] }.
    • turnovers(): Aggregates period totals: turnover (net) and turnoverVat (with VAT).
    • ordersChart(): Groups orders by day, counts orders per day. Returns { labels: [...], total: [...] }.
    • payWayPie(): Groups orders by payway, counts per payment method. Returns { payway: { count, label, color } } where color is auto-generated from the payway string.
    • popularProducts(): Joins shop_order_basket with product_codes and shop_product_mui, groups by product, orders by sell count DESC. Returns top 100 products with { name, count }.
  4. All queries exclude orders with status CANCELED, PENDING, or RETURN.
  5. Returns combined JSON with JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE flags.

Live Dashboard (dashboardLive) ​

  1. AJAX POST to adminrun/dashboardLive.
  2. Merges three sub-methods:
    • dashboardLiveDaysData(): Detailed breakdown of today's orders -- total with VAT, guest vs. signed-up revenue, last-hour orders, unique customers, phone orders, orders to send, orders to send to stores, etc.
    • dashboardLiveMonthData(): Current month aggregates.
    • dashboardLiveExtraData(): Additional live metrics.
  3. All queries run against shop_order joined with shop_customer for customer type classification.

Vendor Charts (vendorschart) ​

  1. AJAX POST with date_start, date_end.
  2. Loads reporting_model and vendors_model.
  3. Fetches current period and previous year same period vendor sales via reporting_model::getVendorsSalesForPeriod().
  4. For each vendor: calculates qty, subtotal, subtotal_percent, old_subtotal, old_percent (year-over-year comparison).
  5. Returns top 15 vendors as bar chart data + "Others" aggregate, plus full vendor table data.

Product Charts (productschart) ​

  1. AJAX POST with date filters.
  2. Uses order_basket_model::getReportingData() to fetch per-product sales.
  3. Aggregates by product ID, calculates qty, subtotal, qty_percent, subtotal_percent.
  4. Sorts by subtotal descending. Returns top 15 for bar chart + full table.

Category Charts (categorieschart, categoriesproductschart) ​

  1. Similar pattern to product charts but joins category data.
  2. categorieschart: Aggregates sales by product category.
  3. categoriesproductschart: Drills into a specific category (passed as cat_id POST param) to show per-product breakdown within that category.

Domain Layer ​

No modern domain layer. Dashboard charts are a pure legacy application controller feature.


Architecture ​

ComponentPathPurpose
Adminrunapplication/controllers/Adminrun.phpMain dashboard controller (~1,376 lines)
order_basket_modelecommercen/eshop/models/Order basket reporting queries
reporting_modelecommercen/eshop/models/Vendor/period sales aggregation
vendors_modelecommercen/eshop/models/Vendor list for chart labels
Frontend JSpublic/ui/admin/js/dashboard.jsChart rendering (Chart.js or similar)
Routesapplication/config/routes.php:550-551adminrun/(.+) -> adminrun/$1

Data Model ​

This flow reads from (does not own):

TablePurpose
shop_orderOrder data: entry_datetime, total, total_vat, status, payway, customer_id, store_id, sent_date_time
shop_order_basketOrder line items: product_code_id, price, qty
product_codesProduct code to product mapping
shop_product / shop_product_muiProduct names and prices
shop_vendor / shop_vendor_muiVendor names
shop_product_category_lp / shop_product_category_muiCategory mappings and names
shop_customerCustomer guest/registered status

Configuration ​

No registry keys or config files specific to dashboard charts. Chart behavior is controlled entirely by the date range parameters.

Status exclusions: All chart queries exclude orders with status CANCELED, PENDING, or RETURN (hardcoded).


Client Extension Points ​

  • Override controller: Extend Adminrun in application/controllers/ to add custom chart endpoints or modify existing ones.
  • Custom chart data: Override individual methods like turnoversWithVatChart(), vendorschart(), etc.
  • Additional charts: Add new AJAX endpoints to Adminrun and corresponding frontend components.

Business Rules ​

  1. AJAX-only: All chart endpoints check is_ajax_request() and return empty data for non-AJAX requests.
  2. Default date range: If no dates provided, defaults to current month (1st to today).
  3. Status exclusion: Orders with status CANCELED, PENDING, or RETURN are excluded from all metrics.
  4. Year-over-year: Vendor charts compare the selected period to the same period one year prior.
  5. Top N + Others: Vendor and product charts show top 15 items in bar charts, with remaining items aggregated as "Others" (labeled "Ypollipoi" in Greek).
  6. Color generation: Payment method pie chart colors are auto-generated from the payway string using genColorCodeFromString().
  7. Live stats: dashboardLive provides real-time metrics for the current day including last-hour order counts.