SET ECHO ON
SPOOL xAKZA#31924.lst
SET DEFINE OFF;

----- Menu-items -----

-- 62=WEB_MLDUSE, 78=WEB_MLDBAC , 74=WEB_MLDBOF, 724=WEB_USER31
-- nieuwe menu-kop
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)
       VALUES (200, NULL, NULL, 'KPI', NULL, 0, 724, 1);

-- nieuwe melding
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)
       VALUES (201, NULL, NULL, 'Nieuwe melding', 'appl/mld/mld_melding.asp?urole=fe&srtdisc=161', 0, 724);

-- afhandelen meldingen
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)
       VALUES (202, NULL, NULL, 'Afhandelen meldingen', 'appl/mld/mld_search.asp?urole=bo&srtdisc=161', 0, 724);

-- overzicht kpi
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)
       VALUES (203, NULL, NULL, 'KPI overzichten', 'cust/akza/kpi_search.asp', 0, 724);

-- bevriezen kpi (kpi waarden van lopende periode opnieuw inlezen)
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)
       VALUES (204, NULL, NULL, 'Bevriezen periode', 'appl/Shared/export.asp?name=MLD_KPI', 0, 724);

-- bevriezen KPI waarden via export.
INSERT INTO fac_export_app (fac_export_app_code, fac_export_app_oms, fac_export_app_flags, fac_functie_key, fac_export_app_folder, fac_export_app_log_postfix, fac_export_app_timestamp)
       VALUES ('MLD_KPI', 'Gegevens KPI huidige periode bevriezen', 0, 78, '.', '.log', 'yyyy-mm-dd');

-- Aanmaken nieuwe KPI-meldingen via geplande actie
-- 1. Kosten Budget                  stdmelding_key: 1281  ins_discipline_key: 1455
-- 2. Audit Catering                                 1282                      1451
-- 4. Catering Duurzaam en derving                   1288                      1453
-- 5. Management rapportage                          1289                      1449
-- 7. Audit Receptie                                 1291                      1451


----- Score-tabel -----
CREATE TABLE akza_kpi_scores
(
   periode           DATE,         -- periode (maand) waarover KPI gaat
   locatie           VARCHAR2(50), -- omschrijving van alg_locatie
   alg_locatie_key   NUMBER,       --
   proces            VARCHAR2(50), -- proces (categorie) van KPI
   onderdeel         VARCHAR2(50), -- onderdeel (categorie) van KPI
   kpi_code          VARCHAR2(15), -- verkorte aanduiding KPI
   kpi_omschrijving  VARCHAR2(60), -- aanduiding KPI
   mld_melding_key   NUMBER,       -- melding waarin KPI-score is ingevuld
   score             NUMBER(9,4),  -- behaalde score voor KPI+periode+loc
   norm_drempels     VARCHAR2(20), -- drempelwaardes voor KPI in periode
   norm_scores       VARCHAR2(20)  -- behaalde genormeerde score
);

--INSERT INTO fac_usrtab (fac_usrtab_naam, fac_usrtab_object, fac_usrtab_omschr)
--VALUES ('KPI Periode', 'USR_KPI PERIODE', 'KPI Periode');

--INSERT INTO fac_usrtab (fac_usrtab_naam, fac_usrtab_object, fac_usrtab_omschr)
--VALUES ('KPI Normen', 'USR_KPI NORMEN', 'KPI Normen');

--Aantal fte per locatie, enz.
--INSERT INTO fac_usrtab (fac_usrtab_naam, fac_usrtab_object, fac_usrtab_omschr)
--VALUES ('KPI Instellingen', 'USR_KPI INSTELLINGEN', 'KPI Instellingen');

--KPI codes en omschrijvingen.
--INSERT INTO fac_usrtab (fac_usrtab_naam, fac_usrtab_object, fac_usrtab_omschr)
--VALUES ('KPI Omschrijving', 'USR_KPI OMSCHRIJVING', 'KPI Omschrijving')


----- Autorisatie-view -----
BEGIN
  DECLARE
    v_srtdiscipline_key NUMBER(10);
    v_sqlstring         VARCHAR2(2000);
  BEGIN
    SELECT MAX(ins_srtdiscipline_key)
      INTO v_srtdiscipline_key
      FROM (SELECT ins_srtdiscipline_key
              FROM ins_srtdiscipline
             WHERE ins_srtdiscipline_omschrijving = 'KPI'
             UNION
            SELECT -1 FROM DUAL);

    IF v_srtdiscipline_key = -1 THEN
      INSERT INTO ins_srtdiscipline
                  (ins_srtdiscipline_module, ins_srtdiscipline_omschrijving, ins_srtdiscipline_prefix, ins_srtdiscipline_alg, ins_srtdiscipline_ins)
           VALUES ('MLD', 'KPI', 'KPI', 0, 0)
        RETURNING ins_srtdiscipline_key
             INTO v_srtdiscipline_key;
    END IF;
    --
    v_sqlstring := 'CREATE OR REPLACE VIEW akza_v_kpi_mylocs'
    || ' AS'
    || ' SELECT DISTINCT wg.prs_perslid_key,'
    || '        alg_locatie_key'
    || '   FROM fac_functie f,'
    || '        fac_v_webgebruiker wg,'
    || '        mld_discipline d,'
    || '        alg_v_my_location ml'
    || '  WHERE f.fac_functie_code = ''WEB_MLDBAC'''
    || '    AND wg.fac_functie_key = f.fac_functie_key'
    || '    AND d.ins_discipline_key = wg.ins_discipline_key'
    || '    AND d.ins_srtdiscipline_key =  ' || v_srtdiscipline_key
    || '    AND fac_gebruiker_alg_level_read <=2'
    || '    AND ml.prs_perslid_key = wg.prs_perslid_key';
    EXECUTE IMMEDIATE v_sqlstring;
  END;
END;
/


----- Grafieken -----
CREATE OR REPLACE VIEW akza_g_kpi_tot_tot AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Totaal ',     'akza_g_kpi_tot_tot',    2,    0,   70,   90,  100, null,        78);

CREATE OR REPLACE VIEW akza_g_kpi_tot_trend AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Trend ',      'akza_g_kpi_tot_trend',  4, null, null, null, null, 'FCLT_SORT', 78);

CREATE OR REPLACE VIEW akza_g_kpi_proc_tot AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Totaal ',     'akza_g_kpi_proc_tot',   2,    0,   70,   90,  100, null,        78);

CREATE OR REPLACE VIEW akza_g_kpi_proc_ond AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Onderdelen ', 'akza_g_kpi_proc_ond',   1, null, null, null, null, 'FCLT_SORT', 78);

CREATE OR REPLACE VIEW akza_g_kpi_proc_trend AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Trend ',      'akza_g_kpi_proc_trend', 4, null, null, null, null, 'FCLT_SORT', 78);

CREATE OR REPLACE VIEW akza_g_kpi_ond_tot AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Totaal ',     'akza_g_kpi_ond_tot',    2,    0,   70,   90,  100, null,        78);

CREATE OR REPLACE VIEW akza_g_kpi_ond_proc AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Onderdelen ', 'akza_g_kpi_ond_proc',   1, null, null, null, null, 'FCLT_SORT', 78);

CREATE OR REPLACE VIEW akza_g_kpi_ond_trend AS SELECT 1 x FROM DUAL;
INSERT INTO fac_usrgraph
( fac_usrgraph_omschrijving, fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_limiet0, fac_usrgraph_limiet1, fac_usrgraph_limiet2, fac_usrgraph_limiet3, fac_usrgraph_orderby, fac_functie_key)
VALUES ('Trend ',      'akza_g_kpi_ond_trend',  4, null, null, null, null, 'FCLT_SORT', 78);

SET SQLBLANKLINES ON
UPDATE fac_usrgraph SET fac_usrgraph_options = '{ title: "",
   seriesDefaults: {
      rendererOptions: {
         background: "white",
         ringColor: "#444",
         needleThickness: 7,
         hubRadius: 7,
         intervalInnerRadius: 25,
         intervalOuterRadius: 50,
         shadowDepth: 0,
         intervalColors: [ "#CC0000", "#EE9900", "#77BB00" ]
      }
   }
}'
WHERE fac_usrgraph_omschrijving = 'Totaal ';

-- onderdeel
UPDATE fac_usrgraph SET fac_usrgraph_options = '{  title: "",
   animate: true,
   stackSeries: false,
   seriesDefaults:{
      pointLabels: {
         show: true,
         edgeTolerance: -100,
         ypadding: 0
      }
   },
   series: [ {
      renderer: $.jqplot.BarRenderer,
      rendererOptions: {
         barWidth: 50,
         varyBarColor: true,
         shadow: false
      }
   } ],
   axes: {
      yaxis: {
         min: 0,
         max: 100,
         ticks: [0, 20, 40, 60, 80, 100],
         tickOptions: {
            enableFontSupport: true,
            fontFamily: "Tahoma",
            fontSize: "9pt"
         },
         rendererOptions: {drawBaseline: false}
      },
      xaxis: {
         tickOptions: {
            enableFontSupport: true,
            fontFamily: "Tahoma",
            fontSize: "10pt",
            showGridline: false
         }
      }
   },
   canvasOverlay: {
      show: true,
      objects: [ {
         horizontalLine: {
            name: "n070",
            y: 70,
            lineWidth: 1,
            lineCap: "square",
            color: "rgba(220, 160, 0, 0.5)",
            shadow: false
         }
      },
      {
         horizontalLine: {
            name: "n090",
            y: 90,
            lineWidth: 1,
            lineCap: "square",
            color: "rgba(85, 238, 0, 0.5)",
            shadow: false
         }
      } ]
   },
   axesStyles: {
           borderWidth: 0,
           ticks: {
               fontSize: "20pt",
               fontFamily: "Tahoma",
               textColor: "black"
           },
           label: {
               fontFamily: "Tahoma",
               textColor: "black"
           }
        },
   grid: {
            backgroundColor: "white",
            borderWidth: 0,
            gridLineColor: "#eee",
            gridLineWidth: 1,
            borderColor: "white",
            shadow: false
        }
}'
WHERE fac_usrgraph_omschrijving = 'Onderdelen ';

-- trend
UPDATE fac_usrgraph SET fac_usrgraph_options = '{  title: "",
   animate: true,
   seriesDefaults: {
      showMarker: false,
      pointLabels: {
         show: true
      }
   },
   series: [ {
      color: "#55acda",
      shadow: true
   } ],
   axes: {
      yaxis: {
         tickOptions: {
            enableFontSupport: true,
            fontFamily: "Tahoma",
            fontSize: "9pt"
         },
         rendererOptions: { drawBaseline: false }
      },
      xaxis: {
         tickOptions: {
            enableFontSupport: true,
            fontFamily: "Tahoma",
            fontSize: "10pt",
            showGridline: false
         }
      }
   },
   axesStyles: {
      borderWidth: 0,
      ticks: {
         fontSize: "20pt",
         fontFamily: "Tahoma",
         textColor: "black"
      },
      label: {
         fontFamily: "Tahoma",
         textColor: "black"
      }
   },
   grid: {
      backgroundColor: "white",
      borderWidth: 0,
      gridLineColor: "#eee",
      gridLineWidth: 1,
      borderColor: "white",
      shadow: false
   },
   canvasOverlay: {
      show: true,
      objects: [ {
         horizontalLine: {
            name: "n070",
            y: 70,
            lineWidth: 2,
            lineCap: "square",
            color: "rgba(220, 160, 0, 0.5)",
            shadow: false
          }
       },
       {
          horizontalLine: {
             name: "n090",
             y: 90,
             lineWidth: 2,
             lineCap: "square",
             color: "rgba(85, 238, 0, 0.5)",
             shadow: false
          }
       } ]
    }
}'
WHERE fac_usrgraph_omschrijving = 'Trend ';
SET SQLBLANKLINES OFF


----- Imports -----

-- Imports schoonmaakmedewerkers (KPI 10)
CREATE TABLE akza_imp_kpi_sch_mw_vast (
   pers_nr        VARCHAR2(20),
   pers_naam      VARCHAR2(100),
   locatie        VARCHAR2(20),
   kostenplaats   NUMBER(8)
);
CREATE TABLE akza_imp_kpi_sch_mw_uren (
   pers_nr        VARCHAR2(20),
   pers_naam      VARCHAR2(100),
   kostenplaats   VARCHAR2(20),
   locatie        VARCHAR2(20),
   uren           NUMBER(6,2)
);


BEGIN adm.systrackscriptId('$Id$', 0); END;
/
COMMIT;
SPOOL OFF
