Fixed calculation of Balance.even_until
This commit is contained in:
parent
abad5dc069
commit
d89ad8c580
@ -36,12 +36,13 @@ CREATE VIEW Balance AS
|
|||||||
SELECT d.debtor AS account,
|
SELECT d.debtor AS account,
|
||||||
max(d.date) AS until
|
max(d.date) AS until
|
||||||
FROM Debit d
|
FROM Debit d
|
||||||
LEFT OUTER JOIN CurrentArrears ca ON d.debtor = ca.debtor
|
LEFT OUTER JOIN (
|
||||||
GROUP BY d.debtor, ca.debtor
|
SELECT debtor, min(date) uneven_from
|
||||||
HAVING COUNT(
|
FROM CurrentArrears
|
||||||
-- Restricts the counting to the settled debts:
|
GROUP BY debtor
|
||||||
CASE d.value WHEN d.paid THEN 1 ELSE NULL END
|
) AS ca ON d.debtor=ca.debtor
|
||||||
) -- Considers that there might be no current arrears:
|
WHERE d.date < IFNULL( ca.uneven_from, '9999-99-99' )
|
||||||
AND d.date <= IFNULL( min(ca.date), '9999-99-99' )
|
GROUP BY d.debtor
|
||||||
) AS even ON Account.ID=even.account
|
) AS even ON Account.ID=even.account
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user