TWYN#52350 budgetten zijn weer aangepast!!

svn path=/Database/trunk/; revision=37181
This commit is contained in:
Erik Groener
2018-02-26 12:27:55 +00:00
parent a693581d47
commit c63c6f3e67

View File

@@ -53,16 +53,18 @@ CREATE_TRIGGER(bgt_t_bgt_budgetmutatie_B_IU)
BEFORE INSERT OR UPDATE ON bgt_budgetmutatie
FOR EACH ROW
BEGIN
-- Bij insert moet het nieuwe mutatiebedrag bij het budgetbedrag worden opgeteld.
-- Bij update moet het VERSCHIL tussen het oude- en nieuwe mutatiebedrag bij het budgetbedrag worden opgeteld.
IF (:new.bgt_budget_key_van IS NOT NULL) THEN
UPDATE bgt_budget
SET bgt_budget_bedrag = NVL(bgt_budget_bedrag, 0) + NVL(:new.bgt_budget_bedrag_van, 0)
, bgt_budget_btwbedrag = NVL(bgt_budget_btwbedrag, 0) + NVL(:new.bgt_budget_btwbedrag_van, 0)
SET bgt_budget_bedrag = NVL(bgt_budget_bedrag, 0) + (NVL(:new.bgt_budget_bedrag_van, 0) - NVL(:old.bgt_budget_bedrag_van, 0))
, bgt_budget_btwbedrag = NVL(bgt_budget_btwbedrag, 0) + (NVL(:new.bgt_budget_btwbedrag_van, 0) - NVL(:old.bgt_budget_btwbedrag_van, 0))
WHERE bgt_budget_key = :new.bgt_budget_key_van;
END IF;
IF (:new.bgt_budget_key_naar IS NOT NULL) THEN
UPDATE bgt_budget
SET bgt_budget_bedrag = NVL(bgt_budget_bedrag, 0) + NVL(:new.bgt_budget_bedrag_naar, 0)
, bgt_budget_btwbedrag = NVL(bgt_budget_btwbedrag, 0) + NVL(:new.bgt_budget_btwbedrag_naar, 0)
SET bgt_budget_bedrag = NVL(bgt_budget_bedrag, 0) + (NVL(:new.bgt_budget_bedrag_naar, 0) - NVL(:old.bgt_budget_bedrag_naar, 0))
, bgt_budget_btwbedrag = NVL(bgt_budget_btwbedrag, 0) + (NVL(:new.bgt_budget_btwbedrag_naar, 0) - NVL(:old.bgt_budget_btwbedrag_naar, 0))
WHERE bgt_budget_key = :new.bgt_budget_key_naar;
END IF;
END;