The thing that causes me trouble is that one purchase can contain the same product several times, with different quantities.
So what I want, is a report that sums up the quantity for each product per purchase for those purchases that are not already invoiced.
The basic SQL is something like
Code: Select all
SELECT *, SUM(pui_quantity) AS total_quantity FROM purchase
LEFT JOIN purchase_item ON pui_purchase_id = purchase_id
LEFT JOIN customer ON customer_id = pur_customer_id
WHERE pur_invoice_date IS NULL
GROUP BY customer_id, pui_product_id