--
-- $Id$
--
--

DEFINE thisfile = 'PCHW#51534.sql'
DEFINE dbuser   = '^PCHW'


SET ECHO ON
SET DEFINE ON
COLUMN fcltlogfile NEW_VALUE fcltlogfile NOPRINT;
WHENEVER SQLERROR EXIT;
SELECT adm.scriptspoolfile('&dbuser', '&thisfile') AS fcltlogfile FROM DUAL;
WHENEVER SQLERROR CONTINUE;
SPOOL &fcltlogfile
SET DEFINE OFF

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

DELETE pchx_monitoring
 WHERE melding_key IN (751, 1269, 1090);


UPDATE pchx_monitoring
   SET totaal = 0, totaal_index = 0, kinderen = REPLACE (kinderen, ',751')
 WHERE kinderen LIKE '%,751%' AND variabelekorting = 250;

UPDATE pchx_monitoring
   SET totaal = totaal - 50,
       totaal_index =
             totaal_index
           - PCHX_MON.get_index_value (TRUNC (SYSDATE) - 1, 'MON') * 50,
       kinderen = REPLACE (kinderen, ',751')
 WHERE kinderen LIKE '%,751%' AND variabelekorting = 50;

UPDATE pchx_monitoring
   SET totaal = 0, totaal_index = 0, kinderen = REPLACE (kinderen, ',1269')
 WHERE kinderen LIKE '%,1269%' AND variabelekorting = 250;

UPDATE pchx_monitoring
   SET totaal = totaal - 50,
       totaal_index =
             totaal_index
           - PCHX_MON.get_index_value (TRUNC (SYSDATE) - 1, 'MON') * 50,
       kinderen = REPLACE (kinderen, ',1269')
 WHERE kinderen LIKE '%,1269%' AND variabelekorting = 50;

UPDATE pchx_monitoring
   SET totaal = 0, totaal_index = 0, kinderen = REPLACE (kinderen, ',1090')
 WHERE kinderen LIKE '%,1090%' AND variabelekorting = 250;

UPDATE pchx_monitoring
   SET totaal = totaal - 50,
       totaal_index =
             totaal_index
           - PCHX_MON.get_index_value (TRUNC (SYSDATE) - 1, 'MON') * 50,
       kinderen = REPLACE (kinderen, ',1090')
 WHERE kinderen LIKE '%,1090%' AND variabelekorting = 50;

 --    select sum(totaal), sum(totaal_index) from pchx_monitoring
 --    where melding_key in (751, 1269, 1090)  -- 1680, 1695,13

 --    select sum(totaal), sum(totaal_index) from pchx_monitoring   -- 125865 126998,05
 --    na script -- 123535,  124647.07

------ payload end   ------

SET DEFINE OFF
BEGIN adm.systrackscriptId ('$Id$', 1); END;
/

COMMIT;
SET ECHO OFF
SPOOL OFF
SET DEFINE ON
PROMPT Logfile of this upgrade is: &fcltlogfile