/*
 * Update script van FACILITOR schema
 * $Revision$
 * $Id$
 */
#include "prologue.inc"

COMMIT;
SET DEFINE OFF

/////////////////////////////////////////////////////////////////////////////////////////// BAUS#81220
ALTER TABLE ins_kenmerk ADD ins_kenmerk_verplicht_status NUMBER(1);

-- Alle "Altijd verplicht" inspectie kenmerken waren verplicht vanaf status "Afgemeld/Te voltooien(5)".
-- Nu zijn de "Altijd verplicht" inspectie kenmerken ook daadwerkelijk altijd verplicht. Deze kenmerken moeten dus omgezet worden.
UPDATE ins_kenmerk k
   SET k.ins_kenmerk_verplicht = NULL,
       k.ins_kenmerk_verplicht_status = 5
 WHERE k.ins_kenmerk_key IN (SELECT k1.ins_kenmerk_key
                               FROM ins_kenmerk k1
                              WHERE k1.ins_kenmerk_verplicht IN (1)
                                AND k1.ins_kenmerk_niveau = 'C');

/////////////////////////////////////////////////////////////////////////////////////////// VLKC#79478
-- Conversie setting: Heropenen voor melder en FO/BO is nu de waarde 3 i.p.v. 1.
UPDATE fac_setting
   SET fac_setting_pvalue = 3
 WHERE fac_setting_name = 'mld_can_reopen_call'
   AND fac_setting_pvalue = 1;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#80553
ALTER TABLE mld_melding
    ADD mld_melding_onderwerp_ai VARCHAR2 (80);

/////////////////////////////////////////////////////////////////////////////////////////// BAUS#80296
CREATE OR REPLACE VIEW fac_v_exp_flex_ctr AS SELECT * FROM DUAL;
DEF_RAPPORT('TRANSPORT', 'WEB_PRSSYS', 0, 'fac_v_exp_flex_ctr'
           , 'Flexkenmerken Periodieke taken',  'Exporteren van flexkenmerken voor CTR'
           , 'Flex properties Recurring tasks', 'Export of flex properties for CTR');

/////////////////////////////////////////////////////////////////////////////////////////// VNOG#81951
ALTER TABLE ins_srtdiscipline DROP CONSTRAINT ins_c_ins_srtdiscipline_bes;
ALTER TABLE ins_srtdiscipline ADD CONSTRAINT ins_c_ins_srtdiscipline_bes CHECK(ins_srtdiscipline_bes IN (0,1,2));

/////////////////////////////////////////////////////////////////////////////////////////// EIND#82432
DEF_MENUITEM(0, 'lcl_menu_fac_jobs_fe', '', 'FAC', 'appl/fac/job_search.asp?urole=fe', 0, 0, 'WEB_MLDUSE', 'W', '0', '');

DEF_MENUITEM(1, 'lcl_menu_fac_jobs_fo', '', 'FAC', 'appl/fac/job_search.asp?urole=fo', 0, 0, 'WEB_MLDFOF', 'W', '1', '');
MENU_INS_AFTER('lcl_menu_fac_jobs_fo', 'lcl_menu_cnt_bo', 100);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#80823
ALTER TABLE fac_import_app ADD fac_import_app_csv NUMBER(1) DEFAULT(0) NOT NULL;
UPDATE fac_import_app
   SET fac_import_app_csv = 1
 WHERE fac_import_app_code IN (SELECT 'GENERICCSV' FROM DUAL
                               UNION SELECT fi.fac_import_app_code
                                 FROM user_source us
                                    , fac_import_app fi
                                    , fac_version fv
                                WHERE us.name = fv.fac_version_cust || '_IMPORT_' || fi.fac_import_app_code
                                  AND us.text LIKE '%fac_import_genericcsv%'
                              );

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#82594
CREATE TABLE mld_kenmerkblokmelding
(  mld_kenmerkblokmelding_key
      NUMBER(10)
      CONSTRAINT mld_k_mld_kenmerkblokmelding_key PRIMARY KEY,
   mld_melding_key
      NUMBER(10)
      CONSTRAINT mld_r_mld_melding_key7 REFERENCES mld_melding(mld_melding_key) ON DELETE CASCADE,
   mld_kenmerk_key -- verwijzing naar het labelkenmerk
      NUMBER(10)
      CONSTRAINT mld_r_mld_kenmerk_key5 REFERENCES mld_kenmerk(mld_kenmerk_key) ON DELETE CASCADE,
   ins_discipline_key
      NUMBER (10)
      CONSTRAINT mld_r_ins_discipline_key6 REFERENCES ins_tab_discipline(ins_discipline_key) ON DELETE CASCADE, -- blokbehandelteam
   prs_perslid_key
      NUMBER (10)
      CONSTRAINT mld_r_prs_perslid_key14 REFERENCES prs_perslid(prs_perslid_key) ON DELETE SET NULL, -- blokbehandelteambehandelaar
   mld_kenmerkblokmelding_afmelddatum
      DATE,
   mld_kenmerkblokmelding_aanmaak
      DATE
      DEFAULT SYSDATE,
   CONSTRAINT mld_u_mld_kenmerkblokmelding UNIQUE(mld_melding_key, mld_kenmerk_key)
);

CREATE SEQUENCE mld_s_mld_kenmerkblokmelding_key MINVALUE 1;

CREATE INDEX mld_i_mld_kenmerkblokmelding ON mld_kenmerkblokmelding(prs_perslid_key);

ALTER TABLE mld_kenmerk ADD
   ins_discipline_key
      NUMBER (10)
      CONSTRAINT mld_r_ins_discipline_key7 REFERENCES ins_tab_discipline(ins_discipline_key);

ALTER TABLE mld_srtkenmerk DROP CONSTRAINT mld_c_mld_srtkenmerk_kenmtype;
-- Onderstaan wordt met WDKA#80394 definitief verwijderd, dus hier niet opnieuw aanmaken
-- ALTER TABLE mld_srtkenmerk ADD
--    CONSTRAINT mld_c_mld_srtkenmerk_kenmtype  CHECK(mld_srtkenmerk_kenmerktype IN ('C','N','D','T','R','S','X','F','E','M','L','l','b','Q','B','V'));

ALTER TABLE fac_kenmwaarden DROP CONSTRAINT fac_c_fac_kenmwaarden_kenmtype;
-- Onderstaan wordt met WDKA#80394 definitief verwijderd, dus hier niet opnieuw aanmaken
-- ALTER TABLE fac_kenmwaarden ADD
--    CONSTRAINT fac_c_fac_kenmwaarden_kenmtype  CHECK(fac_kenmwaarden_kenmerktype IN ('C','N','D','T','R','S','X','F','E','M','L','l','b','Q','B','V'));

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#83243

UPDATE aut_idp
   SET aut_idp_ipfilter = '80.250.128.5,80.250.128.6,80.250.129.195,31.161.17.4,80.250.129.2'
 WHERE aut_idp_code = 'FACILITORSUPPORT';

/////////////////////////////////////////////////////////////////////////////////////////// MARX#81174
DEF_FAC_SRTNOT('FINANO', 0, 'lcl_noti_FINANO', 'fin/fin_factuur.asp?fin_key=', '0', 'factuur', 10);

/////////////////////////////////////////////////////////////////////////////////////////// EIND#82452

ALTER PACKAGE fac COMPILE; // anders (nog) invalid en lukt het volgende niet niet
ALTER PACKAGE fac COMPILE BODY;
-- Laten we een release lang staan
ALTER TABLE mld_melding RENAME COLUMN mld_melding_omschrijving TO mld_melding_omschrijving_old;
ALTER TABLE mld_melding ADD (mld_melding_omschrijving CLOB);

--Een UPDATE van miljoenen (MARX, HSLE) records duurt te lang. Daarom in een loopje.
--UPDATE mld_melding SET mld_melding_omschrijving = mld_melding_omschrijving_old;
PROMPT Warning: next update statement can take up to 10 minutes.
PROMPT Monitor progress in another session using
PROMPT SELECT COUNT (*) FROM mld_melding WHERE mld_melding_omschrijving IS NULL
BEGIN
   EXECUTE IMMEDIATE 'ALTER TRIGGER mld_t_mld_melding_B_IU DISABLE';
   LOOP
      LOCK TABLE mld_melding IN EXCLUSIVE MODE; -- Wordt door COMMIT ongedaan gemaakt
      UPDATE mld_melding
         SET mld_melding_omschrijving = mld_melding_omschrijving_old
       WHERE mld_melding_omschrijving IS NULL
         AND mld_melding_omschrijving_old IS NOT NULL
         AND ROWNUM <= 10000;
      EXIT WHEN sql%notfound;
      COMMIT;
   END LOOP;
   EXECUTE IMMEDIATE 'ALTER TRIGGER mld_t_mld_melding_B_IU ENABLE';
EXCEPTION
   WHEN OTHERS THEN
         EXECUTE IMMEDIATE 'ALTER TRIGGER mld_t_mld_melding_B_IU ENABLE';
   RAISE;
END;
/
COMMIT;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#76580
#include "../INI/INI_TAB.SRC"
#include "../INI/INI_SEQ.SRC"
#include "../INI/INI_IND.SRC"
#include "../INI/INI_TRI.SRC"
#include "../INI/INI_INI.SRC"
DEF_MENUENTRY(2, 99010, 'lcl_menu_setup_framework'     , '', 'FAC', 'appl/init/init_setup.asp', 0, 0, 'WEB_FACTAB');

/////////////////////////////////////////////////////////////////////////////////////////// FBEA#79162
DEF_IMPORT('WEB_PRSSYS', 'VRIJEDAGEN', 'Vrije dagen', 'Non-working days', 1);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#81771
ALTER TABLE fac_notificatie_job ADD fac_usrrap_key NUMBER(10)
  CONSTRAINT fac_r_fac_usrrap_key1 REFERENCES fac_usrrap(fac_usrrap_key) ON DELETE CASCADE;

UPDATE fac_notificatie_job
   SET fac_usrrap_key = TO_NUMBER(SUBSTR(REGEXP_SUBSTR(fac_notificatie_job_geturl, 'usrrap%5Fkey=(\d+)/?')
                                        , 14)
                                 )
 WHERE fac_notificatie_job_geturl LIKE 'appl/fac/fac_report.asp?formail=1%';

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#82157
ALTER TABLE mld_meldbron ADD mld_meldbron_kiesbaar NUMBER(1) DEFAULT 0 NOT NULL;
DEF_MENUITEM(2, 'lcl_menu_mld_meldbron'   , '', 'MLD', 'appl/mgt/mld_meldbron.asp', 0, 0, 'WEB_MLDMGT', 'W', '1', '');
MENU_INS_AFTER('lcl_menu_mld_meldbron', 'lcl_menu_mld_opdrkosten', 25);
DECLARE
    CURSOR c(p_bron IN VARCHAR2) IS
        SELECT TO_NUMBER(column_value) AS bron_key
          FROM xmltable(p_bron);
    v_bron VARCHAR2(100);
BEGIN
    SELECT fac_setting_pvalue
      INTO v_bron
      FROM fac_setting
     WHERE fac_setting_name = 'mld_meldbron_extern';

    IF v_bron <> ''
    THEN
        FOR i IN c(v_bron)
        LOOP
            UPDATE mld_meldbron
            SET mld_meldbron_kiesbaar = 2
            WHERE mld_meldbron_key = i.bron_key;
        END LOOP;
    END IF;
END;
/
-- De setting mld_meldbron_extern kan nu verwijderd worden.

/////////////////////////////////////////////////////////////////////////////////////////// MARX#82116
ALTER TABLE fac_email_setting
  ADD fac_email_setting_attachmaxkb NUMBER(10);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#82351
-- De settings hier al toevoegen omdat er ook een update van de waarde wordt gedaan.
-- Nieuwe settings worden na de upgrade in de recreate toegevoegd.
INSERT INTO fac_setting (fac_setting_module, fac_setting_flags, fac_functie_key, fac_setting_name, fac_setting_type, fac_setting_description)
     SELECT 'FAC', 1, fac_functie_key, 'udr_graph_bar_json',   'string', 'Default json options for report graphs bar (string!)'
       FROM fac_functie
      WHERE fac_functie_code = 'WEB_PRSSYS';
INSERT INTO fac_setting (fac_setting_module, fac_setting_flags, fac_functie_key, fac_setting_name, fac_setting_type, fac_setting_description)
     SELECT 'FAC', 1, fac_functie_key, 'udr_graph_gauge_json', 'string', 'Default json options for report graphs gauge (string!)'
       FROM fac_functie
      WHERE fac_functie_code = 'WEB_PRSSYS';
INSERT INTO fac_setting (fac_setting_module, fac_setting_flags, fac_functie_key, fac_setting_name, fac_setting_type, fac_setting_description)
     SELECT 'FAC', 1, fac_functie_key, 'udr_graph_pie_json',   'string', 'Default json options for report graphs pie (string!)'
       FROM fac_functie
      WHERE fac_functie_code = 'WEB_PRSSYS';
INSERT INTO fac_setting (fac_setting_module, fac_setting_flags, fac_functie_key, fac_setting_name, fac_setting_type, fac_setting_description)
     SELECT 'FAC', 1, fac_functie_key, 'udr_graph_line_json',  'string', 'Default json options for report graphs line (string!)'
       FROM fac_functie
      WHERE fac_functie_code = 'WEB_PRSSYS';
INSERT INTO fac_setting (fac_setting_module, fac_setting_flags, fac_functie_key, fac_setting_name, fac_setting_type, fac_setting_description)
     SELECT 'FAC', 1, fac_functie_key, 'udr_graph_block_json', 'string', 'Default json options for report graphs block (string!)'
       FROM fac_functie
      WHERE fac_functie_code = 'WEB_PRSSYS';

UPDATE fac_setting
   SET fac_setting_pvalue = (SELECT fac_setting_pvalue FROM fac_setting WHERE fac_setting_name = 'udr_graph_default_json')
 WHERE fac_setting_name IN ('udr_graph_bar_json','udr_graph_gauge_json','udr_graph_pie_json','udr_graph_line_json','udr_graph_block_json');

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#82642
DELETE FROM cad_thema WHERE cad_thema_view = 'cad_v_thema_vloerafwerking';
DROP VIEW cad_v_thema_vloerafwerking;
UPDATE fac_setting SET fac_setting_pvalue = 12 WHERE fac_setting_name = 'fg_infobordthema_key' AND fac_setting_pvalue IS NULL;
UPDATE fac_setting SET fac_setting_pvalue = 12 WHERE fac_setting_name = 'fg_infobordlabel_key' AND fac_setting_pvalue IS NULL;
UPDATE fac_setting SET fac_setting_pvalue = 12 WHERE fac_setting_name = 'fg_infobordreport_key' AND fac_setting_pvalue IS NULL;

UPDATE fac_usrrap SET fac_usrrap_groep = 'TRANSPORT' WHERE fac_usrrap_groep IS NULL and fac_usrrap_omschrijving LIKE 'TRANSPORT: %';
UPDATE fac_usrrap SET fac_usrrap_groep = 'STATS' WHERE fac_usrrap_groep IS NULL and fac_usrrap_omschrijving LIKE 'STATS: %';
UPDATE fac_usrrap SET fac_usrrap_groep = 'ADMIN' WHERE fac_usrrap_groep IS NULL and fac_usrrap_omschrijving LIKE 'BEHEER: %';
UPDATE fac_usrrap SET fac_usrrap_groep = 'BASIS' WHERE fac_usrrap_groep IS NULL and fac_usrrap_omschrijving LIKE 'UDR: %';
UPDATE fac_usrrap SET fac_usrrap_groep = 'LANGUAGE' WHERE fac_usrrap_groep IS NULL and fac_usrrap_omschrijving = 'Vertalingen';

UPDATE fac_usrrap SET fac_usrrap_omschrijving = REPLACE(fac_usrrap_omschrijving, 'TRANSPORT: ', '') WHERE fac_usrrap_groep IS NOT NULL and fac_usrrap_omschrijving LIKE 'TRANSPORT: %';
UPDATE fac_usrrap SET fac_usrrap_omschrijving = REPLACE(fac_usrrap_omschrijving, 'STATS: ', '') WHERE fac_usrrap_groep IS NOT NULL and fac_usrrap_omschrijving LIKE 'STATS: %';
UPDATE fac_usrrap SET fac_usrrap_omschrijving = REPLACE(fac_usrrap_omschrijving, 'BEHEER: ', '') WHERE fac_usrrap_groep IS NOT NULL and fac_usrrap_omschrijving LIKE 'BEHEER: %';

UPDATE fac_groep SET fac_groep_opmerking = 'Systeemautorisatiegroep voor applicatiebeheerders' WHERE fac_groep_upper = '_ADMIN' AND fac_groep_opmerking IS NULL;
UPDATE fac_groep SET fac_groep_opmerking = 'Systeemautorisatiegroep voor ALLE gebruikers' WHERE fac_groep_upper = '_DEFAULT' AND fac_groep_opmerking IS NULL;
UPDATE fac_groep SET fac_groep_opmerking = 'Systeemautorisatiegroep voor Facilitor-ondersteuning' WHERE fac_groep_upper = '_FACILITOR' AND fac_groep_opmerking IS NULL;
UPDATE fac_groep SET fac_groep_opmerking = 'Systeemautorisatiegroep voor de Facilitor-mailserver' WHERE fac_groep_upper = '_HMAIL' AND fac_groep_opmerking IS NULL;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#83649
DROP SEQUENCE bes_s_bes_grootheid_key;
DROP TRIGGER bes_t_bes_grootheid_B_IU;
DROP TABLE bes_grootheid;

/////////////////////////////////////////////////////////////////////////////////////////// AAIT#83560
ALTER TABLE prs_bedrijf MODIFY prs_overeenkomst_nr VARCHAR2(30);
ALTER TABLE fac_imp_ext_bedrijf MODIFY prs_overeenkomst_nr VARCHAR2(30);
ALTER TABLE fac_imp_factuur MODIFY leveranciernr VARCHAR2(30);

/////////////////////////////////////////////////////////////////////////////////////////// BAMG#83299
ALTER TABLE cnt_disc_params ADD cnt_disc_params_opties NUMBER(1) DEFAULT 0 NOT NULL;
ALTER TABLE cnt_contract ADD cnt_contract_verleng_termijn NUMBER(10)
  CONSTRAINT cnt_r_cnt_termijn_key5 REFERENCES cnt_termijn(cnt_termijn_key);
ALTER TABLE cnt_contract DROP CONSTRAINT cnt_r_cnt_contract_verlenging;
ALTER TABLE cnt_contract ADD CONSTRAINT cnt_r_cnt_contract_verlenging CHECK(cnt_contract_verlenging IN (0,1,2,3,4,5,6,7));

/////////////////////////////////////////////////////////////////////////////////////////// PZEE#75836
ALTER TABLE res_rsv_ruimte ADD res_rsv_ruimte_teverzenden NUMBER(1) DEFAULT 0 NOT NULL;
ALTER TABLE res_rsv_ruimte ADD res_rsv_ruimte_verzonden DATE;
ALTER TABLE prs_bedrijfadres DROP CONSTRAINT prs_c_prs_bedrijfadrestype;
ALTER TABLE prs_bedrijfadres ADD  CONSTRAINT prs_c_prs_bedrijfadrestype CHECK (prs_bedrijfadres_type IN ('O','B','C','V','N','I','R'));

DEF_FAC_SRTNOT('RESSNT', 0, 'lcl_noti_RESSNT', 'res/res_reservering.asp?rsv_ruimte_key=', '0', 'reservering', 10);
DEF_FAC_SRTNOT('RESSNX', 0, 'lcl_noti_RESSNX', 'res/res_reservering.asp?rsv_ruimte_key=', '0', 'reservering', 10);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#83889
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_onrgoed1',      'FIP: 1-Aanvullen districten t/m gebouwen',  'Inventarisatie Vastgoed, tabblad Locaties', 'FIP: 1-Real estate 1', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_onrgoed2',      'FIP: 2-Aanvullen bouwlagen en ruimten',     'Inventarisatie Vastgoed, tabblad Ruimten', 'FIP: 2-Real estate 2', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_organisatie',   'FIP: 3-Aanvullen organisatiestructuur',     'Inventarisatie Organisatiestructuur', 'FIP: 3-Organisation', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_perslid',       'FIP: 4-Aanvullen personen',                 'Inventarisatie Personen', 'FIP: 4-Persons', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_mld',           'FIP: 5-Aanvullen servicedesk',              'Inventarisatie Meldingen', 'FIP: 5-Calls structure', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_ins',           'FIP: 6-Aanvullen objecten',                 'Inventarisatie Objecten', 'FIP: 6-Objects', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_inspectie',     'FIP: 9-Aanvullen van inspectiedefinities',  'Inventarisatie Inspecties', 'FIP: 9-Inspections', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_ext_bedrijf',   'FIP: Aanvullen externe bedrijven',          'Inventarisatie Externe bedrijven, tabblad Externe Bedrijven',   'FIP: Companies/Companies', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_bedrijfadres',  'FIP: Aanvullen technische bedrijfadressen', 'Inventarisatie Externe bedrijven, tabblad Technische adressen', 'FIP: Companies/Tech adresses', 'For internal use only')
DEF_RAPPORT('EXPORT', 'WEB_FACFAC', 0, 'fac_v_exp_contactpersoon','FIP: Aanvullen contactpersonen',            'Inventarisatie Externe bedrijven, tabblad Contactpersonen',     'FIP: Companies/Contact persons', 'For internal use only')

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#83782
--Mag niet zo maar. Via de interface @prod de rapporten gewoon verwijderd.
--UPDATE fac_usrrap SET fac_functie_key = NULL
-- WHERE fac_functie_key IN (SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code IN ('WEB_OUTLET','WEB_PRSCNG'));

-- Ooit misgegaan bij BLOS bij aanmaken DB38
UPDATE fac_menuitems
   SET fac_functie_key = (SELECT fac_functie_key
                            FROM fac_functie
                           WHERE UPPER (fac_functie_code) = 'WEB_EXTFIN')
 WHERE fac_menuitems_label = 'lcl_menu_fin_fe';
// WEB_FINUSE is vervangen door WEBEXTFIN voor menuitem DEF_MENUITEM(1, 'lcl_menu_fin_fe_overz'         , '', 'FIN', 'appl/fin/fin_search.asp', 0, 0, 'WEB_EXTFIN', 'R', '1', '');            /* fe = leverancier */
UPDATE fac_menuitems
   SET fac_functie_key = (SELECT fac_functie_key
                            FROM fac_functie
                           WHERE UPPER (fac_functie_code) = 'WEB_EXTFIN')
 WHERE fac_menuitems_label = 'lcl_menu_fin_fe_overz';

 DELETE FROM fac_functie WHERE fac_functie_code IN ('WEB_OUTLET','WEB_PRSCNG','WEB_FINUSE');

ALTER PACKAGE fac COMPILE; // anders (nog) invalid en lukt het volgende niet niet
ALTER PACKAGE fac COMPILE BODY;
/////////////////////////////////////////////////////////////////////////////////////////// BLOS#82278
BEGIN
    IF (fac.getSetting ('mld_opdr_discipline_mode') = 1)
    THEN
        DECLARE
            CURSOR c_upd IS
                SELECT o.mld_opdr_key, s.mld_ins_discipline_key
                  FROM mld_opdr o, mld_melding m, mld_stdmelding s
                 WHERE o.mld_melding_key = m.mld_melding_key
                   AND m.mld_stdmelding_key = s.mld_stdmelding_key
                   AND m.mld_melding_status IN (4, 5, 6, 7)
                   AND o.mld_opdr_discipline_key <> s.mld_ins_discipline_key;
        BEGIN
            FOR rec IN c_upd
            LOOP
                UPDATE mld_opdr o
                   SET o.mld_opdr_discipline_key = rec.mld_ins_discipline_key
                 WHERE o.mld_opdr_key = rec.mld_opdr_key;
            END LOOP;
        END;
    END IF;
END;
/

/////////////////////////////////////////////////////////////////////////////////////////// MARX#82611
ALTER TABLE fac_api ADD fac_api_errorhandling NUMBER (10) DEFAULT 1 NOT NULL; // 0=200 on error, 1=400 on error

/////////////////////////////////////////////////////////////////////////////////////////// WDKA#80394
ALTER TABLE alg_kenmerk DROP CONSTRAINT alg_c_alg_kenmerk_type1;
ALTER TABLE bes_srtkenmerk DROP CONSTRAINT bes_c_bes_srtkenmerk_kenmtype;
ALTER TABLE bez_kenmerk DROP CONSTRAINT bez_c_bez_kenmerk_type2;
ALTER TABLE cnt_srtkenmerk DROP CONSTRAINT cnt_c_cnt_srtkenmerk_kenmtype;
-- ALTER TABLE fac_kenmwaarden DROP CONSTRAINT fac_c_fac_kenmwaarden_kenmtype; Reeds met FCLT#82594 verwijderd (hierboven)
ALTER TABLE faq_kenmerk DROP CONSTRAINT faq_c_faq_kenmerk_type1;
ALTER TABLE fin_kenmerk DROP CONSTRAINT fin_c_fin_kenmerk_type1;
ALTER TABLE ins_srtkenmerk DROP CONSTRAINT ins_c_ins_srtkenmerk_kenmtype;
-- ALTER TABLE mld_srtkenmerk DROP CONSTRAINT mld_c_mld_srtkenmerk_kenmtype; Reeds met FCLT#82594 verwijderd (hierboven)
ALTER TABLE prs_kenmerk DROP CONSTRAINT prs_c_prs_kenmerk_type2;
ALTER TABLE res_srtkenmerk DROP CONSTRAINT res_c_res_srtkenmerk_kenmtype;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#83472
ALTER PACKAGE fac COMPILE; // anders (nog) invalid en lukt het volgende niet niet
ALTER PACKAGE fac COMPILE BODY;

DELETE FROM fac_tracking ft
      WHERE fac_tracking_oms IS NULL
        AND ft.fac_srtnotificatie_key IN
            (SELECT fs.fac_srtnotificatie_key
               FROM fac_srtnotificatie fs
               WHERE fs.fac_srtnotificatie_key = ft.fac_srtnotificatie_key
               AND fac_srtnotificatie_oms IS NULL);

/////////////////////////////////////////////////////////////////////////////////////////// MNNL#73376
ALTER TABLE fac_faq ADD fac_faq_module VARCHAR2(4) DEFAULT 'MLD' NOT NULL;
UPDATE fac_faq
   SET fac_faq_module = 'FAQ'
 WHERE fac_faq_key NOT IN (SELECT fac_faq_key FROM mld_stdmeldingfaq
                            UNION
                           SELECT fac_faq_key FROM mld_typeopdrfaq
                            UNION
                           SELECT fac_faq_key FROM alg_algfaq
                          );


/////////////////////////////////////////////////////////////////////////////////////////// FCLT#83387
INSERT INTO fac_setting (fac_setting_module,
                         fac_setting_name,
                         fac_setting_description,
                         fac_setting_default,
                         fac_setting_pvalue,
                         fac_setting_flags,
                         fac_setting_type,
                         fac_functie_key)
    SELECT 'FAC',
           'mld_instemmer_self',
           'Fallback option for approving a concept if no consenter is defined or if you are the consenter { 0=No consent needed | 1=Budgetholder | 2=Objectmanager | 4=Departmentmanager  | 8=Manager | 16=Buildingmanager}',
           fac_setting_default,
           fac_setting_pvalue,
           1,
           fac_setting_type,
           (SELECT fac_functie_key
              FROM fac_functie
             WHERE fac_functie_code = 'WEB_PRSSYS')
      FROM fac_setting
     WHERE     fac_setting_name = 'fac_reserved_number1'
           AND NOT EXISTS
                   (SELECT 1
                      FROM fac_setting
                     WHERE fac_setting_name = 'mld_instemmer_self');

UPDATE fac_setting
   SET fac_setting_pvalue = NULL
 WHERE fac_setting_name = 'fac_reserved_number1';

/////////////////////////////////////////////////////////////////////////////////////////// TWYN#83949
ALTER TABLE prs_kostensoortgrp ADD prs_kostensoortgrp_verwijder DATE;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#84105
DROP TRIGGER fac_t_fac_notificatie_B_IU;
DROP TRIGGER fac_t_fac_notificatie_A_U;
CREATE INDEX fac_i_notificatie3 ON fac_notificatie(fac_notificatie_refkey);

ALTER PACKAGE fac COMPILE; // anders (nog) invalid en lukt het volgende niet niet
ALTER PACKAGE fac COMPILE BODY;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#00000

REGISTERONCE('$Id$')

#include "epilogue.inc"
