-- Script containing customer specific configuration sql statements for aafm: Arcadis Aqumen Facility Management
-- (c) 2005-2007 Dijkoraad IT bv
-- $Revision$
-- $Id$
--
-- Support: +31 53 4800700

SET DEFINE OFF
SET ECHO ON
spool xaafm.lst

-- grants die nodig zijn om de persoonsgegeven uit de aa database te koppelen aan
-- de personen uit de andere accounts.
-- Daartoe is ooit een grant gedaan:
-- GRANT SELECT ON aait.aait_imp_perslid TO PUBLIC

CREATE OR REPLACE VIEW aafm_v_lcrap_fe_vs_key
(
   account,
   tijdstip,
   fe_users,
   key_users,
   recent_login
)
AS
   SELECT 'AAAH', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAAH.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAAR', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAAR.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AADB', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AADB.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AADO', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AADO.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AADS', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AADS.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAES', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAES.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAGN', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAGN.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAHB', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAHB.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAIT', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAIT.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAPM', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAPM.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AARW', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AARW.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AASA', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AASA.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AAVG', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AAVG.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'AQQA', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM AQQA.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'EXPO', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM EXPO.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'GULU', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM GULU.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'INLO', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM INLO.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'NMMS', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM NMMS.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'RABO', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM RABO.FAC_V_LCRAP_FE_VS_KEY r
   UNION ALL
   SELECT 'SMKA', r.tijdstip, r.fe_users, r.key_users, r.recent_login
     FROM NMMS.FAC_V_LCRAP_FE_VS_KEY r;


CREATE OR REPLACE VIEW aafm_v_lcrap_key_stats
(
   account,
   prs_perslid_key,
   prs_perslid_oslogin,
   prs_perslid_oslogin2,
   prs_perslid_nr,
   prs_perslid_naam_full,
   prs_afdeling_naam,
   lev_write_cnt,
   max_alg_write,
   max_prs_write,
   lev_read_cnt,
   max_alg_read,
   max_prs_read,
   aut_groep_cnt
)
AS
   SELECT 'AAAH',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aaah.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAAR',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aaar.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AADB',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aadb.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AADO',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aado.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AADS',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aads.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAES',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aaes.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAGN',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aagn.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAHB',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aahb.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAIT',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aait.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAPM',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aapm.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AARW',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aarw.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AASA',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aasa.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AAVG',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aavg.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'AQQA',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM aqqa.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'EXPO',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM expo.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'GULU',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM gulu.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'INLO',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM inlo.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'NMMS',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM nmms.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'RABO',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM rabo.aaxx_v_lcrap_key_stats r
   UNION ALL
   SELECT 'SMKA',
          r."PRS_PERSLID_KEY",
          r."PRS_PERSLID_OSLOGIN",
          r."PRS_PERSLID_OSLOGIN2",
          r."PRS_PERSLID_NR",
          r."PRS_PERSLID_NAAM_FULL",
          r."PRS_AFDELING_NAAM",
          r."LEV_WRITE_CNT",
          r."MAX_ALG_WRITE",
          r."MAX_PRS_WRITE",
          r."LEV_READ_CNT",
          r."MAX_ALG_READ",
          r."MAX_PRS_READ",
          r."AUT_GROEP_CNT"
     FROM smka.aaxx_v_lcrap_key_stats r;


CREATE OR REPLACE VIEW aafm_v_it_key_users
(
   account,
   prs_perslid_naam_full,
   accountsperuser
)
AS
     SELECT 'AAIT' account,
            a.prs_perslid_naam_full,
            COUNT (a.prs_perslid_naam_full) accountsperuser
       FROM aafm_v_lcrap_key_stats a, aait.aait_imp_perslid i
      WHERE a.prs_perslid_nr = i.personeelsnummer
   GROUP BY a.prs_perslid_naam_full;


CREATE OR REPLACE VIEW aafm_v_other_key_users
(
   account,
   prs_perslid_key,
   prs_perslid_naam_full
)
AS
   SELECT account, prs_perslid_key, prs_perslid_naam_full
     FROM aafm_v_lcrap_key_stats a
    WHERE NOT EXISTS
             (SELECT prs_perslid_key
                FROM aait.aait_imp_perslid i
               WHERE a.prs_perslid_nr = i.personeelsnummer);


CREATE OR REPLACE VIEW aafm_v_user
(
   account,
   tijdstip,
   fe_users,
   key_users,
   key_users_cor
)
AS
   SELECT org.account,
          TO_CHAR (tijdstip, 'dd-mm-yyyy hh24:mi'),
          fe_users,
          key_users,
          nrofkeyusers key_users_cor
     FROM (  SELECT account, COUNT (prs_perslid_key) nrofkeyusers
               FROM aafm_v_other_key_users
           GROUP BY account) cor, aafm_v_lcrap_fe_vs_key org
    WHERE org.account = cor.account(+) AND org.account <> 'AAIT'
   UNION ALL
   SELECT 'AAIT',
          TO_CHAR (SYSDATE, 'dd-mm-yyyy hh24:mi'),
          TO_NUMBER(NULL),
          TO_NUMBER(NULL),
          nrofkeyusers key_users_cor
     FROM (  SELECT account, COUNT (prs_perslid_naam_full) nrofkeyusers
               FROM aafm_v_it_key_users
           GROUP BY account);

-- AAFM heeft geen standaard FACILITOR packages
-- BEGIN adm.systrackscriptId('$Id$', 0); END;
/
COMMIT;
SPOOL OFF
