BLCC#71247 Reconstrueren ruimten per (huur)maand van 2021-01 t/m 2022-03.
svn path=/Customer/; revision=56415
This commit is contained in:
205
onces/BLCC/BLCC#71247_3.sql
Normal file
205
onces/BLCC/BLCC#71247_3.sql
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
--
|
||||||
|
-- $Id$
|
||||||
|
--
|
||||||
|
-- Customer specific once-script BLCC#71247_2.sql.
|
||||||
|
DEFINE thisfile = 'BLCC#71247_3.sql'
|
||||||
|
DEFINE dbuser = '^BLCC'
|
||||||
|
|
||||||
|
SET ECHO ON
|
||||||
|
SET DEFINE ON
|
||||||
|
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
|
||||||
|
COLUMN fcltcusterr NEW_VALUE fcltcusterr NOPRINT;
|
||||||
|
WHENEVER SQLERROR CONTINUE;
|
||||||
|
SELECT adm.getscriptspoolfile('&thisfile') AS fcltlogfile FROM DUAL;
|
||||||
|
SPOOL &fcltlogfile
|
||||||
|
WHENEVER SQLERROR EXIT;
|
||||||
|
SELECT adm.checkscriptcust('&dbuser') AS fcltcusterr FROM DUAL;
|
||||||
|
WHENEVER SQLERROR CONTINUE;
|
||||||
|
PROMPT &fcltcusterr
|
||||||
|
SET DEFINE OFF
|
||||||
|
|
||||||
|
------ payload begin ------
|
||||||
|
|
||||||
|
-- BLCC#71247: Reconstrueren ruimten per (huur)maand van 2021-01 t/m 2022-03.
|
||||||
|
SET SERVEROUTPUT ON size 1000000;
|
||||||
|
|
||||||
|
DECLARE
|
||||||
|
CURSOR twk_ruimte_freeze
|
||||||
|
IS
|
||||||
|
WITH maanden -- Ontbrekende historie (2021 + 2022)
|
||||||
|
AS ( SELECT ADD_MONTHS (TRUNC (SYSDATE, 'mm'), LEVEL - 24) mnd
|
||||||
|
FROM DUAL
|
||||||
|
WHERE ADD_MONTHS (TRUNC (SYSDATE, 'mm'), LEVEL - 24) >= fac.safe_to_date ('01-12-2020', 'dd-mm-yyyy')
|
||||||
|
AND ADD_MONTHS (TRUNC (SYSDATE, 'mm'), LEVEL - 24) <= fac.safe_to_date ('01-03-2022', 'dd-mm-yyyy')
|
||||||
|
CONNECT BY LEVEL <= 24)
|
||||||
|
SELECT m.mnd,
|
||||||
|
r.alg_ruimte_key,
|
||||||
|
l.alg_locatie_code locatiecode,
|
||||||
|
g.alg_gebouw_code gebouwcode,
|
||||||
|
v.alg_verdieping_code verdiepingcode,
|
||||||
|
COALESCE (x.ruimtenummer, r.alg_ruimte_nr) ruimtenummer,
|
||||||
|
sr.alg_srtruimte_omschrijving ruimtefunctie, -- Actueel of NULL?
|
||||||
|
r.alg_ruimte_bruto_vloeropp nvo, -- Actueel of NULL?
|
||||||
|
tekcont.cad_imp_contour_opp nvo_getekend, -- Actueel of NULL?
|
||||||
|
COALESCE (x.vvo, r.alg_ruimte_opp_alt1) vvo, -- Uit Verkoopfactuur-tabel, anders actueel?
|
||||||
|
COALESCE (x.vvo, tekcont.cad_imp_contour_opp_alt1) vvo_getekend, -- Uit Verkoopfactuur-tabel, anders actueel?
|
||||||
|
COALESCE (x.lhkotc_class, lhkotc.waarde) lhkotc_class, -- Uit Verkoopfactuur-tabel, anders actueel?
|
||||||
|
TO_CHAR (ADD_MONTHS (m.mnd, 1), 'yyyy-mm') huur_maand, -- Altijd vullen?
|
||||||
|
x.huur_contract,
|
||||||
|
g.alg_gebouw_vervaldatum gebouw_vervallen, -- Actueel?
|
||||||
|
gebouw_strategie.waarde gebouw_strategie -- Actueel?
|
||||||
|
FROM maanden m,
|
||||||
|
alg_ruimte r,
|
||||||
|
alg_verdieping v,
|
||||||
|
alg_gebouw g,
|
||||||
|
alg_locatie l,
|
||||||
|
alg_srtruimte sr,
|
||||||
|
(SELECT tek.alg_verdieping_key, cont.cad_imp_contour_nr, cont.cad_imp_contour_opp, cont.cad_imp_contour_opp_alt1
|
||||||
|
FROM cad_tekening tek, cad_imp_contour cont
|
||||||
|
WHERE tek.cad_tekening_verwijder IS NULL
|
||||||
|
AND tek.cad_tekening_key = cont.cad_tekening_key
|
||||||
|
AND cont.cad_imp_contour_concept = 0
|
||||||
|
AND cont.prj_scenario_key IS NULL) tekcont,
|
||||||
|
(SELECT ok.alg_onrgoed_key, ud.fac_usrdata_omschr waarde
|
||||||
|
FROM alg_v_aanwezigonrgoedkenmerk ok, fac_v_aanwezigusrdata ud
|
||||||
|
WHERE ok.alg_kenmerk_key = 1100 -- LHKOTC Classificatie
|
||||||
|
AND ok.alg_onrgoed_niveau = 'R'
|
||||||
|
AND fac.safe_to_number (ok.alg_onrgoedkenmerk_waarde) = ud.fac_usrdata_key) lhkotc,
|
||||||
|
(SELECT ok.alg_onrgoed_key, ud.fac_usrdata_omschr waarde
|
||||||
|
FROM alg_v_aanwezigonrgoedkenmerk ok, fac_v_aanwezigusrdata ud
|
||||||
|
WHERE ok.alg_kenmerk_key = 1161 -- Strategie
|
||||||
|
AND ok.alg_onrgoed_niveau = 'G'
|
||||||
|
AND fac.safe_to_number (ok.alg_onrgoedkenmerk_waarde) = ud.fac_usrdata_key) gebouw_strategie,
|
||||||
|
( SELECT x.fin_verkoopfactuur_datum freeze_datum,
|
||||||
|
TO_CHAR (x.fin_verkoopfactuur_datum, 'yyyymm')
|
||||||
|
freeze_maand,
|
||||||
|
fac.safe_to_number (SUBSTR (x.fin_verkoopfactuur_c6, 2, INSTR (x.fin_verkoopfactuur_c6, '=') - 2))
|
||||||
|
alg_ruimte_key,
|
||||||
|
SUBSTR (x.fin_verkoopfactuur_c6,
|
||||||
|
INSTR (x.fin_verkoopfactuur_c6, '-', -1) + 1,
|
||||||
|
INSTR (x.fin_verkoopfactuur_c6, '#', -1) - INSTR (x.fin_verkoopfactuur_c6, '-', -1) - 1)
|
||||||
|
ruimtenummer,
|
||||||
|
COALESCE (x.fin_verkoopfactuur_n1, 0) vvo,
|
||||||
|
DECODE (SUBSTR (x.fin_verkoopfactuur_c6, INSTR (x.fin_verkoopfactuur_c6, '#') + 1),
|
||||||
|
'L', 'Lab',
|
||||||
|
'H', 'Hal',
|
||||||
|
'K', 'Kantoor',
|
||||||
|
'O', 'Overig',
|
||||||
|
'T', 'Terrein',
|
||||||
|
'C', 'Collectief',
|
||||||
|
NULL)
|
||||||
|
lhkotc_class,
|
||||||
|
x.fin_verkoopfactuur_maand huur_maand,
|
||||||
|
LISTAGG (DISTINCT TO_CHAR (c.cnt_contract_key) || '=' || c.cnt_contract_nummer_intern || '.' || COALESCE (c.cnt_contract_versie, '0'), ',') WITHIN GROUP (ORDER BY TO_CHAR (c.cnt_contract_key) || '=' || c.cnt_contract_nummer_intern || '.' || COALESCE (c.cnt_contract_versie, '0'))
|
||||||
|
huur_contract
|
||||||
|
FROM fin_verkoopfactuur x, cnt_contract c
|
||||||
|
WHERE x.fin_verkoopfactuur_maand BETWEEN '202101' AND '202204'
|
||||||
|
AND x.fin_verkoopfactuur_n2 IS NOT NULL -- Bedrag in N2 (dus FACT)
|
||||||
|
AND x.fin_verkoopfactuur_n5 IS NULL -- Geen melding (dus regulier)
|
||||||
|
AND x.fin_verkoopfactuur_xmlnode = 'contract'
|
||||||
|
AND x.fin_verkoopfactuur_refkey = c.cnt_contract_key
|
||||||
|
AND c.ins_discipline_key IN (2122, 2123) -- LA/LA CRF
|
||||||
|
AND SUBSTR (x.fin_verkoopfactuur_c6, 1, 1) = 'R'
|
||||||
|
GROUP BY x.fin_verkoopfactuur_datum,
|
||||||
|
TO_CHAR (x.fin_verkoopfactuur_datum, 'yyyymm'),
|
||||||
|
fac.safe_to_number (SUBSTR (x.fin_verkoopfactuur_c6, 2, INSTR (x.fin_verkoopfactuur_c6, '=') - 2)),
|
||||||
|
SUBSTR (x.fin_verkoopfactuur_c6,
|
||||||
|
INSTR (x.fin_verkoopfactuur_c6, '-', -1) + 1,
|
||||||
|
INSTR (x.fin_verkoopfactuur_c6, '#', -1) - INSTR (x.fin_verkoopfactuur_c6, '-', -1) - 1),
|
||||||
|
COALESCE (x.fin_verkoopfactuur_n1, 0),
|
||||||
|
DECODE (SUBSTR (x.fin_verkoopfactuur_c6, INSTR (x.fin_verkoopfactuur_c6, '#') + 1),
|
||||||
|
'L', 'Lab',
|
||||||
|
'H', 'Hal',
|
||||||
|
'K', 'Kantoor',
|
||||||
|
'O', 'Overig',
|
||||||
|
'T', 'Terrein',
|
||||||
|
'C', 'Collectief',
|
||||||
|
NULL),
|
||||||
|
x.fin_verkoopfactuur_maand) x
|
||||||
|
WHERE m.mnd BETWEEN r.alg_ruimte_aanmaak AND COALESCE (r.alg_ruimte_verwijder, SYSDATE)
|
||||||
|
AND r.alg_verdieping_key = v.alg_verdieping_key
|
||||||
|
AND v.alg_gebouw_key = g.alg_gebouw_key
|
||||||
|
AND g.alg_locatie_key = l.alg_locatie_key
|
||||||
|
AND r.alg_srtruimte_key = sr.alg_srtruimte_key(+)
|
||||||
|
AND r.alg_verdieping_key = tekcont.alg_verdieping_key(+)
|
||||||
|
AND r.alg_ruimte_nr = tekcont.cad_imp_contour_nr(+)
|
||||||
|
AND r.alg_ruimte_key = lhkotc.alg_onrgoed_key(+)
|
||||||
|
AND g.alg_gebouw_key = gebouw_strategie.alg_onrgoed_key(+)
|
||||||
|
AND TO_CHAR (m.mnd, 'yyyymm') = x.freeze_maand(+)
|
||||||
|
AND r.alg_ruimte_key = x.alg_ruimte_key(+)
|
||||||
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
|
v_errormsg VARCHAR2 (1000);
|
||||||
|
oracle_err_num NUMBER;
|
||||||
|
oracle_err_mes VARCHAR2 (200);
|
||||||
|
freeze_datum DATE;
|
||||||
|
v_count NUMBER;
|
||||||
|
BEGIN
|
||||||
|
freeze_datum := SYSDATE;
|
||||||
|
v_count := 0;
|
||||||
|
|
||||||
|
FOR rec IN twk_ruimte_freeze
|
||||||
|
LOOP
|
||||||
|
BEGIN
|
||||||
|
v_errormsg := 'Fout toevoegen TWK-ruimte';
|
||||||
|
INSERT INTO blcc_alg_freeze (freeze_datum,
|
||||||
|
alg_ruimte_key,
|
||||||
|
locatiecode,
|
||||||
|
gebouwcode,
|
||||||
|
verdiepingcode,
|
||||||
|
ruimtenummer,
|
||||||
|
ruimtefunctie,
|
||||||
|
nvo,
|
||||||
|
nvo_getekend,
|
||||||
|
vvo,
|
||||||
|
vvo_getekend,
|
||||||
|
lhkotc_class,
|
||||||
|
huur_maand,
|
||||||
|
huur_contract,
|
||||||
|
gebouw_vervaldatum,
|
||||||
|
gebouw_strategie)
|
||||||
|
VALUES (rec.mnd,
|
||||||
|
rec.alg_ruimte_key,
|
||||||
|
rec.locatiecode,
|
||||||
|
rec.gebouwcode,
|
||||||
|
rec.verdiepingcode,
|
||||||
|
rec.ruimtenummer,
|
||||||
|
rec.ruimtefunctie,
|
||||||
|
rec.nvo,
|
||||||
|
rec.nvo_getekend,
|
||||||
|
rec.vvo,
|
||||||
|
rec.vvo_getekend,
|
||||||
|
rec.lhkotc_class,
|
||||||
|
rec.huur_maand,
|
||||||
|
rec.huur_contract,
|
||||||
|
rec.gebouw_vervallen,
|
||||||
|
rec.gebouw_strategie);
|
||||||
|
|
||||||
|
v_count := v_count + 1;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS
|
||||||
|
THEN
|
||||||
|
oracle_err_num := SQLCODE;
|
||||||
|
oracle_err_mes := SUBSTR (SQLERRM, 1, 200);
|
||||||
|
v_errormsg := v_errormsg || ' ORACLE (error ' || oracle_err_num || '/' || oracle_err_mes || ')';
|
||||||
|
DBMS_OUTPUT.PUT_LINE ('E: [' || rec.mnd || '|' || TO_CHAR (rec.alg_ruimte_key) || '] ' || v_errormsg);
|
||||||
|
COMMIT;
|
||||||
|
END;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
DBMS_OUTPUT.PUT_LINE ('S: ' || TO_CHAR (v_count) || ' TWK-ruimten toegevoegd');
|
||||||
|
COMMIT;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
|
||||||
|
------ payload end ------
|
||||||
|
|
||||||
|
SET DEFINE OFF
|
||||||
|
BEGIN adm.systrackscriptId ('$Id$', 1); END;
|
||||||
|
/
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
SET ECHO OFF
|
||||||
|
SPOOL OFF
|
||||||
|
SET DEFINE ON
|
||||||
|
PROMPT Logfile of this upgrade is: &fcltlogfile
|
||||||
Reference in New Issue
Block a user