2017-01-19 21:44:22 +01:00
|
|
|
-- When we enter a transfer, the targetCredit of the associated bill might already be the credId
|
|
|
|
-- of a transfer for other dues itself. We can update (replace) the transfer for an unfullfilled one.
|
|
|
|
-- That way, a transfer may issue recursively chained transfers.
|
|
|
|
CREATE TRIGGER rebalanceIncreasedCredit
|
|
|
|
AFTER UPDATE OF value ON Credit
|
2017-01-22 21:20:17 +01:00
|
|
|
WHEN NEW.value > OLD.value
|
2017-01-19 21:44:22 +01:00
|
|
|
BEGIN
|
|
|
|
|
2017-01-22 21:20:17 +01:00
|
|
|
INSERT INTO __INTERNAL_TRIGGER_STACK
|
2017-01-22 21:39:41 +01:00
|
|
|
SELECT t.ROWID, t.billId, t.credId,
|
2017-01-22 21:20:17 +01:00
|
|
|
min(ca.difference, NEW.value - OLD.value)
|
2017-01-19 21:44:22 +01:00
|
|
|
FROM Transfer t
|
|
|
|
JOIN CurrentArrears ca ON t.billId = ca.billId
|
|
|
|
WHERE OLD.credId = t.credId
|
|
|
|
;
|
|
|
|
|
|
|
|
END;
|