--
-- $Id$
--
-- Customer specific once-script BLCC#38826.
DEFINE thisfile = 'BLCC#38826.SQL'
DEFINE dbuser   = '^BLCC'
DEFINE custid   = 'BLCC'

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

-- Verplichte Doorbelasten-veld (201 voor Workorder en 202 voor Splitorder) op
-- ToDo (= 321) zetten voor alle nog niet gesloten opdrachten!
/* Formatted on 18-8-2016 9:45:15 (QP5 v5.136.908.31019) */
INSERT INTO mld_kenmerkopdr (mld_opdr_key, mld_kenmerk_key, mld_kenmerkopdr_waarde)
   SELECT o.mld_opdr_key, DECODE (o.mld_typeopdr_key, 101, 201, 202), '321'
     FROM mld_opdr o
    WHERE o.mld_typeopdr_key IN (101, 102)             -- Workorder/Splitorder
          AND o.mld_statusopdr_key NOT IN (1, 2, 7)       -- Nog niet gesloten
          AND NOT EXISTS
                (SELECT 1
                   FROM mld_v_aanwezigkenmerkopdr ko, mld_kenmerk k
                  WHERE     ko.mld_kenmerk_key = k.mld_kenmerk_key
                        AND k.mld_srtkenmerk_key = 241  -- Doorbelasten Ja/Nee
                        AND ko.mld_opdr_key = o.mld_opdr_key);

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

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

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