--
-- $Id$
--
-- Aanpassingen
-- Script om het kenmerk Klant kostenplaats aan te passen.

DEFINE thisfile = 'YASK#70928.SQL'
DEFINE dbuser   = '^YASK'

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

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


DECLARE

CURSOR c IS
SELECT 'A6995' melding,'A6995/1' opdracht,'B2' kpn FROM DUAL UNION
SELECT 'A6995','A6995/3','B2' FROM DUAL UNION
SELECT 'A7136','A7136/2','B3' FROM DUAL UNION
SELECT 'A8358','A8358/1','B3' FROM DUAL UNION
SELECT 'A9390','A9390/3','B3' FROM DUAL UNION
SELECT 'S10444','S10444/2','B3' FROM DUAL UNION
SELECT 'S12066','S12066/1','B3' FROM DUAL UNION
SELECT 'A1132','A1132/1','B3' FROM DUAL UNION
SELECT 'A1132','A1132/2','B3' FROM DUAL UNION
SELECT 'A1789','A1789/1','B2' FROM DUAL UNION
SELECT 'A5801','A5801/1','B2' FROM DUAL UNION
SELECT 'A5801','A5801/2','B2' FROM DUAL UNION
SELECT 'A5801','A5801/3','B2' FROM DUAL UNION
SELECT 'A6995','A6995/2','B2' FROM DUAL UNION
SELECT 'A11722','A11722/1','B2' FROM DUAL UNION
SELECT 'A11722','A11722/2','B2' FROM DUAL UNION
SELECT 'A8223','A8223/1','B2' FROM DUAL UNION
SELECT 'A8223','A8223/2','B2' FROM DUAL UNION
SELECT 'A8223','A8223/3','B2' FROM DUAL UNION
SELECT 'A11274','A11274/1','B2' FROM DUAL UNION
SELECT 'A11274','A11274/2','B2' FROM DUAL;


v_melding_key NUMBER;
v_opdr_key NUMBER;

BEGIN

   FOR rec IN c
   LOOP
      SELECT mld_melding_key
       INTO v_melding_key
       FROM mld_melding
       WHERE rec.melding LIKE '_' || mld_melding_key;

      INSERT INTO fac_tracking (fac_srtnotificatie_key,
                                fac_tracking_refkey,
                                fac_tracking_oms)
      VALUES (53,  -- MLDUPD
              v_melding_key,
              'Kostenplaats klant aangepast naar: ' || rec.kpn);

      MLD.upsertmeldingkenmerk (181, v_melding_key, rec.kpn);

      SELECT mld_opdr_key
        INTO v_opdr_key
        FROM mld_opdr
       WHERE rec.opdracht LIKE '_' || mld_melding_key || '/' || mld_opdr_bedrijfopdr_volgnr;

      INSERT INTO fac_tracking (fac_srtnotificatie_key,
                                fac_tracking_refkey,
                                fac_tracking_oms)
      VALUES (76,  -- ORDUPD
              v_opdr_key,
              'Kostenplaats klant aangepast naar: ' || rec.kpn);

      MLD.upsertopdrachtkenmerk (81, v_opdr_key, rec.kpn);

      UPDATE fin_verkoopfactuur SET fin_verkoopfactuur_c8 = rec.kpn WHERE fin_verkoopfactuur_id = rec.opdracht;

   END LOOP;
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
