DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSP_LABOR_DIST

Source


1 PACKAGE BODY PSP_LABOR_DIST as
2 /* $Header: PSPLDCDB.pls 120.33.12010000.4 2008/10/17 07:48:08 aniagarw ship $ */
3 
4 g_dist_line_id		NUMBER;
5 /* Following variables are added for bug 2374680 */
6 g_assignment_number     VARCHAR2(30);
7 g_employee_number       VARCHAR2(30);
8 g_gl_effective_date       date;  -- introduced for 2663344
9 
10 --	Introduced the following for bug fix 2916848
11 g_precision	NUMBER := 2; -- Assigned a default value of 2 for bug fix 4067668
12 g_ext_precision	NUMBER;
13 --	End of bug fix 2916848
14 
15 g_sub_line_id           integer; --- added for 3813688
16 /* Following procedure is added for bug 2374680. */
17 g_retro_parent_element_id integer; ---- 5090002
18 PROCEDURE Get_assign_number
19           (p_assignment_id                IN  NUMBER,
20            p_payroll_start_date           IN  DATE,
21            p_assignment_number            OUT NOCOPY VARCHAR2,
22            p_employee_number              OUT NOCOPY VARCHAR2 ) IS
23 
24   CURSOR assign_num_cur IS
25     SELECT paf.assignment_number,
26      ppf.employee_number
27      FROM
28      per_assignments_f paf,per_people_f ppf
29      WHERE paf.assignment_id =p_assignment_id
30      AND   paf.person_id =ppf.person_id
31      and   paf.assignment_type = 'E'
32      AND   p_payroll_start_date between paf.effective_start_date and paf.effective_end_date
33      AND  p_payroll_start_date between ppf.effective_start_date and ppf.effective_end_date;
34 
35 BEGIN
36     OPEN assign_num_cur;
37     FETCH assign_num_cur INTO p_assignment_number,p_employee_number;
38     CLOSE assign_num_cur;
39 
40 END get_assign_number;
41 
42 ------------------------- M A I N    P R O C E D U R E -------------------------------
43 
44  PROCEDURE create_lines (errbuf           	OUT NOCOPY VARCHAR2,
45                          retcode          	OUT NOCOPY VARCHAR2,
46                          p_source_type     	IN VARCHAR2,
47                          p_source_code     	IN VARCHAR2,
48 			 p_payroll_id		IN NUMBER,
49                          p_time_period_id  	IN NUMBER,
50                          p_batch_name      	IN VARCHAR2,
51 			 p_business_group_id	IN NUMBER,
52 			 p_set_of_books_id	IN NUMBER,
53                          p_start_asg_id         IN NUMBER,
54                          p_end_asg_id           IN NUMBER) IS
55 
56 
57   --- changed cursor for 5454270
58 CURSOR payroll_control_cur IS
59   SELECT payroll_control_id,
60          source_type,        /* Bug 1874696 Introduced source type */
61 	 currency_code	-- Introduced for bug fix 2916848
62   FROM   psp_payroll_controls
63   WHERE  cdl_payroll_Action_id = g_payroll_action_id;
64 
65 
66 /* Bug 2663344 reverted change done for 1874696,re-introduced per_time_periods */
67   CURSOR payroll_cur(P_PAYROLL_CONTROL_ID  IN  NUMBER) IS
68   SELECT ptp.end_date,           --- added for 2663344
69          ppl.payroll_line_id,
70          ppl.assignment_id,
71          ppl.element_type_id,
72          ppl.dr_cr_flag,
73          nvl(ppl.accounting_date, ppl.effective_Date) effective_date,
74          ppsl.payroll_sub_line_id,
75          ppsl.sub_line_start_date,
76          ppsl.sub_line_end_date,
77          ppl.cost_id,  --- 5090002
78 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute_category, NULL) attribute_category,	-- Introduced DFF columns for bug fix 2908859
79 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute1, NULL) attribute1,
80 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute2, NULL) attribute2,
81 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute3, NULL) attribute3,
82 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute4, NULL) attribute4,
83 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute5, NULL) attribute5,
84 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute6, NULL) attribute6,
85 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute7, NULL) attribute7,
86 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute8, NULL) attribute8,
87 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute9, NULL) attribute9,
88 	DECODE(g_dff_grouping_option, 'Y', ppsl.attribute10, NULL) attribute10,
89          round(ppsl.daily_rate, g_ext_precision) daily_rate,  -- Get only 2 decimal places Modified to currency extended precision for bug fix 2916848
90          round(ppsl.pay_amount, g_precision) pay_amount,	-- Bug 2916848: Modified to currency precision (from 2)
91          ppl.person_id,
92          ppl.payroll_action_type,
93 	or_gl_code_combination_id,
94 	or_project_id,
95 	or_task_id,
96 	or_award_id,
97 	or_expenditure_org_id,
98 	or_expenditure_type
99   FROM   psp_payroll_lines ppl,
100          psp_payroll_sub_lines ppsl,
101          per_time_periods ptp,
102          psp_payroll_controls ppc
103   WHERE  ppl.payroll_line_id = ppsl.payroll_line_id
104   AND    ppl.status_code = 'N'
105   AND    ppsl.pay_amount <> 0
106   AND    ppl.payroll_control_id = p_payroll_control_id
107   AND    ppc.time_period_id = ptp.time_period_id
108   AND    ppc.payroll_control_id = ppl.payroll_control_id
109   AND    ppl.assignment_id between p_start_asg_id and p_end_asg_id
110   ORDER BY ppl.person_id,ppl.assignment_id,ppl.payroll_line_id, ppl.element_type_id;
111 
112 
113   l_org_def_labor_schedule   VARCHAR2(3)  := psp_general.get_specific_profile('PSP_DEFAULT_SCHEDULE');
114   l_org_def_account          VARCHAR2(3)  := psp_general.get_specific_profile('PSP_DEFAULT_ACCOUNT');
115   --
116   l_element_type_id          NUMBER(9);
117   l_payroll_sub_line_id      NUMBER(10);
118   l_sub_line_start_date      DATE;
119   l_sub_line_end_date        DATE;
120   l_daily_rate               NUMBER;
121   l_payroll_start_date       DATE;
122   l_proc_executed            VARCHAR2(10);
123   l_batch_count              NUMBER  := 0;
124   --
125   l_return_status            VARCHAR2(1);
126   l_msg_count                NUMBER;
127   l_msg_data                 VARCHAR2(2000);
128   l_msg_index_out            NUMBER;
129   --
130   l_dist_message             VARCHAR2(200);
131   --
132   payroll_control_rec		payroll_control_cur%ROWTYPE;
133   payroll_rec			payroll_cur%ROWTYPE;
134   l_total_dist_dr_amount	NUMBER := 0;
135   l_total_dist_cr_amount	NUMBER := 0;
136   l_sub_line_dist_amount	NUMBER := 0;
137   l_effective_date		DATE;
138   -- exception corresponding to ORA-000054
139   RECORD_ALREADY_LOCKED		EXCEPTION;
140   EXCESS_SALARY_FOUND           EXCEPTION;
141   PRAGMA EXCEPTION_INIT (RECORD_ALREADY_LOCKED, -54);
142   l_dummy_id			NUMBER(10);
143   l_no_business_days		NUMBER;
144 ---
145   l_excess_sal                  VARCHAR2(12);
146   l_emp_name                    VARCHAR2(30);
147   l_source_type_desc            VARCHAR2(15);
148   l_sub_start_dt                VARCHAR2(12);
149   l_sub_end_dt                  VARCHAR2(12);
150   l_total_dr_pay_amount		number := 0;
151   l_total_cr_pay_amount		number := 0;
152   l_last_working_date		DATE;
153   l_count                       integer;
154   l_prev_payroll_line_id        integer;   --- 5090002
155 
156   cursor check_adj_exists is
157   select count(1)
158     from psp_adjustment_lines_history
159    where assignment_id = payroll_rec.assignment_id
160      and distribution_date = l_payroll_start_date
161      and adjustment_batch_name is null
162      and reversal_entry_flag is null
163      and element_type_id = payroll_rec.element_type_id
164      and original_line_flag = 'N';
165   cursor get_adjusted_percentages is
166   select project_id,
167          task_id,
168          award_id,
169          expenditure_type,
170          expenditure_organization_id,
171          gl_code_combination_id,
172          sum(decode(dr_Cr_Flag, 'D', distribution_amount, - distribution_amount)) sum_dist_amount,
173           attribute_category,
174                   attribute1,
175                   attribute2,
176                   attribute3,
177                   attribute4,
178                   attribute5,
179                   attribute6,
180                   attribute7,
181                   attribute8,
182                   attribute9,
183                   attribute10
184     from ( select psl.project_id,
185                   psl.task_id,
186                   psl.award_id,
187                   psl.expenditure_organization_id,
188                   psl.expenditure_type,
189                   psl.gl_code_combination_id,
190                   pdl.distribution_amount,
191                   psl.dr_Cr_flag,
192                   pdl.attribute_category,
193                   pdl.attribute1,
194                   pdl.attribute2,
195                   pdl.attribute3,
196                   pdl.attribute4,
197                   pdl.attribute5,
198                   pdl.attribute6,
199                   pdl.attribute7,
200                   pdl.attribute8,
201                   pdl.attribute9,
202                   pdl.attribute10
203              from psp_summary_lines psl,
204                   psp_distribution_lines_history pdl,
205                   psp_payroll_lines ppl,
206                   psp_payroll_sub_lines ppsl
207             where pdl.summary_line_id = psl.summary_line_id
208               and pdl.reversal_entry_flag is null
209               and pdl.adjustment_batch_name is null
210               and psl.person_id = payroll_rec.person_id
211               and psl.assignment_id = payroll_rec.assignment_id
212               and pdl.distribution_date = l_payroll_start_date
213               and pdl.payroll_sub_line_id = ppsl.payroll_sub_line_id
214               and ppsl.payroll_line_id = ppl.payroll_line_id
215               and ppl.element_type_id = payroll_rec.element_type_id
216             union all
217            select project_id,
218                   task_id,
219                   award_id,
220                   expenditure_organization_id,
221                   expenditure_type,
222                   gl_code_combination_id,
223                   distribution_amount,
224                   dr_Cr_flag,
225                   attribute_category,
226                   attribute1,
227                   attribute2,
228                   attribute3,
229                   attribute4,
230                   attribute5,
231                   attribute6,
232                   attribute7,
233                   attribute8,
234                   attribute9,
235                   attribute10
236              from psp_adjustment_lines_history
237             where reversal_entry_flag is null
238               and adjustment_batch_name is null
239               and assignment_id = payroll_rec.assignment_id
240               and distribution_date = l_payroll_start_date
241               and original_line_flag = 'N'
242               and element_type_id = payroll_rec.element_type_id)
243       group by project_id,
244                task_id,
245                award_id,
246                expenditure_organization_id,
247                expenditure_type,
248                gl_code_combination_id,
249                 attribute_category,
250                   attribute1,
251                   attribute2,
252                   attribute3,
253                   attribute4,
254                   attribute5,
255                   attribute6,
256                   attribute7,
257                   attribute8,
258                   attribute9,
259                   attribute10;
260 TYPE v_num_array IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
261 TYPE v_num2_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
262 TYPE v_char_array IS TABLE OF varchar2(150) INDEX BY BINARY_INTEGER;
263     project_id_array  v_num_array;
264     award_id_array v_num_array;
265     task_id_array v_num_array;
266     exp_org_array v_num_array;
267     gl_ccid_array v_num_array;
268     exp_type_array v_char_array;
269     adj_amount_array v_num2_array;
270     adj_percent_array v_num_array;
271     attribute_category_array v_char_array;
272     attribute1_array v_char_array;
273     attribute2_array v_char_array;
274    attribute3_array v_char_array;
275    attribute4_array v_char_array;
276    attribute5_array v_char_array;
277    attribute6_array v_char_array;
278    attribute7_array v_char_array;
279    attribute8_array v_char_array;
280    attribute9_array v_char_array;
281    attribute10_array v_char_array;
282     l_adj_dff_flag varchar2(1);
283     l_sum_adj_amount number;
284     l_tot_dist_amount number;
285     l_dist_amount number;
286     l_gl_project_flag varchar2(1);
287     l_action_parameter_group   VARCHAR2(30)  := psp_general.get_specific_profile('ACTION_PARAMETER_GROUPS'); --6661707
288 
289     cursor get_tgl_revb_acc_date  is
290     select nvl(parameter_value, 'P') parameter_value
291     from PAY_ACTION_PARAMETER_VALUES
292     where parameter_name = 'TGL_REVB_ACC_DATE'
293     and action_parameter_group_id = l_action_parameter_group;
294 
295     l_tgl_revb_acc_date varchar2(10);
296 
297  BEGIN
298   hr_utility.trace('CDL procedure begin');
299   g_msg := '';
300   g_error_api_path := '';
301 
302    hr_utility.trace('CDL procedure: g_cap_element_set_id = '||g_cap_element_set_id);
303    hr_utility.trace('CDL procedure: g_salary_cap_option='|| g_salary_cap_option);
304 
305    open get_tgl_revb_acc_date;
306    fetch get_tgl_revb_acc_date into l_TGL_REVB_ACC_DATE;
307    if get_tgl_revb_acc_date%NOTFOUND then
308      l_TGL_REVB_ACC_DATE := 'P';
309    end if;
310    close get_tgl_revb_acc_date;
311 
312   fnd_msg_pub.initialize;
313   OPEN payroll_control_cur;
314   LOOP
315    l_total_dr_pay_amount		:= 0;
316    l_total_cr_pay_amount		:= 0;
317    FETCH payroll_control_cur INTO payroll_control_rec;
318    IF payroll_control_cur%NOTFOUND THEN
319     CLOSE payroll_control_cur;
320     EXIT;
321    END IF;
322    BEGIN
323 
324 --	Introduced the following for bug fix 2916848
325 	psp_general.get_currency_precision(payroll_control_rec.currency_code, g_precision, g_ext_precision);
326 --	End of bug fix 2916848
327 
328     OPEN  payroll_cur(payroll_control_rec.payroll_control_id);
329    LOOP
330      l_sub_line_dist_amount := 0;
331      g_tot_dist_amount := 0;
332      FETCH payroll_cur INTO payroll_rec;
333      hr_utility.trace('CDL procedure: payroll_rec='|| payroll_control_rec.payroll_control_id);
334     --#fnd_file.put_line(fnd_file.log,'asg id, payroll_sub_line_id ='|| payroll_Rec.assignment_id||','||payroll_rec.payroll_sub_line_id);
335 
336      IF payroll_cur%NOTFOUND
337      THEN
338 	-- dbms_output.put_line('in ayroll_cur');
339         CLOSE payroll_cur;
340         EXIT;
341      END IF;
342 
343      --- 5090002 get retro element parent
344      if nvl(payroll_rec.payroll_action_type,'X') = 'L' then
345         if nvl(l_prev_payroll_line_id, -999) <> payroll_rec.payroll_line_id then
346              l_prev_payroll_line_id := payroll_rec.payroll_line_id;
347               g_retro_parent_element_id := get_retro_parent_element_id(payroll_rec.cost_id);
348         end if;
349      else
350         if g_retro_parent_element_id is not null then
351            g_retro_parent_element_id := null;
352          end if;
353      end if;
354 
355      l_payroll_sub_line_id	:= payroll_rec.payroll_sub_line_id;
356      ---
357     l_effective_date := payroll_rec.effective_date;
358     if payroll_control_rec.source_type = 'N' then
359       if g_use_eff_date = 'Y' then
360          null;
361       else
362          l_effective_date := payroll_rec.end_date;
363       end if;
364     end if;
365     g_gl_effective_date := l_effective_date;
366 
367      l_payroll_start_date := payroll_rec.sub_line_start_date;
368      -- FInd out NOCOPY the last working date for a period
369      l_last_working_date := psp_general.last_working_date(payroll_rec.sub_line_end_date);
370 
371 
372      IF payroll_rec.daily_rate = 0 THEN
373        l_no_business_days := psp_general.business_days(payroll_rec.sub_line_start_date,payroll_rec.sub_line_end_date,payroll_rec.assignment_id);
374 	   IF NVL(l_no_business_days,0)=0 THEN
375 	      l_no_business_days := 1;
376 	   END IF;
377        l_daily_rate := round((payroll_rec.pay_amount / l_no_business_days), g_ext_precision);   -- Modified to currency extended precision for bug fix 2916848, 3109943
378         -- 4304623
379         update psp_payroll_sub_lines
380            set daily_rate = l_daily_rate
381          where payroll_sub_line_id = payroll_rec.payroll_sub_line_id;
382      ELSE
383        l_daily_rate  := round(payroll_rec.daily_rate, g_ext_precision); -- Modified to currency extended precision for bug fix 2916848 ,3109943
384 
385      END IF;
386 
387      LOOP
388        -- For each date within each payroll sub-line, find the appropriate schedule hierarchy
389        -- Skip the processing if the date encountered is a Saturday or Sunday
390        /*Bug 5557724: to_char(some_date,'D') returns a number indicating the weekday. However, for a given date, this number
391        returned varies with NLS_TERRITORY. So replaced it with to_char(some_date,'DY') that gives the abbreviated day. */
392 --       IF to_char(l_payroll_start_date, 'DY', 'nls_date_language=english') NOT IN ('SUN', 'SAT')
393          IF (psp_general.business_days(l_payroll_start_date, l_payroll_start_date, payroll_rec.assignment_id) > 0)
394            OR payroll_rec.sub_line_start_date = payroll_rec.sub_line_end_date THEN
395        --For Bug 1994421 : Zero work Days build :Introduced the above OR condtion
396 
397           -- changed the if condn for 2663344
398           if payroll_control_rec.source_type <> 'N' OR nvl(g_use_eff_date,'N') <> 'Y' then
399             l_effective_date := l_payroll_start_date;
400           end if;
401 
402           if payroll_rec.payroll_action_type <> 'R' and l_tgl_revb_acc_date = 'C' then
403             l_effective_date := payroll_rec.effective_date;
404           end if;
405           l_count := 0;
406           if payroll_rec.payroll_action_type <> 'R' then  --- only for non regular runs
407            hr_utility.trace('l_payroll_action_type ='||payroll_rec.payroll_action_type||'start date, assig id ='|| l_payroll_start_date||','||payroll_rec.assignment_id);
408                open check_adj_exists;
409                fetch check_adj_exists into l_count;
410                close check_adj_exists;
411            end if;
412 
413            -- Introduced BEGIN, EXCEPTION, END for bug 7041286
414           BEGIN
415           fnd_file.put_line (fnd_file.LOG,'Entering begin inside loop3');
416 
417            if payroll_rec.payroll_action_type <> 'R' and l_count > 0 then  --- only for non regular runs and pre-adjusted
418                     hr_utility.trace('l_count = '||l_count);
419                     open get_adjusted_percentages;
420                     Fetch get_adjusted_percentages bulk collect into project_id_array,
421                                                              Task_id_array,
422                                                             award_id_array,
423                                                             exp_type_array,
424                                                              exp_org_array,
425                                                              gl_ccid_array,
426                                                              adj_amount_array,
427                                                              attribute_category_array ,
428                                                              attribute1_array ,
429                                                              attribute2_array ,
430                                                             attribute3_array ,
431                                                             attribute4_array ,
432                                                             attribute5_array ,
433                                                             attribute6_array ,
434                                                             attribute7_array ,
435                                                             attribute8_array ,
436                                                             attribute9_array ,
437                                                             attribute10_array;
438                      close get_adjusted_percentages;
439                      begin
440                         if project_id_array.count = 0 and gl_ccid_array.count = 0 then
441                                 raise fnd_api.g_exc_unexpected_error;
442                         end if;
443                      exception
444                      when others then
445                              fnd_msg_pub.add_exc_msg('PSP_LABOR_DIST','ADJUSTED_PERCENTAGES');
446                              raise;
447                      end;
448                      hr_utility.trace('Close get_adjusted_percentages array_size='||project_id_array.count);
449                      l_sum_adj_amount := 0;
450                      for I in 1..adj_amount_array.count
451                      loop
452                        l_sum_adj_amount := l_sum_adj_amount + adj_amount_array(i);
453                      end loop;
454                      for I in 1..adj_amount_array.count
455                      loop
456                         adj_percent_array(i) := adj_amount_array(i) * 100 / l_sum_adj_amount;
457                      end loop;
458                      hr_utility.trace('adj_amount_array-100');
459                 -----create distributions based on this array.
460                 L_tot_dist_amount :=  0;
461                 for I in 1..adj_amount_array.count
462                 loop
463                  hr_utility.trace('Entered array loop.. adj array');
464                 if project_id_array(i) is null then
465                     l_gl_project_flag :='G';
466                     if nvl(g_use_eff_date, 'N') <> 'Y' then
467                         l_effective_date := g_gl_effective_date;
468                     end if;
469                 else
470                    l_gl_project_flag := 'P';
471                 end if;
472                 if i < adj_amount_array.count then
473                     l_dist_amount := round((l_daily_rate * adj_percent_array(i)/100), g_precision);
474                     hr_utility.trace('l_daily_rate, l_dist_amount, adj_percent ='|| l_daily_rate||','||l_dist_amount||','||adj_percent_array(i));
475                     l_tot_dist_amount := l_tot_dist_amount + l_dist_amount;
476                 else   --- last line will have the remaining amount.
477                    l_dist_amount :=l_daily_rate - l_tot_dist_amount;
478                    l_dist_amount := round(l_dist_amount, g_precision);
479                 end if;
480                 g_tot_dist_amount := g_tot_dist_amount + l_dist_amount;
481       if (      attribute_category_array(i) is not null or
482                 attribute1_array(i) is not null or
483                 attribute2_array(i) is not null or
484                 attribute3_array(i) is not null or
485                 attribute4_array(i) is not null or
486                 attribute5_array(i) is not null or
487                 attribute6_array(i) is not null or
488                 attribute7_array(i) is not null or
489                 attribute8_array(i) is not null or
490                 attribute9_array(i) is not null or
491                 attribute10_array(i) is not null) then
492             l_adj_dff_flag := 'Y';
493         else
494             l_adj_dff_flag := 'N';
495         end if;
496         INSERT INTO PSP_DISTRIBUTION_LINES(
497                 DISTRIBUTION_LINE_ID,
498                 PAYROLL_SUB_LINE_ID,
499                 DISTRIBUTION_DATE,
500                 EFFECTIVE_DATE,
501                 DISTRIBUTION_AMOUNT,
502                 STATUS_CODE,
503                 GL_PROJECT_FLAG,
504                 business_group_id,
505                 set_of_books_id,
506                 attribute_category,                     -- Introduced DFF columns for bug fix 2908859
507                 attribute1,
508                 attribute2,
509                 attribute3,
510                 attribute4,
511                 attribute5,
512                 attribute6,
513                 attribute7,
514                 attribute8,
515                 attribute9,
516                 attribute10,
517                 adj_account_flag,
518                 CAP_EXCESS_GLCCID ,
519                 CAP_EXCESS_PROJECT_ID,
520                 CAP_EXCESS_AWARD_ID,
521                 CAP_EXCESS_TASK_ID,
522                 CAP_EXCESS_EXP_ORG_ID,
523                 CAP_EXCESS_EXP_TYPE)
524         VALUES(
525                 PSP_DISTRIBUTION_LINES_S.NEXTVAL,
526                 payroll_rec.PAYROLL_SUB_LINE_ID,
527                 L_payroll_start_DATE,
528                 L_EFFECTIVE_DATE,
529                 L_DIST_AMOUNT,
530                 'N',
531                 L_GL_PROJECT_FLAG,
532                 P_BUSINESS_GROUP_ID,
533                 P_SET_OF_BOOKS_ID,
534                 decode(l_adj_dff_flag,'Y', attribute_category_array(i), payroll_rec.attribute_category),
535                 decode(l_adj_dff_flag,'Y', attribute1_array(i), payroll_rec.attribute1),
536                 decode(l_adj_dff_flag,'Y', attribute2_array(i), payroll_rec.attribute2),
537                 decode(l_adj_dff_flag,'Y', attribute3_array(i), payroll_rec.attribute3),
538                 decode(l_adj_dff_flag,'Y', attribute4_array(i), payroll_rec.attribute4),
539                 decode(l_adj_dff_flag,'Y', attribute5_array(i), payroll_rec.attribute5),
540                 decode(l_adj_dff_flag,'Y', attribute6_array(i), payroll_rec.attribute6),
541                 decode(l_adj_dff_flag,'Y', attribute7_array(i), payroll_rec.attribute7),
542                 decode(l_adj_dff_flag,'Y', attribute8_array(i), payroll_rec.attribute8),
543                 decode(l_adj_dff_flag,'Y', attribute9_array(i), payroll_rec.attribute9),
544                 decode(l_adj_dff_flag,'Y', attribute10_array(i), payroll_rec.attribute10),
545                 'Y',
546                 gl_ccid_array(i),
547                 project_id_array(i),
548                 award_id_array(i),
549                 Task_id_array(i),
550                 exp_org_array(i),
551                 exp_type_array(i));
552 
553              end loop;
554 
555                else
556         -- dbms_output.put_line('before get dist lines');
557            hr_utility.trace('Calling Get_distribution_lines');
558           Get_Distribution_Lines
559                       (p_proc_executed       => l_proc_executed,
560                        p_person_id           => payroll_rec.person_id,
561                        p_sub_line_id         => payroll_rec.payroll_sub_line_id,
562                        p_assignment_id       => payroll_rec.assignment_id,
563                        p_element_type_id     => payroll_rec.element_type_id,
564                        p_payroll_start_date  => l_payroll_start_date ,
565                        p_daily_rate          => l_daily_rate,
566                        p_effective_date      => l_effective_date,
567                        p_mode                => 'I',
568 		       p_business_group_id   => p_business_group_id,
569 		       p_set_of_books_id     => p_set_of_books_id,
570 			p_attribute_category	=>	payroll_rec.attribute_category,		-- Introduced DFF columns for bug fix 2908859
571 			p_attribute1		=>	payroll_rec.attribute1,
572 			p_attribute2		=>	payroll_rec.attribute2,
573 			p_attribute3		=>	payroll_rec.attribute3,
574 			p_attribute4		=>	payroll_rec.attribute4,
575 			p_attribute5		=>	payroll_rec.attribute5,
576 			p_attribute6		=>	payroll_rec.attribute6,
577 			p_attribute7		=>	payroll_rec.attribute7,
578 			p_attribute8		=>	payroll_rec.attribute8,
579 			p_attribute9		=>	payroll_rec.attribute9,
580 			p_attribute10		=>	payroll_rec.attribute10,
581 			p_or_gl_ccid		=>	payroll_rec.or_gl_code_combination_id,
582 			p_or_project_id		=>	payroll_rec.or_project_id,
583 			p_or_task_id		=>	payroll_rec.or_task_id,
584 			p_or_award_id		=>	payroll_rec.or_award_id,
585 			p_or_expenditure_org_id	=>	payroll_rec.or_expenditure_org_id,
586 			p_or_expenditure_type	=>	payroll_rec.or_expenditure_type,
587                        p_return_status       => l_return_status);
588 
589 	   end if;
590 
591           EXCEPTION   ---- Introduced BEGIN, EXCEPTION, END for bug 7041286
592 
593 	  	WHEN ZERO_DIVIDE
594 	  	THEN
595 	  	    fnd_file.put_line (fnd_file.LOG,
596 	                           'Calling Get_distribution_lines for sub line id - '
597 	                              || payroll_rec.payroll_sub_line_id );
598 
599 	            get_distribution_lines (
600 	               p_proc_executed=> l_proc_executed,
601 	               p_person_id=> payroll_rec.person_id,
602 	               p_sub_line_id=> payroll_rec.payroll_sub_line_id,
603 	               p_assignment_id=> payroll_rec.assignment_id,
604 	               p_element_type_id=> payroll_rec.element_type_id,
605 	               p_payroll_start_date=> l_payroll_start_date,
606 	               p_daily_rate=> l_daily_rate,
607 	               p_effective_date=> l_effective_date,
608 	               p_mode=> 'I',
609 	               p_business_group_id=> p_business_group_id,
610 	               p_set_of_books_id=> p_set_of_books_id,
611 	               p_attribute_category=> payroll_rec.attribute_category,
612 	               p_attribute1=> payroll_rec.attribute1,
613 	               p_attribute2=> payroll_rec.attribute2,
614 	               p_attribute3=> payroll_rec.attribute3,
615 	               p_attribute4=> payroll_rec.attribute4,
616 	               p_attribute5=> payroll_rec.attribute5,
617 	               p_attribute6=> payroll_rec.attribute6,
618 	               p_attribute7=> payroll_rec.attribute7,
619 	               p_attribute8=> payroll_rec.attribute8,
620 	               p_attribute9=> payroll_rec.attribute9,
621 	               p_attribute10=> payroll_rec.attribute10,
622 	               p_or_gl_ccid=> payroll_rec.or_gl_code_combination_id,
623 	               p_or_project_id=> payroll_rec.or_project_id,
624 	               p_or_task_id=> payroll_rec.or_task_id,
625 	               p_or_award_id=> payroll_rec.or_award_id,
626 	               p_or_expenditure_org_id=> payroll_rec.or_expenditure_org_id,
627 	               p_or_expenditure_type=> payroll_rec.or_expenditure_type,
628 	               p_return_status=> l_return_status
629 	            );
630 
631 
632 
633 	            WHEN OTHERS THEN
634       			ROLLBACK;
635 
636       			fnd_msg_pub.add_exc_msg('PSP_LABOR_DIST','CREATE_LINES2');
637        			fnd_message.set_name('PSP','PSP_LD_BATCH_DISTRIBUTED');
638       			fnd_message.set_token('NUMB_BATCHES',l_batch_count);
639       			fnd_msg_pub.add;
640       			retcode := 2;
641       			psp_message_s.print_error(p_mode => FND_FILE.LOG,
642 			    p_print_header => FND_API.G_TRUE);
643       			raise;
644           END;    -- Introduced BEGIN, EXCEPTION, END for bug 7041286
645 
646            IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
647                --dbms_output.put_line('error in get dist line sproc ');
648                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
649            END IF;
650 
651 
652           l_sub_line_dist_amount := round((l_sub_line_dist_amount + l_daily_rate), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
653 
654         END IF;             -- ENDIF to_char(l_payroll_start_date, 'D') IN (1, 7)
655        l_payroll_start_date := l_payroll_start_date + 1;
656 
657        IF trunc(l_payroll_start_date) = trunc(l_last_working_date) THEN
658           l_daily_rate := payroll_rec.pay_amount - g_tot_dist_amount;
659        ELSIF l_payroll_start_date > payroll_rec.sub_line_end_date THEN
660          EXIT;
661        END IF;
662      END LOOP;
663 
664      if payroll_rec.pay_amount <> g_tot_dist_amount
665      then
666         UPDATE psp_distribution_lines
667         SET distribution_amount = distribution_amount +
668                                   (payroll_rec.pay_amount - g_tot_dist_amount)
669         WHERE distribution_line_id = (select max(distribution_line_id)    -- 2470954 added this SQL
670                                       from psp_distribution_lines
671                                        where payroll_rec.payroll_sub_line_id = payroll_sub_line_id);
672       end if;
673 	-- total of pay_amout to check at the end for the
674 	-- difference amount
675 	if payroll_rec.dr_cr_flag = 'D'
676 	then
677 		l_total_dr_pay_amount := l_total_dr_pay_amount +
678 			payroll_rec.pay_amount;
679 	elsif payroll_rec.dr_cr_flag = 'C'
680 	then
681 		l_total_cr_pay_amount := l_total_cr_pay_amount +
682 			payroll_rec.pay_amount;
683 	end if;
684 	-- dbms_output.put_line('after update ');
685      -- END IF;
686    END LOOP;
687 --- changed the if condition to use new globals for 5080403
688  if g_asg_autopop = 'Y' or g_asg_element_autopop = 'Y' or g_asg_ele_group_autopop = 'Y' then
689          update_dist_schedule_autopop(p_payroll_control_id =>payroll_control_rec.payroll_control_id, p_business_group_id=>p_business_group_id, p_set_of_books_id=>p_Set_of_books_id,p_start_asg_id=>p_start_asg_id, p_end_asg_id=>p_end_asg_id,
690                                 p_return_Status =>l_return_status);
691   end if;
692 
693           IF l_org_def_labor_schedule = 'Y' and g_org_schedule_autopop = 'Y' THEN
694 
695              update_dist_odls_autopop(p_payroll_control_id => payroll_control_rec.payroll_control_id, p_business_group_id=>p_business_group_id, p_set_of_books_id =>p_set_of_books_id,p_start_asg_id=>p_start_asg_id, p_end_asg_id=>p_end_asg_id,
696                                        p_return_status => l_return_status);
697           END IF;
698 
699 
700      hr_utility.trace(' CDL --> create lines --> before call to apply_salary_cap, g_salary_cap = '||g_salary_cap_option);
701      -- if Salary Cap is set to Y then call Apply_salary_cap. Enh 4304623
702      If g_salary_cap_option = 'Y' then
703          apply_salary_cap(payroll_control_rec.payroll_control_id,
704                           payroll_control_rec.currency_code,
705                           p_business_group_id,
706                           p_Set_of_books_id,
707                           p_start_asg_id,
708                           p_end_asg_id);
709 
710          --- added for 4304623
711           if g_excess_account_autopop = 'Y' then
712          excess_account_autopop( payroll_control_rec.payroll_control_id,
713                                  p_business_group_id,
714                                  p_set_of_books_id,
715                                  p_start_asg_id,
716                                  p_end_asg_id,
717                                  l_return_status);
718           end if;
719      End if;
720          --- autopop calls for global element, default account, suspense account .. 5080403
721           if g_global_element_autopop = 'Y' then
722                generic_account_autopop( payroll_control_rec.payroll_control_id,
723                                        p_business_group_id,
724                                        p_set_of_books_id,
725                                        p_start_asg_id,
726                                        p_end_asg_id,
727                                        'GLOBAL_ELEMENT');
728           end if;
729           if g_default_account_autopop = 'Y' and l_org_def_account = 'Y' then
730                generic_account_autopop( payroll_control_rec.payroll_control_id,
731                                        p_business_group_id,
732                                        p_set_of_books_id,
733                                        p_start_asg_id,
734                                        p_end_asg_id,
735                                        'DEFAULT_ACCOUNT');
736           end if;
737           if g_suspense_account_autopop = 'Y' then
738                generic_account_autopop( payroll_control_rec.payroll_control_id,
739                                        p_business_group_id,
740                                        p_set_of_books_id,
741                                        p_start_asg_id,
742                                        p_end_asg_id,
743                                        'SUSPENSE');
744           end if;
745 
746    l_batch_count := l_batch_count + 1;
747    --
748    EXCEPTION
749     WHEN RECORD_ALREADY_LOCKED THEN
750       NULL;
751    END;
752 
753   END LOOP;
754 
755   fnd_message.set_name('PSP','PSP_LD_BATCH_DISTRIBUTED');
756   fnd_message.set_token('NUMB_BATCHES',l_batch_count);
757   -- l_dist_message := fnd_message.get;
758   -- return success to the concurrent program
759   -- errbuf  := SUBSTR(g_msg || chr(10) || l_dist_message,1,230);
760   retcode := 0;
761   /*********************************************************************
762   ** Added by Bijoy - 08/06/99 to display error in consurrent log
763   *******************************************************************/
764   fnd_msg_pub.add;
765   psp_message_s.print_success;
766 
767   EXCEPTION
768 WHEN EXCESS_SALARY_FOUND THEN
769       ROLLBACK;
770       g_error_api_path := SUBSTR('CREATE_LINES 1:'||g_error_api_path,1,230);
771       fnd_message.set_name('PSP','PSP_EXCESS_SALARY_FOUND');
772       fnd_message.set_token('EXCESS_SAL',l_excess_sal);
773       fnd_message.set_token('EMP_NAME',l_emp_name);
774       fnd_message.set_token('SOURCE_DESC',l_source_type_desc);
775       fnd_message.set_token('START_DATE',l_sub_start_dt);
776       fnd_message.set_token('END_DATE',l_sub_end_dt);
777   /*********************************************************************
778   ** Added by Bijoy - 08/06/99 to display error in consurrent log
779   *******************************************************************/
780       fnd_msg_pub.add;
781       retcode := 2;
782       psp_message_s.print_error(p_mode => FND_FILE.LOG,
783 			    p_print_header => FND_API.G_TRUE);
784       -- l_dist_message := fnd_message.get;
785 
786       -- errbuf := SUBSTR(g_msg || chr(10) || l_msg_data || chr(10) || l_dist_message||chr(10)||chr(10)||g_error_api_path,1,230);
787         raise;    --- for nih sal cap 4304623
788        WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
789       ROLLBACK;
790   /*********************************************************************
791   ** Added by Bijoy - 08/06/99 to display error in consurrent log
792   *******************************************************************/
793       g_error_api_path := SUBSTR('CREATE_LINES:'||g_error_api_path,1,230);
794       /* fnd_msg_pub.get(p_msg_index     =>  FND_MSG_PUB.G_FIRST,
795                       p_encoded       =>  FND_API.G_FALSE,
796                       p_data          =>  l_msg_data,
797                       p_msg_index_out =>  l_msg_count); */
798 
799       fnd_message.set_name('PSP','PSP_LD_BATCH_DISTRIBUTED');
800       fnd_message.set_token('NUMB_BATCHES',l_batch_count);
801       fnd_msg_pub.add;
802       -- l_dist_message := fnd_message.get;
803 
804       -- errbuf := SUBSTR(g_msg || chr(10) || l_msg_data || chr(10) || l_dist_message||chr(10)||chr(10)||g_error_api_path,1,230);
805       retcode := 2;
806       psp_message_s.print_error(p_mode => FND_FILE.LOG,
807 			    p_print_header => FND_API.G_TRUE);
808 
809         raise;    --- for nih sal cap 4304623
810     WHEN OTHERS THEN
811       ROLLBACK;
812       -- g_error_api_path := SUBSTR('CREATE_LINES:'||g_error_api_path,1,230);
813       fnd_msg_pub.add_exc_msg('PSP_LABOR_DIST','CREATE_LINES2');
814       /* fnd_msg_pub.get(p_msg_index     =>  FND_MSG_PUB.G_FIRST,
815                       p_encoded       =>  FND_API.G_FALSE,
816                       p_data          =>  l_msg_data,
817                       p_msg_index_out =>  l_msg_count); */
818 
819       fnd_message.set_name('PSP','PSP_LD_BATCH_DISTRIBUTED');
820       fnd_message.set_token('NUMB_BATCHES',l_batch_count);
821       fnd_msg_pub.add;
822       -- l_dist_message := fnd_message.get;
823 
824       /* errbuf := SUBSTR(g_msg || chr(10) || l_msg_data || chr(10) || l_dist_message||chr(10)||chr(10)||g_error_api_path,1,230); */
825       retcode := 2;
826       psp_message_s.print_error(p_mode => FND_FILE.LOG,
827 			    p_print_header => FND_API.G_TRUE);
828         raise;    --- for nih sal cap 4304623
829   END;
830 
831 ---------------------- G L O B A L   E A R N I N G S   E L E M E N T -----------------------
832 
833  PROCEDURE global_earnings_element(p_proc_executed       OUT NOCOPY VARCHAR2,
834                                    p_person_id           IN  NUMBER,
835                                    p_sub_line_id         IN  NUMBER,
836                                    p_assignment_id       IN  NUMBER,
837                                    p_element_type_id     IN  NUMBER,
838                                    p_payroll_start_date  IN  DATE,
839                                    p_daily_rate          IN  NUMBER,
840                                    p_org_def_account     IN  VARCHAR2,
841                                    p_effective_date      IN  DATE,
842                                    p_mode                IN  VARCHAR2 := 'I',
843 				   p_business_group_id	 IN  NUMBER,
844 				   p_set_of_books_id	 IN  NUMBER,
845 				p_attribute_category	IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
846 				p_attribute1		IN	VARCHAR2,
847 				p_attribute2		IN	VARCHAR2,
848 				p_attribute3		IN	VARCHAR2,
849 				p_attribute4		IN	VARCHAR2,
850 				p_attribute5		IN	VARCHAR2,
851 				p_attribute6		IN	VARCHAR2,
852 				p_attribute7		IN	VARCHAR2,
853 				p_attribute8		IN	VARCHAR2,
854 				p_attribute9		IN	VARCHAR2,
855 				p_attribute10		IN	VARCHAR2,
856                                    p_return_status       OUT NOCOPY VARCHAR2) IS
857 
858  CURSOR global_element_cur(P_ELEMENT_TYPE_ID    NUMBER,
859                            P_PAYROLL_START_DATE DATE) IS
860  SELECT element_account_id,
861         peta.gl_code_combination_id,
862         peta.project_id,
863         peta.task_id,
864         peta.award_id,
865         round(peta.percent,2) percent,
866         peta.expenditure_type,
867         peta.expenditure_organization_id,
868         peta.start_date_active,
869         peta.end_date_active,   --- added decode below for 5014193
870 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute_category, peta.attribute_category)) attribute_category,		-- Introduced DFF columns for bug fix 2908859
871 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute1, peta.attribute1)) attribute1,
872 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute2, peta.attribute2)) attribute2,
873 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute3, peta.attribute3)) attribute3,
874 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute4, peta.attribute4)) attribute4,
875 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute5, peta.attribute5)) attribute5,
876 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute6, peta.attribute6)) attribute6,
877 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute7, peta.attribute7)) attribute7,
878 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute8, peta.attribute8)) attribute8,
879 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute9, peta.attribute9)) attribute9,
880 	decode(g_dff_grouping_option, 'Y', NVL(p_attribute10, peta.attribute10)) attribute10
881  FROM   psp_element_type_accounts peta
882  WHERE  business_group_id = p_business_group_id
883  AND    set_of_books_id  = p_set_of_books_id
884  AND    peta.element_type_id = p_element_type_id
885  AND    p_payroll_start_date BETWEEN peta.start_date_active AND
886                                          nvl(peta.end_date_active,p_payroll_start_date) ;
887 
888 
889   l_dist_amount                    NUMBER       := 0;
890   l_tot_dist_amount                NUMBER       := 0;
891   l_bal_dist_amount                NUMBER       := 0;
892   l_tot_percent                    NUMBER       := 0;
893 
894   l_element_account_id             NUMBER(9);
895   l_gl_code_combination_id         NUMBER(15);
896   l_project_id                     NUMBER(15);
897   l_task_id                        NUMBER(15);
898   l_award_id                       NUMBER(15);
899   l_expenditure_type               VARCHAR2(30);
900   l_expenditure_org_id             NUMBER(15);
901   l_schedule_percent               NUMBER;
902   l_effective_start_date           DATE;
903   l_effective_end_date             DATE;
904 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variables for bug fix 2908859
905 	l_attribute1		VARCHAR2(150);
906 	l_attribute2		VARCHAR2(150);
907 	l_attribute3		VARCHAR2(150);
908 	l_attribute4		VARCHAR2(150);
909 	l_attribute5		VARCHAR2(150);
910 	l_attribute6		VARCHAR2(150);
911 	l_attribute7		VARCHAR2(150);
912 	l_attribute8		VARCHAR2(150);
913 	l_attribute9		VARCHAR2(150);
914 	l_attribute10		VARCHAR2(150);
915   x_proc_executed                  VARCHAR2(10) := 'TRUE';
916   l_rec_count                      NUMBER := 0;
917   l_return_status                  VARCHAR2(1);
918   -- l_effective_date                 DATE; Bug 1874696
919   l_gl_project_flag                VARCHAR2(1);
920   l_linkage_status                 VARCHAR2(50);
921   l_patc_status                    VARCHAR2(50);
922   l_billable_flag                  VARCHAR2(1);
923 
924   l_msg_count     NUMBER;
925 
926   l_msg_app       VARCHAR2(2000);
927   l_msg_type      varchar2(2000);
928   l_msg_token1    varchar2(2000);
929   l_msg_token2    varchar2(2000);
930   l_msg_token3    varchar2(2000);
931   --l_award_status  varchar2(50);  -- for bug fix 1931680
932   l_award_status  varchar2(200);
933 
934  BEGIN
935 
936      p_proc_executed := 'TRUE';
937 
938      -- For the payroll date passed to the procedure, check if there is global element
939      -- override. If exists, then fetch the schedule percent and calculate the
940      -- total distribution amount by adding the distribution amount in each of the lines.
941      -- If global element override does not exist,set the p_proc_executed flag as FALSE
942 
943      OPEN global_element_cur(p_element_type_id,p_payroll_start_date);
944      LOOP
945            l_patc_status   := NULL;
946            l_linkage_status:= NULL;
947            l_billable_flag := NULL;
948 	   l_award_status  := NULL;
949 
950            FETCH global_element_cur INTO
951 				l_element_account_id,
952                                 l_gl_code_combination_id,
953   				l_project_id,
954   				l_task_id,
955   				l_award_id,
956   				l_schedule_percent,
957                                 l_expenditure_type,
958                                 l_expenditure_org_id,
959                                 l_effective_start_date,
960                                 l_effective_end_date,
961 				l_attribute_category,
962 				l_attribute1,
963 				l_attribute2,
964 				l_attribute3,
965 				l_attribute4,
966 				l_attribute5,
967 				l_attribute6,
968 				l_attribute7,
969 				l_attribute8,
970 				l_attribute9,
971 				l_attribute10;
972 
973            l_rec_count := l_rec_count + 1;
974            IF global_element_cur%NOTFOUND THEN
975              IF l_rec_count = 1 THEN
976                p_proc_executed := 'FALSE';
977                CLOSE global_element_cur ;
978                RETURN;
979              ELSE
980                CLOSE global_element_cur ;
981                EXIT;
982              END IF;
983            END IF;
984 
985            l_tot_percent := l_tot_percent + l_schedule_percent;
986            IF l_tot_percent <= 100 THEN
987              l_dist_amount := round((p_daily_rate * l_schedule_percent/100), g_precision); 	-- Bug 2916848: Modified to currency precision (from 2)
988            -- ELSIF l_tot_percent = 100 THEN
989            --  l_dist_amount := round((p_daily_rate - l_tot_dist_amount),2);
990            ELSIF l_tot_percent > 100 THEN
991 	     	Get_assign_number(p_assignment_id
992 			      ,p_payroll_start_date
993 			      ,g_assignment_number
994 			      ,g_employee_number);--Bug 2374680
995              	fnd_message.set_name('PSP','PSP_LD_PERCENT_GREATER_100');
996              	fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
997 --          	fnd_message.set_token('ASSIGNMENT_ID',p_assignment_id); --Commented for bug 2374680
998             	 /* Added assignment_number and employee_number inplace of assignment_id*/
999              	fnd_message.set_token('ASSIGNMENT_NUMBER',g_assignment_number);
1000              	fnd_message.set_token('EMPLOYEE_NUMBER',g_employee_number);
1001              	fnd_msg_pub.add;
1002 --		Commented for bug fix 2267098 (return status set in exception)
1003 --             p_return_status := fnd_api.g_ret_sts_unexp_error;
1004 		RAISE fnd_api.g_exc_unexpected_error;	-- Introduced for bug 2267098
1005 
1006            END IF;
1007 
1008            l_tot_dist_amount := round((l_tot_dist_amount + l_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
1009 
1010            IF l_gl_code_combination_id IS NOT NULL THEN
1011               -- l_effective_date := p_effective_date; Bug 1874696
1012               l_gl_project_flag := 'G';
1013 
1014               -- insert the record in psp_distribution_lines
1015               insert_into_distribution_lines(
1016 		P_SUB_LINE_ID,                  -- payroll sub-lines id
1017  		P_PAYROLL_START_DATE,           -- distribution date
1018                 g_gl_EFFECTIVE_DATE,              -- replaced p_effective_date     -- Bug 2663344
1019  		L_DIST_AMOUNT,                  -- distribution amount
1020  		'N',                            -- status code
1021                 NULL,                           -- suspense reason code
1022                 NULL,                           -- default reason code
1023           	NULL,                           -- schedule line id
1024  		NULL,                           -- default organization a/c
1025  		NULL,                           -- suspense organization a/c
1026  		L_ELEMENT_ACCOUNT_ID,           -- global element type
1027 		NULL,                           -- org default schedule id
1028                 L_GL_PROJECT_FLAG,              -- gl project flag
1029                 NULL,                           -- reversal entry flag
1030                 l_gl_code_combination_id,       -- gl_code_combination_id
1031                 l_project_id,                   -- project_id,
1032                 l_task_id   ,                   -- task_id,
1033                 l_award_id  ,                   -- award_id,
1034                 l_expenditure_org_id,           -- expenditure org id
1035                 l_expenditure_type,             -- expenditure_type
1036                 l_effective_start_date,         -- Eff start date of schedule
1037                 l_effective_end_date,           -- Eff start date of schedule
1038                 p_mode,                         -- 'I' for LD ,'R' for others
1039 	 	p_business_group_id,		-- Business Group Id
1040 		p_set_of_books_id,		-- Set of Books Id
1041 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1042 		l_attribute1,
1043 		l_attribute2,
1044 		l_attribute3,
1045 		l_attribute4,
1046 		l_attribute5,
1047 		l_attribute6,
1048 		l_attribute7,
1049 		l_attribute8,
1050 		l_attribute9,
1051 		l_attribute10,
1052                 l_return_status);
1053 
1054               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1055                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1056               END IF;
1057 
1058            ELSIF l_gl_code_combination_id IS NULL THEN
1059             IF g_global_element_autopop = 'Y' THEN   -- introduced for 5080403
1060                    l_gl_project_flag:='P';
1061 
1062                     insert_into_distribution_lines(
1063  			P_SUB_LINE_ID,             -- payroll sub-line_id
1064  			P_PAYROLL_START_DATE,      -- distribution date
1065                         P_EFFECTIVE_DATE,          -- effective date     Bug 1874696 Changed from l_Effective_date
1066  			L_DIST_AMOUNT,             -- distribution amount
1067  			'N',                       -- status code
1068                         NULL,                      -- suspense reason code
1069                         NULL,                      -- default reason code
1070       			NULL,        -- schedule line id
1071  			NULL,                      -- default organization a/c
1072  			NULL,                      -- suspense organization a/c
1073 			l_element_account_id,      -- global element type
1074 			NULL,                      -- org default schedule id
1075                         L_GL_PROJECT_FLAG,         -- gl project flag
1076                         NULL,                      -- reversal entry flag
1077                         l_gl_code_combination_id,  -- gl_code_combination_id
1078                         l_project_id,              -- project_id,
1079                         l_task_id   ,              -- task_id,
1080                         l_award_id  ,              -- award_id,
1081                         l_expenditure_org_id,      -- expenditure org id
1082                         l_expenditure_type,        -- expenditure_type
1083                         l_effective_start_date,    -- Eff start date of schedule
1084                         l_effective_end_date,      -- Eff start date of schedule
1085                         p_mode,                    -- 'I' for LD ,'R' for others
1086 			p_business_group_id,       -- Business Group Id
1087                         p_set_of_books_id,         -- Set of Books Id
1088 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1089 			l_attribute1,
1090 			l_attribute2,
1091 			l_attribute3,
1092 			l_attribute4,
1093 			l_attribute5,
1094 			l_attribute6,
1095 			l_attribute7,
1096 			l_attribute8,
1097 			l_attribute9,
1098 			l_attribute10,
1099                         l_return_status);
1100 
1101                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1102                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1103                     END IF;
1104             ELSE
1105 
1106 	    -- modified as per 11i changes
1107 	   -- dbms_output.put_line('Project id 1 '|| to_char(l_project_id));
1108 	   -- dbms_output.put_line('task id 1 '|| to_char(l_task_id));
1109 	   -- dbms_output.put_line('Type 1 '|| p_payroll_start_date);
1110 	   -- dbms_output.put_line('person_id 1 '|| to_char(p_person_id));
1111 
1112 	    pa_transactions_pub.validate_transaction(
1113 			x_project_id		=> l_project_id,
1114 			x_task_id		=> l_task_id,
1115 			x_ei_date		=> p_effective_date,  --p_payroll_start_date, Bug 1874696
1116 			x_expenditure_type	=> l_expenditure_type,
1117 			x_non_labor_resource	=> null,
1118 			x_person_id		=> p_person_id,
1119 			x_incurred_by_org_id	=> l_expenditure_org_id,
1120 			x_calling_module	=> 'PSPLDCDB',
1121 			x_msg_application	=> l_msg_app,
1122 			x_msg_type		=> l_msg_type,
1123 			x_msg_token1		=> l_msg_token1,
1124 			x_msg_token2		=> l_msg_token2,
1125 			x_msg_token3		=> l_msg_token3,
1126 			x_msg_count		=> l_msg_count,
1127 			x_msg_data		=> l_patc_status,
1128 			x_billable_flag		=> l_billable_flag,
1129 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
1130 
1131 
1132 	   -- dbms_output.put_line('patc stat 1 '|| l_patc_status);
1133 
1134 	     -- GMS is enabled, PATC validation went fine
1135 	     if l_award_id is not null and l_patc_status is null
1136 	     then
1137 		 gms_transactions_pub.validate_transaction
1138 				(l_project_id,
1139 			   	l_task_id,
1140 				l_award_id,
1141 			   	l_expenditure_type,
1142 				p_effective_date, ---p_payroll_start_date, Bug 1874696
1143 				'PSPLDCDB',
1144 				l_award_status);
1145 
1146 /************************************************************
1147 		 if l_award_status is null
1148 		 then
1149  			project_award_linkage(l_project_id,
1150                                   l_award_id,
1151                                   l_linkage_status,
1152                                   l_return_status);
1153 		else -- fix 2054610
1154 ****************************************************************/
1155                      if l_award_status IS NOT NULL then
1156 		--	l_patc_status := l_award_status;  for bug fix 1931680
1157                         l_patc_status  := substr(l_award_status,1,50);
1158 	        end if;
1159 	     end if;
1160              IF ( l_patc_status IS NOT NULL ) OR
1161 --- ( l_linkage_status IS NOT NULL ) OR  2054610
1162 		(l_award_status is not null ) THEN
1163                 suspense_account(
1164                          x_proc_executed,
1165                          p_person_id,
1166                          p_sub_line_id,
1167                          p_assignment_id,
1168                          p_payroll_start_date,
1169                          l_dist_amount,
1170                          l_patc_status,
1171                          NULL,
1172                          NULL,
1173                          l_element_account_id,
1174                          NULL,
1175                          p_effective_date,
1176                          p_mode,
1177 			 p_business_group_id,
1178 			 p_set_of_books_id,
1179                          NULL,   ---    for autopop perf. patch
1180                          l_return_status);
1181 
1182                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1183                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1184                  END IF;
1185 
1186               ELSIF (l_patc_status IS NULL) OR
1187 --- (l_linkage_status IS NULL) OR
1188 			(l_award_status is null) THEN
1189                 /* Commented for Bug 1874696
1190 		if l_award_id is not null
1191 		then
1192                    psp_general.poeta_effective_date(p_payroll_start_date,
1193                                      l_project_id,
1194                                      l_award_id,
1195 				     l_task_id,
1196                                      l_effective_date,
1197                                      l_return_status);
1198 		elsif l_award_id is null then
1199                    psp_general.poeta_effective_date(p_payroll_start_date,
1200                                      l_project_id,
1201 				     l_task_id,
1202                                      l_effective_date,
1203                                      l_return_status);
1204 		end if;
1205                    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1206                      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1207                    END IF; */
1208                    l_gl_project_flag := 'P';
1209 
1210                    -- insert the record in psp_distribution_lines
1211                    insert_into_distribution_lines(
1212  		       P_SUB_LINE_ID,              -- payroll sub-lines id
1213 	               P_PAYROLL_START_DATE,       -- distribution date
1214                        P_EFFECTIVE_DATE,           -- effective date     changed from l_effective_date Bug 1874696
1215  		       L_DIST_AMOUNT,              -- distribution amount
1216  		       'N',                        -- status code
1217                         NULL,                      -- suspense reason code
1218                         NULL,                      -- default reason code
1219       			NULL,                      -- schedule line id
1220  			NULL,                      -- default organization a/c
1221  			NULL,                      -- suspense organization a/c
1222  			L_ELEMENT_ACCOUNT_ID,      -- global element type
1223 			NULL,                      -- org default schedule id
1224                         L_GL_PROJECT_FLAG,         -- gl project flag
1225                         NULL,                      -- reversal entry flag
1226                         l_gl_code_combination_id,  -- gl_code_combination_id
1227                         l_project_id,              -- project_id,
1228                         l_task_id   ,              -- task_id,
1229                         l_award_id  ,              -- award_id,
1230                         l_expenditure_org_id,      -- expenditure org id
1231                         l_expenditure_type,        -- expenditure_type
1232                         l_effective_start_date,    -- Eff start date of schedule
1233                         l_effective_end_date,      -- Eff start date of schedule
1234                         p_mode,                    -- 'I' for LD ,'R' for others
1235 			p_business_group_id,	   -- Business group Id
1236 			p_set_of_books_id,	   -- Set of Books Id
1237 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1238 			l_attribute1,
1239 			l_attribute2,
1240 			l_attribute3,
1241 			l_attribute4,
1242 			l_attribute5,
1243 			l_attribute6,
1244 			l_attribute7,
1245 			l_attribute8,
1246 			l_attribute9,
1247 			l_attribute10,
1248                         l_return_status);
1249 
1250                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1251                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1252                     END IF;
1253                 END IF;
1254              END IF;
1255            END IF;
1256 
1257          END LOOP; -- loop through all the schedule lines having the payroll period date
1258 
1259          l_bal_dist_amount  := round((p_daily_rate - l_tot_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
1260 
1261          -- IF abs(l_bal_dist_amount) > 0 THEN  -- #1339616
1262          IF l_tot_percent < 100 THEN
1263 
1264            IF p_org_def_account = 'Y' then
1265              default_account(
1266                             x_proc_executed,
1267                             p_person_id,
1268                             p_sub_line_id,
1269                             p_assignment_id,
1270                             p_payroll_start_date,
1271                             l_bal_dist_amount,
1272                             '1',---'LDM_BAL_NOT_100_PERCENT',
1273                             p_effective_date,
1274                             p_mode,
1275 			    p_business_group_id,
1276 			    p_attribute_category,	-- Introduced DFF columns for bug fix 2908859
1277 			    p_attribute1,
1278 			    p_attribute2,
1279 			    p_attribute3,
1280 			    p_attribute4,
1281 			    p_attribute5,
1282 			    p_attribute6,
1283 			    p_attribute7,
1284 			    p_attribute8,
1285 			    p_attribute9,
1286 			    p_attribute10,
1287 			    p_set_of_books_id,
1288                             l_return_status);
1289              IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1290                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1291              END IF;
1292 
1293              IF x_proc_executed = 'FALSE' then
1294                 suspense_account(
1295                                  x_proc_executed,
1296                                  p_person_id,
1297                                  p_sub_line_id,
1298                                  p_assignment_id,
1299                                  p_payroll_start_date,
1300                                  l_bal_dist_amount,
1301                                  'LDM_BAL_NOT_100_PERCENT',
1302                                  NULL,
1303                                  NULL,
1304                                  NULL,
1305                                  NULL,
1306                                  p_effective_date,
1307                                  p_mode,
1308 			         p_business_group_id,
1309 			         p_set_of_books_id,
1310                                  NULL,   ---    for autopop perf. patch
1311                                  l_return_status);
1312                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1313                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1314                  END IF;
1315                END IF;
1316            ELSE
1317                 suspense_account(
1318                                  x_proc_executed,
1319                                  p_person_id,
1320                                  p_sub_line_id,
1321                                  p_assignment_id,
1322                                  p_payroll_start_date,
1323                                  l_bal_dist_amount,
1324                                  'LDM_BAL_NOT_100_PERCENT',
1325                                  NULL,
1326                                  NULL,
1327                                  NULL,
1328                                  NULL,
1329                                  p_effective_date,
1330                                  p_mode,
1331 			         p_business_group_id,
1332 			         p_set_of_books_id,
1333                                  NULL,   ---    for autopop perf. patch
1334                                  l_return_status);
1335                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1336                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1337                  END IF;
1338            END IF;
1339          END IF;
1340    --
1341    p_return_status := fnd_api.g_ret_sts_success;
1342 
1343  EXCEPTION
1344    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1345       g_error_api_path := SUBSTR('GLOBAL_EARNINGS_ELEMENT:'||g_error_api_path,1,230);
1346       p_return_status := fnd_api.g_ret_sts_unexp_error;
1347 
1348    WHEN OTHERS THEN
1349       g_error_api_path := SUBSTR('GLOBAL_EARNINGS_ELEMENT:'||g_error_api_path,1,230);
1350       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','GLOBAL_EARNINGS_ELEMENT');
1351       p_return_status := fnd_api.g_ret_sts_unexp_error;
1352  END;
1353 
1354 ----------------------------- E L E M E N T   T Y P E --------------------------------------
1355 
1356  PROCEDURE element_type_hierarchy(p_proc_executed      OUT NOCOPY  VARCHAR2,
1357                                   p_person_id           IN NUMBER,
1358                                   p_sub_line_id         IN  NUMBER,
1359                                   p_assignment_id       IN  NUMBER,
1360                                   p_element_type_id     IN  NUMBER,
1361                                   p_payroll_start_date  IN  DATE,
1362                                   p_daily_rate          IN  NUMBER,
1363                                   p_org_def_account     IN  VARCHAR2,
1364                                   p_effective_date      IN  DATE,
1365                                   p_mode                IN  VARCHAR2 := 'I',
1366 				  p_business_group_id	IN  NUMBER,
1367 				  p_set_of_books_id	IN  NUMBER,
1368 				p_attribute_category	IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
1369 				p_attribute1		IN	VARCHAR2,
1370 				p_attribute2		IN	VARCHAR2,
1371 				p_attribute3		IN	VARCHAR2,
1372 				p_attribute4		IN	VARCHAR2,
1373 				p_attribute5		IN	VARCHAR2,
1374 				p_attribute6		IN	VARCHAR2,
1375 				p_attribute7		IN	VARCHAR2,
1376 				p_attribute8		IN	VARCHAR2,
1377 				p_attribute9		IN	VARCHAR2,
1378 				p_attribute10		IN	VARCHAR2,
1379                                   p_return_status       OUT NOCOPY VARCHAR2) IS
1380 
1381 
1382 
1383   CURSOR sch_lines_element_type_cur(P_ASSIGNMENT_ID      NUMBER,
1384                                     P_ELEMENT_TYPE_ID    NUMBER,
1385                                     P_PAYROLL_START_DATE DATE) IS
1386   SELECT psl.schedule_line_id,
1387          psl.gl_code_combination_id,
1388          psl.project_id,
1389          psl.task_id,
1390          psl.award_id,
1391          round(psl.schedule_percent,2) schedule_percent,
1392          psl.expenditure_type,
1393          psl.expenditure_organization_id,
1394          psl.schedule_begin_date,
1395          nvl(psl.schedule_begin_date,p_payroll_start_date),
1396           ---- added decode for 5014193
1397 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute_category, psl.attribute_category)) attribute_category,		-- Introduced DFF columns for bug fix 2908859
1398 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute1, psl.attribute1)) attribute1,
1399 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute2, psl.attribute2)) attribute2,
1400 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute3, psl.attribute3)) attribute3,
1401 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute4, psl.attribute4)) attribute4,
1402 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute5, psl.attribute5)) attribute5,
1403 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute6, psl.attribute6)) attribute6,
1404 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute7, psl.attribute7)) attribute7,
1405 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute8, psl.attribute8)) attribute8,
1406 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute9, psl.attribute9)) attribute9,
1407 	decode(g_dff_grouping_option, 'Y',NVL(p_attribute10, psl.attribute10)) attribute10
1408   FROM   psp_schedule_hierarchy psh,
1409          psp_schedule_lines     psl
1410   WHERE  psh.business_group_id = p_business_group_id
1411   AND    psh.set_of_books_id = p_set_of_books_id
1412   AND    psh.business_group_id = psl.business_group_id
1413   AND    psh.set_of_books_id = psl.set_of_books_id
1414   AND    psh.assignment_id = p_assignment_id
1415   AND    psh.element_type_id = p_element_type_id
1416   AND    psh.schedule_hierarchy_id = psl.schedule_hierarchy_id
1417   AND    p_payroll_start_date BETWEEN psl.schedule_begin_date AND
1418                                       nvl(psl.schedule_end_date,p_payroll_start_date)
1419   AND    psl.default_flag IS NULL;
1420 
1421   l_dist_amount                    NUMBER       := 0;
1422   l_tot_dist_amount                NUMBER       := 0;
1423   l_bal_dist_amount                NUMBER       := 0;
1424   l_tot_percent                    NUMBER       := 0;
1425 
1426   l_schedule_line_id               NUMBER(15);
1427   l_gl_code_combination_id         NUMBER(15);
1428   l_project_id                     NUMBER(15);
1429   l_task_id                        NUMBER(15);
1430   l_award_id                       NUMBER(15);
1431   l_schedule_percent               NUMBER;
1432   l_expenditure_type               VARCHAR2(30);
1433   l_expenditure_org_id             NUMBER(15);
1434   l_effective_start_date           DATE;
1435   l_effective_end_date             DATE;
1436 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variables for bug fix 2908859
1437 	l_attribute1		VARCHAR2(150);
1438 	l_attribute2		VARCHAR2(150);
1439 	l_attribute3		VARCHAR2(150);
1440 	l_attribute4		VARCHAR2(150);
1441 	l_attribute5		VARCHAR2(150);
1442 	l_attribute6		VARCHAR2(150);
1443 	l_attribute7		VARCHAR2(150);
1444 	l_attribute8		VARCHAR2(150);
1445 	l_attribute9		VARCHAR2(150);
1446 	l_attribute10		VARCHAR2(150);
1447   x_proc_executed                  VARCHAR2(10) := 'TRUE';
1448   l_rec_count                      NUMBER := 0;
1449   l_return_status                  VARCHAR2(1);
1450   --  l_effective_date                 DATE;  Bug 1874696
1451   l_gl_project_flag                VARCHAR2(1);
1452   l_linkage_status                 VARCHAR2(50);
1453   l_patc_status                    VARCHAR2(50);
1454   l_billable_flag                  VARCHAR2(1);
1455   l_msg_count                      NUMBER;
1456   l_msg_app                        VARCHAR2(2000);
1457   l_msg_type                       varchar2(2000);
1458   l_msg_token1                     varchar2(2000);
1459   l_msg_token2                     varchar2(2000);
1460   l_msg_token3                     varchar2(2000);
1461   --l_award_status  varchar2(50);  -- for bug fix 1931680
1462   l_award_status  varchar2(200);
1463 
1464  BEGIN
1465          p_proc_executed := 'TRUE';
1466 
1467          -- For the payroll date passed to the procedure, check if there are schedule line(s).
1468          -- If the schedule line(s) exists, then fetch the schedule percent and calculate the
1469          -- total distribution amount by adding the distribution amount in each of the lines.
1470          -- If the schedule line(s) does not exist,set the p_proc_executed flag as FALSE
1471 
1472          OPEN sch_lines_element_type_cur(p_assignment_id,p_element_type_id,p_payroll_start_date);
1473 
1474          LOOP
1475            l_linkage_status:= NULL;
1476            l_patc_status   := NULL;
1477            l_billable_flag := NULL;
1478 	   l_award_status  := NULL;
1479 
1480            FETCH sch_lines_element_type_cur INTO
1481 				l_schedule_line_id,
1482                                 l_gl_code_combination_id,
1483   				l_project_id,
1484   				l_task_id,
1485   				l_award_id,
1486   				l_schedule_percent,
1487                                 l_expenditure_type,
1488                                 l_expenditure_org_id,
1489                                 l_effective_start_date,
1490                                 l_effective_end_date,
1491 				l_attribute_category,			-- Introduced DFf variable for bug fix 2908859
1492 				l_attribute1,
1493 				l_attribute2,
1494 				l_attribute3,
1495 				l_attribute4,
1496 				l_attribute5,
1497 				l_attribute6,
1498 				l_attribute7,
1499 				l_attribute8,
1500 				l_attribute9,
1501 				l_attribute10;
1502 
1503            l_rec_count := l_rec_count + 1;
1504            IF sch_lines_element_type_cur%NOTFOUND THEN
1505              IF l_rec_count = 1 THEN
1506                p_proc_executed := 'FALSE';
1507                CLOSE sch_lines_element_type_cur;
1508                RETURN;
1509              ELSE
1510                CLOSE sch_lines_element_type_cur;
1511                EXIT;
1512              END IF;
1513            END IF;
1514 
1515 
1516            l_tot_percent := l_tot_percent + l_schedule_percent;
1517            IF l_tot_percent <= 100 THEN
1518              l_dist_amount := round((p_daily_rate * l_schedule_percent/100), g_precision); 	-- Bug 2916848: Modified to currency precision (from 2)
1519            -- ELSIF l_tot_percent = 100 THEN
1520            --   l_dist_amount := round((p_daily_rate - l_tot_dist_amount),2);
1521            ELSIF l_tot_percent > 100 THEN
1522 	     	Get_assign_number(p_assignment_id
1523 			      ,p_payroll_start_date
1524 			      ,g_assignment_number
1525 			      ,g_employee_number);--Bug 2374680
1526              	fnd_message.set_name('PSP','PSP_LD_PERCENT_GREATER_100');
1527              	fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
1528 --          	fnd_message.set_token('ASSIGNMENT_ID',p_assignment_id); --Commented for bug 2374680
1529                /* Added assignment_number and employee_number inplace of assignment_id*/
1530             	fnd_message.set_token('ASSIGNMENT_NUMBER',g_assignment_number);
1531              	fnd_message.set_token('EMPLOYEE_NUMBER',g_employee_number);
1532              	fnd_msg_pub.add;
1533 --		Commented for bug fix 2267098 (return status set in exception)
1534 --             p_return_status := fnd_api.g_ret_sts_unexp_error;
1535 		RAISE fnd_api.g_exc_unexpected_error;	-- Introduced for bug 2267098
1536            END IF;
1537 
1538            l_tot_dist_amount := round((l_tot_dist_amount + l_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
1539 
1540            IF l_gl_code_combination_id IS NOT NULL THEN
1541               -- l_effective_date := p_effective_date; Bug 1874696
1542               l_gl_project_flag := 'G';
1543 
1544               -- insert the record in psp_distribution_lines
1545               insert_into_distribution_lines(
1546  			P_SUB_LINE_ID,              -- payroll sub-lines id
1547  			P_PAYROLL_START_DATE,       -- distribution date
1548                         G_GL_EFFECTIVE_DATE,        --  changed from p_effective_date Bug 2663344
1549  			L_DIST_AMOUNT,              -- distribution amount
1550  			'N',                        -- status code
1551                         NULL,                       -- suspense reason code
1552                         NULL,                       -- default reason code
1553       			L_SCHEDULE_LINE_ID,         -- schedule line id
1554  			NULL,                       -- default organization a/c
1555  			NULL,                       -- suspense organization a/c
1556  			NULL,                       -- global element type
1557 			NULL,                       -- org default schedule id
1558                         L_GL_PROJECT_FLAG,          -- gl project flag
1559                         NULL,                       -- reversal entry flag
1560                         l_gl_code_combination_id,   -- gl_code_combination_id
1561                         l_project_id,               -- project_id,
1562                         l_task_id   ,               -- task_id,
1563                         l_award_id  ,               -- award_id,
1564                         l_expenditure_org_id,       -- expenditure org id
1565                         l_expenditure_type,         -- expenditure_type
1566                         l_effective_start_date,    -- Eff start date of schedule
1567                         l_effective_end_date,      -- Eff start date of schedule
1568                         p_mode,                    -- 'I' for LD ,'R' for others
1569 			p_business_group_id,       -- Business Group Id
1570                         p_set_of_books_id,         -- Set of Books Id
1571 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1572 			l_attribute1,
1573 			l_attribute2,
1574 			l_attribute3,
1575 			l_attribute4,
1576 			l_attribute5,
1577 			l_attribute6,
1578 			l_attribute7,
1579 			l_attribute8,
1580 			l_attribute9,
1581 			l_attribute10,
1582                         l_return_status);
1583 
1584               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1585                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1586               END IF;
1587            --  END IF; -- Auto Population ON/OFF  for bug fix 2023955
1588 
1589 
1590            ELSIF l_gl_code_combination_id IS NULL THEN
1591 
1592                --IF (g_auto_population = 'Y' AND p_mode='I') THEN
1593                IF (g_asg_element_autopop = 'Y' ) THEN
1594                     l_gl_project_flag:='P';
1595 
1596                     insert_into_distribution_lines(
1597  			P_SUB_LINE_ID,             -- payroll sub-lines id
1598  			P_PAYROLL_START_DATE,      -- distribution date
1599                         P_EFFECTIVE_DATE,          -- effective date    Changed from l_effective_date Bug 1874696
1600  			L_DIST_AMOUNT,             -- distribution amount
1601  			'N',                       -- status code
1602                         NULL,                      -- suspense reason code
1603                         NULL,                      -- default reason code
1604       			L_SCHEDULE_LINE_ID,        -- schedule line id
1605  			NULL,                      -- default organization a/c
1606  			NULL,                      -- suspense organization a/c
1607  			NULL,                      -- global element type
1608 			NULL,                      -- org default schedule id
1609                         L_GL_PROJECT_FLAG,         -- gl project flag
1610                         NULL,                      -- reversal entry flag
1611                         l_gl_code_combination_id,  -- gl_code_combination_id
1612                         l_project_id,              -- project_id,
1613                         l_task_id   ,              -- task_id,
1614                         l_award_id  ,              -- award_id,
1615                         l_expenditure_org_id,      -- expenditure org id
1616                         l_expenditure_type,        -- expenditure_type
1617                         l_effective_start_date,    -- Eff start date of schedule
1618                         l_effective_end_date,      -- Eff start date of schedule
1619                         p_mode,                    -- 'I' for LD ,'R' for others
1620 			p_business_group_id,       -- Business Group Id
1621                         p_set_of_books_id,         -- Set of Books Id
1622 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1623 			l_attribute1,
1624 			l_attribute2,
1625 			l_attribute3,
1626 			l_attribute4,
1627 			l_attribute5,
1628 			l_attribute6,
1629 			l_attribute7,
1630 			l_attribute8,
1631 			l_attribute9,
1632 			l_attribute10,
1633                         l_return_status);
1634 
1635             ELSE
1636 	  -- Auto-Population is OFF. Get project status and insert record.
1637 
1638 	      -- modified as per 11i changes
1639 	   -- dbms_output.put_line('Project id 2 '|| to_char(l_project_id));
1640 	   -- dbms_output.put_line('task id 2 '|| to_char(l_task_id));
1641 	   -- dbms_output.put_line('Type 2 '|| l_expenditure_type);
1642 	   -- dbms_output.put_line('Dt 2 '|| to_char(p_payroll_start_date));
1643 	   -- dbms_output.put_line('person_id 2 '|| to_char(p_person_id));
1644 	    pa_transactions_pub.validate_transaction(
1645 			x_project_id		=> l_project_id,
1646 			x_task_id		=> l_task_id,
1647 			x_ei_date		=> p_effective_date, ----p_payroll_start_date, Bug 1874696
1648 			x_expenditure_type	=> l_expenditure_type,
1649 			x_non_labor_resource	=> null,
1650 			x_person_id		=> p_person_id,
1651 			x_incurred_by_org_id	=> l_expenditure_org_id,
1652 			x_calling_module	=> 'PSPLDCDB',
1653 			x_msg_application	=> l_msg_app,
1654 			x_msg_type		=> l_msg_type,
1655 			x_msg_token1		=> l_msg_token1,
1656 			x_msg_token2		=> l_msg_token2,
1657 			x_msg_token3		=> l_msg_token3,
1658 			x_msg_count		=> l_msg_count,
1659 			x_msg_data		=> l_patc_status,
1660 			x_billable_flag		=> l_billable_flag,
1661 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
1662 
1663 
1664 	   -- dbms_output.put_line('patc stat 2 '|| l_patc_status);
1665 	    -- GMS is enabled and PATC validation went through
1666 	    if l_award_id is not null and l_patc_status is null
1667              then
1668                  gms_transactions_pub.validate_transaction
1669                                 (l_project_id,
1670                                 l_task_id,
1671 				l_award_id,
1672                                 l_expenditure_type,
1673                                 p_effective_date, ---p_payroll_start_date, Bug 1874696
1674                                 'PSPLDCDB',
1675                                 l_award_status);
1676 /*****************************************************************
1677 
1678                  if l_award_status is null
1679                  then
1680                         project_award_linkage(l_project_id,
1681                                   l_award_id,
1682                                   l_linkage_status,
1683                                   l_return_status);
1684 		 else
1685 
1686 -- bug fxi 2054610
1687 ******************************************************************/
1688 
1689                 if l_award_status is not null then
1690 		--	l_patc_status := l_award_status;  for bug fix 1931680
1691                         l_patc_status  := substr(l_award_status,1,50);
1692                  end if;
1693             end if;
1694 
1695              IF (l_patc_status IS NOT NULL) OR
1696 ---  (l_linkage_status IS NOT NULL) OR   2054610
1697 		(l_award_status is not null) THEN
1698                 suspense_account(
1699                          x_proc_executed,
1700                          p_person_id,
1701                          p_sub_line_id,
1702                          p_assignment_id,
1703                          p_payroll_start_date,
1704                          l_dist_amount,
1705                          l_patc_status,
1706                          l_schedule_line_id,
1707                          NULL,
1708                          NULL,
1709                          NULL,
1710                          p_effective_date,
1711                          p_mode,
1712 			 p_business_group_id,
1713                          p_set_of_books_id,
1714                          NULL,   ---    for autopop perf. patch
1715                          l_return_status);
1716 
1717                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1718                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1719                  END IF;
1720 
1721               ELSIF (l_patc_status IS NULL) OR
1722 --- (l_linkage_status IS NULL) OR
1723 		    (l_award_status is null) THEN
1724                /* Bug 1874696
1725 		 if l_award_id is not null
1726 		 then
1727                     psp_general.poeta_effective_date(p_payroll_start_date,
1728                                      l_project_id,
1729                                      l_award_id,
1730   				     l_task_id,
1731                                      l_effective_date,
1732                                      l_return_status);
1733 		 elsif l_award_id is null
1734 		 then
1735                     psp_general.poeta_effective_date(p_payroll_start_date,
1736                                      l_project_id,
1737   				     l_task_id,
1738                                      l_effective_date,
1739                                      l_return_status);
1740 		 end if;
1741                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1742                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1743                     END IF; */
1744                     l_gl_project_flag := 'P';
1745 
1746                     -- insert the record in psp_distribution_lines
1747                     insert_into_distribution_lines(
1748  			P_SUB_LINE_ID,             -- payroll sub-lines id
1749  			P_PAYROLL_START_DATE,      -- distribution date
1750                         P_EFFECTIVE_DATE,          -- effective date    Changed from l_effective_date Bug 1874696
1751  			L_DIST_AMOUNT,             -- distribution amount
1752  			'N',                       -- status code
1753                         NULL,                      -- suspense reason code
1754                         NULL,                      -- default reason code
1755       			L_SCHEDULE_LINE_ID,        -- schedule line id
1756  			NULL,                      -- default organization a/c
1757  			NULL,                      -- suspense organization a/c
1758  			NULL,                      -- global element type
1759 			NULL,                      -- org default schedule id
1760                         L_GL_PROJECT_FLAG,         -- gl project flag
1761                         NULL,                      -- reversal entry flag
1762                         l_gl_code_combination_id,  -- gl_code_combination_id
1763                         l_project_id,              -- project_id,
1764                         l_task_id   ,              -- task_id,
1765                         l_award_id  ,              -- award_id,
1766                         l_expenditure_org_id,      -- expenditure org id
1767                         l_expenditure_type,        -- expenditure_type
1768                         l_effective_start_date,    -- Eff start date of schedule
1769                         l_effective_end_date,      -- Eff start date of schedule
1770                         p_mode,                    -- 'I' for LD ,'R' for others
1771 			p_business_group_id,       -- Business Group Id
1772                         p_set_of_books_id,         -- Set of Books Id
1773 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1774 			l_attribute1,
1775 			l_attribute2,
1776 			l_attribute3,
1777 			l_attribute4,
1778 			l_attribute5,
1779 			l_attribute6,
1780 			l_attribute7,
1781 			l_attribute8,
1782 			l_attribute9,
1783 			l_attribute10,
1784                         l_return_status);
1785 
1786                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1787                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1788                     END IF;
1789              END IF;
1790            END IF;  -- Auto-Population ON/OFF
1791          END IF;
1792 
1793          END LOOP; -- loop through all the schedule lines having the payroll period date
1794 
1795          l_bal_dist_amount  := round((p_daily_rate - l_tot_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
1796 
1797          -- IF abs(l_bal_dist_amount) > 0 THEN  -- #1339616
1798          IF l_tot_percent < 100 THEN
1799 
1800            IF p_org_def_account = 'Y' then
1801              default_account(
1802                             x_proc_executed,
1803                             p_person_id,
1804                             p_sub_line_id,
1805                             p_assignment_id,
1806                             p_payroll_start_date,
1807                             l_bal_dist_amount,
1808                             '1',---'LDM_BAL_NOT_100_PERCENT',
1809                             p_effective_date,
1810                             p_mode,
1811 			    p_business_group_id,
1812                             p_set_of_books_id,
1813 			p_attribute_category,	-- Introduced DFF columns for bug fix 2908859
1814 			p_attribute1,
1815 			p_attribute2,
1816 			p_attribute3,
1817 			p_attribute4,
1818 			p_attribute5,
1819 			p_attribute6,
1820 			p_attribute7,
1821 			p_attribute8,
1822 			p_attribute9,
1823 			p_attribute10,
1824                             l_return_status);
1825 
1826              IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1827                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1828              END IF;
1829 
1830              IF x_proc_executed = 'FALSE' then
1831                 suspense_account(
1832                                  x_proc_executed,
1833                                  p_person_id,
1834                                  p_sub_line_id,
1835                                  p_assignment_id,
1836                                  p_payroll_start_date,
1837                                  l_bal_dist_amount,
1838                                  'LDM_BAL_NOT_100_PERCENT',
1839                                  NULL,
1840                                  NULL,
1841                                  NULL,
1842                                  NULL,
1843                                  p_effective_date,
1844                                  p_mode,
1845 				 p_business_group_id,
1846                                  p_set_of_books_id,
1847                                  NULL,   ---    for autopop perf. patch
1848                                  l_return_status);
1849 
1850                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1851                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1852                  END IF;
1853                END IF;
1854            ELSE
1855                 suspense_account(
1856                                  x_proc_executed,
1857                                  p_person_id,
1858                                  p_sub_line_id,
1859                                  p_assignment_id,
1860                                  p_payroll_start_date,
1861                                  l_bal_dist_amount,
1862                                  'LDM_BAL_NOT_100_PERCENT',
1863                                  NULL,
1864                                  NULL,
1865                                  NULL,
1866                                  NULL,
1867                                  p_effective_date,
1868                                  p_mode,
1869 				 p_business_group_id,
1870                                  p_set_of_books_id,
1871                                  NULL, -- for autopop perf. patch 2023955
1872                                  l_return_status);
1873 
1874                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1875                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1876                  END IF;
1877            END IF;
1878          END IF;
1879    --
1880    p_return_status := fnd_api.g_ret_sts_success;
1881 
1882  EXCEPTION
1883    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1884       g_error_api_path := SUBSTR('ELEMENT_TYPE_HIERARCHY:'||g_error_api_path,1,230);
1885       p_return_status := fnd_api.g_ret_sts_unexp_error;
1886 
1887    WHEN OTHERS THEN
1888       g_error_api_path := SUBSTR('ELEMENT_TYPE_HIERARCHY:'||g_error_api_path,1,230);
1889       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','ELEMENT_TYPE_HIERARCHY');
1890       p_return_status := fnd_api.g_ret_sts_unexp_error;
1891  END;
1892 
1893 ----------------------------- E L E M E N T   C L A S S --------------------------------------
1894 
1895  PROCEDURE element_class_hierarchy(p_proc_executed      OUT NOCOPY  VARCHAR2,
1896                                   p_person_id           IN  NUMBER,
1897                                   p_sub_line_id         IN  NUMBER,
1898                                   p_assignment_id       IN  NUMBER,
1899                                   p_element_type_id     IN  NUMBER,
1900                                   p_payroll_start_date  IN  DATE,
1901                                   p_daily_rate          IN  NUMBER,
1902                                   p_org_def_account     IN  VARCHAR2,
1903                                   p_effective_date      IN  DATE,
1904                                   p_mode                IN  VARCHAR2 := 'I',
1905 				  p_business_group_id   IN  NUMBER,
1906                                   p_set_of_books_id     IN  NUMBER,
1907 				p_attribute_category	IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
1908 				p_attribute1		IN	VARCHAR2,
1909 				p_attribute2		IN	VARCHAR2,
1910 				p_attribute3		IN	VARCHAR2,
1911 				p_attribute4		IN	VARCHAR2,
1912 				p_attribute5		IN	VARCHAR2,
1913 				p_attribute6		IN	VARCHAR2,
1914 				p_attribute7		IN	VARCHAR2,
1915 				p_attribute8		IN	VARCHAR2,
1916 				p_attribute9		IN	VARCHAR2,
1917 				p_attribute10		IN	VARCHAR2,
1918                                   p_return_status       OUT NOCOPY VARCHAR2) IS
1919 
1920 
1921 
1922   CURSOR sch_lines_element_class_cur(P_ASSIGNMENT_ID      NUMBER,
1923                                      P_ELEMENT_TYPE_ID    NUMBER,
1924                                      P_PAYROLL_START_DATE DATE) IS
1925   SELECT psl.schedule_line_id,
1926          psl.gl_code_combination_id,
1927          psl.project_id,
1928          psl.task_id,
1929          psl.award_id,
1930          round(psl.schedule_percent,2) schedule_percent,
1931          psl.expenditure_type,
1932          psl.expenditure_organization_id,
1933          pet.start_date_active,
1934          nvl(pet.end_date_active,p_payroll_start_date),
1935           ---- introduced decode for 5014193
1936 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute_category, psl.attribute_category)) attribute_category,		-- Introduced DFF columns for bug fix 2908859
1937 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute1, psl.attribute1)) attribute1,
1938 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute2, psl.attribute2)) attribute2,
1939 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute3, psl.attribute3)) attribute3,
1940 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute4, psl.attribute4)) attribute4,
1941 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute5, psl.attribute5)) attribute5,
1942 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute6, psl.attribute6)) attribute6,
1943 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute7, psl.attribute7)) attribute7,
1944 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute8, psl.attribute8)) attribute8,
1945 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute9, psl.attribute9)) attribute9,
1946 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute10, psl.attribute10)) attribute10
1947   FROM   psp_element_types      pet,
1948          psp_group_element_list pgel,
1949          psp_schedule_hierarchy psh,
1950          psp_schedule_lines     psl
1951   WHERE  pet.element_type_id = p_element_type_id
1952 --	Introduced the following BG/SOB check for bug fix 3098050
1953   AND	 pet.business_group_id = p_business_group_id
1954   AND	 pet.set_of_books_id = p_set_of_books_id
1955   AND    p_payroll_start_date BETWEEN pet.start_date_active AND
1956                                       nvl(pet.end_date_active,p_payroll_start_date)
1957   AND    pet.element_type_id = pgel.element_type_id
1958   AND    pet.start_date_active = pgel.start_date_active
1959   AND    pgel.element_group_id = psh.element_group_id
1960   AND    psl.business_group_id = p_business_group_id
1961   AND    psl.set_of_books_id   = p_set_of_books_id
1962   AND    psh.assignment_id = p_assignment_id
1963   AND    psh.schedule_hierarchy_id = psl.schedule_hierarchy_id
1964   AND    p_payroll_start_date BETWEEN psl.schedule_begin_date AND
1965                                       nvl(psl.schedule_end_date,p_payroll_start_date);
1966 
1967 
1968   x_proc_executed            	     VARCHAR2(10) := 'TRUE';
1969   l_dist_amount                    NUMBER       := 0;
1970   l_tot_dist_amount                NUMBER       := 0;
1971   l_bal_dist_amount                NUMBER       := 0;
1972   l_tot_percent                    NUMBER       := 0;
1973 
1974   l_schedule_line_id               NUMBER(15);
1975   l_gl_code_combination_id         NUMBER(15);
1976   l_project_id                     NUMBER(15);
1977   l_task_id                        NUMBER(15);
1978   l_award_id                       NUMBER(15);
1979   l_expenditure_type               VARCHAR2(30);
1980   l_schedule_percent               NUMBER;
1981   l_expenditure_org_id             NUMBER(15);
1982   l_effective_start_date           DATE;
1983   l_effective_end_date             DATE;
1984 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variables for bug fix 2908859
1985 	l_attribute1		VARCHAR2(150);
1986 	l_attribute2		VARCHAR2(150);
1987 	l_attribute3		VARCHAR2(150);
1988 	l_attribute4		VARCHAR2(150);
1989 	l_attribute5		VARCHAR2(150);
1990 	l_attribute6		VARCHAR2(150);
1991 	l_attribute7		VARCHAR2(150);
1992 	l_attribute8		VARCHAR2(150);
1993 	l_attribute9		VARCHAR2(150);
1994 	l_attribute10		VARCHAR2(150);
1995   l_rec_count                      NUMBER := 0;
1996   l_return_status                  VARCHAR2(1);
1997   --l_effective_date                 DATE;    Bug 1874696
1998   l_gl_project_flag                VARCHAR2(1);
1999   l_linkage_status                 VARCHAR2(50);
2000   l_patc_status                    VARCHAR2(50);
2001   l_billable_flag                  VARCHAR2(1);
2002   l_msg_count                      NUMBER;
2003   l_msg_app                        VARCHAR2(2000);
2004   l_msg_type                       varchar2(2000);
2005   l_msg_token1                     varchar2(2000);
2006   l_msg_token2                     varchar2(2000);
2007   l_msg_token3                     varchar2(2000);
2008   --l_award_status  varchar2(50);  -- for bug fix 1931680
2009   l_award_status  varchar2(200);
2010 
2011  BEGIN
2012          p_proc_executed := 'TRUE';
2013 
2014          -- For the payroll date passed to the procedure, check if there are schedule line(s).
2015          -- If the schedule line(s) exists, then fetch the schedule percent and calculate the
2016          -- total distribution amount by adding the distribution amount in each of the lines.
2017          -- If the schedule line(s) does not exist,set the p_proc_executed flag as FALSE
2018 
2019          OPEN sch_lines_element_class_cur(p_assignment_id,p_element_type_id,p_payroll_start_date);
2020 
2021          LOOP
2022            l_linkage_status := NULL;
2023            l_patc_status    := NULL;
2024            l_billable_flag  := NULL;
2025 	   l_award_status   := NULL;
2026 
2027            FETCH sch_lines_element_class_cur INTO
2028 		        l_schedule_line_id,
2029                         l_gl_code_combination_id,
2030   			l_project_id,
2031   			l_task_id,
2032   			l_award_id,
2033   			l_schedule_percent,
2034                         l_expenditure_type,
2035                         l_expenditure_org_id,
2036                         l_effective_start_date,
2037                         l_effective_end_date,
2038 			l_attribute_category,			-- Introduced DFf variable for bug fix 2908859
2039 			l_attribute1,
2040 			l_attribute2,
2041 			l_attribute3,
2042 			l_attribute4,
2043 			l_attribute5,
2044 			l_attribute6,
2045 			l_attribute7,
2046 			l_attribute8,
2047 			l_attribute9,
2048 			l_attribute10;
2049 
2050            l_rec_count := l_rec_count + 1;
2051            IF sch_lines_element_class_cur%NOTFOUND THEN
2052              IF l_rec_count = 1 THEN
2053                p_proc_executed := 'FALSE';
2054                CLOSE sch_lines_element_class_cur;
2055                RETURN;
2056              ELSE
2057                CLOSE sch_lines_element_class_cur;
2058                EXIT;
2059              END IF;
2060            END IF;
2061 
2062            l_tot_percent := l_tot_percent + l_schedule_percent;
2063            IF l_tot_percent <= 100 THEN
2064              l_dist_amount := round((p_daily_rate * l_schedule_percent/100), g_precision); 	-- Bug 2916848: Modified to currency precision (from 2)
2065            -- ELSIF l_tot_percent = 100 THEN
2066            --   l_dist_amount := round((p_daily_rate - l_tot_dist_amount),2);
2067            ELSIF l_tot_percent > 100 THEN
2068 	      	Get_assign_number(p_assignment_id
2069 	 		       ,p_payroll_start_date
2070 			       ,g_assignment_number
2071 			       ,g_employee_number);--Bug 2374680
2072               	fnd_message.set_name('PSP','PSP_LD_PERCENT_GREATER_100');
2073               	fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
2074 --            	fnd_message.set_token('ASSIGNMENT_ID',p_assignment_id); --Commented for bug 2374680
2075               	/* Added assignment_number and employee_number inplace of assignment_id*/
2076               	fnd_message.set_token('ASSIGNMENT_NUMBER',g_assignment_number);
2077               	fnd_message.set_token('EMPLOYEE_NUMBER',g_employee_number);
2078               	fnd_msg_pub.add;
2079 --		Commented for bug fix 2267098 (return status set in exception)
2080 --             	p_return_status := fnd_api.g_ret_sts_unexp_error;
2081 		RAISE fnd_api.g_exc_unexpected_error;	-- Introduced for bug 2267098
2082 
2083            END IF;
2084 
2085            l_tot_dist_amount := round((l_tot_dist_amount + l_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
2086 
2087 
2088            IF l_gl_code_combination_id IS NOT NULL THEN
2089               -- l_effective_date := p_effective_date; Bug 1874696
2090               l_gl_project_flag := 'G';
2091 
2092 
2093               insert_into_distribution_lines(
2094  			P_SUB_LINE_ID,         -- payroll sub-lines id
2095  			P_PAYROLL_START_DATE,  -- distribution date
2096                         G_GL_EFFECTIVE_DATE,   --  Changed from P_Effective_date Bug 2663344
2097  			L_DIST_AMOUNT,         -- distribution amount
2098  			'N',                   -- status code
2099                         NULL,                  -- suspense reason code
2100                         NULL,                  -- default reason code
2101       	                L_SCHEDULE_LINE_ID,    -- schedule line id
2102  			NULL,                  -- default organization a/c
2103  			NULL,                  -- suspense organization a/c
2104  			NULL,                  -- global element type
2105 			NULL,                  -- org default schedule id
2106                         L_GL_PROJECT_FLAG,     -- gl project flag
2107                         NULL,                  -- reversal entry flag
2108                         l_gl_code_combination_id,  -- gl_code_combination_id
2109                         l_project_id,          -- project_id,
2110                         l_task_id   ,          -- task_id,
2111                         l_award_id  ,          -- award_id,
2112                         l_expenditure_org_id,  -- expenditure org id
2113                         l_expenditure_type,    -- expenditure_type
2114                         l_effective_start_date,-- Eff start date of schedule
2115                         l_effective_end_date,  -- Eff start date of schedule
2116                         p_mode,                -- 'I' for LD ,'R' for others
2117 			p_business_group_id,   -- Business Group Id
2118                         p_set_of_books_id,     -- Set of books Id
2119 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
2120 			l_attribute1,
2121 			l_attribute2,
2122 			l_attribute3,
2123 			l_attribute4,
2124 			l_attribute5,
2125 			l_attribute6,
2126 			l_attribute7,
2127 			l_attribute8,
2128 			l_attribute9,
2129 			l_attribute10,
2130                         l_return_status);
2131 
2132                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2133                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2134                 END IF;
2135 
2136            ELSIF l_gl_code_combination_id IS NULL THEN
2137              --IF g_auto_population = 'Y' THEN
2138 
2139              IF (g_asg_ele_group_autopop = 'Y')THEN  --- 5080403
2140               -- insert the record in psp_distribution_lines  bug 2023955
2141                    l_gl_project_flag:='P';
2142 
2143               insert_into_distribution_lines(
2144  			P_SUB_LINE_ID,         -- payroll sub-lines id
2145  			P_PAYROLL_START_DATE,  -- distribution date
2146                         P_EFFECTIVE_DATE,      -- effective date     Changed from l_Effective_date Bug 1874696
2147  			L_DIST_AMOUNT,         -- distribution amount
2148  			'N',                   -- status code
2149                         NULL,                  -- suspense reason code
2150                         NULL,                  -- default reason code
2151       	                L_SCHEDULE_LINE_ID,    -- schedule line id
2152  			NULL,                  -- default organization a/c
2153  			NULL,                  -- suspense organization a/c
2154  			NULL,                  -- global element type
2155 			NULL,                  -- org default schedule id
2156                         L_GL_PROJECT_FLAG,     -- gl project flag
2157                         NULL,                  -- reversal entry flag
2158                         l_gl_code_combination_id,  -- gl_code_combination_id
2159                         l_project_id,          -- project_id,
2160                         l_task_id   ,          -- task_id,
2161                         l_award_id  ,          -- award_id,
2162                         l_expenditure_org_id,  -- expenditure org id
2163                         l_expenditure_type,    -- expenditure_type
2164                         l_effective_start_date,-- Eff start date of schedule
2165                         l_effective_end_date,  -- Eff start date of schedule
2166                         p_mode,                -- 'I' for LD ,'R' for others
2167 			p_business_group_id,   -- Business Group Id
2168                         p_set_of_books_id,     -- Set of books Id
2169 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
2170 			l_attribute1,
2171 			l_attribute2,
2172 			l_attribute3,
2173 			l_attribute4,
2174 			l_attribute5,
2175 			l_attribute6,
2176 			l_attribute7,
2177 			l_attribute8,
2178 			l_attribute9,
2179 			l_attribute10,
2180                         l_return_status);
2181 
2182               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2183                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2184               END IF;
2185           --  END IF; -- Auto-Population ON/OFF  Commented out NOCOPY for bug fxi 2023955
2186 
2187 
2188            ELSE
2189 
2190 
2191 /*
2192 
2193   Commented out NOCOPY  for Bug fix 2023955
2194 
2195                autopop(p_acct_type                   => 'E',
2196 		       p_person_id                   => p_person_id,
2197 		       p_assignment_id               => p_assignment_id,
2198 		       p_element_type_id             => p_element_type_id,
2199 		       p_project_id                  => l_project_id,
2200 		       p_expenditure_organization_id => l_expenditure_org_id,
2201 		       p_task_id                     => l_task_id,
2202 		       p_award_id                    => l_award_id,
2203                        p_expenditure_type            => l_expenditure_type,
2204 		       p_gl_code_combination_id      => null,
2205 		       p_payroll_start_date          => p_payroll_start_date,
2206 		       p_effective_date              => p_effective_date,
2207 		       p_dist_amount                 => l_dist_amount,
2208                        p_schedule_line_id            => l_schedule_line_id,
2209 		       p_org_schedule_id             => null,
2210 		       p_sub_line_id                 => p_sub_line_id,
2211                        p_effective_start_date        => l_effective_start_date,
2212                        p_effective_end_date          => l_effective_end_date,
2213                        p_mode                        => p_mode,
2214 		       p_business_group_id           => p_business_group_id,
2215                        p_set_of_books_id             => p_set_of_books_id,
2216 		       p_return_status 		     => l_return_status);
2217 
2218 	       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2219                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2220                END IF;
2221 */
2222 --            ELSE
2223 		  -- Auto-Population is OFF. Get project status and insert record.
2224 	     -- modified as per 11i changes
2225 	   -- dbms_output.put_line('Project id 3 '|| to_char(l_project_id));
2226 	   -- dbms_output.put_line('task id 3 '|| to_char(l_task_id));
2227 	   -- dbms_output.put_line('Type 3 '|| l_expenditure_type);
2228 	   -- dbms_output.put_line('Dt 3 '|| to_char(p_payroll_start_date));
2229 	   -- dbms_output.put_line('person_id 3 '|| to_char(p_person_id));
2230 
2231 	    pa_transactions_pub.validate_transaction(
2232 			x_project_id		=> l_project_id,
2233 			x_task_id		=> l_task_id,
2234 			x_ei_date		=> p_effective_date, ----p_payroll_start_date, Bug 1874696
2235 			x_expenditure_type	=> l_expenditure_type,
2236 			x_non_labor_resource	=> null,
2237 			x_person_id		=> p_person_id,
2238 			x_incurred_by_org_id	=> l_expenditure_org_id,
2239 			x_calling_module	=> 'PSPLDCDB',
2240 			x_msg_application	=> l_msg_app,
2241 			x_msg_type		=> l_msg_type,
2242 			x_msg_token1		=> l_msg_token1,
2243 			x_msg_token2		=> l_msg_token2,
2244 			x_msg_token3		=> l_msg_token3,
2245 			x_msg_count		=> l_msg_count,
2246 			x_msg_data		=> l_patc_status,
2247 			x_billable_flag		=> l_billable_flag,
2248 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
2249 
2250 
2251 	   -- dbms_output.put_line('patc stat 3 '|| l_patc_status);
2252 	    -- GMS is enabled and PATC went through
2253 	    if l_award_id is not null and l_patc_status is null
2254              then
2255                  gms_transactions_pub.validate_transaction
2256                                 (l_project_id,
2257                                 l_task_id,
2258 				l_award_id,
2259                                 l_expenditure_type,
2260                                 p_effective_date, ----p_payroll_start_date, Bug 1874696
2261                                 'PSPLDCDB',
2262                                 l_award_status);
2263 /************************************************************************
2264 
2265                  if l_award_status is null
2266                  then
2267                         project_award_linkage(l_project_id,
2268                                   l_award_id,
2269                                   l_linkage_status,
2270                                   l_return_status);
2271 		 else
2272  --  Bug 2054610
2273 *************************************************************************/
2274 
2275                  if l_award_status is not null then
2276 		--	l_patc_status := l_award_status;  for bug fix 1931680
2277                         l_patc_status  := substr(l_award_status,1,50);
2278                  end if;
2279              end if;
2280 
2281              IF (l_patc_status IS NOT NULL) OR
2282 --- (l_linkage_status IS NOT NULL) OR
2283 		(l_award_status is not null) THEN
2284                 suspense_account(
2285                          x_proc_executed,
2286                          p_person_id,
2287                          p_sub_line_id,
2288                          p_assignment_id,
2289                          p_payroll_start_date,
2290                          l_dist_amount,
2291                          l_patc_status,
2292                          l_schedule_line_id,
2293                          NULL,
2294                          NULL,
2295                          NULL,
2296                          p_effective_date,
2297                          p_mode,
2298 			 p_business_group_id,
2299                          p_set_of_books_id,
2300                          NULL,   ---    for autopop perf. patch
2301                          l_return_status);
2302 
2303                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2304                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2305                  END IF;
2306 
2307               ELSIF (l_patc_status IS NULL) OR
2308 --- (l_linkage_status IS NULL) OR
2309 		    (l_award_status is null)  THEN
2310                 /* Bug 1874696
2311 		if l_award_id is not null
2312 		then
2313                    psp_general.poeta_effective_date(p_payroll_start_date,
2314                                      l_project_id,
2315                                      l_award_id,
2316   				     l_task_id,
2317                                      l_effective_date,
2318                                      l_return_status);
2319 		elsif l_award_id is null
2320 		then
2321                    psp_general.poeta_effective_date(p_payroll_start_date,
2322                                      l_project_id,
2323   				     l_task_id,
2324                                      l_effective_date,
2325                                      l_return_status);
2326 		end if;
2327                    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2328                      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2329                    END IF; */
2330                    l_gl_project_flag := 'P';
2331 
2332                     -- insert the record in psp_distribution_lines
2333                     insert_into_distribution_lines(
2334  			P_SUB_LINE_ID,             -- payroll sub-lines id
2335  			P_PAYROLL_START_DATE,      -- distribution date
2336                         P_EFFECTIVE_DATE,          -- effective date     Changed from l_effective_date Bug 1874696
2337  			L_DIST_AMOUNT,             -- distribution amount
2338  			'N',                       -- status code
2339                         NULL,                      -- suspense reason code
2340                         NULL,                      -- default reason code
2341       			L_SCHEDULE_LINE_ID,        -- schedule line id
2342  			NULL,                      -- default organization a/c
2343  			NULL,                      -- suspense organization a/c
2344  			NULL,                      -- global element type
2345 			NULL,                      -- org default schedule id
2346                         L_GL_PROJECT_FLAG,         -- gl project flag
2347                         NULL,                      -- reversal entry flag
2348                         l_gl_code_combination_id,  -- gl_code_combination_id
2349                         l_project_id,              -- project_id,
2350                         l_task_id   ,              -- task_id,
2351                         l_award_id  ,              -- award_id,
2352                         l_expenditure_org_id    ,  -- expenditure org id
2353                         l_expenditure_type,             -- expenditure_type
2354                         l_effective_start_date,    -- Eff start date of schedule
2355                         l_effective_end_date,      -- Eff start date of schedule
2356                         p_mode,                    -- 'I' for LD ,'R' for others
2357 			p_business_group_id,       -- Business_group_id
2358                         p_set_of_books_id,         -- Set of Books Id
2359 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
2360 			l_attribute1,
2361 			l_attribute2,
2362 			l_attribute3,
2363 			l_attribute4,
2364 			l_attribute5,
2365 			l_attribute6,
2366 			l_attribute7,
2367 			l_attribute8,
2368 			l_attribute9,
2369 			l_attribute10,
2370                         l_return_status);
2371 
2372                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2373                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2374                     END IF;
2375              END IF;
2376            END IF; -- g_auto_population = 'Y'
2377           END IF;
2378          END LOOP; -- loop through all the schedule lines having the payroll period date
2379 
2380          l_bal_dist_amount  := round((p_daily_rate - l_tot_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
2381 
2382          -- IF abs(l_bal_dist_amount) > 0 THEN  -- #1339616
2383          IF l_tot_percent <  100 THEN
2384 
2385            IF p_org_def_account = 'Y' then
2386              default_account(
2387                             x_proc_executed,
2388                             p_person_id,
2389                             p_sub_line_id,
2390                             p_assignment_id,
2391                             p_payroll_start_date,
2392                             l_bal_dist_amount,
2393                             '1',---'LDM_BAL_NOT_100_PERCENT',
2394                             p_effective_date,
2395                             p_mode,
2396 			    p_business_group_id,
2397                             p_set_of_books_id,
2398 			p_attribute_category,	-- Introduced DFF columns for bug fix 2908859
2399 			p_attribute1,
2400 			p_attribute2,
2401 			p_attribute3,
2402 			p_attribute4,
2403 			p_attribute5,
2404 			p_attribute6,
2405 			p_attribute7,
2406 			p_attribute8,
2407 			p_attribute9,
2408 			p_attribute10,
2409                             l_return_status);
2410               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2411                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2412               END IF;
2413 
2414 
2415               IF x_proc_executed = 'FALSE' then
2416                 suspense_account(
2417                                  x_proc_executed,
2418                                  p_person_id,
2419                                  p_sub_line_id,
2420                                  p_assignment_id,
2421                                  p_payroll_start_date,
2422                                  l_bal_dist_amount,
2423                                  'LDM_BAL_NOT_100_PERCENT',
2424                                  NULL,
2425                                  NULL,
2426                                  NULL,
2427                                  NULL,
2428                                  p_effective_date,
2429                                  p_mode,
2430 				 p_business_group_id,
2431                                  p_set_of_books_id,
2432                                  NULL,   ---    for autopop perf. patch
2433                                  l_return_status);
2434                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2435                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2436                  END IF;
2437 
2438                END IF;
2439            ELSE
2440                 suspense_account(
2441                                  x_proc_executed,
2442                                  p_person_id,
2443                                  p_sub_line_id,
2444                                  p_assignment_id,
2445                                  p_payroll_start_date,
2446                                  l_bal_dist_amount,
2447                                  'LDM_BAL_NOT_100_PERCENT',
2448                                  NULL,
2449                                  NULL,
2450                                  NULL,
2451                                  NULL,
2452                                  p_effective_date,
2453                                  p_mode,
2454 				 p_business_group_id,
2455                                  p_set_of_books_id,
2456                                  NULL,   ---    for autopop perf. patch
2457                                  l_return_status);
2458                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2459                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2460                  END IF;
2461 
2462            END IF;
2463          END IF;
2464    --
2465    p_return_status := fnd_api.g_ret_sts_success;
2466 
2467  EXCEPTION
2468    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2469       g_error_api_path := SUBSTR('ELEMENT_CLASS_HIERARCHY:'||g_error_api_path,1,230);
2470       p_return_status := fnd_api.g_ret_sts_unexp_error;
2471 
2472    WHEN OTHERS THEN
2473       g_error_api_path := SUBSTR('ELEMENT_CLASS_HIERARCHY:'||g_error_api_path,1,230);
2474       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','ELEMENT_CLASS_HIERARCHY');
2475       p_return_status := fnd_api.g_ret_sts_unexp_error;
2476 
2477  END;
2478 
2479 ----------------------------- A S S I G N M E N T --------------------------------------
2480 
2481 
2482 
2483 
2484  PROCEDURE assignment_hierarchy(p_proc_executed      OUT NOCOPY  VARCHAR2,
2485                                 p_person_id           IN  NUMBER,
2486                                 p_sub_line_id         IN  NUMBER,
2487                                 p_assignment_id       IN  NUMBER,
2488                                 p_element_type_id     IN  NUMBER,
2489                                 p_payroll_start_date  IN  DATE,
2490                                 p_daily_rate          IN  NUMBER,
2491                                 p_org_def_account     IN  VARCHAR2,
2492                                 p_effective_date      IN  DATE,
2493                                 p_mode                IN  VARCHAR2 := 'I',
2494 				p_business_group_id   IN  NUMBER,
2495                                 p_set_of_books_id     IN  NUMBER,
2496 				p_attribute_category	IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
2497 				p_attribute1		IN	VARCHAR2,
2498 				p_attribute2		IN	VARCHAR2,
2499 				p_attribute3		IN	VARCHAR2,
2500 				p_attribute4		IN	VARCHAR2,
2501 				p_attribute5		IN	VARCHAR2,
2502 				p_attribute6		IN	VARCHAR2,
2503 				p_attribute7		IN	VARCHAR2,
2504 				p_attribute8		IN	VARCHAR2,
2505 				p_attribute9		IN	VARCHAR2,
2506 				p_attribute10		IN	VARCHAR2,
2507                                 p_return_status       OUT NOCOPY VARCHAR2) IS
2508 
2509 
2510   CURSOR sch_lines_assignment_cur(P_ASSIGNMENT_ID      NUMBER,
2511                                   P_PAYROLL_START_DATE DATE) IS
2512   SELECT psl.schedule_line_id,
2513          psl.gl_code_combination_id,
2514          psl.project_id,
2515          psl.task_id,
2516          psl.award_id,
2517          round(psl.schedule_percent,2) schedule_percent,
2518          psl.expenditure_type,
2519          psl.expenditure_organization_id,
2520          psl.schedule_begin_date,
2521          nvl(psl.schedule_end_date,p_payroll_start_date),
2522 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute_category, psl.attribute_category)) attribute_category,		-- Introduced DFF columns for bug fix 2908859
2523 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute1, psl.attribute1)) attribute1,
2524 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute2, psl.attribute2)) attribute2,
2525 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute3, psl.attribute3)) attribute3,
2526 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute4, psl.attribute4)) attribute4,
2527 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute5, psl.attribute5)) attribute5,
2528 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute6, psl.attribute6)) attribute6,
2529 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute7, psl.attribute7)) attribute7,
2530 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute8, psl.attribute8)) attribute8,
2531 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute9, psl.attribute9)) attribute9,
2532 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute10, psl.attribute10)) attribute10
2533   FROM   psp_schedule_hierarchy psh,
2534          psp_schedule_lines     psl
2535   WHERE  psh.business_group_id = p_business_group_id
2536   AND    psh.set_of_books_id   = p_set_of_books_id
2537   AND	 psh.scheduling_types_code = 'A'
2538   AND    psh.element_group_id IS NULL
2539   AND    psh.element_type_id IS NULL
2540   AND    psh.assignment_id = p_assignment_id
2541   AND    psh.schedule_hierarchy_id = psl.schedule_hierarchy_id
2542   AND	 psl.business_group_id = psh.business_group_id
2543   AND    psl.set_of_books_id   = psh.set_of_books_id
2544   AND    p_payroll_start_date BETWEEN psl.schedule_begin_date AND
2545                                       nvl(psl.schedule_end_date,p_payroll_start_date);
2546 
2547 
2548   x_proc_executed                  VARCHAR2(10) := 'TRUE';
2549   l_dist_amount                    NUMBER       := 0;
2550   l_tot_dist_amount                NUMBER       := 0;
2551   l_bal_dist_amount                NUMBER       := 0;
2552   l_tot_percent                    NUMBER       := 0;
2553 
2554   l_schedule_line_id               NUMBER(15);
2555   l_gl_code_combination_id         NUMBER(15);
2556   l_project_id                     NUMBER(15);
2557   l_task_id                        NUMBER(15);
2558   l_award_id                       NUMBER(15);
2559   l_schedule_percent               NUMBER;
2560   l_expenditure_type               VARCHAR2(30);
2561   l_expenditure_org_id             NUMBER(15);
2562   l_effective_start_date           DATE;
2563   l_effective_end_date             DATE;
2564 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variables for bug fix 2908859
2565 	l_attribute1		VARCHAR2(150);
2566 	l_attribute2		VARCHAR2(150);
2567 	l_attribute3		VARCHAR2(150);
2568 	l_attribute4		VARCHAR2(150);
2569 	l_attribute5		VARCHAR2(150);
2570 	l_attribute6		VARCHAR2(150);
2571 	l_attribute7		VARCHAR2(150);
2572 	l_attribute8		VARCHAR2(150);
2573 	l_attribute9		VARCHAR2(150);
2574 	l_attribute10		VARCHAR2(150);
2575   l_rec_count                      NUMBER := 0;
2576   l_return_status                  VARCHAR2(1);
2577   ---  l_effective_date                 DATE; Bug 1874696
2578   l_gl_project_flag                VARCHAR2(1);
2579   l_linkage_status                 VARCHAR2(50);
2580   l_patc_status                    VARCHAR2(50);
2581   l_billable_flag                  VARCHAR2(1);
2582   l_msg_count                      NUMBER;
2583   l_msg_app                        VARCHAR2(2000);
2584   l_msg_type                       varchar2(2000);
2585   l_msg_token1                     varchar2(2000);
2586   l_msg_token2                     varchar2(2000);
2587   l_msg_token3                     varchar2(2000);
2588   --l_award_status  varchar2(50);  -- for bug fix 1931680
2589   l_award_status  varchar2(200);
2590  BEGIN
2591         -- dbms_output.put_line('asg hierarchy sub_line_id = '|| p_sub_line_id);
2592          p_proc_executed := 'TRUE';
2593 
2594          -- For the payroll date passed to the procedure, check if there are schedule line(s).
2595          -- If the schedule line(s) exists, then fetch the schedule percent and calculate the
2596          -- total distribution amount by adding the distribution amount in each of the lines.
2597          -- If the schedule line(s) does not exist,set the p_proc_executed flag as FALSE
2598 
2599          OPEN sch_lines_assignment_cur(p_assignment_id,p_payroll_start_date);
2600 
2601          LOOP
2602            l_linkage_status  := NULL;
2603            l_patc_status     := NULL;
2604            l_billable_flag   := NULL;
2605 	   l_award_status    := NULL;
2606 
2607            FETCH sch_lines_assignment_cur INTO
2608 		        l_schedule_line_id,
2609                         l_gl_code_combination_id,
2610   			l_project_id,
2611   			l_task_id,
2612   			l_award_id,
2613   			l_schedule_percent,
2614                         l_expenditure_type,
2615                         l_expenditure_org_id,
2616                         l_effective_start_date,
2617                         l_effective_end_date,
2618 			l_attribute_category,			-- Introduced DFf variable for bug fix 2908859
2619 			l_attribute1,
2620 			l_attribute2,
2621 			l_attribute3,
2622 			l_attribute4,
2623 			l_attribute5,
2624 			l_attribute6,
2625 			l_attribute7,
2626 			l_attribute8,
2627 			l_attribute9,
2628 			l_attribute10;
2629 
2630            l_rec_count := l_rec_count + 1;
2631            IF sch_lines_assignment_cur%NOTFOUND THEN
2632              IF l_rec_count = 1 THEN
2633                p_proc_executed := 'FALSE';
2634                CLOSE sch_lines_assignment_cur;
2635                RETURN;
2636              ELSE
2637                CLOSE sch_lines_assignment_cur;
2638                EXIT;
2639              END IF;
2640            END IF;
2641           -- dbms_output.put_line('asg hiearchy l_schedule_line_id='||l_schedule_line_id);
2642            l_tot_percent := l_tot_percent + l_schedule_percent;
2643            IF l_tot_percent <= 100 THEN
2644              l_dist_amount := round((p_daily_rate * l_schedule_percent/100), g_precision); 	-- Bug 2916848: Modified to currency precision (from 2)
2645            -- ELSIF l_tot_percent = 100 THEN
2646            --   l_dist_amount := round((p_daily_rate - l_tot_dist_amount),2);
2647            ELSIF l_tot_percent > 100 THEN
2648 	    	 Get_assign_number(p_assignment_id
2649 			      ,p_payroll_start_date
2650 			      ,g_assignment_number
2651 			      ,g_employee_number);--Bug 2374680
2652              	fnd_message.set_name('PSP','PSP_LD_PERCENT_GREATER_100');
2653              	fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
2654 --           	fnd_message.set_token('ASSIGNMENT_ID',p_assignment_id); --Commented for bug 2374680
2655              	/* Added assignment_number and employee_number inplace of assignment_id*/
2656             	fnd_message.set_token('ASSIGNMENT_NUMBER',g_assignment_number);
2657             	fnd_message.set_token('EMPLOYEE_NUMBER',g_employee_number);
2658              	fnd_msg_pub.add;
2659 --		Commented for bug fix 2267098 (return status set in exception)
2660 --             	p_return_status := fnd_api.g_ret_sts_unexp_error;
2661 		RAISE fnd_api.g_exc_unexpected_error;	-- Introduced for bug 2267098
2662 
2663            END IF;
2664 
2665            l_tot_dist_amount := round((l_tot_dist_amount + l_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
2666 
2667 
2668            IF l_gl_code_combination_id IS NOT NULL THEN
2669               --- l_effective_date := p_effective_date; 1874696
2670               l_gl_project_flag := 'G';
2671 
2672               -- insert the record in psp_distribution_lines
2673               insert_into_distribution_lines(
2674  			P_SUB_LINE_ID,             -- payroll sub-lines id
2675  			P_PAYROLL_START_DATE,      -- distribution date
2676                         G_GL_EFFECTIVE_DATE,       -- changed fron p_effective date  --- Bug 2663344
2677  			L_DIST_AMOUNT,             -- distribution amount
2678  			'N',                       -- status code
2679                         NULL,                      -- suspense reason code
2680                         NULL,                      -- default reason code
2681       			L_SCHEDULE_LINE_ID,        -- schedule line id
2682  			NULL,                      -- default organization a/c
2683  			NULL,                      -- suspense organization a/c
2684  			NULL,                      -- global element type
2685 			NULL,                      -- org default schedule id
2686                         L_GL_PROJECT_FLAG,         -- gl project flag
2687                         NULL,                      -- reversal entry flag
2688                         l_gl_code_combination_id,  -- gl_code_combination_id
2689                         l_project_id,              -- project_id,
2690                         l_task_id   ,              -- task_id,
2691                         l_award_id  ,              -- award_id,
2692                         l_expenditure_org_id,      -- expenditure org id
2693                         l_expenditure_type,        -- expenditure_type
2694                         l_effective_start_date,    -- Eff start date of schedule
2695                         l_effective_end_date,      -- Eff start date of schedule
2696                         p_mode,                    -- 'I' for LD ,'R' for others
2697 			p_business_group_id,       -- Business Group Id
2698                         p_set_of_books_id,         -- Set of Books Id
2699 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
2700 			l_attribute1,
2701 			l_attribute2,
2702 			l_attribute3,
2703 			l_attribute4,
2704 			l_attribute5,
2705 			l_attribute6,
2706 			l_attribute7,
2707 			l_attribute8,
2708 			l_attribute9,
2709 			l_attribute10,
2710                         l_return_status);
2711 
2712               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2713                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2714               END IF;
2715 --            END IF; -- g_auto_population = 'Y'   bug fix 2023955
2716 
2717 
2718            ELSIF l_gl_code_combination_id IS NULL THEN
2719 
2720             --- IF (g_auto_population = 'Y'  and p_mode= 'I' ) THEN   5080403
2721             IF g_asg_autopop = 'Y' THEN
2722                    l_gl_project_flag:='P';
2723 
2724                     insert_into_distribution_lines(
2725  			P_SUB_LINE_ID,             -- payroll sub-line_id
2726  			P_PAYROLL_START_DATE,      -- distribution date
2727                         P_EFFECTIVE_DATE,          -- effective date     Bug 1874696 Changed from l_Effective_date
2728  			L_DIST_AMOUNT,             -- distribution amount
2729  			'N',                       -- status code
2730                         NULL,                      -- suspense reason code
2731                         NULL,                      -- default reason code
2732       			L_SCHEDULE_LINE_ID,        -- schedule line id
2733  			NULL,                      -- default organization a/c
2734  			NULL,                      -- suspense organization a/c
2735 			NULL,                      -- global element type
2736 			NULL,                      -- org default schedule id
2737                         L_GL_PROJECT_FLAG,         -- gl project flag
2738                         NULL,                      -- reversal entry flag
2739                         l_gl_code_combination_id,  -- gl_code_combination_id
2740                         l_project_id,              -- project_id,
2741                         l_task_id   ,              -- task_id,
2742                         l_award_id  ,              -- award_id,
2743                         l_expenditure_org_id,      -- expenditure org id
2744                         l_expenditure_type,        -- expenditure_type
2745                         l_effective_start_date,    -- Eff start date of schedule
2746                         l_effective_end_date,      -- Eff start date of schedule
2747                         p_mode,                    -- 'I' for LD ,'R' for others
2748 			p_business_group_id,       -- Business Group Id
2749                         p_set_of_books_id,         -- Set of Books Id
2750 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
2751 			l_attribute1,
2752 			l_attribute2,
2753 			l_attribute3,
2754 			l_attribute4,
2755 			l_attribute5,
2756 			l_attribute6,
2757 			l_attribute7,
2758 			l_attribute8,
2759 			l_attribute9,
2760 			l_attribute10,
2761                         l_return_status);
2762 
2763                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2764                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2765                     END IF;
2766 
2767             ELSE
2768 		  -- Auto-Population is OFF. Get project status and insert record.
2769 
2770 	 -- modified as per 11i changes
2771 	   -- dbms_output.put_line('Project id 4 '|| to_char(l_project_id));
2772 	   -- dbms_output.put_line('task id 4 '|| to_char(l_task_id));
2773 	   -- dbms_output.put_line('Type 4 '|| l_expenditure_type);
2774 	   -- dbms_output.put_line('Dt 4 '|| to_char(p_payroll_start_date));
2775 	   -- dbms_output.put_line('person_id 4 '|| to_char(p_person_id));
2776 
2777 	    pa_transactions_pub.validate_transaction(
2778 			x_project_id		=> l_project_id,
2779 			x_task_id		=> l_task_id,
2780 			x_ei_date		=> p_effective_date, --- Bug 1874696 p_payroll_start_date,
2781 			x_expenditure_type	=> l_expenditure_type,
2782 			x_non_labor_resource	=> null,
2783 			x_person_id		=> p_person_id,
2784 			x_incurred_by_org_id	=> l_expenditure_org_id,
2785 			x_calling_module	=> 'PSPLDCDB',
2786 			x_msg_application	=> l_msg_app,
2787 			x_msg_type		=> l_msg_type,
2788 			x_msg_token1		=> l_msg_token1,
2789 			x_msg_token2		=> l_msg_token2,
2790 			x_msg_token3		=> l_msg_token3,
2791 			x_msg_count		=> l_msg_count,
2792 			x_msg_data		=> l_patc_status,
2793 			x_billable_flag		=> l_billable_flag,
2794 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
2795 
2796 
2797 	   -- dbms_output.put_line('patc stat 4 '|| l_patc_status|| ' p_eff_date='||p_effective_date);
2798 	    -- GMS is enabled and patc went through
2799 	     if l_award_id is not null and l_patc_status is null
2800              then
2801                  gms_transactions_pub.validate_transaction
2802                                 (l_project_id,
2803                                 l_task_id,
2804 				l_award_id,
2805                                 l_expenditure_type,
2806                                 p_effective_date, ----p_payroll_start_date, Bug 1874696
2807                                 'PSPLDCDB',
2808                                 l_award_status);
2809 
2810 /**************************************************************
2811                  if l_award_status is null
2812                  then
2813                         project_award_linkage(l_project_id,
2814                                   l_award_id,
2815                                   l_linkage_status,
2816                                   l_return_status);
2817 		 else
2818  bug 2054610
2819 
2820 ***************************************************************/
2821                    if l_award_status is not null then
2822 		--	l_patc_status := l_award_status;  for bug fix 1931680
2823                         l_patc_status  := substr(l_award_status,1,50);
2824                  end if;
2825              end if;
2826 
2827              IF (l_patc_status IS NOT NULL)
2828 --  2054610 OR (l_linkage_status IS NOT NULL)
2829 		OR (l_award_status is not null) THEN
2830                 suspense_account(
2831                          x_proc_executed,
2832                          p_person_id,
2833                          p_sub_line_id,
2834                          p_assignment_id,
2835                          p_payroll_start_date,
2836                          l_dist_amount,
2837                          l_patc_status,
2838                          l_schedule_line_id,
2839                          NULL,
2840                          NULL,
2841                          NULL,
2842                          p_effective_date,
2843                          p_mode,
2844 			 p_business_group_id,
2845                          p_set_of_books_id,
2846                          NULL,   ---    for autopop perf. patch
2847                          l_return_status);
2848 
2849                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2850                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2851                  END IF;
2852 
2853               ELSIF (l_patc_status IS NULL)
2854 ---- OR (l_linkage_status IS NULL)
2855  OR
2856 			(l_award_status is null) THEN
2857                 /* Bug 1874696
2858 		if l_award_id is not null
2859 		then
2860                     psp_general.poeta_effective_date(p_payroll_start_date,
2861                                      l_project_id,
2862                                      l_award_id,
2863 				     l_task_id,
2864                                      l_effective_date,
2865                                      l_return_status);
2866 		elsif l_award_id is null
2867 		then
2868                     psp_general.poeta_effective_date(p_payroll_start_date,
2869                                      l_project_id,
2870 				     l_task_id,
2871                                      l_effective_date,
2872                                      l_return_status);
2873 		end if;
2874                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2875                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2876                     END IF; */
2877                     l_gl_project_flag := 'P';
2878 
2879                     -- insert the record in psp_distribution_lines
2880                     insert_into_distribution_lines(
2881  			P_SUB_LINE_ID,             -- payroll sub-line_id
2882  			P_PAYROLL_START_DATE,      -- distribution date
2883                         P_EFFECTIVE_DATE,          -- effective date     Bug 1874696 Changed from l_Effective_date
2884  			L_DIST_AMOUNT,             -- distribution amount
2885  			'N',                       -- status code
2886                         NULL,                      -- suspense reason code
2887                         NULL,                      -- default reason code
2888       			L_SCHEDULE_LINE_ID,        -- schedule line id
2889  			NULL,                      -- default organization a/c
2890  			NULL,                      -- suspense organization a/c
2891 			NULL,                      -- global element type
2892 			NULL,                      -- org default schedule id
2893                         L_GL_PROJECT_FLAG,         -- gl project flag
2894                         NULL,                      -- reversal entry flag
2895                         l_gl_code_combination_id,  -- gl_code_combination_id
2896                         l_project_id,              -- project_id,
2897                         l_task_id   ,              -- task_id,
2898                         l_award_id  ,              -- award_id,
2899                         l_expenditure_org_id,      -- expenditure org id
2900                         l_expenditure_type,        -- expenditure_type
2901                         l_effective_start_date,    -- Eff start date of schedule
2902                         l_effective_end_date,      -- Eff start date of schedule
2903                         p_mode,                    -- 'I' for LD ,'R' for others
2904 			p_business_group_id,       -- Business Group Id
2905                         p_set_of_books_id,         -- Set of Books Id
2906 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
2907 			l_attribute1,
2908 			l_attribute2,
2909 			l_attribute3,
2910 			l_attribute4,
2911 			l_attribute5,
2912 			l_attribute6,
2913 			l_attribute7,
2914 			l_attribute8,
2915 			l_attribute9,
2916 			l_attribute10,
2917                         l_return_status);
2918 
2919                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2920                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2921                     END IF;
2922              END IF;
2923            END IF; -- g_auto_population = 'Y'
2924           END IF;
2925 
2926          END LOOP; -- loop through all the schedule lines having the payroll period date
2927 
2928          l_bal_dist_amount  := round((p_daily_rate - l_tot_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
2929 
2930          -- IF abs(l_bal_dist_amount) > 0 THEN  -- #1339616
2931          IF l_tot_percent < 100 THEN
2932 
2933            IF p_org_def_account = 'Y' then
2934              default_account(
2935                             x_proc_executed,
2936                             p_person_id,
2937                             p_sub_line_id,
2938                             p_assignment_id,
2939                             p_payroll_start_date,
2940                             l_bal_dist_amount,
2941                             '1',---'LDM_BAL_NOT_100_PERCENT',
2942                             p_effective_date,
2943                             p_mode,
2944 			    p_business_group_id,
2945                             p_set_of_books_id,
2946 				p_attribute_category,	-- Introduced DFF columns for bug fix 2908859
2947 				p_attribute1,
2948 				p_attribute2,
2949 				p_attribute3,
2950 				p_attribute4,
2951 				p_attribute5,
2952 				p_attribute6,
2953 				p_attribute7,
2954 				p_attribute8,
2955 				p_attribute9,
2956 				p_attribute10,
2957                             l_return_status);
2958 
2959                IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2960                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2961                END IF;
2962 
2963               IF x_proc_executed = 'FALSE' then
2964                 suspense_account(
2965                                  x_proc_executed,
2966                                  p_person_id,
2967                                  p_sub_line_id,
2968                                  p_assignment_id,
2969                                  p_payroll_start_date,
2970                                  l_bal_dist_amount,
2971                                  'LDM_BAL_NOT_100_PERCENT',
2972                                  NULL,
2973                                  NULL,
2974                                  NULL,
2975                                  NULL,
2976                                  p_effective_date,
2977                                  p_mode,
2978 				 p_business_group_id,
2979                                  p_set_of_books_id,
2980                                  NULL,   ---    for autopop perf. patch
2981                                  l_return_status);
2982 
2983                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2984                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2985                  END IF;
2986 
2987                END IF;
2988            ELSE
2989                 suspense_account(
2990                                  x_proc_executed,
2991                                  p_person_id,
2992                                  p_sub_line_id,
2993                                  p_assignment_id,
2994                                  p_payroll_start_date,
2995                                  l_bal_dist_amount,
2996                                  'LDM_BAL_NOT_100_PERCENT',
2997                                  NULL,
2998                                  NULL,
2999                                  NULL,
3000                                  NULL,
3001                                  p_effective_date,
3002                                  p_mode,
3003 				 p_business_group_id,
3004                                  p_set_of_books_id,
3005                                  NULL,   ---    for autopop perf. patch
3006                                  l_return_status);
3007 
3008                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3009                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3010                  END IF;
3011 
3012            END IF;
3013          END IF;
3014    --
3015    p_return_status := fnd_api.g_ret_sts_success;
3016 
3017  EXCEPTION
3018    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3019      -- dbms_output.put_line(' asg hiearchy unexpected error');
3020       g_error_api_path := SUBSTR('ASSIGNMENT_HIERARCHY:'||g_error_api_path,1,230);
3021       p_return_status := fnd_api.g_ret_sts_unexp_error;
3022 
3023    WHEN OTHERS THEN
3024      -- dbms_output.put_line(' asg hiearchy when others ='||sqlerrm);
3025       g_error_api_path := SUBSTR('ASSIGNMENT_HIERARCHY:'||g_error_api_path,1,230);
3026       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','ASSIGNMENT_HIERARCHY');
3027       p_return_status := fnd_api.g_ret_sts_unexp_error;
3028 
3029  END;
3030 
3031 --------------------------  ORGANIZATION DEFAULT LABOR SCHEDULE   --------------------------
3032  PROCEDURE org_labor_schedule_hierarchy(
3033                            p_proc_executed      OUT NOCOPY  VARCHAR2,
3034                            p_person_id           IN  NUMBER,
3035                            p_sub_line_id         IN  NUMBER,
3036                            p_assignment_id       IN  NUMBER,
3037                            p_element_type_id     IN  NUMBER,
3038                            p_payroll_start_date  IN  DATE,
3039                            p_daily_rate          IN  NUMBER,
3040                            p_org_def_account     IN  VARCHAR2,
3041                            p_effective_date      IN  DATE,
3042                            p_mode                IN  VARCHAR2 := 'I',
3043 			   p_business_group_id   IN  NUMBER,
3044                            p_set_of_books_id     IN  NUMBER,
3045 				p_attribute_category	IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
3046 				p_attribute1		IN	VARCHAR2,
3047 				p_attribute2		IN	VARCHAR2,
3048 				p_attribute3		IN	VARCHAR2,
3049 				p_attribute4		IN	VARCHAR2,
3050 				p_attribute5		IN	VARCHAR2,
3051 				p_attribute6		IN	VARCHAR2,
3052 				p_attribute7		IN	VARCHAR2,
3053 				p_attribute8		IN	VARCHAR2,
3054 				p_attribute9		IN	VARCHAR2,
3055 				p_attribute10		IN	VARCHAR2,
3056                            p_return_status       OUT NOCOPY VARCHAR2) IS
3057 
3058 
3059   CURSOR org_labor_schedule_cur(P_ASSIGNMENT_ID      NUMBER,
3060                                 P_PAYROLL_START_DATE DATE) IS
3061   SELECT pdls.org_schedule_id,
3062          pdls.gl_code_combination_id,
3063          pdls.project_id,
3064          pdls.task_id,
3065          pdls.award_id,
3066          round(pdls.schedule_percent,2) schedule_percent,
3067          pdls.expenditure_type,
3068          pdls.expenditure_organization_id,
3069          pdls.schedule_begin_date,
3070          nvl(pdls.schedule_end_date,p_payroll_start_date),
3071             --- introduced decode for 5014193
3072 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute_category, pdls.attribute_category)) attribute_category,		-- Introduced DFF columns for bug fix 2908859
3073 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute1, pdls.attribute1)) attribute1,
3074 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute2, pdls.attribute2)) attribute2,
3075 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute3, pdls.attribute3)) attribute3,
3076 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute4, pdls.attribute4)) attribute4,
3077 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute5, pdls.attribute5)) attribute5,
3078 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute6, pdls.attribute6)) attribute6,
3079 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute7, pdls.attribute7)) attribute7,
3080 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute8, pdls.attribute8)) attribute8,
3081 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute9, pdls.attribute9)) attribute9,
3082 	 decode(g_dff_grouping_option, 'Y',NVL(p_attribute10, pdls.attribute10)) attribute10
3083   FROM   per_assignments_f paf,
3084          psp_default_labor_schedules pdls
3085   WHERE  pdls.business_group_id = p_business_group_id
3086   AND    pdls.set_of_books_id   = p_set_of_books_id
3087   and    paf.assignment_type = 'E'
3088   AND    pdls.organization_id = paf.organization_id
3089   AND    paf.assignment_id = p_assignment_id
3090   AND    p_payroll_start_date BETWEEN paf.effective_start_date AND paf.effective_end_date
3091   AND    p_payroll_start_date BETWEEN pdls.schedule_begin_date AND
3092                                       nvl(pdls.schedule_end_date,p_payroll_start_date);
3093 
3094   x_proc_executed                  VARCHAR2(10) := 'TRUE';
3095   l_dist_amount                    NUMBER       := 0;
3096   l_tot_dist_amount                NUMBER       := 0;
3097   l_bal_dist_amount                NUMBER       := 0;
3098   l_tot_percent                    NUMBER       := 0;
3099 
3100   l_org_schedule_id                NUMBER(9);
3101   l_gl_code_combination_id         NUMBER(15);
3102   l_project_id                     NUMBER(15);
3103   l_task_id                        NUMBER(15);
3104   l_award_id                       NUMBER(15);
3105   l_expenditure_type               VARCHAR2(30);
3106   l_expenditure_org_id             NUMBER(15);
3107   l_effective_start_date           DATE;
3108   l_effective_end_date             DATE;
3109 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variables for bug fix 2908859
3110 	l_attribute1		VARCHAR2(150);
3111 	l_attribute2		VARCHAR2(150);
3112 	l_attribute3		VARCHAR2(150);
3113 	l_attribute4		VARCHAR2(150);
3114 	l_attribute5		VARCHAR2(150);
3115 	l_attribute6		VARCHAR2(150);
3116 	l_attribute7		VARCHAR2(150);
3117 	l_attribute8		VARCHAR2(150);
3118 	l_attribute9		VARCHAR2(150);
3119 	l_attribute10		VARCHAR2(150);
3120   l_schedule_percent               NUMBER;
3121   l_rec_count                      NUMBER := 0;
3122   l_return_status                  VARCHAR2(1);
3123   ---l_effective_date                 DATE; Bug 1874696
3124   l_gl_project_flag                VARCHAR2(1);
3125   l_linkage_status                 VARCHAR2(50);
3126   l_patc_status                    VARCHAR2(50);
3127   l_billable_flag                  VARCHAR2(1);
3128   l_msg_count                      NUMBER;
3129   l_msg_app                        VARCHAR2(2000);
3130   l_msg_type                       varchar2(2000);
3131   l_msg_token1                     varchar2(2000);
3132   l_msg_token2                     varchar2(2000);
3133   l_msg_token3                     varchar2(2000);
3134   --l_award_status  varchar2(50);  -- for bug fix 1931680
3135   l_award_status  varchar2(200);
3136 
3137  BEGIN
3138          p_proc_executed := 'TRUE';
3139 
3140          -- For the payroll date passed to the procedure, check if there are schedule line(s).
3141          -- If the schedule line(s) exists, then fetch the schedule percent and calculate the
3142          -- total distribution amount by adding the distribution amount in each of the lines.
3143          -- If the schedule line(s) does not exist,set the p_proc_executed flag as FALSE
3144 
3145          OPEN org_labor_schedule_cur(p_assignment_id,p_payroll_start_date);
3146          hr_utility.trace('entered org labor schedules proce');
3147 
3148          LOOP
3149            l_linkage_status  := NULL;
3150            l_patc_status     := NULL;
3151            l_billable_flag   := NULL;
3152 	   l_award_status    := NULL;
3153 
3154            FETCH org_labor_schedule_cur INTO
3155 		        l_org_schedule_id,
3156                         l_gl_code_combination_id,
3157   			l_project_id,
3158   			l_task_id,
3159   			l_award_id,
3160   			l_schedule_percent,
3161                         l_expenditure_type,
3162                         l_expenditure_org_id,
3163                         l_effective_start_date,
3164                         l_effective_end_date,
3165 			l_attribute_category,			-- Introduced DFf variable for bug fix 2908859
3166 			l_attribute1,
3167 			l_attribute2,
3168 			l_attribute3,
3169 			l_attribute4,
3170 			l_attribute5,
3171 			l_attribute6,
3172 			l_attribute7,
3173 			l_attribute8,
3174 			l_attribute9,
3175 			l_attribute10;
3176 
3177            l_rec_count := l_rec_count + 1;
3178            IF org_labor_schedule_cur%NOTFOUND THEN
3179              IF l_rec_count = 1 THEN
3180                p_proc_executed := 'FALSE';
3181                CLOSE org_labor_schedule_cur;
3182                RETURN;
3183              ELSE
3184                CLOSE org_labor_schedule_cur;
3185                EXIT;
3186              END IF;
3187            END IF;
3188 
3189            l_tot_percent := l_tot_percent + l_schedule_percent;
3190            IF l_tot_percent <= 100 THEN
3191              l_dist_amount := round((p_daily_rate * l_schedule_percent/100), g_precision); 	-- Bug 2916848: Modified to currency precision (from 2)
3192            -- ELSIF l_tot_percent = 100 THEN
3193            --   l_dist_amount := round((p_daily_rate - l_tot_dist_amount),2);
3194            ELSIF l_tot_percent > 100 THEN
3195 	     	Get_assign_number(p_assignment_id
3196 			      ,p_payroll_start_date
3197 			      ,g_assignment_number
3198 			      ,g_employee_number);--Bug 2374680
3199              	fnd_message.set_name('PSP','PSP_LD_PERCENT_GREATER_100');
3200              	fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
3201 --           	fnd_message.set_token('ASSIGNMENT_ID',p_assignment_id); --Commented for bug 2374680
3202              	/* Added assignment_number and employee_number inplace of assignment_id*/
3203              	fnd_message.set_token('ASSIGNMENT_NUMBER',g_assignment_number);
3204              	fnd_message.set_token('EMPLOYEE_NUMBER',g_employee_number);
3205              	fnd_msg_pub.add;
3206 --		Commented for bug fix 2267098 (return status set in exception)
3207 --             p_return_status := fnd_api.g_ret_sts_unexp_error;
3208 		RAISE fnd_api.g_exc_unexpected_error;	-- Introduced for bug 2267098
3209 
3210            END IF;
3211 
3212            l_tot_dist_amount := round((l_tot_dist_amount + l_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
3213 
3214            IF l_gl_code_combination_id IS NOT NULL THEN
3215               --- l_effective_date := p_effective_date; Bug 1874696
3216               l_gl_project_flag := 'G';
3217 
3218               -- insert the record in psp_distribution_lines
3219          hr_utility.trace('inserting dist line for g_org_schedule_autopop ='||g_org_schedule_autopop);
3220               insert_into_distribution_lines(
3221  			P_SUB_LINE_ID,              -- payroll sub-lines id
3222  			P_PAYROLL_START_DATE,       -- distribution date
3223                         G_GL_EFFECTIVE_DATE,        -- changed from p_effective date  Bug 2663344
3224  			L_DIST_AMOUNT,              -- distribution amount
3225  			'N',                        -- status code
3226                         NULL,                       -- suspense reason code
3227                         NULL,                       -- default reason code
3228       			NULL,                       -- schedule line id
3229  			NULL,                       -- default organization a/c
3230  			NULL,                       -- suspense organization a/c
3231  			NULL,                       -- global element type
3232 			L_ORG_SCHEDULE_ID,          -- org default schedule id
3233                         L_GL_PROJECT_FLAG,          -- gl project flag
3234                         NULL,                       -- reversal entry flag
3235                         l_gl_code_combination_id,   -- gl_code_combination_id
3236                         l_project_id,               -- project_id,
3237                         l_task_id   ,               -- task_id,
3238                         l_award_id  ,               -- award_id,
3239                         l_expenditure_org_id,       -- expenditure org id
3240                         l_expenditure_type,         -- expenditure_type
3241                         l_effective_start_date,    -- Eff start date of schedule
3242                         l_effective_end_date,      -- Eff start date of schedule
3243                         p_mode,                    -- 'I' for LD ,'R' for others
3244 			p_business_group_id,       -- Business Group Id
3245                         p_set_of_books_id,         -- Set of Books Id
3246 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
3247 			l_attribute1,
3248 			l_attribute2,
3249 			l_attribute3,
3250 			l_attribute4,
3251 			l_attribute5,
3252 			l_attribute6,
3253 			l_attribute7,
3254 			l_attribute8,
3255 			l_attribute9,
3256 			l_attribute10,
3257                         l_return_status);
3258 
3259               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3260                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3261               END IF;
3262  --           END IF; -- g_auto_population = 'Y'  for bug fix 2023955
3263 
3264            ELSIF l_gl_code_combination_id IS NULL THEN
3265 
3266   		  ---IF (g_auto_population = 'Y' and p_mode='I') THEN -- commented for 5080403
3267                   if (g_org_schedule_autopop = 'Y') then
3268          hr_utility.trace('g_org_schedule_autopop = Y');
3269 
3270  -- bug fix  2023955
3271                    l_gl_project_flag:='P';
3272 
3273  ---- Insert the record into psp_distribution_lines
3274 
3275               insert_into_distribution_lines(
3276  			P_SUB_LINE_ID,              -- payroll sub-lines id
3277  			P_PAYROLL_START_DATE,       -- distribution date
3278                         P_EFFECTIVE_DATE,           -- effective date     Bug 1874696
3279  			L_DIST_AMOUNT,              -- distribution amount
3280  			'N',                        -- status code
3281                         NULL,                       -- suspense reason code
3282                         NULL,                       -- default reason code
3283       			NULL,                       -- schedule line id
3284  			NULL,                       -- default organization a/c
3285  			NULL,                       -- suspense organization a/c
3286  			NULL,                       -- global element type
3287 			L_ORG_SCHEDULE_ID,          -- org default schedule id
3288                         L_GL_PROJECT_FLAG,          -- gl project flag
3289                         NULL,                       -- reversal entry flag
3290                         l_gl_code_combination_id,   -- gl_code_combination_id
3291                         l_project_id,               -- project_id,
3292                         l_task_id   ,               -- task_id,
3293                         l_award_id  ,               -- award_id,
3294                         l_expenditure_org_id,       -- expenditure org id
3295                         l_expenditure_type,         -- expenditure_type
3296                         l_effective_start_date,    -- Eff start date of schedule
3297                         l_effective_end_date,      -- Eff start date of schedule
3298                         p_mode,                    -- 'I' for LD ,'R' for others
3299 			p_business_group_id,       -- Business Group id
3300                         p_set_of_books_id,         -- Set of Books Id
3301 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
3302 			l_attribute1,
3303 			l_attribute2,
3304 			l_attribute3,
3305 			l_attribute4,
3306 			l_attribute5,
3307 			l_attribute6,
3308 			l_attribute7,
3309 			l_attribute8,
3310 			l_attribute9,
3311 			l_attribute10,
3312                         l_return_status);
3313 
3314                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3315                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3316                     END IF;
3317 
3318 ELSE --   bug fix 2023955
3319 
3320 	-- modified as per 11i changes
3321 	   -- dbms_output.put_line('Project id 5 '|| to_char(l_project_id));
3322 	   -- dbms_output.put_line('task id 5 '|| to_char(l_task_id));
3323 	   -- dbms_output.put_line('Type 5 '|| l_expenditure_type);
3324 	   -- dbms_output.put_line('Dt 5 '|| to_char(p_payroll_start_date));
3325 	   -- dbms_output.put_line('person_id 5 '|| to_char(p_person_id));
3326 	    pa_transactions_pub.validate_transaction(
3327 			x_project_id		=> l_project_id,
3328 			x_task_id		=> l_task_id,
3329 			x_ei_date		=> p_effective_date, ---p_payroll_start_date, Bug 1874696
3330 			x_expenditure_type	=> l_expenditure_type,
3331 			x_non_labor_resource	=> null,
3332 			x_person_id		=> p_person_id,
3333 			x_incurred_by_org_id	=> l_expenditure_org_id,
3334 			x_calling_module	=> 'PSPLDCDB',
3335 			x_msg_application	=> l_msg_app,
3336 			x_msg_type		=> l_msg_type,
3337 			x_msg_token1		=> l_msg_token1,
3338 			x_msg_token2		=> l_msg_token2,
3339 			x_msg_token3		=> l_msg_token3,
3340 			x_msg_count		=> l_msg_count,
3341 			x_msg_data		=> l_patc_status,
3342 			x_billable_flag		=> l_billable_flag,
3343 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
3344 
3345 
3346 	   -- dbms_output.put_line('patc stat 5 '|| l_patc_status);
3347 	    -- GMS is enabled and patc went through
3348 	    if l_award_id is not null and l_patc_status is null
3349              then
3350                  gms_transactions_pub.validate_transaction
3351                                 (l_project_id,
3352                                 l_task_id,
3353 				l_award_id,
3354                                 l_expenditure_type,
3355                                 p_effective_date, ----p_payroll_start_date, Bug 1874696
3356                                 'PSPLDCDB',
3357                                 l_award_status);
3358 
3359 /****************************************************************************************
3360                  if l_award_status is null
3361                  then
3362                         project_award_linkage(l_project_id,
3363                                   l_award_id,
3364                                   l_linkage_status,
3365                                   l_return_status);
3366 		 else
3367 
3368 
3369 ****************************************************************************************/
3370 
3371                 if l_award_status IS NOT NULL then
3372 		--	l_patc_status := l_award_status;  for bug fix 1931680
3373                         l_patc_status  := substr(l_award_status,1,50);
3374                  end if;
3375              end if;
3376 
3377              IF (l_patc_status IS NOT NULL) OR
3378 ---  (l_linkage_status IS NOT NULL) OR
3379 		(l_award_status IS NOT NULL) THEN
3380                 suspense_account(
3381                          x_proc_executed,
3382                          p_person_id,
3383                          p_sub_line_id,
3384                          p_assignment_id,
3385                          p_payroll_start_date,
3386                          l_dist_amount,
3387                          l_patc_status,
3388                          NULL,
3389                          NULL,
3390                          NULL,
3391                          l_org_schedule_id,
3392                          p_effective_date,
3393                          p_mode,
3394 			 p_business_group_id,
3395                          p_set_of_books_id,
3396                          NULL,   ---    for autopop perf. patch
3397                          l_return_status);
3398 
3399                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3400                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3401                  END IF;
3402 
3403               ELSIF (l_patc_status IS NULL) OR
3404 ----  (l_linkage_status IS NULL) OR
3405 		    (l_award_status IS NULL) THEN
3406                 /* Bug 1874696
3407 		if l_award_id is not null
3408 		then
3409                     psp_general.poeta_effective_date(p_payroll_start_date,
3410                                      l_project_id,
3411                                      l_award_id,
3412 				     l_task_id,
3413                                      l_effective_date,
3414                                      l_return_status);
3415 		elsif l_award_id is null
3416 		then
3417                     psp_general.poeta_effective_date(p_payroll_start_date,
3418                                      l_project_id,
3419 				     l_task_id,
3420                                      l_effective_date,
3421                                      l_return_status);
3422 		end if;
3423                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3424                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3425                     END IF; */
3426                     l_gl_project_flag := 'P';
3427 
3428                     -- insert the record in psp_distribution_lines
3429               insert_into_distribution_lines(
3430  			P_SUB_LINE_ID,              -- payroll sub-lines id
3431  			P_PAYROLL_START_DATE,       -- distribution date
3432                         P_EFFECTIVE_DATE,           -- effective date     Bug 1874696
3433  			L_DIST_AMOUNT,              -- distribution amount
3434  			'N',                        -- status code
3435                         NULL,                       -- suspense reason code
3436                         NULL,                       -- default reason code
3437       			NULL,                       -- schedule line id
3438  			NULL,                       -- default organization a/c
3439  			NULL,                       -- suspense organization a/c
3440  			NULL,                       -- global element type
3441 			L_ORG_SCHEDULE_ID,          -- org default schedule id
3442                         L_GL_PROJECT_FLAG,          -- gl project flag
3443                         NULL,                       -- reversal entry flag
3444                         l_gl_code_combination_id,   -- gl_code_combination_id
3445                         l_project_id,               -- project_id,
3446                         l_task_id   ,               -- task_id,
3447                         l_award_id  ,               -- award_id,
3448                         l_expenditure_org_id,       -- expenditure org id
3449                         l_expenditure_type,         -- expenditure_type
3450                         l_effective_start_date,    -- Eff start date of schedule
3451                         l_effective_end_date,      -- Eff start date of schedule
3452                         p_mode,                    -- 'I' for LD ,'R' for others
3453 			p_business_group_id,       -- Business Group id
3454                         p_set_of_books_id,         -- Set of Books Id
3455 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
3456 			l_attribute1,
3457 			l_attribute2,
3458 			l_attribute3,
3459 			l_attribute4,
3460 			l_attribute5,
3461 			l_attribute6,
3462 			l_attribute7,
3463 			l_attribute8,
3464 			l_attribute9,
3465 			l_attribute10,
3466                         l_return_status);
3467 
3468                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3469                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3470                     END IF;
3471              END IF;
3472            END IF; -- g_auto_population = 'Y'
3473          END IF;
3474 
3475          END LOOP; -- loop through all the schedule lines having the payroll period date
3476 
3477          l_bal_dist_amount  := round((p_daily_rate - l_tot_dist_amount), g_precision);	-- Bug 2916848: Modified to currency precision (from 2)
3478 
3479          -- IF abs(l_bal_dist_amount) > 0 THEN  -- #1339616
3480          IF l_tot_percent < 100 THEN
3481 
3482            IF p_org_def_account = 'Y' then
3483              default_account(
3484                             x_proc_executed,
3485                             p_person_id,
3486                             p_sub_line_id,
3487                             p_assignment_id,
3488                             p_payroll_start_date,
3489                             l_bal_dist_amount,
3490                             '1',---'LDM_BAL_NOT_100_PERCENT',
3491                             p_effective_date,
3492                             p_mode,
3493 			    p_business_group_id,
3494                             p_set_of_books_id,
3495 				p_attribute_category,	-- Introduced DFF columns for bug fix 2908859
3496 				p_attribute1,
3497 				p_attribute2,
3498 				p_attribute3,
3499 				p_attribute4,
3500 				p_attribute5,
3501 				p_attribute6,
3502 				p_attribute7,
3503 				p_attribute8,
3504 				p_attribute9,
3505 				p_attribute10,
3506                             l_return_status);
3507               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3508                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3509               END IF;
3510 
3511               IF x_proc_executed = 'FALSE' then
3512                 suspense_account(
3513                                  x_proc_executed,
3514                                  p_person_id,
3515                                  p_sub_line_id,
3516                                  p_assignment_id,
3517                                  p_payroll_start_date,
3518                                  l_bal_dist_amount,
3519                                  'LDM_BAL_NOT_100_PERCENT',
3520                                  NULL,
3521                                  NULL,
3522                                  NULL,
3523                                  NULL,
3524                                  p_effective_date,
3525                                  p_mode,
3526 				 p_business_group_id,
3527                                  p_set_of_books_id,
3528                                  NULL,   ---    for autopop perf. patch
3529                                  l_return_status);
3530 
3531                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3532                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3533                  END IF;
3534 
3535                END IF;
3536            ELSE
3537                 suspense_account(
3538                                  x_proc_executed,
3539                                  p_person_id,
3540                                  p_sub_line_id,
3541                                  p_assignment_id,
3542                                  p_payroll_start_date,
3543                                  l_bal_dist_amount,
3544                                  'LDM_BAL_NOT_100_PERCENT',
3545                                  NULL,
3546                                  NULL,
3547                                  NULL,
3548                                  NULL,
3549                                  p_effective_date,
3550                                  p_mode,
3551 				 p_business_group_id,
3552                                  p_set_of_books_id,
3553                                  NULL,   ---    for autopop perf. patch
3554                                  l_return_status);
3555 
3556                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3557                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3558                  END IF;
3559 
3560            END IF;
3561          END IF;
3562    --
3563    p_return_status := fnd_api.g_ret_sts_success;
3564 
3565  EXCEPTION
3566    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3567       g_error_api_path := SUBSTR('ORG_LABOR_SCHEDULE_HIERARCHY:'||g_error_api_path,1,230);
3568       p_return_status := fnd_api.g_ret_sts_unexp_error;
3569 
3570    WHEN OTHERS THEN
3571       g_error_api_path := SUBSTR('ORG_LABOR_SCHEDULE_HIERARCHY:'||g_error_api_path,1,230);
3572       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','ORG_LABOR_SCHEDULE_HIERARCHY');
3573       p_return_status := fnd_api.g_ret_sts_unexp_error;
3574  END;
3575 
3576 ------------------------------ D E F A U L T   A / C --------------------------------------
3577  PROCEDURE default_account(
3578                            p_proc_executed      OUT NOCOPY  VARCHAR2,
3579                            p_person_id           IN  NUMBER,
3580                            p_sub_line_id         IN  NUMBER,
3581                            p_assignment_id       IN  NUMBER,
3582                            p_payroll_start_date  IN  DATE,
3583                            p_daily_rate          IN  NUMBER,
3584                            p_default_reason_code IN  VARCHAR2,
3585                            p_effective_date      IN  DATE,
3586                            p_mode                IN  VARCHAR2 := 'I',
3587 			   p_business_group_id   IN  NUMBER,
3588                            p_set_of_books_id     IN  NUMBER,
3589 				p_attribute_category	IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
3590 				p_attribute1		IN	VARCHAR2,
3591 				p_attribute2		IN	VARCHAR2,
3592 				p_attribute3		IN	VARCHAR2,
3593 				p_attribute4		IN	VARCHAR2,
3594 				p_attribute5		IN	VARCHAR2,
3595 				p_attribute6		IN	VARCHAR2,
3596 				p_attribute7		IN	VARCHAR2,
3597 				p_attribute8		IN	VARCHAR2,
3598 				p_attribute9		IN	VARCHAR2,
3599 				p_attribute10		IN	VARCHAR2,
3600                            p_return_status      OUT NOCOPY  VARCHAR2) IS
3601 
3602   CURSOR default_account_cur(P_PAYROLL_START_DATE	IN	DATE,
3603                              P_ASSIGNMENT_ID		IN	NUMBER) IS
3604       SELECT poa.organization_account_id,
3605              poa.gl_code_combination_id,
3606              poa.project_id,
3607              poa.task_id,
3608              poa.award_id,
3609              poa.expenditure_type,
3610              poa.expenditure_organization_id,
3611              poa.start_date_active,
3612              nvl(poa.end_date_active,p_payroll_start_date),    --- decode for 5014193
3613 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute_category, poa.attribute_category)) attribute_category,		-- Introduced DFF columns for bug fix 2908859
3614 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute1, poa.attribute1)) attribute1,
3615 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute2, poa.attribute2)) attribute2,
3616 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute3, poa.attribute3)) attribute3,
3617 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute4, poa.attribute4)) attribute4,
3618 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute5, poa.attribute5)) attribute5,
3619 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute6, poa.attribute6)) attribute6,
3620 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute7, poa.attribute7)) attribute7,
3621 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute8, poa.attribute8)) attribute8,
3622 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute9, poa.attribute9)) attribute9,
3623 		 decode(g_dff_grouping_option, 'Y',NVL(p_attribute10, poa.attribute10)) attribute10
3624       FROM   per_assignments_f paf,
3625              psp_organization_accounts poa
3626       WHERE  poa.business_group_id = p_business_group_id
3627       AND    poa.set_of_books_id   = p_set_of_books_id
3628       and    paf.assignment_type = 'E'
3629       AND    paf.assignment_id = p_assignment_id
3630       AND    p_payroll_start_date BETWEEN paf.effective_start_date AND paf.effective_end_date
3631       AND    poa.organization_id = paf.organization_id
3632       AND    poa.account_type_code ||' '= 'D' ||' '
3633       AND    p_payroll_start_date BETWEEN poa.start_date_active AND
3634                                           nvl(poa.end_date_active,p_payroll_start_date);
3635 
3636   x_proc_executed                  VARCHAR2(10) := 'TRUE';
3637   l_organization_account_id        NUMBER(15);
3638   l_gl_code_combination_id         NUMBER(15);
3639   l_project_id                     NUMBER(15);
3640   l_task_id                        NUMBER(15);
3641   l_award_id                       NUMBER(15);
3642   l_expenditure_type               VARCHAR2(30);
3643   l_expenditure_org_id             NUMBER(15);
3644   l_effective_start_date           DATE;
3645   l_effective_end_date             DATE;
3646 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variables for bug fix 2908859
3647 	l_attribute1		VARCHAR2(150);
3648 	l_attribute2		VARCHAR2(150);
3649 	l_attribute3		VARCHAR2(150);
3650 	l_attribute4		VARCHAR2(150);
3651 	l_attribute5		VARCHAR2(150);
3652 	l_attribute6		VARCHAR2(150);
3653 	l_attribute7		VARCHAR2(150);
3654 	l_attribute8		VARCHAR2(150);
3655 	l_attribute9		VARCHAR2(150);
3656 	l_attribute10		VARCHAR2(150);
3657   l_return_status                  VARCHAR2(1);
3658   -- l_effective_date                 DATE; Bug 1874696
3659   default_ac_not_found             EXCEPTION;
3660   l_gl_project_flag                VARCHAR2(1);
3661   l_linkage_status                 VARCHAR2(50) := NULL;
3662   l_patc_status                    VARCHAR2(50) := NULL;
3663   l_billable_flag                  VARCHAR2(1)  := NULL;
3664   l_msg_count                      NUMBER;
3665   l_msg_app                        VARCHAR2(2000);
3666   l_msg_type                       varchar2(2000);
3667   l_msg_token1                     varchar2(2000);
3668   l_msg_token2                     varchar2(2000);
3669   l_msg_token3                     varchar2(2000);
3670   --l_award_status  varchar2(50);  -- for bug fix 1931680
3671   l_award_status  varchar2(200);
3672 
3673   BEGIN
3674       p_proc_executed := 'TRUE';
3675       OPEN default_account_cur(p_payroll_start_date,p_assignment_id);
3676       FETCH default_account_cur INTO
3677              l_organization_account_id,
3678              l_gl_code_combination_id,
3679              l_project_id,
3680              l_task_id,
3681              l_award_id,
3682              l_expenditure_type,
3683              l_expenditure_org_id,
3684              l_effective_start_date,
3685              l_effective_end_date,
3686 		l_attribute_category,			-- Introduced DFf variable for bug fix 2908859
3687 		l_attribute1,
3688 		l_attribute2,
3689 		l_attribute3,
3690 		l_attribute4,
3691 		l_attribute5,
3692 		l_attribute6,
3693 		l_attribute7,
3694 		l_attribute8,
3695 		l_attribute9,
3696 		l_attribute10;
3697 
3698       IF default_account_cur%NOTFOUND THEN
3699         RAISE default_ac_not_found;
3700       END IF;
3701 
3702 
3703            IF l_gl_code_combination_id IS NOT NULL THEN
3704               --l_effective_date := p_effective_date; commented for bug 1874696
3705               l_gl_project_flag := 'G';
3706 
3707               -- insert the record in psp_distribution_lines
3708               insert_into_distribution_lines(
3709 		P_SUB_LINE_ID,                  -- payroll sub-lines id
3710  		P_PAYROLL_START_DATE,           -- distribution date
3711                 G_GL_EFFECTIVE_DATE,            -- effective date     Changed from p_effective_date Bug 2663344
3712  		ROUND(P_DAILY_RATE, g_precision),-- distribution amount Introduced rounding for bug 3109943
3713  		'N',                            -- status code
3714                 NULL,                           -- suspense reason code
3715                 P_DEFAULT_REASON_CODE,          -- default reason code
3716           	NULL,                           -- schedule line id
3717  		L_ORGANIZATION_ACCOUNT_ID,      -- default organization a/c
3718  		NULL,                           -- suspense organization a/c
3719  		NULL                ,           -- global element type
3720 		NULL,                           -- org default schedule id
3721                 L_GL_PROJECT_FLAG,              -- gl project flag
3722                 NULL,                           -- reversal entry flag
3723                 l_gl_code_combination_id,       -- gl_code_combination_id
3724                 l_project_id,                   -- project_id,
3725                 l_task_id   ,                   -- task_id,
3726                 l_award_id  ,                   -- award_id,
3727                 l_expenditure_org_id,           -- expenditure org id
3728                 l_expenditure_type,             -- expenditure_type
3729                 l_effective_start_date,         -- Eff start date of schedule
3730                 l_effective_end_date,           -- Eff start date of schedule
3731                 p_mode,                         -- 'I' for LD ,'R' for others
3732 		p_business_group_id,            -- Business Group Id
3733                 p_set_of_books_id,              -- Set of Books Id
3734 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
3735 		l_attribute1,
3736 		l_attribute2,
3737 		l_attribute3,
3738 		l_attribute4,
3739 		l_attribute5,
3740 		l_attribute6,
3741 		l_attribute7,
3742 		l_attribute8,
3743 		l_attribute9,
3744 		l_attribute10,
3745                 l_return_status);
3746 
3747               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3748                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3749               END IF;
3750 
3751            ELSIF l_gl_code_combination_id IS NULL THEN
3752             IF g_default_account_autopop = 'Y' THEN   -- introduced for 5080403
3753                    l_gl_project_flag:='P';
3754 
3755                     insert_into_distribution_lines(
3756  			P_SUB_LINE_ID,             -- payroll sub-line_id
3757  			P_PAYROLL_START_DATE,      -- distribution date
3758                         P_EFFECTIVE_DATE,          -- effective date     Bug 1874696 Changed from l_Effective_date
3759  			ROUND(P_DAILY_RATE, g_precision),-- distribution amount Introduced rounding for bug 3109943
3760  			'N',                       -- status code
3761                         NULL,                      -- suspense reason code
3762                         p_default_Reason_code,     -- default reason code
3763       			NULL,        -- schedule line id
3764  			l_organization_account_id, -- default organization a/c
3765  			NULL,                      -- suspense organization a/c
3766 			NULL,                      -- global element type
3767 			NULL,                      -- org default schedule id
3768                         L_GL_PROJECT_FLAG,         -- gl project flag
3769                         NULL,                      -- reversal entry flag
3770                         l_gl_code_combination_id,  -- gl_code_combination_id
3771                         l_project_id,              -- project_id,
3772                         l_task_id   ,              -- task_id,
3773                         l_award_id  ,              -- award_id,
3774                         l_expenditure_org_id,      -- expenditure org id
3775                         l_expenditure_type,        -- expenditure_type
3776                         l_effective_start_date,    -- Eff start date of schedule
3777                         l_effective_end_date,      -- Eff start date of schedule
3778                         p_mode,                    -- 'I' for LD ,'R' for others
3779 			p_business_group_id,       -- Business Group Id
3780                         p_set_of_books_id,         -- Set of Books Id
3781 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
3782 			l_attribute1,
3783 			l_attribute2,
3784 			l_attribute3,
3785 			l_attribute4,
3786 			l_attribute5,
3787 			l_attribute6,
3788 			l_attribute7,
3789 			l_attribute8,
3790 			l_attribute9,
3791 			l_attribute10,
3792                         l_return_status);
3793 
3794                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3795                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3796                     END IF;
3797             ELSE
3798 
3799 
3800 	   -- modified as per 11i changes
3801 	   -- dbms_output.put_line('Project id 6 '|| to_char(l_project_id));
3802 	   -- dbms_output.put_line('task id 6 '|| to_char(l_task_id));
3803 	   -- dbms_output.put_line('Type 6 '|| l_expenditure_type);
3804 	   -- dbms_output.put_line('Dt 6 '|| to_char(p_payroll_start_date));
3805 	   -- dbms_output.put_line('person_id 6 '|| to_char(p_person_id));
3806 	    pa_transactions_pub.validate_transaction(
3807 			x_project_id		=> l_project_id,
3808 			x_task_id		=> l_task_id,
3809 			x_ei_date		=> p_effective_date, ----p_payroll_start_date, Bug 1874696
3810 			x_expenditure_type	=> l_expenditure_type,
3811 			x_non_labor_resource	=> null,
3812 			x_person_id		=> p_person_id,
3813 			x_incurred_by_org_id	=> l_expenditure_org_id,
3814 			x_calling_module	=> 'PSPLDCDB',
3815 			x_msg_application	=> l_msg_app,
3816 			x_msg_type		=> l_msg_type,
3817 			x_msg_token1		=> l_msg_token1,
3818 			x_msg_token2		=> l_msg_token2,
3819 			x_msg_token3		=> l_msg_token3,
3820 			x_msg_count		=> l_msg_count,
3821 			x_msg_data		=> l_patc_status,
3822 			x_billable_flag		=> l_billable_flag,
3823 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
3824 
3825 
3826 	   -- dbms_output.put_line('patc stat 6 '|| l_patc_status);
3827 	    -- GMS is enabled and patc went through
3828 	     if l_award_id is not null and l_patc_status is null
3829              then
3830                  gms_transactions_pub.validate_transaction
3831                                 (l_project_id,
3832                                 l_task_id,
3833 				l_award_id,
3834                                 l_expenditure_type,
3835                                 p_effective_date, ----p_payroll_start_date, Bug 1874696
3836                                 'PSPLDCDB',
3837                                 l_award_status);
3838 
3839 /*********************************************************************
3840                  if l_award_status is null
3841                  then
3842                         project_award_linkage(l_project_id,
3843                                   l_award_id,
3844                                   l_linkage_status,
3845                                   l_return_status);
3846 		 else
3847 
3848 *************************************************************************/
3849 
3850                 if l_award_status IS NOT NULL then
3851 		--	l_patc_status := l_award_status;  for bug fix 1931680
3852                         l_patc_status  := substr(l_award_status,1,50);
3853                  end if;
3854              end if;
3855 
3856              IF (l_patc_status IS NOT NULL) OR
3857 ----  (l_linkage_status IS NOT NULL) OR
3858 		(l_award_status is not null) THEN
3859                 suspense_account(
3860                          x_proc_executed,
3861                          p_person_id,
3862                          p_sub_line_id,
3863                          p_assignment_id,
3864                          p_payroll_start_date,
3865                          p_daily_rate,
3866                          l_patc_status,
3867                          NULL,
3868                          l_organization_account_id,
3869                          NULL,
3870                          NULL,
3871                          p_effective_date,
3872                          p_mode,
3873 			 p_business_group_id,
3874                          p_set_of_books_id,
3875                         NULL,   ---    for autopop perf. patch
3876                          l_return_status);
3877 
3878                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3879                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3880                  END IF;
3881 
3882               ELSIF (l_patc_status IS NULL)
3883 ---OR (l_linkage_status IS NULL) OR
3884                 OR
3885 			(l_award_status is null) THEN
3886                 /* Bug 1874696
3887 		if l_award_id is not null
3888 		then
3889                     psp_general.poeta_effective_date(p_payroll_start_date,
3890                                      l_project_id,
3891                                      l_award_id,
3892 				     l_task_id,
3893                                      l_effective_date,
3894                                      l_return_status);
3895 		elsif l_award_id is null
3896 		then
3897                     psp_general.poeta_effective_date(p_payroll_start_date,
3898                                      l_project_id,
3899 				     l_task_id,
3900                                      l_effective_date,
3901                                      l_return_status);
3902 		end if;
3903 
3904                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3905                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3906                     END IF; */
3907                     l_gl_project_flag := 'P';
3908 
3909                     -- insert the record in psp_distribution_lines
3910                     insert_into_distribution_lines(
3911 			P_SUB_LINE_ID,             -- payroll sub-lines id
3912  			P_PAYROLL_START_DATE,      -- distribution date
3913                         P_EFFECTIVE_DATE,          -- effective date     Bug 1874696 changed from l_Effective_date
3914  			ROUND(P_DAILY_RATE, g_precision),-- distribution amount Introduced rounding for bug 3109943
3915  			'N',                       -- status code
3916                         NULL,                      -- suspense reason code
3917                         P_DEFAULT_REASON_CODE,     -- default reason code
3918       			NULL,                      -- schedule line id
3919  			L_ORGANIZATION_ACCOUNT_ID, -- default organization a/c
3920  			NULL,                      -- suspense organization a/c
3921  			NULL,                      -- global element type
3922 			NULL,                      -- org default schedule id
3923                         L_GL_PROJECT_FLAG,         -- gl project flag
3924                         NULL,                      -- reversal entry flag
3925                         l_gl_code_combination_id,  -- gl_code_combination_id
3926                         l_project_id,              -- project_id,
3927                         l_task_id   ,              -- task_id,
3928                         l_award_id  ,              -- award_id,
3929                         l_expenditure_org_id,      -- expenditure org id
3930                         l_expenditure_type,        -- expenditure_type
3931                         l_effective_start_date,    -- Eff start date of schedule
3932                         l_effective_end_date,      -- Eff start date of schedule
3933                         p_mode,                    -- 'I' for LD ,'R' for others
3934 			p_business_group_id,       -- Business Group Id
3935                         p_set_of_books_id,         -- Set of Books Id
3936 			l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
3937 			l_attribute1,
3938 			l_attribute2,
3939 			l_attribute3,
3940 			l_attribute4,
3941 			l_attribute5,
3942 			l_attribute6,
3943 			l_attribute7,
3944 			l_attribute8,
3945 			l_attribute9,
3946 			l_attribute10,
3947                         l_return_status);
3948 
3949                      IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3950                        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3951                      END IF;
3952                 END IF;
3953              END IF;
3954            END IF;
3955    --
3956    p_return_status := fnd_api.g_ret_sts_success;
3957 
3958   EXCEPTION
3959    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3960       g_error_api_path := SUBSTR('DEFAULT_ACCOUNT:'||g_error_api_path,1,230);
3961       p_return_status := fnd_api.g_ret_sts_unexp_error;
3962 
3963     WHEN DEFAULT_AC_NOT_FOUND THEN
3964       g_error_api_path := SUBSTR('DEFAULT_ACCOUNT:'||g_error_api_path,1,230);
3965       fnd_message.set_name('PSP','PSP_LD_DEFAULT_AC_NOT_SET_UP');
3966       fnd_msg_pub.add;
3967       g_msg := SUBSTR(fnd_message.get,1,230);
3968       --- Next line added by Abhijit as a patch on 7/24/98.
3969       p_proc_executed := 'FALSE';
3970       p_return_status := fnd_api.g_ret_sts_success;
3971 
3972     WHEN OTHERS THEN
3973       g_error_api_path := SUBSTR('DEFAULT_ACCOUNT:'||g_error_api_path,1,230);
3974       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','DEFAULT_ACCOUNT');
3975       p_return_status := fnd_api.g_ret_sts_unexp_error;
3976 
3977   END;
3978 
3979 ------------------------- S U S P E N S E  A / C --------------------------------------
3980  PROCEDURE suspense_account (
3981                              p_proc_executed          OUT NOCOPY  VARCHAR2,
3982                              p_person_id               IN NUMBER,
3983                              p_sub_line_id             IN  NUMBER,
3984                              p_assignment_id           IN  NUMBER,
3985                              p_payroll_start_date      IN  DATE,
3986                              p_daily_rate              IN  NUMBER,
3987                              p_suspense_reason_code    IN  VARCHAR2,
3988                              p_schedule_line_id        IN  NUMBER,
3989                              p_default_org_account_id  IN  NUMBER,
3990                              p_element_account_id      IN  NUMBER,
3991                              p_org_schedule_id         IN  NUMBER,
3992                              p_effective_date          IN  DATE,
3993                              p_mode                    IN  VARCHAR2 := 'I',
3994 			     p_business_group_id       IN  NUMBER,
3995                              p_set_of_books_id         IN  NUMBER,
3996                              p_dist_line_id            IN NUMBER,
3997                              p_return_status          OUT NOCOPY  VARCHAR2) IS
3998 
3999   CURSOR org_name_cur(P_PAYROLL_START_DATE	IN	DATE,
4000                       P_ASSIGNMENT_ID		IN	NUMBER) IS
4001     SELECT hou.organization_id,
4002            hou.name
4003     FROM   hr_organization_units hou,
4004            per_assignments_f paf
4005     WHERE  paf.business_group_id = p_business_group_id
4006     AND    paf.assignment_id = p_assignment_id
4007     and    paf.assignment_type = 'E'
4008     AND    paf.business_group_id = hou.business_group_id
4009     AND    p_payroll_start_date BETWEEN paf.effective_start_date AND paf.effective_end_date
4010     AND    hou.organization_id = paf.organization_id
4011     AND    p_payroll_start_date between date_from and nvl(date_to,p_payroll_start_date);
4012 
4013 
4014    CURSOR suspense_account_cur(L_ORGANIZATION_ID	IN	NUMBER,
4015                                P_PAYROLL_START_DATE	IN	DATE,
4016                                L_ACCOUNT_TYPE_CODE	IN	VARCHAR2) IS
4017    SELECT poa.organization_account_id,
4018           poa.gl_code_combination_id,
4019           poa.project_id,
4020           poa.task_id,
4021           poa.award_id,
4022           poa.expenditure_type,
4023           poa.expenditure_organization_id,
4024           poa.start_date_active,
4025           nvl(poa.end_date_active,p_payroll_start_date),    ---- introduced decode below for 5014193
4026           decode(g_dff_grouping_option, 'Y',	poa.attribute_category),-- Introduced DFF columns for bug fix 2908859
4027 	 decode(g_dff_grouping_option, 'Y',poa.attribute1),
4028 	 decode(g_dff_grouping_option, 'Y',poa.attribute2),
4029 	 decode(g_dff_grouping_option, 'Y',poa.attribute3),
4030 	 decode(g_dff_grouping_option, 'Y',poa.attribute4),
4031 	 decode(g_dff_grouping_option, 'Y',poa.attribute5),
4032 	 decode(g_dff_grouping_option, 'Y',poa.attribute6),
4033 	 decode(g_dff_grouping_option, 'Y',poa.attribute7),
4034 	 decode(g_dff_grouping_option, 'Y',poa.attribute8),
4035 	 decode(g_dff_grouping_option, 'Y',poa.attribute9),
4036 	 decode(g_dff_grouping_option, 'Y',poa.attribute10)
4037    FROM   psp_organization_accounts poa
4038    WHERE  business_group_id = p_business_group_id
4039    AND    set_of_books_id = p_set_of_books_id
4040    AND    poa.organization_id = l_organization_id
4041    AND    poa.account_type_code = l_account_type_code
4042    AND    p_payroll_start_date BETWEEN poa.start_date_active AND
4043                                        nvl(poa.end_date_active,p_payroll_start_date);
4044 
4045  /* Following cursor is added for bug 2514611 */
4046    CURSOR employee_name_cur IS
4047    SELECT full_name
4048    FROM   per_people_f
4049    WHERE  person_id =p_person_id;
4050 
4051 /*
4052    CURSOR global_susp_account_cur(P_PAYROLL_START_DATE IN	DATE) IS
4053    SELECT poa.organization_account_id,
4054           poa.gl_code_combination_id,
4055           poa.project_id,
4056           poa.task_id,
4057           poa.award_id,
4058           poa.expenditure_type,
4059           poa.expenditure_organization_id
4060    FROM   psp_organization_accounts poa
4061    WHERE  poa.account_type_code = 'G'
4062    AND    p_payroll_start_date BETWEEN poa.start_date_active AND
4063                                        nvl(poa.end_date_active,p_payroll_start_date);
4064 */
4065 
4066 
4067   l_organization_id                NUMBER(15);
4068   l_organization_name              hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
4069   l_gl_code_combination_id         NUMBER(15);
4070   l_project_id                     NUMBER(15);
4071   l_task_id                        NUMBER(15);
4072   l_award_id                       NUMBER(15);
4073   l_expenditure_type               VARCHAR2(30);
4074   l_expenditure_org_id             NUMBER(15);
4075   l_effective_start_date           DATE;
4076   l_effective_end_date             DATE;
4077 	l_attribute_category	VARCHAR2(30);			-- Introduced DFF variable for bug fix 2908859
4078 	l_attribute1		VARCHAR2(150);
4079 	l_attribute2		VARCHAR2(150);
4080 	l_attribute3		VARCHAR2(150);
4081 	l_attribute4		VARCHAR2(150);
4082 	l_attribute5		VARCHAR2(150);
4083 	l_attribute6		VARCHAR2(150);
4084 	l_attribute7		VARCHAR2(150);
4085 	l_attribute8		VARCHAR2(150);
4086 	l_attribute9		VARCHAR2(150);
4087 	l_attribute10		VARCHAR2(150);
4088   l_return_status                  VARCHAR2(1);
4089   ---l_effective_date                 DATE; Bug 1874696
4090   profile_val_date_matches         EXCEPTION;
4091   no_profile_exists                EXCEPTION;
4092   no_val_date_matches              EXCEPTION;
4093   no_global_acct_exists            EXCEPTION;
4094   suspense_ac_invalid              EXCEPTION;
4095   NO_REC_IN_GMS_AWARDS_V           EXCEPTION;
4096   PROJECT_AWARD_NOT_LNKD           EXCEPTION;
4097   l_gl_project_flag                VARCHAR2(1);
4098   l_organization_account_id        NUMBER(9);
4099   l_return_value                   VARCHAR2(30);
4100   l_linkage_status                 VARCHAR2(50) := NULL;
4101   l_patc_status                    VARCHAR2(50) := NULL;
4102   l_billable_flag                  VARCHAR2(1)  := NULL;
4103   l_msg_count                      NUMBER;
4104   l_msg_app                        VARCHAR2(2000);
4105   l_msg_type                       varchar2(2000);
4106   l_msg_token1                     varchar2(2000);
4107   l_msg_token2                     varchar2(2000);
4108   l_msg_token3                     varchar2(2000);
4109   --l_award_status  varchar2(50);  -- for bug fix 1931680
4110   l_employee_name  VARCHAR2(240); --Added for bug 2514611
4111   l_award_status  varchar2(200);
4112 
4113  BEGIN
4114     -- dbms_output.put_line('Entereing suspense');
4115      hr_utility.trace('CDL process --> suspense account proc entered');
4116      p_proc_executed := 'TRUE';
4117      OPEN org_name_cur(p_payroll_start_date,p_assignment_id);
4118         FETCH org_name_cur INTO l_organization_id,l_organization_name;
4119      CLOSE org_name_cur;
4120      --
4121      OPEN suspense_account_cur(l_organization_id,p_payroll_start_date,'S');
4122      FETCH suspense_account_cur INTO
4123            l_organization_account_id,
4124            l_gl_code_combination_id,
4125            l_project_id,
4126            l_task_id,
4127            l_award_id,
4128            l_expenditure_type,
4129            l_expenditure_org_id,
4130            l_effective_start_date,
4131            l_effective_end_date,
4132 	l_attribute_category,			-- Introduced DFF variables for bug fix 2908859
4133 	l_attribute1,
4134 	l_attribute2,
4135 	l_attribute3,
4136 	l_attribute4,
4137 	l_attribute5,
4138 	l_attribute6,
4139 	l_attribute7,
4140 	l_attribute8,
4141 	l_attribute9,
4142 	l_attribute10;
4143 
4144      IF suspense_account_cur%NOTFOUND THEN
4145        CLOSE suspense_account_cur;
4146        ---
4147        l_return_value := psp_general.find_global_suspense(p_payroll_start_date,
4148 							  p_business_group_id,
4149                                                           p_set_of_books_id,
4150                                                           l_organization_account_id );
4151        /* --------------------------------------------------------------------
4152        Valid return values are
4153        PROFILE_VAL_DATE_MATCHES       Profile and Value and Date matching 'G'
4154        NO_PROFILE_EXISTS              No Profile
4155        NO_VAL_DATE_MATCHES            Profile and Either Value/date do not
4156                                       match with 'G'
4157        NO_GLOBAL_ACCT_EXISTS          No 'G' exists
4158        ---------------------------------------------------------------------- */
4159        IF l_return_value = 'PROFILE_VAL_DATE_MATCHES' THEN
4160           BEGIN
4161              SELECT gl_code_combination_id,
4162                     project_id,
4163                     task_id,
4164                     award_id,
4165                     expenditure_type,
4166                     expenditure_organization_id,
4167                     start_date_active,
4168                     end_date_active,
4169 			attribute_category,			-- Introduced DFF columns for bug fix 2908859
4170 			attribute1,
4171 			attribute2,
4172 			attribute3,
4173 			attribute4,
4174 			attribute5,
4175 			attribute6,
4176 			attribute7,
4177 			attribute8,
4178 			attribute9,
4179 			attribute10
4180              INTO   l_gl_code_combination_id,
4181                     l_project_id,
4182                     l_task_id,
4183                     l_award_id,
4184                     l_expenditure_type,
4185                     l_expenditure_org_id,
4186                     l_effective_start_date,
4187                     l_effective_end_date,
4188 			l_attribute_category,			-- Introduced DFF variables for bug fix 2908859
4189 			l_attribute1,
4190 			l_attribute2,
4191 			l_attribute3,
4192 			l_attribute4,
4193 			l_attribute5,
4194 			l_attribute6,
4195 			l_attribute7,
4196 			l_attribute8,
4197 			l_attribute9,
4198 			l_attribute10
4199              FROM   psp_organization_accounts
4200              WHERE  organization_account_id = l_organization_account_id;
4201 
4202           EXCEPTION
4203              WHEN OTHERS THEN
4204                 RAISE no_global_acct_exists;
4205           END;
4206        ELSIF l_return_value = 'NO_GLOBAL_ACCT_EXISTS' THEN
4207          RAISE no_global_acct_exists;
4208        ELSIF l_return_value = 'NO_VAL_DATE_MATCHES' THEN
4209          RAISE no_val_date_matches;
4210        ELSIF l_return_value = 'NO_PROFILE_EXISTS' THEN
4211          RAISE no_profile_exists;
4212        END IF;
4213      END IF;
4214 /*
4215        OPEN global_susp_account_cur(p_payroll_start_date);
4216        FETCH global_susp_account_cur INTO
4217              l_organization_account_id,
4218              l_gl_code_combination_id,
4219              l_project_id,
4220              l_task_id,
4221              l_award_id,
4222              l_expenditure_type,
4223              l_expenditure_org_id;
4224        IF global_susp_account_cur%NOTFOUND THEN
4225          CLOSE global_susp_account_cur;
4226          RAISE suspense_ac_not_found;
4227        END IF;
4228    -- dbms_output.put_line('Project id ='||to_char(l_project_id));
4229    -- dbms_output.put_line('Task id ='||to_char(l_task_id));
4230    -- dbms_output.put_line('Payroll date ='||to_char(p_payroll_start_date));
4231    -- dbms_output.put_line('Exp. type ='||l_expenditure_type);
4232    -- dbms_output.put_line('Award id ='||to_char(l_award_id));
4233 */
4234      hr_utility.trace('CDL process --> suspense account --> suspense l_gl_project_flag ='||l_gl_project_flag);
4235     IF l_gl_code_combination_id IS NOT NULL THEN
4236        ---l_effective_date := p_effective_date; Bug 1874696
4237        l_gl_project_flag := 'G';
4238 
4239  -- if (g_auto_population= 'Y' and p_mode='I') then  --- for autopop perf bug fixing
4240 
4241   if p_dist_line_id is not null then
4242        -- commented first check and introduced above for bug fix 2463092
4243      hr_utility.trace('CDL process --> suspense account --> dist line not null ='||p_dist_line_id);
4244 
4245       update psp_distribution_lines set
4246           suspense_org_account_id = l_organization_account_id,
4247           suspense_reason_code= p_suspense_reason_code,
4248           gl_project_flag = l_gl_project_flag,
4249           effective_date = g_gl_effective_date, --- added for 2663344
4250 	attribute_category	=	l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4251 	attribute1		=	l_attribute1,
4252 	attribute2		=	l_attribute2,
4253 	attribute3		=	l_attribute3,
4254 	attribute4		=	l_attribute4,
4255 	attribute5		=	l_attribute5,
4256 	attribute6		=	l_attribute6,
4257 	attribute7		=	l_attribute7,
4258 	attribute8		=	l_attribute8,
4259 	attribute9		=	l_attribute9,
4260 	attribute10		=	l_attribute10
4261       where distribution_line_id = p_dist_line_id;
4262 
4263   else
4264 
4265        -- insert rows into psp_distribution_lines
4266        insert_into_distribution_lines(
4267  		P_SUB_LINE_ID,                  -- payroll sub-lines id
4268  		P_PAYROLL_START_DATE,           -- distribution date
4269                 G_GL_EFFECTIVE_DATE,            -- effective_date  changed from p_Effective_date Bug 2663344
4270  		ROUND(P_DAILY_RATE, g_precision),-- distribution amount. Introduced rounding for bug 3109943
4271  		'N',                            -- status code
4272                 P_SUSPENSE_REASON_CODE,         -- suspense reason code
4273                 NULL,                           -- default reason code
4274       	        P_SCHEDULE_LINE_ID,             -- schedule line id
4275  		P_DEFAULT_ORG_ACCOUNT_ID,       -- default organization a/c
4276  		L_ORGANIZATION_ACCOUNT_ID,      -- suspense organization a/c
4277  		P_ELEMENT_ACCOUNT_ID,           -- global element type
4278 		P_ORG_SCHEDULE_ID,              -- org default schedule id
4279                 L_GL_PROJECT_FLAG,              -- gl project flag
4280                 NULL,                           -- reversal entry flag
4281                 l_gl_code_combination_id,       -- gl_code_combination_id
4282                 l_project_id,                   -- project_id,
4283                 l_task_id   ,                   -- task_id,
4284                 l_award_id  ,                   -- award_id,
4285                 l_expenditure_org_id,           -- expenditure org id
4286                 l_expenditure_type,             -- expenditure_type
4287                 l_effective_start_date,         -- Eff start date of schedule
4288                 l_effective_end_date,           -- Eff start date of schedule
4289                 p_mode,                         -- 'I' for LD ,'R' for others
4290 		p_business_group_id,            -- Business Group Id
4291                 p_set_of_books_id,              -- Set of Books Id
4292 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4293 		l_attribute1,
4294 		l_attribute2,
4295 		l_attribute3,
4296 		l_attribute4,
4297 		l_attribute5,
4298 		l_attribute6,
4299 		l_attribute7,
4300 		l_attribute8,
4301 		l_attribute9,
4302 		l_attribute10,
4303                 l_return_status);
4304 
4305 
4306 
4307        IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4308           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4309        END IF;
4310   end if;
4311 
4312      ELSIF l_gl_code_combination_id IS NULL THEN
4313         IF g_suspense_account_autopop = 'Y'  then--- 5080403
4314                    l_gl_project_flag:='P';
4315         if p_dist_line_id is null then
4316 
4317        insert_into_distribution_lines(
4318  		P_SUB_LINE_ID,                  -- payroll sub-lines id
4319  		P_PAYROLL_START_DATE,           -- distribution date
4320                 P_EFFECTIVE_DATE,            -- effective_date  changed from p_Effective_date Bug 2663344
4321  		ROUND(P_DAILY_RATE, g_precision),-- distribution amount. Introduced rounding for bug 3109943
4322  		'N',                            -- status code
4323                 P_SUSPENSE_REASON_CODE,         -- suspense reason code
4324                 NULL,                           -- default reason code
4325       	        P_SCHEDULE_LINE_ID,             -- schedule line id
4326  		P_DEFAULT_ORG_ACCOUNT_ID,       -- default organization a/c
4327  		L_ORGANIZATION_ACCOUNT_ID,      -- suspense organization a/c
4328  		P_ELEMENT_ACCOUNT_ID,           -- global element type
4329 		P_ORG_SCHEDULE_ID,              -- org default schedule id
4330                 L_GL_PROJECT_FLAG,              -- gl project flag
4331                 NULL,                           -- reversal entry flag
4332                 l_gl_code_combination_id,       -- gl_code_combination_id
4333                 l_project_id,                   -- project_id,
4334                 l_task_id   ,                   -- task_id,
4335                 l_award_id  ,                   -- award_id,
4336                 l_expenditure_org_id,           -- expenditure org id
4337                 l_expenditure_type,             -- expenditure_type
4338                 l_effective_start_date,         -- Eff start date of schedule
4339                 l_effective_end_date,           -- Eff start date of schedule
4340                 p_mode,                         -- 'I' for LD ,'R' for others
4341 		p_business_group_id,            -- Business Group Id
4342                 p_set_of_books_id,              -- Set of Books Id
4343 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4344 		l_attribute1,
4345 		l_attribute2,
4346 		l_attribute3,
4347 		l_attribute4,
4348 		l_attribute5,
4349 		l_attribute6,
4350 		l_attribute7,
4351 		l_attribute8,
4352 		l_attribute9,
4353 		l_attribute10,
4354                 l_return_status);
4355 
4356                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4357                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4358                     END IF;
4359              else
4360                  update psp_distribution_lines set
4361                         suspense_reason_code= p_suspense_reason_code,
4362                         suspense_org_Account_id= l_organization_account_id,
4363                         gl_project_flag = l_gl_project_flag,
4364                         effective_date = p_effective_date,
4365 		          attribute_category	=	l_attribute_category,
4366 		          attribute1		=	l_attribute1,
4367 		          attribute2		=	l_attribute2,
4368 		          attribute3		=	l_attribute3,
4369 		          attribute4		=	l_attribute4,
4370 		          attribute5		=	l_attribute5,
4371 		          attribute6		=	l_attribute6,
4372 		          attribute7		=	l_attribute7,
4373 		          attribute8		=	l_attribute8,
4374 		          attribute9		=	l_attribute9,
4375 		          attribute10		=	l_attribute10
4376                     where distribution_line_id=p_dist_line_id;
4377              end if;
4378 
4379             ELSE
4380 
4381 	    pa_transactions_pub.validate_transaction(
4382 			x_project_id		=> l_project_id,
4383 			x_task_id		=> l_task_id,
4384 			x_ei_date		=> p_effective_date, ---p_payroll_start_date, Bug 1874696
4385 			x_expenditure_type	=> l_expenditure_type,
4386 			x_non_labor_resource	=> null,
4387 			x_person_id		=> p_person_id,
4388 			x_incurred_by_org_id	=> l_expenditure_org_id,
4389 			x_calling_module	=> 'PSPLDCDB',
4390 			x_msg_application	=> l_msg_app,
4391 			x_msg_type		=> l_msg_type,
4392 			x_msg_token1		=> l_msg_token1,
4393 			x_msg_token2		=> l_msg_token2,
4394 			x_msg_token3		=> l_msg_token3,
4395 			x_msg_count		=> l_msg_count,
4396 			x_msg_data		=> l_patc_status,
4397 			x_billable_flag		=> l_billable_flag,
4398 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
4399 
4400 
4401 	   -- dbms_output.put_line('patc stat 7 '|| l_patc_status);
4402 	     -- GMS is enabled and patc went fine
4403 	     if l_award_id is not null  and l_patc_status is null
4404              then
4405                  gms_transactions_pub.validate_transaction
4406                                 (l_project_id,
4407                                 l_task_id,
4408 				l_award_id,
4409                                 l_expenditure_type,
4410                                 p_effective_date, ----p_payroll_start_date, Bug 1874696
4411                                 'PSPLDCDB',
4412                                 l_award_status);
4413 
4414 /************************************************************************************
4415                  if l_award_status is null
4416                  then
4417                         project_award_linkage(l_project_id,
4418                                   l_award_id,
4419                                   l_linkage_status,
4420                                   l_return_status);
4421 		 else
4422 
4423 ***************************************************************************************/
4424 
4425                  if l_award_status IS NOT NULL THEN
4426 		--	l_patc_status := l_award_status;  for bug fix 1931680
4427                         l_patc_status  := substr(l_award_status,1,50);
4428                  end if;
4429              end if;
4430 
4431 /**********************************************************************
4432 
4433        IF l_linkage_status = 'PSP_GMS_AWARDS_V_NO_RECS'  THEN
4434           RAISE NO_REC_IN_GMS_AWARDS_V;
4435        ELSIF l_linkage_status = 'PSP_PROJ_AWRD_NOT_LNKD' THEN
4436           RAISE PROJECT_AWARD_NOT_LNKD;
4437        ELSIF l_patc_status IS NOT NULL THEN
4438 
4439 ***************************************************************/
4440 
4441        IF l_patc_status IS NOT NULL THEN
4442           RAISE SUSPENSE_AC_INVALID;
4443        END IF;
4444        ---
4445        IF (l_patc_status IS NULL) OR
4446 ---  OR (l_linkage_status IS NULL) OR
4447 		(l_award_status IS NULL) THEN
4448         /* Bug 1874696
4449 	if l_award_id is not null
4450 	then
4451             psp_general.poeta_effective_date(p_payroll_start_date,
4452                                l_project_id,
4453                                l_award_id,
4454 			       l_task_id,
4455                                l_effective_date,
4456                                l_return_status);
4457 	elsif l_award_id is null
4458 	then
4459             psp_general.poeta_effective_date(p_payroll_start_date,
4460                                l_project_id,
4461 			       l_task_id,
4462                                l_effective_date,
4463                                l_return_status);
4464 	end if; */
4465              l_gl_project_flag := 'P';
4466              IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4467                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4468              END IF;
4469 
4470   -- if (g_auto_population='Y' and p_mode='I')then
4471 
4472          -- commented above and introduced if condition below for bug fix 2463092
4473 
4474    if p_dist_line_id is not null  then
4475       update psp_distribution_lines set
4476               suspense_reason_code= p_suspense_reason_code,
4477               suspense_org_Account_id= l_organization_account_id,
4478               gl_project_flag = l_gl_project_flag,
4479               effective_date = p_effective_date, --- added for 2663344
4480 		attribute_category	=	l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4481 		attribute1		=	l_attribute1,
4482 		attribute2		=	l_attribute2,
4483 		attribute3		=	l_attribute3,
4484 		attribute4		=	l_attribute4,
4485 		attribute5		=	l_attribute5,
4486 		attribute6		=	l_attribute6,
4487 		attribute7		=	l_attribute7,
4488 		attribute8		=	l_attribute8,
4489 		attribute9		=	l_attribute9,
4490 		attribute10		=	l_attribute10
4491       where distribution_line_id=p_dist_line_id;
4492 
4493 
4494 
4495    else
4496               -- insert rows into psp_distribution_lines
4497               insert_into_distribution_lines(
4498  		P_SUB_LINE_ID,                  -- payroll sub-lines id
4499  		P_PAYROLL_START_DATE,           -- distribution date
4500                 P_EFFECTIVE_DATE,               -- effective_date     Bug 1874696
4501   		ROUND(P_DAILY_RATE, g_precision),-- distribution amount. Introduced rounding for bug 3109943
4502  		'N',                            -- status code
4503                 P_SUSPENSE_REASON_CODE,         -- suspense reason code
4504                 NULL,                           -- default reason code
4505       	        P_SCHEDULE_LINE_ID,             -- schedule line id
4506  	        P_DEFAULT_ORG_ACCOUNT_ID,       -- default organization a/c
4507  		L_ORGANIZATION_ACCOUNT_ID,      -- suspense organization a/c
4508  		P_ELEMENT_ACCOUNT_ID,           -- global element type
4509 		P_ORG_SCHEDULE_ID,              -- org default schedule id
4510                 L_GL_PROJECT_FLAG,              -- gl project flag
4511                 NULL,                           -- reversal entry flag
4512                 l_gl_code_combination_id,       -- gl_code_combination_id
4513                 l_project_id,                   -- project_id,
4514                 l_task_id   ,                   -- task_id,
4515                 l_award_id  ,                   -- award_id,
4516                 l_expenditure_org_id,           -- expenditure org id
4517                 l_expenditure_type,             -- expenditure_type
4518                 l_effective_start_date,         -- Eff start date of schedule
4519                 l_effective_end_date,           -- Eff start date of schedule
4520                 p_mode,                         -- 'I' for LD ,'R' for others
4521 		p_business_group_id,            -- Business Group Id
4522                 p_set_of_books_id,              -- Set of Books Id
4523 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4524 		l_attribute1,
4525 		l_attribute2,
4526 		l_attribute3,
4527 		l_attribute4,
4528 		l_attribute5,
4529 		l_attribute6,
4530 		l_attribute7,
4531 		l_attribute8,
4532 		l_attribute9,
4533 		l_attribute10,
4534                 l_return_status);
4535 
4536                IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4537                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4538                END IF;
4539      END IF;
4540    END IF;
4541   END IF;
4542  END IF;
4543      p_return_status := fnd_api.g_ret_sts_success;
4544 
4545  EXCEPTION
4546    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4547       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4548       p_return_status := fnd_api.g_ret_sts_unexp_error;
4549 
4550    WHEN NO_PROFILE_EXISTS THEN
4551       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4552       fnd_message.set_name('PSP','PSP_NO_PROFILE_EXISTS');
4553       fnd_msg_pub.add;
4554       p_return_status := fnd_api.g_ret_sts_unexp_error;
4555 
4556    WHEN NO_VAL_DATE_MATCHES THEN
4557       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4558       fnd_message.set_name('PSP','PSP_NO_VAL_DATE_MATCHES');
4559       fnd_message.set_token('ORG_NAME',l_organization_name);
4560       fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
4561       fnd_msg_pub.add;
4562       p_return_status := fnd_api.g_ret_sts_unexp_error;
4563 
4564    WHEN NO_GLOBAL_ACCT_EXISTS THEN
4565       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4566       fnd_message.set_name('PSP','PSP_NO_GLOBAL_ACCT_EXISTS');
4567       fnd_message.set_token('ORG_NAME',l_organization_name);
4568       fnd_message.set_token('PAYROLL_DATE',p_payroll_start_date);
4569       fnd_msg_pub.add;
4570       p_return_status := fnd_api.g_ret_sts_unexp_error;
4571 
4572    WHEN NO_REC_IN_GMS_AWARDS_V THEN
4573       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4574       fnd_message.set_name('PSP','PSP_NO_REC_IN_GMS_AWARDS_V');
4575       fnd_msg_pub.add;
4576       p_return_status := fnd_api.g_ret_sts_unexp_error;
4577 
4578    WHEN PROJECT_AWARD_NOT_LNKD THEN
4579       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4580       fnd_message.set_name('PSP','PSP_PROJECT_AWARD_NOT_LINKED');
4581       fnd_message.set_token('PROJECT_NAME',to_char(l_project_id));
4582       fnd_message.set_token('AWARD_NAME',to_char(l_award_id));
4583       fnd_msg_pub.add;
4584       p_return_status := fnd_api.g_ret_sts_unexp_error;
4585 
4586    WHEN SUSPENSE_AC_INVALID THEN
4587      /* Following added for bug 2514611 */
4588       OPEN   employee_name_cur;
4589       FETCH  employee_name_cur INTO l_employee_name;
4590       CLOSE  employee_name_cur;
4591 
4592       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4593       fnd_message.set_name('PSP','PSP_LD_SUSPENSE_AC_INVALID');
4594       fnd_message.set_token('ORG_NAME',l_organization_name);
4595       fnd_message.set_token('PATC_STATUS',l_patc_status);
4596       fnd_message.set_token('EMPLOYEE_NAME',l_employee_name); --Bug 2514611
4597       fnd_msg_pub.add;
4598       p_return_status := fnd_api.g_ret_sts_unexp_error;
4599 
4600    WHEN OTHERS THEN
4601       g_error_api_path := SUBSTR('SUSPENSE_ACCOUNT:'||g_error_api_path,1,230);
4602       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','SUSPENSE_ACCOUNT');
4603       p_return_status := fnd_api.g_ret_sts_unexp_error;
4604 
4605  END;
4606 
4607 /*
4608 
4609  Commented out NOCOPY  for autopop performance optimization
4610 
4611 
4612 --------------- A U T O - P O P U L A T I O N -----------------------------------------
4613 PROCEDURE autopop(p_acct_type                   IN VARCHAR2,
4614 		  p_person_id                   IN NUMBER,
4615 		  p_assignment_id               IN NUMBER,
4616 		  p_element_type_id             IN NUMBER,
4617 		  p_project_id                  IN NUMBER,
4618 		  p_expenditure_organization_id IN NUMBER,
4619 		  p_task_id                     IN NUMBER,
4620 		  p_award_id                    IN NUMBER,
4621                   p_expenditure_type            IN VARCHAR2,
4622 		  p_gl_code_combination_id      IN NUMBER,
4623 		  p_payroll_start_date          IN DATE,
4624 		  p_effective_date              IN DATE,
4625  		  p_dist_amount                 IN NUMBER,
4626 		  p_schedule_line_id            IN NUMBER,
4627                   p_org_schedule_id             IN NUMBER,
4628 		  p_sub_line_id                 IN NUMBER,
4629                   p_effective_start_date        IN DATE ,
4630                   p_effective_end_date          IN DATE ,
4631                   p_mode                        IN VARCHAR2 := 'I',
4632 		  p_business_group_id           IN NUMBER,
4633                   p_set_of_books_id             IN NUMBER,
4634 		  p_return_status 		OUT NOCOPY VARCHAR2) IS
4635 
4636 l_new_gl_code_combination_id     NUMBER(15);
4637 l_new_expenditure_type	         VARCHAR2(30);
4638 --g_distribution_line_id           NUMBER(10); 2470954
4639 l_auto_pop_status		         VARCHAR2(1);
4640 l_gl_project_flag                VARCHAR2(1);
4641 l_auto_status                    VARCHAR2(20) := null;
4642 l_return_status                  VARCHAR2(1);
4643 l_patc_status			   VARCHAR2(50);
4644 x_proc_executed                  VARCHAR2(10) := 'TRUE';
4645 l_billable_flag                  VARCHAR2(1);
4646 l_effective_date                 DATE;
4647 l_msg_count                      NUMBER;
4648 l_msg_app                        VARCHAR2(2000);
4649 l_msg_type                       varchar2(2000);
4650 l_msg_token1                     varchar2(2000);
4651 l_msg_token2                     varchar2(2000);
4652 l_msg_token3                     varchar2(2000);
4653   --l_award_status  varchar2(50);  -- for bug fix 1931680
4654   l_award_status  varchar2(200);
4655 l_linkage_status                 VARCHAR2(50) := NULL;
4656 
4657 
4658 BEGIN
4659 
4660    IF p_acct_type = 'N' THEN
4661      l_gl_project_flag := 'G';
4662 
4663   --dbms_output.put_line('params are '||p_person_id,' '||p_assignment_id||' '||p_element_type_id );
4664 -- dbms_output.put_line('ccid is '||p_gl_code_combination_id||' '||p_payroll_start_date||' ');
4665 -- dbms_output.put_line(' bg is '||p_business_group_id||' '||p_ste_of_books_id);
4666 
4667      psp_autopop.main(
4668                     p_acct_type                   => p_acct_type,
4669 		    p_person_id                   => p_person_id,
4670 	            p_assignment_id               => p_assignment_id,
4671 		    p_element_type_id             => p_element_type_id,
4672 		    p_project_id                  => null,
4673 		    p_expenditure_organization_id => null,
4674 		    p_task_id                     => null,
4675 		    p_award_id                    => null,
4676                     p_expenditure_type            => null,
4677 		    p_gl_code_combination_id      => p_gl_code_combination_id,
4678 		    p_payroll_date                => p_payroll_start_date,
4679 		    p_set_of_books_id             => p_set_of_books_id,
4680                     p_business_group_id           => p_business_group_id,
4681 		    ret_expenditure_type          => l_new_expenditure_type,
4682 		    ret_gl_code_combination_id    => l_new_gl_code_combination_id,
4683 		    retcode 			  => l_auto_pop_status);
4684 
4685      IF (l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
4686        (l_auto_pop_status = FND_API.G_RET_STS_ERROR) THEN
4687        IF l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4688          l_auto_status := 'AUTO_POP_NA_ERROR';
4689        ELSIF l_auto_pop_status = FND_API.G_RET_STS_ERROR THEN
4690          l_auto_status := 'AUTO_POP_NO_VALUE';
4691        END IF;
4692 
4693        -- Auto-Population returned an error or no value. Use Suspense Acct.
4694          suspense_account(x_proc_executed,
4695                         p_person_id,
4696                         p_sub_line_id,
4697                         p_assignment_id,
4698                         p_payroll_start_date,
4699                         p_dist_amount,
4700                         l_auto_status,
4701                         p_schedule_line_id,
4702                         NULL,
4703                         NULL,
4704                         p_org_schedule_id,
4705                         p_effective_date,
4706                         p_mode,
4707 			p_business_group_id,
4708                         p_set_of_books_id,
4709                         l_return_status);
4710 
4711          IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4712            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4713          END IF;
4714 
4715      ELSIF l_auto_pop_status = FND_API.G_RET_STS_SUCCESS THEN
4716  	 -- insert the record in psp_distribution_lines
4717        insert_into_distribution_lines(
4718 	          P_SUB_LINE_ID,                  -- payroll sub-lines id
4719  	          P_PAYROLL_START_DATE,           -- distribution date
4720                   P_EFFECTIVE_DATE,               -- effective date
4721  		  P_DIST_AMOUNT,                  -- distribution amount
4722  		  'N',                            -- status code
4723                   NULL,                           -- suspense reason code
4724                   NULL,                           -- default reason code
4725       		  P_SCHEDULE_LINE_ID,             -- schedule line id
4726  		  NULL,                           -- default organization a/c
4727  		  NULL,                           -- suspense organization a/c
4728  		  NULL,                           -- global element type
4729 	          P_ORG_SCHEDULE_ID,              -- org default schedule id
4730                   l_gl_project_flag,              -- gl project flag
4731                   NULL,                           -- reversal entry flag
4732                   l_new_gl_code_combination_id,   -- gl_code_combination_id
4733                   p_project_id,                   -- project_id,
4734                   p_task_id   ,                   -- task_id,
4735                   p_award_id  ,                   -- award_id,
4736                   p_expenditure_organization_id,  -- expenditure org id
4737                   p_expenditure_type,             -- expenditure_type
4738                   p_effective_start_date,         -- Eff start date of schedule
4739                   p_effective_end_date,           -- Eff start date of schedule
4740                   p_mode,                         -- 'I' for LD ,'R' for others
4741 		  p_business_group_id,            -- Business Group Id
4742                   p_set_of_books_id,              -- Set of Books Id
4743 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4744 		l_attribute1,
4745 		l_attribute2,
4746 		l_attribute3,
4747 		l_attribute4,
4748 		l_attribute5,
4749 		l_attribute6,
4750 		l_attribute7,
4751 		l_attribute8,
4752 		l_attribute9,
4753 		l_attribute10,
4754                   l_return_status);
4755 
4756         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4757           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4758         END IF;
4759         insert_into_autopop_results(
4760 				    G_DIST_LINE_ID,
4761 				    NULL,
4762 				    L_NEW_GL_CODE_COMBINATION_ID,
4763 				    l_return_status);
4764         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4765           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4766         END IF;
4767 
4768       END IF; -- l_auto_pop_status = FND_API.G_RET_STS_SUCCESS
4769 
4770   ELSIF p_acct_type = 'E' THEN
4771     psp_autopop.main(p_acct_type                   => 'E',
4772 	  p_person_id                    => p_person_id,
4773 	  p_assignment_id                => p_assignment_id,
4774 	  p_element_type_id              => p_element_type_id,
4775 	  p_project_id                   => p_project_id,
4776 	  p_expenditure_organization_id  => p_expenditure_organization_id,
4777 	  p_task_id                      => p_task_id,
4778 	  p_award_id                     => p_award_id,
4779           p_expenditure_type             => p_expenditure_type,
4780           p_gl_code_combination_id       => null,
4781           p_payroll_date                 => p_payroll_start_date,
4782 	  p_set_of_books_id              => p_set_of_books_id,
4783           p_business_group_id            => p_business_group_id,
4784           ret_expenditure_type           => l_new_expenditure_type,
4785           ret_gl_code_combination_id     => l_new_gl_code_combination_id,
4786 	  retcode 		         => l_auto_pop_status);
4787 
4788     IF (l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
4789        (l_auto_pop_status = FND_API.G_RET_STS_ERROR) THEN
4790        IF l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
4791          l_auto_status := 'AUTO_POP_NA_ERROR';
4792        ELSIF l_auto_pop_status = FND_API.G_RET_STS_ERROR THEN
4793          l_auto_status := 'AUTO_POP_NO_VALUE';
4794        END IF;
4795 
4796        -- Auto-Population returned an error or no value. Use Suspense Acct.
4797        suspense_account(x_proc_executed,
4798                        p_person_id,
4799                        p_sub_line_id,
4800                        p_assignment_id,
4801                        p_payroll_start_date,
4802                        p_dist_amount,
4803                        l_auto_status,
4804                        p_schedule_line_id,
4805                        NULL,
4806                        NULL,
4807                        NULL,
4808                        p_effective_date,
4809                        p_mode,
4810 		       p_business_group_id,
4811                        p_set_of_books_id,
4812                        l_return_status);
4813 
4814       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4815         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4816       END IF;
4817 
4818     ELSIF l_auto_pop_status = FND_API.G_RET_STS_SUCCESS THEN
4819 	-- modified as per 11i changes
4820 	   -- dbms_output.put_line('Project id 8 '|| to_char(p_project_id));
4821 	   -- dbms_output.put_line('task id 8 '|| to_char(p_task_id));
4822 	   -- dbms_output.put_line('Dte id 8 '|| to_char(p_payroll_start_date));
4823 	   -- dbms_output.put_line('Type 8 '|| l_new_expenditure_type);
4824 	   -- dbms_output.put_line('person_id 8 '|| to_char(p_person_id));
4825 
4826 	    pa_transactions_pub.validate_transaction(
4827 			x_project_id		=> p_project_id,
4828 			x_task_id		=> p_task_id,
4829 			x_ei_date		=> p_effective_date, ---p_payroll_start_date, Bug 1874696
4830 			x_expenditure_type	=> l_new_expenditure_type,
4831 			x_non_labor_resource	=> null,
4832 			x_person_id		=> p_person_id,
4833 			x_incurred_by_org_id	=> p_expenditure_organization_id,
4834 			x_calling_module	=> 'PSPLDCDB',
4835 			x_msg_application	=> l_msg_app,
4836 			x_msg_type		=> l_msg_type,
4837 			x_msg_token1		=> l_msg_token1,
4838 			x_msg_token2		=> l_msg_token2,
4839 			x_msg_token3		=> l_msg_token3,
4840 			x_msg_count		=> l_msg_count,
4841 			x_msg_data		=> l_patc_status,
4842 			x_billable_flag		=> l_billable_flag,
4843 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
4844 
4845 
4846 	   -- dbms_output.put_line('patc stat 8 '|| l_patc_status);
4847 	    -- GMS is enabled and patc went through
4848 	     if p_award_id is not null and l_patc_status is null
4849              then
4850                  gms_transactions_pub.validate_transaction
4851                                 (p_project_id,
4852                                 p_task_id,
4853 				p_award_id,
4854                                 l_new_expenditure_type,
4855                                 p_effective_date, ---- p_payroll_start_date, Bug 1874696
4856                                 'PSPLDCDB',
4857                                 l_award_status);
4858 
4859                  if l_award_status is null
4860                  then
4861                         project_award_linkage(p_project_id,
4862                                   p_award_id,
4863                                   l_linkage_status,
4864                                   l_return_status);
4865 		 else
4866 
4867 
4868                    if l_award_status IS NOT NULL
4869 
4870 		--	l_patc_status := l_award_status;  for bug fix 1931680
4871                         l_patc_status  := substr(l_award_status,1,50);
4872                  end if;
4873              end if;
4874 
4875 
4876       IF l_patc_status IS NOT NULL OR l_award_status is not null
4877 --	or 	l_linkage_status is not null
4878         THEN
4879         suspense_account(x_proc_executed,
4880                          p_person_id,
4881                          p_sub_line_id,
4882                          p_assignment_id,
4883                          p_payroll_start_date,
4884                          p_dist_amount,
4885                          l_patc_status,
4886                          p_schedule_line_id,
4887                          NULL,
4888                          NULL,
4889                          p_org_schedule_id,
4890                          p_effective_date,
4891                          p_mode,
4892 			 p_business_group_id,
4893                          p_set_of_books_id,
4894                          l_return_status);
4895 
4896         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4897           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4898         END IF;
4899 
4900 	ELSIF l_patc_status IS NULL
4901 --  OR l_linkage_status IS NULL   2014950
4902 		OR l_award_status is null THEN
4903       -- Bug 1874696
4904 --	if p_award_id is not null
4905 --	then
4906   --          psp_general.poeta_effective_date(p_payroll_start_date,
4907    --                          p_project_id,
4908     --                         p_award_id,
4909    --			     P_task_id,
4910     --                         l_effective_date,
4911                              l_return_status);
4912 --	elsif p_award_id is null
4913 --	then
4914  --           psp_general.poeta_effective_date(p_payroll_start_date,
4915   --                           p_project_id,
4916    --			     P_task_id,
4917                              l_effective_date,
4918     --                         l_return_status);
4919 --	end if;
4920  --       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4921   --        RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4922    --     END IF;
4923         l_gl_project_flag := 'P';
4924 
4925         -- insert the record in psp_distribution_lines
4926         insert_into_distribution_lines(
4927 	      	P_SUB_LINE_ID,                  -- payroll sub-lines id
4928        	        P_PAYROLL_START_DATE,           -- distribution date
4929                 P_EFFECTIVE_DATE,               -- effective date, changed from l_Effective_date for 1874696
4930  	      	P_DIST_AMOUNT,                  -- distribution amount
4931  	       'N',                             -- status code
4932                 NULL,                           -- suspense reason code
4933                 NULL,                           -- default reason code
4934       	        P_SCHEDULE_LINE_ID,             -- schedule line id
4935  	      	NULL,                           -- default organization a/c
4936  	      	NULL,                           -- suspense organization a/c
4937  	      	NULL,                           -- global element type
4938     	        P_ORG_SCHEDULE_ID,              -- org default schedule id
4939                 L_GL_PROJECT_FLAG,              -- gl project flag
4940                 NULL,                           -- reversal entry flag
4941                 p_gl_code_combination_id,       -- gl_code_combination_id
4942                 p_project_id,                   -- project_id,
4943                 p_task_id   ,                   -- task_id,
4944                 p_award_id  ,                   -- award_id,
4945                 p_expenditure_organization_id,  -- expenditure org id
4946                 l_new_expenditure_type,         -- expenditure_type
4947                 p_effective_start_date,    -- Eff start date of schedule
4948                 p_effective_end_date,      -- Eff start date of schedule
4949                 p_mode,                    -- 'I' for LD ,'R' for others
4950 		p_business_group_id,            -- Business Group id
4951                 p_set_of_books_id,              -- Set of Books Id
4952 		l_attribute_category,		-- Introduced DFF columns for bug fix 2908859
4953 		l_attribute1,
4954 		l_attribute2,
4955 		l_attribute3,
4956 		l_attribute4,
4957 		l_attribute5,
4958 		l_attribute6,
4959 		l_attribute7,
4960 		l_attribute8,
4961 		l_attribute9,
4962 		l_attribute10,
4963                 l_return_status);
4964 
4965          IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4966            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4967          END IF;
4968 
4969 	   insert_into_autopop_results(
4970 				      G_DIST_LINE_ID,
4971 				      L_NEW_EXPENDITURE_TYPE,
4972 				      NULL,
4973 				      l_return_status);
4974          IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4975            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4976          END IF;
4977        END IF; -- l_patc_status IS NOT NULL
4978 
4979      END IF; -- l_auto_pop_status = FND_API.G_RET_STS_SUCCESS
4980 
4981 
4982    END IF;
4983 
4984 p_return_status := fnd_api.g_ret_sts_success;
4985 
4986  EXCEPTION
4987    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4988       g_error_api_path := SUBSTR('AUTOPOP:'||g_error_api_path,1,1000);
4989       p_return_status := fnd_api.g_ret_sts_unexp_error;
4990 
4991    WHEN OTHERS THEN
4992       g_error_api_path := SUBSTR('AUTOPOP:'||g_error_api_path,1,1000);
4993       p_return_status := fnd_api.g_ret_sts_unexp_error;
4994 
4995 
4996 END autopop;
4997 
4998 
4999 
5000 ************************************************************************************/
5001 
5002 
5003 ---------------------- I N S E R T   S T A T E M E N T  ------------------------------------
5004  PROCEDURE insert_into_distribution_lines(
5005  	   L_PAYROLL_SUB_LINE_ID  	 IN	NUMBER,
5006  	   L_DISTRIBUTION_DATE		 IN	DATE,
5007 	   L_EFFECTIVE_DATE		 IN	DATE,
5008  	   L_DISTRIBUTION_AMOUNT	 IN	NUMBER,
5009  	   L_STATUS_CODE		 IN	VARCHAR2,
5010  	   L_SUSPENSE_REASON_CODE	 IN	VARCHAR2,
5011            L_DEFAULT_REASON_CODE	 IN	VARCHAR2,
5012  	   L_SCHEDULE_LINE_ID		 IN	NUMBER,
5013  	   L_DEFAULT_ORG_ACCOUNT_ID	 IN	NUMBER,
5014            L_SUSPENSE_ORG_ACCOUNT_ID	 IN	NUMBER,
5015  	   L_ELEMENT_ACCOUNT_ID		 IN	NUMBER,
5016  	   L_ORG_SCHEDULE_ID		 IN	NUMBER,
5017            L_GL_PROJECT_FLAG		 IN	VARCHAR2,
5018            L_REVERSAL_ENTRY_FLAG         IN	VARCHAR2,
5019            P_GL_CODE_COMBINATION_ID      IN     NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5020            P_PROJECT_ID                  IN     NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5021            P_TASK_ID                     IN     NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5022            P_AWARD_ID                    IN     NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5023            P_EXPENDITURE_ORGANIZATION_ID IN     NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5024            P_EXPENDITURE_TYPE            IN     VARCHAR2,	-- := FND_API.G_MISS_CHAR, Commented initialization for bug fix 2916848
5025            P_EFFECTIVE_START_DATE        IN     DATE,	-- := FND_API.G_MISS_DATE, Commented initialization for bug fix 2916848
5026            P_EFFECTIVE_END_DATE          IN     DATE,	-- := FND_API.G_MISS_DATE, Commented initialization for bug fix 2916848
5027            P_MODE                        IN     VARCHAR2 := 'I',
5028 	   P_BUSINESS_GROUP_ID           IN     NUMBER,
5029            P_SET_OF_BOOKS_ID             IN     NUMBER,
5030 	p_attribute_category		IN	VARCHAR2,		-- Introduced DFF parameters for bug fix 2908859
5031 	p_attribute1			IN	VARCHAR2,
5032 	p_attribute2			IN	VARCHAR2,
5033 	p_attribute3			IN	VARCHAR2,
5034 	p_attribute4			IN	VARCHAR2,
5035 	p_attribute5			IN	VARCHAR2,
5036 	p_attribute6			IN	VARCHAR2,
5037 	p_attribute7			IN	VARCHAR2,
5038 	p_attribute8			IN	VARCHAR2,
5039 	p_attribute9			IN	VARCHAR2,
5040 	p_attribute10			IN	VARCHAR2,
5041 	P_RETURN_STATUS               OUT NOCOPY    VARCHAR2,
5042 	P_CAP_EXCESS_GLCCID		IN	NUMBER	DEFAULT NULL,
5043 	P_CAP_EXCESS_PROJECT_ID		IN	NUMBER	DEFAULT NULL,
5044 	P_CAP_EXCESS_TASK_ID		IN	NUMBER	DEFAULT NULL,
5045 	P_CAP_EXCESS_AWARD_ID		IN	NUMBER	DEFAULT NULL,
5046 	P_CAP_EXCESS_EXP_ORG_ID		IN	NUMBER	DEFAULT NULL,
5047 	P_CAP_EXCESS_EXP_TYPE		IN	VARCHAR2 DEFAULT NULL ) IS
5048 
5049 -- l_description   VARCHAR2(180);		Commented for bug fix 2447912
5050  l_description	 VARCHAR2(360) DEFAULT  '';	-- Bug 2447912: Increased Width to accomodate Org Name increase
5051  l_return_status VARCHAR2(1);
5052 
5053  BEGIN
5054  -- dbms_output.put_line('inserting into dist lines table');
5055   --- inserting into table for PSB mode also, 3813688
5056 	g_tot_dist_amount := g_tot_dist_amount + l_distribution_amount;
5057 	INSERT INTO PSP_DISTRIBUTION_LINES(
5058  		DISTRIBUTION_LINE_ID,
5059  		PAYROLL_SUB_LINE_ID,
5060  		DISTRIBUTION_DATE,
5061             	EFFECTIVE_DATE,
5062  		DISTRIBUTION_AMOUNT,
5063  		STATUS_CODE,
5064  		SUSPENSE_REASON_CODE,
5065             	DEFAULT_REASON_CODE,
5066  		SCHEDULE_LINE_ID,
5067  		DEFAULT_ORG_ACCOUNT_ID,
5068             	SUSPENSE_ORG_ACCOUNT_ID,
5069  		ELEMENT_ACCOUNT_ID,
5070  		ORG_SCHEDULE_ID,
5071 		GL_PROJECT_FLAG,
5072             	REVERSAL_ENTRY_FLAG,
5073 		business_group_id,
5074 		set_of_books_id,
5075 		attribute_category,			-- Introduced DFF columns for bug fix 2908859
5076 		attribute1,
5077 		attribute2,
5078 		attribute3,
5079 		attribute4,
5080 		attribute5,
5081 		attribute6,
5082 		attribute7,
5083 		attribute8,
5084 		attribute9,
5085 		attribute10,
5086 		CAP_EXCESS_GLCCID,
5087                 CAP_EXCESS_PROJECT_ID,
5088                 CAP_EXCESS_AWARD_ID,
5089                 CAP_EXCESS_TASK_ID,
5090                 CAP_EXCESS_EXP_ORG_ID,
5091                 CAP_EXCESS_EXP_TYPE)
5092 	VALUES(
5093                 PSP_DISTRIBUTION_LINES_S.NEXTVAL,
5094  		L_PAYROLL_SUB_LINE_ID,
5095  		L_DISTRIBUTION_DATE,
5096                 L_EFFECTIVE_DATE,
5097  		L_DISTRIBUTION_AMOUNT,
5098  		L_STATUS_CODE,
5099  		L_SUSPENSE_REASON_CODE,
5100             	L_DEFAULT_REASON_CODE,
5101  		L_SCHEDULE_LINE_ID,
5102  		L_DEFAULT_ORG_ACCOUNT_ID,
5103             	L_SUSPENSE_ORG_ACCOUNT_ID,
5104  		L_ELEMENT_ACCOUNT_ID,
5105  		L_ORG_SCHEDULE_ID,
5106 		L_GL_PROJECT_FLAG,
5107             	L_REVERSAL_ENTRY_FLAG,
5108 		P_BUSINESS_GROUP_ID,
5109             	P_SET_OF_BOOKS_ID,
5110 		p_attribute_category,			-- Introduced DFF columns for bug fix 2908859
5111 		p_attribute1,
5112 		p_attribute2,
5113 		p_attribute3,
5114 		p_attribute4,
5115 		p_attribute5,
5116 		p_attribute6,
5117 		p_attribute7,
5118 		p_attribute8,
5119 		p_attribute9,
5120 		p_attribute10,
5121 		P_CAP_EXCESS_GLCCID,
5122                 P_CAP_EXCESS_PROJECT_ID,
5123                 P_CAP_EXCESS_AWARD_ID,
5124                 P_CAP_EXCESS_TASK_ID,
5125                 P_CAP_EXCESS_EXP_ORG_ID,
5126                 P_CAP_EXCESS_EXP_TYPE);
5127        -- dbms_output.put_line('rowcount dist lines insert ='||sql%rowcount);
5128         p_return_status := fnd_api.g_ret_sts_success;
5129  EXCEPTION
5130    WHEN OTHERS THEN
5131      -- dbms_output.put_line('inert into dist lines = '||sqlerrm);
5132       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','INSERT_INTO_DISTRIBUTION_LINES');
5133       p_return_status := fnd_api.g_ret_sts_unexp_error;
5134 
5135  END insert_into_distribution_lines;
5136 
5137 /*
5138 
5139  PROCEDURE insert_into_autopop_results(
5140  		P_DISTRIBUTION_LINE_ID		IN	NUMBER,
5141                 P_NEW_EXPENDITURE_TYPE          IN VARCHAR2,
5142                 P_NEW_GL_CODE_COMBINATION_ID    IN NUMBER,
5143             p_return_status              OUT NOCOPY    VARCHAR2) IS
5144  BEGIN
5145      --********************************************************************
5146 	INSERT INTO PSP_AUTO_POPULATION_RESULTS(
5147  		DISTRIBUTION_LINE_ID,
5148  		EXPENDITURE_TYPE,
5149  		GL_CODE_COMBINATION_ID)
5150 	VALUES(
5151             P_DISTRIBUTION_LINE_ID,
5152  		P_NEW_EXPENDITURE_TYPE,
5153  		P_NEW_GL_CODE_COMBINATION_ID);
5154    --  ***************************************************************************
5155        UPDATE PSP_DISTRIBUTION_LINES
5156 	SET auto_expenditure_type = p_new_expenditure_type,
5157 	    auto_gl_code_combination_id = p_new_gl_code_combination_id
5158 	WHERE distribution_line_id = p_distribution_line_id;
5159 
5160       p_return_status := fnd_api.g_ret_sts_success;
5161 
5162  EXCEPTION
5163    WHEN OTHERS THEN
5164       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','INSERT_INTO_AUTOPOP_RESULTS');
5165       p_return_status := fnd_api.g_ret_sts_unexp_error;
5166 
5167  END insert_into_autopop_results;
5168 
5169 */
5170 
5171  PROCEDURE Get_Distribution_Lines
5172                (p_proc_executed       OUT NOCOPY VARCHAR2,
5173                 p_person_id           IN  NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5174                 p_sub_line_id         IN  NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization 2916848
5175                 p_assignment_id       IN  NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5176                 p_element_type_id     IN  NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5177                 p_payroll_start_date  IN  DATE,	--   := FND_API.G_MISS_DATE, Commented initialization for bug fix 2916848
5178                 p_daily_rate          IN  NUMBER,	-- := FND_API.G_MISS_NUM, Commented initialization for bug fix 2916848
5179                 p_effective_date      IN  DATE,	--   := FND_API.G_MISS_DATE, Commented initialization for bug fix 2916848
5180                 p_mode                IN  VARCHAR2 := 'I',
5181 		p_business_group_id   IN  NUMBER,
5182                 p_set_of_books_id     IN  NUMBER,
5183 		p_attribute_category	IN	VARCHAR2 default null,		-- Introduced DFF parameters for bug fix 2908859
5184 		p_attribute1		IN	VARCHAR2 default null,
5185 		p_attribute2		IN	VARCHAR2 default null,
5186 		p_attribute3		IN	VARCHAR2 default null,
5187 		p_attribute4		IN	VARCHAR2 default null,
5188 		p_attribute5		IN	VARCHAR2 default null,
5189 		p_attribute6		IN	VARCHAR2 default null,
5190 		p_attribute7		IN	VARCHAR2 default null,
5191 		p_attribute8		IN	VARCHAR2 default null,
5192 		p_attribute9		IN	VARCHAR2 default null,
5193 		p_attribute10		IN	VARCHAR2 default null,
5194 		p_or_gl_ccid		IN	NUMBER DEFAULT NULL,
5195 		p_or_project_id		IN	NUMBER DEFAULT NULL,
5196 		p_or_task_id		IN	NUMBER DEFAULT NULL,
5197 		p_or_award_id		IN	NUMBER DEFAULT NULL,
5198 		p_or_expenditure_org_id	IN	NUMBER DEFAULT NULL,
5199 		p_or_expenditure_type	IN	VARCHAR2 DEFAULT NULL,
5200                 p_return_status       OUT NOCOPY VARCHAR2) IS
5201 
5202    -- variables for 3813688
5203    l_payroll_control_id integer;
5204 
5205     cursor get_control_id is
5206     select ppl.payroll_control_id
5207       from psp_payroll_lines ppl,
5208            psp_payroll_sub_lines ppsl
5209      where ppl.payroll_line_id = ppsl.payroll_line_id
5210        and ppsl.payroll_sub_line_id = g_sub_line_id;
5211 
5212   l_proc_executed  varchar2(10);
5213   l_org_def_labor_schedule   VARCHAR2(3)  := psp_general.get_specific_profile('PSP_DEFAULT_SCHEDULE');
5214   l_org_def_account          VARCHAR2(3)  := psp_general.get_specific_profile('PSP_DEFAULT_ACCOUNT');
5215   l_return_status            VARCHAR2(1);
5216 
5217 
5218 x_proc_executed		VARCHAR2(10) := 'TRUE';
5219 l_linkage_status	VARCHAR2(50);
5220 l_patc_status		VARCHAR2(50);
5221 l_billable_flag		VARCHAR2(1);
5222 l_msg_count		NUMBER;
5223 l_msg_app		VARCHAR2(2000);
5224 l_msg_type		VARCHAR2(2000);
5225 l_msg_token1		VARCHAR2(2000);
5226 l_msg_token2		VARCHAR2(2000);
5227 l_msg_token3		VARCHAR2(2000);
5228 l_award_status		VARCHAR2(200);
5229 
5230  --- new procedure for PSB array bug 3813688
5231 procedure create_master_lines( p_assignment_id in integer,
5232                               p_daily_rate in number,
5233                               p_payroll_start_date in date,
5234                               p_business_group_id in integer,
5235                               p_set_of_books_id in integer,
5236                               p_element_type_id in integer) is
5237    l_line_id integer;
5238    l_control_id integer;
5239    --- introduced for 5080403
5240   cursor autopop_config_cur is
5241   select pcv_information1 global_element_autopop,
5242          pcv_information2 element_type_autopop,
5243          pcv_information3 element_class_autopop,
5244          pcv_information4 assignment_autopop,
5245          pcv_information5 default_schedule_autopop,
5246          pcv_information6 default_account_autopop,
5247          pcv_information7 suspense_account,
5248          pcv_information10 excess_account
5249     from pqp_configuration_values
5250    where pcv_information_category = 'PSP_ENABLE_AUTOPOPULATION'
5251      and legislation_code is null
5252      and nvl(business_group_id, p_business_group_id) = p_business_group_id;
5253 
5254 begin
5255 
5256 savepoint psp_create_pay_paysub_lines;   --- 4639139
5257    open autopop_config_cur;
5258    fetch autopop_config_cur into g_global_element_autopop,
5259                                  g_asg_element_autopop,
5260                                  g_asg_ele_group_autopop,
5261                                  g_asg_autopop,
5262                                  g_org_schedule_autopop,
5263                                  g_default_account_autopop,
5264                                  g_suspense_account_autopop,
5265                                  g_excess_account_autopop;
5266    close autopop_config_cur;
5267 
5268 -- dbms_output.put_line('Entered create master');
5269  select psp_payroll_lines_s.nextval,
5270         psp_payroll_sub_lines_s.nextval,
5271         psp_payroll_controls_s.nextval
5272    into l_line_id,
5273         g_sub_line_id,
5274         l_control_id
5275    from dual;
5276 
5277  insert into psp_payroll_lines
5278    (payroll_line_id,
5279     set_of_books_id,
5280     assignment_id,
5281     person_id,
5282     element_type_id,
5283     pay_amount,
5284     status_code,
5285     payroll_control_id,
5286     dr_cr_flag,
5287     last_update_date,
5288     last_updated_by,
5289     last_update_login,
5290     created_by,
5291     creation_date,
5292     effective_date)
5293   select l_line_id,
5294     p_set_of_books_id,
5295     p_assignment_id,
5296     person_id,
5297     p_element_type_id,
5298     p_daily_rate,
5299     'N',
5300     l_control_id,
5301     'D',
5302     sysdate,
5303     0,
5304     0,
5305     0,
5306     sysdate,
5307     sysdate
5308   from per_all_assignments_f
5309   where assignment_id = p_assignment_id
5310     and assignment_type = 'E'
5311     and rownum = 1;
5312 
5313 -- dbms_output.put_line('Create master payroll_line rowcount='||sql%rowcount);
5314  insert into psp_payroll_sub_lines
5315     (payroll_sub_line_id,
5316      sub_line_start_date,
5317      sub_line_end_date,
5318      pay_amount,
5319      daily_rate,
5320      salary_used,
5321     last_update_date,
5322     last_updated_by,
5323     last_update_login,
5324     created_by,
5325     creation_date,
5326     payroll_line_id)
5327   values ( g_sub_line_id,
5328            p_payroll_start_date,
5329            p_payroll_start_date,
5330            p_daily_rate,
5331            p_daily_rate,
5332            0,
5333            sysdate,
5334            0,
5335            0,
5336            0,
5337            sysdate,
5338            l_line_id);
5339 
5340 -- dbms_output.put_line('Create master payroll sub line rowcount='||sql%rowcount);
5341 -- dbms_output.put_line('Create master payroll sub line id='||g_sub_line_id);
5342 end create_master_lines;
5343 
5344  --- new procedure for PSB array bug 3813688
5345 procedure fill_psb_array(p_payroll_sub_line_id in integer) is
5346 cursor get_ci_percents (p_payroll_sub_line_id in integer) is
5347 select  pdl.distribution_amount Amount,
5348 	nvl(poa2.start_date_active, nvl(psl.schedule_begin_date, nvl(poa.start_date_active,
5349             nvl(peta.start_date_active, pdls.schedule_begin_date)))) start_date,
5350 	nvl(poa2.end_date_active, nvl(psl.schedule_end_date, nvl(poa.end_date_active,
5351            nvl(peta.start_date_active, nvl(pdls.schedule_end_date, pdl.distribution_date))))) end_date,
5352 	DECODE(pdl.gl_project_flag, 'G', DECODE(pdl.suspense_org_Account_id, NULL,
5353 						nvl(pdl.auto_gl_code_combination_id,
5354 						nvl(psl.gl_code_combination_id,
5355               					nvl(poa.gl_code_combination_id,
5356               					nvl(peta.gl_code_combination_id,
5357                   			pdls.gl_code_combination_id)))),
5358                                              nvl(pdl.suspense_auto_glccid, poa2.gl_code_combination_id)), --5080403
5359 					NULL) glccid,
5360 	DECODE(pdl.gl_project_flag, 'P', DECODE(pdl.suspense_org_account_id, NULL,
5361               				     	nvl(psl.project_id,
5362               					nvl(poa.project_id,
5363               					nvl(peta.project_id,
5364                   				pdls.project_id))),poa2.project_id),
5365 					NULL) project_id,
5366 	DECODE(pdl.gl_project_flag, 'P', decode(pdl.suspense_org_account_id, NULL,
5367               					nvl(psl.task_id,
5368               					nvl(poa.task_id,
5369               					nvl(peta.task_id,
5370                   				pdls.task_id))),poa2.task_id),
5371 					NULL) task_id,
5372 	DECODE(pdl.gl_project_flag, 'P', decode(pdl.suspense_org_account_id, NULL,
5373               					nvl(psl.award_id,
5374               					nvl(poa.award_id,
5375              					nvl(peta.award_id,
5376                   				pdls.award_id))),poa2.award_id),
5377 					NULL) award_id,
5378 	DECODE(pdl.gl_project_flag, 'P', decode(pdl.suspense_org_account_id, NULL,
5379 						nvl(pdl.auto_expenditure_type,
5380 						nvl(psl.expenditure_type,
5381                     				nvl(poa.expenditure_type,
5382                         				nvl(peta.expenditure_type,
5383                               			pdls.expenditure_type)))),
5384                                              nvl(pdl.suspense_auto_exp_type,poa2.expenditure_type)), --5080403
5385 					NULL) expenditure_type,
5386 	DECODE(pdl.gl_project_flag, 'P', decode(pdl.suspense_org_account_id, NULL,
5387               					nvl(psl.expenditure_organization_id,
5388               					nvl(poa.expenditure_organization_id,
5389               					nvl(peta.expenditure_organization_id,
5390                   				pdls.expenditure_organization_id))),
5391         poa2.expenditure_organization_id), NULL) exp_org_id
5392 FROM	Psp_distribution_lines pdl,
5393 	psp_payroll_sub_lines ppsl,
5394 	psp_payroll_lines ppl,
5395 	psp_schedule_lines psl,
5396 	psp_organization_accounts poa,
5397 	psp_element_type_accounts peta,
5398 	psp_default_labor_Schedules pdls,
5399 	psp_organization_accounts poa2
5400 WHERE	ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
5401 AND	ppsl.payroll_line_id 	= ppl.payroll_line_id
5402 AND    	pdl.schedule_line_id = psl.schedule_line_id(+)
5403 AND    	pdl.default_org_account_id = poa.organization_account_id(+)
5404 AND    	pdl.element_account_id = peta.element_account_id(+)
5405 AND    	pdl.org_schedule_id = pdls.org_schedule_id(+)
5406 AND    	pdl.suspense_org_account_id = poa2.organization_account_id(+)
5407 AND 	(pdl.reversal_entry_flag = 'N' OR pdl.reversal_entry_flag IS NULL)
5408 AND		pdl.status_code = 'N'
5409 AND     ppsl.payroll_sub_line_id = p_payroll_sub_line_id;
5410  l_description varchar2(360);
5411  l_return_status varchar2(10);
5412 begin
5413  g_num_dist := 1;
5414  open get_ci_percents(p_payroll_sub_line_id);
5415  loop
5416    fetch get_ci_percents into
5417             g_charging_instructions(g_num_dist).percent,
5418             g_charging_instructions(g_num_dist).effective_start_date,
5419             g_charging_instructions(g_num_dist).effective_end_date,
5420             g_charging_instructions(g_num_dist).gl_code_combination_id,
5421             g_charging_instructions(g_num_dist).project_id,
5422             g_charging_instructions(g_num_dist).task_id,
5423             g_charging_instructions(g_num_dist).award_id,
5424             g_charging_instructions(g_num_dist).expenditure_type,
5425             g_charging_instructions(g_num_dist).expenditure_organization_id;
5426     if get_ci_percents%notfound then
5427        close get_ci_percents;
5428        g_num_dist := g_num_dist - 1;
5429        exit;
5430     end if;
5431   -- dbms_output.put_line(' fetching get_ci_percents');
5432    l_description := '';
5433    if (g_charging_instructions(g_num_dist).gl_code_combination_id is null) then
5434        get_poeta_description
5435               (p_project_id       => g_charging_instructions(g_num_dist).project_id,
5436                p_award_id         => g_charging_instructions(g_num_dist).award_id,
5437                p_task_id          => g_charging_instructions(g_num_dist).task_id,
5438                p_organization_id  => g_charging_instructions(g_num_dist).expenditure_organization_id,
5439                p_description      => l_description,
5440                p_return_status    => l_return_status);
5441 
5442       IF (l_return_status = FND_API.G_RET_STS_SUCCESS ) THEN
5443            g_charging_instructions(g_num_dist).description    := l_description;
5444       end if;
5445 
5446    end if;
5447    g_num_dist := g_num_dist + 1;
5448  end loop;
5449  rollback to psp_create_pay_paysub_lines; --- 4639139
5450 end fill_psb_array;
5451 
5452 BEGIN
5453  -- dbms_output.put_line('Entered get_dist');
5454   -- create master records payroll line, subline  -  only for PSB, bug 3813688
5455   if p_mode = 'D' then
5456    g_gl_effective_date := p_effective_date;
5457    create_master_lines( p_assignment_id,
5458                        p_daily_rate,
5459                        p_payroll_start_date,
5460                        p_business_group_id,
5461                        p_set_of_books_id,
5462                        p_element_type_id);
5463   -- dbms_output.put_line('G Sub line Id '||g_sub_line_id);
5464   else
5465 
5466     -- dbms_output.put_line('CANNOT enter for PSB mode');
5467      g_sub_line_id := p_sub_line_id;
5468   end if;
5469 
5470   -- dbms_output.put_line('Inside hierarchy Check');
5471    g_num_dist := 0;
5472    ----g_auto_population := psp_general.get_specific_profile('PSP_USE_AUTO_POPULATION');  commented for 5080403
5473 
5474    if g_charging_instructions.count > 0 then
5475       g_charging_instructions.delete;
5476    end if;
5477 
5478   -- dbms_output.put_line('Before Global Earnings ');
5479   -- dbms_output.put_line('Person id '||p_person_id);
5480   -- dbms_output.put_line('Sub line Id '||p_sub_line_id);
5481   -- dbms_output.put_line('Assignment id '||p_assignment_id);
5482   -- dbms_output.put_line(' Element type id '||p_element_type_id);
5483   -- dbms_output.put_line('Payroll STart date '||p_payroll_start_date);
5484 
5485 
5486 
5487 
5488 IF (p_or_gl_ccid IS NOT NULL) THEN
5489 		insert_into_distribution_lines
5490 			(P_SUB_LINE_ID,
5491 			P_PAYROLL_START_DATE,
5492 			g_gl_EFFECTIVE_DATE,
5493 			ROUND(p_daily_rate, g_precision),
5494 			'N',
5495 			NULL,
5496 			NULL,
5497 			NULL,
5498 			NULL,
5499 			NULL,
5500 			NULL,
5501 			NULL,
5502 			'G',
5503 			NULL,
5504 			p_or_gl_ccid,
5505 			NULL,
5506 			NULL,
5507 			NULL,
5508 			NULL,
5509 			NULL,
5510 			NULL,
5511 			NULL,
5512 			p_mode,
5513 			p_business_group_id,
5514 			p_set_of_books_id,
5515 			p_attribute_category,
5516 			p_attribute1,
5517 			p_attribute2,
5518 			p_attribute3,
5519 			p_attribute4,
5520 			p_attribute5,
5521 			p_attribute6,
5522 			p_attribute7,
5523 			p_attribute8,
5524 			p_attribute9,
5525 			p_attribute10,
5526 			l_return_status,
5527 			p_or_gl_ccid,
5528 			NULL,
5529 			NULL,
5530 			NULL,
5531 			NULL,
5532 			NULL);
5533 
5534 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5535 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5536 		END IF;
5537 	ELSIF (p_or_project_id IS NOT NULL) THEN
5538 		pa_transactions_pub.validate_transaction
5539 			(x_project_id		=> p_or_project_id,
5540 			x_task_id		=> p_or_task_id,
5541 			x_ei_date		=> p_effective_date,
5542 			x_expenditure_type	=> p_or_expenditure_type,
5543 			x_non_labor_resource	=> NULL,
5544 			x_person_id		=> p_person_id,
5545 			x_incurred_by_org_id	=> p_or_expenditure_org_id,
5546 			x_calling_module	=> 'PSPLDCDB',
5547 			x_msg_application	=> l_msg_app,
5548 			x_msg_type		=> l_msg_type,
5549 			x_msg_token1		=> l_msg_token1,
5550 			x_msg_token2		=> l_msg_token2,
5551 			x_msg_token3		=> l_msg_token3,
5552 			x_msg_count		=> l_msg_count,
5553 			x_msg_data		=> l_patc_status,
5554 			x_billable_flag		=> l_billable_flag,
5555 			p_sys_link_function	=> 'ST');
5556 
5557 		IF ((p_or_award_id IS NOT NULL) AND (l_patc_status IS NULL)) THEN
5558 			gms_transactions_pub.validate_transaction
5559 				(p_or_project_id,
5560 				p_or_task_id,
5561 				p_or_award_id,
5562 				p_or_expenditure_type,
5563 				p_effective_date,
5564 				'PSPLDCDB',
5565 				l_award_status);
5566 
5567 			IF l_award_status IS NOT NULL THEN
5568 				l_patc_status := substr(l_award_status,1,50);
5569 			END IF;
5570 		END IF;
5571 
5572 		IF ((l_patc_status IS NOT NULL ) OR (l_award_status IS NOT NULL)) THEN
5573 			suspense_account(x_proc_executed,
5574 				p_person_id,
5575 				p_sub_line_id,
5576 				p_assignment_id,
5577 				p_payroll_start_date,
5578 				ROUND(p_daily_rate, g_precision),
5579 				l_patc_status,
5580 				NULL,
5581 				NULL,
5582 				NULL,
5583 				NULL,
5584 				p_effective_date,
5585 				p_mode,
5586 				p_business_group_id,
5587 				p_set_of_books_id,
5588 				NULL,
5589 				l_return_status);
5590 
5591 			IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5592 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5593 			END IF;
5594 		ELSIF ((l_patc_status IS NULL) OR (l_award_status IS NULL)) THEN
5595 			insert_into_distribution_lines
5596 				(P_SUB_LINE_ID,
5597 				P_PAYROLL_START_DATE,
5598 				P_EFFECTIVE_DATE,
5599 				ROUND(p_daily_rate, g_precision),
5600 				'N',
5601 				NULL,
5602 				NULL,
5603 				NULL,
5604 				NULL,
5605 				NULL,
5606 				NULL,
5607 				NULL,
5608 				'P',
5609 				NULL,
5610 				NULL,
5611 				p_or_project_id,
5612 				p_or_task_id	,
5613 				p_or_award_id ,
5614 				p_or_expenditure_org_id,
5615 				p_or_expenditure_type,
5616 				NULL,
5617 				NULL,
5618 				p_mode,
5619 				p_business_group_id,
5620 				p_set_of_books_id,
5621 				p_attribute_category,
5622 				p_attribute1,
5623 				p_attribute2,
5624 				p_attribute3,
5625 				p_attribute4,
5626 				p_attribute5,
5627 				p_attribute6,
5628 				p_attribute7,
5629 				p_attribute8,
5630 				p_attribute9,
5631 				p_attribute10,
5632 				l_return_status,
5633 				NULL,
5634 				p_or_project_id,
5635 				p_or_task_id,
5636 				p_or_award_id,
5637 				p_or_expenditure_org_id,
5638 				p_or_expenditure_type);
5639 
5640 			IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5641 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5642 			END IF;
5643 		END IF;
5644 	ELSE	--	else part of EE overrides
5645   -- Search for the global earnings element
5646 
5647 
5648          global_earnings_element(
5649                                  l_proc_executed,
5650                                  p_person_id,
5651                                  g_sub_line_id,
5652                                  p_assignment_id,
5653                                  p_element_type_id,
5654                                  p_payroll_start_date,
5655                                  p_daily_rate,
5656                                  l_org_def_account,
5657                                  p_effective_date,
5658                                  p_mode,
5659 				 p_business_group_id,
5660                                  p_set_of_books_id,
5661 				p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
5662 				p_attribute1,
5663 				p_attribute2,
5664 				p_attribute3,
5665 				p_attribute4,
5666 				p_attribute5,
5667 				p_attribute6,
5668 				p_attribute7,
5669 				p_attribute8,
5670 				p_attribute9,
5671 				p_attribute10,
5672                                  l_return_status);
5673 
5674        -- dbms_output.put_line('Output of global earnings = '||l_proc_executed);
5675 
5676          IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5677            -- dbms_output.put_line('G_Error '||g_error_api_path);
5678             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5679          END IF;
5680 
5681         ---5090002 retro parent element.
5682         if g_retro_parent_element_id is not null
5683           and l_proc_executed = 'FALSE' then
5684                 global_earnings_element(l_proc_executed,
5685                                         p_person_id,
5686                                         g_sub_line_id,
5687                                         p_assignment_id,
5688                                         g_retro_parent_element_id,
5689                                         p_payroll_start_date,
5690                                         p_daily_rate,
5691                                         l_org_def_account,
5692                                         p_effective_date,
5693                                         p_mode,
5694                                         p_business_group_id,
5695                                         p_set_of_books_id,
5696                                         p_attribute_category,
5697                                         p_attribute1,
5698                                         p_attribute2,
5699                                         p_attribute3,
5700                                         p_attribute4,
5701                                         p_attribute5,
5702                                         p_attribute6,
5703                                         p_attribute7,
5704                                         p_attribute8,
5705                                         p_attribute9,
5706                                         p_attribute10,
5707                                         l_return_status);
5708            if l_return_status <> fnd_api.g_ret_sts_success then
5709               raise fnd_api.g_exc_unexpected_error;
5710            end if;
5711         end if;
5712 
5713       -- dbms_output.put_line('Before Element Earnings ');
5714          IF l_proc_executed = 'FALSE' THEN
5715          -- Search for the assignment's element type in psp_schedule_lines
5716 
5717            element_type_hierarchy(
5718                                  l_proc_executed,
5719                                  p_person_id,
5720                                  g_sub_line_id,
5721                                  p_assignment_id,
5722                                  p_element_type_id,
5723                                  p_payroll_start_date,
5724                                  p_daily_rate,
5725                                  l_org_def_account,
5726                                  p_effective_date,
5727                                  p_mode,
5728 				 p_business_group_id,
5729                                  p_set_of_books_id,
5730 				p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
5731 				p_attribute1,
5732 				p_attribute2,
5733 				p_attribute3,
5734 				p_attribute4,
5735 				p_attribute5,
5736 				p_attribute6,
5737 				p_attribute7,
5738 				p_attribute8,
5739 				p_attribute9,
5740 				p_attribute10,
5741                                  l_return_status);
5742 
5743       -- dbms_output.put_line('Output of element hierarchy = '||l_proc_executed);
5744            IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5745              RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5746            END IF;
5747         ---5090002 retro parent element.
5748         if g_retro_parent_element_id is not null
5749           and l_proc_executed = 'FALSE' then
5750       hr_utility.trace('Before calling element_type hierarchy-100 parent element id = '||g_retro_parent_element_id);
5751            element_type_hierarchy(
5752                                  l_proc_executed,
5753                                  p_person_id,
5754                                  g_sub_line_id,
5755                                  p_assignment_id,
5756                                  g_retro_parent_element_id,
5757                                  p_payroll_start_date,
5758                                  p_daily_rate,
5759                                  l_org_def_account,
5760                                  p_effective_date,
5761                                  p_mode,
5762                                  p_business_group_id,
5763                                  p_set_of_books_id,
5764                                  p_attribute_category,
5765                                  p_attribute1,
5766                                  p_attribute2,
5767                                  p_attribute3,
5768                                  p_attribute4,
5769                                  p_attribute5,
5770                                  p_attribute6,
5771                                  p_attribute7,
5772                                  p_attribute8,
5773                                  p_attribute9,
5774                                  p_attribute10,
5775                                  l_return_status);
5776            if l_return_status <> fnd_api.g_ret_sts_success then
5777               raise fnd_api.g_exc_unexpected_error;
5778            end if;
5779         end if;
5780 
5781 
5782       -- dbms_output.put_line('Before Element Class ');
5783            IF l_proc_executed = 'FALSE' THEN
5784              element_class_hierarchy(
5785                                  l_proc_executed,
5786                                  p_person_id,
5787                                  g_sub_line_id,
5788                                  p_assignment_id,
5789                                  p_element_type_id,
5790                                  p_payroll_start_date,
5791                                  p_daily_rate,
5792                                  l_org_def_account,
5793                                  p_effective_date,
5794                                  p_mode,
5795 				 p_business_group_id,
5796                                  p_set_of_books_id,
5797 				p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
5798 				p_attribute1,
5799 				p_attribute2,
5800 				p_attribute3,
5801 				p_attribute4,
5802 				p_attribute5,
5803 				p_attribute6,
5804 				p_attribute7,
5805 				p_attribute8,
5806 				p_attribute9,
5807 				p_attribute10,
5808                                  l_return_status);
5809 
5810       -- dbms_output.put_line('Output of element class hierarchy = '||l_proc_executed);
5811              IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5812                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5813              END IF;
5814         ---5090002 retro parent element.
5815         if  g_retro_parent_element_id is not null
5816           and l_proc_executed = 'FALSE' then
5817              element_class_hierarchy(
5818                                  l_proc_executed,
5819                                  p_person_id,
5820                                  g_sub_line_id,
5821                                  p_assignment_id,
5822                                  g_retro_parent_element_id,
5823                                  p_payroll_start_date,
5824                                  p_daily_rate,
5825                                  l_org_def_account,
5826                                  p_effective_date,
5827                                  p_mode,
5828                                  p_business_group_id,
5829                                  p_set_of_books_id,
5830                                  p_attribute_category,
5831                                  p_attribute1,
5832                                  p_attribute2,
5833                                  p_attribute3,
5834                                  p_attribute4,
5835                                  p_attribute5,
5836                                  p_attribute6,
5837                                  p_attribute7,
5838                                  p_attribute8,
5839                                  p_attribute9,
5840                                  p_attribute10,
5841                                 l_return_status);
5842            if l_return_status <> fnd_api.g_ret_sts_success then
5843               raise fnd_api.g_exc_unexpected_error;
5844            end if;
5845         end if;
5846 
5847 
5848              IF l_proc_executed = 'FALSE' THEN
5849 
5850       -- dbms_output.put_line('Before Assignment g_sub_line_id   = '||g_sub_line_id   );
5851                assignment_hierarchy(
5852                                  l_proc_executed,
5853                                  p_person_id,
5854                                  g_sub_line_id,
5855                                  p_assignment_id,
5856                                  p_element_type_id,
5857                                  p_payroll_start_date,
5858                                  p_daily_rate,
5859                                  l_org_def_account,
5860                                  p_effective_date,
5861                                  p_mode,
5862 				 p_business_group_id,
5863                                  p_set_of_books_id,
5864 				p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
5865 				p_attribute1,
5866 				p_attribute2,
5867 				p_attribute3,
5868 				p_attribute4,
5869 				p_attribute5,
5870 				p_attribute6,
5871 				p_attribute7,
5872 				p_attribute8,
5873 				p_attribute9,
5874 				p_attribute10,
5875                                  l_return_status);
5876 
5877          -- dbms_output.put_line('The output of assignment hierarchy = '||l_proc_executed);
5878 
5879                IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5880                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5881                END IF;
5882 
5883 
5884                IF l_proc_executed = 'FALSE' THEN
5885                  IF l_org_def_labor_schedule = 'Y' THEN
5886                    org_labor_schedule_hierarchy(
5887                                          l_proc_executed,
5888                                          p_person_id,
5889                                          g_sub_line_id,
5890                                          p_assignment_id,
5891                                          p_element_type_id,
5892                                          p_payroll_start_date,
5893                                          p_daily_rate,
5894                                          l_org_def_account,
5895                                          p_effective_date,
5896                                          p_mode,
5897 				 	p_business_group_id,
5898                                  	p_set_of_books_id,
5899 				p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
5900 				p_attribute1,
5901 				p_attribute2,
5902 				p_attribute3,
5903 				p_attribute4,
5904 				p_attribute5,
5905 				p_attribute6,
5906 				p_attribute7,
5907 				p_attribute8,
5908 				p_attribute9,
5909 				p_attribute10,
5910                                          l_return_status);
5911                  END IF;
5912 
5913          -- dbms_output.put_line('The output of org labor = '||l_proc_executed);
5914 
5915                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5916                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5917                  END IF;
5918 
5919                  IF l_proc_executed = 'FALSE' THEN
5920                    IF l_org_def_account = 'Y' THEN
5921                      default_account(
5922                            l_proc_executed,
5923                            p_person_id,
5924                            g_sub_line_id,
5925                            p_assignment_id,
5926                            p_payroll_start_date,
5927                            p_daily_rate,
5928                            '3',    ---'LDM_NO_CI_FOUND',
5929                            p_effective_date,
5930                            p_mode,
5931 			   p_business_group_id,
5932                            p_set_of_books_id,
5933 				p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
5934 				p_attribute1,
5935 				p_attribute2,
5936 				p_attribute3,
5937 				p_attribute4,
5938 				p_attribute5,
5939 				p_attribute6,
5940 				p_attribute7,
5941 				p_attribute8,
5942 				p_attribute9,
5943 				p_attribute10,
5944                            l_return_status);
5945 
5946                     END IF;
5947 
5948     -- dbms_output.put_line('The output of default account = '||l_proc_executed);
5949                    IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5950                       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5951                    END IF;
5952 
5953                    IF l_proc_executed = 'FALSE' THEN
5954                       suspense_account (
5955                              l_proc_executed,
5956                              p_person_id,
5957                              g_sub_line_id,
5958                              p_assignment_id,
5959                              p_payroll_start_date,
5960                              p_daily_rate,
5961                              'LDM_NO_CI_FOUND',
5962                              NULL,
5963                              NULL,
5964                              NULL,
5965                              NULL,
5966                              p_effective_date,
5967                              p_mode,
5968 			     p_business_group_id,
5969                              p_set_of_books_id,
5970                              NULL,   ---    for autopop perf. patch
5971                              l_return_status);
5972 
5973                       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5974                          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5975                       END IF;
5976 
5977                     END IF; -- suspense account
5978                   END IF;   -- default account
5979                 END IF;     -- default org labor schedule
5980               END IF;       -- assignment class
5981             END IF;         -- element group
5982           END IF;           -- element type
5983       END IF;			-- Global Element Introduced for Element Entry Overrides
5984 
5985 
5986 if p_mode = 'D' then   --- introduced for 3813688
5987   ---g_auto_population := FND_PROFILE.value('PSP_USE_AUTO_POPULATION');
5988     open get_control_id;
5989     fetch get_control_id into l_payroll_control_id;
5990     close get_control_id;
5991 
5992     --#fnd_file.put_line(fnd_file.log,'autopop is ON and control_id ='||l_payroll_control_id);
5993     if g_asg_autopop = 'Y' or g_asg_element_autopop = 'Y' or g_asg_ele_group_autopop = 'Y' then
5994     update_dist_schedule_autopop(p_payroll_control_id =>l_payroll_control_id,
5995                                  p_business_group_id=>p_business_group_id,
5996                                  p_set_of_books_id=>p_Set_of_books_id,
5997                                  p_start_asg_id=>p_assignment_id,
5998                                  p_end_asg_id=>p_assignment_id,
5999                                  p_return_Status =>l_return_status);
6000     end if;
6001 
6002     if l_org_def_labor_schedule = 'Y'  and g_org_schedule_autopop = 'Y' THEN
6003              update_dist_odls_autopop(p_payroll_control_id => l_payroll_control_id,
6004                                       p_business_group_id=> p_business_group_id,
6005                                       p_set_of_books_id => p_set_of_books_id,
6006                                       p_start_asg_id=> p_assignment_id,
6007                                       p_end_asg_id=> p_assignment_id,
6008                                       p_return_status => l_return_status);
6009     end if;
6010           --- autopop calls for global element, default account, suspense account .. 5080403
6011           if g_global_element_autopop = 'Y' then
6012                generic_account_autopop( l_payroll_control_id,
6013                                        p_business_group_id,
6014                                        p_set_of_books_id,
6015                                        p_assignment_id,
6016                                        p_assignment_id,
6017                                        'GLOBAL_ELEMENT');
6018           end if;
6019           if g_default_account_autopop = 'Y' and l_org_def_account = 'Y' then
6020                generic_account_autopop( l_payroll_control_id,
6021                                        p_business_group_id,
6022                                        p_set_of_books_id,
6023                                        p_assignment_id,
6024                                        p_assignment_id,
6025                                        'DEFAULT_ACCOUNT');
6026           end if;
6027           if g_suspense_account_autopop = 'Y' then
6028                generic_account_autopop( l_payroll_control_id,
6029                                        p_business_group_id,
6030                                        p_set_of_books_id,
6031                                        p_assignment_id,
6032                                        p_assignment_id,
6033                                        'SUSPENSE');
6034           end if;
6035  -- dbms_output.put_line(' before call to fill_psb_array g_sub_line_id = ' || g_sub_line_id);
6036   fill_psb_array(g_sub_line_id);
6037 end if;
6038 
6039    p_return_status := FND_API.G_RET_STS_SUCCESS;
6040 
6041   EXCEPTION
6042    WHEN FND_API.G_EXC_ERROR THEN
6043     -- dbms_output.put_line('error occured d = 1');
6044       g_error_api_path := SUBSTR('GET DISTRIBUTION LINES:'||g_error_api_path,1,230);
6045       p_return_status := FND_API.G_RET_STS_ERROR;
6046 
6047 
6048    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6049     -- dbms_output.put_line('error occured d ='||sqlerrm);
6050     -- dbms_output.put_line('error occured d = 2');
6051       g_error_api_path := SUBSTR('GET_DISTRIBUTION LINES :'||g_error_api_path,1,230);
6052       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6053 
6054    WHEN OTHERS THEN
6055     -- dbms_output.put_line('error occured d ='||sqlerrm);
6056       g_error_api_path := SUBSTR('GET_DISTRIBUTION LINES:'||g_error_api_path,1,230);
6057 
6058       /*if FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) then
6059 
6060        FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,
6061                                 l_api_name);
6062       end if; */
6063 
6064      p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6065 
6066 end Get_Distribution_Lines;
6067 
6068 
6069 
6070 PROCEDURE update_dist_schedule_autopop(p_payroll_control_id IN NUMBER,
6071                          p_business_group_id IN NUMBER,
6072                          p_set_of_books_id IN NUMBER,
6073                          p_start_asg_id in integer,
6074                          p_end_asg_id   in integer,
6075                                        p_return_status OUT NOCOPY VARCHAR2)  IS
6076 
6077 CURSOR autopop_exc_cur(P_PAYROLL_CONTROL_ID  IN  NUMBER) IS
6078   SELECT pdl.payroll_sub_line_id ,
6079          max(pdl.distribution_date) max_dist_date,  --5592789
6080          max(pdl.effective_date) effective_date,
6081          ppl.person_id,
6082          ppl.assignment_id,
6083          ppl.element_type_id,
6084 psl.project_id,
6085 psl.expenditure_organization_id,
6086 psl.expenditure_type,
6087 psl.task_id,
6088 psl.award_id,
6089 psl.gl_code_combination_id,
6090 pdl.schedule_line_id schedule_line_id,
6091 ppl.cost_id,
6092 ppl.payroll_action_type
6093   FROM   psp_distribution_lines pdl,
6094          psp_payroll_lines ppl,
6095          psp_payroll_sub_lines ppsl,
6096          psp_Schedule_lines psl,
6097          psp_schedule_hierarchy psh
6098   WHERE
6099      ppl.payroll_control_id = p_payroll_control_id
6100   AND    ppl.payroll_line_id = ppsl.payroll_line_id
6101 and ppsl.payroll_sub_line_id=pdl.payroll_sub_line_id
6102   and pdl.suspense_org_account_id is null
6103  and pdl.schedule_line_id=psl.schedule_line_id
6104  and ppl.assignment_id between p_start_asg_id and p_end_asg_id
6105  and psh.schedule_hierarchy_id = psl.schedule_hierarchy_id
6106  and psh.scheduling_types_code in (decode(g_asg_autopop,'Y','A') ,
6107                                    decode(g_asg_element_autopop,'Y','ET'),
6108                                    decode(g_asg_ele_group_autopop,'Y','EG'))
6109   and pdl.adj_account_flag is null
6110 group by
6111 ppl.cost_id,
6112 ppl.payroll_action_type,
6113 pdl.payroll_Sub_line_id,
6114 ppl.person_id,
6115 ppl.assignment_id,
6116 ppl.element_type_id ,
6117 psl.PROJECT_ID ,
6118 psl.EXPENDITURE_ORGANIZATION_ID,
6119 psl.EXPENDITURE_TYPE,
6120 psl.TASK_ID,
6121 psl.AWARD_ID,
6122 psl.gl_code_combination_id,
6123 pdl.schedule_line_id;
6124 
6125 
6126 autopop_exc_rec autopop_exc_cur%ROWTYPE;
6127 
6128  CURSOR dist_line_psl_cur(p_payroll_sub_line_id in number , p_schedule_line_id in number ) is
6129 select distribution_line_id , effective_date, distribution_amount from psp_distribution_lines pdl
6130 where payroll_sub_line_id= p_payroll_sub_line_id and
6131       schedule_line_id= p_schedule_line_id
6132       and suspense_org_account_id is null
6133 order by effective_date;
6134 
6135   l_dist_amount                  NUMBER:=0;
6136   l_acct_type                   VARCHAR2(1);
6137 l_auto_pop_status		         VARCHAR2(1);
6138  l_new_expenditure_type         VARCHAR2(30);
6139  l_new_gl_code_combination_id                  NUMBER(15);
6140 l_auto_status                    VARCHAR2(20) := null;
6141  l_dist_line_id                 NUMBER(9);
6142   l_linkage_status                 VARCHAR2(50);
6143   l_patc_status                    VARCHAR2(50);
6144   x_proc_executed                  VARCHAR2(10) := 'TRUE';
6145   l_billable_flag                  VARCHAR2(1);
6146  l_mode                         VARCHAR2(1) := 'I';
6147 l_effective_date                DATE;
6148   l_return_status            VARCHAR2(1);
6149 l_dbg_ctr number :=0;
6150   l_msg_count                      NUMBER;
6151   l_msg_app                        VARCHAR2(2000);
6152   l_msg_type                       varchar2(2000);
6153   l_msg_token1                     varchar2(2000);
6154   l_msg_token2                     varchar2(2000);
6155   l_msg_token3                     varchar2(2000);
6156   --l_award_status  varchar2(50);  -- for bug fix 1931680
6157   l_award_status  varchar2(200);
6158   ---
6159    l_prev_cost_id                   integer;
6160 
6161 begin
6162 
6163 open autopop_exc_cur(p_payroll_control_id);
6164 loop
6165  fetch autopop_exc_cur into autopop_exc_rec;
6166  if autopop_exc_cur%notfound then exit;
6167  end if;
6168  if nvl(autopop_exc_rec.payroll_action_type,'X') = 'L' then --- 5090002
6169    if nvl(l_prev_cost_id, -999) <> autopop_exc_rec.cost_id then
6170        l_prev_cost_id :=  autopop_exc_rec.cost_id;
6171        g_retro_parent_element_id := nvl(get_retro_parent_element_id(autopop_exc_rec.cost_id), autopop_exc_rec.element_type_id);
6172    end if;
6173        autopop_exc_rec.element_type_id := g_retro_parent_element_id;
6174   hr_utility.trace(' 201 Parent element id = '||autopop_exc_rec.element_type_id);
6175  end if;
6176     --#fnd_file.put_line(fnd_file.log,'autopop for sched lines  exp type, glccid, psob, pbg  ='|| autopop_exc_rec.expenditure_type||','||autopop_exc_rec.gl_code_combination_id||','|| p_set_of_books_id||','||p_business_group_id);
6177 if autopop_exc_rec.gl_code_combination_id is null then
6178     l_acct_type:='E';
6179 else
6180   l_acct_type:='N';
6181 end if;
6182 if nvl(g_use_eff_date,'N') = 'Y' then    --- added if condn for 5505041
6183    null;
6184 else
6185    autopop_exc_rec.effective_date := autopop_exc_rec.max_dist_date;
6186 end if;
6187 
6188 /*
6189    l_dbg_ctr:=l_dbg_ctr+1;
6190    insert into psp_stout values(l_dbg_ctr, 'inside schedule lines');
6191 */
6192 
6193      psp_autopop.main(
6194                     p_acct_type                   => l_acct_type,
6195 		    p_person_id                   => autopop_exc_rec.person_id,
6196 	            p_assignment_id               => autopop_exc_rec.assignment_id,
6197 		    p_element_type_id             => autopop_exc_rec.element_type_id,
6198 		    p_project_id                  => autopop_exc_rec.project_id,
6199 		    p_expenditure_organization_id => autopop_exc_rec.expenditure_organization_id,
6200 		    p_task_id                     => autopop_exc_rec.task_id,
6201 		    p_award_id                    => autopop_exc_rec.award_id,
6202                     p_expenditure_type            => autopop_exc_rec.expenditure_type,
6203 		    p_gl_code_combination_id      => autopop_exc_rec.gl_code_combination_id,
6204 		    p_payroll_date                => autopop_exc_rec.effective_date,
6205 		    p_set_of_books_id             => p_set_of_books_id,
6206                     p_business_group_id           => p_business_group_id,
6207 		    ret_expenditure_type          => l_new_expenditure_type,
6208 		    ret_gl_code_combination_id    => l_new_gl_code_combination_id,
6209 		    retcode 			  => l_auto_pop_status);
6210 
6211     --#fnd_file.put_line(fnd_file.log,'autopop status='|| l_auto_pop_status);
6212 --insert into psp_stout values(1, 'after autopop call');
6213 
6214      IF (l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
6215        (l_auto_pop_status = FND_API.G_RET_STS_ERROR) THEN
6216          --dbms_output.put_line('autopop returned an error ');
6217        IF l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6218 
6219          if l_acct_type ='N'  then
6220               l_auto_status := 'AUTO_POP_NA_ERROR';
6221          else
6222 -- new code for expenditure type error as part of autopop performance patch
6223               l_auto_status :='AUTO_POP_EXP_ERROR';
6224          end if;
6225 
6226        ELSIF l_auto_pop_status = FND_API.G_RET_STS_ERROR THEN
6227          l_auto_status := 'AUTO_POP_NO_VALUE';
6228        END IF;
6229 
6230     open dist_line_psl_cur(autopop_exc_rec.payroll_sub_line_id, autopop_exc_rec.schedule_line_id);
6231 
6232  loop
6233    fetch dist_line_psl_cur into l_dist_line_id , l_effective_date, l_dist_amount;
6234 
6235       if dist_line_psl_cur%notfound then exit;
6236          else
6237 
6238                 suspense_account(
6239                          x_proc_executed,
6240                          autopop_exc_rec.person_id,
6241                          autopop_exc_rec.payroll_sub_line_id,
6242                          autopop_exc_rec.assignment_id,
6243                        --l  p_payroll_start_date,loop thru for each day
6244                          l_effective_date,
6245                          l_dist_amount, -- will be distribution_amount
6246                          l_auto_status,
6247                          NULL,
6248                          NULL,
6249                          NULL,
6250                          NULL,
6251                          l_effective_date,
6252                          l_mode,
6253           --               l_dist_line_id,   bug fix  2126171
6254                          p_business_group_id,
6255                          p_set_of_books_id,
6256                          l_dist_line_id,
6257                          l_return_status
6258                           );
6259        end if;
6260   end loop;
6261       --dbms_output.put_line('after inserting into suspense account');
6262    close dist_line_psl_cur;
6263 
6264 else   --- autopop is successful
6265     if l_acct_type= 'E' then
6266        --dbms_output.put_line(' For expenditure type ');
6267             open dist_line_psl_cur(autopop_exc_rec.payroll_sub_line_id,autopop_exc_rec.schedule_line_id);
6268 
6269     loop
6270           fetch dist_line_psl_cur into l_dist_line_id , l_effective_date, l_dist_amount;
6271 
6272                if dist_line_psl_cur%notfound then exit;
6273                      else
6274 
6275 	    pa_transactions_pub.validate_transaction(
6276 			x_project_id		=> autopop_exc_rec.project_id,
6277 			x_task_id		=> autopop_exc_rec.task_id,
6278 			x_ei_date		=> l_effective_date,
6279 			x_expenditure_type	=> l_new_expenditure_type,   --- changed from old exp type.. for 5080403
6280 			x_non_labor_resource	=> null,
6281 			x_person_id		=> autopop_exc_rec.person_id,
6282 			x_incurred_by_org_id	=> autopop_exc_rec.expenditure_organization_id,
6283 			x_calling_module	=> 'PSPLDCDB',
6284 			x_msg_application	=> l_msg_app,
6285 			x_msg_type		=> l_msg_type,
6286 			x_msg_token1		=> l_msg_token1,
6287 			x_msg_token2		=> l_msg_token2,
6288 			x_msg_token3		=> l_msg_token3,
6289 			x_msg_count		=> l_msg_count,
6290 			x_msg_data		=> l_patc_status,
6291 			x_billable_flag		=> l_billable_flag,
6292 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
6293 
6294 
6295 	   -- dbms_output.put_line('patc stat 1 '|| l_patc_status);
6296 
6297 	     -- GMS is enabled, PATC validation went fine
6298 	     if autopop_exc_rec.award_id is not null and l_patc_status is null
6299 	     then
6300 		 gms_transactions_pub.validate_transaction
6301 				(autopop_exc_rec.project_id,
6302 			   	autopop_exc_rec.task_id,
6303 				autopop_exc_rec.award_id,
6304 			   	l_new_expenditure_type,
6305 				l_effective_date, ---p_payroll_start_date, Bug 1874696
6306 				'PSPLDCDB',
6307 				l_award_status);
6308 
6309 /********************************************************************
6310 		 if l_award_status is null
6311 		 then
6312  			project_award_linkage(autopop_exc_rec.project_id,
6313                                   autopop_exc_rec.award_id,
6314                                   l_linkage_status,
6315                                   l_return_status);
6316 		else
6317 *****************************************************************************/
6318 
6319                 if l_award_status IS NOT NULL then
6320 		--	l_patc_status := l_award_status;  for bug fix 1931680
6321                         l_patc_status  := substr(l_award_status,1,50);
6322 	        end if;
6323 	     end if;
6324              IF ( l_patc_status IS NOT NULL ) OR
6325 --- ( l_linkage_status IS NOT NULL ) OR
6326 		(l_award_status is not null ) THEN
6327 
6328 
6329 /*
6330 
6331     open dist_line_psl_cur;
6332 
6333  loop
6334    fetch dist_line_psl_cur into l_dist_line_id , l_effective_date, l_dist_amount;
6335 
6336       if dist_line_psl_cur%notfound then exit;
6337          else
6338 
6339 
6340 */
6341  -- added following update for 5080403
6342  update psp_distribution_lines  set auto_expenditure_type  = l_new_expenditure_type
6343  where distribution_line_id=l_dist_line_id;
6344                 suspense_account(
6345                          x_proc_executed,
6346                          autopop_exc_rec.person_id,
6347                          autopop_exc_rec.payroll_sub_line_id,
6348                          autopop_exc_rec.assignment_id,
6349                          l_effective_date,
6350                          l_dist_amount,
6351                          l_patc_status,
6352                          NULL,
6353                          NULL,
6354                          NULL,
6355                          NULL,
6356                          l_effective_date,
6357                          l_mode,
6358                   --       l_dist_line_id,   bug fix 2126171
6359                          p_business_group_id,
6360                          p_set_of_books_id,
6361                          l_dist_line_id,
6362                          l_return_status);
6363 
6364                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6365                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6366                  END IF;
6367 
6368 --   end if;
6369 --  end loop;
6370 --   close dist_line_psl_cur;
6371 
6372 else  -- linkage status is successful
6373 
6374   --dbms_output.put_line(' linkage status is successful');
6375 
6376  update psp_distribution_lines  set auto_expenditure_type  = l_new_expenditure_type
6377  where
6378 distribution_line_id=l_dist_line_id;
6379  --- check the above that  it is necessary and sufficient
6380 -- commit; ---- after -- to debug -- will be removed later
6381 
6382    end if;   -- patc status
6383   end if ;  -- dist_line_csr not found;
6384 end loop;
6385 close dist_line_psl_cur;
6386 
6387    else   --  if natural account then
6388 
6389 
6390   ---dbms_output.put_line(' oops --  this  is natural account');
6391 
6392  update psp_distribution_lines  set auto_gl_code_combination_id  = l_new_gl_code_combination_id
6393  where
6394 payroll_sub_line_id=autopop_exc_rec.payroll_sub_line_id
6395 and schedule_line_id =
6396 autopop_exc_rec.schedule_line_id  and suspense_org_account_id is null;
6397 
6398  end if; -- end natural account
6399  end if;  -- end of autopop successful
6400 
6401  end loop;
6402   close autopop_exc_cur;
6403 
6404 end;
6405 
6406 PROCEDURE update_dist_odls_autopop(p_payroll_control_id IN NUMBER,
6407                                    p_business_group_id IN NUMBER,
6408                                    p_Set_of_books_id IN NUMBER,
6409                                    p_start_asg_id in integer,
6410                                    p_end_asg_id   in integer,
6411                                    p_return_status OUT NOCOPY VARCHAR2) IS
6412 
6413 CURSOR autopop_odls_cur(p_payroll_control_id in number) is
6414   SELECT pdl.payroll_sub_line_id ,
6415          max(pdl.distribution_date) max_dist_date,
6416          max(pdl.effective_date) effective_date,
6417          ppl.person_id,
6418          ppl.assignment_id,
6419          ppl.element_type_id
6420 ,
6421    pdls.project_id,
6422     pdls.expenditure_organization_id,
6423     pdls.expenditure_type,
6424     pdls.task_id,
6425     pdls.award_id,
6426     pdls.gl_code_combination_id,
6427     pdls.org_schedule_id,
6428     ppl.cost_id,
6429     ppl.payroll_action_type
6430   FROM   psp_distribution_lines pdl,
6431          psp_payroll_lines ppl,
6432          psp_payroll_sub_lines ppsl,
6433          psp_default_labor_schedules pdls
6434   WHERE
6435      ppl.payroll_control_id = p_payroll_control_id
6436  and ppl.assignment_id between p_start_asg_id and p_end_asg_id
6437   AND    ppl.payroll_line_id = ppsl.payroll_line_id
6438 and ppsl.payroll_sub_line_id=pdl.payroll_sub_line_id
6439   and pdl.suspense_org_account_id is null and
6440    pdl.org_schedule_id= pdls.org_schedule_id
6441   and pdl.adj_account_flag is null
6442 group by
6443 ppl.cost_id,
6444 ppl.payroll_action_type,
6445 pdl.payroll_Sub_line_id,
6446 ppl.person_id,
6447 ppl.assignment_id,
6448 ppl.element_type_id ,
6449 pdls.PROJECT_ID,
6450 pdls.EXPENDITURE_ORGANIZATION_ID,
6451 pdls.EXPENDITURE_TYPE,
6452 pdls.TASK_ID,
6453 pdls.AWARD_ID,
6454 pdls.gl_code_combination_id,
6455 pdls.org_schedule_id;
6456 
6457 
6458 autopop_odls_rec autopop_odls_cur%ROWTYPE;
6459 
6460   CURSOR dist_line_odls_cur(p_payroll_sub_line_id in number  ,p_org_schedule_id in number) is
6461 select distribution_line_id , effective_date, distribution_amount from psp_distribution_lines pdl
6462 where payroll_sub_line_id= autopop_odls_rec.payroll_sub_line_id and
6463       org_schedule_id= autopop_odls_rec.org_schedule_id
6464       and suspense_org_account_id is null
6465 order by effective_date;
6466 
6467   l_dist_amount                  NUMBER:=0;
6468   l_acct_type                   VARCHAR2(1);
6469 l_auto_pop_status		         VARCHAR2(1);
6470  l_new_expenditure_type         VARCHAR2(30);
6471  l_new_gl_code_combination_id                  NUMBER(15);
6472 l_auto_status                    VARCHAR2(20) := null;
6473  l_dist_line_id                 NUMBER(9);
6474   l_linkage_status                 VARCHAR2(50);
6475   l_patc_status                    VARCHAR2(50);
6476   x_proc_executed                  VARCHAR2(10) := 'TRUE';
6477  l_mode                         VARCHAR2(1) := 'I';
6478  l_effective_date               DATE;
6479   l_return_status            VARCHAR2(1);
6480    l_dbg_ctr                number :=0;
6481   l_billable_flag                  VARCHAR2(1)  := NULL;
6482   l_msg_count                      NUMBER;
6483   l_msg_app                        VARCHAR2(2000);
6484   l_msg_type                       varchar2(2000);
6485   l_msg_token1                     varchar2(2000);
6486   l_msg_token2                     varchar2(2000);
6487   l_msg_token3                     varchar2(2000);
6488   l_award_status  varchar2(200);
6489   ---
6490    l_prev_cost_id    integer;
6491 begin
6492 
6493 open autopop_odls_cur(p_payroll_control_id);
6494 loop
6495  fetch autopop_odls_cur into autopop_odls_rec;
6496  if autopop_odls_cur%notfound then exit;
6497  end if;
6498  if nvl(autopop_odls_rec.payroll_action_type,'X') = 'L' then --- 5090002
6499    if nvl(l_prev_cost_id, -999) <> autopop_odls_rec.cost_id then
6500        l_prev_cost_id :=  autopop_odls_rec.cost_id;
6501        g_retro_parent_element_id := nvl(get_retro_parent_element_id(autopop_odls_rec.cost_id), autopop_odls_rec.element_type_id);
6502    end if;
6503        autopop_odls_rec.element_type_id := g_retro_parent_element_id;
6504  end if;
6505 
6506 if autopop_odls_rec.gl_code_combination_id is null then
6507     l_acct_type:='E';
6508 else
6509   l_acct_type:='N';
6510 end if;
6511 if nvl(g_use_eff_date,'N') = 'Y' then    --- added if condn for 5505041
6512    null;
6513 else
6514    autopop_odls_rec.effective_date := autopop_odls_rec.max_dist_date;
6515 end if;
6516 
6517 /*
6518 
6519 l_dbg_ctr:=l_dbg_ctr+1;
6520 insert into psp_stout values(l_dbg_ctr,'inside odls');
6521 */
6522 
6523      psp_autopop.main(
6524                     p_acct_type                   => l_acct_type,
6525 		    p_person_id                   => autopop_odls_rec.person_id,
6526 	            p_assignment_id               => autopop_odls_rec.assignment_id,
6527 		    p_element_type_id             => autopop_odls_rec.element_type_id,
6528 		    p_project_id                  => autopop_odls_rec.project_id,
6529 		    p_expenditure_organization_id => autopop_odls_rec.expenditure_organization_id,
6530 		    p_task_id                     => autopop_odls_rec.task_id,
6531 		    p_award_id                    => autopop_odls_rec.award_id,
6532                     p_expenditure_type            => autopop_odls_rec.expenditure_type,
6533 		    p_gl_code_combination_id      => autopop_odls_rec.gl_code_combination_id,
6534 		    p_payroll_date                => autopop_odls_rec.effective_date,
6535 		    p_set_of_books_id             => p_set_of_books_id,
6536                     p_business_group_id           => p_business_group_id,
6537 		    ret_expenditure_type          => l_new_expenditure_type,
6538 		    ret_gl_code_combination_id    => l_new_gl_code_combination_id,
6539 		    retcode 			  => l_auto_pop_status);
6540 
6541 --insert into psp_stout values(1, 'after autopop call');
6542      IF (l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
6543        (l_auto_pop_status = FND_API.G_RET_STS_ERROR) THEN
6544        IF l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6545 
6546          if l_acct_type='N' then
6547             l_auto_status := 'AUTO_POP_NA_ERROR';
6548          else
6549             l_auto_status :='AUTO_POP_EXP_ERROR';
6550 
6551 -- new code for autopop error for expenditure type
6552 
6553          end if;
6554 
6555        ELSIF l_auto_pop_status = FND_API.G_RET_STS_ERROR THEN
6556          l_auto_status := 'AUTO_POP_NO_VALUE';
6557        END IF;
6558 
6559     open dist_line_odls_cur(autopop_odls_rec.payroll_sub_line_id, autopop_odls_rec.org_schedule_id);
6560 
6561  loop
6562    fetch dist_line_odls_cur into l_dist_line_id , l_effective_date, l_dist_amount;
6563 
6564       if dist_line_odls_cur%notfound then exit;
6565          else
6566  --          insert into psp_stout values(11, 'before suspense postings');
6567                 suspense_account(
6568                          x_proc_executed,
6569                          autopop_odls_rec.person_id,
6570                          autopop_odls_rec.payroll_sub_line_id,
6571                          autopop_odls_rec.assignment_id,
6572                        --l  p_payroll_start_date,loop thru for each day
6573                          l_effective_date,
6574                          l_dist_amount, -- will be distribution_amount
6575                          l_auto_status,
6576                          NULL,
6577                          NULL,
6578                          NULL,
6579                          NULL,
6580                          l_effective_date,
6581                          l_mode,
6582                          p_business_group_id,
6583                          p_set_of_books_id,
6584                          l_dist_line_id,
6585                          l_return_status
6586                           );
6587        end if;
6588   end loop;
6589   close dist_line_odls_cur;
6590 
6591 else   --- autopop is successful
6592     if l_acct_type= 'E' then
6593 
6594     open dist_line_odls_cur(autopop_odls_rec.payroll_sub_line_id, autopop_odls_rec.org_schedule_id);
6595 
6596  loop
6597    fetch dist_line_odls_cur into l_dist_line_id , l_effective_date, l_dist_amount;
6598 
6599       if dist_line_odls_cur%notfound then exit;
6600          else
6601         --   insert into psp_stout values(12, 'inside patc status ');
6602 
6603 	    pa_transactions_pub.validate_transaction(
6604 			x_project_id		=> autopop_odls_rec.project_id,
6605 			x_task_id		=> autopop_odls_rec.task_id,
6606 			x_ei_date		=> l_effective_date,
6607 			x_expenditure_type	=> l_new_expenditure_type,
6608 			x_non_labor_resource	=> null,
6609 			x_person_id		=> autopop_odls_rec.person_id,
6610 			x_incurred_by_org_id	=> autopop_odls_rec.expenditure_organization_id,
6611 			x_calling_module	=> 'PSPLDCDB',
6612 			x_msg_application	=> l_msg_app,
6613 			x_msg_type		=> l_msg_type,
6614 			x_msg_token1		=> l_msg_token1,
6615 			x_msg_token2		=> l_msg_token2,
6616 			x_msg_token3		=> l_msg_token3,
6617 			x_msg_count		=> l_msg_count,
6618 			x_msg_data		=> l_patc_status,
6619 			x_billable_flag		=> l_billable_flag,
6620 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
6621 
6622 
6623 	   -- dbms_output.put_line('patc stat 1 '|| l_patc_status);
6624 
6625 	     -- GMS is enabled, PATC validation went fine
6626 	     if autopop_odls_rec.award_id is not null and l_patc_status is null
6627 	     then
6628 		 gms_transactions_pub.validate_transaction
6629 				(autopop_odls_rec.project_id,
6630 			   	autopop_odls_rec.task_id,
6631 				autopop_odls_rec.award_id,
6632 			   	l_new_expenditure_type,
6633 				l_effective_date, ---p_payroll_start_date, Bug 1874696
6634 				'PSPLDCDB',
6635 				l_award_status);
6636 
6637 /****************************************************************************
6638 		 if l_award_status is null
6639 		 then
6640  			project_award_linkage(autopop_odls_rec.project_id,
6641                                  autopop_odls_rec.award_id,
6642                                   l_linkage_status,
6643                                   l_return_status);
6644 		else
6645 ********************************************************************************/
6646 
6647                  if l_award_status IS NOT NULL THEN
6648 		--	l_patc_status := l_award_status;  for bug fix 1931680
6649                         l_patc_status  := substr(l_award_status,1,50);
6650 	        end if;
6651 	     end if;
6652              IF ( l_patc_status IS NOT NULL ) OR
6653 ----    ( l_linkage_status IS NOT NULL ) OR
6654 		(l_award_status is not null ) THEN
6655 
6656 
6657 
6658 
6659 /*
6660 
6661 	    patc.get_status(x_project_id	=> autopop_odls_rec.project_id,
6662 			    x_task_id		=> autopop_odls_rec.task_id,
6663 			    x_ei_date		=> l_effective_date,
6664 			    x_expenditure_type	=> l_new_expenditure_type,
6665 			    x_non_labor_resource => null,
6666 			    x_person_id		=> autopop_odls_rec.person_id,
6667 			    x_status		=> l_patc_status,
6668 			    x_billable_flag	=> l_billable_flag,
6669 			    x_incurred_by_org_id => autopop_odls_rec.expenditure_organization_id,
6670 			    x_calling_module	=> 'PSPLDCDB',
6671 			    x_attribute1	=> to_char(autopop_odls_rec.award_id));
6672 
6673              project_award_linkage(autopop_odls_rec.project_id,
6674                                   autopop_odls_rec.award_id,
6675                                   l_linkage_status,
6676                                   l_return_status);
6677 
6678              IF ( l_patc_status IS NOT NULL ) OR ( l_linkage_status IS NOT NULL ) THEN
6679 
6680 
6681 */
6682 --    open dist_line_odls_cur;
6683 
6684  --loop
6685   -- fetch dist_line_odls_cur into l_dist_line_id , l_effective_date, l_dist_amount;
6686 
6687 
6688  --- added for 5080403
6689  update psp_distribution_lines  set auto_expenditure_type  = l_new_expenditure_type
6690  where distribution_line_id =l_dist_line_id;
6691 
6692                 suspense_account(
6693                          x_proc_executed,
6694                          autopop_odls_rec.person_id,
6695                          autopop_odls_rec.payroll_sub_line_id,
6696                          autopop_odls_rec.assignment_id,
6697                          l_effective_date,
6698                          l_dist_amount,
6699                          l_patc_status,
6700                          NULL,
6701                          NULL,
6702                          NULL,
6703                          NULL,
6704                          l_effective_date,
6705                          l_mode,
6706                          p_business_group_id,
6707                          p_set_of_books_id,
6708                          l_dist_line_id,
6709                          l_return_status);
6710 
6711                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6712                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6713                  END IF;
6714 
6715 -- end if;  --
6716 --  end loop;
6717 --   close dist_line_odls_cur;
6718 
6719 else  -- linkage status is successful
6720 
6721  update psp_distribution_lines  set auto_expenditure_type  = l_new_expenditure_type
6722  where
6723  distribution_line_id =l_dist_line_id;
6724  --- check the above that  it is necessary and sufficient
6725 -- commit; ---- after -- to debug -- will be removed later
6726 
6727    end if;   -- end of linkage status is sucessful
6728    end if; --  end of dist_line_csr
6729   end loop;
6730  close dist_line_odls_cur;
6731 
6732    else   --  if natural account then
6733 
6734  update psp_distribution_lines  set auto_gl_code_combination_id  = l_new_gl_code_combination_id
6735  where
6736 payroll_sub_line_id=autopop_odls_rec.payroll_sub_line_id
6737 and org_schedule_id =
6738 autopop_odls_rec.org_schedule_id  and suspense_org_account_id is null;
6739 
6740  end if; -- end natural account
6741  end if;  -- end of autopop successful
6742 
6743  end loop;
6744   close autopop_odls_cur;
6745 
6746 end;
6747 
6748 PROCEDURE Get_Poeta_Description
6749           (p_project_id       IN NUMBER,
6750            p_task_id          IN NUMBER,
6751            p_award_id         IN NUMBER,
6752            p_organization_id  IN NUMBER,
6753            p_description     OUT NOCOPY VARCHAR2,
6754            p_return_status   OUT NOCOPY VARCHAR2)
6755 
6756 IS
6757 
6758 --l_description VARCHAR2(180) := '';		Commented for bug fix Bug 2447912
6759 l_description VARCHAR2(360) DEFAULT  '';	-- Bug 2447912: Increased Width to accomodate Org Name increase
6760 
6761 /*  Comented the following code for Bug 3263333
6762  Cursor C_proj is
6763   Select project_number
6764     from gms_projects_expend_v
6765    where project_id = p_project_id; */
6766 
6767 -- Introduced the following code for Bug 3263333
6768 
6769  Cursor C_proj is
6770   Select segment1 Project_number
6771     from pa_projects_all
6772    where project_id = p_project_id;
6773 
6774 
6775  /*  Comented the following code for Bug 3263333
6776 Cursor C_task is
6777   Select task_number
6778     from pa_tasks_expend_v
6779    where task_id = p_task_id; */
6780 
6781 -- Introduced the following code for Bug 3263333
6782 
6783 Cursor C_task is
6784   Select task_number
6785     from pa_tasks
6786    where task_id = p_task_id;
6787 
6788 /* Comented the following code for Bug 3263333
6789 Cursor C_award is
6790   Select award_number
6791     from gms_awards_basic_v
6792    where award_id = p_award_id
6793      and rownum = 1;
6794 */
6795 
6796  -- Introduced the following code for Bug 3263333
6797 
6798  Cursor C_award is
6799   Select award_number
6800     from gms_awards_all
6801    where award_id = p_award_id
6802      and rownum = 1;
6803 
6804 Cursor C_org is
6805   Select name
6806     from pa_organizations_expend_v
6807    where organization_id = p_organization_id
6808    and   active_flag = 'Y';  -- #1339622
6809 
6810 BEGIN
6811 
6812  l_description := null;
6813 
6814  For C_proj_rec in C_proj
6815  Loop
6816    l_description := l_description||'#;'||C_proj_rec.project_number;
6817  End Loop;
6818 
6819  For C_task_rec in C_task
6820  Loop
6821    l_description := l_description||'#;'||C_task_rec.task_number;
6822  End Loop;
6823 
6824  if p_award_id is not null
6825  then
6826  For C_award_rec in C_award
6827  Loop
6828    l_description := l_description||'#;'||C_award_rec.award_number;
6829  End Loop;
6830  else
6831    l_description := l_description||'#;';   ---- for 5215280
6832  end if;
6833  For C_org_rec in C_org
6834  Loop
6835    l_description := l_description||'#;'||C_org_rec.name;
6836  End Loop;
6837 
6838    l_description := l_description||'#;';
6839 
6840    p_description := l_description;
6841    p_return_status := FND_API.G_RET_STS_SUCCESS;
6842 
6843  Exception
6844    WHEN OTHERS THEN
6845       p_return_status := FND_API.G_RET_STS_ERROR;
6846 END;
6847 --- NIH Salary Cap enhancement.
6848 Procedure apply_salary_cap(p_payroll_control_id in integer,
6849                            p_currency_code      in varchar2,
6850                            p_business_group_id IN NUMBER,
6851                            p_Set_of_books_id IN NUMBER,
6852                            p_start_asg_id in integer,
6853                            p_end_asg_id in integer) is
6854 
6855 cursor get_units_per_year(p_payroll_id integer) is
6856 select type.number_per_fiscal_year
6857   from per_time_period_types type,
6858        pay_all_payrolls_f pay
6859  where pay.payroll_id = p_payroll_id
6860    and pay.period_type = type.period_type;
6861 
6862 l_tp_start_date        date;
6863 l_tp_end_date          date;
6864 l_no_units_per_year    integer;
6865 l_tp_no_of_work_days   integer;
6866 l_sponsor_str          varchar2(4000);
6867 l_parent_sponsor_sql_str varchar2(4000);
6868 l_sponsor_code         varchar2(30);
6869 l_sponsor_id           integer;
6870 l_element_sql_str      varchar2(4000);
6871 l_sql_str              varchar2(4000);
6872 l_account_id           integer;
6873 no_excess_account      exception;
6874 l_full_name            varchar2(400);
6875 l_asg_number            varchar2(200);
6876 l_person_id            integer;
6877 
6878 
6879 cursor get_asg_number(p_asg_id integer) is
6880 select person_id, assignment_number
6881   from per_all_assignments_f
6882  where assignment_id = p_asg_id
6883    and assignment_type = 'E'
6884  order by effective_end_date desc;
6885 
6886 cursor get_person_name(p_person_id integer) is
6887 select full_name
6888  from per_all_people_f
6889 where person_id = p_person_id;
6890 
6891 cursor get_control_details(p_payroll_control_id integer) is
6892 select time_period_id,
6893        payroll_id,
6894        currency_code
6895   from psp_payroll_controls
6896  where payroll_control_id = p_payroll_control_id;
6897 
6898 control_details_rec get_control_details%rowtype;
6899 
6900 cursor get_salary_cap_setups is
6901 select cap.start_date start_date,
6902        cap.end_date end_date,
6903        project_id,
6904        substr(l_sponsor_str, instr(l_sponsor_str,fnd.lookup_code)+length(fnd.lookup_code),15) sponsor_id,
6905        cap.annual_salary_cap / l_no_units_per_year / l_tp_no_of_work_days daily_cap_rate,
6906        funding_source_code,
6907        annual_salary_cap
6908   from psp_salary_cap_overrides cap,
6909        fnd_lookup_values fnd
6910  where cap.start_date < l_tp_end_date
6911    and cap.end_date > l_tp_start_date
6912    and cap.funding_source_code = fnd.lookup_code
6913    and fnd.lookup_type = 'PSP_SPONSOR_NAMES'
6914    and fnd.language = userenv('LANG')
6915    and fnd.enabled_flag = 'Y'
6916    and l_tp_start_date between fnd.start_date_active and nvl(fnd.end_date_active, fnd_date.canonical_to_date('4000/01/31'))
6917    and cap.currency_code = control_details_rec.currency_code
6918 union all
6919 select cap2.start_date start_date,
6920        cap2.end_date end_date,
6921        null,
6922        substr(l_sponsor_str, instr(l_sponsor_str,fnd2.lookup_code)+length(fnd2.lookup_code),15) sponsor_id,
6923        cap2.annual_salary_cap / l_no_units_per_year / l_tp_no_of_work_days daily_cap_rate,
6924        funding_source_code,
6925        annual_salary_cap
6926  from psp_salary_caps cap2,
6927        fnd_lookup_values fnd2
6928 where cap2.start_date < l_tp_end_date
6929   and cap2.end_date > l_tp_start_date
6930   and fnd2.enabled_flag = 'Y'
6931   and l_tp_start_date between fnd2.start_date_active and nvl(fnd2.end_date_active, fnd_date.canonical_to_date('4000/01/31'))
6932   and cap2.funding_source_code = fnd2.lookup_code
6933   and fnd2.lookup_type = 'PSP_SPONSOR_NAMES'
6934   and fnd2.language = userenv('LANG')
6935   and cap2.currency_code = control_details_rec.currency_code
6936 order by project_id, sponsor_id;
6937 
6938 cap_rec get_salary_cap_setups%rowtype;
6939 
6940 cursor get_period_dates(p_time_period_id integer) is
6941 select start_date,
6942        end_date
6943   from per_time_periods
6944  where time_period_id = p_time_period_id;
6945 
6946 cursor org_excess_act(p_asg_id    integer,
6947                       p_dist_date date,
6948                       p_funding_source_code varchar2) is
6949 select org.organization_account_id
6950   from psp_organization_accounts org,
6951        per_all_assignments_f paf
6952  where org.account_type_code in ( 'ORG_EXCESS')
6953    and p_dist_date between org.start_date_active and nvl(org.end_date_active, fnd_date.canonical_to_date('4000/01/31'))
6954    and paf.assignment_type = 'E'
6955    and paf.assignment_id = p_asg_id
6956    and p_dist_date between paf.effective_Start_date and paf.effective_end_date
6957    and paf.organization_id = org.organization_id
6958    and org.funding_source_code = p_funding_source_code;   --- added condn for 4744285
6959 
6960 cursor generic_excess_act(p_dist_date date,
6961                           p_excess_org_id number,
6962                           p_funding_source_code varchar2) is
6963 select organization_account_id
6964   from psp_organization_accounts
6965  where p_dist_date between start_date_active and nvl(end_date_active, fnd_date.canonical_to_date('4000/01/31'))
6966    and account_type_code = 'ORG_EXCESS'
6967    and organization_id = p_excess_org_id
6968    and p_funding_source_code = funding_source_code;
6969 
6970 cursor get_funding_source_codes(p_tp_start_date date) is
6971 select distinct lookup_code
6972   from fnd_lookup_values
6973  where lookup_type = 'PSP_SPONSOR_NAMES'
6974    and language = userenv('LANG')
6975    and enabled_flag = 'Y'
6976    and p_tp_start_date between start_date_active and  nvl(end_date_active, fnd_date.canonical_to_date('4000/01/31'));
6977 
6978  t_dist_line_id  psp_sql_tab_number15;
6979  t_dist_date     psp_sql_tab_date;
6980  t_dist_amount   psp_sql_tab_number;
6981  t_assignment_id  psp_sql_tab_number15;
6982  t_excess_line_id  psp_sql_tab_number15;
6983  t_excess_account  psp_sql_tab_number15;
6984  t_cap_sched_amount psp_sql_tab_number;
6985 
6986 cursor check_excess_poeta(p_dist_line_id number) is
6987 select pdl.cap_excess_project_id,
6988        pdl.cap_excess_task_id,
6989        pdl.cap_excess_award_id,
6990        pdl.cap_excess_exp_type,
6991        pdl.cap_excess_exp_org_id,
6992        pdl.effective_date,
6993        ppl.person_id,
6994        ppl.assignment_id,
6995        pdl.distribution_date,
6996        pdl.set_of_books_id,
6997        pdl.distribution_amount,
6998        pdl.business_group_id,
6999        psl.payroll_sub_line_id,
7000        pdl.distribution_line_id
7001   from psp_distribution_lines pdl,
7002        psp_payroll_sub_lines psl,
7003        psp_payroll_lines ppl
7004  where pdl.gl_projecT_flag = 'P'
7005    and psl.payroll_sub_line_id = pdl.payroll_sub_line_id
7006    and pdl.distribution_line_id = p_dist_line_id
7007    and psl.payroll_line_id = ppl.payroll_line_id;
7008 
7009 check_excess_poeta_rec check_excess_poeta%rowtype;
7010 
7011   x_proc_executed     VARCHAR2(10) := 'TRUE';
7012   l_return_status     VARCHAR2(1);
7013   l_gl_project_flag   VARCHAR2(1);
7014   l_patc_status       VARCHAR2(50);
7015   l_billable_flag     VARCHAR2(1);
7016   l_msg_count     NUMBER;
7017   l_msg_app       VARCHAR2(2000);
7018   l_msg_type      varchar2(2000);
7019   l_msg_token1    varchar2(2000);
7020   l_msg_token2    varchar2(2000);
7021   l_msg_token3    varchar2(2000);
7022   l_award_status  varchar2(200);
7023 begin
7024 
7025 hr_utility.trace('CDL procedure: --> apply_salary_cap proc Start');
7026 
7027 open get_control_details(p_payroll_control_id);
7028 fetch get_control_details into control_details_rec;
7029 close get_control_details;
7030 
7031 open get_period_dates(control_details_rec.time_period_id);
7032 fetch get_period_dates into l_tp_start_date, l_tp_end_date;
7033 close get_period_dates;
7034 
7035  hr_utility.trace('CDL program --> apply_salary_cap l_tp_start and end date ='||
7036           l_tp_start_date||','||l_tp_end_date);
7037 
7038 open get_units_per_year(control_details_rec.payroll_id);
7039 fetch get_units_per_year into l_no_units_per_year;
7040 close get_units_per_year;
7041 
7042 l_tp_no_of_work_days := psp_general.business_days(l_tp_start_date, l_tp_end_date);
7043 l_sponsor_str := null;
7044 
7045 open get_funding_source_codes(l_tp_start_date);
7046 loop
7047  fetch get_funding_source_codes into l_sponsor_code;
7048  hr_utility.trace('CDL program --> apply_salary_cap l_sponsor_code (lkup)= '||l_sponsor_code );
7049  if get_funding_source_codes%notfound then
7050    close get_funding_source_codes;
7051    exit;
7052  end if;
7053  l_sponsor_id :=
7054    psp_general.get_configuration_option_value(p_business_group_id,
7055                                               'PSP_SET_SPONSORS_FOR_CAPPING',
7056                                               l_sponsor_code);
7057  l_sponsor_str := l_sponsor_str ||'@@@'|| l_sponsor_code||rpad(to_char(l_sponsor_id),15);
7058  hr_utility.trace('CDL program --> apply_salary_cap WITHIN LOOP l_sponsor_str= '||l_sponsor_str );
7059 end loop;
7060 
7061  hr_utility.trace('CDL program --> apply_salary_cap l_sponsor_str= '||l_sponsor_str );
7062 l_sponsor_id := 0;
7063 open get_salary_cap_setups;
7064 loop
7065   fetch get_salary_cap_setups into cap_rec;
7066   if get_salary_cap_setups%notfound then
7067       close get_salary_cap_setups;
7068       exit;
7069   end if;
7070 
7071   hr_utility.trace('CDL program --> apply_salary_cap cap_rec.sponsor_id, cap_rec.project_id, cap_rec.start_date, cap_rec.enc_date, cap_rec.annual_salary_cap , daily_cap_rate = '||
7072   cap_rec.sponsor_id||','||cap_rec.project_id||','|| cap_rec.start_date||','|| cap_rec.end_date||','|| cap_rec.annual_salary_cap||' , '||cap_rec.daily_cap_rate);
7073 
7074     --#fnd_file.put_line(fnd_file.log,
7075   ---'CDL program --> apply_salary_cap cap_rec.sponsor_id, cap_rec.project_id, cap_rec.start_date, cap_rec.enc_date, cap_rec.annual_salary_cap , daily_cap_rate , l_no_units_per_year , l_tp_no_of_work_days= '
7076 ---|| cap_rec.sponsor_id||','||cap_rec.project_id||','|| cap_rec.start_date||','|| cap_rec.end_date||','|| cap_rec.annual_salary_cap||' , '||cap_rec.daily_cap_rate||' , '||l_no_units_per_year ||' , '||l_tp_no_of_work_days);
7077 
7078 --- removed hard coded strings and replaced with parameters. 5530231
7079      hr_utility.trace('CDL program --> apply_salary_cap constructiong element_str');
7080   ---  added assignment_type = E check for 5575398
7081    if g_cap_element_set_id is null then
7082       l_element_sql_str :=
7083          'and (ppl.assignment_id, ppl.element_type_id) in
7084         (select paf.assignment_id, min(piv.element_type_id)
7085            From per_all_assignments_f paf,
7086                 per_pay_bases         ppb,
7087                 pay_input_values_f    piv
7088           where paf.payroll_id = '||control_details_rec.payroll_id||'
7089             and ('||''''||l_tp_start_date ||''''||'    between paf.effective_start_date  and paf.effective_end_date
7090                 or '||''''||l_tp_end_date   ||''''||' between  paf.effective_start_date  and paf.effective_end_date )
7091             and paf.assignment_id between '||p_start_asg_id||'  and '||p_end_asg_id||'
7092             and paf.pay_basis_id = ppb.pay_basis_id
7093             and paf.assignment_type =  '||''''||'E'||''''||'
7094             and ppb.input_value_id = piv.input_value_id
7095             group by paf.assignment_id, paf.pay_basis_id);';
7096    else
7097       l_element_sql_str :=
7098        'and  ppl.element_type_id in
7099                 ((select petr.element_type_id
7100                     from pay_element_type_rules petr
7101                    where petr.include_or_exclude = '||''''||'I'||''''||'
7102                      and petr.element_Set_id = '||g_cap_element_set_id||')
7103                   union all
7104                   (select pet1.element_type_id
7105                      from pay_element_types_f pet1,
7106                           pay_ele_classification_rules pecr
7107                     where pet1.classification_id = pecr.classification_id
7108                       and pecr.element_set_id = '||g_cap_element_set_id||' ))
7109         and ppl.element_type_id not in
7110                  (select petr1.element_type_id
7111                     from pay_element_type_rules petr1
7112                    where petr1.include_or_exclude='||''''||'E'||''''||'
7113                      and petr1.element_set_id = '||g_cap_element_set_id||');';
7114    end if;
7115      hr_utility.trace('CDL program --> apply_salary_cap DONE constructiong element_str');
7116   if cap_rec.project_id is not null then
7117      hr_utility.trace('CDL program --> apply_salary_cap cap project not null id='||cap_rec.project_id);
7118    l_sql_str :=
7119    'Select pdl.distribution_line_id,
7120            pdl.distribution_date,
7121            pdl.distribution_amount,
7122            round(nvl(psl.schedule_percent, nvl(pdls.schedule_percent, nvl(pea.percent, (100 * pdl.distribution_amount)/ppsl.daily_rate )))/100 * '||
7123               fnd_number.number_to_canonical(cap_rec.daily_cap_rate)||', '||g_precision||') capped_schedule_amount,
7124            ppl.assignment_id,
7125            null excess_account_id,
7126            null excess_line_id
7127        bulk collect
7128        into  :t_dist_line_id,
7129              :t_dist_date,
7130              :t_dist_amount,
7131              :t_capped_sched_amount,
7132              :t_assignment_id,
7133              :t_excess_account,
7134              :t_excess_line_id
7135       From psp_schedule_lines          psl,
7136            psp_organization_accounts   pod,
7137            psp_element_type_accounts   pea,
7138            psp_default_labor_schedules pdls,
7139            psp_payroll_controls        ppc,
7140            psp_payroll_lines           ppl,
7141            psp_payroll_sub_lines       ppsl,
7142            gms_awards_all              awd,
7143            psp_distribution_lines      pdl
7144      where pdl.status_code = '||''''||'N'||''''||'
7145        and pdl.payroll_sub_line_id = ppsl.payroll_sub_line_id
7146        and ppsl.payroll_line_id = ppl.payroll_line_id
7147        and ppl.payroll_control_id = ppc.payroll_control_id
7148        and pdl.schedule_line_id = psl.schedule_line_id(+)
7149        and pdl.default_org_account_id = pod.organization_account_id(+)
7150        and pdl.element_account_id = pea.element_account_id(+)
7151        and pdl.suspense_org_account_id is null
7152        and pdl.org_schedule_id = pdls.org_schedule_id(+)
7153        and pdl.gl_project_flag = '||''''||'P'||''''||'
7154        and pdl.distribution_amount <> 0
7155        and ppc.payroll_control_id = '||p_payroll_control_id||'
7156        and ppc.business_group_id = '||p_business_group_id||'
7157        and ppc.set_of_books_id = '||p_set_of_books_id||'
7158        and ppsl.daily_rate > '||cap_rec.daily_cap_rate||'
7159        and ppl.dr_cr_flag = '||''''||'D'||''''||'
7160        and ppl.assignment_id between '||p_start_asg_id||' and '||p_end_asg_id||'
7161        and pdl.cap_excess_dist_line_id is null
7162        and pdl.distribution_date between '||''''||cap_rec.start_date||''''||' and '||''''||cap_rec.end_date||''''||'
7163        and nvl(psl.award_id,
7164            nvl(pod.award_id,
7165            nvl(pea.award_id, pdls.award_id))) = awd.award_id
7166        and nvl(psl.project_id,
7167            nvl(pod.project_id,
7168            nvl(pea.project_id,
7169               pdls.project_id)))  = '||cap_rec.project_id;
7170  else  --- sponsor_id is not null
7171      hr_utility.trace('CDL program --> apply_salary_cap capping for sponsor ');
7172    l_sql_str :=
7173    '  select pdl.distribution_line_id,
7174              pdl.distribution_date,
7175              pdl.distribution_amount,
7176              round(nvl(psl.schedule_percent, nvl(pdls.schedule_percent, nvl(pea.percent, (100 * pdl.distribution_amount)/ppsl.daily_rate )))/100 * '||
7177               fnd_number.number_to_canonical(cap_rec.daily_cap_rate)||', '||g_precision||') capped_schedule_amount,
7178              ppl.assignment_id,
7179              null excess_account_id,
7180              null excess_line_id
7181        bulk collect
7182        into  :t_dist_line_id,
7183              :t_dist_date,
7184              :t_dist_amount,
7185              :t_capped_sched_amount,
7186              :t_assignment_id,
7187              :t_excess_account,
7188              :t_excess_line_id
7189        From  psp_schedule_lines        psl,
7190              psp_organization_accounts    pod,
7191              psp_element_type_accounts       pea,
7192              psp_default_labor_schedules     pdls,
7193              psp_payroll_controls            ppc,
7194              psp_payroll_lines               ppl,
7195              psp_payroll_sub_lines           ppsl,
7196              psp_distribution_lines          pdl,
7197              gms_awards_all                   awd
7198        where pdl.status_code = '||''''||'N'||''''||'
7199          AND pdl.payroll_sub_line_id = ppsl.payroll_sub_line_id
7200          AND ppsl.payroll_line_id = ppl.payroll_line_id
7201          AND ppl.payroll_control_id = ppc.payroll_control_id
7202          AND pdl.schedule_line_id = psl.schedule_line_id(+)
7203          AND pdl.default_org_account_id = pod.organization_account_id(+)
7204          AND pdl.element_account_id = pea.element_account_id(+)
7205          AND pdl.org_schedule_id = pdls.org_schedule_id(+)
7206          and pdl.suspense_org_account_id is null
7207          AND pdl.gl_project_flag = '||''''||'P'||''''||'
7208          AND pdl.distribution_amount <> 0
7209          and ppc.payroll_control_id = '||p_payroll_control_id||'
7210          and ppc.business_group_id = '||p_business_group_id||'
7211          and ppc.set_of_books_id = '||p_set_of_books_id||'
7212          and ppsl.daily_rate > '||cap_rec.daily_cap_rate||'
7213          AND ppl.dr_cr_flag = '||''''||'D'||''''||'
7214          and pdl.cap_excess_dist_line_id is null
7215          and pdl.distribution_date between '||''''||cap_rec.start_date||''''||' and '||''''||cap_rec.end_date||''''||'
7216          and ppl.assignment_id between '||p_start_asg_id||' and '||p_end_asg_id||'
7217          and nvl(psl.award_id,
7218              nvl(pod.award_id,
7219              nvl(pea.award_id, pdls.award_id))) = awd.award_id
7220          and not exists
7221            (select 1
7222               from psp_salary_cap_overrides over
7223              where nvl(psl.project_id, nvl(pod.project_id, nvl(pea.project_id, pdls.project_id)))
7224                                = over.project_id
7225                    and over.currency_code = ppc.currency_code
7226                    and over.funding_source_code = '||''''||cap_rec.funding_source_code||''''||'
7227                    and pdl.distribution_date between over.start_date and over.end_date)';
7228     end if;
7229 
7230      hr_utility.trace('CDL program --> After the dist line string is built');
7231     --#fnd_file.put_line(fnd_file.log,'l_sql_str0 ='||l_sql_str);
7232     if psp_salary_cap_custom.g_parent_sponsor_field is null then
7233         -- by default gms.funding_source_id has sponsor.
7234          l_parent_sponsor_sql_str :=
7235             ' AND awd.funding_source_id = '||cap_rec.sponsor_id;
7236      else
7237         /*  l_parent_sponsor_sql_str :=
7238         ' AND (awd.'||rtrim(ltrim(psp_salary_cap_custom.g_parent_sponsor_field))||' = '
7239                    ||cap_rec.sponsor_id || ' or awd.funding_source_id = '||cap_rec.sponsor_id||')'; */
7240           l_parent_sponsor_sql_str :=
7241         ' AND awd.'||rtrim(ltrim(psp_salary_cap_custom.g_parent_sponsor_field))||' = ' ||cap_rec.sponsor_id;
7242      end if;
7243 
7244   l_sql_str := ' begin '|| l_sql_str ||' '
7245                         || l_parent_sponsor_sql_str ||' '
7246                         || l_element_sql_str ||' '||
7247                ' end; ';
7248 
7249 
7250    hr_utility.trace('CDL program --> apply_salary_cap --> l_sql_str=');
7251    hr_utility.trace(substr(l_sql_str,1,200));
7252    hr_utility.trace(substr(l_sql_str,201,200));
7253    hr_utility.trace(substr(l_sql_str,401,200));
7254    hr_utility.trace(substr(l_sql_str,601,200));
7255    hr_utility.trace(substr(l_sql_str,801,200));
7256    hr_utility.trace(substr(l_sql_str,1001,200));
7257    hr_utility.trace(substr(l_sql_str,1201,200));
7258    hr_utility.trace(substr(l_sql_str,1401,200));
7259    hr_utility.trace(substr(l_sql_str,1601,200));
7260    hr_utility.trace(substr(l_sql_str,1801,200));
7261    hr_utility.trace(substr(l_sql_str,2001,200));
7262    hr_utility.trace(substr(l_sql_str,2201,200));
7263    hr_utility.trace(substr(l_sql_str,2401,200));
7264    hr_utility.trace(substr(l_sql_str,2601,200));
7265    hr_utility.trace(substr(l_sql_str,2801,200));
7266             --- added more trace for 5899407
7267    if substr(l_sql_str,3000,200) is not null then
7268      hr_utility.trace(substr(l_sql_str,3000,200));
7269    end if;
7270    if substr(l_sql_str,3201,200) is not null then
7271      hr_utility.trace(substr(l_sql_str,3201,200));
7272    end if;
7273    if substr(l_sql_str,3401,200) is not null then
7274      hr_utility.trace(substr(l_sql_str,3401,200));
7275    end if;
7276 
7277     --#fnd_file.put_line(fnd_file.log,' before exec immediate l_sql_str ='||l_sql_str);
7278   execute immediate l_sql_str
7279   using out t_dist_line_id,
7280         out t_dist_date,
7281         out t_dist_amount,
7282         out t_cap_sched_amount,
7283         out t_assignment_id,
7284         out t_excess_account,
7285         out t_excess_line_id;
7286 
7287   hr_utility.trace('CDL program --> apply_salary_cap --> dist_line_id.count='||t_dist_line_id.count);
7288   for i in 1..t_dist_line_id.count
7289   loop
7290      open org_excess_act(t_assignment_id(i), t_dist_date(i), cap_rec.funding_source_code);  -- introduced sponsor 4744285
7291      fetch org_excess_act into l_account_id;
7292      if org_excess_act%notfound then
7293         open generic_excess_act(t_dist_date(i), g_gen_excess_org_id,
7294 cap_rec.funding_source_code);
7295         fetch generic_excess_act into l_account_id;
7296         if generic_excess_act%notfound then
7297           close org_excess_act;
7298           close generic_excess_act;
7299           hr_utility.trace('CDL program --> apply_salary_cap --> NO_EXCESS_ACCOUNT for asg, date ='||t_assignment_id(i)||','|| t_dist_date(i));
7300 
7301           open get_asg_number(t_assignment_id(i));
7302           fetch get_asg_number into l_person_id, l_asg_number;
7303           close get_asg_number;
7304 
7305           open get_person_name(l_person_id);
7306           fetch get_person_name into l_full_name;
7307           close get_person_name;
7308 
7309           fnd_message.set_name('PSP','PSP_NO_EXCESS_ACCOUNT');
7310           fnd_message.set_token('ENAME',l_full_name);
7311           fnd_message.set_token('ASGNUM',l_asg_number);
7312           fnd_message.set_token('DISTDATE',t_dist_date(i));
7313           fnd_msg_pub.add;
7314           raise no_excess_account;
7315         end if;
7316         close generic_excess_act;
7317         close org_excess_act;
7318      else
7319        close org_excess_act;
7320      end if;
7321      t_excess_account(i) := l_account_id;
7322    end loop;
7323 
7324    for i in 1..t_dist_line_id.count
7325    loop
7326    select psp_distribution_lines_s.nextval
7327      into t_excess_line_id(i)
7328      from dual;
7329    end loop;
7330 
7331    forall i in 1..t_dist_line_id.count
7332    Insert into psp_distribution_lines(distribution_line_id,
7333                                       distribution_date,
7334                                       distribution_amount,
7335                                       effective_date,
7336                                       status_code,
7337                                       payroll_sub_line_id,
7338                                       business_group_id,
7339                                       set_of_books_id,
7340                                       gl_project_flag,
7341                                       cap_excess_glccid,
7342                                       cap_excess_project_id,
7343                                       cap_excess_award_id,
7344                                       cap_excess_task_id,
7345                                       cap_excess_exp_org_id,
7346                                       cap_excess_exp_type,
7347                                       funding_source_code,
7348                                       annual_salary_cap)
7349    select t_excess_line_id(i),
7350           pdl.distribution_date,
7351           pdl.distribution_amount - t_cap_sched_amount(i),
7352           decode(exc.gl_code_combination_id,null,pdl.effective_date,g_gl_effective_date),
7353           pdl.status_code,
7354           pdl.payroll_sub_line_id,
7355           pdl.business_group_id,
7356           pdl.set_of_books_id,
7357           decode(exc.gl_code_combination_id,null,'P','G'),
7358           exc.gl_code_combination_id,
7359           exc.project_id,
7360           exc.award_id,
7361           exc.task_id,
7362           exc.expenditure_organization_id,
7363           exc.expenditure_type,
7364           cap_rec.funding_source_code,
7365           cap_rec.annual_salary_cap
7366      from psp_distribution_lines  pdl,
7367           psp_organization_accounts exc
7368     where pdl.distribution_line_id = t_dist_line_id(i)
7369       and exc.organization_account_id = t_excess_account(i);
7370 
7371    forall i in 1..t_dist_line_id.count
7372    update psp_distribution_lines pdl
7373       set distribution_amount = t_cap_sched_amount(i),
7374           cap_excess_dist_line_id = t_excess_line_id(i),
7375           funding_source_code = cap_rec.funding_source_code,
7376           annual_salary_cap = cap_rec.annual_salary_cap
7377     where distribution_line_id = t_dist_line_id(i);
7378 
7379   hr_utility.trace('CDL Program --> apply_salary_cap -->  Excess array count='||t_excess_line_id.count);
7380 for i in 1..t_excess_line_id.count
7381 loop
7382   open check_excess_poeta(t_excess_line_id(i));
7383   fetch check_excess_poeta into check_excess_poeta_rec;
7384   if check_excess_poeta%found then
7385           hr_utility.trace(
7386           'CDL program --> apply_salary_cap --> Excess account Suspense check for dist line id ='||
7387                            t_excess_line_id(i));
7388 
7389           hr_utility.trace(
7390           'CDL program --> apply_salary_cap --> calling pa_txn_pub  x_project_id=>'||
7391                          check_excess_poeta_rec.cap_excess_project_id||
7392                  ', x_task_id=>'|| check_excess_poeta_rec.cap_excess_task_id||
7393                  ', x_ei_date=>'|| check_excess_poeta_rec.effective_date||
7394                  ', x_expenditure_type	=> '||check_excess_poeta_rec.cap_excess_exp_type||
7395                  ', x_person_id		=> '||check_excess_poeta_rec.person_id||
7396                  ', x_incurred_by_org_id=> '||check_excess_poeta_rec.cap_excess_exp_org_id);
7397                       pa_transactions_pub.validate_transaction(
7398 			x_project_id		=> check_excess_poeta_rec.cap_excess_project_id,
7399 			x_task_id		=> check_excess_poeta_rec.cap_excess_task_id,
7400 			x_ei_date		=> check_excess_poeta_rec.effective_date,
7401 			x_expenditure_type	=> check_excess_poeta_rec.cap_excess_exp_type,
7402 			x_non_labor_resource	=> null,
7403 			x_person_id		=> check_excess_poeta_rec.person_id,
7404 			x_incurred_by_org_id	=> check_excess_poeta_rec.cap_excess_exp_org_id,
7405 			x_calling_module	=> 'PSPLDCDB',
7406 			x_msg_application	=> l_msg_app,
7407 			x_msg_type		=> l_msg_type,
7408 			x_msg_token1		=> l_msg_token1,
7409 			x_msg_token2		=> l_msg_token2,
7410 			x_msg_token3		=> l_msg_token3,
7411 			x_msg_count		=> l_msg_count,
7412 			x_msg_data		=> l_patc_status,
7413 			x_billable_flag		=> l_billable_flag,
7414 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
7415 
7416 
7417           hr_utility.trace(
7418           'CDL program --> apply_salary_cap --> Excess account Suspense l_patc ='||l_patc_status);
7419 	     if check_excess_poeta_rec.cap_excess_award_id is not null and l_patc_status is null
7420 	     then
7421 		 gms_transactions_pub.validate_transaction
7422 				(check_excess_poeta_rec.cap_excess_project_id,
7423 			   	check_excess_poeta_rec.cap_excess_task_id,
7424 				check_excess_poeta_rec.cap_excess_award_id,
7425 			   	check_excess_poeta_rec.cap_excess_exp_type,
7426 				check_excess_poeta_rec.effective_date,
7427 				'PSPLDCDB',
7428 				l_award_status);
7429 
7430                       hr_utility.trace(
7431                       'CDL program --> apply_salary_cap --> Excess account Suspense l_award_status ='||
7432                       l_award_status);
7433 
7434                      if l_award_status IS NOT NULL then
7435                         l_patc_status  := substr(l_award_status,1,50);
7436 	             end if;
7437 	     end if;
7438              IF ( l_patc_status IS NOT NULL ) OR
7439 		(l_award_status is not null ) THEN
7440 
7441                  hr_utility.trace( 'CDL program --> apply_salary_cap --> invoke suspense_acc prarams ='||
7442                          check_excess_poeta_rec.person_id||','||
7443                          check_excess_poeta_rec.payroll_sub_line_id||','||
7444                          check_excess_poeta_rec.assignment_id||','||
7445                          check_excess_poeta_rec.distribution_date||','||
7446                          check_excess_poeta_rec.distribution_amount||','||
7447                          l_patc_status||','||
7448                          check_excess_poeta_rec.effective_date||','||
7449 			 check_excess_poeta_rec.business_group_id||','||
7450 			 check_excess_poeta_rec.set_of_books_id||','||
7451                          check_excess_poeta_rec.distribution_line_id);
7452 
7453                 suspense_account(
7454                          x_proc_executed,
7455                          check_excess_poeta_rec.person_id,
7456                          check_excess_poeta_rec.payroll_sub_line_id,
7457                          check_excess_poeta_rec.assignment_id,
7458                          check_excess_poeta_rec.distribution_date,
7459                          check_excess_poeta_rec.distribution_amount,
7460                          l_patc_status,
7461                          NULL,
7462                          NULL,
7463                          NULL,
7464                          NULL,
7465                          check_excess_poeta_rec.effective_date,
7466                          'I',
7467 			 check_excess_poeta_rec.business_group_id,
7468 			 check_excess_poeta_rec.set_of_books_id,
7469                          check_excess_poeta_rec.distribution_line_id,
7470                          l_return_status);
7471 
7472                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7473                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7474                  END IF;
7475                END IF;
7476    end if;
7477   close check_excess_poeta;
7478 end loop;  ---  apply suspense
7479 
7480 End loop;  --- salary Cap array.
7481  t_dist_line_id  := psp_sql_tab_number15(null);
7482  t_dist_date     := psp_sql_tab_date(null);
7483  t_dist_amount   := psp_sql_tab_number(null);
7484  t_assignment_id  := psp_sql_tab_number15(null);
7485  t_excess_line_id  := psp_sql_tab_number15(null);
7486  t_excess_account  := psp_sql_tab_number15(null);
7487  t_cap_sched_amount := psp_sql_tab_number(null);
7488  t_dist_line_id.delete;
7489  t_dist_date.delete;
7490  t_dist_amount.delete;
7491  t_assignment_id.delete;
7492  t_excess_line_id.delete;
7493  t_excess_account.delete;
7494  t_cap_sched_amount.delete;
7495 
7496 exception
7497 when others then
7498    fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','APPLY_SALARY_CAP');
7499    raise;
7500 End apply_salary_cap;
7501 
7502 procedure excess_account_autopop(p_payroll_control_id in number,
7503                                  p_business_group_id  in number,
7504                                  p_set_of_books_id    in number,
7505                                  p_start_asg_id       in integer,
7506                                  p_end_asg_id         in integer,
7507                                  p_return_status      out nocopy varchar2)  is
7508 
7509 cursor autopop_exc_cur(p_payroll_control_id in number) IS
7510 select pdl.payroll_sub_line_id ,
7511        max(pdl.distribution_date) max_dist_date, ---5505041
7512        max(pdl.effective_date) effective_date,
7513        ppl.person_id,
7514        ppl.assignment_id,
7515        ppl.element_type_id,
7516        pdl.cap_excess_project_id project_id,
7517        pdl.cap_excess_exp_org_id expenditure_organization_id,
7518        pdl.cap_excess_exp_type expenditure_type,
7519        pdl.cap_excess_task_id task_id,
7520        pdl.cap_excess_award_id award_id,
7521        pdl.cap_excess_glccid gl_code_combination_id,
7522        ppl.cost_id,
7523        ppl.payroll_action_type
7524   from psp_distribution_lines pdl,
7525        psp_payroll_lines ppl,
7526        psp_payroll_sub_lines ppsl
7527  where ppl.payroll_control_id = p_payroll_control_id
7528    and ppl.payroll_line_id = ppsl.payroll_line_id
7529    and ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
7530    and pdl.suspense_org_account_id is null
7531    and (pdl.cap_excess_glccid is not null or
7532         pdl.cap_excess_project_id is not null)
7533    and ppl.assignment_id between p_start_asg_id and p_end_Asg_id
7534    and pdl.adj_account_flag is null
7535  group by ppl.cost_id,
7536           ppl.payroll_action_type,
7537           pdl.payroll_sub_line_id,
7538           ppl.person_id,
7539           ppl.assignment_id,
7540           ppl.element_type_id,
7541           pdl.cap_excess_project_id,
7542           pdl.cap_excess_exp_org_id,
7543           pdl.cap_excess_exp_type,
7544           pdl.cap_excess_task_id,
7545           pdl.cap_excess_award_id,
7546           pdl.cap_excess_glccid;
7547 
7548 autopop_exc_rec autopop_exc_cur%ROWTYPE;
7549 
7550 cursor dist_line_exc_cur(p_payroll_sub_line_id in number,
7551                          p_cap_excess_project_id in number,
7552                          p_cap_excess_exp_org_id in number,
7553                          p_cap_excess_exp_type in varchar2,
7554                          p_cap_excess_task_id in number,
7555                          p_cap_excess_award_id in number,
7556                          p_cap_excess_glccid in number) is
7557 
7558 select distribution_line_id,
7559        effective_date,
7560        distribution_amount
7561   from psp_distribution_lines pdl
7562  where payroll_sub_line_id = p_payroll_sub_line_id
7563    and ((   p_cap_excess_glccid is not null
7564        and p_cap_excess_glccid  = pdl.cap_excess_glccid)
7565        or
7566         (p_cap_excess_project_id = pdl.cap_excess_project_id
7567         and p_cap_excess_exp_org_id = pdl.cap_excess_exp_org_id
7568         and p_cap_excess_exp_type = pdl.cap_excess_exp_type
7569         and p_cap_excess_task_id  = pdl.cap_excess_task_id
7570         and nvl(p_cap_excess_award_id,-1)  = nvl(pdl.cap_excess_award_id,-1)))
7571 order by effective_date;
7572 
7573   l_dist_amount                 NUMBER:=0;
7574   l_acct_type                   VARCHAR2(1);
7575   l_auto_pop_status		VARCHAR2(1);
7576   l_new_expenditure_type        VARCHAR2(30);
7577   l_new_gl_code_combination_id  NUMBER(15);
7578   l_auto_status                 VARCHAR2(20) := null;
7579   l_dist_line_id                NUMBER(9);
7580   l_linkage_status              VARCHAR2(50);
7581   l_patc_status                 VARCHAR2(50);
7582   x_proc_executed               VARCHAR2(10) := 'TRUE';
7583   l_billable_flag               VARCHAR2(1);
7584   l_mode                        VARCHAR2(1) := 'I';
7585   l_effective_date              DATE;
7586   l_return_status               VARCHAR2(1);
7587   l_dbg_ctr                     number :=0;
7588   l_msg_count                   NUMBER;
7589   l_msg_app                     VARCHAR2(2000);
7590   l_msg_type                    varchar2(2000);
7591   l_msg_token1                  varchar2(2000);
7592   l_msg_token2                  varchar2(2000);
7593   l_msg_token3                  varchar2(2000);
7594   l_award_status                varchar2(200);
7595   l_prev_cost_id                integer; ---- for 5090002
7596 
7597 begin
7598 
7599 open autopop_exc_cur(p_payroll_control_id);
7600 loop
7601  fetch autopop_exc_cur into autopop_exc_rec;
7602  if autopop_exc_cur%notfound then exit;
7603  end if;
7604  if nvl(autopop_exc_rec.payroll_action_type,'X') = 'L' then --- 5090002
7605    if nvl(l_prev_cost_id, -999) <> autopop_exc_rec.cost_id then
7606        l_prev_cost_id :=  autopop_exc_rec.cost_id;
7607        g_retro_parent_element_id := nvl(get_retro_parent_element_id(autopop_exc_rec.cost_id), autopop_exc_rec.element_type_id);
7608    end if;
7609        autopop_exc_rec.element_type_id := g_retro_parent_element_id;
7610  end if;
7611 
7612 if autopop_exc_rec.gl_code_combination_id is null then
7613     l_acct_type:='E';
7614 else
7615     l_acct_type:='N';
7616 end if;
7617 if nvl(g_use_eff_date,'N') = 'Y' then    --- added if condn for 5505041
7618    null;
7619 else
7620    autopop_exc_rec.effective_date := autopop_exc_rec.max_dist_date;
7621 end if;
7622 
7623 
7624      psp_autopop.main(
7625                     p_acct_type                   => l_acct_type,
7626 		    p_person_id                   => autopop_exc_rec.person_id,
7627 	            p_assignment_id               => autopop_exc_rec.assignment_id,
7628 		    p_element_type_id             => autopop_exc_rec.element_type_id,
7629 		    p_project_id                  => autopop_exc_rec.project_id,
7630 		    p_expenditure_organization_id => autopop_exc_rec.expenditure_organization_id,
7631 		    p_task_id                     => autopop_exc_rec.task_id,
7632 		    p_award_id                    => autopop_exc_rec.award_id,
7633                     p_expenditure_type            => autopop_exc_rec.expenditure_type,
7634 		    p_gl_code_combination_id      => autopop_exc_rec.gl_code_combination_id,
7635 		    p_payroll_date                => autopop_exc_rec.effective_date,
7636 		    p_set_of_books_id             => p_set_of_books_id,
7637                     p_business_group_id           => p_business_group_id,
7638 		    ret_expenditure_type          => l_new_expenditure_type,
7639 		    ret_gl_code_combination_id    => l_new_gl_code_combination_id,
7640 		    retcode 			  => l_auto_pop_status);
7641 
7642      IF (l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
7643        (l_auto_pop_status = FND_API.G_RET_STS_ERROR) THEN
7644        IF l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
7645          if l_acct_type ='N'  then
7646               l_auto_status := 'AUTO_POP_NA_ERROR';
7647          else
7648               l_auto_status :='AUTO_POP_EXP_ERROR';
7649          end if;
7650        ELSIF l_auto_pop_status = FND_API.G_RET_STS_ERROR THEN
7651          l_auto_status := 'AUTO_POP_NO_VALUE';
7652        END IF;
7653 
7654     open dist_line_exc_cur(autopop_exc_rec.payroll_sub_line_id,
7655                            autopop_exc_rec.project_id,
7656                            autopop_exc_rec.expenditure_organization_id,
7657                            autopop_exc_rec.expenditure_type,
7658                            autopop_exc_rec.task_id,
7659                            autopop_exc_rec.award_id,
7660                            autopop_exc_rec.gl_code_combination_id);
7661     loop
7662     fetch dist_line_exc_cur into l_dist_line_id, l_effective_date, l_dist_amount;
7663 
7664       if dist_line_exc_cur%notfound then exit;
7665          else
7666                 suspense_account(
7667                          x_proc_executed,
7668                          autopop_exc_rec.person_id,
7669                          autopop_exc_rec.payroll_sub_line_id,
7670                          autopop_exc_rec.assignment_id,
7671                          l_effective_date,
7672                          l_dist_amount, -- will be distribution_amount
7673                          l_auto_status,
7674                          NULL,
7675                          NULL,
7676                          NULL,
7677                          NULL,
7678                          l_effective_date,
7679                          l_mode,
7680                          p_business_group_id,
7681                          p_set_of_books_id,
7682                          l_dist_line_id,
7683                          l_return_status);
7684        end if;
7685     end loop;
7686    close dist_line_exc_cur;
7687 
7688 else   --- autopop is successful
7689     if l_acct_type= 'E' then
7690     open dist_line_exc_cur(autopop_exc_rec.payroll_sub_line_id,
7691                            autopop_exc_rec.project_id,
7692                            autopop_exc_rec.expenditure_organization_id,
7693                            autopop_exc_rec.expenditure_type,
7694                            autopop_exc_rec.task_id,
7695                            autopop_exc_rec.award_id,
7696                            autopop_exc_rec.gl_code_combination_id);
7697     loop
7698           fetch dist_line_exc_cur into l_dist_line_id , l_effective_date, l_dist_amount;
7699 
7700                if dist_line_exc_cur%notfound then exit;
7701                      else
7702 
7703 	    pa_transactions_pub.validate_transaction(
7704 			x_project_id		=> autopop_exc_rec.project_id,
7705 			x_task_id		=> autopop_exc_rec.task_id,
7706 			x_ei_date		=> l_effective_date,
7707 			x_expenditure_type	=> l_new_expenditure_type,
7708 			x_non_labor_resource	=> null,
7709 			x_person_id		=> autopop_exc_rec.person_id,
7710 			x_incurred_by_org_id	=> autopop_exc_rec.expenditure_organization_id,
7711 			x_calling_module	=> 'PSPLDCDB',
7712 			x_msg_application	=> l_msg_app,
7713 			x_msg_type		=> l_msg_type,
7714 			x_msg_token1		=> l_msg_token1,
7715 			x_msg_token2		=> l_msg_token2,
7716 			x_msg_token3		=> l_msg_token3,
7717 			x_msg_count		=> l_msg_count,
7718 			x_msg_data		=> l_patc_status,
7719 			x_billable_flag		=> l_billable_flag,
7720 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
7721 
7722 
7723 	     if autopop_exc_rec.award_id is not null and l_patc_status is null
7724 	     then
7725 		 gms_transactions_pub.validate_transaction
7726 				(autopop_exc_rec.project_id,
7727 			   	autopop_exc_rec.task_id,
7728 				autopop_exc_rec.award_id,
7729 			   	l_new_expenditure_type,
7730 				l_effective_date, ---p_payroll_start_date, Bug 1874696
7731 				'PSPLDCDB',
7732 				l_award_status);
7733 
7734                 if l_award_status IS NOT NULL then
7735                         l_patc_status  := substr(l_award_status,1,50);
7736 	        end if;
7737 	     end if;
7738              IF ( l_patc_status IS NOT NULL ) OR
7739 		(l_award_status is not null ) THEN
7740 
7741 
7742                 suspense_account(
7743                          x_proc_executed,
7744                          autopop_exc_rec.person_id,
7745                          autopop_exc_rec.payroll_sub_line_id,
7746                          autopop_exc_rec.assignment_id,
7747                          l_effective_date,
7748                          l_dist_amount,
7749                          l_patc_status,
7750                          NULL,
7751                          NULL,
7752                          NULL,
7753                          NULL,
7754                          l_effective_date,
7755                          l_mode,
7756                          p_business_group_id,
7757                          p_set_of_books_id,
7758                          l_dist_line_id,
7759                          l_return_status);
7760 
7761                  IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7762                    RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7763                  END IF;
7764 
7765 else  -- linkage status is successful
7766 
7767  update psp_distribution_lines  set auto_expenditure_type  = l_new_expenditure_type
7768  where distribution_line_id=l_dist_line_id;
7769 
7770    end if;   -- patc status
7771   end if ;  -- dist_line_csr not found;
7772 end loop;
7773 close dist_line_exc_cur;
7774 
7775    else   --  if natural account then
7776 
7777  update psp_distribution_lines  set auto_gl_code_combination_id  = l_new_gl_code_combination_id
7778  where payroll_sub_line_id = autopop_exc_rec.payroll_sub_line_id
7779    and  cap_excess_glccid = autopop_exc_rec.gl_code_combination_id
7780    and suspense_org_account_id is null;
7781 
7782  end if; -- end natural account
7783  end if;  -- end of autopop successful
7784 
7785  end loop;
7786   close autopop_exc_cur;
7787 exception
7788 when others then
7789    fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','EXCESS_ACCOUNT_AUTOPOP');
7790    raise;
7791 end excess_account_autopop;
7792 ------------- introduced for 5080403
7793 procedure generic_account_autopop(p_payroll_control_id in number,
7794                                   p_business_group_id  in number,
7795                                   p_set_of_books_id    in number,
7796                                   p_start_asg_id       in integer,
7797                                   p_end_asg_id         in integer,
7798                                   p_schedule_type      in varchar2)  is
7799   cursor org_default_account_cur is
7800   select pdl.payroll_sub_line_id,
7801          decode(g_use_eff_date, 'Y', max(pdl.effective_date) ,
7802                max(pdl.distribution_date)) effective_date,   --- 5505041
7803          ppl.person_id,
7804          ppl.assignment_id,
7805          ppl.element_type_id,
7806          poa.project_id,
7807          poa.expenditure_organization_id,
7808          poa.expenditure_type,
7809          poa.task_id,
7810          poa.award_id,
7811          poa.gl_code_combination_id,
7812          poa.organization_account_id,
7813          ppl.payroll_action_type,
7814          ppl.cost_id
7815     from psp_distribution_lines pdl,
7816          psp_payroll_lines ppl,
7817          psp_payroll_sub_lines ppsl,
7818          psp_organization_accounts poa
7819    where ppl.payroll_control_id = p_payroll_control_id
7820      and ppl.assignment_id between p_start_asg_id and p_end_asg_id
7821      and ppl.payroll_line_id = ppsl.payroll_line_id
7822      and ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
7823      and pdl.suspense_org_account_id is null
7824      and pdl.default_org_account_id = poa.organization_account_id
7825      and pdl.adj_account_flag is null
7826 group by ppl.cost_id,
7827          ppl.payroll_action_type,
7828          pdl.payroll_Sub_line_id,
7829          ppl.person_id,
7830          ppl.assignment_id,
7831          ppl.element_type_id ,
7832          poa.project_id,
7833          poa.expenditure_organization_id,
7834          poa.expenditure_type,
7835          poa.task_id,
7836          poa.award_id,
7837          poa.gl_code_combination_id,
7838          poa.organization_account_id;
7839 
7840   cursor suspense_account_cur is
7841   select pdl.payroll_sub_line_id,
7842          decode(g_use_eff_date, 'Y', max(pdl.effective_date) ,
7843                max(pdl.distribution_date)) effective_date,   --- 5505041
7844          ppl.person_id,
7845          ppl.assignment_id,
7846          ppl.element_type_id,
7847          poa.project_id,
7848          poa.expenditure_organization_id,
7849          poa.expenditure_type,
7850          poa.task_id,
7851          poa.award_id,
7852          poa.gl_code_combination_id,
7853          poa.organization_account_id,
7854          ppl.payroll_action_type,
7855          ppl.cost_id
7856     from psp_distribution_lines pdl,
7857          psp_payroll_lines ppl,
7858          psp_payroll_sub_lines ppsl,
7859          psp_organization_accounts poa
7860    where ppl.payroll_control_id = p_payroll_control_id
7861      and ppl.assignment_id between p_start_asg_id and p_end_asg_id
7862      and ppl.payroll_line_id = ppsl.payroll_line_id
7863      and ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
7864      and pdl.suspense_org_account_id = poa.organization_account_id
7865      and pdl.adj_account_flag is null
7866 group by ppl.cost_id,
7867          ppl.payroll_action_type,
7868          pdl.payroll_Sub_line_id,
7869          ppl.person_id,
7870          ppl.assignment_id,
7871          ppl.element_type_id ,
7872          poa.project_id,
7873          poa.expenditure_organization_id,
7874          poa.expenditure_type,
7875          poa.task_id,
7876          poa.award_id,
7877          poa.gl_code_combination_id,
7878          poa.organization_account_id;
7879 
7880   cursor global_elem_account_cur is
7881   select pdl.payroll_sub_line_id,
7882          decode(g_use_eff_date, 'Y', max(pdl.effective_date) ,
7883                max(pdl.distribution_date)) effective_date,   --- 5505041
7884          ppl.person_id,
7885          ppl.assignment_id,
7886          ppl.element_type_id,
7887          ele.project_id,
7888          ele.expenditure_organization_id,
7889          ele.expenditure_type,
7890          ele.task_id,
7891          ele.award_id,
7892          ele.gl_code_combination_id,
7893          ele.element_account_id,
7894          ppl.payroll_action_type,
7895          ppl.cost_id
7896     from psp_distribution_lines pdl,
7897          psp_payroll_lines ppl,
7898          psp_payroll_sub_lines ppsl,
7899          psp_element_type_accounts ele
7900    where ppl.payroll_control_id = p_payroll_control_id
7901      and ppl.assignment_id between p_start_asg_id and p_end_asg_id
7902      and ppl.payroll_line_id = ppsl.payroll_line_id
7903      and ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
7904      and pdl.suspense_org_account_id is null
7905      and pdl.element_account_id = ele.element_account_id
7906      and pdl.adj_account_flag is null
7907 group by ppl.cost_id,
7908          ppl.payroll_action_type,
7909          pdl.payroll_Sub_line_id,
7910          ppl.person_id,
7911          ppl.assignment_id,
7912          ppl.element_type_id,
7913          ele.project_id,
7914          ele.expenditure_organization_id,
7915          ele.expenditure_type,
7916          ele.task_id,
7917          ele.award_id,
7918          ele.gl_code_combination_id,
7919          ele.element_account_id;
7920 
7921   l_dist_sql_string             VARCHAR2(4000);
7922   l_dist_amount                 NUMBER:=0;
7923   l_acct_type                   VARCHAR2(1);
7924   l_auto_pop_status		VARCHAR2(1);
7925   l_new_expenditure_type        VARCHAR2(30);
7926   l_new_gl_code_combination_id  NUMBER(15);
7927   l_auto_status                 VARCHAR2(20) := null;
7928   l_dist_line_id                NUMBER(9);
7929   l_linkage_status              VARCHAR2(50);
7930   l_patc_status                 VARCHAR2(50);
7931   x_proc_executed               VARCHAR2(10) := 'TRUE';
7932   l_billable_flag               VARCHAR2(1);
7933   l_mode                        VARCHAR2(1) := 'I';
7934   l_effective_date              DATE;
7935   l_return_status               VARCHAR2(1);
7936   l_dbg_ctr                     number :=0;
7937   l_msg_count                   NUMBER;
7938   l_msg_app                     VARCHAR2(2000);
7939   l_msg_type                    varchar2(2000);
7940   l_msg_token1                  varchar2(2000);
7941   l_msg_token2                  varchar2(2000);
7942   l_msg_token3                  varchar2(2000);
7943   l_award_status                varchar2(200);
7944   l_organization_name           varchar2(400);
7945   l_employee_name               varchar2(400);
7946   l_asg_num                     varchar2(400);
7947   l_account                     varchar2(800);
7948   l_prev_cost_id                integer;
7949 
7950 
7951   type ref_cur_type is ref cursor;
7952   dist_line_cur ref_cur_type;
7953   SUSPENSE_AUTOPOP_FAIL exception;
7954   cursor get_person_details (p_person_id in number,
7955                              p_assignment_id in number,
7956                              p_eff_date in date) is
7957    select ppf.full_name,
7958           paf.assignment_number,
7959           hou.name
7960      from per_all_people_f ppf,
7961           per_all_assignments_f paf,
7962           hr_all_organization_units hou
7963     where ppf.person_id = p_person_id
7964       and p_eff_date between ppf.effective_start_date and ppf.effective_end_date
7965       and paf.assignment_type = 'E'
7966       and paf.assignment_id = p_assignment_id
7967       and p_eff_date between paf.effective_start_date and paf.effective_end_date
7968       and paf.organization_id = hou.organization_id;
7969 begin
7970 hr_utility.trace('Entering generic_account_autopop');
7971 
7972 if p_schedule_type = 'GLOBAL_ELEMENT' then
7973   open  global_elem_account_cur;
7974   fetch global_elem_account_cur bulk collect into t_payroll_sub_line_id,
7975                                                   t_effective_date     ,
7976                                                   t_person_id          ,
7977                                                   t_assignment_id      ,
7978                                                   t_element_type_id    ,
7979                                                   t_project_id         ,
7980                                                   t_expenditure_organization_id,
7981                                                   t_expenditure_type         ,
7982                                                   t_task_id                  ,
7983                                                   t_award_id                 ,
7984                                                   t_gl_code_combination_id   ,
7985                                                   t_account_id,
7986                                                   t_payroll_action_type,
7987                                                   t_cost_id;
7988 
7989   close global_elem_account_cur;
7990 elsif p_schedule_type = 'DEFAULT_ACCOUNT' then
7991   open  org_default_account_cur;
7992   fetch org_default_account_cur bulk collect into t_payroll_sub_line_id,
7993                                                   t_effective_date     ,
7994                                                   t_person_id          ,
7995                                                   t_assignment_id      ,
7996                                                   t_element_type_id    ,
7997                                                   t_project_id         ,
7998                                                   t_expenditure_organization_id,
7999                                                   t_expenditure_type         ,
8000                                                   t_task_id                  ,
8001                                                   t_award_id                 ,
8002                                                   t_gl_code_combination_id   ,
8003                                                   t_account_id,
8004                                                   t_payroll_action_type,
8005                                                   t_cost_id;
8006 
8007   close org_default_account_cur;
8008 else
8009   ---fnd_file.put_line(fnd_file.log, 'before suspense cursor');
8010   open  suspense_account_cur;
8011   fetch suspense_account_cur bulk collect into t_payroll_sub_line_id,
8012                                                t_effective_date     ,
8013                                                t_person_id          ,
8014                                                t_assignment_id      ,
8015                                                t_element_type_id    ,
8016                                                t_project_id         ,
8017                                                t_expenditure_organization_id,
8018                                                t_expenditure_type         ,
8019                                                t_task_id                  ,
8020                                                t_award_id                 ,
8021                                                t_gl_code_combination_id   ,
8022                                                t_account_id,
8023                                                   t_payroll_action_type,
8024                                                   t_cost_id;
8025 
8026   close suspense_account_cur;
8027 end if;
8028 if t_payroll_sub_line_id.count > 0 then
8029    if p_schedule_type = 'DEFAULT_ACCOUNT' then
8030      l_dist_sql_string :=
8031            'select pdl.distribution_line_id,
8032                    pdl.effective_date,
8033                    pdl.distribution_amount
8034               from psp_distribution_lines pdl
8035              where pdl.payroll_sub_line_id = :1
8036                and pdl.default_org_account_id = :2
8037                and pdl.suspense_org_account_id is null';
8038    elsif p_schedule_type = 'GLOBAL_ELEMENT' then
8039       l_dist_sql_string :=
8040               'select pdl.distribution_line_id,
8041                       pdl.effective_date,
8042                       pdl.distribution_amount
8043                  from psp_distribution_lines pdl
8044                 where pdl.payroll_sub_line_id = :1
8045                   and pdl.element_account_id = :2
8046                   and pdl.suspense_org_account_id is null';
8047    else
8048       l_dist_sql_string :=
8049               'select pdl.distribution_line_id,
8050                       pdl.effective_date,
8051                       pdl.distribution_amount
8052                  from psp_distribution_lines pdl
8053                 where pdl.payroll_sub_line_id = :1
8054                   and pdl.suspense_org_account_id = :2';
8055   ---#fnd_file.put_line(fnd_file.log, 'Suspense sql string l_dist_sql_string='||l_dist_sql_string||', count='||t_payroll_sub_line_id.count);
8056    end if;
8057 end if;
8058    for i in 1..t_payroll_sub_line_id.count
8059    loop
8060       if t_gl_code_combination_id(i) is null then
8061           l_acct_type:='E';
8062       else
8063           l_acct_type:='N';
8064       end if;
8065       if nvl(t_payroll_action_type(i),'X') = 'L' then
8066         if nvl(l_prev_cost_id, -999) <> t_cost_id(i) then
8067             l_prev_cost_id :=  t_cost_id(i);
8068             g_retro_parent_element_id := nvl(get_retro_parent_element_id(t_cost_id(i)), t_element_type_id(i));
8069         end if;
8070             t_element_type_id(i) := g_retro_parent_element_id;
8071       end if;
8072   ---fnd_file.put_line(fnd_file.log, 'Generic_account_autopop.. Suspense.. before autopop call');
8073       psp_autopop.main(
8074                     p_acct_type                   => l_acct_type,
8075 		    p_person_id                   => t_person_id(i),
8076 	            p_assignment_id               => t_assignment_id(i),
8077 		    p_element_type_id             => t_element_type_id(i),
8078 		    p_project_id                  => t_project_id(i),
8079 		    p_expenditure_organization_id => t_expenditure_organization_id(i),
8080 		    p_task_id                     => t_task_id(i),
8081 		    p_award_id                    => t_award_id(i),
8082                     p_expenditure_type            => t_expenditure_type(i),
8083 		    p_gl_code_combination_id      => t_gl_code_combination_id(i),
8084 		    p_payroll_date                => t_effective_date(i),
8085 		    p_set_of_books_id             => p_set_of_books_id,
8086                     p_business_group_id           => p_business_group_id,
8087 		    ret_expenditure_type          => l_new_expenditure_type,
8088 		    ret_gl_code_combination_id    => l_new_gl_code_combination_id,
8089 		    retcode 			  => l_auto_pop_status);
8090   ---fnd_file.put_line(fnd_file.log, 'Generic_account_autopop.. Suspense.. After autopop call');
8091 
8092     IF (l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
8093         (l_auto_pop_status = FND_API.G_RET_STS_ERROR) THEN
8094        IF l_auto_pop_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
8095          if l_acct_type ='N'  then
8096               l_auto_status := 'AUTO_POP_NA_ERROR';
8097          else
8098               l_auto_status :='AUTO_POP_EXP_ERROR';
8099          end if;
8100        ELSIF l_auto_pop_status = FND_API.G_RET_STS_ERROR THEN
8101          l_auto_status := 'AUTO_POP_NO_VALUE';
8102        END IF;
8103 
8104       ----fnd_file.put_line(fnd_file.log,'error in  autopop main in generic_account_autopop code='||l_auto_status||' sched type='||p_Schedule_type);
8105       open dist_line_cur for l_dist_sql_string using t_payroll_sub_line_id(i), t_account_id(i);
8106       loop
8107          fetch dist_line_cur into l_dist_line_id, l_effective_date, l_dist_amount;
8108          if dist_line_cur%notfound then exit;
8109          else
8110             if p_schedule_type = 'SUSPENSE' then
8111                    open get_person_details(t_person_id(i), t_assignment_id(i), l_effective_date);
8112                    fetch get_person_details into l_employee_name, l_asg_num, l_organization_name;
8113                    close get_person_details;
8114                    hr_utility.trace('generic_account_autopop gl_ccid = '||t_gl_code_combination_id(i));
8115                    psp_enc_crt_xml.p_set_of_books_id := p_set_of_books_id;
8116                    psp_enc_crt_xml.p_business_group_id := p_business_group_id;
8117                    l_account :=
8118                      psp_enc_crt_xml.cf_charging_instformula(t_gl_code_combination_id(i),
8119                                                              t_project_id(i),
8120                                                              t_task_id(i),
8121                                                              t_award_id(i),
8122                                                              t_expenditure_organization_id(i),
8123                                                              t_expenditure_type(i));
8124                    fnd_message.set_name('PSP','PSP_SUSPENSE_AUTOPOP_FAIL');
8125                    fnd_message.set_token('ORG_NAME',l_organization_name);
8126                    fnd_message.set_token('EMPLOYEE_NAME',l_employee_name);
8127                    fnd_message.set_token('ASG_NUM',l_asg_num);
8128                    fnd_message.set_token('CHARGING_ACCOUNT',l_account);
8129                    fnd_message.set_token('AUTOPOP_ERROR',l_auto_status);
8130                    fnd_message.set_token('EFF_DATE',l_effective_date);
8131                    fnd_msg_pub.add;
8132                    raise suspense_autopop_fail;
8133             else
8134                 suspense_account(
8135                          x_proc_executed,
8136                          t_person_id(i),
8137                          t_payroll_sub_line_id(i),
8138                          t_assignment_id(i),
8139                          l_effective_date,
8140                          l_dist_amount, -- will be distribution_amount
8141                          l_auto_status,
8142                          NULL,
8143                          NULL,
8144                          NULL,
8145                          NULL,
8146                          l_effective_date,
8147                          l_mode,
8148                          p_business_group_id,
8149                          p_set_of_books_id,
8150                          l_dist_line_id,
8151                          l_return_status);
8152                        IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8153                            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8154                        END IF;
8155             end if;
8156        end if;
8157       end loop;
8158       close dist_line_cur;
8159 
8160    else   --- autopop is successful
8161       ----fnd_file.put_line(fnd_file.log,'SUCCESS in  autopop main in generic_account_autopop code='||l_auto_status);
8162     if l_acct_type= 'E' then
8163       open dist_line_cur for l_dist_sql_string using t_payroll_sub_line_id(i), t_account_id(i);
8164       loop
8165          fetch dist_line_cur into l_dist_line_id, l_effective_date, l_dist_amount;
8166          if dist_line_cur%notfound then exit;
8167          else
8168 
8169 	    pa_transactions_pub.validate_transaction(
8170 			x_project_id		=> t_project_id(i),
8171 			x_task_id		=> t_task_id(i),
8172 			x_ei_date		=> l_effective_date,
8173 			x_expenditure_type	=> l_new_expenditure_type,
8174 			x_non_labor_resource	=> null,
8175 			x_person_id		=> t_person_id(i),
8176 			x_incurred_by_org_id	=> t_expenditure_organization_id(i),
8177 			x_calling_module	=> 'PSPLDCDB',
8178 			x_msg_application	=> l_msg_app,
8179 			x_msg_type		=> l_msg_type,
8180 			x_msg_token1		=> l_msg_token1,
8181 			x_msg_token2		=> l_msg_token2,
8182 			x_msg_token3		=> l_msg_token3,
8183 			x_msg_count		=> l_msg_count,
8184 			x_msg_data		=> l_patc_status,
8185 			x_billable_flag		=> l_billable_flag,
8186 			p_sys_link_function     => 'ST');            --Bug 5639589: Added parameter
8187 
8188 
8189 	     if t_award_id(i) is not null and l_patc_status is null
8190 	     then
8191 		 gms_transactions_pub.validate_transaction
8192 				(t_project_id(i),
8193 			   	t_task_id(i),
8194 				t_award_id(i),
8195 			   	l_new_expenditure_type,
8196 				l_effective_date, ---p_payroll_start_date, Bug 1874696
8197 				'PSPLDCDB',
8198 				l_award_status);
8199 
8200                 if l_award_status IS NOT NULL then
8201                         l_patc_status  := substr(l_award_status,1,50);
8202 	        end if;
8203 	     end if;
8204              IF ( l_patc_status IS NOT NULL ) OR
8205 		(l_award_status is not null ) THEN
8206                    open get_person_details(t_person_id(i), t_assignment_id(i), l_effective_date);
8207                    fetch get_person_details into l_employee_name, l_asg_num, l_organization_name;
8208                    close get_person_details;
8209                    ---fnd_file.put_line(fnd_file.log,'failure in _autopop code='||l_auto_status||' person_id, asgid, edate='||
8210                         ---t_person_id(i)||' ,  '|| t_assignment_id(i)||' ,  '|| l_effective_date);
8211 
8212                 if p_schedule_type = 'SUSPENSE' then
8213                     fnd_message.set_name('PSP','PSP_LD_SUSPENSE_AC_INVALID');
8214                     fnd_message.set_token('ORG_NAME',l_organization_name);
8215                     fnd_message.set_token('PATC_STATUS',l_patc_status);
8216                     fnd_message.set_token('EMPLOYEE_NAME',l_employee_name); --Bug 2514611
8217                     fnd_msg_pub.add;
8218                     raise suspense_autopop_fail;
8219                 else
8220                     update psp_distribution_lines
8221                        set auto_expenditure_type  = l_new_expenditure_type
8222                      where distribution_line_id=l_dist_line_id;
8223                      suspense_account(
8224                            x_proc_executed,
8225                            t_person_id(i),
8226                            t_payroll_sub_line_id(i),
8227                            t_assignment_id(i),
8228                            l_effective_date,
8229                            l_dist_amount,
8230                            l_patc_status,
8231                            NULL,
8232                            NULL,
8233                            NULL,
8234                            NULL,
8235                            l_effective_date,
8236                            l_mode,
8237                            p_business_group_id,
8238                            p_set_of_books_id,
8239                            l_dist_line_id,
8240                            l_return_status);
8241 
8242                        IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8243                            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8244                        END IF;
8245                   end if;
8246              else  -- linkage status is successful
8247                 if p_schedule_type = 'SUSPENSE' then
8248                  update psp_distribution_lines
8249                     set suspense_auto_exp_type  = l_new_expenditure_type
8250                   where distribution_line_id=l_dist_line_id;
8251                 else
8252                  update psp_distribution_lines
8253                     set auto_expenditure_type  = l_new_expenditure_type
8254                   where distribution_line_id=l_dist_line_id;
8255                  end if;
8256 
8257              end if;   -- patc status
8258         end if ;  -- dist_line_csr not found;
8259       end loop;
8260       close dist_line_cur;
8261 
8262     else   --  if natural account then
8263       ----fnd_file.put_line(fnd_file.log,'SUCCESS-NA in  autopop main in generic_account_autopop code='||l_auto_status);
8264       if p_schedule_type = 'SUSPENSE' then
8265           update psp_distribution_lines
8266              set suspense_auto_glccid  = l_new_gl_code_combination_id
8267           where payroll_sub_line_id = t_payroll_sub_line_id(i)
8268             and suspense_org_account_id = t_account_id(i);
8269        elsif p_schedule_type = 'GLOBAL_ELEMENT' then
8270           update psp_distribution_lines
8271              set auto_gl_code_combination_id  = l_new_gl_code_combination_id
8272           where payroll_sub_line_id = t_payroll_sub_line_id(i)
8273             and element_account_id = t_account_id(i)
8274             and suspense_org_account_id is null;
8275        else
8276           update psp_distribution_lines
8277              set auto_gl_code_combination_id  = l_new_gl_code_combination_id
8278           where payroll_sub_line_id = t_payroll_sub_line_id(i)
8279             and default_org_account_id= t_account_id(i)
8280             and suspense_org_account_id is null;
8281        end if;
8282 
8283      end if; -- end natural account
8284  end if;  -- end of autopop successful
8285  end loop;
8286  t_payroll_sub_line_id.delete;
8287  t_effective_date.delete;
8288  t_person_id.delete;
8289  t_assignment_id.delete;
8290  t_element_type_id.delete;
8291  t_project_id.delete;
8292  t_expenditure_organization_id.delete;
8293  t_expenditure_type.delete;
8294  t_task_id.delete;
8295  t_award_id.delete;
8296  t_gl_code_combination_id.delete;
8297  t_account_id.delete;
8298  t_payroll_action_type.delete;
8299  t_cost_id.delete;
8300                    ---fnd_file.put_line(fnd_file.log,'Xiting generic_account_autop');
8301 exception
8302    when suspense_autopop_fail then
8303       t_payroll_sub_line_id.delete;
8304       t_effective_date.delete;
8305       t_person_id.delete;
8306       t_assignment_id.delete;
8307       t_element_type_id.delete;
8308       t_project_id.delete;
8309       t_expenditure_organization_id.delete;
8310       t_expenditure_type.delete;
8311       t_task_id.delete;
8312       t_award_id.delete;
8313       t_gl_code_combination_id.delete;
8314       t_account_id.delete;
8315       close dist_line_cur;
8316       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','GENERIC_ACCOUNT_AUTOPOP');
8317       raise;
8318    when others then
8319       if dist_line_cur%isopen then
8320         close dist_line_cur;
8321       end if;
8322       if t_payroll_sub_line_id.count > 0 then
8323          t_payroll_sub_line_id.delete;
8324          t_effective_date.delete;
8325          t_person_id.delete;
8326          t_assignment_id.delete;
8327          t_element_type_id.delete;
8328          t_project_id.delete;
8329          t_expenditure_organization_id.delete;
8330          t_expenditure_type.delete;
8331          t_task_id.delete;
8332          t_award_id.delete;
8333          t_gl_code_combination_id.delete;
8334          t_account_id.delete;
8335       end if;
8336       fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','GENERIC_ACCOUNT_AUTOPOP:'||p_schedule_type);
8337       raise;
8338 end generic_account_autopop;
8339 ------------------------------------------
8340 
8341    function get_parameter(name           in varchar2,
8342                           parameter_list in varchar2) return varchar2
8343    is
8344      start_ptr number;
8345      end_ptr   number;
8346      token_val pay_payroll_actions.legislative_parameters%type;
8347      par_value pay_payroll_actions.legislative_parameters%type;
8348    begin
8349         token_val := name||'=';
8350          ---dbms_output.put_line('CDL--> Get Param --> Token, Paramlist='||token_val||','||parameter_list);
8351          ---dbms_output.put_line('Paramlist='||parameter_list);
8352         start_ptr := instr(parameter_list, token_val) + length(token_val);
8353         if token_val in ('BATCH_NAME=','SOURCE_CODE=') then
8354          ---dbms_output.put_line('CDL--> Get Param --> BATCH_NAME start_ptr='||start_ptr);
8355           if start_ptr + 30 > length(parameter_list) then
8356               end_ptr := 0;
8357           else
8358               end_ptr := start_ptr + 30;
8359           end if;
8360         else
8361            end_ptr := instr(parameter_list, ' ',start_ptr);
8362         end if;
8363         if end_ptr = 0 then
8364            end_ptr := length(parameter_list)+1;
8365         end if;
8366          ---dbms_output.put_line('CDL-->Get param stptr, endptr = '||start_ptr||','|| end_ptr);
8367         if instr(parameter_list, token_val) = 0 then
8368           par_value := NULL;
8369         else
8370           par_value := trim(substr(parameter_list, start_ptr, end_ptr -
8371 start_ptr));
8372         end if;
8373         return par_value;
8374    end get_parameter;
8375 
8376 procedure cdl_init(p_payroll_action_id in number) IS
8377  --- introduced for 5080403
8378   cursor autopop_config_cur is
8379   select pcv_information1 global_element_autopop,
8380          pcv_information2 element_type_autopop,
8381          pcv_information3 element_class_autopop,
8382          pcv_information4 assignment_autopop,
8383          pcv_information5 default_schedule_autopop,
8384          pcv_information6 default_account_autopop,
8385          pcv_information7 suspense_account,
8386          pcv_information10 excess_account
8387     from pqp_configuration_values
8388    where pcv_information_category = 'PSP_ENABLE_AUTOPOPULATION'
8389      and legislation_code is null
8390      and nvl(business_group_id, g_business_group_id) = g_business_group_id;
8391 
8392 begin
8393     ---hr_utility.trace_on('Y','CDL-1');
8394      select get_parameter('SOURCE_TYPE',ppa.legislative_parameters) ,
8395           get_parameter('SOURCE_CODE',ppa.legislative_parameters)  ,
8396           get_parameter('TIME_PERIOD_ID',ppa.legislative_parameters),
8397           get_parameter('BATCH_NAME',ppa.legislative_parameters),
8398           get_parameter('PAYROLL_ID',ppa.legislative_parameters)
8399      into g_source_type,
8400           g_source_code,
8401           g_time_period_id,
8402           g_batch_name,
8403           g_payroll_id
8404      from pay_payroll_actions ppa
8405     where ppa.payroll_action_id = p_payroll_action_id;
8406 
8407     if g_time_period_id is not null and g_payroll_id is null then
8408     select payroll_id
8409       into g_payroll_id
8410      from per_time_periods
8411     where time_period_id = g_time_period_id;
8412     end if;
8413 
8414  g_set_of_books_id :=  FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
8415  g_business_group_id  := FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID');
8416     --#fnd_file.put_line(fnd_file.log,'########CDL_INIT#######PACTID, g_business_group_id,  g_set_of_books_id ,g_source_type, g_time_period_id, g_batch_name=');
8417     --#fnd_file.put_line(fnd_file.log, p_payroll_action_id||','|| g_business_group_id||','||  g_set_of_books_id ||','||g_source_type||','|| psp_labor_dist.g_time_period_id||','|| g_batch_name);
8418 
8419 -- moved from archive part .. 4744285, commented for 5080403 and introduced below cursor
8420   ---g_auto_population := FND_PROFILE.value('PSP_USE_AUTO_POPULATION');
8421    open autopop_config_cur;
8422    fetch autopop_config_cur into g_global_element_autopop,
8423                                  g_asg_element_autopop,
8424                                  g_asg_ele_group_autopop,
8425                                  g_asg_autopop,
8426                                  g_org_schedule_autopop,
8427                                  g_default_account_autopop,
8428                                  g_suspense_account_autopop,
8429                                  g_excess_account_autopop;
8430    close autopop_config_cur;
8431 
8432   --dbms_output.put_line('value of profile is '||g_auto_population);
8433 
8434   g_use_eff_date := FND_PROFILE.VALUE('PSP_USE_NON_ORACLE_EFFECTIVE_DATE'); /* bug 1874696 */
8435 
8436    g_dff_grouping_option := psp_general.get_act_dff_grouping_option(g_business_group_id);	-- Introduced for bug fix 2908859
8437 
8438    g_salary_cap_option := psp_general.get_configuration_option_value(g_business_group_id, 'PSP_ENABLE_SALARY_CAP');
8439    hr_utility.trace('CDL procedure: setting g_cap_element_set_id');
8440    if g_salary_cap_option = 'Y' then
8441      g_cap_element_set_id  := psp_general.get_configuration_option_value(g_business_group_id, 'PSP_CAP_ELEMENT_SET_ID');
8442      g_gen_excess_org_id :=   -- 4744285
8443             psp_general.get_configuration_option_value(g_business_group_id, 'PSP_GENERIC_EXCESS_ACCT_ORG');
8444    end if;
8445 END;
8446 
8447 procedure range_code (pactid IN NUMBER, sqlstr out nocopy varchar2) is
8448 
8449 l_count integer;
8450 l_begin_dist_date date;
8451 l_end_dist_date date;
8452 l_sponsor_code varchar2(10);
8453 l_sponsor_name varchar2(200);
8454 l_sponsor_id   integer;
8455 
8456 cursor check_generic_excess(p_date in date,
8457                             p_excess_org_id in number,
8458                             p_business_group_id in number) is
8459 select count(*)
8460   from psp_organization_accounts
8461  where account_type_code = 'ORG_EXCESS'
8462    and p_date between trunc(start_date_active) and trunc(end_date_active)
8463    and organization_id = p_excess_org_id
8464    and business_group_id = p_business_group_id ;
8465 
8466 cursor get_min_max_dist_date is
8467                 select min(ptp.start_date), max(ptp.end_date)
8468                   from psp_payroll_controls ppc,
8469                        per_time_periods ptp
8470                  where  ppc.source_type = g_source_type
8471                    and  ppc.payroll_source_code = g_source_code
8472                    and (ppc.batch_name = nvl(g_batch_name, ppc.batch_name)
8473                        or (ppc.batch_name is null and g_batch_name is null))
8474                    and  ppc.time_period_id = nvl(g_time_period_id, ppc.time_period_id)
8475                    and  ppc.payroll_id = nvl(g_payroll_id, ppc.payroll_id)
8476                    and  ppc.cdl_payroll_action_id = pactid
8477                    and  ppc.status_code = 'N'
8478                    and  ppc.dist_dr_amount is null
8479                    and  ppc.dist_cr_amount is null
8480                    and  ppc.business_group_id = g_business_group_id
8481                    and  ppc.set_of_books_id   = g_set_of_books_id
8482                    and  ptp.time_period_id = ppc.time_period_id;
8483 
8484 cursor get_sponsor_codes(p_begin_date date) is
8485 select distinct lookup_code, meaning
8486   from fnd_lookup_values
8487  where lookup_type = 'PSP_SPONSOR_NAMES'
8488    and language = 'US'
8489    and p_begin_date between start_date_active and  nvl(end_date_active, fnd_date.canonical_to_date('4000/01/31'))
8490    and enabled_flag = 'Y';
8491 
8492 cursor check_salary_cap_exists(p_sponsor_code in varchar2,
8493                                        p_date in date) is
8494 select 1
8495   from psp_salary_caps
8496  where funding_source_code = p_sponsor_code
8497    and p_date between start_date and end_date;
8498 
8499  l_error_flag varchar2(1);
8500  l_gen_excess_org_id number;   -- 4744285
8501 
8502  cursor get_control_ids is
8503  select payroll_control_id
8504    from psp_payroll_controls ppc
8505   where ppc.source_type = g_source_type
8506     and  ppc.payroll_source_code = g_source_code
8507     and (ppc.batch_name = nvl(g_batch_name, ppc.batch_name)
8508      or (ppc.batch_name is null and g_batch_name is null))
8509     and  ppc.time_period_id = nvl(g_time_period_id, ppc.time_period_id)
8510     and  ppc.payroll_id = nvl(g_payroll_id, ppc.payroll_id)
8511     and  ppc.cdl_payroll_action_id is null
8512     and  ppc.status_code = 'N'
8513     and  ppc.dist_dr_amount is null
8514     and  ppc.dist_cr_amount is null
8515     and  ppc.business_group_id = g_business_group_id
8516     and  ppc.parent_payroll_control_id is null
8517     and  ppc.set_of_books_id   = g_set_of_books_id;
8518 
8519  l_payroll_control_id integer;
8520 
8521 begin
8522    --- hr_utility.trace_on('Y','CDL-2');
8523      select get_parameter('SOURCE_TYPE',ppa.legislative_parameters) ,
8524           get_parameter('SOURCE_CODE',ppa.legislative_parameters)  ,
8525           get_parameter('TIME_PERIOD_ID',ppa.legislative_parameters),
8526           get_parameter('BATCH_NAME',ppa.legislative_parameters),
8527           get_parameter('PAYROLL_ID',ppa.legislative_parameters)
8528      into g_source_type,
8529           g_source_code,
8530           g_time_period_id,
8531           g_batch_name,
8532           g_payroll_id
8533      from pay_payroll_actions ppa
8534     where ppa.payroll_action_id = pactid;
8535 
8536  g_business_group_id  := FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID');
8537  g_set_of_books_id :=  FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
8538 
8539 
8540     --#fnd_file.put_line(fnd_file.log,'########ENTERED RangeCode#######pactid, g_source_code='||pactid||','|| g_source_code);
8541  open get_control_ids;
8542  loop
8543     fetch get_control_ids into l_payroll_control_id;
8544     if get_control_ids%notfound then
8545            close get_control_ids;
8546            exit;
8547      end if;
8548      update psp_payroll_controls ppc
8549         set ppc.cdl_payroll_action_id = pactid
8550       where payroll_control_id = l_payroll_control_id
8551          or parent_payroll_control_id = l_payroll_control_id;
8552  end loop;
8553 
8554     if sql%rowcount > 0 then
8555 
8556  if psp_general.get_configuration_option_value(g_business_group_id, 'PSP_ENABLE_SALARY_CAP') = 'Y' then
8557    l_error_flag := 'N';
8558 
8559    hr_utility.trace('CDL process --> range_code --> source_type, source_code, time_period_id, batch_name = '||
8560       g_source_code||','||g_source_type||','||g_time_period_id||','||g_batch_name);
8561 
8562    open get_min_max_dist_date;
8563    fetch get_min_max_dist_date into l_begin_dist_date, l_end_dist_date;
8564    close get_min_max_dist_date;
8565 
8566    --fnd_file.put_line(fnd_file.log,'  l_begin_dist_date = '||l_begin_dist_date||' , l_end_dist_date='||l_end_dist_date);
8567    hr_utility.trace('CDL process --> range_code --> l_begin_dist_date = '||l_begin_dist_date);
8568 
8569    l_gen_excess_org_id :=   -- 4744285
8570    psp_general.get_configuration_option_value(g_business_group_id,
8571                                               'PSP_GENERIC_EXCESS_ACCT_ORG');
8572    if l_gen_excess_org_id is null then
8573       fnd_message.set_name('PSP','PSP_SET_GEN_EXCESS_ORG');
8574       fnd_msg_pub.add;
8575       l_error_flag := 'Y';
8576    else
8577 
8578       open check_generic_excess(l_begin_dist_date, l_gen_excess_org_id, g_business_group_id);
8579       fetch check_generic_excess into l_count;
8580       close check_generic_excess;
8581 
8582       if l_count = 0 then
8583          fnd_message.set_name('PSP', 'PSP_SET_GEN_EXCESS_ACNT');
8584          fnd_message.set_token('BDATE',l_begin_dist_date);
8585          fnd_msg_pub.add;
8586          l_error_flag := 'Y';
8587       else
8588          open check_generic_excess(l_end_dist_date, l_gen_excess_org_id, g_business_group_id);
8589          fetch check_generic_excess into l_count;
8590          close check_generic_excess;
8591 
8592          if l_count = 0 then
8593             fnd_message.set_name('PSP', 'PSP_SET_GEN_EXCESS_ACNT');
8594             fnd_message.set_token('BDATE',l_end_dist_date);
8595             fnd_msg_pub.add;
8596             l_error_flag := 'Y';
8597          end if;
8598       end if;
8599     end if;
8600 
8601    open get_sponsor_codes(l_begin_dist_date);
8602    loop
8603 
8604        fetch get_sponsor_codes into l_sponsor_code, l_sponsor_name;
8605 
8606       if get_sponsor_codes%notfound then
8607          close get_sponsor_codes;
8608          exit;
8609       end if;
8610 
8611        -- replaced the cursor get_map_sponsor, with following function call
8612        l_sponsor_id := null;
8613        l_sponsor_id := psp_general.get_configuration_option_value(g_business_group_id,
8614                                        'PSP_SET_SPONSORS_FOR_CAPPING', l_sponsor_code);
8615       if l_sponsor_id is null then
8616          l_error_flag := 'Y';
8617          fnd_message.set_name('PSP', 'PSP_MAP_SAL_CAP_SPONSOR');
8618          fnd_message.set_token('SPONSOR_NAME', l_sponsor_name);
8619          fnd_msg_pub.add;
8620       end if;
8621 
8622       open check_salary_cap_exists(l_sponsor_code, l_begin_dist_date);
8623       fetch check_salary_cap_exists into l_count;
8624       if check_salary_cap_exists%notfound then
8625          l_error_flag := 'Y';
8626          fnd_message.set_name('PSP', 'PSP_NO_SALARY_CAP_DATA');
8627          fnd_message.set_token('SPONSOR_NAME', l_sponsor_name);
8628          fnd_message.set_token('XDATE', l_begin_dist_date);
8629          fnd_message.set_token('BDATE', l_begin_dist_date);
8630          fnd_message.set_token('EDATE', l_end_dist_date);
8631          fnd_msg_pub.add;
8632          close check_salary_cap_exists;
8633       else
8634          close check_salary_cap_exists;
8635          open check_salary_cap_exists(l_sponsor_code, l_end_dist_date);
8636          fetch check_salary_cap_exists into l_count;
8637          if check_salary_cap_exists%notfound then
8638             l_error_flag := 'Y';
8639             fnd_message.set_name('PSP', 'PSP_NO_SALARY_CAP_DATA');
8640             fnd_message.set_token('SPONSOR_NAME', l_sponsor_name);
8641             fnd_message.set_token('XDATE', l_end_dist_date);
8642             fnd_message.set_token('BDATE', l_begin_dist_date);
8643             fnd_message.set_token('EDATE', l_end_dist_date);
8644             fnd_msg_pub.add;
8645          end if;
8646          close check_salary_cap_exists;
8647       end if;
8648     end loop;
8649 
8650   if l_error_flag = 'Y' then
8651       psp_message_s.print_error(p_mode => FND_FILE.LOG,
8652                                 p_print_header => FND_API.G_TRUE);
8653     rollback;
8654     raise fnd_api.g_exc_unexpected_error;
8655   end if;
8656  end if;
8657      g_time_period_id := nvl(g_time_period_id, -999);
8658      g_payroll_id     := nvl(g_payroll_id, -999);
8659 
8660      --- introduced distinct for 4614640
8661      sqlstr := 'select distinct ppl.assignment_id
8662                   from psp_payroll_lines ppl,
8663                        psp_payroll_controls ppc
8664                  where ppc.payroll_control_id = ppl.payroll_control_id
8665                    and  ppc.cdl_payroll_action_id = :payroll_action_id
8666                  order by ppl.assignment_id';
8667 
8668 --- comment it
8669    --- fnd_file.put_line(fnd_file.log,' sqlstr ='||sqlstr);
8670     else
8671           fnd_msg_pub.add_exc_msg('PSB_LABOR_DIST','RANGE_CODE-NO RECORDS');
8672           psp_message_s.print_error(p_mode => FND_FILE.LOG,
8673                                     p_print_header => FND_API.G_TRUE);
8674           raise fnd_api.g_exc_unexpected_error;
8675     end if;
8676 
8677 
8678 end range_code;
8679 
8680 procedure cdl_archive(p_payroll_action_id in number,
8681                            p_chunk_number in number) IS
8682 
8683   l_start_asg integer;
8684   l_end_asg   integer;
8685   errBuf      varchar2(240);
8686   retcode     varchar2(1);
8687 
8688   cursor get_chunk_status is
8689    select action_status
8690      from pay_temp_object_actions
8691     where payroll_action_id = p_payroll_action_id
8692       and chunk_number = p_chunk_number;
8693 
8694   l_chunk_status varchar2(10);
8695 
8696 Begin
8697 
8698   open get_chunk_status;
8699   fetch get_chunk_status into l_chunk_status;
8700 
8701    hr_utility.trace('CHUNK_STATUS = '||l_chunk_status);
8702   if l_chunk_status <> 'C' then
8703 
8704     hr_utility.trace('########START_ARCHIVE##### g_source_type, g_source_code, g_payroll_id, g_time_period_id, g_batch_name, g_business_group_id, l_chunk_status)='|| g_source_type||','||
8705                                g_source_code||','||
8706                                g_payroll_id||','||
8707                                g_time_period_id||','||
8708                                g_batch_name||','||
8709                                g_business_group_id||','||
8710                                g_set_of_books_id||','||
8711                                g_set_of_books_id||','||l_chunk_status);
8712 
8713 
8714   select min(object_id), max(object_id)
8715     into l_start_asg, l_end_asg
8716     from pay_temp_object_actions
8717    where payroll_action_id = p_payroll_action_id
8718      and chunk_number = p_chunk_number;
8719 
8720   --#fnd_file.put_line(fnd_file.log,'ENTERED ARCHIVE start, end asg='||l_start_asg||','||l_end_asg);
8721   ---#fnd_file.put_line(fnd_file.log,'ENTERED ARCHIVE start, end asg='||l_start_asg||','||l_end_asg||' chunk_number='||p_chunk_number);
8722 
8723 /*
8724    --- #fnd_file.put_line(fnd_file.log,'########START_ARCHIVE##### g_source_type, g_source_code, g_payroll_id, g_time_period_id, g_batch_name, g_business_group_id, l_chunk_status)='|| g_source_type||','||
8725                                g_source_code||','||
8726                                g_payroll_id||','||
8727                                g_time_period_id||','||
8728                                g_batch_name||','||
8729                                g_business_group_id||','||
8730                                g_set_of_books_id||','||
8731                                g_set_of_books_id||','||l_chunk_status);  */
8732 
8733    psp_labor_dist.g_payroll_action_id := p_payroll_Action_id;
8734    psp_labor_dist.create_lines(errbuf  ,
8735                                retcode ,
8736                                g_source_type,
8737                                g_source_code,
8738                                g_payroll_id,
8739                                g_time_period_id,
8740                                g_batch_name,
8741                                g_business_group_id,
8742                                g_set_of_books_id,
8743                                l_start_asg,
8744                                l_end_asg);
8745    /*if 12467 between l_start_asg and l_end_asg then
8746     hr_utility.trace('########START_ARCHIVE#####SLEEP');
8747        raise no_data_found;
8748    end if;   */
8749 end if;
8750 close get_chunk_status;
8751 End;
8752 procedure asg_action_code (p_pactid IN NUMBER,
8753                            stasg IN NUMBER,
8754                            endasg IN NUMBER,
8755                            p_chunk_num IN NUMBER) IS
8756 
8757 l_asgactid  number;
8758 
8759 cursor get_assignments(p_pactid number, stasg number, endasg number,
8760 p_time_period_id number)  is
8761 select  distinct ppl.assignment_id
8762   FROM   psp_payroll_controls ppc,
8763          psp_payroll_lines ppl
8764  WHERE   ppc.business_group_id = g_business_group_id
8765   AND    ppc.set_of_books_id   = g_set_of_books_id
8766   AND    ppc.source_type = nvl(g_source_type,ppc.source_type)
8767   AND    ppc.payroll_source_code = nvl(g_source_code,ppc.payroll_source_code)
8768   AND    ppc.time_period_id <= nvl(p_time_period_id, ppc.time_period_id)   -- Bug 6733614
8769   AND    ppc.payroll_id = nvl(g_payroll_id, ppc.payroll_id)
8770   AND    nvl(ppc.batch_name,'N') = nvl(nvl(g_batch_name,ppc.batch_name),'N')
8771   AND    (ppc.sublines_dr_amount IS NOT NULL OR ppc.sublines_cr_amount IS NOT NULL)
8772   AND    (ppc.dist_dr_amount IS NULL AND ppc.dist_cr_amount IS NULL)
8773   AND    ppl.payroll_control_id = ppc.payroll_control_id
8774   AND    ppl.assignment_id between stasg and endasg;
8775 begin
8776      select get_parameter('SOURCE_TYPE',ppa.legislative_parameters) ,
8777           get_parameter('SOURCE_CODE',ppa.legislative_parameters)  ,
8778           get_parameter('TIME_PERIOD_ID',ppa.legislative_parameters),
8779           get_parameter('BATCH_NAME',ppa.legislative_parameters),
8780           get_parameter('PAYROLL_ID',ppa.legislative_parameters)
8781      into g_source_type,
8782           g_source_code,
8783           g_time_period_id,
8784           g_batch_name,
8785           g_payroll_id
8786      from pay_payroll_actions ppa
8787     where ppa.payroll_action_id = p_pactid;
8788 
8789     if g_time_period_id is not null and g_payroll_id is null then
8790     --#fnd_file.put_line(fnd_file.log,'########AssignCode2#######');
8791     select payroll_id
8792       into g_payroll_id
8793      from per_time_periods
8794     where time_period_id = g_time_period_id;
8795     end if;
8796  g_business_group_id  := FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID');
8797  g_set_of_books_id :=  FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
8798     --#fnd_file.put_line(fnd_file.log,'########asg_action_code#######PACTID, g_business_group_id,  g_set_of_books_id ,g_source_type, g_time_period_id, g_batch_name=');
8799     --#fnd_file.put_line(fnd_file.log,p_pactid||','|| g_business_group_id||','||  g_set_of_books_id ||','||g_source_type||','|| psp_labor_dist.g_time_period_id||','|| g_batch_name);
8800 
8801   open get_assignments(p_pactid, stasg, endasg, psp_labor_dist.g_time_period_id);
8802   fetch get_assignments bulk collect into t_asg_array;
8803   close get_assignments;
8804   for i in 1..t_asg_array.count
8805   loop
8806     --#fnd_file.put_line(fnd_file.log,'########asg_action_code#######PACTID, asg_id='||p_pactid||','|| t_asg_array(i));
8807   select pay_assignment_actions_s.nextval into l_asgactid from dual;
8808 
8809   hr_nonrun_asact.insact( l_asgactid ,
8810                           pactid =>       p_pactid,
8811                           chunk =>        p_chunk_num,
8812                           object_id =>    t_asg_array(i),
8813                           object_type =>      'ASG',
8814                           p_transient_action =>      TRUE);
8815   end loop;
8816  --#fnd_file.put_line(fnd_file.log,'leaving asg action');
8817 
8818 end;
8819 
8820 procedure deinit_code(pactid in number) as
8821 
8822   CURSOR payroll_control_cur IS
8823   SELECT payroll_control_id
8824   FROM   psp_payroll_controls
8825   WHERE  cdl_payroll_action_id = pactid;
8826 
8827   l_total_dist_dr_amount number;
8828   l_total_dist_cr_amount number;
8829   payroll_control_rec payroll_control_cur%rowtype;
8830   l_count_fail_actions integer;
8831 
8832 begin
8833    select get_parameter('SOURCE_TYPE',ppa.legislative_parameters) ,
8834           get_parameter('SOURCE_CODE',ppa.legislative_parameters)  ,
8835           get_parameter('TIME_PERIOD_ID',ppa.legislative_parameters),
8836           get_parameter('BATCH_NAME',ppa.legislative_parameters),
8837           get_parameter('PAYROLL_ID',ppa.legislative_parameters)
8838      into g_source_type,
8839           g_source_code,
8840           g_time_period_id,
8841           g_batch_name,
8842           g_payroll_id
8843      from pay_payroll_actions ppa
8844     where ppa.payroll_action_id = pactid;
8845 
8846     g_business_group_id  := FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID');
8847     g_set_of_books_id :=  FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
8848     --#fnd_file.put_line(fnd_file.log,'DEINIT source_type ='||g_source_type);
8849     --#fnd_file.put_line(fnd_file.log,'DEINIT source_code ='||g_source_code);
8850     --#fnd_file.put_line(fnd_file.log,'DEINIT batch_name ='||g_batch_name);
8851     --#fnd_file.put_line(fnd_file.log,'DEINIT payroll_id ='||g_payroll_id);
8852     --#fnd_file.put_line(fnd_file.log,'DEINIT time_period_id ='||g_time_period_id);
8853     --#fnd_file.put_line(fnd_file.log,'DEINIT set_of_books ='||g_business_group_id);
8854     --#fnd_file.put_line(fnd_file.log,'DEINIT bg_id ='||g_set_of_books_id);
8855 
8856 
8857   select count(*)
8858    into  l_count_fail_actions
8859    from  pay_payroll_actions
8860   where  payroll_action_id = pactid
8861     and  action_status <> 'C';
8862 
8863   if l_count_fail_actions = 0 then
8864 
8865    select count(*)
8866      into l_count_fail_actions
8867      from pay_temp_object_actions
8868     where payroll_action_id = pactid
8869       and action_status <> 'C';
8870 
8871   end if;
8872 
8873 
8874   --#fnd_file.put_line(fnd_file.log,'########entered deinit#######');
8875   hr_utility.trace('CDL process --> deinit action_status ='||l_count_fail_actions);
8876 
8877  if l_count_fail_actions = 0 then
8878 open payroll_control_cur;
8879 loop
8880    fetch payroll_control_cur into payroll_control_rec;
8881    if payroll_control_cur%notfound then
8882      close payroll_control_cur;
8883      exit;
8884    end if;
8885    SELECT nvl(sum(distribution_amount),0)
8886    INTO l_total_dist_dr_amount
8887    FROM psp_distribution_lines  pdl,
8888         psp_payroll_sub_lines   ppsl,
8889         psp_payroll_lines       ppl,
8890         psp_payroll_controls    ppc
8891    WHERE ppc.payroll_control_id = payroll_control_rec.payroll_control_id
8892    AND   ppc.payroll_control_id = ppl.payroll_control_id
8893    AND   ppl.payroll_line_id = ppsl.payroll_line_id
8894    AND   ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
8895    AND   pdl.reversal_entry_flag IS NULL
8896    AND   ppl.dr_cr_flag = 'D';
8897 
8898    SELECT nvl(sum(distribution_amount),0)
8899    INTO l_total_dist_cr_amount
8900    FROM psp_distribution_lines  pdl,
8901         psp_payroll_sub_lines   ppsl,
8902         psp_payroll_lines       ppl,
8903         psp_payroll_controls    ppc
8904    WHERE ppc.payroll_control_id = payroll_control_rec.payroll_control_id
8905    AND   ppc.payroll_control_id = ppl.payroll_control_id
8906    AND   ppl.payroll_line_id = ppsl.payroll_line_id
8907    AND   ppsl.payroll_sub_line_id = pdl.payroll_sub_line_id
8908    AND   pdl.reversal_entry_flag IS NULL
8909    AND   ppl.dr_cr_flag = 'C';
8910 
8911    UPDATE psp_payroll_controls
8912    SET dist_dr_amount = l_total_dist_dr_amount,
8913        dist_cr_amount = l_total_dist_cr_amount
8914    WHERE payroll_control_id = payroll_control_rec.payroll_control_id;
8915 end loop;
8916 end if;
8917 
8918 end;
8919 function get_retro_parent_element_id(p_cost_id integer) return integer is
8920   cursor retro_parent_cur is
8921   select epd.source_element_type_id
8922     from pay_entry_process_details epd,
8923          pay_run_results prr,
8924          pay_costs pc
8925    where epd.element_entry_id = prr.source_id
8926      and prr.run_result_id = pc.run_result_id
8927      and pc.cost_id = p_cost_id;
8928 begin
8929    g_retro_parent_element_id := null;
8930    open retro_parent_cur;
8931    fetch retro_parent_cur into g_retro_parent_element_id;
8932    close retro_parent_cur;
8933    return g_retro_parent_element_id;
8934 end get_retro_parent_element_id;
8935 
8936 
8937 END PSP_LABOR_DIST;