WHMCS guide

Find the unpaid invoices nobody will ever pay.

Old Unpaid invoices make the outstanding total look healthier than it is, keep overdue e-mails going to people who left years ago and hide the overdue invoices that still matter. On our own US install the second query below found three invoices more than a year overdue, the oldest due in January 2021.

DMS.S2 — Before you start

Before you run anything.

Read only

Every query below is a SELECT. It changes nothing. Run it in phpMyAdmin or the mysql client, on a copy of the database if you have one.

A list, not a verdict

Some old invoices are real debts you still intend to collect. The queries show what to look at; whether to cancel, chase or write off is your call.

Tested on sample rows

We ran each query on a test database with rows that should match and rows that should not: paid and cancelled invoices, recent ones, zero-total ones, active clients. Then we ran them on our two live installs.

DMS.S3 — The queries

Four ways to find them.

Open invoices of closed clients

The Close Clients Account link cancels Unpaid invoices. A row here means the account was closed some other way or the invoice came later, and it still counts as owed.

SELECT i.id, i.userid, i.status, i.duedate, i.total
FROM tblinvoices i
JOIN tblclients c ON c.id = i.userid
WHERE c.status = 'Closed'
  AND i.status IN ('Unpaid', 'Payment Pending');

Unpaid for more than a year

The paid and credit columns matter: Enable Auto Cancellation never cancels an invoice with a partial payment or applied credit, however old it is.

SELECT i.id, i.userid, i.duedate, i.total, i.credit,
       (SELECT COALESCE(SUM(a.amountin), 0) FROM tblaccounts a WHERE a.invoiceid = i.id) AS paid
FROM tblinvoices i
WHERE i.status = 'Unpaid'
  AND i.duedate < CURDATE() - INTERVAL 365 DAY
ORDER BY i.duedate;

Inactive clients, 90 days overdue

WHMCS marks a client Inactive when nothing active is left. The invoice stays Unpaid and, unless overdue notices are off for that client, the reminders keep going.

SELECT i.id, i.userid, i.duedate, i.total, c.overideduenotices AS overdue_notices_off
FROM tblinvoices i
JOIN tblclients c ON c.id = i.userid
WHERE c.status = 'Inactive'
  AND i.status = 'Unpaid'
  AND i.duedate < CURDATE() - INTERVAL 90 DAY
ORDER BY i.duedate;

Due before it was created

A due date typed earlier than the invoice date: the invoice is born overdue, so reminders, late fees and suspension can fire on day one, and it sorts among the oldest debts.

SELECT id, userid, date AS created, duedate, total
FROM tblinvoices
WHERE status = 'Unpaid'
  AND total > 0
  AND duedate < date;

DMS.S4 — The addon

Or get the list inside the WHMCS admin.

Brasa Billing Audit runs these checks with the rest of its billing checks, links each invoice and e-mails admins when a new one appears. It never cancels or edits an invoice.

Brasa Billing Audit screen in the WHMCS admin, with sample data

Brasa Billing Audit

$39 per year

Finds the billing records that do not add up.

  • Payment booked twice, and more money than the invoice was worth
  • Credit with no money behind it, and invoices marked Paid with nothing allocated or with every payment refunded
  • Client billed twice for one period, and a period that will never be billed
  • Suspended but paid up, a domain set to renew at 0 on a paid extension, a next due date after the registrar expiry, a late fee charged before the due date, a payment booked to no invoice or to a deleted one, a payment dated before its invoice was created, 48 checks in all
First run in 16 seconds, on sample data: the summary, then each finding with what to do about it. Brasa Billing Audit on the WHMCS Marketplace
Buy for $39

DMS.S5 — Questions

Cleaning up without losing money.

Should I cancel these invoices?

Only the ones you will not collect. Cancelling an invoice stops payment on it and, per the WHMCS documentation, does not touch the related services. On WHMCS 9.1 it also creates a credit note, so the write-off stays on record. Check with your accountant before writing off a real debt.

Can WHMCS cancel old invoices by itself?

Yes. Under Configuration > System Settings > Automation Settings, Billing Settings, turn on Enable Auto Cancellation and set Days Overdue. The daily cron then cancels Unpaid invoices older than that, except ones with a partial payment or applied credit, and lists them under Overdue Invoice Cancellations in Automation Status.

How do I stop reminders to a client who left?

Close the account with Close Clients Account on the client's Summary tab, which also cancels the Unpaid invoices, or, if the debt stands, turn off Overdue Notices on the client's Profile tab so the first, second and third overdue notices stop.