WP Residence Help WP Residence Help

  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / 13. WPResidence / WPEstate CRM / WPResidence CRM Stats — Developer Reference

WPResidence CRM Stats — Developer Reference

11 views 0

Developer documentation for the Stats module of the WPResidence real estate CRM. Covers the stats-functions API, Chart.js integration, deferred loading, and scope filtering.

Files

  • libs/stats-functions.php — aggregate queries and counters.
  • page-templates/wpestate-crm-dashboard_stats.php — dashboard template.

Server-Side KPI Functions

Function Returns
wpestate_crm_get_lead_stats() total, by_status, by_source, by_type
wpestate_crm_get_enquiry_stats() Counts keyed by status
wpestate_crm_get_deal_stats() total, value_sum, by_stage, avg_value, won_count, lost_count
wpestate_crm_get_tasks_by_priority() Task counts per priority
wpestate_crm_stats_tasks_overdue() int — overdue task count

KPI Tiles (Server-Side Render)

The 5 tiles render synchronously in the template using the stats functions above plus helper date math:

  • first_day_of_month / first_day_of_prev_month — for “this month vs. previous” deltas.
  • monday_this_week / monday_last_week — for weekly activity delta.
  • Overdue tasks: conditional red CSS class applied when count > 0.

Charts (Deferred AJAX Render)

All six charts load after first paint via an AJAX call, to keep the page fast on sites with many records:

Action Purpose
wpestate_crm_get_stats Returns JSON payload with labels and datasets for all six charts.

Chart.js 4.4.7 is enqueued conditionally on the Stats page only (check in wpestate-crm.php around lines 59/90). The chart render logic reads wpestate_crm_vars.nonces for the request.

The Six Charts

  1. Contacts by Lifecycle Stage — doughnut.
  2. Deals by Pipeline Stage — bar with count + value.
  3. New Contacts over Time — line, 30-day rolling.
  4. Activity Volume by Type — bar.
  5. Deal Win/Loss Ratio — pie.
  6. Task Completion Rate — bar (% completed vs. total).

Scope Filtering

Every stats function respects wpestate_crm_get_ownership_where(). Admins receive unfiltered queries; agents get WHERE clauses scoped to their user_id and assigned agent ID.

Capabilities

The template is gated by wpestate_dashboard_header_permissions() (login required) and individual functions also respect wpestate_crm_user_can(‘activities’, ‘view’) where applicable.

Customizing Charts

  • To add a metric, extend libs/stats-functions.php from a child plugin (do not edit the CRM plugin directly).
  • Inject your new dataset into the wpestate_crm_get_stats AJAX response with a priority-20 filter on the response JSON.
  • Add a <canvas> element in a child template override of wpestate-crm-dashboard_stats.php and wire it to a Chart.js constructor on DOM ready.

Performance Notes

  • Pipeline summary uses a single GROUP BY deal_stage query.
  • Contacts-by-lifecycle uses a single GROUP BY lifecycle_stage query.
  • Activity volume uses a GROUP BY type with a WHERE created_at >= filter (last 30 days by default).
  • For sites with 100K+ rows, consider adding materialized summary tables and a daily cron to refresh them.
13. WPResidence / WPEstate CRM

Related Articles

  • WPResidence CRM Security Model — Developer Reference
  • CRM Security and Data Privacy
  • WPResidence CRM Installation and Updates — Developer Reference
  • Installing and Updating the WPResidence CRM

WP Residence Documentation

  • 01. Getting Started
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 02. Installation & Setup
  • 03. Installation FAQ
  • 06. Search & Filtering
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 09. Agent, Agency & Developers
  • 08. Property Pages & Layouts
  • 07. Property Lists, Categories & Archive
  • 14. WPResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • 04. Theme Options & Global Settings
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • 20. Translations & Languages
  • 26. FAQ
  • 10. Pages
  • 11. Header
  • 12. Footer
  • 05. Maps & Location Settings
  • 18. Payments & Monetization
  • Plugins
    • 19. Included Plugins
    • 22. Third Party Plugins – IDX Compatibility
    • 21. Third-Party Plugins – Multi-Language
    • 23. Third party Plugins – Other
  • Technical
    • 24. Technical how to | Custom Code Required
    • 25. Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API