--  aads481to500
--
--
SET ECHO ON
SPOOL aads481to500.lst
PROMPT $Revision$
ALTER SESSION SET nls_territory='america';
SET DEFINE OFF

-- kenmerk bijlagen bij factuur
INSERT INTO fin_kenmerk
(
    fin_kenmerk_volgnr, fin_kenmerk_omschrijving, fin_kenmerk_kenmerktype
)
VALUES (100, 'Bijlages', 'M');

-- update de logincodes. Alle logincodes van medewerkers met een dsm.com emailadres worden 
-- vervangen door het emailadres.
DECLARE
   CURSOR c1
   IS
      SELECT prs_perslid_key, prs_perslid_email
      FROM prs_v_aanwezigperslid
      WHERE UPPER (SUBSTR (prs_perslid_email, 1, 30)) IN
                  (SELECT UPPER (SUBSTR (prs_perslid_email, 1, 30))
                   FROM prs_v_aanwezigperslid
                   WHERE UPPER (prs_perslid_email) LIKE '%DSM.COM%'
                   GROUP BY UPPER (SUBSTR (prs_perslid_email, 1, 30))
                   HAVING COUNT (UPPER (SUBSTR (prs_perslid_email, 1, 30))) =
                             1);

   v_rec1   c1%ROWTYPE;
BEGIN
   FOR v_rec1 IN c1
   LOOP
      BEGIN
         DBMS_OUTPUT.put_line('wijziging login:'
                              || SUBSTR (v_rec1.prs_perslid_email, 1, 30));

         UPDATE prs_perslid
         SET prs_perslid_oslogin    = SUBSTR (v_rec1.prs_perslid_email, 1, 30)
         WHERE prs_perslid_key = v_rec1.prs_perslid_key;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line('ERROR:wijziging login:'
                                 || SUBSTR (v_rec1.prs_perslid_email, 1, 30));
      END;
   END LOOP;
END;
/

CREATE TABLE aads_hv_freeze (
   freeze_datum DATE,
   kwartaal VARCHAR2 (10),
   eigenaar VARCHAR2 (100),
   loc_code VARCHAR2 (10),
   geb_code VARCHAR2 (10),
   ver_code VARCHAR2 (10),
   ruimte_nr VARCHAR2 (10),
   ruimtesoort VARCHAR2 (30),
   code VARCHAR2 (30),
   opp NUMBER (8, 2),
   teken_opp NUMBER (8, 2),
   dsm_derden VARCHAR2 (30),
   debiteur VARCHAR2 (30),
   huurder_nummer VARCHAR2 (30),
   huurder_naam VARCHAR2 (60),
   fdc VARCHAR2 (30),
   bezetting NUMBER (3),
   tarief_huur NUMBER (8, 2),
   tarief_service NUMBER (8, 2),
   rema VARCHAR2 (30),
   fm VARCHAR2 (30)
);

-- remove old views
DROP VIEW AAFM_TMP;
DROP VIEW AAFM_TMP_AFD1_NIETAAFM;
DROP VIEW AAFM_TMP_AFD2_NIETAAFM;
DROP VIEW AAFM_V_EXPORT_KOPREGEL;
DROP VIEW AAFM_V_EXPORT_LOGIN;
DROP VIEW AAFM_V_EXPORT_NOTIFICATIE;
DROP VIEW AAFM_V_EXPORT_SUBREGEL;
DROP VIEW AAFM_V_EXPORT_USAGE;
DROP VIEW AAFM_V_HV_ACTUAL;
DROP VIEW AAFM_V_PILOT_USING_FRONTO;
DROP VIEW AAFM_V_RAP_HV_AFD_TOTALEN;
DROP VIEW AAFM_V_RES_BY_FRONTO;
DROP VIEW AAFM_V_RES_OVERVIEW;
DROP VIEW AAFM_V_RES_PILOT_INVOERDER;
DROP VIEW aafm_v_rsv_ruimte_2_alg_ruimte;
DROP VIEW AAFM_V_STAT_LOGIN_USER;
DROP VIEW AAFM_V_THEMA_LEEGSTAND;
DROP VIEW AAFM_V_THEMA_RUIMTE_HUURDER;
DROP VIEW AAFM_V_THEMA_RUIMTE_HUURDER1;
DROP VIEW AAFM_V_THEMA_SRTRUIMTE;

-- remove old procedures
DROP PROCEDURE AAFM_EXPORT_LOGIN;
DROP PROCEDURE AAFM_EXPORT_NOTIFICATIE;
DROP PROCEDURE AAFM_IMPORT_DIENST_LOC_BLD;
DROP PROCEDURE AAFM_SELECT_LOGIN;
DROP PROCEDURE AAFM_SELECT_NOTIFICATIE;
DROP PROCEDURE AAFM_UPDATE_DIENST_LOC_BLD;

DROP PACKAGE AAFM;

-- rename tables to aads
ALTER TABLE aafm_hv_freeze RENAME TO aads_hv_freeze;
ALTER TABLE aafm_perslid_login RENAME TO aads_perslid_login;
ALTER TABLE aafm_imp_dienst_loc_bld RENAME TO aads_imp_dienst_loc_bld;

UPDATE fac_usrrap
SET fac_usrrap_view_name   =
       REPLACE (UPPER (fac_usrrap_view_name), 'AAFM', 'AADS')
WHERE UPPER (fac_usrrap_view_name) LIKE 'AAFM%';

UPDATE cad_thema
SET cad_thema_view   =
       REPLACE (UPPER (cad_thema_view), 'AAFM', 'AADS')
WHERE UPPER (cad_thema_view) LIKE 'AAFM%';


UPDATE cad_label
SET cad_label_view   =
       REPLACE (UPPER (cad_label_view), 'AAFM', 'AADS')
WHERE UPPER (cad_label_view) LIKE 'AAFM%';

-- zet catering scope voor nieuwe catalogi
DELETE res_srtartikel_onrgoed
WHERE res_srtartikel_og_verwijder IS NULL
      AND res_discipline_key IN
               (SELECT ins_discipline_key
                FROM res_discipline
                WHERE ins_discipline_min_level = 2
                      AND ins_discipline_aanmaak >
                            TO_DATE ('20091201', 'yyyymmdd'));

INSERT INTO res_srtartikel_onrgoed
(
    alg_onrgoed_key, alg_onrgoed_niveau, res_discipline_key
)
   SELECT l.alg_locatie_key, 'L', ins_discipline_key
   FROM res_discipline, alg_v_aanweziglocatie l
   WHERE ins_discipline_min_level = 2
         AND ins_discipline_aanmaak > TO_DATE ('20091201', 'yyyymmdd');


SPOOL OFF
@aads.sql