-- Script containing customer specific db-configuration for VENT.
-- (c) 2015 Facilitor B.V.
--
-- Support: +31 53 4800700
set echo on
spool xvent.lst

/* Formatted on 22-4-2016 16:23:01 (QP5 v5.136.908.31019) */
CREATE OR REPLACE VIEW vent_v_noti_cntreminder
(
   code,
   sender,
   receiver,
   text,
   KEY,
   par1,
   par2,
   xkey
)
AS
   SELECT sn.fac_srtnotificatie_code,
          '',
          c.prs_perslid_key_beh,
          --sn.fac_srtnotificatie_oms,
          REPLACE (
             sn.fac_srtnotificatie_oms,
             '##CNR##',
             c.cnt_contract_nummer_intern
             || DECODE (cnt_contract_versie, NULL, '', '.' || cnt_contract_versie)),
          c.cnt_contract_key,
          c.cnt_contract_nummer_intern,
          NULL,
          NULL
     FROM cnt_v_aanwezigcontract c, fac_srtnotificatie sn
    WHERE c.cnt_contract_status = 0
          AND TRUNC (cnt.cnt_getRappeldatum (c.cnt_contract_key)) = TRUNC (SYSDATE)
          AND sn.fac_srtnotificatie_code = 'CUST01'
   UNION ALL
   SELECT sn.fac_srtnotificatie_code,
          '',
          c.prs_perslid_key_eig,
          REPLACE (
             sn.fac_srtnotificatie_oms,
             '##CNR##',
             c.cnt_contract_nummer_intern
             || DECODE (cnt_contract_versie, NULL, '', '.' || cnt_contract_versie)),
          c.cnt_contract_key,
          c.cnt_contract_nummer_intern,
          NULL,
          NULL
     FROM cnt_v_aanwezigcontract c, fac_srtnotificatie sn
    WHERE c.cnt_contract_status = 0
          AND TRUNC (cnt.cnt_getOpzegdatum (c.cnt_contract_key)) = TRUNC (SYSDATE)
          AND sn.fac_srtnotificatie_code = 'CUST02'
   UNION ALL
   SELECT sn.fac_srtnotificatie_code,
          '',
          c.prs_perslid_key_beh,
          REPLACE (
             sn.fac_srtnotificatie_oms,
             '##CNR##',
             c.cnt_contract_nummer_intern
             || DECODE (cnt_contract_versie, NULL, '', '.' || cnt_contract_versie)),
          c.cnt_contract_key,
          c.cnt_contract_nummer_intern,
          NULL,
          NULL
     FROM cnt_v_aanwezigcontract c, fac_srtnotificatie sn
    WHERE c.cnt_contract_status = 0
          AND TRUNC (cnt.cnt_getOpzegdatum (c.cnt_contract_key)) = TRUNC (SYSDATE)
          AND sn.fac_srtnotificatie_code = 'CUST02'
   UNION ALL
   SELECT sn.fac_srtnotificatie_code,
          '',
          c.prs_perslid_key_beh,
          REPLACE (
             sn.fac_srtnotificatie_oms,
             '##CNR##',
             c.cnt_contract_nummer_intern
             || DECODE (cnt_contract_versie, NULL, '', '.' || cnt_contract_versie)),
          c.cnt_contract_key,
          c.cnt_contract_nummer_intern,
          NULL,
          NULL
     FROM cnt_v_aanwezigcontract c, cnt_kenmerkcontract kc, cnt_kenmerk k, fac_srtnotificatie sn
    WHERE     c.cnt_contract_status = 0
          AND c.cnt_contract_key = kc.cnt_contract_key
          AND kc.cnt_kenmerkcontract_verwijder IS NULL
          AND kc.cnt_kenmerk_key = k.cnt_kenmerk_key
          AND k.cnt_srtkenmerk_key = 3                     -- Datum indexering
          AND SUBSTR (kc.cnt_kenmerkcontract_waarde, 1, 10) = TO_CHAR (SYSDATE, 'dd-mm-yyyy')
          AND sn.fac_srtnotificatie_code = 'CUST03'
   UNION ALL
   SELECT sn.fac_srtnotificatie_code,
          '',
          c.prs_perslid_key_beh,
          REPLACE (
             sn.fac_srtnotificatie_oms,
             '##CNR##',
             c.cnt_contract_nummer_intern
             || DECODE (cnt_contract_versie, NULL, '', '.' || cnt_contract_versie)),
          c.cnt_contract_key,
          c.cnt_contract_nummer_intern,
          NULL,
          NULL
     FROM cnt_v_aanwezigcontract c, cnt_kenmerkcontract kc, cnt_kenmerk k, fac_srtnotificatie sn
    WHERE     c.cnt_contract_status = 0
          AND c.cnt_contract_key = kc.cnt_contract_key
          AND kc.cnt_kenmerkcontract_verwijder IS NULL
          AND kc.cnt_kenmerk_key = k.cnt_kenmerk_key
          AND k.cnt_srtkenmerk_key = 4                  -- Datum rentebetaling
          AND SUBSTR (kc.cnt_kenmerkcontract_waarde, 1, 10) = TO_CHAR (SYSDATE, 'dd-mm-yyyy')
          AND sn.fac_srtnotificatie_code = 'CUST04';

BEGIN adm.systrackscriptId('$Id$'); END;
/
BEGIN fac.registercustversion('VENT', 1); END;
/
commit;
spool off
