Added check so that debits cannot be linked with an incoming payment as target

This commit is contained in:
Florian "flowdy" Heß 2016-06-26 21:27:39 +02:00
parent acad2118c5
commit d915d32e3b
2 changed files with 12 additions and 3 deletions

View File

@ -58,6 +58,15 @@ BEGIN
!= (SELECT account FROM Credit WHERE Id=NEW.fromCredit)
;
SELECT RAISE(FAIL, "Target of a debit cannot be an incoming payment")
FROM Credit c
JOIN Debit d ON c.Id = d.targetCredit
WHERE c.Id = NEW.fromCredit
AND c.value > 0
GROUP BY c.Id
HAVING count(d.billId) == 0
;
INSERT INTO _temp
SELECT remainingDebt, remainingCredit, min(remainingDebt,remainingCredit)
FROM (SELECT

View File

@ -9,9 +9,9 @@ john: 0 +0 0
Club: 0 +0 -16250
alex: 7200 +16250 0
# Some updates and deletes that could, unless denied, destroy consistency ...
Error: near line 338: paid is set and adjusted automatically according to added Transfer records
Error: near line 339: Debt is involved in transfers to revoke at first
Error: near line 340: FOREIGN KEY constraint failed
Error: near line 347: paid is set and adjusted automatically according to added Transfer records
Error: near line 348: Debt is involved in transfers to revoke at first
Error: near line 349: FOREIGN KEY constraint failed
# After revoking transactions, you are free to change or delete debts and credits ...
Club: 7200 +0 0
alex: 0 +0 0