--
-- $Id$
--
-- Script containing customer specific sql statements for Netwerkstat Twente (Gemeente Borne)

DEFINE thisfile = 'NETS.SQL'
DEFINE dbuser   = 'NETS'

SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
COLUMN fcltcusttxt NEW_VALUE fcltcusttxt NOPRINT;
WHENEVER SQLERROR CONTINUE;
SELECT adm.getscriptspoolfile('&thisfile') AS fcltlogfile FROM DUAL;
SPOOL &fcltlogfile
WHENEVER SQLERROR EXIT;
SELECT adm.checkscriptcust('&dbuser') AS fcltcusttxt FROM DUAL;
WHENEVER SQLERROR CONTINUE;
---------------------------------------
PROMPT &fcltcusttxt
---------------------------------------
SET DEFINE OFF

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

CREATE OR REPLACE VIEW nets_v_noti_cntreminder_rappel
AS
   SELECT 'CUST01' code,
          NULL sender,
          c.prs_perslid_key_beh receiver,
             'Op '
          || TO_CHAR (c.cnt_contract_looptijd_tot, 'dd-mm-yyyy')
          || ' loopt '
          || c.cnt_contract_nummer_intern
          || ' ('
          || c.cnt_contract_omschrijving
          || ') af.' text,
          c.cnt_contract_key key,
          NULL xkey
     FROM cnt_v_aanwezigcontract  c,
          prs_bedrijf             b,
          prs_perslid             p,
          prs_v_afdeling_boom     ab
    WHERE     c.cnt_prs_bedrijf_key = b.prs_bedrijf_key
          AND c.prs_perslid_key_beh = p.prs_perslid_key
          AND p.prs_afdeling_key = ab.prs_afdeling_key
          AND ab.prs_afdeling_key1 IN (41, 42, 43)                                 -- Alleen mails naar ALM/ENS/BOR-beh!
          AND TRUNC (SYSDATE) = TRUNC (cnt.cnt_getRappeldatum (c.cnt_contract_key))
   UNION ALL
   SELECT 'CUST01' code,
          NULL sender,
          c.prs_perslid_key_eig receiver,
          'Op '
          || TO_CHAR (c.cnt_contract_looptijd_tot, 'dd-mm-yyyy')
          || ' loopt '
          || c.cnt_contract_nummer_intern
          || ' ('
          || c.cnt_contract_omschrijving
          || ') af.' text,
          c.cnt_contract_key key,
          NULL xkey
     FROM cnt_v_aanwezigcontract  c,
          prs_bedrijf             b,
          prs_perslid             p,
          prs_v_afdeling_boom     ab
    WHERE     c.cnt_prs_bedrijf_key = b.prs_bedrijf_key
          AND c.prs_perslid_key_eig = p.prs_perslid_key
          AND p.prs_afdeling_key = ab.prs_afdeling_key
          AND ab.prs_afdeling_key1 = 43                                                    -- Alleen mails naar BOR-eig!
          AND TRUNC (SYSDATE) = TRUNC (cnt.cnt_getRappeldatum (c.cnt_contract_key));

------ 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
