Improved by RLT

svn path=/Database/trunk/; revision=7879
This commit is contained in:
Peter Feij
2001-11-05 09:33:00 +00:00
parent 33ba3bdec8
commit 9b632aa4d8
3 changed files with 184 additions and 42 deletions

View File

@@ -5,5 +5,12 @@
* 03-11-20000 PF CREATION (concept).
*/
create index bes_i_bes_bestelling_item2 on bes_bestelling_item(bes_bestelling_item_status);
create index bes_i_bes_bestelling2 on bes_bestelling(bes_bestelling_status);
create index bes_i_bes_bestelopdr2 on bes_bestelopdr(bes_bestelopdr_status);
create index bes_bes_bestelopdrstate1 on bes_bestelopdrstate(bes_bestelopdrstate,bes_bestelopdr_key)
create index bes_bes_bestellingstate1 on bes_bestellingstate(bes_bestellingstate,bes_bestelling_key)
#endif // BES

View File

@@ -38,8 +38,6 @@ CREATE_TABLE(bes_bestelling,BES_BIBLIOTHEEK_PRIVILEGE)
CONSTRAINT bes_r_alg_locatie_key2 REFERENCES alg_locatie(alg_locatie_key),
bes_bestelling_opmerking
VARCHAR2(320),
bes_bestelling_melder_naam
VARCHAR2(30),
bes_bestelling_document
LONG RAW,
bes_bestelling_documentnaam
@@ -55,7 +53,7 @@ CREATE_TABLE(bes_bestelling,BES_BIBLIOTHEEK_PRIVILEGE)
AND bes_bestelling_opmerking IS NOT NULL)));
CREATE_TABLE(bes_bestelopdr, BES_BIBLIOTHEEK_PRIVILEGE)
(
bes_bestelopdr_key
bes_bestelopdr_key
NUMBER(10)
CONSTRAINT bes_k_bes_bestelopdr_key PRIMARY KEY,
bes_bestelopdr_module
@@ -68,32 +66,31 @@ CREATE_TABLE(bes_bestelopdr, BES_BIBLIOTHEEK_PRIVILEGE)
bes_bestelopdr_datum
DATE
DEFAULT SYSDATE,
mld_adres_key_lev
mld_adres_key_lev
NUMBER(10)
CONSTRAINT bes_r_mld_adres_key1 REFERENCES mld_adres(mld_adres_key),
mld_adres_key_fac
mld_adres_key_fac
NUMBER(10)
CONSTRAINT bes_r_mld_adres_key_fac1 REFERENCES mld_adres(mld_adres_key),
bes_bestelopdr_leverdatum
bes_bestelopdr_leverdatum
DATE,
bes_bestelopdr_opmerking
bes_bestelopdr_opmerking
VARCHAR2(320),
cnt_contract_key
cnt_contract_key
NUMBER(10),
prs_perslid_key
NUMBER(10)
CONSTRAINT bes_r_opdr_prs_user_key1 REFERENCES prs_perslid(prs_perslid_key)
);
CREATE_TABLE(bes_bestelling_item, BES_BIBLIOTHEEK_PRIVILEGE)
(
bes_bestelling_item_key
NUMBER(10)
CONSTRAINT bes_k_bes_bestelling_item_key PRIMARY KEY,
bes_bestelling_key
bes_bestelling_key
NUMBER(10)
CONSTRAINT bes_c_bes_bestelling_key CHECK(bes_bestelling_key IS NOT NULL)
CONSTRAINT bes_r_bes_bestelling_key1 REFERENCES bes_bestelling(bes_bestelling_key),
CONSTRAINT bes_r_bes_bestelling_key1 REFERENCES bes_bestelling(bes_bestelling_key) ON DELETE CASCADE,
ins_srtdeel_key
NUMBER(10)
CONSTRAINT bes_c_ins_srtdeel_key1 CHECK(ins_srtdeel_key IS NOT NULL)
@@ -106,10 +103,14 @@ CREATE_TABLE(bes_bestelling_item, BES_BIBLIOTHEEK_PRIVILEGE)
CONSTRAINT bes_r_bes_bestelopdr_key1 REFERENCES bes_bestelopdr(bes_bestelopdr_key),
bes_bestelling_i_gcpt_us_key
NUMBER(10)
CONSTRAINT bes_r_prs_user_key4 REFERENCES prs_perslid(prs_perslid_key)
CONSTRAINT bes_r_prs_user_key4 REFERENCES prs_perslid(prs_perslid_key),
bes_bestelopdr_status
NUMBER(1),
bes_bestelling_item_aantalontv
NUMBER(5),
bes_bestelling_item_changed
NUMBER(1)
);
CREATE_TABLE(bes_bestelopdr_item, BES_BIBLIOTHEEK_PRIVILEGE)
(
bes_bestelopdr_item_key
@@ -125,14 +126,15 @@ CREATE_TABLE(bes_bestelopdr_item, BES_BIBLIOTHEEK_PRIVILEGE)
NUMBER(5)
CONSTRAINT bes_c_bes_bestelopdr_i_aantal CHECK(bes_bestelopdr_item_aantal IS NOT NULL),
bes_bestelopdr_item_aantalontv
NUMBER(5)
CONSTRAINT bes_c_bes_bestelopdr_i_antltv CHECK(bes_bestelopdr_item_aantalontv IS NOT NULL),
bes_bestelopdr_item_omschrijv
NUMBER(5),
bes_bestelopdr_item_omschrijv
VARCHAR2(320),
bes_bestelopdr_item_prijs
bes_bestelopdr_item_prijs
NUMBER(8,2),
bes_bestelopdr_item_ontvangen
DATE
bes_bestelopdr_item_ontvangen
DATE,
bes_bestelopdr_item_changed
NUMBER(1)
);
ALTER TABLE INS_SRTDEEL
@@ -153,9 +155,12 @@ ALTER TABLE PRS_BEDRIJF
ADD
(
prs_bedrijf_email
VARCHAR2(32)
VARCHAR2(32),
prs_bedrijf_XSL
VARCHAR2(256)
);
CREATE_TABLE(bes_bestellingstatuses,BES_BIBLIOTHEEK_PRIVILEGE)
(
bes_bestellingstatuses_key
@@ -173,4 +178,20 @@ CREATE_TABLE(bes_bestelopdrstatuses,BES_BIBLIOTHEEK_PRIVILEGE)
VARCHAR2(30)
);
CREATE_TABLE(bes_bestelopdrstate,BES_BIBLIOTHEEK_PRIVILEGE)
(
bes_bestelopdr_key
NUMBER(10),
bes_bestelopdrstate
NUMBER(1)
);
CREATE_TABLE(bes_bestellingstate,BES_BIBLIOTHEEK_PRIVILEGE)
(
bes_bestelling_key
NUMBER(10),
bes_bestellingstate
NUMBER(1)
);
#endif // BES

View File

@@ -8,35 +8,24 @@
#include "comsql.h"
CREATE_TRIGGER(bes_t_bes_bestelling_B_IU)
BEFORE INSERT OR UPDATE ON bes_bestelling
FOR EACH ROW
BEGIN
UPDATE_PRIMARY_KEY(bes_bestelling_key,bes_s_bes_bestelling_key);
IF :new.BES_BESTELLING_DATUM is not null and
IF :new.BES_BESTELLING_DATUM is not null and
:old.BES_BESTELLING_DATUM is null THEN :new.BES_BESTELLING_STATUS := 2;
ELSIF (:new.BES_BESTELLING_AFGEWEZEN is not null and
ELSIF (:new.BES_BESTELLING_AFGEWEZEN is not null and
:old.BES_BESTELLING_AFGEWEZEN is null) OR
(:new.BES_BESTELLING_AFGEWEZEN is not null and
(:new.BES_BESTELLING_AFGEWEZEN is not null and
:old.BES_BESTELLING_AFGEWEZEN is not null and
:new.BES_BESTELLING_AFGEWEZEN <> :old.BES_BESTELLING_AFGEWEZEN) THEN
:new.BES_BESTELLING_AFGEWEZEN <> :old.BES_BESTELLING_AFGEWEZEN) THEN
BEGIN
IF :new.BES_BESTELLING_OPMERKING is not null THEN
:new.BES_BESTELLING_STATUS := 1;
ELSE
APPLICATION_ERROR(-20000, 'BES_NO_REJECTED_MESSAGE');
ELSE
raise_application_error(-20000, 'BES_NO_REJECTED_MESSAGE');
END IF;
END;
ELSIF :new.BES_BESTELLING_AFGEMELD is not null and
:old.BES_BESTELLING_AFGEMELD is null THEN :new.BES_BESTELLING_STATUS := 6;
ELSIF :new.BES_BESTELLING_GEACCEPTEERD is not null and
:old.BES_BESTELLING_GEACCEPTEERD is null THEN :new.BES_BESTELLING_STATUS := 4;
ELSIF :new.BES_BESTELLING_GEACCEPTEERD is not null and
:old.BES_BESTELLING_GEACCEPTEERD is not null and
:new.BES_BESTELLING_GEACCEPTEERD <> :old.BES_BESTELLING_GEACCEPTEERD THEN :new.BES_BESTELLING_STATUS := 5;
ELSIF :new.BES_BESTELLING_VERWERKT is not null and
ELSIF :new.BES_BESTELLING_VERWERKT is not null and
:old.BES_BESTELLING_VERWERKT is null THEN :new.BES_BESTELLING_STATUS := 7;
ELSIF :new.BES_BESTELLING_DATUM is not null and
:old.BES_BESTELLING_DATUM is not null and
ELSIF :new.BES_BESTELLING_DATUM is not null and
:old.BES_BESTELLING_DATUM is not null and
:old.BES_BESTELLING_DATUM <> :new.BES_BESTELLING_DATUM and
:old.BES_BESTELLING_STATUS = 1 THEN :new.BES_BESTELLING_STATUS := 2;
END IF;
@@ -57,7 +46,7 @@ FOR EACH ROW
BEGIN
UPDATE_PRIMARY_KEY(bes_bestelopdr_key,bes_s_bes_bestelopdr_key);
IF :old.bes_bestelopdr_status is null THEN
:new.bes_bestelopdr_status = 2;
:new.bes_bestelopdr_status := 2;
END IF;
END;
/
@@ -70,4 +59,129 @@ BEGIN
END;
/
CREATE_TRIGGER(BES_T_BES_BESTELOPDR_ITEM_B_U)
BEFORE UPDATE ON BES_BESTELOPDR_ITEM FOR EACH ROW
BEGIN
IF :new.bes_bestelopdr_item_aantalontv is not null and
(:old.bes_bestelopdr_item_aantalontv is null or
:old.bes_bestelopdr_item_aantalontv <> :new.bes_bestelopdr_item_aantalontv) and
:new.bes_bestelopdr_item_aantalontv >= :new.bes_bestelopdr_item_aantal THEN
insert into bes_bestelopdrstate values (:new.bes_bestelopdr_key, 1);
END IF;
END;
/
CREATE_TRIGGER(BES_T_BES_BESTELOPDR_ITEM_A_UT)
after update on BES_BESTELOPDR_ITEM
begin
declare bokey number(10);
CURSOR query
IS select bkey from
(select
b1.bes_bestelopdr_key bkey,
sum(bes_bestelopdr_item_aantal) request,
sum(bes_bestelopdr_item_aantalontv) deliver
from bes_bestelopdr_item b1,
(select bes_bestelopdr_key
from bes_bestelopdr_item b
where b.bes_bestelopdr_key in
(select bes_bestelopdr_key from bes_bestelopdrstate where bes_bestelopdrstate = 1)) b2
where b1.bes_bestelopdr_key = b2.bes_bestelopdr_key
group by b1.bes_bestelopdr_key) where deliver >= request;
BEGIN
bokey := 0;
FOR besitem_rec IN query() LOOP
update bes_bestelopdr set bes_bestelopdr_leverdatum = sysdate, bes_bestelopdr_status = 5
where bes_bestelopdr_key = besitem_rec.bkey;
bokey := besitem_rec.bkey;
END LOOP;
if bokey <> 0 then
delete bes_bestelopdrstate;
end if;
END;
END;
CREATE_TRIGGER(BES_T_BES_BESTELLING_ITEM_B_U)
BEFORE UPDATE ON BES_BESTELLING_ITEM FOR EACH ROW
BEGIN
IF :new.bes_bestelling_i_gcpt_us_key is not null and
:old.bes_bestelling_i_gcpt_us_key is null THEN
:new.bes_bestelling_item_status := 4;
insert into bes_bestellingstate values(:new.bes_bestelling_key,2);
END IF;
IF :new.BES_BESTELOPDR_KEY is not null and
:old.BES_BESTELOPDR_KEY is null THEN
:new.bes_bestelling_item_status := 5;
update BES_BESTELLING set BES_BESTELLING_STATUS = 5
where BES_BESTELLING_KEY = :new.BES_BESTELLING_KEY;
END IF;
IF :new.bes_bestelling_item_aantalontv is not null and
(:old.bes_bestelling_item_aantalontv is null or
:old.bes_bestelling_item_aantalontv <> :new.bes_bestelling_item_aantalontv) and
:new.bes_bestelling_item_aantalontv >= :new.bes_bestelling_item_aantal THEN
:new.bes_bestelling_item_status := 6;
insert into bes_bestellingstate values(:new.bes_bestelling_key,1);
END IF;
END;
/
CREATE_TRIGGER(BES_T_BES_BESTELLING_ITEM_A_UT)
after update on BES_BESTELLING_ITEM
begin
declare bkey number(10); bstate number(1);
CURSOR query
IS select bkey, bstate, request, deliver from
(select
b2.bes_bestellingstate bstate, b1.bes_bestelling_key bkey,
count(distinct b1.bes_bestelling_item_key) request,
count(distinct b2.bes_bestelling_item_key) deliver
from bes_bestelling_item b1,
(select b.bes_bestelling_key, bes_bestellingstate, bes_bestelling_item_key
from bes_bestelling_item b, bes_bestellingstate bs
where bs.BES_BESTELLING_KEY = b.BES_BESTELLING_KEY
and b.bes_bestelling_item_status = 6 and
bes_bestellingstate = 1 ) b2
where b1.bes_bestelling_key = b2.bes_bestelling_key
group by b2.bes_bestellingstate, b1.bes_bestelling_key)
where deliver = request
union all
select bkey, bstate, request, deliver from
(select
b2.bes_bestellingstate bstate, b1.bes_bestelling_key bkey,
count(distinct b1.bes_bestelling_item_key) request,
count(distinct b2.bes_bestelling_item_key) deliver
from bes_bestelling_item b1,
(select b.bes_bestelling_key, bes_bestellingstate, bes_bestelling_item_key
from bes_bestelling_item b, bes_bestellingstate bs
where bs.BES_BESTELLING_KEY = b.BES_BESTELLING_KEY
and b.bes_bestelling_item_status = 4 and
bes_bestellingstate = 2 ) b2
where b1.bes_bestelling_key = b2.bes_bestelling_key
group by b2.bes_bestellingstate, b1.bes_bestelling_key)
where deliver = request;
BEGIN
bkey := 0;
FOR besitem_rec IN query() LOOP
if besitem_rec.bstate = 1 then
update bes_bestelling set bes_bestelling_afgemeld = sysdate,
bes_bestelling_status = 6
where bes_bestelling_key = besitem_rec.bkey;
bkey := besitem_rec.bkey;
end if;
if besitem_rec.bstate = 2 then
update bes_bestelling set bes_bestelling_geaccepteerd = sysdate,
bes_bestelling_status = 4
where bes_bestelling_key = besitem_rec.bkey;
bkey := besitem_rec.bkey;
end if;
END LOOP;
if bkey <> 0 then
delete bes_bestellingstate;
end if;
END;
END;
/
#endif // BES