Advertisement
odinsride

Code Critique 1

Aug 22nd, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 36.95 KB | None | 0 0
  1. CREATE OR REPLACE PACKAGE BODY xx_hr_jobs_pos_time_info AS
  2.  
  3.   -- Global Constants for Output Destination
  4.   C_LOG                CONSTANT VARCHAR2(1) := 'L';       -- log only
  5.   C_OUTPUT             CONSTANT VARCHAR2(1) := 'O';       -- output only
  6.   C_OUTPUT_LOG         CONSTANT VARCHAR2(2) := 'OL';      -- output and log
  7.  
  8.   -- Statistics Variables
  9.   g_record_count       NUMBER := 0;
  10.   g_records_skipped    NUMBER := 0;
  11.   g_time_created       NUMBER := 0;
  12.   g_time_updated       NUMBER := 0;
  13.   g_time_end_dated     NUMBER := 0;
  14.   g_time_errors        NUMBER := 0;
  15.  
  16.   -- Exceptions for Rotation Plan and Earning Policy
  17.   rotation_plan_error   EXCEPTION;
  18.   earning_policy_error  EXCEPTION;
  19.   init_time_info_error  EXCEPTION;
  20.  
  21.   CURSOR gc_pos IS
  22.     SELECT pd.ROWID row_id,
  23.            pd.assign_id,
  24.            pd.effectivedate,
  25.            pd.employeenumber,
  26.            pd.employeelastname,
  27.            pd.employeefirstname,
  28.            pd.payroll,
  29.            pd.flsa,
  30.            pd.numberhoursperweek,
  31.            pd.organizationname,
  32.            paa.assignment_id,
  33.            paa.assignment_number,
  34.            paa.effective_start_date,
  35.            paa.effective_end_date,
  36.            ppb.name pay_basis_name,
  37.            ppg.segment5
  38.       FROM xx_peopleadmin_position_data pd,
  39.            per_all_assignments_f paa,
  40.            per_pay_bases ppb,
  41.            pay_people_groups ppg
  42.      WHERE pd.assign_id = paa.assignment_id (+)
  43.        AND pd.effectivedate
  44.              BETWEEN paa.effective_start_date (+) AND paa.effective_end_date (+)
  45.        AND paa.pay_basis_id = ppb.pay_basis_id (+)
  46.        AND paa.people_group_id = ppg.people_group_id (+)
  47.        AND pd.record_status           = 'S'
  48.        AND pd.updateincumbent         = 'Yes'
  49.        AND NVL(pd.time_info_chg,'Y') != 'N'
  50.      ORDER BY pd.employeelastname;
  51.          
  52. /******************************************************************************
  53.   Create Procedure display_log
  54. ******************************************************************************/
  55. PROCEDURE display_log
  56.   (p_description     IN VARCHAR2)
  57. IS
  58. BEGIN
  59.  
  60.   fnd_file.put_line(fnd_file.LOG, p_description);
  61.  
  62. EXCEPTION
  63.   WHEN OTHERS THEN
  64.     display_log('Error in display_log: ' || SQLERRM);
  65.    
  66. END display_log;
  67.  
  68.  
  69. /******************************************************************************
  70.   Create Procedure display_output
  71. ******************************************************************************/
  72. PROCEDURE display_output
  73.   (p_description     IN VARCHAR2)
  74. IS
  75. BEGIN
  76.  
  77.   fnd_file.put_line(fnd_file.OUTPUT, p_description);
  78.  
  79. EXCEPTION
  80.   WHEN OTHERS THEN
  81.     display_log('Error in display_output: ' || SQLERRM);
  82.    
  83. END display_output;
  84.  
  85.  
  86. /******************************************************************************
  87.   Create Procedure print_header
  88. ******************************************************************************/
  89. PROCEDURE print_header
  90. IS
  91.  
  92.   -- Variables for out parameters of GET_CONC_REQUEST_DETAIL_VALUES below
  93.   l_conc_request_id          NUMBER         := NULL;
  94.   l_last_ddl_time            DATE;
  95.   l_conc_req_name            VARCHAR2(1000) := NULL;
  96.   l_conc_description         VARCHAR2(1000) := NULL;
  97.   l_request_start_date       DATE;
  98.   l_request_completion_date  DATE;
  99.   l_duration                 VARCHAR2(2000) := NULL;
  100.   l_completion_text          VARCHAR2(2000) := NULL;
  101.   l_oracle_user              VARCHAR2(2000) := NULL;
  102.   l_responsibility_name      VARCHAR2(2000) := NULL;
  103.  
  104. BEGIN
  105.  
  106.    xx_common_pkg.GET_CONC_REQUEST_DETAIL_VALUES
  107.                     (  p_package_name              => 'XX_HR_JOBS_POS_TIME_INFO',
  108.                        p_conc_request_id           => l_conc_request_id,
  109.                        p_last_ddl_time             => l_last_ddl_time,
  110.                        p_conc_program_name         => l_conc_req_name,
  111.                        p_conc_description          => l_conc_description,
  112.                        p_request_start_date        => l_request_start_date,
  113.                        p_request_completion_date   => l_request_completion_date,
  114.                        p_duration                  => l_duration,
  115.                        p_completion_text           => l_completion_text,
  116.                        p_oracle_user               => l_oracle_user,
  117.                        p_responsibility_name       => l_responsibility_name
  118.                     );
  119.  
  120.   /*   Header Information    */
  121.  
  122.   display_output('---------------------------------------------------------------------------------------------------------------------------------');
  123.   --  Lines removed for confidentiality
  124.   display_output('                                                       For '||TO_CHAR(SYSDATE,'DD-MON-RRRR')                                      );
  125.   display_output('                                         Request ID: ' || l_conc_request_id || '   Submitted By: ' || l_oracle_user);
  126.   display_output('---------------------------------------------------------------------------------------------------------------------------------');
  127.   display_output('');
  128.   display_output('Date of Process : '|| TO_CHAR(SYSDATE,'DD-MON-RRRR HH:MI:SS'));
  129.   display_output('');
  130.  
  131.   display_output(RPAD('Employee Name', 35) || RPAD('Assignment', 20) ||  'Message');
  132.   display_output('---------------------------------- ------------------- --------------------------------------------------------------------------');
  133.  
  134.   display_log('---------------------------------------------------------------------------------------------------------------------------------');
  135.   -- Lines removed for confidentiality
  136.   display_log('                                                       For '||TO_CHAR(SYSDATE,'DD-MON-RRRR')                                      );
  137.   display_log('                           Compile Date: ' || l_last_ddl_time || '   Request ID: ' || l_conc_request_id || '   Submitted By: ' || l_oracle_user              );
  138.   display_log('---------------------------------------------------------------------------------------------------------------------------------');
  139.   display_log('');
  140.   display_log('Date of Process : '|| TO_CHAR(SYSDATE,'DD-MON-RRRR HH:MI:SS'));
  141.   display_log('');
  142.  
  143. END print_header;
  144.  
  145.  
  146. /******************************************************************************
  147.   Create Procedure print_record
  148. ******************************************************************************/
  149. PROCEDURE print_record
  150.   (p_pos            IN  gc_pos%ROWTYPE
  151.   ,p_msg            IN  VARCHAR2
  152.   ,p_print_target   IN  VARCHAR2)
  153. IS
  154.  
  155.   l_record             VARCHAR2(1000);
  156.  
  157. BEGIN
  158.  
  159.   -- Built record for output
  160.   l_record :=    RPAD(   p_pos.employeelastname
  161.                       || ', '
  162.                       || p_pos.employeefirstname, 35)
  163.               || RPAD(p_pos.assignment_number, 20)  
  164.               || p_msg;
  165.  
  166.   IF p_print_target = C_LOG THEN
  167.     display_log(p_msg);
  168.   ELSIF p_print_target = C_OUTPUT THEN
  169.     display_output(l_record);
  170.   ELSIF p_print_target = C_OUTPUT_LOG THEN
  171.     display_log(p_msg);
  172.     display_output(l_record);
  173.   ELSE
  174.     display_log('PRINT_RECORD: Invalid Print Target');
  175.   END IF;
  176.  
  177. END print_record;
  178.  
  179.  
  180. /******************************************************************************
  181.   Create Procedure print_log_header
  182. ******************************************************************************/
  183. PROCEDURE print_log_header
  184.   (p_pos            IN  gc_pos%ROWTYPE)
  185. IS
  186. BEGIN
  187.  
  188.   -- Print detailed record information in the log
  189.   display_log(' ');
  190.   display_log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
  191.   display_log('  Record #: ' || g_record_count || ' Processing Salary and Time for: '||p_pos.employeefirstname||' '||p_pos.employeelastname);
  192.   display_log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
  193.   display_log('  ');
  194.   display_log('Cursor Record Values');
  195.   display_log('-----------------------------------------------');
  196.   display_log('pd.assign_id             : '|| p_pos.assign_id);  
  197.   display_log('pd.effectivedate         : '|| TO_CHAR(p_pos.effectivedate, 'DD-MON-YYYY'));
  198.   display_log('pd.employeenumber        : '|| p_pos.employeenumber);
  199.   display_log('pd.employeelastname      : '|| p_pos.employeelastname);
  200.   display_log('pd.employeefirstname     : '|| p_pos.employeefirstname);
  201.   display_log('pd.flsa                  : '|| p_pos.flsa);
  202.   display_log('pd.numberhoursperweek    : '|| p_pos.numberhoursperweek);
  203.   display_log('pd.organizationname      : '|| p_pos.organizationname);
  204.   display_log('pd.payroll               : '|| p_pos.payroll);
  205.   display_log('paa.assignment_id        : '|| p_pos.assignment_id);
  206.   display_log('paa.assignment_number    : '|| p_pos.assignment_number);
  207.   display_log('paa.effective_start_date : '|| TO_CHAR(p_pos.effective_start_date, 'DD-MON-YYYY'));
  208.   display_log('paa.effective_end_date   : '|| TO_CHAR(p_pos.effective_end_date, 'DD-MON-YYYY'));
  209.   display_log('ppb.pay_basis_name       : '|| p_pos.pay_basis_name);
  210.   display_log('ppg.segment5             : '|| p_pos.segment5);
  211.   display_log('  ');
  212.  
  213. END print_log_header;
  214.  
  215.  
  216. /******************************************************************************
  217.   Create Procedure print_log_footer
  218. ******************************************************************************/
  219. PROCEDURE print_log_footer
  220. IS
  221. BEGIN
  222.  
  223.   display_log('  ');
  224.   display_log('++++++++++++++++++++++++++++++++++++++++++++++ End of record +++++++++++++++++++++++++++++++++++++++++++++++++++++');
  225.   display_log('  ');
  226.  
  227. END print_log_footer;
  228.  
  229.  
  230. /******************************************************************************
  231.   Create Procedure print_statistics
  232. ******************************************************************************/
  233. PROCEDURE print_statistics
  234. IS
  235. BEGIN
  236.  
  237.   IF g_record_count = 0 THEN
  238.     display_output('     - No records were processed -     ');
  239.     display_log   ('     - No records were processed -     ');
  240.   END IF;  
  241.  
  242.   display_output(' ');
  243.   display_output('---------------------------------------------------------------------------------------------------------------------------------');
  244.   display_output('                                       Position Time Information Interface - Statistics                                          ');
  245.   display_output('---------------------------------------------------------------------------------------------------------------------------------');
  246.   display_output(' ');
  247.   display_output('Total Number of Records Selected               : '|| TO_CHAR(g_record_count));
  248.   display_output('Total Number of Records Skipped                : '|| TO_CHAR(g_records_skipped));
  249.   display_output('Total Number of Records Errored                : '|| TO_CHAR(g_time_errors));
  250.   display_output('Total Number of Time Info Records Created      : '|| TO_CHAR(g_time_created));
  251.   display_output('Total Number of Time Info Records Updated      : '|| TO_CHAR(g_time_updated));
  252.   display_output('Total Number of Time Info Records End-Dated    : '|| TO_CHAR(g_time_end_dated));
  253.  
  254.   display_output(' ');
  255.   display_output('---------------------------------------------------------------------------------------------------------------------------------');
  256.   display_output(' ');
  257.   display_output('---------------------------------------------------------------------------------------------------------------------------------');
  258.  
  259.   display_log(' ');
  260.   display_log('---------------------------------------------------------------------------------------------------------------------------------');
  261.   display_log('                                          Position Time Information Interface - Statistics                                       ');
  262.   display_log('---------------------------------------------------------------------------------------------------------------------------------');
  263.   display_log(' ');
  264.   display_log('Total Number of Records Selected               : '|| TO_CHAR(g_record_count));
  265.   display_log('Total Number of Records Skipped                : '|| TO_CHAR(g_records_skipped));
  266.   display_log('Total Number of Records Errored                : '|| TO_CHAR(g_time_errors));
  267.   display_log('Total Number of Time Info Records Created      : '|| TO_CHAR(g_time_created));
  268.   display_log('Total Number of Time Info Records Updated      : '|| TO_CHAR(g_time_updated));
  269.   display_log('Total Number of Time Info Records End-Dated    : '|| TO_CHAR(g_time_end_dated));
  270.  
  271.   display_log(' ');
  272.   display_log('---------------------------------------------------------------------------------------------------------------------------------');
  273.   display_log(' ');
  274.  
  275. END print_statistics;
  276.  
  277.  
  278. /******************************************************************************
  279.   Create Function get_rotation_plan
  280. ******************************************************************************/
  281. FUNCTION get_rotation_plan
  282.  (p_pos            IN  gc_pos%ROWTYPE)
  283. RETURN NUMBER
  284. IS
  285.  
  286.   l_rotation_plan    NUMBER;
  287.  
  288. BEGIN
  289.  
  290.   IF        p_pos.payroll        = 'Bi-weekly'
  291.         AND p_pos.pay_basis_name = 'Hourly Rate'
  292.   THEN
  293.    
  294.     l_rotation_plan := 121; -- wage
  295.  
  296.   ELSIF     p_pos.payroll        = 'Bi-weekly'
  297.         AND p_pos.pay_basis_name = 'Annual Salary'
  298.         AND p_pos.flsa           = 'Non Exempt'
  299.   THEN
  300.  
  301.     SELECT hrp.id
  302.       INTO l_rotation_plan
  303.       FROM hxt_rotation_plans hrp
  304.      WHERE hrp.name LIKE TRUNC(p_pos.numberhoursperweek) || '% hour week';
  305.      
  306.   END IF;
  307.  
  308.   IF l_rotation_plan IS NOT NULL THEN
  309.     display_log('GET_ROTATION_PLAN: Rotation plan found: ' || l_rotation_plan);
  310.   END IF;
  311.  
  312.   RETURN l_rotation_plan;
  313.  
  314. EXCEPTION
  315.   WHEN NO_DATA_FOUND THEN
  316.     display_log('GET_ROTATION_PLAN: Rotation plan not found from hxt_rotation_plans');
  317.     RAISE rotation_plan_error;
  318.    
  319.   WHEN TOO_MANY_ROWS THEN
  320.     display_log('GET_ROTATION_PLAN: Multiple Rotation plans found in hxt_rotation_plans.  Expected 1.');
  321.     l_rotation_plan := NULL;
  322.     RAISE rotation_plan_error;
  323.    
  324.   WHEN OTHERS THEN
  325.     display_log('GET_ROTATION_PLAN: Unhandled exception: ' || SQLERRM);
  326.     l_rotation_plan := NULL;
  327.     RAISE;
  328.        
  329. END get_rotation_plan;
  330.  
  331.  
  332. /******************************************************************************
  333.   Create Function get_earning_policy
  334. ******************************************************************************/
  335. FUNCTION get_earning_policy
  336.  (p_pos            IN  gc_pos%ROWTYPE)
  337. RETURN NUMBER
  338. IS
  339.  
  340.   l_earning_policy    NUMBER;
  341.  
  342. BEGIN
  343.  
  344.   IF        p_pos.payroll        = 'Bi-weekly'
  345.         AND p_pos.pay_basis_name = 'Hourly Rate'
  346.   THEN
  347.    
  348.     l_earning_policy := 86;             -- Wage Earning Policy
  349.  
  350.  
  351.   ELSIF     p_pos.payroll        = 'Bi-weekly'
  352.         AND p_pos.pay_basis_name = 'Annual Salary'
  353.         AND p_pos.flsa           = 'Non Exempt'
  354.   THEN
  355.  
  356.     IF p_pos.organizationname LIKE '%WS%' THEN
  357.      
  358.       l_earning_policy := 137295085;    -- XX Standard Earning Policy
  359.    
  360.     ELSE
  361.    
  362.       SELECT hep.id
  363.         INTO l_earning_policy
  364.         FROM hxt_earning_policies hep
  365.        WHERE hep.name LIKE TRUNC(p_pos.numberhoursperweek) || '% hour week';
  366.          
  367.     END IF;
  368.    
  369.   END IF;
  370.  
  371.   IF l_earning_policy IS NOT NULL THEN
  372.     display_log('GET_EARNING_POLICY: Earning policy found: ' || l_earning_policy);
  373.   END IF;
  374.  
  375.   RETURN l_earning_policy;
  376.  
  377. EXCEPTION
  378.   WHEN NO_DATA_FOUND THEN
  379.     display_log('GET_EARNING_POLICY: Earning Policy not found from hxt_earning_policies');
  380.     RAISE earning_policy_error;
  381.    
  382.   WHEN TOO_MANY_ROWS THEN
  383.     display_log('GET_EARNING_POLICY: Multiple Earning Policies found in hxt_earning_policies.  Expected 1.');
  384.     l_earning_policy := NULL;
  385.     RAISE earning_policy_error;
  386.    
  387.   WHEN OTHERS THEN
  388.     display_log('GET_EARNING_POLICY: Unhandled exception: ' || SQLERRM);
  389.     l_earning_policy := NULL;
  390.     RAISE;
  391.        
  392. END get_earning_policy;
  393.  
  394.  
  395. /******************************************************************************
  396.   Create Procedure init_time_info
  397. ******************************************************************************/
  398. PROCEDURE init_time_info
  399.   (p_pos                      IN  gc_pos%ROWTYPE
  400.   ,p_hxt_id                   OUT hxt_add_assign_info_f.id%TYPE
  401.   ,p_hxt_eff_start_date       OUT hxt_add_assign_info_f.effective_start_date%TYPE
  402.   ,p_hxt_eff_end_date         OUT hxt_add_assign_info_f.effective_end_date%TYPE
  403.   ,p_hep_name                 OUT hxt_earning_policies.name%TYPE
  404.   ,p_rotation_plan            OUT hxt_add_assign_info_f.rotation_plan%TYPE
  405.   ,p_earning_policy           OUT hxt_add_assign_info_f.earning_policy%TYPE
  406.   ,p_shift_diff_policy        OUT hxt_add_assign_info_f.shift_differential_policy%TYPE)
  407. IS
  408. BEGIN
  409.  
  410.   SELECT haai.id,
  411.          TRUNC(haai.effective_start_date),
  412.          TRUNC(haai.effective_end_date),
  413.          hep.name,
  414.          haai.rotation_plan,
  415.          haai.earning_policy,
  416.          haai.shift_differential_policy
  417.     INTO p_hxt_id,
  418.          p_hxt_eff_start_date,
  419.          p_hxt_eff_end_date,
  420.          p_hep_name,
  421.          p_rotation_plan,
  422.          p_earning_policy,
  423.          p_shift_diff_policy
  424.     FROM hxt_add_assign_info_f haai,
  425.          hxt_earning_policies hep
  426.    WHERE haai.earning_policy = hep.id (+)
  427.      AND haai.assignment_id = p_pos.assign_id
  428.      AND haai.effective_end_date = (SELECT MAX(t1.effective_end_date)
  429.                                       FROM hxt_add_assign_info_f t1
  430.                                      WHERE t1.assignment_id = haai.assignment_id);
  431.                                      
  432.   display_log('INIT_TIME_INFO: Retrieved the following values...');
  433.   display_log('INIT_TIME_INFO: hxt_id                    : ' || p_hxt_id);
  434.   display_log('INIT_TIME_INFO: hxt_eff_start_date        : ' || TO_CHAR(p_hxt_eff_start_date, 'DD-MON-YYYY'));
  435.   display_log('INIT_TIME_INFO: hxt_eff_end_date          : ' || TO_CHAR(p_hxt_eff_end_date, 'DD-MON-YYYY'));
  436.   display_log('INIT_TIME_INFO: hep_name                  : ' || p_hep_name);
  437.   display_log('INIT_TIME_INFO: rotation_plan             : ' || p_rotation_plan);
  438.   display_log('INIT_TIME_INFO: earning_policy            : ' || p_earning_policy);
  439.   display_log('INIT_TIME_INFO: shift_differential_policy : ' || p_shift_diff_policy);
  440.   display_log('');
  441.  
  442. EXCEPTION
  443.   WHEN NO_DATA_FOUND THEN
  444.     display_log('INIT_TIME_INFO: No time information exists in hxt_add_assign_info_f.  A new record will be created.');
  445.    
  446.   WHEN TOO_MANY_ROWS THEN
  447.     display_log('INIT_TIME_INFO: Too many rows encountered in hxt_add_assign_info_f. Expected 1.');
  448.     RAISE init_time_info_error;
  449.    
  450.   WHEN OTHERS THEN
  451.     display_log('INIT_TIME_INFO: Unhandled exception: ' || SQLERRM);
  452.     RAISE;
  453.    
  454. END init_time_info;
  455.  
  456.  
  457. /******************************************************************************
  458.   Create Procedure end_date_existing_time_info
  459. ******************************************************************************/
  460. PROCEDURE end_date_existing_time_info
  461.  (p_id                     IN    NUMBER
  462.  ,p_effective_start_date   IN    DATE
  463.  ,p_effective_end_date     IN    DATE
  464.  ,p_effective_date         IN    DATE
  465.  ,p_msg                    OUT   VARCHAR2
  466.  )
  467. IS
  468.  
  469.   l_update_count             NUMBER;
  470.  
  471. BEGIN
  472.  
  473.   display_log('End dating existing time info for haai.id = ' || p_id);
  474.                      
  475.   UPDATE hxt.hxt_add_assign_info_f haai
  476.      SET haai.effective_end_date = p_effective_date - 1
  477.    WHERE haai.id = p_id
  478.      AND haai.effective_start_date = p_effective_start_date
  479.      AND haai.effective_end_date   = p_effective_end_date;
  480.  
  481.   l_update_count := SQL%ROWCOUNT;
  482.  
  483.   IF l_update_count > 0 THEN
  484.     p_msg            := 'Success: End-dated existing time info. End date set to ' || TO_CHAR(p_effective_date - 1, 'DD-MON-YYYY');
  485.     g_time_end_dated := g_time_end_dated + 1;  
  486.   ELSE
  487.     p_msg         := 'ERROR: Tried to end date existing time info, but no rows were updated';
  488.     g_time_errors := g_time_errors + 1;      
  489.   END IF;
  490.  
  491. EXCEPTION
  492.   WHEN OTHERS THEN
  493.     p_msg       := 'ERROR: Time Information end dating not successful';
  494.     g_time_errors := g_time_errors + 1;
  495.     display_log('END_DATE_EXISTING_TIME_INFO: Unhandled exception: ' || SQLERRM);    
  496.        
  497. END end_date_existing_time_info;
  498.  
  499.  
  500. /******************************************************************************
  501.   Create Procedure create_otlr_add_assign_info
  502. ******************************************************************************/
  503. PROCEDURE create_otlr_add_assign_info
  504.  (p_pos                    IN    gc_pos%ROWTYPE
  505.  ,p_rotation_plan          IN    NUMBER
  506.  ,p_earning_policy         IN    NUMBER
  507.  ,p_msg                    OUT   VARCHAR2
  508.  )
  509. IS
  510.  
  511.   l_id                       NUMBER;
  512.  
  513. BEGIN
  514.  
  515.   -- Get new id
  516.   SELECT hxt_seqno.NEXTVAL
  517.     INTO l_id
  518.     FROM sys.dual;  
  519.  
  520.   display_log('CREATE_OTLR_ADD_ASSIGN_INFO: Calling hxt_gen_aai.create_otlr_add_assign_info');
  521.   display_log('CREATE_OTLR_ADD_ASSIGN_INFO: p_id (new)               : ' || l_id);
  522.   display_log('CREATE_OTLR_ADD_ASSIGN_INFO: p_effective_start_date   : ' || TO_CHAR(p_pos.effectivedate, 'DD-MON-YYYY'));
  523.   display_log('CREATE_OTLR_ADD_ASSIGN_INFO: p_assignment_id          : ' || p_pos.assign_id);
  524.   display_log('CREATE_OTLR_ADD_ASSIGN_INFO: p_rotation_plan          : ' || p_rotation_plan);
  525.   display_log('CREATE_OTLR_ADD_ASSIGN_INFO: p_earning_policy         : ' || p_earning_policy);
  526.  
  527.   hxt_gen_aai.create_otlr_add_assign_info
  528.     ( p_id                    => l_id
  529.     , p_effective_start_date  => p_pos.effectivedate
  530.     , p_assignment_id         => p_pos.assign_id
  531.     , p_autogen_hours_yn      => 'Y'
  532.     , p_rotation_plan         => p_rotation_plan
  533.     , p_earning_policy        => p_earning_policy
  534.     , p_created_by            => fnd_profile.VALUE('USER_ID')
  535.     , p_creation_date         => SYSDATE
  536.     , p_last_updated_by       => fnd_profile.VALUE('USER_ID')
  537.     , p_last_update_date      => SYSDATE
  538.     , p_last_update_login     => fnd_global.conc_login_id
  539.     );
  540.  
  541.   p_msg := 'Success: Created Time Information record';
  542.   g_time_created := g_time_created + 1;
  543.  
  544. EXCEPTION
  545.   WHEN OTHERS THEN
  546.     p_msg := 'ERROR: Time Information create not successful';
  547.     g_time_errors := g_time_errors + 1;
  548.     display_log('CREATE_OTLR_ADD_ASSIGN_INFO: Unhandled exception: ' || SQLERRM);
  549.        
  550. END create_otlr_add_assign_info;
  551.  
  552.  
  553. /******************************************************************************
  554.   Create Procedure update_otlr_add_assign_info
  555. ******************************************************************************/
  556. PROCEDURE update_otlr_add_assign_info
  557.  (p_pos                    IN    gc_pos%ROWTYPE
  558.  ,p_id                     IN    hxt_add_assign_info_f.id%TYPE
  559.  ,p_eff_start_date         IN    DATE
  560.  ,p_rotation_plan          IN    NUMBER
  561.  ,p_earning_policy         IN    NUMBER
  562.  ,p_msg                    OUT   VARCHAR2
  563.  )
  564. IS  
  565. BEGIN
  566.  
  567.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: Calling hxt_gen_aai.update_otlr_add_assign_info');
  568.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_id                     : ' || p_id);
  569.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_effective_date         : ' || TO_CHAR(p_pos.effectivedate, 'DD-MON-YYYY'));
  570.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_effective_start_date   : ' || TO_CHAR(p_eff_start_date, 'DD-MON-YYYY'));
  571.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_assignment_id          : ' || p_pos.assign_id);
  572.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_rotation_plan          : ' || p_rotation_plan);
  573.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_earning_policy         : ' || p_earning_policy);
  574.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_created_by             : ' || fnd_profile.VALUE('USER_ID'));
  575.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_creation_date          : ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY'));
  576.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_last_updated_by        : ' || fnd_profile.VALUE('USER_ID'));
  577.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_last_update_date       : ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY'));
  578.   display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: p_last_update_login      : ' || fnd_global.conc_login_id);
  579.  
  580.   hxt_gen_aai.update_otlr_add_assign_info
  581.     ( p_id                    => p_id
  582.     , p_datetrack_mode        => 'UPDATE_OVERRIDE'
  583.     , p_effective_date        => p_pos.effectivedate
  584.     , p_effective_start_date  => p_eff_start_date
  585.     , p_assignment_id         => p_pos.assign_id
  586.     , p_autogen_hours_yn      => 'Y'
  587.     , p_rotation_plan         => p_rotation_plan
  588.     , p_earning_policy        => p_earning_policy
  589.     , p_created_by            => fnd_profile.VALUE('USER_ID')
  590.     , p_creation_date         => SYSDATE
  591.     , p_last_updated_by       => fnd_profile.VALUE('USER_ID')
  592.     , p_last_update_date      => SYSDATE
  593.     , p_last_update_login     => fnd_global.conc_login_id
  594.     );
  595.  
  596.   p_msg := 'Success: Time Information updated';
  597.   g_time_updated := g_time_updated + 1;
  598.  
  599. EXCEPTION
  600.   WHEN OTHERS THEN
  601.     p_msg := 'ERROR: Time Information update not successful';
  602.     g_time_errors := g_time_errors + 1;
  603.     display_log('UPDATE_OTLR_ADD_ASSIGN_INFO: Unhandled exception: ' || SQLERRM);
  604.    
  605. END update_otlr_add_assign_info;
  606.  
  607.  
  608. /******************************************************************************
  609.   Create Procedure process_time_info
  610.  
  611.   This process will end-date an existing time information row if no longer
  612.   qualifying; or, update an existing row as needed, as well as create a new
  613.   row as needed.  
  614. ******************************************************************************/
  615. PROCEDURE process_time_info
  616.   (p_pos             IN  gc_pos%ROWTYPE
  617.   ,p_msg             OUT VARCHAR2
  618.   ,p_print_target    OUT VARCHAR2)  
  619. IS
  620.  
  621.   -- Constants for Record Messages
  622.   C_OT_MSG                   CONSTANT VARCHAR2(1000) := 'Skipped: Salaried with OT Earning Policy.';
  623.   C_ASGN_NF                  CONSTANT VARCHAR2(1000) := 'Skipped: Oracle Assignment not found.';
  624.   C_ASGN_END_DATED           CONSTANT VARCHAR2(1000) := 'Skipped: Oracle Assignment has been end-dated.';
  625.   C_TIME_INFO_FUTURE_DATE    CONSTANT VARCHAR2(1000) := 'Skipped: Time Information exists with same or future date.';
  626.   C_NO_UPDATE                CONSTANT VARCHAR2(1000) := 'Skipped: Time Information exists but update does not need to be performed.';
  627.   C_JOB_EXEMPT               CONSTANT VARCHAR2(1000) := 'Skipped: Job is exempt; time info not needed.';
  628.   C_ERR_ROTATION_PLAN        CONSTANT VARCHAR2(1000) := 'ERROR: Unable to determine Rotation Policy.';
  629.   C_ERR_EARNING_POLICY       CONSTANT VARCHAR2(1000) := 'ERROR: Unable to determine Earning Policy.';
  630.   C_ERR_INIT_TIME            CONSTANT VARCHAR2(1000) := 'ERROR: Unable to initialize Time Information.';
  631.   C_ERR_OTHERS               CONSTANT VARCHAR2(1000) := 'ERROR: Encountered an error processing time information.';
  632.  
  633.   l_hxt_id                   hxt_add_assign_info_f.id%TYPE;
  634.   l_hxt_eff_start_date       hxt_add_assign_info_f.effective_start_date%TYPE;
  635.   l_hxt_eff_end_date         hxt_add_assign_info_f.effective_end_date%TYPE;
  636.   l_hep_name                 hxt_earning_policies.name%TYPE;
  637.   l_rotation_plan            NUMBER;
  638.   l_earning_policy           NUMBER;
  639.   l_shift_diff_policy        NUMBER;
  640.  
  641.   l_check_rotation_plan      NUMBER;
  642.   l_check_earning_policy     NUMBER;  
  643.  
  644.   l_message                  VARCHAR2(1000);
  645.   l_ot_flag                  VARCHAR2(1) := 'N';
  646.  
  647.   l_pos                      gc_pos%ROWTYPE := p_pos;
  648.  
  649. BEGIN
  650.  
  651.   -- Make sure assignment is found
  652.   IF l_pos.assignment_id IS NULL THEN
  653.    
  654.     p_msg              := C_ASGN_NF;
  655.     p_print_target     := C_OUTPUT_LOG;
  656.     g_records_skipped  := g_records_skipped + 1;
  657.     RETURN; -- continue to the next cursor record
  658.    
  659.   END IF;
  660.  
  661.   -- Make sure assignment is not end-dated
  662.   IF l_pos.effective_end_date != TO_DATE('31-DEC-4712') THEN
  663.    
  664.     p_msg              := C_ASGN_END_DATED;
  665.     p_print_target     := C_OUTPUT_LOG;
  666.     g_records_skipped  := g_records_skipped + 1;
  667.     RETURN; -- continue to the next cursor record
  668.  
  669.   END IF;
  670.  
  671.   -- Initialize time info variables
  672.   init_time_info
  673.     ( p_pos                      => l_pos
  674.     , p_hxt_id                   => l_hxt_id
  675.     , p_hxt_eff_start_date       => l_hxt_eff_start_date
  676.     , p_hxt_eff_end_date         => l_hxt_eff_end_date
  677.     , p_hep_name                 => l_hep_name
  678.     , p_rotation_plan            => l_rotation_plan
  679.     , p_earning_policy           => l_earning_policy
  680.     , p_shift_diff_policy        => l_shift_diff_policy);
  681.    
  682.   -- Determine the rotation plan and earning policy
  683.   l_check_rotation_plan   := get_rotation_plan(l_pos);
  684.   l_check_earning_policy  := get_earning_policy(l_pos);
  685.  
  686.   IF l_hxt_id IS NOT NULL THEN     -- If a row is returned, proceed with Update logic
  687.  
  688.     /*
  689.     -- Check Oracle assignment end date vs datafile end date
  690.     IF l_hxt_eff_end_date < l_pos.effectivedate THEN
  691.      
  692.       p_msg       := 'ERROR: Assignment end date is less than datafile end date. Assignment ID => ' || p_pos.assign_id;
  693.       g_time_errors := g_time_errors + 1;
  694.       RETURN; -- continue to the next cursor record
  695.      
  696.     END IF;
  697.    */
  698.    
  699.     -- Check if Salaried has OT Earning Policy
  700.     IF     l_pos.segment5 =    'Salaried'
  701.        AND l_pos.flsa     =    'Non Exempt'                                    
  702.        AND l_hep_name     LIKE '%OT Leave%' THEN
  703.              
  704.       l_ot_flag       := 'Y';
  705.              
  706.     END IF;
  707.    
  708.     -- haai.shift_differential_policy should be NULL
  709.     -- If not, display a warning but continue processing
  710.     IF l_shift_diff_policy IS NOT NULL THEN
  711.    
  712.       l_message := '**** Warning for ' || p_pos.employeelastname || ', ' || p_pos.employeefirstname ||
  713.                     ': Time Info Shift Differential Policy not null; review manually.';
  714.       display_output(l_message);
  715.       display_log('PROCESS_TIME_INFO: ' || l_message);
  716.    
  717.     END IF;
  718.    
  719.     -- Check to see if the time info needs to be end-dated
  720.     IF         l_pos.payroll        = 'Monthly'
  721.        OR (    l_pos.payroll        = 'Bi-weekly'
  722.            AND l_pos.pay_basis_name IN ('Goal Payment', 'Unit Pay'))
  723.        OR (    l_pos.payroll        = 'Bi-weekly'
  724.            AND l_pos.pay_basis_name = 'Annual Salary'
  725.            AND l_pos.flsa           = 'Exempt')
  726.     THEN
  727.      
  728.       -- Only print this message if the program tries to change the time info
  729.       IF l_ot_flag = 'Y' THEN      
  730.         p_msg             := C_OT_MSG;
  731.         p_print_target    := C_OUTPUT_LOG;
  732.         g_records_skipped := g_records_skipped + 1;
  733.         RETURN;    -- continue to the next cursor record      
  734.       END IF;
  735.    
  736.       -- End date the exiting time information
  737.       end_date_existing_time_info
  738.         ( p_id                   => l_hxt_id
  739.         , p_effective_start_date => l_hxt_eff_start_date
  740.         , p_effective_end_date   => l_hxt_eff_end_date
  741.         , p_effective_date       => l_pos.effectivedate
  742.         , p_msg                  => p_msg);
  743.      
  744.       RETURN;  -- continue to the next cursor record
  745.          
  746.     END IF;
  747.  
  748.     -- Check to see if the time info needs to be updated
  749.     IF    (    l_pos.payroll        = 'Bi-weekly'
  750.            AND l_pos.pay_basis_name = 'Hourly Rate')
  751.        OR (    l_pos.payroll        = 'Bi-weekly'
  752.            AND l_pos.pay_basis_name = 'Annual Salary'
  753.            AND l_pos.flsa           = 'Non Exempt')
  754.     THEN
  755.  
  756.       -- Make sure time information doesn't already exist with same/future date
  757.       IF         l_hxt_eff_start_date =  TRUNC(l_pos.effectivedate)
  758.          OR (    l_hxt_eff_end_date   >  TRUNC(l_pos.effectivedate)
  759.              AND l_hxt_eff_end_date   != TO_DATE('31-DEC-4712'))
  760.       THEN
  761.      
  762.         p_msg             := C_TIME_INFO_FUTURE_DATE;
  763.         p_print_target    := C_OUTPUT_LOG;
  764.         g_records_skipped := g_records_skipped + 1;
  765.         RETURN;   -- continue to the next cursor record
  766.      
  767.       END IF;      
  768.      
  769.       -- Determine if the update needs to be performed
  770.       IF    l_check_rotation_plan  != l_rotation_plan
  771.          OR l_check_earning_policy != l_earning_policy
  772.          OR l_hxt_eff_end_date     <  l_pos.effectivedate THEN
  773.          
  774.         -- Only print this message if the program tries to change the time info
  775.         IF l_ot_flag = 'Y' THEN      
  776.           p_msg             := C_OT_MSG;
  777.           p_print_target    := C_OUTPUT_LOG;
  778.           g_records_skipped := g_records_skipped + 1;
  779.           RETURN;    -- continue to the next cursor record      
  780.         END IF;
  781.          
  782.         -- Call hxt_gen_aai.update_oltr_add_assign_info
  783.         update_otlr_add_assign_info
  784.           ( p_pos                  => l_pos
  785.           , p_id                   => l_hxt_id
  786.           , p_eff_start_date       => l_hxt_eff_start_date
  787.           , p_rotation_plan        => l_check_rotation_plan
  788.           , p_earning_policy       => l_check_earning_policy
  789.           , p_msg                  => p_msg
  790.           );
  791.        
  792.         RETURN;    -- continue to the next cursor record
  793.      
  794.       END IF;
  795.      
  796.     END IF;
  797.    
  798.     -- Record did not meet any criteria above; no action was taken
  799.     IF p_msg IS NULL THEN
  800.      
  801.       p_msg              := C_NO_UPDATE;
  802.       p_print_target     := C_LOG;
  803.       g_records_skipped  := g_records_skipped + 1;
  804.       RETURN;    -- continue to the next cursor record
  805.      
  806.     END IF;
  807.                      
  808.   ELSE      -- No row found in hxt_add_assign_info_f, so create a new record
  809.  
  810.     IF l_pos.flsa = 'Non Exempt' THEN                                          
  811.    
  812.       -- Only print this message if the program tries to change the time info
  813.       IF l_ot_flag = 'Y' THEN      
  814.         p_msg             := C_OT_MSG;
  815.         p_print_target    := C_OUTPUT_LOG;
  816.         g_records_skipped := g_records_skipped + 1;
  817.         RETURN;    -- continue to the next cursor record      
  818.       END IF;
  819.    
  820.       -- Call hxt_gen_aai.create_oltr_add_assign_info
  821.       create_otlr_add_assign_info
  822.         ( p_pos            => l_pos
  823.         , p_rotation_plan  => l_check_rotation_plan
  824.         , p_earning_policy => l_check_earning_policy
  825.         , p_msg            => p_msg
  826.         );
  827.    
  828.     ELSE
  829.    
  830.       p_msg             := C_JOB_EXEMPT;  
  831.       p_print_target    := C_LOG;
  832.       g_records_skipped := g_records_skipped + 1;      
  833.    
  834.     END IF;    
  835.    
  836.     RETURN;     -- continue to the next cursor record
  837.    
  838.   END IF;
  839.  
  840. EXCEPTION
  841.   WHEN rotation_plan_error THEN
  842.     p_msg           := C_ERR_ROTATION_PLAN;
  843.     p_print_target  := c_output_log;
  844.     g_time_errors   := g_time_errors + 1;
  845.    
  846.   WHEN earning_policy_error THEN
  847.     p_msg           := C_ERR_EARNING_POLICY;
  848.     p_print_target  := c_output_log;
  849.     g_time_errors   := g_time_errors + 1;
  850.    
  851.   WHEN init_time_info_error THEN
  852.     p_msg           := C_ERR_INIT_TIME;
  853.     p_print_target  := c_output_log;
  854.     g_time_errors   := g_time_errors + 1;
  855.    
  856.   WHEN OTHERS THEN
  857.     p_msg           := C_ERR_OTHERS;
  858.     p_print_target  := c_output_log;
  859.     g_time_errors   := g_time_errors + 1;
  860.     display_log('PROCESS_TIME_INFO: Unhandled exception: ' || SQLERRM);    
  861.    
  862. END process_time_info;
  863.  
  864.  
  865. /******************************************************************************
  866.  Create Procedure p_main_process
  867. ******************************************************************************/
  868. PROCEDURE main_process
  869.   (p_errbuf            OUT     VARCHAR2
  870.   ,p_errcode           OUT     VARCHAR2
  871.   ,p_validate_only     IN      VARCHAR2)
  872. IS
  873.  
  874.   l_msg                VARCHAR2(255);
  875.   l_print_target       VARCHAR2(2);    
  876.  
  877. BEGIN
  878.  
  879.   p_errcode       := '0';
  880.   p_errbuf        :=  NULL;
  881.  
  882.   print_header;
  883.      
  884.   FOR l_pos IN gc_pos LOOP
  885.  
  886.     g_record_count := g_record_count + 1;
  887.  
  888.     -- Print log header
  889.     print_log_header(l_pos);
  890.      
  891.     -- Process the record and retrieve the status
  892.     process_time_info
  893.       ( p_pos          => l_pos
  894.       , p_msg          => l_msg
  895.       , p_print_target => l_print_target
  896.       );
  897.    
  898.     -- Print the record and record status in the output
  899.     print_record
  900.       ( p_pos          => l_pos
  901.       , p_msg          => l_msg
  902.       , p_print_target => l_print_target
  903.       );
  904.    
  905.     -- Print log footer
  906.     print_log_footer;
  907.    
  908.   END LOOP;
  909.  
  910.   -- Print Process Statistics in Output and Log
  911.   print_statistics;
  912.  
  913.   IF SUBSTR(UPPER(p_validate_only),1,1) = 'Y' THEN
  914.     display_log('MAIN_PROCESS: Validate Mode => Changes rolled back.');
  915.     ROLLBACK;
  916.   ELSE
  917.     display_log('MAIN_PROCESS: Changes committed.');
  918.     COMMIT;
  919.   END IF;
  920.  
  921.   IF g_time_errors > 0 THEN
  922.     p_errcode       := '1';
  923.     p_errbuf        := 'Program encountered errors. Please review.';
  924.     display_log('MAIN_PROCESS: Program encountered errors. Please review.');
  925.   ELSE
  926.     p_errcode       := '0';
  927.     p_errbuf        := 'Program completed successfully...';
  928.     display_log('MAIN_PROCESS: Program completed successfully...');
  929.   END IF;
  930.    
  931. EXCEPTION
  932.   WHEN OTHERS THEN
  933.     p_errcode     := '2';
  934.     p_errbuf      := 'MAIN_PROCESS: Error in HR Jobs Position Time Info Interface. '|| SQLERRM;
  935.     ROLLBACK;
  936.  
  937. END main_process;
  938.  
  939. END xx_hr_jobs_pos_time_info;
  940. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement