DBA Data[Home] [Help]

PACKAGE BODY: APPS.GHR_MSL_PKG

Source


1 PACKAGE BODY GHR_MSL_PKG AS
2 /* $Header: ghmslexe.pkb 120.27 2011/12/02 08:55:27 utokachi ship $ */
3 
4 g_no number := 0;
5 g_package  varchar2(32) := 'GHR_MSL_PKG';
6 g_proc     varchar2(72) := null;
7 g_effective_date  date;
8 g_rg_recs_failed  NUMBER := 0;
9 
10 -- Bug#5063304
11 l_log_text varchar2(2000) := null;
12 l_mslerrbuf   varchar2(2000) := null;
13 --l_errbuf   varchar2(2000) := null;
14 
15 PROCEDURE execute_msl (p_errbuf out nocopy varchar2,
16                        p_retcode out nocopy number,
17                        p_mass_salary_id in number,
18                        p_action in varchar2 ) is
19                        --p_bus_grp_id in number) IS
20 
21 p_mass_salary varchar2(32);
22 
23 --
24 --
25 -- Main Cursor which fetches from per_assignments_f and per_people_f
26 --
27 /***** Splitting the cursor into two for better performance
28  ***** 1. First eliminate the check of assignment_status_type_id in the cursor and have outside.
29  ***** 2. One cursor as organization as not null
30  ***** 3. One cursor as organization is null (One FTS will be there because
31  *****    the system should search the entire database.)
32 
33 cursor cur_people (effective_date date, p_org_id number) is
34 select ppf.person_id    PERSON_ID,
35        ppf.first_name   FIRST_NAME,
36        ppf.last_name    LAST_NAME,
37        ppf.middle_names MIDDLE_NAMES,
38        ppf.full_name    FULL_NAME,
39        ppf.date_of_birth DATE_OF_BIRTH,
40        ppf.national_identifier NATIONAL_IDENTIFIER,
41        paf.position_id  POSITION_ID,
42        paf.assignment_id ASSIGNMENT_ID,
43        paf.grade_id     GRADE_ID,
44        paf.job_id       JOB_ID,
45        paf.location_id  LOCATION_ID,
46        paf.organization_id ORGANIZATION_ID,
47        paf.business_group_id BUSINESS_GROUP_ID
48   from per_assignments_f   paf,
49        per_people_f        ppf,
50        per_person_types    ppt,
51        per_assignment_status_types pas_t
52  where ppf.person_id    = paf.person_id
53    and paf.primary_flag = 'Y'
54    and paf.assignment_type <> 'B'
55    and paf.assignment_status_type_id = pas_t.assignment_status_type_id
56    and pas_t.user_status not in (
57                          'Terminate Assignment',
58                          'Active Application',
59                          'Offer',
60                          'Accepted',
61                          'Terminate Application',
62                          'End',
63                          'Terminate Appointment',
64                          'Separated')
65    and effective_date between paf.effective_start_date
66              and nvl(paf.effective_end_date,effective_date+1)
67    and ppf.person_type_id = ppt.person_type_id
68    and ppt.system_person_type = 'EMP'
69    and effective_date between ppf.effective_start_date
70              and nvl(ppf.effective_end_date,effective_date+1)
71 -- VSM. Enhancements [Masscrit.doc] Organization can be null
72    and paf.organization_id + 0 = nvl(p_org_id, paf.organization_id)
73    and paf.position_id is not null
74    order by ppf.person_id; -- 3539816 Order by added to prevent snapshot old error
75 ****/
76 ---
77 --- Bug  3539816 Order by added to prevent snapshot old error
78 --- 1. Cursor with organization.
79 ---
80 CURSOR cur_people_org (effective_date date, p_org_id number) IS
81 SELECT ppf.person_id                 PERSON_ID,
82        ppf.first_name                FIRST_NAME,
83        ppf.last_name                 LAST_NAME,
84        ppf.middle_names              MIDDLE_NAMES,
85        ppf.full_name                 FULL_NAME,
86        ppf.date_of_birth             DATE_OF_BIRTH,
87        ppf.national_identifier       NATIONAL_IDENTIFIER,
88        --Bug # 9329643
89        ppf.employee_number           EMPLOYEE_NUMBER,
90        paf.position_id               POSITION_ID,
91        paf.assignment_id             ASSIGNMENT_ID,
92        paf.grade_id                  GRADE_ID,
93        paf.job_id                    JOB_ID,
94        paf.location_id               LOCATION_ID,
95        paf.organization_id           ORGANIZATION_ID,
96        paf.business_group_id         BUSINESS_GROUP_ID,
97        paf.assignment_status_type_id ASSIGNMENT_STATUS_TYPE_ID
98   FROM per_assignments_f   paf,
99        per_people_f        ppf,
100        per_person_types    ppt
101  WHERE ppf.person_id           = paf.person_id
102    AND effective_date between ppf.effective_start_date and ppf.effective_end_date
103    AND effective_date between paf.effective_start_date and paf.effective_end_date
104    AND paf.primary_flag        = 'Y'
105    AND paf.assignment_type     <> 'B'
106    AND ppf.person_type_id      = ppt.person_type_id
107    AND ppt.system_person_type  IN ('EMP','EMP_APL')
108    AND paf.organization_id     = p_org_id
109    AND paf.position_id is not null
110    ORDER BY ppf.person_id;
111 
112 
113 ---
114 --- Bug  3539816 Order by added to prevent snapshot old error
115 --- 2. Cursor with no organization.
116 ---
117 --- This SQL is tuned by joining the hr_organization_units to avoid the FTS of PAF.
118 --- Bug 6152582
119 ---
120 CURSOR cur_people (effective_date date) IS
121 SELECT ppf.person_id                 PERSON_ID,
122        ppf.first_name                FIRST_NAME,
123        ppf.last_name                 LAST_NAME,
124        ppf.middle_names              MIDDLE_NAMES,
125        ppf.full_name                 FULL_NAME,
126        ppf.date_of_birth             DATE_OF_BIRTH,
127        ppf.national_identifier       NATIONAL_IDENTIFIER,
128        --Bug # 9329643
129        ppf.employee_number           EMPLOYEE_NUMBER,
130        paf.position_id               POSITION_ID,
131        paf.assignment_id             ASSIGNMENT_ID,
132        paf.grade_id                  GRADE_ID,
133        paf.job_id                    JOB_ID,
134        paf.location_id               LOCATION_ID,
135        paf.organization_id           ORGANIZATION_ID,
136        paf.business_group_id         BUSINESS_GROUP_ID,
137        paf.assignment_status_type_id ASSIGNMENT_STATUS_TYPE_ID
138   FROM per_assignments_f   paf,
139        per_people_f        ppf,
140        per_person_types    ppt,
141        hr_organization_units hou
142  WHERE ppf.person_id           = paf.person_id
143    AND effective_date between ppf.effective_start_date and ppf.effective_end_date
144    AND effective_date between paf.effective_start_date and paf.effective_end_date
145    AND paf.primary_flag        = 'Y'
146    AND paf.assignment_type     <> 'B'
147    AND ppf.person_type_id      = ppt.person_type_id
148    AND ppt.system_person_type  IN ('EMP','EMP_APL')
149    AND paf.organization_id     = hou.organization_id
150    AND paf.position_id is not null
151    ORDER BY ppf.person_id;
152 --
153 -- Check assignment_status_type
154 --
155 
156 CURSOR cur_ast (asg_status_type_id number) IS
157 SELECT user_status from per_assignment_status_types
158 WHERE assignment_status_type_id = asg_status_type_id
159   AND upper(user_status) not in (
160                          'TERMINATE ASSIGNMENT',           /* 3 */
161                          'ACTIVE APPLICATION',             /* 4 */
162                          'OFFER',                          /* 5 */
163                          'ACCEPTED',                       /* 6 */
164                          'TERMINATE APPLICATION',          /* 7 */
165                          'END',                            /* 8 */
166                          'TERMINATE APPOINTMENT',          /* 126 */
167                          'SEPARATED');                     /* 132 */
168 
169 --
170 -- Cursor to select from GHR_MASS_SALARIES - Where criteria is stored
171 -- Before executing this package
172 -- from ghr_mass_salary_criteria
173 --
174 
175 cursor ghr_msl (p_msl_id number) is
176 select name, effective_date, mass_salary_id, user_table_id, submit_flag,
177        executive_order_number, executive_order_date, ROWID, PA_REQUEST_ID,
178        ORGANIZATION_ID, DUTY_STATION_ID, PERSONNEL_OFFICE_ID,
179        AGENCY_CODE_SUBELEMENT, OPM_ISSUANCE_NUMBER, OPM_ISSUANCE_DATE, PROCESS_TYPE
180   from ghr_mass_salaries
181  where MASS_SALARY_ID = p_msl_id
182    for update of user_table_id nowait;
183 
184 -- VSM [family name was hardcoded previously to SALARY_CHG. Fetching it from DB now]
185 cursor get_sal_chg_fam is
186 select NOA_FAMILY_CODE
187 from ghr_families
188 where NOA_FAMILY_CODE in
189     (select NOA_FAMILY_CODE from ghr_noa_families
190          where  nature_of_action_id =
191             (select nature_of_action_id
192              from ghr_nature_of_actions
193              where code = '894')
194     ) and proc_method_flag = 'Y';    --AVR 13-JAN-99
195  -------------   ) and update_hr_flag = 'Y';
196 
197 l_assignment_id        per_assignments_f.assignment_id%type;
198 l_position_id          per_assignments_f.position_id%type;
199 l_grade_id             per_assignments_f.grade_id%type;
200 l_business_group_id    per_assignments_f.business_group_id%type;
201 
202 l_position_title       varchar2(300);
203 l_position_number      varchar2(20);
204 l_position_seq_no      varchar2(20);
205 
206 l_msl_cnt              number := 0;
207 l_recs_failed          number := 0;
208 
209 l_tenure               varchar2(35);
210 l_annuitant_indicator  varchar2(35);
211 l_pay_rate_determinant varchar2(35);
212 l_work_schedule        varchar2(35);
213 l_part_time_hour       varchar2(35);
214 l_pay_table_id         number;
215 l_pay_plan             varchar2(30);
216 l_grade_or_level       varchar2(30);
217 -- Bug#5089732 Added current pay plan, grade_or_level
218 l_to_grade_id          number;
219 l_to_pay_plan          varchar2(30);
220 l_to_grade_or_level    varchar2(30);
221 -- Bug#5089732
222 l_step_or_rate         varchar2(30);
223 l_pay_basis            varchar2(30);
224 l_location_id          number;
225 l_duty_station_id      number;
226 l_duty_station_desc    ghr_pa_requests.duty_station_desc%type;
227 l_duty_station_code    ghr_pa_requests.duty_station_code%type;
228 l_effective_date       date;
229 l_personnel_office_id  varchar2(300);
230 l_org_structure_id     varchar2(300);
231 l_sub_element_code     varchar2(300);
232 
233 l_old_basic_pay        number;
234 l_old_avail_pay        number;
235 l_old_loc_diff         number;
236 l_tot_old_sal          number;
237 l_old_auo_pay          number;
238 l_old_ADJ_basic_pay    number;
239 l_other_pay            number;
240 
241 
242 l_auo_premium_pay_indicator     varchar2(30);
243 l_ap_premium_pay_indicator      varchar2(30);
244 l_retention_allowance           number;
245 l_retention_allow_perc          number;     ---AVR
246 l_new_retention_allowance       number;     ---AVR
247 l_supervisory_differential      number;
248 l_supervisory_diff_perc         number;     ---AVR
249 l_new_supervisory_differential  number;     ---AVR
250 l_staffing_differential         number;
251 
252 l_new_avail_pay             number;
253 l_new_loc_diff              number;
254 l_tot_new_sal               number;
255 l_new_auo_pay               number;
256 
257 l_new_basic_pay             number;
258 l_new_locality_adj          number;
259 l_new_adj_basic_pay         number;
260 l_new_total_salary          number;
261 l_new_other_pay_amount      number;
262 l_new_au_overtime           number;
263 l_new_availability_pay      number;
264 l_out_step_or_rate          varchar2(30);
265 l_out_pay_rate_determinant  varchar2(30);
266 l_out_pay_plan              varchar2(30);
267 l_out_grade_id              number;
268 l_out_grade_or_level        varchar2(30);
269 
270 l_PT_eff_start_date         date;
271 l_open_pay_fields           boolean;
272 l_message_set               boolean;
273 l_calculated                boolean;
274 
275 l_mass_salary_id            number;
276 l_user_table_id             number;
277 l_submit_flag               varchar2(2);
278 l_executive_order_number    ghr_mass_salaries.executive_order_number%TYPE;
279 l_executive_order_date      ghr_mass_salaries.executive_order_date%TYPE;
280 l_opm_issuance_number       ghr_mass_salaries.opm_issuance_number%TYPE;
281 l_opm_issuance_date         ghr_mass_salaries.opm_issuance_date%TYPE;
282 l_pa_request_id             number;
283 l_rowid                     varchar2(30);
284 
285 l_p_ORGANIZATION_ID           number;
286 l_p_DUTY_STATION_ID           number;
287 l_p_PERSONNEL_OFFICE_ID       varchar2(5);
288 
289 L_row_cnt                   number := 0;
290 
291 l_sf52_rec                  ghr_pa_requests%rowtype;
292 l_lac_sf52_rec              ghr_pa_requests%rowtype;
293 l_errbuf                    varchar2(2000);
294 
295 l_retcode                   number;
296 
297 l_pos_ei_data               per_position_extra_info%rowtype;
298 l_pos_grp1_rec              per_position_extra_info%rowtype;
299 
300 l_pay_calc_in_data          ghr_pay_calc.pay_calc_in_rec_type;
301 l_pay_calc_out_data         ghr_pay_calc.pay_calc_out_rec_type;
302 l_sel_flg                   varchar2(2);
303 
304 l_first_action_la_code1     varchar2(30);
305 l_first_action_la_code2     varchar2(30);
306 
307 l_remark_code1              varchar2(30);
308 l_remark_code2              varchar2(30);
309 l_p_AGENCY_CODE_SUBELEMENT       varchar2(30);
310 
311 ----Pay cap variables
312 l_entitled_other_pay        NUMBER;
313 l_capped_other_pay          NUMBER;
314 l_adj_basic_message         BOOLEAN  := FALSE;
315 l_pay_cap_message           BOOLEAN  := FALSE;
316 l_temp_retention_allowance  NUMBER;
317 l_open_pay_fields_caps      BOOLEAN;
318 l_message_set_caps          BOOLEAN;
319 l_total_pay_check           VARCHAR2(1);
320 l_comment                   VARCHAR2(150);
321 l_comment_sal               VARCHAR2(150);
322 -- Bug#3968005 Commented l_pay_sel as it is not required.
323 -- l_pay_sel                   VARCHAR2(1) := NULL;
324 l_old_capped_other_pay     NUMBER;
325 
326 -- Bug#5063304
327 l_elig_flag        BOOLEAN := FALSE;
328 ----
329 REC_BUSY                    exception;
330 pragma exception_init(REC_BUSY,-54);
331 
332 l_proc  varchar2(72) :=  g_package || '.execute_msl';
333 
334 -- Bug#5063304 Moved the following cursor, variable declaration
335 -- from execute_msl.
336 CURSOR c_pay_tab_essl IS
337 SELECT 1 from pay_user_tables
338  WHERE substr(user_table_name,1,4) = 'ESSL'
339    AND user_table_id = l_user_table_id;
340 
341 l_essl_table  BOOLEAN := FALSE;
342 l_org_name	hr_organization_units.name%type;
343 
344 -- Bug 3315432 Madhuri
345 --
346 CURSOR cur_pp_prd(p_msl_id ghr_mass_salary_criteria.mass_salary_id%type)
347 IS
348 SELECT pay_plan ,pay_rate_determinant prd
349 FROM   ghr_mass_salary_criteria
350 WHERE  mass_salary_id=p_msl_id;
351 
352 
353 rec_pp_prd	pp_prd;
354 l_index         NUMBER:=1;
355 l_cnt           NUMBER;
356 l_process_type  ghr_mass_salaries.process_type%TYPE;
357 --
358 --
359 -- Local procedure msl_process
360 --
361 
362 --
363 -- GPPA Update 46
364 --
365 cursor cur_eq_ppl (c_pay_plan ghr_pay_plans.pay_plan%type)
366 IS
367 select EQUIVALENT_PAY_PLAN
368 from ghr_pay_plans
369 where pay_plan = c_pay_plan;
370 
371 l_eq_pay_plan ghr_pay_plans.equivalent_pay_plaN%type;
372 
373 --
374 --
375 
376 PROCEDURE msl_process( p_assignment_id  per_assignments_f.assignment_id%TYPE
377 							 ,p_person_id per_assignments_f.person_id%TYPE
378 							 ,p_position_id  per_assignments_f.position_id%TYPE
379 							 ,p_grade_id per_assignments_f.grade_id%TYPE
380 							 ,p_business_group_id per_assignments_f.business_group_iD%TYPE
381 							 ,p_location_id per_assignments_f.location_id%TYPE
382 							 ,p_organization_id per_assignments_f.organization_id%TYPE
383 							 ,p_date_of_birth date
384 							 ,p_first_name per_people_f.first_name%TYPE
385 							 ,p_last_name per_people_f.last_name%TYPE
386                              ,p_full_name per_people_f.full_name%TYPE
387                              ,p_middle_names per_people_f.middle_names%TYPE
388 							 ,p_national_identifier per_people_f.national_identifier%TYPE
389 							 --Bug # 9329643
390 							 ,p_employee_number  per_people_f.employee_number%TYPE
391                              ,p_personnel_office_id IN VARCHAR2
392                              ,p_org_structure_id    IN VARCHAR2
393                              ,p_position_title      IN VARCHAR2
394                              ,p_position_number     IN VARCHAR2
395                              ,p_position_seq_no     IN VARCHAR2
396                              ,p_subelem_code        IN VARCHAR2
397                              ,p_duty_station_id     IN ghr_duty_stations_f.duty_station_id%TYPE
398                              ,p_tenure              IN VARCHAR2
399                              ,p_annuitant_indicator IN VARCHAR2
400                              ,p_pay_rate_determinant IN VARCHAR2
401                              ,p_work_schedule       IN  VARCHAR2
402                              ,p_part_time_hour      IN VARCHAR2
403                              ,p_to_grade_id         IN per_assignments_f.grade_id%type
404                              ,p_pay_plan            IN VARCHAR2
405                              ,p_to_pay_plan         IN VARCHAR2
406                              ,p_pay_table_id        IN NUMBER
407                              ,p_grade_or_level      IN VARCHAR2
408                              ,p_to_grade_or_level   IN VARCHAR2
409                              ,p_step_or_rate        IN VARCHAR2
410                              ,p_pay_basis           IN VARCHAR2
411 							)	IS
412         -- Bug3437354
413         CURSOR cur_valid_DS(p_ds_id NUMBER)
414             IS
415             SELECT effective_end_date  end_date
416             FROM   ghr_duty_stations_f
417             WHERE  duty_station_id=p_ds_id
418             AND    g_effective_date between effective_start_date and effective_end_date;
419 
420             l_ds_end_date	  ghr_duty_stations_f.effective_end_date%type;
421 
422 BEGIN
423       savepoint execute_msl_sp;
424          l_msl_cnt := l_msl_cnt +1;
425 	 --Bug#3968005 Initialised l_sel_flg
426          l_sel_flg := NULL;
427          l_pay_calc_in_data  := NULL;
428          l_pay_calc_out_data := NULL;
429 
430        l_assignment_id     := p_assignment_id;
431        l_position_id       := p_position_id;
432        l_grade_id          := p_grade_id;
433        l_business_group_id := p_business_group_iD;
434        l_location_id       := p_location_id;
435        -- Bug#5063304
436         l_personnel_office_id  := p_personnel_office_id;
437         l_org_structure_id     := p_org_structure_id;
438         l_position_title       := p_position_title;
439         l_position_number      := p_position_number;
440         l_position_seq_no      := p_position_seq_no;
441         l_sub_element_code     := p_subelem_code;
442         l_duty_station_id      := p_duty_station_id;
443         l_tenure               := p_tenure;
444         l_annuitant_indicator  := p_annuitant_indicator;
445         l_pay_rate_determinant := p_pay_rate_determinant;
446         l_work_schedule        := P_work_schedule;
447         l_part_time_hour       := p_part_time_hour;
448         l_to_grade_id          := p_to_grade_id;
449         l_pay_plan             := p_pay_plan;
450         l_to_pay_plan          := p_to_pay_plan;
451         l_pay_table_id         := p_pay_table_id;
452         l_grade_or_level       := p_grade_or_level;
453         l_to_grade_or_level    := p_to_grade_or_level;
454         l_step_or_rate         := P_step_or_rate;
455         l_pay_basis            := p_pay_basis;
456 	    hr_utility.set_location('The location id is:'||l_location_id,1);
457 
458 --------GPPA Update 46 start
459             ghr_msl_pkg.g_first_noa_code := NULL;
460             FOR cur_eq_ppl_rec IN cur_eq_ppl(l_pay_plan)
461             LOOP
462                 l_eq_pay_plan   := cur_eq_ppl_rec.EQUIVALENT_PAY_PLAN;
463                 exit;
464             END LOOP;
465             if l_effective_date >= to_date('2007/01/07','YYYY/MM/DD') AND
466                l_eq_pay_plan = 'GS' AND
467                l_lac_sf52_rec.first_action_la_code1 = 'QLP' AND
468                l_lac_sf52_rec.first_action_la_code2 = 'ZLM' THEN
469 
470                ghr_msl_pkg.g_first_noa_code := '890';
471 
472             end if;
473             if l_effective_date >= to_date('2007/01/07','YYYY/MM/DD') AND
474                l_eq_pay_plan = 'FW' AND
475                l_lac_sf52_rec.first_action_la_code1 = 'RJR' THEN
476 
477                ghr_msl_pkg.g_first_noa_code := '890';
478 
479             end if;
480 --------GPPA Update 46 end
481 
482         g_proc := 'Location Validation';
483         -- Start of Bug3437354
484         IF l_location_id IS NULL THEN
485             l_mslerrbuf := ' Error: No valid Location found, salary cannot be calculated correctly'||
486                                ' without the employee''s duty location. ';
487                 RAISE msl_error;
488         END IF;
489 
490         g_proc := 'Duty Station Validation';
491         IF l_duty_station_id IS NOT NULL THEN
492 
493             --
494             -- Added this condition for bug 3437354, error out the record without valid Loc id
495             --
496             FOR rec_ds in cur_valid_ds(l_duty_station_id)
497             LOOP
498                 l_ds_end_date	:= rec_ds.end_Date;
499             END LOOP;
500             IF l_ds_end_date IS NULL THEN
501                 hr_utility.set_location('Under DS null check'||l_duty_station_id, 1);
502                 l_mslerrbuf := ' Error: Duty Station associated with the location is INVALID. '||
503                                'Salary cannot be calculated correctly without valid duty station. ';
504                 RAISE msl_error;
505             END IF;
506 
507         END IF;
508         -- End of bug 3437354
509 
510        /*    -- BEGIN
511               ghr_pa_requests_pkg.get_SF52_loc_ddf_details
512                   (p_location_id      => l_location_id
513                   ,p_duty_station_id  => l_duty_station_id);
514            /  *exception
515               when others then
516                  hr_utility.set_location(
517                  'Error in Ghr_pa_requests_pkg.get_sf52_loc_ddf_details'||
518                        'Err is '||sqlerrm(sqlcode),20);
519                  l_mslerrbuf := 'Error in get_sf52_loc_ddf_details '||
520                        'Sql Err is '|| sqlerrm(sqlcode);
521                  raise msl_error;
522            end;*  /
523 
524 
525 
526        get_pos_grp1_ddf(l_position_id,
527                         l_effective_date,
528                         l_pos_grp1_rec);
529 
530        l_personnel_office_id :=  l_pos_grp1_rec.poei_information3;
531        l_org_structure_id    :=  l_pos_grp1_rec.poei_information5;
532 
533        get_sub_element_code_pos_title(l_position_id,
534                                      p_person_id,
535                                      l_business_group_id,
536                                      l_assignment_id,
537                                      l_effective_date,
538                                      l_sub_element_code,
539                                      l_position_title,
540                                      l_position_number,
541                                      l_position_seq_no);
542 
543 	hr_utility.set_location('The duty station id is:'||l_duty_station_id,12345);
544 
545        if check_init_eligibility(l_p_duty_station_id,
546                               l_p_PERSONNEL_OFFICE_ID,
547                               l_p_AGENCY_CODE_SUBELEMENT,
548                               l_duty_station_id,
549                               l_personnel_office_id,
550                               l_sub_element_code) then
551 
552 		   hr_utility.set_location('check_init_eligibility    ' || l_proc,6);
553 		-- Bug 3457205 Filter the Pay plan table id condition also b4 checking any other thing
554 		-- Moving check_eligibility to here.
555 			-- Get PRD, work schedule etc form ASG EI
556 			 begin
557 				ghr_pa_requests_pkg.get_sf52_asg_ddf_details
558 						  (l_assignment_id,
559 						   l_effective_date,
560 						   l_tenure,
561 						   l_annuitant_indicator,
562 						   l_pay_rate_determinant,
563 						   l_work_schedule,
564 						   l_part_time_hour);
565 			 exception
566 				when others then
567 					hr_utility.set_location('Error in Ghr_pa_requests_pkg.get_sf52_asg_ddf_details'||
568 							  'Err is '||sqlerrm(sqlcode),20);
569 					l_mslerrbuf := 'Error in get_sf52_asgddf_details Sql Err is '|| sqlerrm(sqlcode);
570 					raise msl_error;
571 			 end;
572 
573 -- Bug 3315432 Madhuri
574 --
575         FOR l_cnt in 1..rec_pp_prd.COUNT LOOP
576 
577 ---Bug 3327999 First filter the PRD. Then check for Pay plan and Pay table ID
578 		IF nvl(rec_pp_prd(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant THEN
579 		-- Get Pay table ID and other details
580            BEGIN
581            -- Bug#5089732 Used the overloaded procedure.
582                         get_pay_plan_and_table_id
583                           (l_pay_rate_determinant,p_person_id,
584                            l_position_id,l_effective_date,
585                            l_grade_id, l_to_grade_id,l_assignment_id,'SHOW',
586                            l_pay_plan,l_to_pay_plan,l_pay_table_id,
587                            l_grade_or_level, l_to_grade_or_level, l_step_or_rate,
588                            l_pay_basis);
589            EXCEPTION
590                when msl_error then
591  		           l_mslerrbuf := hr_utility.get_message;
592                    raise;
593            END;
594 
595 		IF ( nvl(rec_pp_prd(l_cnt).pay_plan,l_pay_plan) = l_pay_plan
596 			and l_user_table_id = nvl(l_pay_table_id,l_user_table_id) ) THEN
597 
598 			IF check_eligibility(l_mass_salary_id,
599                                l_user_table_id,
600                                l_pay_table_id,
601                                l_pay_plan,
602                                l_pay_rate_determinant,
603                                p_person_id,
604                                l_effective_date,
605                                p_action) THEN
606                 hr_utility.set_location('check_eligibility    ' || l_proc,8);   */
607                 -- Bug#5063304 Moved this call outside check_init_eligibility condition to
608                 --             this location.
609                 -- BUG 3377958 Madhuri
610                 -- Pick the organization name
611                 g_proc := 'Fetch Organization Name';
612                 l_org_name :=GHR_MRE_PKG.GET_ORGANIZATION_NAME(P_ORGANIZATION_ID);
613                 -- BUG 3377958 Madhuri
614 			IF upper(p_action) = 'REPORT' AND l_submit_flag = 'P' THEN
615 		 	 -- BUG 3377958 Madhuri
616 			 --Bug # 9329643
617  			    pop_dtls_from_pa_req(p_person_id,l_effective_date,l_mass_salary_id,l_org_name,p_employee_number);
618  		    	 -- BUG 3377958 Madhuri
619 			 ELSE
620 			   if check_select_flg(p_person_id,upper(p_action),
621 									l_effective_date,p_mass_salary_id,l_sel_flg) then
622 
623 				   hr_utility.set_location('check_select_flg    ' || l_proc,7);
624                    BEGIN
625 					hr_utility.set_location('The duty station name is:'||l_duty_station_code,12345);
626 					hr_utility.set_location('The duty station desc is:'||l_duty_station_desc,12345);
627 		            ghr_pa_requests_pkg.get_duty_station_details
628                        (p_duty_station_id        => l_duty_station_id
629                        ,p_effective_date        => l_effective_date
630                        ,p_duty_station_code        => l_duty_station_code
631                        ,p_duty_station_desc        => l_duty_station_desc);
632                   EXCEPTION
633                      WHEN others THEN
634                         hr_utility.set_location('Error in Ghr_pa_requests_pkg.get_duty_station_details'||
635                                'Err is '||sqlerrm(sqlcode),20);
636                         l_mslerrbuf := 'Error in get_duty_station_details Sql Err is '|| sqlerrm(sqlcode);
637                         RAISE msl_error;
638 
639                   END;
640 
641                      get_other_dtls_for_rep(l_pay_rate_determinant,
642                                      l_executive_order_number,
643                                      to_char(l_executive_order_date),
644                                      l_first_action_la_code1,
645                                      l_first_action_la_code2,
646                                      l_remark_code1,
647                                      l_remark_code2);
648 
649                      get_from_sf52_data_elements
650                             (l_assignment_id,  l_effective_date,
651                              l_old_basic_pay, l_old_avail_pay,
652                              l_old_loc_diff, l_tot_old_sal,
653                              l_old_auo_pay, l_old_adj_basic_pay,
654                              l_other_pay, l_auo_premium_pay_indicator,
655                              l_ap_premium_pay_indicator,
656                              l_retention_allowance,
657                              l_retention_allow_perc,
658                              l_supervisory_differential,
659                              l_supervisory_diff_perc,
660                              l_staffing_differential);
661 
662 
663 
664 
665 
666                   l_pay_calc_in_data.person_id          := p_person_id;
667                   l_pay_calc_in_data.position_id              := l_position_id;
668                   --l_pay_calc_in_data.noa_family_code          := 'SALARY_CHG';
669                   l_pay_calc_in_data.noa_family_code          := 'GHR_SAL_PAY_ADJ';
670                   l_pay_calc_in_data.noa_code                 := nvl(g_first_noa_code,'894');
671                   l_pay_calc_in_data.second_noa_code          := null;
672                   l_pay_calc_in_data.first_action_la_code1    := l_lac_sf52_rec.first_action_la_code1;
673                   l_pay_calc_in_data.effective_date           := l_effective_date;
674                   l_pay_calc_in_data.pay_rate_determinant     := l_pay_rate_determinant;
675                   l_pay_calc_in_data.pay_plan                 := l_pay_plan;
676                   l_pay_calc_in_data.grade_or_level           := l_grade_or_level;
677                   l_pay_calc_in_data.step_or_rate             := l_step_or_rate;
678                   l_pay_calc_in_data.pay_basis                := l_pay_basis;
679                   l_pay_calc_in_data.user_table_id            := l_pay_table_id;
680                   l_pay_calc_in_data.duty_station_id          := l_duty_station_id;
681                   l_pay_calc_in_data.auo_premium_pay_indicator := l_auo_premium_pay_indicator;
682                   l_pay_calc_in_data.ap_premium_pay_indicator  := l_ap_premium_pay_indicator;
683                   l_pay_calc_in_data.retention_allowance       := l_retention_allowance;
684                   l_pay_calc_in_data.to_ret_allow_percentage   := l_retention_allow_perc;
685                   l_pay_calc_in_data.supervisory_differential  := l_supervisory_differential;
686                   l_pay_calc_in_data.staffing_differential    := l_staffing_differential;
687                   l_pay_calc_in_data.current_basic_pay        := l_old_basic_pay;
688                --Bug 6340584
689                   l_pay_calc_in_data.open_out_locality_adj    := l_old_loc_diff;
690                --
691                   l_pay_calc_in_data.current_adj_basic_pay    := l_old_adj_basic_pay;
692                   l_pay_calc_in_data.current_step_or_rate     := l_step_or_rate;
693                   l_pay_calc_in_data.pa_request_id            := null;
694 
695                   ghr_msl_pkg.g_ses_msl_process              := 'N';
696 
697                  IF l_pay_plan in ('ES','EP','IE','FE') and l_essl_table THEN
698                      ghr_msl_pkg.g_ses_msl_process           := 'Y';
699                      l_step_or_rate                          := '00';
700                   END IF;
701 
702                   BEGIN
703                       ghr_pay_calc.sql_main_pay_calc (l_pay_calc_in_data
704                            ,l_pay_calc_out_data
705                            ,l_message_set
706                            ,l_calculated);
707 
708                         IF l_message_set THEN
709                             hr_utility.set_location( l_proc, 40);
710                             l_calculated     := FALSE;
711                             l_mslerrbuf  := hr_utility.get_message;
712                 --			raise msl_error;
713                         END IF;
714                   EXCEPTION
715                       when msl_error then
716                            g_proc := 'ghr_pay_calc';
717                           raise;
718                       when others then
719                     ----BUG 3287299 Start
720                     IF ghr_pay_calc.gm_unadjusted_pay_flg = 'Y' then
721                       l_comment := 'MSL:Error: Unadjusted Basic Pay must be entered in Employee record.';
722                     ELSE
723                       l_comment := 'MSL:Error: See process log for details.';
724                     END IF;
725 
726                     IF upper(p_action) IN ('SHOW') THEN
727                           -- Bug#2383392
728 	  		  --bug # 9329643 added employee number
729                             create_mass_act_prev (
730                             p_effective_date          => l_effective_date,
731                             p_date_of_birth           => p_date_of_birth,
732                             p_full_name               => p_full_name,
733                             p_national_identifier     => p_national_identifier,
734 			    --Bug # 9329643
735 			    p_employee_number         => p_employee_number,
736                             p_duty_station_code       => l_duty_station_code,
737                             p_duty_station_desc       => l_duty_station_desc,
738                             p_personnel_office_id     => l_personnel_office_id,
739                             p_basic_pay               => l_old_basic_pay,
740                             p_new_basic_pay           => null,
741                             --Bug#2383992 Added old_adj_basic_pay
742                             p_adj_basic_pay           => l_old_adj_basic_pay,
743                             p_new_adj_basic_pay       => null,
744                             p_old_avail_pay           => l_old_avail_pay,
745                             p_new_avail_pay           => null,
746                             p_old_loc_diff            => l_old_loc_diff,
747                             p_new_loc_diff            => null,
748                             p_tot_old_sal             => l_tot_old_sal,
749                             p_tot_new_sal             => null,
750                             p_old_auo_pay             => l_old_auo_pay,
751                             p_new_auo_pay             => null,
752                             p_position_id             => l_position_id,
753                             p_position_title          => l_position_title,
754                             -- FWFA Changes Bug#4444609
755                             p_position_number         => l_position_number,
756                             p_position_seq_no         => l_position_seq_no,
757                             -- FWFA Changes
758                             p_org_structure_id        => l_org_structure_id,
759                             p_agency_sub_element_code => l_sub_element_code,
760                             p_person_id               => p_person_id,
761                             p_mass_salary_id          => l_mass_salary_id,
762                             p_sel_flg                 => l_sel_flg,
763                             p_first_action_la_code1   => l_first_action_la_code1,
764                             p_first_action_la_code2   => l_first_action_la_code2,
765                             p_remark_code1            => l_remark_code1,
766                             p_remark_code2            => l_remark_code2,
767                             p_grade_or_level          => l_grade_or_level,
768                             p_step_or_rate            => l_step_or_rate,
769                             p_pay_plan                => l_pay_plan,
770                             p_pay_rate_determinant    =>  null,
771                             p_tenure                  => l_tenure,
772                             p_action                  => p_action,
773                             p_assignment_id           => l_assignment_id,
774                             p_old_other_pay           => l_other_pay,
775                             p_new_other_pay           => null,
776                             -- Bug#2383992
777                             p_old_capped_other_pay    => NULL,
778                             p_new_capped_other_pay    => NULL,
779                             p_old_retention_allowance => l_retention_allowance,
780                             p_new_retention_allowance => NULL,
781                             p_old_supervisory_differential => l_supervisory_differential,
782                             p_new_supervisory_differential => NULL,
783                             -- BUG 3377958 Madhuri
784                             p_organization_name            => l_org_name,
785                             -- BUG 3377958 Madhuri
786                             -- Bug#2383992
787                             -- FWFA changes Bug#4444609
788                             p_input_pay_rate_determinant  => l_pay_rate_determinant,
789                             p_from_pay_table_id         => l_user_table_id,
790                             p_to_pay_table_id           =>  null
791                             -- FWFA changes
792                              );
793                           END IF;
794                           -- Bug#3968005 Replaced parameter l_pay_sel with l_sel_flg
795                           ins_upd_per_extra_info
796                              (p_person_id,l_effective_date, l_sel_flg, l_comment,p_mass_salary_id);
797                           l_comment := NULL;
798                           ------  BUG 3287299 End
799                           hr_utility.set_location('Error in Ghr_pay_calc.sql_main_pay_calc '||
800                                     'Err is '||sqlerrm(sqlcode),20);
801                         l_mslerrbuf := 'Error in ghr_pay_calc  Sql Err is '|| sqlerrm(sqlcode);
802                         g_proc := 'ghr_pay_calc';
803                         raise msl_error;
804                   END;
805 
806         ghr_msl_pkg.g_ses_msl_process              := 'N';
807 
808         l_new_basic_pay        := l_pay_calc_out_data.basic_pay;
809         l_new_locality_adj     := l_pay_calc_out_data.locality_adj;
810         l_new_adj_basic_pay    := l_pay_calc_out_data.adj_basic_pay;
811         l_new_au_overtime      := l_pay_calc_out_data.au_overtime;
812         l_new_availability_pay := l_pay_calc_out_data.availability_pay;
813 
814         --Added by mani related to the bug 5919694
815 	l_out_pay_plan          := l_pay_calc_out_data.out_to_pay_plan;
816 	l_out_grade_id          := l_pay_calc_out_data.out_to_grade_id;
817 	l_out_grade_or_level    := l_pay_calc_out_data.out_to_grade_or_level;
818 
819 
820         l_out_pay_rate_determinant := l_pay_calc_out_data.out_pay_rate_determinant;
821 
822 
823         l_out_step_or_rate        := l_pay_calc_out_data.out_step_or_rate;
824         l_new_retention_allowance :=  l_pay_calc_out_data.retention_allowance;
825         l_new_supervisory_differential := l_supervisory_differential;
826         l_new_other_pay_amount    := l_pay_calc_out_data.other_pay_amount;
827         l_entitled_other_pay      := l_new_other_pay_amount;
828         if l_new_other_pay_amount = 0 then
829            l_new_other_pay_amount := null;
830         end if;
831         l_new_total_salary        := l_pay_calc_out_data.total_salary;
832 
833      hr_utility.set_location('retention_allowance = ' || to_char(l_retention_allowance),10);
834      hr_utility.set_location('Supervisory Diff Amount = ' || to_char(l_supervisory_differential),10);
835 
836 
837 -------------Call Pay cap Procedure
838      begin
839       l_capped_other_pay := ghr_pa_requests_pkg2.get_cop( p_assignment_id  => l_assignment_id
840                                                          ,p_effective_date => l_effective_date);
841       l_old_capped_other_pay :=  l_capped_other_pay;
842 		-- Sundar Added the following if statement to improve performance
843 			if hr_utility.debug_enabled = true then
844 				  hr_utility.set_location('Before Pay Cap    ' || l_proc,21);
845 				  hr_utility.set_location('l_effective_date  ' || l_effective_date,21);
846 				  hr_utility.set_location('l_out_pay_rate_determinant  ' || l_out_pay_rate_determinant,21);
847 				  hr_utility.set_location('l_pay_plan  ' || l_pay_plan,21);
848 				  hr_utility.set_location('l_position_id  ' || to_char(l_position_id),21);
849 				  hr_utility.set_location('l_pay_basis  ' || l_pay_basis,21);
850 				  hr_utility.set_location('person_id  ' || to_char(p_person_id),21);
851 				  hr_utility.set_location('l_new_basic_pay  ' || to_char(l_new_basic_pay),21);
852 				  hr_utility.set_location('l_new_locality_adj  ' || to_char(l_new_locality_adj),21);
853 				  hr_utility.set_location('l_new_adj_basic_pay  ' || to_char(l_new_adj_basic_pay),21);
854 				  hr_utility.set_location('l_new_total_salary  ' || to_char(l_new_total_salary),21);
855 				  hr_utility.set_location('l_entitled_other_pay  ' || to_char(l_entitled_other_pay),21);
856 				  hr_utility.set_location('l_capped_other_pay  ' || to_char(l_capped_other_pay),21);
857 				  hr_utility.set_location('l_new_retention_allowance  ' || to_char(l_new_retention_allowance),21);
858 				  hr_utility.set_location('l_new_supervisory_differential  ' || to_char(l_new_supervisory_differential),21);
859 				  hr_utility.set_location('l_staffing_differential  ' || to_char(l_staffing_differential),21);
860 				  hr_utility.set_location('l_new_au_overtime  ' || to_char(l_new_au_overtime),21);
861 				  hr_utility.set_location('l_new_availability_pay  ' || to_char(l_new_availability_pay),21);
862 
863 			end if;
864 
865 
866       ghr_pay_caps.do_pay_caps_main
867                    (p_pa_request_id        =>    null
868                    ,p_effective_date       =>    l_effective_date
869 		   ,p_duty_station_id      =>    l_duty_station_id --bug# 13414643,13403289
870                    ,p_pay_rate_determinant =>    nvl(l_out_pay_rate_determinant,l_pay_rate_determinant)
871                    ,p_pay_plan             =>    nvl(l_out_pay_plan,l_pay_plan)
872                    ,p_to_position_id       =>    l_position_id
873                    ,p_pay_basis            =>    l_pay_basis
874                    ,p_person_id            =>    p_person_id
875                    ,p_noa_code             =>    nvl(g_first_noa_code,'894')
876                    ,p_basic_pay            =>    l_new_basic_pay
877                    ,p_locality_adj         =>    l_new_locality_adj
878                    ,p_adj_basic_pay        =>    l_new_adj_basic_pay
879                    ,p_total_salary         =>    l_new_total_salary
880                    ,p_other_pay_amount     =>    l_entitled_other_pay
881                    ,p_capped_other_pay     =>    l_capped_other_pay
882                    ,p_retention_allowance  =>    l_new_retention_allowance
883                    ,p_retention_allow_percentage => l_retention_allow_perc
884                    ,p_supervisory_allowance =>   l_new_supervisory_differential
885                    ,p_staffing_differential =>   l_staffing_differential
886                    ,p_au_overtime          =>    l_new_au_overtime
887                    ,p_availability_pay     =>    l_new_availability_pay
888                    ,p_adj_basic_message    =>    l_adj_basic_message
889                    ,p_pay_cap_message      =>    l_pay_cap_message
890                    ,p_pay_cap_adj          =>    l_temp_retention_allowance
891                    ,p_open_pay_fields      =>    l_open_pay_fields_caps
892                    ,p_message_set          =>    l_message_set_caps
893                    ,p_total_pay_check      =>    l_total_pay_check);
894 
895 
896              l_new_other_pay_amount := nvl(l_capped_other_pay,l_entitled_other_pay);
897 
898 			-- Sundar Added the following statement to improve performance
899 			if hr_utility.debug_enabled = true then
900 				  hr_utility.set_location('After Pay Cap    ' || l_proc,22);
901 				  hr_utility.set_location('l_effective_date  ' || l_effective_date,22);
902 				  hr_utility.set_location('l_out_pay_rate_determinant  ' || l_out_pay_rate_determinant,22);
903 				  hr_utility.set_location('l_pay_plan  ' || l_pay_plan,22);
904 				  hr_utility.set_location('l_position_id  ' || to_char(l_position_id),22);
905 				  hr_utility.set_location('l_pay_basis  ' || l_pay_basis,22);
906 				  hr_utility.set_location('person_id  ' || to_char(p_person_id),22);
907 				  hr_utility.set_location('l_new_basic_pay  ' || to_char(l_new_basic_pay),22);
908 				  hr_utility.set_location('l_new_locality_adj  ' || to_char(l_new_locality_adj),22);
909 				  hr_utility.set_location('l_new_adj_basic_pay  ' || to_char(l_new_adj_basic_pay),22);
910 				  hr_utility.set_location('l_new_total_salary  ' || to_char(l_new_total_salary),22);
911 				  hr_utility.set_location('l_entitled_other_pay  ' || to_char(l_entitled_other_pay),22);
912 				  hr_utility.set_location('l_capped_other_pay  ' || to_char(l_capped_other_pay),22);
913 				  hr_utility.set_location('l_new_retention_allowance  ' || to_char(l_new_retention_allowance),22);
914 				  hr_utility.set_location('l_new_supervisory_differential  ' || to_char(l_new_supervisory_differential),22);
915 				  hr_utility.set_location('l_staffing_differential  ' || to_char(l_staffing_differential),22);
916 				  hr_utility.set_location('l_new_au_overtime  ' || to_char(l_new_au_overtime),22);
917 				  hr_utility.set_location('l_new_availability_pay  ' || to_char(l_new_availability_pay),22);
918 			end if;
919 
920        IF l_pay_cap_message THEN
921 			IF nvl(l_temp_retention_allowance,0) > 0 THEN
922 			  l_comment := 'MSL: Exceeded Total Cap - reduce Retention Allow to '
923 					|| to_char(l_temp_retention_allowance);
924 			  -- Bug#3968005 Replaced l_pay_sel with l_sel_flg
925 			  l_sel_flg := 'N';
926 			ELSE
927 			  l_comment := 'MSL: Exceeded Total cap - pls review.';
928 			END IF;
929        ELSIF l_adj_basic_message THEN
930           l_comment := 'MSL: Exceeded Adjusted Pay Cap - Locality reduced.';
931        END IF;
932 
933        -- Bug 2639698 Sundar
934 	   IF (l_old_basic_pay > l_new_basic_pay) THEN
935 			l_comment_sal := 'MSL: From Basic Pay exceeds To Basic Pay.';
936        END IF;
937 	   -- End Bug 2639698
938 
939        IF l_pay_cap_message or l_adj_basic_message THEN
940 			-- Bug 2639698
941 		  IF (l_comment_sal IS NOT NULL) THEN
942 		     l_comment := l_comment_sal || ' ' || l_comment;
943 		  END IF;
944 		  -- End Bug 2639698
945 	     -- Bug#3968005 Replaced parameter l_pay_sel with l_sel_flg
946              ins_upd_per_extra_info
947                (p_person_id,l_effective_date, l_sel_flg, l_comment,p_mass_salary_id);
948           l_comment := NULL;
949        --------------------Bug 2639698 Sundar To add comments
950 	   -- Should create comments only if comments need to be inserted
951        ELSIF l_comment_sal IS NOT NULL THEN
952             -- Bug#3968005 Replaced parameter l_pay_sel with l_sel_flg
953 	    ins_upd_per_extra_info
954                (p_person_id,l_effective_date, l_sel_flg, l_comment_sal,p_mass_salary_id);
955 	   END IF;
956 
957        l_comment_sal := NULL; -- bug 2639698
958      exception
959           when msl_error then
960                raise;
961           when others then
962                hr_utility.set_location('Error in ghr_pay_caps.do_pay_caps_main ' ||
963                                 'Err is '||sqlerrm(sqlcode),23);
964                     l_mslerrbuf := 'Error in do_pay_caps_main  Sql Err is '|| sqlerrm(sqlcode);
965                     raise msl_error;
966      end;
967 
968 
969                 IF upper(p_action) IN ('SHOW','REPORT') THEN
970                           -- Bug#2383392
971 
972 
973 		  --6753050    modified if user manually changes position table from special
974                   -- pay table identifier to '0000' then PRD should change to '0'
975                   If  l_pay_rate_determinant  = '6' and
976           	      get_user_table_name(l_pay_table_id) = '0000' then
977 		      l_out_pay_rate_determinant  := '0';
978                   End If;
979      	          --6753050
980 		  --bug # 9329643 added employee number
981                     create_mass_act_prev (
982                         p_effective_date          => l_effective_date,
983                         p_date_of_birth           => p_date_of_birth,
984                         p_full_name               => p_full_name,
985                         p_national_identifier     => p_national_identifier,
986 			--Bug # 9329643
987 			p_employee_number         => p_employee_number,
988                         p_duty_station_code       => l_duty_station_code,
989                         p_duty_station_desc       => l_duty_station_desc,
990                         p_personnel_office_id     => l_personnel_office_id,
991                         p_basic_pay               => l_old_basic_pay,
992                         p_new_basic_pay           => l_new_basic_pay,
993                         --Bug#2383992 Added old_adj_basic_pay
994                         p_adj_basic_pay           => l_old_adj_basic_pay,
995                         p_new_adj_basic_pay       => l_new_adj_basic_pay,
996                         p_old_avail_pay           => l_old_avail_pay,
997                         p_new_avail_pay           =>  l_new_availability_pay,
998                         p_old_loc_diff            => l_old_loc_diff,
999                         p_new_loc_diff            => l_new_locality_adj,
1000                         p_tot_old_sal             => l_tot_old_sal,
1001                         p_tot_new_sal             =>   l_new_total_salary,
1002                         p_old_auo_pay             => l_old_auo_pay,
1003                         p_new_auo_pay             =>   l_new_au_overtime,
1004                         p_position_id             => l_position_id,
1005                         p_position_title          => l_position_title,
1006                         -- FWFA Changes Bug#4444609
1007                         p_position_number         => l_position_number,
1008                         p_position_seq_no         => l_position_seq_no,
1009                         -- FWFA Changes
1010                         p_org_structure_id        => l_org_structure_id,
1011                         p_agency_sub_element_code => l_sub_element_code,
1012                         p_person_id               => p_person_id,
1013                         p_mass_salary_id          => l_mass_salary_id,
1014                         p_sel_flg                 => l_sel_flg,
1015                         p_first_action_la_code1   => l_first_action_la_code1,
1016                         p_first_action_la_code2   => l_first_action_la_code2,
1017                         p_remark_code1            => l_remark_code1,
1018                         p_remark_code2            => l_remark_code2,
1019                         p_grade_or_level          => NVL(l_out_grade_or_level,l_grade_or_level),
1020                         p_step_or_rate            => l_step_or_rate,
1021                         p_pay_plan                => NVL(l_out_pay_plan,l_pay_plan),
1022                         -- FWFA Changes Bug#4444609
1023                         p_pay_rate_determinant    => NVL(l_out_pay_rate_determinant,l_pay_rate_determinant),
1024                         -- FWFA Changes
1025                         p_tenure                  => l_tenure,
1026                         p_action                  => p_action,
1027                         p_assignment_id           => l_assignment_id,
1028                         p_old_other_pay           => l_other_pay,
1029                         p_new_other_pay           => l_new_other_pay_amount,
1030                         -- Bug#2383992
1031                         p_old_capped_other_pay    => l_old_capped_other_pay,--NULL,
1032                         p_new_capped_other_pay    => l_capped_other_pay,
1033                         p_old_retention_allowance => l_retention_allowance,
1034                         p_new_retention_allowance => l_new_retention_allowance,
1035                         p_old_supervisory_differential => l_supervisory_differential,
1036                         p_new_supervisory_differential => l_new_supervisory_differential,
1037                         -- BUG 3377958 Madhuri
1038                         p_organization_name            => l_org_name,
1039                         -- Bug#2383992
1040                         -- FWFA Changes Bug#4444609
1041                         p_input_pay_rate_determinant   => l_pay_rate_determinant,
1042                         p_from_pay_table_id            => l_pay_calc_out_data.pay_table_id,
1043                         p_to_pay_table_id              => l_pay_calc_out_data.calculation_pay_table_id
1044                         -- FWFA Changes
1045                          );
1046                 ELSIF upper(p_action) = 'CREATE' then
1047 
1048                     BEGIN
1049                         -- Bug#5089732 Used the overloaded procedure.
1050                         get_pay_plan_and_table_id
1051                           (l_pay_rate_determinant,p_person_id,
1052                            l_position_id,l_effective_date,
1053                            l_grade_id, l_to_grade_id,l_assignment_id,'CREATE',
1054                            l_pay_plan,l_to_pay_plan,l_pay_table_id,
1055                            l_grade_or_level, l_to_grade_or_level, l_step_or_rate,
1056                            l_pay_basis);
1057                      EXCEPTION
1058                        when msl_error then
1059  		               l_mslerrbuf := hr_utility.get_message;
1060                        raise;
1061                      END;
1062 
1063 		     --6753050    modified if user manually changes position table from special
1064                      -- pay table identifier to '0000' then PRD should change to '0'
1065                      If l_pay_rate_determinant  = '6' and
1066           	        get_user_table_name(l_pay_table_id) = '0000' then
1067    		        l_pay_rate_determinant  := '0';
1068                      End If;
1069      	             --6753050
1070 
1071                      assign_to_sf52_rec(
1072                        p_person_id,
1073                        p_first_name,
1074                        p_last_name,
1075                        p_middle_names,
1076                        p_national_identifier,
1077                        p_date_of_birth,
1078                        l_effective_date,
1079                        l_assignment_id,
1080                        l_tenure,
1081                        -- Bug#5089732
1082                        NVL(l_out_grade_id,l_to_grade_id),
1083                        NVL(l_out_pay_plan,l_to_pay_plan),
1084                        NVL(l_out_grade_or_level,l_to_grade_or_level),
1085                        -- Bug#5089732
1086                        l_step_or_rate,
1087                        l_annuitant_indicator,
1088                        -- FWFA Changes Bug#4444609
1089                        NVL(l_out_pay_rate_determinant,l_pay_rate_determinant),
1090                        -- FWFA Changes
1091                        l_work_schedule,
1092                        l_part_time_hour,
1093                        l_pos_ei_data.poei_information7, --FLSA Category
1094                        l_pos_ei_data.poei_information8, --Bargaining Unit Status
1095                        l_pos_ei_data.poei_information11,--Functional Class
1096                        l_pos_ei_data.poei_information16,--Supervisory Status,
1097                        l_new_basic_pay,
1098                        l_new_locality_adj,
1099                        l_new_adj_basic_pay,
1100                        l_new_total_salary,
1101                        l_other_pay,
1102                        l_new_other_pay_amount,
1103                        l_new_au_overtime,
1104                        l_new_availability_pay,
1105                        l_new_retention_allowance,
1106                        l_retention_allow_perc,
1107                        l_new_supervisory_differential,
1108                        l_supervisory_diff_perc,
1109                        l_staffing_differential,
1110                        l_duty_station_id,
1111                        l_duty_station_code,
1112                        l_duty_station_desc,
1113                        -- FWFA Changes  Bug#4444609
1114                        l_pay_rate_determinant,
1115                        l_pay_calc_out_data.pay_table_id,
1116                        l_pay_calc_out_data.calculation_pay_table_id,
1117                        -- FWFA Changes
1118                        l_lac_sf52_rec,
1119                        l_sf52_rec);
1120 
1121 					  BEGIN
1122 						   ghr_mass_actions_pkg.pay_calc_rec_to_sf52_rec
1123 							   (l_pay_calc_out_data,
1124 								l_sf52_rec);
1125 					  EXCEPTION
1126 						  when others then
1127 							  hr_utility.set_location('Error in Ghr_mass_actions_pkg.pay_calc_rec_to_sf52_rec '||
1128 										'Err is '||sqlerrm(sqlcode),20);
1129 							 l_mslerrbuf := 'Error in ghr_mass_act_pkg.pay_calc_to_sf52  Sql Err is '|| sqlerrm(sqlcode);
1130 							 raise msl_error;
1131 					  END;
1132 
1133                    BEGIN
1134 		               l_sf52_rec.mass_action_id := p_mass_salary_id;
1135                        l_sf52_rec.rpa_type := 'MSL';
1136                        g_proc  := 'Create_sf52_recrod';
1137                        ghr_mass_changes.create_sf52_for_mass_changes
1138                            (p_mass_action_type => 'MASS_SALARY_CHG',
1139                             p_pa_request_rec  => l_sf52_rec,
1140                             p_errbuf           => l_errbuf,
1141                             p_retcode          => l_retcode);
1142 
1143                        ------ Added by Dinkar for List reports problem
1144                        ---------------------------------------
1145                        IF l_errbuf IS NULL THEN
1146 
1147 					       DECLARE
1148 					           l_pa_request_number ghr_pa_requests.request_number%TYPE;
1149 						   BEGIN
1150               			       l_pa_request_number   :=
1151 								     l_sf52_rec.request_number||'-'||p_mass_salary_id;
1152 
1153 						       ghr_par_upd.upd
1154                                       (p_pa_request_id             => l_sf52_rec.pa_request_id,
1155                                        p_object_version_number     => l_sf52_rec.object_version_number,
1156                                        p_request_number            => l_pa_request_number
1157                                       );
1158 						   END;
1159 
1160                            pr('No error in create sf52 ');
1161                            --Bug # 9329643 Modified SSN to Emp No
1162                            ghr_mto_int.log_message(
1163                               p_procedure => 'Successful Completion',
1164                               p_message   => 'Name: '||p_full_name ||
1165                               ' Emp No: ' || p_employee_number||
1166                               '  Mass Salary : '||
1167                               p_mass_salary ||' SF52 Successfully completed');
1168 
1169                            create_lac_remarks(l_pa_request_id,
1170                                            l_sf52_rec.pa_request_id);
1171 
1172                            -- Added by Enunez 11-SEP-1999
1173                            IF l_lac_sf52_rec.first_action_la_code1 IS NULL THEN
1174                                -- Added by Edward Nunez for 894 rules
1175                                g_proc := 'Apply_894_Rules';
1176                                --Bug 2012782 fix
1177                                IF l_out_pay_rate_determinant IS NULL THEN
1178                                    l_out_pay_rate_determinant := l_pay_rate_determinant;
1179                                END IF;
1180                                --Bug 2012782 fix end
1181                                ghr_lacs_remarks.Apply_894_Rules(
1182                                        l_sf52_rec.pa_request_id,
1183                                        l_out_pay_rate_determinant,
1184                                        l_pay_rate_determinant,
1185                                        l_out_step_or_rate,
1186                                        l_executive_order_number,
1187                                        l_executive_order_date,
1188                                        l_opm_issuance_number,
1189                                        l_opm_issuance_date,
1190                                        l_errbuf,
1191                                        l_retcode
1192                                        );
1193                                IF l_errbuf IS NOT NULL THEN
1194                                    IF sqlcode = 0000 THEN
1195                                    l_mslerrbuf := l_mslerrbuf || '; ' || l_errbuf;
1196                                    ELSE
1197                                    l_mslerrbuf := l_mslerrbuf || ' ' || l_errbuf || ' Sql Err is: '
1198                                                                   || sqlerrm(sqlcode);
1199                                    END IF;
1200                                    RAISE msl_error;
1201                                END IF;
1202                            END IF; -- IF l_lac_sf52_rec.first_action_la_code1
1203                            g_proc := 'update_SEL_FLG';
1204 
1205                            update_SEL_FLG(p_PERSON_ID,l_effective_date);
1206 
1207                            COMMIT;
1208                        ELSE
1209                            pr('Error in create sf52',l_errbuf);
1210                            l_recs_failed := l_recs_failed + 1;
1211                            -- Raising MSL_ERROR is not required as the process log
1212                            -- was updated in ghr_mass_changes.create_sf52_for_mass_changes pkg itself.
1213                            --raise msl_error;
1214                        END IF; -- if l_errbuf is null then
1215                    EXCEPTION
1216                       WHEN msl_error then raise;
1217                       WHEN others then  null;
1218                       l_mslerrbuf := 'Error in ghr_mass_chg.create_sf52 '||
1219                                    ' Sql Err is '|| sqlerrm(sqlcode);
1220                       RAISE msl_error;
1221                    END;
1222                END IF; --  IF upper(p_action) IN ('SHOW','REPORT') THEN
1223             END IF; -- end if for check_select_flg
1224          END IF; -- end if for p_action = 'REPORT'
1225 
1226 
1227          L_row_cnt := L_row_cnt + 1;
1228          IF upper(p_action) <> 'CREATE' THEN
1229              IF L_row_cnt > 50 then
1230                  COMMIT;
1231                  L_row_cnt := 0;
1232              END IF;
1233          END IF;
1234       EXCEPTION
1235          WHEN MSL_ERROR THEN
1236                HR_UTILITY.SET_LOCATION('Error occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),10);
1237                begin
1238                 ------  BUG 3287299 -- Not to rollback for preview.
1239        	        if upper(p_action) <> 'SHOW' then
1240                   ROLLBACK TO EXECUTE_MSL_SP;
1241                 end if;
1242                EXCEPTION
1243                   WHEN OTHERS THEN NULL;
1244                END;
1245 	       --Bug # 9329643 Modified SSN to Emp No
1246                l_log_text  := 'Error in '||l_proc||' '||
1247                               ' For Mass Salary Name : '||p_mass_salary||
1248                               'Name: '|| p_full_name || ' Emp No: ' || p_employee_number ||
1249                               l_mslerrbuf;
1250                hr_utility.set_location('before creating entry in log file',10);
1251                l_recs_failed := l_recs_failed + 1;
1252             begin
1253                ghr_mto_int.log_message(
1254                               p_procedure => g_proc,
1255                               p_message   => l_log_text);
1256             exception
1257                 when others then
1258                     hr_utility.set_message(8301, 'GHR_38475_ERROR_LOG_FAILURE');
1259                     hr_utility.raise_error;
1260             end;
1261          when others then
1262                HR_UTILITY.SET_LOCATION('Error (Others) occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),20);
1263                BEGIN
1264                  ROLLBACK TO EXECUTE_MSL_SP;
1265                EXCEPTION
1266                  WHEN OTHERS THEN NULL;
1267                END;
1268 	       --Bug # 9329643 Modified SSN to Emp No
1269                l_log_text  := 'Error (others) in '||l_proc||
1270                               ' For Mass Salary Name : '||p_mass_salary||
1271                               'Name: '|| p_full_name || ' Emp No: ' || p_employee_number ||
1272                               ' Sql Err is '||sqlerrm(sqlcode);
1273                hr_utility.set_location('before creating entry in log file',20);
1274                l_recs_failed := l_recs_failed + 1;
1275             begin
1276                ghr_mto_int.log_message(
1277                               p_procedure => g_proc,
1278                               p_message   => l_log_text);
1279             exception
1280                 when others then
1281                     hr_utility.set_message(8301, 'Create Error Log failed');
1282                     hr_utility.raise_error;
1283             end;
1284       END;
1285 
1286 --
1287 -- msl_process END
1288 
1289 --
1290 --
1291 BEGIN
1292   g_proc  := 'execute_msl';
1293   hr_utility.set_location('Entering    ' || l_proc,5);
1294 
1295   g_first_noa_code     := null;
1296   p_retcode  := 0;
1297   BEGIN
1298     FOR msl IN ghr_msl (p_mass_salary_id)
1299     LOOP
1300         p_mass_salary    := msl.name;
1301         l_effective_date := msl.effective_date;
1302         l_mass_salary_id := msl.mass_salary_id;
1303         l_user_table_id  := msl.user_table_id;
1304         l_submit_flag    := msl.submit_flag;
1305         l_executive_order_number := msl.executive_order_number;
1306         l_executive_order_date :=  msl.executive_order_date;
1307         l_opm_issuance_number  :=  msl.opm_issuance_number;
1308         l_opm_issuance_date    :=  msl.opm_issuance_date;
1309         l_pa_request_id  := msl.pa_request_id;
1310         l_rowid          := msl.rowid;
1311         l_p_ORGANIZATION_ID        := msl.ORGANIZATION_ID;
1312         l_p_DUTY_STATION_ID        := msl.DUTY_STATION_ID;
1313         l_p_PERSONNEL_OFFICE_ID    := msl.PERSONNEL_OFFICE_ID;
1314         l_p_AGENCY_CODE_SUBELEMENT := msl.AGENCY_CODE_SUBELEMENT;
1315 	    l_process_type             := msl.process_type;
1316 
1317 		pr('Pa request id is '||to_char(l_pa_request_id));
1318        exit;
1319     END LOOP;
1320   EXCEPTION
1321     when REC_BUSY then
1322          hr_utility.set_location('Mass Salary is in use',1);
1323          l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
1324         -- raise error;
1325         hr_utility.set_message(8301, 'GHR_38477_LOCK_ON_MSL');
1326         hr_utility.raise_error;
1327 --
1328     when others then
1329       hr_utility.set_location('Error in '||l_proc||' Sql err is '||sqlerrm(sqlcode),1);
1330 --    raise_application_error(-20111,'Error while selecting from Ghr Mass Salaries');
1331      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
1332      raise msl_error;
1333   END;
1334    --Bug#5063304 Moved this cursor from execute_msl to this place.
1335   FOR c_pay_tab_essl_rec in c_pay_tab_essl
1336   LOOP
1337       l_essl_table := TRUE;
1338   EXIT;
1339   END LOOP;
1340 
1341   IF l_process_type = 'P' THEN
1342 
1343 	hr_utility.set_location('befo perc' || l_proc,5);
1344 	execute_msl_perc( p_errbuf,
1345                           p_retcode,
1346                           p_mass_salary_id,
1347                           p_action );
1348 
1349   ELSIF l_process_type = 'T' THEN
1350 
1351 	ghr_mlc_pkg.execute_msl_pay( p_errbuf,
1352 				 p_retcode,
1353 				 p_mass_salary_id,
1354 				 p_action );
1355 
1356   ELSIF l_process_type = 'L' THEN
1357 
1358 	ghr_mlc_pkg.execute_mlc( p_errbuf,
1359 				 p_retcode,
1360 				 p_mass_salary_id,
1361 				 p_action );
1362 
1363   ELSIF l_process_type = 'R' THEN
1364      hr_utility.set_location('befo proc' || l_proc,5);
1365      execute_msl_ses_range( p_errbuf,
1366                       p_retcode,
1367                       p_mass_salary_id,
1368                       p_action);
1369   ELSE
1370 
1371   g_effective_date := l_effective_date;
1372 
1373 
1374 
1375 -- Bug 3315432 Madhuri
1376 --
1377   FOR pp_prd IN cur_pp_prd(p_mass_salary_id)
1378   LOOP
1379 	rec_pp_prd(l_index).pay_plan := pp_prd.pay_plan;
1380 	rec_pp_prd(l_index).prd      := pp_prd.prd;
1381 	l_index := l_index +1;
1382   END LOOP;
1383 
1384   IF upper(p_action) = 'CREATE' then
1385      ghr_mto_int.set_log_program_name('GHR_MSL_PKG');
1386   ELSE
1387      ghr_mto_int.set_log_program_name('MSL_'||p_mass_salary);
1388   END IF;
1389 
1390   get_lac_dtls(l_pa_request_id, l_lac_sf52_rec);
1391 
1392   hr_utility.set_location('After fetch msl '||to_char(l_effective_date)||' '||to_char(l_user_table_id),20);
1393   IF l_p_ORGANIZATION_ID is not null then
1394     FOR per IN cur_people_org (l_effective_date,l_p_ORGANIZATION_ID)
1395     LOOP
1396 
1397         -- Bug#5719467 Initialised the variable l_mslerrbuf to avoid ora error 6502
1398         l_mslerrbuf := NULL;
1399         -- Bug#5063304 Added the following IF Condition.
1400         IF  NVL(l_p_organization_id,per.organization_id) = per.organization_id THEN
1401             FOR ast IN cur_ast (per.assignment_status_type_id) LOOP
1402                                 --
1403                 -- Set all local variables to NULL
1404                 l_personnel_office_id  := NULL;
1405                 l_org_structure_id     := NULL;
1406                 l_position_title       := NULL;
1407                 l_position_number      := NULL;
1408                 l_position_seq_no      := NULL;
1409                 l_sub_element_code     := NULL;
1410                 l_duty_station_id      := NULL;
1411                 l_tenure               := NULL;
1412                 l_annuitant_indicator  := NULL;
1413                 l_pay_rate_determinant := NULL;
1414                 l_work_schedule        := NULL;
1415                 l_part_time_hour       := NULL;
1416                 l_to_grade_id          := NULL;
1417                 l_pay_plan             := NULL;
1418                 l_to_pay_plan          := NULL;
1419                 l_pay_table_id         := NULL;
1420                 l_grade_or_level       := NULL;
1421                 l_to_grade_or_level    := NULL;
1422                 l_step_or_rate         := NULL;
1423                 l_pay_basis            := NULL;
1424                 l_elig_flag            := FALSE;
1425                 --
1426                 hr_utility.set_location('SSN: '||per.national_identifier,1000);
1427                 BEGIN
1428                 fetch_and_validate_emp(
1429                                 p_action                => p_action
1430                                ,p_mass_salary_id        => p_mass_salary_id
1431                                ,p_mass_salary_name      => p_mass_salary
1432                                ,p_full_name             => per.full_name
1433                                ,p_national_identifier   => per.national_identifier
1434 			       --Bug # 9329643
1435 			       ,p_employee_number       => per.employee_number
1436                                ,p_assignment_id         => per.assignment_id
1437                                ,p_person_id             => per.person_id
1438                                ,p_position_id           => per.position_id
1439                                ,p_grade_id              => per.grade_id
1440                                ,p_business_group_id     => per.business_group_id
1441                                ,p_location_id           => per.location_id
1442                                ,p_organization_id       => per.organization_id
1443                                ,p_msl_organization_id    => l_p_organization_id
1444                                ,p_msl_duty_station_id    => l_p_duty_station_id
1445                                ,p_msl_personnel_office_id   => l_p_personnel_office_id
1446                                ,p_msl_agency_code_subelement => l_p_agency_code_subelement
1447                                ,p_msl_user_table_id         => l_user_table_id
1448                                ,p_rec_pp_prd                => rec_pp_prd
1449                                ,p_personnel_office_id   => l_personnel_office_id
1450                                ,p_org_structure_id      => l_org_structure_id
1451                                ,p_position_title        => l_position_title
1452                                ,p_position_number       => l_position_number
1453                                ,p_position_seq_no       => l_position_seq_no
1454                                ,p_subelem_code          => l_sub_element_code
1455                                ,p_duty_station_id       => l_duty_station_id
1456                                ,p_tenure                => l_tenure
1457                                ,p_annuitant_indicator   => l_annuitant_indicator
1458                                ,p_pay_rate_determinant  => l_pay_rate_determinant
1459                                ,p_work_schedule         => l_work_schedule
1460                                ,p_part_time_hour        => l_part_time_hour
1461                                ,p_to_grade_id           => l_to_grade_id
1462                                ,p_pay_plan              => l_pay_plan
1463                                ,p_to_pay_plan           => l_to_pay_plan
1464                                ,p_pay_table_id          => l_pay_table_id
1465                                ,p_grade_or_level        => l_grade_or_level
1466                                ,p_to_grade_or_level     => l_to_grade_or_level
1467                                ,p_step_or_rate          => l_step_or_rate
1468                                ,p_pay_basis             => l_pay_basis
1469                                ,p_elig_flag             => l_elig_flag
1470                                );
1471                 EXCEPTION
1472                     --WHEN fetch_validate_error THEN
1473                     --    l_elig_flag := FALSE;
1474                     WHEN OTHERS THEN
1475                         l_elig_flag := FALSE;
1476                 END;
1477 
1478                 IF l_elig_flag THEN
1479 
1480                     msl_process( p_assignment_id  => per.assignment_id
1481                               ,p_person_id => per.person_id
1482                               ,p_position_id  => per.position_id
1483                               ,p_grade_id => per.grade_id
1484                               ,p_business_group_id => per.business_group_id
1485                               ,p_location_id => per.location_id
1486                               ,p_organization_id => per.organization_id
1487                               ,p_date_of_birth => per.date_of_birth
1488                               ,p_first_name => per.first_name
1489                               ,p_last_name => per.last_name
1490                               ,p_full_name => per.full_name
1491                               ,p_middle_names => per.middle_names
1492                               ,p_national_identifier => per.national_identifier
1493 			      --Bug # 9329643
1494 			      ,p_employee_number     => per.employee_number
1495                               ,p_personnel_office_id   => l_personnel_office_id
1496                             ,p_org_structure_id      => l_org_structure_id
1497                             ,p_position_title        => l_position_title
1498                             ,p_position_number       => l_position_number
1499                             ,p_position_seq_no       => l_position_seq_no
1500                             ,p_subelem_code          => l_sub_element_code
1501                             ,p_duty_station_id       => l_duty_station_id
1502                             ,p_tenure                => l_tenure
1503                             ,p_annuitant_indicator   => l_annuitant_indicator
1504                             ,p_pay_rate_determinant  => l_pay_rate_determinant
1505                             ,p_work_schedule         => l_work_schedule
1506                             ,p_part_time_hour        => l_part_time_hour
1507                             ,p_to_grade_id           => l_to_grade_id
1508                             ,p_pay_plan              => l_pay_plan
1509                             ,p_to_pay_plan           => l_to_pay_plan
1510                             ,p_pay_table_id          => l_pay_table_id
1511                             ,p_grade_or_level        => l_grade_or_level
1512                             ,p_to_grade_or_level     => l_to_grade_or_level
1513                             ,p_step_or_rate          => l_step_or_rate
1514                             ,p_pay_basis             => l_pay_basis
1515                               );
1516                 END IF;
1517             END LOOP;
1518         END IF;
1519     END LOOP;
1520   ELSE
1521     FOR per IN cur_people (l_effective_date)
1522     LOOP
1523         -- Bug#5719467 Initialised the variable l_mslerrbuf to avoid ora error 6502
1524         l_mslerrbuf := NULL;
1525         FOR ast IN cur_ast (per.assignment_status_type_id)
1526         LOOP
1527             --
1528             -- Set all local variables to NULL
1529             l_personnel_office_id  := NULL;
1530             l_org_structure_id     := NULL;
1531             l_position_title       := NULL;
1532             l_position_number      := NULL;
1533             l_position_seq_no      := NULL;
1534             l_sub_element_code     := NULL;
1535             l_duty_station_id      := NULL;
1536             l_tenure               := NULL;
1537             l_annuitant_indicator  := NULL;
1538             l_pay_rate_determinant := NULL;
1539             l_work_schedule        := NULL;
1540             l_part_time_hour       := NULL;
1541             l_to_grade_id          := NULL;
1542             l_pay_plan             := NULL;
1543             l_to_pay_plan          := NULL;
1544             l_pay_table_id         := NULL;
1545             l_grade_or_level       := NULL;
1546             l_to_grade_or_level    := NULL;
1547             l_step_or_rate         := NULL;
1548             l_pay_basis            := NULL;
1549             l_elig_flag            := FALSE;
1550             --
1551             hr_utility.set_location('SSN: '||per.national_identifier,2000);
1552             BEGIN
1553                 fetch_and_validate_emp(
1554                 p_action                => p_action
1555                ,p_mass_salary_id        => p_mass_salary_id
1556                ,p_mass_salary_name      => p_mass_salary
1557                ,p_full_name             => per.full_name
1558                ,p_national_identifier   => per.national_identifier
1559 	       --Bug # 9329643
1560 	       ,p_employee_number       => per.employee_number
1561                ,p_assignment_id         => per.assignment_id
1562                ,p_person_id             => per.person_id
1563                ,p_position_id           => per.position_id
1564                ,p_grade_id              => per.grade_id
1565                ,p_business_group_id     => per.business_group_id
1566                ,p_location_id           => per.location_id
1567                ,p_organization_id       => per.organization_id
1568                ,p_msl_organization_id    => l_p_organization_id
1569                ,p_msl_duty_station_id    => l_p_duty_station_id
1570                ,p_msl_personnel_office_id   => l_p_personnel_office_id
1571                ,p_msl_agency_code_subelement => l_p_agency_code_subelement
1572                ,p_msl_user_table_id         => l_user_table_id
1573                ,p_rec_pp_prd                => rec_pp_prd
1574                ,p_personnel_office_id   => l_personnel_office_id
1575                ,p_org_structure_id      => l_org_structure_id
1576                ,p_position_title        => l_position_title
1577                ,p_position_number       => l_position_number
1578                ,p_position_seq_no       => l_position_seq_no
1579                ,p_subelem_code          => l_sub_element_code
1580                ,p_duty_station_id       => l_duty_station_id
1581                ,p_tenure                => l_tenure
1582                ,p_annuitant_indicator   => l_annuitant_indicator
1583                ,p_pay_rate_determinant  => l_pay_rate_determinant
1584                ,p_work_schedule         => l_work_schedule
1585                ,p_part_time_hour        => l_part_time_hour
1586                ,p_to_grade_id           => l_to_grade_id
1587                ,p_pay_plan              => l_pay_plan
1588                ,p_to_pay_plan           => l_to_pay_plan
1589                ,p_pay_table_id          => l_pay_table_id
1590                ,p_grade_or_level        => l_grade_or_level
1591                ,p_to_grade_or_level     => l_to_grade_or_level
1592                ,p_step_or_rate          => l_step_or_rate
1593                ,p_pay_basis             => l_pay_basis
1594                ,p_elig_flag             => l_elig_flag
1595                 );
1596             EXCEPTION
1597                 --WHEN fetch_validate_error THEN
1598                    -- l_elig_flag := FALSE;
1599                 WHEN OTHERS THEN
1600                     l_elig_flag := FALSE;
1601             END;
1602             IF l_elig_flag THEN
1603                 msl_process( p_assignment_id  => per.assignment_id
1604                           ,p_person_id => per.person_id
1605                           ,p_position_id  => per.position_id
1606                           ,p_grade_id => per.grade_id
1607                           ,p_business_group_id => per.business_group_id
1608                           ,p_location_id => per.location_id
1609                           ,p_organization_id => per.organization_id
1610                           ,p_date_of_birth => per.date_of_birth
1611                           ,p_first_name => per.first_name
1612                           ,p_last_name => per.last_name
1613                           ,p_full_name => per.full_name
1614                           ,p_middle_names => per.middle_names
1615                           ,p_national_identifier => per.national_identifier
1616 			  --Bug # 9329643
1617 			  ,p_employee_number => per.employee_number
1618                           ,p_personnel_office_id   => l_personnel_office_id
1619                           ,p_org_structure_id      => l_org_structure_id
1620                           ,p_position_title        => l_position_title
1621                           ,p_position_number       => l_position_number
1622                           ,p_position_seq_no       => l_position_seq_no
1623                           ,p_subelem_code          => l_sub_element_code
1624                           ,p_duty_station_id       => l_duty_station_id
1625                           ,p_tenure                => l_tenure
1626                           ,p_annuitant_indicator   => l_annuitant_indicator
1627                           ,p_pay_rate_determinant  => l_pay_rate_determinant
1628                           ,p_work_schedule         => l_work_schedule
1629                           ,p_part_time_hour        => l_part_time_hour
1630                           ,p_to_grade_id           => l_to_grade_id
1631                           ,p_pay_plan              => l_pay_plan
1632                           ,p_to_pay_plan           => l_to_pay_plan
1633                           ,p_pay_table_id          => l_pay_table_id
1634                           ,p_grade_or_level        => l_grade_or_level
1635                           ,p_to_grade_or_level     => l_to_grade_or_level
1636                           ,p_step_or_rate          => l_step_or_rate
1637                           ,p_pay_basis             => l_pay_basis
1638                           );
1639             END IF;
1640         END LOOP;
1641     END LOOP;
1642   END IF;
1643 
1644 pr('After processing is over ',to_char(l_recs_failed));
1645    --Bug#4016384  Add the RG expired record count to the l_recs_failed count
1646    l_recs_failed := l_recs_failed + g_rg_recs_failed;
1647    IF (l_recs_failed  = 0) THEN
1648      IF UPPER(p_action) = 'CREATE' THEN
1649        BEGIN
1650           UPDATE ghr_mass_salaries
1651              SET submit_flag = 'P'
1652            WHERE rowid = l_rowid;
1653        EXCEPTION
1654          WHEN others THEN
1655            HR_UTILITY.SET_LOCATION('Error in Update ghr_msl  Sql error '||sqlerrm(sqlcode),30);
1656            hr_utility.set_message(8301, 'GHR_38476_UPD_GHR_MSL_FAILURE');
1657            hr_utility.raise_error;
1658        END;
1659      END IF;
1660   ELSE
1661       p_errbuf   := 'Error in '||l_proc || ' Details in GHR_PROCESS_LOG';
1662       p_retcode  := 2;
1663       IF upper(p_action) = 'CREATE' THEN
1664          UPDATE ghr_mass_salaries
1665             SET submit_flag = 'E'
1666           WHERE rowid = l_rowid;
1667       END IF;
1668   END IF;
1669 pr('Before commiting.....');
1670 COMMIT;
1671 pr('After commiting.....',to_char(l_recs_failed));
1672 
1673 END IF;
1674 
1675 EXCEPTION
1676     when others then
1677       HR_UTILITY.SET_LOCATION('Error (Others2) occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),30);
1678       BEGIN
1679         ROLLBACK TO EXECUTE_MSL_SP;
1680       EXCEPTION
1681         WHEN OTHERS THEN NULL;
1682       END;
1683       l_log_text  := 'Error in '||l_proc||
1684                      ' For Mass Salary Name : '||p_mass_salary||
1685                      ' Sql Err is '||sqlerrm(sqlcode);
1686       l_recs_failed := l_recs_failed + 1;
1687       hr_utility.set_location('before creating entry in log file',30);
1688 
1689       p_errbuf   := 'Error in '||l_proc || ' Details in GHR_PROCESS_LOG';
1690       p_retcode  := 2;
1691       IF upper(p_action) = 'CREATE' THEN
1692          UPDATE ghr_mass_salaries
1693             SET submit_flag = 'E'
1694           WHERE rowid = l_rowid;
1695           COMMIT;
1696       END IF;
1697 
1698       BEGIN
1699          ghr_mto_int.log_message(
1700                         p_procedure => g_proc,
1701                         p_message   => l_log_text);
1702       EXCEPTION
1703           WHEN others THEN
1704               hr_utility.set_message(8301, 'Create Error Log failed');
1705               hr_utility.raise_error;
1706       END;
1707 
1708 
1709 END EXECUTE_MSL;
1710 
1711 --
1712 --
1713 --
1714 
1715 -- Function returns the request id.
1716 -- This is coded as a wrapper for fnd_request.submit_request
1717 -- if all the params are passed as null, the submit request is passing all the
1718 -- params as null and so, we get wrong no of params passed error.
1719 --
1720 
1721 FUNCTION submit_conc_req (P_APPLICATION IN VARCHAR2,
1722                               P_PROGRAM IN VARCHAR2,
1723                               P_DESCRIPTION IN VARCHAR2,
1724                               P_START_TIME IN VARCHAR2,
1725                               P_SUB_REQUEST IN BOOLEAN,
1726                               P_ARGUMENT1 IN VARCHAR2,
1727                               P_ARGUMENT2 IN VARCHAR2)
1728    RETURN NUMBER IS
1729 BEGIN
1730   return (fnd_request.submit_request(
1731    APPLICATION    => p_application
1732   ,PROGRAM        => p_program
1733   ,DESCRIPTION    => p_description
1734   ,START_TIME     => p_start_time
1735   ,SUB_REQUEST    => p_sub_request
1736   ,ARGUMENT1      => p_argument1
1737   ,ARGUMENT2      => p_argument2
1738  ));
1739 
1740 END submit_conc_req;
1741 
1742 --
1743 --
1744 --
1745 -- Procedure Deletes all records processed by the report
1746 --
1747 
1748 PROCEDURE purge_processed_recs(p_session_id in number,
1749                                p_err_buf out nocopy varchar2) IS
1750 BEGIN
1751    p_err_buf := null;
1752    DELETE from ghr_mass_actions_preview
1753     WHERE mass_action_type = 'SALARY'
1754       AND session_id  = p_session_id;
1755    COMMIT;
1756 
1757 EXCEPTION
1758    WHEN others THEN
1759      p_err_buf := 'Sql err '|| sqlerrm(sqlcode);
1760 END;
1761 
1762 -- BUG 3377958 Madhuri
1763 -- Added p_org_name to this proc for MSL form changes
1764 --
1765 PROCEDURE pop_dtls_from_pa_req(p_person_id in number,p_effective_date in date,
1766          p_mass_salary_id in number, p_org_name in varchar2, p_employee_number in varchar2) IS
1767 
1768 CURSOR ghr_pa_req_cur IS
1769 SELECT EMPLOYEE_DATE_OF_BIRTH,
1770        substr(EMPLOYEE_LAST_NAME||', '||EMPLOYEE_FIRST_NAME||' '||
1771               EMPLOYEE_MIDDLE_NAMES,1,240)  FULL_NAME,
1772        EMPLOYEE_NATIONAL_IDENTIFIER,
1773        DUTY_STATION_CODE,
1774        DUTY_STATION_DESC,
1775        PERSONNEL_OFFICE_ID,
1776        FROM_BASIC_PAY,
1777        TO_BASIC_PAY,
1778        --Bug#2383992
1779        FROM_ADJ_BASIC_PAY,
1780        TO_ADJ_BASIC_PAY,
1781        --Bug#2383992
1782        NULL FROM_AVAILABILITY_PAY,
1783        TO_AVAILABILITY_PAY,
1784        FROM_LOCALITY_ADJ,
1785        TO_LOCALITY_ADJ,
1786        FROM_TOTAL_SALARY,
1787        TO_TOTAL_SALARY,
1788        NULL FROM_AU_OVERTIME,
1789        TO_AU_OVERTIME,
1790        TO_POSITION_ID POSITION_ID,
1791        TO_POSITION_TITLE POSITION_TITLE,
1792        -- FWFA Changes Bug#4444609
1793        TO_POSITION_NUMBER POSITION_NUMBER,
1794        TO_POSITION_SEQ_NO POSITION_SEQ_NO,
1795        -- FWFA Changes
1796        null org_structure_id,
1797        FROM_AGENCY_CODE,
1798        PERSON_ID,
1799 --       p_mass_salary_id
1800        'Y'  Sel_flag,
1801        first_action_la_code1,
1802        first_action_la_code2,
1803        NULL REMARK_CODE1,
1804        NULL REMARK_CODE2,
1805        from_grade_or_level,
1806        from_step_or_rate,
1807        from_pay_plan,
1808        PAY_RATE_DETERMINANT,
1809        TENURE,
1810        EMPLOYEE_ASSIGNMENT_ID,
1811        FROM_OTHER_PAY_AMOUNT,
1812        TO_OTHER_PAY_AMOUNT,
1813        --Bug#2383992
1814        NULL FROM_RETENTION_ALLOWANCE,
1815        TO_RETENTION_ALLOWANCE,
1816        NULL FROM_SUPERVISORY_DIFFERENTIAL,
1817        TO_SUPERVISORY_DIFFERENTIAL,
1818        NULL FROM_CAPPED_OTHER_PAY,
1819        NULL TO_CAPPED_OTHER_PAY,
1820 	   RPA_TYPE,
1821        -- FWFA Changes Bug#4444609
1822        input_pay_rate_determinant,
1823        from_pay_table_identifier,
1824        to_pay_table_identifier
1825        -- FWFA Changes
1826   FROM ghr_pa_requests
1827  WHERE person_id = p_person_id
1828    AND effective_date = p_effective_date
1829 -- Added by Dinkar for reports
1830    AND SUBSTR(request_number,(instr(request_number,'-')+1)) = TO_CHAR(p_mass_salary_id)
1831    AND first_noa_code = nvl(g_first_noa_code,'894');
1832 
1833 -- Bug#3964284 Added the following cursor to get the custom percentage.
1834 CURSOR ghr_mass_percent(p_pay_plan VARCHAR2,
1835 			            p_grade    VARCHAR2,
1836                         p_prd      NUMBER,
1837 			            p_msl_id   NUMBER
1838 			           ) IS
1839 SELECT ext.increase_percent percent
1840 FROM   ghr_mass_salary_criteria criteria, ghr_mass_salary_criteria_ext ext
1841 WHERE  criteria.mass_salary_id = p_msl_id
1842 AND    criteria.mass_salary_criteria_id=ext.mass_salary_criteria_id
1843 AND    criteria.pay_plan = p_pay_plan
1844 AND    criteria.PAY_RATE_DETERMINANT = p_prd
1845 And    ext.GRADE = p_grade;
1846 
1847 l_proc    varchar2(72) :=  g_package || '.pop_dtls_from_pa_req';
1848 l_sel_flag VARCHAR2(3) := NULL;
1849 l_comments VARCHAR2(150) := NULL;
1850 l_increase_percent ghr_mass_actions_preview.increase_percent%type;
1851 l_ses_basic_pay    ghr_mass_actions_preview.to_basic_pay%type;
1852 
1853 BEGIN
1854     g_proc  := 'pop_dtls_from_pa_req';
1855 
1856     hr_utility.set_location('Entering    ' || l_proc,5);
1857     FOR pa_req_rec in ghr_pa_req_cur
1858     LOOP
1859         -- To calculate percent increase from From Pay and To Pay if rpa_type = 'MPC'.
1860 		IF pa_req_rec.rpa_type = 'MPC' THEN
1861 			-- Bug#3964284 Get the customized increase percent from History using get_extra_info_comments procedure.
1862             -- If the value is NULL THEN
1863             --     Get the value from the table ghr_mass_salary_criteria_ext.
1864 			-- End If;
1865 			get_extra_info_comments
1866                 (p_person_id => p_person_id,
1867                  p_effective_date => p_effective_date,
1868                  p_sel_flag    => l_sel_flag,
1869                  p_comments    => l_comments,
1870 	             p_mass_salary_id => p_mass_salary_id,
1871     		     p_increase_percent => l_increase_percent,
1872 		     p_ses_basic_pay    => l_ses_basic_pay);
1873 
1874             IF l_increase_percent is NULL THEN
1875                 For cur in ghr_mass_percent(pa_req_rec.from_pay_plan,
1876                                              pa_req_rec.from_grade_or_level,
1877                                              pa_req_rec.pay_rate_determinant,
1878                                              p_mass_salary_id)
1879                 LOOP
1880                    l_increase_percent := cur.percent;
1881                 END LOOP;
1882             END IF;
1883 		ELSE
1884 			l_increase_percent := NULL;
1885 		END IF;
1886 
1887      create_mass_act_prev (
1888 			p_effective_date          => p_effective_date,
1889 			p_date_of_birth           =>  pa_req_rec.employee_date_of_birth,
1890 			p_full_name               => pa_req_rec.full_name,
1891 			p_national_identifier     =>   pa_req_rec.employee_national_identifier,
1892 			--Bug # 9329643
1893 			p_employee_number         =>   p_employee_number,
1894 			p_duty_station_code       => pa_req_rec.duty_station_code,
1895 			p_duty_station_desc       => pa_req_rec.duty_station_desc,
1896 			p_personnel_office_id     => pa_req_rec.personnel_office_id,
1897 			p_basic_pay               =>pa_req_rec.from_basic_pay,
1898 			p_new_basic_pay           => pa_req_rec.to_basic_pay,
1899 			--Bug#2383992 Added old_adj_basic_pay
1900 			p_adj_basic_pay           => pa_req_rec.from_adj_basic_pay,
1901 			p_new_adj_basic_pay       => pa_req_rec.to_adj_basic_pay,
1902 			p_old_avail_pay           =>  pa_req_rec.from_availability_pay,
1903 			p_new_avail_pay           =>   pa_req_rec.to_availability_pay,
1904 			p_old_loc_diff            =>  pa_req_rec.from_locality_adj,
1905 			p_new_loc_diff            => pa_req_rec.to_locality_adj,
1906 			p_tot_old_sal             =>   pa_req_rec.from_total_salary,
1907 			p_tot_new_sal             =>   pa_req_rec.to_total_salary,
1908 			p_old_auo_pay             =>  pa_req_rec.from_au_overtime,
1909 			p_new_auo_pay             =>  pa_req_rec.to_au_overtime,
1910 			p_position_id             => pa_req_rec.position_id,
1911 			p_position_title          => pa_req_rec.position_title,
1912             -- FWFA Changes Bug#4444609
1913             p_position_number         => pa_req_rec.position_number,
1914             p_position_seq_no         => pa_req_rec.position_seq_no,
1915             -- FWFA Changes
1916 			p_org_structure_id        => pa_req_rec.org_structure_id,
1917 			p_agency_sub_element_code =>  pa_req_rec.from_agency_code,
1918 			p_person_id               => pa_req_rec.person_id,
1919 			p_mass_salary_id          =>  p_mass_salary_id,
1920 			p_sel_flg                 => 'Y', --- Sel flag
1921 			p_first_action_la_code1   => pa_req_rec.first_action_la_code1,
1922 			p_first_action_la_code2   =>  pa_req_rec.first_action_la_code2,
1923 			p_remark_code1            => pa_req_rec.remark_code1,   --- will be null
1924 			p_remark_code2            => pa_req_rec.remark_code2,    --- will be null
1925 			p_grade_or_level          => pa_req_rec.from_grade_or_level,
1926 			p_step_or_rate            =>  pa_req_rec.from_step_or_rate,
1927 			p_pay_plan                => pa_req_rec.from_pay_plan,
1928 			p_pay_rate_determinant    =>  pa_req_rec.pay_rate_determinant,
1929 			p_tenure                  => pa_req_rec.tenure,
1930 			p_action                  => 'REPORT',
1931 			p_assignment_id           => pa_req_rec.employee_assignment_id,
1932 			p_old_other_pay           => pa_req_rec.from_other_pay_amount,
1933 			p_new_other_pay           => pa_req_rec.to_other_pay_amount,
1934 			-- Bug#2383992
1935 			p_old_capped_other_pay    => pa_req_rec.from_capped_other_pay,
1936 			p_new_capped_other_pay    => pa_req_rec.to_capped_other_pay,
1937 			p_old_retention_allowance => pa_req_rec.from_retention_allowance,
1938 			p_new_retention_allowance => pa_req_rec.to_retention_allowance,
1939 			p_old_supervisory_differential => pa_req_rec.from_supervisory_differential,
1940 			p_new_supervisory_differential => pa_req_rec.to_supervisory_differential,
1941 			-- BUG 3377958 Madhuri
1942 			p_organization_name            =>  p_org_name,
1943   		    p_increase_percent             => l_increase_percent,
1944 			-- Bug#2383992
1945             -- FWFA Changes Bug#4444609
1946             p_input_pay_rate_determinant     =>  pa_req_rec.input_pay_rate_determinant,
1947             p_from_pay_table_id            =>  pa_req_rec.from_pay_table_identifier,
1948             p_to_pay_table_id              =>  pa_req_rec.to_pay_table_identifier
1949             -- FWFA Changes
1950   		     );
1951        exit;
1952      END LOOP;
1953      hr_utility.set_location('Exiting    ' || l_proc,10);
1954 exception
1955   when msl_error then raise;
1956   when others then
1957      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
1958      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
1959      raise msl_error;
1960 end pop_dtls_from_pa_req;
1961 
1962 
1963 --
1964 --
1965 --
1966 
1967 function check_select_flg_msl_perc(p_person_id in number,
1968                           p_action in varchar2,
1969                           p_effective_date in date,
1970                           p_mass_salary_id in number,
1971                           p_sel_flg in out nocopy varchar2,
1972 						  p_increase_percent in out nocopy number
1973 			  )
1974 return boolean IS
1975 
1976    l_per_ei_data        per_people_extra_info%rowtype;
1977    l_comments varchar2(250);
1978    l_sel_flag varchar2(3);
1979    l_line number := 0;
1980    l_proc     varchar2(72) :=  g_package || '.check_select_flg_msl_perc';
1981    l_increase_percent ghr_mass_actions_preview.increase_percent%type; -- Added by Sundar 3843306
1982    l_ses_basic_pay    ghr_mass_actions_preview.to_basic_pay%type;
1983    l_temp_increase_percent number;
1984 begin
1985 
1986   g_proc  := 'check_select_flg_msl_perc';
1987   l_temp_increase_percent := p_increase_percent;
1988 
1989   hr_utility.set_location('Entering    ' || l_proc,5);
1990 
1991 l_line := 5;
1992      get_extra_info_comments(p_person_id,p_effective_date,l_sel_flag,l_comments,p_mass_salary_id,l_increase_percent,l_ses_basic_pay); -- Added by Sundar 3843306
1993 
1994 		--------- Initialize the comments
1995 		-- Sundar 3337361 Included GM Error, To basic pay < From basic pay in the condition
1996 		-- Now all the messages have MSL as a prefix. Rest of the conditions are alo
1997 		-- included for the old records which may still have old message.
1998      IF l_comments is not null THEN
1999        --Bug#4093705 Added ltrim function to verify the System generated Comments as few comments
2000        --            might start with Blank Spaces. Removed NVL condition as control comes here
2001        --            only when l_comments has Non Null value.
2002        IF substr(ltrim(l_comments),1,8) = 'Exceeded'
2003 		OR substr(ltrim(l_comments),1,3) = 'MSL'
2004 		OR substr(ltrim(l_comments),1,5) = 'Error'
2005 		OR substr(ltrim(l_comments),1,13) = 'The From Side'
2006 	   THEN
2007           ins_upd_per_extra_info
2008                (p_person_id,p_effective_date, l_sel_flag, null,p_mass_salary_id,l_increase_percent);
2009        END IF;
2010      END IF;
2011    -- Bug 3843306 If Increase percent is entered from Preview screen, the same should be retrieved
2012    -- and not the one entered in Grade screen.
2013 
2014     IF l_increase_percent IS NOT NULL THEN
2015 		p_increase_percent := l_increase_percent;
2016     END IF;
2017     -- 8320557 added to not check percentage is 0 for pay band conversion
2018     IF not ghr_msl_pkg.g_sl_payband_conv then
2019     IF p_increase_percent = 0 THEN
2020 		l_sel_flag := 'N';
2021     END IF;
2022     END IF;
2023 
2024 	l_line := 10;
2025      if l_sel_flag is null then
2026           p_sel_flg := 'Y';
2027      else
2028           p_sel_flg := l_sel_flag;
2029      end if;
2030 
2031 	l_line := 15;
2032      if p_action IN ('SHOW','REPORT') THEN
2033          return TRUE;
2034      elsif p_action = 'CREATE' THEN
2035          if p_sel_flg = 'Y' THEN
2036             return TRUE;
2037          else
2038             return FALSE;
2039          end if;
2040      end if;
2041 exception
2042   when msl_error then raise;
2043   when others then
2044      p_increase_percent := l_temp_increase_percent ;
2045      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
2046      l_mslerrbuf := 'Error in '||l_proc||' @'||to_char(l_line)||'  Sql Err is '|| sqlerrm(sqlcode);
2047      raise msl_error;
2048 end;
2049 
2050 --
2051 --
2052 --
2053 function check_select_flg(p_person_id in number,
2054                           p_action in varchar2,
2055                           p_effective_date in date,
2056                           p_mass_salary_id in number,
2057                           p_sel_flg in out nocopy varchar2
2058 			  )
2059 return boolean IS
2060 
2061    l_per_ei_data        per_people_extra_info%rowtype;
2062    l_comments varchar2(250);
2063    l_sel_flag varchar2(3);
2064    l_line number := 0;
2065    l_temp NUMBER;
2066    l_ses_basic_pay    ghr_mass_actions_preview.to_basic_pay%type;
2067 
2068    l_proc     varchar2(72) :=  g_package || '.check_select_flg';
2069 begin
2070 
2071   g_proc  := 'check_select_flg';
2072 
2073   hr_utility.set_location('Entering    ' || l_proc,5);
2074 
2075 l_line := 5;
2076      get_extra_info_comments(p_person_id,p_effective_date,l_sel_flag,l_comments,p_mass_salary_id,l_temp,l_ses_basic_pay);
2077 
2078 		--------- Initialize the comments
2079 		-- Sundar 3337361 Included GM Error, To basic pay < From basic pay in the condition
2080 		-- Now all the messages have MSL as a prefix. Rest of the conditions are alo
2081 		-- included for the old records which may still have old message.
2082      IF l_comments is not null THEN
2083        IF substr(nvl(l_comments,'@#%'),1,8) = 'Exceeded'
2084 		OR substr(nvl(l_comments,'@#%'),1,3) = 'MSL'
2085 		OR substr(nvl(l_comments,'@#%'),1,5) = 'Error'
2086 		OR substr(nvl(l_comments,'@#%'),1,13) = 'The From Side'
2087 	   THEN
2088           ins_upd_per_extra_info
2089                (p_person_id,p_effective_date, l_sel_flag, null,p_mass_salary_id);
2090        END IF;
2091      END IF;
2092 ---------
2093 
2094 
2095 	l_line := 10;
2096      if l_sel_flag is null then
2097           p_sel_flg := 'Y';
2098      else
2099           p_sel_flg := l_sel_flag;
2100      end if;
2101 
2102 	l_line := 15;
2103      if p_action IN ('SHOW','REPORT') THEN
2104          return TRUE;
2105      elsif p_action = 'CREATE' THEN
2106          if p_sel_flg = 'Y' THEN
2107             return TRUE;
2108          else
2109             return FALSE;
2110          end if;
2111      end if;
2112 exception
2113   when msl_error then raise;
2114   when others then
2115      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
2116      l_mslerrbuf := 'Error in '||l_proc||' @'||to_char(l_line)||'  Sql Err is '|| sqlerrm(sqlcode);
2117      raise msl_error;
2118 end;
2119 
2120 
2121 --
2122 --
2123 --
2124 
2125 
2126 procedure purge_old_data (p_mass_salary_id in number) is
2127 l_proc   varchar2(72) :=  g_package || '.purge_old_data';
2128 BEGIN
2129    g_proc  := 'purge_old_data';
2130 
2131    hr_utility.set_location('Entering    ' || l_proc,5);
2132    delete from ghr_mass_actions_preview
2133     where mass_action_type = 'SALARY'
2134       and session_id  = p_mass_salary_id;
2135    commit;
2136    hr_utility.set_location('Exiting    ' || l_proc,10);
2137 exception
2138   when msl_error then raise;
2139   when others then
2140      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
2141      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
2142      raise msl_error;
2143 END;
2144 
2145 --
2146 --
2147 --
2148 
2149 PROCEDURE get_pay_plan_and_table_id (p_prd in varchar2,
2150                         p_person_id in number,
2151                         p_position_id in per_assignments_f.position_id%type,
2152                         p_effective_date in date,
2153                         p_grade_id in per_assignments_f.grade_id%type,
2154                         p_assignment_id in per_assignments_f.assignment_id%type,
2155                         p_action in varchar2,
2156                         p_pay_plan out nocopy varchar2,
2157                         p_pay_table_id out nocopy number,
2158                         p_grade_or_level out nocopy varchar2,
2159                         p_step_or_rate   out nocopy varchar2,
2160                         p_pay_basis out nocopy varchar2) is
2161 
2162 p_person_extra_info_id number;
2163 ----p_locality_percent number;       --- AVR 12/08/98
2164 
2165 l_pos_ei_data         per_position_extra_info%rowtype;
2166 l_asg_ei_data         per_assignment_extra_info%rowtype;
2167 
2168 cursor c_grade_kff (grd_id number) is
2169         select gdf.segment1
2170               ,gdf.segment2
2171           from per_grades grd,
2172                per_grade_definitions gdf
2173          where grd.grade_id = grd_id
2174            and grd.grade_definition_id = gdf.grade_definition_id;
2175 
2176    l_retained_grade_rec  ghr_pay_calc.retained_grade_rec_type;
2177 l_proc     varchar2(72) :=  g_package || '.get_pay_plan_and_table_id';
2178 l_line number := 0;
2179 l_check_grade_retention VARCHAR2(200);
2180 BEGIN
2181   g_proc  := 'get_pay_plan_and_table_id';
2182   hr_utility.set_location('Entering    ' || l_proc,5);
2183   ghr_mre_pkg.pr('Entering ',l_proc,'ACTION '||p_action);
2184   -- Bug# 4126137,4179270,4086677
2185   l_check_grade_retention := CHECK_GRADE_RETENTION(P_PRD,P_PERSON_ID,P_EFFECTIVE_DATE);
2186 
2187   IF p_action = 'CREATE' THEN
2188 
2189 l_line := 10;
2190         FOR c_grade_kff_rec IN c_grade_kff (p_grade_id)
2191         LOOP
2192            p_pay_plan          := c_grade_kff_rec.segment1;
2193            p_grade_or_level    := c_grade_kff_rec.segment2;
2194            exit;
2195         end loop;
2196 
2197 l_line := 20;
2198   hr_utility.set_location('Got grade or level and pay plan',2);
2199   ghr_mre_pkg.pr('Got grade or level and pay plan');
2200 
2201         ghr_history_fetch.fetch_positionei
2202                         (p_position_id      => p_position_id
2203                         ,p_information_type => 'GHR_US_POS_VALID_GRADE'
2204                         ,p_date_effective   => p_effective_date
2205                         ,p_pos_ei_data      => l_pos_ei_data
2206                         );
2207 
2208 l_line := 30;
2209         P_PAY_table_id  := l_pos_ei_data.poei_information5;
2210         P_PAY_BASIS     := l_pos_ei_data.poei_information6;
2211 
2212   ghr_mre_pkg.pr(' Before fetch asgei', to_char(p_assignment_id));
2213 
2214         ghr_history_fetch.fetch_asgei
2215                         (p_assignment_id         => p_assignment_id
2216                         ,p_information_type      => 'GHR_US_ASG_SF52'
2217                         ,p_date_effective        => p_effective_date
2218                         ,p_asg_ei_data           => l_asg_ei_data
2219                         );
2220 
2221 l_line := 40;
2222         p_step_or_rate           :=  l_asg_ei_data.aei_information3;
2223 
2224      ELSIF l_check_grade_retention = 'REGULAR' THEN
2225   hr_utility.set_location('Grade retention is regular',1);
2226 
2227   ghr_mre_pkg.pr('Grade retention is regular',1);
2228 
2229         FOR c_grade_kff_rec IN c_grade_kff (p_grade_id)
2230         LOOP
2231            p_pay_plan          := c_grade_kff_rec.segment1;
2232            p_grade_or_level    := c_grade_kff_rec.segment2;
2233            exit;
2234         end loop;
2235 
2236   hr_utility.set_location('Got grade or level and pay plan',2);
2237 
2238   ghr_mre_pkg.pr('Got grade or level and pay plan',2);
2239 
2240 l_line := 50;
2241         ghr_history_fetch.fetch_positionei
2242                         (p_position_id      => p_position_id
2243                         ,p_information_type => 'GHR_US_POS_VALID_GRADE'
2244                         ,p_date_effective   => p_effective_date
2245                         ,p_pos_ei_data      => l_pos_ei_data
2246                         );
2247 
2248         P_PAY_table_id  := l_pos_ei_data.poei_information5;
2249         P_PAY_BASIS     := l_pos_ei_data.poei_information6;
2250 
2251 l_line := 60;
2252 
2253   ghr_mre_pkg.pr('before fetch asgei 2 ',to_char(p_assignment_id));
2254 
2255         ghr_history_fetch.fetch_asgei
2256                         (p_assignment_id         => p_assignment_id
2257                         ,p_information_type      => 'GHR_US_ASG_SF52'
2258                         ,p_date_effective        => p_effective_date
2259                         ,p_asg_ei_data           => l_asg_ei_data
2260                         );
2261         p_step_or_rate           :=  l_asg_ei_data.aei_information3;
2262 
2263 l_line := 70;
2264     ELSIF l_check_grade_retention = 'RETAIN' THEN
2265      --
2266      -- get retained details
2267      --
2268      hr_utility.set_location('Before get retained grade',4);
2269 
2270 l_line := 80;
2271   ghr_mre_pkg.pr('Retained prd ',P_PRD);
2272 
2273   ghr_mre_pkg.pr('before get retained grade 2 ',to_char(p_person_id));
2274 
2275        BEGIN
2276            l_retained_grade_rec :=
2277                    ghr_pc_basic_pay.get_retained_grade_details
2278                                       ( p_person_id,
2279                                         p_effective_date);
2280            p_person_extra_info_id := l_retained_grade_rec.person_extra_info_id;
2281            p_pay_plan        := l_retained_grade_rec.pay_plan;
2282            p_grade_or_level  := l_retained_grade_rec.grade_or_level;
2283            p_step_or_rate    := l_retained_grade_rec.step_or_rate;
2284            p_pay_basis       := l_retained_grade_rec.pay_basis;
2285            p_pay_table_id    := l_retained_grade_rec.user_table_id;
2286  --        p_locality_percent  := l_retained_grade_rec.locality_percent;  --AVR 12/08/98
2287        EXCEPTION
2288           WHEN ghr_pay_calc.pay_calc_message THEN
2289              IF p_action = 'CREATE' THEN
2290                 l_mslerrbuf := 'Error in Get retained grade for Person ID'||
2291                           to_char(p_person_id)||
2292                          'Error is '||' Sql Err is '|| sqlerrm(sqlcode);
2293                 ghr_mre_pkg.pr('Person id '||to_char(p_person_id),'ERROR 1',l_mslerrbuf);
2294                 raise msl_error;
2295              END IF;
2296           WHEN others THEN
2297                 l_mslerrbuf := 'Others error in Get retained grade '||
2298                          'Error is '||' Sql Err is '|| sqlerrm(sqlcode);
2299                 ghr_mre_pkg.pr('Person ID '||to_char(p_person_id),'ERROR 2',l_mslerrbuf);
2300                 raise msl_error;
2301        END;
2302 l_line := 90;
2303    -- Bug#4179270,4126137,4086677 Added the following ELSIF Condition.
2304    ELSIF l_check_grade_retention ='MSL_ERROR' THEN
2305        hr_utility.set_message(8301,'GHR_38927_MISSING_MA_RET_DET');
2306        raise msl_error;
2307    ELSIF l_check_grade_retention = 'OTHER_ERROR' THEN
2308      l_mslerrbuf := 'Others error in check_grade_retention function while fetching retained grade record. Please
2309                      verify the retained grade record';
2310       raise msl_error;
2311    END IF;
2312    hr_utility.set_location('Exiting    ' || l_proc,10);
2313 l_line := 100;
2314 EXCEPTION
2315    when msl_error then raise;
2316    when others then
2317         raise msl_error;
2318 END get_pay_plan_and_table_id;
2319 
2320 --
2321 --
2322 
2323 -- Bug#5089732 Added p_to_grade_id,p_to_pay_plan, p_to_grade_or_level parameters.
2324 PROCEDURE get_pay_plan_and_table_id (p_prd in varchar2,
2325                         p_person_id in number,
2326                         p_position_id in per_assignments_f.position_id%type,
2327                         p_effective_date in date,
2328                         p_grade_id in per_assignments_f.grade_id%type,
2329                         p_to_grade_id out nocopy per_assignments_f.grade_id%type,
2330                         p_assignment_id in per_assignments_f.assignment_id%type,
2331                         p_action in varchar2,
2332                         p_pay_plan out nocopy varchar2,
2333 			            p_to_pay_plan out nocopy varchar2,
2334                         p_pay_table_id out nocopy number,
2335                         p_grade_or_level out nocopy varchar2,
2336 			            p_to_grade_or_level out nocopy varchar2,
2337                         p_step_or_rate   out nocopy varchar2,
2338                         p_pay_basis out nocopy varchar2) is
2339 
2340 p_person_extra_info_id number;
2341 --p_locality_percent number;       --- AVR 12/08/98
2342 
2343 l_pos_ei_data         per_position_extra_info%rowtype;
2344 l_asg_ei_data         per_assignment_extra_info%rowtype;
2345 
2346 
2347 cursor c_grade_kff (grd_id number) is
2348         select gdf.segment1
2349               ,gdf.segment2
2350           from per_grades grd,
2351                per_grade_definitions gdf
2352          where grd.grade_id = grd_id
2353            and grd.grade_definition_id = gdf.grade_definition_id;
2354 
2355 l_retained_grade_rec  ghr_pay_calc.retained_grade_rec_type;
2356 l_proc     varchar2(72) :=  g_package || '.get_pay_plan_and_table_id';
2357 l_line number := 0;
2358 l_check_grade_retention VARCHAR2(200);
2359 BEGIN
2360   g_proc  := 'get_pay_plan_and_table_id';
2361   hr_utility.set_location('Entering    ' || l_proc,5);
2362   ghr_mre_pkg.pr('Entering ',l_proc,'ACTION '||p_action);
2363   -- Bug# 4126137,4179270,4086677
2364   l_check_grade_retention := CHECK_GRADE_RETENTION(P_PRD,P_PERSON_ID,P_EFFECTIVE_DATE);
2365 
2366   IF p_action = 'CREATE' THEN
2367 
2368 l_line := 10;
2369         FOR c_grade_kff_rec IN c_grade_kff (p_grade_id)
2370         LOOP
2371            p_pay_plan          := c_grade_kff_rec.segment1;
2372            p_grade_or_level    := c_grade_kff_rec.segment2;
2373            exit;
2374         end loop;
2375 
2376 l_line := 20;
2377   hr_utility.set_location('Got grade or level and pay plan',2);
2378   ghr_mre_pkg.pr('Got grade or level and pay plan');
2379 
2380         ghr_history_fetch.fetch_positionei
2381                         (p_position_id      => p_position_id
2382                         ,p_information_type => 'GHR_US_POS_VALID_GRADE'
2383                         ,p_date_effective   => p_effective_date
2384                         ,p_pos_ei_data      => l_pos_ei_data
2385                         );
2386 
2387 l_line := 30;
2388         -- Bug#5089732 Added the cursor to fetch the pay plan as on effective date.
2389         p_to_grade_id := l_pos_ei_data.poei_information3;
2390         FOR c_grade_kff_rec IN c_grade_kff (p_to_grade_id)
2391         LOOP
2392            p_to_pay_plan          := c_grade_kff_rec.segment1;
2393            p_to_grade_or_level    := c_grade_kff_rec.segment2;
2394            exit;
2395         END LOOP;
2396         -- Pass the position pay plan, grade or level as output for comparison, pay calculation.
2397         IF p_to_pay_plan <> p_pay_plan THEN
2398            p_pay_plan := p_to_pay_plan;
2399            p_grade_or_level := p_to_grade_or_level;
2400         END IF;
2401 
2402         P_PAY_table_id  := l_pos_ei_data.poei_information5;
2403         P_PAY_BASIS     := l_pos_ei_data.poei_information6;
2404 
2405   ghr_mre_pkg.pr(' Before fetch asgei', to_char(p_assignment_id));
2406 
2407         ghr_history_fetch.fetch_asgei
2408                         (p_assignment_id         => p_assignment_id
2409                         ,p_information_type      => 'GHR_US_ASG_SF52'
2410                         ,p_date_effective        => p_effective_date
2411                         ,p_asg_ei_data           => l_asg_ei_data
2412                         );
2413 
2414 l_line := 40;
2415         p_step_or_rate           :=  l_asg_ei_data.aei_information3;
2416 
2417      ELSIF l_check_grade_retention = 'REGULAR' THEN
2418   hr_utility.set_location('Grade retention is regular',1);
2419 
2420   ghr_mre_pkg.pr('Grade retention is regular',1);
2421 
2422         FOR c_grade_kff_rec IN c_grade_kff (p_grade_id)
2423         LOOP
2424            p_pay_plan          := c_grade_kff_rec.segment1;
2425            p_grade_or_level    := c_grade_kff_rec.segment2;
2426            exit;
2427         end loop;
2428 
2429   hr_utility.set_location('Got grade or level and pay plan',2);
2430 
2431   ghr_mre_pkg.pr('Got grade or level and pay plan',2);
2432 
2433 l_line := 50;
2434         ghr_history_fetch.fetch_positionei
2435                         (p_position_id      => p_position_id
2436                         ,p_information_type => 'GHR_US_POS_VALID_GRADE'
2437                         ,p_date_effective   => p_effective_date
2438                         ,p_pos_ei_data      => l_pos_ei_data
2439                         );
2440         -- Bug#5089732 Added the cursor to fetch the pay plan as on effective date.
2441         p_to_grade_id := l_pos_ei_data.poei_information3;
2442         FOR c_grade_kff_rec IN c_grade_kff (p_to_grade_id)
2443         LOOP
2444            p_to_pay_plan          := c_grade_kff_rec.segment1;
2445            p_to_grade_or_level    := c_grade_kff_rec.segment2;
2446            exit;
2447         end loop;
2448          -- Pass the position pay plan, grade or level as output for comparison, pay calculation.
2449         IF p_to_pay_plan <> p_pay_plan THEN
2450            p_pay_plan := p_to_pay_plan;
2451            p_grade_or_level := p_to_grade_or_level;
2452         END IF;
2453         P_PAY_table_id  := l_pos_ei_data.poei_information5;
2454         P_PAY_BASIS     := l_pos_ei_data.poei_information6;
2455 
2456 l_line := 60;
2457 
2458   ghr_mre_pkg.pr('before fetch asgei 2 ',to_char(p_assignment_id));
2459 
2460         ghr_history_fetch.fetch_asgei
2461                         (p_assignment_id         => p_assignment_id
2462                         ,p_information_type      => 'GHR_US_ASG_SF52'
2463                         ,p_date_effective        => p_effective_date
2464                         ,p_asg_ei_data           => l_asg_ei_data
2465                         );
2466         p_step_or_rate           :=  l_asg_ei_data.aei_information3;
2467 
2468 l_line := 70;
2469     ELSIF l_check_grade_retention = 'RETAIN' THEN
2470      --
2471      -- get retained details
2472      --
2473      hr_utility.set_location('Before get retained grade',4);
2474 
2475 l_line := 80;
2476   ghr_mre_pkg.pr('Retained prd ',P_PRD);
2477 
2478   ghr_mre_pkg.pr('before get retained grade 2 ',to_char(p_person_id));
2479 
2480        BEGIN
2481            l_retained_grade_rec :=
2482                    ghr_pc_basic_pay.get_retained_grade_details
2483                                       ( p_person_id,
2484                                         p_effective_date);
2485            p_person_extra_info_id := l_retained_grade_rec.person_extra_info_id;
2486            p_pay_plan        := l_retained_grade_rec.pay_plan;
2487            p_grade_or_level  := l_retained_grade_rec.grade_or_level;
2488            p_step_or_rate    := l_retained_grade_rec.step_or_rate;
2489            p_pay_basis       := l_retained_grade_rec.pay_basis;
2490            p_pay_table_id    := l_retained_grade_rec.user_table_id;
2491  --        p_locality_percent  := l_retained_grade_rec.locality_percent;  --AVR 12/08/98
2492        EXCEPTION
2493           WHEN ghr_pay_calc.pay_calc_message THEN
2494              IF p_action = 'CREATE' THEN
2495                 l_mslerrbuf := 'Error in Get retained grade for Person ID'||
2496                           to_char(p_person_id)||
2497                          'Error is '||' Sql Err is '|| sqlerrm(sqlcode);
2498                 ghr_mre_pkg.pr('Person id '||to_char(p_person_id),'ERROR 1',l_mslerrbuf);
2499                 raise msl_error;
2500              END IF;
2501           WHEN others THEN
2502                 l_mslerrbuf := 'Others error in Get retained grade '||
2503                          'Error is '||' Sql Err is '|| sqlerrm(sqlcode);
2504                 ghr_mre_pkg.pr('Person ID '||to_char(p_person_id),'ERROR 2',l_mslerrbuf);
2505                 raise msl_error;
2506        END;
2507 l_line := 85;
2508        -- Bug#5089732 Pass the to to position pay plan, grade, grade_id also.
2509        p_to_grade_id := p_grade_id;
2510        FOR c_grade_kff_rec IN c_grade_kff (p_to_grade_id)
2511         LOOP
2512            p_to_pay_plan          := c_grade_kff_rec.segment1;
2513            p_to_grade_or_level    := c_grade_kff_rec.segment2;
2514            exit;
2515         END LOOP;
2516 l_line := 90;
2517    -- Bug#4179270,4126137,4086677 Added the following ELSIF Condition.
2518    ELSIF l_check_grade_retention ='MSL_ERROR' THEN
2519        hr_utility.set_message(8301,'GHR_38927_MISSING_MA_RET_DET');
2520        raise msl_error;
2521    ELSIF l_check_grade_retention = 'OTHER_ERROR' THEN
2522      l_mslerrbuf := 'Others error in check_grade_retention function while fetching retained grade record. Please
2523                      verify the retained grade record';
2524       raise msl_error;
2525    END IF;
2526    hr_utility.set_location('Exiting    ' || l_proc,10);
2527 l_line := 100;
2528 EXCEPTION
2529    when msl_error then raise;
2530    when others then
2531         raise msl_error;
2532 END get_pay_plan_and_table_id;
2533 
2534 --
2535 --
2536 
2537 procedure update_sel_flg (p_person_id in number,p_effective_date date) is
2538 
2539    l_person_extra_info_id number;
2540    l_object_version_number number;
2541    l_per_ei_data         per_people_extra_info%rowtype;
2542    l_proc  varchar2(72) :=  g_package || '.update_sel_flg';
2543 l_ind number := 1;
2544 begin
2545   g_proc  := 'update_sel_flg';
2546    hr_utility.set_location('Entering    ' || l_proc,5);
2547 pr('Inside '||l_proc,to_char(p_person_id));
2548 l_ind := 10;
2549    ghr_history_fetch.fetch_peopleei
2550                   (p_person_id             => p_person_id
2551                   ,p_information_type      => 'GHR_US_PER_MASS_ACTIONS'
2552                   ,p_date_effective        => p_effective_date
2553                   ,p_per_ei_data           => l_per_ei_data);
2554 
2555 l_ind := 20;
2556    l_person_extra_info_id  := l_per_ei_data.person_extra_info_id;
2557    l_object_version_number := l_per_ei_data.object_version_number;
2558 
2559    if l_person_extra_info_id is not null then
2560       ghr_person_extra_info_api.update_person_extra_info
2561                    (P_PERSON_EXTRA_INFO_ID   => l_person_extra_info_id
2562                    ,P_EFFECTIVE_DATE         => sysdate
2563                    ,P_OBJECT_VERSION_NUMBER  => l_object_version_number
2564                    ,p_pei_INFORMATION3       => NULL
2565                    ,p_pei_INFORMATION4       => NULL
2566                    ,p_pei_INFORMATION5       => NULL
2567 		   -- Bug#3988449 Added p_pei_information10 to clear the increase percentage value.
2568 		   ,p_pei_information10      => NULL
2569                    ,P_PEI_INFORMATION_CATEGORY  => 'GHR_US_PER_MASS_ACTIONS');
2570 
2571 l_ind := 30;
2572      hr_utility.set_location('Exiting    ' || l_proc,10);
2573 -- There is a trigger on PER_PEOPLE_EXTRA_INFO to make the employee INVALID
2574 -- when there is a update done on the table.
2575 ---Commented the following three lines to remove Validation functionality on Person.
2576 ---   ghr_validate_perwsepi.validate_perwsepi(p_person_id);
2577 ---   l_ind := 40;
2578 ---   ghr_validate_perwsepi.update_person_user_type(p_person_id);
2579    end if;
2580 
2581 l_ind := 50;
2582   pr('Exiting '||l_proc,to_char(p_person_id));
2583 exception
2584   when msl_error then raise;
2585   when others then
2586      hr_utility.set_location('Error in '||l_proc||
2587                            ' Err is '||sqlerrm(sqlcode),20);
2588      l_mslerrbuf := 'Error in '||l_proc||' at '||to_char(l_ind)||
2589                           '  Sql Err is '|| sqlerrm(sqlcode);
2590      raise msl_error;
2591 end update_sel_flg;
2592 
2593 --
2594 --
2595 --
2596 
2597 FUNCTION GET_PAY_PLAN_NAME (PP IN VARCHAR2) RETURN VARCHAR2 IS
2598 
2599  CURSOR CUR_PP IS
2600  select pay_plan,description
2601    from ghr_pay_plans
2602   WHERE PAY_PLAN = PP;
2603   l_pp_desc varchar2(150);
2604 BEGIN
2605   FOR PP_REC IN CUR_PP
2606   LOOP
2607      l_pp_desc := pp_rec.description;
2608      exit;
2609   END LOOP;
2610   return (l_pp_desc);
2611 END;
2612 
2613 FUNCTION GET_USER_TABLE_name (P_USER_TABLE_id IN NUMBER) RETURN VARCHAR2 IS
2614    CURSOR MSL_CUR IS
2615    select user_table_id,substr(user_table_name,0,4) user_table_name
2616      from pay_user_tables
2617          where substr(user_table_name,6,14) in
2618                      ('Oracle Federal','Federal Agency')
2619            and user_table_id = p_user_table_id;
2620   l_user_table_name varchar2(80);
2621 BEGIN
2622     for msl in msl_cur
2623     LOOP
2624        l_user_table_name := msl.user_table_name;
2625        exit;
2626     end loop;
2627     return (l_user_table_name);
2628 END;
2629 
2630 --
2631 --
2632 --
2633 /*
2634 Procedure to get Person EI for MSL Percentage.
2635 */
2636 
2637 PROCEDURE get_extra_info_comments
2638                 (p_person_id in number,
2639                  p_effective_date in date,
2640                  p_sel_flag    in out nocopy varchar2,
2641                  p_comments    in out nocopy varchar2,
2642 		 p_mass_salary_id in number,
2643 		 p_increase_percent out nocopy number,
2644 		 p_ses_basic_pay out nocopy number) is
2645 
2646   l_per_ei_data        per_people_extra_info%rowtype;
2647   l_proc  varchar2(72) := g_package || '.get_extra_info_comments';
2648   l_eff_date date;
2649 
2650   CURSOR chk_history (p_person_id in NUMBER ,
2651                       eff_date    in Date) IS
2652    select information9  info9
2653          ,information10 info10
2654 	 ,information11 info11
2655 	 ,information16 increase_percent -- Added by Sundar 3843306
2656 	 ,information17 info17
2657    from ghr_pa_history
2658    where person_id = p_person_id
2659    and pa_history_id IN ( select max(pa_history_id)
2660                           from ghr_pa_history
2661                           where person_id  = p_person_id
2662                           and information5 = 'GHR_US_PER_MASS_ACTIONS'
2663                           and table_name   = 'PER_PEOPLE_EXTRA_INFO'
2664                           and effective_date = eff_date
2665                           group by  information11);
2666 
2667 begin
2668   g_proc  := 'get_extra_info_comments';
2669   hr_utility.set_location('Entering    ' || l_proc,5);
2670 
2671   l_eff_date := p_effective_date;
2672 
2673   ghr_history_fetch.fetch_peopleei
2674                   (p_person_id             => p_person_id
2675                   ,p_information_type      => 'GHR_US_PER_MASS_ACTIONS'
2676                   ,p_date_effective        => l_eff_date
2677                   ,p_per_ei_data           => l_per_ei_data);
2678 
2679    --Bug#3988449 Added NVL and to_number in the following condition
2680    IF NVL(to_number(l_per_ei_data.pei_information5),hr_api.g_number) <> NVL(p_mass_salary_id,hr_api.g_number) then
2681       p_sel_flag := 'Y';
2682       p_comments := null;
2683       p_increase_percent := null;
2684       p_ses_basic_pay := null;
2685    else
2686       p_sel_flag := l_per_ei_data.pei_information3;
2687       p_comments := l_per_ei_data.pei_information4;
2688       p_increase_percent := l_per_ei_data.pei_information10; -- Added by Sundar 3843306
2689       p_ses_basic_pay    := l_per_ei_data.pei_information11;
2690    end if;
2691 
2692     --Bug#3988449 Added NVL and to_number to l_per_ei_data.pei_information5, p_mass_salary_id.
2693     IF  p_sel_flag IS NOT NULL and
2694         NVL(to_number(l_per_ei_data.pei_information5),hr_api.g_number) <> NVL(p_mass_salary_id,hr_api.g_number) THEN
2695      FOR chk_history_rec in chk_history(p_person_id => p_person_id,
2696 					eff_date => l_eff_date) loop
2697        If chk_history_rec.info11 = p_mass_salary_id then
2698           p_sel_flag := chk_history_rec.info9;
2699 	  p_comments := chk_history_rec.info10;--Added by Ashley
2700 	  p_increase_percent := chk_history_rec.increase_percent; -- Added by Sundar 3843306
2701 	  p_ses_basic_pay    := chk_history_rec.info11; -- Added by Sundar 3843306
2702        END IF;
2703      END LOOP;
2704    END IF;
2705 
2706 
2707 exception
2708   when msl_error then
2709   p_increase_percent := NULL;
2710   raise;
2711   when others then
2712      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
2713      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
2714      p_increase_percent := NULL;
2715      p_ses_basic_pay    := NULL;
2716      raise msl_error;
2717 end;
2718 
2719 --
2720 --
2721 --
2722 
2723 
2724 
2725 procedure ins_upd_per_extra_info
2726                (p_person_id in number,
2727 			    p_effective_date in date,
2728                 p_sel_flag in varchar2,
2729 				p_comment in varchar2,
2730 				p_msl_id in number,
2731 				p_increase_percent in number default NULL) is
2732 
2733    l_person_extra_info_id number;
2734    l_object_version_number number;
2735    l_per_ei_data         per_people_extra_info%rowtype;
2736 
2737    CURSOR people_ext_cur (person number) is
2738    SELECT person_extra_info_id, object_version_number
2739      FROM PER_people_EXTRA_INFO
2740     WHERE person_ID = person
2741       and information_type = 'GHR_US_PER_MASS_ACTIONS';
2742 
2743     l_proc    varchar2(72) :=  g_package || '.ins_upd_per_extra_info';
2744     l_eff_date date;
2745 
2746 begin
2747   g_proc  := 'ins_upd_per_extra_info';
2748   hr_utility.set_location('Entering    ' || l_proc,5);
2749   if p_effective_date > sysdate then
2750        l_eff_date := sysdate;
2751   else
2752        l_eff_date := p_effective_date;
2753   end if;
2754 
2755    ghr_history_fetch.fetch_peopleei
2756                   (p_person_id           => p_person_id
2757                   ,p_information_type      => 'GHR_US_PER_MASS_ACTIONS'
2758                   ,p_date_effective        => l_eff_date
2759                   ,p_per_ei_data           => l_per_ei_data);
2760 
2761    l_person_extra_info_id  := l_per_ei_data.person_extra_info_id;
2762    l_object_version_number := l_per_ei_data.object_version_number;
2763 
2764    if l_person_extra_info_id is null then
2765       for per_ext_rec in people_ext_cur(p_person_id)
2766       loop
2767          l_person_extra_info_id  := per_ext_rec.person_extra_info_id;
2768          l_object_version_number := per_ext_rec.object_version_number;
2769       end loop;
2770    end if;
2771 
2772    if l_person_extra_info_id is not null then
2773         ghr_person_extra_info_api.update_person_extra_info
2774                        (P_PERSON_EXTRA_INFO_ID   => l_person_extra_info_id
2775                        ,P_EFFECTIVE_DATE           => trunc(l_eff_date)
2776                        ,P_OBJECT_VERSION_NUMBER    => l_object_version_number
2777                        ,p_pei_INFORMATION3        => p_sel_flag
2778                        ,p_pei_INFORMATION4        => p_comment
2779                        ,p_pei_INFORMATION5        => to_char(p_msl_id)
2780 					   ,p_pei_information10       => to_char(p_increase_percent)
2781                        ,P_PEI_INFORMATION_CATEGORY  => 'GHR_US_PER_MASS_ACTIONS');
2782    else
2783         ghr_person_extra_info_api.create_person_extra_info
2784                        (P_pERSON_ID             => p_PERSON_id
2785                        ,P_INFORMATION_TYPE        => 'GHR_US_PER_MASS_ACTIONS'
2786                        ,P_EFFECTIVE_DATE          => trunc(l_eff_date)
2787                        ,p_pei_INFORMATION3       => p_sel_flag
2788                        ,p_pei_INFORMATION4       => p_comment
2789                        ,p_pei_INFORMATION5       => to_char(p_msl_id)
2790 					   ,p_pei_information10       =>to_char(p_increase_percent)
2791                        ,P_PEI_INFORMATION_CATEGORY  => 'GHR_US_PER_MASS_ACTIONS'
2792                        ,P_pERSON_EXTRA_INFO_ID  => l_pERSON_extra_info_id
2793                        ,P_OBJECT_VERSION_NUMBER   => l_object_version_number);
2794    end if;
2795 
2796 ---Commented the following two lines to remove Validation functionality on Person.
2797 -- ghr_validate_perwsepi.validate_perwsepi(p_person_id);
2798 -- ghr_validate_perwsepi.update_person_user_type(p_person_id);
2799 
2800    hr_utility.set_location('Exiting    ' || l_proc,10);
2801 exception
2802   when msl_error then raise;
2803   when others then
2804      pr('Error in '||l_proc);
2805      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
2806      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
2807      raise msl_error;
2808 end ins_upd_per_extra_info;
2809 
2810 --
2811 -- Bug#5063304 Created this new procedure
2812 PROCEDURE fetch_and_validate_emp(
2813                               p_action                     IN VARCHAR2
2814                              ,p_mass_salary_id             IN NUMBER
2815                              ,p_mass_salary_name           IN VARCHAR2
2816                              ,p_full_name                  IN per_people_f.full_name%TYPE
2817    			     ,p_national_identifier        IN per_people_f.national_identifier%TYPE
2818 			     --Bug # 9329643
2819 			     ,p_employee_number            IN per_people_f.employee_number%TYPE
2820                              ,p_assignment_id              IN per_assignments_f.assignment_id%TYPE
2821 			     ,p_person_id                  IN per_assignments_f.person_id%TYPE
2822 			     ,p_position_id                IN per_assignments_f.position_id%TYPE
2823 			     ,p_grade_id                   IN per_assignments_f.grade_id%TYPE
2824 			     ,p_business_group_id          IN per_assignments_f.business_group_iD%TYPE
2825 			     ,p_location_id                IN per_assignments_f.location_id%TYPE
2826 			     ,p_organization_id            IN per_assignments_f.organization_id%TYPE
2827                              ,p_msl_organization_id        IN per_assignments_f.organization_id%TYPE
2828                              ,p_msl_duty_station_id        IN ghr_duty_stations_f.duty_station_id%TYPE
2829                              ,p_msl_personnel_office_id    IN VARCHAR2
2830                              ,p_msl_agency_code_subelement IN VARCHAR2
2831                              ,p_msl_user_table_id          IN NUMBER
2832                              ,p_rec_pp_prd                 IN pp_prd
2833                              ,p_personnel_office_id        OUT NOCOPY VARCHAR2
2834                              ,p_org_structure_id           OUT NOCOPY VARCHAR2
2835                              ,p_position_title             OUT NOCOPY VARCHAR2
2836                              ,p_position_number            OUT NOCOPY VARCHAR2
2837                              ,p_position_seq_no            OUT NOCOPY VARCHAR2
2838                              ,p_subelem_code               OUT NOCOPY VARCHAR2
2839                              ,p_duty_station_id     OUT NOCOPY ghr_duty_stations_f.duty_station_id%TYPE
2840                              ,p_tenure              OUT NOCOPY VARCHAR2
2841                              ,p_annuitant_indicator OUT NOCOPY VARCHAR2
2842                              ,p_pay_rate_determinant OUT NOCOPY VARCHAR2
2843                              ,p_work_schedule       OUT NOCOPY  VARCHAR2
2844                              ,p_part_time_hour      OUT NOCOPY VARCHAR2
2845                              ,p_to_grade_id         OUT NOCOPY per_assignments_f.grade_id%type
2846                              ,p_pay_plan            OUT NOCOPY VARCHAR2
2847                              ,p_to_pay_plan         OUT NOCOPY VARCHAR2
2848                              ,p_pay_table_id        OUT NOCOPY NUMBER
2849                              ,p_grade_or_level      OUT NOCOPY VARCHAR2
2850                              ,p_to_grade_or_level   OUT NOCOPY VARCHAR2
2851                              ,p_step_or_rate        OUT NOCOPY VARCHAR2
2852                              ,p_pay_basis           OUT NOCOPY VARCHAR2
2853                              ,p_elig_flag           OUT NOCOPY BOOLEAN
2854 			                ) IS
2855 
2856 
2857 
2858     CURSOR msl_dtl_cur (cur_pay_plan varchar2, cur_prd varchar2) IS
2859     SELECT count(*) cnt
2860       FROM ghr_mass_salary_criteria
2861      WHERE mass_salary_id = p_mass_salary_id
2862        AND pay_plan = cur_pay_plan
2863        AND pay_rate_determinant = cur_prd;
2864 
2865     l_row_cnt               NUMBER := 0;
2866     l_pos_grp1_rec          per_position_extra_info%rowtype;
2867     l_assignment_id         per_assignments_f.assignment_id%TYPE;
2868     l_person_id             per_assignments_f.person_id%TYPE;
2869     l_position_id           per_assignments_f.position_id%TYPE;
2870     l_grade_id              per_assignments_f.grade_id%TYPE;
2871     l_business_group_id     per_assignments_f.business_group_iD%TYPE;
2872     l_location_id           per_assignments_f.location_id%TYPE;
2873     l_organization_id       per_assignments_f.organization_id%TYPE;
2874     l_tenure               VARCHAR2(35);
2875     l_annuitant_indicator  VARCHAR2(35);
2876     l_pay_rate_determinant VARCHAR2(35);
2877     l_work_schedule        VARCHAR2(35);
2878     l_part_time_hour       VARCHAR2(35);
2879     l_pay_table_id         NUMBER;
2880     l_pay_plan             VARCHAR2(30);
2881     l_grade_or_level       VARCHAR2(30);
2882     -- Bug#5089732 Added current pay plan, grade_or_level
2883     l_to_grade_id          NUMBER;
2884     l_to_pay_plan          VARCHAR2(30);
2885     l_to_grade_or_level    VARCHAR2(30);
2886     -- Bug#5089732
2887     l_step_or_rate         VARCHAR2(30);
2888     l_pay_basis            VARCHAR2(30);
2889     l_duty_station_id      NUMBER;
2890     l_duty_station_desc    ghr_pa_requests.duty_station_desc%type;
2891     l_duty_station_code    ghr_pa_requests.duty_station_code%type;
2892     l_effective_date       DATE;
2893     l_personnel_office_id  VARCHAR2(300);
2894     l_org_structure_id     VARCHAR2(300);
2895     l_sub_element_code     VARCHAR2(300);
2896     l_position_title       VARCHAR2(300);
2897     l_position_number      VARCHAR2(20);
2898     l_position_seq_no      VARCHAR2(20);
2899     l_log_text             VARCHAR2(2000) := null;
2900     l_retained_grade_rec  ghr_pay_calc.retained_grade_rec_type;
2901     l_fetch_poid_data       BOOLEAN := FALSE;
2902     l_fetch_ds_data         BOOLEAN := FALSE;
2903     l_fetch_agency_data     BOOLEAN := FALSE;
2904     init_elig_flag          BOOLEAN := FALSE;
2905     l_prd_matched           BOOLEAN := FALSE;
2906     l_prd_pp_matched        BOOLEAN := FALSE;
2907 
2908 
2909     l_proc   varchar2(72) :=  g_package || '.fetch_and_validate_emp';
2910 
2911 BEGIN
2912 
2913     g_proc  := 'fetch_and_validate_emp';
2914     hr_utility.set_location('Entering    ' || l_proc,5);
2915     -- Bug#5623035 Moved the local variable assigning to here.
2916     l_assignment_id     := p_assignment_id;
2917     l_position_id       := p_position_id;
2918     l_grade_id          := p_grade_id;
2919     l_business_group_id := p_business_group_iD;
2920     l_location_id       := p_location_id;
2921     l_effective_date    := g_effective_date;
2922 
2923     -- Verify whether this process is required or not.
2924     IF p_msl_organization_id IS NOT NULL  OR
2925        p_msl_duty_station_id IS NOT NULL  OR
2926        p_msl_personnel_office_id IS NOT NULL  OR
2927        p_msl_agency_code_subelement IS NOT NULL THEN
2928         -- get the values and verify whether the record meets the condition or not.
2929         -- If Yes, proceed further. Otherwise, skip the other checks for this record
2930 
2931         hr_utility.set_location('The location id is:'||l_location_id,12345);
2932         hr_utility.set_location('MSL Org ID:'||p_msl_organization_id,11111);
2933         hr_utility.set_location('Org ID:'||p_organization_id,22222);
2934         IF NVL(p_msl_organization_id,p_organization_id) = p_organization_id THEN
2935             hr_utility.set_location('Org ID PASS',10);
2936             IF p_msl_personnel_office_id IS NOT NULL THEN
2937                 hr_utility.set_location('POID CHECK',15);
2938                 get_pos_grp1_ddf(l_position_id,
2939                                  l_effective_date,
2940                                  l_pos_grp1_rec);
2941 
2942                 l_personnel_office_id :=  l_pos_grp1_rec.poei_information3;
2943                 l_org_structure_id    :=  l_pos_grp1_rec.poei_information5;
2944                 l_fetch_poid_data := TRUE;
2945             END IF;
2946             IF  (p_msl_personnel_office_id = l_personnel_office_id) OR
2947                 NOT(l_fetch_poid_data) THEN
2948                 hr_utility.set_location('POID PASS',20);
2949                 IF p_msl_agency_code_subelement IS NOT NULL THEN
2950                     hr_utility.set_location('Agency CHECK',25);
2951                     get_sub_element_code_pos_title(l_position_id,
2952                                              p_person_id,
2953                                              l_business_group_id,
2954                                              l_assignment_id,
2955                                              l_effective_date,
2956                                              l_sub_element_code,
2957                                              l_position_title,
2958                                              l_position_number,
2959                                              l_position_seq_no);
2960                     l_fetch_agency_data := TRUE;
2961                 END IF;
2962                 -- Bug#5674003 Modified the following IF condition
2963                 IF  (SUBSTR(p_msl_agency_code_subelement,1,2)  = SUBSTR(l_sub_element_code,1,2) AND
2964                      NVL(SUBSTR(p_msl_agency_code_subelement,3,2),SUBSTR(l_sub_element_code,3,2))=
2965                          SUBSTR(l_sub_element_code,3,2)
2966                     ) OR
2967                     NOT(l_fetch_agency_data) THEN
2968                                     hr_utility.set_location('Agency PASS',30);
2969                     IF p_msl_duty_station_id IS NOT NULL THEN
2970                         hr_utility.set_location('DS CHECK',35);
2971                         ghr_pa_requests_pkg.get_SF52_loc_ddf_details
2972                         (p_location_id      => l_location_id
2973                         ,p_duty_station_id  => l_duty_station_id);
2974                         l_fetch_ds_data := TRUE;
2975                     END IF;
2976                     IF (p_msl_duty_station_id = l_duty_station_id) OR
2977                        NOT(l_fetch_ds_data)THEN
2978                        hr_utility.set_location('DS PASS',40);
2979                         init_elig_flag := TRUE;
2980                     ELSE -- Duty Station not matching.
2981                        hr_utility.set_location('DS FAIL',45);
2982                         init_elig_flag := FALSE;
2983                     END IF;
2984                 ELSE -- Agency Code Subelement Not matching.
2985                     hr_utility.set_location('Agency FAIL',55);
2986                     init_elig_flag := FALSE;
2987                 END IF;
2988             ELSE -- Personnel Office ID not matching
2989                 hr_utility.set_location('POID FAIL',65);
2990                 init_elig_flag := FALSE;
2991             END IF;
2992         ELSE -- Organization_id is not matching.
2993             hr_utility.set_location('Org FAIL',75);
2994             init_elig_flag := FALSE;
2995         END IF;
2996     ELSE  -- If No value is entered for organization, Duty Station, Agency, POID of MSL Criteria.
2997        hr_utility.set_location('No INIT CRITERIA',85);
2998         init_elig_flag := TRUE;
2999     END IF;
3000 
3001     -- If the initial eligibility is passed then proceed further. Otherwise move to next record.
3002     IF init_elig_flag THEN
3003         hr_utility.set_location('Init Criteria Pass',95);
3004         ghr_pa_requests_pkg.get_sf52_asg_ddf_details
3005                                   (l_assignment_id,
3006                                    l_effective_date,
3007                                    l_tenure,
3008                                    l_annuitant_indicator,
3009                                    l_pay_rate_determinant,
3010                                    l_work_schedule,
3011                                    l_part_time_hour);
3012 
3013         FOR l_cnt in 1..p_rec_pp_prd.COUNT LOOP
3014            IF nvl(p_rec_pp_prd(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant THEN
3015                 hr_utility.set_location('PRD PASS',105);
3016                 l_prd_matched := TRUE;
3017                 exit;
3018            END IF;
3019         END LOOP;
3020 
3021         IF l_prd_matched THEN
3022             -- Bug#5089732 Used the overloaded procedure.
3023             BEGIN
3024                 get_pay_plan_and_table_id
3025                       (l_pay_rate_determinant,p_person_id,
3026                        l_position_id,l_effective_date,
3027                        l_grade_id, l_to_grade_id,l_assignment_id,'SHOW',
3028                        l_pay_plan,l_to_pay_plan,l_pay_table_id,
3029                        l_grade_or_level, l_to_grade_or_level, l_step_or_rate,
3030                        l_pay_basis);
3031             -- Bug#4016384 Added the exception handling to report RG employees in the process log.
3032             EXCEPTION
3033                 WHEN OTHERS THEN
3034                     -- Report the record in the process log if the pay table ID matches.
3035                     BEGIN
3036                         hr_utility.set_location('before calling expired_rg_det',10);
3037                         l_retained_grade_rec := ghr_pc_basic_pay.get_expired_rg_details
3038                                                   (p_person_id => p_person_id
3039                                                   ,p_effective_date => l_effective_date);
3040                         hr_utility.set_location('ret grd tableid:'||l_retained_grade_rec.user_table_id,99999);
3041                         hr_utility.set_location('MSL tableid:'||p_msl_user_table_id,99999);
3042                         IF l_retained_grade_rec.user_table_id = p_msl_user_table_id THEN
3043                             hr_utility.set_location('Rg table matches with MSL table ID',10);
3044 			    --Bug # 9329643 Modified SSN to Emp No
3045                             l_log_text  := 'Error in RG Record In Mass Salary Name: '||
3046                                             p_mass_salary_name||'; Employee Name: '|| p_full_name ||
3047                                             '; Emp No: ' || p_employee_number || '; '||
3048                                             hr_utility.get_message;
3049                             BEGIN
3050                                 ghr_mto_int.log_message(
3051                                       p_procedure => 'check_grade_retention',
3052                                       p_message   => l_log_text);
3053                                 g_rg_recs_failed := g_rg_recs_failed + 1;
3054                             EXCEPTION
3055                                 WHEN OTHERS THEN
3056                                    l_prd_pp_matched := FALSE;
3057                             END;
3058                         ELSE
3059                             l_prd_pp_matched := FALSE;
3060                         END IF;
3061                     EXCEPTION
3062                         WHEN OTHERS THEN
3063                             hr_utility.set_location('WHEN OTHERS of EXPIRED RG ',999999);
3064                             l_prd_pp_matched := FALSE;
3065                     END;
3066                 --WHEN OTHERS THEN
3067                     -- Skip this record from reporting.
3068                    -- l_prd_pp_matched := FALSE;
3069             END;
3070         END IF;
3071 
3072         FOR l_cnt in 1..p_rec_pp_prd.COUNT LOOP
3073            IF nvl(p_rec_pp_prd(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant AND
3074               nvl(p_rec_pp_prd(l_cnt).pay_plan,l_pay_plan) = l_pay_plan THEN
3075                 hr_utility.set_location('PP/PRD PASS',115);
3076                 l_prd_pp_matched := TRUE;
3077                 exit;
3078            END IF;
3079         END LOOP;
3080 
3081         IF l_prd_pp_matched THEN
3082             IF l_pay_table_id = p_msl_user_table_id THEN
3083                 hr_utility.set_location('Table ID PASS',125);
3084                 IF NOT (p_action = 'CREATE' AND
3085                             person_in_pa_req_1noa
3086                               (p_person_id      => p_person_id,
3087                                p_effective_date => l_effective_date,
3088                                p_first_noa_code => nvl(g_first_noa_code,'894'),
3089                                p_pay_plan       => p_pay_plan
3090                                )
3091                        )THEN
3092                      -- Pass l_pay_plan instead of l_to_pay_plan.
3093                      FOR msl_dtl IN msl_dtl_cur(l_pay_plan, l_pay_rate_determinant)
3094                      LOOP
3095                         IF msl_dtl.cnt <> 0 THEN
3096                         l_row_cnt := msl_dtl.cnt;
3097                         END IF;
3098                      END LOOP;
3099 
3100                     IF l_row_cnt <> 0 THEN
3101                         hr_utility.set_location('ROW COUNT PASS',135);
3102                         -- Get the required details if the related check has not been done above.
3103                         IF NOT l_fetch_poid_data THEN
3104 
3105                             get_pos_grp1_ddf(l_position_id,
3106                                              l_effective_date,
3107                                              l_pos_grp1_rec);
3108                         END IF;
3109 
3110                         IF NOT l_fetch_ds_data THEN
3111                             ghr_pa_requests_pkg.get_SF52_loc_ddf_details
3112                                         (p_location_id      => l_location_id
3113                                         ,p_duty_station_id  => l_duty_station_id);
3114                         END IF;
3115 
3116                         IF NOT l_fetch_agency_data THEN
3117                             get_sub_element_code_pos_title(
3118                                                          l_position_id,
3119                                                          p_person_id,
3120                                                          l_business_group_id,
3121                                                          l_assignment_id,
3122                                                          l_effective_date,
3123                                                          l_sub_element_code,
3124                                                          l_position_title,
3125                                                          l_position_number,
3126                                                          l_position_seq_no
3127                                                          );
3128                         END IF;
3129 
3130                         -- Set all the out parameters
3131                         p_elig_flag := TRUE;
3132                         p_personnel_office_id  := l_personnel_office_id;
3133                         p_org_structure_id     := l_org_structure_id;
3134                         p_position_title       := l_position_title;
3135                         p_position_number      := l_position_number;
3136                         p_position_seq_no      := l_position_seq_no;
3137                         p_subelem_code         := l_sub_element_code;
3138                         p_duty_station_id      := l_duty_station_id;
3139                         p_tenure               := l_tenure;
3140                         p_annuitant_indicator  := l_annuitant_indicator;
3141                         p_pay_rate_determinant := l_pay_rate_determinant;
3142                         p_work_schedule        := l_work_schedule;
3143                         p_part_time_hour       := l_part_time_hour;
3144                         p_to_grade_id          := l_to_grade_id;
3145                         p_pay_plan             := l_pay_plan;
3146                         p_to_pay_plan          := l_to_pay_plan;
3147                         p_pay_table_id         := l_pay_table_id;
3148                         p_grade_or_level       := l_grade_or_level;
3149                         p_to_grade_or_level    := l_to_grade_or_level;
3150                         p_step_or_rate         := l_step_or_rate;
3151                         p_pay_basis            := l_pay_basis;
3152                     ELSE -- If PP,PRD combinations are "0".
3153                         -- Raise Error
3154                         NULL;
3155                     END IF;
3156                 ELSE -- Not (Create and RPA exists)
3157                     hr_utility.set_location('ROW COUNT FAIL',145);
3158                     p_elig_flag := FALSE;
3159                 END IF;
3160             ELSE -- Pay table id is not matched
3161                 hr_utility.set_location('Pay Table FAIL',155);
3162                 p_elig_flag := FALSE;
3163             END IF;
3164         ELSE  -- Pay Plan and PRD not matched
3165             hr_utility.set_location('PP/PRD FAIL',165);
3166             p_elig_flag := FALSE;
3167         END IF;
3168     ELSE
3169         hr_utility.set_location('PP FAIL',175);
3170         p_elig_flag := FALSE;
3171     END IF;
3172 EXCEPTION
3173     WHEN others THEN
3174         hr_utility.set_location('WHEN OTHERS',185);
3175         RAISE;
3176 END fetch_and_validate_emp;
3177 --
3178 --
3179 --
3180 -- Bug#5063304 Created this new procedure
3181 PROCEDURE fetch_and_validate_emp_perc(
3182                               p_action              IN VARCHAR2
3183                              ,p_mass_salary_id      IN NUMBER
3184                              ,p_mass_salary_name    IN VARCHAR2
3185                              ,p_full_name           IN per_people_f.full_name%TYPE
3186 							 ,p_national_identifier IN per_people_f.national_identifier%TYPE
3187 							 --Bug # 9329643
3188 							 ,p_employee_number     IN per_people_f.employee_number%TYPE
3189                              ,p_assignment_id       IN per_assignments_f.assignment_id%TYPE
3190 							 ,p_person_id           IN per_assignments_f.person_id%TYPE
3191 							 ,p_position_id         IN per_assignments_f.position_id%TYPE
3192 							 ,p_grade_id            IN per_assignments_f.grade_id%TYPE
3193 							 ,p_business_group_id   IN per_assignments_f.business_group_iD%TYPE
3194 							 ,p_location_id         IN per_assignments_f.location_id%TYPE
3195 							 ,p_organization_id     IN per_assignments_f.organization_id%TYPE
3196                              ,p_msl_organization_id       IN per_assignments_f.organization_id%TYPE
3197                              ,p_msl_duty_station_id       IN ghr_duty_stations_f.duty_station_id%TYPE
3198                              ,p_msl_personnel_office_id    IN VARCHAR2
3199                              ,p_msl_agency_code_subelement IN VARCHAR2
3200                              ,p_msl_user_table_id          IN NUMBER
3201                              ,p_rec_pp_prd_per_gr          IN pp_prd_per_gr
3202                              ,p_personnel_office_id OUT NOCOPY VARCHAR2
3203                              ,p_org_structure_id    OUT NOCOPY VARCHAR2
3204                              ,p_position_title      OUT NOCOPY VARCHAR2
3205                              ,p_position_number     OUT NOCOPY VARCHAR2
3206                              ,p_position_seq_no     OUT NOCOPY VARCHAR2
3207                              ,p_subelem_code        OUT NOCOPY VARCHAR2
3208                              ,p_duty_station_id     OUT NOCOPY ghr_duty_stations_f.duty_station_id%TYPE
3209                              ,p_tenure              OUT NOCOPY VARCHAR2
3210                              ,p_annuitant_indicator OUT NOCOPY VARCHAR2
3211                              ,p_pay_rate_determinant OUT NOCOPY VARCHAR2
3212                              ,p_work_schedule       OUT NOCOPY  VARCHAR2
3213                              ,p_part_time_hour      OUT NOCOPY VARCHAR2
3214                              ,p_pay_plan            OUT NOCOPY VARCHAR2
3215                              ,p_pay_table_id        OUT NOCOPY NUMBER
3216                              ,p_grade_or_level      OUT NOCOPY VARCHAR2
3217                              ,p_step_or_rate        OUT NOCOPY VARCHAR2
3218                              ,p_pay_basis           OUT NOCOPY VARCHAR2
3219                              ,p_increase_percent    OUT NOCOPY NUMBER
3220                              ,p_elig_flag           OUT NOCOPY BOOLEAN
3221 			                ) IS
3222 
3223     CURSOR msl_dtl_cur (cur_pay_plan varchar2, cur_prd varchar2) IS
3224     SELECT count(*) cnt
3225       FROM ghr_mass_salary_criteria
3226      WHERE mass_salary_id = p_mass_salary_id
3227        AND pay_plan = cur_pay_plan
3228        AND pay_rate_determinant = cur_prd;
3229 
3230     l_row_cnt               NUMBER := 0;
3231     l_pos_grp1_rec          per_position_extra_info%rowtype;
3232     l_assignment_id         per_assignments_f.assignment_id%TYPE;
3233     l_person_id             per_assignments_f.person_id%TYPE;
3234     l_position_id           per_assignments_f.position_id%TYPE;
3235     l_grade_id              per_assignments_f.grade_id%TYPE;
3236     l_business_group_id     per_assignments_f.business_group_iD%TYPE;
3237     l_location_id           per_assignments_f.location_id%TYPE;
3238     l_organization_id       per_assignments_f.organization_id%TYPE;
3239     l_increase_percent      ghr_mass_actions_preview.increase_percent%type;
3240     l_tenure               VARCHAR2(35);
3241     l_annuitant_indicator  VARCHAR2(35);
3242     l_pay_rate_determinant VARCHAR2(35);
3243     l_work_schedule        VARCHAR2(35);
3244     l_part_time_hour       VARCHAR2(35);
3245     l_pay_table_id         NUMBER;
3246     l_pay_plan             VARCHAR2(30);
3247     l_grade_or_level       VARCHAR2(30);
3248     l_step_or_rate         VARCHAR2(30);
3249     l_pay_basis            VARCHAR2(30);
3250     l_duty_station_id      NUMBER;
3251     l_duty_station_desc    ghr_pa_requests.duty_station_desc%type;
3252     l_duty_station_code    ghr_pa_requests.duty_station_code%type;
3253     l_effective_date       DATE;
3254     l_personnel_office_id  VARCHAR2(300);
3255     l_org_structure_id     VARCHAR2(300);
3256     l_sub_element_code     VARCHAR2(300);
3257     l_position_title       VARCHAR2(300);
3258     l_position_number      VARCHAR2(20);
3259     l_position_seq_no      VARCHAR2(20);
3260     l_log_text             VARCHAR2(2000) := null;
3261     l_retained_grade_rec   ghr_pay_calc.retained_grade_rec_type;
3262     l_fetch_poid_data       BOOLEAN := FALSE;
3263     l_fetch_ds_data         BOOLEAN := FALSE;
3264     l_fetch_agency_data     BOOLEAN := FALSE;
3265     init_elig_flag          BOOLEAN := FALSE;
3266     l_prd_matched           BOOLEAN := FALSE;
3267     l_prd_pp_matched        BOOLEAN := FALSE;
3268 
3269     l_proc   varchar2(72) :=  g_package || '.fetch_and_validate_emp_perc';
3270 
3271 BEGIN
3272 
3273     g_proc  := 'fetch_and_validate_emp_perc';
3274     hr_utility.set_location('Entering    ' || l_proc,5);
3275     -- Bug#5623035 Moved the local variable declaratio to here.
3276     l_assignment_id     := p_assignment_id;
3277     l_position_id       := p_position_id;
3278     l_grade_id          := p_grade_id;
3279     l_business_group_id := p_business_group_iD;
3280     l_location_id       := p_location_id;
3281     l_effective_date    := g_effective_date;
3282     -- Verify whether this process is required or not.
3283     IF p_msl_organization_id IS NOT NULL  OR
3284        p_msl_duty_station_id IS NOT NULL  OR
3285        p_msl_personnel_office_id IS NOT NULL  OR
3286        p_msl_agency_code_subelement IS NOT NULL THEN
3287         -- get the values and verify whether the record meets the condition or not.
3288         -- If Yes, proceed further. Otherwise, skip the other checks for this record
3289 
3290         hr_utility.set_location('The location id is:'||l_location_id,12345);
3291         hr_utility.set_location('MSL Org ID:'||p_msl_organization_id,11111);
3292         hr_utility.set_location('Org ID:'||p_organization_id,22222);
3293         IF NVL(p_msl_organization_id,p_organization_id) = p_organization_id THEN
3294             hr_utility.set_location('Org ID PASS',10);
3295             IF p_msl_personnel_office_id IS NOT NULL THEN
3296                 hr_utility.set_location('POID CHECK',15);
3297                 get_pos_grp1_ddf(l_position_id,
3298                                  l_effective_date,
3299                                  l_pos_grp1_rec);
3300 
3301                 l_personnel_office_id :=  l_pos_grp1_rec.poei_information3;
3302                 l_org_structure_id    :=  l_pos_grp1_rec.poei_information5;
3303                 l_fetch_poid_data := TRUE;
3304             END IF;
3305             IF  (p_msl_personnel_office_id = l_personnel_office_id) OR
3306                 NOT(l_fetch_poid_data) THEN
3307                 hr_utility.set_location('POID PASS',20);
3308                 IF p_msl_agency_code_subelement IS NOT NULL THEN
3309                     hr_utility.set_location('Agency CHECK',25);
3310                     get_sub_element_code_pos_title(l_position_id,
3311                                              p_person_id,
3312                                              l_business_group_id,
3313                                              l_assignment_id,
3314                                              l_effective_date,
3315                                              l_sub_element_code,
3316                                              l_position_title,
3317                                              l_position_number,
3318                                              l_position_seq_no);
3319                     l_fetch_agency_data := TRUE;
3320                 END IF;
3321                 -- Bug#5674003 Modified the following IF condition
3322                 IF  (SUBSTR(p_msl_agency_code_subelement,1,2)  = SUBSTR(l_sub_element_code,1,2) AND
3323                      NVL(SUBSTR(p_msl_agency_code_subelement,3,2),SUBSTR(l_sub_element_code,3,2))=
3324                          SUBSTR(l_sub_element_code,3,2)
3325                     ) OR
3326                     NOT(l_fetch_agency_data) THEN
3327                                     hr_utility.set_location('Agency PASS',30);
3328                     IF p_msl_duty_station_id IS NOT NULL THEN
3329                         hr_utility.set_location('DS CHECK',35);
3330                         ghr_pa_requests_pkg.get_SF52_loc_ddf_details
3331                         (p_location_id      => l_location_id
3332                         ,p_duty_station_id  => l_duty_station_id);
3333                         l_fetch_ds_data := TRUE;
3334                     END IF;
3335                     IF (p_msl_duty_station_id = l_duty_station_id) OR
3336                        NOT(l_fetch_ds_data)THEN
3337                        hr_utility.set_location('DS PASS',40);
3338                         init_elig_flag := TRUE;
3339                     ELSE -- Duty Station not matching.
3340                        hr_utility.set_location('DS FAIL',45);
3341                         init_elig_flag := FALSE;
3342                     END IF;
3343                 ELSE -- Agency Code Subelement Not matching.
3344                     hr_utility.set_location('Agency FAIL',55);
3345                     init_elig_flag := FALSE;
3346                 END IF;
3347             ELSE -- Personnel Office ID not matching
3348                 hr_utility.set_location('POID FAIL',65);
3349                 init_elig_flag := FALSE;
3350             END IF;
3351         ELSE -- Organization_id is not matching.
3352             hr_utility.set_location('Org FAIL',75);
3353             init_elig_flag := FALSE;
3354         END IF;
3355     ELSE  -- If No value is entered for organization, Duty Station, Agency, POID of MSL Criteria.
3356        hr_utility.set_location('No INIT CRITERIA',85);
3357         init_elig_flag := TRUE;
3358     END IF;
3359 
3360     -- If the initial eligibility is passed then proceed further. Otherwise move to next record.
3361     IF init_elig_flag THEN
3362         hr_utility.set_location('Init Criteria Pass',95);
3363         ghr_pa_requests_pkg.get_sf52_asg_ddf_details
3364                                   (l_assignment_id,
3365                                    l_effective_date,
3366                                    l_tenure,
3367                                    l_annuitant_indicator,
3368                                    l_pay_rate_determinant,
3369                                    l_work_schedule,
3370                                    l_part_time_hour);
3371 
3372         FOR l_cnt in 1..p_rec_pp_prd_per_gr.COUNT LOOP
3373            IF nvl(p_rec_pp_prd_per_gr(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant THEN
3374                 hr_utility.set_location('PRD PASS',105);
3375                 l_prd_matched := TRUE;
3376                 exit;
3377            END IF;
3378         END LOOP;
3379 
3380         IF l_prd_matched THEN
3381             BEGIN
3382                 get_pay_plan_and_table_id(l_pay_rate_determinant,p_person_id,
3383                            l_position_id,l_effective_date,
3384                            l_grade_id, l_assignment_id,'SHOW',l_pay_plan,
3385                            l_pay_table_id,l_grade_or_level, l_step_or_rate,
3386                            l_pay_basis);
3387             -- Bug#4016384 Added the exception handling to report RG employees in the process log.
3388             EXCEPTION
3389                 WHEN MSL_ERROR THEN
3390                     -- Report the record in the process log if the pay table ID matches.
3391                     BEGIN
3392                         l_retained_grade_rec := ghr_pc_basic_pay.get_expired_rg_details
3393                                                   (p_person_id => p_person_id
3394                                                   ,p_effective_date => l_effective_date);
3395 
3396                         IF l_retained_grade_rec.user_table_id = p_msl_user_table_id THEN
3397 
3398 			     --Bug # 9329643 Modified SSN to Emp No
3399                             l_log_text  := 'Error in RG Record In Mass Salary Name: '||
3400                                             p_mass_salary_name||'; Employee Name: '|| p_full_name ||
3401                                             '; Emp No: ' || p_employee_number || '; '||
3402                                             hr_utility.get_message;
3403                             BEGIN
3404                                 ghr_mto_int.log_message(
3405                                       p_procedure => 'check_grade_retention',
3406                                       p_message   => l_log_text);
3407                                 g_rg_recs_failed := g_rg_recs_failed + 1;
3408                             EXCEPTION
3409                                 WHEN OTHERS THEN
3410                                    l_prd_pp_matched := FALSE;
3411                             END;
3412                         ELSE
3413                             l_prd_pp_matched := FALSE;
3414                         END IF;
3415                     EXCEPTION
3416                         WHEN OTHERS THEN
3417                             l_prd_pp_matched := FALSE;
3418                     END;
3419                 WHEN OTHERS THEN
3420                     -- Skip this record from reporting.
3421                     l_prd_pp_matched := FALSE;
3422             END;
3423         END IF;
3424 
3425         FOR l_cnt in 1..p_rec_pp_prd_per_gr.COUNT LOOP
3426            IF nvl(p_rec_pp_prd_per_gr(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant AND
3427               nvl(p_rec_pp_prd_per_gr(l_cnt).pay_plan,l_pay_plan) = l_pay_plan  AND
3428               nvl(p_rec_pp_prd_per_gr(l_cnt).grade,l_grade_or_level) = l_grade_or_level THEN
3429                 l_prd_pp_matched := TRUE;
3430                 l_increase_percent := nvl(p_rec_pp_prd_per_gr(l_cnt).percent,0);
3431                 EXIT;
3432            END IF;
3433         END LOOP;
3434 
3435         IF l_prd_pp_matched THEN
3436             IF l_pay_table_id = p_msl_user_table_id THEN
3437                 hr_utility.set_location('Table ID PASS',125);
3438                 IF NOT (p_action = 'CREATE' AND
3439                             person_in_pa_req_1noa
3440                               (p_person_id      => p_person_id,
3441                                p_effective_date => l_effective_date,
3442                                p_first_noa_code => nvl(g_first_noa_code,'894'),
3443                                p_pay_plan       => p_pay_plan
3444                                )
3445                        )THEN
3446                      FOR msl_dtl IN msl_dtl_cur(l_pay_plan, l_pay_rate_determinant)
3447                      LOOP
3448                         IF msl_dtl.cnt <> 0 THEN
3449                         l_row_cnt := msl_dtl.cnt;
3450                         END IF;
3451                      END LOOP;
3452 
3453                     IF l_row_cnt <> 0 THEN
3454                         hr_utility.set_location('ROW COUNT PASS',135);
3455                         -- Get the required details if the related check has not been done above.
3456                         IF NOT l_fetch_poid_data THEN
3457 
3458                             get_pos_grp1_ddf(l_position_id,
3459                                              l_effective_date,
3460                                              l_pos_grp1_rec);
3461                         END IF;
3462 
3463                         IF NOT l_fetch_ds_data THEN
3464                             ghr_pa_requests_pkg.get_SF52_loc_ddf_details
3465                                         (p_location_id      => l_location_id
3466                                         ,p_duty_station_id  => l_duty_station_id);
3467                         END IF;
3468 
3469                         IF NOT l_fetch_agency_data THEN
3470                             get_sub_element_code_pos_title(
3471                                                          l_position_id,
3472                                                          p_person_id,
3473                                                          l_business_group_id,
3474                                                          l_assignment_id,
3475                                                          l_effective_date,
3476                                                          l_sub_element_code,
3477                                                          l_position_title,
3478                                                          l_position_number,
3479                                                          l_position_seq_no
3480                                                          );
3481                         END IF;
3482 
3483                         -- Set all the out parameters
3484                         p_elig_flag := TRUE;
3485                         p_personnel_office_id  := l_personnel_office_id;
3486                         p_org_structure_id     := l_org_structure_id;
3487                         p_position_title       := l_position_title;
3488                         p_position_number      := l_position_number;
3489                         p_position_seq_no      := l_position_seq_no;
3490                         p_subelem_code         := l_sub_element_code;
3491                         p_duty_station_id      := l_duty_station_id;
3492                         p_tenure               := l_tenure;
3493                         p_annuitant_indicator  := l_annuitant_indicator;
3494                         p_pay_rate_determinant := l_pay_rate_determinant;
3495                         p_work_schedule        := l_work_schedule;
3496                         p_part_time_hour       := l_part_time_hour;
3497                         p_pay_plan             := l_pay_plan;
3498                         p_pay_table_id         := l_pay_table_id;
3499                         p_grade_or_level       := l_grade_or_level;
3500                         p_step_or_rate         := l_step_or_rate;
3501                         p_pay_basis            := l_pay_basis;
3502                         p_increase_percent     := l_increase_percent;
3503                     ELSE -- If PP,PRD combinations are "0".
3504                         -- Raise Error
3505                         NULL;
3506                     END IF;
3507                 ELSE -- Not (Create and RPA exists)
3508                     hr_utility.set_location('ROW COUNT FAIL',145);
3509                     p_elig_flag := FALSE;
3510                 END IF;
3511             ELSE -- Pay table id is not matched
3512                 hr_utility.set_location('Pay Table FAIL',155);
3513                 p_elig_flag := FALSE;
3514             END IF;
3515         ELSE  -- Pay Plan and PRD not matched
3516             hr_utility.set_location('PP/PRD FAIL',165);
3517             p_elig_flag := FALSE;
3518         END IF;
3519     ELSE
3520         hr_utility.set_location('PP FAIL',175);
3521         p_elig_flag := FALSE;
3522     END IF;
3523 EXCEPTION
3524     WHEN others THEN
3525         hr_utility.set_location('WHEN OTHERS',185);
3526         RAISE;
3527 END fetch_and_validate_emp_perc;
3528 --
3529 --
3530 --
3531 
3532 FUNCTION check_init_eligibility(p_duty_station_id in number,
3533                             p_PERSONNEL_OFFICE_ID in varchar2,
3534                             p_AGENCY_CODE_SUBELEMENT   in varchar2,
3535                             p_l_duty_station_id   in number,
3536                             p_l_personnel_office_id in varchar2,
3537                             p_l_sub_element_code in varchar2)
3538 return boolean is
3539 
3540 CURSOR cur_valid_DS(p_ds_id NUMBER)
3541 IS
3542 SELECT effective_end_date  end_date
3543 FROM   ghr_duty_stations_f
3544 WHERE  duty_station_id=p_ds_id
3545 AND    g_effective_date between effective_start_date and effective_end_date;
3546 
3547 l_ds_end_date	ghr_duty_stations_f.effective_end_date%type;
3548 
3549 
3550 l_proc   varchar2(72) :=  g_package || '.check_init_eligibility';
3551 BEGIN
3552 
3553   g_proc  := 'check_init_eligibility';
3554   hr_utility.set_location('Entering    ' || l_proc,5);
3555 
3556   if p_personnel_office_id is not null then
3557       if p_personnel_office_id <> nvl(p_l_personnel_office_id,'NULL!~') then
3558          return false;
3559       end if;
3560   end if;
3561 
3562 -- VSM [Masscrit.doc]
3563 -- 2 char - Test for Agency Code only
3564 -- 4 char Test for agency and subelement
3565   if p_agency_code_subelement is not null then
3566       if substr(p_agency_code_subelement, 1, 2) <> nvl(substr(p_l_sub_element_code, 1, 2), 'NULL!~') then
3567          return false;
3568       end if;
3569   end if;
3570 
3571   if substr(p_agency_code_subelement, 3, 2) is not null then
3572       if substr(p_agency_code_subelement, 3, 2) <> nvl(substr(p_l_sub_element_code, 3, 2), 'NULL!~') then
3573          return false;
3574       end if;
3575   end if;
3576 
3577 -- Start of Bug3437354
3578 --
3579 -- Added this condition for bug 3437354, error out the record without valid Loc id
3580 --
3581       if p_duty_station_id <> nvl(p_l_duty_station_id,0) then
3582          return false;
3583       end if;
3584 
3585     FOR rec_ds in cur_valid_ds(p_l_duty_station_id)
3586     LOOP
3587       l_ds_end_date	:= rec_ds.end_Date;
3588     END LOOP;
3589 
3590      If l_ds_end_date IS NULL THEN
3591      hr_utility.set_location('Under DS null check'||p_l_duty_station_id,12345);
3592      raise msl_error;
3593      return false;
3594      end if;
3595 -- End of bug 3437354
3596 --
3597   pr('Eligible');
3598   return true;
3599 exception
3600   when msl_error then --raise;
3601    hr_utility.set_location('Error NO DUTY STATION '||l_proc||' Err is '||sqlerrm(sqlcode),20);
3602      l_mslerrbuf :=
3603      'Error - No valid Location found, salary cannot be correctly calculated without the employee''s duty location ';
3604      raise msl_error;
3605   when others then
3606      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
3607      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
3608      raise msl_error;
3609 END check_init_eligibility;
3610 
3611 
3612 FUNCTION check_eligibility(p_mass_salary_id  in number,
3613                            p_user_table_id   in  number,
3614                            p_pay_table_id    in  number,
3615                            p_pay_plan        in  varchar2,
3616                            p_pay_rate_determinant in varchar2,
3617                            p_person_id in number,
3618                            p_effective_date in date,
3619                            p_action in varchar2)
3620 return boolean is
3621 
3622    cursor msl_dtl_cur (cur_pay_plan varchar2, cur_prd varchar2) is
3623    select count(*) count
3624      from ghr_mass_salary_criteria
3625     where mass_salary_id = p_mass_salary_id
3626       and pay_plan = cur_pay_plan
3627       and pay_rate_determinant = cur_prd;
3628 
3629    l_row_cnt      number := 0;
3630 l_proc   varchar2(72) :=  g_package || '.check_eligibility';
3631 BEGIN
3632   g_proc  := 'check_eligibility';
3633   hr_utility.set_location('Entering    ' || l_proc,5);
3634    --return true;
3635 
3636    if p_user_table_id is null or p_pay_table_id is null then
3637           return false;
3638    end if;
3639 
3640 /************ on 3/21/1998
3641    if p_pay_rate_determinant not in ('0','2','3','4','6','A','B','E','F','J','K','R','S','U','V')
3642        then
3643            return false;
3644    end if;
3645 **************/
3646 
3647    if p_pay_plan is null or p_pay_rate_determinant is null then
3648   ghr_mre_pkg.pr('pay plan, prd failed');
3649         return false;
3650    end if;
3651 
3652    IF p_user_table_id <> p_pay_table_id THEN
3653   ghr_mre_pkg.pr('pay table id failed');
3654       return false;
3655    END IF;
3656 
3657    FOR msl_dtl IN msl_dtl_cur(p_pay_plan, p_pay_rate_determinant)
3658    LOOP
3659       if msl_dtl.count <> 0 then
3660           l_row_cnt := msl_dtl.count;
3661       end if;
3662    END LOOP;
3663 
3664    IF l_row_cnt = 0 THEN
3665       RETURN FALSE;
3666    END IF;
3667 
3668   if p_action = 'CREATE' THEN
3669   if person_in_pa_req_1noa
3670           (p_person_id      => p_person_id,
3671            p_effective_date => p_effective_date,
3672            p_first_noa_code => nvl(g_first_noa_code,'894'),
3673            p_pay_plan       => p_pay_plan
3674            ) then
3675   ghr_mre_pkg.pr('1noa failed',to_char(p_person_id));
3676        return false;
3677    ELSE
3678   ghr_mre_pkg.pr('Eligible');
3679       RETURN TRUE;
3680   end if;
3681   end if;
3682 /************ This is not required****************
3683   if person_in_pa_req_2noa
3684           (p_person_id      => p_person_id,
3685            p_effective_date => p_effective_date,
3686            p_second_noa_code => '894'
3687            ) then
3688   ghr_mre_pkg.pr('2noa failed',to_char(p_person_id));
3689        return false;
3690   end if;
3691 
3692 *********** This is not required****************/
3693  return true;
3694 exception
3695   when msl_error then raise;
3696   when others then
3697      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
3698      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
3699      raise msl_error;
3700 END check_eligibility;
3701 
3702 --
3703 --
3704 --
3705 
3706 function person_in_pa_req_1noa
3707           (p_person_id      in number,
3708            p_effective_date in date,
3709            p_first_noa_code in varchar2,
3710            p_pay_plan       in varchar2,
3711            p_days           in number default 350
3712            )
3713   return boolean is
3714 --
3715   l_name            per_people_f.full_name%type;
3716   -- Bug#3718167  Added l_ssn
3717   l_ssn             per_people_f.national_identifier%TYPE;
3718   l_pa_request_id   ghr_pa_requests.pa_request_id%TYPE;
3719   --Bug # 9329643
3720   l_employee_number  per_people_f.employee_number%type;
3721 
3722   cursor csr_action_taken is
3723       select pr.pa_request_id, max(pa_routing_history_id) pa_routing_history_id
3724         from ghr_pa_requests pr, ghr_pa_routing_history prh
3725       where pr.pa_request_id = prh.pa_request_id
3726       and   person_id = p_person_id
3727       and   first_noa_code = p_first_noa_code
3728       and   effective_date = p_effective_date
3729       and nvl(pr.first_noa_cancel_or_correct,'X') <> ghr_history_api.g_cancel
3730 ---- Bug # 657439
3731       --and nvl(pr.first_noa_cancel_or_correct,'X') <> 'CANCELED'
3732       group by pr.pa_request_id;
3733 
3734     -- Bug#3718167
3735     cursor csr_name_ssn is
3736     select substr(pr.employee_last_name || ', ' || pr.employee_first_name,1,240) fname,
3737            pr.employee_national_identifier SSN
3738     from ghr_pa_requests pr
3739     where pr.pa_request_id = l_pa_request_id;
3740 
3741   cursor csr_action_taken_fw is
3742       select pr.pa_request_id, max(pa_routing_history_id) pa_routing_history_id
3743         from ghr_pa_requests pr, ghr_pa_routing_history prh
3744       where pr.pa_request_id = prh.pa_request_id
3745       and   person_id        = p_person_id
3746       and   first_noa_code   = p_first_noa_code
3747       and   effective_date   = p_effective_date
3748       and nvl(pr.first_noa_cancel_or_correct,'X') <> ghr_history_api.g_cancel
3749       group by pr.pa_request_id;
3750 
3751   cursor csr_eq_pay_plan is
3752       SELECT equivalent_pay_plan
3753       FROM ghr_pay_plans
3754      WHERE pay_plan = p_pay_plan;
3755 
3756     cursor pa_hist_cur (p_r_hist_id number) is
3757       select nvl(action_taken,' ') action_taken
3758         from ghr_pa_routing_history
3759       where pa_routing_history_id = p_r_hist_id;
3760 
3761   l_action_taken    ghr_pa_routing_history.action_taken%TYPE;
3762   l_proc     varchar2(72) :=  g_package || '.person_in_pa_req_1noa';
3763   l_eq_pay_plan     ghr_pay_plans.equivalent_pay_plan%type;
3764 
3765 begin
3766   g_proc  := 'person_in_pa_req_1noa';
3767   hr_utility.set_location('Entering    ' || l_proc,5);
3768 -- Bug 1631952 start
3769    for csr_eq_pay_plan_rec in csr_eq_pay_plan loop
3770       l_eq_pay_plan := csr_eq_pay_plan_rec.equivalent_pay_plan;
3771    end loop;
3772 
3773  if l_eq_pay_plan = 'FW' then
3774    for v_action_taken_fw in csr_action_taken_fw loop
3775        l_pa_request_id := v_action_taken_fw.pa_request_id;
3776        for v_name in csr_name_ssn
3777        loop
3778            l_name := v_name.fname;
3779 	   -- Bug#3718167 Added l_ssn statement
3780 	   l_ssn  := v_name.ssn;
3781        exit;
3782        end loop;
3783 
3784        for pa_hist_rec in pa_hist_cur (v_action_taken_fw.pa_routing_history_id)
3785        loop
3786            l_action_taken := pa_hist_rec.action_taken;
3787            exit;
3788        end loop;
3789         --Bug # 9329643
3790        If p_person_id is not null then
3791           l_employee_number := ghr_pa_requests_pkg2.get_employee_number
3792                                 (p_person_id => p_person_id,
3793 	        	         p_effective_date => p_effective_date);
3794        End if;
3795       if l_action_taken <> 'CANCELED' then
3796 	  -- Bug#3718167 Added SSN in the following message
3797 	  --Bug # 9329643 Modified SSN to Emp No
3798           ghr_mto_int.log_message(
3799           p_procedure => 'RPA Exists Already',
3800           p_message   => 'Name: '|| l_name || '; Emp No: '||l_employee_number||
3801 	                 ' - Salary Change ' ||
3802                          ' RPA Exists for the given FWS pay_lan and effective date' );
3803          return true;
3804       end if;
3805    end loop;
3806  else
3807 --- Bug 1631952 end.  The same bug was extended to GS equvalent pay plans.
3808    for v_action_taken in csr_action_taken loop
3809        l_pa_request_id := v_action_taken.pa_request_id;
3810        for v_name in csr_name_ssn
3811        loop
3812            l_name := v_name.fname;
3813 	   -- Bug#3718167 Added l_ssn statement
3814 	   l_ssn  := v_name.ssn;
3815        exit;
3816        end loop;
3817 
3818        for pa_hist_rec in pa_hist_cur (v_action_taken.pa_routing_history_id)
3819        loop
3820            l_action_taken := pa_hist_rec.action_taken;
3821            exit;
3822        end loop;
3823          --Bug # 9329643
3824        If p_person_id is not null then
3825           l_employee_number := ghr_pa_requests_pkg2.get_employee_number
3826                                 (p_person_id => p_person_id,
3827 	        	         p_effective_date => p_effective_date);
3828        End if;
3829       if l_action_taken <> 'CANCELED' then
3830           -- Bug#3718167 Added SSN in the following message
3831   	  --Bug # 9329643 Modified SSN to Emp No
3832           ghr_mto_int.log_message(
3833           p_procedure => 'RPA Exists Already',
3834           p_message   => 'Name: '|| l_name || '; Emp No: '||l_employee_number||
3835 	                 ' - Salary Change ' ||
3836                          ' RPA Exists for the given effective date ' );
3837          return true;
3838       end if;
3839 
3840    end loop;
3841  end if; ------Bug 1631952
3842    return false;
3843 end person_in_pa_req_1noa;
3844 
3845 --
3846 --
3847 --
3848 
3849 function person_in_pa_req_2noa
3850           (p_person_id      in number,
3851            p_effective_date in date,
3852            p_second_noa_code in varchar2,
3853            p_days           in number default 350
3854            )
3855   return boolean is
3856 --
3857   cursor csr_action_taken is
3858       select pr.pa_request_id, max(pa_routing_history_id) pa_routing_history_id
3859         from ghr_pa_requests pr, ghr_pa_routing_history prh
3860       where pr.pa_request_id = prh.pa_request_id
3861       and   nvl(person_id,0) = p_person_id
3862       and   nvl(second_noa_code,0) = p_second_noa_code
3863       and   nvl(effective_date,trunc(sysdate)) >= (p_effective_date-p_days)
3864       and nvl(pr.second_noa_cancel_or_correct,'X') <> ghr_history_api.g_cancel
3865 --Bug 657439
3866 --      and nvl(pr.second_noa_cancel_or_correct,'X') <> 'CANCELED'
3867       group by pr.pa_request_id;
3868 
3869     cursor pa_hist_cur (p_r_hist_id number) is
3870       select nvl(action_taken,' ') action_taken
3871         from ghr_pa_routing_history
3872       where pa_routing_history_id = p_r_hist_id;
3873 
3874   l_action_taken    ghr_pa_routing_history.action_taken%TYPE;
3875   l_proc     varchar2(72) :=  g_package || '.person_in_pa_req_2noa';
3876 begin
3877   g_proc  := 'person_in_pa_req_2noa';
3878   hr_utility.set_location('Entering    ' || l_proc,5);
3879    for v_action_taken in csr_action_taken loop
3880        for pa_hist_rec in pa_hist_cur (v_action_taken.pa_routing_history_id)
3881        loop
3882            l_action_taken := pa_hist_rec.action_taken;
3883            exit;
3884        end loop;
3885       if l_action_taken <> 'CANCELED' then
3886          return true;
3887       end if;
3888    end loop;
3889    return false;
3890 end person_in_pa_req_2noa;
3891 
3892 --
3893 --
3894 --
3895 
3896 FUNCTION check_grade_retention(p_prd in varchar2
3897                               ,p_person_id in number
3898                               ,p_effective_date in date) return varchar2 is
3899 
3900 l_retained_grade_rec  ghr_pay_calc.retained_grade_rec_type;
3901 l_per_ei_data         per_people_extra_info%rowtype;
3902 
3903 l_proc  varchar2(72) :=  g_package || '.check_grade_retention';
3904 
3905 BEGIN
3906   g_proc  := 'check_grade_retention';
3907   hr_utility.set_location('Entering    ' || l_proc,5);
3908   IF p_prd in ('A','B','E','F','U','V') THEN
3909      IF p_prd in ('A','B','E','F') THEN
3910        -- Bug#4179270,4126137,4086677 Removed the History Fetch call.
3911        -- Note: Do not use fetch_peopleei to get Retained grade details as it
3912        --       is not date tracked.
3913        BEGIN
3914 	       l_retained_grade_rec :=
3915                    ghr_pc_basic_pay.get_retained_grade_details
3916                                       ( p_person_id,
3917                                         p_effective_date);
3918 	       IF l_retained_grade_rec.temp_step is not null THEN
3919 		      return 'REGULAR';
3920 	       END IF;
3921 	   EXCEPTION
3922            WHEN ghr_pay_calc.pay_calc_message THEN
3923                  raise msl_error;
3924            WHEN OTHERS THEN
3925                 raise;
3926        END;
3927      END IF;
3928      return 'RETAIN';
3929   ELSE
3930      return 'REGULAR';
3931   END IF;
3932 EXCEPTION
3933   when msl_error then
3934      RETURN 'MSL_ERROR';
3935   when others then
3936      RETURN 'OTHER_ERROR';
3937 END CHECK_GRADE_RETENTION;
3938 
3939 --
3940 --
3941 --
3942 
3943 procedure get_pos_grp1_ddf (p_position_id in per_assignments_f.position_id%type,
3944                             p_effective_date in date,
3945                             p_pos_ei_data     out nocopy per_position_extra_info%rowtype)
3946 IS
3947 
3948 l_proc  varchar2(72) :=  g_package || '.get_pos_grp1_ddf';
3949 --l_pos_ei_data         per_position_extra_info%type;
3950 
3951 begin
3952   g_proc  := 'get_pos_grp1_ddf';
3953   hr_utility.set_location('Entering    ' || l_proc,5);
3954      ghr_history_fetch.fetch_positionei
3955                   (p_position_id           => p_position_id
3956                   ,p_information_type      => 'GHR_US_POS_GRP1'
3957                   ,p_date_effective        => p_effective_date
3958                   ,p_pos_ei_data           => p_pos_ei_data
3959                                         );
3960      hr_utility.set_location('Exiting    ' || l_proc,10);
3961 exception
3962   when msl_error then raise;
3963   when others then
3964      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
3965      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
3966      raise msl_error;
3967 END get_pos_grp1_ddf;
3968 
3969 --
3970 --
3971 --
3972 
3973 procedure get_from_sf52_data_elements (p_assignment_id in number,
3974                                        p_effective_date in date,
3975                                        p_old_basic_pay out nocopy number,
3976                                        p_old_avail_pay out nocopy number,
3977                                        p_old_loc_diff out nocopy number,
3978                                        p_tot_old_sal out nocopy number,
3979                                        p_old_auo_pay out nocopy number,
3980                                        p_old_adj_basic_pay out nocopy number,
3981                                        p_other_pay out nocopy number,
3982                                        p_auo_premium_pay_indicator out nocopy varchar2,
3983                                        p_ap_premium_pay_indicator out nocopy varchar2,
3984                                        p_retention_allowance out nocopy number,
3985                                        p_retention_allow_perc out nocopy number,
3986                                        p_supervisory_differential out nocopy number,
3987                                        p_supervisory_diff_perc out nocopy number,
3988                                        p_staffing_differential out nocopy number) is
3989 
3990   l_multi_error_flag    boolean;
3991   l_total_salary        number;
3992   l_basic_pay           number;
3993   l_locality_adj        number;
3994   l_adj_basic_pay       number;
3995   l_other_pay           number;
3996   l_au_overtime               NUMBER;
3997   l_auo_premium_pay_indicator VARCHAR2(30);
3998   l_availability_pay          NUMBER;
3999   l_ap_premium_pay_indicator  VARCHAR2(30);
4000   l_retention_allowance       NUMBER;
4001   l_retention_allow_perc      NUMBER;
4002   l_supervisory_differential  NUMBER;
4003   l_supervisory_diff_perc     NUMBER;
4004   l_staffing_differential     NUMBER;
4005 l_proc   varchar2(72) :=  g_package || '.get_from_sf52_data_elements';
4006 
4007 BEGIN
4008 
4009   g_proc  := 'get_from_sf52_data_elements';
4010   hr_utility.set_location('Entering    ' || l_proc,5);
4011 
4012 -- Processing Total Pay and Adjusted Basic Pay
4013 -- NAME    DATE       BUG           COMMENTS
4014 -- Ashley  17-JUL-03  Payroll Intg  Modified the Input Value name
4015 --                                  Changes from Total Salary -> Amount
4016 --                                               Adjusted Pay -> Amount
4017 
4018   ghr_api.retrieve_element_entry_value
4019                        (p_element_name    => 'Total Pay'
4020                        ,p_input_value_name      => 'Amount'
4021                        ,p_assignment_id         => p_assignment_id
4022                        ,p_effective_date        => p_effective_date
4023                        ,p_value                 => l_total_salary
4024                        ,p_multiple_error_flag   => l_multi_error_flag);
4025 
4026   hr_utility.set_location('Total Pay = ' || to_char(l_total_salary), 6);
4027 
4028   if l_multi_error_flag then
4029     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4030     hr_utility.raise_error;
4031   end if;
4032 
4033   ghr_api.retrieve_element_entry_value
4034                        (p_element_name  => 'Basic Salary Rate'
4035                        ,p_input_value_name      => 'Rate'
4036                        ,p_assignment_id         => p_assignment_id
4037                        ,p_effective_date        => p_effective_date
4038                        ,p_value                 => l_basic_pay
4039                        ,p_multiple_error_flag   => l_multi_error_flag);
4040 
4041   hr_utility.set_location('Basic Salary Rate = ' || to_char(l_basic_pay), 6);
4042 
4043   if l_multi_error_flag then
4044     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4045     hr_utility.raise_error;
4046   end if;
4047 
4048  ghr_api.retrieve_element_entry_value
4049  -- FWFA Changes Bug#4444609
4050                        (p_element_name   => 'Locality Pay or SR Supplement'
4051  -- FWFA Changes Modify 'Locality Pay' to 'Locality Pay or SR Supplement'
4052                        ,p_input_value_name      => 'Rate'
4053 -- Changed by Ashu. 'Amount' to 'Rate'
4054                        ,p_assignment_id         => p_assignment_id
4055                        ,p_effective_date        => p_effective_date
4056                        ,p_value                 => l_locality_adj
4057                        ,p_multiple_error_flag   => l_multi_error_flag);
4058 
4059   hr_utility.set_location('Locality Pay = ' || to_char(l_locality_adj), 6);
4060 
4061   if l_multi_error_flag then
4062     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4063     hr_utility.raise_error;
4064   end if;
4065 
4066   ghr_api.retrieve_element_entry_value
4067                        (p_element_name  => 'Adjusted Basic Pay'
4068                        ,p_input_value_name      => 'Amount'
4069                        ,p_assignment_id         => p_assignment_id
4070                        ,p_effective_date        => p_effective_date
4071                        ,p_value                 => l_adj_basic_pay
4072                        ,p_multiple_error_flag   => l_multi_error_flag);
4073 
4074   hr_utility.set_location('Adjusted Basic Pay = ' || to_char(l_adj_basic_pay), 6);
4075 
4076   if l_multi_error_flag then
4077     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4078     hr_utility.raise_error;
4079   end if;
4080 
4081   ghr_api.retrieve_element_entry_value
4082                        (p_element_name  => 'Other Pay'
4083                        ,p_input_value_name      => 'Amount'
4084                        ,p_assignment_id         => p_assignment_id
4085                        ,p_effective_date        => p_effective_date
4086                        ,p_value                 => l_other_pay
4087                        ,p_multiple_error_flag   => l_multi_error_flag);
4088 
4089   hr_utility.set_location('Other Pay = ' || to_char(l_other_pay), 6);
4090 
4091   if l_multi_error_flag then
4092     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4093     hr_utility.raise_error;
4094   end if;
4095 
4096   ghr_api.retrieve_element_entry_value
4097                        (p_element_name  => 'AUO'
4098                        ,p_input_value_name      => 'Amount'
4099                        ,p_assignment_id         => p_assignment_id
4100                        ,p_effective_date        => p_effective_date
4101                        ,p_value                 => l_au_overtime
4102                        ,p_multiple_error_flag   => l_multi_error_flag);
4103 
4104   hr_utility.set_location('AUO Amount = ' || to_char(l_au_overtime), 6);
4105 
4106   if l_multi_error_flag then
4107     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4108     hr_utility.raise_error;
4109   end if;
4110 
4111   ghr_api.retrieve_element_entry_value
4112                        (p_element_name  => 'AUO'
4113                        ,p_input_value_name      => 'Premium Pay Ind'
4114                        ,p_assignment_id         => p_assignment_id
4115                        ,p_effective_date        => p_effective_date
4116                        ,p_value                 => l_auo_premium_pay_indicator
4117                        ,p_multiple_error_flag   => l_multi_error_flag);
4118 
4119   if l_multi_error_flag then
4120     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4121     hr_utility.raise_error;
4122   end if;
4123 
4124   ghr_api.retrieve_element_entry_value
4125                        (p_element_name  => 'Availability Pay'
4126                        ,p_input_value_name      => 'Amount'
4127                        ,p_assignment_id         => p_assignment_id
4128                        ,p_effective_date        => p_effective_date
4129                        ,p_value                 => l_availability_pay
4130                        ,p_multiple_error_flag   => l_multi_error_flag);
4131 
4132   hr_utility.set_location('Availability Pay Amount = ' || to_char(l_availability_pay), 6);
4133 
4134   if l_multi_error_flag then
4135     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4136     hr_utility.raise_error;
4137   end if;
4138 
4139   ghr_api.retrieve_element_entry_value
4140                        (p_element_name  => 'Availability Pay'
4141                        ,p_input_value_name      => 'Premium Pay Ind'
4142                        ,p_assignment_id         => p_assignment_id
4143                        ,p_effective_date        => p_effective_date
4144                        ,p_value                 => l_ap_premium_pay_indicator
4145                        ,p_multiple_error_flag   => l_multi_error_flag);
4146 
4147   if l_multi_error_flag then
4148     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4149     hr_utility.raise_error;
4150   end if;
4151   --
4152   ghr_api.retrieve_element_entry_value
4153                        (p_element_name  => 'Retention Allowance'
4154                        ,p_input_value_name      => 'Amount'
4155                        ,p_assignment_id         => p_assignment_id
4156                        ,p_effective_date        => p_effective_date
4157                        ,p_value                 => l_retention_allowance
4158                        ,p_multiple_error_flag   => l_multi_error_flag);
4159 
4160   hr_utility.set_location('Retention Allowance Amount = ' || to_char(l_retention_allowance), 6);
4161 
4162   if l_multi_error_flag then
4163     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4164     hr_utility.raise_error;
4165   end if;
4166 
4167   ghr_api.retrieve_element_entry_value
4168                        (p_element_name  => 'Retention Allowance'
4169                        ,p_input_value_name      => 'Percentage'
4170                        ,p_assignment_id         => p_assignment_id
4171                        ,p_effective_date        => p_effective_date
4172                        ,p_value                 => l_retention_allow_perc
4173                        ,p_multiple_error_flag   => l_multi_error_flag);
4174 
4175   hr_utility.set_location('Retention Allowance Percent = ' || to_char(l_retention_allow_perc), 6);
4176 
4177   if l_multi_error_flag then
4178     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4179     hr_utility.raise_error;
4180   end if;
4181 
4182   ghr_api.retrieve_element_entry_value
4183                        (p_element_name    => 'Supervisory Differential'
4184                        ,p_input_value_name      => 'Amount'
4185                        ,p_assignment_id         => p_assignment_id
4186                        ,p_effective_date        => p_effective_date
4187                        ,p_value                 => l_supervisory_differential
4188                        ,p_multiple_error_flag   => l_multi_error_flag);
4189 
4190   hr_utility.set_location('Supervisory Diff Amount = ' || to_char(l_supervisory_differential), 6);
4191 
4192   if l_multi_error_flag then
4193     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4194     hr_utility.raise_error;
4195   end if;
4196 
4197   ghr_api.retrieve_element_entry_value
4198                        (p_element_name    => 'Supervisory Differential'
4199                        ,p_input_value_name      => 'Percentage'
4200                        ,p_assignment_id         => p_assignment_id
4201                        ,p_effective_date        => p_effective_date
4202                        ,p_value                 => l_supervisory_diff_perc
4203                        ,p_multiple_error_flag   => l_multi_error_flag);
4204 
4205   hr_utility.set_location('Supervisory Diff Percent = ' || to_char(l_supervisory_diff_perc), 6);
4206 
4207   if l_multi_error_flag then
4208     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4209     hr_utility.raise_error;
4210   end if;
4211 
4212  --
4213  --
4214   ghr_api.retrieve_element_entry_value
4215                        (p_element_name  => 'Staffing Differential'
4216                        ,p_input_value_name    => 'Amount'
4217                        ,p_assignment_id       => p_assignment_id
4218                        ,p_effective_date      => p_effective_date
4219                        ,p_value               => l_staffing_differential
4220                        ,p_multiple_error_flag => l_multi_error_flag);
4221 
4222   hr_utility.set_location('Staffing Diff Amount = ' || to_char(l_staffing_differential), 6);
4223 
4224   if l_multi_error_flag then
4225     hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
4226     hr_utility.raise_error;
4227   end if;
4228 
4229   p_tot_old_sal               := round(l_total_salary,2);
4230   p_OLD_BASIC_PAY             := round(l_basic_pay,2);
4231   p_OLD_LOC_DIFF              := round(l_locality_adj,0);
4232   p_old_adj_basic_pay         := round(l_adj_basic_pay,2);
4233   p_other_pay                 := l_other_pay;
4234   p_OLD_AUO_PAY               := l_au_overtime;
4235   p_auo_premium_pay_indicator := l_auo_premium_pay_indicator;
4236   p_OLD_AVAIL_PAY             := l_availability_pay;
4237   p_ap_premium_pay_indicator  := l_ap_premium_pay_indicator;
4238   p_retention_allowance       := l_retention_allowance;
4239   p_retention_allow_perc      := l_retention_allow_perc;
4240   p_supervisory_differential  := l_supervisory_differential;
4241   p_supervisory_diff_perc     := l_supervisory_diff_perc;
4242   p_staffing_differential     := l_staffing_differential;
4243 
4244   hr_utility.set_location('Exiting    ' || l_proc,10);
4245 
4246 exception
4247   when msl_error then raise;
4248   when others then
4249      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4250      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4251      raise msl_error;
4252 END GET_FROM_SF52_DATA_ELEMENTS;
4253 
4254 --
4255 --
4256 --
4257 
4258 procedure get_sub_element_code_pos_title
4259                (p_position_id in per_assignments_f.position_id%type,
4260                 p_person_id in number,
4261                 p_business_group_id in per_assignments_f.business_group_id%type,
4262                 p_assignment_id in per_assignments_f.assignment_id%type,
4263                 p_effective_date in date,
4264                 p_sub_element_code out nocopy varchar2,
4265                 p_position_title   out nocopy varchar2,
4266                 p_position_number   out nocopy varchar2,
4267                 p_position_seq_no   out nocopy varchar2) is
4268 l_proc     varchar2(72) :=  g_package || '.get_sub_element_code_pos_title';
4269 begin
4270   g_proc  := 'get_sub_element_code_pos_title';
4271   hr_utility.set_location('Entering    ' || l_proc,5);
4272    p_sub_element_code := ghr_api.get_position_agency_code_pos
4273                    (p_position_id,p_business_group_id,p_effective_date);
4274 
4275    p_position_title := ghr_api.get_position_title_pos
4276 	(p_position_id            => p_position_id
4277 	,p_business_group_id      => p_business_group_id
4278         ,p_effective_date         => p_effective_date ) ;
4279 
4280    if p_person_id is not null then
4281     p_position_number := ghr_api.get_position_description_no
4282 	(p_person_id            => p_person_id
4283 	,p_assignment_id        => p_assignment_id
4284 	,p_effective_date       => p_effective_date
4285 	);
4286 
4287    p_position_seq_no := ghr_api.get_position_sequence_no
4288 	(p_person_id            => p_person_id
4289 	,p_assignment_id        => p_assignment_id
4290 	,p_effective_date       => p_effective_date
4291 	);
4292    end if;
4293 
4294   hr_utility.set_location('Exiting    ' || l_proc,10);
4295 end get_sub_element_code_pos_title;
4296 
4297 --
4298 -- Get all details for the reporting...
4299 --
4300 
4301 procedure get_other_dtls_for_rep(p_prd in varchar2,
4302                  p_first_lac2_information1 in varchar2,
4303                  p_first_lac2_information2 in varchar2,
4304                  p_first_action_la_code1 out nocopy varchar2,
4305                  p_first_action_la_code2 out nocopy varchar2,
4306                  p_remark_code1 out nocopy varchar2,
4307                  p_remark_code2 out nocopy varchar2
4308                  ) is
4309 l_proc   varchar2(72) :=  g_package || '.get_other_dtls_for_rep';
4310 BEGIN
4311   g_proc  := 'get_other_dtls_for_rep';
4312   hr_utility.set_location('Entering    ' || l_proc,5);
4313   p_first_action_la_code1  :=  'QWM';
4314   p_first_action_la_code2  :=  'ZLM';
4315 
4316 /**
4317        If  p_prd in ('A','B','E','F') then -- retained grade
4318          p_first_action_la_code1  :=  'QWM';
4319          p_first_action_la_code2  :=  'ZLM';
4320          p_remark_code1           :=  'X44';
4321        Elsif p_prd in ('3','J','K') then   -- retained  pay
4322          p_first_action_la_code1  :=  'QWM';
4323          p_first_action_la_code2  :=  'ZLM';
4324          p_remark_code1           :=  'X40';
4325        Elsif p_prd in ('U','V') then    -- pay and grade
4326          p_first_action_la_code1  :=  'QWM';
4327          p_first_action_la_code2  :=  'ZLM';
4328          p_remark_code1         :=  'X40';
4329          p_remark_code2         :=  'X44';
4330        Else
4331          p_first_action_la_code1  :=  'QWM';
4332          p_first_action_la_code2  :=  'ZLM';
4333        End if;
4334 */
4335 
4336    hr_utility.set_location('Exiting    ' || l_proc,10);
4337 
4338 exception
4339   when msl_error then raise;
4340   when others then
4341      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4342      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4343      raise msl_error;
4344 END get_other_dtls_for_rep;
4345 
4346 --
4347 --
4348 --
4349 
4350 procedure create_mass_act_prev (
4351  p_effective_date in date,
4352  p_date_of_birth in date,
4353  p_full_name in varchar2,
4354  p_national_identifier in varchar2,
4355 --Bug # 9329643
4356  p_employee_number   in varchar2,
4357  p_duty_station_code in varchar2,
4358  p_duty_station_desc in varchar2,
4359  p_personnel_office_id in varchar2,
4360  p_basic_pay       in number,
4361  p_new_basic_pay   in number,
4362   -- Bug#2383992
4363  p_adj_basic_pay       in number,
4364  p_new_adj_basic_pay   in number,
4365   -- Bug#2383992
4366  p_old_avail_pay   in number,
4367  p_new_avail_pay   in number,
4368  p_old_loc_diff    in number,
4369  p_new_loc_diff    in number,
4370  p_tot_old_sal     in number,
4371  p_tot_new_sal     in number,
4372  p_old_auo_pay     in number,
4373  p_new_auo_pay     in number,
4374  p_position_id in per_assignments_f.position_id%type,
4375  p_position_title in varchar2,
4376  -- FWFA Changes Bug#4444609
4377  p_position_number in varchar2,
4378  p_position_seq_no in varchar2,
4379 -- FWFA Changes
4380  p_org_structure_id in varchar2,
4381  p_agency_sub_element_code in varchar2,
4382  p_person_id       in number,
4383  p_mass_salary_id  in number,
4384  p_sel_flg         in varchar2,
4385  p_first_action_la_code1 in varchar2,
4386  p_first_action_la_code2 in varchar2,
4387  p_remark_code1 in varchar2,
4388  p_remark_code2 in varchar2,
4389  p_grade_or_level in varchar2,
4390  p_step_or_rate in varchar2,
4391  p_pay_plan     in varchar2,
4392  p_pay_rate_determinant in varchar2,
4393  p_tenure in varchar2,
4394  p_action in varchar2,
4395  p_assignment_id in number,
4396  p_old_other_pay in number,
4397  p_new_other_pay in number,
4398  -- Bug#2383992
4399  p_old_capped_other_pay in number,
4400  p_new_capped_other_pay in number,
4401  p_old_retention_allowance in number,
4402  p_new_retention_allowance in number,
4403  p_old_supervisory_differential in number,
4404  p_new_supervisory_differential in number,
4405  p_organization_name   in varchar2,
4406  -- Bug#2383992
4407  p_increase_percent in number default null,
4408   -- FWFA Changes Bug#4444609
4409  p_input_pay_rate_determinant in varchar2,
4410  p_from_pay_table_id in number,
4411  p_to_pay_table_id   in number
4412  -- FWFA Changes
4413  )
4414 is
4415 
4416  l_comb_rem varchar2(30);
4417  l_proc     varchar2(72) :=  g_package || '.create_mass_act_prev';
4418 
4419  l_cust_rec     ghr_mass_act_custom.ghr_mass_custom_out_rec_type;
4420  l_cust_in_rec  ghr_mass_act_custom.ghr_mass_custom_in_rec_type;
4421  l_poi_desc                   varchar2(80);
4422 ----Temp Promo Changes.
4423  l_step_or_rate  varchar2(30);
4424  l_retained_grade_rec  ghr_pay_calc.retained_grade_rec_type;
4425 -- Bug# 4126137,4179270,4086677
4426   l_check_grade_retention VARCHAR2(200);
4427 
4428 begin
4429   g_proc  := 'create_mass_act_prev';
4430   hr_utility.set_location('Entering    ' || l_proc,5);
4431   if p_remark_code2 is not null then
4432      l_comb_rem := p_remark_code1||', '||p_remark_code2;
4433   else
4434      l_comb_rem := p_remark_code1;
4435   end if;
4436 
4437   l_poi_desc := GHR_MRE_PKG.GET_POI_NAME (p_personnel_office_id);
4438 
4439   BEGIN
4440      l_cust_in_rec.person_id := p_person_id;
4441      l_cust_in_rec.position_id := p_position_id;
4442      l_cust_in_rec.assignment_id := p_assignment_id;
4443      l_cust_in_rec.national_identifier := p_national_identifier;
4444      l_cust_in_rec.mass_action_type := 'SALARY';
4445      l_cust_in_rec.mass_action_id := p_mass_salary_id;
4446      l_cust_in_rec.effective_date := p_effective_date;
4447 
4448      GHR_MASS_ACT_CUSTOM.pre_insert (
4449                        p_cust_in_rec => l_cust_in_rec,
4450                        p_cust_rec => l_cust_rec);
4451 
4452   exception
4453      when others then
4454      hr_utility.set_location('Error in Mass Act Custom '||
4455               'Err is '||sqlerrm(sqlcode),20);
4456      l_mslerrbuf := 'Error in Mass Act Custom '||
4457               'Err is '|| sqlerrm(sqlcode);
4458      raise msl_error;
4459   END;
4460 
4461   l_step_or_rate := p_step_or_rate;
4462 
4463     IF p_pay_rate_determinant in ('A','B','E','F') THEN
4464 
4465         -- Bug#4179270,4126137,4086677 Modified the following IF Condition.
4466         l_check_grade_retention := CHECK_GRADE_RETENTION(p_pay_rate_determinant,p_person_id,p_effective_date);
4467         IF  l_check_grade_retention = 'REGULAR' THEN
4468             BEGIN
4469                   l_retained_grade_rec :=
4470                     ghr_pc_basic_pay.get_retained_grade_details
4471                                               ( p_person_id,
4472                                                 p_effective_date);
4473                     if l_retained_grade_rec.temp_step is not null then
4474                        l_step_or_rate := l_retained_grade_rec.temp_step;
4475                     end if;
4476             EXCEPTION
4477                 when others then
4478                       l_mslerrbuf := 'Preview -  Others error in Get retained grade '||
4479                                'Error is '||' Sql Err is '|| sqlerrm(sqlcode);
4480                       ghr_mre_pkg.pr('Person ID '||to_char(p_person_id),'ERROR 2',l_mslerrbuf);
4481                       raise msl_error;
4482             END;
4483         ELSIF l_check_grade_retention ='MSL_ERROR' THEN
4484            hr_utility.set_message(8301,'GHR_38927_MISSING_MA_RET_DET');
4485            raise msl_error;
4486         ELSIF l_check_grade_retention = 'OTHER_ERROR' THEN
4487              l_mslerrbuf := 'Others error in check_grade_retention function while fetching retained grade record. Please
4488                              verify the retained grade record';
4489               raise msl_error;
4490         END IF;
4491     END IF;
4492 
4493 insert into GHR_MASS_ACTIONS_PREVIEW
4494 (
4495  mass_action_type,
4496  --report_type,
4497  ui_type,
4498  session_id,
4499  effective_date,
4500  employee_date_of_birth,
4501  full_name,
4502  national_identifier,
4503  --Bug # 9329643
4504  employee_number,
4505  duty_station_code,
4506  duty_station_desc,
4507  personnel_office_id,
4508  from_basic_pay,
4509  to_basic_pay,
4510    -- Bug#2383992
4511  from_adj_basic_pay       ,
4512  to_adj_basic_pay   ,
4513     -- Bug#2383992
4514  from_availability_pay,
4515  to_availability_pay,
4516  from_locality_adj,
4517  to_locality_adj,
4518  from_total_salary,
4519  to_total_salary,
4520  from_auo_pay,
4521  to_auo_pay,
4522  from_other_pay,
4523  to_other_pay,
4524   -- Bug#2383992
4525   from_capped_other_pay,
4526  to_capped_other_pay,
4527  from_retention_allowance,
4528  to_retention_allowance,
4529  from_supervisory_differential ,
4530  to_supervisory_differential ,
4531  -- Bug#2383992
4532  position_id,
4533  position_title,
4534  -- FWFA Changes Bug#4444609
4535  position_number,
4536  position_seq_no,
4537  -- FWFA Changes
4538  org_structure_id,
4539  agency_code,
4540  person_id,
4541  select_flag,
4542  first_noa_code,
4543  first_action_la_code1,
4544  first_action_la_code2,
4545  grade_or_level,
4546  step_or_rate,
4547  pay_plan,
4548  pay_rate_determinant,
4549  tenure,
4550  POI_DESC,
4551  organization_name,
4552  -- FWFA Changes Bug#4444609
4553  input_pay_rate_determinant,
4554  from_pay_table_identifier,
4555  to_pay_table_identifier,
4556  -- FWFA Changes
4557  USER_ATTRIBUTE1,
4558  USER_ATTRIBUTE2,
4559  USER_ATTRIBUTE3,
4560  USER_ATTRIBUTE4,
4561  USER_ATTRIBUTE5,
4562  USER_ATTRIBUTE6,
4563  USER_ATTRIBUTE7,
4564  USER_ATTRIBUTE8,
4565  USER_ATTRIBUTE9,
4566  USER_ATTRIBUTE10,
4567  USER_ATTRIBUTE11,
4568  USER_ATTRIBUTE12,
4569  USER_ATTRIBUTE13,
4570  USER_ATTRIBUTE14,
4571  USER_ATTRIBUTE15,
4572  USER_ATTRIBUTE16,
4573  USER_ATTRIBUTE17,
4574  USER_ATTRIBUTE18,
4575  USER_ATTRIBUTE19,
4576  USER_ATTRIBUTE20,
4577  increase_percent
4578 )
4579 values
4580 (
4581  'SALARY',
4582  /*--decode(p_action,'REPORT',userenv('SESSIONID'),p_mass_realignment_id),*/
4583  decode(p_action,'SHOW','FORM','REPORT'),
4584  userenv('SESSIONID'),
4585  p_effective_date,
4586  p_date_of_birth,
4587  p_full_name,
4588  p_national_identifier,
4589  --Bug # 9329643
4590  p_employee_number,
4591  p_duty_station_code,
4592  p_duty_station_desc,
4593  p_personnel_office_id,
4594  p_basic_pay,
4595  p_new_basic_pay,
4596  -- Bug#2383992
4597  p_adj_basic_pay       ,
4598  p_new_adj_basic_pay   ,
4599  -- Bug#2383992
4600  p_old_avail_pay,
4601  p_new_avail_pay,
4602  p_old_loc_diff,
4603  p_new_loc_diff,
4604  p_tot_old_sal,
4605  p_tot_new_sal,
4606  p_old_auo_pay,
4607  p_new_auo_pay,
4608  p_old_other_pay,                 ----------- nvl(p_old_auo_pay,0)+ nvl(p_old_avail_pay,0),
4609  p_new_other_pay,                 ----------- nvl(p_new_auo_pay,0)+ nvl(p_new_avail_pay,0),
4610   -- Bug#2383992
4611  p_old_capped_other_pay,
4612  p_new_capped_other_pay,
4613  p_old_retention_allowance,
4614  p_new_retention_allowance,
4615  p_old_supervisory_differential ,
4616  p_new_supervisory_differential ,
4617  -- Bug#2383992
4618  p_position_id,
4619  p_position_title,
4620  -- FWFA Changes Bug#4444609
4621  p_position_number,
4622  p_position_seq_no,
4623  -- FWFA Changes
4624  p_org_structure_id,
4625  p_agency_sub_element_code,
4626  p_person_id,
4627  p_sel_flg,
4628  nvl(g_first_noa_code,'894'),
4629  p_first_action_la_code1,
4630  p_first_action_la_code2,
4631  p_grade_or_level,
4632  l_step_or_rate,
4633  p_pay_plan,
4634  p_pay_rate_determinant,
4635  p_tenure,
4636  l_poi_desc,
4637  p_organization_name,
4638  -- FWFA Changes Bug#4444609
4639  p_input_pay_rate_determinant,
4640  p_from_pay_table_id,
4641  p_to_pay_table_id,
4642  -- FWFA Changes
4643  l_cust_rec.user_attribute1,
4644  l_cust_rec.user_attribute2,
4645  l_cust_rec.user_attribute3,
4646  l_cust_rec.user_attribute4,
4647  l_cust_rec.user_attribute5,
4648  l_cust_rec.user_attribute6,
4649  l_cust_rec.user_attribute7,
4650  l_cust_rec.user_attribute8,
4651  l_cust_rec.user_attribute9,
4652  l_cust_rec.user_attribute10,
4653  l_cust_rec.user_attribute11,
4654  l_cust_rec.user_attribute12,
4655  l_cust_rec.user_attribute13,
4656  l_cust_rec.user_attribute14,
4657  l_cust_rec.user_attribute15,
4658  l_cust_rec.user_attribute16,
4659  l_cust_rec.user_attribute17,
4660  l_cust_rec.user_attribute18,
4661  l_cust_rec.user_attribute19,
4662  l_cust_rec.user_attribute20,
4663  p_increase_percent
4664 );
4665 
4666      hr_utility.set_location('Exiting    ' || l_proc,10);
4667 exception
4668    when msl_error then raise;
4669    when others then
4670      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4671      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4672      raise msl_error;
4673 end create_mass_act_prev;
4674 
4675 --
4676 --
4677 --
4678 
4679 procedure get_lac_dtls
4680             (p_pa_request_id  in number,
4681              p_sf52_rec       out nocopy ghr_pa_requests%rowtype) IS
4682 
4683 l_proc varchar2(72) :=  g_package || '.get_lac_dtls';
4684 
4685 cursor cur_pa_req_cur is
4686 select * from ghr_pa_requests
4687  where pa_request_id = p_pa_request_id;
4688 
4689 begin
4690   g_proc  := 'get_lac_dtls';
4691   hr_utility.set_location('Entering    ' || l_proc,5);
4692 
4693 pr('Entering '||l_proc||' Pa req id ',to_char(p_pa_request_id));
4694 if p_pa_request_id is null then
4695     pr('PA request id is null.................');
4696 else
4697 
4698   for cur_pa_rec in cur_pa_req_cur
4699   loop
4700      p_sf52_rec := cur_pa_rec;
4701      exit;
4702   end loop;
4703 end if;
4704 
4705   hr_utility.set_location('Exiting    ' || l_proc,10);
4706 exception
4707   when others then
4708      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4709      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4710      raise msl_error;
4711 end get_lac_dtls;
4712 
4713 --
4714 --
4715 --
4716 
4717 procedure create_lac_remarks
4718             (p_pa_request_id  in number,
4719              p_new_pa_request_id  in number) is
4720 
4721 l_proc varchar2(72) :=  g_package || '.create_lac_remarks';
4722 
4723 cursor cur_pa_rem_cur is
4724 select * from ghr_pa_remarks
4725  where pa_request_id = p_pa_request_id;
4726 
4727 l_remarks_rec     ghr_pa_remarks%rowtype;
4728 
4729 begin
4730   g_proc  := 'create_lac_remarks';
4731   hr_utility.set_location('Entering    ' || l_proc,5);
4732 
4733   pr('Inside '||l_proc,to_char(p_pa_request_id),to_char(p_new_pa_request_id));
4734 
4735     FOR CUR_PA_REM_rec in cur_pa_rem_cur
4736     loop
4737 
4738       l_remarks_rec := cur_pa_rem_rec;
4739 
4740 pr('Rem id '||to_char(l_remarks_rec.remark_id));
4741     ghr_pa_remarks_api.create_pa_remarks
4742     (p_validate                 => false
4743     ,p_pa_request_id            => p_new_pa_request_id
4744     ,p_remark_id                => l_remarks_rec.remark_id
4745     ,p_description              => l_remarks_rec.description
4746     ,p_remark_code_information1 => l_remarks_rec.remark_code_information1
4747     ,p_remark_code_information2 => l_remarks_rec.remark_code_information2
4748     ,p_remark_code_information3 => l_remarks_rec.remark_code_information3
4749     ,p_remark_code_information4 => l_remarks_rec.remark_code_information4
4750     ,p_remark_code_information5 => l_remarks_rec.remark_code_information5
4751     ,p_pa_remark_id             => l_remarks_rec.pa_remark_id
4752     ,p_object_version_number    => l_remarks_rec.object_version_number
4753     );
4754 
4755   end loop;
4756 
4757   hr_utility.set_location('Exiting    ' || l_proc,10);
4758 
4759 exception
4760   when others then
4761      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4762      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4763      raise msl_error;
4764 end create_lac_remarks;
4765 
4766 --
4767 --
4768 --
4769 
4770 procedure upd_ext_info_to_null(p_effective_date in date) is
4771 
4772   cursor cur1 is
4773   select person_id
4774     FROM PER_people_EXTRA_INFO
4775    WHERE information_type = 'GHR_US_PER_MASS_ACTIONS'
4776      AND pei_INFORMATION3 IS NOT NULL;
4777 
4778 l_person_id number;
4779 
4780 l_proc   varchar2(72) :=  g_package || '.upd_ext_info_to_null';
4781 
4782 begin
4783   g_proc  := 'upd_ext_info_to_null';
4784   hr_utility.set_location('Entering    ' || l_proc,5);
4785 
4786   pr('Inside '||l_proc);
4787 
4788   for per_ext_rec in cur1
4789   loop
4790      l_person_id := per_ext_rec.person_id;
4791      update_sel_flg (l_person_id,p_effective_date);
4792   end loop;
4793 
4794   commit;
4795 
4796   pr('Exiting '||l_proc);
4797   hr_utility.set_location('Exiting    ' || l_proc,10);
4798 
4799 exception
4800   when msl_error then raise;
4801   when others then
4802      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4803      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4804      raise msl_error;
4805 end;
4806 
4807 --
4808 --
4809 --
4810 
4811 PROCEDURE assign_to_sf52_rec(
4812  p_person_id              in number,
4813  p_first_name             in varchar2,
4814  p_last_name              in varchar2,
4815  p_middle_names           in varchar2,
4816  p_national_identifier    in varchar2,
4817  p_date_of_birth          in date,
4818  p_effective_date         in date,
4819  p_assignment_id          in number,
4820  p_tenure                 in varchar2,
4821  -- Bug#5089732 Added to_grade_id, to_pay_plan,to_grade_or_level parameters.
4822  p_to_grade_id            in number,
4823  p_to_pay_plan            in varchar2,
4824  p_to_grade_or_level      in varchar2,
4825  -- Bug#5089732
4826  p_step_or_rate           in varchar2,
4827  p_annuitant_indicator    in varchar2,
4828  p_pay_rate_determinant   in varchar2,
4829  p_work_schedule          in varchar2,
4830  p_part_time_hour         in varchar2,
4831  p_flsa_category          in varchar2,
4832  p_bargaining_unit_status in varchar2,
4833  p_functional_class       in varchar2,
4834  p_supervisory_status     in varchar2,
4835  p_basic_pay              in number,
4836  p_to_locality_adj        in number,
4837  p_to_adj_basic_pay       in number,
4838  p_to_total_salary        in number,
4839  p_from_other_pay_amount  in number,
4840  p_to_other_pay_amount    in number,
4841  p_to_au_overtime         in number,
4842  p_to_availability_pay    in number,
4843  p_to_retention_allowance in number,
4844  p_to_retention_allow_perce in number,
4845  p_to_supervisory_differential in number,
4846  p_to_supervisory_diff_perce in number,
4847  p_to_staffing_differential in number,
4848  p_duty_station_id        in number,
4849  p_duty_station_code      in ghr_pa_requests.duty_station_code%type,
4850  p_duty_station_desc      in ghr_pa_requests.duty_station_desc%type,
4851  -- FWFA Changes Bug#4444609
4852  p_input_pay_rate_determinant in ghr_pa_requests.input_pay_rate_determinant%type,
4853  p_from_pay_table_id       in ghr_pa_requests.from_pay_table_identifier%type,
4854  p_to_pay_table_id         in ghr_pa_requests.to_pay_table_identifier%type,
4855   -- FWFA Changes
4856  p_lac_sf52_rec           in ghr_pa_requests%rowtype,
4857  p_sf52_rec               out nocopy ghr_pa_requests%rowtype) IS
4858 
4859 l_proc   varchar2(72) :=  g_package || '.assign_to_sf52_rec';
4860 begin
4861 
4862   g_proc  := 'assign_to_sf52_rec';
4863 
4864   hr_utility.set_location('Entering    ' || l_proc,5);
4865 
4866  p_sf52_rec.person_id := p_person_id;
4867  p_sf52_rec.employee_first_name := p_first_name;
4868  p_sf52_rec.employee_last_name := p_last_name;
4869  p_sf52_rec.employee_middle_names := p_middle_names;
4870  p_sf52_rec.employee_national_identifier := p_national_identifier;
4871  p_sf52_rec.employee_date_of_birth := p_date_of_birth;
4872  p_sf52_rec.effective_date := p_effective_date;
4873  p_sf52_rec.employee_assignment_id := p_assignment_id;
4874  p_sf52_rec.tenure := p_tenure;
4875  -- Bug#5089732 Added to_grade_id, to_pay_plan,to_grade_or_level parameters.
4876  p_sf52_rec.to_grade_id       := p_to_grade_id;
4877  p_sf52_rec.to_pay_plan       := p_to_pay_plan;
4878  p_sf52_rec.to_grade_or_level := p_to_grade_or_level;
4879  -- Bug35089732
4880  p_sf52_rec.to_step_or_rate := p_step_or_rate;
4881  p_sf52_rec.annuitant_indicator  := p_annuitant_indicator;
4882  p_sf52_rec.pay_rate_determinant  := p_pay_rate_determinant;
4883  p_sf52_rec.work_schedule := p_work_schedule;
4884  p_sf52_rec.part_time_hours := p_part_time_hour;
4885  p_sf52_rec.flsa_category := p_flsa_category;
4886  p_sf52_rec.bargaining_unit_status := p_bargaining_unit_status;
4887  p_sf52_rec.functional_class := p_functional_class;
4888  p_sf52_rec.supervisory_status := p_supervisory_status;
4889  p_sf52_rec.to_basic_pay := p_basic_pay;
4890  p_sf52_rec.to_locality_adj := p_to_locality_adj;
4891  p_sf52_rec.to_adj_basic_pay := p_to_adj_basic_pay;
4892  p_sf52_rec.to_total_salary := p_to_total_salary;
4893  p_sf52_rec.from_other_pay_amount := p_from_other_pay_amount;
4894  p_sf52_rec.to_other_pay_amount := p_to_other_pay_amount;
4895  p_sf52_rec.to_au_overtime := p_to_au_overtime;
4896  p_sf52_rec.to_availability_pay := p_to_availability_pay;
4897  if p_to_retention_allowance = 0 or p_to_retention_allowance is null then
4898     p_sf52_rec.to_retention_allowance := null;
4899  else
4900     p_sf52_rec.to_retention_allowance := p_to_retention_allowance;
4901  end if;
4902  p_sf52_rec.to_retention_allow_percentage := p_to_retention_allow_perce;
4903  if p_to_supervisory_differential = 0 or p_to_supervisory_differential is null then
4904     p_sf52_rec.to_supervisory_differential := null;
4905  else
4906     p_sf52_rec.to_supervisory_differential := p_to_supervisory_differential;
4907  end if;
4908  p_sf52_rec.to_supervisory_diff_percentage := p_to_supervisory_diff_perce;
4909  p_sf52_rec.to_staffing_differential := p_to_staffing_differential;
4910  p_sf52_rec.duty_station_id := p_duty_station_id;
4911  p_sf52_rec.duty_station_code := p_duty_station_code;
4912  p_sf52_rec.duty_station_desc := p_duty_station_desc;
4913  -- FWFA Changes Bug#4444609
4914  p_sf52_rec.input_pay_rate_determinant := p_input_pay_rate_determinant;
4915  p_sf52_rec.from_pay_table_identifier  := p_from_pay_table_id;
4916  p_sf52_rec.to_pay_table_identifier    := p_to_pay_table_id;
4917  -- FWFA Changes
4918  p_sf52_rec.FIRST_LAC1_INFORMATION1 := p_lac_sf52_rec.FIRST_LAC1_INFORMATION1;
4919  p_sf52_rec.FIRST_LAC1_INFORMATION2 := p_lac_sf52_rec.FIRST_LAC1_INFORMATION2;
4920  p_sf52_rec.FIRST_LAC1_INFORMATION3 := p_lac_sf52_rec.FIRST_LAC1_INFORMATION3;
4921  p_sf52_rec.FIRST_LAC1_INFORMATION4 := p_lac_sf52_rec.FIRST_LAC1_INFORMATION4;
4922  p_sf52_rec.FIRST_LAC1_INFORMATION5 := p_lac_sf52_rec.FIRST_LAC1_INFORMATION5;
4923  p_sf52_rec.SECOND_LAC1_INFORMATION1 := p_lac_sf52_rec.SECOND_LAC1_INFORMATION1;
4924  p_sf52_rec.SECOND_LAC1_INFORMATION2 := p_lac_sf52_rec.SECOND_LAC1_INFORMATION2;
4925  p_sf52_rec.SECOND_LAC1_INFORMATION3 := p_lac_sf52_rec.SECOND_LAC1_INFORMATION3;
4926  p_sf52_rec.SECOND_LAC1_INFORMATION4 := p_lac_sf52_rec.SECOND_LAC1_INFORMATION4;
4927  p_sf52_rec.SECOND_LAC1_INFORMATION5 := p_lac_sf52_rec.SECOND_LAC1_INFORMATION5;
4928  p_sf52_rec.FIRST_ACTION_LA_CODE1 := p_lac_sf52_rec.FIRST_ACTION_LA_CODE1;
4929  p_sf52_rec.FIRST_ACTION_LA_CODE2 := p_lac_sf52_rec.FIRST_ACTION_LA_CODE2;
4930  p_sf52_rec.FIRST_ACTION_LA_DESC1 := p_lac_sf52_rec.FIRST_ACTION_LA_DESC1;
4931  p_sf52_rec.FIRST_ACTION_LA_DESC2 := p_lac_sf52_rec.FIRST_ACTION_LA_DESC2;
4932 
4933      hr_utility.set_location('Exiting    ' || l_proc,10);
4934 
4935 exception
4936   when msl_error then raise;
4937   when others then
4938      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
4939      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
4940      raise msl_error;
4941 end assign_to_sf52_rec;
4942 
4943 --
4944 --
4945 --
4946 
4947 procedure pr (msg varchar2,par1 in varchar2 default null,
4948             par2 in varchar2 default null) is
4949 begin
4950 --  g_no := g_no +1;
4951 --  insert into l_tmp values (g_no,substr(msg||'-'||par1||' -'||par2||'-',1,199));
4952  -- DBMS_OUTPUT.PUT_LINE(msg||'-'||par1||' -'||par2||'-');
4953 
4954     ghr_mto_int.put_line(msg||'-'||par1||' -'||par2||'-');
4955 exception
4956   when others then
4957      hr_utility.set_location('Error in pr '||' Err is '||sqlerrm(sqlcode),20);
4958      l_mslerrbuf := 'Error in pr  Sql Err is '|| sqlerrm(sqlcode);
4959      raise msl_error;
4960 end;
4961 
4962 -- 3843306
4963 -- Start of MSL Percentage Changes
4964 -- This is same as Execute_msl except for few modifications
4965 --
4966 --+-----------------------------------------------------------------+------
4967 --+ Procedure for Mass Percentage Pay Adjustmentfor Range employees +--
4968 --+ ----------------------------------------------------------------+------
4969 PROCEDURE execute_msl_perc (p_errbuf out nocopy varchar2,
4970                        p_retcode out nocopy number,
4971                        p_mass_salary_id in number,
4972                        p_action in varchar2) is
4973                        --p_bus_grp_id in number) is
4974 
4975 p_mass_salary varchar2(32);
4976 
4977 --
4978 --
4979 -- Main Cursor which fetches from per_assignments_f and per_people_f
4980 --
4981 --
4982 --1. Cursor with organization.
4983 ---
4984 
4985 
4986 cursor cur_people_org (effective_date date, p_org_id number) is
4987 select ppf.person_id                 PERSON_ID,
4988        ppf.first_name                FIRST_NAME,
4989        ppf.last_name                 LAST_NAME,
4990        ppf.middle_names              MIDDLE_NAMES,
4991        ppf.full_name                 FULL_NAME,
4992        ppf.date_of_birth             DATE_OF_BIRTH,
4993        ppf.national_identifier       NATIONAL_IDENTIFIER,
4994        --Bug # 9329643
4995        ppf.employee_number           EMPLOYEE_NUMBER,
4996        paf.position_id               POSITION_ID,
4997        paf.assignment_id             ASSIGNMENT_ID,
4998        paf.grade_id                  GRADE_ID,
4999        paf.job_id                    JOB_ID,
5000        paf.location_id               LOCATION_ID,
5001        paf.organization_id           ORGANIZATION_ID,
5002        paf.business_group_id         BUSINESS_GROUP_ID,
5003        paf.assignment_status_type_id ASSIGNMENT_STATUS_TYPE_ID
5004   from per_assignments_f   paf,
5005        per_people_f        ppf,
5006        per_person_types    ppt
5007  where ppf.person_id           = paf.person_id
5008    and effective_date between ppf.effective_start_date and ppf.effective_end_date
5009    and effective_date between paf.effective_start_date and paf.effective_end_date
5010    and paf.primary_flag        = 'Y'
5011    and paf.assignment_type     <> 'B'
5012    and ppf.person_type_id      = ppt.person_type_id
5013    and ppt.system_person_type  IN ('EMP','EMP_APL')
5014    and paf.organization_id     = p_org_id
5015    and paf.position_id is not null
5016    order by ppf.person_id;
5017 
5018 ---
5019 --- Bug  3539816 Order by added to prevent snapshot old error
5020 --- 2. Cursor with no organization.
5021 ---
5022 --- This SQL is tuned by joining the hr_organization_units to avoid the FTS of PAF.
5023 --- Bug 6152582
5024 ---
5025 cursor cur_people (effective_date date) is
5026 select ppf.person_id                 PERSON_ID,
5027        ppf.first_name                FIRST_NAME,
5028        ppf.last_name                 LAST_NAME,
5029        ppf.middle_names              MIDDLE_NAMES,
5030        ppf.full_name                 FULL_NAME,
5031        ppf.date_of_birth             DATE_OF_BIRTH,
5032        ppf.national_identifier       NATIONAL_IDENTIFIER,
5033        --Bug # 9329643
5034        ppf.employee_number           EMPLOYEE_NUMBER,
5035        paf.position_id               POSITION_ID,
5036        paf.assignment_id             ASSIGNMENT_ID,
5037        paf.grade_id                  GRADE_ID,
5038        paf.job_id                    JOB_ID,
5039        paf.location_id               LOCATION_ID,
5040        paf.organization_id           ORGANIZATION_ID,
5041        paf.business_group_id         BUSINESS_GROUP_ID,
5042        paf.assignment_status_type_id ASSIGNMENT_STATUS_TYPE_ID
5043   from per_assignments_f   paf,
5044        per_people_f        ppf,
5045        per_person_types    ppt,
5046        hr_organization_units hou
5047  where ppf.person_id           = paf.person_id
5048    and effective_date between ppf.effective_start_date and ppf.effective_end_date
5049    and effective_date between paf.effective_start_date and paf.effective_end_date
5050    and paf.primary_flag        = 'Y'
5051    and paf.assignment_type     <> 'B'
5052    and ppf.person_type_id      = ppt.person_type_id
5053    and ppt.system_person_type  IN ('EMP','EMP_APL')
5054    and paf.organization_id     = hou.organization_id
5055    and paf.position_id is not null
5056    order by ppf.person_id;
5057 --
5058 -- Check assignment_status_type
5059 --
5060 
5061 cursor cur_ast (asg_status_type_id number) is
5062 select user_status from per_assignment_status_types
5063 where assignment_status_type_id = asg_status_type_id
5064   and upper(user_status) not in (
5065                          'TERMINATE ASSIGNMENT',           /* 3 */
5066                          'ACTIVE APPLICATION',             /* 4 */
5067                          'OFFER',                          /* 5 */
5068                          'ACCEPTED',                       /* 6 */
5069                          'TERMINATE APPLICATION',          /* 7 */
5070                          'END',                            /* 8 */
5071                          'TERMINATE APPOINTMENT',          /* 126 */
5072                          'SEPARATED');                     /* 132 */
5073 
5074 --
5075 -- Cursor to select from GHR_MASS_SALARIES - Where criteria is stored
5076 -- Before executing this package
5077 -- from ghr_mass_salary_criteria
5078 
5079 cursor ghr_msl (p_msl_id number) is
5080 select name, effective_date, mass_salary_id, user_table_id, submit_flag,
5081        executive_order_number, executive_order_date, ROWID, PA_REQUEST_ID,
5082        ORGANIZATION_ID, DUTY_STATION_ID, PERSONNEL_OFFICE_ID,
5083        AGENCY_CODE_SUBELEMENT, OPM_ISSUANCE_NUMBER, OPM_ISSUANCE_DATE, PROCESS_TYPE
5084   from ghr_mass_salaries
5085  where MASS_SALARY_ID = p_msl_id
5086    for update of user_table_id nowait;
5087 
5088 -- VSM [family name was hardcoded previously to SALARY_CHG. Fetching it from DB now]
5089 /*cursor get_sal_chg_fam is
5090 select NOA_FAMILY_CODE
5091 from ghr_families
5092 where NOA_FAMILY_CODE in
5093     (select NOA_FAMILY_CODE from ghr_noa_families
5094          where  nature_of_action_id =
5095             (select nature_of_action_id
5096              from ghr_nature_of_actions
5097              where code = '894')
5098     ) and proc_method_flag = 'Y';    --AVR 13-JAN-99	  */
5099  -------------   ) and update_hr_flag = 'Y';
5100 
5101 l_assignment_id        per_assignments_f.assignment_id%type;
5102 l_position_id          per_assignments_f.position_id%type;
5103 l_grade_id             per_assignments_f.grade_id%type;
5104 l_business_group_id    per_assignments_f.business_group_id%type;
5105 
5106 l_position_title       varchar2(300);
5107 l_position_number      varchar2(20);
5108 l_position_seq_no      varchar2(20);
5109 
5110 l_msl_cnt              number := 0;
5111 l_recs_failed          number := 0;
5112 
5113 l_tenure               varchar2(35);
5114 l_annuitant_indicator  varchar2(35);
5115 l_pay_rate_determinant varchar2(35);
5116 l_work_schedule        varchar2(35);
5117 l_part_time_hour       varchar2(35);
5118 l_pay_table_id         number;
5119 l_pay_plan             varchar2(30);
5120 l_grade_or_level       varchar2(30);
5121 l_step_or_rate         varchar2(30);
5122 l_pay_basis            varchar2(30);
5123 l_location_id          number;
5124 l_duty_station_id      number;
5125 l_duty_station_desc    ghr_pa_requests.duty_station_desc%type;
5126 l_duty_station_code    ghr_pa_requests.duty_station_code%type;
5127 l_effective_date       date;
5128 l_personnel_office_id  varchar2(300);
5129 l_org_structure_id     varchar2(300);
5130 l_sub_element_code     varchar2(300);
5131 
5132 l_old_basic_pay        number;
5133 l_old_avail_pay        number;
5134 l_old_loc_diff         number;
5135 l_tot_old_sal          number;
5136 l_old_auo_pay          number;
5137 l_old_ADJ_basic_pay    number;
5138 l_other_pay            number;
5139 
5140 
5141 l_auo_premium_pay_indicator     varchar2(30);
5142 l_ap_premium_pay_indicator      varchar2(30);
5143 l_retention_allowance           number;
5144 l_retention_allow_perc          number;     ---AVR
5145 l_new_retention_allowance       number;     ---AVR
5146 l_supervisory_differential      number;
5147 l_supervisory_diff_perc         number;     ---AVR
5148 l_new_supervisory_differential  number;     ---AVR
5149 l_staffing_differential         number;
5150 
5151 l_new_avail_pay             number;
5152 l_new_loc_diff              number;
5153 l_tot_new_sal               number;
5154 l_new_auo_pay               number;
5155 
5156 l_new_basic_pay             number;
5157 l_new_locality_adj          number;
5158 l_new_adj_basic_pay         number;
5159 l_new_total_salary          number;
5160 l_new_other_pay_amount      number;
5161 l_new_au_overtime           number;
5162 l_new_availability_pay      number;
5163 l_out_step_or_rate          varchar2(30);
5164 l_out_pay_rate_determinant  varchar2(30);
5165 l_PT_eff_start_date         date;
5166 l_open_pay_fields           boolean;
5167 l_message_set               boolean;
5168 l_calculated                boolean;
5169 
5170 l_mass_salary_id            number;
5171 l_user_table_id             number;
5172 l_submit_flag               varchar2(2);
5173 l_executive_order_number    ghr_mass_salaries.executive_order_number%TYPE;
5174 l_executive_order_date      ghr_mass_salaries.executive_order_date%TYPE;
5175 l_opm_issuance_number       ghr_mass_salaries.opm_issuance_number%TYPE;
5176 l_opm_issuance_date         ghr_mass_salaries.opm_issuance_date%TYPE;
5177 l_pa_request_id             number;
5178 l_rowid                     varchar2(30);
5179 
5180 l_p_ORGANIZATION_ID           number;
5181 l_p_DUTY_STATION_ID           number;
5182 l_p_PERSONNEL_OFFICE_ID       varchar2(5);
5183 
5184 L_row_cnt                   number := 0;
5185 
5186 l_sf52_rec                  ghr_pa_requests%rowtype;
5187 l_lac_sf52_rec              ghr_pa_requests%rowtype;
5188 l_errbuf                    varchar2(2000);
5189 
5190 l_retcode                   number;
5191 
5192 l_pos_ei_data               per_position_extra_info%rowtype;
5193 l_pos_grp1_rec              per_position_extra_info%rowtype;
5194 
5195 l_pay_calc_in_data          ghr_pay_calc.pay_calc_in_rec_type;
5196 l_pay_calc_out_data         ghr_pay_calc.pay_calc_out_rec_type;
5197 l_sel_flg                   varchar2(2);
5198 
5199 l_first_action_la_code1     varchar2(30);
5200 l_first_action_la_code2     varchar2(30);
5201 
5202 l_remark_code1              varchar2(30);
5203 l_remark_code2              varchar2(30);
5204 l_p_AGENCY_CODE_SUBELEMENT       varchar2(30);
5205 
5206 ----Pay cap variables
5207 l_entitled_other_pay        NUMBER;
5208 l_capped_other_pay          NUMBER;
5209 l_adj_basic_message         BOOLEAN  := FALSE;
5210 l_pay_cap_message           BOOLEAN  := FALSE;
5211 l_temp_retention_allowance  NUMBER;
5212 l_open_pay_fields_caps      BOOLEAN;
5213 l_message_set_caps          BOOLEAN;
5214 l_total_pay_check           VARCHAR2(1);
5215 l_comment                   VARCHAR2(150);
5216 l_comment_sal               VARCHAR2(150);
5217 l_pay_sel                   VARCHAR2(1) := NULL;
5218 l_old_capped_other_pay     NUMBER;
5219 ----
5220 l_row_low NUMBER;
5221 l_row_high NUMBER;
5222 l_comment_range VARCHAR2(150);
5223 l_comments      VARCHAR2(150);
5224 
5225 REC_BUSY                    exception;
5226 pragma exception_init(REC_BUSY,-54);
5227 
5228 l_proc  varchar2(72) :=  g_package || '.execute_msl_perc';
5229 
5230 cursor c_pay_tab_essl is
5231   select 1 from pay_user_tables
5232   where substr(user_table_name,1,4) = 'ESSL'
5233   and user_table_id = l_user_table_id;
5234 
5235 l_essl_table  BOOLEAN := FALSE;
5236 l_org_name	hr_organization_units.name%type;
5237 
5238 -- Bug 3315432 Madhuri
5239 --
5240 CURSOR cur_pp_prd_per_gr(p_msl_id ghr_mass_salary_criteria.mass_salary_id%type)
5241 IS
5242 SELECT criteria.pay_plan pay_plan,
5243        criteria.pay_rate_determinant prd,
5244        ext.increase_percent percent,
5245        ext.grade grade
5246 FROM   ghr_mass_salary_criteria criteria, ghr_mass_salary_criteria_ext ext
5247 WHERE  criteria.mass_salary_id=p_msl_id
5248 AND    criteria.mass_salary_criteria_id=ext.mass_salary_criteria_id;
5249 
5250 
5251 rec_pp_prd_per_gr pp_prd_per_gr;
5252 
5253 l_index         NUMBER:=1;
5254 l_cnt           NUMBER;
5255 l_increase_percent NUMBER;
5256 l_cust_percent     NUMBER;
5257 l_elig_flag        BOOLEAN := FALSE;
5258 --
5259 -- Defining the record type variable
5260 --
5261 l_pay_calc_msl_percentage  ghr_mass_salary_criteria_ext.increase_percent%type;
5262 l_ses_basic_pay   NUMBER;
5263 --
5264 --
5265 
5266 --
5267 -- GPPA Update 46
5268 --
5269 cursor cur_eq_ppl (c_pay_plan ghr_pay_plans.pay_plan%type)
5270 IS
5271 select EQUIVALENT_PAY_PLAN
5272 from ghr_pay_plans
5273 where pay_plan = c_pay_plan;
5274 
5275 l_eq_pay_plan ghr_pay_plans.equivalent_pay_plaN%type;
5276 
5277 --
5278 --
5279 PROCEDURE msl_perc_process(p_assignment_id  per_assignments_f.assignment_id%TYPE
5280 							 ,p_person_id per_assignments_f.person_id%TYPE
5281 							 ,p_position_id  per_assignments_f.position_id%TYPE
5282 							 ,p_grade_id per_assignments_f.grade_id%TYPE
5283 							 ,p_business_group_id per_assignments_f.business_group_iD%TYPE
5284 							 ,p_location_id per_assignments_f.location_id%TYPE
5285 							 ,p_organization_id per_assignments_f.organization_id%TYPE
5286 							 ,p_date_of_birth date
5287 							 ,p_first_name per_people_f.first_name%TYPE
5288 							 ,p_last_name per_people_f.last_name%TYPE
5289                              ,p_full_name per_people_f.full_name%TYPE
5290                              ,p_middle_names per_people_f.middle_names%TYPE
5291 							 ,p_national_identifier per_people_f.national_identifier%TYPE
5292 							 --Bug # 9329643
5293 			     ,p_employee_number     per_people_f.employee_number%TYPE
5294                              ,p_personnel_office_id IN VARCHAR2
5295                              ,p_org_structure_id    IN VARCHAR2
5296                              ,p_position_title      IN VARCHAR2
5297                              ,p_position_number     IN VARCHAR2
5298                              ,p_position_seq_no     IN VARCHAR2
5299                              ,p_subelem_code        IN VARCHAR2
5300                              ,p_duty_station_id     IN ghr_duty_stations_f.duty_station_id%TYPE
5301                              ,p_tenure              IN VARCHAR2
5302                              ,p_annuitant_indicator IN VARCHAR2
5303                              ,p_pay_rate_determinant IN VARCHAR2
5304                              ,p_work_schedule       IN  VARCHAR2
5305                              ,p_part_time_hour      IN VARCHAR2
5306                              ,p_pay_plan            IN VARCHAR2
5307                              ,p_pay_table_id        IN NUMBER
5308                              ,p_grade_or_level      IN VARCHAR2
5309                              ,p_step_or_rate        IN VARCHAR2
5310                              ,p_pay_basis           IN VARCHAR2
5311                              ,p_increase_percent    IN VARCHAR2
5312                ) IS
5313 
5314     -- Bug3437354
5315     CURSOR cur_valid_DS(p_ds_id NUMBER)
5316         IS
5317         SELECT effective_end_date  end_date
5318         FROM   ghr_duty_stations_f
5319         WHERE  duty_station_id=p_ds_id
5320         AND    g_effective_date between effective_start_date and effective_end_date;
5321  --7577249
5322     cursor get_sal_chg_fam is
5323     select NOA_FAMILY_CODE
5324     from ghr_families
5325     where NOA_FAMILY_CODE in
5326        (select NOA_FAMILY_CODE from ghr_noa_families
5327         where  nature_of_action_id =
5328             (select nature_of_action_id
5329              from ghr_nature_of_actions
5330              where code = nvl(g_first_noa_code,'894') and g_effective_date between date_from and nvl(date_to,g_effective_date))
5331         ) and proc_method_flag = 'Y';
5332 --7577249
5333         l_ds_end_date	  ghr_duty_stations_f.effective_end_date%type;
5334 
5335 	l_locality_adj      number;
5336 	l_multi_error_flag  boolean;
5337 
5338 	--9309268
5339 	l_bp_diff  number;
5340 
5341 BEGIN
5342       savepoint execute_msl_perc_sp;
5343          l_msl_cnt := l_msl_cnt +1;
5344          --Bug#3968005 Initialised l_sel_flg
5345          l_sel_flg := NULL;
5346          l_pay_calc_in_data  := NULL;
5347          l_pay_calc_out_data := NULL;
5348 
5349 
5350        l_assignment_id     := p_assignment_id;
5351        l_position_id       := p_position_id;
5352        l_grade_id          := p_grade_id;
5353        l_business_group_id := p_business_group_iD;
5354        l_location_id       := p_location_id;
5355 
5356        -- Bug#5063304
5357         l_personnel_office_id  := p_personnel_office_id;
5358         l_org_structure_id     := p_org_structure_id;
5359         l_position_title       := p_position_title;
5360         l_position_number      := p_position_number;
5361         l_position_seq_no      := p_position_seq_no;
5362         l_sub_element_code     := p_subelem_code;
5363         l_duty_station_id      := p_duty_station_id;
5364         l_tenure               := p_tenure;
5365         l_annuitant_indicator  := p_annuitant_indicator;
5366         l_pay_rate_determinant := p_pay_rate_determinant;
5367         l_work_schedule        := P_work_schedule;
5368         l_part_time_hour       := p_part_time_hour;
5369         l_pay_plan             := p_pay_plan;
5370         l_pay_table_id         := p_pay_table_id;
5371         l_grade_or_level       := p_grade_or_level;
5372         l_step_or_rate         := P_step_or_rate;
5373         l_pay_basis            := p_pay_basis;
5374 
5375 	hr_utility.set_location('The location id is:'||l_location_id,12345);
5376 
5377         ghr_msl_pkg.g_first_noa_code := '894';
5378 --------GPPA Update 46 start
5379           --  ghr_msl_pkg.g_first_noa_code := NULL;
5380             FOR cur_eq_ppl_rec IN cur_eq_ppl(l_pay_plan)
5381             LOOP
5382                 l_eq_pay_plan   := cur_eq_ppl_rec.EQUIVALENT_PAY_PLAN;
5383                 exit;
5384             END LOOP;
5385             if l_effective_date >= to_date('2007/01/07','YYYY/MM/DD') AND
5386                l_eq_pay_plan = 'GS' AND
5387                l_lac_sf52_rec.first_action_la_code1 = 'QLP' AND
5388                l_lac_sf52_rec.first_action_la_code2 = 'ZLM' THEN
5389 
5390                ghr_msl_pkg.g_first_noa_code := '890';
5391 
5392             end if;
5393             if l_effective_date >= to_date('2007/01/07','YYYY/MM/DD') AND
5394                l_eq_pay_plan = 'FW' AND
5395                l_lac_sf52_rec.first_action_la_code1 = 'RJR' THEN
5396 
5397                ghr_msl_pkg.g_first_noa_code := '890';
5398 
5399             end if;
5400 --------GPPA Update 46 end
5401 
5402 
5403 ---- Start of Bug #7577249
5404        IF l_essl_table and (l_eq_pay_plan = 'ES' OR l_pay_plan = 'FE') then
5405         If l_pay_plan in ('ES', 'FE', 'IE', 'EP') and
5406  	    l_lac_sf52_rec.first_action_la_code1 = 'Q3A' then
5407 	    ghr_msl_pkg.g_first_noa_code := '891';
5408 	elsif l_pay_plan in ('ES', 'FE', 'IE', 'EP') and
5409             l_lac_sf52_rec.first_action_la_code1 = 'Q3B' then
5410 	    ghr_msl_pkg.g_first_noa_code := '892';
5411 	elsif l_pay_plan in ('ES', 'FE', 'IE', 'EP') and
5412 	      l_lac_sf52_rec.first_action_la_code1 = 'Q3D' then
5413 	    ghr_msl_pkg.g_first_noa_code := '890';
5414         elsif l_pay_plan in ('ES', 'FE', 'IE', 'EP') and
5415 	      l_lac_sf52_rec.first_action_la_code1 = 'Q3E' then
5416 	    ghr_msl_pkg.g_first_noa_code := '890';
5417 	end if;
5418        END IF;
5419 
5420        --------end of Bug #7577249
5421 
5422        -- Bug 8320557 SL Equivalent Pay band conv
5423        ghr_msl_pkg.g_sl_payband_conv := FALSE;
5424        ---Changes related to SL/ST/IP conversion
5425        If l_essl_table and l_eq_pay_plan = 'SL' then
5426 --         If l_pay_plan in ('SL', 'ST', 'IP') then
5427 	   If l_effective_date = to_date('2009/04/12','YYYY/MM/DD') then
5428 	       --Fetching the locality adjustment as this conversion
5429 	       -- is applicable only if locality is available
5430                ghr_api.retrieve_element_entry_value
5431                        (p_element_name          => 'Locality Pay or SR Supplement'
5432                        ,p_input_value_name      => 'Rate'
5433                        ,p_assignment_id         => l_assignment_id
5434                        ,p_effective_date        => l_effective_date
5435                        ,p_value                 => l_locality_adj
5436                        ,p_multiple_error_flag   => l_multi_error_flag);
5437 
5438                if l_multi_error_flag then
5439                   hr_utility.set_message(8301, 'GHR_38014_API_MULTI_ELE_ENTR');
5440                   hr_utility.raise_error;
5441                end if;
5442 
5443 	       If NVL(l_locality_adj,0) > 0 then
5444 	          ghr_msl_pkg.g_sl_payband_conv := TRUE;
5445 	          ghr_msl_pkg.g_first_noa_code := '890';
5446 		  l_lac_sf52_rec.first_action_la_code1 := 'ZLM';
5447                   l_lac_sf52_rec.first_action_la_desc1 := 'P.L. 110-372';
5448 	       end if;
5449 	   end if;
5450 --	end if;
5451       end if;
5452 --------end of Bug #8320557
5453 
5454 
5455 
5456     -- Start of Bug3437354
5457         g_proc := 'Location Validation';
5458         IF l_location_id IS NULL THEN
5459             l_mslerrbuf := 'Error - No valid Location found, salary cannot be calculated correctly'||
5460                                ' without the employee''s duty location. ';
5461                 RAISE msl_error;
5462         END IF;
5463         g_proc := 'Duty Station Validation';
5464         IF l_duty_station_id IS NOT NULL THEN
5465 
5466             --
5467             -- Added this condition for bug 3437354, error out the record without valid Loc id
5468             --
5469             FOR rec_ds in cur_valid_ds(l_duty_station_id)
5470             LOOP
5471                 l_ds_end_date	:= rec_ds.end_Date;
5472             END LOOP;
5473             IF l_ds_end_date IS NULL THEN
5474                 hr_utility.set_location('Under DS null check'||l_duty_station_id,12345);
5475                 l_mslerrbuf := 'Error - Duty Station associated with the location is INVALID. '||
5476                                'Salary cannot be calculated correctly without valid duty station. ';
5477                 RAISE msl_error;
5478             END IF;
5479 
5480         END IF;
5481         -- End of bug 3437354
5482 
5483        /*begin
5484           ghr_pa_requests_pkg.get_SF52_loc_ddf_details
5485               (p_location_id      => l_location_id
5486               ,p_duty_station_id  => l_duty_station_id);
5487        exception
5488           when others then
5489              hr_utility.set_location(
5490              'Error in Ghr_pa_requests_pkg.get_sf52_loc_ddf_details'||
5491                    'Err is '||sqlerrm(sqlcode),20);
5492              l_mslerrbuf := 'Error in get_sf52_loc_ddf_details '||
5493                    'Sql Err is '|| sqlerrm(sqlcode);
5494              raise msl_error;
5495        end;*/
5496 
5497 	--
5498 	-- BUG 3377958 Madhuri
5499 	-- Pick the organization name
5500 	--
5501 	l_org_name :=GHR_MRE_PKG.GET_ORGANIZATION_NAME(p_ORGANIZATION_ID);
5502 	-- BUG 3377958 Madhuri
5503 	--
5504        /*get_pos_grp1_ddf(l_position_id,
5505                         l_effective_date,
5506                         l_pos_grp1_rec);
5507 
5508        l_personnel_office_id :=  l_pos_grp1_rec.poei_information3;
5509        l_org_structure_id    :=  l_pos_grp1_rec.poei_information5;
5510 
5511        get_sub_element_code_pos_title(l_position_id,
5512                                      p_person_id,
5513                                      l_business_group_id,
5514                                      l_assignment_id,
5515                                      l_effective_date,
5516                                      l_sub_element_code,
5517                                      l_position_title,
5518                                      l_position_number,
5519                                      l_position_seq_no);
5520 
5521 	hr_utility.set_location('The duty station id is:'||l_duty_station_id,12345);
5522 
5523        if check_init_eligibility(l_p_duty_station_id,
5524                               l_p_PERSONNEL_OFFICE_ID,
5525                               l_p_AGENCY_CODE_SUBELEMENT,
5526                               l_duty_station_id,
5527                               l_personnel_office_id,
5528                               l_sub_element_code) then
5529 
5530 		   hr_utility.set_location('check_init_eligibility    ' || l_proc,6);
5531 		-- Bug 3457205 Filter the Pay plan table id condition also b4 checking any other thing
5532 		-- Moving check_eligibility to here.
5533 			-- Get PRD, work schedule etc form ASG EI
5534 			 begin
5535 				ghr_pa_requests_pkg.get_sf52_asg_ddf_details
5536 						  (l_assignment_id,
5537 						   l_effective_date,
5538 						   l_tenure,
5539 						   l_annuitant_indicator,
5540 						   l_pay_rate_determinant,
5541 						   l_work_schedule,
5542 						   l_part_time_hour);
5543 			 exception
5544 				when others then
5545 					hr_utility.set_location('Error in Ghr_pa_requests_pkg.get_sf52_asg_ddf_details'||
5546 							  'Err is '||sqlerrm(sqlcode),20);
5547 					l_mslerrbuf := 'Error in get_sf52_asgddf_details Sql Err is '|| sqlerrm(sqlcode);
5548 					raise msl_error;
5549 			 end;
5550 
5551 -- Bug 3315432 Madhuri
5552 --
5553         FOR l_cnt in 1..rec_pp_prd_per_gr.COUNT LOOP
5554 
5555 / *	IF ( nvl(rec_pp_prd_per_gr(l_cnt).pay_plan,l_pay_plan) = l_pay_plan
5556 	    and nvl(rec_pp_prd_per_gr(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant
5557 	    and l_user_table_id = nvl(l_pay_table_id,l_user_table_id) ) THEN * /
5558 
5559 ---Bug 3327999 First filter the PRD. Then check for Pay plan and Pay table ID
5560 		IF nvl(rec_pp_prd_per_gr(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant THEN
5561 		-- Get Pay table ID and other details
5562            BEGIN
5563 		       get_pay_plan_and_table_id(l_pay_rate_determinant,p_person_id,
5564                            l_position_id,l_effective_date,
5565                            l_grade_id, l_assignment_id,'SHOW',l_pay_plan,
5566                            l_pay_table_id,l_grade_or_level, l_step_or_rate,
5567                            l_pay_basis);
5568            EXCEPTION
5569                when msl_error then
5570                  l_mslerrbuf := hr_utility.get_message;
5571                  raise;
5572            END;
5573 
5574 		IF ( nvl(rec_pp_prd_per_gr(l_cnt).pay_plan,l_pay_plan) = l_pay_plan
5575 			and l_user_table_id = nvl(l_pay_table_id,l_user_table_id) ) THEN
5576 
5577 		IF ( nvl(rec_pp_prd_per_gr(l_cnt).grade,l_grade_or_level)=l_grade_or_level
5578 			and nvl(rec_pp_prd_per_gr(l_cnt).percent,0) <> 0 ) THEN
5579 
5580 
5581 			IF check_eligibility(l_mass_salary_id,
5582                                l_user_table_id,
5583                                l_pay_table_id,
5584                                l_pay_plan,
5585                                l_pay_rate_determinant,
5586                                p_person_id,
5587                                l_effective_date,
5588                                p_action) THEN
5589                 hr_utility.set_location('check_eligibility    ' || l_proc,8);
5590 
5591 			 l_increase_percent := nvl(rec_pp_prd_per_gr(l_cnt).percent,0);*/
5592 
5593 			 if upper(p_action) = 'REPORT' AND l_submit_flag = 'P' THEN
5594 		 	 -- BUG 3377958 Madhuri
5595  			    pop_dtls_from_pa_req(p_person_id,l_effective_date,l_mass_salary_id,l_org_name,p_employee_number);
5596  		    	 -- BUG 3377958 Madhuri
5597 			 ELSE
5598 			   if check_select_flg_msl_perc(p_person_id,upper(p_action),
5599 						l_effective_date,p_mass_salary_id,l_sel_flg,
5600 						l_increase_percent ) then
5601 
5602 				   hr_utility.set_location('check_select_flg    ' || l_proc,7);
5603                    begin
5604 					hr_utility.set_location('The duty station name is:'||l_duty_station_code,12345);
5605 					hr_utility.set_location('The duty station desc is:'||l_duty_station_desc,12345);
5606 
5607 			     ghr_pa_requests_pkg.get_duty_station_details
5608                        (p_duty_station_id        => l_duty_station_id
5609                        ,p_effective_date        => l_effective_date
5610                        ,p_duty_station_code        => l_duty_station_code
5611                        ,p_duty_station_desc        => l_duty_station_desc);
5612                   exception
5613                      when others then
5614                         hr_utility.set_location('Error in Ghr_pa_requests_pkg.get_duty_station_details'||
5615                                'Err is '||sqlerrm(sqlcode),20);
5616                     l_mslerrbuf := 'Error in get_duty_station_details Sql Err is '|| sqlerrm(sqlcode);
5617                     raise msl_error;
5618 
5619                   end;
5620 
5621                      get_other_dtls_for_rep(l_pay_rate_determinant,
5622                                      l_executive_order_number,
5623                                      to_char(l_executive_order_date),
5624                                      l_first_action_la_code1,
5625                                      l_first_action_la_code2,
5626                                      l_remark_code1,
5627                                      l_remark_code2);
5628 
5629                      get_from_sf52_data_elements
5630                             (l_assignment_id,  l_effective_date,
5631                              l_old_basic_pay, l_old_avail_pay,
5632                              l_old_loc_diff, l_tot_old_sal,
5633                              l_old_auo_pay, l_old_adj_basic_pay,
5634                              l_other_pay, l_auo_premium_pay_indicator,
5635                              l_ap_premium_pay_indicator,
5636                              l_retention_allowance,
5637                              l_retention_allow_perc,
5638                              l_supervisory_differential,
5639                              l_supervisory_diff_perc,
5640                              l_staffing_differential);
5641 
5642 --7577249 commented hardcoding and fetched the family code from DB
5643 -- as it changes the NOA code based on LAC for SES perc process.
5644   open get_sal_chg_fam;
5645   fetch get_sal_chg_fam into l_pay_calc_in_data.noa_family_code;
5646   close get_sal_chg_fam;
5647 --7577249
5648 
5649 
5650 
5651   l_pay_calc_in_data.person_id          := p_person_id;
5652   l_pay_calc_in_data.position_id              := l_position_id;
5653   --l_pay_calc_in_data.noa_family_code          := 'SALARY_CHG';
5654   --l_pay_calc_in_data.noa_family_code          := 'GHR_SAL_PAY_ADJ';
5655   l_pay_calc_in_data.noa_code                 := nvl(g_first_noa_code,'894');
5656   l_pay_calc_in_data.second_noa_code          := null;
5657   l_pay_calc_in_data.first_action_la_code1    := l_lac_sf52_rec.first_action_la_code1;
5658   l_pay_calc_in_data.effective_date           := l_effective_date;
5659   l_pay_calc_in_data.pay_rate_determinant     := l_pay_rate_determinant;
5660   l_pay_calc_in_data.pay_plan                 := l_pay_plan;
5661   l_pay_calc_in_data.grade_or_level           := l_grade_or_level;
5662   l_pay_calc_in_data.step_or_rate             := l_step_or_rate;
5663   l_pay_calc_in_data.pay_basis                := l_pay_basis;
5664   l_pay_calc_in_data.user_table_id            := l_pay_table_id;
5665   l_pay_calc_in_data.duty_station_id          := l_duty_station_id;
5666   l_pay_calc_in_data.auo_premium_pay_indicator := l_auo_premium_pay_indicator;
5667   l_pay_calc_in_data.ap_premium_pay_indicator  := l_ap_premium_pay_indicator;
5668   l_pay_calc_in_data.retention_allowance       := l_retention_allowance;
5669   l_pay_calc_in_data.to_ret_allow_percentage   := l_retention_allow_perc;
5670   l_pay_calc_in_data.supervisory_differential  := l_supervisory_differential;
5671   l_pay_calc_in_data.staffing_differential    := l_staffing_differential;
5672   l_pay_calc_in_data.current_basic_pay        := l_old_basic_pay;
5673   l_pay_calc_in_data.current_adj_basic_pay    := l_old_adj_basic_pay;
5674   l_pay_calc_in_data.current_step_or_rate     := l_step_or_rate;
5675   l_pay_calc_in_data.pa_request_id            := null;
5676 
5677   ghr_msl_pkg.g_ses_msl_process              := 'N';
5678 
5679   if l_pay_plan in ('ES','EP','IE','FE') and l_essl_table then
5680      ghr_msl_pkg.g_ses_msl_process           := 'Y';
5681      l_step_or_rate                          := '00';
5682   end if;
5683 
5684   -- Bug # 8320557 to add basic pay with locality
5685   if ghr_msl_pkg.g_sl_payband_conv then
5686      l_pay_calc_in_data.open_range_out_basic_pay   := l_old_basic_pay+l_old_loc_diff;
5687   else
5688 
5689   ---3843306
5690   -- Start of MSL percentage changes
5691   --
5692   --l_pay_calc_msl_percentage := rec_pp_prd_per_gr(l_cnt).percent;
5693 	  l_pay_calc_msl_percentage := l_increase_percent; -- Bug 3843306
5694 
5695      get_extra_info_comments(p_person_id,l_effective_date,l_pay_sel,
5696                              l_comments,p_mass_salary_id,l_cust_percent,l_ses_basic_pay); -- Added by AVR 3964284
5697      l_comments := NULL;
5698 
5699   -- Recalculate Open range basic pay with new %.
5700 	   ghr_pay_calc.get_open_pay_table_values
5701                           (p_user_table_id     =>   l_pay_table_id
5702                          ,p_pay_plan          =>  l_pay_plan
5703                           ,p_grade_or_level    =>   l_grade_or_level
5704                         ,p_effective_date    =>  NVL(l_effective_date,TRUNC(sysdate))
5705                           ,p_row_high          =>  l_row_high
5706                           ,p_row_low           =>  l_row_low );
5707 -- MSL Percentage issue
5708 	IF l_pay_basis='PA' THEN
5709 	  l_pay_calc_in_data.open_range_out_basic_pay := round(l_pay_calc_in_data.current_basic_pay *
5710                  				( 1 + ( l_pay_calc_msl_percentage / 100 ) ),0);
5711 	ELSIF l_pay_basis='PH' THEN
5712 	  l_pay_calc_in_data.open_range_out_basic_pay := round(l_pay_calc_in_data.current_basic_pay *
5713                  				( 1 + ( l_pay_calc_msl_percentage / 100 ) ),2);
5714 	ELSE
5715 	  l_pay_calc_in_data.open_range_out_basic_pay := round(l_pay_calc_in_data.current_basic_pay *
5716                  				( 1 + ( l_pay_calc_msl_percentage / 100 ) ),0);
5717         END IF;
5718 
5719 		IF l_pay_calc_in_data.open_range_out_basic_pay < l_row_low THEN
5720 		   l_comment_range := 'MSL:New Basic Pay is set to table minimum ' || l_row_low;
5721            l_comments := substr(l_comments || ' ' || l_comment_range , 1,150);
5722 			ins_upd_per_extra_info
5723 				   (p_person_id,l_effective_date, l_sel_flg, l_comments,p_mass_salary_id,l_cust_percent);
5724 			l_pay_calc_in_data.open_range_out_basic_pay := l_row_low;
5725 		   l_comment_range:= NULL;
5726 
5727 		ELSIF l_pay_calc_in_data.open_range_out_basic_pay > l_row_high THEN
5728 		   l_comment_range := 'MSL:New Basic Pay is set to table maximum ' || l_row_high;
5729            l_comments := substr(l_comments || ' ' || l_comment_range , 1,150);
5730 		   ins_upd_per_extra_info
5731 				   (p_person_id,l_effective_date, l_sel_flg, l_comments,p_mass_salary_id,l_cust_percent);
5732 		   l_pay_calc_in_data.open_range_out_basic_pay := l_row_high;
5733 		   l_comment_range:= NULL;
5734 		ELSE
5735 		   l_comment_range:= NULL;
5736 		END IF;
5737      end if;
5738 
5739   -- 3843306
5740   -- End of MSL percentage Changes
5741               begin
5742                   ghr_pay_calc.sql_main_pay_calc (l_pay_calc_in_data
5743                        ,l_pay_calc_out_data
5744                        ,l_message_set
5745                        ,l_calculated);
5746 
5747 					IF l_message_set THEN
5748 						hr_utility.set_location( l_proc, 40);
5749 						l_calculated     := FALSE;
5750 						l_mslerrbuf  := hr_utility.get_message;
5751 			--			raise msl_error;
5752 					END IF;
5753               exception
5754                   when msl_error then
5755                        g_proc := 'ghr_pay_calc';
5756                       raise;
5757                   when others then
5758                 ----BUG 3287299 Start
5759                 IF ghr_pay_calc.gm_unadjusted_pay_flg = 'Y' then
5760                   l_comment := 'MSL:Error: Unadjusted Basic Pay must be entered in Employee record.';
5761                 ELSE
5762                   l_comment := 'MSL:Error: See process log for details.';
5763                 END IF;
5764 
5765                 IF upper(p_action) IN ('SHOW') THEN
5766                       -- Bug#2383392
5767                      create_mass_act_prev (
5768 			p_effective_date          => l_effective_date,
5769 			p_date_of_birth           => p_date_of_birth,
5770 			p_full_name               => p_full_name,
5771 			p_national_identifier     => p_national_identifier,
5772 			--Bug # 9329643
5773 			p_employee_number         => p_employee_number,
5774 			p_duty_station_code       => l_duty_station_code,
5775 			p_duty_station_desc       => l_duty_station_desc,
5776 			p_personnel_office_id     => l_personnel_office_id,
5777 			p_basic_pay               => l_old_basic_pay,
5778 			p_new_basic_pay           => null,
5779 			--Bug#2383992 Added old_adj_basic_pay
5780 			p_adj_basic_pay           => l_old_adj_basic_pay,
5781 			p_new_adj_basic_pay       => null,
5782 			p_old_avail_pay           => l_old_avail_pay,
5783 			p_new_avail_pay           => null,
5784 			p_old_loc_diff            => l_old_loc_diff,
5785 			p_new_loc_diff            => null,
5786 			p_tot_old_sal             => l_tot_old_sal,
5787 			p_tot_new_sal             => null,
5788 			p_old_auo_pay             => l_old_auo_pay,
5789 			p_new_auo_pay             => null,
5790 			p_position_id             => l_position_id,
5791 			p_position_title          => l_position_title,
5792              -- FWFA Changes Bug#4444609
5793             p_position_number         => l_position_number,
5794             p_position_seq_no         => l_position_seq_no,
5795              -- FWFA Changes
5796 			p_org_structure_id        => l_org_structure_id,
5797 			p_agency_sub_element_code => l_sub_element_code,
5798 			p_person_id               => p_person_id,
5799 			p_mass_salary_id          => l_mass_salary_id,
5800 			p_sel_flg                 => l_sel_flg,
5801 			p_first_action_la_code1   => l_first_action_la_code1,
5802 			p_first_action_la_code2   => l_first_action_la_code2,
5803 			p_remark_code1            => l_remark_code1,
5804 			p_remark_code2            => l_remark_code2,
5805 			p_grade_or_level          => l_grade_or_level,
5806 			p_step_or_rate            => l_step_or_rate,
5807 			p_pay_plan                => l_pay_plan,
5808 			p_pay_rate_determinant    => NULL,
5809 			p_tenure                  => l_tenure,
5810 			p_action                  => p_action,
5811 			p_assignment_id           => l_assignment_id,
5812 			p_old_other_pay           => l_other_pay,
5813 			p_new_other_pay           => null,
5814 			-- Bug#2383992
5815 			p_old_capped_other_pay    => NULL,
5816 			p_new_capped_other_pay    => NULL,
5817 			p_old_retention_allowance => l_retention_allowance,
5818 			p_new_retention_allowance => NULL,
5819 			p_old_supervisory_differential => l_supervisory_differential,
5820 			p_new_supervisory_differential => NULL,
5821 			-- BUG 3377958 Madhuri
5822 			p_organization_name            => l_org_name,
5823 			-- BUG 3377958 Madhuri
5824 			-- Bug#2383992
5825 			p_increase_percent => l_pay_calc_msl_percentage,
5826             -- FWFA Changes Bug#4444609
5827             p_input_pay_rate_determinant  => l_pay_rate_determinant,
5828             p_from_pay_table_id         => l_user_table_id,
5829             p_to_pay_table_id           =>  null
5830             -- FWFA Changes
5831              );
5832                       END IF;
5833                       l_comments := substr(l_comments || ' ' || l_comment , 1,150);
5834                       ins_upd_per_extra_info
5835                          (p_person_id,l_effective_date, l_sel_flg, l_comments,p_mass_salary_id,l_cust_percent);
5836                       l_comment := NULL;
5837                       ------  BUG 3287299 End
5838                       hr_utility.set_location('Error in Ghr_pay_calc.sql_main_pay_calc '||
5839                                 'Err is '||sqlerrm(sqlcode),20);
5840                     l_mslerrbuf := 'Error in ghr_pay_calc  Sql Err is '|| sqlerrm(sqlcode);
5841                     g_proc := 'ghr_pay_calc';
5842                     raise msl_error;
5843               end;
5844 
5845         ghr_msl_pkg.g_ses_msl_process              := 'N';
5846 
5847         l_new_basic_pay        := l_pay_calc_out_data.basic_pay;
5848         l_new_locality_adj     := l_pay_calc_out_data.locality_adj;
5849         l_new_adj_basic_pay    := l_pay_calc_out_data.adj_basic_pay;
5850         l_new_au_overtime      := l_pay_calc_out_data.au_overtime;
5851         l_new_availability_pay := l_pay_calc_out_data.availability_pay;
5852 
5853         l_out_pay_rate_determinant := l_pay_calc_out_data.out_pay_rate_determinant;
5854         l_out_step_or_rate         := l_pay_calc_out_data.out_step_or_rate;
5855         l_new_retention_allowance :=  l_pay_calc_out_data.retention_allowance;
5856         l_new_supervisory_differential := l_supervisory_differential;
5857         l_new_other_pay_amount         := l_pay_calc_out_data.other_pay_amount;
5858         l_entitled_other_pay      := l_new_other_pay_amount;
5859         if l_new_other_pay_amount = 0 then
5860            l_new_other_pay_amount := null;
5861         end if;
5862         l_new_total_salary        := l_pay_calc_out_data.total_salary;
5863 
5864      hr_utility.set_location('retention_allowance = ' || to_char(l_retention_allowance),10);
5865      hr_utility.set_location('Supervisory Diff Amount = ' || to_char(l_supervisory_differential),10);
5866 
5867 -------------Call Pay cap Procedure
5868      begin
5869       l_capped_other_pay := ghr_pa_requests_pkg2.get_cop( p_assignment_id  => l_assignment_id
5870                                                          ,p_effective_date => l_effective_date);
5871       l_old_capped_other_pay :=  l_capped_other_pay;
5872 		-- Sundar Added the following if statement to improve performance
5873 			if hr_utility.debug_enabled = true then
5874 				  hr_utility.set_location('Before Pay Cap    ' || l_proc,21);
5875 				  hr_utility.set_location('l_effective_date  ' || l_effective_date,21);
5876 				  hr_utility.set_location('l_out_pay_rate_determinant  ' || l_out_pay_rate_determinant,21);
5877 				  hr_utility.set_location('l_pay_plan  ' || l_pay_plan,21);
5878 				  hr_utility.set_location('l_position_id  ' || to_char(l_position_id),21);
5879 				  hr_utility.set_location('l_pay_basis  ' || l_pay_basis,21);
5880 				  hr_utility.set_location('person_id  ' || to_char(p_person_id),21);
5881 				  hr_utility.set_location('l_new_basic_pay  ' || to_char(l_new_basic_pay),21);
5882 				  hr_utility.set_location('l_new_locality_adj  ' || to_char(l_new_locality_adj),21);
5883 				  hr_utility.set_location('l_new_adj_basic_pay  ' || to_char(l_new_adj_basic_pay),21);
5884 				  hr_utility.set_location('l_new_total_salary  ' || to_char(l_new_total_salary),21);
5885 				  hr_utility.set_location('l_entitled_other_pay  ' || to_char(l_entitled_other_pay),21);
5886 				  hr_utility.set_location('l_capped_other_pay  ' || to_char(l_capped_other_pay),21);
5887 				  hr_utility.set_location('l_new_retention_allowance  ' || to_char(l_new_retention_allowance),21);
5888 				  hr_utility.set_location('l_new_supervisory_differential  ' || to_char(l_new_supervisory_differential),21);
5889 				  hr_utility.set_location('l_staffing_differential  ' || to_char(l_staffing_differential),21);
5890 				  hr_utility.set_location('l_new_au_overtime  ' || to_char(l_new_au_overtime),21);
5891 				  hr_utility.set_location('l_new_availability_pay  ' || to_char(l_new_availability_pay),21);
5892 			end if;
5893 
5894       --Bug # 9309268
5895       ghr_msl_pkg.g_msl_bp_paycap := NULL;
5896       ghr_pay_caps.do_pay_caps_main
5897                    (p_pa_request_id        =>    null
5898                    ,p_effective_date       =>    l_effective_date
5899 		   ,p_duty_station_id      =>    l_duty_station_id --bug# 13414643,13403289
5900                    ,p_pay_rate_determinant =>    nvl(l_out_pay_rate_determinant,l_pay_rate_determinant)
5901                    ,p_pay_plan             =>    l_pay_plan
5902                    ,p_to_position_id       =>    l_position_id
5903                    ,p_pay_basis            =>    l_pay_basis
5904                    ,p_person_id            =>    p_person_id
5905                    ,p_noa_code             =>    nvl(g_first_noa_code,'894')
5906                    ,p_basic_pay            =>    l_new_basic_pay
5907                    ,p_locality_adj         =>    l_new_locality_adj
5908                    ,p_adj_basic_pay        =>    l_new_adj_basic_pay
5909                    ,p_total_salary         =>    l_new_total_salary
5910                    ,p_other_pay_amount     =>    l_entitled_other_pay
5911                    ,p_capped_other_pay     =>    l_capped_other_pay
5912                    ,p_retention_allowance  =>    l_new_retention_allowance
5913                    ,p_retention_allow_percentage => l_retention_allow_perc
5914                    ,p_supervisory_allowance =>   l_new_supervisory_differential
5915                    ,p_staffing_differential =>   l_staffing_differential
5916                    ,p_au_overtime          =>    l_new_au_overtime
5917                    ,p_availability_pay     =>    l_new_availability_pay
5918                    ,p_adj_basic_message    =>    l_adj_basic_message
5919                    ,p_pay_cap_message      =>    l_pay_cap_message
5920                    ,p_pay_cap_adj          =>    l_temp_retention_allowance
5921                    ,p_open_pay_fields      =>    l_open_pay_fields_caps
5922                    ,p_message_set          =>    l_message_set_caps
5923                    ,p_total_pay_check      =>    l_total_pay_check);
5924 
5925 
5926              l_new_other_pay_amount := nvl(l_capped_other_pay,l_entitled_other_pay);
5927 
5928 			-- Sundar Added the following statement to improve performance
5929 			if hr_utility.debug_enabled = true then
5930 				  hr_utility.set_location('After Pay Cap    ' || l_proc,22);
5931 				  hr_utility.set_location('l_effective_date  ' || l_effective_date,22);
5932 				  hr_utility.set_location('l_out_pay_rate_determinant  ' || l_out_pay_rate_determinant,22);
5933 				  hr_utility.set_location('l_pay_plan  ' || l_pay_plan,22);
5934 				  hr_utility.set_location('l_position_id  ' || to_char(l_position_id),22);
5935 				  hr_utility.set_location('l_pay_basis  ' || l_pay_basis,22);
5936 				  hr_utility.set_location('person_id  ' || to_char(p_person_id),22);
5937 				  hr_utility.set_location('l_new_basic_pay  ' || to_char(l_new_basic_pay),22);
5938 				  hr_utility.set_location('l_new_locality_adj  ' || to_char(l_new_locality_adj),22);
5939 				  hr_utility.set_location('l_new_adj_basic_pay  ' || to_char(l_new_adj_basic_pay),22);
5940 				  hr_utility.set_location('l_new_total_salary  ' || to_char(l_new_total_salary),22);
5941 				  hr_utility.set_location('l_entitled_other_pay  ' || to_char(l_entitled_other_pay),22);
5942 				  hr_utility.set_location('l_capped_other_pay  ' || to_char(l_capped_other_pay),22);
5943 				  hr_utility.set_location('l_new_retention_allowance  ' || to_char(l_new_retention_allowance),22);
5944 				  hr_utility.set_location('l_new_supervisory_differential  ' || to_char(l_new_supervisory_differential),22);
5945 				  hr_utility.set_location('l_staffing_differential  ' || to_char(l_staffing_differential),22);
5946 				  hr_utility.set_location('l_new_au_overtime  ' || to_char(l_new_au_overtime),22);
5947 				  hr_utility.set_location('l_new_availability_pay  ' || to_char(l_new_availability_pay),22);
5948 			end if;
5949 
5950        IF l_pay_cap_message THEN
5951 			IF nvl(l_temp_retention_allowance,0) > 0 THEN
5952 			  l_comment := 'MSL: Exceeded Total Cap - reduce Retention Allow to '
5953 										|| to_char(l_temp_retention_allowance);
5954 			  l_sel_flg := 'N';
5955 			ELSE
5956 			  l_comment := 'MSL: Exceeded Total cap - pls review.';
5957 			END IF;
5958        ELSIF l_adj_basic_message THEN
5959           l_comment := 'MSL: Exceeded Adjusted Pay Cap - Locality reduced.';
5960        END IF;
5961 
5962        -- Bug 2639698 Sundar
5963 	   IF (l_old_basic_pay > l_new_basic_pay) THEN
5964 			l_comment_sal := 'MSL: From Basic Pay exceeds To Basic Pay.';
5965        END IF;
5966 	   -- End Bug 2639698
5967 
5968        IF l_pay_cap_message or l_adj_basic_message THEN
5969 			-- Bug 2639698
5970 		  IF (l_comment_sal IS NOT NULL) THEN
5971 		     l_comment := l_comment_sal || ' ' || l_comment;
5972 		  END IF;
5973 		  -- End Bug 2639698
5974           l_comments := substr(l_comments || ' ' || l_comment, 1,150);
5975           ins_upd_per_extra_info
5976                (p_person_id,l_effective_date, l_sel_flg, l_comments,p_mass_salary_id,l_cust_percent);
5977           l_comment := NULL;
5978        --------------------Bug 2639698 Sundar To add comments
5979 	   -- Should create comments only if comments need to be inserted
5980 	   ELSIF l_comment_sal IS NOT NULL THEN
5981           l_comments := substr(l_comments || ' ' || l_comment_sal, 1,150);
5982 		  ins_upd_per_extra_info
5983                (p_person_id,l_effective_date, l_sel_flg, l_comments,p_mass_salary_id,l_cust_percent);
5984 	   END IF;
5985 
5986        l_comment_sal := NULL; -- bug 2639698
5987      exception
5988           when msl_error then
5989                raise;
5990           when others then
5991 	  -- Bug # 9309268  Handled to insert a comment and set basic pay to pay cap when basic pay is exceeding the pay cap
5992 	    IF ghr_msl_pkg.g_ses_bp_capped = TRUE and NVL(l_new_locality_adj,0) = 0  THEN
5993 	        l_bp_diff :=  l_new_basic_pay - ghr_msl_pkg.g_msl_bp_paycap;
5994 		l_new_basic_pay := ghr_msl_pkg.g_msl_bp_paycap;
5995 		l_new_adj_basic_pay := l_new_basic_pay;
5996 		l_new_total_salary := l_new_total_salary - l_bp_diff;
5997                 l_comment := 'MSL: New Basic Pay has been set to Maximum Pay Cap ';
5998 	        ins_upd_per_extra_info
5999                    (p_person_id,l_effective_date, l_sel_flg, l_comment,p_mass_salary_id);
6000 	        l_comment := NULL;
6001               ELSE
6002 	    	  -- Bug # 9309268
6003                 hr_utility.set_location('Error in ghr_pay_caps.do_pay_caps_main ' ||
6004                                         'Err is '||sqlerrm(sqlcode),23);
6005                 l_mslerrbuf := 'Error in do_pay_caps_main  Sql Err is '|| sqlerrm(sqlcode);
6006                 raise msl_error;
6007               END IF;
6008 	      	    ghr_msl_pkg.g_msl_bp_paycap := NULL;
6009      end;
6010 
6011                 IF upper(p_action) IN ('SHOW','REPORT') THEN
6012                           -- Bug#2383392
6013                     create_mass_act_prev (
6014                         p_effective_date          => l_effective_date,
6015                         p_date_of_birth           => p_date_of_birth,
6016                         p_full_name               => p_full_name,
6017                         p_national_identifier     => p_national_identifier,
6018 			--Bug # 9329643
6019 			p_employee_number         => p_employee_number,
6020                         p_duty_station_code       => l_duty_station_code,
6021                         p_duty_station_desc       => l_duty_station_desc,
6022                         p_personnel_office_id     => l_personnel_office_id,
6023                         p_basic_pay               => l_old_basic_pay,
6024                         p_new_basic_pay           => l_new_basic_pay,
6025                         --Bug#2383992 Added old_adj_basic_pay
6026                         p_adj_basic_pay           => l_old_adj_basic_pay,
6027                         p_new_adj_basic_pay       => l_new_adj_basic_pay,
6028                         p_old_avail_pay           => l_old_avail_pay,
6029                         p_new_avail_pay           =>  l_new_availability_pay,
6030                         p_old_loc_diff            => l_old_loc_diff,
6031                         p_new_loc_diff            => l_new_locality_adj,
6032                         p_tot_old_sal             => l_tot_old_sal,
6033                         p_tot_new_sal             =>   l_new_total_salary,
6034                         p_old_auo_pay             => l_old_auo_pay,
6035                         p_new_auo_pay             =>   l_new_au_overtime,
6036                         p_position_id             => l_position_id,
6037                         p_position_title          => l_position_title,
6038                     -- FWFA Changes Bug#4444609
6039                         p_position_number         => l_position_number,
6040                         p_position_seq_no         => l_position_seq_no,
6041                     -- FWFA Changes
6042                         p_org_structure_id        => l_org_structure_id,
6043                         p_agency_sub_element_code => l_sub_element_code,
6044                         p_person_id               => p_person_id,
6045                         p_mass_salary_id          => l_mass_salary_id,
6046                         p_sel_flg                 => l_sel_flg,
6047                         p_first_action_la_code1   => l_first_action_la_code1,
6048                         p_first_action_la_code2   => l_first_action_la_code2,
6049                         p_remark_code1            => l_remark_code1,
6050                         p_remark_code2            => l_remark_code2,
6051                         p_grade_or_level          => l_grade_or_level,
6052                         p_step_or_rate            => l_step_or_rate,
6053                         p_pay_plan                => l_pay_plan,
6054                         p_pay_rate_determinant    => NVL(l_out_pay_rate_determinant,l_pay_rate_determinant),
6055                         p_tenure                  => l_tenure,
6056                         p_action                  => p_action,
6057                         p_assignment_id           => l_assignment_id,
6058                         p_old_other_pay           => l_other_pay,
6059                         p_new_other_pay           => l_new_other_pay_amount,
6060                         -- Bug#2383992
6061                         p_old_capped_other_pay    => l_old_capped_other_pay,--NULL,
6062                         p_new_capped_other_pay    => l_capped_other_pay,
6063                         p_old_retention_allowance => l_retention_allowance,
6064                         p_new_retention_allowance => l_new_retention_allowance,
6065                         p_old_supervisory_differential => l_supervisory_differential,
6066                         p_new_supervisory_differential => l_new_supervisory_differential,
6067                         -- BUG 3377958 Madhuri
6068                         p_organization_name            => l_org_name,
6069                         -- Bug#2383992
6070                         p_increase_percent => l_pay_calc_msl_percentage,
6071                         -- FWFA Changes Bug#4444609
6072                         p_input_pay_rate_determinant     => l_pay_rate_determinant,
6073                         p_from_pay_table_id            => l_pay_calc_out_data.pay_table_id,
6074                         p_to_pay_table_id              => l_pay_calc_out_data.calculation_pay_table_id
6075                         -- FWFA Changes
6076                          );
6077 
6078 
6079                 ELSIF upper(p_action) = 'CREATE' then
6080                     BEGIN
6081                        get_pay_plan_and_table_id
6082                           (l_pay_rate_determinant,p_person_id,
6083                            l_position_id,l_effective_date,
6084                            l_grade_id, l_assignment_id,'CREATE',
6085                            l_pay_plan,l_pay_table_id,
6086                            l_grade_or_level, l_step_or_rate,
6087                            l_pay_basis);
6088                     EXCEPTION
6089                     when msl_error then
6090                       l_mslerrbuf := hr_utility.get_message;
6091                       raise;
6092                     END;
6093                     assign_to_sf52_rec(
6094                        p_person_id,
6095                        p_first_name,
6096                        p_last_name,
6097                        p_middle_names,
6098                        p_national_identifier,
6099                        p_date_of_birth,
6100                        l_effective_date,
6101                        l_assignment_id,
6102                        l_tenure,
6103                        -- Bug#5089732
6104                        l_grade_id,
6105                        l_pay_plan,
6106                        l_grade_or_level,
6107                        -- Bug#5089732
6108                        l_step_or_rate,
6109                        l_annuitant_indicator,
6110                        -- FWFA Changes Bug#4444609
6111                        NVL(l_out_pay_rate_determinant,l_pay_rate_determinant),
6112                        -- FWFA Changes
6113                        l_work_schedule,
6114                        l_part_time_hour,
6115                        l_pos_ei_data.poei_information7, --FLSA Category
6116                        l_pos_ei_data.poei_information8, --Bargaining Unit Status
6117                        l_pos_ei_data.poei_information11,--Functional Class
6118                        l_pos_ei_data.poei_information16,--Supervisory Status,
6119                        l_new_basic_pay,
6120                        l_new_locality_adj,
6121                        l_new_adj_basic_pay,
6122                        l_new_total_salary,
6123                        l_other_pay,
6124                        l_new_other_pay_amount,
6125                        l_new_au_overtime,
6126                        l_new_availability_pay,
6127                        l_new_retention_allowance,
6128                        l_retention_allow_perc,
6129                        l_new_supervisory_differential,
6130                        l_supervisory_diff_perc,
6131                        l_staffing_differential,
6132                        l_duty_station_id,
6133                        l_duty_station_code,
6134                        l_duty_station_desc,
6135                        -- FWFA Changes Bug#4444609
6136                        l_pay_rate_determinant,
6137                        l_pay_calc_out_data.pay_table_id,
6138                        l_pay_calc_out_data.calculation_pay_table_id,
6139                        -- FWFA Changes
6140                        l_lac_sf52_rec,
6141                        l_sf52_rec);
6142 
6143 					/* Bug#3964284 Commented the following code as PAY RELATED FIELDS are already
6144                                    Assigned to l_sf52_rec variable in the above procedure call(i.e.assign_to_sf52_rec)
6145                        */
6146 
6147                    BEGIN
6148 
6149 		               l_sf52_rec.mass_action_id := p_mass_salary_id;
6150                        l_sf52_rec.rpa_type := 'MPC';
6151                        g_proc  := 'create_sf52_recrod';
6152                        ghr_mass_changes.create_sf52_for_mass_changes
6153                                (p_mass_action_type => 'MASS_SALARY_CHG',
6154                                 p_pa_request_rec  => l_sf52_rec,
6155                                 p_errbuf           => l_errbuf,
6156                                 p_retcode          => l_retcode);
6157 
6158                        ------ Added by Dinkar for List reports problem
6159                        ---------------------------------------
6160                        IF l_errbuf IS NULL THEN
6161                            DECLARE
6162                                l_pa_request_number ghr_pa_requests.request_number%TYPE;
6163 						   BEGIN
6164          				       l_pa_request_number   :=
6165 							    	 l_sf52_rec.request_number||'-'||p_mass_salary_id;
6166 
6167 						       ghr_par_upd.upd
6168                               (p_pa_request_id             => l_sf52_rec.pa_request_id,
6169                                p_object_version_number     => l_sf52_rec.object_version_number,
6170                                p_request_number            => l_pa_request_number
6171                               );
6172 						   END;
6173 
6174                            pr('No error in create sf52 ');
6175 		   	  --Bug # 9329643 Modified SSN to Emp No
6176                            ghr_mto_int.log_message(
6177                               p_procedure => 'Successful Completion',
6178                               p_message   => 'Name: '||p_full_name ||
6179                               ' Emp No: ' || p_employee_number||
6180                               '  Mass Salary : '||
6181                               p_mass_salary ||' SF52 Successfully completed');
6182 
6183                            create_lac_remarks(l_pa_request_id,
6184                                            l_sf52_rec.pa_request_id);
6185 
6186                            -- Added by Enunez 11-SEP-1999
6187                            IF l_lac_sf52_rec.first_action_la_code1 IS NULL THEN
6188                                -- Added by Edward Nunez for 894 rules
6189                                g_proc := 'Apply_894_Rules';
6190                                --Bug 2012782 fix
6191                                IF l_out_pay_rate_determinant IS NULL THEN
6192                                   l_out_pay_rate_determinant := l_pay_rate_determinant;
6193                                END IF;
6194                                --Bug 2012782 fix end
6195                                ghr_lacs_remarks.Apply_894_Rules(
6196                                    l_sf52_rec.pa_request_id,
6197                                    l_out_pay_rate_determinant,
6198                                    l_pay_rate_determinant,
6199                                    l_out_step_or_rate,
6200                                    l_executive_order_number,
6201                                    l_executive_order_date,
6202                                    l_opm_issuance_number,
6203                                    l_opm_issuance_date,
6204                                    l_errbuf,
6205                                    l_retcode
6206                                    );
6207                                IF l_errbuf IS NOT NULL THEN
6208                                    l_mslerrbuf := l_mslerrbuf || ' ' || l_errbuf || ' Sql Err is '
6209                                                                   || sqlerrm(sqlcode);
6210                                    RAISE msl_error;
6211                                END IF;
6212                            END IF; -- IF l_lac_sf52_rec.first_action_la_code1
6213                            g_proc := 'update_SEL_FLG';
6214 
6215                            update_SEL_FLG(p_PERSON_ID,l_effective_date);
6216 
6217                            COMMIT;
6218                        ELSE
6219                            pr('Error in create sf52',l_errbuf);
6220                            hr_utility.set_location('Error in '||to_char(p_position_id),20);
6221                            l_recs_failed := l_recs_failed + 1;
6222                            -- Error raising is not required as the error is written to process
6223                            -- log in the create_sf52_for_mass_changes procedure.
6224                            --raise msl_error;
6225                        END IF; -- if l_errbuf is null then
6226                    EXCEPTION
6227                        when msl_error then raise;
6228                        when others then  null;
6229                            l_mslerrbuf := 'Error in ghr_mass_chg.create_sf52 '||
6230                                           ' Sql Err is '|| sqlerrm(sqlcode);
6231                            RAISE msl_error;
6232                    END;
6233                END IF; --  IF upper(p_action) IN ('SHOW','REPORT') THEN
6234            END IF; -- end if for check_select_flg
6235        END IF; -- end if for p_action = 'REPORT'
6236 
6237        l_row_cnt := l_row_cnt + 1;
6238        IF UPPER(p_action) <> 'CREATE' THEN
6239            IF L_row_cnt > 50 THEN
6240                COMMIT;
6241                L_row_cnt := 0;
6242            END IF;
6243        END IF;
6244    EXCEPTION
6245          WHEN MSL_ERROR THEN
6246                HR_UTILITY.SET_LOCATION('Error occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),10);
6247                begin
6248                 ------  BUG 3287299 -- Not to rollback for preview.
6249        	        if upper(p_action) <> 'SHOW' then
6250                   ROLLBACK TO execute_msl_perc_SP;
6251                 end if;
6252                EXCEPTION
6253                   WHEN OTHERS THEN NULL;
6254                END;
6255 	       	  --Bug # 9329643 Modified SSN to Emp No
6256                l_log_text  := 'Error in '||l_proc||' '||
6257                               ' For Mass Salary Name : '||p_mass_salary||
6258                               'Name: '|| p_full_name || ' Emp No: ' || p_employee_number ||' '||
6259                               l_mslerrbuf;
6260                hr_utility.set_location('before creating entry in log file',10);
6261                l_recs_failed := l_recs_failed + 1;
6262             begin
6263                ghr_mto_int.log_message(
6264                               p_procedure => g_proc,
6265                               p_message   => l_log_text);
6266 
6267             exception
6268                 when others then
6269                     hr_utility.set_message(8301, 'GHR_38475_ERROR_LOG_FAILURE');
6270                     hr_utility.raise_error;
6271             end;
6272          when others then
6273                HR_UTILITY.SET_LOCATION('Error (Others) occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),20);
6274                BEGIN
6275                  ROLLBACK TO execute_msl_perc_SP;
6276                EXCEPTION
6277                  WHEN OTHERS THEN NULL;
6278                END;
6279 	       	  --Bug # 9329643 Modified SSN to Emp No
6280                l_log_text  := 'Error (others) in '||l_proc||
6281                               ' For Mass Salary Name : '||p_mass_salary||
6282                               'Name: '|| p_full_name || ' Emp No: ' || p_employee_number ||
6283                               ' Sql Err is '||sqlerrm(sqlcode);
6284                hr_utility.set_location('before creating entry in log file',20);
6285                l_recs_failed := l_recs_failed + 1;
6286             begin
6287                ghr_mto_int.log_message(
6288                               p_procedure => g_proc,
6289                               p_message   => l_log_text);
6290 
6291             exception
6292                 when others then
6293                     hr_utility.set_message(8301, 'Create Error Log failed');
6294                     hr_utility.raise_error;
6295             end;
6296 
6297 
6298    END msl_perc_process;
6299 
6300 BEGIN
6301 
6302   g_proc  := 'execute_msl_perc';
6303   hr_utility.set_location('Entering    ' || l_proc,5);
6304   p_retcode  := 0;
6305 
6306   g_first_noa_code     := null;
6307   BEGIN
6308     FOR msl IN ghr_msl (p_mass_salary_id)
6309     LOOP
6310         p_mass_salary    := msl.name;
6311         l_effective_date := msl.effective_date;
6312         l_mass_salary_id := msl.mass_salary_id;
6313         l_user_table_id  := msl.user_table_id;
6314         l_submit_flag    := msl.submit_flag;
6315         l_executive_order_number := msl.executive_order_number;
6316         l_executive_order_date :=  msl.executive_order_date;
6317         l_opm_issuance_number  :=  msl.opm_issuance_number;
6318         l_opm_issuance_date    :=  msl.opm_issuance_date;
6319         l_pa_request_id  := msl.pa_request_id;
6320         l_rowid          := msl.rowid;
6321         l_p_ORGANIZATION_ID        := msl.ORGANIZATION_ID;
6322         l_p_DUTY_STATION_ID        := msl.DUTY_STATION_ID;
6323         l_p_PERSONNEL_OFFICE_ID    := msl.PERSONNEL_OFFICE_ID;
6324         l_p_AGENCY_CODE_SUBELEMENT := msl.AGENCY_CODE_SUBELEMENT;
6325 
6326 		pr('Pa request id is '||to_char(l_pa_request_id));
6327        exit;
6328     END LOOP;
6329   EXCEPTION
6330     when REC_BUSY then
6331          hr_utility.set_location('Mass Salary is in use',1);
6332          l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
6333         -- raise error;
6334         hr_utility.set_message(8301, 'GHR_38477_LOCK_ON_MSL');
6335         hr_utility.raise_error;
6336 --
6337     when others then
6338   hr_utility.set_location('Error in '||l_proc||' Sql err is '||sqlerrm(sqlcode),1);
6339 --    raise_application_error(-20111,'Error while selecting from Ghr Mass Salaries');
6340      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
6341      raise msl_error;
6342   END;
6343 
6344   g_effective_date := l_effective_date;
6345 
6346   for c_pay_tab_essl_rec in c_pay_tab_essl loop
6347       l_essl_table := TRUE;
6348   exit;
6349   end loop;
6350 
6351 -- Bug 3315432 Madhuri
6352 --
6353   FOR pp_prd_per_gr IN cur_pp_prd_per_gr(p_mass_salary_id)
6354   LOOP
6355 	rec_pp_prd_per_gr(l_index).pay_plan := pp_prd_per_gr.pay_plan;
6356 	rec_pp_prd_per_gr(l_index).prd      := pp_prd_per_gr.prd;
6357 	rec_pp_prd_per_gr(l_index).percent  := pp_prd_per_gr.percent;
6358 	rec_pp_prd_per_gr(l_index).grade    := pp_prd_per_gr.grade;
6359 	l_index := l_index +1;
6360 
6361   END LOOP;
6362 
6363   IF upper(p_action) = 'CREATE' then
6364      ghr_mto_int.set_log_program_name('GHR_MSL_PKG');
6365   ELSE
6366      ghr_mto_int.set_log_program_name('MSL_'||p_mass_salary);
6367   END IF;
6368 
6369 --  Commented out by Edward Nunez. It's not needed anymore with 894 rules
6370 --  IF upper(p_action) = 'CREATE' then
6371 --    if l_pa_request_id is null then
6372 --       hr_utility.set_message(8301, 'GHR_99999_SELECT_LAC_REMARKS');
6373 --       hr_utility.raise_error;
6374 --    END IF;
6375 --  END IF;
6376 
6377   get_lac_dtls(l_pa_request_id,
6378                l_lac_sf52_rec);
6379 
6380   --purge_old_data(l_mass_salary_id);
6381 
6382   hr_utility.set_location('After fetch msl '||to_char(l_effective_date)
6383     ||' '||to_char(l_user_table_id),20);
6384 
6385 IF l_p_ORGANIZATION_ID is not null then
6386     FOR per IN cur_people_org (l_effective_date,l_p_ORGANIZATION_ID)
6387     LOOP
6388         -- Bug#5719467 Initialised the variable l_mslerrbuf to avoid ora error 6502
6389         l_mslerrbuf := NULL;
6390         -- Bug#5063304 Added the following IF Condition.
6391         IF  NVL(l_p_organization_id,per.organization_id) = per.organization_id THEN
6392             FOR ast IN cur_ast (per.assignment_status_type_id)
6393             LOOP
6394                 -- Set all local variables to NULL
6395                 l_personnel_office_id  := NULL;
6396                 l_org_structure_id     := NULL;
6397                 l_position_title       := NULL;
6398                 l_position_number      := NULL;
6399                 l_position_seq_no      := NULL;
6400                 l_sub_element_code     := NULL;
6401                 l_duty_station_id      := NULL;
6402                 l_tenure               := NULL;
6403                 l_annuitant_indicator  := NULL;
6404                 l_pay_rate_determinant := NULL;
6405                 l_work_schedule        := NULL;
6406                 l_part_time_hour       := NULL;
6407                 l_pay_plan             := NULL;
6408                 l_pay_table_id         := NULL;
6409                 l_grade_or_level       := NULL;
6410                 l_step_or_rate         := NULL;
6411                 l_pay_basis            := NULL;
6412                 l_increase_percent     := NULL;
6413                 l_elig_flag            := FALSE;
6414                 --
6415                 BEGIN
6416 		--Bug # 9329643 added employee_number
6417                     fetch_and_validate_emp_perc(
6418                                     p_action                => p_action
6419                                    ,p_mass_salary_id        => p_mass_salary_id
6420                                    ,p_mass_salary_name      => p_mass_salary
6421                                    ,p_full_name             => per.full_name
6422                                    ,p_national_identifier   => per.national_identifier
6423 				   ,p_employee_number       => per.employee_number
6424                                    ,p_assignment_id         => per.assignment_id
6425                                    ,p_person_id             => per.person_id
6426                                    ,p_position_id           => per.position_id
6427                                    ,p_grade_id              => per.grade_id
6428                                    ,p_business_group_id     => per.business_group_id
6429                                    ,p_location_id           => per.location_id
6430                                    ,p_organization_id       => per.organization_id
6431                                    ,p_msl_organization_id    => l_p_organization_id
6432                                    ,p_msl_duty_station_id    => l_p_duty_station_id
6433                                    ,p_msl_personnel_office_id   => l_p_personnel_office_id
6434                                    ,p_msl_agency_code_subelement => l_p_agency_code_subelement
6435                                    ,p_msl_user_table_id         => l_user_table_id
6436                                    ,p_rec_pp_prd_per_gr         => rec_pp_prd_per_gr
6437                                    ,p_personnel_office_id   => l_personnel_office_id
6438                                    ,p_org_structure_id      => l_org_structure_id
6439                                    ,p_position_title        => l_position_title
6440                                    ,p_position_number       => l_position_number
6441                                    ,p_position_seq_no       => l_position_seq_no
6442                                    ,p_subelem_code          => l_sub_element_code
6443                                    ,p_duty_station_id       => l_duty_station_id
6444                                    ,p_tenure                => l_tenure
6445                                    ,p_annuitant_indicator   => l_annuitant_indicator
6446                                    ,p_pay_rate_determinant  => l_pay_rate_determinant
6447                                    ,p_work_schedule         => l_work_schedule
6448                                    ,p_part_time_hour        => l_part_time_hour
6449                                    ,p_pay_plan              => l_pay_plan
6450                                    ,p_pay_table_id          => l_pay_table_id
6451                                    ,p_grade_or_level        => l_grade_or_level
6452                                    ,p_step_or_rate          => l_step_or_rate
6453                                    ,p_pay_basis             => l_pay_basis
6454                                    ,p_increase_percent      => l_increase_percent
6455                                    ,p_elig_flag             => l_elig_flag
6456                                    );
6457                 EXCEPTION
6458                     --WHEN fetch_validate_error THEN
6459                        --l_elig_flag := FALSE;
6460                     WHEN OTHERS THEN
6461                         l_elig_flag := FALSE;
6462                 END;
6463 
6464                 IF l_elig_flag THEN
6465                     msl_perc_process( p_assignment_id  => per.assignment_id
6466                               ,p_person_id => per.person_id
6467                               ,p_position_id  => per.position_id
6468                               ,p_grade_id => per.grade_id
6469                               ,p_business_group_id => per.business_group_id
6470                               ,p_location_id => per.location_id
6471                               ,p_organization_id => per.organization_id
6472                               ,p_date_of_birth => per.date_of_birth
6473                               ,p_first_name => per.first_name
6474                               ,p_last_name => per.last_name
6475                               ,p_full_name => per.full_name
6476                               ,p_middle_names => per.middle_names
6477                               ,p_national_identifier => per.national_identifier
6478 			      --Bug # 9329643
6479 			      ,p_employee_number     => per.employee_number
6480                               ,p_personnel_office_id   => l_personnel_office_id
6481                               ,p_org_structure_id      => l_org_structure_id
6482                               ,p_position_title        => l_position_title
6483                               ,p_position_number       => l_position_number
6484                               ,p_position_seq_no       => l_position_seq_no
6485                               ,p_subelem_code          => l_sub_element_code
6486                               ,p_duty_station_id       => l_duty_station_id
6487                               ,p_tenure                => l_tenure
6488                               ,p_annuitant_indicator   => l_annuitant_indicator
6489                               ,p_pay_rate_determinant  => l_pay_rate_determinant
6490                               ,p_work_schedule         => l_work_schedule
6491                               ,p_part_time_hour        => l_part_time_hour
6492                               ,p_pay_plan              => l_pay_plan
6493                               ,p_pay_table_id          => l_pay_table_id
6494                               ,p_grade_or_level        => l_grade_or_level
6495                               ,p_step_or_rate          => l_step_or_rate
6496                               ,p_pay_basis             => l_pay_basis
6497                               ,p_increase_percent      => l_increase_percent
6498                               );
6499 
6500                    END IF;
6501                END LOOP;
6502            END IF;
6503        END LOOP;
6504    ELSE
6505     FOR per IN cur_people (l_effective_date)
6506     LOOP
6507         -- Bug#5719467 Initialised the variable l_mslerrbuf to avoid ora error 6502
6508         l_mslerrbuf := NULL;
6509         FOR ast IN cur_ast (per.assignment_status_type_id)
6510         LOOP
6511             --
6512             -- Set all local variables to NULL
6513             l_personnel_office_id  := NULL;
6514             l_org_structure_id     := NULL;
6515             l_position_title       := NULL;
6516             l_position_number      := NULL;
6517             l_position_seq_no      := NULL;
6518             l_sub_element_code     := NULL;
6519             l_duty_station_id      := NULL;
6520             l_tenure               := NULL;
6521             l_annuitant_indicator  := NULL;
6522             l_pay_rate_determinant := NULL;
6523             l_work_schedule        := NULL;
6524             l_part_time_hour       := NULL;
6525             l_pay_plan             := NULL;
6526             l_pay_table_id         := NULL;
6527             l_grade_or_level       := NULL;
6528             l_step_or_rate         := NULL;
6529             l_pay_basis            := NULL;
6530             l_increase_percent     := NULL;
6531             l_elig_flag            := FALSE;
6532             --
6533             BEGIN
6534                 fetch_and_validate_emp_perc(
6535                                         p_action                => p_action
6536                                        ,p_mass_salary_id        => p_mass_salary_id
6537                                        ,p_mass_salary_name      => p_mass_salary
6538                                        ,p_full_name             => per.full_name
6539                                        ,p_national_identifier   => per.national_identifier
6540 				       --Bug # 9329643
6541 				       ,p_employee_number       => per.employee_number
6542                                        ,p_assignment_id         => per.assignment_id
6543                                        ,p_person_id             => per.person_id
6544                                        ,p_position_id           => per.position_id
6545                                        ,p_grade_id              => per.grade_id
6546                                        ,p_business_group_id     => per.business_group_id
6547                                        ,p_location_id           => per.location_id
6548                                        ,p_organization_id       => per.organization_id
6549                                        ,p_msl_organization_id    => l_p_organization_id
6550                                        ,p_msl_duty_station_id    => l_p_duty_station_id
6551                                        ,p_msl_personnel_office_id   => l_p_personnel_office_id
6552                                        ,p_msl_agency_code_subelement => l_p_agency_code_subelement
6553                                        ,p_msl_user_table_id         => l_user_table_id
6554                                        ,p_rec_pp_prd_per_gr         => rec_pp_prd_per_gr
6555                                        ,p_personnel_office_id   => l_personnel_office_id
6556                                        ,p_org_structure_id      => l_org_structure_id
6557                                        ,p_position_title        => l_position_title
6558                                        ,p_position_number       => l_position_number
6559                                        ,p_position_seq_no       => l_position_seq_no
6560                                        ,p_subelem_code          => l_sub_element_code
6561                                        ,p_duty_station_id       => l_duty_station_id
6562                                        ,p_tenure                => l_tenure
6563                                        ,p_annuitant_indicator   => l_annuitant_indicator
6564                                        ,p_pay_rate_determinant  => l_pay_rate_determinant
6565                                        ,p_work_schedule         => l_work_schedule
6566                                        ,p_part_time_hour        => l_part_time_hour
6567                                        ,p_pay_plan              => l_pay_plan
6568                                        ,p_pay_table_id          => l_pay_table_id
6569                                        ,p_grade_or_level        => l_grade_or_level
6570                                        ,p_step_or_rate          => l_step_or_rate
6571                                        ,p_pay_basis             => l_pay_basis
6572                                        ,p_increase_percent      => l_increase_percent
6573                                        ,p_elig_flag             => l_elig_flag
6574                                        );
6575                     EXCEPTION
6576                         --WHEN fetch_validate_error THEN
6577                           --  l_elig_flag := FALSE;
6578                         WHEN OTHERS THEN
6579                             l_elig_flag := FALSE;
6580                     END;
6581                     IF l_elig_flag THEN
6582 
6583                         msl_perc_process(
6584                                        p_assignment_id  => per.assignment_id
6585                                       ,p_person_id => per.person_id
6586                                       ,p_position_id  => per.position_id
6587                                       ,p_grade_id => per.grade_id
6588                                       ,p_business_group_id => per.business_group_id
6589                                       ,p_location_id => per.location_id
6590                                       ,p_organization_id => per.organization_id
6591                                       ,p_date_of_birth => per.date_of_birth
6592                                       ,p_first_name => per.first_name
6593                                       ,p_last_name => per.last_name
6594                                       ,p_full_name => per.full_name
6595                                       ,p_middle_names => per.middle_names
6596                                       ,p_national_identifier => per.national_identifier
6597 				      --Bug # 9329643
6598                                       ,p_employee_number => per.employee_number
6599                                       ,p_personnel_office_id   => l_personnel_office_id
6600                                       ,p_org_structure_id      => l_org_structure_id
6601                                       ,p_position_title        => l_position_title
6602                                       ,p_position_number       => l_position_number
6603                                       ,p_position_seq_no       => l_position_seq_no
6604                                       ,p_subelem_code          => l_sub_element_code
6605                                       ,p_duty_station_id       => l_duty_station_id
6606                                       ,p_tenure                => l_tenure
6607                                       ,p_annuitant_indicator   => l_annuitant_indicator
6608                                       ,p_pay_rate_determinant  => l_pay_rate_determinant
6609                                       ,p_work_schedule         => l_work_schedule
6610                                       ,p_part_time_hour        => l_part_time_hour
6611                                       ,p_pay_plan              => l_pay_plan
6612                                       ,p_pay_table_id          => l_pay_table_id
6613                                       ,p_grade_or_level        => l_grade_or_level
6614                                       ,p_step_or_rate          => l_step_or_rate
6615                                       ,p_pay_basis             => l_pay_basis
6616                                       ,p_increase_percent      => l_increase_percent
6617                                       );
6618                     END IF;
6619 
6620         END LOOP;
6621     END LOOP;
6622   END IF;
6623 
6624   pr('After processing is over ',to_char(l_recs_failed));
6625 /*
6626     if (l_recs_failed  < (l_msl_cnt  * (1/3))) then
6627 */
6628    if (l_recs_failed  = 0) then
6629      IF upper(p_action) = 'CREATE' THEN
6630        begin
6631           update ghr_mass_salaries
6632              set submit_flag = 'P'
6633            where rowid = l_rowid;
6634        EXCEPTION
6635          when others then
6636            HR_UTILITY.SET_LOCATION('Error in Update ghr_msl  Sql error '||sqlerrm(sqlcode),30);
6637            hr_utility.set_message(8301, 'GHR_38476_UPD_GHR_MSL_FAILURE');
6638            hr_utility.raise_error;
6639        END;
6640 -----Bug 2849262. Updating extra info to null is already done by Update_sel_flg in the main loop.
6641 -----             So it is not required to do in global if you see the procedure upd_ext_info_to_null
6642 -----             Commenting the following line. Dated 14-OCT-2003.
6643 -----
6644 -----  upd_ext_info_to_null(l_effective_date);
6645      end if;
6646   ELSE
6647 --if (l_recs_failed  <> 0) then
6648       p_errbuf   := 'Error in '||l_proc || ' Details in GHR_PROCESS_LOG';
6649       p_retcode  := 2;
6650       IF upper(p_action) = 'CREATE' THEN
6651          update ghr_mass_salaries
6652             set submit_flag = 'E'
6653           where rowid = l_rowid;
6654       END IF;
6655   end if;
6656 pr('Before commiting.....');
6657 COMMIT;
6658 pr('After commiting.....',to_char(l_recs_failed));
6659 
6660 EXCEPTION
6661     when others then
6662 --    raise_application_error(-20121,'Error in execute_msl_perc Err is '||sqlerrm(sqlcode));
6663       HR_UTILITY.SET_LOCATION('Error (Others2) occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),30);
6664       BEGIN
6665         ROLLBACK TO execute_msl_perc_SP;
6666       EXCEPTION
6667         WHEN OTHERS THEN NULL;
6668       END;
6669       l_log_text  := 'Error in '||l_proc||
6670                      ' For Mass Salary Name : '||p_mass_salary||
6671                      ' Sql Err is '||sqlerrm(sqlcode);
6672       l_recs_failed := l_recs_failed + 1;
6673       hr_utility.set_location('before creating entry in log file',30);
6674 
6675       p_errbuf   := 'Error in '||l_proc || ' Details in GHR_PROCESS_LOG';
6676       p_retcode  := 2;
6677       IF upper(p_action) = 'CREATE' THEN
6678          update ghr_mass_salaries
6679             set submit_flag = 'E'
6680           where rowid = l_rowid;
6681           commit;
6682       END IF;
6683 
6684       begin
6685          ghr_mto_int.log_message(
6686                         p_procedure => g_proc,
6687                         p_message   => l_log_text);
6688 
6689       exception
6690           when others then
6691               hr_utility.set_message(8301, 'Create Error Log failed');
6692               hr_utility.raise_error;
6693       end;
6694 
6695 END execute_msl_perc;
6696 -- 3843306
6697 -- END of MSL Percentage Changes
6698 -- This is same as Execute_msl except for few modifications
6699 --
6700 PROCEDURE set_ses_msl_process(ses_flag varchar2)
6701 IS
6702 BEGIN
6703 	ghr_msl_pkg.g_ses_msl_process := ses_flag;
6704 END set_ses_msl_process;
6705 
6706 -- Bug#5063304 Created this new procedure
6707 
6708 --5470182 -- For SES Relative Rate Range
6709 -- Bug#5063304 Created this new procedure
6710 PROCEDURE fetch_and_validate_emp_ses(
6711                               p_action              IN VARCHAR2
6712                              ,p_mass_salary_id      IN NUMBER
6713                              ,p_mass_salary_name    IN VARCHAR2
6714                              ,p_full_name           IN per_people_f.full_name%TYPE
6715 			     ,p_national_identifier IN per_people_f.national_identifier%TYPE
6716 			     ,p_employee_number     IN per_people_f.employee_number%TYPE
6717                              ,p_assignment_id       IN per_assignments_f.assignment_id%TYPE
6718 			     ,p_person_id           IN per_assignments_f.person_id%TYPE
6719 			     ,p_position_id                IN per_assignments_f.position_id%TYPE
6720 			     ,p_grade_id                   IN per_assignments_f.grade_id%TYPE
6721 			     ,p_business_group_id          IN per_assignments_f.business_group_iD%TYPE
6722 			     ,p_location_id                IN per_assignments_f.location_id%TYPE
6723 			     ,p_organization_id            IN per_assignments_f.organization_id%TYPE
6724                              ,p_msl_organization_id        IN per_assignments_f.organization_id%TYPE
6725                              ,p_msl_duty_station_id        IN ghr_duty_stations_f.duty_station_id%TYPE
6726                              ,p_msl_personnel_office_id    IN VARCHAR2
6727                              ,p_msl_agency_code_subelement IN VARCHAR2
6728                              ,p_msl_user_table_id          IN NUMBER
6729                              ,p_rec_pp_prd                 IN pp_prd
6730                              ,p_personnel_office_id        OUT NOCOPY VARCHAR2
6731                              ,p_org_structure_id           OUT NOCOPY VARCHAR2
6732                              ,p_position_title             OUT NOCOPY VARCHAR2
6733                              ,p_position_number            OUT NOCOPY VARCHAR2
6734                              ,p_position_seq_no            OUT NOCOPY VARCHAR2
6735                              ,p_subelem_code               OUT NOCOPY VARCHAR2
6736                              ,p_duty_station_id            OUT NOCOPY ghr_duty_stations_f.duty_station_id%TYPE
6737                              ,p_tenure                     OUT NOCOPY VARCHAR2
6738                              ,p_annuitant_indicator        OUT NOCOPY VARCHAR2
6739                              ,p_pay_rate_determinant       OUT NOCOPY VARCHAR2
6740                              ,p_work_schedule              OUT NOCOPY  VARCHAR2
6741                              ,p_part_time_hour             OUT NOCOPY VARCHAR2
6742                              ,p_to_grade_id                OUT NOCOPY per_assignments_f.grade_id%type
6743                              ,p_pay_plan                   OUT NOCOPY VARCHAR2
6744                              ,p_to_pay_plan                OUT NOCOPY VARCHAR2
6745                              ,p_pay_table_id               OUT NOCOPY NUMBER
6746                              ,p_grade_or_level         OUT NOCOPY VARCHAR2
6747                              ,p_to_grade_or_level   OUT NOCOPY VARCHAR2
6748                              ,p_step_or_rate        OUT NOCOPY VARCHAR2
6749                              ,p_pay_basis           OUT NOCOPY VARCHAR2
6750                              ,p_elig_flag           OUT NOCOPY BOOLEAN
6751 			                ) IS
6752 
6753 
6754 
6755     CURSOR msl_dtl_cur (cur_pay_plan varchar2, cur_prd varchar2) IS
6756     SELECT count(*) cnt
6757       FROM ghr_mass_salary_criteria
6758      WHERE mass_salary_id = p_mass_salary_id
6759        AND pay_plan = cur_pay_plan
6760        AND pay_rate_determinant = cur_prd;
6761 
6762     l_row_cnt               NUMBER := 0;
6763     l_pos_grp1_rec          per_position_extra_info%rowtype;
6764     l_assignment_id         per_assignments_f.assignment_id%TYPE;
6765     l_person_id             per_assignments_f.person_id%TYPE;
6766     l_position_id           per_assignments_f.position_id%TYPE;
6767     l_grade_id              per_assignments_f.grade_id%TYPE;
6768     l_business_group_id     per_assignments_f.business_group_iD%TYPE;
6769     l_location_id           per_assignments_f.location_id%TYPE;
6770     l_organization_id       per_assignments_f.organization_id%TYPE;
6771     l_tenure               VARCHAR2(35);
6772     l_annuitant_indicator  VARCHAR2(35);
6773     l_pay_rate_determinant VARCHAR2(35);
6774     l_work_schedule        VARCHAR2(35);
6775     l_part_time_hour       VARCHAR2(35);
6776     l_pay_table_id         NUMBER;
6777     l_pay_plan             VARCHAR2(30);
6778     l_grade_or_level       VARCHAR2(30);
6779     -- Bug#5089732 Added current pay plan, grade_or_level
6780     l_to_grade_id          NUMBER;
6781     l_to_pay_plan          VARCHAR2(30);
6782     l_to_grade_or_level    VARCHAR2(30);
6783     -- Bug#5089732
6784     l_step_or_rate         VARCHAR2(30);
6785     l_pay_basis            VARCHAR2(30);
6786     l_duty_station_id      NUMBER;
6787     l_duty_station_desc    ghr_pa_requests.duty_station_desc%type;
6788     l_duty_station_code    ghr_pa_requests.duty_station_code%type;
6789     l_effective_date       DATE;
6790     l_personnel_office_id  VARCHAR2(300);
6791     l_org_structure_id     VARCHAR2(300);
6792     l_sub_element_code     VARCHAR2(300);
6793     l_position_title       VARCHAR2(300);
6794     l_position_number      VARCHAR2(20);
6795     l_position_seq_no      VARCHAR2(20);
6796     l_log_text             VARCHAR2(2000) := null;
6797     l_retained_grade_rec  ghr_pay_calc.retained_grade_rec_type;
6798     l_fetch_poid_data       BOOLEAN := FALSE;
6799     l_fetch_ds_data         BOOLEAN := FALSE;
6800     l_fetch_agency_data     BOOLEAN := FALSE;
6801     init_elig_flag          BOOLEAN := FALSE;
6802     l_prd_matched           BOOLEAN := FALSE;
6803     l_prd_pp_matched        BOOLEAN := FALSE;
6804     l_rat_matched           BOOLEAN := FALSE;
6805 
6806 
6807     --5470182
6808      l_special_info_type                    ghr_api.special_information_type;
6809 
6810 
6811 
6812     l_proc   varchar2(72) :=  g_package || '.fetch_and_validate_emp_ses';
6813 
6814 BEGIN
6815 
6816     g_proc  := 'fetch_and_validate_emp_ses';
6817     hr_utility.set_location('Entering    ' || l_proc,5);
6818 
6819     -- Bug#5623035 Moved the local variable assigning to here.
6820     l_assignment_id     := p_assignment_id;
6821     l_position_id       := p_position_id;
6822     l_grade_id          := p_grade_id;
6823     l_business_group_id := p_business_group_iD;
6824     l_location_id       := p_location_id;
6825     l_effective_date    := g_effective_date;
6826 
6827     -- Verify whether this process is required or not.
6828     IF p_msl_organization_id IS NOT NULL  OR
6829        p_msl_duty_station_id IS NOT NULL  OR
6830        p_msl_personnel_office_id IS NOT NULL  OR
6831        p_msl_agency_code_subelement IS NOT NULL THEN
6832         -- get the values and verify whether the record meets the condition or not.
6833         -- If Yes, proceed further. Otherwise, skip the other checks for this record
6834 
6835         hr_utility.set_location('The location id is:'||l_location_id,12345);
6836         hr_utility.set_location('MSL Org ID:'||p_msl_organization_id,11111);
6837         hr_utility.set_location('Org ID:'||p_organization_id,22222);
6838         IF NVL(p_msl_organization_id,p_organization_id) = p_organization_id THEN
6839             hr_utility.set_location('Org ID PASS',10);
6840             IF p_msl_personnel_office_id IS NOT NULL THEN
6841                 hr_utility.set_location('POID CHECK',15);
6842                 get_pos_grp1_ddf(l_position_id,
6843                                  l_effective_date,
6844                                  l_pos_grp1_rec);
6845 
6846                 l_personnel_office_id :=  l_pos_grp1_rec.poei_information3;
6847                 l_org_structure_id    :=  l_pos_grp1_rec.poei_information5;
6848                 l_fetch_poid_data := TRUE;
6849             END IF;
6850             IF  (p_msl_personnel_office_id = l_personnel_office_id) OR
6851                 NOT(l_fetch_poid_data) THEN
6852 
6853 	    hr_utility.set_location('POID PASS',20);
6854                 IF p_msl_agency_code_subelement IS NOT NULL THEN
6855                     hr_utility.set_location('Agency CHECK',25);
6856                     get_sub_element_code_pos_title(l_position_id,
6857                                              p_person_id,
6858                                              l_business_group_id,
6859                                              l_assignment_id,
6860                                              l_effective_date,
6861                                              l_sub_element_code,
6862                                              l_position_title,
6863                                              l_position_number,
6864                                              l_position_seq_no);
6865                     l_fetch_agency_data := TRUE;
6866                 END IF;
6867                 -- Bug#5674003 Modified the following IF condition
6868                 IF  (SUBSTR(p_msl_agency_code_subelement,1,2)  = SUBSTR(l_sub_element_code,1,2) AND
6869                      NVL(SUBSTR(p_msl_agency_code_subelement,3,2),SUBSTR(l_sub_element_code,3,2))=
6870                          SUBSTR(l_sub_element_code,3,2)
6871                     ) OR
6872                     NOT(l_fetch_agency_data) THEN
6873                                     hr_utility.set_location('Agency PASS',30);
6874                     IF p_msl_duty_station_id IS NOT NULL THEN
6875                         hr_utility.set_location('DS CHECK',35);
6876                         ghr_pa_requests_pkg.get_SF52_loc_ddf_details
6877                         (p_location_id      => l_location_id
6878                         ,p_duty_station_id  => l_duty_station_id);
6879                         l_fetch_ds_data := TRUE;
6880                     END IF;
6881                     IF (p_msl_duty_station_id = l_duty_station_id) OR
6882                        NOT(l_fetch_ds_data)THEN
6883                        hr_utility.set_location('DS PASS',40);
6884                         init_elig_flag := TRUE;
6885                     ELSE -- Duty Station not matching.
6886                        hr_utility.set_location('DS FAIL',45);
6887                         init_elig_flag := FALSE;
6888                     END IF;
6889                 ELSE -- Agency Code Subelement Not matching.
6890                     hr_utility.set_location('Agency FAIL',55);
6891                     init_elig_flag := FALSE;
6892                 END IF;
6893             ELSE -- Personnel Office ID not matching
6894                 hr_utility.set_location('POID FAIL',65);
6895                 init_elig_flag := FALSE;
6896             END IF;
6897         ELSE -- Organization_id is not matching.
6898             hr_utility.set_location('Org FAIL',75);
6899             init_elig_flag := FALSE;
6900         END IF;
6901     ELSE  -- If No value is entered for organization, Duty Station, Agency, POID of MSL Criteria.
6902        hr_utility.set_location('No INIT CRITERIA',85);
6903         init_elig_flag := TRUE;
6904     END IF;
6905 
6906     -- If the initial eligibility is passed then proceed further. Otherwise move to next record.
6907     IF init_elig_flag THEN
6908         hr_utility.set_location('Init Criteria Pass',95);
6909         ghr_pa_requests_pkg.get_sf52_asg_ddf_details
6910                                   (l_assignment_id,
6911                                    l_effective_date,
6912                                    l_tenure,
6913                                    l_annuitant_indicator,
6914                                    l_pay_rate_determinant,
6915                                    l_work_schedule,
6916                                    l_part_time_hour);
6917 
6918         FOR l_cnt in 1..p_rec_pp_prd.COUNT LOOP
6919            IF nvl(p_rec_pp_prd(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant THEN
6920                 hr_utility.set_location('PRD PASS',105);
6921                 l_prd_matched := TRUE;
6922                 exit;
6923            END IF;
6924         END LOOP;
6925 
6926         IF l_prd_matched THEN
6927             -- Bug#5089732 Used the overloaded procedure.
6928             BEGIN
6929                 get_pay_plan_and_table_id
6930                       (l_pay_rate_determinant,p_person_id,
6931                        l_position_id,l_effective_date,
6932                        l_grade_id, l_to_grade_id,l_assignment_id,'SHOW',
6933                        l_pay_plan,l_to_pay_plan,l_pay_table_id,
6934                        l_grade_or_level, l_to_grade_or_level, l_step_or_rate,
6935                        l_pay_basis);
6936             -- Bug#4016384 Added the exception handling to report RG employees in the process log.
6937             EXCEPTION
6938                 WHEN OTHERS THEN
6939                     -- Report the record in the process log if the pay table ID matches.
6940                     BEGIN
6941                         hr_utility.set_location('before calling expired_rg_det',10);
6942                         l_retained_grade_rec := ghr_pc_basic_pay.get_expired_rg_details
6943                                                   (p_person_id => p_person_id
6944                                                   ,p_effective_date => l_effective_date);
6945                         hr_utility.set_location('ret grd tableid:'||l_retained_grade_rec.user_table_id,99999);
6946                         hr_utility.set_location('MSL tableid:'||p_msl_user_table_id,99999);
6947                         IF l_retained_grade_rec.user_table_id = p_msl_user_table_id THEN
6948                             hr_utility.set_location('Rg table matches with MSL table ID',10);
6949 			    	  --Bug # 9329643 Modified SSN to Emp No
6950                             l_log_text  := 'Error in RG Record In Mass Salary Name: '||
6951                                             p_mass_salary_name||'; Employee Name: '|| p_full_name ||
6952                                             '; Emp No: ' || p_employee_number || '; '||
6953                                             hr_utility.get_message;
6954                             BEGIN
6955                                 ghr_mto_int.log_message(
6956                                       p_procedure => 'check_grade_retention',
6957                                       p_message   => l_log_text);
6958                                 g_rg_recs_failed := g_rg_recs_failed + 1;
6959                             EXCEPTION
6960                                 WHEN OTHERS THEN
6961                                    l_prd_pp_matched := FALSE;
6962                             END;
6963                         ELSE
6964                             l_prd_pp_matched := FALSE;
6965                         END IF;
6966                     EXCEPTION
6967                         WHEN OTHERS THEN
6968                             hr_utility.set_location('WHEN OTHERS of EXPIRED RG ',999999);
6969                             l_prd_pp_matched := FALSE;
6970                     END;
6971                 --WHEN OTHERS THEN
6972                     -- Skip this record from reporting.
6973                    -- l_prd_pp_matched := FALSE;
6974             END;
6975         END IF;
6976 
6977         FOR l_cnt in 1..p_rec_pp_prd.COUNT LOOP
6978            IF nvl(p_rec_pp_prd(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant AND
6979               nvl(p_rec_pp_prd(l_cnt).pay_plan,l_pay_plan) = l_pay_plan THEN
6980                 hr_utility.set_location('PP/PRD PASS',115);
6981                 l_prd_pp_matched := TRUE;
6982                 exit;
6983            END IF;
6984         END LOOP;
6985 
6986 
6987 	--5470182
6988 	IF l_prd_pp_matched AND l_pay_table_id = p_msl_user_table_id THEN
6989             ghr_history_fetch.return_special_information
6990                         (p_person_id         =>  p_person_id,
6991                          p_structure_name    =>  'US Fed Perf Appraisal',
6992                          p_effective_date    =>  l_effective_date,
6993                          p_special_info      =>  l_special_info_type
6994                         );
6995 
6996            -- BUG #6528698 Appraisal effective date need to be considered instead of Appraisal start date
6997              /* Rating of Record Level must be within 12 months*/
6998              IF l_effective_date between fnd_date.canonical_to_date(l_special_info_type.segment3)
6999 	                        and     ADD_MONTHS(fnd_date.canonical_to_date(l_special_info_type.segment3),12) THEN
7000                /*Rating of Record Level must be '3','4' '5' or Rating of Record
7001 	         must be 'E','F' or 'O'*/
7002               IF l_special_info_type.segment5 in ('3','4','5')
7003 	         OR
7004                  l_special_info_type.segment2 in ('E','F','O') THEN
7005 	         l_rat_matched :=TRUE;
7006 
7007    	      END IF; -- rating of recor level comp
7008              END IF; -- rating of record level with in 12 months
7009 	    END IF;  -- prd and payplan matched and user table id matched
7010 	    --5470182
7011 
7012         IF l_rat_matched THEN
7013             IF l_pay_table_id = p_msl_user_table_id THEN
7014                 hr_utility.set_location('Table ID PASS',125);
7015                 IF NOT (p_action = 'CREATE' AND
7016                             person_in_pa_req_1noa
7017                               (p_person_id      => p_person_id,
7018                                p_effective_date => l_effective_date,
7019                                p_first_noa_code => nvl(g_first_noa_code,'890'),
7020                                p_pay_plan       => p_pay_plan
7021                                )
7022                        )THEN
7023                      -- Pass l_pay_plan instead of l_to_pay_plan.
7024                      FOR msl_dtl IN msl_dtl_cur(l_pay_plan, l_pay_rate_determinant)
7025                      LOOP
7026                         IF msl_dtl.cnt <> 0 THEN
7027                         l_row_cnt := msl_dtl.cnt;
7028                         END IF;
7029                      END LOOP;
7030 
7031                     IF l_row_cnt <> 0 THEN
7032                         hr_utility.set_location('ROW COUNT PASS',135);
7033                         -- Get the required details if the related check has not been done above.
7034                         IF NOT l_fetch_poid_data THEN
7035 
7036                             get_pos_grp1_ddf(l_position_id,
7037                                              l_effective_date,
7038                                              l_pos_grp1_rec);
7039                         END IF;
7040 
7041                         IF NOT l_fetch_ds_data THEN
7042                             ghr_pa_requests_pkg.get_SF52_loc_ddf_details
7043                                         (p_location_id      => l_location_id
7044                                         ,p_duty_station_id  => l_duty_station_id);
7045                         END IF;
7046 
7047                         IF NOT l_fetch_agency_data THEN
7048                             get_sub_element_code_pos_title(
7049                                                          l_position_id,
7050                                                          p_person_id,
7051                                                          l_business_group_id,
7052                                                          l_assignment_id,
7053                                                          l_effective_date,
7054                                                          l_sub_element_code,
7055                                                          l_position_title,
7056                                                          l_position_number,
7057                                                          l_position_seq_no
7058                                                          );
7059                         END IF;
7060 
7061                         -- Set all the out parameters
7062                         p_elig_flag := TRUE;
7063                         p_personnel_office_id  := l_personnel_office_id;
7064                         p_org_structure_id     := l_org_structure_id;
7065                         p_position_title       := l_position_title;
7066                         p_position_number      := l_position_number;
7067                         p_position_seq_no      := l_position_seq_no;
7068                         p_subelem_code         := l_sub_element_code;
7069                         p_duty_station_id      := l_duty_station_id;
7070                         p_tenure               := l_tenure;
7071                         p_annuitant_indicator  := l_annuitant_indicator;
7072                         p_pay_rate_determinant := l_pay_rate_determinant;
7073                         p_work_schedule        := l_work_schedule;
7074                         p_part_time_hour       := l_part_time_hour;
7075                         p_to_grade_id          := l_to_grade_id;
7076                         p_pay_plan             := l_pay_plan;
7077                         p_to_pay_plan          := l_to_pay_plan;
7078                         p_pay_table_id         := l_pay_table_id;
7079                         p_grade_or_level       := l_grade_or_level;
7080                         p_to_grade_or_level    := l_to_grade_or_level;
7081                         p_step_or_rate         := l_step_or_rate;
7082                         p_pay_basis            := l_pay_basis;
7083                     ELSE -- If PP,PRD combinations are "0".
7084                         -- Raise Error
7085                         NULL;
7086                     END IF;
7087                 ELSE -- Not (Create and RPA exists)
7088                     hr_utility.set_location('ROW COUNT FAIL',145);
7089                     p_elig_flag := FALSE;
7090                 END IF;
7091             ELSE -- Pay table id is not matched
7092                 hr_utility.set_location('Pay Table FAIL',155);
7093                 p_elig_flag := FALSE;
7094             END IF;
7095         ELSE  -- Pay Plan and PRD not matched
7096             hr_utility.set_location('PP/PRD FAIL',165);
7097             p_elig_flag := FALSE;
7098         END IF;
7099     ELSE
7100         hr_utility.set_location('PP FAIL',175);
7101         p_elig_flag := FALSE;
7102     END IF;
7103 EXCEPTION
7104     WHEN others THEN
7105         hr_utility.set_location('WHEN OTHERS',185);
7106         RAISE;
7107 END fetch_and_validate_emp_ses;
7108 
7109 PROCEDURE execute_msl_ses_range (p_errbuf out nocopy varchar2,
7110                                  p_retcode out nocopy number,
7111                                  p_mass_salary_id in number,
7112                                  p_action in varchar2) is
7113 
7114 p_mass_salary varchar2(32);
7115 
7116 --
7117 --
7118 -- Main Cursor which fetches from per_assignments_f and per_people_f
7119 --
7120 --
7121 --1. Cursor with organization.
7122 ---
7123 cursor cur_people_org (effective_date date, p_org_id number) is
7124 select ppf.person_id                 PERSON_ID,
7125        ppf.first_name                FIRST_NAME,
7126        ppf.last_name                 LAST_NAME,
7127        ppf.middle_names              MIDDLE_NAMES,
7128        ppf.full_name                 FULL_NAME,
7129        ppf.date_of_birth             DATE_OF_BIRTH,
7130        ppf.national_identifier       NATIONAL_IDENTIFIER,
7131        --Bug # 9329643
7132        ppf.employee_number           EMPLOYEE_NUMBER,
7133        paf.position_id               POSITION_ID,
7134        paf.assignment_id             ASSIGNMENT_ID,
7135        paf.grade_id                  GRADE_ID,
7136        paf.job_id                    JOB_ID,
7137        paf.location_id               LOCATION_ID,
7138        paf.organization_id           ORGANIZATION_ID,
7139        paf.business_group_id         BUSINESS_GROUP_ID,
7140        paf.assignment_status_type_id ASSIGNMENT_STATUS_TYPE_ID
7141   from per_assignments_f   paf,
7142        per_people_f        ppf,
7143        per_person_types    ppt
7144  where ppf.person_id           = paf.person_id
7145    and effective_date between ppf.effective_start_date and ppf.effective_end_date
7146    and effective_date between paf.effective_start_date and paf.effective_end_date
7147    and paf.primary_flag        = 'Y'
7148    and paf.assignment_type     <> 'B'
7149    and ppf.person_type_id      = ppt.person_type_id
7150    and ppt.system_person_type  IN ('EMP','EMP_APL')
7151    and paf.organization_id     = p_org_id
7152    and paf.position_id is not null
7153    order by ppf.person_id;
7154 
7155 ---
7156 --- Bug  3539816 Order by added to prevent snapshot old error
7157 --- 2. Cursor with no organization.
7158 ---
7159 cursor cur_people (effective_date date) is
7160 select ppf.person_id                 PERSON_ID,
7161        ppf.first_name                FIRST_NAME,
7162        ppf.last_name                 LAST_NAME,
7163        ppf.middle_names              MIDDLE_NAMES,
7164        ppf.full_name                 FULL_NAME,
7165        ppf.date_of_birth             DATE_OF_BIRTH,
7166        ppf.national_identifier       NATIONAL_IDENTIFIER,
7167        --Bug # 9329643
7168        ppf.employee_number           EMPLOYEE_NUMBER,
7169        paf.position_id               POSITION_ID,
7170        paf.assignment_id             ASSIGNMENT_ID,
7171        paf.grade_id                  GRADE_ID,
7172        paf.job_id                    JOB_ID,
7173        paf.location_id               LOCATION_ID,
7174        paf.organization_id           ORGANIZATION_ID,
7175        paf.business_group_id         BUSINESS_GROUP_ID,
7176        paf.assignment_status_type_id ASSIGNMENT_STATUS_TYPE_ID
7177   from per_assignments_f   paf,
7178        per_people_f        ppf,
7179        per_person_types    ppt,
7180        hr_organization_units hou
7181  where ppf.person_id           = paf.person_id
7182    and effective_date between ppf.effective_start_date and ppf.effective_end_date
7183    and effective_date between paf.effective_start_date and paf.effective_end_date
7184    and paf.primary_flag        = 'Y'
7185    and paf.assignment_type     <> 'B'
7186    and ppf.person_type_id      = ppt.person_type_id
7187    and ppt.system_person_type  IN ('EMP','EMP_APL')
7188    and paf.organization_id     = hou.organization_id
7189    and paf.position_id is not null
7190    order by ppf.person_id;
7191 --
7192 -- Check assignment_status_type
7193 --
7194 
7195 cursor cur_ast (asg_status_type_id number)
7196     is
7197     select user_status
7198     from per_assignment_status_types
7199     where assignment_status_type_id = asg_status_type_id
7200   and upper(user_status) not in (
7201                          'TERMINATE ASSIGNMENT',           /* 3 */
7202                          'ACTIVE APPLICATION',             /* 4 */
7203                          'OFFER',                          /* 5 */
7204                          'ACCEPTED',                       /* 6 */
7205                          'TERMINATE APPLICATION',          /* 7 */
7206                          'END',                            /* 8 */
7207                          'TERMINATE APPOINTMENT',          /* 126 */
7208                          'SEPARATED');                     /* 132 */
7209 
7210 --
7211 -- Cursor to select from GHR_MASS_SALARIES - Where criteria is stored
7212 -- Before executing this package
7213 -- from ghr_mass_salary_criteria
7214 
7215 cursor ghr_msl (p_msl_id number) is
7216 select name, effective_date, mass_salary_id, user_table_id, submit_flag,
7217        executive_order_number, executive_order_date, ROWID, PA_REQUEST_ID,
7218        ORGANIZATION_ID, DUTY_STATION_ID, PERSONNEL_OFFICE_ID,
7219        AGENCY_CODE_SUBELEMENT, OPM_ISSUANCE_NUMBER, OPM_ISSUANCE_DATE, PROCESS_TYPE
7220   from ghr_mass_salaries
7221  where MASS_SALARY_ID = p_msl_id
7222    for update of user_table_id nowait;
7223 
7224 -- VSM [family name was hardcoded previously to SALARY_CHG. Fetching it from DB now]
7225 cursor get_sal_chg_fam is
7226 select NOA_FAMILY_CODE
7227 from ghr_families
7228 where NOA_FAMILY_CODE in
7229     (select NOA_FAMILY_CODE from ghr_noa_families
7230          where  nature_of_action_id =
7231             (select nature_of_action_id
7232              from ghr_nature_of_actions
7233              where code = '890')
7234     ) and proc_method_flag = 'Y';    --AVR 13-JAN-99
7235  -------------   ) and update_hr_flag = 'Y';
7236 
7237 l_assignment_id        per_assignments_f.assignment_id%type;
7238 l_position_id          per_assignments_f.position_id%type;
7239 l_grade_id             per_assignments_f.grade_id%type;
7240 l_business_group_id    per_assignments_f.business_group_id%type;
7241 
7242 l_position_title       varchar2(300);
7243 l_position_number      varchar2(20);
7244 l_position_seq_no      varchar2(20);
7245 
7246 l_msl_cnt              number := 0;
7247 l_recs_failed          number := 0;
7248 
7249 l_tenure               varchar2(35);
7250 l_annuitant_indicator  varchar2(35);
7251 l_pay_rate_determinant varchar2(35);
7252 l_work_schedule        varchar2(35);
7253 l_part_time_hour       varchar2(35);
7254 l_pay_table_id         number;
7255 l_pay_plan             varchar2(30);
7256 l_grade_or_level       varchar2(30);
7257 l_step_or_rate         varchar2(30);
7258 l_pay_basis            varchar2(30);
7259 l_location_id          number;
7260 l_duty_station_id      number;
7261 l_duty_station_desc    ghr_pa_requests.duty_station_desc%type;
7262 l_duty_station_code    ghr_pa_requests.duty_station_code%type;
7263 l_effective_date       date;
7264 l_personnel_office_id  varchar2(300);
7265 l_org_structure_id     varchar2(300);
7266 l_sub_element_code     varchar2(300);
7267 
7268 l_old_basic_pay        number;
7269 l_old_avail_pay        number;
7270 l_old_loc_diff         number;
7271 l_tot_old_sal          number;
7272 l_old_auo_pay          number;
7273 l_old_ADJ_basic_pay    number;
7274 l_other_pay            number;
7275 
7276 l_out_step_or_rate          varchar2(30);
7277 l_out_pay_rate_determinant  varchar2(30);
7278 l_out_pay_plan              varchar2(30);
7279 l_out_grade_id              number;
7280 l_out_grade_or_level        varchar2(30);
7281 
7282 
7283 l_auo_premium_pay_indicator     varchar2(30);
7284 l_ap_premium_pay_indicator      varchar2(30);
7285 l_retention_allowance           number;
7286 l_retention_allow_perc          number;     ---AVR
7287 l_new_retention_allowance       number;     ---AVR
7288 l_supervisory_differential      number;
7289 l_supervisory_diff_perc         number;     ---AVR
7290 l_new_supervisory_differential  number;     ---AVR
7291 l_staffing_differential         number;
7292 
7293 l_new_avail_pay             number;
7294 l_new_loc_diff              number;
7295 l_tot_new_sal               number;
7296 l_new_auo_pay               number;
7297 
7298 l_new_basic_pay             number;
7299 l_new_locality_adj          number;
7300 l_new_adj_basic_pay         number;
7301 l_new_total_salary          number;
7302 l_new_other_pay_amount      number;
7303 l_new_au_overtime           number;
7304 l_new_availability_pay      number;
7305 
7306 l_open_pay_fields           boolean;
7307 l_message_set               boolean;
7308 l_calculated                boolean;
7309 
7310 l_mass_salary_id            number;
7311 l_user_table_id             number;
7312 l_submit_flag               varchar2(2);
7313 
7314 l_executive_order_number    ghr_mass_salaries.executive_order_number%TYPE;
7315 l_executive_order_date      ghr_mass_salaries.executive_order_date%TYPE;
7316 l_opm_issuance_number       ghr_mass_salaries.opm_issuance_number%TYPE;
7317 l_opm_issuance_date         ghr_mass_salaries.opm_issuance_date%TYPE;
7318 l_pa_request_id             number;
7319 l_rowid                     varchar2(30);
7320 
7321 l_p_ORGANIZATION_ID           number;
7322 l_p_DUTY_STATION_ID           number;
7323 l_p_PERSONNEL_OFFICE_ID       varchar2(5);
7324 
7325 L_row_cnt                   number := 0;
7326 
7327 l_sf52_rec                  ghr_pa_requests%rowtype;
7328 l_lac_sf52_rec              ghr_pa_requests%rowtype;
7329 l_errbuf                    varchar2(2000);
7330 
7331 l_retcode                   number;
7332 
7333 l_pos_ei_data               per_position_extra_info%rowtype;
7334 l_pos_grp1_rec              per_position_extra_info%rowtype;
7335 
7336 l_pay_calc_in_data          ghr_pay_calc.pay_calc_in_rec_type;
7337 l_pay_calc_out_data         ghr_pay_calc.pay_calc_out_rec_type;
7338 l_sel_flg                   varchar2(2);
7339 
7340 l_first_action_la_code1     varchar2(30);
7341 l_first_action_la_code2     varchar2(30);
7342 
7343 l_remark_code1              varchar2(30);
7344 l_remark_code2              varchar2(30);
7345 l_p_AGENCY_CODE_SUBELEMENT       varchar2(30);
7346 
7347 ----Pay cap variables
7348 l_entitled_other_pay        NUMBER;
7349 l_capped_other_pay          NUMBER;
7350 l_adj_basic_message         BOOLEAN  := FALSE;
7351 l_pay_cap_message           BOOLEAN  := FALSE;
7352 l_temp_retention_allowance  NUMBER;
7353 l_open_pay_fields_caps      BOOLEAN;
7354 l_message_set_caps          BOOLEAN;
7355 l_total_pay_check           VARCHAR2(1);
7356 l_comment                   VARCHAR2(150);
7357 l_comment_sal               VARCHAR2(150);
7358 l_pay_sel                   VARCHAR2(1) := NULL;
7359 l_old_capped_other_pay     NUMBER;
7360 ----
7361 l_row_low NUMBER;
7362 l_row_high NUMBER;
7363 l_comment_range VARCHAR2(150);
7364 l_comments      VARCHAR2(150);
7365 
7366 -- Bug#5089732 Added current pay plan, grade_or_level
7367 l_to_grade_id          per_assignments_f.grade_id%type;
7368 l_to_pay_plan          varchar2(30);
7369 l_to_grade_or_level    varchar2(30);
7370 -- Bug#5089732
7371 
7372 REC_BUSY                    exception;
7373 pragma exception_init(REC_BUSY,-54);
7374 
7375 l_proc  varchar2(72) :=  g_package || '.execute_msl_ses_range';
7376 
7377 cursor c_pay_tab_essl is
7378   select 1 from pay_user_tables
7379   where substr(user_table_name,1,4) = 'ESSL'
7380   and user_table_id = l_user_table_id;
7381 
7382 l_essl_table  BOOLEAN := FALSE;
7383 l_org_name	hr_organization_units.name%type;
7384 
7385 CURSOR cur_pp_prd(p_msl_id ghr_mass_salary_criteria.mass_salary_id%type)
7386 IS
7387 SELECT pay_plan ,pay_rate_determinant prd
7388 FROM   ghr_mass_salary_criteria
7389 WHERE  mass_salary_id=p_msl_id;
7390 
7391 rec_pp_prd   pp_prd;
7392 
7393 l_index         NUMBER:=1;
7394 l_cnt           NUMBER;
7395 l_elig_flag        BOOLEAN := FALSE;
7396 --
7397 
7398 --
7399 -- GPPA Update 46
7400 --
7401 cursor cur_eq_ppl (c_pay_plan ghr_pay_plans.pay_plan%type)
7402 IS
7403 select EQUIVALENT_PAY_PLAN
7404 from ghr_pay_plans
7405 where pay_plan = c_pay_plan;
7406 
7407 l_eq_pay_plan ghr_pay_plans.equivalent_pay_plaN%type;
7408 l_ses_basic_pay ghr_mass_actions_preview.to_basic_pay%type;
7409 
7410 
7411 PROCEDURE msl_ses_process(p_assignment_id  per_assignments_f.assignment_id%TYPE
7412 		     ,p_person_id per_assignments_f.person_id%TYPE
7413 		     ,p_position_id  per_assignments_f.position_id%TYPE
7414 		     ,p_grade_id per_assignments_f.grade_id%TYPE
7415 		     ,p_business_group_id per_assignments_f.business_group_iD%TYPE
7416 		     ,p_location_id per_assignments_f.location_id%TYPE
7417 		     ,p_organization_id per_assignments_f.organization_id%TYPE
7418 		     ,p_date_of_birth date
7419 		     ,p_first_name per_people_f.first_name%TYPE
7420 		     ,p_last_name per_people_f.last_name%TYPE
7421                      ,p_full_name per_people_f.full_name%TYPE
7422                              ,p_middle_names per_people_f.middle_names%TYPE
7423 							 ,p_national_identifier per_people_f.national_identifier%TYPE
7424 							 --Bug # 9329643
7425 							 ,p_employee_number per_people_f.employee_number%TYPE
7426                              ,p_personnel_office_id IN VARCHAR2
7427                              ,p_org_structure_id    IN VARCHAR2
7428                              ,p_position_title      IN VARCHAR2
7429                              ,p_position_number     IN VARCHAR2
7430                              ,p_position_seq_no     IN VARCHAR2
7431                              ,p_subelem_code        IN VARCHAR2
7432                              ,p_duty_station_id     IN ghr_duty_stations_f.duty_station_id%TYPE
7433                              ,p_tenure              IN VARCHAR2
7434                              ,p_annuitant_indicator IN VARCHAR2
7435                              ,p_pay_rate_determinant IN VARCHAR2
7436                              ,p_work_schedule       IN  VARCHAR2
7437                              ,p_part_time_hour      IN VARCHAR2
7438                              ,p_to_grade_id         IN per_assignments_f.grade_id%type
7439                              ,p_pay_plan            IN VARCHAR2
7440                              ,p_to_pay_plan         IN VARCHAR2
7441                              ,p_pay_table_id        IN NUMBER
7442                              ,p_grade_or_level      IN VARCHAR2
7443                              ,p_to_grade_or_level   IN VARCHAR2
7444                              ,p_step_or_rate        IN VARCHAR2
7445                              ,p_pay_basis           IN VARCHAR2
7446 							)	IS
7447         -- Bug3437354
7448         CURSOR cur_valid_DS(p_ds_id NUMBER)
7449             IS
7450             SELECT effective_end_date  end_date
7451             FROM   ghr_duty_stations_f
7452             WHERE  duty_station_id=p_ds_id
7453             AND    g_effective_date between effective_start_date and effective_end_date;
7454 
7455             l_ds_end_date	  ghr_duty_stations_f.effective_end_date%type;
7456 
7457 BEGIN
7458       savepoint execute_msl_sp;
7459          l_msl_cnt := l_msl_cnt +1;
7460 	 --Bug#3968005 Initialised l_sel_flg
7461          l_sel_flg := NULL;
7462          l_pay_calc_in_data  := NULL;
7463          l_pay_calc_out_data := NULL;
7464 
7465        l_assignment_id     := p_assignment_id;
7466        l_position_id       := p_position_id;
7467        l_grade_id          := p_grade_id;
7468        l_business_group_id := p_business_group_iD;
7469        l_location_id       := p_location_id;
7470        -- Bug#5063304
7471         l_personnel_office_id  := p_personnel_office_id;
7472         l_org_structure_id     := p_org_structure_id;
7473         l_position_title       := p_position_title;
7474         l_position_number      := p_position_number;
7475         l_position_seq_no      := p_position_seq_no;
7476         l_sub_element_code     := p_subelem_code;
7477         l_duty_station_id      := p_duty_station_id;
7478         l_tenure               := p_tenure;
7479         l_annuitant_indicator  := p_annuitant_indicator;
7480         l_pay_rate_determinant := p_pay_rate_determinant;
7481         l_work_schedule        := P_work_schedule;
7482         l_part_time_hour       := p_part_time_hour;
7483         l_to_grade_id          := p_to_grade_id;
7484         l_pay_plan             := p_pay_plan;
7485         l_to_pay_plan          := p_to_pay_plan;
7486         l_pay_table_id         := p_pay_table_id;
7487         l_grade_or_level       := p_grade_or_level;
7488         l_to_grade_or_level    := p_to_grade_or_level;
7489         l_step_or_rate         := P_step_or_rate;
7490         l_pay_basis            := p_pay_basis;
7491 	    hr_utility.set_location('The location id is:'||l_location_id,1);
7492  /*5470182 need to be commented
7493 --------GPPA Update 46 start
7494             ghr_msl_pkg.g_first_noa_code := NULL;
7495             FOR cur_eq_ppl_rec IN cur_eq_ppl(l_pay_plan)
7496             LOOP
7497                 l_eq_pay_plan   := cur_eq_ppl_rec.EQUIVALENT_PAY_PLAN;
7498                 exit;
7499             END LOOP;
7500             if l_effective_date >= to_date('2007/01/07','YYYY/MM/DD') AND
7501                l_eq_pay_plan = 'GS' AND
7502                l_lac_sf52_rec.first_action_la_code1 = 'QLP' AND
7503                l_lac_sf52_rec.first_action_la_code2 = 'ZLM' THEN
7504 
7505                ghr_msl_pkg.g_first_noa_code := '890';
7506 
7507             end if;
7508             if l_effective_date >= to_date('2007/01/07','YYYY/MM/DD') AND
7509                l_eq_pay_plan = 'FW' AND
7510                l_lac_sf52_rec.first_action_la_code1 = 'RJR' THEN
7511 
7512                ghr_msl_pkg.g_first_noa_code := '890';
7513 
7514             end if;
7515 --------GPPA Update 46 end */
7516 
7517 --5470182
7518        ghr_msl_pkg.g_first_noa_code := '890';
7519        l_lac_sf52_rec.first_action_la_code1 := 'Q3C';
7520 --       l_lac_sf52_rec.first_action_la_desc1 := 'Reg. 534.404(h)';
7521        l_lac_sf52_rec.first_action_la_desc1 := ghr_pa_requests_pkg.get_lookup_description(800,'GHR_US_LEGAL_AUTHORITY','Q3C');
7522 
7523         g_proc := 'Location Validation';
7524         -- Start of Bug3437354
7525         IF l_location_id IS NULL THEN
7526             l_mslerrbuf := ' Error: No valid Location found, salary cannot be calculated correctly'||
7527                                ' without the employee''s duty location. ';
7528                 RAISE msl_error;
7529         END IF;
7530 
7531         g_proc := 'Duty Station Validation';
7532         IF l_duty_station_id IS NOT NULL THEN
7533 
7534             --
7535             -- Added this condition for bug 3437354, error out the record without valid Loc id
7536             --
7537             FOR rec_ds in cur_valid_ds(l_duty_station_id)
7538             LOOP
7539                 l_ds_end_date	:= rec_ds.end_Date;
7540             END LOOP;
7541             IF l_ds_end_date IS NULL THEN
7542                 hr_utility.set_location('Under DS null check'||l_duty_station_id, 1);
7543                 l_mslerrbuf := ' Error: Duty Station associated with the location is INVALID. '||
7544                                'Salary cannot be calculated correctly without valid duty station. ';
7545                 RAISE msl_error;
7546             END IF;
7547 
7548         END IF;
7549         -- End of bug 3437354
7550 
7551        /*    -- BEGIN
7552               ghr_pa_requests_pkg.get_SF52_loc_ddf_details
7553                   (p_location_id      => l_location_id
7554                   ,p_duty_station_id  => l_duty_station_id);
7555            /  *exception
7556               when others then
7557                  hr_utility.set_location(
7558                  'Error in Ghr_pa_requests_pkg.get_sf52_loc_ddf_details'||
7559                        'Err is '||sqlerrm(sqlcode),20);
7560                  l_mslerrbuf := 'Error in get_sf52_loc_ddf_details '||
7561                        'Sql Err is '|| sqlerrm(sqlcode);
7562                  raise msl_error;
7563            end;*  /
7564 
7565 
7566 
7567        get_pos_grp1_ddf(l_position_id,
7568                         l_effective_date,
7569                         l_pos_grp1_rec);
7570 
7571        l_personnel_office_id :=  l_pos_grp1_rec.poei_information3;
7572        l_org_structure_id    :=  l_pos_grp1_rec.poei_information5;
7573 
7574        get_sub_element_code_pos_title(l_position_id,
7575                                      p_person_id,
7576                                      l_business_group_id,
7577                                      l_assignment_id,
7578                                      l_effective_date,
7579                                      l_sub_element_code,
7580                                      l_position_title,
7581                                      l_position_number,
7582                                      l_position_seq_no);
7583 
7584 	hr_utility.set_location('The duty station id is:'||l_duty_station_id,12345);
7585 
7586        if check_init_eligibility(l_p_duty_station_id,
7587                               l_p_PERSONNEL_OFFICE_ID,
7588                               l_p_AGENCY_CODE_SUBELEMENT,
7589                               l_duty_station_id,
7590                               l_personnel_office_id,
7591                               l_sub_element_code) then
7592 
7593 		   hr_utility.set_location('check_init_eligibility    ' || l_proc,6);
7594 		-- Bug 3457205 Filter the Pay plan table id condition also b4 checking any other thing
7595 		-- Moving check_eligibility to here.
7596 			-- Get PRD, work schedule etc form ASG EI
7597 			 begin
7598 				ghr_pa_requests_pkg.get_sf52_asg_ddf_details
7599 						  (l_assignment_id,
7600 						   l_effective_date,
7601 						   l_tenure,
7602 						   l_annuitant_indicator,
7603 						   l_pay_rate_determinant,
7604 						   l_work_schedule,
7605 						   l_part_time_hour);
7606 			 exception
7607 				when others then
7608 					hr_utility.set_location('Error in Ghr_pa_requests_pkg.get_sf52_asg_ddf_details'||
7609 							  'Err is '||sqlerrm(sqlcode),20);
7610 					l_mslerrbuf := 'Error in get_sf52_asgddf_details Sql Err is '|| sqlerrm(sqlcode);
7611 					raise msl_error;
7612 			 end;
7613 
7614 -- Bug 3315432 Madhuri
7615 --
7616         FOR l_cnt in 1..rec_pp_prd.COUNT LOOP
7617 
7618 ---Bug 3327999 First filter the PRD. Then check for Pay plan and Pay table ID
7619 		IF nvl(rec_pp_prd(l_cnt).prd,l_pay_rate_determinant) = l_pay_rate_determinant THEN
7620 		-- Get Pay table ID and other details
7621            BEGIN
7622            -- Bug#5089732 Used the overloaded procedure.
7623                         get_pay_plan_and_table_id
7624                           (l_pay_rate_determinant,p_person_id,
7625                            l_position_id,l_effective_date,
7626                            l_grade_id, l_to_grade_id,l_assignment_id,'SHOW',
7627                            l_pay_plan,l_to_pay_plan,l_pay_table_id,
7628                            l_grade_or_level, l_to_grade_or_level, l_step_or_rate,
7629                            l_pay_basis);
7630            EXCEPTION
7631                when msl_error then
7632  		           l_mslerrbuf := hr_utility.get_message;
7633                    raise;
7634            END;
7635 
7636 		IF ( nvl(rec_pp_prd(l_cnt).pay_plan,l_pay_plan) = l_pay_plan
7637 			and l_user_table_id = nvl(l_pay_table_id,l_user_table_id) ) THEN
7638 
7639 			IF check_eligibility(l_mass_salary_id,
7640                                l_user_table_id,
7641                                l_pay_table_id,
7642                                l_pay_plan,
7643                                l_pay_rate_determinant,
7644                                p_person_id,
7645                                l_effective_date,
7646                                p_action) THEN
7647                 hr_utility.set_location('check_eligibility    ' || l_proc,8);   */
7648                 -- Bug#5063304 Moved this call outside check_init_eligibility condition to
7649                 --             this location.
7650                 -- BUG 3377958 Madhuri
7651                 -- Pick the organization name
7652                 g_proc := 'Fetch Organization Name';
7653                 l_org_name :=GHR_MRE_PKG.GET_ORGANIZATION_NAME(P_ORGANIZATION_ID);
7654 		l_ses_basic_pay := NULL;
7655                 -- BUG 3377958 Madhuri
7656 			IF upper(p_action) = 'REPORT' AND l_submit_flag = 'P' THEN
7657 		 	 -- BUG 3377958 Madhuri
7658  			    pop_dtls_from_pa_req(p_person_id,l_effective_date,l_mass_salary_id,l_org_name,p_employee_number);
7659  		    	 -- BUG 3377958 Madhuri
7660 			 ELSE
7661 			   if check_select_flg_ses(p_person_id,upper(p_action),
7662 									l_effective_date,p_mass_salary_id,l_sel_flg,l_ses_basic_pay) then
7663 
7664 				   hr_utility.set_location('check_select_flg    ' || l_proc,7);
7665                    BEGIN
7666 					hr_utility.set_location('The duty station name is:'||l_duty_station_code,12345);
7667 					hr_utility.set_location('The duty station desc is:'||l_duty_station_desc,12345);
7668 		            ghr_pa_requests_pkg.get_duty_station_details
7669                        (p_duty_station_id        => l_duty_station_id
7670                        ,p_effective_date        => l_effective_date
7671                        ,p_duty_station_code        => l_duty_station_code
7672                        ,p_duty_station_desc        => l_duty_station_desc);
7673                   EXCEPTION
7674                      WHEN others THEN
7675                         hr_utility.set_location('Error in Ghr_pa_requests_pkg.get_duty_station_details'||
7676                                'Err is '||sqlerrm(sqlcode),20);
7677                         l_mslerrbuf := 'Error in get_duty_station_details Sql Err is '|| sqlerrm(sqlcode);
7678                         RAISE msl_error;
7679 
7680                   END;
7681 
7682                      get_other_dtls_for_rep(l_pay_rate_determinant,
7683                                      l_executive_order_number,
7684                                      to_char(l_executive_order_date),
7685                                      l_first_action_la_code1,
7686                                      l_first_action_la_code2,
7687                                      l_remark_code1,
7688                                      l_remark_code2);
7689 
7690                      get_from_sf52_data_elements
7691                             (l_assignment_id,  l_effective_date,
7692                              l_old_basic_pay, l_old_avail_pay,
7693                              l_old_loc_diff, l_tot_old_sal,
7694                              l_old_auo_pay, l_old_adj_basic_pay,
7695                              l_other_pay, l_auo_premium_pay_indicator,
7696                              l_ap_premium_pay_indicator,
7697                              l_retention_allowance,
7698                              l_retention_allow_perc,
7699                              l_supervisory_differential,
7700                              l_supervisory_diff_perc,
7701                              l_staffing_differential);
7702 
7703                   l_pay_calc_in_data.person_id          := p_person_id;
7704                   l_pay_calc_in_data.position_id              := l_position_id;
7705                   --l_pay_calc_in_data.noa_family_code          := 'SALARY_CHG';
7706                   l_pay_calc_in_data.noa_family_code          := 'GHR_SAL_PAY_ADJ';
7707                   l_pay_calc_in_data.noa_code                 := nvl(g_first_noa_code,'890');
7708                   l_pay_calc_in_data.second_noa_code          := null;
7709                   l_pay_calc_in_data.first_action_la_code1    := l_lac_sf52_rec.first_action_la_code1;
7710                   l_pay_calc_in_data.effective_date           := l_effective_date;
7711                   l_pay_calc_in_data.pay_rate_determinant     := l_pay_rate_determinant;
7712                   l_pay_calc_in_data.pay_plan                 := l_pay_plan;
7713                   l_pay_calc_in_data.grade_or_level           := l_grade_or_level;
7714                   l_pay_calc_in_data.step_or_rate             := l_step_or_rate;
7715                   l_pay_calc_in_data.pay_basis                := l_pay_basis;
7716                   l_pay_calc_in_data.user_table_id            := l_pay_table_id;
7717                   l_pay_calc_in_data.duty_station_id          := l_duty_station_id;
7718                   l_pay_calc_in_data.auo_premium_pay_indicator := l_auo_premium_pay_indicator;
7719                   l_pay_calc_in_data.ap_premium_pay_indicator  := l_ap_premium_pay_indicator;
7720                   l_pay_calc_in_data.retention_allowance       := l_retention_allowance;
7721                   l_pay_calc_in_data.to_ret_allow_percentage   := l_retention_allow_perc;
7722                   l_pay_calc_in_data.supervisory_differential  := l_supervisory_differential;
7723                   l_pay_calc_in_data.staffing_differential    := l_staffing_differential;
7724                   l_pay_calc_in_data.current_basic_pay        := l_old_basic_pay;
7725                   l_pay_calc_in_data.current_adj_basic_pay    := l_old_adj_basic_pay;
7726                   l_pay_calc_in_data.current_step_or_rate     := l_step_or_rate;
7727                   l_pay_calc_in_data.pa_request_id            := null;
7728 
7729 		  l_pay_calc_in_data.open_range_out_basic_pay := l_ses_basic_pay;
7730 
7731                   ghr_msl_pkg.g_ses_msl_process              := 'N';
7732 
7733                  IF l_pay_plan in ('ES','EP','IE','FE') and l_essl_table THEN
7734                      ghr_msl_pkg.g_ses_msl_process           := 'Y';
7735                      l_step_or_rate                          := '00';
7736                   END IF;
7737 
7738                   BEGIN
7739                       ghr_pay_calc.sql_main_pay_calc (l_pay_calc_in_data
7740                            ,l_pay_calc_out_data
7741                            ,l_message_set
7742                            ,l_calculated);
7743 
7744                         IF l_message_set THEN
7745                             hr_utility.set_location( l_proc, 40);
7746                             l_calculated     := FALSE;
7747                             l_mslerrbuf  := hr_utility.get_message;
7748                 --			raise msl_error;
7749                         END IF;
7750                   EXCEPTION
7751                       when msl_error then
7752                            g_proc := 'ghr_pay_calc';
7753                           raise;
7754                       when others then
7755                     ----BUG 3287299 Start
7756                     IF ghr_pay_calc.gm_unadjusted_pay_flg = 'Y' then
7757                       l_comment := 'MSL:Error: Unadjusted Basic Pay must be entered in Employee record.';
7758                     ELSE
7759                       l_comment := 'MSL:Error: See process log for details.';
7760                     END IF;
7761 
7762                     IF upper(p_action) IN ('SHOW') THEN
7763                           -- Bug#2383392
7764                             create_mass_act_prev (
7765                             p_effective_date          => l_effective_date,
7766                             p_date_of_birth           => p_date_of_birth,
7767                             p_full_name               => p_full_name,
7768                             p_national_identifier     => p_national_identifier,
7769 			    --Bug # 9329643
7770 			    p_employee_number         => p_employee_number,
7771                             p_duty_station_code       => l_duty_station_code,
7772                             p_duty_station_desc       => l_duty_station_desc,
7773                             p_personnel_office_id     => l_personnel_office_id,
7774                             p_basic_pay               => l_old_basic_pay,
7775                             p_new_basic_pay           => null,
7776                             --Bug#2383992 Added old_adj_basic_pay
7777                             p_adj_basic_pay           => l_old_adj_basic_pay,
7778                             p_new_adj_basic_pay       => null,
7779                             p_old_avail_pay           => l_old_avail_pay,
7780                             p_new_avail_pay           => null,
7781                             p_old_loc_diff            => l_old_loc_diff,
7782                             p_new_loc_diff            => null,
7783                             p_tot_old_sal             => l_tot_old_sal,
7784                             p_tot_new_sal             => null,
7785                             p_old_auo_pay             => l_old_auo_pay,
7786                             p_new_auo_pay             => null,
7787                             p_position_id             => l_position_id,
7788                             p_position_title          => l_position_title,
7789                             -- FWFA Changes Bug#4444609
7790                             p_position_number         => l_position_number,
7791                             p_position_seq_no         => l_position_seq_no,
7792                             -- FWFA Changes
7793                             p_org_structure_id        => l_org_structure_id,
7794                             p_agency_sub_element_code => l_sub_element_code,
7795                             p_person_id               => p_person_id,
7796                             p_mass_salary_id          => l_mass_salary_id,
7797                             p_sel_flg                 => l_sel_flg,
7798                             p_first_action_la_code1   => l_first_action_la_code1,
7799                             p_first_action_la_code2   => l_first_action_la_code2,
7800                             p_remark_code1            => l_remark_code1,
7801                             p_remark_code2            => l_remark_code2,
7802                             p_grade_or_level          => l_grade_or_level,
7803                             p_step_or_rate            => l_step_or_rate,
7804                             p_pay_plan                => l_pay_plan,
7805                             p_pay_rate_determinant    =>  null,
7806                             p_tenure                  => l_tenure,
7807                             p_action                  => p_action,
7808                             p_assignment_id           => l_assignment_id,
7809                             p_old_other_pay           => l_other_pay,
7810                             p_new_other_pay           => null,
7811                             -- Bug#2383992
7812                             p_old_capped_other_pay    => NULL,
7813                             p_new_capped_other_pay    => NULL,
7814                             p_old_retention_allowance => l_retention_allowance,
7815                             p_new_retention_allowance => NULL,
7816                             p_old_supervisory_differential => l_supervisory_differential,
7817                             p_new_supervisory_differential => NULL,
7818                             -- BUG 3377958 Madhuri
7819                             p_organization_name            => l_org_name,
7820                             -- BUG 3377958 Madhuri
7821                             -- Bug#2383992
7822                             -- FWFA changes Bug#4444609
7823                             p_input_pay_rate_determinant  => l_pay_rate_determinant,
7824                             p_from_pay_table_id         => l_user_table_id,
7825                             p_to_pay_table_id           =>  null
7826                             -- FWFA changes
7827                              );
7828                           END IF;
7829                           -- Bug#3968005 Replaced parameter l_pay_sel with l_sel_flg
7830                           ins_upd_per_ses_extra_info
7831                              (p_person_id,l_effective_date, l_sel_flg, l_comment,p_mass_salary_id);
7832                           l_comment := NULL;
7833                           ------  BUG 3287299 End
7834                           hr_utility.set_location('Error in Ghr_pay_calc.sql_main_pay_calc '||
7835                                     'Err is '||sqlerrm(sqlcode),20);
7836                         l_mslerrbuf := 'Error in ghr_pay_calc  Sql Err is '|| sqlerrm(sqlcode);
7837                         g_proc := 'ghr_pay_calc';
7838                         raise msl_error;
7839                   END;
7840 
7841         ghr_msl_pkg.g_ses_msl_process              := 'N';
7842 
7843         l_new_basic_pay        := l_pay_calc_out_data.basic_pay;
7844         l_new_locality_adj     := l_pay_calc_out_data.locality_adj;
7845         l_new_adj_basic_pay    := l_pay_calc_out_data.adj_basic_pay;
7846         l_new_au_overtime      := l_pay_calc_out_data.au_overtime;
7847         l_new_availability_pay := l_pay_calc_out_data.availability_pay;
7848 
7849         --Added by mani related to the bug 5919694
7850 	l_out_pay_plan          := l_pay_calc_out_data.out_to_pay_plan;
7851 	l_out_grade_id          := l_pay_calc_out_data.out_to_grade_id;
7852 	l_out_grade_or_level    := l_pay_calc_out_data.out_to_grade_or_level;
7853 
7854 
7855         l_out_pay_rate_determinant := l_pay_calc_out_data.out_pay_rate_determinant;
7856         l_out_step_or_rate         := l_pay_calc_out_data.out_step_or_rate;
7857         l_new_retention_allowance :=  l_pay_calc_out_data.retention_allowance;
7858         l_new_supervisory_differential := l_supervisory_differential;
7859         l_new_other_pay_amount         := l_pay_calc_out_data.other_pay_amount;
7860         l_entitled_other_pay      := l_new_other_pay_amount;
7861         if l_new_other_pay_amount = 0 then
7862            l_new_other_pay_amount := null;
7863         end if;
7864         l_new_total_salary        := l_pay_calc_out_data.total_salary;
7865 
7866      hr_utility.set_location('retention_allowance = ' || to_char(l_retention_allowance),10);
7867      hr_utility.set_location('Supervisory Diff Amount = ' || to_char(l_supervisory_differential),10);
7868 
7869 
7870 -------------Call Pay cap Procedure
7871      begin
7872       l_capped_other_pay := ghr_pa_requests_pkg2.get_cop( p_assignment_id  => l_assignment_id
7873                                                          ,p_effective_date => l_effective_date);
7874       l_old_capped_other_pay :=  l_capped_other_pay;
7875 		-- Sundar Added the following if statement to improve performance
7876 			if hr_utility.debug_enabled = true then
7877 				  hr_utility.set_location('Before Pay Cap    ' || l_proc,21);
7878 				  hr_utility.set_location('l_effective_date  ' || l_effective_date,21);
7879 				  hr_utility.set_location('l_out_pay_rate_determinant  ' || l_out_pay_rate_determinant,21);
7880 				  hr_utility.set_location('l_pay_plan  ' || l_pay_plan,21);
7881 				  hr_utility.set_location('l_position_id  ' || to_char(l_position_id),21);
7882 				  hr_utility.set_location('l_pay_basis  ' || l_pay_basis,21);
7883 				  hr_utility.set_location('person_id  ' || to_char(p_person_id),21);
7884 				  hr_utility.set_location('l_new_basic_pay  ' || to_char(l_new_basic_pay),21);
7885 				  hr_utility.set_location('l_new_locality_adj  ' || to_char(l_new_locality_adj),21);
7886 				  hr_utility.set_location('l_new_adj_basic_pay  ' || to_char(l_new_adj_basic_pay),21);
7887 				  hr_utility.set_location('l_new_total_salary  ' || to_char(l_new_total_salary),21);
7888 				  hr_utility.set_location('l_entitled_other_pay  ' || to_char(l_entitled_other_pay),21);
7889 				  hr_utility.set_location('l_capped_other_pay  ' || to_char(l_capped_other_pay),21);
7890 				  hr_utility.set_location('l_new_retention_allowance  ' || to_char(l_new_retention_allowance),21);
7891 				  hr_utility.set_location('l_new_supervisory_differential  ' || to_char(l_new_supervisory_differential),21);
7892 				  hr_utility.set_location('l_staffing_differential  ' || to_char(l_staffing_differential),21);
7893 				  hr_utility.set_location('l_new_au_overtime  ' || to_char(l_new_au_overtime),21);
7894 				  hr_utility.set_location('l_new_availability_pay  ' || to_char(l_new_availability_pay),21);
7895 
7896 			end if;
7897 
7898 
7899       ghr_pay_caps.do_pay_caps_main
7900                    (p_pa_request_id        =>    null
7901                    ,p_effective_date       =>    l_effective_date
7902 		   ,p_duty_station_id      =>    l_duty_station_id --bug# 13414643,13403289
7903                    ,p_pay_rate_determinant =>    nvl(l_out_pay_rate_determinant,l_pay_rate_determinant)
7904                    ,p_pay_plan             =>    nvl(l_out_pay_plan,l_pay_plan)
7905                    ,p_to_position_id       =>    l_position_id
7906                    ,p_pay_basis            =>    l_pay_basis
7907                    ,p_person_id            =>    p_person_id
7908                    ,p_noa_code             =>    nvl(g_first_noa_code,'894')
7909                    ,p_basic_pay            =>    l_new_basic_pay
7910                    ,p_locality_adj         =>    l_new_locality_adj
7911                    ,p_adj_basic_pay        =>    l_new_adj_basic_pay
7912                    ,p_total_salary         =>    l_new_total_salary
7913                    ,p_other_pay_amount     =>    l_entitled_other_pay
7914                    ,p_capped_other_pay     =>    l_capped_other_pay
7915                    ,p_retention_allowance  =>    l_new_retention_allowance
7916                    ,p_retention_allow_percentage => l_retention_allow_perc
7917                    ,p_supervisory_allowance =>   l_new_supervisory_differential
7918                    ,p_staffing_differential =>   l_staffing_differential
7919                    ,p_au_overtime          =>    l_new_au_overtime
7920                    ,p_availability_pay     =>    l_new_availability_pay
7921                    ,p_adj_basic_message    =>    l_adj_basic_message
7922                    ,p_pay_cap_message      =>    l_pay_cap_message
7923                    ,p_pay_cap_adj          =>    l_temp_retention_allowance
7924                    ,p_open_pay_fields      =>    l_open_pay_fields_caps
7925                    ,p_message_set          =>    l_message_set_caps
7926                    ,p_total_pay_check      =>    l_total_pay_check);
7927 
7928 
7929              l_new_other_pay_amount := nvl(l_capped_other_pay,l_entitled_other_pay);
7930 
7931 			-- Sundar Added the following statement to improve performance
7932 			if hr_utility.debug_enabled = true then
7933 				  hr_utility.set_location('After Pay Cap    ' || l_proc,22);
7934 				  hr_utility.set_location('l_effective_date  ' || l_effective_date,22);
7935 				  hr_utility.set_location('l_out_pay_rate_determinant  ' || l_out_pay_rate_determinant,22);
7936 				  hr_utility.set_location('l_pay_plan  ' || l_pay_plan,22);
7937 				  hr_utility.set_location('l_position_id  ' || to_char(l_position_id),22);
7938 				  hr_utility.set_location('l_pay_basis  ' || l_pay_basis,22);
7939 				  hr_utility.set_location('person_id  ' || to_char(p_person_id),22);
7940 				  hr_utility.set_location('l_new_basic_pay  ' || to_char(l_new_basic_pay),22);
7941 				  hr_utility.set_location('l_new_locality_adj  ' || to_char(l_new_locality_adj),22);
7942 				  hr_utility.set_location('l_new_adj_basic_pay  ' || to_char(l_new_adj_basic_pay),22);
7943 				  hr_utility.set_location('l_new_total_salary  ' || to_char(l_new_total_salary),22);
7944 				  hr_utility.set_location('l_entitled_other_pay  ' || to_char(l_entitled_other_pay),22);
7945 				  hr_utility.set_location('l_capped_other_pay  ' || to_char(l_capped_other_pay),22);
7946 				  hr_utility.set_location('l_new_retention_allowance  ' || to_char(l_new_retention_allowance),22);
7947 				  hr_utility.set_location('l_new_supervisory_differential  ' || to_char(l_new_supervisory_differential),22);
7948 				  hr_utility.set_location('l_staffing_differential  ' || to_char(l_staffing_differential),22);
7949 				  hr_utility.set_location('l_new_au_overtime  ' || to_char(l_new_au_overtime),22);
7950 				  hr_utility.set_location('l_new_availability_pay  ' || to_char(l_new_availability_pay),22);
7951 			end if;
7952 
7953        IF l_pay_cap_message THEN
7954 	 IF nvl(l_temp_retention_allowance,0) > 0 THEN
7955 	    l_comment := 'MSL: Exceeded Total Cap - reduce Retention Allow to '
7956 			|| to_char(l_temp_retention_allowance);
7957 	  -- Bug#3968005 Replaced l_pay_sel with l_sel_flg
7958 	     l_sel_flg := 'N';
7959 	 ELSE
7960 	     l_comment := 'MSL: Exceeded Total cap - pls review.';
7961 	 END IF;
7962        ELSIF l_adj_basic_message THEN
7963           l_comment := 'MSL: Exceeded Adjusted Pay Cap - Locality reduced.';
7964        END IF;
7965 
7966 
7967 
7968        -- Bug 2639698 Sundar
7969 	   IF (l_old_basic_pay > l_new_basic_pay) THEN
7970 			l_comment_sal := 'MSL: From Basic Pay exceeds To Basic Pay.';
7971        END IF;
7972 	   -- End Bug 2639698
7973 
7974        IF l_pay_cap_message or l_adj_basic_message THEN
7975 			-- Bug 2639698
7976 		  IF (l_comment_sal IS NOT NULL) THEN
7977 		     l_comment := l_comment_sal || ' ' || l_comment;
7978 		  END IF;
7979 		  -- End Bug 2639698
7980 	     -- Bug#3968005 Replaced parameter l_pay_sel with l_sel_flg
7981              ins_upd_per_extra_info
7982                (p_person_id,l_effective_date, l_sel_flg, l_comment,p_mass_salary_id);
7983           l_comment := NULL;
7984        --------------------Bug 2639698 Sundar To add comments
7985 	   -- Should create comments only if comments need to be inserted
7986        ELSIF l_comment_sal IS NOT NULL THEN
7987             -- Bug#3968005 Replaced parameter l_pay_sel with l_sel_flg
7988 	    ins_upd_per_extra_info
7989                (p_person_id,l_effective_date, l_sel_flg, l_comment_sal,p_mass_salary_id);
7990 	   END IF;
7991 
7992        l_comment_sal := NULL; -- bug 2639698
7993      exception
7994           when msl_error then
7995                raise;
7996           when others then
7997 	   IF ghr_msl_pkg.g_ses_bp_capped = TRUE and upper(p_action) IN ('SHOW') THEN
7998               l_comment := 'MSL: Exceeded Basic Pay Cap EX III';
7999     	      l_sel_flg := 'N';
8000 	      ins_upd_per_extra_info
8001                (p_person_id,l_effective_date, l_sel_flg, l_comment,p_mass_salary_id);
8002 	      l_comment := NULL;
8003            ELSE
8004                hr_utility.set_location('Error in ghr_pay_caps.do_pay_caps_main ' ||
8005                                 'Err is '||sqlerrm(sqlcode),23);
8006                     l_mslerrbuf := 'Error in do_pay_caps_main  Sql Err is '|| sqlerrm(sqlcode);
8007                     raise msl_error;
8008            END IF;
8009      end;
8010 
8011 
8012                 IF upper(p_action) IN ('SHOW','REPORT') THEN
8013                           -- Bug#2383392
8014                     create_mass_act_prev (
8015                         p_effective_date          => l_effective_date,
8016                         p_date_of_birth           => p_date_of_birth,
8017                         p_full_name               => p_full_name,
8018                         p_national_identifier     => p_national_identifier,
8019 			--Bug # 9329643
8020 			p_employee_number         => p_employee_number,
8021                         p_duty_station_code       => l_duty_station_code,
8022                         p_duty_station_desc       => l_duty_station_desc,
8023                         p_personnel_office_id     => l_personnel_office_id,
8024                         p_basic_pay               => l_old_basic_pay,
8025                         p_new_basic_pay           => l_new_basic_pay,
8026                         --Bug#2383992 Added old_adj_basic_pay
8027                         p_adj_basic_pay           => l_old_adj_basic_pay,
8028                         p_new_adj_basic_pay       => l_new_adj_basic_pay,
8029                         p_old_avail_pay           => l_old_avail_pay,
8030                         p_new_avail_pay           =>  l_new_availability_pay,
8031                         p_old_loc_diff            => l_old_loc_diff,
8032                         p_new_loc_diff            => l_new_locality_adj,
8033                         p_tot_old_sal             => l_tot_old_sal,
8034                         p_tot_new_sal             =>   l_new_total_salary,
8035                         p_old_auo_pay             => l_old_auo_pay,
8036                         p_new_auo_pay             =>   l_new_au_overtime,
8037                         p_position_id             => l_position_id,
8038                         p_position_title          => l_position_title,
8039                         -- FWFA Changes Bug#4444609
8040                         p_position_number         => l_position_number,
8041                         p_position_seq_no         => l_position_seq_no,
8042                         -- FWFA Changes
8043                         p_org_structure_id        => l_org_structure_id,
8044                         p_agency_sub_element_code => l_sub_element_code,
8045                         p_person_id               => p_person_id,
8046                         p_mass_salary_id          => l_mass_salary_id,
8047                         p_sel_flg                 => l_sel_flg,
8048                         p_first_action_la_code1   => l_first_action_la_code1,
8049                         p_first_action_la_code2   => l_first_action_la_code2,
8050                         p_remark_code1            => l_remark_code1,
8051                         p_remark_code2            => l_remark_code2,
8052                         p_grade_or_level          => NVL(l_out_grade_or_level,l_grade_or_level),
8053                         p_step_or_rate            => l_step_or_rate,
8054                         p_pay_plan                => NVL(l_out_pay_plan,l_pay_plan),
8055                         -- FWFA Changes Bug#4444609
8056                         p_pay_rate_determinant    => NVL(l_out_pay_rate_determinant,l_pay_rate_determinant),
8057                         -- FWFA Changes
8058                         p_tenure                  => l_tenure,
8059                         p_action                  => p_action,
8060                         p_assignment_id           => l_assignment_id,
8061                         p_old_other_pay           => l_other_pay,
8062                         p_new_other_pay           => l_new_other_pay_amount,
8063                         -- Bug#2383992
8064                         p_old_capped_other_pay    => l_old_capped_other_pay,--NULL,
8065                         p_new_capped_other_pay    => l_capped_other_pay,
8066                         p_old_retention_allowance => l_retention_allowance,
8067                         p_new_retention_allowance => l_new_retention_allowance,
8068                         p_old_supervisory_differential => l_supervisory_differential,
8069                         p_new_supervisory_differential => l_new_supervisory_differential,
8070                         -- BUG 3377958 Madhuri
8071                         p_organization_name            => l_org_name,
8072                         -- Bug#2383992
8073                         -- FWFA Changes Bug#4444609
8074                         p_input_pay_rate_determinant   => l_pay_rate_determinant,
8075                         p_from_pay_table_id            => l_pay_calc_out_data.pay_table_id,
8076                         p_to_pay_table_id              => l_pay_calc_out_data.calculation_pay_table_id
8077                         -- FWFA Changes
8078                          );
8079                 ELSIF upper(p_action) = 'CREATE' then
8080 
8081                     BEGIN
8082                         -- Bug#5089732 Used the overloaded procedure.
8083                         get_pay_plan_and_table_id
8084                           (l_pay_rate_determinant,p_person_id,
8085                            l_position_id,l_effective_date,
8086                            l_grade_id, l_to_grade_id,l_assignment_id,'CREATE',
8087                            l_pay_plan,l_to_pay_plan,l_pay_table_id,
8088                            l_grade_or_level, l_to_grade_or_level, l_step_or_rate,
8089                            l_pay_basis);
8090                      EXCEPTION
8091                        when msl_error then
8092  		               l_mslerrbuf := hr_utility.get_message;
8093                        raise;
8094                      END;
8095 
8096                      assign_to_sf52_rec(
8097                        p_person_id,
8098                        p_first_name,
8099                        p_last_name,
8100                        p_middle_names,
8101                        p_national_identifier,
8102                        p_date_of_birth,
8103                        l_effective_date,
8104                        l_assignment_id,
8105                        l_tenure,
8106                        -- Bug#5089732
8107                        NVL(l_out_grade_id,l_to_grade_id),
8108                        NVL(l_out_pay_plan,l_to_pay_plan),
8109                        NVL(l_out_grade_or_level,l_to_grade_or_level),
8110                        -- Bug#5089732
8111                        l_step_or_rate,
8112                        l_annuitant_indicator,
8113                        -- FWFA Changes Bug#4444609
8114                        NVL(l_out_pay_rate_determinant,l_pay_rate_determinant),
8115                        -- FWFA Changes
8116                        l_work_schedule,
8117                        l_part_time_hour,
8118                        l_pos_ei_data.poei_information7, --FLSA Category
8119                        l_pos_ei_data.poei_information8, --Bargaining Unit Status
8120                        l_pos_ei_data.poei_information11,--Functional Class
8121                        l_pos_ei_data.poei_information16,--Supervisory Status,
8122                        l_new_basic_pay,
8123                        l_new_locality_adj,
8124                        l_new_adj_basic_pay,
8125                        l_new_total_salary,
8126                        l_other_pay,
8127                        l_new_other_pay_amount,
8128                        l_new_au_overtime,
8129                        l_new_availability_pay,
8130                        l_new_retention_allowance,
8131                        l_retention_allow_perc,
8132                        l_new_supervisory_differential,
8133                        l_supervisory_diff_perc,
8134                        l_staffing_differential,
8135                        l_duty_station_id,
8136                        l_duty_station_code,
8137                        l_duty_station_desc,
8138                        -- FWFA Changes  Bug#4444609
8139                        l_pay_rate_determinant,
8140                        l_pay_calc_out_data.pay_table_id,
8141                        l_pay_calc_out_data.calculation_pay_table_id,
8142                        -- FWFA Changes
8143                        l_lac_sf52_rec,
8144                        l_sf52_rec);
8145 
8146 					  BEGIN
8147 						   ghr_mass_actions_pkg.pay_calc_rec_to_sf52_rec
8148 							   (l_pay_calc_out_data,
8149 								l_sf52_rec);
8150 					  EXCEPTION
8151 						  when others then
8152 							  hr_utility.set_location('Error in Ghr_mass_actions_pkg.pay_calc_rec_to_sf52_rec '||
8153 										'Err is '||sqlerrm(sqlcode),20);
8154 							 l_mslerrbuf := 'Error in ghr_mass_act_pkg.pay_calc_to_sf52  Sql Err is '|| sqlerrm(sqlcode);
8155 							 raise msl_error;
8156 					  END;
8157 
8158                    BEGIN
8159 		               l_sf52_rec.mass_action_id := p_mass_salary_id;
8160                        l_sf52_rec.rpa_type := 'MRR';
8161                        g_proc  := 'Create_sf52_recrod';
8162                        ghr_mass_changes.create_sf52_for_mass_changes
8163                            (p_mass_action_type => 'MASS_SALARY_CHG',
8164                             p_pa_request_rec  => l_sf52_rec,
8165                             p_errbuf           => l_errbuf,
8166                             p_retcode          => l_retcode);
8167 
8168                        ------ Added by Dinkar for List reports problem
8169                        ---------------------------------------
8170                        IF l_errbuf IS NULL THEN
8171 
8172 					       DECLARE
8173 					           l_pa_request_number ghr_pa_requests.request_number%TYPE;
8174 						   BEGIN
8175               			       l_pa_request_number   :=
8176 								     l_sf52_rec.request_number||'-'||p_mass_salary_id;
8177 
8178 						       ghr_par_upd.upd
8179                                       (p_pa_request_id             => l_sf52_rec.pa_request_id,
8180                                        p_object_version_number     => l_sf52_rec.object_version_number,
8181                                        p_request_number            => l_pa_request_number
8182                                       );
8183 						   END;
8184 
8185                            pr('No error in create sf52 ');
8186 
8187 			   	  --Bug # 9329643 Modified SSN to Emp No
8188                            ghr_mto_int.log_message(
8189                               p_procedure => 'Successful Completion',
8190                               p_message   => 'Name: '||p_full_name ||
8191                               ' Emp No: ' || p_employee_number||
8192                               '  Mass Salary : '||
8193                               p_mass_salary ||' SF52 Successfully completed');
8194 
8195                            create_lac_remarks(l_pa_request_id,
8196                                            l_sf52_rec.pa_request_id);
8197 
8198    --5470182
8199 /*                          -- Added by Enunez 11-SEP-1999
8200                            IF l_lac_sf52_rec.first_action_la_code1 IS NULL THEN
8201                                -- Added by Edward Nunez for 894 rules
8202                                g_proc := 'Apply_894_Rules';
8203                                --Bug 2012782 fix
8204                                IF l_out_pay_rate_determinant IS NULL THEN
8205                                    l_out_pay_rate_determinant := l_pay_rate_determinant;
8206                                END IF;
8207                                --Bug 2012782 fix end
8208                                ghr_lacs_remarks.Apply_894_Rules(
8209                                        l_sf52_rec.pa_request_id,
8210                                        l_out_pay_rate_determinant,
8211                                        l_pay_rate_determinant,
8212                                        l_out_step_or_rate,
8213                                        l_executive_order_number,
8214                                        l_executive_order_date,
8215                                        l_opm_issuance_number,
8216                                        l_opm_issuance_date,
8217                                        l_errbuf,
8218                                        l_retcode
8219                                        );
8220                                IF l_errbuf IS NOT NULL THEN
8221                                    IF sqlcode = 0000 THEN
8222                                    l_mslerrbuf := l_mslerrbuf || '; ' || l_errbuf;
8223                                    ELSE
8224                                    l_mslerrbuf := l_mslerrbuf || ' ' || l_errbuf || ' Sql Err is: '
8225                                                                   || sqlerrm(sqlcode);
8226                                    END IF;
8227                                    RAISE msl_error;
8228                                END IF;
8229                            END IF; -- IF l_lac_sf52_rec.first_action_la_code1*/
8230                            g_proc := 'update_SEL_FLG';
8231 
8232                            update_SEL_FLG(p_PERSON_ID,l_effective_date);
8233 
8234                            COMMIT;
8235                        ELSE
8236                            pr('Error in create sf52',l_errbuf);
8237                            l_recs_failed := l_recs_failed + 1;
8238                            -- Raising MSL_ERROR is not required as the process log
8239                            -- was updated in ghr_mass_changes.create_sf52_for_mass_changes pkg itself.
8240                            --raise msl_error;
8241                        END IF; -- if l_errbuf is null then
8242                    EXCEPTION
8243                       WHEN msl_error then raise;
8244                       WHEN others then  null;
8245                       l_mslerrbuf := 'Error in ghr_mass_chg.create_sf52 '||
8246                                    ' Sql Err is '|| sqlerrm(sqlcode);
8247                       RAISE msl_error;
8248                    END;
8249                END IF; --  IF upper(p_action) IN ('SHOW','REPORT') THEN
8250             END IF; -- end if for check_select_flg
8251          END IF; -- end if for p_action = 'REPORT'
8252 
8253 
8254          L_row_cnt := L_row_cnt + 1;
8255          IF upper(p_action) <> 'CREATE' THEN
8256              IF L_row_cnt > 50 then
8257                  COMMIT;
8258                  L_row_cnt := 0;
8259              END IF;
8260          END IF;
8261       EXCEPTION
8262          WHEN MSL_ERROR THEN
8263                HR_UTILITY.SET_LOCATION('Error occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),10);
8264                begin
8265                 ------  BUG 3287299 -- Not to rollback for preview.
8266        	        if upper(p_action) <> 'SHOW' then
8267                   ROLLBACK TO EXECUTE_MSL_SP;
8268                 end if;
8269                EXCEPTION
8270                   WHEN OTHERS THEN NULL;
8271                END;
8272 	       	  --Bug # 9329643 Modified SSN to Emp No
8273                l_log_text  := 'Error in '||l_proc||' '||
8274                               ' For Mass Salary Name : '||p_mass_salary||
8275                               'Name: '|| p_full_name || ' Emp No: ' || p_employee_number ||
8276                               l_mslerrbuf;
8277                hr_utility.set_location('before creating entry in log file',10);
8278                l_recs_failed := l_recs_failed + 1;
8279             begin
8280                ghr_mto_int.log_message(
8281                               p_procedure => g_proc,
8282                               p_message   => l_log_text);
8283             exception
8284                 when others then
8285                     hr_utility.set_message(8301, 'GHR_38475_ERROR_LOG_FAILURE');
8286                     hr_utility.raise_error;
8287             end;
8288          when others then
8289                HR_UTILITY.SET_LOCATION('Error (Others) occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),20);
8290                BEGIN
8291                  ROLLBACK TO EXECUTE_MSL_SP;
8292                EXCEPTION
8293                  WHEN OTHERS THEN NULL;
8294                END;
8295 	       	  --Bug # 9329643 Modified SSN to Emp No
8296                l_log_text  := 'Error (others) in '||l_proc||
8297                               ' For Mass Salary Name : '||p_mass_salary||
8298                               'Name: '|| p_full_name || ' Emp No: ' || p_employee_number ||
8299                               ' Sql Err is '||sqlerrm(sqlcode);
8300                hr_utility.set_location('before creating entry in log file',20);
8301                l_recs_failed := l_recs_failed + 1;
8302             begin
8303                ghr_mto_int.log_message(
8304                               p_procedure => g_proc,
8305                               p_message   => l_log_text);
8306             exception
8307                 when others then
8308                     hr_utility.set_message(8301, 'Create Error Log failed');
8309                     hr_utility.raise_error;
8310             end;
8311       END msl_ses_process;
8312 
8313 BEGIN
8314 
8315   g_proc  := 'execute_msl_ses_range';
8316   hr_utility.set_location('Entering    ' || l_proc,5);
8317   p_retcode  := 0;
8318 
8319   g_first_noa_code     := null;
8320   BEGIN
8321     FOR msl IN ghr_msl (p_mass_salary_id)
8322     LOOP
8323         p_mass_salary    := msl.name;
8324         l_effective_date := msl.effective_date;
8325         l_mass_salary_id := msl.mass_salary_id;
8326         l_user_table_id  := msl.user_table_id;
8327         l_submit_flag    := msl.submit_flag;
8328 
8329 
8330         l_executive_order_number := msl.executive_order_number;
8331         l_executive_order_date :=  msl.executive_order_date;
8332 
8333         l_opm_issuance_number  :=  msl.opm_issuance_number;
8334         l_opm_issuance_date    :=  msl.opm_issuance_date;
8335         l_pa_request_id  := msl.pa_request_id;
8336         l_rowid          := msl.rowid;
8337         l_p_ORGANIZATION_ID        := msl.ORGANIZATION_ID;
8338         l_p_DUTY_STATION_ID        := msl.DUTY_STATION_ID;
8339         l_p_PERSONNEL_OFFICE_ID    := msl.PERSONNEL_OFFICE_ID;
8340         l_p_AGENCY_CODE_SUBELEMENT := msl.AGENCY_CODE_SUBELEMENT;
8341 
8342 		pr('Pa request id is '||to_char(l_pa_request_id));
8343        exit;
8344     END LOOP;
8345   EXCEPTION
8346     when REC_BUSY then
8347          hr_utility.set_location('Mass Salary is in use',1);
8348          l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
8349         -- raise error;
8350         hr_utility.set_message(8301, 'GHR_38477_LOCK_ON_MSL');
8351         hr_utility.raise_error;
8352 --
8353     when others then
8354       hr_utility.set_location('Error in '||l_proc||' Sql err is '||sqlerrm(sqlcode),1);
8355 --    raise_application_error(-20111,'Error while selecting from Ghr Mass Salaries');
8356       l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
8357       raise msl_error;
8358   END;
8359 
8360   g_effective_date := l_effective_date;
8361 
8362   for c_pay_tab_essl_rec in c_pay_tab_essl loop
8363       l_essl_table := TRUE;
8364       exit;
8365   end loop;
8366 --5470182
8367 
8368 FOR pp_prd IN cur_pp_prd(p_mass_salary_id)
8369   LOOP
8370 	rec_pp_prd(l_index).pay_plan := pp_prd.pay_plan;
8371 	rec_pp_prd(l_index).prd      := pp_prd.prd;
8372 	l_index := l_index +1;
8373   END LOOP;
8374 
8375 
8376 /*-- Bug 3315432 Madhuri
8377 --
8378   FOR pp_prd_per_gr IN cur_pp_prd_per_gr(p_mass_salary_id)
8379   LOOP
8380 	rec_pp_prd_per_gr(l_index).pay_plan := pp_prd_per_gr.pay_plan;
8381 	rec_pp_prd_per_gr(l_index).prd      := pp_prd_per_gr.prd;
8382 	rec_pp_prd_per_gr(l_index).percent  := pp_prd_per_gr.percent;
8383 	rec_pp_prd_per_gr(l_index).grade    := pp_prd_per_gr.grade;
8384 	l_index := l_index +1;
8385 
8386   END LOOP;*/
8387 
8388   IF upper(p_action) = 'CREATE' then
8389      ghr_mto_int.set_log_program_name('GHR_MSL_PKG');
8390   ELSE
8391      ghr_mto_int.set_log_program_name('MSL_'||p_mass_salary);
8392   END IF;
8393 
8394 --  Commented out by Edward Nunez. It's not needed anymore with 894 rules
8395 --  IF upper(p_action) = 'CREATE' then
8396 --    if l_pa_request_id is null then
8397 --       hr_utility.set_message(8301, 'GHR_99999_SELECT_LAC_REMARKS');
8398 --       hr_utility.raise_error;
8399 --    END IF;
8400 --  END IF;
8401 
8402   get_lac_dtls(l_pa_request_id,
8403                l_lac_sf52_rec);
8404 
8405   --purge_old_data(l_mass_salary_id);
8406 
8407   hr_utility.set_location('After fetch msl '||to_char(l_effective_date)
8408     ||' '||to_char(l_user_table_id),20);
8409 
8410 IF l_p_ORGANIZATION_ID is not null then
8411     FOR per IN cur_people_org (l_effective_date,l_p_ORGANIZATION_ID)
8412     LOOP
8413         -- Bug#5719467 Initialised the variable l_mslerrbuf to avoid ora error 6502
8414         l_mslerrbuf := NULL;
8415         -- Bug#5063304 Added the following IF Condition.
8416         IF  NVL(l_p_organization_id,per.organization_id) = per.organization_id THEN
8417             FOR ast IN cur_ast (per.assignment_status_type_id)
8418             LOOP
8419                 -- Set all local variables to NULL
8420                  l_personnel_office_id  := NULL;
8421                  l_org_structure_id     := NULL;
8422                  l_position_title       := NULL;
8423                  l_position_number      := NULL;
8424                  l_position_seq_no      := NULL;
8425                  l_sub_element_code     := NULL;
8426                  l_duty_station_id      := NULL;
8427                  l_tenure               := NULL;
8428                  l_annuitant_indicator  := NULL;
8429                  l_pay_rate_determinant := NULL;
8430                  l_work_schedule        := NULL;
8431                  l_part_time_hour       := NULL;
8432                  l_to_grade_id          := NULL;
8433                  l_pay_plan             := NULL;
8434                  l_to_pay_plan          := NULL;
8435                  l_pay_table_id         := NULL;
8436                  l_grade_or_level       := NULL;
8437                  l_to_grade_or_level    := NULL;
8438                  l_step_or_rate         := NULL;
8439                  l_pay_basis            := NULL;
8440                  l_elig_flag            := FALSE;
8441                 --
8442                 BEGIN
8443                    fetch_and_validate_emp_ses(
8444                                 p_action                => p_action
8445                                ,p_mass_salary_id        => p_mass_salary_id
8446                                ,p_mass_salary_name      => p_mass_salary
8447                                ,p_full_name             => per.full_name
8448                                ,p_national_identifier   => per.national_identifier
8449 			       --Bug # 9329643
8450 			       ,p_employee_number       => per.employee_number
8451                                ,p_assignment_id         => per.assignment_id
8452                                ,p_person_id             => per.person_id
8453                                ,p_position_id           => per.position_id
8454                                ,p_grade_id              => per.grade_id
8455                                ,p_business_group_id     => per.business_group_id
8456                                ,p_location_id           => per.location_id
8457                                ,p_organization_id       => per.organization_id
8458                                ,p_msl_organization_id    => l_p_organization_id
8459                                ,p_msl_duty_station_id    => l_p_duty_station_id
8460                                ,p_msl_personnel_office_id   => l_p_personnel_office_id
8461                                ,p_msl_agency_code_subelement => l_p_agency_code_subelement
8462                                ,p_msl_user_table_id         => l_user_table_id
8463                                ,p_rec_pp_prd                => rec_pp_prd
8464                                ,p_personnel_office_id   => l_personnel_office_id
8465                                ,p_org_structure_id      => l_org_structure_id
8466                                ,p_position_title        => l_position_title
8467                                ,p_position_number       => l_position_number
8468                                ,p_position_seq_no       => l_position_seq_no
8469                                ,p_subelem_code          => l_sub_element_code
8470                                ,p_duty_station_id       => l_duty_station_id
8471                                ,p_tenure                => l_tenure
8472                                ,p_annuitant_indicator   => l_annuitant_indicator
8473                                ,p_pay_rate_determinant  => l_pay_rate_determinant
8474                                ,p_work_schedule         => l_work_schedule
8475                                ,p_part_time_hour        => l_part_time_hour
8476                                ,p_to_grade_id           => l_to_grade_id
8477                                ,p_pay_plan              => l_pay_plan
8478                                ,p_to_pay_plan           => l_to_pay_plan
8479                                ,p_pay_table_id          => l_pay_table_id
8480                                ,p_grade_or_level        => l_grade_or_level
8481                                ,p_to_grade_or_level     => l_to_grade_or_level
8482                                ,p_step_or_rate          => l_step_or_rate
8483                                ,p_pay_basis             => l_pay_basis
8484                                ,p_elig_flag             => l_elig_flag
8485                                );
8486                 EXCEPTION
8487                     --WHEN fetch_validate_error THEN
8488                        --l_elig_flag := FALSE;
8489                     WHEN OTHERS THEN
8490                         l_elig_flag := FALSE;
8491                 END;
8492 
8493                 IF l_elig_flag THEN
8494 		    msl_ses_process( p_assignment_id  => per.assignment_id
8495                                     ,p_person_id => per.person_id
8496                                     ,p_position_id  => per.position_id
8497                                     ,p_grade_id => per.grade_id
8498                                     ,p_business_group_id => per.business_group_id
8499                                     ,p_location_id => per.location_id
8500                                     ,p_organization_id => per.organization_id
8501                                     ,p_date_of_birth => per.date_of_birth
8502                                     ,p_first_name => per.first_name
8503                                     ,p_last_name => per.last_name
8504                                     ,p_full_name => per.full_name
8505                                     ,p_middle_names => per.middle_names
8506                                     ,p_national_identifier => per.national_identifier
8507 				    --Bug # 9329643
8508 				    ,p_employee_number     => per.employee_number
8509                                     ,p_personnel_office_id   => l_personnel_office_id
8510                                     ,p_org_structure_id      => l_org_structure_id
8511                                     ,p_position_title        => l_position_title
8512                                     ,p_position_number       => l_position_number
8513                                     ,p_position_seq_no       => l_position_seq_no
8514                                     ,p_subelem_code          => l_sub_element_code
8515                                     ,p_duty_station_id       => l_duty_station_id
8516                                     ,p_tenure                => l_tenure
8517                                     ,p_annuitant_indicator   => l_annuitant_indicator
8518                                     ,p_pay_rate_determinant  => l_pay_rate_determinant
8519                                     ,p_work_schedule         => l_work_schedule
8520                                     ,p_part_time_hour        => l_part_time_hour
8521 				    ,p_to_grade_id           => l_to_grade_id
8522                                     ,p_pay_plan              => l_pay_plan
8523                                     ,p_to_pay_plan           => l_to_pay_plan
8524                                     ,p_pay_table_id          => l_pay_table_id
8525                                     ,p_grade_or_level        => l_grade_or_level
8526                                     ,p_to_grade_or_level     => l_to_grade_or_level
8527                                     ,p_step_or_rate          => l_step_or_rate
8528                                     ,p_pay_basis             => l_pay_basis
8529                               );
8530                  END IF;
8531                END LOOP;
8532            END IF;
8533        END LOOP;
8534    ELSE
8535     FOR per IN cur_people (l_effective_date)
8536     LOOP
8537         -- Bug#5719467 Initialised the variable l_mslerrbuf to avoid ora error 6502
8538         l_mslerrbuf := NULL;
8539         FOR ast IN cur_ast (per.assignment_status_type_id)
8540         LOOP
8541             --
8542             -- Set all local variables to NULL
8543             l_personnel_office_id  := NULL;
8544             l_org_structure_id     := NULL;
8545             l_position_title       := NULL;
8546             l_position_number      := NULL;
8547             l_position_seq_no      := NULL;
8548             l_sub_element_code     := NULL;
8549             l_duty_station_id      := NULL;
8550             l_tenure               := NULL;
8551             l_annuitant_indicator  := NULL;
8552             l_pay_rate_determinant := NULL;
8553             l_work_schedule        := NULL;
8554             l_part_time_hour       := NULL;
8555             l_to_grade_id          := NULL;
8556             l_pay_plan             := NULL;
8557             l_to_pay_plan          := NULL;
8558             l_pay_table_id         := NULL;
8559             l_grade_or_level       := NULL;
8560             l_to_grade_or_level    := NULL;
8561             l_step_or_rate         := NULL;
8562             l_pay_basis            := NULL;
8563             l_elig_flag            := FALSE;
8564             --
8565             BEGIN
8566                 fetch_and_validate_emp_ses(
8567                                         p_action                => p_action
8568                                        ,p_mass_salary_id        => p_mass_salary_id
8569                                        ,p_mass_salary_name      => p_mass_salary
8570                                        ,p_full_name             => per.full_name
8571                                        ,p_national_identifier   => per.national_identifier
8572 				       --Bug # 9329643
8573 				       ,p_employee_number       => per.employee_number
8574                                        ,p_assignment_id         => per.assignment_id
8575                                        ,p_person_id             => per.person_id
8576                                        ,p_position_id           => per.position_id
8577                                        ,p_grade_id              => per.grade_id
8578                                        ,p_business_group_id     => per.business_group_id
8579                                        ,p_location_id           => per.location_id
8580                                        ,p_organization_id       => per.organization_id
8581                                        ,p_msl_organization_id    => l_p_organization_id
8582                                        ,p_msl_duty_station_id    => l_p_duty_station_id
8583                                        ,p_msl_personnel_office_id   => l_p_personnel_office_id
8584                                        ,p_msl_agency_code_subelement => l_p_agency_code_subelement
8585                                        ,p_msl_user_table_id         => l_user_table_id
8586                                        ,p_rec_pp_prd               => rec_pp_prd
8587                                        ,p_personnel_office_id   => l_personnel_office_id
8588                                        ,p_org_structure_id      => l_org_structure_id
8589                                        ,p_position_title        => l_position_title
8590                                        ,p_position_number       => l_position_number
8591                                        ,p_position_seq_no       => l_position_seq_no
8592                                        ,p_subelem_code          => l_sub_element_code
8593                                        ,p_duty_station_id       => l_duty_station_id
8594                                        ,p_tenure                => l_tenure
8595                                        ,p_annuitant_indicator   => l_annuitant_indicator
8596                                        ,p_pay_rate_determinant  => l_pay_rate_determinant
8597                                        ,p_work_schedule         => l_work_schedule
8598                                        ,p_part_time_hour        => l_part_time_hour
8599 				       ,p_to_grade_id           => l_to_grade_id
8600                                        ,p_pay_plan              => l_pay_plan
8601                                        ,p_to_pay_plan           => l_to_pay_plan
8602                                        ,p_pay_table_id          => l_pay_table_id
8603                                        ,p_grade_or_level        => l_grade_or_level
8604                                        ,p_to_grade_or_level     => l_to_grade_or_level
8605                                        ,p_step_or_rate          => l_step_or_rate
8606                                        ,p_pay_basis             => l_pay_basis
8607                                        ,p_elig_flag             => l_elig_flag
8608                                         );
8609                     EXCEPTION
8610                         --WHEN fetch_validate_error THEN
8611                           --  l_elig_flag := FALSE;
8612                         WHEN OTHERS THEN
8613                             l_elig_flag := FALSE;
8614                     END;
8615                     IF l_elig_flag THEN
8616 		       msl_ses_process(
8617                                        p_assignment_id  => per.assignment_id
8618                                       ,p_person_id => per.person_id
8619                                       ,p_position_id  => per.position_id
8620                                       ,p_grade_id => per.grade_id
8621                                       ,p_business_group_id => per.business_group_id
8622                                       ,p_location_id => per.location_id
8623                                       ,p_organization_id => per.organization_id
8624                                       ,p_date_of_birth => per.date_of_birth
8625                                       ,p_first_name => per.first_name
8626                                       ,p_last_name => per.last_name
8627                                       ,p_full_name => per.full_name
8628                                       ,p_middle_names => per.middle_names
8629                                       ,p_national_identifier => per.national_identifier
8630 				      --Bug # 9329643
8631 				      ,p_employee_number     => per.employee_number
8632                                       ,p_personnel_office_id   => l_personnel_office_id
8633                                       ,p_org_structure_id      => l_org_structure_id
8634                                       ,p_position_title        => l_position_title
8635                                       ,p_position_number       => l_position_number
8636                                       ,p_position_seq_no       => l_position_seq_no
8637                                       ,p_subelem_code          => l_sub_element_code
8638                                       ,p_duty_station_id       => l_duty_station_id
8639                                       ,p_tenure                => l_tenure
8640                                       ,p_annuitant_indicator   => l_annuitant_indicator
8641                                       ,p_pay_rate_determinant  => l_pay_rate_determinant
8642                                       ,p_work_schedule         => l_work_schedule
8643                                       ,p_part_time_hour        => l_part_time_hour
8644                                       ,p_to_grade_id           => l_to_grade_id
8645                                       ,p_pay_plan              => l_pay_plan
8646                                       ,p_to_pay_plan           => l_to_pay_plan
8647                                       ,p_pay_table_id          => l_pay_table_id
8648                                       ,p_grade_or_level        => l_grade_or_level
8649                                       ,p_to_grade_or_level     => l_to_grade_or_level
8650                                       ,p_step_or_rate          => l_step_or_rate
8651                                       ,p_pay_basis             => l_pay_basis
8652                                       );
8653                     END IF;
8654 
8655         END LOOP;
8656     END LOOP;
8657   END IF;
8658 
8659   pr('After processing is over ',to_char(l_recs_failed));
8660 /*
8661     if (l_recs_failed  < (l_msl_cnt  * (1/3))) then
8662 */
8663    if (l_recs_failed  = 0) then
8664      IF upper(p_action) = 'CREATE' THEN
8665        begin
8666           update ghr_mass_salaries
8667              set submit_flag = 'P'
8668            where rowid = l_rowid;
8669        EXCEPTION
8670          when others then
8671            HR_UTILITY.SET_LOCATION('Error in Update ghr_msl  Sql error '||sqlerrm(sqlcode),30);
8672            hr_utility.set_message(8301, 'GHR_38476_UPD_GHR_MSL_FAILURE');
8673            hr_utility.raise_error;
8674        END;
8675 -----Bug 2849262. Updating extra info to null is already done by Update_sel_flg in the main loop.
8676 -----             So it is not required to do in global if you see the procedure upd_ext_info_to_null
8677 -----             Commenting the following line. Dated 14-OCT-2003.
8678 -----
8679 -----  upd_ext_info_to_null(l_effective_date);
8680      end if;
8681   ELSE
8682 --if (l_recs_failed  <> 0) then
8683       p_errbuf   := 'Error in '||l_proc || ' Details in GHR_PROCESS_LOG';
8684       p_retcode  := 2;
8685       IF upper(p_action) = 'CREATE' THEN
8686          update ghr_mass_salaries
8687             set submit_flag = 'E'
8688           where rowid = l_rowid;
8689       END IF;
8690   end if;
8691 pr('Before commiting.....');
8692 COMMIT;
8693 pr('After commiting.....',to_char(l_recs_failed));
8694 
8695 EXCEPTION
8696     when others then
8697 --    raise_application_error(-20121,'Error in execute_msl_ses Err is '||sqlerrm(sqlcode));
8698       HR_UTILITY.SET_LOCATION('Error (Others2) occurred in  '||l_proc||' Sql error '||sqlerrm(sqlcode),30);
8699       BEGIN
8700         ROLLBACK TO execute_msl_ses_sp;
8701       EXCEPTION
8702         WHEN OTHERS THEN NULL;
8703       END;
8704       l_log_text  := 'Error in '||l_proc||
8705                      ' For Mass Salary Name : '||p_mass_salary||
8706                      ' Sql Err is '||sqlerrm(sqlcode);
8707       l_recs_failed := l_recs_failed + 1;
8708       hr_utility.set_location('before creating entry in log file',30);
8709 
8710       p_errbuf   := 'Error in '||l_proc || ' Details in GHR_PROCESS_LOG';
8711       p_retcode  := 2;
8712       IF upper(p_action) = 'CREATE' THEN
8713          update ghr_mass_salaries
8714             set submit_flag = 'E'
8715           where rowid = l_rowid;
8716           commit;
8717       END IF;
8718 
8719       begin
8720          ghr_mto_int.log_message(
8721                         p_procedure => g_proc,
8722                         p_message   => l_log_text);
8723 
8724       exception
8725           when others then
8726               hr_utility.set_message(8301, 'Create Error Log failed');
8727               hr_utility.raise_error;
8728       end;
8729 
8730 END execute_msl_ses_range;
8731 
8732 
8733 procedure ins_upd_per_ses_extra_info
8734                (p_person_id in number,
8735 			    p_effective_date in date,
8736                 p_sel_flag in varchar2,
8737 				p_comment in varchar2,
8738 				p_msl_id in number,
8739 				p_ses_basic_pay in number default NULL) is
8740 
8741    l_person_extra_info_id number;
8742    l_object_version_number number;
8743    l_per_ei_data         per_people_extra_info%rowtype;
8744 
8745    CURSOR people_ext_cur (person number) is
8746    SELECT person_extra_info_id, object_version_number
8747      FROM PER_people_EXTRA_INFO
8748     WHERE person_ID = person
8749       and information_type = 'GHR_US_PER_MASS_ACTIONS';
8750 
8751     l_proc    varchar2(72) :=  g_package || '.ins_upd_per_ses_extra_info';
8752     l_eff_date date;
8753 
8754 begin
8755   g_proc  := 'ins_upd_per_ses_extra_info';
8756   hr_utility.set_location('Entering    ' || l_proc,5);
8757   if p_effective_date > sysdate then
8758        l_eff_date := sysdate;
8759   else
8760        l_eff_date := p_effective_date;
8761   end if;
8762 
8763    ghr_history_fetch.fetch_peopleei
8764                   (p_person_id           => p_person_id
8765                   ,p_information_type      => 'GHR_US_PER_MASS_ACTIONS'
8766                   ,p_date_effective        => l_eff_date
8767                   ,p_per_ei_data           => l_per_ei_data);
8768 
8769    l_person_extra_info_id  := l_per_ei_data.person_extra_info_id;
8770    l_object_version_number := l_per_ei_data.object_version_number;
8771 
8772    if l_person_extra_info_id is null then
8773       for per_ext_rec in people_ext_cur(p_person_id)
8774       loop
8775          l_person_extra_info_id  := per_ext_rec.person_extra_info_id;
8776          l_object_version_number := per_ext_rec.object_version_number;
8777       end loop;
8778    end if;
8779 
8780    if l_person_extra_info_id is not null then
8781         ghr_person_extra_info_api.update_person_extra_info
8782                        (P_PERSON_EXTRA_INFO_ID   => l_person_extra_info_id
8783                        ,P_EFFECTIVE_DATE           => trunc(l_eff_date)
8784                        ,P_OBJECT_VERSION_NUMBER    => l_object_version_number
8785                        ,p_pei_INFORMATION3        => p_sel_flag
8786                        ,p_pei_INFORMATION4        => p_comment
8787                        ,p_pei_INFORMATION5        => to_char(p_msl_id)
8788 		       ,p_pei_information10       => NULL
8789 		       ,p_pei_information11       => to_char(p_ses_basic_pay)
8790                        ,P_PEI_INFORMATION_CATEGORY  => 'GHR_US_PER_MASS_ACTIONS');
8791    else
8792         ghr_person_extra_info_api.create_person_extra_info
8793                        (P_pERSON_ID               => p_PERSON_id
8794                        ,P_INFORMATION_TYPE        => 'GHR_US_PER_MASS_ACTIONS'
8795                        ,P_EFFECTIVE_DATE          => trunc(l_eff_date)
8796                        ,p_pei_INFORMATION3        => p_sel_flag
8797                        ,p_pei_INFORMATION4        => p_comment
8798                        ,p_pei_INFORMATION5        => to_char(p_msl_id)
8799 		       ,p_pei_information10       =>NULL
8800 		       ,p_pei_information11       => to_char(p_ses_basic_pay)
8801                        ,P_PEI_INFORMATION_CATEGORY  => 'GHR_US_PER_MASS_ACTIONS'
8802                        ,P_pERSON_EXTRA_INFO_ID  => l_pERSON_extra_info_id
8803                        ,P_OBJECT_VERSION_NUMBER   => l_object_version_number);
8804    end if;
8805 
8806 ---Commented the following two lines to remove Validation functionality on Person.
8807 -- ghr_validate_perwsepi.validate_perwsepi(p_person_id);
8808 -- ghr_validate_perwsepi.update_person_user_type(p_person_id);
8809 
8810    hr_utility.set_location('Exiting    ' || l_proc,10);
8811 exception
8812   when msl_error then raise;
8813   when others then
8814      pr('Error in '||l_proc);
8815      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
8816      l_mslerrbuf := 'Error in '||l_proc||'  Sql Err is '|| sqlerrm(sqlcode);
8817      raise msl_error;
8818 end ins_upd_per_ses_extra_info;
8819 
8820 
8821 function check_select_flg_ses(p_person_id in number,
8822                               p_action in varchar2,
8823                               p_effective_date in date,
8824                               p_mass_salary_id in number,
8825                               p_sel_flg in out nocopy varchar2,
8826 			      p_ses_basic_pay in out nocopy number
8827 			  )
8828 return boolean IS
8829 
8830    l_per_ei_data        per_people_extra_info%rowtype;
8831    l_comments varchar2(250);
8832    l_sel_flag varchar2(3);
8833    l_line number := 0;
8834    l_proc     varchar2(72) :=  g_package || '.check_select_flg_ses';
8835    l_ses_basic_pay ghr_mass_actions_preview.to_basic_pay%type;
8836    l_temp_ses_basic_pay number;
8837    l_increase_percent number;
8838 begin
8839 
8840   g_proc  := 'check_select_flg_ses';
8841   l_temp_ses_basic_pay := p_ses_basic_pay;
8842 
8843   hr_utility.set_location('Entering    ' || l_proc,5);
8844 
8845   get_extra_info_comments(p_person_id,p_effective_date,l_sel_flag,l_comments,p_mass_salary_id,l_increase_percent,l_ses_basic_pay); -- Added by Sundar 3843306
8846 
8847    -------- Initialize the comments
8848    -- Sundar 3337361 Included GM Error, To basic pay < From basic pay in the condition
8849    -- Now all the messages have MSL as a prefix. Rest of the conditions are alo
8850    -- included for the old records which may still have old message.
8851    IF l_comments is not null THEN
8852        --Bug#4093705 Added ltrim function to verify the System generated Comments as few comments
8853        --            might start with Blank Spaces. Removed NVL condition as control comes here
8854        --            only when l_comments has Non Null value.
8855        IF substr(ltrim(l_comments),1,8) = 'Exceeded'
8856 		OR substr(ltrim(l_comments),1,3) = 'MSL'
8857 		OR substr(ltrim(l_comments),1,5) = 'Error'
8858 		OR substr(ltrim(l_comments),1,13) = 'The From Side'
8859 	   THEN
8860           ins_upd_per_ses_extra_info
8861                (p_person_id,p_effective_date, l_sel_flag, null,p_mass_salary_id,l_ses_basic_pay);
8862        END IF;
8863      END IF;
8864    -- Bug 3843306 If Increase percent is entered from Preview screen, the same should be retrieved
8865    -- and not the one entered in Grade screen.
8866 
8867     IF l_ses_basic_pay IS NOT NULL THEN
8868 		p_ses_basic_pay := l_ses_basic_pay;
8869     END IF;
8870 
8871      if l_sel_flag is null then
8872           p_sel_flg := 'Y';
8873      else
8874           p_sel_flg := l_sel_flag;
8875      end if;
8876 
8877 	l_line := 15;
8878      if p_action IN ('SHOW','REPORT') THEN
8879          return TRUE;
8880      elsif p_action = 'CREATE' THEN
8881          if p_sel_flg = 'Y' THEN
8882             return TRUE;
8883          else
8884             return FALSE;
8885          end if;
8886      end if;
8887 exception
8888   when msl_error then raise;
8889   when others then
8890      p_ses_basic_pay := l_temp_ses_basic_pay ;
8891      hr_utility.set_location('Error in '||l_proc||' Err is '||sqlerrm(sqlcode),20);
8892      l_mslerrbuf := 'Error in '||l_proc||' @'||to_char(l_line)||'  Sql Err is '|| sqlerrm(sqlcode);
8893      raise msl_error;
8894 end check_select_flg_ses;
8895 
8896 
8897 END GHR_MSL_PKG;