Daniel López Azaña

Theme

Social Media

Electricity Customer Portal - Private Web Application with Yii Framework and SugarCRM Integration

Secure customer portal for electricity distribution company built with Yii Framework, featuring SugarCRM database integration for real-time contract and billing data, Bootstrap responsive design, automated user registration with contract verification, role-based access control for customers and sales agents, and promotional code management. 5-month development delivering complete self-service customer platform.

When an electricity distribution company needs to provide customers with 24/7 access to their contract, consumption, and billing information, a secure, integrated customer portal becomes essential. This project involved building a private customer area for a Spanish electricity distribution company, accessible from their corporate website. The challenge was to create a self-service platform that displayed real-time customer data from a SugarCRM backend while maintaining security, performance, and usability across all devices.

Electricity Customer Portal Homepage

I architected and developed a complete customer portal using Yii Framework, featuring deep SugarCRM integration for real-time data access, automated user registration with contract verification, responsive Bootstrap design, and role-based access control for both customers and sales agents. The platform included contract management, consumption tracking, billing history, promotional code handling, and comprehensive user management, all while maintaining separation from the main WordPress corporate site.

The Business Challenge: Secure Self-Service for Energy Customers

Electricity distribution companies handle sensitive customer data including contracts, billing information, and consumption patterns. Providing secure, self-service access to this information reduces customer support costs while improving customer satisfaction.

Critical Business Requirements:

  • Real-time contract information - Display current contracts with all relevant details from CRM system.
  • Consumption tracking - Show monthly electricity consumption with period-by-period breakdowns.
  • Billing history - Provide access to past invoices and payment records.
  • Automated registration - Allow customers to self-register by verifying existing contract data.
  • Sales agent portal - Separate interface for sales agents to create new contracts and manage promotional codes.
  • Promotional code system - Enable marketing campaigns with trackable promo codes.
  • Security and privacy - Protect sensitive customer data with robust authentication.
  • WordPress independence - Separate the customer portal from the main corporate CMS for security and performance.

Why WordPress Wasn’t Enough:

The corporate website ran on WordPress, but building a secure customer portal within WordPress posed significant risks. Mixing public content with sensitive customer data, limited framework capabilities for complex business logic, and performance concerns with large datasets made a separate solution necessary.

The Solution: Decoupled Portal with SugarCRM Integration

My approach was to build a standalone customer portal on a separate subdomain using Yii Framework, which provided the robust MVC architecture, security features, and database handling capabilities required. The portal acted as a presentation layer for data stored in SugarCRM, creating a seamless integration between CRM backend and customer-facing frontend.

Architecture and Technical Approach

The system was designed with clear separation between presentation (Yii Framework), business logic (SugarCRM), and data storage (MySQL database shared between both systems).

Technical Implementation Strategy:

  • Separate Subdomain Deployment - Isolated customer portal from main WordPress site for security and performance.
  • Yiinitializr Advanced Template - Foundation for scalable architecture supporting future expansion.
  • SugarCRM Database Integration - Direct database access to CRM data without relying on APIs.
  • Yii-SugarCRM Data Layer - Custom abstraction layer mapping SugarCRM entities to Yii models.
  • Bootstrap Responsive Framework - Mobile-first design ensuring accessibility across devices.
  • Role-Based Access Control (RBAC) - Separate permissions for customers vs. sales agents.
  • Automated Registration Workflow - Contract verification process without manual intervention.
  • Session Management - 15-day remember-me functionality for user convenience.

Technology Stack

ComponentTechnologyPurpose
FrameworkYii Framework 1.1MVC foundation with ActiveRecord
TemplateYiinitializr AdvancedScalable application structure
CRM BackendSugarCRM CECustomer data and business logic
DatabaseMySQL 5.5Shared database for both systems
Frontend FrameworkBootstrap 3Responsive UI components
MarkupHTML5Modern semantic markup
StylingCSS3Advanced styling and responsive design
InteractivityjQueryClient-side interactions and AJAX
AuthenticationYii Auth ModuleUser authentication and authorization

SugarCRM Integration: The Data Bridge

The most technically challenging aspect was creating a seamless integration between Yii Framework and SugarCRM, allowing the customer portal to display real-time data from the CRM without tight coupling.

Integration Architecture:

Direct Database Access:

  • Yii models mapped directly to SugarCRM database tables.
  • Custom ActiveRecord classes representing SugarCRM entities (Accounts, Contracts, Invoices, Consumption).
  • Read-only access for customer data; write access only for sales agent functions.

Data Synchronization:

  • Real-time data access ensures customers always see current information.
  • No data duplication between systems.
  • Changes in SugarCRM immediately reflected in customer portal.

Account Linking:

  • Form allowing customers to link their portal user account to SugarCRM customer account.
  • Verification process using contract numbers and invoice data.
  • One-to-one mapping between portal users and CRM accounts.

Account linking form

Custom SugarCRM Modules:

The SugarCRM backend included custom modules specifically designed for the electricity distribution business (detailed in a separate portfolio project):

  • Custom Contracts module with energy-specific fields.
  • Custom Invoices module with electricity billing data.
  • Custom Consumption Tracking module with period-based usage data.
  • Accounts module extended with electricity customer fields.

User Management and Authentication

Security was paramount given the sensitive nature of electricity contracts and billing data. The authentication system needed to be both secure and user-friendly.

Automated Registration System:

Contract Verification Process:

  1. User enters email and creates password.
  2. System prompts for contract number and recent invoice data.
  3. Backend verifies these details against SugarCRM database.
  4. If match found, account is created and linked to CRM customer record.
  5. Verification email sent to confirm email address.
  6. User can immediately access their data after email confirmation.

Security Features:

  • Password hashing using bcrypt.
  • Email verification required before full access.
  • Failed login attempt tracking and temporary lockout.
  • CAPTCHA integration to prevent automated attacks.
  • Session timeout after inactivity.
  • HTTPS enforcement for all portal traffic.

Session Management:

  • “Remember Me” functionality extending sessions up to 15 days.
  • Secure cookie storage with httpOnly and secure flags.
  • Session regeneration after login to prevent fixation attacks.

Role-Based Access Control:

Customer Role:

  • View own contracts, consumption, and billing data.
  • Modify basic user profile information.
  • Access support resources and FAQs.
  • No access to sales agent functions.

Sales Agent Role:

  • Create new customer contracts.
  • Generate and manage promotional codes.
  • Access contract creation tools.
  • View assigned customer accounts.
  • Track promotional code usage and attribution.

Customer Features: Contracts, Consumption, and Billing

The core value of the portal was providing customers with instant access to their electricity service information.

Contract Management:

Contract Listing:

  • Display all active and historical contracts for the customer.
  • Contract details including supply point, rate plan, start/end dates.
  • Clear indication of current vs. terminated contracts.
  • Downloadable contract PDFs.

Contract Detail Views:

  • Complete contract specifications.
  • Rate plan details and pricing breakdown.
  • Supply point identification (CUPS code in Spanish market).
  • Contract modification history.
  • Related consumption and billing data.

Consumption Tracking:

Period-Based Consumption Data:

  • Monthly electricity consumption in kWh.
  • Period comparison (current month vs. previous months).
  • Visual charts showing consumption trends.
  • Peak vs. off-peak consumption breakdown (for time-of-use rates).
  • Historical data for analysis and budgeting.

Consumption Detail Views:

  • Meter readings with dates.
  • Calculation methodology transparency.
  • Estimated vs. actual readings clearly marked.
  • Consumption patterns and insights.

Billing and Invoices:

Invoice Management:

  • List of all invoices with dates and amounts.
  • Payment status tracking (paid, pending, overdue).
  • Downloadable invoice PDFs.
  • Payment history and methods.
  • Outstanding balance display.

Invoice Detail Views:

  • Complete billing breakdown.
  • Line items for energy consumption, distribution charges, taxes.
  • Due dates and payment instructions.
  • Historical payment records for that invoice.

Customer invoices view

Sales Agent Features: Contract Creation and Promotional Codes

Sales agents needed specialized tools to efficiently onboard new customers and manage marketing campaigns.

Contract Creation Interface:

  • Streamlined form for new contract data entry.
  • Customer search and selection from existing CRM accounts.
  • Rate plan selection with pricing display.
  • Supply point (CUPS) validation.
  • Promotional code application.
  • Direct creation into SugarCRM database.
  • Contract confirmation and documentation generation.

Promotional Code Management:

Code Generation:

  • Create unique promotional codes for marketing campaigns.
  • Define discount rules (percentage or fixed amount).
  • Set validity periods and usage limits.
  • Campaign tracking and attribution.

Code Tracking:

  • View all generated promotional codes.
  • Monitor usage statistics (redemptions, conversions).
  • Deactivate expired or completed campaigns.
  • Performance analytics per code.

Responsive Design: Accessibility Across Devices

Given that customers access electricity information from various contexts (home desktop, mobile while moving, tablet), responsive design was essential.

Bootstrap Foundation:

  • Mobile-First Approach - Designed for smartphones first, enhanced for larger screens.
  • Breakpoint Optimization - Custom breakpoints matching customer usage patterns.
  • Touch-Friendly Interface - Large buttons and form elements for mobile devices.
  • Readable Typography - Font sizes and line spacing optimized for all screen sizes.
  • Collapsible Navigation - Hamburger menu for mobile, expanded menu for desktop.

Performance Optimization:

  • Lightweight Pages - Minimal assets, fast load times even on mobile networks.
  • Lazy Loading - Images and non-critical content loaded as needed.
  • Cached Data - Yii caching reducing database queries for frequently accessed data.
  • Optimized Queries - Careful database query design minimizing SugarCRM database load.

Technical Challenges and Solutions

Challenge 1: SugarCRM Database Complexity

SugarCRM’s database schema is complex with numerous tables and relationships, making direct database access challenging.

Solution: Created a custom data abstraction layer with Yii models specifically designed to encapsulate SugarCRM’s schema complexity. Models handled joins, relationships, and custom fields transparently, allowing controllers and views to work with clean, simple data structures.

Challenge 2: Contract Verification Without Manual Intervention

Allowing automated registration required verifying users actually had contracts without involving company staff.

Solution: Implemented a multi-factor verification system requiring: (1) Valid contract number, (2) Recent invoice amount and date, (3) Supply point identifier. The combination of these three data points provided sufficient confidence that the registrant was the actual customer.

Challenge 3: Performance with Large Customer Datasets

Some customers had years of consumption and billing data, causing slow page loads if not handled carefully.

Solution: Implemented pagination for large datasets, lazy loading of detailed data, and aggressive caching of frequently accessed information. Only displayed summary data initially with “load more” functionality for historical records.

Challenge 4: Separating Customer and Agent Access

Different user types needed completely different interfaces and capabilities within the same application.

Solution: Leveraged Yii’s RBAC (Role-Based Access Control) system with separate controllers and views for customer vs. agent functionality. Middleware checked roles on every request, ensuring proper access control. Custom layouts for each user type provided appropriate navigation and feature access.

Project Outcome

The electricity customer portal successfully launched, providing thousands of customers with 24/7 self-service access to their electricity service information while reducing customer support workload.

Business Results:

  • Reduced support calls - Customers self-serve for contract and billing inquiries, reducing call center volume by approximately 30%.
  • Faster sales agent onboarding - New contract creation streamlined, reducing processing time from days to minutes.
  • Promotional campaign tracking - Marketing team gained visibility into campaign effectiveness through promo code analytics.
  • Customer satisfaction improvement - 24/7 access to information improved overall customer satisfaction scores.
  • Scalability achieved - Platform handled growing customer base without performance degradation.

Technical Achievements:

  • Seamless Yii Framework and SugarCRM integration with real-time data synchronization.
  • Automated user registration with contract verification, zero manual intervention.
  • Role-based access control separating customer and sales agent capabilities.
  • Responsive design working flawlessly across desktop, tablet, and mobile devices.
  • Secure authentication and session management protecting sensitive customer data.
  • Performance optimization handling large datasets efficiently.
  • Separate subdomain deployment maintaining security isolation from corporate site.

Key Learnings

1. Framework Selection Matters - Yii Framework’s ActiveRecord pattern and RBAC capabilities were perfect for this project’s requirements. The framework choice significantly impacted development speed and final quality.

2. Direct Database Integration Trade-offs - Accessing SugarCRM’s database directly provided performance benefits but created tight coupling. For this use case, the trade-off was acceptable, but API-based integration would be more maintainable for more complex scenarios.

3. Automated Verification is Powerful - The contract verification system enabled true self-service without compromising security. Careful design of verification criteria was key to balancing security with user experience.

4. Separation from Main Site Was Correct - Deploying on a separate subdomain provided security isolation, performance independence, and deployment flexibility. The decision to separate from WordPress was validated throughout the project.

5. User Role Complexity Should Not Be Underestimated - Supporting two completely different user types (customers and agents) added significant complexity. Early architectural decisions to properly separate these concerns paid dividends later.

Conclusion

This electricity customer portal project demonstrated the power of system integration when combining the right technologies for their respective strengths. By using Yii Framework for the presentation layer and SugarCRM for business logic and data management, the solution achieved both robust functionality and maintainability.

The project successfully delivered a secure, performant customer self-service platform that improved both customer satisfaction and operational efficiency. The automated registration system, in particular, showed that with careful verification design, even sensitive domains like energy distribution can enable true self-service without manual intervention.

This experience reinforced the importance of proper system architecture when integrating different platforms, the value of framework-specific features like Yii’s RBAC, and the critical nature of security in customer-facing portals handling sensitive data.


Confidentiality Note: Client name and specific business details have been omitted per confidentiality agreement. Screenshots have been sanitized to remove identifying customer information.

Daniel López Azaña

About the author

Daniel López Azaña

Tech entrepreneur and cloud architect with over 20 years of experience transforming infrastructures and automating processes.

Specialist in AI/LLM integration, Rust and Python development, and AWS & GCP architecture. Restless mind, idea generator, and passionate about technological innovation and AI.

Related projects

SugarCRM and WordPress integration for electricity company

SugarCRM Enterprise System for Electricity Distribution - Complete CRM with Custom Modules and Integrations

Comprehensive SugarCRM customization for Spanish electricity distribution company featuring 10+ custom modules for contracts, rates, consumption tracking, invoicing, tax reporting (Model 159), WordPress website integration for rate simulator and automated opportunity creation, Dropbox API integration for automated file processing, server deployment and hardening, backup policies, and scheduled email automation. 8-month ongoing development and maintenance delivering complete business management solution for energy sector.

Dreue Electric2013
Trendmii fashion platform homepage with responsive design

Trendmii Fashion Platform - Complete E-commerce Website with Custom CMS

Full-stack e-commerce fashion platform for Trendmii startup, built with Yii Framework featuring responsive design, custom blog system, comprehensive admin panel with Ace Admin theme, multilingual support for English and Spanish, social authentication integration, and online marketing consultancy. 6-month development delivering complete fashion marketplace solution.

Trendmii2013
SugarCRM and Gretur Viajes logos

SugarCRM Travel Agency CRM/ERP System - Complete Business Automation Platform

Comprehensive customer relationship and business management system for travel agency combining CRM, ERP, and CMS capabilities. Full SugarCRM customization enabling quote requests, booking management, automated state machines, real-time website synchronization, custom field types, intelligent alerting, and complete travel product administration. Seamless integration between SugarCRM backend and Joomla-based corporate website achieving instant content publishing and total process automation for travel bookings, documentation, billing, and customer service.

Gretur Viajes2008-2011

Comments

Be the first to comment

Submit comment

Have a Similar Project in Mind?

Let's discuss how I can help you achieve your goals

Start a Conversation