-- PCHD
-- maak structuur aan in temp folder: xcopy /T  d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\CNT .
-- met onderstaande scripts wordt de batchfile aangemaakt om de geldige bestanden te kopieeren naar de tijdelijke folder
-- vervolgens met synchronise directories de overbodige bestanden uit PCHD verwijderen.
SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\MLD\M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || ' M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
  FROM mld_melding m
UNION ALL
SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\MLD\O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || ' O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
  FROM mld_opdr o;

SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\CNT\C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || ' C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
  FROM cnt_contract c
 WHERE cnt_contract_verwijder IS NULL;
 
-- PCHH
SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHH\flexfiles\MLD\M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || ' M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
  FROM mld_melding m
UNION ALL
SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHH\flexfiles\MLD\O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || ' O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
  FROM mld_opdr o;



SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHH\flexfiles\CNT\C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || ' C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
  FROM cnt_contract c
 WHERE cnt_contract_verwijder IS NULL;
 
-- PCHP
SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHP\flexfiles\MLD\M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || ' M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
  FROM mld_melding m
UNION ALL
SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHP\flexfiles\MLD\O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || ' O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
  FROM mld_opdr o;

SELECT    'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHP\flexfiles\CNT\C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || ' C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
  FROM cnt_contract c
 WHERE cnt_contract_verwijder IS NULL;
 
 -- PCHS
 -- Voor Schiphol en IJsbaan waren de flexfiles nog niet gekopieerd. Daarom worden hier de bestanden uit de PCHD
 -- omgeving overgeheveld.
 SELECT    'mkdir  M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || CHR (10)
       || 'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\MLD\M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || ' M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
  FROM mld_melding m
UNION ALL
SELECT    'mkdir  O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || CHR (10)
       || 'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\MLD\O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || ' O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
  FROM mld_opdr o;

SELECT    'mkdir  C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || CHR (10)
       || 'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\CNT\C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || ' C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
  FROM cnt_contract c
 WHERE cnt_contract_verwijder IS NULL;
 
-- PCHY
SELECT    'mkdir  M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || CHR (10)
       || 'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHY\flexfiles\MLD\M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
       || ' M'
       || SUBSTR (LPAD (m.mld_melding_key, 7, '0'), 1, 4)
       || '___\M'
       || m.mld_melding_key
  FROM mld_melding m
UNION ALL
SELECT    'mkdir  O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || CHR (10)
       || 'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHY\flexfiles\MLD\O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
       || ' O'
       || SUBSTR (LPAD (o.mld_opdr_key, 7, '0'), 1, 4)
       || '___\O'
       || o.mld_opdr_key
  FROM mld_opdr o;

SELECT    'mkdir  C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || CHR (10)
       || 'xcopy /S d:\Apps\Facilitor\Fplace5i\CUST\PCHD\flexfiles\CNT\C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
       || ' C'
       || SUBSTR (LPAD (c.cnt_contract_key, 7, '0'), 1, 4)
       || '___\C'
       || c.cnt_contract_key
  FROM cnt_contract c
 WHERE cnt_contract_verwijder IS NULL;