See image below. Payments adds up dollar for dollar to the amount I have been paid in the time frame selected. Outstanding adds up dollar for dollar to the amount of outstanding invoices that I have sent out that have not been paid yet.
I can’t however for the life of me figure out what is included in the “Invoices” roll up? I had a hunch that maybe it includes unpaid deleted invoices, but that’s not the case as that sum was off.
Invoice should be the sum of all invoices generated in the time period, grouped into their currency
SELECT
sum(invoices.amount) as invoiced_amount,
IFNULL(CAST(JSON_UNQUOTE(JSON_EXTRACT( clients.settings, '$.currency_id' )) AS SIGNED), :company_currency) AS currency_id
FROM clients
JOIN invoices
on invoices.client_id = clients.id
WHERE invoices.status_id IN (2,3,4)
AND invoices.company_id = :company_id
AND invoices.amount > 0
AND clients.is_deleted = 0
AND invoices.is_deleted = 0
AND (invoices.date BETWEEN :start_date AND :end_date)
GROUP BY currency_id
Thanks David. I explored a little bit further and found that I had an invoice which was created last year, but paid this year, and thus my payments + outstanding was larger than invoices by the amount of that invoice.