-- Customer specific once-script ARAI.
--
-- (c) 2012 SG|facilitor bv 
-- $Revision$ 
-- $Id$
--
-- Support: +31 53 4800700

SET ECHO ON
SPOOL arai10.lst
SET DEFINE OFF


CREATE TABLE arai_imp_kpi_energie (
   ins_deel_omschrijving VARCHAR2 (256),
   ins_deel_meetwaarde VARCHAR2 (256)
);


-- WEB_USER07 is fac_functie bedoeld voor API-imports.
INSERT INTO fac_import_app
            (fac_import_app_code, fac_import_app_oms,
             fac_functie_key, fac_import_app_prefix,
             fac_import_app_xsl, fac_import_app_charset
             )
   SELECT 'KPI_ENERGIE', 'Import energie meetwaarden als water, gas en elektra',
          fac_functie_key, 'ARAI', 'xsl/fclt_import_kpi_energie.xsl', 'UTF-8'
     FROM fac_functie
    WHERE fac_functie_code = 'WEB_USER07';

-- PRS_PERSLID_KEY = 2501 is de gebruiker met naam 'KPIIMPORT_ENERGIE' (is handmatig toegevoegd in productie, d.d. 25 apr 2013 om 15:32u)

INSERT INTO fac_api 
(FAC_API_NAME, 
 FAC_API_APIKEY,
 FAC_API_OMSCHRIJVING,
 FAC_API_NO_SESSION,
 PRS_PERSLID_KEY,
 FAC_API_LOGLEVEL,
 FAC_API_FILEPATH,
 FAC_IMPORT_APP_KEY,
 FAC_API_OPTIONS_JSON
)
SELECT  'KPI_ENERGIE',
        'fQqCaAXWlavSutOluDfYbvnGnCYAAeWa', 
        'Priva import van energiewaarden',
        1,
        2501,
        1, 
        'appl/API/api_gen_import.asp',
        fac_import_app_key, '{"import_app_key":' || fac_import_app_key || '}'
FROM fac_import_app
WHERE fac_import_app_code = 'KPI_ENERGIE';


-- Menutaak 'RTM Energie' handmatig, deze menutaak activeert "appl/fac/fac_widgetspage.asp?wgrp=rtm_energie"


--
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)
SELECT 'rtm_energie',5,'', 25, 99, '..\..\cust\arai\html\rtm_empty.html', NULL FROM dual;
--

-- RIJ 1: WATER en GAS VERBRUIK

INSERT INTO fac_usrgraph (fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_orderby, fac_usrgraph_maxrows)
VALUES ('arai_v_graph_water_nu', 1, 'FCLT_XAS_', 10);
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)
SELECT 'rtm_energie',9,'', 180 , 10, '..\..\cust\arai\html\rtm_energie_water.html', 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)
SELECT 'rtm_energie',10,'Waterverbruik (m3)', 180, 30, 'fac_usrgraph.asp?usrgraph_key=' || MAX(fac_usrgraph_key), 60 FROM fac_usrgraph;
--
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)
SELECT 'rtm_energie',11,'', 180, 15, '..\..\cust\arai\html\rtm_empty.html', NULL FROM dual;
--
INSERT INTO fac_usrgraph (fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_orderby, fac_usrgraph_maxrows)
VALUES ('arai_v_graph_gas_nu', 1, 'FCLT_XAS_', 10);
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)
SELECT 'rtm_energie',19,'',180 , 10, '..\..\cust\arai\html\rtm_energie_gas.html', 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)
SELECT 'rtm_energie',20,'Gasverbruik (m3)', 180, 30, 'fac_usrgraph.asp?usrgraph_key=' || MAX(fac_usrgraph_key), 60 FROM fac_usrgraph;
--


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)
SELECT 'rtm_energie',25,'', 25, 99, '..\..\cust\arai\html\rtm_empty.html', NULL FROM dual;

--

-- RIJ 2: EELKTRA en WARMTE VERBRUIK

INSERT INTO fac_usrgraph (fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_orderby, fac_usrgraph_maxrows)
VALUES ('arai_v_graph_elektra_nu', 1, 'FCLT_XAS_', 10);
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)
SELECT 'rtm_energie',29,'',180 , 10, '..\..\cust\arai\html\rtm_energie_elektra.html', 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)
SELECT 'rtm_energie',30,'Elektraverbruik (kW)', 180, 30, 'fac_usrgraph.asp?usrgraph_key=' || MAX(fac_usrgraph_key), 60 FROM fac_usrgraph;
--
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)
SELECT 'rtm_energie',31,'', 180, 15, '..\..\cust\arai\html\rtm_empty.html', NULL FROM dual;
--
INSERT INTO fac_usrgraph (fac_usrgraph_view_name, fac_usrgraph_type, fac_usrgraph_orderby, fac_usrgraph_maxrows)
VALUES ('arai_v_graph_warmte_nu', 1, 'FCLT_XAS_', 10);
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)
SELECT 'rtm_energie',39,'',180 , 10, '..\..\cust\arai\html\rtm_energie_warmte.html', 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)
SELECT 'rtm_energie',40,'Warmteverbruik (gj)', 180, 30, 'fac_usrgraph.asp?usrgraph_key=' || MAX(fac_usrgraph_key), 60 FROM fac_usrgraph;

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)
SELECT 'rtm_energie',50,'', 40, 99, '..\..\cust\arai\html\rtm_empty.html', NULL FROM dual;

-----
-- Behalve de energiegrafieken, ook 1 XSL-rapportage als RT-monitor, te weten de halbezetting.
-- WEB_USER08 is de CUST-autorisatie functie voor RTM Energie

INSERT INTO fac_usrrap
            (fac_usrrap_omschrijving,
             fac_usrrap_view_name,
             fac_usrrap_in_huidige_locatie,
             fac_usrrap_template,
             fac_usrrap_macro,
             fac_usrrap_vraagbegindatum,
             fac_usrrap_vraageinddatum,
             fac_usrrap_functie,
             fac_usrrap_info,
             fac_functie_key,
             fac_usrrap_autorefresh
            )
    SELECT  'Halbezetting',
             'arai_v_hall_bezetting',
             NULL,
             NULL,
             NULL,
             0,
             0,
             1,
             'RTM - halbezetting',
             fac_functie_key,
             0
     FROM fac_functie WHERE fac_functie_code = 'WEB_USER08';


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)
SELECT 'rtm_energie',60,'', 200, 99, 'fac_usrrap.asp?rap_name=arai_v_hall_bezetting' || '&' || 'autoexec=1', 600 FROM dual;



----------------------------------------------------------------------------------------------------------------------------------------------------------
--- ** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **  --
--- ** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **  --
--- ** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **** TEMP **  --
----------------------------------------------------------------------------------------------------------------------------------------------------------


-- Tbv import objecten die kenmerken standaard meenemen en inserten, nu alvast een voorschot op 5.3.1 waar dat standaard gebeurt een customer-variant (copy van nybu)
-- Importtabel objecten
CREATE TABLE arai_imp_ins
(
   ins_discipline_omschrijving   VARCHAR2 (30),
   ins_discipline_kostensoort    VARCHAR2 (60),
   ins_srtgroep_omschrijving     VARCHAR2 (60),
   ins_srtdeel_code              VARCHAR2 (10),
   ins_srtdeel_omschrijving      VARCHAR2 (100),
   ins_deel_omschrijving         VARCHAR2 (60),
   reserveerbaar                 NUMBER (1),
   res_deel_eenheid              VARCHAR2 (10),
   res_deel_prijs                NUMBER (7, 2),
   alg_locatie_code              VARCHAR2 (10),
   alg_gebouw_code               VARCHAR2 (12),
   alg_verdieping_volgnr         NUMBER (3),
   alg_ruimte_nr                 VARCHAR2 (10),
   res_deel_alg_level            NUMBER (1),
   res_discipline_omschrijving   VARCHAR2 (30),
   res_discipline_kostensoort    VARCHAR2 (60),
   prs_perslid_matchcode         VARCHAR2 (255),
   prs_perslid_matchwaarde       VARCHAR2 (255),
   ins_kenmerkwaarde1            VARCHAR2 (255),
   ins_kenmerkwaarde2            VARCHAR2 (255),
   ins_kenmerkwaarde3            VARCHAR2 (255),
   ins_kenmerkwaarde4            VARCHAR2 (255),
   ins_kenmerkwaarde5            VARCHAR2 (255),
   ins_kenmerkwaarde6            VARCHAR2 (255),
   ins_kenmerkwaarde7            VARCHAR2 (255),
   ins_kenmerkwaarde8            VARCHAR2 (255),
   ins_kenmerkwaarde9            VARCHAR2 (255),
   ins_kenmerkwaarde10           VARCHAR2 (255),
   ins_kenmerkwaarde11           VARCHAR2 (255),
   ins_kenmerkwaarde12           VARCHAR2 (255),
   ins_kenmerkwaarde13           VARCHAR2 (255),
   ins_kenmerkwaarde14           VARCHAR2 (255),
   ins_kenmerkwaarde15           VARCHAR2 (255),
   ins_kenmerkwaarde16           VARCHAR2 (255),
   ins_kenmerkwaarde17           VARCHAR2 (255),
   ins_kenmerkwaarde18           VARCHAR2 (255),
   ins_kenmerkwaarde19           VARCHAR2 (255),
   ins_kenmerkwaarde20           VARCHAR2 (255)
);

-- Importfunctie objecten
INSERT INTO fac_import_app (fac_import_app_code,
                            fac_import_app_oms,
                            fac_functie_key,
                            fac_import_app_prefix)
   SELECT   'INS',
            'FIP: Aanmaken/bijwerken objecten',
            fac_functie_key,
            'arai'
     FROM   fac_functie
    WHERE   fac_functie_code = 'WEB_PRSSYS';



BEGIN adm.systrackscript('$Workfile: arai10.sql $', '$Revision$', 1); END;
/

SPOOL OFF

@arai.sql
