WHMCS Automatic Batch Invoice PDF Export via FTP and Email

Back   Posted on 18 april 2020 / Updated on 24 january 2021
Reading time 4 minutes

Automating Invoice PDF Sending

How many times have you used Batch Invoice PDF Export? How often have you had trouble transmitting them to your accountant? What about missing files and weird sorting? You can now sit down and relax.

Billing Extension can automate the sending of invoice PDF. You can finally stop this repetitive task and reclaim precious time. You can schedule the sending of PDF files via email and FTP.

Visit Addons > Billing Extension > Settings and click the + icon in navigation bar. This opens plugin section - yes, the module is so big that it also includes plugins. Activate Invoice Archiving and go back to Settings for configuration.

Take your time to explore plugin area where you can also find things like Facebook Pixel and LinkedIn integration for WHMCS.

Customizing Filename and Directory Structure

When it comes to PDF, WHMCS is not flexible. The only thing you can customize if the prefix for invoices and proforma. That's it. The module lets you customize filenames and store them in a logical folder structure. It also handles credit notes. Below there's a list of the available auto tags that work for both FTP and email transmission.

  • {YEAR} Format yyyy (2020, 2021...)
  • {MONTH} Format mm (10, 11...)
  • {DAY} Format gg (09, 10...)
  • {NUMBER} Invoice number (tblinvoices.invoicenum)
  • {ID} Invoice ID (tblinvoices.id)
  • {TYPE} Document type (Proforma, Invoice, CreditNote)
  • {USERID} User ID
  • {COUNTRY} User country ISO 3166-1 alpha-2 (IT, US, DE...)
  • {CURRENCY} User currency (EUR, USD, AUD...)
  • {PAYMENTMETHOD} Payment gateway system name (paypal, stripe...)

It's the same principle used to customize invoice numbering. You can design folder structure and file naming conventions in seconds. An auto-tag like {COUNTRY} acts as a placeholder that in this case is replaced by customer's country. Let's see some examples.

Format Path & Filename

{YEAR}/{MONTH}/{CURRENCY}/{COUNTRY}-{NUMBER}.pdf

  • 2020/04/USD/US-Invoice 120.pdf
  • 2020/04/USD/US-Invoice 121.pdf
  • 2020/04/EUR/IT-Invoice 122.pdf
  • 2020/04/EUR/FR-Invoice 123.pdf

{YEAR}/{MONTH}/{TYPE}/{CURRENCY}-{COUNTRY}-{NUMBER}.pdf

  • 2020/04/Invoice/USD-US-Invoice 120.pdf
  • 2020/04/Invoice/USD-US-Invoice 121.pdf
  • 2020/04/CreditNote/EUR-IT-Credit Note 122.pdf
  • 2020/04/Proforma/EUR-FR-Proforma 8204.pdf

{TYPE}/{PAYMENTMETHOD}/{TYPE}-{ID}.pdf

  • Invoice/banktransfer/Invoice-120.pdf
  • Invoice/banktransfer/Invoice-121.pdf
  • Proforma/stripe/Proforma-8912.pdf
  • Proforma/paypal/Proforma-8924.pdf

There are no limits to customization. Here are a few more things to consider:

  • You can pick any tag and use it in any order
  • The same tag can be used multiple times
  • Use slash / as directory separator and .pdf as file extension
  • You can insert any other character but / \ : * ? " < > | will be replaced with -

Automatic PDF Archiving

Both FTP and email transmission follow the same automation logic. First off in order to avoid transmitting very old PDF files, Billing Extension lets you define a starting date. File transmission occurs when WHMCS daily cron job completes and is based on invoice date (more precisely on tblinvoices.date). Typically this value corresponds to:

  • Generation date for proforma
  • Issuing date for invoices and credit notes

Whenever the module completes a transmission, it stores "last run" date so that it always knows where to resume the processing in case daily cron job didn't run for some reason.

It is worth to remind you that:

  • If something goes wrong the module creates an entry in both warning system and Activiy Log
  • You can force the module to retransmit files by changing start date
  • Understand that with proforma invoicing the same document is archived twice. The first when on proforma creation and the second when it turns into an invoice
  • Files with the same name and path get overwritten

If you need more room for customization, you can take a look at the integrated web service that allows to pull data from WHMCS and ease your accounting workflow.

Transmitting Invoice PDF with FTP

After configuring directory structure and defining file naming conventions, you can instruct Billing Extension to transmit PDF on a remote FTP server. You just need to specify FTP connection details. The module automatically sends files on a daily basis right after WHMCS cron job completes.

This is particularly useful if your company uses a DMS (Document Management System) to process invoices as PDF files. This way not only you can to extract data from files but also store them in a logical folder structure. For example you can store invoices grouped by currency, payment method and so on.

Invoice PDF as Attachment with Email

As for email sending, you can schedule the transmission on a weely or monthly basis. Weekly report is sent every Monday while monthly one on the first of every month. You can schedule the sending of PDF files to multiple recipients (eg. accountant, administrative personnel, yourself).

We clear once again that you can have a different folder structure and file naming convention for FTP and the zip archive attached in the email. Last but not least, weekly report includes current week number of the year.

WHMCS & Htaccess Credentials

You may be asking yourself why our plugin requires your WHMCS credentials.

First let us underline that you can safely provide credentials - they're stored locally in your database. Passwords are encrypted using the same encryption of WHMCS.

Back to the topic, as we said earlier WHMCS isn't very flexible when it comes to PDF files. The file that prepares and prompt download is obfuscated and there's no way to apply customizations. That's how we came up with the idea of overcoming this issue coding a pretty complex PHP script that makes the following:

  • Performs .htaccess authentication when applicable
  • Logs in as administrator to WHMCS backend
  • Keeps login session
  • Downloads PDF files in PHP stream
  • Manipulates the file to apply customizations
  • Stores files on FTP server and/or as attachment via email
  • Closes connection and login

That's why the plugin requires your to provide WHMCS and .htaccess credentials. Without it there's no way to customize and archive PDF files via FTP and/or email.

Comments (0)

Speak Your Mind Cancel Reply