--
-- $Id$
--
-- Maak contactpersoon aan obv ingelezen prs_import

DEFINE thisfile = 'LOGC#59736.SQL'
DEFINE dbuser   = '^LOGC'

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

INSERT INTO prs_contactpersoon (prs_contactpersoon_naam,
                                prs_contactpersoon_voornaam,
                                prs_contactpersoon_voorletters,
                                prs_contactpersoon_titel,
                                prs_contactpersoon_telefoon_1,
                                prs_contactpersoon_telefoon_2,
                                prs_contactpersoon_email,
                                prs_contactpersoon_functie,
                                prs_contactpersoon_opmerking,
                                prs_bedrijf_key)
   SELECT prs_perslid_naam,
          prs_perslid_voornaam,
          prs_perslid_voorletters,
          prs_perslid_titel,
          prs_perslid_telefoonnr,
          prs_perslid_mobiel,
          prs_perslid_email,
          prs_srtperslid_omschrijving,
          prs_perslid_nr,
          (SELECT prs_bedrijf_key
             FROM prs_bedrijf
            WHERE prs_overeenkomst_nr = prs_afdeling_naam
                  AND prs_bedrijf_verwijder IS NULL)
     FROM fac_imp_perslid;

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