--
-- $Id$
--
-- Script containing customer specific sql statements for the STCH database

DEFINE thisfile = 'STCH#54706.SQL'
DEFINE dbuser   = 'STCH'

SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
WHENEVER SQLERROR EXIT;
SELECT adm.scriptspoolfile('&dbuser', '&thisfile') AS fcltlogfile FROM DUAL;
WHENEVER SQLERROR CONTINUE;
SPOOL &fcltlogfile
SET DEFINE OFF

------ payload begin ------

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

-- Dit script is nog Work in Progress--
-- De bedoeling is om de sporen van AAFM zoveel mogelijk uit te wissen--

-- Hier moet nog in: Verwijder alle locaties, gebouwen, ruimtes, objecten die niet
-- vallen onder "ON-site" locaties.
-- Tevens zijn er nog sporen van oude AAFM medewekers, die mogen ook weg
-- als dat mogelijk is.
-- Er zijn ook een (groot) aantal "myfaciltor" widgets die weg mogen (waarschijnlijk?)

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

-- Eerst opschonen voor droppen

-- Exports
DELETE FROM fac_export_app
      WHERE fac_export_app_prefix LIKE '%AAXX%'
            OR fac_export_app_prefix LIKE '%AASI%';
            
-- Imports            
DELETE FROM fac_import
      WHERE fac_import_key IN
                  (SELECT f.fac_import_key
                     FROM fac_import f,
                          (SELECT fac_import_app_key
                             FROM fac_import_app
                            WHERE fac_import_app_prefix LIKE '%AAXX%'
                                  OR fac_import_app_prefix LIKE '%AASI%')
                          sub1,
                          (SELECT fac_import_app_key
                             FROM fac_import_app
                            WHERE fac_import_app_code = 'OPDRSTAT_STRUKTON')
                          sub2
                    WHERE f.fac_import_app_key = sub1.fac_import_app_key
                          AND f.fac_import_app_key != sub2.fac_import_app_key);

DELETE FROM fac_import_app
      WHERE fac_import_app_prefix LIKE '%AAXX%'
            OR fac_import_app_prefix LIKE '%AASI%'
           AND fac_import_app_code NOT LIKE '%STRUKTON';   

           
-- Dit laten we voor nu lekker AAXX, die benaming is nog niet zo`n probleem, en nu werkt alles nog prima         
           
--ALTER TABLE
--aaxx_imp_opdrstat_strukton
--RENAME TO stch_imp_opdrstat_strukton;

-- Rapportages
         
DELETE FROM fac_usrrap
      WHERE UPPER (fac_usrrap_view_name) NOT LIKE '%HV%'
           AND (UPPER (fac_usrrap_view_name) LIKE 'AASI%'
             OR UPPER (fac_usrrap_view_name) LIKE 'AAXX%');
                          
-- Nu kunnen we gaan droppen
-- DROP TABLES

-- Alle huisvesting (HV) tables/views worden overgeslagen, die worden nog gebruikt door STCH
-- Ook de rapportages zie in de laatste 100 dagen nog zijn gebruikt blijven voor nu behouden

DROP TABLE AAXX_BUNDEL_CATERING_REF;
DROP TABLE AAXX_EXP_EXACT_VERKOOP;
DROP TABLE AAXX_EXP_FACTUUR;
DROP TABLE AAXX_EXP_UREN;
DROP TABLE AAXX_EXP_UREN_DEKKING;
--DROP TABLE AASI_HV_FREEZE;
DROP TABLE AAXX_IMP_CONTRACT;
DROP TABLE AAXX_IMP_DIENST_LOC_BLD;
DROP TABLE AAXX_IMP_FACTUURSCHEMA;
DROP TABLE AAXX_IMP_MLD_LANG;
DROP TABLE AAXX_IMP_RUIMTE;
DROP TABLE AAXX_IMP_SRTRUIMTE;
DROP TABLE AAXX_IMP_UPLIFT;
DROP TABLE AAXX_PERSLID_LOGIN;
DROP TABLE AAXX_VERKOOPBUFFER;

-- DROP PROCEDURES

DROP PROCEDURE AAXX_UPDATE_UPLIFT;
DROP PROCEDURE AAXX_UPDATE_SRTRUIMTE;
DROP PROCEDURE AAXX_UPDATE_RUIMTE;
DROP PROCEDURE AAXX_UPDATE_OPDRSTAT_STRUKTON;
DROP PROCEDURE AAXX_UPDATE_MLD_LANG;
DROP PROCEDURE AAXX_UPDATE_FACTUURSCHEMA;
DROP PROCEDURE AAXX_UPDATE_FACTUUR;
DROP PROCEDURE AAXX_UPDATE_DIENST_LOC_BLD;
DROP PROCEDURE AAXX_UPDATE_CONTRACT;
DROP PROCEDURE AAXX_UPDATE_CONTACTPERSOON;
DROP PROCEDURE AAXX_UPDATE_ASSET;
DROP PROCEDURE AAXX_UPDATE_AAFM_MEDEWERKERS;
DROP PROCEDURE AAXX_SET_KENMERK;
DROP PROCEDURE AAXX_SELECT_NOSHOW_REMINDER;
DROP PROCEDURE AAXX_SELECT_EXACT_XML;
DROP PROCEDURE AAXX_SELECT_EXACT_VERKOOP;
DROP PROCEDURE AAXX_SELECT_EXACT_UREN_XML;
DROP PROCEDURE AAXX_SELECT_EXACT;
DROP PROCEDURE AAXX_SELECT_DWH_SET_KENMERKEN;
DROP PROCEDURE AAXX_SELECT_DAILY_TASK;
DROP PROCEDURE AAXX_PROCESSEMAIL;
DROP PROCEDURE AAXX_ORDERCORRECTIES;
DROP PROCEDURE AAXX_IMPORT_UPLIFT;
DROP PROCEDURE AAXX_IMPORT_SRTRUIMTE;
DROP PROCEDURE AAXX_IMPORT_RUIMTE;
DROP PROCEDURE AAXX_IMPORT_OPDRSTAT_STRUKTON;
DROP PROCEDURE AAXX_IMPORT_MLD_LANG;
DROP PROCEDURE AAXX_IMPORT_FACTUURSCHEMA;
DROP PROCEDURE AAXX_IMPORT_FACTUUR;
DROP PROCEDURE AAXX_IMPORT_DIENST_LOC_BLD;
DROP PROCEDURE AAXX_IMPORT_CONTRACT;
DROP PROCEDURE AAXX_IMPORT_CONTACTPERSOON;
DROP PROCEDURE AAXX_IMPORT_ASSET;
DROP PROCEDURE AAXX_IMPORT_AAFM_MEDEWERKERS;
DROP PROCEDURE AAXX_IMP_WRITELOG;
DROP PROCEDURE AAXX_EXPORT_VERWERK_EXACT_UREN;
DROP PROCEDURE AAXX_EXPORT_VERWERK_EXACT;
DROP PROCEDURE AAXX_EXPORT_LOGIN;
DROP PROCEDURE AAXX_EXPORT_EXACT_VERKOOP;
DROP PROCEDURE AAXX_EXPORT_EXACT_ADM;
DROP PROCEDURE AAXX_EXPORT_EXACT;
DROP PROCEDURE AAXX_EXPORT_BUNDEL_CATERING;
DROP PROCEDURE AAXX_DELETE_NON_ACTIVE_USERS;
DROP PROCEDURE AAXX_DELETE_NON_ACTIVE_KEY;
DROP PROCEDURE AAXX_DAILY_TASK;
DROP PROCEDURE AAXX_AFMELDEN_COMPLIMENTEN;
DROP PROCEDURE AAXX_ADD_XML_ROW;
DROP PROCEDURE AAXX_ADD_XML_ELEMENT;

-- DROP VIEWS

DROP VIEW AASI_V_BUNDEL_CATERING;
DROP VIEW AASI_V_DWH_BUDGET_TRACK_M2;
--DROP VIEW AASI_V_DWH_HV_FREEZE;
DROP VIEW AASI_V_EXPORT_BUNDEL_CATERING;
DROP VIEW AASI_V_EXPORT_EXACT_UREN;
DROP VIEW AASI_V_EXPORT_EXACT_VERKOOP;
DROP VIEW AASI_V_EXPORT_EXACT_VERKOOP_VJ;
DROP VIEW AASI_V_EXPORT_VERWERK_EXACT;
--DROP VIEW AASI_V_HV_ACTUAL;
--DROP VIEW AASI_V_HV_DETAIL;
--DROP VIEW AASI_V_RAP_AUTH_BESTELLERS;
DROP VIEW AASI_V_RAP_CATERING_INKOOP;
DROP VIEW AASI_V_RAP_CATERING_VERKOOP;
--DROP VIEW AASI_V_RAP_HV_ACTUAL;
--DROP VIEW AASI_V_RAP_HV_AFD_TOTALEN;
--DROP VIEW AASI_V_RAP_HV_CHECK;
--DROP VIEW AASI_V_RAP_HV_DOORBEL_DELTA;
--DROP VIEW AASI_V_RAP_HV_FREEZE;
DROP VIEW AASI_V_THEMA_LEEGSTAND;
DROP VIEW AASI_V_THEMA_RUIMTE_HUURDER;
DROP VIEW AASI_V_THEMA_RUIMTE_HUURDER1;
DROP VIEW AASI_V_THEMA_SRTRUIMTE;
DROP VIEW AAXX_RAP_PERSLID_MISMATCH;
DROP VIEW AAXX_V_AANWEZIGFACTUUR;
DROP VIEW AAXX_V_BESTELGEGEVENS;
DROP VIEW AAXX_V_BRON_EXPORT_EXACT_XML;
DROP VIEW AAXX_V_CAD_LABEL_RES_INFO;
DROP VIEW AAXX_V_CAD_THEMA_RESINFO;
DROP VIEW AAXX_V_DWH_ALG_ONRGOED;
DROP VIEW AAXX_V_DWH_BES_BESTELLING;
DROP VIEW AAXX_V_DWH_BEZ_BEZOEKERS;
DROP VIEW AAXX_V_DWH_BUDGET_TRACKER;
DROP VIEW AAXX_V_DWH_CNT_CONTRACT;
DROP VIEW AAXX_V_DWH_CNT_CONTRACT_MANTEL;
DROP VIEW AAXX_V_DWH_CNT_CONTRACT_SCOPE;
DROP VIEW AAXX_V_DWH_CNT_FACTUURSCHEMA;
DROP VIEW AAXX_V_DWH_FAC_GROEPRECHTEN;
DROP VIEW AAXX_V_DWH_FIN_FACTUUR;
DROP VIEW AAXX_V_DWH_FIN_FACTUUR2;
DROP VIEW AAXX_V_DWH_GUI_COUNTER;
DROP VIEW AAXX_V_DWH_INS_OBJECT;
DROP VIEW AAXX_V_DWH_INS_SENSOR_STATUS;
DROP VIEW AAXX_V_DWH_INSPECTIE;
DROP VIEW AAXX_V_DWH_KENMERK_BESTELLING;
DROP VIEW AAXX_V_DWH_KENMERK_CONTRACT;
DROP VIEW AAXX_V_DWH_KENMERK_INSPECTIE;
DROP VIEW AAXX_V_DWH_KENMERK_MELDING;
DROP VIEW AAXX_V_DWH_KENMERK_OBJECT;
DROP VIEW AAXX_V_DWH_KENMERK_ONRGOED;
DROP VIEW AAXX_V_DWH_KENMERK_OPDRACHT;
DROP VIEW AAXX_V_DWH_KENMERK_PRS;
DROP VIEW AAXX_V_DWH_KENMERK_RESERVERING;
DROP VIEW AAXX_V_DWH_MLD_MELDING;
DROP VIEW AAXX_V_DWH_PRS_AFDELING;
DROP VIEW AAXX_V_DWH_PRS_BEDRIJF;
DROP VIEW AAXX_V_DWH_PRS_BEDRIJFADRES;
DROP VIEW AAXX_V_DWH_PRS_KOSTENPLAATS;
DROP VIEW AAXX_V_DWH_PRS_KOSTENSOORT;
DROP VIEW AAXX_V_DWH_PRS_PERSLID;
DROP VIEW AAXX_V_DWH_RES_RESERVERING;
DROP VIEW AAXX_V_DWH_TRACKING;
DROP VIEW AAXX_V_DWH_UREN;
DROP VIEW AAXX_V_DWH_UREN_IMPROD;
DROP VIEW AAXX_V_EXACT_CODE_DISTRICT;
DROP VIEW AAXX_V_EXACT_CODE_DISTRICT_FAC;
DROP VIEW AAXX_V_EXACT_CODE_GEBOUW;
DROP VIEW AAXX_V_EXACT_CODE_GEBOUW_FAC;
DROP VIEW AAXX_V_EXACT_UREN_GEGEVENS;
DROP VIEW AAXX_V_EXPORT_BUDGET_TRACKER;
DROP VIEW AAXX_V_EXPORT_BUNDEL_CATERING;
DROP VIEW AAXX_V_EXPORT_EXACT;
DROP VIEW AAXX_V_EXPORT_EXACT_UREN_XML;
DROP VIEW AAXX_V_EXPORT_EXACT_VERKOOP;
DROP VIEW AAXX_V_EXPORT_EXACT_VERKOOP_T;
DROP VIEW AAXX_V_EXPORT_EXACT_XML;
DROP VIEW AAXX_V_EXPORT_VERWERK_EXACT;
DROP VIEW AAXX_V_FACTUUR_GEGEVENS;
DROP VIEW AAXX_V_GRAPH_MELDINGPM;
DROP VIEW AAXX_V_GRAPH_OPENST_BEHAND;
DROP VIEW AAXX_V_GRAPH_PPI_ACC;
DROP VIEW AAXX_V_GRAPH_PPI_UITV;
DROP VIEW AAXX_V_GRAPH_VAKGROEP_AFG;
DROP VIEW AAXX_V_GRAPH_VAKGROEP_OPEN;
DROP VIEW AAXX_V_GUI_SEARCHRESULTS;
DROP VIEW AAXX_V_IMP_BES_ARTIKEL_SYNC;
DROP VIEW AAXX_V_LCRAP_KEY_STATS;
DROP VIEW AAXX_V_NOTI_BEZOEKERS;
DROP VIEW AAXX_V_NOTI_KLACHT_REMINDER;
DROP VIEW AAXX_V_NOTI_MLD_PROJECTEN;
DROP VIEW AAXX_V_NOTI_NON_ACTIVE_USERS;
DROP VIEW AAXX_V_NOTI_OFFERTE_ACCEPTED;
DROP VIEW AAXX_V_NOTI_PLAN_OPDR;
DROP VIEW AAXX_V_NOTI_SM_RECEPTIE;
DROP VIEW AAXX_V_NOTI_SM_RESAFM_REMINDER;
DROP VIEW AAXX_V_PROJECT_BOOM;
DROP VIEW AAXX_V_PROJECT_BOOM_NODES;
DROP VIEW AAXX_V_RAP_ASSET_INSP;
DROP VIEW AAXX_V_RAP_BDL_CONTRACT;
DROP VIEW AAXX_V_RAP_BEDRIJF_ORDERADRES;
DROP VIEW AAXX_V_RAP_BES_INKFACTUUR;
DROP VIEW AAXX_V_RAP_CATERING_EXPORT;
DROP VIEW AAXX_V_RAP_CONTRACTORDERS;
DROP VIEW AAXX_V_RAP_DIENST_LOC_BLD;
DROP VIEW AAXX_V_RAP_ERRORLOG;
DROP VIEW AAXX_V_RAP_GEBRUIKERS_AUTH;
DROP VIEW AAXX_V_RAP_IMP_JAARCONTRACT;
DROP VIEW AAXX_V_RAP_IMP_RUIMTE;
DROP VIEW AAXX_V_RAP_INFOBORD;
DROP VIEW AAXX_V_RAP_INKOOPFACTUUR;
DROP VIEW AAXX_V_RAP_INVOICE_SCAN;
DROP VIEW AAXX_V_RAP_KOSTENMUTATIE;
DROP VIEW AAXX_V_RAP_LANG_DISCIPLINE_OMS;
DROP VIEW AAXX_V_RAP_LANG_STDMELDING_OMS;
DROP VIEW AAXX_V_RAP_LOGIN_USER;
DROP VIEW AAXX_V_RAP_MLD_QRC;
-- DROP VIEW AAXX_V_RAP_OFFERTE_STATUS;
DROP VIEW AAXX_V_RAP_ORDBO2_NO_BDR;
DROP VIEW AAXX_V_RAP_PROJECTBOOM;
DROP VIEW AAXX_V_RAP_SHARE_MEET_KOSTEN;
DROP VIEW AAXX_V_RAP_SRTRUIMTE;
DROP VIEW AAXX_V_RAP_STDMELDING_GEGBASIS;
DROP VIEW AAXX_V_RAP_STDMELDING_GEGEVENS;
DROP VIEW AAXX_V_RAP_TRACE_UITV_Z_TFM;
DROP VIEW AAXX_V_RAP_TRACE_UITVOERDER;
DROP VIEW AAXX_V_RAP_UPLIFT;
DROP VIEW AAXX_V_STDMELDING_GEGEVENS;
DROP VIEW AAXX_V_UDR_HERGOEDKEUREN;

------ payload end   ------

SET DEFINE OFF
BEGIN adm.systrackscriptId ('$Id$', 0); END;
/

COMMIT;
SET ECHO OFF
SPOOL OFF
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile