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

COMMIT;

/////////////////////////////////////////////////////////////////////////////////////////// FSN#36226
ALTER TABLE fac_email_setting DROP PRIMARY KEY;
ALTER TABLE fac_email_setting MODIFY (fac_email_setting_user VARCHAR2 (255) NOT NULL);
ALTER TABLE fac_email_setting ADD (fac_email_setting_key NUMBER(10));
CREATE SEQUENCE fac_s_fac_email_setting_key START WITH 1;
UPDATE fac_email_setting SET fac_email_setting_key = fac_s_fac_email_setting_key.NEXTVAL;
ALTER TABLE fac_email_setting ADD CONSTRAINT fac_k_fac_email_setting_key PRIMARY KEY (fac_email_setting_key);

CREATE_TRIGGER(fac_t_fac_email_setting_B_IU)
BEFORE INSERT OR UPDATE ON fac_email_setting
FOR EACH ROW
BEGIN
    UPDATE_PRIMARY_KEY(fac_email_setting_key, fac_s_fac_email_setting_key);
END;
/

DEF_MENUENTRY(2, 99090, 'lcl_menu_fac_email_setting', '', 'FAC', 'appl/mgt/fac_email_setting.asp', 0, 0, 'WEB_FACTAB');

/////////////////////////////////////////////////////////////////////////////////////////// FSN#36227
DEF_MENUENTRY(2, 99100, 'lcl_menu_fac_notificaties', '', 'FAC', 'appl/mgt/fac_srtnotificatie.asp?cust=1', 0, 0, 'WEB_FACTAB');

/////////////////////////////////////////////////////////////////////////////////////////// HSLE#35760
CREATE VIEW ins_v_udr_deelmelding AS SELECT '' dummy FROM DUAL;
INSERT INTO fac_usrrap (fac_usrrap_omschrijving, fac_usrrap_view_name,fac_usrrap_info, fac_functie_key, fac_usrrap_functie)
 SELECT 'UDR: Objectmeldingen','INS_V_UDR_DEELMELDING','Basisrapport voor objecten met hun meldinggegevens', fac_functie_key, 32
   FROM fac_functie WHERE fac_functie_code='WEB_UDRMAN'
    AND NOT EXISTS (SELECT '' FROM fac_usrrap WHERE UPPER(fac_usrrap_view_name)='INS_V_UDR_DEELMELDING');

/////////////////////////////////////////////////////////////////////////////////////////// FSN#36595
UPDATE fac_setting
   SET fac_setting_pvalue = NULL
 WHERE fac_setting_name = 'puo_proxyserveripaddress'
   AND fac_setting_pvalue = '127.0.0.1';

/////////////////////////////////////////////////////////////////////////////////////////// HSLE#36201
ALTER TABLE mld_stdmelding
    ADD mld_stdmelding_subject  -- 0:geen onderwerp, 1:optionele onderwerp, 2:verplichte onderwerp
        NUMBER(1)
        DEFAULT 1
        CONSTRAINT mld_c_mld_stdmelding_subject CHECK(mld_stdmelding_subject IS NOT NULL);

-- als omschrijving onzichtbaar dan onderwerp ook onzichtbaar anders (default) optioneel
UPDATE mld_stdmelding
   SET mld_stdmelding_subject = mld_stdmelding_freetext
   WHERE mld_stdmelding_freetext = 0;

/////////////////////////////////////////////////////////////////////////////////////////// BLCC#36669
UPDATE res_disc_params
   SET res_disc_params_expire_tijd = NULL
 WHERE res_disc_params_expire_tijd = -1;

/////////////////////////////////////////////////////////////////////////////////////////// DENB#35726
ALTER TABLE mld_afmeldtekst ADD mld_afmeldtekst_usefor number(1) DEFAULT 1 NOT NULL;
ALTER TABLE fac_imp_mldafmtxt ADD mld_afmeldtekst_usefor number(1);

/////////////////////////////////////////////////////////////////////////////////////////// AKZA#36031
ALTER TABLE ins_deel ADD ins_deel_actief NUMBER(1) DEFAULT 1 NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// AAIT#36912
UPDATE fac_menuitems
   SET fac_functie_key = (SELECT fac_functie_key
                            FROM fac_functie
                           WHERE fac_functie_code = 'FAC_PRSSYS')
 WHERE fac_menuitems_label = 'lcl_menu_cad_verify';

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37004/FSN#37999
#include "../ctr/ctr_tab.src"
#include "../ctr/ctr_seq.src"
#include "../ctr/ctr_ind.src"
#include "../ctr/ctr_tri.src"
#include "../ctr/ctr_ini.src"

ALTER TABLE ins_srtcontrole ADD
    ctr_discipline_key NUMBER(10)
        --CONSTRAINT ctr_c_ins_srtcontrole_dis_key CHECK(ctr_discipline_key IS NOT NULL)
        CONSTRAINT ctr_c_ins_srtctr_discipline REFERENCES ins_tab_discipline(ins_discipline_key);

UPDATE ins_srtcontrole SET
    ctr_discipline_key = (SELECT ctr_ins_discipline_key
                            FROM ctr_disc_params
                           WHERE ctr_disc_params_controle_type = ins_srtcontrole_type);

ALTER TABLE ins_srtcontrole ADD
        CONSTRAINT ctr_c_ins_srtcontrole_dis_key CHECK(ctr_discipline_key IS NOT NULL);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37318
ALTER TABLE ins_srtcontroledl_xcp ADD
		ins_srtcontroledl_xcp_opmerk  VARCHAR2(320);

ALTER TABLE ins_srtcontrole ADD
		ins_srtcontrole_afbouwtijd NUMBER(6,2);

ALTER TABLE ins_srtcontrole ADD
		fin_btwtabelwaarde_key NUMBER(10)
 		CONSTRAINT ins_r_fin_btwtabelwaarde1 REFERENCES fin_btwtabelwaarde(fin_btwtabelwaarde_key);

ALTER TABLE ins_srtcontroledl_xcp
		MODIFY ins_srtcontroledl_xcp_perc DEFAULT NULL;

UPDATE ins_srtcontroledl_xcp
   SET ins_srtcontroledl_xcp_perc = NULL
 WHERE ins_srtcontroledl_xcp_perc = 100;

/////////////////////////////////////////////////////////////////////////////////////////// FSN#33999

DEF_FAC_FUNCTIE2('WEB_CTRMGT', 'Modulebeheer:Periodieke taken',            'CTR', 0, 0, 2, 'Modulebeheer');
ALTER PACKAGE fac COMPILE; // anders (nog) invalid en lukt het volgende niet niet
ALTER PACKAGE fac COMPILE BODY;
INSERT INTO fac_groeprechten
          ( fac_groep_key
          , fac_functie_key
          , fac_gebruiker_prs_level_read
          , fac_gebruiker_alg_level_read
          , fac_gebruiker_prs_level_write
          , fac_gebruiker_alg_level_write
          )
   SELECT g.fac_groep_key
        , (select fac_functie_key from fac_functie where fac_functie_code = 'WEB_CTRMGT')
        , r.fac_gebruiker_prs_level_read
        , r.fac_gebruiker_alg_level_read
        , r.fac_gebruiker_prs_level_write
        , r.fac_gebruiker_alg_level_write
     FROM fac_groeprechten r
        , fac_functie f
        , fac_groep g
    WHERE r.fac_functie_key = f.fac_functie_key
      AND r.fac_groep_key = g.fac_groep_key
      AND f.fac_functie_code = 'WEB_PRSSYS';

DEF_FAC_FUNCTIE2('WEB_CTRUSE', 'Backoffice:Periodieke taken',    'CTR',  3, 1,    1, 'Om periodieke taken van objecten te kunnen uitvoeren');

// Als je INSUSE op een discipline met inspecties had krijg je CTRUSE schrijfrechten op alledrie de CTR-disciplines
// Dat is backwards compatible en kan eventuel na upgrade handmatig aangescherpt worden.
INSERT INTO fac_groeprechten (fac_groep_key,
                              fac_functie_key,
                              fac_gebruiker_prs_level_read,
                              fac_gebruiker_alg_level_read,
                              fac_gebruiker_prs_level_write,
                              fac_gebruiker_alg_level_write,
                              ins_discipline_key)
   SELECT DISTINCT g.fac_groep_key,
                   (SELECT fac_functie_key
                      FROM fac_functie
                     WHERE fac_functie_code = 'WEB_CTRUSE'),
                   -1,
                   -1,
                   -1,
                   -1,
                   c.ins_discipline_key
     FROM ins_tab_discipline c,
          fac_groeprechten r,
          fac_functie f,
          fac_groep g
    WHERE     c.ins_discipline_module = 'CTR'
          AND r.fac_functie_key = f.fac_functie_key
          AND r.fac_groep_key = g.fac_groep_key
          AND f.fac_functie_code = 'WEB_INSUSE'
          AND r.ins_discipline_key IN
                   (SELECT sg.ins_discipline_key
                      FROM ins_srtdeel s, ins_srtgroep sg, ins_srtcontrole isc
                     WHERE s.ins_srtgroep_key = sg.ins_srtgroep_key
                           AND (isc.ins_srtcontrole_niveau = 'S'
                                AND isc.ins_srtinstallatie_key = s.ins_srtdeel_key
                                OR isc.ins_srtcontrole_niveau = 'G'
                                  AND isc.ins_srtinstallatie_key = sg.ins_srtgroep_key
                                OR isc.ins_srtcontrole_niveau = 'D'
                                  AND isc.ins_srtinstallatie_key = sg.ins_discipline_key));
UPDATE fac_menuitems
   SET fac_functie_key =
          (SELECT fac_functie_key
             FROM fac_functie
            WHERE fac_functie_code = 'WEB_CTRUSE')
 WHERE fac_menuitems_label = 'lcl_menu_ins_controle';

DEF_MENUITEM(2, 'lcl_menu_ctr_disciplines' , '', 'CTR', 'appl/mgt/ctr_discipline.asp', 0, 0, 'WEB_CTRMGT', 'W', '1', '');
MENU_INS_AFTER( 'lcl_menu_ctr_disciplines' , 'lcl_menu_ins_kenmerkdomeinen', 2);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#32209
DEF_MENUITEM(3, 'lcl_mobile_planned_act', '', 'CTR', 'appl/pda/ins_inspect_list.asp', 0, 0, 'WEB_CTRUSE', 'R', '1', 'm_acties-werk-terugkerende-zaken.png');
MENU_INS_AFTER( 'lcl_mobile_planned_act', 'lcl_mobile_objecten', 2);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#33170*
INSERT INTO fac_menuitems (fac_menuitems_groep,
                           fac_menuitems_label,
                           fac_menuitems_oms,
                           fac_menuitems_module,
                           fac_menuitems_url,
                           fac_menuitems_srtdisc,
                           fac_menuitems_disc,
                           fac_functie_key,
                           fac_menuitems_rw,
                           fac_menuitems_default,
                           fac_menuitems_image)
   SELECT 1,
          'lcl_menu_kpi',
          '',
          'KPI',
          'appl/kpi/kpi_search.asp',
          0,
          0,
          fac_functie_key,
          'R',
          '0',
          ''
     FROM fac_functie
    WHERE fac_functie_code = 'WEB_KPIRAP'
          AND NOT EXISTS (SELECT ''
                            FROM fac_menuitems
                           WHERE fac_menuitems_label = 'lcl_menu_kpi');

/////////////////////////////////////////////////////////////////////////////////////////// AAIT#35977
ALTER TABLE ins_kenmerk MODIFY ins_kenmerk_default VARCHAR2(4000);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37025
ALTER TABLE prs_bedrijfadres ADD
    prs_bedrijfadres_encoding NUMBER(3) DEFAULT 0 NOT NULL;

UPDATE prs_bedrijfadres
   SET prs_bedrijfadres_encoding = 1
 WHERE LOWER(prs_bedrijfadres_url) LIKE '%www.axxerion.com%';  /* bizar dat dit hier in de core hoort! */

/////////////////////////////////////////////////////////////////////////////////////////// MARX#37122
ALTER TABLE prs_bedrijfadres ADD
    prs_bedrijfadres_authmethod NUMBER(3) DEFAULT 0 NOT NULL;

ALTER TABLE prs_bedrijfadres ADD /* Future use */
    prs_bedrijfadres_soapversion VARCHAR2(10);

ALTER TABLE prs_bedrijfadres ADD
    prs_bedrijfadres_soapaction VARCHAR2(128);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#36975
CREATE_TABLE(fac_imp_translation, 0)
(
   locale_label     VARCHAR2(60 CHAR),
   locale_module    VARCHAR2(3),
   locale_lang      VARCHAR2(3) NOT NULL,
   locale_tekst     VARCHAR2(2000 CHAR)
);

INSERT INTO fac_import_app (fac_import_app_code, fac_import_app_oms, fac_functie_key)
   SELECT 'TRANSLATION', 'Import of FACILITOR translation file', fac_functie_key
     FROM fac_functie
    WHERE fac_functie_code = 'WEB_LCLSYS';

CREATE VIEW fac_v_rap_language AS SELECT '' dummy FROM DUAL;

INSERT INTO fac_usrrap (fac_usrrap_omschrijving, fac_usrrap_view_name,fac_usrrap_info, fac_functie_key, fac_usrrap_functie)
 SELECT 'Vertalingen','FAC_V_RAP_LANGUAGE','Basisrapport voor vertalingen export', fac_functie_key, 32
   FROM fac_functie WHERE fac_functie_code='WEB_LCLSYS'
    AND NOT EXISTS (SELECT '' FROM fac_usrrap WHERE UPPER(fac_usrrap_view_name)='FAC_V_RAP_LANGUAGE');


/////////////////////////////////////////////////////////////////////////////////////////// ALLI#35808
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'));

/////////////////////////////////////////////////////////////////////////////////////////// AAIT#36874
ALTER TABLE fin_factuur ADD fin_factuur_bron NUMBER(3) DEFAULT 0 NOT NULL;

///////////////////////////////////////////////////////////////////////////////////////////  FSN#37228
UPDATE fac_module SET fac_module_remark = 'Facilitor algemeen' WHERE fac_module_name = 'FAC';
UPDATE fac_module SET fac_module_remark = 'Basis: Vastgoed- en ruimtebeheer' WHERE fac_module_name = 'ALG';
UPDATE fac_module SET fac_module_remark = 'Basis: Organisatie- en personenbeheer' WHERE fac_module_name = 'PRS';
_FAC_MODULE('PDA','Facilitor Mobile')
_FAC_MODULE('UDR','User Defined Reporting')
UPDATE fac_functie SET fac_functie_module='UDR' WHERE fac_functie_code='WEB_UDRMAN';

/////////////////////////////////////////////////////////////////////////////////////////// FSN#34066
CREATE VIEW ins_v_udr_deelkenmerk_cnd AS SELECT '' dummy FROM DUAL;
INSERT INTO fac_usrrap (fac_usrrap_omschrijving, fac_usrrap_view_name,fac_usrrap_info, fac_functie_key, fac_usrrap_functie)
 SELECT 'UDR: Objecten plus','INS_V_UDR_DEELKENMERK_CND','Basisrapport voor object+kenmerk rapportages', fac_functie_key, 32
   FROM fac_functie WHERE fac_functie_code='WEB_UDRMAN'
    AND NOT EXISTS (SELECT '' FROM fac_usrrap WHERE UPPER(fac_usrrap_view_name)='INS_V_UDR_DEELKENMERK_CND');

/////////////////////////////////////////////////////////////////////////////////////////// UWVA#36747
ALTER TABLE alg_gebouw ADD alg_gebouw_vervaldatum DATE;

/////////////////////////////////////////////////////////////////////////////////////////// UWVA#36747
ALTER TABLE fac_email_setting
     ADD fac_email_setting_frommode NUMBER(3)
     DEFAULT 0 NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// AKZA#37157
// Merk op: er is nog bij geen enkele klant de syncstate ingevuld (akza gebruikt
// een res_ruimte_syncstate1). Daarom is geen dataconversie nodig hier
ALTER TABLE res_ruimte DROP COLUMN res_ruimte_syncstate;
ALTER TABLE res_ruimte ADD res_ruimte_syncstate CLOB;
ALTER TABLE res_ruimte ADD res_ruimte_syncdate DATE;

/////////////////////////////////////////////////////////////////////////////////////////// ALLI#35808
INSERT INTO prs_bedrijfadres (prs_bedrijfadres_type, prs_bedrijf_key, prs_bedrijfadres_url, prs_bedrijfadres_xsl)
SELECT 'V', b.prs_bedrijf_key, b.prs_bedrijf_xmldetails_loc, a.prs_bedrijfadres_xsl
  FROM prs_bedrijf b
     , prs_bedrijfadres a
 WHERE a.prs_bedrijf_key = b.prs_bedrijf_key
   AND a.prs_bedrijfadres_type = 'B'
   AND b.prs_bedrijf_xmldetails_loc IS NOT NULL
   AND b.prs_bedrijf_verwijder IS NULL;

/////////////////////////////////////////////////////////////////////////////////////////// MARX#36974
ALTER TABLE fin_factuur ADD fin_factuur_gbedrag NUMBER(10,2);

/////////////////////////////////////////////////////////////////////////////////////////// HSLE#37203
ALTER TABLE ins_kenmerk ADD ins_kenmerk_wissen
      NUMBER(1)
      DEFAULT 0 NOT NULL
      CONSTRAINT ins_c_ins_kenmerk_wissen CHECK(ins_kenmerk_wissen IN (0,1,2));

/////////////////////////////////////////////////////////////////////////////////////////// RWSN#35302
DEF_FAC_SRTNOT('INSIN2', 0, 'Object ingenomen', 'ins/ins_deel.asp?ins_key=', '0', 'deel', 10);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#36602
ALTER TABLE fac_import ADD fac_import_backupdir VARCHAR(320);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37554
ALTER TABLE ins_srtcontrole ADD
(
    prs_kostenplaats_key
        NUMBER(10)
        CONSTRAINT ins_r_prs_kostenplaats_key1 REFERENCES prs_kostenplaats(prs_kostenplaats_key)
);
/////////////////////////////////////////////////////////////////////////////////////////// FSN#35197
UPDATE fac_menuitems
   SET fac_menuitems_url = 'appl/mgt/fac_widget.asp'
 WHERE fac_menuitems_url = 'appl/fac/fac_widget_search.asp';

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37529
CREATE TABLE fac_idp
(
    fac_idp_key
        NUMBER(10)
        CONSTRAINT fac_k_idp_key PRIMARY KEY,
    fac_idp_code            -- Voor &sso=<code>
        VARCHAR2(30),
    fac_idp_type            -- 1=Internal (login.asp, future use), 2=UID_DEC (deprecated),
        NUMBER(3),          -- 3=GUID-encrypted (deprecated), 4=JWT, 5=SAML (future use)
    fac_idp_algorithm       -- HS256 is HMAC-SHA256
        VARCHAR2(30),
    fac_idp_omschrijving
        VARCHAR2(30),
    fac_idp_opmerking
        VARCHAR2(320),
    fac_idp_secret
        VARCHAR2(128),
    fac_idp_audience
        VARCHAR2(128),
    fac_idp_issuer
        VARCHAR2(128),
    fac_idp_remote_loginurl
        VARCHAR2(128),
    fac_idp_remote_logouturl
        VARCHAR2(128),
    fac_idp_usermapping
        VARCHAR2(30),
    fac_idp_clockskew
        NUMBER(10),
    fac_idp_duration
        NUMBER(10),
-- Note: these column are defined in PRS_TAB.SRC
--    prs_afdeling_key         NUMBER(10)
--    prs_bedrijf_key          NUMBER(10)
    fac_functie_key
        NUMBER(10)
        CONSTRAINT fac_r_idp_functie REFERENCES fac_functie(fac_functie_key),
    fac_idp_internal
        NUMBER(1)
        DEFAULT 0 NOT NULL,
    fac_idp_ipfilter
        VARCHAR2(320),
    fac_idp_ipauto
        NUMBER(1)
        DEFAULT 0 NOT NULL,
    fac_idp_aanmaak
        DATE
        DEFAULT SYSDATE
);

ALTER TABLE fac_idp
ADD
(
    prs_bedrijf_key
        NUMBER(10)
        CONSTRAINT fac_r_idp_prs_bedrijf REFERENCES prs_bedrijf(prs_bedrijf_key) ON DELETE CASCADE
);
ALTER TABLE fac_idp ADD
(
    prs_afdeling_key
       NUMBER(10)
       CONSTRAINT alg_r_idp_prs_afdeling REFERENCES prs_afdeling(prs_afdeling_key) ON DELETE CASCADE
);
CREATE SEQUENCE fac_s_fac_idp_key MINVALUE 1;
CREATE UNIQUE INDEX fac_i_idp_code ON fac_idp(fac_idp_code);

CREATE_TRIGGER(fac_t_fac_idp_B_IU)
BEFORE INSERT OR UPDATE ON fac_idp
FOR EACH ROW
BEGIN
   UPDATE_PRIMARY_KEY(fac_idp_key, fac_s_fac_idp_key);
END;
/
ALTER PACKAGE fac COMPILE; // anders (nog) invalid en lukt het volgende niet niet
ALTER PACKAGE fac COMPILE BODY;

INSERT INTO fac_idp (fac_idp_code,
                     fac_idp_type,
                     fac_idp_omschrijving,
                     fac_idp_secret,
                     fac_idp_audience,
                     fac_idp_remote_loginurl,
                     fac_idp_remote_logouturl,
                     fac_idp_clockskew,
                     fac_idp_ipfilter)
   SELECT '1',
          3, /* Oldstyle GUID encrypted */
          'Automatically converted',
          fac.getSetting ('sso_advanced_secret'),
          (SELECT LOWER(fac_version_cust) FROM fac_version) || '.facilitor.nl',
          fac.getSetting ('sso_advanced_url'),
          fac.getSetting ('logoff_return_url'),
          fac.getSetting ('sso_advanced_timeout'),
          fac.getSetting ('sso_advanced_autoip')
     FROM DUAL
    WHERE fac.getSetting ('sso_advanced_secret') IS NOT NULL
          AND fac.getSetting ('sso_advanced_url') IS NOT NULL;

INSERT INTO fac_idp (fac_idp_code,
                     fac_idp_type,
                     fac_idp_omschrijving,
                     fac_idp_secret,
                     fac_idp_audience,
                     fac_idp_remote_loginurl,
                     fac_idp_remote_logouturl,
                     fac_idp_clockskew,
                     fac_idp_ipfilter)
   SELECT '2',
          3, /* Oldstyle GUID encrypted */
          'Automatically converted',
          fac.getSetting ('sso_advanced_secret_alt'),
          (SELECT LOWER(fac_version_cust) FROM fac_version) || '.facilitor.nl',
          fac.getSetting ('sso_advanced_url_alt'),
          fac.getSetting ('logoff_return_url'),
          fac.getSetting ('sso_advanced_timeout'),
          fac.getSetting ('sso_advanced_autoip_alt')
     FROM DUAL
    WHERE fac.getSetting ('sso_advanced_secret_alt') IS NOT NULL
          AND fac.getSetting ('sso_advanced_url_alt') IS NOT NULL;

DEF_MENUENTRY(2, 99110, 'lcl_menu_fac_idp'             , '', 'FAC', 'appl/mgt/fac_idp.asp', 0, 0, 'WEB_FACFAC');

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37536
ALTER TABLE prs_perslid ADD
    prs_perslid_credentials_datum /* wanneer voor het laatst gewijzigd. Oudere sessies ongeldig */
        DATE
        DEFAULT SYSDATE NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// FSN#37479
-- Daar zat een foutje in sinds 10-3-2010
UPDATE fac_menuitems
   SET fac_functie_key =
          (SELECT fac_functie_key
             FROM fac_functie
            WHERE fac_functie_code = 'WEB_MLDBOF')
 WHERE fac_menuitems_url = 'appl/mld/mld_show_note.asp?urole=bo'
       AND fac_functie_key = (SELECT fac_functie_key
                                FROM fac_functie
                               WHERE fac_functie_code = 'WEB_UURBOF');

UPDATE fac_menuitems SET fac_menuitems_label='lcl_mobile_opdrachten1' WHERE fac_menuitems_label='lcl_mobile_opdrachten' AND fac_functie_key=(SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_ORDBO2');
UPDATE fac_menuitems SET fac_menuitems_label='lcl_mobile_opdrachten2' WHERE fac_menuitems_label='lcl_mobile_opdrachten' AND fac_functie_key=(SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_ORDBOF');
UPDATE fac_menuitems SET fac_menuitems_label='lcl_mobile_opdrachten3' WHERE fac_menuitems_label='lcl_mobile_opdrachten' AND fac_functie_key=(SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_MLDORD');
UPDATE fac_menuitems SET fac_menuitems_label='lcl_menu_mld_notes_bo' WHERE fac_menuitems_label='lcl_menu_mld_notes' AND fac_functie_key IN (SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code IN ('WEB_UURBOF','WEB_MLDBOF'));
UPDATE fac_menuitems SET fac_menuitems_label='lcl_menu_sle_sleutels_bo' WHERE fac_menuitems_label='lcl_menu_sle_sleutels' AND fac_functie_key=(SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_SLEBOF');
UPDATE fac_menuitems SET fac_menuitems_label='lcl_menu_fac_fiattering_fe' WHERE fac_menuitems_label='lcl_menu_fac_fiattering' AND fac_functie_key=(SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_MLDUSE');
UPDATE fac_menuitems SET fac_menuitems_label='lcl_mobile_meldingen2' WHERE fac_menuitems_label='lcl_mobile_meldingen' AND fac_functie_key=(SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_MLDBO2');

CREATE UNIQUE INDEX fac_i_fac_menuitems1 ON fac_menuitems (fac_menuitems_label);

/////////////////////////////////////////////////////////////////////////////////////////// PNBR#36941
ALTER TABLE res_deel ADD res_deel_image VARCHAR2(255);
ALTER TABLE res_artikel ADD res_artikel_image VARCHAR2(255);

/////////////////////////////////////////////////////////////////////////////////////////// FSN#36975
ALTER TABLE fac_locale_xsl
  ADD fac_locale_xsl_isvalid
     NUMBER(1)
     DEFAULT 1 NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// PNBR#37466
UPDATE bes_srtdeel
   SET bes_srtdeel_voorraadfactor = 1
 WHERE bes_srtdeel_voorraadfactor IS NULL;

/////////////////////////////////////////////////////////////////////////////////////////// KFNS#34792
ALTER TABLE mld_typeopdr ADD
    mld_typeopdr_slamode
        NUMBER(1)                                 -- 1: Leverancier-SLA, 2=Melding-SLA
        DEFAULT 1 NOT NULL;

/////////////////////////////////////////////////////////////////////////////////////////// GENERAL

/////////////////////////////////////////////////////////////////////////////////////////// CLEANUP
ALTER TABLE ins_srtcontroledl_xcp DROP COLUMN ins_srtcontroledl_xcp_respijt;
ALTER TABLE ins_deelsrtcontrole DROP COLUMN ins_deelsrtcontrole_datum_xcp;
-- FSN#36395
DROP SEQUENCE fac_s_fac_locale_mgt_key;
DROP TABLE fac_locale_mgt PURGE;

///////////////////////////////////////////////////////////////////////////////////////////
REGISTERONCE('$Id$')
#include "epilogue.inc"
