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

COMMIT;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#64792
-- Setting is al handmatig overgenomen naar fg_move_origin
UPDATE fac_setting
   SET fac_setting_pvalue = NULL
 WHERE fac_setting_name = 'fac_reserved_number1';


/////////////////////////////////////////////////////////////////////////////////////////// FCLT#63749
UPDATE ins_tab_discipline
   SET INS_DISCIPLINE_IMAGE = SUBSTR(INS_DISCIPLINE_IMAGE, 1, LENGTH(INS_DISCIPLINE_IMAGE) - 2)
 WHERE INS_DISCIPLINE_IMAGE LIKE '%-o';

UPDATE ins_srtdiscipline
   SET INS_SRTDISCIPLINE_IMAGE = SUBSTR(INS_SRTDISCIPLINE_IMAGE, 1, LENGTH(INS_SRTDISCIPLINE_IMAGE) - 2)
 WHERE INS_SRTDISCIPLINE_IMAGE LIKE '%-o';

UPDATE mld_stdmelding
   SET mld_stdmelding_image = SUBSTR(mld_stdmelding_image, 1, LENGTH(mld_stdmelding_image) - 2)
 WHERE mld_stdmelding_image LIKE '%-o';

UPDATE fac_menu
   SET fac_menu_image = SUBSTR(fac_menu_image, 1, LENGTH(fac_menu_image) - 2)
 WHERE fac_menu_image LIKE '%-o';

UPDATE fac_menuitems
   SET fac_menuitems_image = SUBSTR(fac_menuitems_image, 1, LENGTH(fac_menuitems_image) - 2)
 WHERE fac_menuitems_image LIKE '%-o';

UPDATE fac_menu
   SET fac_menu_image = 'fa-sliders-v-square'
 WHERE fac_menu_image = 'fa-sliders';


/////////////////////////////////////////////////////////////////////////////////////////// FCLT#63749 2e batch

UPDATE fac_menu
   SET fac_menu_image = 'fa-blank'
 WHERE fac_menu_image = 'blank';

UPDATE fac_menu
   SET fac_menu_image = 'fa-euro-sign'
 WHERE fac_menu_image = 'fa-eur';

UPDATE fac_menu
   SET fac_menu_image = 'fa-money-bill'
 WHERE fac_menu_image = 'fa-money';

UPDATE fac_menu
   SET fac_menu_image = 'fa-chart-pie'
 WHERE fac_menu_image = 'fa-pie-chart';

UPDATE fac_menu
   SET fac_menu_image = 'fa-blank'
 WHERE fac_menu_image = 'blank';

UPDATE fac_menu
   SET fac_menu_image = 'fa-sliders-v'
 WHERE fac_menu_image = 'fa-sliders';

UPDATE fac_menu
   SET fac_menu_image = 'fa-chart-bar'
 WHERE fac_menu_image = 'fa-bar-chart';

UPDATE fac_menu
   SET fac_menu_image = 'fa-credit-card'
 WHERE fac_menu_image = 'fa-vcard';

UPDATE fac_menu
   SET fac_menu_image = 'fa-chart-line'
 WHERE fac_menu_image = 'fa-line-chart';

UPDATE fac_menu
   SET fac_menu_image = 'fa-utensils-alt'
 WHERE fac_menu_image = 'fa-cutlery';

UPDATE fac_menu
   SET fac_menu_image = 'fa-file-alt'
 WHERE fac_menu_image = 'fa-file-text';

UPDATE fac_menu
   SET fac_menu_image = 'fa-cog'
 WHERE fac_menu_image = 'fa-gear';

UPDATE fac_menu
   SET fac_menu_image = 'fa-chart-line'
 WHERE fac_menu_image = 'fa-chart';

  UPDATE fac_menu
   SET fac_menu_image = 'fa-cogs'
 WHERE fac_menu_image = 'fa-gears';

UPDATE fac_menu
   SET fac_menu_image = 'fa-euro-sign'
 WHERE fac_menu_image = 'fa-euro';

UPDATE fac_menu
   SET fac_menu_image = 'fa-exclamation-triangle'
 WHERE fac_menu_image = 'fa-warning';

UPDATE fac_menuitems
   SET fac_menuitems_image = 'fa-file-alt'
 WHERE fac_menuitems_image = 'fa-file-text';


/////////////////////////////////////////////////////////////////////////////////////////// AAGN#61402
DEF_FAC_SRTNOT('ORDCAE', 0, 'lcl_noti_ORDCAE', 'mld/mld_opdr.asp?opdr_key=', '0', 'opdracht', 10);
DEF_FAC_SRTNOT('ORDCAI', 0, 'lcl_noti_ORDCAI', 'mld/mld_opdr.asp?opdr_key=', '0', 'opdracht', 10);

/////////////////////////////////////////////////////////////////////////////////////////// MNNL#64001
ALTER TABLE mld_kenmerk
  ADD mld_kenmerk_wissen NUMBER(1) DEFAULT 0 NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#63906
ALTER TABLE res_activiteit
  ADD res_activiteit_image VARCHAR2(255);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#64850
DELETE fac_kenmwaarden;

/////////////////////////////////////////////////////////////////////////////////////////// FLEX#64624
ALTER TABLE res_rsv_ruimte
  ADD res_rsv_ruimte_van_actual DATE;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#60030
ALTER TABLE alg_regio          ADD (         alg_regio_externnr VARCHAR2(256),       alg_regio_externsyncdate DATE);
ALTER TABLE alg_district       ADD (      alg_district_externnr VARCHAR2(256),    alg_district_externsyncdate DATE);
ALTER TABLE alg_locatie        ADD (       alg_locatie_externnr VARCHAR2(256),     alg_locatie_externsyncdate DATE);
ALTER TABLE alg_terreinsector  ADD ( alg_terreinsector_externnr VARCHAR2(256),  alg_terreinsector_extsyncdate DATE);
ALTER TABLE alg_gebouw         ADD (        alg_gebouw_externnr VARCHAR2(256),      alg_gebouw_externsyncdate DATE);
ALTER TABLE alg_verdieping     ADD (    alg_verdieping_externnr VARCHAR2(256),  alg_verdieping_externsyncdate DATE);
ALTER TABLE alg_ruimte         ADD (        alg_ruimte_externnr VARCHAR2(256),      alg_ruimte_externsyncdate DATE);
ALTER TABLE bes_bestelling     ADD (    bes_bestelling_externnr VARCHAR2(256),  bes_bestelling_externsyncdate DATE);
ALTER TABLE bes_bestelopdr     ADD (    bes_bestelopdr_externnr VARCHAR2(256),  bes_bestelopdr_externsyncdate DATE);
ALTER TABLE bez_afspraak       ADD (      bez_afspraak_externnr VARCHAR2(256),    bez_afspraak_externsyncdate DATE);
ALTER TABLE bez_bezoekers      ADD (     bez_bezoekers_externnr VARCHAR2(256),   bez_bezoekers_externsyncdate DATE);
ALTER TABLE fin_factuur        ADD (       fin_factuur_externnr VARCHAR2(256),     fin_factuur_externsyncdate DATE);
ALTER TABLE ins_srtdiscipline  ADD ( ins_srtdiscipline_externnr VARCHAR2(256),  ins_srtdiscipline_extsyncdate DATE);
ALTER TABLE ins_tab_discipline ADD (    ins_discipline_externnr VARCHAR2(256),  ins_discipline_externsyncdate DATE);
ALTER TABLE ins_srtgroep       ADD (      ins_srtgroep_externnr VARCHAR2(256),    ins_srtgroep_externsyncdate DATE);
ALTER TABLE ins_srtdeel        ADD (       ins_srtdeel_externnr VARCHAR2(256),     ins_srtdeel_externsyncdate DATE);
ALTER TABLE ins_deel           ADD (          ins_deel_externnr VARCHAR2(256),        ins_deel_externsyncdate DATE);
ALTER TABLE mld_opdr_materiaal ADD (mld_opdr_materiaal_externnr VARCHAR2(256), mld_opdr_materiaal_extsyncdate DATE);
ALTER TABLE mld_stdmelding     ADD (    mld_stdmelding_externnr VARCHAR2(256),  mld_stdmelding_externsyncdate DATE);
ALTER TABLE res_deel           ADD (          res_deel_externnr VARCHAR2(256),        res_deel_externsyncdate DATE);
ALTER TABLE res_artikel        ADD (       res_artikel_externnr VARCHAR2(256),     res_artikel_externsyncdate DATE);
ALTER TABLE res_ruimte         ADD (                                                res_ruimte_externsyncdate DATE);
ALTER TABLE res_rsv_artikel    ADD (   res_rsv_artikel_externnr VARCHAR2(256), res_rsv_artikel_externsyncdate DATE);
ALTER TABLE res_rsv_deel       ADD (      res_rsv_deel_externnr VARCHAR2(256),    res_rsv_deel_externsyncdate DATE);
ALTER TABLE res_rsv_ruimte     ADD (                                            res_rsv_ruimte_externsyncdate DATE);
ALTER TABLE res_reservering    ADD (   res_reservering_externnr VARCHAR2(256), res_reservering_externsyncdate DATE);

ALTER TABLE prs_bedrijf_bedrijf ADD (  prs_bedrijf_externsyncdate1 DATE);
ALTER TABLE prs_bedrijf_bedrijf ADD (  prs_bedrijf_externsyncdate2 DATE);
ALTER TABLE prs_afdeling        ADD (  prs_afdeling_externsyncdate DATE);
ALTER TABLE prs_perslid         ADD (   prs_perslid_externsyncdate DATE);
ALTER TABLE prs_kostenplaats    ADD (    prs_kostenplaats_externnr VARCHAR2(256),   prs_kostenplaats_extsyncdate DATE);
ALTER TABLE prs_werkplek        ADD (        prs_werkplek_externnr VARCHAR2(256),    prs_werkplek_externsyncdate DATE);
ALTER TABLE prs_perslidwerkplek ADD ( prs_perslidwerkplek_externnr VARCHAR2(256),   prs_perslidwerkplek_extsyncd DATE);
ALTER TABLE prs_contactpersoon  ADD (  prs_contactpersoon_externnr VARCHAR2(256), prs_contactpersoon_extsyncdate DATE);

ALTER TABLE prs_bedrijf_bedrijf MODIFY prs_bedrijf_externid1 VARCHAR2(256);
ALTER TABLE prs_bedrijf_bedrijf MODIFY prs_bedrijf_externid2 VARCHAR2(256);
ALTER TABLE prs_afdeling        MODIFY prs_afdeling_externid VARCHAR2(256);
ALTER TABLE prs_perslid         MODIFY prs_perslid_externid  VARCHAR2(256);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#64883
ALTER TABLE fac_version DROP COLUMN fac_version_major;
ALTER TABLE fac_version DROP COLUMN fac_version_minor;
ALTER TABLE fac_version DROP COLUMN fac_version_patch;

DELETE fac_message
 WHERE fac_message_code = 'FAC_M005';

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#65049
_FAC_MODULE('CHT', 'lcl_module_CHT')

DEF_FAC_FUNCTIE3('WEB_CHTOPR', 'CHT',  0, 1,    0);
DEF_FAC_FUNCTIE3('WEB_CHTREQ', 'CHT',  0, 1,    0);

DEF_MENUITEM(2, 'lcl_menu_cht_chatkanalen', '', 'CHT', 'appl/mgt/cht_discipline.asp', 0, 0, 'WEB_PRSSYS', 'W', '1', '');
MENU_INS_AFTER('lcl_menu_cht_chatkanalen', 'lcl_menu_fac_notificaties', 2);

DEF_MENUITEM(0, 'lcl_menu_cht_chatnow'          , '', 'CHT', 'appl/chat/ChatterWant.asp', 0, 1, 'WEB_CHTREQ', 'R', '1', '');
MENU_INS_AFTER('lcl_menu_cht_chatnow', 'lcl_menu_fe_search', 2);

DEF_MENUITEM(1, 'lcl_menu_cht_incoming'          , '', 'CHT', 'appl/chat/ChatterAccept.asp', 0, 1, 'WEB_CHTOPR', 'W', '1', '');
MENU_INS_AFTER('lcl_menu_cht_incoming', 'lcl_menu_sle_sleutels', 2);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#64375
UPDATE fac_usrgraph
   SET fac_usrgraph_options = REPLACE (fac_usrgraph_options, '      "renderer": "$.jqplot.BarRenderer",' || CHR(10), '')
 WHERE fac_usrgraph_omschrijving = 'Category';

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#63800
UPDATE fac_menuitems
   SET fac_menuitems_url = 'appl/msg/fac_nieuws_search.asp'
 WHERE fac_menuitems_label = 'lcl_menu_msg_overzicht';

UPDATE fac_menuitems
   SET fac_menuitems_label = 'lcl_menu_msg_bericht_maken',
       fac_menuitems_default = 1
 WHERE fac_menuitems_label = 'lcl_menu_msg_berichten';

/* Nu default wel in het menu, dat dan ook even voor bestaande klanten; */
INSERT INTO fac_menu (fac_menuitems_key, fac_menu_volgnr)
    SELECT fac_menuitems_key, fac_menuitems_key * 100
      FROM fac_menuitems i
     WHERE     fac_menuitems_label = 'lcl_menu_msg_bericht_maken'
           AND i.fac_menuitems_key NOT IN
                   (SELECT m.fac_menuitems_key
                      FROM fac_menu m
                     WHERE m.fac_menuitems_key IS NOT NULL);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66753
DELETE FROM mld_melding_object mmo
 WHERE mmo.mld_melding_key NOT IN (SELECT mld_melding_key FROM mld_melding);

DELETE FROM mld_melding_object mmo
 WHERE mmo.mld_melding_key IS NULL;

/////////////////////////////////////////////////////////////////////////////////////////// UWVA#65182
ALTER TABLE fin_kenmerkfactuur   DROP CONSTRAINT fin_r_fin_factuur_key;
ALTER TABLE fin_factuurregel     DROP CONSTRAINT fin_r_fin_factuurregel1;
ALTER TABLE fin_kenmerkfactregel DROP CONSTRAINT fin_r_fin_factuurregel_key;
ALTER TABLE bes_bestelling       DROP CONSTRAINT bes_r_mld_melding1;
ALTER TABLE cnt_contract_object  DROP CONSTRAINT cnt_r_cnt_contract_key_object;
ALTER TABLE cnt_contract_plaats  DROP CONSTRAINT cnt_r_cnt_contract_key_plaats;
ALTER TABLE cnt_contract_dienst  DROP CONSTRAINT cnt_r_cnt_contract_dienst;
ALTER TABLE cnt_factuurschema    DROP CONSTRAINT cnt_r_cnt_factuurschema1;
ALTER TABLE res_rsv_deel         DROP CONSTRAINT res_c_res_rsv_ruimte_key;
ALTER TABLE res_rsv_artikel      DROP CONSTRAINT res_c_res_rsv_ruimte_key2;
ALTER TABLE mld_melding          DROP CONSTRAINT mld_r_res_rsv_ruimte_key;
ALTER TABLE mld_opdr             DROP CONSTRAINT mld_r_cnt_contract_key;
ALTER TABLE mld_opdr_materiaal   DROP CONSTRAINT mld_r_mld_opdr_key3;
ALTER TABLE mld_opdr_uitvoeren   DROP CONSTRAINT mld_r_mld_opdr_key2;
ALTER TABLE mld_opdr_uren        DROP CONSTRAINT mld_r_mld_opdr_key1;

ALTER TABLE fin_kenmerkfactuur   MODIFY fin_factuur_key      CONSTRAINT fin_r_fin_factuur_key         REFERENCES fin_factuur(fin_factuur_key)           ON DELETE CASCADE;
ALTER TABLE fin_factuurregel     MODIFY fin_factuur_key      CONSTRAINT fin_r_factuurregel1           REFERENCES fin_factuur(fin_factuur_key)           ON DELETE CASCADE;
ALTER TABLE fin_kenmerkfactregel MODIFY fin_factuurregel_key CONSTRAINT fin_r_fin_factuurregel_key    REFERENCES fin_factuurregel(fin_factuurregel_key) ON DELETE CASCADE;
ALTER TABLE bes_bestelling       MODIFY mld_melding_key      CONSTRAINT bes_r_mld_melding1            REFERENCES mld_melding(mld_melding_key)           ON DELETE SET NULL;
ALTER TABLE cnt_contract_object  MODIFY cnt_contract_key     CONSTRAINT cnt_r_cnt_contract_key_object REFERENCES cnt_contract(cnt_contract_key)         ON DELETE CASCADE;
ALTER TABLE cnt_contract_plaats  MODIFY cnt_contract_key     CONSTRAINT cnt_r_cnt_contract_key_plaats REFERENCES cnt_contract(cnt_contract_key)         ON DELETE CASCADE;
ALTER TABLE cnt_contract_dienst  MODIFY cnt_contract_key     CONSTRAINT cnt_r_cnt_contract_dienst     REFERENCES cnt_contract(cnt_contract_key)         ON DELETE CASCADE;
ALTER TABLE cnt_factuurschema    MODIFY cnt_contract_key     CONSTRAINT cnt_r_cnt_factuurschema1      REFERENCES cnt_contract(cnt_contract_key)         ON DELETE CASCADE;
ALTER TABLE res_rsv_deel         MODIFY res_rsv_ruimte_key   CONSTRAINT res_c_res_rsv_ruimte_key      REFERENCES res_rsv_ruimte(res_rsv_ruimte_key)     ON DELETE CASCADE;
ALTER TABLE res_rsv_artikel      MODIFY res_rsv_ruimte_key   CONSTRAINT res_c_res_rsv_ruimte_key2     REFERENCES res_rsv_ruimte(res_rsv_ruimte_key)     ON DELETE CASCADE;
ALTER TABLE mld_melding          MODIFY res_rsv_ruimte_key   CONSTRAINT mld_r_res_rsv_ruimte_key      REFERENCES res_rsv_ruimte(res_rsv_ruimte_key)     ON DELETE SET NULL;
ALTER TABLE mld_melding_object   MODIFY mld_melding_key      CONSTRAINT mld_r_mld_melding_key5        REFERENCES mld_melding(mld_melding_key)           ON DELETE CASCADE;
ALTER TABLE mld_opdr             MODIFY cnt_contract_key     CONSTRAINT mld_r_cnt_contract_key        REFERENCES cnt_contract(cnt_contract_key)         ON DELETE SET NULL;
ALTER TABLE mld_opdr_materiaal   MODIFY mld_opdr_key         CONSTRAINT mld_r_mld_opdr_key3           REFERENCES mld_opdr(mld_opdr_key)                 ON DELETE CASCADE;
ALTER TABLE mld_opdr_uitvoeren   MODIFY mld_opdr_key         CONSTRAINT mld_r_mld_opdr_key2           REFERENCES mld_opdr(mld_opdr_key)                 ON DELETE CASCADE;
ALTER TABLE mld_opdr_uren        MODIFY mld_opdr_key         CONSTRAINT mld_r_mld_opdr_key1           REFERENCES mld_opdr(mld_opdr_key)                 ON DELETE CASCADE;

/////////////////////////////////////////////////////////////////////////////////////////// LOGC#65120
DEF_FAC_SRTNOT('PRSREG', 127, 'lcl_noti_PRSREG', '', '0', 'perslid', 0);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#65498
UPDATE fac_version
   SET fac_version_cust = UPPER(fac_version_cust)
     , fac_version_group = UPPER(fac_version_group);

/////////////////////////////////////////////////////////////////////////////////////////// FLEX#64726
ALTER TABLE ins_srtdeel
 ADD ins_srtdeel_sensortype NUMBER(3) DEFAULT 0 NOT NULL;
CREATE INDEX ins_i_ins_srtdeel7 ON ins_srtdeel(ins_srtdeel_sensortype);

/////////////////////////////////////////////////////////////////////////////////////////// YKPN#64081
DEF_FAC_SRTNOT('BEZBEZ', 18, 'lcl_noti_BEZBEZ', '', '0', 'afspraak', 10);

/////////////////////////////////////////////////////////////////////////////////////////// FLEX#64717
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'));
ALTER TABLE fac_notificatie ADD prs_bedrijfadres_key
    NUMBER(10) CONSTRAINT prs_r_bedrijfadres_key1
    REFERENCES prs_bedrijfadres(prs_bedrijfadres_key) ON DELETE CASCADE;

ALTER TABLE fac_notificatie_job ADD fac_notificatie_job_seconds NUMBER(5);
ALTER TABLE fac_notificatie_job ADD CONSTRAINT fac_c_notificatie_job1 CHECK((fac_notificatie_job_interval IS NOT NULL AND fac_notificatie_job_seconds IS NULL) OR (fac_notificatie_job_interval IS NULL AND fac_notificatie_job_seconds IS NOT NULL));
ALTER TABLE fac_notificatie_job ADD fac_notificatie_job_queue VARCHAR2(20) DEFAULT 'DEFAULT' NOT NULL;
ALTER TABLE fac_notificatie ADD fac_notificatie_queue VARCHAR2(20) DEFAULT 'DEFAULT' NOT NULL;

DEF_FAC_SRTNOT('FACTST', 0, 'lcl_noti_FACTST', '', '0', 'perslid', 10);

/////////////////////////////////////////////////////////////////////////////////////////// FLEX#65726

ALTER TABLE prs_bedrijfadres
    ADD prs_bedrijfadres_plugin VARCHAR(320);
ALTER TABLE prs_bedrijfadres
    ADD prs_bedrijfadres_plugindata VARCHAR(4000);

/////////////////////////////////////////////////////////////////////////////////////////// YKPN#64730
ALTER TABLE res_activiteit DROP CONSTRAINT res_c_activiteit_aantal;
ALTER TABLE res_activiteit ADD  CONSTRAINT res_c_activiteit_aantal CHECK(res_activiteit_aantalverplicht IN (0,1,2));

///////////////////////////////////////////////////////////////////////////////////////////  ARAI#59648
ALTER TABLE mld_melding ADD mld_melding_dwgx NUMBER(16,3);
ALTER TABLE mld_melding ADD mld_melding_dwgy NUMBER(16,3);
ALTER TABLE mld_melding ADD mld_melding_dwgz NUMBER(16,3);
ALTER TABLE mld_melding ADD mld_melding_x NUMBER(16,6);
ALTER TABLE mld_melding ADD mld_melding_y NUMBER(16,6);
ALTER TABLE mld_melding ADD mld_melding_z NUMBER(16,6);

/////////////////////////////////////////////////////////////////////////////////////////// FMHN#65858
ALTER TABLE fac_imp_onrgoed2 MODIFY alg_ruimte_nr VARCHAR2(20);
ALTER TABLE fac_imp_perslid MODIFY alg_ruimte_nr VARCHAR2(20);
ALTER TABLE fac_imp_ins MODIFY alg_ruimte_nr VARCHAR2(20);
ALTER TABLE fac_imp_sle MODIFY alg_ruimte_nr VARCHAR2(20);
ALTER TABLE alg_ruimte MODIFY alg_ruimte_nr VARCHAR2(20);
ALTER TABLE alg_ruimte MODIFY alg_ruimte_upper_nr VARCHAR2(20);
ALTER TABLE prj_ruimte MODIFY prj_ruimte_nr VARCHAR2(20);
ALTER TABLE prj_ruimte MODIFY prj_ruimte_upper_nr VARCHAR2(20);

/////////////////////////////////////////////////////////////////////////////////////////// GDZW#65247
ALTER TABLE bez_bezoekers ADD bez_bezoekers_done_actual DATE;
ALTER TABLE bez_bezoekers ADD bez_bezoekers_out_actual DATE;

/////////////////////////////////////////////////////////////////////////////////////////// MARX#65917
ALTER TABLE bes_bestelopdr_item MODIFY bes_bestelopdr_item_aantal NUMBER (15, 3);
ALTER TABLE bes_bestelopdr_item MODIFY bes_bestelopdr_item_aantalontv NUMBER (15, 3);
ALTER TABLE bes_bestelopdr_item MODIFY bes_bestelopdr_item_aantalexp NUMBER (15, 3);
ALTER TABLE bes_bestelling_item MODIFY bes_bestelling_item_aantal NUMBER (15, 3);
ALTER TABLE bes_bestelling_item MODIFY bes_bestelling_item_aantalontv NUMBER (15, 3);

/////////////////////////////////////////////////////////////////////////////////////////// MNNL#65934
ALTER TABLE mld_melding ADD mld_melding_actiedatum DATE;

/////////////////////////////////////////////////////////////////////////////////////////// AAXX#65358
DECLARE
    -- Bij afgemelden(5) of voltooien(6) van periodieke inspecties (NIET MJOB) wordt het veld ins_deelsrtcontrole_freezecost pas gevuld.
    -- Het veld ins_deelsrtcontrole_freezedate veld wordt daarbij nooit gevuld. Dat gebeurd alleen bij MJOB taken.
    -- Alle afgemelde of voltooide periodieke inspecties (NIET MJOB) ophalen waarvoor geldt:
    -- 1) de freezecost zijn groter dan 0 en
    -- 2) het aantal van het bijbehorende object is groter dan 1.
    CURSOR c_freezecost IS
        SELECT idsc.ins_deelsrtcontrole_key,
               id.ins_deel_aantal
          FROM ins_deelsrtcontrole idsc,
               ins_deel id,
               ins_srtcontrole isc,
               ctr_disc_params cdp
         WHERE idsc.ins_deel_key = id.ins_deel_key
           AND idsc.ins_srtcontrole_key = isc.ins_srtcontrole_key
           AND isc.ctr_discipline_key = cdp.ctr_ins_discipline_key
           AND idsc.ins_deelsrtcontrole_status IN (5, 6)
           AND idsc.ins_deelsrtcontrole_freezedate IS NULL
           AND id.ins_deel_aantal > 1
           AND idsc.ins_deelsrtcontrole_freezecost > 0
           AND cdp.ctr_disc_params_ismjob = 0;

BEGIN
    FOR f_freezecost IN c_freezecost
    LOOP
        -- Vermenigvuldig het totaalbedrag (freezecost) met het aantal opbjecten.
        UPDATE ins_deelsrtcontrole
           SET ins_deelsrtcontrole_freezecost = (f_freezecost.ins_deel_aantal * ins_deelsrtcontrole_freezecost)
         WHERE ins_deelsrtcontrole_key = f_freezecost.ins_deelsrtcontrole_key;
    END LOOP;
END;
/

/////////////////////////////////////////////////////////////////////////////////////////// MARX#63145
DROP INDEX res_i_res_deel3;
CREATE UNIQUE INDEX res_i_res_deel3 ON res_deel(res_ins_deel_key, res_prs_perslid_key, res_discipline_key, res_deel_verwijder);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66178
ALTER TABLE prs_perslid ADD prs_perslid_visibility NUMBER(3) DEFAULT 0 NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#60561
ALTER TABLE res_ruimte ADD res_ruimte_graphhooksecret VARCHAR(128);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66441
ALTER TABLE ins_srtdeel ADD ins_srtdeel_acadsymbol_dwgx NUMBER(16,3);
ALTER TABLE ins_srtdeel ADD ins_srtdeel_acadsymbol_dwgy NUMBER(16,3);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#65949
ALTER TABLE bes_srtdeel MODIFY bes_srtdeel_veelvoud NUMBER(9,3);

/////////////////////////////////////////////////////////////////////////////////////////// FLEX#64726
CREATE_TABLE(ins_deel_state_history_all, 0)
(
    ins_deel_state_history_all_key
        NUMBER(10)
        CONSTRAINT ins_k_deel_state_histall_key PRIMARY KEY,
    ins_deel_key
        NUMBER(10)
        CONSTRAINT ins_r_ins_deel_key3 REFERENCES ins_deel(ins_deel_key),
    ins_deel_statedate
        DATE,
    ins_deel_state
        VARCHAR2(128),
    ins_deel_statetime
        NUMBER
);

CREATE SEQUENCE ins_s_ins_deel_st_histall_key MINVALUE 1;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#65180
ALTER TABLE fac_import_app ADD   fac_import_app_delimiter VARCHAR(2);
ALTER TABLE fac_export_app ADD   fac_export_app_delimiter VARCHAR(2);

/////////////////////////////////////////////////////////////////////////////////////////// FMHN#66368
ALTER TABLE fac_faq ADD fac_faq_vervaldatum DATE;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66612
ALTER TABLE alg_gebouw MODIFY (alg_gebouw_dwgx NUMBER(16,3) );
ALTER TABLE alg_gebouw MODIFY (alg_gebouw_dwgy NUMBER(16,3) );

ALTER TABLE prj_deel MODIFY (prj_deel_dwgx NUMBER(16,3) );
ALTER TABLE prj_deel MODIFY (prj_deel_dwgy NUMBER(16,3) );
ALTER TABLE prj_deel MODIFY (prj_deel_dwgz NUMBER(16,3) );

ALTER TABLE prj_scenario_note MODIFY (prj_scenario_note_DWGX NUMBER(16,3) );
ALTER TABLE prj_scenario_note MODIFY (prj_scenario_note_DWGY NUMBER(16,3) );

ALTER TABLE prj_werkplek MODIFY (prj_werkplek_dwgx NUMBER(16,3) );
ALTER TABLE prj_werkplek MODIFY (prj_werkplek_dwgy NUMBER(16,3) );
ALTER TABLE prj_werkplek MODIFY (prj_werkplek_dwgz NUMBER(16,3) );

ALTER TABLE prs_werkplek MODIFY (prs_werkplek_dwgx NUMBER(16,3) );
ALTER TABLE prs_werkplek MODIFY (prs_werkplek_dwgy NUMBER(16,3) );
ALTER TABLE prs_werkplek MODIFY (prs_werkplek_dwgz NUMBER(16,3) );

/////////////////////////////////////////////////////////////////////////////////////////// FMHN#63210
INSERT INTO fac_notificatie_job (fac_notificatie_job_view, fac_notificatie_job_oms, fac_notificatie_job_mode, fac_notificatie_job_interval, fac_notificatie_job_flags)
     VALUES ('fac_v_noti_auditfail_day', 'Dagelijkse signaleringen van >5 inlogpogingen', 2, 24, 0);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66765
drop index mld_i_mld_kenmerkmelding2;
drop index mld_i_mld_kenmerkmelding3;

drop index mld_i_mld_kenmerkopdr2;
drop index mld_i_mld_kenmerkopdr3;

drop index bes_i_bes_kenmerkbestell2;
drop index bes_i_bes_kenmerkbestell3;

drop index bes_i_bes_kenmerkbesteli2;
drop index bes_i_bes_kenmerkbesteli3;

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

-- Toevoegen ontbrekende gebruiker om HMAIL-API uit te voeren
INSERT INTO prs_perslid (prs_perslid_module,
                         prs_srtperslid_key,
                         prs_afdeling_key,
                         prs_perslid_naam,
                         prs_perslid_oslogin,
                         prs_perslid_apikey,
                         prs_perslid_flags,
                         prs_perslid_opmerking)
   SELECT prs_perslid_module,
          prs_srtperslid_key,
          prs_afdeling_key,
          'API-user tbv. hMail-koppeling',
          '_HMAIL',
          DBMS_RANDOM.string ('a', 32),
          36,
          'System account for incoming email.'||CHR(13)||'For Facilitor internal use'
     FROM prs_perslid
    WHERE prs_perslid_oslogin = '_FACILITOR'
      AND NOT EXISTS (SELECT 1 FROM prs_perslid WHERE prs_perslid_oslogin = '_HMAIL');

-- Toevoegen ontbrekende gebruiker om PUTORDERS-API uit te voeren
INSERT INTO prs_perslid (prs_perslid_module,
                         prs_srtperslid_key,
                         prs_afdeling_key,
                         prs_perslid_naam,
                         prs_perslid_oslogin,
                         prs_perslid_apikey,
                         prs_perslid_flags,
                         prs_perslid_opmerking)
   SELECT prs_perslid_module,
          prs_srtperslid_key,
          prs_afdeling_key,
          'API-user tbv. Putorders-koppeling',
          '_PUTORDERS',
          fac.getsetting('puo_fclt_web_apikey'),
          36,
          'System account for outgoing email.'||CHR(13)||'For Facilitor internal use'
     FROM prs_perslid
    WHERE prs_perslid_oslogin = '_FACILITOR'
      AND NOT EXISTS (SELECT 1 FROM prs_perslid WHERE prs_perslid_oslogin = '_PUTORDERS');

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66686
DELETE FROM fac_notificatie
 WHERE fac_notificatie_status IN (0,16)
   AND fac_notificatie_systeemadres IS NULL
   AND prs_bedrijfadres_key IS NULL;

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#56923
DELETE FROM fac_api
 WHERE LOWER(fac_api_filepath) IN ('appl/api/api_perslid.asp', 'appl/api/api_ressoap_info.asp');

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#65005

ALTER TABLE fac_import_app ADD
  fac_import_app_browse_f_key
    NUMBER(10)
    CONSTRAINT fac_r_fac_functie_key4 REFERENCES fac_functie(fac_functie_key);

ALTER TABLE fac_export_app ADD
  fac_export_app_browse_f_key
    NUMBER(10)
    CONSTRAINT fac_r_fac_functie_key5 REFERENCES fac_functie(fac_functie_key);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66924
ALTER TABLE fac_imp_catalogus        ADD ( ins_srtdeel_sensortype         NUMBER(3)
                                         , ins_srtdeel_acadsymbol_dwgx    NUMBER(16,3)
                                         , ins_srtdeel_acadsymbol_dwgy    NUMBER(16,3)
                                         , ins_srtdeel_externnr           VARCHAR2(256) );
ALTER TABLE fac_imp_mld              ADD ( mld_stdmelding_externnr        VARCHAR2(256) );
ALTER TABLE fac_imp_organisatie      ADD ( prs_afdeling_externid          VARCHAR2 (256) );
ALTER TABLE fac_imp_kpn              ADD ( prs_kostenplaats_externnr      VARCHAR2(256) );
ALTER TABLE fac_imp_perslid          ADD ( prs_perslid_visibility         NUMBER(3)
                                         , prs_perslid_externid           VARCHAR2(256) );
ALTER TABLE fac_imp_ins              ADD ( ins_deel_externnr              VARCHAR2(256) );
ALTER TABLE fac_imp_res_artikel_sync ADD ( res_artikel_externnr           VARCHAR2(256) );
ALTER TABLE fac_imp_bedrijfadres     ADD ( prs_bedrijfadres_plugin        VARCHAR2 (320)
                                         , prs_bedrijfadres_plugindata    VARCHAR2 (4000) );
ALTER TABLE fac_imp_factuur          ADD ( externnr                       VARCHAR2(256) );
ALTER TABLE fac_imp_flex             ADD ( kenmerk_wissen                 NUMBER(1) );
ALTER TABLE fac_imp_faq              ADD ( fac_faq_vervaldatum            DATE );

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#66929
ALTER TABLE imp_schedule ADD (
  prs_perslid_key
  NUMBER(10)
  CONSTRAINT imp_r_perslid REFERENCES prs_perslid(prs_perslid_key) ON DELETE SET NULL
);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#64018
-- Dan hebben we de oude waarde in de logging
SELECT fac_setting_pvalue
  FROM fac_setting
 WHERE fac_setting_name = 'csstemplate';

-- Styling resetten
UPDATE fac_setting
   SET fac_setting_pvalue = NULL
 WHERE fac_setting_name = 'csstemplate';

/////////////////////////////////////////////////////////////////////////////////////////// KFHT#67002
ALTER TABLE prs_contactpersoon MODIFY (prs_contactpersoon_email VARCHAR2(200));

/////////////////////////////////////////////////////////////////////////////////////////// DLLG#60172
DEF_MENUITEM(3, 'lcl_mobile_res_catering',  '', 'RES', 'appl/pda/reservering.asp?restype=C', 0, 0, 'WEB_RESUSE', 'W', '0', 'fa-coffee');
MENU_INS_AFTER('lcl_mobile_res_catering', 'lcl_mobile_res_voorziening', 2);
DEF_MENUITEM(3, 'lcl_mobile_res_looplijst', '', 'RES', 'appl/pda/catering_looplijst.asp',    0, 0, 'WEB_RESUSE', 'W', '0', 'fa-person-carry');
MENU_INS_AFTER('lcl_mobile_res_looplijst', 'lcl_mobile_res_catering', 2);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#67053

-- Verwijder alle kenmerken met kenmerktype 'Q' / Blanco, incl. references (ALG, BEZ, FAQ, FIN, PRS)
DELETE FROM alg_onrgoedkenmerk
      WHERE alg_kenmerk_key IN
                (SELECT alg_kenmerk_key
                   FROM alg_kenmerk
                  WHERE alg_kenmerk_kenmerktype = 'Q');

DELETE FROM alg_kenmerk
      WHERE alg_kenmerk_kenmerktype = 'Q';

DELETE FROM bez_kenmerkwaarde
      WHERE bez_kenmerk_key IN
                (SELECT bez_kenmerk_key
                   FROM bez_kenmerk
                  WHERE bez_kenmerk_kenmerktype = 'Q');

DELETE FROM bez_kenmerk
      WHERE bez_kenmerk_kenmerktype = 'Q';

DELETE FROM faq_kenmerk
      WHERE faq_kenmerk_kenmerktype = 'Q';

DELETE FROM fin_kenmerkfactregel
      WHERE fin_kenmerk_key IN
                (SELECT fin_kenmerk_key
                   FROM fin_kenmerk
                  WHERE fin_kenmerk_kenmerktype = 'Q');

DELETE FROM fin_kenmerk
      WHERE fin_kenmerk_kenmerktype = 'Q';

DELETE FROM prs_kenmerk
      WHERE prs_kenmerk_kenmerktype = 'Q';

-- Verwijder alle kenmerken van een kenmerksoort met kenmerktype 'Q' / Blanco, incl. references (BES, CNT, INS, MLD, RES)
DELETE FROM bes_kenmerkbestell
      WHERE bes_kenmerk_key IN
                (SELECT bes_kenmerk_key
                   FROM bes_kenmerk
                  WHERE bes_srtkenmerk_key IN
                            (SELECT bes_srtkenmerk_key
                               FROM bes_srtkenmerk
                              WHERE bes_srtkenmerk_kenmerktype = 'Q'));

DELETE FROM bes_kenmerkbesteli
      WHERE bes_kenmerk_key IN
                (SELECT bes_kenmerk_key
                   FROM bes_kenmerk
                  WHERE bes_srtkenmerk_key IN
                            (SELECT bes_srtkenmerk_key
                               FROM bes_srtkenmerk
                              WHERE bes_srtkenmerk_kenmerktype = 'Q'));

DELETE FROM bes_kenmerk
      WHERE bes_srtkenmerk_key IN
                (SELECT bes_srtkenmerk_key
                   FROM bes_srtkenmerk
                  WHERE bes_srtkenmerk_kenmerktype = 'Q');

DELETE FROM cnt_kenmerkcontract
      WHERE cnt_kenmerk_key IN
                (SELECT cnt_kenmerk_key
                   FROM cnt_kenmerk
                  WHERE cnt_srtkenmerk_key IN
                            (SELECT cnt_srtkenmerk_key
                               FROM cnt_srtkenmerk
                              WHERE cnt_srtkenmerk_kenmerktype = 'Q'));

DELETE FROM cnt_kenmerk
      WHERE cnt_srtkenmerk_key IN
                (SELECT cnt_srtkenmerk_key
                   FROM cnt_srtkenmerk
                  WHERE cnt_srtkenmerk_kenmerktype = 'Q');

DELETE FROM ins_kenmerkdeel
      WHERE ins_kenmerk_key IN
                (SELECT ins_kenmerk_key
                   FROM ins_kenmerk
                  WHERE ins_srtkenmerk_key IN
                            (SELECT ins_srtkenmerk_key
                               FROM ins_srtkenmerk
                              WHERE ins_srtkenmerk_kenmerktype = 'Q'));

DELETE FROM ins_kenmerk
      WHERE ins_srtkenmerk_key IN (SELECT ins_srtkenmerk_key
                                     FROM ins_srtkenmerk
                                    WHERE ins_srtkenmerk_kenmerktype = 'Q');

DELETE FROM mld_kenmerkmelding
      WHERE mld_kenmerk_key IN
                (SELECT mld_kenmerk_key
                   FROM mld_kenmerk
                  WHERE mld_srtkenmerk_key IN
                            (SELECT mld_srtkenmerk_key
                               FROM mld_srtkenmerk
                              WHERE mld_srtkenmerk_kenmerktype = 'Q'));

DELETE FROM mld_kenmerkopdr
      WHERE mld_kenmerk_key IN
                (SELECT mld_kenmerk_key
                   FROM mld_kenmerk
                  WHERE mld_srtkenmerk_key IN
                            (SELECT mld_srtkenmerk_key
                               FROM mld_srtkenmerk
                              WHERE mld_srtkenmerk_kenmerktype = 'Q'));

DELETE FROM mld_kenmerk
      WHERE mld_srtkenmerk_key IN (SELECT mld_srtkenmerk_key
                                     FROM mld_srtkenmerk
                                    WHERE mld_srtkenmerk_kenmerktype = 'Q');

DELETE FROM res_kenmerk
      WHERE res_srtkenmerk_key IN (SELECT res_srtkenmerk_key
                                     FROM res_srtkenmerk
                                    WHERE res_srtkenmerk_kenmerktype = 'Q');

-- Verwijder alle kenmerksoorten met kenmerktype 'Q' / Blanco, incl. references (BES, CNT, INS, MLD, RES)
DELETE FROM bes_srtkenmerk
      WHERE bes_srtkenmerk_kenmerktype = 'Q';

DELETE FROM cnt_srtkenmerk
      WHERE cnt_srtkenmerk_kenmerktype = 'Q';

DELETE FROM ins_srtkenmerk
      WHERE ins_srtkenmerk_kenmerktype = 'Q';

DELETE FROM mld_srtkenmerk
      WHERE mld_srtkenmerk_kenmerktype = 'Q';

DELETE FROM res_srtkenmerk
      WHERE res_srtkenmerk_kenmerktype = 'Q';

/////////////////////////////////////////////////////////////////////////////////////////// FMHN#67972
ALTER TABLE res_ruimte ADD res_ruimte_minbezoekers
      NUMBER(5)
      DEFAULT 0
      CONSTRAINT res_c_ruimte_minbezoekers CHECK(res_ruimte_minbezoekers IS NOT NULL);

/////////////////////////////////////////////////////////////////////////////////////////// FMHN#67970
ALTER TABLE bes_srtdeel ADD bes_srtdeel_maximum
        NUMBER(6);

/////////////////////////////////////////////////////////////////////////////////////////// FCLT#*****
///////////////////////////////////////////////////////////////////////////////////////////

REGISTERONCE('$Id$')

#include "epilogue.inc"
