Showing posts with label HRMS. Show all posts
Showing posts with label HRMS. Show all posts

Monday, July 12, 2021

Machine Data

 SELECT 

         OTL.EMPLOYEE_ID ERP_NUMBER,

         PAPF.FULL_NAME  EMPLOYEE_NAME,

         TO_CHAR(OTL.ATTD_DATE, 'DD-MON-YYYY') ATTD_DATE,

--         OTL.ATTD_TIME,

         TO_CHAR(OTL.ATTD_TIME, 'HH24:MI:SS AM') ATTD_TIME,

--         (SELECT NG_ORGANIZATION_TYPE (PAAF.ORGANIZATION_ID)

--          FROM DUAL) ORG_TYPE,

--         (SELECT NG_ORGANIZATION_NAME (PAAF.ORGANIZATION_ID)

--          FROM DUAL) ORG_NAME,

         (SELECT NG_DESIGNATION (PAAF.POSITION_ID)

          FROM DUAL) DESIGNATION,

         REGEXP_SUBSTR (HAOU.NAME, '(\S*)(\.)') DEPARTMENT,

         HAOU.NAME UNIT_NAME

--         HAOU.ORGANIZATION_ID

FROM 

        PER_ALL_PEOPLE_F            PAPF 

       ,PER_ALL_ASSIGNMENTS_F       PAAF    

       ,TEMP_OTL_MACHINE_DATA       OTL

       ,HR_ALL_ORGANIZATION_UNITS   HAOU

WHERE 

     1 = 1

AND  PAAF.PERSON_ID       =     PAPF.PERSON_ID

AND  PAPF.EMPLOYEE_NUMBER =     OTL.EMPLOYEE_ID

AND SYSDATE BETWEEN PAAF.EFFECTIVE_START_DATE   AND PAAF.EFFECTIVE_END_DATE 

AND SYSDATE BETWEEN PAPF.EFFECTIVE_START_DATE   AND PAPF.EFFECTIVE_END_DATE 

AND PAAF.ORGANIZATION_ID    =   HAOU.ORGANIZATION_ID

--AND OTL.EMPLOYEE_ID       =   4328

AND OTL.UNIT_NAME = 'Gulshan Office Chairman House Unit 2'

AND OTL.ATTD_DATE between '06-jan-2021' and '06-jan-2021'

--AND OTL.ATTD_DATE = '10-dec-2020'

ORDER BY  DEPARTMENT, ERP_NUMBER

Delete OTL Timecard

  set serveroutput on;

declare



CURSOR building_block_id_csr (c_resource_id NUMBER, 

                     c_start_time DATE,

                     c_stop_time DATE) IS

select time_building_block_id 

  from hxc_time_building_blocks 

start with resource_id = c_resource_id 

       and trunc(start_time) = c_start_time

       and trunc(stop_time) = c_stop_time

connect by prior time_building_block_id = parent_building_block_id

        and prior object_version_number = parent_building_block_ovn

order by time_building_block_id;


CURSOR app_period_csr (c_resource_id NUMBER, 

                   c_start_time DATE,

                   c_stop_time DATE) IS

  select time_building_block_id

    from hxc_time_building_blocks

   where scope = 'APPLICATION_PERIOD'

     and resource_id in (c_resource_id) 

     and trunc(start_time) = c_start_time

     and trunc(stop_time) = c_stop_time ; 

     

TYPE numtab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;

tbb_id_tab numtab;

app_period_tab numtab;


l_retrieval_count NUMBER;

l_resource_id  NUMBER;

l_start_time DATE;

l_stop_time DATE;

l_item_key wf_items.item_key%TYPE;


begin


  dbms_output.put_line('Start processing...');

  

  l_resource_id := 17555; /* This is person id*/

  l_start_time := '31-OCT-2020';

  l_stop_time := '31-OCT-2020';

  

  /* l_resource_id := &1; 

  l_start_time := &2;

  l_stop_time := &3; */


  DELETE 

  FROM    hxc_transaction_details

  WHERE   time_building_block_id IN

        (

        SELECT  time_building_block_id

        FROM    hxc_latest_details

        WHERE   resource_id IN (l_resource_id)

        AND     trunc (start_time) = l_start_time

        );

        

  select count(*) 

    into l_retrieval_count

    from hxc_transactions ht,

         hxc_transaction_details htd

   where ht.transaction_id = htd.transaction_id

     and ht.type = 'RETRIEVAL'

     and ht.status = 'SUCCESS'

     and htd.status = 'SUCCESS'

     and htd.time_building_block_id in

       (select time_building_block_id from hxc_latest_details

         where resource_id in (l_resource_id) 

           and trunc(start_time) = l_start_time) ;


  dbms_output.put_line('l_retrieval_count = '||l_retrieval_count);

  

 IF (l_retrieval_count <> 0) THEN

   dbms_output.put_line('**********************************************************');

   dbms_output.put_line('This timecard has been successfully retrieved atleast once');

   dbms_output.put_line('DO NOT USE THIS SCRIPT TO DELETE DATA FOR THIS TIMECARD');

   dbms_output.put_line('Exiting .....');

   dbms_output.put_line('**********************************************************');

 

 

 ELSE

 

  OPEN app_period_csr (l_resource_id, l_start_time, l_stop_time);

  FETCH app_period_csr BULK COLLECT INTO 

        app_period_tab;

  CLOSE app_period_csr;  

  

  OPEN building_block_id_csr (l_resource_id, l_start_time, l_stop_time);

  FETCH building_block_id_csr BULK COLLECT INTO 

        tbb_id_tab;

  CLOSE building_block_id_csr;

  

    

  dbms_output.put_line('tbb_id_tab.COUNT = '||tbb_id_tab.COUNT);    


  -- Process TIMECARD, DAY, DETAIL scope building block ids

  IF (tbb_id_tab.COUNT > 0) THEN

    

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE FROM hxc_time_building_blocks

       WHERE time_building_block_id = tbb_id_tab(i);

       

    dbms_output.put_line('Deleted from hxc_time_building_blocks... ');     

       

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE FROM hxc_time_attributes

       WHERE time_attribute_id IN

           (select time_attribute_id from hxc_time_attribute_usages

             where time_building_block_id = tbb_id_tab(i));


    dbms_output.put_line('Deleted from hxc_time_attributes... ');                  

             

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE FROM hxc_time_attribute_usages

       WHERE time_building_block_id = tbb_id_tab(i);

       

    dbms_output.put_line('Deleted from hxc_time_attribute_usages... ');            

             

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from hxc_tc_ap_links

       WHERE timecard_id = tbb_id_tab(i);


    dbms_output.put_line('Deleted from hxc_tc_ap_links... ');     

    

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE FROM hxc_latest_details

       WHERE time_building_block_id = tbb_id_tab(i);       


    dbms_output.put_line('Deleted from hxc_latest_details... ');     

    

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE FROM hxc_ap_detail_links

       WHERE time_building_block_id = tbb_id_tab(i);   

       

    dbms_output.put_line('Deleted from hxc_ap_detail_links... ');     

    

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from hxc_transactions

       WHERE transaction_id in

            (select transaction_id from hxc_transaction_details

              where time_building_block_id = tbb_id_tab(i));


    dbms_output.put_line('Deleted from hxc_transactions... ');     

    

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from hxc_transaction_details

       WHERE time_building_block_id = tbb_id_tab(i);    

       

    dbms_output.put_line('Deleted from hxc_transaction_details... ');         


     FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from HXC_PA_LATEST_DETAILS 

       WHERE time_building_block_id = tbb_id_tab(i);    

       

     dbms_output.put_line('Deleted from HXC_PA_LATEST_DETAILS  ');  


     FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from HXC_PAY_LATEST_DETAILS

       WHERE time_building_block_id = tbb_id_tab(i);    

       

     dbms_output.put_line('Deleted from HXC_PAY_LATEST_DETAILS ');  

  

     FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from HXC_RET_PA_LATEST_DETAILS

       WHERE time_building_block_id = tbb_id_tab(i);  

      dbms_output.put_line('Deleted from HXC_RET_PA_LATEST_DETAILS ');  


     FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from HXC_RET_PAY_LATEST_DETAILS 

       WHERE time_building_block_id = tbb_id_tab(i);  

   dbms_output.put_line('Deleted from HXC_RET_PAY_LATEST_DETAILS  ');  


   

    

   BEGIN

    -- abort the workflows

    FOR i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

    LOOP

      

      SELECT approval_item_key 

        INTO l_item_key

        FROM hxc_timecard_summary

       WHERE timecard_id = tbb_id_tab(i);

       

      wf_engine.abortprocess('HXCEMP', l_item_key);

      wf_purge.items('HXCEMP',l_item_key,SYSDATE,FALSE);

      

    END LOOP;

   EXCEPTION 

        when NO_DATA_FOUND then

         DBMS_OUTPUT.PUT_LINE('There is no workflow found');

       when OTHERS then

         DBMS_OUTPUT.PUT_LINE('Workflow not found');

  END;


   

    

    FORALL i IN tbb_id_tab.FIRST..tbb_id_tab.LAST 

      DELETE from hxc_timecard_summary

       WHERE timecard_id = tbb_id_tab(i);  

       

    dbms_output.put_line('Deleted from hxc_timecard_summary... ');         

       

  END IF;


  dbms_output.put_line('Process the application periods... ');     

    

-- Process the application period scope building block ids


  dbms_output.put_line('app_period_tab.COUNT = '||app_period_tab.COUNT);  

    

  IF (app_period_tab.COUNT > 0) THEN

 

    -- abort the workflows

  BEGIN

    FOR i IN app_period_tab.FIRST..app_period_tab.LAST 

    LOOP

      

      SELECT approval_item_key 

        INTO l_item_key

        FROM hxc_app_period_summary

       WHERE application_period_id = app_period_tab(i);

       

      wf_engine.abortprocess('HXCEMP', l_item_key);

      wf_purge.items('HXCEMP',l_item_key,SYSDATE,FALSE);

      

    END LOOP;

    EXCEPTION 

        when NO_DATA_FOUND then

         DBMS_OUTPUT.PUT_LINE('There is no workflow found1');

       when OTHERS then

         DBMS_OUTPUT.PUT_LINE('Workflow not found1');

  END;


    FORALL i IN app_period_tab.FIRST..app_period_tab.LAST 

      DELETE FROM hxc_app_period_summary

       WHERE application_period_id = app_period_tab(i);       

       

    dbms_output.put_line('Deleted from hxc_app_period_summary... ');         

       

  END IF;


 END IF;



  

end;

/