-- Customer specific once-script NETS4.
--
-- (c) 2016 Facilitor B,V.
--
-- Support: +31 53 4800700
SET ECHO ON
SPOOL xNETS4.lst
SET DEFINE OFF

-- NETS#35845
-- Beheerder naar eigenaar voor Borne-contracten
/*
SELECT *
  FROM cnt_contract c
 WHERE c.cnt_contract_verwijder IS NULL
       AND c.cnt_contract_looptijd_tot >= SYSDATE
       --[inverse] AND c.prs_perslid_key_eig IS NOT NULL
       --[inverse] AND c.prs_perslid_key_beh IN (10901, 12649)    -- Fons Olijve/Hans Pauw
       AND (c.prs_perslid_key_eig IS NULL
            OR (c.prs_perslid_key_eig IS NOT NULL
                AND c.prs_perslid_key_beh NOT IN (10901, 12649))) -- Fons Olijve/Hans Pauw
       AND EXISTS
             (SELECT 1
                FROM prs_perslid p, prs_v_afdeling_boom ab
               WHERE     p.prs_perslid_key = c.prs_perslid_key_beh
                     AND p.prs_afdeling_key = ab.prs_afdeling_key
                     AND ab.prs_afdeling_key1 = 43);
*/
UPDATE cnt_contract c
   SET c.prs_perslid_key_eig = c.prs_perslid_key_beh
 WHERE c.cnt_contract_verwijder IS NULL
       AND c.cnt_contract_looptijd_tot >= SYSDATE
       AND (c.prs_perslid_key_eig IS NULL
            OR (c.prs_perslid_key_eig IS NOT NULL
                AND c.prs_perslid_key_beh NOT IN (10901, 12649))) -- Fons Olijve/Hans Pauw
       AND EXISTS
             (SELECT 1
                FROM prs_perslid p, prs_v_afdeling_boom ab
               WHERE     p.prs_perslid_key = c.prs_perslid_key_beh
                     AND p.prs_afdeling_key = ab.prs_afdeling_key
                     AND ab.prs_afdeling_key1 = 43);

-- Eigenaar op Fons Olijve voor Borne-contracten
UPDATE cnt_contract c
   SET c.prs_perslid_key_beh = 10901                            -- Fons Olijve
 WHERE c.cnt_contract_verwijder IS NULL
       AND c.cnt_contract_looptijd_tot >= SYSDATE
       AND (c.prs_perslid_key_eig IS NULL
            OR (c.prs_perslid_key_eig IS NOT NULL
                AND c.prs_perslid_key_beh NOT IN (10901, 12649))) -- Fons Olijve/Hans Pauw
       AND EXISTS
             (SELECT 1
                FROM prs_perslid p, prs_v_afdeling_boom ab
               WHERE     p.prs_perslid_key = c.prs_perslid_key_beh
                     AND p.prs_afdeling_key = ab.prs_afdeling_key
                     AND ab.prs_afdeling_key1 = 43)
       AND c.prs_perslid_key_beh NOT IN (10901, 12649);

COMMIT;
BEGIN adm.systrackscriptId('$Id$'); END;
/
SPOOL OFF
@nets.sql
