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.
WHMCS guide
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
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.
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.
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
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');
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;
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;
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
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.

$39 per year
Finds the billing records that do not add up.
DMS.S5 — Questions
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.
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.
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.
DMS.S6 — Start a project
Tell us how it got there. If other hosts would hit it, it may become a check.