FSN#15140
svn path=/Database/trunk/; revision=10168
This commit is contained in:
489
RES/RES_TRI.SRC
489
RES/RES_TRI.SRC
@@ -1,7 +1,7 @@
|
||||
#ifdef RES
|
||||
/*
|
||||
* $Revision: 94 $
|
||||
* $Modtime: 7-05-09 14:37 $
|
||||
* $Revision: 95 $
|
||||
* $Modtime: 30-11-09 17:44 $
|
||||
*/
|
||||
|
||||
#include "comsql.h"
|
||||
@@ -88,9 +88,6 @@ BEGIN
|
||||
UPDATE_UPPER(res_opstelling_omschrijving, res_opstelling_upper,res_opstelling);
|
||||
CHECK_NOG_REFERENCES(res_opstelling, res_opstelling_verwijder, res_ruimte_opstelling,
|
||||
res_opstelling_key, 'res_m038');
|
||||
#ifdef MS_SQL
|
||||
lerror:
|
||||
#endif
|
||||
END;
|
||||
/
|
||||
|
||||
@@ -154,9 +151,6 @@ BEGIN
|
||||
END IF;
|
||||
END;
|
||||
END IF;
|
||||
#ifdef MS_SQL
|
||||
lerror:
|
||||
#endif
|
||||
END;
|
||||
/
|
||||
|
||||
@@ -166,13 +160,6 @@ FOR EACH ROW
|
||||
BEGIN
|
||||
IF :old.res_status_bo_key=6 THEN raise_application_error(-20000, 'Reserveringsgegevens zijn verwerkt; wijzigen is niet meer toegestaan.'); END IF;
|
||||
UPDATE_PRIMARY_KEY(res_rsv_artikel_key, res_s_res_rsv_artikel_key);
|
||||
IF :new.res_status_bo_key = 6 AND :old.res_status_bo_key <> 6 AND :new.res_rsv_artikel_verwerkt IS NULL THEN
|
||||
:new.res_rsv_artikel_verwerkt := SYSDATE;
|
||||
END IF;
|
||||
IF UPDATING ('res_rsv_artikel_aantal')
|
||||
THEN
|
||||
:new.res_rsv_artikel_mutatie := SYSDATE;
|
||||
END IF;
|
||||
END;
|
||||
/
|
||||
|
||||
@@ -182,13 +169,6 @@ FOR EACH ROW
|
||||
BEGIN
|
||||
IF :old.res_status_bo_key=6 THEN raise_application_error(-20000, 'Reserveringsgegevens zijn verwerkt; wijzigen is niet meer toegestaan.'); END IF;
|
||||
UPDATE_PRIMARY_KEY(res_rsv_deel_key, res_s_res_rsv_deel_key);
|
||||
IF :new.res_status_bo_key = 6 AND :old.res_status_bo_key <> 6 AND :new.res_rsv_deel_verwerkt IS NULL THEN
|
||||
:new.res_rsv_deel_verwerkt := SYSDATE;
|
||||
END IF;
|
||||
IF UPDATING ('res_rsv_deel_aantal') OR UPDATING ('res_rsv_deel_van') OR UPDATING ('res_rsv_deel_tot')
|
||||
THEN
|
||||
:new.res_rsv_deel_mutatie := SYSDATE;
|
||||
END IF;
|
||||
END;
|
||||
/
|
||||
CREATE_TRIGGER(res_t_res_cyclus_B_IU)
|
||||
@@ -360,19 +340,8 @@ BEGIN
|
||||
BEGIN IF :new.res_rsv_ruimte_verwijder IS NOT NULL OR (:new.res_rsv_ruimte_verwijder IS NULL AND :old.res_rsv_ruimte_verwijder IS NOT NULL) THEN UPDATE res_rsv_artikel SET res_rsv_artikel_verwijder = :new.res_rsv_ruimte_verwijder WHERE res_rsv_artikel.res_rsv_ruimte_key = :new.res_rsv_ruimte_key AND res_rsv_artikel.res_rsv_artikel_verwijder IS NULL; END IF; END;
|
||||
BEGIN IF :new.res_rsv_ruimte_verwijder IS NOT NULL OR (:new.res_rsv_ruimte_verwijder IS NULL AND :old.res_rsv_ruimte_verwijder IS NOT NULL) THEN UPDATE res_rsv_deel SET res_rsv_deel_verwijder = :new.res_rsv_ruimte_verwijder WHERE res_rsv_deel.res_rsv_ruimte_key = :new.res_rsv_ruimte_key AND res_rsv_deel.res_rsv_deel_verwijder IS NULL; END IF; END;
|
||||
BEGIN IF :new.res_rsv_ruimte_verwijder IS NOT NULL THEN DELETE FROM bez_afspraak WHERE bez_afspraak.res_rsv_ruimte_key = :new.res_rsv_ruimte_key; END IF; END;
|
||||
IF :new.res_status_bo_key = 6 AND :old.res_status_bo_key <> 6 AND :new.res_rsv_ruimte_verwerkt IS NULL THEN
|
||||
:new.res_rsv_ruimte_verwerkt := SYSDATE;
|
||||
END IF;
|
||||
BEGIN IF :new.res_rsv_ruimte_host_key <> :old.res_rsv_ruimte_host_key THEN UPDATE bez_afspraak set bez_afspraak_host_key = :new.res_rsv_ruimte_host_key WHERE res_rsv_ruimte_key = :new.res_rsv_ruimte_key AND bez_afspraak_host_key IS NOT NULL; END IF; END;
|
||||
BEGIN IF :new.res_rsv_ruimte_contact_key <> :old.res_rsv_ruimte_contact_key THEN UPDATE bez_afspraak set bez_afspraak_contact_key= :new.res_rsv_ruimte_contact_key WHERE res_rsv_ruimte_key =:new.res_rsv_ruimte_key; END IF; END;
|
||||
IF UPDATING ('res_rsv_ruimte_verwijder')
|
||||
OR UPDATING ('res_ruimte_opstel_key')
|
||||
OR UPDATING ('alg_ruimte_key')
|
||||
OR UPDATING ('res_rsv_ruimte_van')
|
||||
OR UPDATING ('res_rsv_ruimte_tot')
|
||||
THEN
|
||||
:new.res_rsv_ruimte_mutatie := SYSDATE;
|
||||
END IF;
|
||||
END;
|
||||
/
|
||||
|
||||
@@ -412,460 +381,6 @@ BEGIN
|
||||
END;
|
||||
/
|
||||
|
||||
CREATE_TRIGGER(res_t_notificatie_rsv_ruimte)
|
||||
AFTER INSERT OR UPDATE
|
||||
ON res_rsv_ruimte
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
-- Proc+edure to create a notification to the enduser that requested the reservation
|
||||
-- pReceiver is optional, if it's null we'll look for the receiver ourself.
|
||||
-- Note that since 4.70 most info is at res_rsv_ruimte level, not res_reservering
|
||||
-- Sometimes we delete previous notifications first
|
||||
DECLARE
|
||||
soms fac_srtnotificatie.fac_srtnotificatie_oms%TYPE;
|
||||
scode fac_srtnotificatie.fac_srtnotificatie_code%TYPE;
|
||||
lomschrijving res_rsv_ruimte.res_rsv_ruimte_omschrijving%TYPE;
|
||||
lstatuswijziging BOOLEAN;
|
||||
sgroep BOOLEAN; -- bepaalt of res_key of rsv_ruimte_key als parameter moet
|
||||
lrefkey res_reservering.res_reservering_key%TYPE;
|
||||
lxrefkey res_rsv_ruimte.res_rsv_ruimte_key%TYPE;
|
||||
skey VARCHAR2 (30);
|
||||
lnotify res_disc_params.res_disc_params_notify%TYPE;
|
||||
lsender fac_notificatie.fac_notificatie_sender_email%TYPE;
|
||||
BEGIN
|
||||
lstatuswijziging := FALSE;
|
||||
|
||||
IF (:NEW.res_ruimte_opstel_key IS NULL AND :NEW.alg_ruimte_key IS NULL)
|
||||
THEN
|
||||
-- Een reservering zonder plaats is (nog) geen reservering!
|
||||
scode := NULL;
|
||||
ELSIF (:OLD.res_ruimte_opstel_key IS NULL AND :NEW.res_ruimte_opstel_key IS NOT NULL)
|
||||
OR (:OLD.alg_ruimte_key IS NULL AND :NEW.alg_ruimte_key IS NOT NULL)
|
||||
THEN
|
||||
-- Een reservering is nieuwe als plaats bekend is gemaakt
|
||||
scode := 'RESNEW';
|
||||
sgroep := TRUE;
|
||||
ELSIF :NEW.res_status_bo_key = 5 AND :OLD.res_status_bo_key <> 5
|
||||
THEN
|
||||
scode := 'RESAFM';
|
||||
sgroep := FALSE;
|
||||
ELSIF :NEW.res_status_bo_key = 6 AND :OLD.res_status_bo_key <> 6
|
||||
THEN
|
||||
scode := 'RESVER';
|
||||
sgroep := FALSE;
|
||||
ELSIF :NEW.res_rsv_ruimte_verwijder IS NOT NULL AND :OLD.res_rsv_ruimte_verwijder IS NULL
|
||||
THEN
|
||||
scode := 'RESDEL';
|
||||
sgroep := FALSE;
|
||||
ELSIF :NEW.res_rsv_ruimte_verwijder IS NULL
|
||||
THEN
|
||||
-- Alleen mekkeren over FO-statuswijzigingen als deze niet verwijderd is/wordt
|
||||
IF :NEW.res_status_fo_key = 1 AND :OLD.res_status_fo_key <> 1
|
||||
THEN
|
||||
scode := 'RESOPT';
|
||||
lstatuswijziging := TRUE;
|
||||
sgroep := FALSE;
|
||||
ELSIF :NEW.res_status_fo_key = 2 AND :OLD.res_status_fo_key <> 2
|
||||
THEN
|
||||
scode := 'RESBEV';
|
||||
lstatuswijziging := TRUE;
|
||||
sgroep := FALSE;
|
||||
ELSIF :NEW.res_status_fo_key = 4 AND :OLD.res_status_fo_key <> 4
|
||||
THEN
|
||||
scode := 'RESDEL';
|
||||
lstatuswijziging := TRUE;
|
||||
sgroep := FALSE;
|
||||
ELSIF :NEW.res_ruimte_opstel_key <> :OLD.res_ruimte_opstel_key
|
||||
OR :NEW.res_rsv_ruimte_van <> :OLD.res_rsv_ruimte_van
|
||||
OR :NEW.res_rsv_ruimte_tot <> :OLD.res_rsv_ruimte_tot
|
||||
OR :NEW.res_activiteit_key <> :OLD.res_activiteit_key
|
||||
OR :NEW.res_rsv_ruimte_bezoekers <> :OLD.res_rsv_ruimte_bezoekers
|
||||
THEN
|
||||
scode := 'RESUPD';
|
||||
sgroep := TRUE;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
lrefkey := :NEW.res_reservering_key;
|
||||
IF sgroep
|
||||
THEN
|
||||
lxrefkey := NULL;
|
||||
ELSE
|
||||
lxrefkey := :NEW.res_rsv_ruimte_key;
|
||||
END IF;
|
||||
|
||||
-- tricky: asp doet eerst halve insert en dan update van de rest. Bij de update is pas de opstelling bekend.
|
||||
lnotify := NULL;
|
||||
IF :new.res_ruimte_opstel_key IS NOT NULL
|
||||
THEN
|
||||
SELECT res_disc_params_notify
|
||||
INTO lnotify
|
||||
FROM res_disc_params rdp, res_ruimte rr, res_ruimte_opstelling rro
|
||||
WHERE rro.res_ruimte_key = rr.res_ruimte_key
|
||||
AND rr.res_discipline_key = rdp.res_ins_discipline_key
|
||||
AND rro.res_ruimte_opstel_key = :new.res_ruimte_opstel_key;
|
||||
END IF;
|
||||
|
||||
IF scode IS NOT NULL AND lnotify = 1
|
||||
THEN
|
||||
BEGIN
|
||||
SELECT sn.fac_srtnotificatie_oms
|
||||
INTO soms
|
||||
FROM fac_srtnotificatie sn
|
||||
WHERE sn.fac_srtnotificatie_code = scode AND sn.fac_srtnotificatie_mode > 0;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND
|
||||
THEN
|
||||
-- Nothing to do
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
-- We support substitution of placeholders in the messages
|
||||
-- ##DESC## = res_rsv_ruimte_omschrijving
|
||||
-- ##KEY## = res_reservering_key
|
||||
IF INSTR2(soms, '#') > 0
|
||||
THEN
|
||||
IF sgroep
|
||||
THEN
|
||||
skey := :NEW.res_reservering_key;
|
||||
ELSE
|
||||
skey := :NEW.res_reservering_key || '/' || :NEW.res_rsv_ruimte_volgnr;
|
||||
END IF;
|
||||
|
||||
soms := REPLACE (REPLACE (soms, '##DESC##', :NEW.res_rsv_ruimte_omschrijving), '##KEY##', skey);
|
||||
END IF;
|
||||
|
||||
-- Stuur notificatie naar de aanvrager
|
||||
IF lstatuswijziging
|
||||
THEN
|
||||
-- eventuele voorgaande statuswijzigingen wissen
|
||||
fac.clrnotifications ('RESOPT', lrefkey);
|
||||
fac.clrnotifications ('RESDEL', lrefkey);
|
||||
fac.clrnotifications ('RESBEV', lrefkey);
|
||||
END IF;
|
||||
BEGIN
|
||||
-- Bepaal afzender, afhankelijk van catalogus (als res_ruimte) of anders de locatie
|
||||
IF :NEW.res_ruimte_opstel_key IS NOT NULL
|
||||
THEN
|
||||
SELECT COALESCE (MAX (d.ins_discipline_email), MAX (l.alg_locatie_email))
|
||||
INTO lsender
|
||||
FROM res_ruimte_opstelling ro,
|
||||
res_ruimte rr,
|
||||
res_alg_ruimte rag,
|
||||
alg_ruimte r,
|
||||
alg_verdieping v,
|
||||
alg_gebouw g,
|
||||
alg_locatie l,
|
||||
ins_tab_discipline d
|
||||
WHERE l.alg_locatie_key = g.alg_locatie_key
|
||||
AND g.alg_gebouw_key = v.alg_gebouw_key
|
||||
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||
AND r.alg_ruimte_key = rag.alg_ruimte_key
|
||||
AND rag.res_ruimte_key = rr.res_ruimte_key
|
||||
AND d.ins_discipline_key = rr.res_discipline_key
|
||||
AND rr.res_ruimte_key = ro.res_ruimte_key
|
||||
AND ro.res_ruimte_opstel_key = :NEW.res_ruimte_opstel_key;
|
||||
ELSIF :NEW.alg_ruimte_key IS NOT NULL
|
||||
THEN
|
||||
SELECT MAX (l.alg_locatie_email)
|
||||
INTO lsender
|
||||
FROM alg_ruimte r, alg_verdieping v, alg_gebouw g, alg_locatie l
|
||||
WHERE l.alg_locatie_key = g.alg_locatie_key
|
||||
AND g.alg_gebouw_key = v.alg_gebouw_key
|
||||
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||
AND r.alg_ruimte_key = :NEW.alg_ruimte_key;
|
||||
ELSE
|
||||
lsender := NULL;
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND
|
||||
THEN
|
||||
lsender := NULL;
|
||||
END;
|
||||
|
||||
fac.clrnotifications (scode, :NEW.res_reservering_key);
|
||||
fac.putnotificationsrtprio (NULL, :NEW.res_rsv_ruimte_contact_key, scode, lrefkey, soms, NULL, NULL, NULL, lxrefkey, 2, lsender);
|
||||
END IF;
|
||||
END;
|
||||
END;
|
||||
/
|
||||
|
||||
CREATE_TRIGGER(res_t_notificatie_rsv_deel)
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON res_rsv_deel
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
-- Only 1 message is visible to that user. If new events occur that would issue a
|
||||
-- new notification, the old message is deleted first.
|
||||
-- Note that since 4.70 most info is at res_rsv_ruimte level, not res_reservering
|
||||
DECLARE
|
||||
soms fac_srtnotificatie.fac_srtnotificatie_oms%TYPE;
|
||||
scode fac_srtnotificatie.fac_srtnotificatie_code%TYPE;
|
||||
lomschrijving res_rsv_ruimte.res_rsv_ruimte_omschrijving%TYPE;
|
||||
lreskey res_rsv_ruimte.res_reservering_key%TYPE;
|
||||
lresrsvruimteomschrijving res_rsv_ruimte.res_rsv_ruimte_omschrijving%TYPE;
|
||||
lresrsvruimtecontactkey res_rsv_ruimte.res_rsv_ruimte_contact_key%TYPE;
|
||||
lresrsvruimtekey res_rsv_ruimte.res_rsv_ruimte_key%TYPE;
|
||||
lnotify res_disc_params.res_disc_params_notify%TYPE;
|
||||
lresruimteopstelkey res_rsv_ruimte.res_ruimte_opstel_key%TYPE;
|
||||
lalgruimtekey res_rsv_ruimte.alg_ruimte_key%TYPE;
|
||||
lsender fac_notificatie.fac_notificatie_sender_email%TYPE;
|
||||
BEGIN
|
||||
lresrsvruimtekey := NVL(:new.res_rsv_ruimte_key, :old.res_rsv_ruimte_key);
|
||||
IF lresrsvruimtekey IS NULL
|
||||
THEN
|
||||
-- parkeerplaats
|
||||
RETURN;
|
||||
END IF;
|
||||
-- scode := 'RESNEW'; parent heeft deze voor losse voorziening niet genotificeerd
|
||||
-- scode := 'RESAFM'; veronderstellen we ook hooguit interessant indien dat op hoger niveau gebeurt
|
||||
-- scode := 'RESVER'; veronderstellen we ook hooguit interessant indien dat op hoger niveau gebeurt
|
||||
-- scode := 'RESBEV'; hoeft nooit genotificeerd te worden, daarvoor heeft een parent altijd al gezorgd
|
||||
-- scode := 'RESDEL'; hoeft nooit genotificeerd te worden, daarvoor heeft een parent altijd al gezorgd
|
||||
IF (:new.res_deel_key IS NOT NULL AND :old.res_deel_key IS NULL)
|
||||
THEN
|
||||
-- insert
|
||||
scode := 'RESNEW';
|
||||
ELSIF (:new.res_rsv_deel_van <> :OLD.res_rsv_deel_van)
|
||||
OR (:new.res_rsv_deel_tot <> :OLD.res_rsv_deel_tot)
|
||||
OR (:new.res_rsv_deel_verwijder IS NOT NULL AND :OLD.res_rsv_deel_verwijder IS NULL)
|
||||
OR :new.res_rsv_deel_key IS NULL
|
||||
THEN
|
||||
-- nb: een echte delete notificeren we dus niet echt; komt deze voor?
|
||||
scode := 'RESUPD';
|
||||
END IF;
|
||||
lnotify := NULL;
|
||||
IF :new.res_deel_key IS NOT NULL
|
||||
THEN
|
||||
SELECT res_disc_params_notify
|
||||
INTO lnotify
|
||||
FROM res_disc_params rdp, res_deel rd
|
||||
WHERE rd.res_discipline_key = rdp.res_ins_discipline_key
|
||||
AND rd.res_deel_key = :new.res_deel_key;
|
||||
END IF;
|
||||
|
||||
IF scode IS NOT NULL AND lnotify = 1
|
||||
THEN
|
||||
BEGIN
|
||||
SELECT sn.fac_srtnotificatie_oms
|
||||
INTO soms
|
||||
FROM fac_srtnotificatie sn
|
||||
WHERE sn.fac_srtnotificatie_code = scode AND sn.fac_srtnotificatie_mode > 0;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND
|
||||
THEN
|
||||
-- Nothing to do
|
||||
RETURN;
|
||||
END;
|
||||
BEGIN
|
||||
SELECT res_reservering_key, res_rsv_ruimte_omschrijving, res_rsv_ruimte_contact_key, res_ruimte_opstel_key, alg_ruimte_key
|
||||
INTO lreskey, lresrsvruimteomschrijving, lresrsvruimtecontactkey, lresruimteopstelkey, lalgruimtekey
|
||||
FROM res_rsv_ruimte
|
||||
WHERE res_rsv_ruimte_key = lresrsvruimtekey;
|
||||
EXCEPTION
|
||||
WHEN OTHERS
|
||||
THEN
|
||||
-- vangnet: liever geen notificatie dan geen updates
|
||||
-- waarschijnlijk een 4091: dan komt deze trigger via een update van de parent
|
||||
-- Dan notificeert die zelf wel.
|
||||
RETURN;
|
||||
END;
|
||||
-- We support substitution of placeholders in the messages
|
||||
-- ##DESC## = res_rsv_ruimte_omschrijving
|
||||
-- ##KEY## = res_reservering_key
|
||||
IF INSTR2(soms, '#') > 0
|
||||
THEN
|
||||
soms := REPLACE (REPLACE (soms, '##DESC##', lresrsvruimteomschrijving), '##KEY##', lreskey);
|
||||
END IF;
|
||||
-- Bepaal afzender, afhankelijk van catalogus of anders de locatie
|
||||
BEGIN
|
||||
SELECT ins_discipline_email
|
||||
INTO lsender
|
||||
FROM ins_tab_discipline d, res_deel r
|
||||
WHERE d.ins_discipline_key = r.res_discipline_key AND r.res_deel_key = :NEW.res_deel_key;
|
||||
|
||||
IF lsender IS NULL
|
||||
THEN
|
||||
IF lresruimteopstelkey IS NOT NULL
|
||||
THEN
|
||||
SELECT MAX (l.alg_locatie_email)
|
||||
INTO lsender
|
||||
FROM res_ruimte_opstelling ro,
|
||||
res_ruimte rr,
|
||||
res_alg_ruimte rag,
|
||||
alg_ruimte r,
|
||||
alg_verdieping v,
|
||||
alg_gebouw g,
|
||||
alg_locatie l
|
||||
WHERE l.alg_locatie_key = g.alg_locatie_key
|
||||
AND g.alg_gebouw_key = v.alg_gebouw_key
|
||||
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||
AND r.alg_ruimte_key = rag.alg_ruimte_key
|
||||
AND rag.res_ruimte_key = rr.res_ruimte_key
|
||||
AND rr.res_ruimte_key = ro.res_ruimte_key
|
||||
AND ro.res_ruimte_opstel_key = lresruimteopstelkey;
|
||||
ELSIF lalgruimtekey IS NOT NULL
|
||||
THEN
|
||||
SELECT MAX (l.alg_locatie_email)
|
||||
INTO lsender
|
||||
FROM alg_ruimte r, alg_verdieping v, alg_gebouw g, alg_locatie l
|
||||
WHERE l.alg_locatie_key = g.alg_locatie_key
|
||||
AND g.alg_gebouw_key = v.alg_gebouw_key
|
||||
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||
AND r.alg_ruimte_key = lalgruimtekey;
|
||||
END IF;
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND
|
||||
THEN
|
||||
lsender := NULL;
|
||||
END;
|
||||
|
||||
fac.clrnotifications (scode, lreskey);
|
||||
fac.putnotificationsrtprio (NULL, lresrsvruimtecontactkey, scode, lreskey, soms, NULL, NULL, NULL, NULL, 2, lsender);
|
||||
END IF;
|
||||
END;
|
||||
END;
|
||||
/
|
||||
|
||||
CREATE_TRIGGER(res_t_notificatie_rsv_artikel)
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON res_rsv_artikel
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
-- Only 1 message is visible to that user. If new events occur that would issue a
|
||||
-- new notification, the old message is deleted first.
|
||||
-- Note that since 4.70 most info is at res_rsv_ruimte level, not res_reservering
|
||||
DECLARE
|
||||
soms fac_srtnotificatie.fac_srtnotificatie_oms%TYPE;
|
||||
scode fac_srtnotificatie.fac_srtnotificatie_code%TYPE;
|
||||
lomschrijving res_rsv_ruimte.res_rsv_ruimte_omschrijving%TYPE;
|
||||
lreskey res_rsv_ruimte.res_reservering_key%TYPE;
|
||||
lresrsvruimteomschrijving res_rsv_ruimte.res_rsv_ruimte_omschrijving%TYPE;
|
||||
lresrsvruimtecontactkey res_rsv_ruimte.res_rsv_ruimte_contact_key%TYPE;
|
||||
lresrsvruimtekey res_rsv_ruimte.res_rsv_ruimte_key%TYPE;
|
||||
lnotify res_disc_params.res_disc_params_notify%TYPE;
|
||||
lresruimteopstelkey res_rsv_ruimte.res_ruimte_opstel_key%TYPE;
|
||||
lalgruimtekey res_rsv_ruimte.alg_ruimte_key%TYPE;
|
||||
lsender fac_notificatie.fac_notificatie_sender_email%TYPE;
|
||||
BEGIN
|
||||
lresrsvruimtekey := NVL (:NEW.res_rsv_ruimte_key, :OLD.res_rsv_ruimte_key);
|
||||
|
||||
-- scode := 'RESNEW'; parent heeft deze voor losse catering niet genotificeerd
|
||||
-- scode := 'RESAFM'; veronderstellen we ook hooguit interessant indien dat op hoger niveau gebeurt
|
||||
-- scode := 'RESVER'; veronderstellen we ook hooguit interessant indien dat op hoger niveau gebeurt
|
||||
-- scode := 'RESBEV'; hoeft nooit genotificeerd te worden, daarvoor heeft een parent altijd al gezorgd
|
||||
-- scode := 'RESDEL'; hoeft nooit genotificeerd te worden, daarvoor heeft een parent altijd al gezorgd
|
||||
IF (:new.res_artikel_key IS NOT NULL AND :old.res_artikel_key IS NULL)
|
||||
THEN
|
||||
-- insert
|
||||
scode := 'RESNEW';
|
||||
ELSIF :OLD.res_rsv_artikel_aantal IS NULL
|
||||
OR :new.res_rsv_artikel_aantal <> :OLD.res_rsv_artikel_aantal
|
||||
OR (:new.res_rsv_artikel_levering IS NOT NULL AND :OLD.res_rsv_artikel_levering IS NULL)
|
||||
OR (:new.res_rsv_artikel_verwijder IS NOT NULL AND :OLD.res_rsv_artikel_verwijder IS NULL)
|
||||
OR :new.res_rsv_artikel_key IS NULL --was deleted
|
||||
THEN
|
||||
-- nb: een echte delete notificeren we dus niet echt als delete
|
||||
scode := 'RESUPD';
|
||||
END IF;
|
||||
|
||||
lnotify := NULL;
|
||||
IF :new.res_artikel_key IS NOT NULL
|
||||
THEN
|
||||
SELECT res_disc_params_notify
|
||||
INTO lnotify
|
||||
FROM res_disc_params rdp, res_artikel ra
|
||||
WHERE ra.res_discipline_key = rdp.res_ins_discipline_key
|
||||
AND ra.res_artikel_key = :new.res_artikel_key;
|
||||
END IF;
|
||||
|
||||
IF scode IS NOT NULL AND lnotify = 1
|
||||
THEN
|
||||
BEGIN
|
||||
SELECT sn.fac_srtnotificatie_oms
|
||||
INTO soms
|
||||
FROM fac_srtnotificatie sn
|
||||
WHERE sn.fac_srtnotificatie_code = scode AND sn.fac_srtnotificatie_mode > 0;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND
|
||||
THEN
|
||||
-- Nothing to do
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
BEGIN
|
||||
SELECT res_reservering_key, res_rsv_ruimte_omschrijving, res_rsv_ruimte_contact_key, res_ruimte_opstel_key, alg_ruimte_key
|
||||
INTO lreskey, lresrsvruimteomschrijving, lresrsvruimtecontactkey, lresruimteopstelkey, lalgruimtekey
|
||||
FROM res_rsv_ruimte
|
||||
WHERE res_rsv_ruimte_key = lresrsvruimtekey;
|
||||
EXCEPTION
|
||||
WHEN OTHERS
|
||||
THEN
|
||||
-- vangnet: liever geen notificatie dan geen updates
|
||||
-- waarschijnlijk een 4091: dan komt deze trigger via een update van de parent
|
||||
-- Dan notificeert die zelf wel.
|
||||
RETURN;
|
||||
END;
|
||||
|
||||
-- We support substitution of placeholders in the messages
|
||||
-- ##DESC## = res_rsv_ruimte_omschrijving
|
||||
-- ##KEY## = res_reservering_key
|
||||
IF INSTR2(soms, '#') > 0
|
||||
THEN
|
||||
soms := REPLACE (REPLACE (soms, '##DESC##', lresrsvruimteomschrijving), '##KEY##', lreskey);
|
||||
END IF;
|
||||
-- Bepaal afzender, afhankelijk van catalogus of anders de locatie
|
||||
BEGIN
|
||||
SELECT ins_discipline_email
|
||||
INTO lsender
|
||||
FROM ins_tab_discipline d, res_artikel a
|
||||
WHERE d.ins_discipline_key = a.res_discipline_key AND a.res_artikel_key = :NEW.res_artikel_key;
|
||||
|
||||
IF lsender IS NULL
|
||||
THEN
|
||||
IF lresruimteopstelkey IS NOT NULL
|
||||
THEN
|
||||
SELECT MAX (l.alg_locatie_email)
|
||||
INTO lsender
|
||||
FROM res_ruimte_opstelling ro,
|
||||
res_ruimte rr,
|
||||
res_alg_ruimte rag,
|
||||
alg_ruimte r,
|
||||
alg_verdieping v,
|
||||
alg_gebouw g,
|
||||
alg_locatie l
|
||||
WHERE l.alg_locatie_key = g.alg_locatie_key
|
||||
AND g.alg_gebouw_key = v.alg_gebouw_key
|
||||
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||
AND r.alg_ruimte_key = rag.alg_ruimte_key
|
||||
AND rag.res_ruimte_key = rr.res_ruimte_key
|
||||
AND rr.res_ruimte_key = ro.res_ruimte_key
|
||||
AND ro.res_ruimte_opstel_key = lresruimteopstelkey;
|
||||
ELSIF lalgruimtekey IS NOT NULL
|
||||
THEN
|
||||
SELECT MAX (l.alg_locatie_email)
|
||||
INTO lsender
|
||||
FROM alg_ruimte r, alg_verdieping v, alg_gebouw g, alg_locatie l
|
||||
WHERE l.alg_locatie_key = g.alg_locatie_key
|
||||
AND g.alg_gebouw_key = v.alg_gebouw_key
|
||||
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||
AND r.alg_ruimte_key = lalgruimtekey;
|
||||
END IF;
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN NO_DATA_FOUND
|
||||
THEN
|
||||
lsender := NULL;
|
||||
END;
|
||||
|
||||
fac.clrnotifications (scode, lreskey);
|
||||
fac.putnotificationsrtprio (NULL, lresrsvruimtecontactkey, scode, lreskey, soms, NULL, NULL, NULL, NULL, 2, lsender);
|
||||
END IF;
|
||||
END;
|
||||
END;
|
||||
/
|
||||
|
||||
CREATE_TRIGGER(res_t_res_activiteitdisc_B_IU)
|
||||
BEFORE INSERT OR UPDATE ON res_activiteitdiscipline
|
||||
FOR EACH ROW
|
||||
|
||||
Reference in New Issue
Block a user