Technical Documentation v1.0.0 WHMCS 9.1.x · PHP 8.2–8.4

Haikhavan PDF Invoice & E-Invoicing Designer

Complete architecture reference, installation guide, database schema, hooks, and troubleshooting.

Quick Installation

  1. Purchase the module and download haikhavan_pdf_einvoice_designer-ioncube-8.2-1.0.0-install.zip from your VPSrv Client Area Downloads.
  2. Upload and extract the ZIP into your WHMCS root directory so files land in modules/addons/haikhavan_pdf_einvoice_designer/.
  3. Verify PHP 8.2–8.4 with ionCube PHP Loader 14+ / 15.5+ is enabled on your server.
  4. Go to System Settings → Addon Modules in WHMCS Admin, click Activate next to Haikhavan PDF Invoice & E-Invoicing Designer, and assign administrator role access.

Visual block-based PDF Invoice & Quote Template Designer for WHMCS 9.x featuring 5 executive presets, real-time A4 live preview, native TCPDF rendering with embedded SEPA EPC & Pay-Now 2D QR codes, ZUGFeRD 2.2 / Factur-X CII & XRechnung 3.0 / Peppol UBL 2.1 XML e-invoicing, per-currency/country routing rules, and 1-click Accountant Batch ZIP exports.


Haikhavan PDF Invoice & E-Invoicing Designer — Technical Documentation (v1.0.0)

Technical architecture, database schema, TCPDF rendering pipeline, SEPA EPC QR payload format, EN 16931 ZUGFeRD/Factur-X CII & Peppol UBL 2.1 XML schemas, WHMCS hooks, and security specification for haikhavan_pdf_einvoice_designer.


1. Architecture & File Inventory

modules/addons/haikhavan_pdf_einvoice_designer/
├── haikhavan_pdf_einvoice_designer.php    # Addon lifecycle (_config, _activate, _deactivate, _upgrade, _output, _clientarea)
├── hooks.php                        # 4 WHMCS hooks (ClientAreaPrimaryNavbar, ClientAreaPageViewInvoice, AdminInvoicesControlsOutput, AdminHomeWidgets)
├── whmcs.json                       # Marketplace manifest (schema 1.0)
├── lib/
│   ├── Database.php                 # 4-table Capsule DDL, settings loader, SHA-256 audit logger, 5-preset seeder
│   ├── PresetCatalog.php            # 5 Executive Presets + 7 reorderable block definitions
│   ├── InvoiceDataResolver.php      # WHMCS tblinvoices/tblinvoiceitems/tblclients/tblcurrencies loader + rule matcher
│   ├── EInvoiceGenerator.php        # ZUGFeRD 2.2/Factur-X CII XML, XRechnung 3.0/Peppol UBL 2.1 XML & SEPA EPC QR builder
│   ├── PdfRenderer.php              # Bundled TCPDF binary renderer (watermarks, fold marks, read-only protection, 2D QR codes)
│   ├── BatchExporter.php            # Accountant Batch ZIP generator (PDFs + CII XML + UBL XML + RFC-4180 CSV ledger)
│   ├── AdminController.php          # 5-tab Admin Studio, binary stream downloads & CSRF-protected AJAX router
│   └── ClientController.php         # Client E-Invoice Portal & ownership-enforced PDF/XML downloader
├── templates/
│   ├── admin/dashboard.php          # Split-screen Visual Designer + Live A4 Preview + Rules + Invoices + Batch + Audit
│   └── client/portal.tpl            # Smarty Client Area Branded PDF & E-Invoicing Portal
└── assets/
    ├── css/haikhavan_pdf_einvoice.css              # Scoped .hk-pdf-* stylesheet + A4 paper preview styling
    └── js/haikhavan_pdf_einvoice.js                # Real-time A4 preview renderer, block reorderer, XML inspector & CSRF fetch helpers

2. Database Schema (4 Custom Tables)

Created idempotently via WHMCS\Database\Capsule::schema() in Haikhavan\PdfEinvoice\Database::install(). Preserved on deactivation.

Table Purpose Key Columns & Indexes
mod_hk_pdf_templates Stored visual invoice/quote/credit-note templates id (PK), slug (UNIQUE), name, doc_type, preset_key, is_default (IDX), primary_color, secondary_color, accent_color, text_color, font_family, logo_position, logo_text, company_name, company_address, company_vat_id, company_tax_reg, bank_iban, bank_bic, bank_beneficiary, show_watermark, watermark_opacity, qr_mode, show_pay_button, show_fold_marks, pdf_protect_readonly, legal_footer, reverse_charge_note, blocks_order_json
mod_hk_pdf_rules Priority-ordered automatic template routing rules id (PK), name, priority (IDX), template_id (IDX), doc_type, currency_code, country_code, client_group_id, enabled
mod_hk_pdf_einvoice_log Cryptographic SHA-256 generation audit trail id (PK), invoice_id (IDX), userid (IDX), adminid (IDX), template_id, format (pdf|facturx_cii|ubl_peppol|batch_zip), filename, file_size_bytes, sha256_hash, status, ip_address, created_at
mod_hk_pdf_exports Accountant Batch ZIP archive history id (PK), adminid, date_from, date_to, status_filter, include_pdf, include_cii, include_ubl, include_csv, invoice_count, total_amount, zip_filename, size_bytes, created_at

3. PDF Generation & 2D QR Pipeline (PdfRenderer)

Uses WHMCS's native bundled TCPDF (ROOTDIR . '/vendor/tecnickcom/tcpdf/tcpdf.php') with zero external binaries:

  • Reorderable Block Engine: Iterates blocks_order_json (header, meta_strip, parties, line_items, totals, qr_payment, legal_footer) in exact user-defined order.
  • Dynamic Status Watermarks: Renders diagonal rotated (38°) translucent (SetAlpha) status text (PAID green, UNPAID/OVERDUE red, CANCELLED slate) beneath document content.
  • DIN 5008 Fold & Punch Marks: Optional left-margin marks at 105mm, 148.5mm, and 210mm.
  • Optional Read-Only Protection: Applies $pdf->SetProtection(['print', 'copy']) when pdf_protect_readonly = 1.
  • 2D QR Payment Barcodes (write2DBarcode(..., 'QRCODE,M')):
    • SEPA EPC QR (EPC069-12 BCD v002): Standard 11-line SCT payload (BCD\n002\n1\nSCT\n<BIC>\n<Beneficiary>\n<IBAN>\nEUR<Amount>\n\n\n<InvoiceRef>).
    • Pay-Now URL QR + Clickable PDF Link: Encodes <SystemURL>/viewinvoice.php?id=<ID> in both a scannable QR code and a clickable TCPDF button cell.

4. E-Invoicing XML Standards (EInvoiceGenerator)

  1. ZUGFeRD 2.2 / Factur-X 1.0 (EN 16931 CII XML):
    • Root: rsm:CrossIndustryInvoice (urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100)
    • Guideline ID: urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:extended
    • Includes ExchangedDocument (TypeCode=380), IncludedSupplyChainTradeLineItem, SellerTradeParty + BuyerTradeParty, SpecifiedTradeSettlementPaymentMeans (TypeCode=58 SEPA Credit Transfer IBAN/BIC), ApplicableTradeTax, and SpecifiedTradeSettlementHeaderMonetarySummation.
  2. XRechnung 3.0 / Peppol BIS Billing 3.0 (UBL 2.1 XML):
    • Root: Invoice (urn:oasis:names:specification:ubl:schema:xsd:Invoice-2)
    • CustomizationID: urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0
    • ProfileID: urn:fdc:peppol.eu:2017:poacc:billing:01:1.0
    • Includes AccountingSupplierParty, AccountingCustomerParty, PaymentMeans (58), TaxTotal, LegalMonetaryTotal, and InvoiceLine elements.

5. WHMCS Hooks & Security

Registered Hooks (hooks.php)

  1. ClientAreaPrimaryNavbar — Adds Branded PDF & E-Invoices under Billing.
  2. ClientAreaPageViewInvoice — Exposes $hk_pdf_url, $hk_pdf_facturx_url, and $hk_pdf_peppol_url template vars on viewinvoice.php.
  3. AdminInvoicesControlsOutput — Renders 1-click Branded PDF (+QR), Factur-X / ZUGFeRD CII XML, and XRechnung / Peppol UBL 2.1 buttons inside WHMCS Admin Invoice View.
  4. AdminHomeWidgets — Registers Haikhavan PDF & E-Invoicing Compliance dashboard widget.

Security Controls

  • CSRF Protection: 48-hex-char session tokens ($_SESSION['hk_pdf_admin_csrf'], $_SESSION['hk_pdf_client_csrf']) validated via hash_equals() on all write AJAX requests (HTTP 403 on failure).
  • Strict Tenant Isolation: ClientController passes $userId = $_SESSION['uid'] to InvoiceDataResolver::resolveInvoice($invId, $userId) on every PDF/XML download and AJAX call, rejecting cross-client invoice IDs with HTTP 403.
  • SHA-256 Integrity Audit: Every generated PDF, CII XML, UBL XML, and Batch ZIP records its SHA-256 hash and file size in mod_hk_pdf_einvoice_log.
  • XML & HTML Escaping: All XML text uses htmlspecialchars(..., ENT_XML1 | ENT_QUOTES, 'UTF-8'); all templates escape output cleanly.

6. AJAX & Download Endpoints

  • Admin Downloads (admin/addonmodules.php?module=haikhavan_pdf_einvoice_designer):
    • &download=pdf&invoice_id=<ID>&template_id=<TID> -> application/pdf
    • &download=facturx_cii&invoice_id=<ID> -> application/xml
    • &download=ubl_peppol&invoice_id=<ID> -> application/xml
    • &download=batch_zip&date_from=...&date_to=...&status_filter=... -> application/zip
  • Admin AJAX (&ajax=1): save_template, set_default_template, clone_template, delete_template, save_rule, delete_rule, preview_xml.
  • Client Downloads (index.php?m=haikhavan_pdf_einvoice_designer): &download=pdf|facturx_cii|ubl_peppol&invoice_id=<ID> (strictly owned invoices).
  • Client AJAX (&ajax=1): sepa_qr (returns IBAN/BIC & EPC QR payload for owned invoice).