--
-- $Id$
--
-- Aanpassen urenimport van AX naar SAP. Aanpassen personeelsnummers en opvoeren onbekende projecten.

DEFINE thisfile = 'LOGC#60115.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 ------

alter table logc_imp_uren_besteding add project_oms VARCHAR2(100);

alter table logc_imp_uren_besteding modify project VARCHAR2(30);

UPDATE prs_perslid SET prs_perslid_nr = '73100002' WHERE prs_perslid_nr = '574';
UPDATE prs_perslid SET prs_perslid_nr = '73100071' WHERE prs_perslid_nr = '585';
UPDATE prs_perslid SET prs_perslid_nr = '73100138' WHERE prs_perslid_nr = '592';
UPDATE prs_perslid SET prs_perslid_nr = '73100003' WHERE prs_perslid_nr = '575';
UPDATE prs_perslid SET prs_perslid_nr = '73100005' WHERE prs_perslid_nr = '577';
UPDATE prs_perslid SET prs_perslid_nr = '73100006' WHERE prs_perslid_nr = '578';
UPDATE prs_perslid SET prs_perslid_nr = '73100007' WHERE prs_perslid_nr = '579';
UPDATE prs_perslid SET prs_perslid_nr = '73100056' WHERE prs_perslid_nr = '587';
UPDATE prs_perslid SET prs_perslid_nr = '73100008' WHERE prs_perslid_nr = '580';
UPDATE prs_perslid SET prs_perslid_nr = '73100016' WHERE prs_perslid_nr = '582';
UPDATE prs_perslid SET prs_perslid_nr = '73100019' WHERE prs_perslid_nr = '583';
UPDATE prs_perslid SET prs_perslid_nr = '73100013' WHERE prs_perslid_nr = '581';
UPDATE prs_perslid SET prs_perslid_nr = '73100094' WHERE prs_perslid_nr = '593';
UPDATE prs_perslid SET prs_perslid_nr = '73100083' WHERE prs_perslid_nr = '590';
UPDATE prs_perslid SET prs_perslid_nr = '73100042' WHERE prs_perslid_nr = '589';
UPDATE prs_perslid SET prs_perslid_nr = '73100057' WHERE prs_perslid_nr = '588';
UPDATE prs_perslid SET prs_perslid_nr = '73100137' WHERE prs_perslid_nr = '591';
UPDATE prs_perslid SET prs_perslid_nr = '73100020' WHERE prs_perslid_nr = '584';

UPDATE logc_imp_uren_besteding SET werknemer = '73100002' WHERE werknemer = '574';
UPDATE logc_imp_uren_besteding SET werknemer = '73100071' WHERE werknemer = '585';
UPDATE logc_imp_uren_besteding SET werknemer = '73100138' WHERE werknemer = '592';
UPDATE logc_imp_uren_besteding SET werknemer = '73100003' WHERE werknemer = '575';
UPDATE logc_imp_uren_besteding SET werknemer = '73100005' WHERE werknemer = '577';
UPDATE logc_imp_uren_besteding SET werknemer = '73100006' WHERE werknemer = '578';
UPDATE logc_imp_uren_besteding SET werknemer = '73100007' WHERE werknemer = '579';
UPDATE logc_imp_uren_besteding SET werknemer = '73100056' WHERE werknemer = '587';
UPDATE logc_imp_uren_besteding SET werknemer = '73100008' WHERE werknemer = '580';
UPDATE logc_imp_uren_besteding SET werknemer = '73100016' WHERE werknemer = '582';
UPDATE logc_imp_uren_besteding SET werknemer = '73100019' WHERE werknemer = '583';
UPDATE logc_imp_uren_besteding SET werknemer = '73100013' WHERE werknemer = '581';
UPDATE logc_imp_uren_besteding SET werknemer = '73100094' WHERE werknemer = '593';
UPDATE logc_imp_uren_besteding SET werknemer = '73100083' WHERE werknemer = '590';
UPDATE logc_imp_uren_besteding SET werknemer = '73100042' WHERE werknemer = '589';
UPDATE logc_imp_uren_besteding SET werknemer = '73100057' WHERE werknemer = '588';
UPDATE logc_imp_uren_besteding SET werknemer = '73100137' WHERE werknemer = '591';
UPDATE logc_imp_uren_besteding SET werknemer = '73100020' WHERE werknemer = '584';

INSERT INTO prs_kostenplaats (prs_kostenplaats_nr,
                              prs_kostenplaats_omschrijving,
                              prs_kostenplaats_module,
                              prs_kostenplaats_begin,
                              prs_kostenplaatsgrp_key)
    SELECT DISTINCT project,
                    project_oms,
                    'PRS',
                    SYSDATE,
                    1
      FROM logc_imp_uren_besteding
     WHERE     project_oms IS NOT NULL
           AND NOT EXISTS
                   (SELECT prs_kostenplaats_key
                      FROM prs_kostenplaats
                     WHERE prs_kostenplaats_nr = project);

UPDATE prs_kostenplaats
   SET prs_kostenplaats_omschrijving =
           (SELECT MAX (project_oms)
              FROM logc_imp_uren_besteding
             WHERE project = prs_kostenplaats_nr)
 WHERE EXISTS
           (SELECT project
              FROM logc_imp_uren_besteding
             WHERE project = prs_kostenplaats_nr);

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