Match to purchase orders
Match a received invoice to your own purchase order by its reference, with a fallback on the supplier and the total.
On this page
The gateway does not hold your purchase orders. It gives you the fields to match on, and your software decides. A received invoice carries reference, which is the reference the supplier printed on it, usually the number of your purchase order. It is empty when the supplier printed none.
What to match on
| Field | Use |
|---|---|
reference | First choice. Compare it with the number of your purchase order. |
partnerCif | The supplier. Use it when reference is empty, or to confirm a match. |
total | The amount with VAT. Compare it with the total of the order and its VAT. |
lines | The code, quantity and unitPrice of each line, for a match line by line. |
Match what you downloaded
Read the received invoices of a company page by page, and match each against your orders. Compare amounts as decimal strings or in the smallest unit of the currency; never as floating-point numbers.
const base = process.env.RDC_BASE_URL;
const headers = {Authorization: `Bearer ${process.env.RDC_TOKEN}`};
async function receivedInvoices(companyId) {
const found = [];
let cursor = null;
do {
const query = new URLSearchParams({companyId, limit: '100'});
if (cursor) query.set('cursor', cursor);
const response = await fetch(`${base}/efactura/v1/received-invoices?${query}`, {headers});
const page = await response.json();
for (const item of page.items) found.push(item);
cursor = page.nextCursor;
} while (cursor);
return found;
}
// orders: [{number, supplierCif, total}] from your own system
function orderOf(invoice, orders) {
const byReference = orders.find(order => invoice.reference !== '' && order.number === invoice.reference);
if (byReference) return byReference;
return orders.find(order => order.supplierCif === invoice.partnerCif && order.total === invoice.total);
}