-- Customer specific once-script BLCC_SSC.
--
-- (c) 2016  Facilitor B.V.
--
-- Support: +31 53 4800700
SET ECHO ON
SPOOL xBLCC_SCC.lst
SET DEFINE OFF

-- Pseudo-user tbv. koppeling met alle SSC-functionaliteit; dezelfde module,
-- afdeling en functie als _FACILITOR (= 4)!
INSERT INTO prs_perslid (prs_perslid_module,
                         prs_srtperslid_key,
                         prs_afdeling_key,
                         prs_perslid_naam,
                         prs_perslid_voornaam,
                         prs_perslid_nr,
                         prs_perslid_oslogin,
                         prs_perslid_systeemadres,
                         prs_perslid_flags,
                         prs_perslid_apikey)
   SELECT   p.prs_perslid_module,
            p.prs_srtperslid_key,
            p.prs_afdeling_key,
            'API-user tbv. SSC',
            '-',
            'NIET WEG!!!',
            '_SSC',
            NULL,
            5,
            'QlElHamwvNMwIIivQbcSASSJAmBynFws'
     FROM   prs_perslid p
    WHERE   p.prs_perslid_key = 4;

SET SERVEROUTPUT ON size 1000000;

/* Formatted on 27-5-2016 13:24:42 (QP5 v5.136.908.31019) */
DECLARE
   c_hidden_ruimte_key   NUMBER := 2183;            -- Fictieve BCC-ruimte '_'
   oracle_err_num        NUMBER;
   oracle_err_mes        VARCHAR2 (255);
   v_errormsg            VARCHAR2 (1024);
   v_inserts             NUMBER := 0;
BEGIN
   -- Loop over alle personen en plaats deze op fictieve BCC-ruimte!
   FOR rc IN (  SELECT p.prs_perslid_key
                  FROM prs_v_aanwezigperslid p
                 WHERE NOT EXISTS (SELECT 1
                                     FROM prs_perslidwerkplek
                                    WHERE prs_perslid_key = p.prs_perslid_key)
              ORDER BY p.prs_perslid_key)
   LOOP
      BEGIN
         PRS.movetoruimte (rc.prs_perslid_key, c_hidden_ruimte_key, NULL);
         v_inserts := v_inserts + 1;
      EXCEPTION
         WHEN OTHERS
         THEN
            oracle_err_num := SQLCODE;
            oracle_err_mes := SUBSTR (SQLERRM, 1, 200);
            v_errormsg :=
                  '['
               || TO_CHAR (rc.prs_perslid_key)
               || '] '
               || '(ORACLE error '
               || oracle_err_num
               || '/'
               || oracle_err_mes
               || ')';
            DBMS_OUTPUT.PUT_LINE ('Fout toekennen WP: ' || v_errormsg);
      END;
   END LOOP;

   DBMS_OUTPUT.PUT_LINE ('#WPs toegekend: ' || TO_CHAR (v_inserts));
END;
/

COMMIT;
BEGIN adm.systrackscriptId('$Id$'); END;
/
SPOOL OFF
