--
-- $Id$
--
-- Niet afgewezen offerteopdrachten verwijderen

DEFINE thisfile = 'YKPN#61880.sql'
DEFINE dbuser   = '^KF'


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

DECLARE
    CURSOR c IS
        SELECT mld_opdr_key
          FROM mld_opdr         o,
               mld_typeopdr     ot,
               mld_melding      m,
               mld_stdmelding   std,
               mld_disc_params  dp
         WHERE     o.mld_typeopdr_key = ot.mld_typeopdr_key
               AND o.mld_melding_key = m.mld_melding_key
               AND m.mld_stdmelding_key = std.mld_stdmelding_key
               AND std.mld_ins_discipline_key = dp.mld_ins_discipline_key
               AND mld_typeopdr_isofferte = 1
               AND COALESCE (dp.mld_disc_params_offerteauto, 0) <> 1
               AND mld_statusopdr_key = 6                          -- Afgemeld
               AND mld_opdr_datumbegin < TO_DATE ('20190101', 'yyyymmdd');
BEGIN
    FOR rec IN c
    LOOP
        mld.setopdrachtstatus (rec.mld_opdr_key, 2, NULL); -- Zet opdrachtstatus op Niet Akkoord
    END LOOP;

    DELETE fac_notificatie
     WHERE fac_srtnotificatie_key =
           (SELECT fac_srtnotificatie_key
              FROM fac_srtnotificatie
             WHERE fac_srtnotificatie_code = 'ORDONO');

    COMMIT;
END;
/

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