-- $Id$
--
-- Script om een inspectie met bijbehorende melding en opdracht te verwijderen.
--
--
DEFINE thisfile = 'SKAF#81021.SQL'
DEFINE dbuser   = '^SKAF'

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

-- Tracking opdracht 26506/1 verwijderen.
DELETE
  FROM fac_tracking ft
 WHERE ft.fac_srtnotificatie_key IN (SELECT fsn.fac_srtnotificatie_key FROM fac_srtnotificatie fsn WHERE fsn.fac_srtnotificatie_code IN ('ORDNEW', 'ORDMLE', 'ORDAFM', 'ORDUPD', 'ORDAFR'))
   AND fac_tracking_refkey = 12614;

-- Tracking melding 26506 verwijderen.
DELETE
  FROM fac_tracking ft
 WHERE ft.fac_srtnotificatie_key IN (SELECT fsn.fac_srtnotificatie_key FROM fac_srtnotificatie fsn WHERE fsn.fac_srtnotificatie_code IN ('MLDNEW', 'MLDBEH', 'MLDACP', 'MLDAFM'))
   AND fac_tracking_refkey = 27252;

-- Tracking inspectie verwijderen.
DELETE
  FROM fac_tracking ft
 WHERE ft.fac_srtnotificatie_key IN (SELECT fsn.fac_srtnotificatie_key FROM fac_srtnotificatie fsn WHERE fsn.fac_srtnotificatie_code IN ('INSCBE', 'INSCTU', 'INSCVE', 'INSCUP'))
   AND fac_tracking_refkey = 3102;

-- Taak aan melding gekoppeld verwijderen.
DELETE
  FROM mld_melding_object
 WHERE ins_deelsrtcontrole_key = 3102;

-- Opdracht 26506/1 verwijderen.
DELETE
  FROM mld_opdr
 WHERE mld_opdr_key = 12614
   AND mld_melding_key = 27252;

-- Melding 26506 verwijderen.
DELETE
  FROM mld_melding
 WHERE mld_melding_key = 27252;

-- Taak verwijderen.
DELETE
  FROM ins_deelsrtcontrole
 WHERE ins_deel_key = 7278
   AND ins_srtcontrole_key = 234
   AND ins_deelsrtcontrole_key = 3102;

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