The Challenge
Problem
A hosting business was transitioning between legal entities. All invoices before January 1st 2026 needed to show the original company details (Company Y), while invoices from 2026 onwards needed to display the new entity (Company Z).
- Different company names, addresses, and VAT details per entity
- Different logos on invoice PDFs
- Different bank account details for payments
- Automatic assignment — no manual intervention per invoice
- Historical invoices must remain unchanged
The Solution
Solution
Built a custom multi-entity billing module for WHMCS that automatically assigns the correct legal entity to each invoice based on the invoice date. The system uses hooks to intercept invoice creation and template overrides to render entity-specific details.
System Flow
Implementation
The system consists of four key components: a database table for entity details, a hook for automatic assignment, and template modifications for PDF and web invoice display.
Core Logic: Simple date-based routing
// Automatic entity assignment based on invoice date if (strtotime($invoiceDate) < strtotime('2026-01-01')) { $entityId = 1; // Company Y (original entity) } else { $entityId = 2; // Company Z (new entity) } // Update invoice with assigned entity Capsule::table('tblinvoices') ->where('id', $invoiceId) ->update(['billing_entity_id' => $entityId]);
Database Schema
CREATE TABLE tbl_billing_entities ( id INT PRIMARY KEY, company_name VARCHAR(255), address TEXT, vat_number VARCHAR(50), bank_details TEXT, logo_path VARCHAR(255), active_from DATE, active_to DATE ); -- Entity 1: Company Y (historical) INSERT INTO tbl_billing_entities VALUES ( 1, 'Company Y', 'Address...', 'VAT...', 'Bank details...', '{company_y_logo}.png', '2010-01-01', '2025-12-31' ); -- Entity 2: Company Z (current) INSERT INTO tbl_billing_entities VALUES ( 2, 'Company Z', 'Address...', NULL, 'Bank details...', '{company_z_logo}.png', '2026-01-01', NULL );
Results
The system went live on January 1st, 2026. All new invoices automatically display the new company details, while historical invoices remain unchanged with the original entity information.
Tech Stack
Need custom billing automation?
We build systems that handle the complexity so you don't have to.
Get in touch