CARG#85437 daily procedure die bestellingen [onder voorwaarden] automatisch als geleverd markeert (en dat trackt/notificeert/vervolgt met een BES2AF waar nodig)

svn path=/Database/trunk/; revision=67977
This commit is contained in:
2025-02-13 21:24:26 +00:00
parent f69cdb8f82
commit e0f2585e97
4 changed files with 192 additions and 2 deletions

View File

@@ -71,6 +71,8 @@ AS
PROCEDURE notifybestelopdrbedrijven (pbestelopdrkey NUMBER,
ptrackingkey NUMBER);
PROCEDURE autodeliver;
END bes;
/
@@ -2263,6 +2265,187 @@ AS
END LOOP;
END;
PROCEDURE autodeliver
IS
v_bes_bestellevr_key bes_bestellevr.bes_bestellevr_key%TYPE;
last_bes_bestelopdr_key bes_bestelopdr.bes_bestelopdr_key%TYPE;
last_bes_bestelling_key bes_bestelling_item.bes_bestelling_key%TYPE;
amount bes_bestelling_item.bes_bestelling_item_aantal%TYPE;
tracking VARCHAR2 (2000);
CURSOR b_upd IS
SELECT b.bes_bestelopdr_key,
b.bes_bestelopdr_id,
boi.bes_bestelopdr_item_key,
boi.bes_bestelopdr_item_aantal,
boi.bes_bestelopdr_item_omschrijv,
bi.bes_bestelling_key,
bi.bes_bestelling_item_key
FROM bes_bestelling bes
JOIN bes_bestelling_item bi
ON bi.bes_bestelling_key = bes.bes_bestelling_key
JOIN bes_bestelopdr_item boi
ON boi.bes_bestelopdr_item_key =
bi.bes_bestelopdr_item_key
JOIN bes_srtdeel s
ON s.bes_srtdeel_key = bi.bes_srtdeel_key
JOIN bes_srtgroep g
ON g.bes_srtgroep_key = s.bes_srtgroep_key
JOIN bes_disc_params bdp
ON bdp.bes_ins_discipline_key = g.ins_discipline_key
JOIN bes_bestelopdr b
ON b.bes_bestelopdr_key = boi.bes_bestelopdr_key
WHERE bdp.bes_disc_params_fe_confirm = 0
AND bdp.bes_disc_params_deliver_fe = 0
AND ( boi.bes_bestelopdr_item_aantalontv IS NULL
OR boi.bes_bestelopdr_item_aantalontv <
boi.bes_bestelopdr_item_aantal)
AND bdp.bes_disc_params_autodeliverdays > 0
AND bes.bes_bestelling_leverdatum
+ bdp.bes_disc_params_autodeliverdays <
SYSDATE
ORDER BY b.bes_bestelopdr_key;
PROCEDURE bes_auto_update (bes_bestelling_key IN NUMBER,
bes_bestelopdr_key IN NUMBER,
tracking IN VARCHAR2)
IS
prs_voor bes_bestelling.prs_perslid_key_voor%TYPE;
sender alg_locatie.alg_locatie_email%TYPE;
CURSOR fin_autoapprove (bestelopdr_key NUMBER)
IS
SELECT f.fin_factuur_key
FROM fin_factuur f
WHERE f.bes_bestelopdr_key = bestelopdr_key
AND f.fin_factuur_statuses_key = 2
AND f.fin_factuur_verwijder IS NULL
ORDER BY f.fin_factuur_key;
BEGIN
IF bes_bestelopdr_key <> -1
THEN
-- Update eerst de vorige nog even (deze is voor de laatste)
UPDATE bes_bestelopdr bo
SET bo.bes_bestelopdr_delivery_opmerk =
lcl.l ('bes_discipline_autodelivered')
WHERE bo.bes_bestelopdr_key =
bes_auto_update.bes_bestelopdr_key;
fac.trackaction ('BES2UP',
bes_bestelopdr_key,
NULL,
NULL,
tracking);
bes.updatebestelopdrstatus (bes_bestelopdr_key, NULL);
bes.updatebestellingstatus (bes_bestelling_key, NULL);
BEGIN
SELECT bes.prs_perslid_key_voor, l.alg_locatie_email
INTO prs_voor, sender
FROM bes_bestelling bes
JOIN mld_adres ma
ON ma.mld_adres_key = bes.mld_adres_key_lev
JOIN alg_locatie l
ON l.alg_locatie_key = ma.alg_locatie_key
WHERE bes.bes_bestelling_key =
bes_auto_update.bes_bestelling_key;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
prs_voor := NULL;
sender := NULL;
END;
fac.putnotificationsrtprio (NULL,
prs_voor,
'BESOT2',
bes_bestelling_key,
NULL,
NULL,
NULL,
NULL,
NULL,
2,
sender);
FOR rec IN fin_autoapprove (bes_bestelopdr_key)
LOOP
fin.autoapprovefactuur (rec.fin_factuur_key);
END LOOP;
END IF;
END;
BEGIN
last_bes_bestelopdr_key := -1;
last_bes_bestelling_key := -1;
FOR rec IN b_upd
LOOP
IF rec.bes_bestelopdr_key <> last_bes_bestelopdr_key
THEN
-- Update eerst de vorige nog even;
bes_auto_update (last_bes_bestelling_key,
last_bes_bestelopdr_key,
tracking);
-- En hierna verder met de huidige
last_bes_bestelopdr_key := rec.bes_bestelopdr_key;
last_bes_bestelling_key := rec.bes_bestelling_key;
tracking :=
REPLACE (
lcl.l ('lcl_bes_is_bes2uptrack'),
'{0}',
fac.getsetting ('bes_bestelopdr_prefix')
|| rec.bes_bestelopdr_id);
INSERT INTO bes_bestellevr (bes_bestellevr_opmerk)
VALUES (lcl.l ('bes_discipline_autodelivered'))
RETURNING bes_bestellevr_key
INTO v_bes_bestellevr_key;
END IF;
SELECT bes_bestelopdr_item_aantal
- COALESCE (bes_bestelopdr_item_aantalontv, 0)
INTO amount
FROM bes_bestelopdr_item
WHERE bes_bestelopdr_item_key = rec.bes_bestelopdr_item_key;
INSERT INTO bes_bestellevr_item (bes_bestellevr_key,
bes_bestelopdr_item_key,
bes_bestellevr_item_aantal)
VALUES (v_bes_bestellevr_key,
rec.bes_bestelopdr_item_key,
amount);
UPDATE bes_bestelopdr_item
SET bes_bestelopdr_item_aantalontv =
bes_bestelopdr_item_aantal,
bes_bestelopdr_item_ontvangen = SYSDATE
WHERE bes_bestelopdr_item_key = rec.bes_bestelopdr_item_key;
UPDATE bes_bestelling_item
SET bes_bestelling_item_aantalontv =
COALESCE (bes_bestelling_item_aantalontv, 0) + amount
WHERE bes_bestelling_item_key = rec.bes_bestelling_item_key;
tracking :=
SUBSTR (
tracking
|| CHR(10)
|| lcl.l ('lcl_bes_delivery')
|| ': '
|| amount
|| ' '
|| rec.bes_bestelopdr_item_omschrijv,
1,
2000);
END LOOP;
-- Update de laatste ook nog even;
bes_auto_update (last_bes_bestelling_key,
last_bes_bestelopdr_key,
tracking);
END;
END bes;
/

View File

@@ -520,7 +520,9 @@ CREATE_TABLE(bes_disc_params, 0)
bes_disc_params_deliver_fe
NUMBER(1)
DEFAULT 0
NOT NULL
NOT NULL,
bes_disc_params_autodeliverdays /* Als bes_disc_params_fe_confirm = 0 AND bes_disc_params_deliver_fe = 0, dan wordt deze bestelopdracht na bes_disc_params_autodeliverdays dagen als 'geleverd' gemarkeerd */
NUMBER(4)
);
//// flexprops