-- Customer specific once-script IVET13.
--
-- (c) 2013 SG|facilitor bv
-- $Revision$
-- $Id$
--
-- Support: +31 53 4800700
SET ECHO ON
SPOOL xivet13.lst
SET DEFINE OFF

SELECT mld_melding_key,
       mld_melding_datum,
       mld_melding_einddatum,
       mld.geteinddatum (
          m.mld_melding_datum,
          m.mld_stdmelding_key,
          m.mld_melding_spoed,
          (SELECT MAX (alg_gebouw_key)
             FROM alg_v_allonroerendgoed
            WHERE alg_onroerendgoed_keys = m.mld_alg_onroerendgoed_keys
                  AND alg_type = 'G'))
          nieuw
  FROM mld_melding m
 WHERE (m.mld_melding_einddatum < m.mld_melding_datum
        AND TO_CHAR (m.mld_melding_einddatum, 'HH24:MI') != '00:00')
       OR (TO_DATE (m.mld_melding_einddatum, 'DD-MM-YYYY') <=
              TO_DATE (m.mld_melding_datum, 'DD-MM-YYYY')
           AND TO_CHAR (m.mld_melding_einddatum, 'HH24:MI') = '00:00');

-- IVET#25802: Overschrijding acceptatietijden en doorlooptijden postkamer.
UPDATE mld_melding m
   SET m.mld_melding_einddatum =
         mld.geteinddatum (m.mld_melding_datum,
                           m.mld_stdmelding_key,
                           m.mld_melding_spoed,
                           (SELECT MAX (alg_gebouw_key)
                              FROM alg_v_allonroerendgoed
                             WHERE alg_onroerendgoed_keys = m.mld_alg_onroerendgoed_keys
                               AND alg_type = 'G'))
   WHERE (m.mld_melding_einddatum < m.mld_melding_datum
          AND TO_CHAR (m.mld_melding_einddatum, 'HH24:MI') != '00:00')
      OR (TO_DATE (m.mld_melding_einddatum, 'DD-MM-YYYY') <= TO_DATE (m.mld_melding_datum, 'DD-MM-YYYY')
          AND TO_CHAR (m.mld_melding_einddatum, 'HH24:MI') = '00:00');

COMMIT;

BEGIN adm.systrackscript('$Workfile: ivet13.sql $', '$Revision$', 1); END;
/
SPOOL OFF
