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
Searching for a repeated transaction ID is the obvious check, and it can come back empty while money is still booked twice. On one of our own installs it returns nothing, yet some invoices hold two payments: one keyed by hand with no transaction ID and one from the gateway.
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.
A client may really have paid twice, or a gateway may split one payment. Check the gateway dashboard before you touch anything.
If the money arrived twice, refund it or keep it as client credit. If it was only booked twice, back up the database before correcting the ledger.
DMS.S3 — The queries
The classic case: a callback that ran two times.
SELECT gateway, transid, COUNT(*) AS times, GROUP_CONCAT(invoiceid ORDER BY id) AS invoice_ids
FROM tblaccounts
WHERE amountin > 0 AND transid <> '' AND gateway <> ''
GROUP BY gateway, transid
HAVING COUNT(*) > 1;
Catches the double that has no repeated ID. Late fees that WHMCS 9 adds as a debit note are counted as owed, so they do not show up here.
SELECT i.id AS invoice_id, i.userid AS client_id, i.total,
SUM(IF(a.gateway NOT IN ('', 'credit'), a.amountin - a.amountout, 0)) AS received,
SUM(IF(a.gateway = '' AND a.description NOT LIKE '%Overpayment%', a.amountout, 0)) AS added_later
FROM tblinvoices i
JOIN tblaccounts a ON a.invoiceid = i.id
WHERE i.total > 0
GROUP BY i.id, i.userid, i.total
HAVING received > i.total + added_later + 0.01;
Same service or domain and same due date on two invoices, at least one still open: the client is being asked to pay twice.
SELECT IF(ii.type LIKE 'Domain%', 'Domain', ii.type) AS kind, ii.relid, ii.duedate,
GROUP_CONCAT(DISTINCT CONCAT('#', i.id, ' ', i.status) ORDER BY i.id) AS invoices
FROM tblinvoiceitems ii
JOIN tblinvoices i ON i.id = ii.invoiceid
WHERE ii.type IN ('Hosting', 'Addon', 'Domain', 'DomainRegister', 'DomainRenew', 'DomainTransfer')
AND ii.relid > 0 AND ii.duedate > '1000-01-01' AND i.total > 0
AND i.status IN ('Unpaid', 'Payment Pending', 'Overdue', 'Paid')
GROUP BY kind, ii.relid, ii.duedate
HAVING COUNT(DISTINCT i.id) > 1 AND SUM(i.status <> 'Paid') > 0;
DMS.S4 — The addon
Brasa Billing Audit runs these comparisons and more, explains each finding with what to do next and e-mails admins when a new one appears. It never changes an invoice or a payment.

$39 per year
Finds the billing records that do not add up.
DMS.S5 — Questions
Refund the second payment through the gateway, or leave it as client credit if the client agrees. WHMCS then applies the credit to a later invoice.
A payment added by hand often has an empty or typed transaction ID, so it never matches the gateway one. Compare the money received with the invoice total instead.
DMS.S6 — Start a project
Tell us how it was booked. If other hosts would hit it, it may become a check.