-- Customer specific once-script UWVA93.
--
-- (c) 2015 SG|facilitor bv
SET ECHO ON
SPOOL xuwva93.lst
SET DEFINE OFF

-- UWVA#32293: CPUA-export (key=5) voortaan dagelijks (ipv. alleen op vrijdag)
UPDATE fac_export_app
   SET fac_export_app_timestamp = 'yyyymmdd'
 WHERE fac_export_app_key = 5;

-- UWVA#31552: Dashboards
INSERT INTO prs_kenmerk (prs_kenmerk_key,
                         prs_kenmerk_niveau,
                         prs_kenmerk_volgnr,
                         prs_kenmerk_omschrijving,
                         prs_kenmerk_hint,
                         prs_kenmerk_default,
                         prs_kenmerk_kenmerktype,
                         prs_kenmerk_lengte,
                         prs_kenmerk_dec,
                         prs_kenmerk_nmin,
                         prs_kenmerk_nmax)
    VALUES (1200,
            'B',
            10,
            'Intern',
            'Intern bedrijf',
            NULL,
            'N',
            1,
            0,
            0,
            1);

CREATE OR REPLACE VIEW UWVA_V_RAP_MLDOPEN_ORANJE1 AS SELECT NULL x FROM DUAL;
INSERT INTO fac_usrrap (fac_usrrap_key,
                        fac_usrrap_omschrijving,
                        fac_usrrap_view_name,
                        fac_usrrap_vraagbegindatum,
                        fac_usrrap_vraageinddatum,
                        fac_usrrap_functie,
                        fac_usrrap_info,
                        fac_functie_key,
                        fac_usrrap_autorefresh)
   SELECT 1285,
          'BEHEER: Meldingen waarvan SLA >70% verstreken (alg-scope)',
          'UWVA_V_RAP_MLDOPEN_ORANJE1',
          0,
          0,
          1,
          '70% meldingen tbv. RTM',
          fac_functie_key,
          0
     FROM fac_functie
    WHERE fac_functie_code = 'WEB_USER48';

CREATE OR REPLACE VIEW UWVA_V_RAP_MLDOPEN_ORANJE2 AS SELECT NULL x FROM DUAL;
INSERT INTO fac_usrrap (fac_usrrap_key,
                        fac_usrrap_omschrijving,
                        fac_usrrap_view_name,
                        fac_usrrap_vraagbegindatum,
                        fac_usrrap_vraageinddatum,
                        fac_usrrap_functie,
                        fac_usrrap_info,
                        fac_functie_key,
                        fac_usrrap_autorefresh)
   SELECT 1286,
          'BEHEER: Meldingen waarvan SLA >70% verstreken (org-scope)',
          'UWVA_V_RAP_MLDOPEN_ORANJE2',
          0,
          0,
          1,
          '70% meldingen tbv. RTM',
          fac_functie_key,
          0
     FROM fac_functie
    WHERE fac_functie_code = 'WEB_USER49';

CREATE OR REPLACE VIEW UWVA_V_RAP_ORDOPEN_ORANJE AS SELECT NULL x FROM DUAL;
INSERT INTO fac_usrrap (fac_usrrap_key,
                        fac_usrrap_omschrijving,
                        fac_usrrap_view_name,
                        fac_usrrap_vraagbegindatum,
                        fac_usrrap_vraageinddatum,
                        fac_usrrap_functie,
                        fac_usrrap_info,
                        fac_functie_key,
                        fac_usrrap_autorefresh)
   SELECT 1287,
          'BEHEER: Opdrachten waarvan SLA (melding!) >70% verstreken',
          'UWVA_V_RAP_ORDOPEN_ORANJE',
          0,
          0,
          1,
          '70% opdrachten tbv. RTM',
          fac_functie_key,
          0
     FROM fac_functie
    WHERE fac_functie_code = 'WEB_USER48';

COMMIT;

-- 495 = WEB_USER48/496 = WEB_USER49
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_BES AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_BHV AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_EVE AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_IEO AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_KLI AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_MUS AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_PEI AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_PEL AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_SBL AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_TIN AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_VEO AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_VEB AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_MLDOPEN_BHND AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_ORDOPEN_UITV_I AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_ORDOPEN_UITV_E AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_PPI_ACP AS SELECT NULL x FROM DUAL;
CREATE OR REPLACE VIEW UWVA_V_GRAPH_PPI_AFM AS SELECT NULL x FROM DUAL;
INSERT INTO fac_usrgraph (fac_usrgraph_key,
                          fac_usrgraph_omschrijving,
                          fac_usrgraph_view_name,
                          fac_usrgraph_type,
                          fac_functie_key,
                          fac_usrgraph_orderby,
                          fac_usrgraph_maxrows,
                          fac_usrgraph_options)
   SELECT 11, NULL, 'UWVA_V_GRAPH_MLDOPEN_BES', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 12, NULL, 'UWVA_V_GRAPH_MLDOPEN_BHV', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 13, NULL, 'UWVA_V_GRAPH_MLDOPEN_EVE', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 14, NULL, 'UWVA_V_GRAPH_MLDOPEN_IEO', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 15, NULL, 'UWVA_V_GRAPH_MLDOPEN_KLI', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 16, NULL, 'UWVA_V_GRAPH_MLDOPEN_MUS', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 17, NULL, 'UWVA_V_GRAPH_MLDOPEN_PEI', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 18, NULL, 'UWVA_V_GRAPH_MLDOPEN_PEL', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 19, NULL, 'UWVA_V_GRAPH_MLDOPEN_SBL', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 20, NULL, 'UWVA_V_GRAPH_MLDOPEN_TIN', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 21, NULL, 'UWVA_V_GRAPH_MLDOPEN_VEO', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 22, NULL, 'UWVA_V_GRAPH_MLDOPEN_VEB', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 31, NULL, 'UWVA_V_GRAPH_MLDOPEN_BHND', 1, 496, 'VOLGORDE', NULL, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 32, NULL, 'UWVA_V_GRAPH_ORDOPEN_UITV_I', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL
   UNION ALL
   SELECT 33, NULL, 'UWVA_V_GRAPH_ORDOPEN_UITV_E', 1, 495, 'VOLGORDE', 10, '{seriesColors: ["green","orange","red"], axes: {yaxis: {tickOptions: {formatString: "%d"}}}}' FROM DUAL;
INSERT INTO fac_usrgraph (fac_usrgraph_key,
                          fac_usrgraph_omschrijving,
                          fac_usrgraph_view_name,
                          fac_usrgraph_type,
                          fac_usrgraph_limiet0,
                          fac_usrgraph_limiet1,
                          fac_usrgraph_limiet2,
                          fac_usrgraph_limiet3,
                          fac_functie_key,
                          fac_usrgraph_orderby,
                          fac_usrgraph_maxrows,
                          fac_usrgraph_options)
   SELECT 41, NULL, 'UWVA_V_GRAPH_PPI_ACP', 2, 0, 50, 75, 100, 495, NULL, 10, NULL FROM DUAL
   UNION ALL
   SELECT 42, NULL, 'UWVA_V_GRAPH_PPI_AFM', 2, 0, 50, 75, 100, 495, NULL, 10, NULL FROM DUAL;

INSERT INTO fac_widget (fac_widget_groep,
                        fac_widget_volgnr,
                        fac_widget_title,
                        fac_widget_height,
                        fac_widget_width,
                        fac_widget_url,
                        fac_widget_refreshtime,
                        fac_functie_key)
   SELECT 'RTM01', 10, 'Openstaande meldingen/Bestellingen', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=11', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM02', 10, 'Openstaande meldingen/BHV', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=12', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM03', 10, 'Openstaande meldingen/Evenementen', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=13', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM04', 10, 'Openstaande meldingen/Input en Output', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=14', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM05', 10, 'Openstaande meldingen/Klimaat', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=15', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM06', 10, 'Openstaande meldingen/Multiservice', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=16', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM07', 10, 'Openstaande meldingen/Pand en Inrichting', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=17', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM08', 10, 'Openstaande meldingen/Post en Logistiek', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=18', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM09', 10, 'Openstaande meldingen/Servicebladen', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=19', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM10', 10, 'Openstaande meldingen/Technische Installaties', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=20', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM11', 10, 'Openstaande meldingen/Vergaderen en Overnachten', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=21', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM12', 10, 'Openstaande meldingen/Verhuizing en Beveiliging', 400, 65, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=22', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM13', 10, 'Openstaande meldingen per behandelaar', 600, 99, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=31', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM14', 10, 'Openstaande opdrachten per interne uitvoerende', 400, 99, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=32', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM14', 20, 'Openstaande opdrachten per externe uitvoerende', 400, 99, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=33', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM15', 10, 'Acceptatie op tijd (lopende meldingen)', 250, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=41', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM15', 20, 'Afhandeling op tijd (lopende meldingen)', 250, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=42', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 10, 'Acceptatie op tijd (lopende meldingen)', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=41', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 20, 'Afhandeling op tijd (lopende meldingen)', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=42', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 30, 'Openstaande meldingen per behandelaar', 300, 75, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=31', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 40, 'Openstaande opdrachten per interne uitvoerende', 300, 75, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=32', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 50, 'Openstaande opdrachten per externe uitvoerende', 300, 75, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=33', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 60, 'Openstaande meldingen/Bestellingen', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=11', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 62, 'Openstaande meldingen/BHV', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=12', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 64, 'Openstaande meldingen/Evenementen', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=13', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 70, 'Openstaande meldingen/Input en Output', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=14', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 72, 'Openstaande meldingen/Klimaat', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=15', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 74, 'Openstaande meldingen/Multiservice', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=16', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 80, 'Openstaande meldingen/Pand en Inrichting', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=17', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 82, 'Openstaande meldingen/Post en Logistiek', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=18', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 84, 'Openstaande meldingen/Servicebladen', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=19', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 90, 'Openstaande meldingen/Technische Installaties', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=20', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 92, 'Openstaande meldingen/Vergaderen en Overnachten', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=21', 500, 495 FROM DUAL
   UNION ALL
   SELECT 'RTM16', 94, 'Openstaande meldingen/Verhuizing en Beveiliging', 200, 32, '../../appl/fac/fac_usrgraph.asp?usrgraph_key=22', 500, 495 FROM DUAL;

INSERT INTO fac_menu (fac_menu_volgnr,
                      fac_menuitems_key,
                      fac_menu_info,
                      fac_menu_altlabel,
                      fac_menu_alturl,
                      fac_menu_altgroep,
                      fac_functie_key,
                      fac_menu_level)
   SELECT 4960, NULL, NULL, 'Real Time Monitors', NULL, 1, 495, 1 FROM DUAL
   UNION ALL
   SELECT 4961, NULL, NULL, 'Bestellingen', 'appl/fac/fac_widgetspage.asp?wgrp=RTM01', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4962, NULL, NULL, 'BHV', 'appl/fac/fac_widgetspage.asp?wgrp=RTM02', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4963, NULL, NULL, 'Evenementen', 'appl/fac/fac_widgetspage.asp?wgrp=RTM03', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4964, NULL, NULL, 'Input en Output', 'appl/fac/fac_widgetspage.asp?wgrp=RTM04', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4965, NULL, NULL, 'Klimaat', 'appl/fac/fac_widgetspage.asp?wgrp=RTM05', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4966, NULL, NULL, 'Multiservice', 'appl/fac/fac_widgetspage.asp?wgrp=RTM06', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4967, NULL, NULL, 'Pand en Inrichting', 'appl/fac/fac_widgetspage.asp?wgrp=RTM07', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4968, NULL, NULL, 'Post en Logistiek', 'appl/fac/fac_widgetspage.asp?wgrp=RTM08', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4969, NULL, NULL, 'Servicebladen', 'appl/fac/fac_widgetspage.asp?wgrp=RTM09', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4970, NULL, NULL, 'Technische installatie', 'appl/fac/fac_widgetspage.asp?wgrp=RTM10', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4971, NULL, NULL, 'Vergaderen en Overnachten', 'appl/fac/fac_widgetspage.asp?wgrp=RTM11', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4972, NULL, NULL, 'Verhuizing en Beveiliging', 'appl/fac/fac_widgetspage.asp?wgrp=RTM12', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4973, NULL, NULL, 'Meldingen Behandelaar', 'appl/fac/fac_widgetspage.asp?wgrp=RTM13', 1, 496, NULL FROM DUAL
   UNION ALL
   SELECT 4974, NULL, NULL, 'Opdrachten Uitvoerenden', 'appl/fac/fac_widgetspage.asp?wgrp=RTM14', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4975, NULL, NULL, 'Acceptatie- en Afhandeltijd', 'appl/fac/fac_widgetspage.asp?wgrp=RTM15', 1, 495, NULL FROM DUAL
   UNION ALL
   SELECT 4976, NULL, NULL, 'Totaaloverzicht', 'appl/fac/fac_widgetspage.asp?wgrp=RTM16', 1, 495, NULL FROM DUAL;

-- UWVA#318844: KTO-export (47=PRSSYS)
INSERT INTO fac_export_app (fac_export_app_code,
                            fac_export_app_oms,
                            fac_functie_key,
                            fac_export_app_folder,
                            fac_export_app_file_prefix,
                            fac_export_app_postfix,
                            fac_export_app_log_postfix,
                            fac_export_app_flags,
                            fac_export_app_timestamp,
                            fac_export_app_prefix)
    VALUES ('KTO',
            'KTO',
            47,
            '.\KTO',
            'KTO_',
            '.csv',
            '.log',
            0,
            'yyyymmdd',
            'UWVA');

COMMIT;

-- UWVA#31905: Eenmalige (achterstallige) anonimiseringsslag
-- Alle MLDUPD-tracking van geanonimiseerde Spobilo-meldingen
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 23                                -- MLDUPD
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2, mld_melding m
               WHERE     t2.fac_srtnotificatie_key = 23              -- MLDUPD
                     AND UPPER (t2.fac_tracking_oms) = 'GEANONIMISEERD'
                     AND t2.fac_tracking_refkey = m.mld_melding_key
                     AND m.mld_stdmelding_key = 361
                     AND t2.fac_tracking_refkey = t1.fac_tracking_refkey
                     AND t2.fac_tracking_key != t1.fac_tracking_key);
COMMIT;

-- Alle MLDUPD-tracking van Spobilo-meldingen voor 27-06-2014
DELETE FROM fac_tracking t1
 WHERE     t1.fac_srtnotificatie_key = 23                            -- MLDUPD
       AND t1.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy')
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2, mld_melding m
               WHERE t2.fac_srtnotificatie_key = 23                  -- MLDUPD
                     AND t2.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy')
                     AND t2.fac_tracking_refkey = m.mld_melding_key
                     AND m.mld_stdmelding_key = 361
                     AND t2.fac_tracking_refkey = t1.fac_tracking_refkey);
COMMIT;

-- Alle MLDUPD-tracking met BSN/NAAM van geanonimiseerde Vertaal/Archief/Dossier-meldingen
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 23                                -- MLDUPD
       AND (UPPER (t1.fac_tracking_oms) LIKE '%BSN%' OR UPPER (t1.fac_tracking_oms) LIKE '%NAAM%')
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2, mld_melding m
               WHERE     t2.fac_srtnotificatie_key = 23              -- MLDUPD
                     AND UPPER (t2.fac_tracking_oms) = 'GEANONIMISEERD'
                     AND t2.fac_tracking_refkey = m.mld_melding_key
                     AND m.mld_stdmelding_key IN (1301, 2, 146, 2961)
                     AND t2.fac_tracking_refkey = t1.fac_tracking_refkey
                     AND t2.fac_tracking_key != t1.fac_tracking_key);
COMMIT;

-- Alle MLDUPD-tracking met BSN/NAAM van Vertaal/Archief/Dossier-meldingen voor 27-06-2015
DELETE FROM fac_tracking t1
 WHERE     t1.fac_srtnotificatie_key = 23                            -- MLDUPD
       AND t1.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy')
       AND (UPPER (t1.fac_tracking_oms) LIKE '%BSN%' OR UPPER (t1.fac_tracking_oms) LIKE '%NAAM%')
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2, mld_melding m
               WHERE t2.fac_srtnotificatie_key = 23                  -- MLDUPD
                     AND t2.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy')
                     AND t2.fac_tracking_refkey = m.mld_melding_key
                     AND m.mld_stdmelding_key IN (1301, 2, 146, 2961)
                     AND t2.fac_tracking_refkey = t1.fac_tracking_refkey);
COMMIT;

-- BEZ
UPDATE bez_afspraak
   SET bez_afspraak_opmerking = NULL
 WHERE bez_afspraak_datum < SYSDATE - 31
       AND UPPER (bez_afspraak_opmerking) LIKE '%BSN%';
COMMIT;

-- Alle BEZUPD-tracking van geanonimiseerde afspraken
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 334                               -- BEZUPD
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2
               WHERE     t2.fac_srtnotificatie_key = 334             -- BEZUPD
                     AND UPPER (t2.fac_tracking_oms) = 'GEANONIMISEERD'
                     AND t2.fac_tracking_refkey = t1.fac_tracking_refkey
                     AND t2.fac_tracking_key != t1.fac_tracking_key);
COMMIT;

-- Alle BEZUPD-tracking met BSN/NAAM van afspraken voor 27-06-2014
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 334                               -- BEZUPD
       AND (UPPER (t1.fac_tracking_oms) LIKE '%BSN%' OR UPPER (t1.fac_tracking_oms) LIKE '%NAAM%')
       AND t1.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy');
COMMIT;

-- Alle BEZBAD-tracking (per bezoeker) van geanonimiseerde afspraken
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 154                               -- BEZBAD
       AND t1.fac_tracking_oms IS NOT NULL                     -- Of ook lege?
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2, bez_bezoekers b
               WHERE     t2.fac_srtnotificatie_key = 334             -- BEZUPD
                     AND UPPER (t2.fac_tracking_oms) = 'GEANONIMISEERD'
                     AND t2.fac_tracking_refkey = b.bez_afspraak_key
                     AND b.bez_bezoekers_key = t1.fac_tracking_refkey);
COMMIT;

-- Alle BEZBAD-tracking (per bezoeker) van afspraken voor 27-06-2014
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 154                               -- BEZBAD
       AND t1.fac_tracking_oms IS NOT NULL                     -- Of ook lege?
       AND t1.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy');
COMMIT;

-- Alle in/uit-tracking (per bezoeker) van geanonimiseerde afspraken
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key IN (14, 15, 61, 62)
       AND t1.fac_tracking_oms IS NOT NULL                  -- Niet van belang
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2, bez_bezoekers b
               WHERE     t2.fac_srtnotificatie_key = 334             -- BEZUPD
                     AND UPPER (t2.fac_tracking_oms) = 'GEANONIMISEERD'
                     AND t2.fac_tracking_refkey = b.bez_afspraak_key
                     AND b.bez_bezoekers_key = t1.fac_tracking_refkey);
COMMIT;

-- Alle in/uit-tracking (per bezoeker) van afspraken voor 27-06-2014
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key IN (14, 15, 61, 62)
       AND t1.fac_tracking_oms IS NOT NULL                  -- Niet van belang
       AND t1.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy');
COMMIT;

-- RES
UPDATE res_rsv_ruimte
   SET res_rsv_ruimte_opmerking = NULL
 WHERE res_rsv_ruimte_tot < SYSDATE - 31
       AND UPPER (res_rsv_ruimte_opmerking) LIKE '%BSN%';
COMMIT;

-- Alle RESUPD-tracking met BSN van geanonimiseerde reserveringen
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 31                                -- RESUPD
       AND UPPER (t1.fac_tracking_oms) LIKE '%BSN%'
       AND EXISTS
             (SELECT 1
                FROM fac_tracking t2
               WHERE     t2.fac_srtnotificatie_key = 31
                     AND UPPER (t2.fac_tracking_oms) = 'GEANONIMISEERD'
                     AND t2.fac_tracking_refkey = t1.fac_tracking_refkey
                     AND t2.fac_tracking_key != t1.fac_tracking_key);
COMMIT;

-- Alle RESUPD-tracking met BSN van reserveringen voor 27-06-2014
DELETE FROM fac_tracking t1
 WHERE t1.fac_srtnotificatie_key = 31                                -- RESUPD
       AND UPPER (t1.fac_tracking_oms) LIKE '%BSN%'
       AND t1.fac_tracking_datum <= TO_DATE ('27062014', 'ddmmyyyy')
       AND EXISTS
             (SELECT 1
                FROM res_rsv_ruimte rr, res_kenmerk k
               WHERE rr.res_activiteit_key = k.res_activiteit_key
                     AND k.res_srtkenmerk_key = 3                       -- BSN
                     AND rr.res_rsv_ruimte_key = t1.fac_tracking_refkey);
COMMIT;
BEGIN adm.systrackscriptId('$Id$'); END;
/
SPOOL OFF

--@@uwva_prs.sql
--@@uwva_fin.sql
@@uwva_hv.sql
@@uwva_misc.sql

BEGIN fac.registercustversion('UWVA', 93); END;
/
COMMIT;
