Installing Billing Extension

Back   Posted on 1 september 2018 / Updated on 9 january 2025
Reading time 3 minutes

Congratulations on successfully activating Billing Extension! You're almost there.

To complete the installation, you must insert the integration code provided below and understand a few essential concepts. Please carefully read all steps, as the module offers an extensive range of features.

Integration Code

To fully utilize Billing Extension, you need to modify the invoicepdf.tpl file, which processes the PDF versions of proformas and invoices in WHMCS. This file is located in your template directory. Typical file paths include:

  • templates/twenty-one/invoicepdf.tpl
  • templates/six/invoicepdf.tpl
  • templates/custom_template/invoicepdf.tpl

Open the file with a text editor and, just below the opening PHP tag <?php, insert the following code:

# Billing Extension - Integration Code
if(file_exists(ROOTDIR . '/modules/addons/BillingExtension/core/autoload.php'))
{
    require_once(ROOTDIR . '/modules/addons/BillingExtension/core/autoload.php');
    $hook = new BillingExtension\BillingExtension_Admin\Hook;
    $hook = $hook->Integration($tplvars, 'pdf');
    foreach($hook as $k=>$v) $$k = $v;
}

Next, find the following line:

$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);

Replace it with this code:

if ($companylogo) {
    $pdf->Image($companylogo, 15, 25, 75); # Billing Extension - Company Logo
}
else {
    $pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);
}

Finally, locate the section starting with # Notes and insert the following code right before it:

# Billing Extension - Footer Text
if ($footertext) {
    $pdf->Ln(5);
    $pdf->SetFont($pdfFont, '', 6);
    $pdf->MultiCell(140, 5, $footertext, 0, 'C', '', 1, 35, '', true);
}

Save the changes. If you use multiple templates, repeat the process for each one.

Note: Without these changes, your PDFs may display incorrect information.

Header & Footer Integration

Starting from WHMCS version 7.0, invoices can include headers and footers that repeat on every page. For more details, refer to the Custom PDF Invoices documentation.

In summary, the header typically includes your logo and company details, while the footer contains contact information and legal notes.

If you use this feature, edit the invoicepdfheader.tpl file in your template directory. Right after the <?php tag, add:

# Billing Extension - Integration Code
if(file_exists(ROOTDIR . '/modules/addons/BillingExtension/core/autoload.php'))
{
require_once(ROOTDIR . '/modules/addons/BillingExtension/core/autoload.php');
$hook = new BillingExtension\BillingExtension_Admin\Hook;
$hook = $hook->Integration($tplvars, 'pdf');
foreach($hook as $k=>$v) $$k = $v;
}

For footers, move the notes section from invoicepdf.tpl to invoicepdffooter.tpl to make them repeat on every page. The same principle applies to other sections, such as logos, which should be moved from invoicepdf.tpl to invoicepdfheader.tpl.

Fine Tunings

Now that you’ve successfully completed the module installation, the next step is to explore all the available settings in Addons > Billing Extension > Settings. The options are divided into multiple tabs, but we recommend focusing primarily on:

  • Business Profile
  • Tax Rules
  • Settings

We encourage you to get familiar with our technologies SorTables, HereLang, and MagicInput, which significantly enhance your experience with WHMCS. Take a look, as we’re sure they’ll save you a lot of time and streamline various tasks.

Bonus Tip: Payment Details

In unpaid proforma PDFs (file invoicepdf.tpl), you may want to display additional information about "offline" payment methods, such as bank transfers. To do so, insert the following code right after the # Client Details section:

// Billing Extension - Payment Method Details
if (in_array($status, array('Unpaid', 'Draft', 'Payment Pending')) AND $paymentmethod == 'banktransfer')
{
	$ref_height = $pdf->GetY() - $addressypos;
	$this_text = "Bank: Test Ltd.\nIBAN: IT005500\nPay to: Mark White\nReference: " . $invoicenum;
	$this_width = 80;
	$this_height = $pdf->getStringHeight($this_width, $this_text, false, true, '', 0);
	if ($this_height < $ref_height): $this_height = $ref_height; endif;
	$pdf->SetFillColor(255);
	$pdf->MultiCell($this_width, $this_height, $this_text, 0, 'R', true, 1, 116, $addressypos, true, 0, false, true, 0, 'T', true);
	$pdf->lastPage();
	$pdf->Ln(5);
}

Click here to preview the result. Please note that the provided code is just an example tested with WHMCS's default invoicepdf.tpl file. You may need to adjust it to suit your specific requirements.

Comments (0)

Speak Your Mind Cancel Reply