Cross-checking the UUID against IdDocumento in Excel
The logic is crossing two lists: the UUIDs of the invoices marked as PPD, and the UUIDs each payment complement references in its IdDocumento field. Any UUID of a PPD invoice that never shows up as an IdDocumento in a REP is an invoice with no complement.
Steps
- Pull the data from inside the XML, not from the file name: from each invoice you want the UUID, the payment method (PUE or PPD), the total, and the date.
- Do the same with the payment complements: from each REP you want the IdDocumento it references and the amount paid.
- Power Query reads XML by folder, and that's enough to build both tables. A script that walks the files and dumps the fields into a sheet does the same.
- Cross the two lists and add up the amounts per UUID. What never shows up, and what shows up without covering the invoice total, is what's still open.
Where it gets stuck
- Power Query with nested XML doesn't come together in five minutes, and the CFDI 4.0 namespaces break the import when the query isn't set up right.
- The payment can arrive in a different month from the invoice, sometimes the following year. If you only cross the folder for the period you're closing, you'll flag as pending an invoice whose REP is filed somewhere else.
- A PPD invoice takes several complements, one per installment, and stays open until they add up to the total. Counting whether at least one REP exists isn't enough: you have to add up amounts.
- With hundreds of files per client, a half-exported UUID breaks the cross-check silently. The error doesn't show until the SAT notices it.