DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSP_PAYTRN

Source


1 PACKAGE BODY PSP_PAYTRN AS
2 /* $Header: PSPPIPLB.pls 120.28.12010000.5 2008/10/17 07:54:16 aniagarw ship $ */
3 
4 --	Introduced the following for bug fix 2916848
5 g_precision		NUMBER;
6 g_ext_precision		NUMBER;
7 --	End of bug fix 2916848
8 
9 --	Introduced the following for bug fix 3107800
10 g_bg_currency_code	psp_payroll_controls.currency_code%TYPE;
11 g_sob_currency_code	gl_sets_of_books.currency_code%TYPE;
12 g_exchange_rate_type	psp_payroll_controls.exchange_rate_type%TYPE;
13 g_uom			VARCHAR2(1);
14 g_entry_date_earned	DATE;
15 g_effective_start_date  DATE;  -- LD Added
16 g_effective_end_date    DATE;  -- LD Added
17 g_ignore_date_earned    VARCHAR(1); -- Bug 6046087
18 --	End of bug fix 3107800
19 
20 l_payroll_id	number(9);	--- made this global for 3922347
21 PROCEDURE IMPORT_PAYTRANS(ERRBUF out NOCOPY varchar2,
22 				RETCODE out NOCOPY varchar2,
23 				p_period_type IN VARCHAR2 ,
24 					p_time_period_id IN NUMBER,
25 			p_business_group_id	IN	NUMBER,	-- Introduced for bug fix 3098050
26 			p_set_of_books_id	IN	NUMBER)	-- Introduced for bug fix 3098050
27 IS
28 
29 -- Get Payroll start date , end date, payroll id
30 -- from per_time_periods_f based on time period id
31 
32 CURSOR	get_payroll_id_csr is
33 SELECT	start_date, end_date, payroll_id
34 FROM	per_time_periods
35 WHERE	time_period_id = p_time_period_id ;
36 
37 -- Declare variables for above cursor
38 
39 l_start_date	date;
40 l_end_date	date;
41 l_total_num_rec		NUMBER DEFAULT 0;
42 
43 /*****	Commented the following cursor for bug fix 3098050
44 CURSOR	get_set_of_books_csr is
45 SELECT	distinct(gl_set_of_books_id),business_group_id
46 FROM	pay_payrolls_f
47 WHERE	payroll_id = l_payroll_id and
48 	((l_start_date between effective_start_date and effective_end_date) or
49 	(l_end_date	between effective_start_date and effective_end_date) or
50 	(l_start_date <= effective_start_date and l_end_date >= effective_end_date))
51 	and gl_set_of_books_id is not null;
52 	end of comment for bug fix 3098050	*****/
53 
54 /******************************************************************************************
55 The last check on gl_set_of_books added in lieu of multi-org responsiblity check
56 *******************************************************************************************
57 
58 CURSOR	get_gl_flex_maps_csr is
59 SELECT	distinct(gl_set_of_books_id)
60 FROM	pay_payroll_gl_flex_maps
61 WHERE	payroll_id = l_payroll_id;
62 
63 
64 **************************************************************************************************
65  The above cursor, and the following two profiles
66  no longer required as we already have the sob id
67 
68 l_profile_sob_id number (15);
69 l_profile_bg_id number(15);
70 l_set_of_books_id number(15);
71 ************************************************************************************************/
72 
73 l_resp_business_group_id number(15) DEFAULT p_business_group_id;	-- Defaulted parameter for bug fix 3098050
74 l_resp_set_of_books_id number (15) DEFAULT p_set_of_books_id;	-- Defaulted parameter for bug fix 3098050
75 
76 -- Error Handling variables
77 
78 l_error_api_name		varchar2(2000);
79 l_return_status			varchar2(1);
80 l_msg_count			number;
81 l_msg_data			varchar2(2000);
82 l_msg_index_out			number;
83 --
84 l_api_name			varchar2(30)	:= 'PSP_PAYTRN';
85 l_subline_message		varchar2(200);
86 l_TGL_REVB_ACC_DATE		varchar2(80); -- added for 3108109
87 l_TGL_DATE_USED		varchar2(80); -- added for 3108109
88 l_prev_accounting_date	date := to_date('01/01/1900','dd/mm/yyyy');	-- added for 3108109
89 l_action_parameter_group   VARCHAR2(30)  := psp_general.get_specific_profile('ACTION_PARAMETER_GROUPS'); -- added for bug 6661707
90 
91 --- added following 2 cursors for 3108109
92 --- modified the below 2 cursors for bug 6661707
93 
94 cursor get_tgl_date_used is
95 select nvl(parameter_value, 'P') parameter_value
96 from PAY_ACTION_PARAMETER_VALUES
97 where parameter_name = 'TGL_DATE_USED'
98 and action_parameter_group_id = l_action_parameter_group;
99 
100 cursor get_tgl_revb_acc_date is
101 select nvl(parameter_value, 'P') parameter_value
102 from PAY_ACTION_PARAMETER_VALUES
103 where parameter_name = 'TGL_REVB_ACC_DATE'
104 and action_parameter_group_id = l_action_parameter_group;
105 
106 /* to select all costed record for quickpay/ regular pay for a particular timeperiod . This would replace both the
107 get payroll actions cursor and get assignment actions cursor
108 
109 */
110  CURSOR get_payroll_assig_actions_csr is
111  select paa2.assignment_id, paa2.assignment_action_id ,
112  	ppa2.payroll_id, ppa2.payroll_action_id, ppa1.effective_date,
113  	ppa1.date_earned, ppa2.time_period_id,
114  	ppa2.pay_advice_date ,
115  	decode(ppa1.action_type,'V',decode(l_TGL_REVB_ACC_DATE,'C',ppa2.effective_date,
116  						ppa1.effective_date),
117  		decode(l_TGL_DATE_USED,'E',ppa1.date_earned,
118  						ppa1.effective_date)) accounting_date
119   from pay_payroll_actions ppa1, pay_assignment_actions paa1,
120  	pay_payroll_actions ppa2,
121  	pay_assignment_actions paa2
122   where ppa1.payroll_id= l_payroll_id
123  	and ppa1.date_earned between l_start_date and l_end_date
124  	and ppa1.action_type IN ('R','Q','V') -- regular run, quick_pay, reversals
125  	and ppa1.payroll_action_id = paa1.payroll_action_id
126  	and EXISTS	(SELECT /*+ use_nl(PAI1) */ pai1.locked_action_id
127  		FROM	pay_action_interlocks pai1
128  		WHERE	paa1.assignment_action_id = pai1.locked_action_id
129  			and pai1.locking_action_id = paa2.assignment_action_id)	-- End of changes for bug fix 3263333
130  	and paa2.payroll_action_id = ppa2.payroll_action_id
131  	and ppa2.action_type = 'C'
132  	and ppa2.action_status='C'
133  and exists (select assignment_action_id from pay_costs where
134  assignment_action_id=paa2.assignment_action_id)
135  UNION
136  -- broke the decode for bug 6409008
137  /* Now for 'B'*/
138  (select paa1.assignment_id, paa1.assignment_action_id,
139  	ppa1.payroll_id, ppa1.payroll_action_id, ppa1.effective_date, ppa1.date_earned,
140  	ppa1.time_period_id, ppa1.pay_advice_date ,
141  	decode(ppa2.action_type,'B',decode(l_TGL_REVB_ACC_DATE,'C',ppa1.effective_date,
142  						ppa2.effective_date),
143  		decode(l_TGL_DATE_USED,'E',ppa2.date_earned,
144  						ppa2.effective_date)) accounting_date
145   from pay_payroll_actions ppa1, pay_assignment_actions paa1,
146  	pay_payroll_actions ppa2,
147  	pay_assignment_actions paa2
148  where   ppa2.action_type = 'B'
149          and ppa2.date_earned between l_start_date and l_end_date
150  	and ppa2.payroll_id=l_payroll_id
151  	and ppa1.action_type='C' and
152  	ppa1.action_status='C'
153  	and ppa1.payroll_action_id=paa1.payroll_action_id
154  	and EXISTS	(SELECT /*+ use_nl(PAI1) */ pai1.locked_action_id
155  			FROM	pay_action_interlocks pai1
156  			WHERE	paa1.assignment_action_id=pai1.locking_action_id
157  				and pai1.locked_action_id = paa2.assignment_action_id)	-- End of changes for bug fix 3263333
158  	and paa2.payroll_action_id = ppa2.payroll_action_id
159  	and ppa2.action_type not in ('R','Q' ,'F','V')
160  and exists
161  (select assignment_action_id from pay_costs where assignment_action_id=paa1.assignment_action_id))
162  UNION
163  /* Now for '0' etc: */
164  (select paa1.assignment_id, paa1.assignment_action_id,
165  	ppa1.payroll_id, ppa1.payroll_action_id, ppa1.effective_date, ppa1.date_earned,
166  	ppa1.time_period_id, ppa1.pay_advice_date ,
167  	decode(ppa2.action_type,'B',decode(l_TGL_REVB_ACC_DATE,'C',ppa1.effective_date,
168  						ppa2.effective_date),
169  		decode(l_TGL_DATE_USED,'E',ppa2.date_earned,
170  						ppa2.effective_date)) accounting_date
171   from pay_payroll_actions ppa1, pay_assignment_actions paa1,
172  	pay_payroll_actions ppa2,
173  	pay_assignment_actions paa2
174   where  ppa2.action_type <> 'B'
175          and ppa1.effective_date between l_start_date and l_end_date
176  	and ppa2.payroll_id=l_payroll_id
177  	and ppa1.action_type='C' and
178  	ppa1.action_status='C'
179  	and ppa1.payroll_action_id=paa1.payroll_action_id
180  	and EXISTS	(SELECT /*+ use_nl(PAI1) */ pai1.locked_action_id
181  			FROM	pay_action_interlocks pai1
182  			WHERE	paa1.assignment_action_id=pai1.locking_action_id
183  				and pai1.locked_action_id = paa2.assignment_action_id)	-- End of changes for bug fix 3263333
184  	and paa2.payroll_action_id = ppa2.payroll_action_id
185  	and ppa2.action_type not in ('R','Q' ,'F','V')
186  and exists
187  (select assignment_action_id from pay_costs where assignment_action_id=paa1.assignment_action_id))
188   order by 9 desc, 7 desc, 2 desc;   -- Bug 7116131;
189 
190 /*added end*/
191 
192 g_payroll_asg_rec get_payroll_assig_actions_csr%ROWTYPE;
193 
194 
195 
196 
197 /*
198  The following two cursors commented out NOCOPY in lieu of bug fix#1004191
199 
200 
201 
202 
203 
204 -- Get all transactions from pay_payroll_actions
205 --	based on effective_date between payroll_start_date
206 --	and payroll_end_date
207 CURSOR get_payroll_actions_csr is
208 SELECT payroll_id,
209 	payroll_action_id,
210 	effective_date,
211 	date_earned,
212 	time_period_id,
213 	pay_advice_date
214 FROM	PAY_PAYROLL_ACTIONS
215 WHERE	effective_date between l_start_date and l_end_date and
216 	payroll_id = l_payroll_id and
217 	action_type in ('R','Q') and action_status = 'C';
218  action type changed from 'C' to (R. Q) to fix bug 1004191
219 
220 
221 --Declare a record for above cursor
222 
223 g_payroll_rec get_payroll_actions_csr%ROWTYPE;
224 
225 -- Get all transactions from pay_assignment_actions
226 --		based on payroll_action_id we got from payroll
227 --		actions we got from payroll actions cursor
228 
229 
230 CURSOR get_assignment_actions_csr is
231 SELECT a.assignment_id,
232 	a.assignment_action_id,
233 	b.person_id
234 FROM	PAY_ASSIGNMENT_ACTIONS a,
235 	PER_ASSIGNMENTS_F b
236 WHERE	a.payroll_action_id = g_payroll_rec.payroll_action_id
237 	and a.action_status = 'C'
238 	and (a.assignment_id = b.assignment_id and
239 	((l_start_date between effective_start_date and effective_end_date) or
240 	(l_end_date	between effective_start_date and effective_end_date) or
241 	(l_start_date <= effective_start_date and l_end_date >= effective_end_date)))
242 	and a.assignment_action_id in (select distinct(assignment_action_id) from pay_costs)
243 	order by a.assignment_id;
244 
245 
246 	check on effective date changed
247 	g_payroll_rec.effective_date between b.effective_start_date and b.effective_end_date)
248  restriction on assignment_action id in selecting only those employees for whom arecord exists in pay_costs table:-
249  fixed by Subha, :- Caltech
250 */
251 --Declare variables for above cursor
252 
253 l_assignment_id		PAY_ASSIGNMENT_ACTIONS.ASSIGNMENT_ID%TYPE;
254 l_assignment_action_id	number		:= 0;
255 l_person_id		number		:= 0;
256 l_employee_name		varchar2(240);
257 l_cur_rec number;
258 
259 CURSOR get_pay_costs_csr is
260 SELECT	a.cost_id,		--- REgular run results
261 	a.costed_value,
262 	a.debit_or_credit,
263 	a.balance_or_cost,
264 	a.cost_allocation_keyflex_id,
265 	b.element_type_id,
266 	DECODE(piv.uom, 'M', d.output_currency_code, 'STAT') output_currency_code,
267 	b.start_date,
268 	b.end_date,
269 	paya.date_earned,
270 	paya.action_type action_type,
271 	ptp.start_date tp_start_date,
272 	ptp.end_date tp_end_date,
273 	ptp.time_period_id,
274 	NVL(b.element_entry_id, (SELECT element_entry_id FROM pay_run_results prr where prr.run_result_id = b.source_id)) source_id
275 FROM	PAY_COSTS a, PAY_RUN_RESULTS b, PSP_ELEMENT_TYPES c, PAY_ELEMENT_TYPES_F d,
276 	pay_assignment_actions asga, pay_payroll_actions paya, per_time_periods ptp,
277 	pay_input_values_f piv
278 WHERE	a.assignment_action_id	= l_assignment_action_id and
279 	SUBSTR(piv.uom, 1, 1) IN ('M', g_uom) AND
280 	not exists ( select null
281 			from pay_element_entries_f pee
282 			where pee.element_entry_id = b.source_id and
283 				pee.creator_type in ('RR','EE')) and
284 	a.balance_or_cost = 'C' and
285 	NVL(a.costed_value,0) <> 0 and
286 	a.run_result_id = b.run_result_id and
287 	a.input_value_id = piv.input_value_id and
288 	c.business_group_id = l_resp_business_group_id and
289 	c.set_of_books_id = l_resp_set_of_books_id and
290 	( b.element_type_id = c.element_type_id and
291 	(c.start_date_active between l_start_date and l_end_date or
292 	nvl( c.end_date_active,to_date('4712/12/31' , 'YYYY/MM/DD'))	between l_start_date and l_end_date or
293 	(c.start_date_active <= l_start_date
294 	and nvl(c.end_date_active, to_date('4712/12/31' , 'YYYY/MM/DD')) >= l_end_date))) and
295 	b.element_type_id = d.element_type_id and
296 	(g_payroll_asg_rec.effective_date between d.effective_start_date and d.effective_end_date)
297 	and b.assignment_action_id = asga.assignment_action_id
298 	and paya.payroll_action_id = asga.payroll_action_id
299 	and ptp.payroll_id = l_payroll_id
300 	and paya.date_earned between ptp.start_date and ptp.end_date
301 union all
302 SELECT	a.cost_id,	--- retro run results
303 	a.costed_value,
304 	a.debit_or_credit,
305 	a.balance_or_cost,
306 	a.cost_allocation_keyflex_id,
307 	b.element_type_id,
308 	DECODE(piv.uom, 'M', d.output_currency_code, 'STAT') output_currency_code,
309 	b.start_date,
310 	b.end_date,
311 	paya.date_earned,
312 	'L' action_type,	---- retro
313 	ptp.start_date tp_start_date,
314 	ptp.end_date tp_end_date,
315 	ptp.time_period_id,
316 	NVL(b.element_entry_id, (SELECT element_entry_id FROM pay_run_results prr where prr.run_result_id = b.source_id)) source_id
317 FROM	PAY_COSTS a, PAY_RUN_RESULTS b, PSP_ELEMENT_TYPES c, PAY_ELEMENT_TYPES_F d,
318 	pay_assignment_actions asga, pay_payroll_actions paya, per_time_periods ptp,
319 	pay_input_values_f piv
320 WHERE	a.assignment_action_id	= l_assignment_action_id and
321 	SUBSTR(piv.uom, 1, 1) IN ('M', g_uom) AND
322 	exists ( select null
323 			from pay_element_entries_f pee
324 		where pee.element_entry_id = b.source_id and
325 				pee.creator_type in ('RR','EE')) and
326 	a.balance_or_cost = 'C' and
327 	NVL(a.costed_value,0) <> 0 and
328 	a.run_result_id = b.run_result_id and
329 	a.input_value_id = piv.input_value_id and
330 	c.business_group_id = l_resp_business_group_id and
331 	c.set_of_books_id = l_resp_set_of_books_id and
332 	( b.element_type_id = c.element_type_id and
333 	(c.start_date_active between l_start_date and l_end_date or
334 	nvl( c.end_date_active,to_date('4712/12/31' , 'YYYY/MM/DD'))	between l_start_date and l_end_date or
335 	(c.start_date_active <= l_start_date
336 	and nvl(c.end_date_active, to_date('4712/12/31' , 'YYYY/MM/DD')) >= l_end_date))) and
337 	b.element_type_id = d.element_type_id and
338 	(g_payroll_asg_rec.effective_date between d.effective_start_date and d.effective_end_date)
339 	and b.assignment_action_id = asga.assignment_action_id
340 	and paya.payroll_action_id = asga.payroll_action_id
341 	and ptp.payroll_id = l_payroll_id
342 	and b.end_date between ptp.start_date and ptp.end_date
343 order by time_period_id desc , 15 asc;
344 
345 g_pay_costs_rec get_pay_costs_csr%ROWTYPE;
346 
347 CURSOR check_payroll_lines_csr is
348 SELECT cost_id
349 FROM	PSP_PAYROLL_LINES
350 WHERE	cost_id = g_pay_costs_rec.cost_id;
351 
352 --Declare variable for above cursor
353 
354 l_cost_id	number(15)	:= 0;
355 l_line_id	number(9)	:= 0;
356 
357 CURSOR get_difference_csr is
358 SELECT sum(pay_amount)
359 FROM	psp_payroll_sub_lines
360 WHERE	payroll_line_id = l_line_id;
361 
362 l_subline_sum	NUMBER	:= 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
363 
364 CURSOR get_clearing_account_csr is
365 SELECT reversing_gl_ccid
366 FROM	psp_clearing_account
367 where set_of_books_id=l_resp_set_of_books_id
368 and business_group_id=l_resp_business_group_id
369 and payroll_id = l_payroll_id; -- Added for bug 5592964
370 
371 /***************************************************************************************************
372 
373  Added the above checks on bg and sob for multi-org implementation
374 
375 ****************************************************************************************************/
376 
377 l_clearing_account	number(15)	:= 0;
378 
379 -- Default variables
380 
381 l_payroll_source varchar2(30)	DEFAULT 'PAY';
382 l_rollback_flag varchar2(1)	DEFAULT 'N';
383 l_rollback_date date		DEFAULT NULL;
384 l_status_code	varchar2(1)	DEFAULT 'N';
385 l_balance_amount	NUMBER	DEFAULT 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
386 l_total_salary		NUMBER	DEFAULT 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
387 l_array_count integer;
388 
389 -- Local variables
390 
391 l_record_count number	:= 0;
392 l_rec_count	number		:= 0;
393 l_counter	number	:= 0;
394 -- reduced the precision to 2 digits to fix 2470954
395 --l_total_debit	NUMBER	:= 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
396 --l_debit_count	number(9)	:= 0;
397 --l_total_credit	NUMBER	:= 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
398 --l_credit_count	number(9)	:= 0;
399 l_payroll_line_amount	NUMBER	:= 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
400 l_payroll_sub_lines_amount NUMBER := 0;	-- Corrected to NUMBER from NUMBER(22, 2) for bug fix 2916848
401 l_export_id	number(9):=NULL	;
402 l_gl_ccid	number(15)	:= 0;
403 x_rowid		varchar2(30)	:= NULL;
404 --Bug 1994421 : Zero Work Days Build -Introduced the new variable :lveerubh
405 l_reason	VARCHAR2(35)	DEFAULT	NULL;
406 
407 /* User Defined Exception */
408 ZERO_WORK_DAYS EXCEPTION;
409 l_return_value		VARCHAR2(30); --Added for bug 2056877.
410 no_profile_exists		EXCEPTION;	--Added for bug 2056877.
411 no_val_date_matches	EXCEPTION;	--Added for bug 2056877.
412 no_global_acct_exists	EXCEPTION;	--Added for bug 2056877.
413 l_organization_account_id	NUMBER(9);		--Added for bug 2056877.
414 l_gms_posting_date		date;	-- for 2426343
415 
416 --	Introduced the following for bug fix 2916848
417 /*
418 CURSOR	proration_option_cur IS
419 SELECT	pcv_information1
420 FROM	pqp_configuration_values pcv
421 WHERE	pcv.business_group_id = l_resp_business_group_id
422 AND	pcv_information_category = 'PSP_PRORATION';
423 */
424 
425 CURSOR	get_legislation_code_cur IS
426 SELECT	legislation_code
427 FROM	per_business_groups
428 WHERE	business_group_id = l_resp_business_group_id;
429 
430 --l_proration_option	pqp_configuration_values.pcv_information1%TYPE;
431 l_legislation_code	per_business_groups.legislation_code%TYPE;
432 l_exchange_rate_type	psp_payroll_controls.exchange_rate_type%TYPE;
433 l_prev_currency_code	psp_payroll_controls.currency_code%TYPE;
434 
435 TYPE v_num_array		IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
436 TYPE v_currency_code		IS TABLE OF VARCHAR2(15) INDEX BY BINARY_INTEGER;
437 TYPE v_amount_array is table of NUMBER(15,5) INDEX by BINARY_INTEGER;
438 
439 time_period_id_a v_num_array;
440 payroll_control_id_a v_num_array;
441 currency_code_a v_currency_code; -- Bug 6468271
442 
443 l_parent_control_id number;
444 l_prev_time_period_id number;
445 l_period_name varchar2(500);
446 l_action_type varchar2(500);
447 l_asg_count integer;
448 
449 l_prev_start_date date;
450 l_prev_end_date	date;
451 
452 TYPE payroll_control_array is RECORD	(r_payroll_control_id	v_num_array,
453 					r_currency_code		v_currency_code,
454 					r_tot_dr	v_num_array,
455 					r_tot_cr	v_num_array,
456 					r_dr_amount v_amount_array,
457 					r_cr_amount v_amount_array,
458 					r_precision v_num_array,
459 					r_ext_precision v_num_array );
460 
461 r_payroll_control_array payroll_control_array;
462 --	End of bug fix 2916848
463 
464 --	Introduced the following for bug fix 3107800
465 CURSOR	sob_currency_code_cur IS
466 SELECT	currency_code
467 FROM	gl_sets_of_books gsob
468 WHERE	set_of_books_id = l_resp_set_of_books_id;
469 --	End of bug fix 3107800
470 l_run_id integer;
471  cursor get_import_summary is
472  select cnt_asg,
473 	fvl.meaning action_name,
474 	ptp.period_name,
475 	parent_payroll_control_id
476 	from (select count(distinct ppl.assignment_id) cnt_asg,
477 		ppl.payroll_action_type,
478 		ppc.time_period_id,
479 		ppc.parent_payroll_control_id
480 		from psp_payroll_controls ppc,
481 		psp_payroll_lines ppl
482 		where ppc.run_id = l_run_id
483 		and ppc.payroll_control_id = ppl.payroll_control_id
484 		group by ppl.payroll_action_type, ppc.time_period_id, ppc.parent_payroll_control_id) kount,
485 	fnd_lookup_values_vl fvl,
486 	per_time_periods ptp
487  where kount.payroll_action_type = fvl.lookup_code
488 	and fvl.lookup_type = 'ACTION_TYPE'
489 	and sysdate between nvl(fvl.start_date_active,fnd_date.canonical_to_date('2000/01/31')) and nvl(fvl.end_date_active, fnd_date.canonical_to_date('4000/01/31'))
490 	and kount.time_period_id = ptp.time_period_id
491 	order by parent_payroll_control_id desc, ptp.time_period_id asc;
492 l_master_period_message varchar2(4000);
493  cursor get_master_rec_mesg is
494 	select message_text
495 	from fnd_new_messages
496 	where application_id = 8403
497 	and message_name = 'PSP_IMP_INDICATE_MASTER'
498 	and language_code = userenv('LANG');
499  cursor get_import_summary_heading is
500  select meaning
501 	from fnd_lookup_values_vl
502 	where lookup_code in ('LABEL1_IMP_SUM', 'LABEL2_IMP_SUM', 'LABEL3_IMP_SUM', 'LABEL4_IMP_SUM')
503 	and lookup_type = 'PSP_MESSAGE_TEXT'
504 	and sysdate between start_date_active and nvl(end_date_active, fnd_date.canonical_to_date('4000/01/31'))
505 order by lookup_code;
506 l_count integer;
507 l_temp_heading varchar2(1000);
508 l_heading varchar2(1000);
509 -- Added for bug 5592964
510 l_gl_value VARCHAR2(1000);
511 l_clearing_account_value VARCHAR2(1000);
512 
513 CURSOR	ee_date_earned_cur IS
514 SELECT	effective_start_date, effective_end_date,date_earned  --LD Dev
515 FROM	pay_element_entries_f
516 WHERE	element_entry_id = g_pay_costs_rec.source_id;
517 
518 CURSOR	emphours_config_cur IS
519 SELECT	DECODE(pcv_information1, 'Y', 'H', 'M') employee_hours
520 FROM	pqp_configuration_values
521 WHERE	pcv_information_category = 'PSP_IMPORT_EMPLOYEE_HOURS'
522 AND	legislation_code IS NULL
523 AND	NVL(business_group_id, p_business_group_id) = p_business_group_id;
524 
525 CURSOR	ee_ci_mapping_cur IS
526 SELECT	pcv_information1,
527 	pcv_information2,
528 	pcv_information3,
529 	pcv_information4,
530 	pcv_information5,
531 	pcv_information6
532 FROM	pqp_configuration_values
533 WHERE	pcv_information_category = 'PSP_ELEMENT_ENTRY_CI_MAPPING'
534 AND	legislation_code IS NULL
535 AND	NVL(business_group_id, p_business_group_id) = p_business_group_id;
536 
537 
538 /* Introduced Ignore date earned in element entries configuration type and the flexfield is named
539    PSP_USE_DATE_EARNED, If the config type value = Y, then ignore date earned, else use date earned
540    value */
541 
542 CURSOR	ignore_date_earned_cur IS
543 SELECT	nvl(pcv_information1,'Y')    --6779790
544 FROM	pqp_configuration_values
545 WHERE	pcv_information_category = 'PSP_USE_DATE_EARNED'
546 AND	legislation_code IS NULL
547 AND	NVL(business_group_id, p_business_group_id) = p_business_group_id;   -- Bug 6046087
548 
549 l_column_count			NUMBER;
550 l_gl_column			VARCHAR2(30);
551 l_pt_column			VARCHAR2(30);
552 l_tk_column			VARCHAR2(30);
553 l_aw_column			VARCHAR2(30);
554 l_eo_column			VARCHAR2(30);
555 l_et_column			VARCHAR2(30);
556 l_or_gl_ccid			NUMBER(15);
557 l_or_project_id			NUMBER(15);
558 l_or_task_id			NUMBER(15);
559 l_or_award_id			NUMBER(15);
560 l_or_expenditure_org_id		NUMBER(15);
561 l_or_expenditure_org_name	VARCHAR2(240);
562 l_or_expenditure_type		VARCHAR2(30);
563 l_project_number		VARCHAR2(30);
564 l_task_number			VARCHAR2(30);
565 l_award_number			VARCHAR2(30);
566 l_org_id			NUMBER(15);
567 l_value				VARCHAR2(240);
568 l_table				VARCHAR2(240);
569 
570 CURSOR	exp_org_cur IS
571 SELECT	name
572 FROM	hr_all_organization_units hou
573 WHERE	organization_id = l_or_expenditure_org_id;
574 
575 CURSOR	project_id_cur IS
576 SELECT	segment1
577 FROM	pa_projects_all
578 WHERE	project_id = l_or_project_id;
579 
580 CURSOR	org_id_cur IS
581 SELECT	org_id
582 FROM	pa_projects_all
583 WHERE	project_id = l_or_project_id;
584 
585 CURSOR	task_id_cur IS
586 SELECT	task_number
587 FROM	pa_tasks
588 WHERE	task_id = l_or_task_id;
589 
590 CURSOR	award_id_cur IS
591 SELECT	award_number
592 FROM	gms_awards_all
593 WHERE	award_id = l_or_award_id;
594 
595 CURSOR	expenditure_type_cur IS
596 SELECT	expenditure_type
597 FROM	pa_expenditure_types
598 WHERE	expenditure_type = l_or_expenditure_type;
599 
600 BEGIN
601 
602  FND_MSG_PUB.Initialize;
603  ---hr_utility.trace_on('Y','IMPORT-1');
604  fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	Import process started');
605  hr_utility.trace('	Entering IMPORT_PAYTRANS');
606 
607 
608 /*******************************************************************************************
609 
610  These profiles no longer required as we pick up on basis of timeperiod
611 
612 
613 Changed from PSP profile to GL profile for 11i	:- Subha	03/Feb/2000
614 Added check on HR profile :- Business_Group_Id
615 
616  l_profile_sob_id	:= FND_PROFILE.VALUE('PSP_SET_OF_BOOKS');
617 
618  l_profile_sob_id := FND_PROFILE.VALUE('GL_SET_OF_BKS_ID');
619  l_profile_bg_id := FND_PROFILE.VALUE('PER_BUSINESS_GROUP_ID');
620 ************************************************************************************************/
621 
622 --- added following two cursor s for 3108109
623 open get_tgl_date_used;
624 fetch get_tgl_date_used into l_TGL_DATE_USED;
625 if get_tgl_date_used%NOTFOUND then
626  l_TGL_DATE_USED := 'P';
627 end if;
628 close get_tgl_date_used;
629 
630 open get_tgl_revb_acc_date;
631 fetch get_tgl_revb_acc_date into l_TGL_REVB_ACC_DATE;
632 if get_tgl_revb_acc_date%NOTFOUND then
633  l_TGL_REVB_ACC_DATE := 'P';
634 end if;
635 close get_tgl_revb_acc_date;
636 
637 fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	l_TGL_REVB_ACC_DATE, l_TGL_DATE_USED='||l_TGL_REVB_ACC_DATE ||','|| l_TGL_DATE_USED);
638 
639 -- open get_payroll_dates_csr;
640 -- fetch get_payroll_dates_csr into l_set_of_books_id, l_start_date, l_end_date, l_payroll_id;
641 
642  open get_payroll_id_csr ;
643 
644 	fetch get_payroll_id_csr into l_start_date, l_end_date, l_payroll_id;
645 
646  if get_payroll_id_csr%NOTFOUND then
647 	FND_MESSAGE.SET_NAME('PSP','PSP_INVALID_PERIOD');
648 	fnd_msg_pub.add;
649 	close get_payroll_id_csr;
650 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
651  end if;
652 
653  close get_payroll_id_csr ;
654 
655 fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	l_start_date, l_end_date, l_payroll_id='||l_start_date ||','|| l_end_date ||','|| l_payroll_id);
656 
657 /*****	Commented the following for bug fix 3098050
658 	Following portion had been commented as henceforth from this bug fix onwards, BG/SOB values would
659 	be passed as parameters to the corresponding concurrenct request.
660  open get_set_of_books_csr ;
661  loop
662 	fetch get_set_of_books_csr into l_resp_set_of_books_id ,l_resp_business_group_id;
663 	EXIT WHEN get_set_of_books_csr%NOTFOUND ;
664 	l_record_count := l_record_count + 1;
665 	if l_record_count > 1 then
666 	FND_MESSAGE.SET_NAME('PSP','PSP_INVALID_NO_OF_BOOKS');
667 	fnd_msg_pub.add;
668 	close get_set_of_books_csr;
669 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
670 	end if;
671  end loop;
672  close get_set_of_books_csr;
673 
674  open get_set_of_books_csr ;
675  fetch get_set_of_books_csr into l_resp_set_of_books_id ,l_resp_business_group_id;
676  if get_set_of_books_csr%NOTFOUND then
677 	FND_MESSAGE.SET_NAME('PSP','PSP_NO_SET_OF_BOOKS');
678 	fnd_msg_pub.add;
679 	close get_set_of_books_csr;
680 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
681  elsif NVL(l_resp_set_of_books_id, 0) = 0 then
682 	FND_MESSAGE.SET_NAME('PSP','PSP_PI_NO_SOB_FOR_PAYROLL');
683 	fnd_msg_pub.add;
684 	close get_set_of_books_csr;
685 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
686  end if;
687 
688  close get_set_of_books_csr;
689 	End of comment for bug fix 3098050	*****/
690 
691 --	Introduced the following for bug fix 3107800
692 	g_bg_currency_code := psp_general.get_currency_code(l_resp_business_group_id);
693 
694 	OPEN sob_currency_code_cur;
695 	FETCH sob_currency_code_cur INTO g_sob_currency_code;
696 	CLOSE sob_currency_code_cur;
697 --	End of bug fix 3107800
698 
699 	OPEN emphours_config_cur;
700 	FETCH emphours_config_cur INTO g_uom;
701 	CLOSE emphours_config_cur;
702 
703 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	g_sob_currency_code, g_uom ='||g_sob_currency_code ||','|| g_uom );
704 
705 	OPEN ee_ci_mapping_cur;
706 	FETCH ee_ci_mapping_cur INTO l_gl_column, l_pt_column, l_tk_column, l_aw_column, l_eo_column, l_et_column;
707 	CLOSE ee_ci_mapping_cur;
708 
709 	-- Bug 6046087
710 	OPEN ignore_date_earned_cur;
711 	FETCH ignore_date_earned_cur INTO g_ignore_date_earned;
712 	CLOSE ignore_date_earned_cur;
713 
714 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	g_ignore_date_earned = '||g_ignore_date_earned);
715 
716 	l_column_count := 0;
717 	IF (l_pt_column IS NOT NULL) THEN
718 		l_column_count := l_column_count + 1;
719 	END IF;
720 
721 	IF (l_tk_column IS NOT NULL) THEN
722 		l_column_count := l_column_count + 1;
723 	END IF;
724 
725 	IF (l_eo_column IS NOT NULL) THEN
726 		l_column_count := l_column_count + 1;
727 	END IF;
728 
729 	IF (l_et_column IS NOT NULL) THEN
730 		l_column_count := l_column_count + 1;
731 	END IF;
732 
733 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	l_column_count ='||l_column_count );
734 
735 	IF (l_column_count > 1) AND (l_column_count < 4) THEN
736 		fnd_message.set_name('PSP', 'PSP_EE_INCOMPLETE_CI');
737 		fnd_msg_pub.add;
738 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
739 	END IF;
740 
741 
742 --	Introduced the following for bug fix 2916848
743 /*
744 	OPEN proration_option_cur;
745 	FETCH proration_option_cur INTO l_proration_option;
746 	IF (proration_option_cur%NOTFOUND) THEN
747 		l_proration_option := 'PAY';
748 		OPEN get_legislation_code_cur;
749 		FETCH get_legislation_code_cur INTO l_legislation_code;
750 		CLOSE get_legislation_code_cur;
751 		IF (l_legislation_code = 'US') THEN
752 			l_proration_option := 'PSP';
753 		END IF;
754 	END IF;
755 	CLOSE proration_option_cur;
756 
757 */
758 
759 --	End of bug fix 2916848
760 
761 -- Verify clearing account in psp_clearing_accounts
762 --	if not found or is 0 exit with error.
763 
764  open get_clearing_account_csr;
765  fetch get_clearing_account_csr into l_clearing_account;
766  if get_clearing_account_csr%NOTFOUND or l_clearing_account = 0 then
767 	FND_MESSAGE.SET_NAME('PSP','PSP_NO_CLEARING_ACCOUNT');
768 	fnd_msg_pub.add;
769 	close get_clearing_account_csr;
770 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
771  end if;
772  close get_clearing_account_csr;
773 
774  fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	l_clearing_account ='||l_clearing_account );
775 
776 	/* Following code is added for bug 2056877 ,Added validation for generic suspense account */
777 		l_return_value := psp_general.find_global_suspense(l_end_date,
778 							l_resp_business_group_id,
779 							l_resp_set_of_books_id,
780 							l_organization_account_id );
781 		/* --------------------------------------------------------------------
782 			Valid return values are
783 			PROFILE_VAL_DATE_MATCHES	Profile and Value and Date matching 'G'
784 			NO_PROFILE_EXISTS		No Profile
785 			NO_VAL_DATE_MATCHES		Profile and Either Value/date do not
786 						match with 'G'
787 			NO_GLOBAL_ACCT_EXISTS	No 'G' exists
788 			---------------------------------------------------------------------- */
789 			IF l_return_value = 'PROFILE_VAL_DATE_MATCHES' THEN
790 		NULL;
791 		ELSIF l_return_value = 'NO_GLOBAL_ACCT_EXISTS' THEN
792 				RAISE no_global_acct_exists;
793 		ELSIF l_return_value = 'NO_VAL_DATE_MATCHES' THEN
794 			RAISE no_val_date_matches;
795 		ELSIF l_return_value = 'NO_PROFILE_EXISTS' THEN
796 			RAISE no_profile_exists;
797 		END IF; -- Bug 2056877.
798  g_start_date	:= l_start_date;
799  g_end_date	:= l_end_date;
800 
801  /* Commented as this code serves no purpose
802  --dbms_output.PUT_LINE('................1');
803  open get_payroll_assig_actions_csr;
804  fetch get_payroll_assig_actions_csr into g_payroll_asg_rec;
805 
806  IF get_payroll_assig_actions_csr%NOTFOUND then
807 	raise NO_DATA_FOUND;
808 	close get_payroll_assig_actions_csr;
809  END IF;
810  close get_payroll_assig_actions_csr;    */
811 
812  SELECT psp_st_run_id_s.nextval
813  INTO l_run_id
814  FROM dual;
815 
816 	open get_payroll_assig_actions_csr;
817 
818 	fetch get_payroll_assig_actions_csr into g_payroll_asg_rec;
819 			l_assignment_id:=g_payroll_asg_rec.assignment_id;
820 			l_assignment_action_id:=g_payroll_asg_rec.assignment_action_id;
821 	if get_payroll_assig_actions_csr%NOTFOUND then
822 		raise NO_DATA_FOUND;
823 		close get_payroll_assig_actions_csr;
824 	end if;
825 	close get_payroll_assig_actions_csr;
826 
827 	open get_payroll_assig_actions_csr;
828 
829 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '       **************************************************************');
830 
831 	LOOP
832 
833 	fetch get_payroll_assig_actions_csr into g_payroll_asg_rec;
834 			l_assignment_id:=g_payroll_asg_rec.assignment_id;
835 			l_assignment_action_id:=g_payroll_asg_rec.assignment_action_id;
836 
837 		SELECT	DISTINCT person_id
838 		INTO	l_person_id
839 		FROM	per_all_assignments_f
840 		WHERE	assignment_id = l_assignment_id;
841 
842 
843 
844 	EXIT WHEN get_payroll_assig_actions_csr%NOTFOUND;	-- Exit when last record is reached
845 	BEGIN
846 -- moving calendar logic to LOOP of get_pay_costs_csr
847 
848 
849 
850 
851 	-- Get all transactions from pay_costs table based on
852 		-- assignment_action_id we got from assignment actions
853 
854 
855 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) ||  '	l_assigment_id, l_assignment_action_id, p_time_period_id = '||l_assignment_id||','||
856 			l_assignment_action_id||','||p_time_period_id);
857 
858 		OPEN get_pay_costs_csr;
859 		FETCH get_pay_costs_csr into g_pay_costs_rec;
860 		IF get_pay_costs_csr%NOTFOUND then
861 		hr_utility.trace('	get_pay_costs_csr NO_DATA_FOUND l_assignment_action_id = '||l_assignment_action_id);
862 		raise NO_DATA_FOUND;
863 		close get_pay_costs_csr;
864 		END IF;
865 		close get_pay_costs_csr;
866 		l_prev_time_period_id := null;
867 		l_prev_start_date := TO_DATE('1','j');
868 		l_prev_end_date := TO_DATE('1','j');
869 
870 		hr_utility.trace('	opening get_pay_costs_csr for l_assignment_action_id = '||l_assignment_action_id);
871 
872 		OPEN get_pay_costs_csr;
873 		LOOP   --LOOP1 begin
874 		BEGIN
875 		fetch get_pay_costs_csr into g_pay_costs_rec;
876 		EXIT WHEN get_pay_costs_csr%NOTFOUND ;
877 
878 		hr_utility.trace('	NEXT loop iteration');
879 		hr_utility.trace('	Initial g_entry_date_earned: ' || to_char(g_entry_date_earned,'DD-MON-YYYY'));
880 		hr_utility.trace('	g_pay_costs_rec.source_id: ' || to_char(g_pay_costs_rec.source_id));
881 
882 
883 		g_entry_date_earned := NULL;
884 		OPEN ee_date_earned_cur;
885 		FETCH ee_date_earned_cur INTO g_effective_start_date, g_effective_end_date, g_entry_date_earned; -- LD Added
886 		CLOSE ee_date_earned_cur;
887 
888 		hr_utility.trace('	after cursor g_effective_start_date: ' || to_char(g_effective_start_date,'DD-MON-YYYY'));
889 		hr_utility.trace('	after cursor g_effective_end_date: ' || to_char(g_effective_end_date,'DD-MON-YYYY'));
890 		hr_utility.trace('	after cursor g_entry_date_earned: ' || to_char(g_entry_date_earned,'DD-MON-YYYY'));
891 
892 		g_pay_costs_rec.date_earned := NVL(g_entry_date_earned, g_pay_costs_rec.date_earned);
893 
894 		/* Commented for bug 6046087
895 		-- Bug 5642002: get the element date if available
896 		g_start_date := NVL(NVL(g_entry_date_earned, g_pay_costs_rec.start_date), g_pay_costs_rec.tp_start_date);
897 		g_end_date := NVL(NVL(g_entry_date_earned, g_pay_costs_rec.end_date), g_pay_costs_rec.tp_end_date);
898 		*/
899 
900 		-- Introduced the following IF - END IF for Bug 6046087
901 		IF (g_ignore_date_earned = 'Y') THEN
902 		   g_start_date := 	 g_pay_costs_rec.tp_start_date;
903 		   g_end_date   :=	 g_pay_costs_rec.tp_end_date;
904 
905 		   hr_utility.trace('IF	cost_id, start_Date,
906 		   			end_Date, tp_id , action_type='||g_pay_costs_rec.cost_id||','||
907 		   			g_pay_costs_rec.tp_start_date||','||g_pay_costs_rec.tp_end_date||','||
908 					g_pay_costs_rec.time_period_id||','||g_pay_costs_rec.action_type);
909 
910 		ELSE
911 	           g_start_date := NVL(NVL(g_entry_date_earned, g_pay_costs_rec.start_date), g_pay_costs_rec.tp_start_date);
912 		   g_end_date := NVL(NVL(g_entry_date_earned, g_pay_costs_rec.end_date), g_pay_costs_rec.tp_end_date);
913 
914 	           hr_utility.trace('ELSE	cost_id, start_Date,
915 					end_Date, tp_id , action_type='||g_pay_costs_rec.cost_id||','||
916 					g_pay_costs_rec.tp_start_date||','||g_pay_costs_rec.tp_end_date||','||
917 					g_pay_costs_rec.time_period_id||','||g_pay_costs_rec.action_type);
918 	        END IF;
919 
920 	        hr_utility.trace('	g_start_date ' || to_char(g_start_date,'DD-MON-YYYY'));
921 	        hr_utility.trace('	g_end_date ' || to_char(g_end_date,'DD-MON-YYYY'));
922 
923 
924 		l_or_gl_ccid := NULL;
925 		l_or_project_id := NULL;
926 		l_or_task_id := NULL;
927 		l_or_award_id := NULL;
928 		l_or_expenditure_org_id := NULL;
929 		l_or_expenditure_type := NULL;
930 
931 		IF ((l_gl_column IS NOT NULL) AND (l_pt_column IS NOT NULL)) THEN
932 			IF (l_aw_column IS NOT NULL) THEN
933 				BEGIN
934 					EXECUTE IMMEDIATE 'SELECT ' || l_gl_column || ', ' || l_pt_column || ', ' ||
935 						l_tk_column || ', ' || l_aw_column || ', ' || l_eo_column || ', ' || l_et_column ||
936 						' FROM	pay_element_entries_f WHERE element_entry_id = ' || g_pay_costs_rec.source_id ||
937 						' AND :g_date_earned BETWEEN effective_start_date AND effective_end_date'
938 					INTO l_or_gl_ccid, l_or_project_id, l_or_task_id, l_or_award_id, l_or_expenditure_org_id, l_or_expenditure_type
939 					USING g_pay_costs_rec.date_earned;
940 				EXCEPTION
941 					WHEN OTHERS THEN
942 						hr_utility.trace('	No Element Entry record found');
943 				END;
944 			ELSE
945 				BEGIN
946 					EXECUTE IMMEDIATE 'SELECT ' || l_gl_column || ', ' || l_pt_column || ', ' ||
947 						l_tk_column || ', ' || l_eo_column || ', ' || l_et_column ||
948 						' FROM	pay_element_entries_f WHERE element_entry_id = ' || g_pay_costs_rec.source_id ||
949 						' AND :g_date_earned BETWEEN effective_start_date AND effective_end_date'
950 					INTO l_or_gl_ccid, l_or_project_id, l_or_task_id, l_or_expenditure_org_id, l_or_expenditure_type
951 					USING g_pay_costs_rec.date_earned;
952 				EXCEPTION
953 					WHEN OTHERS THEN
954 						hr_utility.trace('	No Element Entry record found');
955 				END;
956 			END IF;
957 		ELSIF (l_gl_column IS NOT NULL) THEN
958 			BEGIN
959 				EXECUTE IMMEDIATE 'SELECT ' || l_gl_column ||
960 				' FROM	pay_element_entries_f WHERE element_entry_id = ' || g_pay_costs_rec.source_id ||
961 				' AND :g_date_earned BETWEEN effective_start_date AND effective_end_date'
962 				INTO l_or_gl_ccid
963 				USING g_pay_costs_rec.date_earned;
964 			EXCEPTION
965 				WHEN OTHERS THEN
966 					hr_utility.trace('	No Element Entry record found');
967 			END;
968 		ELSIF (l_pt_column IS NOT NULL) THEN
969 			IF (l_aw_column IS NOT NULL) THEN
970 				BEGIN
971 					EXECUTE IMMEDIATE 'SELECT ' || l_pt_column || ', ' || l_tk_column || ', ' ||
972 						l_aw_column || ', ' || l_eo_column || ', ' || l_et_column ||
973 						' FROM	pay_element_entries_f WHERE element_entry_id = ' ||
974 						g_pay_costs_rec.source_id ||
975 						' AND :g_date_earned BETWEEN effective_start_date AND effective_end_date'
976 					INTO l_or_project_id, l_or_task_id, l_or_award_id, l_or_expenditure_org_id, l_or_expenditure_type
977 					USING g_pay_costs_rec.date_earned;
978 				EXCEPTION
979 					WHEN OTHERS THEN
980 						hr_utility.trace('	No Element Entry record found');
981 				END;
982 			ELSE
983 				BEGIN
984 					EXECUTE IMMEDIATE 'SELECT ' || l_pt_column || ', ' || l_tk_column || ', ' ||
985 						l_eo_column || ', ' || l_et_column ||
986 						' FROM	pay_element_entries_f WHERE element_entry_id = ' ||
987 						g_pay_costs_rec.source_id ||
988 						' AND :g_date_earned BETWEEN effective_start_date AND effective_end_date'
989 					INTO l_or_project_id, l_or_task_id, l_or_expenditure_org_id, l_or_expenditure_type
990 					USING g_pay_costs_rec.date_earned;
991 				EXCEPTION
992 					WHEN OTHERS THEN
993 						hr_utility.trace('	No Element Entry record found');
994 				END;
995 			END IF;
996 		END IF;
997 
998 		IF (l_or_project_id IS NOT NULL) THEN
999 			OPEN exp_org_cur;
1000 			FETCH exp_org_cur INTO l_or_expenditure_org_name;
1001 			IF (exp_org_cur%NOTFOUND) THEN
1002 				SELECT	full_name
1003 				INTO	l_employee_name
1004 				FROM	per_people_f
1005 				WHERE	person_id = l_person_id
1006 				AND	g_pay_costs_rec.date_earned BETWEEN effective_start_date AND effective_end_date;
1007 				l_value := 'Organization Id = ' || TO_CHAR(l_or_expenditure_org_id);
1008 				l_table := 'HR_ORGANIZATION_UNITS';
1009 				fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
1010 				fnd_message.set_token('VALUE', l_value);
1011 				fnd_message.set_token('TABLE', l_table);
1012 				fnd_message.set_token('BATCH_NAME', NULL);
1013 				fnd_message.set_token('PERSON_NAME', l_employee_name);
1014 				fnd_msg_pub.add;
1015 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1016 			END IF;
1017 			CLOSE exp_org_cur;
1018 
1019 			OPEN project_id_cur;
1020 			FETCH project_id_cur INTO l_project_number;
1021 			IF (project_id_cur%NOTFOUND) THEN
1022 				SELECT	full_name
1023 				INTO	l_employee_name
1024 				FROM	per_people_f
1025 				WHERE	person_id = l_person_id
1026 				AND	g_pay_costs_rec.date_earned BETWEEN effective_start_date AND effective_end_date;
1027 				l_value := 'Project Id = ' || TO_CHAR(l_or_project_id);
1028 				l_table := 'PA_PROJECTS_ALL';
1029 				fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
1030 				fnd_message.set_token('VALUE',l_value);
1031 				fnd_message.set_token('TABLE',l_table);
1032 				fnd_message.set_token('BATCH_NAME', NULL);
1033 				fnd_message.set_token('PERSON_NAME', l_employee_name);
1034 				fnd_msg_pub.add;
1035 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1036 			END IF;
1037 			CLOSE project_id_cur;
1038 
1039 			OPEN org_id_cur;
1040 			FETCH org_id_cur INTO l_org_id;
1041 			IF (org_id_cur%NOTFOUND) THEN
1042 				SELECT	full_name
1043 				INTO	l_employee_name
1044 				FROM	per_people_f
1045 				WHERE	person_id = l_person_id
1046 				AND	g_pay_costs_rec.date_earned BETWEEN effective_start_date AND effective_end_date;
1047 				l_value := 'Project Id = ' || TO_CHAR(l_or_project_id);
1048 				l_table := 'PA_PROJECTS_ALL';
1049 				fnd_message.set_name('PSP','PSP_ORG_VALUE_NOT_FOUND');
1050 				fnd_message.set_token('VALUE',l_value);
1051 				fnd_message.set_token('TABLE',l_table);
1052 				fnd_message.set_token('BATCH_NAME', NULL);
1053 				fnd_message.set_token('PERSON_NAME', l_employee_name);
1054 				fnd_msg_pub.add;
1055 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1056 			END IF;
1057 			CLOSE org_id_cur;
1058 
1059 			OPEN task_id_cur;
1060 			FETCH task_id_cur INTO l_task_number;
1061 			IF (task_id_cur%NOTFOUND) THEN
1062 				SELECT	full_name
1063 				INTO	l_employee_name
1064 				FROM	per_people_f
1065 				WHERE	person_id = l_person_id
1066 				AND	g_pay_costs_rec.date_earned BETWEEN effective_start_date AND effective_end_date;
1067 				l_value := 'TaskId = ' || TO_CHAR(l_or_task_id);
1068 				l_table := 'PA_TASKS';
1069 				fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
1070 				fnd_message.set_token('VALUE',l_value);
1071 				fnd_message.set_token('TABLE',l_table);
1072 				fnd_message.set_token('BATCH_NAME', NULL);
1073 				fnd_message.set_token('PERSON_NAME', l_employee_name);
1074 				fnd_msg_pub.add;
1075 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1076 			END IF;
1077 			CLOSE task_id_cur;
1078 
1079 			IF (l_or_award_id IS NOT NULL) THEN
1080 				OPEN award_id_cur;
1081 				FETCH award_id_cur INTO l_award_number;
1082 				IF (award_id_cur%NOTFOUND) THEN
1083 					SELECT	full_name
1084 					INTO	l_employee_name
1085 					FROM	per_people_f
1086 					WHERE	person_id = l_person_id
1087 					AND	g_pay_costs_rec.date_earned BETWEEN effective_start_date AND effective_end_date;
1088 					l_value := 'Award Id = ' || TO_CHAR(l_or_award_id);
1089 					l_table := 'GMS_AWARDS_ALL';
1090 					fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
1091 					fnd_message.set_token('VALUE',l_value);
1092 					fnd_message.set_token('TABLE',l_table);
1093 				fnd_message.set_token('BATCH_NAME', NULL);
1094 				fnd_message.set_token('PERSON_NAME', l_employee_name);
1095 					fnd_msg_pub.add;
1096 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1097 				END IF;
1098 				CLOSE award_id_cur;
1099 			END IF;
1100 
1101 			OPEN expenditure_type_cur;
1102 			FETCH expenditure_type_cur INTO l_award_number;
1103 			IF (expenditure_type_cur%NOTFOUND) THEN
1104 				SELECT	full_name
1105 				INTO	l_employee_name
1106 				FROM	per_people_f
1107 				WHERE	person_id = l_person_id
1108 				AND	g_pay_costs_rec.date_earned BETWEEN effective_start_date AND effective_end_date;
1109 				l_value := 'Expenditure Type = ' || l_or_expenditure_type;
1110 				l_table := 'PA_EXPENDITURE_TYPES';
1111 				fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
1112 				fnd_message.set_token('VALUE',l_value);
1113 				fnd_message.set_token('TABLE',l_table);
1114 				fnd_message.set_token('BATCH_NAME', NULL);
1115 				fnd_message.set_token('PERSON_NAME', l_employee_name);
1116 				fnd_msg_pub.add;
1117 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1118 			END IF;
1119 			CLOSE expenditure_type_cur;
1120 		END IF;
1121 
1122 		--- recreate the calendar for reversal time period
1123 		if g_pay_costs_rec.time_period_id <> nvl(l_prev_time_period_id, -1) OR
1124 		g_start_date <> l_prev_start_date OR
1125 		g_end_date <> l_prev_end_date
1126 		then
1127 		hr_utility.trace('	CHANGE IN TIME PERIOD ');
1128 		l_prev_time_period_id := g_pay_costs_rec.time_period_id;
1129 		l_prev_start_date := g_start_date;
1130 		l_prev_end_date := g_end_date;
1131 
1132 		-- Create an working calander (array) for this transaction.
1133 		-- Array contains no of rows that is equal to no. of days that payroll period has.
1134 		-- Each row will have either 'Y' if that day is working day or 'N' if
1135 		-- that day is non-working day
1136 		-- moved the calendar code inside the get_pay_costs cursor for handling of payroll reversals
1137 --		CREATE_WORKING_CALENDAR;
1138 		create_working_calendar(l_assignment_id);
1139 		g_no_of_person_work_days	:= g_no_of_work_days;
1140 
1141 	-- This procedure looks into per_assignments_f for assignment
1142 	-- end date. If the assignment end date falls in to the payroll period,
1143 	-- it updates the array rows with 'N' for the rows after the assignment end date.
1144 
1145 		hr_utility.trace('	UPDATE_WCAL_ASG_END_DATE');
1146 		UPDATE_WCAL_ASG_END_DATE(X_ASSIGNMENT_ID	=> l_assignment_id,
1147 					X_RETURN_STATUS	=> l_return_status);
1148 		if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1149 		l_error_api_name	:= 'UPDATE_WCAL_ASG_END_DATE : ';
1150 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1151 		end if;
1152 
1153 		hr_utility.trace('	UPDATE_WCAL_ASG_BEGIN_DATE');
1154 		UPDATE_WCAL_ASG_BEGIN_DATE(X_ASSIGNMENT_ID	=> l_assignment_id,
1155 					X_RETURN_STATUS	=> l_return_status);
1156 		if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1157 		l_error_api_name	:= 'UPDATE_WCAL_ASG_BEGIN_DATE : ';
1158 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1159 		end if;
1160 
1161 -- This procedure looks into per_assignments_f for assignment
1162 -- status. If the assignment status is 'Suspend' or 'Terminate' for any of the days
1163 -- in the payroll period, it updates the working calendar array with 'N' for those days.
1164 
1165 		hr_utility.trace('	UPDATE_WCAL_ASG_STATUS');
1166 		UPDATE_WCAL_ASG_STATUS(X_ASSIGNMENT_ID	=> l_assignment_id,
1167 					X_RETURN_STATUS	=> l_return_status);
1168 		if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1169 		l_error_api_name	:= 'UPDATE_WCAL_ASG_STATUS : ';
1170 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1171 		end if;
1172 		hr_utility.trace('	AFTER UPDATE_WCAL_ASG_STATUS');
1173 		begin
1174 		l_export_id := null;
1175 
1176 		for i in 1..time_period_id_a.count
1177 		loop
1178 			hr_utility.trace('	KKKK='||i);
1179 		        if (g_pay_costs_rec.time_period_id = time_period_id_a(i)
1180 		                    AND g_pay_costs_rec.output_currency_code = currency_code_a(i))  -- Bug 6468271
1181 		        then
1182 		           hr_utility.trace('	KXyy='||i);
1183 		           l_export_id := payroll_control_id_a(i);
1184 		           hr_utility.trace('	KXzy='||i);
1185 		        end if;
1186 		end loop;
1187 
1188 		exception
1189 		when others then
1190 			l_period_name := sqlerrm;
1191 			hr_utility.trace('	KKKK'||l_period_name);
1192 
1193 
1194 		end;
1195 		hr_utility.trace('	AFTER SET l_export_id');
1196 	end if;
1197 
1198 		hr_utility.trace('	Found cost record Cost_id, costed_value =' ||g_pay_costs_rec.cost_id||','||g_pay_costs_rec.costed_value);
1199 -- Bug 1994421 : Zero Work Days Build - Assigned values to variables for processing non active assignments -lveerubh
1200 		g_non_active_flag	:=	'N';
1201 		g_hire_zero_Work_days	:=	'N';
1202 		g_all_holiday_zero_work_days := 'N';
1203 /* New procedure added for continuing if zero work days :- Caltech, Yale :- subha */
1204 
1205 		/*IF ((g_entry_date_earned IS NULL) or (g_ignore_date_earned = 'Y')) THEN  -- Bug 6046087*/  --6779790
1206 			CHECK_ZERO_WORK_DAYS(	X_ASSIGNMENT_ID => l_assignment_id,
1207 					X_COSTED_VALUE => g_pay_costs_rec.costed_value,
1208 					x_start_date	=> TRUNC(g_start_date),   --Bug 6046087
1209 					x_end_date	=> TRUNC(g_end_date),   --Bug 6046087
1210 					X_RETURN_STATUS => l_return_status);
1211 
1212 			if l_return_status <> FND_API.G_RET_STS_SUCCESS then
1213 				l_error_api_name := 'CHECK_ZERO_WORK_DAYS : ';
1214 				RAISE ZERO_WORK_DAYS;
1215 			end if;
1216 		/*END IF;*/
1217 
1218 		hr_utility.trace('	Before opening check_payroll_lines_csr');
1219 		OPEN check_payroll_lines_csr;
1220 		FETCH check_payroll_lines_csr into l_cost_id;
1221 
1222 		IF check_payroll_lines_csr%NOTFOUND then
1223 			l_counter	:= l_counter + 1;
1224 
1225 		---hr_utility.trace('	No data found in payroll_lines ');
1226 		-- If first record insert a record in psp_payroll_controls
1227 
1228 
1229 	hr_utility.trace('	l_counter = '||l_counter);
1230 	IF l_counter > 0 then
1231 --	Introduced for bug fix 2916848
1232 
1233                 hr_utility.trace('	l_prev_currency_code, g_pay_costs_rec.output_currency_code  = '||l_prev_currency_code||','||
1234 			g_pay_costs_rec.output_currency_code);
1235 		IF nvl(l_prev_currency_code,g_pay_costs_rec.output_currency_code) <> g_pay_costs_rec.output_currency_code THEN
1236 			l_prev_currency_code := g_pay_costs_rec.output_currency_code;
1237 			l_export_id := NULL;
1238 			FOR i IN 1..r_payroll_control_array.r_payroll_control_id.COUNT
1239 			LOOP
1240 				IF (r_payroll_control_array.r_currency_code(i) = l_prev_currency_code) THEN
1241 					l_export_id := r_payroll_control_array.r_payroll_control_id(i);
1242 					g_precision:= r_payroll_control_array.r_precision(i);
1243 					g_ext_precision:= r_payroll_control_array.r_ext_precision(i);
1244 
1245 					l_cur_rec:=i;
1246 
1247 			EXIT;
1248 
1249 				END IF;
1250 			END LOOP;
1251 		END IF;
1252 
1253 --	Introduced the following for bug fix 3107800
1254 			IF (g_pay_costs_rec.output_currency_code = g_bg_currency_code AND
1255 				g_bg_currency_code = g_sob_currency_code) THEN
1256 				l_exchange_rate_type := NULL;
1257 			ELSE
1258 			l_exchange_rate_type := g_exchange_rate_type;
1259 			IF (g_exchange_rate_type IS NULL OR
1260 				l_prev_accounting_date <> g_payroll_asg_rec.accounting_date) THEN
1261 				g_exchange_rate_type := hruserdt.get_table_value
1262 					(p_bus_group_id	=>	l_resp_business_group_id,
1263 					p_table_name		=>	'EXCHANGE_RATE_TYPES',
1264 					p_col_name		=>	'Conversion Rate Type',
1265 					p_row_value		=>	'PAY',
1266 					p_effective_date	=>	g_payroll_asg_rec.accounting_date);
1267 				l_prev_accounting_date := g_payroll_asg_rec.accounting_date; -- 3108109
1268 				l_exchange_rate_type := g_exchange_rate_type;
1269 			END IF;
1270 			END IF;
1271 --	End of bug fix 3107800
1272 
1273 		IF (l_export_id IS NULL) THEN
1274 --		End of bug fix 2916848
1275 
1276 		SELECT PSP_PAYROLL_CONTROLS_S.NEXTVAL into l_export_id
1277 			FROM DUAL;
1278 
1279 			l_total_num_rec:= l_total_num_rec + 1;
1280 			l_cur_rec:= l_total_num_rec;
1281 
1282 			psp_general.get_currency_precision(g_pay_costs_rec.output_currency_code,
1283 							g_precision,
1284 						g_ext_precision);
1285 
1286 			r_payroll_control_array.r_currency_code(l_cur_rec) := g_pay_costs_rec.output_currency_code;
1287 
1288 			r_payroll_control_array.r_payroll_control_id(l_cur_rec) := l_export_id;
1289 
1290 			r_payroll_control_array.r_tot_dr(l_cur_rec) := 0;
1291 			r_payroll_control_array.r_tot_cr(l_cur_rec) := 0;
1292 			r_payroll_control_array.r_cr_amount(l_cur_rec) := 0;
1293 			r_payroll_control_array.r_dr_amount(l_cur_rec) := 0;
1294 			r_payroll_control_array.r_precision(l_cur_rec):= g_precision;
1295 			r_payroll_control_array.r_ext_precision(l_cur_rec):=g_ext_precision;
1296 
1297 
1298 			l_prev_currency_code := g_pay_costs_rec.output_currency_code;
1299 
1300 
1301 			PSP_PAYROLL_CONTROLS_PKG.INSERT_ROW(
1302 				X_ROWID		=>	x_rowid,
1303 				X_PAYROLL_CONTROL_ID	=>	l_export_id,
1304 				X_PAYROLL_ACTION_ID	=>	g_payroll_asg_rec.payroll_action_id,
1305 				X_PAYROLL_SOURCE_CODE	=>	l_payroll_source,
1306 					X_SOURCE_TYPE		=>	'O',
1307 				X_PAYROLL_ID		=>	l_payroll_id,
1308 				X_TIME_PERIOD_ID	=> g_pay_costs_rec.time_period_id,
1309 				X_BATCH_NAME		=>	NULL,
1310 				X_NUMBER_OF_CR		=>	0,
1311 				X_NUMBER_OF_DR		=>	0,
1312 				X_TOTAL_DR_AMOUNT	=>	0,
1313 				X_TOTAL_CR_AMOUNT	=>	0,
1314 				X_SUBLINES_DR_AMOUNT	=>	NULL,
1315 				X_SUBLINES_CR_AMOUNT	=>	NULL,
1316 				X_DIST_CR_AMOUNT	=>	NULL,
1317 				X_DIST_DR_AMOUNT	=>	NULL,
1318 				X_OGM_DR_AMOUNT		=>	NULL,
1319 				X_OGM_CR_AMOUNT		=>	NULL,
1320 				X_GL_DR_AMOUNT		=>	NULL,
1321 				X_GL_CR_AMOUNT		=>	NULL,
1322 				X_STATUS_CODE		=>	l_status_code,
1323 				X_MODE				=>	'R' ,
1324 				X_GL_POSTING_OVERRIDE_DATE => NULL,
1325 				X_GMS_POSTING_OVERRIDE_DATE => NULL,
1326 				X_SET_OF_BOOKS_ID		=>l_resp_set_of_books_id,
1327 				X_BUSINESS_GROUP_ID	=> l_resp_business_group_id ,
1328 				X_GL_PHASE		=> NULL,
1329 				X_GMS_PHASE		=> NULL,
1330 				X_ADJ_SUM_BATCH_NAME	=> NULL,
1331 --	Introduced the following for bug fix 2916848
1332 				x_currency_code		=>	g_pay_costs_rec.output_currency_code,
1333 				x_exchange_rate_type	=>	null,
1334 				x_parent_payroll_control_id	=> l_parent_control_id);	--- exch rate =null for 3108109
1335 
1336 			l_array_count := nvl(time_period_id_a.count,0) + 1;
1337 			time_period_id_a(l_array_count) := g_pay_costs_rec.time_period_id;
1338 			payroll_control_id_a(l_array_count ) := l_export_id;
1339 			currency_code_a(l_array_count) := g_pay_costs_rec.output_currency_code; -- Bug 6468271
1340 
1341 			update psp_payroll_controls
1342 			set run_id = l_run_id
1343 			where payroll_control_id = l_export_id;
1344 		end if;
1345 	END IF;	-- Introduced for bug fix 2916848
1346 		if l_parent_control_id is null then
1347 			l_parent_control_id := l_export_id;
1348 		end if;
1349 
1350 
1351 			PSP_GENERAL.GET_GL_CCID(
1352 			P_PAYROLL_ID			=> l_payroll_id,
1353 			P_SET_OF_BOOKS_ID		=> l_resp_set_of_books_id,
1354 			P_COST_KEYFLEX_ID		=> g_pay_costs_rec.cost_allocation_keyflex_id,
1355 			X_GL_CCID			=> l_gl_ccid);
1356 
1357 		IF l_gl_ccid = 0 or l_gl_ccid IS NULL then
1358 		l_error_api_name	:= 'GET_GL_CCID : ';
1359 		fnd_message.set_name('PSP','PSP_NO_GL_FOR_COSTING');
1360 		fnd_message.set_token('COST_ID', g_pay_costs_rec.cost_allocation_keyflex_id);
1361 		fnd_msg_pub.add;
1362 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1363 		ELSIF l_gl_ccid <> l_clearing_account then
1364 		l_gl_value := psp_general.get_gl_values(l_resp_set_of_books_id, l_gl_ccid);
1365 		l_clearing_account_value := psp_general.get_gl_values(l_resp_set_of_books_id, l_clearing_account);
1366 		l_error_api_name	:= 'GET_GL_CCID : ';
1367 		fnd_message.set_name('PSP','PSP_CLEARING_ACCT_MISMATCH');
1368 		fnd_message.set_token('GL_ACCOUNT', l_gl_value);
1369 		fnd_message.set_token('CLEARING', l_clearing_account_value);
1370 		fnd_msg_pub.add;
1371 		hr_utility.trace('	fail kff ='|| g_pay_costs_rec.cost_allocation_keyflex_id);
1372 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1373 		END IF;
1374 		hr_utility.trace('	pass kff ='|| g_pay_costs_rec.cost_allocation_keyflex_id);
1375 
1376 		SELECT PSP_PAYROLL_LINES_S.NEXTVAL into l_line_id
1377 		FROM DUAL;
1378 		x_rowid := NULL;
1379 
1380  -- intro this IF-ENDIF and changed the next IF stmt to check gms_posting_date for 2426343
1381  If g_non_active_flag = 'Y' then
1382 	-- date earned will be the max date any child sub line can take as effective date.
1383 	l_gms_posting_date := g_pay_costs_rec.date_earned;
1384 	psp_general.get_gms_effective_date(l_person_id, l_gms_posting_date);
1385 
1386 	IF l_gms_posting_date is null then
1387 	select distinct substr(full_name,1,50)
1388 	into l_employee_name
1389 	from per_people_f
1390 	where person_id = l_person_id and
1391 		g_pay_costs_rec.date_earned between effective_start_date and effective_end_date;
1392 	FND_MESSAGE.Set_Name('PSP', 'PSP_PI_PRMRY_ASG_INACTIVE');
1393 	FND_MESSAGE.set_token('Employee',l_employee_name);
1394 	FND_MSG_PUB.ADD;
1395 	g_non_active_flag := 'E'; --ERROR, skip this assg, bcos not a single day it is active
1396 	END IF;
1397  END IF;
1398 
1399 
1400 /* For Bug 1994421 - Zero Work Days Build :
1401  To process the non active assignments the new procedure Create_sline_term_employee is called
1402  A assignment is non active if the g_non_active_flag or g_hire_zero_work_days are 'Y'
1403  -lveerubh
1404 */
1405 	IF g_non_active_flag <> 'E' then	-- introduced for 2426343
1406 	IF	g_non_active_flag = 'Y' OR	g_hire_zero_work_days = 'Y'	OR g_all_holiday_zero_work_days = 'Y'	THEN
1407 
1408  --Insert a single line into psp_payroll_lines
1409 
1410 	PSP_PAYROLL_LINES_PKG.INSERT_ROW (
1411 			X_ROWID			=> x_rowid,
1412 			X_PAYROLL_LINE_ID		=> l_line_id ,
1413 			X_PAYROLL_CONTROL_ID		=> l_export_id ,
1414 			X_SET_OF_BOOKS_ID		=> l_resp_set_of_books_id ,
1415 			X_ASSIGNMENT_ID		=> l_assignment_id ,
1416 			X_PERSON_ID			=> l_person_id ,
1417 			X_COST_ID			=> g_pay_costs_rec.cost_id,
1418 			X_ELEMENT_TYPE_ID		=> g_pay_costs_rec.element_type_id,
1419 			X_PAY_AMOUNT			=> g_pay_costs_rec.costed_value ,
1420 			X_STATUS_CODE			=> l_status_code ,
1421 			X_EFFECTIVE_DATE		=> g_payroll_asg_rec.accounting_date,
1422 			X_ACCOUNTING_DATE		=> g_payroll_asg_rec.accounting_date, --added for
1423 			X_EXCHANGE_RATE_TYPE		=> l_exchange_rate_type,		-- 3108109
1424 			X_CHECK_DATE			=> g_payroll_asg_rec.pay_advice_date,
1425 			X_EARNED_DATE			=> g_pay_costs_rec.date_earned,
1426 			X_COST_ALLOCATION_KEYFLEX_ID	=> g_pay_costs_rec.cost_allocation_keyflex_id,
1427 			X_GL_CODE_COMBINATION_ID	=> l_gl_ccid,
1428 			X_BALANCE_AMOUNT		=> l_balance_amount,
1429 			X_DR_CR_FLAG			=> g_pay_costs_rec.debit_or_credit,
1430 			X_MODE			=> 'R',
1431 			X_PAYROLL_ACTION_TYPE		=> g_pay_costs_rec.action_type,
1432 			X_OR_GL_CODE_COMBINATION_ID	=> l_or_gl_ccid,
1433 			X_OR_PROJECT_ID			=> l_or_project_id,
1434 			X_OR_TASK_ID			=> l_or_task_id,
1435 			X_OR_AWARD_ID			=> l_or_award_id,
1436 			X_OR_EXPENDITURE_ORG_ID		=> l_or_expenditure_org_id,
1437 			X_OR_EXPENDITURE_TYPE		=> l_or_expenditure_type);
1438 
1439 -- The following code is required as psp_payroll_controls will be updated with the total debit and credit amount
1440 
1441 
1442 	IF g_pay_costs_rec.debit_or_credit = 'D' then
1443 		r_payroll_control_array.r_tot_dr(l_cur_rec)
1444 		:= r_payroll_control_array.r_tot_dr(l_cur_rec) +1;
1445 
1446 		r_payroll_control_array.r_dr_amount(l_cur_rec) :=
1447 			r_payroll_control_array.r_dr_amount(l_cur_rec) + g_pay_costs_rec.costed_value;
1448 
1449 	ELSE
1450 		r_payroll_control_array.r_tot_cr(l_cur_rec)
1451 		:= r_payroll_control_array.r_tot_cr(l_cur_rec) +1;
1452 
1453 		r_payroll_control_array.r_cr_amount(l_cur_rec) :=
1454 		r_payroll_control_array.r_cr_amount(l_cur_rec) + g_pay_costs_rec.costed_value;
1455 
1456 	END IF;
1457 
1458 -- write single sub-line in PSP_PAYROLL_SUB_LINES
1459 
1460 	IF	g_non_active_flag	= 'Y' THEN
1461 		l_reason := 'NON_ACTIVE_ASSIGNMENT';
1462 	ELSIF g_hire_zero_work_days	= 'Y' THEN
1463 		l_reason := 'ASG_START_LAST_NON_WORK_DAY';
1464 	ELSIF g_all_holiday_zero_work_days = 'Y' THEN
1465 		l_reason := 'ELEMENT_ENTRY_FOR_SAT_SUN_ONLY';
1466 	END IF;
1467 
1468 	CREATE_SLINE_TERM_EMP( X_PAYROLL_LINE_ID	=> l_line_id,
1469 				X_REASON		=> l_reason,
1470 				X_RETURN_STATUS	=> l_return_status);
1471 
1472 	IF l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1473 				l_error_api_name	:= 'CREATE_SLINE_TERM_EMP'||' '||l_reason;
1474 				Raise FND_API.G_EXC_UNEXPECTED_ERROR;
1475 	END IF;
1476 
1477  ELSE
1478 ---End of changes made for Non active assignments: Done as part of Bug 1994421 -Zero Work Days Build -lveerubh
1479 
1480 
1481 
1482 		PSP_PAYROLL_LINES_PKG.INSERT_ROW (
1483 			X_ROWID			=> x_rowid,
1484 			X_PAYROLL_LINE_ID		=> l_line_id ,
1485 			X_PAYROLL_CONTROL_ID		=> l_export_id ,
1486 			X_SET_OF_BOOKS_ID		=> l_resp_set_of_books_id ,
1487 			X_ASSIGNMENT_ID		=> l_assignment_id ,
1488 			X_PERSON_ID			=> l_person_id ,
1489 			X_COST_ID			=> g_pay_costs_rec.cost_id,
1490 			X_ELEMENT_TYPE_ID		=> g_pay_costs_rec.element_type_id,
1491 			X_PAY_AMOUNT			=> g_pay_costs_rec.costed_value ,
1492 			X_STATUS_CODE		=> l_status_code ,
1493 			X_EFFECTIVE_DATE		=> g_payroll_asg_rec.effective_date,
1494 			X_ACCOUNTING_DATE		=> g_payroll_asg_rec.accounting_date, --added for
1495 			X_EXCHANGE_RATE_TYPE		=> l_exchange_rate_type,		-- 3108109
1496 			X_CHECK_DATE			=> g_payroll_asg_rec.pay_advice_date,
1497 			X_EARNED_DATE		=> g_pay_costs_rec.date_earned,
1498 			X_COST_ALLOCATION_KEYFLEX_ID	=> g_pay_costs_rec.cost_allocation_keyflex_id,
1499 			X_GL_CODE_COMBINATION_ID	=> l_gl_ccid,
1500 			X_BALANCE_AMOUNT		=> l_balance_amount,
1501 			X_DR_CR_FLAG			=> g_pay_costs_rec.debit_or_credit,
1502 			X_MODE			=> 'R',
1503 			X_PAYROLL_ACTION_TYPE		=> g_pay_costs_rec.action_type,
1504 			X_OR_GL_CODE_COMBINATION_ID	=> l_or_gl_ccid,
1505 			X_OR_PROJECT_ID			=> l_or_project_id,
1506 			X_OR_TASK_ID			=> l_or_task_id,
1507 			X_OR_AWARD_ID			=> l_or_award_id,
1508 			X_OR_EXPENDITURE_ORG_ID		=> l_or_expenditure_org_id,
1509 			X_OR_EXPENDITURE_TYPE		=> l_or_expenditure_type);
1510 
1511 --	IF (l_proration_option = 'PSP' or g_pay_costs_rec.start_date IS NULL) THEN	-- Introduced for bug fix 2916848
1512 
1513 	---IF g_pay_costs_rec.start_date IS NULL THEN ... commented for 4897071
1514 
1515 
1516 		CREATE_DAILY_RATE_CALENDAR(
1517 				X_ASSIGNMENT_ID		=> l_assignment_id,
1518 				X_time_period_id		=> p_time_period_id,
1519 				X_ELEMENT_TYPE_ID	=> g_pay_costs_rec.element_type_id,
1520 				X_RETURN_STATUS		=> l_return_status);
1521 		IF l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1522 		l_error_api_name	:= 'CREATE_DAILY_RATE_CALENDAR : ';
1523 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1524 		END IF;
1525 
1526 
1527 -- Sum up the salary from daily calendar array
1528 -- compare the salary amount we got from pay costs table
1529 -- if it is different, calculate the difference amount
1530 
1531 		CALCULATE_BALANCE_AMOUNT(X_PAY_AMOUNT		=> g_pay_costs_rec.costed_value,
1532 					X_BALANCE_AMOUNT	=> l_balance_amount,
1533 					X_RETURN_STATUS	=> l_return_status);
1534 		if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1535 		l_error_api_name	:= 'CREATE_BALANCE_AMOUNT : ';
1536 		--dbms_output.PUT_LINE('...CREATE_BALANCE_AMOUNT :');
1537 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1538 		end if;
1539 
1540 /* commented for 4897071
1541 --	Introduced the following for bug fix 2916848
1542 	ELSE
1543 		create_prorate_calendar
1544 			(p_start_date		=>	g_pay_costs_rec.start_date,
1545 			p_end_date		=>	g_pay_costs_rec.end_date,
1546 			p_pay_amount		=>	g_pay_costs_rec.costed_value,
1547 			p_payroll_line_id	=>	l_line_id,
1548 			p_balance_amount	=>	l_balance_amount,
1549 			p_return_status		=>	l_return_status);
1550 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1551 			l_error_api_name	:= 'CREATE_PRORATE_CALENDAR : ';
1552 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1553 		END IF;
1554 
1555 
1556 	END IF;
1557 */
1558 
1559 	UPDATE PSP_PAYROLL_LINES set balance_amount=l_balance_amount where payroll_line_id=l_line_id;
1560 
1561 --	End of bug fix 2916848
1562 
1563 		IF g_pay_costs_rec.debit_or_credit = 'D' then
1564 
1565 				r_payroll_control_array.r_tot_dr(l_cur_rec):=
1566 			r_payroll_control_array.r_tot_dr(l_cur_rec) +1;
1567 			r_payroll_control_array.r_dr_amount(l_cur_rec) :=
1568 			r_payroll_control_array.r_dr_amount(l_cur_rec) +
1569 			g_pay_costs_rec.costed_value;
1570 
1571 		ELSE
1572 
1573 			r_payroll_control_array.r_tot_cr(l_cur_rec):=
1574 			r_payroll_control_array.r_tot_cr(l_cur_rec) +1;
1575 
1576 			r_payroll_control_array.r_cr_amount(l_cur_rec) :=
1577 			r_payroll_control_array.r_cr_amount(l_cur_rec) +
1578 			g_pay_costs_rec.costed_value;
1579 
1580 		END IF;
1581 
1582 -- If salary change happens during the payroll period
1583 --	write two sub-lines in PSP_PAYROLL_SUB_LINES
1584 --	table
1585 -- else
1586 --	write single sub-line in PSP_PAYROLL_SUB_LINES
1587 --	table
1588 -- end if;
1589 
1590 ---	IF (l_proration_option = 'PSP' or g_pay_costs_rec.start_date is null ) THEN	-- Introduced for bug fix 2916848
1591 
1592 --- IF g_pay_costs_rec.start_date IS NULL then .. commented for 4897071
1593 		/*Bug 5642002: Added parameters x_start_date and x_end_date */
1594 			CREATE_SLINE_SALARY_CHANGE (X_PAYROLL_LINE_ID	=> l_line_id,
1595 						x_start_date		=> TRUNC(g_start_date), -- Bug 6046087
1596 						x_end_date		=> TRUNC(g_end_date),   -- Bug 6046087
1597 						X_RETURN_STATUS		=> l_return_status);
1598 
1599 
1600 			IF l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1601 			l_error_api_name	:= 'CREATE_SLINE_SALARY_CHANGE : ';
1602 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1603 			END IF;
1604 
1605  ----END IF;	-- Introduced for bug fix 2916848
1606 
1607 -- if assignment starts during pay period then
1608 --	update sub-line start date with assignment start
1609 --	date.
1610 -- If assignment ends during pay period then
1611 --	update sub-line end date with assignment end
1612 --	date.
1613 
1614 			CREATE_SLINE_ASG_CHANGE (X_PAYROLL_LINE_ID		=> l_line_id,
1615 						X_ASSIGNMENT_ID		=> l_assignment_id,
1616 						X_RETURN_STATUS		=> l_return_status);
1617 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1618 			l_error_api_name	:= 'CREATE_SLINE_ASG_CHANGE : ';
1619 				----dbms_output.PUT_LINE('...CREATE_SLINE_ASG_CHANGE :');
1620 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1621 			end if;
1622 
1623 
1624 -- Looks in to per_assignments_f for assignment statuses either
1625 -- 'Suspend' or 'Terminate' during the pay period.
1626 -- If found then split the sub-line in to two sub-lines and
1627 -- delete the existing sub-line.
1628 
1629 			CREATE_SLINE_ASG_STATUS_CHANGE (X_PAYROLL_LINE_ID		=> l_line_id,
1630 								X_ASSIGNMENT_ID		=> l_assignment_id,
1631 							X_BALANCE_AMOUNT		=> l_balance_amount,
1632 							X_RETURN_STATUS		=> l_return_status);
1633 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1634 			l_error_api_name	:= 'CREATE_SLINE_ASG_STATUS_CHANGE : ';
1635 				----dbms_output.PUT_LINE('...CREATE_SLINE_ASG_STATUS_CHANGE :');
1636 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1637 			end if;
1638 
1639 
1640 -- Looks into per_periods_of_service for ending employment.
1641 -- If found then split the sub-line in to two sub-lines and
1642 -- delete the existing sub-line.
1643 
1644 			CREATE_SLINE_EMP_END_DATE(X_PAYROLL_LINE_ID		=> l_line_id,
1645 						X_PERSON_ID		=> l_person_id,
1646 						X_RETURN_STATUS		=> l_return_status);
1647 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1648 			l_error_api_name	:= 'CREATE_SLINE_EMP_END_DATE : ';
1649 				----dbms_output.PUT_LINE('...CREATE_SLINE_EMP_END_DATE :');
1650 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1651 			end if;
1652 
1653 -- Looks into per_assignments_f for Organization change during the pay period.
1654 -- If found split the sub-line into two sub-lines and delete the existing sub-line.
1655 
1656 			CREATE_SLINE_ORG_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1657 						X_ASSIGNMENT_ID		=> l_assignment_id,
1658 						X_BALANCE_AMOUNT		=> l_balance_amount,
1659 						X_RETURN_STATUS		=> l_return_status);
1660 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1661 			l_error_api_name	:= 'CREATE_SLINE_ORG_CHANGE : ';
1662 				----dbms_output.PUT_LINE('...CREATE_SLINE_ORG_CHANGE :');
1663 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1664 			end if;
1665 
1666 
1667 -- Looks into per_assignments_f for Job change during the pay period.
1668 -- If found split the sub-line into two sub-lines and delete the existing sub-line.
1669 
1670 
1671 			CREATE_SLINE_JOB_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1672 						X_ASSIGNMENT_ID		=> l_assignment_id,
1673 						X_BALANCE_AMOUNT		=> l_balance_amount,
1674 						X_RETURN_STATUS		=> l_return_status);
1675 
1676 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1677 			l_error_api_name	:= 'CREATE_SLINE_JOB_CHANGE : ';
1678 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1679 			end if;
1680 
1681 
1682 -- Looks into per_assignments_f for Position change during the pay period.
1683 -- If found split the sub-line into two sub-lines and delete the existing sub-line.
1684 
1685 			CREATE_SLINE_POSITION_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1686 						X_ASSIGNMENT_ID		=> l_assignment_id,
1687 						X_BALANCE_AMOUNT		=> l_balance_amount,
1688 						X_RETURN_STATUS		=> l_return_status);
1689 
1690 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1691 			l_error_api_name	:= 'CREATE_SLINE_POSITION_CHANGE : ';
1692 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1693 			end if;
1694 
1695 /* New Procedures added for splitting sublines by garde and people group */
1696 
1697 
1698 			CREATE_SLINE_GRADE_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1699 						X_ASSIGNMENT_ID		=> l_assignment_id,
1700 						X_BALANCE_AMOUNT		=> l_balance_amount,
1701 						X_RETURN_STATUS		=> l_return_status);
1702 
1703 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1704 			l_error_api_name	:= 'CREATE_SLINE_GRADE_CHANGE : ';
1705 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1706 			end if;
1707 
1708 
1709 
1710 
1711 			CREATE_SLINE_PPGROUP_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1712 						X_ASSIGNMENT_ID		=> l_assignment_id,
1713 						X_BALANCE_AMOUNT		=> l_balance_amount,
1714 						X_RETURN_STATUS		=> l_return_status);
1715 
1716 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1717 			l_error_api_name	:= 'CREATE_SLINE_PPGROUP_CHANGE : ';
1718 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1719 			end if;
1720 
1721 
1722 
1723 -- Get profile value of profile 'PSP_FTE_OPTIONS'
1724 -- If the value is 'Budget_Values' don't do anything
1725 -- else look for the fte change in per_assignments_f.
1726 -- If found split the sub-line into two sub-lines and delete the existing sub-line.
1727 		/* Commented for Bug 4055483
1728 
1729 			CREATE_SLINE_FTE_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1730 						X_ASSIGNMENT_ID		=> l_assignment_id,
1731 						X_BALANCE_AMOUNT		=> l_balance_amount,
1732 						X_RETURN_STATUS		=> l_return_status);
1733 
1734 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1735 			l_error_api_name	:= 'CREATE_SLINE_FTE_CHANGE : ';
1736 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1737 			end if;
1738 		End of code changes for bug 4055483 */
1739 
1740 			CREATE_SLINE_BUDGET_CHANGE(X_PAYROLL_LINE_ID		=> l_line_id,
1741 						X_ASSIGNMENT_ID		=> l_assignment_id,
1742 						X_BALANCE_AMOUNT		=> l_balance_amount,
1743 						X_RETURN_STATUS		=> l_return_status);
1744 
1745 			if l_return_status	<> FND_API.G_RET_STS_SUCCESS then
1746 			l_error_api_name	:= 'CREATE_SLINE_BUDGET_CHANGE : ';
1747 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
1748 			end if;
1749 
1750 		hr_utility.trace('	Opening get_difference_csr cursor');
1751 
1752 --		Insert rounding routine here
1753 		open get_difference_csr;
1754 		fetch get_difference_csr into l_subline_sum;
1755 		if get_difference_csr%NOTFOUND then
1756 		l_error_api_name	:= 'PSP_PAYTRN : error at GET_DIFFERECE_CSR';
1757 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1758 		end if;
1759 		close get_difference_csr;
1760 -- Added daily rate not equal to 0 to where clause to fix bug no 89157
1761 		if (NVL(to_number(g_pay_costs_rec.costed_value),0) - NVL(l_subline_sum,0)) <> 0 then
1762 		update psp_payroll_sub_lines
1763 			set pay_amount = pay_amount + (NVL(to_number(g_pay_costs_rec.costed_value),0) - NVL(l_subline_sum,0))
1764 		where payroll_line_id = l_line_id and
1765 			NVL(daily_rate,0) <> 0 and
1766 			pay_amount <> 0 and	--- rounding difference to nonzero amount .. 4670588
1767 			rownum = 1;
1768 		if SQL%NOTFOUND then
1769 			l_error_api_name	:= 'PSP_PAYTRN : error while updating subline for rounding';
1770 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1771 		end if;
1772 		end if;
1773 
1774 		end if;
1775 		end if; -- for g_non_active_flag <> E for 2426343
1776 
1777 -- Bug 1994421 : Zero Work Days Build - Closing the Non active assignment IF ENDIF :lveerubh
1778 	END IF;
1779 		close check_payroll_lines_csr;
1780 
1781 /* Added to let the program continue with next record if zero work days is encountered for any assignment	*/
1782 		EXCEPTION
1783 			WHEN ZERO_WORK_DAYS then
1784 
1785 			retcode:= FND_API.G_RET_STS_SUCCESS;
1786 
1787 		END;
1788 		END LOOP; -- LOOP1 end
1789 		close get_pay_costs_csr;
1790 
1791 		EXCEPTION
1792 
1793 		WHEN FND_API.G_EXC_UNEXPECTED_ERROR then
1794 			rollback;
1795 			retcode := 2;
1796 
1797 
1798 			psp_message_s.print_error(p_mode=>FND_FILE.log,
1799 					p_print_header=>FND_API.G_TRUE
1800 					);
1801 
1802 			return;
1803 		WHEN NO_DATA_FOUND then
1804 			close get_pay_costs_csr;
1805 		select distinct substr(full_name,1,50) into l_employee_name from per_people_f
1806 		--where person_id = l_person_id; /* Tar#12269298 WVU */
1807 		where person_id = l_person_id and
1808 		effective_start_date = (select max(effective_start_date ) from per_people_f where
1809 		person_id=l_person_id);
1810 /* Changed in lieu of caltech's reporting, that an employee terminated on the last day was not getting paid
1811 
1812 
1813 			sysdate between effective_start_date and effective_end_date;
1814 */
1815 			FND_MESSAGE.Set_Name('PSP', 'PSP_PI_NO_COSTING_EMP');
1816 			FND_MESSAGE.set_token('Employee',l_employee_name);
1817 			FND_MSG_PUB.ADD;
1818 
1819 			retcode:= FND_API.G_RET_STS_SUCCESS;
1820 
1821 			WHEN OTHERS then
1822 			retcode := 2;
1823 			rollback;
1824 
1825 			hr_utility.trace('	Process failed here');
1826 
1827 			psp_message_s.print_error(p_mode=>FND_FILE.log,
1828 					p_print_header=>FND_API.G_TRUE
1829 					);
1830 
1831 
1832 			return;
1833 		END;
1834 		END LOOP;
1835 		close get_payroll_assig_actions_csr;
1836 
1837 /* The follwing code commented out NOCOPY in lieu of bug fix 1004191 Subha
1838 */
1839 payroll_control_id_a.delete;
1840 time_period_id_a.delete;
1841 currency_code_a.delete; -- Bug 6468271
1842 
1843 	hr_utility.trace('	Finally Updating psp_payroll_controls');
1844 
1845 	FORALL k in 1 .. l_total_num_rec
1846 	UPDATE	psp_payroll_controls
1847 		set number_of_cr = r_payroll_Control_array.r_tot_cr(k),
1848 		number_of_dr = r_payroll_Control_array.r_tot_dr(k),
1849 		total_dr_amount = r_payroll_control_array.r_dr_amount(k),
1850 		total_cr_amount	=r_payroll_control_array.r_cr_amount(k)
1851 	WHERE	payroll_control_id = r_payroll_control_array.r_payroll_control_id(k);
1852 
1853 --end if;
1854 
1855 
1856 	FORALL k in 1 .. l_total_num_rec
1857 	update psp_payroll_controls
1858 		set sublines_dr_amount = ( select sum(pay_amount)
1859 					from	psp_payroll_sub_lines
1860 						where payroll_line_id in (
1861 						select payroll_line_id
1862 						from	psp_payroll_lines
1863 							where payroll_control_id =
1864 							r_payroll_control_array.r_payroll_control_id(k)
1865 								and dr_cr_flag = 'D')),
1866 		sublines_cr_amount = ( select sum(pay_amount)
1867 					from	psp_payroll_sub_lines
1868 						where payroll_line_id in (
1869 						select payroll_line_id
1870 						from	psp_payroll_lines
1871 							where payroll_control_id = r_payroll_control_array.r_payroll_control_id(k) and
1872 							dr_cr_flag = 'C'))
1873 		where payroll_control_id	= r_payroll_control_array.r_payroll_control_id(K);
1874 
1875 	IF sql%NOTFOUND then
1876 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','Error while Updating Sublines Total in Payroll Controls ');
1877 		raise FND_API.G_EXC_UNEXPECTED_ERROR;
1878 	END IF;
1879 
1880 	IF l_total_num_rec=0 then
1881 		fnd_message.set_name('PSP','PSP_PI_NO_PAYROLL_TRXN');
1882 		fnd_msg_pub.add;
1883 
1884 	ELSE
1885 
1886  --- Delete the record of arrays
1887 
1888 	r_payroll_control_array.r_payroll_control_id.DELETE;
1889 	r_payroll_control_array.r_currency_code.DELETE;
1890 	r_payroll_control_array.r_tot_dr.DELETE;
1891 	r_payroll_control_array.r_tot_cr.DELETE;
1892 	r_payroll_control_array.r_dr_amount.DELETE;
1893 	r_payroll_control_array.r_cr_amount.DELETE;
1894 	r_payroll_control_array.r_precision.DELETE;
1895 	r_payroll_control_array.r_ext_precision.DELETE;
1896 
1897 
1898 	END IF;
1899 
1900 	/* added by subha to always print the success message when the program terminates successfully */
1901 
1902 	fnd_file.put_line(fnd_file.log,'********************************************************');
1903 
1904 	fnd_message.set_name('PSP','PSP_PROGRAM_SUCCESS') ;
1905 	fnd_msg_pub.add;
1906 	retcode:= FND_API.G_RET_STS_SUCCESS;
1907 
1908 	COMMIT;
1909 
1910 		psp_message_s.print_error(p_mode=>FND_FILE.log,
1911 					p_print_header=>FND_API.G_FALSE);
1912 
1913 	fnd_file.put_line(fnd_file.log,'********************************************************');
1914 	fnd_file.put_line(fnd_file.log, '');
1915 
1916 	l_count := 0;
1917 	l_heading := null;
1918 	hr_utility.trace('	before get_import_summary_heading');
1919 	fnd_file.put_line(fnd_file.log, ' ');
1920 	fnd_file.put_line(fnd_file.log, ' ');
1921 	fnd_file.put_line(fnd_file.log, ' ');
1922 	open get_import_summary_heading;
1923 	loop
1924 	fetch get_import_summary_heading into l_temp_heading;
1925 	if get_import_summary_heading%notfound then
1926 		close get_import_summary_heading;
1927 		exit;
1928 	end if;
1929 	if l_count = 0 then
1930 		fnd_file.put_line(fnd_file.log, l_temp_heading||':');
1931 		fnd_file.put_line(fnd_file.log, ' ');
1932 		l_count := l_count + 1;
1933 	else
1934 		if l_count = 1 then
1935 		l_heading := l_heading || rpad(l_temp_heading,38)||' ';
1936 		elsif l_count = 2 then
1937 		l_heading := l_heading || rpad(l_temp_heading,20)||' ';
1938 		elsif l_count = 3 then
1939 		l_heading := l_heading || l_temp_heading;
1940 		end if;
1941 		l_count := l_count + 1;
1942 	end if;
1943 	end loop;
1944 	open get_master_rec_mesg;
1945 	fetch get_master_rec_mesg into l_master_period_message;
1946 	close get_master_rec_mesg;
1947 	fnd_file.put_line(fnd_file.log, l_master_period_message);
1948 	fnd_file.put_line(fnd_file.log, l_heading);
1949 	fnd_file.put_line(fnd_file.log, '------------------------------------------------------------------------------');
1950 
1951 	open get_import_summary;
1952 	loop
1953 	fetch get_import_summary into l_asg_count, l_action_type, l_period_name, l_parent_control_id;
1954 	if get_import_summary%notfound then
1955 		close get_import_summary;
1956 		exit;
1957 	end if;
1958 	if l_parent_control_id is null then
1959 		fnd_file.put_line(fnd_file.log, rpad(l_period_name,38) ||' '|| rpad(l_action_type,22)||' '|| lpad(l_asg_count, 10));
1960 	else
1961 		fnd_file.put_line(fnd_file.log,'	'|| rpad(l_period_name,34) ||' '|| rpad(l_action_type,22)||' '|| lpad(l_asg_count, 10));
1962 	end if;
1963 	end loop;
1964 
1965 
1966 	fnd_file.put_line(fnd_file.log, '------------------------------------------------------------------------------');
1967 	fnd_file.put_line(fnd_file.log, '');
1968 	fnd_file.put_line(fnd_file.log, '');
1969 	fnd_file.put_line(fnd_file.log, '');
1970         hr_utility.trace('	Leaving IMPORT_PAYTRANS');
1971 
1972 	EXCEPTION
1973 	WHEN NO_DATA_FOUND then
1974 		close get_payroll_assig_actions_csr;
1975 		fnd_message.set_name('PSP','PSP_PI_NO_PAYROLL_TRXN');
1976 		fnd_msg_pub.add;
1977 		fnd_message.set_name('PSP','PSP_PROGRAM_SUCCESS') ;
1978 		fnd_msg_pub.add;
1979 		retcode:= FND_API.G_RET_STS_SUCCESS;
1980 
1981 
1982 		psp_message_s.print_error(p_mode=>FND_FILE.log,
1983 					p_print_header=>FND_API.G_FALSE);
1984 		return;
1985 
1986 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR then
1987 		retcode := 2;
1988 		rollback;
1989 
1990 
1991 		psp_message_s.print_error(p_mode=>FND_FILE.log,
1992 					p_print_header=>FND_API.G_TRUE
1993 					);
1994 
1995 		return;
1996 	/* Added Exceptions for bug 2056877 */
1997 		WHEN NO_PROFILE_EXISTS THEN
1998 		fnd_message.set_name('PSP','PSP_NO_PROFILE_EXISTS');
1999 		fnd_msg_pub.add;
2000 		psp_message_s.print_error(p_mode=>FND_FILE.log,
2001 					p_print_header=>FND_API.G_TRUE);
2002 		retcode := 2;
2003 
2004 
2005 	WHEN NO_VAL_DATE_MATCHES THEN
2006 	fnd_message.set_name('PSP','PSP_IMP_NO_VAL_DATE_MATCHES');
2007 	fnd_message.set_token('PAYROLL_DATE',l_end_date);
2008 	fnd_msg_pub.add;
2009 	psp_message_s.print_error(p_mode=>FND_FILE.log,
2010 					p_print_header=>FND_API.G_TRUE);
2011 	retcode := 2;
2012 
2013 	WHEN NO_GLOBAL_ACCT_EXISTS THEN
2014 	-- commented the below line and replaced it with the next line, fix done is fixing the gscc warning on not to use chr(x)
2015 	-- instead use fnd_global.local_chr(x)
2016 	--errbuf	:= l_error_api_name || chr(10) || l_msg_data || chr(10);
2017 	errbuf	:= l_error_api_name || fnd_global.local_chr(10) || l_msg_data || fnd_global.local_chr(10);
2018 	fnd_message.set_name('PSP','PSP_IMP_NO_GLOBAL_ACCT_EXISTS');
2019 	fnd_message.set_token('PAYROLL_DATE',l_end_date);
2020 	fnd_msg_pub.add;
2021 	psp_message_s.print_error(p_mode=>FND_FILE.log,
2022 					p_print_header=>FND_API.G_TRUE);
2023 	retcode := 2; --End of Modification for Bug 2056877.
2024 
2025 	WHEN OTHERS then
2026 		retcode := 2;
2027 		rollback;
2028 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','IMPORT_PAY_TRNS');
2029 
2030 
2031 		psp_message_s.print_error(p_mode=>FND_FILE.log,
2032 					p_print_header=>FND_API.G_TRUE
2033 					);
2034 
2035 		return;
2036 	END;
2037 
2038 
2039 /*****	Commented for Work Schedules enh.
2040 -------------------------------CREATE_WORKING_CALENDAR---------------------------------------
2041 PROCEDURE create_working_calendar IS
2042 
2043 i		number(9)	:= 0;
2044 l_low_date	date	:= trunc(g_start_date);
2045 l_high_date	date	:= trunc(g_end_date);
2046 
2047 begin
2048  g_no_of_days		:= 0;
2049  g_no_of_work_days	:= 0;
2050 
2051  ----dbms_output.put_line('Entered Proceduer create_working_calendar..');
2052  while l_low_date <= l_high_date loop
2053 	g_no_of_days := g_no_of_days + 1;
2054 	/ *Bug 5557724: to_char(some_date,'D') returns a number indicating the weekday. However, for a given date, this number
2055 	returned varies with NLS_TERRITORY. So replaced it with to_char(some_date,'DY') that gives the abbreviated day. * /
2056 	if to_char(l_low_date, 'DY', 'nls_date_language=english') NOT IN ('SUN', 'SAT') then
2057 		work_calendar(g_no_of_days)	:= 'Y';
2058 		g_no_of_work_days		:= g_no_of_work_days + 1;
2059 	else
2060 		work_calendar(g_no_of_days)	:= 'N';
2061 	end if;
2062 	-- ----dbms_output.PUT_LINE('Day ...Value ... ' || to_char(g_no_of_days) || ' ' || work_calendar(g_no_of_days));
2063 	l_low_date := l_low_date + 1;
2064  end loop;
2065 
2066 end;
2067 	End of comment for work schedules enh.	*****/
2068 
2069 PROCEDURE create_working_calendar (p_assignment_id	IN	NUMBER) IS
2070 CURSOR	business_days_cur IS
2071 SELECT	DECODE(psp_general.business_days(g_start_date + (ROWNUM-1), g_start_date + (ROWNUM-1), p_assignment_id), 1, 'Y', 'N')
2072 FROM	DUAL
2073 CONNECT BY 1=1
2074 AND	ROWNUM <= (g_end_date + 1) - g_start_date;
2075 BEGIN
2076 	OPEN business_days_cur;
2077 	FETCH business_days_cur BULK COLLECT INTO work_calendar;
2078 	CLOSE business_days_cur;
2079 
2080 	g_no_of_work_days := psp_general.business_days(g_start_date, g_end_date, p_assignment_id);
2081 	g_no_of_days := work_calendar.COUNT;
2082 
2083 	IF ((g_start_date = g_end_date) AND (NVL(g_entry_date_earned,g_start_date) = g_start_date)) THEN
2084 		g_no_of_work_days := 1;
2085 		work_calendar(1) := 'Y';
2086 	END IF;
2087 END create_working_calendar;
2088 
2089 --------------------------UPDATE_WCAL_ASG_END_DATE------------------------------
2090 --
2091 PROCEDURE update_wcal_asg_end_date(x_assignment_id IN NUMBER,
2092 					x_return_status OUT NOCOPY VARCHAR2) IS
2093 
2094 /* CURSOR get_asg_end_date_csr IS
2095 SELECT effective_end_date
2096 FROM	per_assignments_f
2097 WHERE assignment_id	= x_assignment_id and
2098 	effective_end_date = (select max(effective_end_date) from per_assignments_f
2099 				where effective_end_date between g_start_date and
2100 					g_end_date);
2101 */
2102 CURSOR get_asg_end_date_csr IS
2103 SELECT max(effective_end_date)
2104 FROM	per_assignments_f
2105 WHERE assignment_id	= x_assignment_id
2106 --	Introduced the following condition for bug fix 2439207
2107 AND	assignment_type = 'E';
2108 
2109 l_end_date	date;
2110 i		number(9)	:= 0;
2111 begin
2112  ----dbms_output.put_line('Entered Proceduer update_wcal_asg_end_date..');
2113  open get_asg_end_date_csr;
2114  fetch get_asg_end_date_csr into l_end_date;
2115  if get_asg_end_date_csr%FOUND then
2116 	if trunc(l_end_date) >= trunc(g_start_date) and
2117 	trunc(l_end_date) <= trunc(g_end_date) then
2118 	------dbms_output.put_line('Entered IF..');
2119 -- In order to take of terminated date .... plus one has been changed to plus two
2120 	i	:= (trunc(l_end_date) - trunc(g_start_date)) + 2;
2121 	while i <= g_no_of_days loop
2122 		if work_calendar(i) = 'Y' then
2123 		g_no_of_person_work_days	:= g_no_of_person_work_days - 1;
2124 		work_calendar(i) := 'N';
2125 		------dbms_output.put_line('Work Calendar ' || to_char(i) || '	N ');
2126 		end if;
2127 		i	:= i + 1;
2128 	end loop;
2129 	end if;
2130  end if;
2131  close get_asg_end_date_csr;
2132  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2133  return;
2134 EXCEPTION
2135  WHEN OTHERS then
2136 	------dbms_output.put_line('When others Error...........');
2137 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','UPDATE_WCAL_ASG_END_DATE');
2138 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
2139 
2140 end;
2141 
2142 --------------------------UPDATE_WCAL_ASG_BEGIN_DATE------------------------------
2143 --
2144 PROCEDURE update_wcal_asg_begin_date(x_assignment_id IN NUMBER,
2145 					x_return_status OUT NOCOPY VARCHAR2) IS
2146 
2147 /* CURSOR get_asg_end_date_csr IS
2148 SELECT effective_end_date
2149 FROM	per_assignments_f
2150 WHERE assignment_id	= x_assignment_id and
2151 	effective_end_date = (select max(effective_end_date) from per_assignments_f
2152 				where effective_end_date between g_start_date and
2153 					g_end_date);
2154 
2155 
2156 CURSOR get_asg_begin_date_csr IS
2157 SELECT min(date_start)
2158 FROM	per_periods_of_service
2159 WHERE	person_id = x_person_id and
2160 	(date_start between g_start_date and g_end_date) ;
2161 */
2162 
2163 ---- removed cursor begin_date_mid_payroll_csr for 4670588
2164 -- that cusor had a check effective_start_date between g_Start_date and
2165  ----- g_end_date, that was causing the problem
2166 CURSOR get_asg_begin_date_csr IS
2167 SELECT min(effective_start_date)
2168 FROM	per_assignments_f
2169 WHERE	assignment_id = x_assignment_id
2170 AND	payroll_id = l_payroll_id	-- 3922347
2171 --	Introduced the following condition for bug fix 2439207
2172 AND	assignment_type = 'E';
2173 
2174 l_begin_date	date;
2175 i		number(9)	:= 1;
2176 n		number(9)	:= 0;
2177 
2178 /*
2179 l_begin_date	date		:= g_start_date;
2180 i		number(9)	:= 0;
2181 n		number(9)	:= 0;
2182 */
2183 
2184 begin
2185  hr_utility.trace('	assignment_id = '||x_assignment_id);
2186 	l_begin_date := null;
2187 
2188  ----dbms_output.put_line('Entered Proceduer update_wcal_asg_begin_date..');
2189  open get_asg_begin_date_csr;
2190  fetch get_asg_begin_date_csr into l_begin_date;
2191  close get_asg_begin_date_csr;
2192  ---hr_utility.trace('	asg begin date = '||l_begin_date);
2193  ---hr_utility.trace('	g date = '||g_start_date||','||g_end_date);
2194 	/*
2195 	if trunc(l_begin_date) != trunc(g_start_date) then
2196 	----dbms_output.put_line('Entered IF..');
2197 	n	:= (trunc(l_begin_date) - trunc(g_start_date)) ;
2198 	FOR i in 1..n	loop
2199 		if work_calendar(i) = 'Y' then
2200 		g_no_of_person_work_days	:= g_no_of_person_work_days - 1;
2201 		work_calendar(i) := 'N';
2202 		----dbms_output.put_line('Work Calendar ' || to_char(i) || '	N ');
2203 		end if; -- Work_calendar(i)
2204 	end loop;
2205 	end if;
2206 */
2207 
2208 
2209 --Changed by Subha to fix Caltech's problem of incorrect daily rate calculation
2210 
2211 if l_begin_date is not null then
2212 	-- ------dbms_output.put_line('after open cursor');
2213 	if trunc(l_begin_date) >= trunc(g_start_date) and
2214 	trunc(l_begin_date) <= trunc(g_end_date) then
2215 	n:= (trunc(l_begin_date)-trunc(g_start_date)) + 1;
2216 
2217 	while i < n loop
2218 		if work_calendar(i)='Y' then
2219 		g_no_of_person_work_days:= g_no_of_person_work_days - 1;
2220 		work_calendar(i):= 'N';
2221 		hr_utility.trace('	i = N, i = '||i);
2222 		-- ------dbms_output.put_line('Work Calendar' ||to_char(i)||' N');
2223 		end if;
2224 		i:= i+1;
2225 	end loop;
2226 	end if;
2227 end if;
2228  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2229  return;
2230 EXCEPTION
2231  WHEN OTHERS then
2232 	-- ------dbms_output.put_line('When others Error...........'||SUBSTR(SQLERRM,1,200));
2233 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','UPDATE_WCAL_ASG_BEGIN_DATE',SUBSTR(SQLERRM,1,100));
2234 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
2235 
2236 end;
2237 
2238 /*
2239 --------------------------UPDATE_WCAL_ASG_BEGIN_DATE------------------------------
2240 --
2241 PROCEDURE update_wcal_asg_begin_date(x_person_id IN NUMBER,
2242 					x_return_status OUT NOCOPY VARCHAR2) IS
2243 
2244  CURSOR get_asg_end_date_csr IS
2245 SELECT effective_end_date
2246 FROM	per_assignments_f
2247 WHERE assignment_id	= x_assignment_id and
2248 	effective_end_date = (select max(effective_end_date) from per_assignments_f
2249 				where effective_end_date between g_start_date and
2250 					g_end_date);
2251 
2252 
2253 CURSOR get_asg_begin_date_csr IS
2254 SELECT min(date_start)
2255 FROM	per_periods_of_service
2256 WHERE	person_id = x_person_id and
2257 		(date_start between g_start_date and g_end_date) ;
2258 
2259 l_begin_date	date;
2260 i		number(9)	:= 0;
2261 n		number(9)	:= 0;
2262 begin
2263  ----dbms_output.put_line('Entered Proceduer update_wcal_asg_begin_date..');
2264  open get_asg_begin_date_csr;
2265  fetch get_asg_begin_date_csr into l_begin_date;
2266  if get_asg_begin_date_csr%FOUND then
2267 	if trunc(l_begin_date) >= trunc(g_start_date) and
2268 	trunc(l_begin_date) <= trunc(g_end_date) then
2269 	----dbms_output.put_line('Entered IF..');
2270 -- In order to take of terminated date .... plus one has been changed to plus two
2271 	n	:= (trunc(l_begin_date) - trunc(g_start_date)) ;
2272 	FOR i in 1..n	loop
2273 		if work_calendar(i) = 'Y' then
2274 		g_no_of_person_work_days	:= g_no_of_person_work_days - 1;
2275 		work_calendar(i) := 'N';
2276 		----dbms_output.put_line('Work Calendar ' || to_char(i) || '	N ');
2277 		end if;
2278 --		i	:= i + 1;
2279 	end loop;
2280 	end if;
2281  end if;
2282  close get_asg_begin_date_csr;
2283  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2284  return;
2285 EXCEPTION
2286  WHEN OTHERS then
2287 	----dbms_output.put_line('When others Error...........');
2288 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','UPDATE_WCAL_ASG_BEGIN_DATE');
2289 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
2290 
2291 end;
2292 */
2293 ---------------------------UPDATE_WCAL_ASG_STATUS-----------------------------------
2294 --
2295 PROCEDURE	UPDATE_WCAL_ASG_STATUS(x_assignment_id IN NUMBER,
2296 					x_return_status OUT NOCOPY VARCHAR2) IS
2297 
2298 CURSOR get_asg_status_csr IS
2299 SELECT	effective_start_date,	effective_end_date
2300 FROM	per_assignments_f
2301 WHERE	assignment_id = x_assignment_id and
2302 	(g_start_date between effective_start_date and effective_end_date or
2303 	g_end_date	between effective_start_date and effective_end_date or
2304 	(g_start_date <= effective_start_date and	g_end_date >= effective_end_date )) and
2305 	assignment_status_type_id in (select assignment_status_type_id
2306 					from per_assignment_status_types
2307 					where per_system_status in ('SUSP_ASSIGN','TERM_ASSIGN') );
2308 
2309 l_start_date	date;
2310 l_end_date	date;
2311 i		number(9)	:= 0;
2312 i2		number(9)	:= 0;
2313 
2314 begin
2315  ----dbms_output.put_line('Entered Proceduer update_wcal_asg_status..');
2316  open get_asg_status_csr;
2317  LOOP
2318 	fetch get_asg_status_csr into l_start_date,l_end_date;
2319 	EXIT WHEN get_asg_status_csr%NOTFOUND;
2320 	if trunc(l_start_date) <= trunc(g_start_date) then
2321 	l_start_date := trunc(g_start_date);
2322 	else
2323 	l_start_date := trunc(l_start_date);
2324 	end if;
2325 
2326 	if trunc(l_end_date) >= trunc(g_end_date) then
2327 	l_end_date	:= trunc(g_end_date);
2328 	else
2329 	l_end_date	:= trunc(l_end_date);
2330 	end if;
2331 	i	:= (l_start_date - g_start_date) + 1;
2332 	i2	:= (l_end_date	- g_start_date) + 1;
2333 	while i <= i2 loop
2334 	if work_calendar(i) = 'Y' then
2335 	g_no_of_person_work_days	:= g_no_of_person_work_days - 1;
2336 	work_calendar(i) := 'N';
2337 	--	----dbms_output.put_line('Work Calendar ' || to_char(i) || '	N ');
2338 	end if;
2339 	i	:= i + 1;
2340 	end loop;
2341  END LOOP;
2342  close get_asg_status_csr;
2343  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2344  return;
2345  EXCEPTION
2346 	WHEN OTHERS then
2347 	close get_asg_status_csr;
2348 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','UPDATE_WCAL_ASG_STATUS');
2349 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2350 	return;
2351 end UPDATE_WCAL_ASG_STATUS;
2352 --
2353 ----------------------CREATE_DAILY_RATE_CALENDAR---------------------------
2354 PROCEDURE	CREATE_DAILY_RATE_CALENDAR(x_assignment_id	IN NUMBER,
2355 					x_time_period_id	IN NUMBER,
2356 					x_element_type_id	IN NUMBER,
2357 					x_return_status		OUT NOCOPY VARCHAR2) IS
2358 
2359 -- Get salary details from per_pay_proposals
2360 /*
2361 CURSOR get_proposal_csr is
2362 SELECT distinct proposed_salary, previous_salary,
2363 	change_date,last_change_date,pay_basis
2364 FROM	per_pay_proposals_v
2365 WHERE assignment_id	= x_assignment_id and
2366 	element_type_id = x_element_type_id and
2367 	approved='Y' and
2368 	change_date between (trunc(g_start_date)+1) and g_end_date
2369 ORDER BY change_date;
2370 
2371 
2372 get_proposal_rec get_proposal_csr%ROWTYPE;
2373 
2374 */
2375 
2376 CURSOR get_proposal_csr is
2377 select ppp.proposed_salary_n proposed_salary, ppp.change_date, ppb.pay_basis
2378  from per_pay_proposals ppp,
2379 	pay_input_values_f piv,
2380 	per_pay_bases ppb,
2381 	per_all_assignments_f paf
2382  where paf.assignment_id = x_assignment_id
2383  and ppp.change_date between paf.effective_start_date and
2384 paf.effective_end_date
2385  and paf.pay_basis_id = ppb.pay_basis_id
2386  and ppp.assignment_id = x_assignment_id
2387  and piv.element_type_id = x_element_type_id
2388  and ppp.approved = 'Y'
2389  --and ppp.change_date <= :g_start_date
2390  and ppp.change_date between (trunc(g_Start_date)+1) and g_end_date
2391  --and ppb.pay_basis_id = :p_pay_basis_id
2392  and ppb.input_value_id = piv.input_value_id
2393  and ppp.change_date
2394 	between piv.effective_start_date and piv.effective_end_date
2395  order by ppp.change_date ;
2396 
2397 get_proposal_rec get_proposal_csr%ROWTYPE;
2398 
2399 
2400 
2401 CURSOR get_proposal_prevsal_csr(p_change_date in date ) is
2402 select ppp.proposed_salary_n previous_salary, ppp.change_date last_change_date
2403  from per_pay_proposals ppp,
2404 	pay_input_values_f piv,
2405 	per_pay_bases ppb,
2406 	per_all_assignments_f paf
2407  where paf.assignment_id = x_assignment_id
2408  and ppp.change_date between paf.effective_start_date and
2409 paf.effective_end_date
2410  and paf.pay_basis_id = ppb.pay_basis_id
2411  and ppp.assignment_id = x_assignment_id
2412  and piv.element_type_id = x_element_type_id
2413 and ppp.approved = 'Y'
2414 --and ppp.change_date between (trunc(g_Start_date)+1) and g_end_date
2415  and ppp.change_date < p_change_date
2416  --and ppb.pay_basis_id = :p_pay_basis_id
2417  and ppb.input_value_id = piv.input_value_id
2418  and ppp.change_date
2419 	between piv.effective_start_date and piv.effective_end_date
2420  order by ppp.change_date desc;
2421 
2422 get_proposal_prevsal_rec get_proposal_prevsal_csr%ROWTYPE;
2423 
2424 /*
2425 CURSOR get_previous_proposal_csr is
2426 SELECT distinct proposed_salary, change_date, pay_basis
2427 FROM	per_pay_proposals_v
2428 WHERE assignment_id	= x_assignment_id and
2429 	element_type_id = x_element_type_id and
2430 	change_date <= g_start_date and
2431 	approved = 'Y' order by change_date desc ;
2432 -- and
2433 --	change_date = (select max(change_date)
2434 --			from per_pay_proposals_v
2435 --			where assignment_id = x_assignment_id and
2436 --				change_date <= g_start_date and approved = 'Y');
2437 */
2438 
2439 CURSOR get_previous_proposal_csr is
2440 select ppp.proposed_salary_n proposed_salary, ppp.change_date, ppb.pay_basis
2441  from per_pay_proposals ppp,
2442 	pay_input_values_f piv,
2443 	per_pay_bases ppb,
2444 	per_all_assignments_f paf
2445  where paf.assignment_id =x_assignment_id
2446  and ppp.change_date between paf.effective_start_date and
2447 paf.effective_end_date
2448  and paf.pay_basis_id = ppb.pay_basis_id
2449  and ppp.assignment_id = x_assignment_id
2450  and piv.element_type_id = x_element_type_id
2451  and ppp.approved = 'Y'
2452  --and ppp.change_date <= :g_start_date
2453  and ppp.change_date =
2454 		(select max(change_date)
2455 		from per_pay_proposals ppp1
2456 		where ppp1.assignment_id = x_assignment_id
2457 		and ppp1.approved = 'Y'
2458 		and ppp1.change_date <= g_start_date)
2459  --and ppb.pay_basis_id = :p_pay_basis_id
2460  and ppb.input_value_id = piv.input_value_id
2461  and ppp.change_date
2462 	between piv.effective_start_date and piv.effective_end_date
2463  order by ppp.change_date desc;
2464 get_previous_proposal_rec get_previous_proposal_csr%ROWTYPE;
2465 
2466 
2467 
2468 CURSOR	get_no_per_fiscal_year_csr is
2469 SELECT number_per_fiscal_year
2470 FROM	per_time_period_types
2471 WHERE	period_type = (select period_type from per_time_periods
2472 			where time_period_id = x_time_period_id);
2473 
2474 --
2475 l_no_fiscal_year	number		:= 0;
2476 l_daily_rate		NUMBER	:= 0;	-- Corrected datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2477 l_change_start_date	date		:= NULL;
2478 l_previous_salary	NUMBER	:= 0;	-- Corrected datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2479 i			number(3)	:= 0;
2480 j number(3)				:=0 ;	-- new variable for bug fix 2426329
2481 -- Added the following variable to fix assignment start date is in between
2482 -- payroll period
2483 l_non_working_day_flag	number := 0;
2484 --
2485 
2486 Begin
2487  --dbms_output.put_line('Entered Proceduer create_daily_rate_calendar..');
2488  --dbms_output.PUT_LINE(' Just entered... ' );
2489 -- --dbms_output.PUT_LINE(' time period id ' || to_char(x_time_period_id));
2490 ----dbms_output.put_line('assignment_id '||to_char(x_assignment_id));
2491 ----dbms_output.put_line('element type id '||to_char(x_element_type_id));
2492 ----dbms_output.put_line('g_start_date '||to_char(g_start_date,'YYYY/MM/DD HH24:MI:SS'));
2493 ----dbms_output.put_line('g_end_date '||to_char(g_end_date,'YYYY/MM/DD HH24:MI:SS'));
2494 
2495 
2496  open get_no_per_fiscal_year_csr;
2497  --dbms_output.PUT_LINE(' open get_proposal_csr; ' );
2498  fetch get_no_per_fiscal_year_csr into l_no_fiscal_year;
2499  --dbms_output.PUT_LINE(' Just entered... ' );
2500  if get_no_per_fiscal_year_csr%NOTFOUND then
2501 	FND_MESSAGE.Set_Name('PSP', 'PSP_PI_NO_PERIOD_TYPES');
2502 	FND_MESSAGE.Set_Token('TIME_PERIOD_ID',x_time_period_id);
2503 	FND_MSG_PUB.Add;
2504 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2505  end if;
2506  close get_no_per_fiscal_year_csr;
2507  --dbms_output.PUT_LINE('No. of periods for fiscal year...	' || to_char(l_no_fiscal_year));
2508  l_change_start_date	:= trunc(g_start_date);
2509 	--dbms_output.put_line('before get_proposal_Cusror');
2510 
2511  open get_proposal_csr;
2512  fetch get_proposal_csr into get_proposal_rec;
2513  if get_proposal_csr%NOTFOUND then
2514 	--dbms_output.put_line('no data found');
2515 	close get_proposal_csr;
2516 	raise NO_DATA_FOUND;
2517  end if;
2518  close get_proposal_csr;
2519 
2520  open get_proposal_csr;
2521  --dbms_output.PUT_LINE(' after open get_proposal_csr; ' );
2522  --dbms_output.PUT_LINE(' Assignment ID	' || to_char(x_assignment_id));
2523  --dbms_output.PUT_LINE(' element_type_id ' || to_char(x_element_type_id));
2524  --dbms_output.PUT_LINE(' time period id ' || to_char(x_time_period_id));
2525 
2526  loop
2527 	fetch get_proposal_csr into get_proposal_rec;
2528 	--dbms_output.PUT_LINE('fetch get_proposal_csr into get_proposal_rec' );
2529 
2530 	EXIT WHEN get_proposal_csr%NOTFOUND;
2531 	l_non_working_day_flag := 0;
2532 
2533 
2534  open get_proposal_prevsal_csr(get_proposal_rec.change_date);
2535  fetch get_proposal_prevsal_csr into get_proposal_prevsal_rec;
2536  if get_proposal_prevsal_csr%NOTFOUND then
2537 	--dbms_output.put_line('no data found');
2538 null;
2539 	-- close get_proposal_prevsal_csr;
2540  --	raise NO_DATA_FOUND;
2541 -- exit;
2542  end if;
2543  close get_proposal_prevsal_csr;
2544 	--dbms_output.PUT_LINE(' There is a record in per_pay_proposals' );
2545 	----dbms_output.PUT_LINE('Proposed Salary	' || get_proposal_rec.proposed_salary);
2546 	----dbms_output.PUT_LINE('Previous Salary	' || get_proposal_prevsal_rec.previous_salary);
2547 	----dbms_output.PUT_LINE('Change Date	' || to_char(get_proposal_rec.change_date,'YYYY/MM/DD'));
2548 	--dbms_output.PUT_LINE('L Change Date	' || to_char(get_proposal_rec.last_change_date,'YYYY/MM/DD'));
2549 
2550 	i := ( trunc(l_change_start_date) - trunc(g_start_date) ) + 1;
2551 	----dbms_output.PUT_LINE('i	............' || to_char(i));
2552 
2553 -- Added the following if statement to fix the bug no. 710248, 710257
2554 	if i < 1 then
2555 	i := 1;
2556 	end if;
2557 
2558 	j:= i; -- bug fix 2426329
2559 	----dbms_output.PUT_LINE('i	............' || to_char(i));
2560 	if NVL(get_proposal_rec.pay_basis,' ') = 'ANNUAL' then
2561 	--dbms_output.PUT_LINE('Pay basis ANNUAL	');
2562 	--dbms_output.PUT_LINE('Salary	' || get_proposal_rec.previous_salary);
2563 	if NVL(to_number(get_proposal_prevsal_rec.previous_salary),0) = 0 then
2564 	l_previous_salary	:= 0.00;
2565 	l_non_working_day_flag := 1;
2566 	else
2567 	l_previous_salary	:= to_number(get_proposal_prevsal_rec.previous_salary) / l_no_fiscal_year;
2568 	end if;
2569 	----dbms_output.PUT_LINE('Previous salary	' || to_char(l_previous_salary));
2570 	elsif NVL(get_proposal_rec.pay_basis,' ') = 'MONTHLY' then
2571 	--dbms_output.PUT_LINE('Pay basis MONTHLY	');
2572 	if NVL(to_number(get_proposal_prevsal_rec.previous_salary),0) = 0 then
2573 	l_previous_salary	:= 0.00;
2574 	l_non_working_day_flag := 1;
2575 	else
2576 	l_previous_salary	:= (to_number(get_proposal_prevsal_rec.previous_salary) * 12) / l_no_fiscal_year;
2577 	end if;
2578 	else
2579 
2580 	if NVL(to_number(get_proposal_prevsal_rec.previous_salary),0) = 0 then
2581 	l_previous_salary	:= 0.00;
2582 	l_non_working_day_flag := 1;
2583 
2584 	end if;	-- added for bug fix 2426329
2585 
2586 	while j <= g_no_of_days loop	-- changed to j for bug fix 2426329
2587 		daily_calendar(j) := 0.00;
2588 		j	:= j + 1;
2589 	end loop;
2590 
2591 	--	exit;	commented out NOCOPY for bug fix 2426329
2592 	end if;
2593 -- Changed if NVL(l_daily_rate) to if NVL(l_previous_salary) in order to fix Bug No. 709900
2594 	if NVL(l_previous_salary,0) <> 0.00 then
2595 
2596 	l_daily_rate	:= round((l_previous_salary / g_no_of_work_days), g_ext_precision);
2597 	else
2598 	l_daily_rate	:= 0.00;
2599 	end if;
2600 	----dbms_output.PUT_LINE( 'Daily Rate ' || to_char(l_daily_rate));
2601 
2602 	while trunc(l_change_start_date) < trunc(get_proposal_rec.change_date) loop
2603 	if work_calendar(i)	= 'Y' then
2604 	if l_non_working_day_flag = 1 then
2605 -- flag is 1 means no salary for this period
2606 		work_calendar(i) := 'N';
2607 		daily_calendar(i) := 0.00;
2608 --		daily_calendar(i) := NVL(l_daily_rate,0.00);
2609 	else
2610 	daily_calendar(i) := NVL(l_daily_rate,0.00);
2611 	end if;
2612 	else
2613 	daily_calendar(i) := 0.00;
2614 	end if;
2615 	i	:= i + 1;
2616 	----dbms_output.PUT_LINE('i	............' || to_char(i));
2617 	l_change_start_date := trunc(l_change_start_date) + 1;
2618 	----dbms_output.PUT_LINE('i	............' || to_char(l_change_start_date));
2619 	end loop;
2620 	l_change_start_date	:= trunc(get_proposal_rec.change_date);
2621  end loop;
2622  ----dbms_output.PUT_LINE( 'Just Crossed end loop ');
2623 
2624  if NVL(get_proposal_rec.pay_basis,' ') = 'ANNUAL' then
2625 	if NVL(to_number(get_proposal_rec.proposed_salary),0) = 0 then
2626 	l_previous_salary	:= 0.00;
2627 	else
2628 	l_previous_salary	:= to_number(get_proposal_rec.proposed_salary) / l_no_fiscal_year;
2629 	end if;
2630  elsif NVL(get_proposal_rec.pay_basis,' ') = 'MONTHLY' then
2631 	if NVL(to_number(get_proposal_rec.proposed_salary),0) = 0 then
2632 		l_previous_salary	:= 0.00;
2633 	else
2634 	l_previous_salary	:= (to_number(get_proposal_rec.proposed_salary) * 12) / l_no_fiscal_year;
2635 	end if;
2636  else
2637 	l_previous_salary	:= 0.00;
2638  end if;
2639  --dbms_output.PUT_LINE( 'L Previous Salary ' || to_char(l_previous_salary));
2640  if NVL(l_previous_salary,0) <> 0.00 then
2641 
2642 	l_daily_rate	:= round((l_previous_salary / g_no_of_work_days), g_ext_precision);
2643 
2644  else
2645 	l_daily_rate	:= 0.00;
2646  end if;
2647  ----dbms_output.PUT_LINE( 'L daily rate ' || to_char(l_daily_rate));
2648  i := ( trunc(l_change_start_date) - trunc(g_start_date) ) + 1;
2649  ----dbms_output.PUT_LINE('i	............' || to_char(i));
2650 
2651  while l_change_start_date <= trunc(g_end_date) loop
2652 	if work_calendar(i)	= 'Y' then
2653 	daily_calendar(i) := l_daily_rate;
2654 	else
2655 	daily_calendar(i) := 0.00;
2656 	end if;
2657 	i	:= i + 1;
2658 	--dbms_output.PUT_LINE('i	............' || to_char(i));
2659 	l_change_start_date := l_change_start_date + 1;
2660 	--dbms_output.PUT_LINE('i	............' || to_char(l_change_start_date,'YYYY/MM/DD HH24:MI:SS'));
2661  end loop;
2662 
2663  close get_proposal_csr;
2664  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2665  EXCEPTION
2666 	WHEN NO_DATA_FOUND then
2667 	begin
2668 	i := 1;
2669 	--dbms_output.PUT_LINE( '	When no_data_found' );
2670 	open get_previous_proposal_csr;
2671 	fetch get_previous_proposal_csr into get_previous_proposal_rec;
2672 	if get_previous_proposal_csr%NOTFOUND then
2673 	for i in 1..g_no_of_days loop
2674 		daily_calendar(i) := 0.00;
2675 	end loop;
2676 	else
2677 	begin
2678 	--dbms_output.PUT_LINE( '	else of if get_previous_proposal_csr%NOTFOUND then' );
2679 		if NVL(get_previous_proposal_rec.pay_basis,' ') = 'ANNUAL' then
2680 		if NVL(to_number(get_previous_proposal_rec.proposed_salary),0) = 0 then
2681 		l_previous_salary	:= 0.00;
2682 		else
2683 		l_previous_salary	:= to_number(get_previous_proposal_rec.proposed_salary) / l_no_fiscal_year;
2684 		end if;
2685 	elsif NVL(get_previous_proposal_rec.pay_basis,' ') = 'MONTHLY' then
2686 		if NVL(to_number(get_previous_proposal_rec.proposed_salary),0) = 0 then
2687 		l_previous_salary	:= 0.00;
2688 		else
2689 		l_previous_salary	:= (to_number(get_previous_proposal_rec.proposed_salary) * 12) / l_no_fiscal_year;
2690 		end if;
2691 		else
2692 		while i <= g_no_of_days loop
2693 		daily_calendar(i) := 0.00;
2694 		i	:= i + 1;
2695 		end loop;
2696 		l_previous_salary	:= 0.00;
2697 		end if;
2698 		if NVL(l_previous_salary,0) <> 0.00 then
2699 		l_daily_rate	:= ROUND((l_previous_salary / g_no_of_work_days), g_ext_precision);	-- Introduced g_ext_precision for bug fix 2916848
2700 		else
2701 		l_daily_rate	:= 0.00;
2702 		end if;
2703 		for i in 1..g_no_of_days loop
2704 		if work_calendar(i)	= 'Y' then
2705 			daily_calendar(i) := l_daily_rate;
2706 		else
2707 			daily_calendar(i) := 0.00;
2708 		end if;
2709 		--dbms_output.PUT_LINE( 'Daily Rate	i ' || to_char(i) || ' ' || to_char(daily_calendar(i)));
2710 		end loop;
2711 		end;
2712 	end if;
2713 	end;
2714 	--dbms_output.PUT_LINE( 'Daily Rate	' || to_char(l_daily_rate));
2715 	--dbms_output.PUT_LINE( 'Previous Salary ' || to_char(l_previous_salary));
2716 	close get_previous_proposal_csr;
2717 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2718  WHEN FND_API.G_EXC_UNEXPECTED_ERROR then
2719 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_DAILY_RATE_CALENDAR');
2720 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
2721 
2722  WHEN OTHERS then
2723 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_DAILY_RATE_CALENDAR');
2724 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
2725 
2726 end create_daily_rate_calendar;
2727 ----------------CALCULATE_BALANCE_AMOUNT--------------------------------
2728 --
2729 PROCEDURE CALCULATE_BALANCE_AMOUNT(x_pay_amount IN NUMBER,
2730 					x_balance_amount OUT NOCOPY NUMBER,
2731 				x_return_status OUT NOCOPY VARCHAR2) IS
2732 i		number(4)	:= 0;
2733 l_total_salary	number(22,2)	:= 0.00;
2734 
2735 begin
2736 
2737  ----dbms_output.PUT_LINE(' Just entered calculate_balance_amount proc... ' );
2738  ----dbms_output.PUT_LINE('g_no_of_days ' || to_char(g_no_of_days));
2739  hr_utility.trace('	Entering CALCULATE_BALANCE_AMOUNT');
2740 
2741  for i in 1..g_no_of_days loop
2742 	----dbms_output.PUT_LINE('Daily Amount ' || to_char(i) || ' ' || to_char(daily_calendar(i)));
2743 	l_total_salary	:= l_total_salary + daily_calendar(i);
2744  end loop;
2745 
2746  ----dbms_output.PUT_LINE(' l_total_salary ... ' || to_char(l_total_salary) );
2747  ----dbms_output.PUT_LINE(' Crossed for loop ... ' );
2748 
2749 
2750  if round(l_total_salary, g_precision) <> round(x_pay_amount, g_precision) then	-- corrected rounding off precision to currency precision for bug fix 2916848
2751 	x_balance_amount	:= x_pay_amount - l_total_salary;
2752  else
2753 	x_balance_amount	:= 0.00;
2754  end if;
2755  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
2756 
2757  hr_utility.trace('	Leaving CALCULATE_BALANCE_AMOUNT');
2758 
2759 EXCEPTION
2760 	WHEN OTHERS then
2761 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CALCULATE_BALANCE_AMOUNT');
2762 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
2763 
2764 end calculate_balance_amount;
2765 --------------CREATE_SLINE_SALARY_CHANGE-----------------------------------
2766 --
2767 /*Bug 5642002: Added parameters x_start_date and x_end_date */
2768 PROCEDURE CREATE_SLINE_SALARY_CHANGE (x_payroll_line_id IN NUMBER,
2769 					x_start_date	IN DATE,
2770 					x_end_date	IN DATE,
2771 					x_return_status OUT NOCOPY VARCHAR2) IS
2772 
2773 
2774 CURSOR get_payroll_line_csr IS
2775 SELECT *
2776 FROM	psp_payroll_lines
2777 WHERE payroll_line_id	= x_payroll_line_id;
2778 
2779 g_payroll_line_rec get_payroll_line_csr%ROWTYPE;
2780 
2781 
2782 --SELECT change_date, previous_salary, proposed_salary
2783 /*
2784 
2785 CURSOR get_proposal_csr is
2786 SELECT proposed_salary,
2787  previous_salary,
2788  change_date,
2789  last_change_date,
2790  pay_basis
2791 FROM	per_pay_proposals_v
2792 WHERE assignment_id = g_payroll_line_rec.assignment_id and
2793 	element_type_id = g_payroll_line_rec.element_type_id and
2794 	approved = 'Y' and
2795 	change_date between (trunc(g_start_date)+1) and g_end_date
2796 ORDER BY change_date;
2797 */
2798 
2799 
2800 
2801 CURSOR get_proposal_csr is
2802 select distinct ppp.proposed_salary_n proposed_salary, ppp.change_date
2803  from per_pay_proposals ppp,
2804 	pay_input_values_f piv,
2805 	per_pay_bases ppb,
2806 	per_all_assignments_f paf
2807  where paf.assignment_id = g_payroll_line_rec.assignment_id
2808  and ppp.change_date between paf.effective_start_date and
2809 paf.effective_end_date
2810  and paf.pay_basis_id = ppb.pay_basis_id
2811  and ppp.assignment_id = g_payroll_line_rec.assignment_id
2812  and piv.element_type_id = g_payroll_line_rec.element_type_id
2813 and ppp.approved = 'Y'
2814  --and ppp.change_date <= :g_start_date
2815  and ppp.change_date between (trunc(g_start_date)+1) and g_end_date
2816  --and ppb.pay_basis_id = :p_pay_basis_id
2817  and ppb.input_value_id = piv.input_value_id
2818  and ppp.change_date
2819 	between piv.effective_start_date and piv.effective_end_date
2820  order by ppp.change_date;
2821 
2822 get_proposal_rec get_proposal_csr%ROWTYPE;
2823 
2824 
2825 
2826 CURSOR get_proposal_prevsal_csr(p_change_date in date ) is
2827 select ppp.proposed_salary_n previous_salary, ppp.change_date last_change_date
2828  from per_pay_proposals ppp,
2829 	pay_input_values_f piv,
2830 	per_pay_bases ppb,
2831 	per_all_assignments_f paf
2832  where paf.assignment_id = g_payroll_line_rec.assignment_id
2833  and ppp.change_date between paf.effective_start_date and
2834 paf.effective_end_date
2835  and paf.pay_basis_id = ppb.pay_basis_id
2836  and ppp.assignment_id = g_payroll_line_rec.assignment_id
2837  and piv.element_type_id = g_payroll_line_rec.element_type_id
2838  and ppp.approved = 'Y'
2839  --and ppp.change_date <= :g_start_date
2840 -- and ppp.change_date between (trunc(g_start_date)+1) and g_end_date
2841 and ppp.change_date < p_change_date
2842  --and ppb.pay_basis_id = :p_pay_basis_id
2843  and ppb.input_value_id = piv.input_value_id
2844  and ppp.change_date
2845 	between piv.effective_start_date and piv.effective_end_date
2846  order by ppp.change_date desc;
2847 
2848 get_proposal_prevsal_rec get_proposal_prevsal_csr%ROWTYPE;
2849 
2850 
2851 l_change_date		date;
2852 l_salary		NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2853 l_proposed_salary	NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2854 --l_proposed_salary	varchar2(30);
2855 
2856 l_pay_basis1		varchar2(30):=NULL;
2857 l_last_change_date1 date;
2858 /*
2859 
2860 CURSOR get_previous_proposal_csr is
2861 SELECT change_date, proposed_salary
2862 FROM	per_pay_proposals_v
2863 WHERE	assignment_id = g_payroll_line_rec.assignment_id and
2864 	element_type_id	= g_payroll_line_rec.element_type_id and
2865 	change_date <= g_start_date and
2866 	approved = 'Y' and
2867 	change_date = (select max(change_date) from per_pay_proposals_v
2868 			where assignment_id = g_payroll_line_rec.assignment_id and
2869 			change_date <= g_start_date and approved = 'Y')
2870 ORDER BY change_date;
2871 
2872 CURSOR get_previous_proposal_csr is
2873 SELECT proposed_salary, change_date,pay_basis
2874 FROM	per_pay_proposals_v
2875 WHERE	assignment_id = g_payroll_line_rec.assignment_id and
2876 	element_type_id	= g_payroll_line_rec.element_type_id and
2877 	change_date <= g_start_date and
2878 	approved = 'Y'
2879 	order by change_date desc;
2880 */
2881 
2882 CURSOR get_previous_proposal_csr is
2883 select ppp.proposed_salary_n proposed_salary, ppp.change_date, ppb.pay_basis
2884  from per_pay_proposals ppp,
2885 	pay_input_values_f piv,
2886 	per_pay_bases ppb,
2887 	per_all_assignments_f paf
2888  where paf.assignment_id =g_payroll_line_rec.assignment_id
2889  and ppp.change_date between paf.effective_start_date and
2890 paf.effective_end_date
2891  and paf.pay_basis_id = ppb.pay_basis_id
2892  and ppp.assignment_id = g_payroll_line_rec.assignment_id
2893  and piv.element_type_id = g_payroll_line_rec.element_type_id
2894  and ppp.approved = 'Y'
2895  --and ppp.change_date <= :g_start_date
2896  and ppp.change_date =
2897 		(select max(change_date)
2898 		from per_pay_proposals ppp1
2899 		where ppp1.assignment_id = g_payroll_line_rec.assignment_id
2900 		and ppp1.approved = 'Y'
2901 		and ppp1.change_date <= g_start_date)
2902  --and ppb.pay_basis_id = :p_pay_basis_id
2903  and ppb.input_value_id = piv.input_value_id
2904  and ppp.change_date
2905 	between piv.effective_start_date and piv.effective_end_date
2906  order by ppp.change_date desc;
2907 get_previous_proposal_rec get_previous_proposal_csr%ROWTYPE;
2908 
2909 --
2910 i			number(3)	:= 0;
2911 l_rowid			varchar2(20)	:= NULL;
2912 l_sub_line_start_date	date;
2913 l_sub_line_end_date	date;
2914 l_sub_line_id		number(9)	:= 0;
2915 l_array_begin		number(4)	:= 0;
2916 l_array_end		number(4)	:= 0;
2917 l_rate_salary		NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2918 l_balance_salary	NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2919 l_daily_rate		NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2920 l_total_daily_rate	NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2921 l_daily_balance	NUMBER	:= 0;	-- Changed Datatype to NUMBER from NUMBER(22, 2) for bug fix 2916848
2922 l_work_days		number(4)	:= 0;
2923 l_total_work_days	number(3)	:= 0;
2924 l_paybasis varchar2(30);
2925 
2926 --
2927 BEGIN
2928  hr_utility.trace('	Entering CREATE_SLINE_SALARY_CHANGE');
2929  hr_utility.trace('	X_Payroll_line_id ...' || to_char(x_payroll_line_id));
2930  open get_payroll_line_csr;
2931  fetch get_payroll_line_csr into g_payroll_line_rec;
2932  if get_payroll_line_csr%NOTFOUND then
2933 	fnd_message.set_name('PSP', 'PSP_NO_PAYROLL_LINES');
2934 	fnd_msg_pub.add;
2935 	close get_payroll_line_csr;
2936 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2937  end if;
2938  close get_payroll_line_csr;
2939  ---hr_utility.trace('	Pay amount ..	' || to_char(g_payroll_line_rec.pay_amount));
2940  ---hr_utility.trace('	Balance amount .. ' || to_char(g_payroll_line_rec.balance_amount));
2941 
2942  l_sub_line_start_date	:= trunc(g_start_date);
2943 
2944  if round(g_payroll_line_rec.balance_amount, g_precision) <> 0.00 then	-- Modified rounding precision to currency precision for bug fix 2916848
2945 -- Added to fix Assignment start_date in payroll period
2946 	for i in 1..g_no_of_days loop
2947 	if work_calendar(i) = 'Y' then
2948 		l_total_work_days	:= l_total_work_days + 1;
2949 	end if;
2950 	end loop;
2951 	l_daily_balance	:= round((g_payroll_line_rec.balance_amount / l_total_work_days), g_ext_precision);
2952  else
2953 	l_daily_balance	:= 0.00;
2954  end if;
2955  ---hr_utility.trace('	Daily Balance..	' || to_char(l_daily_balance));
2956  ---hr_utility.trace('	Assignment_id ..	' || to_char(g_payroll_line_rec.assignment_id));
2957  ---hr_utility.trace('	Element type_id .. ' || to_char(g_payroll_line_rec.element_type_id));
2958  ---hr_utility.trace('	G_start_date	.. ' || to_char(g_start_date,'YYYY/MM/DD HH24:MI:SS'));
2959  ---hr_utility.trace('	G_end_date	..	' || to_char(g_end_date,'YYYY/MM/DD HH24:MI:SS'));
2960 
2961  open get_proposal_csr;
2962  --fetch geto _proposal_csr into l_change_date, l_salary, l_proposed_salary;
2963  fetch get_proposal_csr into
2964 	l_proposed_salary, l_change_date;
2965 	-- l_proposed_salary, l_salary, l_change_date;
2966  -- l_last_change_date1, l_pay_basis1;
2967 
2968  ---hr_utility.trace('	Just After fetch get_proposal l_change_date '||to_char(l_change_date) );
2969  ---hr_utility.trace('	Just After fetch get_proposal l_proposed_sal '||to_char(l_proposed_salary) );
2970  if get_proposal_csr%NOTFOUND then
2971 	close get_proposal_csr;
2972 	raise NO_DATA_FOUND;
2973  end if;
2974  close get_proposal_csr;
2975 
2976  hr_utility.trace('	Just crossed NOTFOUND if' );
2977 
2978  open get_proposal_csr;
2979  loop
2980 	hr_utility.trace('	Just entered Loop ' );
2981 --	fetch get_proposal_csr into l_change_date, l_salary, l_proposed_salary;
2982 
2983 
2984  fetch get_proposal_csr into
2985 	l_proposed_salary, l_change_date;
2986 --	l_proposed_salary, l_salary, l_change_date,
2987  --	l_last_change_date1, l_pay_basis1;
2988 
2989 	EXIT WHEN get_proposal_csr%NOTFOUND;
2990 ---	hr_utility.trace('	After Exit When' );
2991 
2992 	---hr_utility.trace('	proposed salary inside loop '||to_char(l_proposed_salary));
2993 	---hr_utility.trace('	change_date is inside loop '||to_char(l_change_date));
2994 
2995  open get_proposal_prevsal_csr(l_change_date);
2996  fetch get_proposal_prevsal_csr into get_proposal_prevsal_rec;
2997  if get_proposal_prevsal_csr%NOTFOUND then
2998  ---	hr_utility.trace('	no data found');
2999  --	close get_proposal_prevsal_csr;
3000  --	raise NO_DATA_FOUND;
3001 --exit;
3002 	null;
3003  end if;
3004  close get_proposal_prevsal_csr;
3005 
3006 	l_salary:=nvl(get_proposal_prevsal_rec.previous_salary, 0);
3007  ---hr_utility.trace('	 sal from previous '||to_char(l_salary));
3008 
3009 
3010 
3011 	l_work_days		:= 0;
3012 	l_rate_salary	:= 0.00;
3013 	l_array_begin	:= (trunc(l_sub_line_start_date) - trunc(g_start_date)) + 1;
3014 	hr_utility.trace('	l_arry_begin .......' || to_char(l_array_begin));
3015 	l_array_end		:= (trunc(l_change_date) - trunc(g_start_date));
3016 	l_sub_line_end_date	:= trunc(l_change_date) - 1;
3017 	hr_utility.trace('	i......... ' || to_char(i));
3018 	for i in l_array_begin..l_array_end loop
3019 	l_rate_salary	:= l_rate_salary + daily_calendar(i);
3020 -- commented the following line and added it in the following if
3021 -- the reason is if the last date is non working day, in sub lines
3022 -- it is writing daily rate as 0
3023 --	l_daily_rate	:= daily_calendar(i);
3024 	if work_calendar(i) = 'Y' then
3025 		l_work_days	:= l_work_days + 1;
3026 	l_daily_rate	:= daily_calendar(i);
3027 	end if;
3028 	end loop;
3029 
3030 	if round(g_payroll_line_rec.balance_amount, g_precision) <> 0.00 then	-- Modified rounding precision to currency precision for bug fix 2916848
3031 	-- l_balance_salary	:= l_daily_balance * l_work_days ;
3032 
3033 	l_balance_salary := round(l_daily_balance * l_work_days, g_precision);	-- bug 3109943
3034 	else
3035 	l_balance_salary := 0.00;
3036 	end if;
3037 
3038 	---hr_utility.trace('	Daily Balance ..' || to_char(l_daily_balance));
3039 	---hr_utility.trace('	Rate Salary ..' || to_char(l_rate_salary));
3040 	hr_utility.trace('	Balance Salary ..' || to_char(l_balance_salary));
3041 	if round((l_rate_salary + l_balance_salary),0) = 0 then
3042 	l_total_daily_rate := 0.00;
3043 	else
3044 	l_total_daily_rate := l_daily_rate + l_daily_balance;
3045 	end if;
3046 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3047 	FROM DUAL;
3048 	---hr_utility.trace('	Sub line		' || to_char(l_sub_line_id));
3049 	hr_utility.trace('	inserting into Sublines -1');
3050 	if l_total_daily_Rate > 0 then
3051 
3052 	PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3053 			X_ROWID				=> l_rowid,
3054 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3055 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3056 			X_SUB_LINE_START_DATE		=> l_sub_line_start_date,
3057 			X_SUB_LINE_END_DATE		=> l_sub_line_end_date,
3058 			X_REASON_CODE			=> 'SALARY_CHANGE',
3059 			X_PAY_AMOUNT			=> round((l_rate_salary + l_balance_salary), g_precision),	-- bug 3109943
3060 			X_DAILY_RATE			=> l_total_daily_rate,
3061 			X_SALARY_USED			=> NVL(l_salary,0),
3062 			X_CURRENT_SALARY		=> NVL(l_salary,0),
3063 			X_FTE				=> NULL,
3064 			X_ORGANIZATION_ID		=> NULL,
3065 			X_JOB_ID			=> NULL,
3066 			X_POSITION_ID			=> NULL,
3067 			X_GRADE_ID			=> NULL,
3068 			X_PEOPLE_GRP_ID		=> NULL,
3069 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3070 			X_EMPLOYMENT_END_DATE		=> NULL,
3071 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3072 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3073 			X_ASSIGNMENT_BEGIN_DATE		=> NULL,
3074 			X_ASSIGNMENT_END_DATE		=> NULL,
3075 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3076 			x_attribute1			=> NULL,
3077 			x_attribute2			=> NULL,
3078 			x_attribute3			=> NULL,
3079 			x_attribute4			=> NULL,
3080 			x_attribute5			=> NULL,
3081 			x_attribute6			=> NULL,
3082 			x_attribute7			=> NULL,
3083 			x_attribute8			=> NULL,
3084 			x_attribute9			=> NULL,
3085 			x_attribute10			=> NULL,
3086 			X_MODE				=> 'R' );
3087 	hr_utility.trace('	Crossed Insert rec into sub lines');
3088 
3089 	l_rowid	:=	NULL;
3090 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3091 			X_ROWID				=> l_rowid,
3092 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3093 			X_REASON_CODE			=> 'SALARY_CHANGE',
3094 			X_PARENT_LINE_ID		=> l_sub_line_id,
3095 			X_MODE				=> 'R');
3096 	end if;
3097 
3098 	l_sub_line_start_date	:= trunc(l_change_date);
3099  end loop;
3100 
3101 	l_work_days		:= 0;
3102 	l_rate_salary	:= 0.00;
3103 	l_array_begin	:= (trunc(l_sub_line_start_date) - trunc(g_start_date)) + 1;
3104 	l_array_end		:= (trunc(g_end_date) - trunc(g_start_date)) + 1;
3105 	for i in l_array_begin..l_array_end loop
3106 	l_rate_salary	:= l_rate_salary + daily_calendar(i);
3107 	if work_calendar(i) = 'Y' then
3108 		l_work_days	:= l_work_days + 1;
3109 		l_daily_rate	:= daily_calendar(i);
3110 	end if;
3111 	end loop;
3112 
3113 	if round(g_payroll_line_rec.balance_amount, g_precision) <> 0.00 then	-- Modified rounding precision to currency precision for bug fix 2916848
3114 	-- l_balance_salary	:= l_daily_balance * l_work_days ;
3115 	l_balance_salary	:= round((l_daily_balance * l_work_days), g_precision) ;	-- bug fix 3109943
3116 	else
3117 	l_balance_salary := 0.00;
3118 	end if;
3119 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3120 	FROM DUAL;
3121 	----hr_utility.trace('	Before Insert rec into sub lines 2');
3122 	hr_utility.trace('	inserting into Sublines -2');
3123 	PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3124 			X_ROWID				=> l_rowid,
3125 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3126 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3127 			X_SUB_LINE_START_DATE		=> l_sub_line_start_date,
3128 			X_SUB_LINE_END_DATE		=> trunc(g_end_date),
3129 			X_REASON_CODE			=> 'SALARY_CHANGE',
3130 			X_PAY_AMOUNT			=> round((l_rate_salary + l_balance_salary), g_precision), -- bug 3109943
3131 			X_DAILY_RATE			=> l_daily_rate + l_daily_balance,
3132 			X_SALARY_USED			=> NVL(l_proposed_salary,0),
3133 			X_CURRENT_SALARY		=> NVL(l_proposed_salary,0),
3134 			X_FTE				=> NULL,
3135 			X_ORGANIZATION_ID		=> NULL,
3136 			X_JOB_ID			=> NULL,
3137 			X_POSITION_ID			=> NULL,
3138 			X_GRADE_ID			=> NULL,
3139 			X_PEOPLE_GRP_ID		=> NULL,
3140 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3141 			X_EMPLOYMENT_END_DATE		=> NULL,
3142 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3143 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3144 			X_ASSIGNMENT_BEGIN_DATE		=> NULL,
3145 			X_ASSIGNMENT_END_DATE		=> NULL,
3146 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3147 			x_attribute1			=> NULL,
3148 			x_attribute2			=> NULL,
3149 			x_attribute3			=> NULL,
3150 			x_attribute4			=> NULL,
3151 			x_attribute5			=> NULL,
3152 			x_attribute6			=> NULL,
3153 			x_attribute7			=> NULL,
3154 			x_attribute8			=> NULL,
3155 			x_attribute9			=> NULL,
3156 			x_attribute10			=> NULL,
3157 			X_MODE				=> 'R' );
3158 	----hr_utility.trace('	Sub line		' || to_char(l_sub_line_id));
3159 	----hr_utility.trace('	Crossed Insert rec into sub lines 2');
3160 	l_rowid	:=	NULL;
3161 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3162 			X_ROWID				=> l_rowid,
3163 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3164 			X_REASON_CODE			=> 'SALARY_CHANGE',
3165 			X_PARENT_LINE_ID		=> l_sub_line_id,
3166 			X_MODE				=> 'R');
3167 
3168  close get_proposal_csr;
3169 
3170  hr_utility.trace('	Leaving CREATE_SLINE_SALARY_CHANGE');
3171 
3172 
3173  EXCEPTION
3174 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR then
3175 --	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_DAILY_RATE_CALENDAR');	Commented for bug fix 2439207
3176 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_SALARY_CHANGE');	-- Introduced for bug 2439207
3177 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
3178 
3179 	WHEN NO_DATA_FOUND then
3180 	begin
3181 	----hr_utility.trace('	Entered NO_DATA_FOUND');
3182 
3183 	open get_previous_proposal_csr;
3184 	----hr_utility.trace('	After open cursor');
3185 	fetch get_previous_proposal_csr into l_salary, l_change_date, l_paybasis;
3186 	----hr_utility.trace('	After fetch cursor');
3187 	if get_previous_proposal_csr%NOTFOUND then
3188 	----hr_utility.trace('	Entered if NOTFOUND');
3189 	----hr_utility.trace('	Pay amount	' || to_char(g_payroll_line_rec.pay_amount));
3190 	----hr_utility.trace('	Person work days ' || to_char(g_no_of_person_work_days));
3191 	----hr_utility.trace('	Balance amount	' || to_char(g_payroll_line_rec.balance_amount));
3192 
3193 	l_daily_rate	:= round((g_payroll_line_rec.pay_amount / g_no_of_person_work_days), g_ext_precision);
3194 
3195 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id FROM DUAL;
3196 	----hr_utility.trace('	Before Insert rec into sub lines 3');
3197 		----hr_utility.trace('	Subline id	' || to_char(l_sub_line_id));
3198 		----hr_utility.trace('	line id	' || to_char(x_payroll_line_id) );
3199 		----hr_utility.trace('	line start date ' || to_char(l_sub_line_start_date,'YYYY/MM/DD HH24:MI:SS'));
3200 
3201 		----hr_utility.trace('	line end date	' || to_char(g_end_date,'YYYY/MM/DD HH24:MI:SS'));
3202 		----hr_utility.trace('	Daily rate	' || to_char(g_end_date,'YYYY/MM/DD HH24:MI:SS'));
3203 			l_salary:=0;
3204  hr_utility.trace('	inserting into Sublines -3');
3205 	PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3206 			X_ROWID				=> l_rowid,
3207 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3208 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3209 			X_SUB_LINE_START_DATE		=> TRUNC(NVL(x_start_date,l_sub_line_start_date)),
3210 			X_SUB_LINE_END_DATE		=> TRUNC(NVL(x_end_date,g_end_date)),
3211 			X_REASON_CODE			=> 'NO_SALARY_CHANGE',
3212 			X_PAY_AMOUNT			=> g_payroll_line_rec.pay_amount,
3213 			X_DAILY_RATE			=> l_daily_rate,
3214 			X_SALARY_USED			=> NVL(l_salary,0),
3215 			X_CURRENT_SALARY		=> NULL,
3216 			X_FTE				=> NULL,
3217 			X_ORGANIZATION_ID		=> NULL,
3218 			X_JOB_ID			=> NULL,
3219 			X_POSITION_ID			=> NULL,
3220 			X_GRADE_ID			=> NULL,
3221 			X_PEOPLE_GRP_ID		=> NULL,
3222 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3223 			X_EMPLOYMENT_END_DATE		=> NULL,
3224 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3225 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3226 			X_ASSIGNMENT_BEGIN_DATE		=> NULL,
3227 			X_ASSIGNMENT_END_DATE		=> NULL,
3228 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3229 			x_attribute1			=> NULL,
3230 			x_attribute2			=> NULL,
3231 			x_attribute3			=> NULL,
3232 			x_attribute4			=> NULL,
3233 			x_attribute5			=> NULL,
3234 			x_attribute6			=> NULL,
3235 			x_attribute7			=> NULL,
3236 			x_attribute8			=> NULL,
3237 			x_attribute9			=> NULL,
3238 			x_attribute10			=> NULL,
3239 			X_MODE				=> 'R' );
3240 	----dbms_output.PUT_LINE('After Insert rec into sub lines 3');
3241 		l_rowid	:=	NULL;
3242 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3243 			X_ROWID				=> l_rowid,
3244 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3245 			X_REASON_CODE			=> 'NO_SALARY_CHANGE',
3246 			X_PARENT_LINE_ID		=> l_sub_line_id,
3247 			X_MODE				=> 'R');
3248 	----dbms_output.PUT_LINE('After Insert rec into sub line reason 3');
3249 
3250 	else
3251 	begin
3252 		----dbms_output.PUT_LINE('Entered else of if %NOTFOUND ');
3253 		l_rate_salary	:= NVL(g_payroll_line_rec.pay_amount,0);
3254 		for i in 1..g_no_of_days loop
3255 		if daily_calendar(i) <> 0 then
3256 		l_daily_rate	:= daily_calendar(i);
3257 		exit;
3258 		end if;
3259 
3260 	end loop;
3261 
3262 		l_balance_salary	:= round(NVL(g_payroll_line_rec.balance_amount,0), g_precision);	-- Modified rounding precision to currency precision for bug fix 2916848
3263 		----dbms_output.PUT_LINE('Balance Amount ' || to_char(round(g_payroll_line_rec.balance_amount,2)));
3264 		----dbms_output.PUT_LINE('Balance Salary ' || to_char(l_balance_salary));
3265 		----dbms_output.PUT_LINE('Daily	Balance ' || to_char(l_daily_balance));
3266 
3267 		----dbms_output.PUT_LINE('Before Insert record ');
3268 		----dbms_output.PUT_LINE('Subline id	' || to_char(l_sub_line_id));
3269 		----dbms_output.PUT_LINE('line id	' || to_char(x_payroll_line_id) );
3270 		----dbms_output.PUT_LINE('line start date ' || to_char(l_sub_line_start_date));
3271 
3272 		----dbms_output.PUT_LINE('line end date	' || to_char(l_sub_line_end_date));
3273 		----dbms_output.PUT_LINE('l_rate_salary	' || to_char(l_rate_salary));
3274 		----dbms_output.PUT_LINE('l_balance_salary ' || to_char(l_balance_salary));
3275 		----dbms_output.PUT_LINE('Daily rate	' || to_char(l_daily_rate+l_daily_balance));
3276 		----dbms_output.PUT_LINE('salary Used	' || to_char(l_salary));
3277 
3278 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3279 		FROM DUAL;
3280  hr_utility.trace('	inserting into Sublines -5');
3281 		PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3282 			X_ROWID				=> l_rowid,
3283 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3284 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3285 			X_SUB_LINE_START_DATE		=> TRUNC(NVL(x_start_date,g_start_date)),
3286 			X_SUB_LINE_END_DATE		=> TRUNC(NVL(x_end_date,g_end_date)),
3287 			X_REASON_CODE			=> 'NO_SALARY_CHANGE',
3288 			X_PAY_AMOUNT			=> l_rate_salary ,
3289 			X_DAILY_RATE			=> l_daily_rate + l_daily_balance,
3290 			X_SALARY_USED			=> NVL(l_salary,0),
3291 			X_CURRENT_SALARY		=> NVL(l_salary,0),
3292 			X_FTE				=> NULL,
3293 			X_ORGANIZATION_ID		=> NULL,
3294 			X_JOB_ID			=> NULL,
3295 			X_POSITION_ID			=> NULL,
3296 			X_GRADE_ID			=> NULL,
3297 			X_PEOPLE_GRP_ID		=> NULL,
3298 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3299 			X_EMPLOYMENT_END_DATE		=> NULL,
3300 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3301 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3302 			X_ASSIGNMENT_BEGIN_DATE		=> NULL,
3303 			X_ASSIGNMENT_END_DATE		=> NULL,
3304 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3305 			x_attribute1			=> NULL,
3306 			x_attribute2			=> NULL,
3307 			x_attribute3			=> NULL,
3308 			x_attribute4			=> NULL,
3309 			x_attribute5			=> NULL,
3310 			x_attribute6			=> NULL,
3311 			x_attribute7			=> NULL,
3312 			x_attribute8			=> NULL,
3313 			x_attribute9			=> NULL,
3314 			x_attribute10			=> NULL,
3315 			X_MODE				=> 'R' );
3316 		l_rowid	:=	NULL;
3317 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3318 			X_ROWID				=> l_rowid,
3319 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3320 			X_REASON_CODE			=> 'NO_SALARY_CHANGE',
3321 			X_PARENT_LINE_ID		=> l_sub_line_id,
3322 			X_MODE				=> 'R');
3323 		----dbms_output.PUT_LINE('After Insert record ');
3324 		end;
3325 	end if;
3326 	end;
3327  	hr_utility.trace('	Leaving CREATE_SLINE_SALARY_CHANGE');
3328 	close get_previous_proposal_csr;
3329 
3330 	WHEN OTHERS then
3331 
3332 	hr_utility.trace('	Failing with the OTHERS exception');
3333 	----dbms_output.PUT_LINE('Error Num : ' || to_char(SQLCODE) || 'Err Msg : ' || SUBSTR(SQLERRM,1,100));
3334 --	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_DAILY_RATE_CALENDAR');	Commented for bug fix 2439207
3335 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_SALARY_CHANGE');	-- Introduced for bug 2439207
3336 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
3337 
3338 end CREATE_SLINE_SALARY_CHANGE;
3339 
3340 ---------------------CREATE_SLINE_ASG_CHANGE--------------------------------
3341 --
3342 PROCEDURE CREATE_SLINE_ASG_CHANGE (x_payroll_line_id IN NUMBER,
3343 					x_assignment_id	IN NUMBER,
3344 					x_return_status OUT NOCOPY VARCHAR2) IS
3345 
3346 CURSOR get_asg_begin_date_csr IS
3347 SELECT effective_start_date
3348 FROM	per_assignments_f
3349 WHERE assignment_id = x_assignment_id and
3350 	effective_start_date between (trunc(g_start_date)+1) and g_end_date and
3351 	effective_start_date = (select min(effective_start_date)
3352 				from per_assignments_f
3353 				where assignment_id = x_assignment_id
3354 				AND	assignment_type ='E' ); --Added for bug 2624259.
3355 
3356 l_start_date	date;
3357 
3358 CURSOR get_asg_end_date_csr IS
3359 SELECT effective_end_date
3360 FROM	per_assignments_f
3361 WHERE assignment_id = x_assignment_id and
3362 	effective_end_date between g_start_date and (trunc(g_end_date) - 1) and
3363 	effective_end_date = (select max(effective_end_date)
3364 				from per_assignments_f
3365 				where assignment_id = x_assignment_id);
3366 l_end_date	date;
3367 
3368 CURSOR get_sublines_csr IS
3369 SELECT *
3370 FROM	psp_payroll_sub_lines
3371 WHERE payroll_line_id = x_payroll_line_id and
3372 	l_start_date between sub_line_start_date and sub_line_end_date;
3373 
3374 g_sublines_rec get_sublines_csr%ROWTYPE;
3375 
3376 
3377 begin
3378 
3379 hr_utility.trace('	Entering CREATE_SLINE_ASG_CHANGE');
3380  ----dbms_output.put_line('Entered Proceduer create_sline_asg_change..');
3381  open get_asg_begin_date_csr;
3382  fetch get_asg_begin_date_csr into l_start_date;
3383  if get_asg_begin_date_csr%FOUND then
3384 	open get_sublines_csr;
3385 	fetch get_sublines_csr into g_sublines_rec;
3386 	if get_sublines_csr%FOUND then
3387 	UPDATE psp_payroll_sub_lines
3388 		SET sub_line_start_date	= trunc(l_start_date),
3389 		reason_code		= 'ASSG_BEGIN_DATE',
3390 		assignment_begin_date = trunc(l_start_date)
3391 	WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
3392 	----dbms_output.put_line('Updated sub line with new begin date');
3393 	end if;
3394 	close get_sublines_csr;
3395  end if;
3396  close get_asg_begin_date_csr;
3397 
3398  open get_asg_end_date_csr;
3399  fetch get_asg_end_date_csr into l_end_date;
3400  if get_asg_end_date_csr%FOUND then
3401 	l_start_date	:= trunc(l_end_date);
3402 	open get_sublines_csr;
3403 	fetch get_sublines_csr into g_sublines_rec;
3404 	if get_sublines_csr%FOUND then
3405 	UPDATE psp_payroll_sub_lines
3406 		SET sub_line_end_date	= trunc(l_start_date),
3407 		reason_code		= 'ASSG_END_DATE',
3408 		assignment_end_date = trunc(l_start_date)
3409 	WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
3410 	----dbms_output.put_line('Updated sub line with new end date');
3411 	end if;
3412 	close get_sublines_csr;
3413  end if;
3414  close get_asg_end_date_csr;
3415  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
3416 
3417  hr_utility.trace('	Leaving CREATE_SLINE_ASG_CHANGE');
3418 
3419 EXCEPTION
3420 	WHEN OTHERS then
3421 	close get_asg_end_date_csr;
3422 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_ASG_CHANGE');
3423 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
3424 
3425 end CREATE_SLINE_ASG_CHANGE;
3426 
3427 
3428 -----------------------CREATE_SLINE_ASG_STATUS_CHANGE------------------------
3429 --
3430 PROCEDURE CREATE_SLINE_ASG_STATUS_CHANGE (x_payroll_line_id IN NUMBER,
3431 					x_assignment_id	IN NUMBER,
3432 					x_balance_amount IN NUMBER,
3433 					x_return_status OUT NOCOPY VARCHAR2) IS
3434 CURSOR get_asg_status_csr IS
3435 SELECT effective_start_date,	effective_end_date
3436 FROM	per_assignments_f
3437 WHERE	assignment_id = x_assignment_id and
3438 	(g_start_date between effective_start_date and effective_end_date or
3439 	g_end_date	between effective_start_date and effective_end_date or
3440 	(g_start_date <= effective_start_date and	g_end_date >= effective_end_date )) and
3441 	assignment_status_type_id in (select assignment_status_type_id
3442 					from per_assignment_status_types
3443 					where per_system_status in ('SUSP_ASSIGN','TERM_ASSIGN') )
3444 ORDER BY effective_start_date;
3445 
3446 l_start_date	date;
3447 l_end_date	date;
3448 
3449 CURSOR get_sublines_csr IS
3450 SELECT *
3451 FROM	psp_payroll_sub_lines
3452 WHERE payroll_line_id = x_payroll_line_id and
3453 	(l_start_date between sub_line_start_date and sub_line_end_date or
3454 	l_end_date	between sub_line_start_date and sub_line_end_date);
3455 -- or
3456 --	(g_start_date <= sub_line_start_date and	g_end_date >= sub_line_end_date ));
3457 
3458 g_sublines_rec get_sublines_csr%ROWTYPE;
3459 
3460 l_sub_line_id	number(9)	:= 0;
3461 l_rowid		varchar2(20);
3462 l_tmp_start_date	date;
3463 l_tmp_end_date		date;
3464 i		number(9)	:= 0;
3465 i2		number(9)	:= 0;
3466 l_amount	number(22,2)	:= 0;
3467 l_no_of_days	number(3)	:= 0;
3468 l_total_work_days number(3) := 0;
3469 
3470 begin
3471 
3472  hr_utility.trace('	Entering CREATE_SLINE_ASG_STATUS_CHANGE');
3473  ----dbms_output.put_line('Entered Proceduer create_sline_asg_status_change..');
3474  for i in 1..g_no_of_days loop
3475 	if work_calendar(i) = 'Y' then
3476 	l_total_work_days := l_total_work_days + 1;
3477 	end if;
3478  end loop;
3479 
3480  open get_asg_status_csr;
3481  LOOP
3482 	fetch get_asg_status_csr into l_start_date,l_end_date;
3483 	----dbms_output.put_line('After fetch get_asg_status_csr and Before Exit......');
3484 	EXIT WHEN get_asg_status_csr%NOTFOUND;
3485 	----dbms_output.put_line('After Exit......');
3486 	begin
3487 	open get_sublines_csr;
3488 	LOOP
3489 	----dbms_output.put_line('Before fetch get_sublines_csr and Before Exit......');
3490 	fetch get_sublines_csr into g_sublines_rec;
3491 	EXIT WHEN get_sublines_csr%NOTFOUND;
3492 	----dbms_output.put_line('After fetch get_sublines_csr and Before Exit......');
3493 	if (l_start_date <= g_sublines_rec.sub_line_start_date and
3494 		l_end_date	>= g_sublines_rec.sub_line_end_date)
3495 	then
3496 		----dbms_output.put_line('Entered 1st if ..');
3497 		UPDATE psp_payroll_sub_lines
3498 		SET	pay_amount	= 0.00,
3499 		daily_rate	= 0.00,
3500 		reason_code = 'ASSG_STATUS_CHANGE'
3501 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
3502 	elsif (l_start_date > g_sublines_rec.sub_line_start_date and
3503 		l_end_date >= g_sublines_rec.sub_line_end_date)
3504 		then
3505 		begin
3506 		----dbms_output.put_line('Entered 2nd if ..');
3507 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
3508 		l_tmp_end_date	:= trunc(l_start_date) - 1;
3509 		i		:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
3510 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
3511 		l_no_of_days	:= 0;
3512 		l_amount	:= 0.00;
3513 		while i <= i2 loop
3514 		l_amount	:= l_amount + daily_calendar(i);
3515 		if work_calendar(i)	= 'Y' then
3516 			l_no_of_days	:= l_no_of_days + 1;
3517 		end if;
3518 		i	:= i + 1;
3519 		end loop;
3520 
3521 		if round(x_balance_amount,g_precision) <> 0.00 then
3522 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / l_total_work_days)), g_precision);
3523 		end if;
3524 --		----dbms_output.put_line('Entered 3rd if ..');
3525 
3526 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3527 			FROM DUAL;
3528  hr_utility.trace('	inserting into Sublines -6');
3529 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3530 			X_ROWID				=> l_rowid,
3531 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3532 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3533 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3534 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3535 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3536 			X_PAY_AMOUNT			=> l_amount,
3537 			X_DAILY_RATE			=> g_sublines_rec.daily_rate ,
3538 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3539 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3540 			X_FTE				=> NULL,
3541 			X_ORGANIZATION_ID		=> NULL,
3542 			X_JOB_ID			=> NULL,
3543 			X_POSITION_ID			=> NULL,
3544 			X_GRADE_ID			=> NULL,
3545 			X_PEOPLE_GRP_ID		=> NULL,
3546 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3547 			X_EMPLOYMENT_END_DATE		=> NULL,
3548 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3549 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3550 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3551 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3552 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3553 			x_attribute1			=> NULL,
3554 			x_attribute2			=> NULL,
3555 			x_attribute3			=> NULL,
3556 			x_attribute4			=> NULL,
3557 			x_attribute5			=> NULL,
3558 			x_attribute6			=> NULL,
3559 			x_attribute7			=> NULL,
3560 			x_attribute8			=> NULL,
3561 			x_attribute9			=> NULL,
3562 			x_attribute10			=> NULL,
3563 			X_MODE				=> 'R');
3564 		l_rowid	:=	NULL;
3565 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3566 			X_ROWID				=> l_rowid,
3567 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3568 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3569 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3570 			X_MODE				=> 'R');
3571 		----dbms_output.put_line('After creating sub line (1)..');
3572 
3573 		l_tmp_start_date	:= trunc(l_start_date);
3574 		l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
3575 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3576 			FROM DUAL;
3577 hr_utility.trace('	inserting into Sublines -7');
3578 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3579 			X_ROWID				=> l_rowid,
3580 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3581 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3582 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3583 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3584 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3585 			X_PAY_AMOUNT			=> 0.00,
3586 			X_DAILY_RATE			=> 0.00,
3587 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3588 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3589 			X_FTE				=> NULL,
3590 			X_ORGANIZATION_ID		=> NULL,
3591 			X_JOB_ID			=> NULL,
3592 			X_POSITION_ID			=> NULL,
3593 			X_GRADE_ID			=> NULL,
3594 			X_PEOPLE_GRP_ID		=> NULL,
3595 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3596 			X_EMPLOYMENT_END_DATE		=> NULL,
3597 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_start_date,
3598 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3599 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3600 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3601 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3602 			x_attribute1			=> NULL,
3603 			x_attribute2			=> NULL,
3604 			x_attribute3			=> NULL,
3605 			x_attribute4			=> NULL,
3606 			x_attribute5			=> NULL,
3607 			x_attribute6			=> NULL,
3608 			x_attribute7			=> NULL,
3609 			x_attribute8			=> NULL,
3610 			x_attribute9			=> NULL,
3611 			x_attribute10			=> NULL,
3612 			X_MODE				=> 'R');
3613 		l_rowid	:=	NULL;
3614 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3615 			X_ROWID				=> l_rowid,
3616 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3617 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3618 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3619 			X_MODE				=> 'R') ;
3620 		----dbms_output.put_line('After creating sub line (2)..');
3621 		DELETE psp_payroll_sub_lines
3622 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
3623 	end;
3624 	elsif (l_start_date = g_sublines_rec.sub_line_start_date and
3625 		l_end_date	< g_sublines_rec.sub_line_end_date) then
3626 		begin
3627 		----dbms_output.put_line('Entered 3rd if..');
3628 
3629 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
3630 		l_tmp_end_date	:= trunc(l_end_date);
3631 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3632 			FROM DUAL;
3633  hr_utility.trace('	inserting into Sublines -8');
3634 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3635 			X_ROWID				=> l_rowid,
3636 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3637 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3638 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3639 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3640 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3641 			X_PAY_AMOUNT			=> 0.00,
3642 			X_DAILY_RATE			=> 0.00,
3643 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3644 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3645 			X_FTE				=> NULL,
3646 			X_ORGANIZATION_ID		=> NULL,
3647 			X_JOB_ID			=> NULL,
3648 			X_POSITION_ID			=> NULL,
3649 			X_GRADE_ID			=> NULL,
3650 			X_PEOPLE_GRP_ID		=> NULL,
3651 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3652 			X_EMPLOYMENT_END_DATE		=> NULL,
3653 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_end_date,
3654 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
3655 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3656 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3657 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3658 			x_attribute1			=> NULL,
3659 			x_attribute2			=> NULL,
3660 			x_attribute3			=> NULL,
3661 			x_attribute4			=> NULL,
3662 			x_attribute5			=> NULL,
3663 			x_attribute6			=> NULL,
3664 			x_attribute7			=> NULL,
3665 			x_attribute8			=> NULL,
3666 			x_attribute9			=> NULL,
3667 			x_attribute10			=> NULL,
3668 			X_MODE				=> 'R');
3669 		l_rowid	:=	NULL;
3670 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3671 			X_ROWID				=> l_rowid,
3672 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3673 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3674 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3675 			X_MODE				=> 'R');
3676 		----dbms_output.put_line('After creating sub line (1)..');
3677 
3678 		l_tmp_start_date	:= trunc(l_end_date) + 1;
3679 		l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
3680 		i		:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
3681 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
3682 		l_no_of_days	:= 0;
3683 		l_amount	:= 0.00;
3684 		while i <= i2 loop
3685 		l_amount	:= l_amount + daily_calendar(i);
3686 		if work_calendar(i)	= 'Y' then
3687 			l_no_of_days	:= l_no_of_days + 1;
3688 		end if;
3689 		i	:= i + 1;
3690 		end loop;
3691 
3692 		if round(x_balance_amount,g_precision) <> 0.00 then
3693 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / l_total_work_days)), g_precision);
3694 		end if;
3695 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3696 			FROM DUAL;
3697  hr_utility.trace('	inserting into Sublines -10');
3698 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3699 			X_ROWID				=> l_rowid,
3700 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3701 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3702 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3703 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3704 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3705 			X_PAY_AMOUNT			=> l_amount,
3706 			X_DAILY_RATE			=> g_sublines_rec.daily_rate ,
3707 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3708 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3709 			X_FTE				=> NULL,
3710 			X_ORGANIZATION_ID		=> NULL,
3711 			X_JOB_ID			=> NULL,
3712 			X_POSITION_ID			=> NULL,
3713 			X_GRADE_ID			=> NULL,
3714 			X_PEOPLE_GRP_ID		=> NULL,
3715 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3716 			X_EMPLOYMENT_END_DATE		=> NULL,
3717 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3718 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
3719 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3720 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3721 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3722 			x_attribute1			=> NULL,
3723 			x_attribute2			=> NULL,
3724 			x_attribute3			=> NULL,
3725 			x_attribute4			=> NULL,
3726 			x_attribute5			=> NULL,
3727 			x_attribute6			=> NULL,
3728 			x_attribute7			=> NULL,
3729 			x_attribute8			=> NULL,
3730 			x_attribute9			=> NULL,
3731 			x_attribute10			=> NULL,
3732 			X_MODE				=> 'R');
3733 		l_rowid	:=	NULL;
3734 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3735 			X_ROWID				=> l_rowid,
3736 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3737 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3738 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3739 			X_MODE				=> 'R');
3740 		----dbms_output.put_line('After creating sub line (2)..');
3741 		DELETE psp_payroll_sub_lines
3742 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
3743 	end;
3744 	elsif (l_start_date > g_sublines_rec.sub_line_start_date and
3745 		l_end_date	< g_sublines_rec.sub_line_end_date) then
3746 		begin
3747 		----dbms_output.put_line('Entered 4th if ..');
3748 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
3749 		l_tmp_end_date	:= trunc(l_start_date) - 1;
3750 		i		:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
3751 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
3752 		l_no_of_days	:= 0;
3753 		l_amount	:= 0.00;
3754 		while i <= i2 loop
3755 		l_amount	:= l_amount + daily_calendar(i);
3756 		if work_calendar(i)	= 'Y' then
3757 			l_no_of_days	:= l_no_of_days + 1;
3758 		end if;
3759 		i	:= i + 1;
3760 		end loop;
3761 
3762 		if round(x_balance_amount,g_precision) <> 0.00 then
3763 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / l_total_work_days)), g_precision);
3764 		end if;
3765 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3766 			FROM DUAL;
3767  hr_utility.trace('	inserting into Sublines -12');
3768 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3769 			X_ROWID				=> l_rowid,
3770 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3771 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3772 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3773 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3774 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3775 			X_PAY_AMOUNT			=> l_amount,
3776 			X_DAILY_RATE			=> g_sublines_rec.daily_rate ,
3777 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3778 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3779 			X_FTE				=> NULL,
3780 			X_ORGANIZATION_ID		=> NULL,
3781 			X_JOB_ID			=> NULL,
3782 			X_POSITION_ID			=> NULL,
3783 			X_GRADE_ID			=> NULL,
3784 			X_PEOPLE_GRP_ID		=> NULL,
3785 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3786 			X_EMPLOYMENT_END_DATE		=> NULL,
3787 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_end_date,
3788 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
3789 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3790 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3791 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3792 			x_attribute1			=> NULL,
3793 			x_attribute2			=> NULL,
3794 			x_attribute3			=> NULL,
3795 			x_attribute4			=> NULL,
3796 			x_attribute5			=> NULL,
3797 			x_attribute6			=> NULL,
3798 			x_attribute7			=> NULL,
3799 			x_attribute8			=> NULL,
3800 			x_attribute9			=> NULL,
3801 			x_attribute10			=> NULL,
3802 			X_MODE				=> 'R');
3803 		l_rowid	:=	NULL;
3804 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3805 			X_ROWID				=> l_rowid,
3806 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3807 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3808 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3809 			X_MODE				=> 'R');
3810 		----dbms_output.put_line('After 1st Insert ..');
3811 		l_tmp_start_date	:= trunc(l_start_date);
3812 		l_tmp_end_date	:= trunc(l_end_date) ;
3813 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3814 			FROM DUAL;
3815  hr_utility.trace('	inserting into Sublines -13');
3816 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3817 			X_ROWID				=> l_rowid,
3818 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3819 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3820 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3821 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3822 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3823 			X_PAY_AMOUNT			=> 0.00,
3824 			X_DAILY_RATE			=> 0.00,
3825 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3826 			X_CURRENT_SALARY		=> NULL,
3827 			X_FTE				=> NULL,
3828 			X_ORGANIZATION_ID		=> NULL,
3829 			X_JOB_ID			=> NULL,
3830 			X_POSITION_ID			=> NULL,
3831 			X_GRADE_ID			=> NULL,
3832 			X_PEOPLE_GRP_ID		=> NULL,
3833 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3834 			X_EMPLOYMENT_END_DATE		=> NULL,
3835 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_start_date,
3836 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> trunc(l_tmp_end_date) + 1,
3837 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3838 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3839 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3840 			x_attribute1			=> NULL,
3841 			x_attribute2			=> NULL,
3842 			x_attribute3			=> NULL,
3843 			x_attribute4			=> NULL,
3844 			x_attribute5			=> NULL,
3845 			x_attribute6			=> NULL,
3846 			x_attribute7			=> NULL,
3847 			x_attribute8			=> NULL,
3848 			x_attribute9			=> NULL,
3849 			x_attribute10			=> NULL,
3850 			X_MODE				=> 'R');
3851 		l_rowid	:=	NULL;
3852 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3853 			X_ROWID				=> l_rowid,
3854 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3855 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3856 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3857 			X_MODE				=> 'R');
3858 		----dbms_output.put_line('After 2nd Insert ..');
3859 		l_tmp_start_date	:= trunc(l_end_date) + 1;
3860 		l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
3861 		i		:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
3862 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
3863 		l_no_of_days	:= 0;
3864 		l_amount	:= 0.00;
3865 		while i <= i2 loop
3866 		l_amount	:= l_amount + daily_calendar(i);
3867 		if work_calendar(i)	= 'Y' then
3868 			l_no_of_days	:= l_no_of_days + 1;
3869 		end if;
3870 		i	:= i + 1;
3871 		end loop;
3872 
3873 		if round(x_balance_amount,g_precision) <> 0.00 then
3874 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / l_total_work_days)), g_precision);
3875 
3876 		end if;
3877 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3878 			FROM DUAL;
3879  hr_utility.trace('	inserting into Sublines -14');
3880 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3881 			X_ROWID				=> l_rowid,
3882 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
3883 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3884 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3885 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3886 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3887 			X_PAY_AMOUNT			=> l_amount,
3888 			X_DAILY_RATE			=> g_sublines_rec.daily_rate ,
3889 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3890 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3891 			X_FTE				=> NULL,
3892 			X_ORGANIZATION_ID		=> NULL,
3893 			X_JOB_ID			=> NULL,
3894 			X_POSITION_ID			=> NULL,
3895 			X_GRADE_ID			=> NULL,
3896 			X_PEOPLE_GRP_ID		=> NULL,
3897 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3898 			X_EMPLOYMENT_END_DATE		=> NULL,
3899 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
3900 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
3901 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3902 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3903 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3904 			x_attribute1			=> NULL,
3905 			x_attribute2			=> NULL,
3906 			x_attribute3			=> NULL,
3907 			x_attribute4			=> NULL,
3908 			x_attribute5			=> NULL,
3909 			x_attribute6			=> NULL,
3910 			x_attribute7			=> NULL,
3911 			x_attribute8			=> NULL,
3912 			x_attribute9			=> NULL,
3913 			x_attribute10			=> NULL,
3914 			X_MODE				=> 'R');
3915 		l_rowid	:=	NULL;
3916 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3917 			X_ROWID				=> l_rowid,
3918 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
3919 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3920 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3921 			X_MODE				=> 'R');
3922 		----dbms_output.put_line('After 3rd Insert ..');
3923 
3924 		DELETE psp_payroll_sub_lines
3925 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
3926 	end;
3927 	elsif (l_start_date = g_sublines_rec.sub_line_end_date and
3928 		l_end_date	> g_sublines_rec.sub_line_end_date) then
3929 	begin
3930 		----dbms_output.put_line('Entered 5th if ..');
3931 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
3932 		l_tmp_end_date	:= trunc((g_sublines_rec.sub_line_end_date) - 1);
3933 
3934 		i		:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
3935 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
3936 		l_no_of_days	:= 0;
3937 		l_amount	:= 0.00;
3938 		while i <= i2 loop
3939 		l_amount	:= l_amount + daily_calendar(i);
3940 		if work_calendar(i)	= 'Y' then
3941 			l_no_of_days	:= l_no_of_days + 1;
3942 		end if;
3943 		i	:= i + 1;
3944 		end loop;
3945 
3946 		if round(x_balance_amount,g_precision) <> 0.00 then
3947 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / l_total_work_days)), g_precision);
3948 		end if;
3949 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3950 			FROM DUAL;
3951 hr_utility.trace('	inserting into Sublines -15');
3952 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
3953 			X_ROWID				=> l_rowid,
3954 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3955 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
3956 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
3957 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
3958 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3959 			X_PAY_AMOUNT			=> l_amount,
3960 			X_DAILY_RATE			=> g_sublines_rec.daily_rate ,
3961 			X_SALARY_USED			=> g_sublines_rec.salary_used,
3962 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
3963 			X_FTE				=> NULL,
3964 			X_ORGANIZATION_ID		=> NULL,
3965 			X_JOB_ID			=> NULL,
3966 			X_POSITION_ID			=> NULL,
3967 			X_GRADE_ID			=> NULL,
3968 			X_PEOPLE_GRP_ID		=> NULL,
3969 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
3970 			X_EMPLOYMENT_END_DATE		=> NULL,
3971 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_end_date,
3972 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
3973 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
3974 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
3975 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
3976 			x_attribute1			=> NULL,
3977 			x_attribute2			=> NULL,
3978 			x_attribute3			=> NULL,
3979 			x_attribute4			=> NULL,
3980 			x_attribute5			=> NULL,
3981 			x_attribute6			=> NULL,
3982 			x_attribute7			=> NULL,
3983 			x_attribute8			=> NULL,
3984 			x_attribute9			=> NULL,
3985 			x_attribute10			=> NULL,
3986 			X_MODE				=> 'R');
3987 		l_rowid	:=	NULL;
3988 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
3989 			X_ROWID				=> l_rowid,
3990 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
3991 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
3992 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
3993 			X_MODE				=> 'R');
3994 
3995 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_end_date);
3996 		l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
3997 
3998 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
3999 		FROM DUAL;
4000  hr_utility.trace('	inserting into Sublines -17');
4001 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4002 			X_ROWID				=> l_rowid,
4003 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
4004 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4005 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4006 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4007 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
4008 			X_PAY_AMOUNT			=> 0.00,
4009 			X_DAILY_RATE			=> 0.00 ,
4010 			X_SALARY_USED			=> 0.00,
4011 			X_CURRENT_SALARY		=> NULL,
4012 			X_FTE				=> NULL,
4013 			X_ORGANIZATION_ID		=> NULL,
4014 			X_JOB_ID			=> NULL,
4015 			X_POSITION_ID			=> NULL,
4016 			X_GRADE_ID			=> NULL,
4017 			X_PEOPLE_GRP_ID		=> NULL,
4018 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
4019 			X_EMPLOYMENT_END_DATE		=> NULL,
4020 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_end_date,
4021 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
4022 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4023 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4024 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4025 			x_attribute1			=> NULL,
4026 			x_attribute2			=> NULL,
4027 			x_attribute3			=> NULL,
4028 			x_attribute4			=> NULL,
4029 			x_attribute5			=> NULL,
4030 			x_attribute6			=> NULL,
4031 			x_attribute7			=> NULL,
4032 			x_attribute8			=> NULL,
4033 			x_attribute9			=> NULL,
4034 			x_attribute10			=> NULL,
4035 			X_MODE				=> 'R');
4036 		l_rowid	:=	NULL;
4037 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4038 			X_ROWID				=> l_rowid,
4039 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
4040 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
4041 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4042 			X_MODE				=> 'R');
4043 		DELETE psp_payroll_sub_lines
4044 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4045 		end;
4046 			elsif (l_start_date < g_sublines_rec.sub_line_start_date and
4047 		l_end_date	< g_sublines_rec.sub_line_end_date) then
4048 		begin
4049 		----dbms_output.put_line('Entered 6th if ..');
4050 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
4051 		l_tmp_end_date	:= trunc(l_end_date);
4052 
4053 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4054 		FROM DUAL;
4055  hr_utility.trace('	inserting into Sublines -19');
4056 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4057 			X_ROWID				=> l_rowid,
4058 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
4059 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4060 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4061 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4062 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
4063 			X_PAY_AMOUNT			=> 0.00,
4064 			X_DAILY_RATE			=> 0.00 ,
4065 			X_SALARY_USED			=> 0.00,
4066 			X_CURRENT_SALARY		=> NULL,
4067 			X_FTE				=> NULL,
4068 			X_ORGANIZATION_ID		=> NULL,
4069 			X_JOB_ID			=> NULL,
4070 			X_POSITION_ID			=> NULL,
4071 			X_GRADE_ID			=> NULL,
4072 			X_PEOPLE_GRP_ID		=> NULL,
4073 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
4074 			X_EMPLOYMENT_END_DATE		=> NULL,
4075 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_end_date,
4076 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
4077 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4078 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4079 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4080 			x_attribute1			=> NULL,
4081 			x_attribute2			=> NULL,
4082 			x_attribute3			=> NULL,
4083 			x_attribute4			=> NULL,
4084 			x_attribute5			=> NULL,
4085 			x_attribute6			=> NULL,
4086 			x_attribute7			=> NULL,
4087 			x_attribute8			=> NULL,
4088 			x_attribute9			=> NULL,
4089 			x_attribute10			=> NULL,
4090 			X_MODE				=> 'R');
4091 		l_rowid	:=	NULL;
4092 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4093 			X_ROWID				=> l_rowid,
4094 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
4095 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
4096 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4097 			X_MODE				=> 'R');
4098 		l_tmp_start_date	:= trunc((l_end_date)+ 1);
4099 		l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
4100 
4101 		i		:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4102 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4103 		l_no_of_days	:= 0;
4104 		l_amount	:= 0.00;
4105 		while i <= i2 loop
4106 		l_amount	:= l_amount + daily_calendar(i);
4107 		if work_calendar(i)	= 'Y' then
4108 			l_no_of_days	:= l_no_of_days + 1;
4109 		end if;
4110 		i	:= i + 1;
4111 		end loop;
4112 
4113 		if round(x_balance_amount,g_precision) <> 0.00 then
4114 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / l_total_work_days)), g_precision);
4115 		end if;
4116 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4117 			FROM DUAL;
4118  hr_utility.trace('	inserting into Sublines -21');
4119 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4120 			X_ROWID				=> l_rowid,
4121 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
4122 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4123 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4124 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4125 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
4126 			X_PAY_AMOUNT			=> l_amount,
4127 			X_DAILY_RATE			=> g_sublines_rec.daily_rate ,
4128 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4129 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4130 			X_FTE				=> NULL,
4131 			X_ORGANIZATION_ID		=> NULL,
4132 			X_JOB_ID			=> NULL,
4133 			X_POSITION_ID			=> NULL,
4134 			X_GRADE_ID			=> NULL,
4135 			X_PEOPLE_GRP_ID		=> NULL,
4136 			X_EMPLOYMENT_BEGIN_DATE		=> NULL,
4137 			X_EMPLOYMENT_END_DATE		=> NULL,
4138 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> l_tmp_end_date,
4139 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> l_tmp_start_date,
4140 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4141 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4142 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4143 			x_attribute1			=> NULL,
4144 			x_attribute2			=> NULL,
4145 			x_attribute3			=> NULL,
4146 			x_attribute4			=> NULL,
4147 			x_attribute5			=> NULL,
4148 			x_attribute6			=> NULL,
4149 			x_attribute7			=> NULL,
4150 			x_attribute8			=> NULL,
4151 			x_attribute9			=> NULL,
4152 			x_attribute10			=> NULL,
4153 			X_MODE				=> 'R');
4154 		l_rowid	:=	NULL;
4155 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4156 			X_ROWID				=> l_rowid,
4157 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
4158 			X_REASON_CODE			=> 'ASSG_STATUS_CHANGE',
4159 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4160 			X_MODE				=> 'R');
4161 		DELETE psp_payroll_sub_lines
4162 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4163 		end;
4164 	end if;
4165 	end loop;
4166 	close get_sublines_csr;
4167 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
4168 	EXCEPTION
4169 	WHEN OTHERS then
4170 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_ASG_STATUS_CHANGE');
4171 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
4172 	close get_sublines_csr;
4173  end;
4174  END LOOP;
4175  close get_asg_status_csr;
4176  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
4177 
4178   hr_utility.trace('	Leaving CREATE_SLINE_ASG_STATUS_CHANGE');
4179  EXCEPTION
4180 	WHEN NO_DATA_FOUND then
4181 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
4182 	close get_asg_status_csr;
4183 
4184 	WHEN OTHERS then
4185 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_ASG_STATUS_CHANGE');
4186 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
4187 	close get_asg_status_csr;
4188 
4189 end create_sline_asg_status_change;
4190 
4191 -------------------------_SLINE_EMP_END_DATE------------------------
4192 PROCEDURE CREATE_SLINE_EMP_END_DATE (x_payroll_line_id IN NUMBER,
4193 					x_person_id	IN NUMBER,
4194 					x_return_status OUT NOCOPY VARCHAR2) IS
4195 
4196 CURSOR check_service_period_begin_csr IS
4197 SELECT date_start
4198 FROM	per_periods_of_service
4199 WHERE	person_id = x_person_id and
4200 		(date_start between g_start_date and g_end_date) ;
4201 
4202 l_date_start			date;
4203 
4204 CURSOR check_service_period_end_csr IS
4205 SELECT actual_termination_date
4206 FROM	per_periods_of_service
4207 WHERE	person_id = x_person_id and
4208 		(date_start between g_start_date and g_end_date) ;
4209 
4210 l_actual_termination_date	date;
4211 l_tmp_date			date;
4212 
4213 CURSOR get_sublines_csr IS
4214 SELECT *
4215 FROM	psp_payroll_sub_lines
4216 WHERE	payroll_line_id = x_payroll_line_id and
4217 	l_tmp_date between sub_line_start_date and sub_line_end_date;
4218 
4219 g_sublines_rec get_sublines_csr%ROWTYPE;
4220 
4221 
4222 l_tmp_start_date	date;
4223 l_tmp_end_date		date;
4224 l_rowid			varchar2(20);
4225 l_sub_line_id		number(9);
4226 
4227 begin
4228  ----dbms_output.put_line('Entered Proceduer create_sline_emp_end_date..');
4229 
4230  hr_utility.trace('	Entering CREATE_SLINE_EMP_END_DATE');
4231 
4232  open check_service_period_begin_csr;
4233  LOOP
4234 	fetch check_service_period_begin_csr into l_date_start;
4235 	EXIT WHEN check_service_period_begin_csr%NOTFOUND;
4236 	l_tmp_date	:= trunc(l_date_start);
4237 	open get_sublines_csr;
4238 	LOOP
4239 	fetch get_sublines_csr into g_sublines_rec;
4240 	EXIT WHEN get_sublines_csr%NOTFOUND;
4241 	if l_date_start > g_sublines_rec.sub_line_start_date then
4242 	l_tmp_end_date	:= trunc(l_date_start) - 1;
4243 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4244 			FROM DUAL;
4245  hr_utility.trace('	inserting into Sublines -22');
4246 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4247 			X_ROWID				=> l_rowid,
4248 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4249 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4250 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
4251 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4252 			X_REASON_CODE			=> 'EMP_BEGIN_DATE',
4253 			X_PAY_AMOUNT			=> 0.00,
4254 			X_DAILY_RATE			=> 0.00 ,
4255 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4256 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4257 			X_FTE				=> NULL,
4258 			X_ORGANIZATION_ID		=> NULL,
4259 			X_JOB_ID			=> NULL,
4260 			X_POSITION_ID			=> NULL,
4261 			X_GRADE_ID			=> NULL,
4262 			X_PEOPLE_GRP_ID		=> NULL,
4263 			X_EMPLOYMENT_BEGIN_DATE		=> l_tmp_end_date,
4264 			X_EMPLOYMENT_END_DATE		=> NULL,
4265 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4266 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4267 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4268 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4269 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4270 			x_attribute1			=> NULL,
4271 			x_attribute2			=> NULL,
4272 			x_attribute3			=> NULL,
4273 			x_attribute4			=> NULL,
4274 			x_attribute5			=> NULL,
4275 			x_attribute6			=> NULL,
4276 			x_attribute7			=> NULL,
4277 			x_attribute8			=> NULL,
4278 			x_attribute9			=> NULL,
4279 			x_attribute10			=> NULL,
4280 			X_MODE				=> 'R');
4281 		l_rowid	:=	NULL;
4282 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4283 			X_ROWID				=> l_rowid,
4284 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4285 			X_REASON_CODE			=> 'EMP_BEGIN_DATE',
4286 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4287 			X_MODE				=> 'R');
4288 
4289 	l_tmp_start_date	:= trunc(l_date_start);
4290 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4291 			FROM DUAL;
4292  hr_utility.trace('	inserting into Sublines -25');
4293 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4294 			X_ROWID				=> l_rowid,
4295 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4296 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4297 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4298 			X_SUB_LINE_END_DATE		=> g_sublines_rec.sub_line_end_date,
4299 			X_REASON_CODE			=> 'EMP_BEGIN_DATE',
4300 			X_PAY_AMOUNT			=> g_sublines_rec.pay_amount,
4301 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4302 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4303 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4304 			X_FTE				=> NULL,
4305 			X_ORGANIZATION_ID		=> NULL,
4306 			X_JOB_ID			=> NULL,
4307 			X_POSITION_ID			=> NULL,
4308 			X_GRADE_ID			=> NULL,
4309 			X_PEOPLE_GRP_ID		=> NULL,
4310 			X_EMPLOYMENT_BEGIN_DATE		=> l_tmp_start_date,
4311 			X_EMPLOYMENT_END_DATE		=> NULL,
4312 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4313 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4314 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4315 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4316 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4317 			x_attribute1			=> NULL,
4318 			x_attribute2			=> NULL,
4319 			x_attribute3			=> NULL,
4320 			x_attribute4			=> NULL,
4321 			x_attribute5			=> NULL,
4322 			x_attribute6			=> NULL,
4323 			x_attribute7			=> NULL,
4324 			x_attribute8			=> NULL,
4325 			x_attribute9			=> NULL,
4326 			x_attribute10			=> NULL,
4327 			X_MODE				=> 'R');
4328 		l_rowid	:=	NULL;
4329 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4330 			X_ROWID				=> l_rowid,
4331 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4332 			X_REASON_CODE			=> 'EMP_BEGIN_DATE',
4333 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4334 			X_MODE				=> 'R');
4335 
4336 
4337 		DELETE psp_payroll_sub_lines
4338 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4339 	end if;
4340 	END LOOP;
4341 	close get_sublines_csr;
4342  END LOOP;
4343  close check_service_period_begin_csr;
4344 
4345  open check_service_period_end_csr;
4346  LOOP
4347 	fetch check_service_period_end_csr into l_actual_termination_date;
4348 	EXIT WHEN check_service_period_end_csr%NOTFOUND;
4349 	l_tmp_date	:= trunc(l_actual_termination_date);
4350 	open get_sublines_csr;
4351 	LOOP
4352 	fetch get_sublines_csr into g_sublines_rec;
4353 	EXIT WHEN get_sublines_csr%NOTFOUND;
4354 	if l_actual_termination_date < g_sublines_rec.sub_line_end_date then
4355 	l_tmp_end_date	:= trunc(l_actual_termination_date) - 1;
4356 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4357 			FROM DUAL;
4358  hr_utility.trace('	inserting into Sublines -28');
4359 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4360 			X_ROWID				=> l_rowid,
4361 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4362 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4363 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
4364 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4365 			X_REASON_CODE			=> 'EMP_END_DATE',
4366 			X_PAY_AMOUNT			=> g_sublines_rec.pay_amount,
4367 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4368 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4369 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4370 			X_FTE				=> NULL,
4371 			X_ORGANIZATION_ID		=> NULL,
4372 			X_JOB_ID			=> NULL,
4373 			X_POSITION_ID			=> NULL,
4374 			X_GRADE_ID			=> NULL,
4375 			X_PEOPLE_GRP_ID		=> NULL,
4376 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4377 			X_EMPLOYMENT_END_DATE		=> l_tmp_end_date,
4378 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4379 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4380 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4381 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4382 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4383 			x_attribute1			=> NULL,
4384 			x_attribute2			=> NULL,
4385 			x_attribute3			=> NULL,
4386 			x_attribute4			=> NULL,
4387 			x_attribute5			=> NULL,
4388 			x_attribute6			=> NULL,
4389 			x_attribute7			=> NULL,
4390 			x_attribute8			=> NULL,
4391 			x_attribute9			=> NULL,
4392 			x_attribute10			=> NULL,
4393 			X_MODE				=> 'R');
4394 		l_rowid	:=	NULL;
4395 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4396 			X_ROWID				=> l_rowid,
4397 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4398 			X_REASON_CODE			=> 'EMP_END_DATE',
4399 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4400 			X_MODE				=> 'R');
4401 
4402 	l_tmp_start_date	:= trunc(l_actual_termination_date);
4403 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4404 			FROM DUAL;
4405  hr_utility.trace('	inserting into Sublines -30');
4406 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4407 			X_ROWID				=> l_rowid,
4408 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4409 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4410 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4411 			X_SUB_LINE_END_DATE		=> g_sublines_rec.sub_line_end_date,
4412 			X_REASON_CODE			=> 'EMP_END_DATE',
4413 			X_PAY_AMOUNT			=> 0.00,
4414 			X_DAILY_RATE			=> 0.00,
4415 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4416 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4417 			X_FTE				=> NULL,
4418 			X_ORGANIZATION_ID		=> NULL,
4419 			X_JOB_ID			=> NULL,
4420 			X_POSITION_ID			=> NULL,
4421 			X_GRADE_ID			=> NULL,
4422 			X_PEOPLE_GRP_ID		=> NULL,
4423 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4424 			X_EMPLOYMENT_END_DATE		=> l_tmp_start_date,
4425 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4426 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4427 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4428 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4429 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4430 			x_attribute1			=> NULL,
4431 			x_attribute2			=> NULL,
4432 			x_attribute3			=> NULL,
4433 			x_attribute4			=> NULL,
4434 			x_attribute5			=> NULL,
4435 			x_attribute6			=> NULL,
4436 			x_attribute7			=> NULL,
4437 			x_attribute8			=> NULL,
4438 			x_attribute9			=> NULL,
4439 			x_attribute10			=> NULL,
4440 			X_MODE				=> 'R');
4441 		l_rowid	:=	NULL;
4442 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4443 			X_ROWID				=> l_rowid,
4444 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4445 			X_REASON_CODE			=> 'EMP_END_DATE',
4446 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4447 			X_MODE				=> 'R');
4448 
4449 
4450 		DELETE psp_payroll_sub_lines
4451 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4452 
4453 	end if;
4454 	END LOOP;
4455 	close get_sublines_csr;	-- bug fix 2806589
4456 
4457  END LOOP;
4458  close check_service_period_end_csr;	-- bug fix 2806589
4459  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
4460 
4461  hr_utility.trace('	Leaving CREATE_SLINE_EMP_END_DATE');
4462 
4463  EXCEPTION
4464 	WHEN OTHERS then
4465 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_EMP_END_DATE');
4466 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
4467 end create_sline_emp_end_date;
4468 ------------------------------CREATE_SLINE_ORG_CHANGE-------------------
4469 ---
4470 PROCEDURE CREATE_SLINE_ORG_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
4471 					X_ASSIGNMENT_ID	IN NUMBER,
4472 					X_BALANCE_AMOUNT IN NUMBER,
4473 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
4474 CURSOR get_old_org_csr IS
4475 SELECT effective_start_date, organization_id
4476 FROM	per_assignments_f
4477 WHERE assignment_id = x_assignment_id and
4478 	effective_start_date < g_start_date and
4479 	effective_start_date = (select max(effective_start_date) from per_assignments_f
4480 		where assignment_id = x_assignment_id
4481 		AND assignment_type ='E' --Added for bug 2624259.
4482 		AND effective_start_date < g_start_date);
4483 
4484 l_effective_start_date	date;
4485 l_old_org_id		number(9);
4486 
4487 CURSOR get_assg_csr IS
4488 SELECT effective_start_date, effective_end_date, organization_id
4489 FROM	per_assignments_f
4490 WHERE assignment_id = x_assignment_id
4491 	AND assignment_type ='E' --Added for bug 2624259.
4492 	AND
4493 	(g_start_date between effective_start_date and effective_end_date or
4494 	g_end_date	between effective_start_date and effective_end_date or
4495 	(g_start_date <= effective_start_date and g_end_date >= effective_end_date ))
4496 order by effective_start_date;
4497 
4498 l_current_start_date	date;
4499 l_current_end_date	date;
4500 l_new_org_id		number(9);
4501 
4502 CURSOR get_sublines_csr IS
4503 SELECT *
4504 FROM	psp_payroll_sub_lines
4505 WHERE payroll_line_id	= x_payroll_line_id and
4506 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
4507 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
4508 	(sub_line_start_date <= l_current_start_date and sub_line_end_date >= l_current_end_date))
4509 order by sub_line_start_date;
4510 
4511 g_sublines_rec get_sublines_csr%ROWTYPE;
4512 
4513 l_tmp_start_date	date;
4514 l_tmp_end_date		date;
4515 l_rowid			varchar2(20);
4516 l_sub_line_id		number(9);
4517 i		number(9)	:= 0;
4518 i2		number(9)	:= 0;
4519 l_amount	number(22,2)	:= 0;
4520 l_no_of_days	number(3)	:= 0;
4521 
4522 
4523 begin
4524 
4525 hr_utility.trace('	Entering CREATE_SLINE_ORG_CHANGE');
4526 
4527  ----dbms_output.put_line('Entered Procedure create_sline_org_change');
4528  open get_old_org_csr;
4529  ----dbms_output.put_line('Before fetch of get_old_org_csr...');
4530  fetch get_old_org_csr into l_effective_start_date, l_old_org_id;
4531  if get_old_org_csr%NOTFOUND then
4532 	l_old_org_id	:= 0;
4533  end if;
4534 
4535  ----dbms_output.put_line('Before open get_assg_csr...');
4536  open get_assg_csr;
4537  LOOP
4538 	----dbms_output.put_line('Before fetch get_assg_csr...');
4539 	fetch get_assg_csr into l_current_start_date, l_current_end_date, l_new_org_id;
4540 	EXIT WHEN get_assg_csr%NOTFOUND;
4541 	----dbms_output.put_line('After fetch get_assg_csr...');
4542 	if l_old_org_id = 0 or l_old_org_id = l_new_org_id then
4543 	l_old_org_id	:= l_new_org_id;
4544 	else
4545 	begin
4546 	----dbms_output.put_line('Before open get_sublines_csr...');
4547 	open get_sublines_csr;
4548 	----dbms_output.put_line('Before loop get_sublines_csr...');
4549 	LOOP
4550 	fetch get_sublines_csr into g_sublines_rec;
4551 	EXIT WHEN get_sublines_csr%NOTFOUND;
4552 	----dbms_output.put_line('After loop get_sublines_csr...');
4553 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
4554 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
4555 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
4556 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
4557 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
4558 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
4559 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
4560 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
4561 		begin
4562 		UPDATE psp_payroll_sub_lines
4563 			set organization_id = l_new_org_id
4564 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4565 		end;
4566 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
4567 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
4568 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
4569 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
4570 		begin
4571 			l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
4572 			l_tmp_end_date	:= trunc(l_current_start_date) - 1;
4573 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4574 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4575 			l_no_of_days	:= 0;
4576 			l_amount	:= 0.00;
4577 			while i <= i2 loop
4578 			l_amount	:= l_amount + daily_calendar(i);
4579 			if work_calendar(i)	= 'Y' then
4580 				l_no_of_days	:= l_no_of_days + 1;
4581 			end if;
4582 			i	:= i + 1;
4583 			end loop;
4584 
4585 			if round(x_balance_amount,g_precision) <> 0.00 then
4586 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4587 			end if;
4588 
4589 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4590 			FROM DUAL;
4591  hr_utility.trace('	inserting into Sublines -32');
4592 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4593 			X_ROWID				=> l_rowid,
4594 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4595 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4596 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
4597 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4598 			X_REASON_CODE			=> 'ORG_CHANGE',
4599 			X_PAY_AMOUNT			=> l_amount,
4600 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4601 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4602 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4603 			X_FTE				=> NULL,
4604 			X_ORGANIZATION_ID		=> l_old_org_id,
4605 			X_JOB_ID			=> NULL,
4606 			X_POSITION_ID			=> NULL,
4607 			X_GRADE_ID			=> NULL,
4608 			X_PEOPLE_GRP_ID		=> NULL,
4609 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4610 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
4611 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4612 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4613 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4614 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4615 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4616 			x_attribute1			=> NULL,
4617 			x_attribute2			=> NULL,
4618 			x_attribute3			=> NULL,
4619 			x_attribute4			=> NULL,
4620 			x_attribute5			=> NULL,
4621 			x_attribute6			=> NULL,
4622 			x_attribute7			=> NULL,
4623 			x_attribute8			=> NULL,
4624 			x_attribute9			=> NULL,
4625 			x_attribute10			=> NULL,
4626 			X_MODE				=> 'R');
4627 		l_rowid	:=	NULL;
4628 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4629 			X_ROWID				=> l_rowid,
4630 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4631 			X_REASON_CODE			=> 'ORG_CHANGE',
4632 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4633 			X_MODE				=> 'R');
4634 
4635 			l_tmp_start_date	:= trunc(l_current_start_date);
4636 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
4637 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4638 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4639 			l_no_of_days	:= 0;
4640 			l_amount	:= 0.00;
4641 			while i <= i2 loop
4642 			l_amount	:= l_amount + daily_calendar(i);
4643 			if work_calendar(i)	= 'Y' then
4644 				l_no_of_days	:= l_no_of_days + 1;
4645 			end if;
4646 			i	:= i + 1;
4647 			end loop;
4648 
4649 			if round(x_balance_amount,g_precision) <> 0.00 then
4650 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4651 			end if;
4652 
4653 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4654 			FROM DUAL;
4655  hr_utility.trace('	inserting into Sublines -33');
4656 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4657 			X_ROWID				=> l_rowid,
4658 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4659 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4660 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4661 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4662 			X_REASON_CODE			=> 'ORG_CHANGE',
4663 			X_PAY_AMOUNT			=> l_amount,
4664 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4665 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4666 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4667 			X_FTE				=> NULL,
4668 			X_ORGANIZATION_ID		=> l_new_org_id,
4669 			X_JOB_ID			=> NULL,
4670 			X_POSITION_ID			=> NULL,
4671 			X_GRADE_ID			=> NULL,
4672 			X_PEOPLE_GRP_ID		=> NULL,
4673 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4674 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
4675 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4676 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4677 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4678 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4679 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4680 			x_attribute1			=> NULL,
4681 			x_attribute2			=> NULL,
4682 			x_attribute3			=> NULL,
4683 			x_attribute4			=> NULL,
4684 			x_attribute5			=> NULL,
4685 			x_attribute6			=> NULL,
4686 			x_attribute7			=> NULL,
4687 			x_attribute8			=> NULL,
4688 			x_attribute9			=> NULL,
4689 			x_attribute10			=> NULL,
4690 			X_MODE				=> 'R');
4691 		l_rowid	:=	NULL;
4692 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4693 			X_ROWID				=> l_rowid,
4694 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4695 			X_REASON_CODE			=> 'ORG_CHANGE',
4696 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4697 			X_MODE				=> 'R');
4698 
4699 
4700 		DELETE psp_payroll_sub_lines
4701 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4702 		end;
4703 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
4704 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
4705 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
4706 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
4707 		begin
4708 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
4709 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
4710 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4711 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4712 		l_no_of_days	:= 0;
4713 		l_amount	:= 0.00;
4714 		while i <= i2 loop
4715 		l_amount	:= l_amount + daily_calendar(i);
4716 		if work_calendar(i)	= 'Y' then
4717 			l_no_of_days	:= l_no_of_days + 1;
4718 		end if;
4719 		i	:= i + 1;
4720 		end loop;
4721 
4722 		if round(x_balance_amount,g_precision) <> 0.00 then
4723 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4724 		end if;
4725 
4726 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4727 			FROM DUAL;
4728  hr_utility.trace('	inserting into Sublines -34');
4729 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4730 			X_ROWID				=> l_rowid,
4731 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4732 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4733 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4734 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4735 			X_REASON_CODE			=> 'ORG_CHANGE',
4736 			X_PAY_AMOUNT			=> l_amount,
4737 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4738 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4739 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4740 			X_FTE				=> NULL,
4741 			X_ORGANIZATION_ID		=> l_new_org_id,
4742 			X_JOB_ID			=> NULL,
4743 			X_POSITION_ID			=> NULL,
4744 			X_GRADE_ID			=> NULL,
4745 			X_PEOPLE_GRP_ID		=> NULL,
4746 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4747 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
4748 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4749 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4750 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4751 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4752 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4753 			x_attribute1			=> NULL,
4754 			x_attribute2			=> NULL,
4755 			x_attribute3			=> NULL,
4756 			x_attribute4			=> NULL,
4757 			x_attribute5			=> NULL,
4758 			x_attribute6			=> NULL,
4759 			x_attribute7			=> NULL,
4760 			x_attribute8			=> NULL,
4761 			x_attribute9			=> NULL,
4762 			x_attribute10			=> NULL,
4763 			X_MODE				=> 'R');
4764 		l_rowid	:=	NULL;
4765 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4766 			X_ROWID				=> l_rowid,
4767 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4768 			X_REASON_CODE			=> 'ORG_CHANGE',
4769 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4770 			X_MODE				=> 'R');
4771 
4772 			l_tmp_start_date	:= trunc(l_current_end_date);
4773 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
4774 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4775 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4776 			l_no_of_days	:= 0;
4777 			l_amount	:= 0.00;
4778 			while i <= i2 loop
4779 			l_amount	:= l_amount + daily_calendar(i);
4780 			if work_calendar(i)	= 'Y' then
4781 				l_no_of_days	:= l_no_of_days + 1;
4782 			end if;
4783 			i	:= i + 1;
4784 			end loop;
4785 
4786 			if round(x_balance_amount,g_precision) <> 0.00 then
4787 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4788 			end if;
4789 
4790 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4791 			FROM DUAL;
4792  hr_utility.trace('	inserting into Sublines -35');
4793 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4794 			X_ROWID				=> l_rowid,
4795 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4796 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4797 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4798 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4799 			X_REASON_CODE			=> 'ORG_CHANGE',
4800 			X_PAY_AMOUNT			=> l_amount,
4801 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4802 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4803 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4804 			X_FTE				=> NULL,
4805 			X_ORGANIZATION_ID		=> l_old_org_id,
4806 			X_JOB_ID			=> NULL,
4807 			X_POSITION_ID			=> NULL,
4808 			X_GRADE_ID			=> NULL,
4809 			X_PEOPLE_GRP_ID		=> NULL,
4810 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4811 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
4812 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4813 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4814 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4815 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4816 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4817 			x_attribute1			=> NULL,
4818 			x_attribute2			=> NULL,
4819 			x_attribute3			=> NULL,
4820 			x_attribute4			=> NULL,
4821 			x_attribute5			=> NULL,
4822 			x_attribute6			=> NULL,
4823 			x_attribute7			=> NULL,
4824 			x_attribute8			=> NULL,
4825 			x_attribute9			=> NULL,
4826 			x_attribute10			=> NULL,
4827 			X_MODE				=> 'R');
4828 		l_rowid	:=	NULL;
4829 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4830 			X_ROWID				=> l_rowid,
4831 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4832 			X_REASON_CODE			=> 'ORG_CHANGE',
4833 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4834 			X_MODE				=> 'R');
4835 
4836 
4837 		DELETE psp_payroll_sub_lines
4838 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
4839 		end;
4840 	else
4841 		begin
4842 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
4843 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
4844 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4845 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4846 		l_no_of_days	:= 0;
4847 		l_amount	:= 0.00;
4848 		while i <= i2 loop
4849 		l_amount	:= l_amount + daily_calendar(i);
4850 		if work_calendar(i)	= 'Y' then
4851 			l_no_of_days	:= l_no_of_days + 1;
4852 		end if;
4853 		i	:= i + 1;
4854 		end loop;
4855 
4856 		if round(x_balance_amount,g_precision) <> 0.00 then
4857 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4858 		end if;
4859 
4860 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4861 			FROM DUAL;
4862  hr_utility.trace('	inserting into Sublines -37');
4863 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4864 			X_ROWID				=> l_rowid,
4865 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4866 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4867 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4868 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4869 			X_REASON_CODE			=> 'ORG_CHANGE',
4870 			X_PAY_AMOUNT			=> l_amount,
4871 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4872 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4873 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4874 			X_FTE				=> NULL,
4875 			X_ORGANIZATION_ID		=> l_old_org_id,
4876 			X_JOB_ID			=> NULL,
4877 			X_POSITION_ID			=> NULL,
4878 			X_GRADE_ID			=> NULL,
4879 			X_PEOPLE_GRP_ID		=> NULL,
4880 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4881 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
4882 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4883 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4884 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4885 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4886 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4887 			x_attribute1			=> NULL,
4888 			x_attribute2			=> NULL,
4889 			x_attribute3			=> NULL,
4890 			x_attribute4			=> NULL,
4891 			x_attribute5			=> NULL,
4892 			x_attribute6			=> NULL,
4893 			x_attribute7			=> NULL,
4894 			x_attribute8			=> NULL,
4895 			x_attribute9			=> NULL,
4896 			x_attribute10			=> NULL,
4897 			X_MODE				=> 'R');
4898 		l_rowid	:=	NULL;
4899 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4900 			X_ROWID				=> l_rowid,
4901 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4902 			X_REASON_CODE			=> 'ORG_CHANGE',
4903 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4904 			X_MODE				=> 'R');
4905 
4906 			l_tmp_start_date	:= trunc(l_current_start_date);
4907 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
4908 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4909 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4910 			l_no_of_days	:= 0;
4911 			l_amount	:= 0.00;
4912 			while i <= i2 loop
4913 			l_amount	:= l_amount + daily_calendar(i);
4914 			if work_calendar(i)	= 'Y' then
4915 				l_no_of_days	:= l_no_of_days + 1;
4916 			end if;
4917 			i	:= i + 1;
4918 			end loop;
4919 
4920 			if round(x_balance_amount,g_precision) <> 0.00 then
4921 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4922 			end if;
4923 
4924 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4925 			FROM DUAL;
4926  hr_utility.trace('	inserting into Sublines -39');
4927 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4928 			X_ROWID				=> l_rowid,
4929 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4930 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4931 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4932 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4933 			X_REASON_CODE			=> 'ORG_CHANGE',
4934 			X_PAY_AMOUNT			=> l_amount,
4935 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
4936 			X_SALARY_USED			=> g_sublines_rec.salary_used,
4937 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
4938 			X_FTE				=> NULL,
4939 			X_ORGANIZATION_ID		=> l_new_org_id,
4940 			X_JOB_ID			=> NULL,
4941 			X_POSITION_ID			=> NULL,
4942 			X_GRADE_ID			=> NULL,
4943 			X_PEOPLE_GRP_ID		=> NULL,
4944 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
4945 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
4946 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
4947 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
4948 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
4949 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
4950 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
4951 			x_attribute1			=> NULL,
4952 			x_attribute2			=> NULL,
4953 			x_attribute3			=> NULL,
4954 			x_attribute4			=> NULL,
4955 			x_attribute5			=> NULL,
4956 			x_attribute6			=> NULL,
4957 			x_attribute7			=> NULL,
4958 			x_attribute8			=> NULL,
4959 			x_attribute9			=> NULL,
4960 			x_attribute10			=> NULL,
4961 			X_MODE				=> 'R');
4962 		l_rowid	:=	NULL;
4963 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
4964 			X_ROWID				=> l_rowid,
4965 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4966 			X_REASON_CODE			=> 'ORG_CHANGE',
4967 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
4968 			X_MODE				=> 'R');
4969 
4970 			l_tmp_start_date	:= trunc(l_current_end_date);
4971 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
4972 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
4973 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
4974 			l_no_of_days	:= 0;
4975 			l_amount	:= 0.00;
4976 			while i <= i2 loop
4977 			l_amount	:= l_amount + daily_calendar(i);
4978 			if work_calendar(i)	= 'Y' then
4979 				l_no_of_days	:= l_no_of_days + 1;
4980 			end if;
4981 			i	:= i + 1;
4982 			end loop;
4983 
4984 			if round(x_balance_amount,g_precision) <> 0.00 then
4985 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
4986 			end if;
4987 
4988 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
4989 			FROM DUAL;
4990  hr_utility.trace('	inserting into Sublines -42');
4991 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
4992 			X_ROWID				=> l_rowid,
4993 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
4994 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
4995 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
4996 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
4997 			X_REASON_CODE			=> 'ORG_CHANGE',
4998 			X_PAY_AMOUNT			=> l_amount,
4999 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5000 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5001 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5002 			X_FTE				=> NULL,
5003 			X_ORGANIZATION_ID		=> l_old_org_id,
5004 			X_JOB_ID			=> NULL,
5005 			X_POSITION_ID			=> NULL,
5006 			X_GRADE_ID			=> NULL,
5007 			X_PEOPLE_GRP_ID		=> NULL,
5008 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5009 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5010 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5011 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5012 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5013 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5014 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5015 			x_attribute1			=> NULL,
5016 			x_attribute2			=> NULL,
5017 			x_attribute3			=> NULL,
5018 			x_attribute4			=> NULL,
5019 			x_attribute5			=> NULL,
5020 			x_attribute6			=> NULL,
5021 			x_attribute7			=> NULL,
5022 			x_attribute8			=> NULL,
5023 			x_attribute9			=> NULL,
5024 			x_attribute10			=> NULL,
5025 			X_MODE				=> 'R');
5026 		l_rowid	:=	NULL;
5027 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5028 			X_ROWID				=> l_rowid,
5029 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5030 			X_REASON_CODE			=> 'ORG_CHANGE',
5031 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5032 			X_MODE				=> 'R');
5033 
5034 
5035 		DELETE psp_payroll_sub_lines
5036 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5037 		end;
5038 	end if;
5039 	l_old_org_id	:= l_new_org_id;
5040 	END LOOP;
5041 	close get_sublines_csr;
5042 	end;
5043 	end if;
5044  END LOOP;
5045  close get_assg_csr;
5046  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
5047 
5048  hr_utility.trace('	Leaving CREATE_SLINE_ORG_CHANGE');
5049 
5050  EXCEPTION
5051 	WHEN NO_DATA_FOUND then
5052 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
5053 	close get_assg_csr;
5054 	WHEN OTHERS then
5055 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_ORG_CHANGE');
5056 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
5057 	close get_assg_csr;
5058 
5059 end create_sline_org_change;
5060 
5061 -----------------------CREATE_SLINE_JOB_CHANGE--------------------
5062 --
5063 PROCEDURE CREATE_SLINE_JOB_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
5064 					X_ASSIGNMENT_ID	IN NUMBER,
5065 					X_BALANCE_AMOUNT IN NUMBER,
5066 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
5067 CURSOR get_old_job_csr IS
5068 SELECT effective_start_date, job_id
5069 FROM	per_assignments_f
5070 WHERE assignment_id = x_assignment_id and
5071 	effective_start_date < g_start_date and
5072 	effective_start_date = (select max(effective_start_date) from per_assignments_f
5073 		where assignment_id = x_assignment_id
5074 		AND assignment_type ='E' --Added for bug 2624259.
5075 		AND effective_start_date < g_start_date);
5076 
5077 l_effective_start_date	date;
5078 l_old_job_id		number(9);
5079 
5080 CURSOR get_assg_csr IS
5081 SELECT effective_start_date, effective_end_date, job_id
5082 FROM	per_assignments_f
5083 WHERE assignment_id = x_assignment_id
5084 	AND assignment_type ='E' --Added for bug 2624259.
5085 	AND
5086 	(g_start_date between effective_start_date and effective_end_date or
5087 	g_end_date	between effective_start_date and effective_end_date or
5088 	(g_start_date <= effective_start_date and g_end_date >= effective_end_date ))
5089 order by effective_start_date;
5090 
5091 l_current_start_date	date;
5092 l_current_end_date	date;
5093 l_new_job_id		number(9);
5094 
5095 CURSOR get_sublines_csr IS
5096 SELECT *
5097 FROM	psp_payroll_sub_lines
5098 WHERE payroll_line_id	= x_payroll_line_id and
5099 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
5100 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
5101 	(sub_line_start_date <= l_current_start_date and sub_line_end_date >= l_current_end_date))
5102 order by sub_line_start_date;
5103 
5104 g_sublines_rec get_sublines_csr%ROWTYPE;
5105 
5106 l_tmp_start_date	date;
5107 l_tmp_end_date		date;
5108 l_rowid			varchar2(20);
5109 l_sub_line_id		number(9);
5110 i		number(9)	:= 0;
5111 i2		number(9)	:= 0;
5112 l_amount	number(22,2)	:= 0;
5113 l_no_of_days	number(3)	:= 0;
5114 
5115 
5116 begin
5117 
5118 hr_utility.trace('	Entering CREATE_SLINE_JOB_CHANGE');
5119 
5120  open get_old_job_csr;
5121  fetch get_old_job_csr into l_effective_start_date, l_old_job_id;
5122  if get_old_job_csr%NOTFOUND then
5123 	l_old_job_id	:= 0;
5124  end if;
5125 
5126  open get_assg_csr;
5127  LOOP
5128 	fetch get_assg_csr into l_current_start_date, l_current_end_date, l_new_job_id;
5129 	EXIT WHEN get_assg_csr%NOTFOUND;
5130 	if NVL(l_old_job_id,0) = 0 or NVL(l_old_job_id,0) = NVL(l_new_job_id,0) then
5131 	l_old_job_id	:= l_new_job_id;
5132 	else
5133 	begin
5134 	open get_sublines_csr;
5135 	LOOP
5136 	fetch get_sublines_csr into g_sublines_rec;
5137 	EXIT WHEN get_sublines_csr%NOTFOUND;
5138 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
5139 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
5140 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
5141 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
5142 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
5143 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
5144 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
5145 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
5146 		begin
5147 		UPDATE psp_payroll_sub_lines
5148 			set job_id = l_new_job_id
5149 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5150 		end;
5151 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
5152 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
5153 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
5154 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
5155 		begin
5156 			l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
5157 			l_tmp_end_date	:= trunc(l_current_start_date) - 1;
5158 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5159 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5160 			l_no_of_days	:= 0;
5161 			l_amount	:= 0.00;
5162 			while i <= i2 loop
5163 			l_amount	:= l_amount + daily_calendar(i);
5164 			if work_calendar(i)	= 'Y' then
5165 				l_no_of_days	:= l_no_of_days + 1;
5166 			end if;
5167 			i	:= i + 1;
5168 			end loop;
5169 
5170 			if round(x_balance_amount,g_precision) <> 0.00 then
5171 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5172 			end if;
5173 
5174 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5175 			FROM DUAL;
5176  hr_utility.trace('	inserting into Sublines -52');
5177 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5178 			X_ROWID				=> l_rowid,
5179 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5180 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5181 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
5182 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5183 			X_REASON_CODE			=> 'JOB_CHANGE',
5184 			X_PAY_AMOUNT			=> l_amount,
5185 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5186 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5187 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5188 			X_FTE				=> NULL,
5189 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5190 			X_JOB_ID			=> l_old_job_id,
5191 			X_POSITION_ID			=> NULL,
5192 			X_GRADE_ID			=> NULL,
5193 			X_PEOPLE_GRP_ID		=> NULL,
5194 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5195 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5196 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5197 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5198 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5199 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5200 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5201 			x_attribute1			=> NULL,
5202 			x_attribute2			=> NULL,
5203 			x_attribute3			=> NULL,
5204 			x_attribute4			=> NULL,
5205 			x_attribute5			=> NULL,
5206 			x_attribute6			=> NULL,
5207 			x_attribute7			=> NULL,
5208 			x_attribute8			=> NULL,
5209 			x_attribute9			=> NULL,
5210 			x_attribute10			=> NULL,
5211 			X_MODE				=> 'R');
5212 		l_rowid	:=	NULL;
5213 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5214 			X_ROWID				=> l_rowid,
5215 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5216 			X_REASON_CODE			=> 'JOB_CHANGE',
5217 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5218 			X_MODE				=> 'R');
5219 
5220 			l_tmp_start_date	:= trunc(l_current_start_date);
5221 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
5222 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5223 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5224 			l_no_of_days	:= 0;
5225 			l_amount	:= 0.00;
5226 			while i <= i2 loop
5227 			l_amount	:= l_amount + daily_calendar(i);
5228 			if work_calendar(i)	= 'Y' then
5229 				l_no_of_days	:= l_no_of_days + 1;
5230 			end if;
5231 			i	:= i + 1;
5232 			end loop;
5233 
5234 			if round(x_balance_amount,g_precision) <> 0.00 then
5235 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5236 			end if;
5237 
5238 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5239 			FROM DUAL;
5240  hr_utility.trace('	inserting into Sublines -62');
5241 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5242 			X_ROWID				=> l_rowid,
5243 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5244 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5245 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5246 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5247 			X_REASON_CODE			=> 'JOB_CHANGE',
5248 			X_PAY_AMOUNT			=> l_amount,
5249 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5250 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5251 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5252 			X_FTE				=> NULL,
5253 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5254 			X_JOB_ID			=> l_new_job_id,
5255 			X_POSITION_ID			=> NULL,
5256 			X_GRADE_ID			=> NULL,
5257 			X_PEOPLE_GRP_ID		=> NULL,
5258 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5259 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5260 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5261 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5262 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5263 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5264 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5265 			x_attribute1			=> NULL,
5266 			x_attribute2			=> NULL,
5267 			x_attribute3			=> NULL,
5268 			x_attribute4			=> NULL,
5269 			x_attribute5			=> NULL,
5270 			x_attribute6			=> NULL,
5271 			x_attribute7			=> NULL,
5272 			x_attribute8			=> NULL,
5273 			x_attribute9			=> NULL,
5274 			x_attribute10			=> NULL,
5275 			X_MODE				=> 'R');
5276 		l_rowid	:=	NULL;
5277 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5278 			X_ROWID				=> l_rowid,
5279 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5280 			X_REASON_CODE			=> 'JOB_CHANGE',
5281 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5282 			X_MODE				=> 'R' );
5283 
5284 
5285 		DELETE psp_payroll_sub_lines
5286 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5287 		end;
5288 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
5289 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
5290 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
5291 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
5292 		begin
5293 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
5294 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
5295 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5296 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5297 		l_no_of_days	:= 0;
5298 		l_amount	:= 0.00;
5299 		while i <= i2 loop
5300 		l_amount	:= l_amount + daily_calendar(i);
5301 		if work_calendar(i)	= 'Y' then
5302 			l_no_of_days	:= l_no_of_days + 1;
5303 		end if;
5304 		i	:= i + 1;
5305 		end loop;
5306 
5307 		if round(x_balance_amount,g_precision) <> 0.00 then
5308 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5309 		end if;
5310 
5311 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5312 			FROM DUAL;
5313  hr_utility.trace('	inserting into Sublines -92');
5314 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5315 			X_ROWID				=> l_rowid,
5316 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5317 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5318 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5319 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5320 			X_REASON_CODE			=> 'JOB_CHANGE',
5321 			X_PAY_AMOUNT			=> l_amount,
5322 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5323 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5324 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5325 			X_FTE				=> NULL,
5326 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5327 			X_JOB_ID			=> l_new_job_id,
5328 			X_POSITION_ID			=> NULL,
5329 			X_GRADE_ID			=> NULL,
5330 			X_PEOPLE_GRP_ID		=> NULL,
5331 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5332 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5333 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5334 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5335 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5336 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5337 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5338 			x_attribute1			=> NULL,
5339 			x_attribute2			=> NULL,
5340 			x_attribute3			=> NULL,
5341 			x_attribute4			=> NULL,
5342 			x_attribute5			=> NULL,
5343 			x_attribute6			=> NULL,
5344 			x_attribute7			=> NULL,
5345 			x_attribute8			=> NULL,
5346 			x_attribute9			=> NULL,
5347 			x_attribute10			=> NULL,
5348 			X_MODE				=> 'R');
5349 		l_rowid	:=	NULL;
5350 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5351 			X_ROWID				=> l_rowid,
5352 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5353 			X_REASON_CODE			=> 'JOB_CHANGE',
5354 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5355 			X_MODE				=> 'R');
5356 
5357 			l_tmp_start_date	:= trunc(l_current_end_date);
5358 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
5359 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5360 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5361 			l_no_of_days	:= 0;
5362 			l_amount	:= 0.00;
5363 			while i <= i2 loop
5364 			l_amount	:= l_amount + daily_calendar(i);
5365 			if work_calendar(i)	= 'Y' then
5366 				l_no_of_days	:= l_no_of_days + 1;
5367 			end if;
5368 			i	:= i + 1;
5369 			end loop;
5370 
5371 			if round(x_balance_amount,g_precision) <> 0.00 then
5372 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5373 			end if;
5374 
5375 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5376 			FROM DUAL;
5377  hr_utility.trace('	inserting into Sublines -102');
5378 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5379 			X_ROWID				=> l_rowid,
5380 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5381 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5382 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5383 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5384 			X_REASON_CODE			=> 'JOB_CHANGE',
5385 			X_PAY_AMOUNT			=> l_amount,
5386 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5387 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5388 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5389 			X_FTE				=> NULL,
5390 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5391 			X_JOB_ID			=> l_old_job_id,
5392 			X_POSITION_ID			=> NULL,
5393 			X_GRADE_ID			=> NULL,
5394 			X_PEOPLE_GRP_ID		=> NULL,
5395 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5396 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5397 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5398 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5399 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5400 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5401 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5402 			x_attribute1			=> NULL,
5403 			x_attribute2			=> NULL,
5404 			x_attribute3			=> NULL,
5405 			x_attribute4			=> NULL,
5406 			x_attribute5			=> NULL,
5407 			x_attribute6			=> NULL,
5408 			x_attribute7			=> NULL,
5409 			x_attribute8			=> NULL,
5410 			x_attribute9			=> NULL,
5411 			x_attribute10			=> NULL,
5412 			X_MODE				=> 'R');
5413 		l_rowid	:=	NULL;
5414 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5415 			X_ROWID				=> l_rowid,
5416 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5417 			X_REASON_CODE			=> 'JOB_CHANGE',
5418 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5419 			X_MODE				=> 'R' );
5420 
5421 
5422 		DELETE psp_payroll_sub_lines
5423 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5424 		end;
5425 	else
5426 		begin
5427 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
5428 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
5429 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5430 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5431 		l_no_of_days	:= 0;
5432 		l_amount	:= 0.00;
5433 		while i <= i2 loop
5434 		l_amount	:= l_amount + daily_calendar(i);
5435 		if work_calendar(i)	= 'Y' then
5436 			l_no_of_days	:= l_no_of_days + 1;
5437 		end if;
5438 		i	:= i + 1;
5439 		end loop;
5440 
5441 		if round(x_balance_amount,g_precision) <> 0.00 then
5442 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5443 		end if;
5444 
5445 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5446 			FROM DUAL;
5447  hr_utility.trace('	inserting into Sublines -202');
5448 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5449 			X_ROWID				=> l_rowid,
5450 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5451 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5452 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5453 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5454 			X_REASON_CODE			=> 'JOB_CHANGE',
5455 			X_PAY_AMOUNT			=> l_amount,
5456 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5457 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5458 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5459 			X_FTE				=> NULL,
5460 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5461 			X_JOB_ID			=> l_old_job_id,
5462 			X_POSITION_ID			=> NULL,
5463 			X_GRADE_ID			=> NULL,
5464 			X_PEOPLE_GRP_ID		=> NULL,
5465 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5466 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5467 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5468 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5469 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5470 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5471 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5472 			x_attribute1			=> NULL,
5473 			x_attribute2			=> NULL,
5474 			x_attribute3			=> NULL,
5475 			x_attribute4			=> NULL,
5476 			x_attribute5			=> NULL,
5477 			x_attribute6			=> NULL,
5478 			x_attribute7			=> NULL,
5479 			x_attribute8			=> NULL,
5480 			x_attribute9			=> NULL,
5481 			x_attribute10			=> NULL,
5482 			X_MODE				=> 'R');
5483 		l_rowid	:=	NULL;
5484 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5485 			X_ROWID				=> l_rowid,
5486 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5487 			X_REASON_CODE			=> 'JOB_CHANGE',
5488 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5489 			X_MODE				=> 'R');
5490 
5491 			l_tmp_start_date	:= trunc(l_current_start_date);
5492 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
5493 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5494 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5495 			l_no_of_days	:= 0;
5496 			l_amount	:= 0.00;
5497 			while i <= i2 loop
5498 			l_amount	:= l_amount + daily_calendar(i);
5499 			if work_calendar(i)	= 'Y' then
5500 				l_no_of_days	:= l_no_of_days + 1;
5501 			end if;
5502 			i	:= i + 1;
5503 			end loop;
5504 
5505 			if round(x_balance_amount,g_precision) <> 0.00 then
5506 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5507 			end if;
5508 
5509 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5510 			FROM DUAL;
5511  hr_utility.trace('	inserting into Sublines -302');
5512 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5513 			X_ROWID				=> l_rowid,
5514 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5515 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5516 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5517 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5518 			X_REASON_CODE			=> 'JOB_CHANGE',
5519 			X_PAY_AMOUNT			=> l_amount,
5520 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5521 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5522 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5523 			X_FTE				=> NULL,
5524 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5525 			X_JOB_ID			=> l_new_job_id,
5526 			X_POSITION_ID			=> NULL,
5527 			X_GRADE_ID			=> NULL,
5528 			X_PEOPLE_GRP_ID		=> NULL,
5529 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5530 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5531 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5532 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5533 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5534 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5535 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5536 			x_attribute1			=> NULL,
5537 			x_attribute2			=> NULL,
5538 			x_attribute3			=> NULL,
5539 			x_attribute4			=> NULL,
5540 			x_attribute5			=> NULL,
5541 			x_attribute6			=> NULL,
5542 			x_attribute7			=> NULL,
5543 			x_attribute8			=> NULL,
5544 			x_attribute9			=> NULL,
5545 			x_attribute10			=> NULL,
5546 			X_MODE				=> 'R');
5547 		l_rowid	:=	NULL;
5548 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5549 			X_ROWID				=> l_rowid,
5550 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5551 			X_REASON_CODE			=> 'JOB_CHANGE',
5552 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5553 			X_MODE				=> 'R');
5554 
5555 			l_tmp_start_date	:= trunc(l_current_end_date);
5556 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
5557 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5558 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5559 			l_no_of_days	:= 0;
5560 			l_amount	:= 0.00;
5561 			while i <= i2 loop
5562 			l_amount	:= l_amount + daily_calendar(i);
5563 			if work_calendar(i)	= 'Y' then
5564 				l_no_of_days	:= l_no_of_days + 1;
5565 			end if;
5566 			i	:= i + 1;
5567 			end loop;
5568 
5569 			if round(x_balance_amount,g_precision) <> 0.00 then
5570 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5571 			end if;
5572 
5573 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5574 			FROM DUAL;
5575  hr_utility.trace('	inserting into Sublines -402');
5576 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5577 			X_ROWID				=> l_rowid,
5578 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5579 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5580 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5581 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5582 			X_REASON_CODE			=> 'JOB_CHANGE',
5583 			X_PAY_AMOUNT			=> l_amount,
5584 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5585 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5586 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5587 			X_FTE				=> NULL,
5588 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5589 			X_JOB_ID			=> l_old_job_id,
5590 			X_POSITION_ID			=> NULL,
5591 			X_GRADE_ID			=> NULL,
5592 			X_PEOPLE_GRP_ID		=> NULL,
5593 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5594 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5595 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5596 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5597 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5598 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5599 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5600 			x_attribute1			=> NULL,
5601 			x_attribute2			=> NULL,
5602 			x_attribute3			=> NULL,
5603 			x_attribute4			=> NULL,
5604 			x_attribute5			=> NULL,
5605 			x_attribute6			=> NULL,
5606 			x_attribute7			=> NULL,
5607 			x_attribute8			=> NULL,
5608 			x_attribute9			=> NULL,
5609 			x_attribute10			=> NULL,
5610 			X_MODE				=> 'R');
5611 		l_rowid	:=	NULL;
5612 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5613 			X_ROWID				=> l_rowid,
5614 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5615 			X_REASON_CODE			=> 'JOB_CHANGE',
5616 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5617 			X_MODE				=> 'R');
5618 
5619 
5620 		DELETE psp_payroll_sub_lines
5621 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5622 		end;
5623 	end if;
5624 	l_old_job_id	:= l_new_job_id;
5625 	END LOOP;
5626 	close get_sublines_csr;
5627 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
5628 	EXCEPTION
5629 	WHEN NO_DATA_FOUND then
5630 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
5631 	close get_sublines_csr;
5632 	WHEN OTHERS then
5633 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_JOB_CHANGE');
5634 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
5635 	close get_sublines_csr;
5636 	end;
5637 	end if;
5638  END LOOP;
5639  close get_assg_csr;
5640  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
5641  hr_utility.trace('	Leaving CREATE_SLINE_JOB_CHANGE');
5642  EXCEPTION
5643 	WHEN NO_DATA_FOUND then
5644 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
5645 	close get_assg_csr;
5646 	WHEN OTHERS then
5647 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_JOB_CHANGE');
5648 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
5649 	close get_assg_csr;
5650 end create_sline_job_change;
5651 --------------------------------CREATE_SLINE_POSITION_CHANGE--------------
5652 ---
5653 PROCEDURE CREATE_SLINE_POSITION_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
5654 					X_ASSIGNMENT_ID	IN NUMBER,
5655 					X_BALANCE_AMOUNT IN NUMBER,
5656 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
5657 CURSOR get_old_position_csr IS
5658 SELECT effective_start_date, position_id
5659 FROM	per_assignments_f
5660 WHERE assignment_id = x_assignment_id and
5661 	effective_start_date < g_start_date and
5662 	effective_start_date = (select max(effective_start_date) from per_assignments_f
5663 		where assignment_id = x_assignment_id
5664 		AND assignment_type ='E' --Added for bug 2624259.
5665 		AND effective_start_date < g_start_date);
5666 
5667 l_effective_start_date		date;
5668 l_old_position_id		number(15);	-- Bug 2231410 : Increased the lenght of position_id column from 9 to 15
5669 
5670 CURSOR get_assg_csr IS
5671 SELECT effective_start_date, effective_end_date, position_id
5672 FROM	per_assignments_f
5673 WHERE assignment_id = x_assignment_id
5674 	AND assignment_type ='E' --Added for bug 2624259.
5675 	AND
5676 	(g_start_date between effective_start_date and effective_end_date or
5677 	g_end_date	between effective_start_date and effective_end_date or
5678 	(g_start_date <= effective_start_date and g_end_date >= effective_end_date ))
5679 order by effective_start_date;
5680 
5681 l_current_start_date	date;
5682 l_current_end_date	date;
5683 l_new_position_id		number(15); -- Bug 2231410 : Increased the lenght of position_id column from 9 to 15
5684 
5685 CURSOR get_sublines_csr IS
5686 SELECT *
5687 FROM	psp_payroll_sub_lines
5688 WHERE payroll_line_id	= x_payroll_line_id and
5689 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
5690 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
5691 	(sub_line_start_date <= l_current_start_date and sub_line_end_date >= l_current_end_date))
5692 order by sub_line_start_date;
5693 
5694 g_sublines_rec get_sublines_csr%ROWTYPE;
5695 
5696 l_tmp_start_date	date;
5697 l_tmp_end_date		date;
5698 l_rowid			varchar2(20);
5699 l_sub_line_id		number(9);
5700 i		number(9)	:= 0;
5701 i2		number(9)	:= 0;
5702 l_amount	number(22,2)	:= 0;
5703 l_no_of_days	number(3)	:= 0;
5704 
5705 
5706 begin
5707 
5708  hr_utility.trace('	Entering CREATE_SLINE_POSITION_CHANGE');
5709 
5710  open get_old_position_csr;
5711  fetch get_old_position_csr into l_effective_start_date, l_old_position_id;
5712  if get_old_position_csr%NOTFOUND then
5713 	l_old_position_id	:= 0;
5714  end if;
5715 
5716  open get_assg_csr;
5717  LOOP
5718 	fetch get_assg_csr into l_current_start_date, l_current_end_date, l_new_position_id;
5719 	EXIT WHEN get_assg_csr%NOTFOUND;
5720 	if NVL(l_old_position_id,0) = 0 or NVL(l_old_position_id,0) = NVL(l_new_position_id,0) then
5721 	l_old_position_id	:= l_new_position_id;
5722 	else
5723 	begin
5724 	open get_sublines_csr;
5725 	LOOP
5726 	fetch get_sublines_csr into g_sublines_rec;
5727 	EXIT WHEN get_sublines_csr%NOTFOUND;
5728 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
5729 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
5730 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
5731 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
5732 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
5733 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
5734 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
5735 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
5736 		begin
5737 		UPDATE psp_payroll_sub_lines
5738 			set position_id = l_new_position_id
5739 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5740 		end;
5741 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
5742 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
5743 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
5744 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
5745 		begin
5746 			l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
5747 			l_tmp_end_date	:= trunc(l_current_start_date) - 1;
5748 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5749 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5750 			l_no_of_days	:= 0;
5751 			l_amount	:= 0.00;
5752 			while i <= i2 loop
5753 			l_amount	:= l_amount + daily_calendar(i);
5754 			if work_calendar(i)	= 'Y' then
5755 				l_no_of_days	:= l_no_of_days + 1;
5756 			end if;
5757 			i	:= i + 1;
5758 			end loop;
5759 
5760 			if round(x_balance_amount,g_precision) <> 0.00 then
5761 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5762 			end if;
5763 
5764 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5765 			FROM DUAL;
5766  hr_utility.trace('	inserting into Sublines -502');
5767 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5768 			X_ROWID				=> l_rowid,
5769 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5770 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5771 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
5772 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5773 			X_REASON_CODE			=> 'POSITION_CHANGE',
5774 			X_PAY_AMOUNT			=> l_amount,
5775 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5776 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5777 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5778 			X_FTE				=> NULL,
5779 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5780 			X_JOB_ID			=> g_sublines_rec.job_id,
5781 			X_POSITION_ID			=> l_old_position_id,
5782 			X_GRADE_ID			=> NULL,
5783 			X_PEOPLE_GRP_ID		=> NULL,
5784 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5785 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5786 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5787 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5788 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5789 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5790 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5791 			x_attribute1			=> NULL,
5792 			x_attribute2			=> NULL,
5793 			x_attribute3			=> NULL,
5794 			x_attribute4			=> NULL,
5795 			x_attribute5			=> NULL,
5796 			x_attribute6			=> NULL,
5797 			x_attribute7			=> NULL,
5798 			x_attribute8			=> NULL,
5799 			x_attribute9			=> NULL,
5800 			x_attribute10			=> NULL,
5801 			X_MODE				=> 'R');
5802 		l_rowid	:=	NULL;
5803 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5804 			X_ROWID				=> l_rowid,
5805 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5806 			X_REASON_CODE			=> 'POSITION_CHANGE',
5807 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5808 			X_MODE				=> 'R');
5809 
5810 			l_tmp_start_date	:= trunc(l_current_start_date);
5811 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
5812 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5813 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5814 			l_no_of_days	:= 0;
5815 			l_amount	:= 0.00;
5816 			while i <= i2 loop
5817 			l_amount	:= l_amount + daily_calendar(i);
5818 			if work_calendar(i)	= 'Y' then
5819 				l_no_of_days	:= l_no_of_days + 1;
5820 			end if;
5821 			i	:= i + 1;
5822 			end loop;
5823 
5824 			if round(x_balance_amount,g_precision) <> 0.00 then
5825 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5826 			end if;
5827 
5828 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5829 			FROM DUAL;
5830  hr_utility.trace('	inserting into Sublines -502');
5831 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5832 			X_ROWID				=> l_rowid,
5833 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5834 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5835 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5836 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5837 			X_REASON_CODE			=> 'POSITION_CHANGE',
5838 			X_PAY_AMOUNT			=> l_amount,
5839 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5840 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5841 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5842 			X_FTE				=> NULL,
5843 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5844 			X_JOB_ID			=> g_sublines_rec.job_id,
5845 			X_POSITION_ID			=> l_new_position_id,
5846 			X_GRADE_ID			=> NULL,
5847 			X_PEOPLE_GRP_ID		=> NULL,
5848 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5849 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5850 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5851 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5852 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5853 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5854 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5855 			x_attribute1			=> NULL,
5856 			x_attribute2			=> NULL,
5857 			x_attribute3			=> NULL,
5858 			x_attribute4			=> NULL,
5859 			x_attribute5			=> NULL,
5860 			x_attribute6			=> NULL,
5861 			x_attribute7			=> NULL,
5862 			x_attribute8			=> NULL,
5863 			x_attribute9			=> NULL,
5864 			x_attribute10			=> NULL,
5865 			X_MODE				=> 'R');
5866 		l_rowid	:=	NULL;
5867 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5868 			X_ROWID				=> l_rowid,
5869 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5870 			X_REASON_CODE			=> 'POSITION_CHANGE',
5871 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5872 			X_MODE				=> 'R');
5873 
5874 
5875 		DELETE psp_payroll_sub_lines
5876 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
5877 		end;
5878 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
5879 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
5880 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
5881 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
5882 		begin
5883 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
5884 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
5885 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5886 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5887 		l_no_of_days	:= 0;
5888 		l_amount	:= 0.00;
5889 		while i <= i2 loop
5890 		l_amount	:= l_amount + daily_calendar(i);
5891 		if work_calendar(i)	= 'Y' then
5892 			l_no_of_days	:= l_no_of_days + 1;
5893 		end if;
5894 		i	:= i + 1;
5895 		end loop;
5896 
5897 		if round(x_balance_amount,g_precision) <> 0.00 then
5898 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5899 		end if;
5900 
5901 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5902 			FROM DUAL;
5903  hr_utility.trace('	inserting into Sublines -702');
5904 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5905 			X_ROWID				=> l_rowid,
5906 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5907 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5908 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5909 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5910 			X_REASON_CODE			=> 'POSITION_CHANGE',
5911 			X_PAY_AMOUNT			=> l_amount,
5912 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5913 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5914 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5915 			X_FTE				=> NULL,
5916 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5917 			X_JOB_ID			=> g_sublines_rec.job_id,
5918 			X_POSITION_ID			=> l_new_position_id,
5919 			X_GRADE_ID			=> NULL,
5920 			X_PEOPLE_GRP_ID		=> NULL,
5921 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5922 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5923 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5924 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5925 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5926 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5927 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5928 			x_attribute1			=> NULL,
5929 			x_attribute2			=> NULL,
5930 			x_attribute3			=> NULL,
5931 			x_attribute4			=> NULL,
5932 			x_attribute5			=> NULL,
5933 			x_attribute6			=> NULL,
5934 			x_attribute7			=> NULL,
5935 			x_attribute8			=> NULL,
5936 			x_attribute9			=> NULL,
5937 			x_attribute10			=> NULL,
5938 			X_MODE				=> 'R');
5939 		l_rowid	:=	NULL;
5940 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
5941 			X_ROWID				=> l_rowid,
5942 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5943 			X_REASON_CODE			=> 'POSITION_CHANGE',
5944 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
5945 			X_MODE				=> 'R');
5946 
5947 			l_tmp_start_date	:= trunc(l_current_end_date);
5948 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
5949 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
5950 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
5951 			l_no_of_days	:= 0;
5952 			l_amount	:= 0.00;
5953 			while i <= i2 loop
5954 			l_amount	:= l_amount + daily_calendar(i);
5955 			if work_calendar(i)	= 'Y' then
5956 				l_no_of_days	:= l_no_of_days + 1;
5957 			end if;
5958 			i	:= i + 1;
5959 			end loop;
5960 
5961 			if round(x_balance_amount,g_precision) <> 0.00 then
5962 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
5963 			end if;
5964 
5965 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
5966 			FROM DUAL;
5967  hr_utility.trace('	inserting into Sublines -802');
5968 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
5969 			X_ROWID				=> l_rowid,
5970 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
5971 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
5972 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
5973 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
5974 			X_REASON_CODE			=> 'POSITION_CHANGE',
5975 			X_PAY_AMOUNT			=> l_amount,
5976 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
5977 			X_SALARY_USED			=> g_sublines_rec.salary_used,
5978 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
5979 			X_FTE				=> NULL,
5980 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
5981 			X_JOB_ID			=> g_sublines_rec.job_id,
5982 			X_POSITION_ID			=> l_old_position_id,
5983 			X_GRADE_ID			=> NULL,
5984 			X_PEOPLE_GRP_ID		=> NULL,
5985 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
5986 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
5987 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
5988 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
5989 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
5990 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
5991 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
5992 			x_attribute1			=> NULL,
5993 			x_attribute2			=> NULL,
5994 			x_attribute3			=> NULL,
5995 			x_attribute4			=> NULL,
5996 			x_attribute5			=> NULL,
5997 			x_attribute6			=> NULL,
5998 			x_attribute7			=> NULL,
5999 			x_attribute8			=> NULL,
6000 			x_attribute9			=> NULL,
6001 			x_attribute10			=> NULL,
6002 			X_MODE				=> 'R');
6003 		l_rowid	:=	NULL;
6004 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6005 			X_ROWID				=> l_rowid,
6006 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6007 			X_REASON_CODE			=> 'POSITION_CHANGE',
6008 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6009 			X_MODE				=> 'R' );
6010 
6011 
6012 		DELETE psp_payroll_sub_lines
6013 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6014 		end;
6015 	else
6016 		begin
6017 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
6018 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
6019 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6020 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6021 		l_no_of_days	:= 0;
6022 		l_amount	:= 0.00;
6023 		while i <= i2 loop
6024 		l_amount	:= l_amount + daily_calendar(i);
6025 		if work_calendar(i)	= 'Y' then
6026 			l_no_of_days	:= l_no_of_days + 1;
6027 		end if;
6028 		i	:= i + 1;
6029 		end loop;
6030 
6031 		if round(x_balance_amount,g_precision) <> 0.00 then
6032 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6033 		end if;
6034 
6035 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6036 			FROM DUAL;
6037  hr_utility.trace('	inserting into Sublines -902');
6038 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6039 			X_ROWID				=> l_rowid,
6040 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6041 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6042 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6043 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6044 			X_REASON_CODE			=> 'POSITION_CHANGE',
6045 			X_PAY_AMOUNT			=> l_amount,
6046 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6047 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6048 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6049 			X_FTE				=> NULL,
6050 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6051 			X_JOB_ID			=> g_sublines_rec.job_id,
6052 			X_POSITION_ID			=> l_old_position_id,
6053 			X_GRADE_ID			=> NULL,
6054 			X_PEOPLE_GRP_ID		=> NULL,
6055 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6056 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6057 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6058 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6059 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6060 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6061 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6062 			x_attribute1			=> NULL,
6063 			x_attribute2			=> NULL,
6064 			x_attribute3			=> NULL,
6065 			x_attribute4			=> NULL,
6066 			x_attribute5			=> NULL,
6067 			x_attribute6			=> NULL,
6068 			x_attribute7			=> NULL,
6069 			x_attribute8			=> NULL,
6070 			x_attribute9			=> NULL,
6071 			x_attribute10			=> NULL,
6072 			X_MODE				=> 'R');
6073 		l_rowid	:=	NULL;
6074 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6075 			X_ROWID				=> l_rowid,
6076 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6077 			X_REASON_CODE			=> 'POSITION_CHANGE',
6078 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6079 			X_MODE				=> 'R');
6080 
6081 			l_tmp_start_date	:= trunc(l_current_start_date);
6082 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
6083 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6084 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6085 			l_no_of_days	:= 0;
6086 			l_amount	:= 0.00;
6087 			while i <= i2 loop
6088 			l_amount	:= l_amount + daily_calendar(i);
6089 			if work_calendar(i)	= 'Y' then
6090 				l_no_of_days	:= l_no_of_days + 1;
6091 			end if;
6092 			i	:= i + 1;
6093 			end loop;
6094 
6095 			if round(x_balance_amount,g_precision) <> 0.00 then
6096 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)),g_precision);
6097 			end if;
6098 
6099 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6100 			FROM DUAL;
6101  hr_utility.trace('	inserting into Sublines -802');
6102 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6103 			X_ROWID				=> l_rowid,
6104 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6105 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6106 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6107 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6108 			X_REASON_CODE			=> 'POSITION_CHANGE',
6109 			X_PAY_AMOUNT			=> l_amount,
6110 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6111 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6112 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6113 			X_FTE				=> NULL,
6114 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6115 			X_JOB_ID			=> g_sublines_rec.job_id,
6116 			X_POSITION_ID			=> l_new_position_id,
6117 			X_GRADE_ID			=> NULL,
6118 			X_PEOPLE_GRP_ID		=> NULL,
6119 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6120 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6121 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6122 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6123 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6124 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6125 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6126 			x_attribute1			=> NULL,
6127 			x_attribute2			=> NULL,
6128 			x_attribute3			=> NULL,
6129 			x_attribute4			=> NULL,
6130 			x_attribute5			=> NULL,
6131 			x_attribute6			=> NULL,
6132 			x_attribute7			=> NULL,
6133 			x_attribute8			=> NULL,
6134 			x_attribute9			=> NULL,
6135 			x_attribute10			=> NULL,
6136 			X_MODE				=> 'R');
6137 		l_rowid	:=	NULL;
6138 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6139 			X_ROWID				=> l_rowid,
6140 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6141 			X_REASON_CODE			=> 'POSITION_CHANGE',
6142 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6143 			X_MODE				=> 'R');
6144 
6145 			l_tmp_start_date	:= trunc(l_current_end_date);
6146 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
6147 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6148 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6149 			l_no_of_days	:= 0;
6150 			l_amount	:= 0.00;
6151 			while i <= i2 loop
6152 			l_amount	:= l_amount + daily_calendar(i);
6153 			if work_calendar(i)	= 'Y' then
6154 				l_no_of_days	:= l_no_of_days + 1;
6155 			end if;
6156 			i	:= i + 1;
6157 			end loop;
6158 
6159 			if round(x_balance_amount,g_precision) <> 0.00 then
6160 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6161 			end if;
6162 
6163 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6164 			FROM DUAL;
6165  hr_utility.trace('	inserting into Sublines -1002');
6166 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6167 			X_ROWID				=> l_rowid,
6168 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6169 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6170 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6171 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6172 			X_REASON_CODE			=> 'POSITION_CHANGE',
6173 			X_PAY_AMOUNT			=> l_amount,
6174 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6175 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6176 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6177 			X_FTE				=> NULL,
6178 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6179 			X_JOB_ID			=> g_sublines_rec.job_id,
6180 			X_POSITION_ID			=> l_old_position_id,
6181 			X_GRADE_ID			=> NULL,
6182 			X_PEOPLE_GRP_ID		=> NULL,
6183 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6184 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6185 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6186 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6187 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6188 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6189 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6190 			x_attribute1			=> NULL,
6191 			x_attribute2			=> NULL,
6192 			x_attribute3			=> NULL,
6193 			x_attribute4			=> NULL,
6194 			x_attribute5			=> NULL,
6195 			x_attribute6			=> NULL,
6196 			x_attribute7			=> NULL,
6197 			x_attribute8			=> NULL,
6198 			x_attribute9			=> NULL,
6199 			x_attribute10			=> NULL,
6200 			X_MODE				=> 'R');
6201 		l_rowid	:=	NULL;
6202 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6203 			X_ROWID				=> l_rowid,
6204 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6205 			X_REASON_CODE			=> 'POSITION_CHANGE',
6206 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6207 			X_MODE				=> 'R');
6208 
6209 
6210 		DELETE psp_payroll_sub_lines
6211 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6212 		end;
6213 	end if;
6214 	l_old_position_id	:= l_new_position_id;
6215 	END LOOP;
6216 	close get_sublines_csr;
6217 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6218 	EXCEPTION
6219 	WHEN NO_DATA_FOUND then
6220 		x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6221 		close get_sublines_csr;
6222 	WHEN OTHERS then
6223 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_POSITION_CHANGE');
6224 		x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
6225 		close get_sublines_csr;
6226 	end;
6227 	end if;
6228  END LOOP;
6229  close get_assg_csr;
6230  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6231  hr_utility.trace('	Leaving CREATE_SLINE_POSITION_CHANGE');
6232  EXCEPTION
6233 	WHEN NO_DATA_FOUND then
6234 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6235 	close get_assg_csr;
6236 	WHEN OTHERS then
6237 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_POSITION_CHANGE');
6238 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
6239 	close get_assg_csr;
6240 
6241 end create_sline_position_change;
6242 
6243 
6244 
6245 
6246 PROCEDURE CREATE_SLINE_GRADE_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
6247 					X_ASSIGNMENT_ID	IN NUMBER,
6248 					X_BALANCE_AMOUNT IN NUMBER,
6249 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
6250 CURSOR get_old_grade_csr IS
6251 SELECT effective_start_date, grade_id
6252 FROM	per_assignments_f
6253 WHERE assignment_id = x_assignment_id and
6254 	effective_start_date < g_start_date and
6255 	effective_start_date = (select max(effective_start_date) from per_assignments_f
6256 		where assignment_id = x_assignment_id
6257 		AND	assignment_type ='E' --Added for bug 2624259.
6258 		AND	effective_start_date < g_start_date);
6259 
6260 l_effective_start_date		date;
6261 l_old_grade_id		number(9);
6262 
6263 CURSOR get_assg_csr IS
6264 SELECT effective_start_date, effective_end_date, grade_id
6265 FROM	per_assignments_f
6266 WHERE assignment_id = x_assignment_id
6267 	AND assignment_type ='E'	--Added for bug 2624259.
6268 	AND
6269 	(g_start_date between effective_start_date and effective_end_date or
6270 	g_end_date	between effective_start_date and effective_end_date or
6271 	(g_start_date <= effective_start_date and g_end_date >= effective_end_date ))
6272 order by effective_start_date;
6273 
6274 l_current_start_date	date;
6275 l_current_end_date	date;
6276 l_new_grade_id		number(9);
6277 
6278 CURSOR get_sublines_csr IS
6279 SELECT *
6280 FROM	psp_payroll_sub_lines
6281 WHERE payroll_line_id	= x_payroll_line_id and
6282 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
6283 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
6284 	(sub_line_start_date <= l_current_start_date and sub_line_end_date >= l_current_end_date))
6285 order by sub_line_start_date;
6286 
6287 g_sublines_rec get_sublines_csr%ROWTYPE;
6288 
6289 l_tmp_start_date	date;
6290 l_tmp_end_date		date;
6291 l_rowid			varchar2(20);
6292 l_sub_line_id		number(9);
6293 i		number(9)	:= 0;
6294 i2		number(9)	:= 0;
6295 l_amount	number(22,2)	:= 0;
6296 l_no_of_days	number(3)	:= 0;
6297 
6298 
6299 begin
6300  hr_utility.trace('	Entering CREATE_SLINE_GRADE_CHANGE');
6301  open get_old_grade_csr;
6302  fetch get_old_grade_csr into l_effective_start_date, l_old_grade_id;
6303  if get_old_grade_csr%NOTFOUND then
6304 	l_old_grade_id	:= 0;
6305  end if;
6306 
6307  open get_assg_csr;
6308  LOOP
6309 	fetch get_assg_csr into l_current_start_date, l_current_end_date, l_new_grade_id;
6310 	EXIT WHEN get_assg_csr%NOTFOUND;
6311 	if NVL(l_old_grade_id,0) = 0 or NVL(l_old_grade_id,0) = NVL(l_new_grade_id,0) then
6312 	l_old_grade_id	:= l_new_grade_id;
6313 	else
6314 	begin
6315 	open get_sublines_csr;
6316 	LOOP
6317 	fetch get_sublines_csr into g_sublines_rec;
6318 	EXIT WHEN get_sublines_csr%NOTFOUND;
6319 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
6320 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
6321 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
6322 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
6323 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
6324 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
6325 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
6326 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
6327 		begin
6328 		UPDATE psp_payroll_sub_lines
6329 			set grade_id = l_new_grade_id
6330 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6331 		end;
6332 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
6333 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
6334 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
6335 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
6336 		begin
6337 			l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
6338 			l_tmp_end_date	:= trunc(l_current_start_date) - 1;
6339 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6340 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6341 			l_no_of_days	:= 0;
6342 			l_amount	:= 0.00;
6343 			while i <= i2 loop
6344 			l_amount	:= l_amount + daily_calendar(i);
6345 			if work_calendar(i)	= 'Y' then
6346 				l_no_of_days	:= l_no_of_days + 1;
6347 			end if;
6348 			i	:= i + 1;
6349 			end loop;
6350 
6351 			if round(x_balance_amount,g_precision) <> 0.00 then
6352 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6353 			end if;
6354 
6355 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6356 			FROM DUAL;
6357  hr_utility.trace('	inserting into Sublines -2002');
6358 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6359 			X_ROWID				=> l_rowid,
6360 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6361 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6362 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
6363 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6364 			X_REASON_CODE			=> 'GRADE_CHANGE',
6365 			X_PAY_AMOUNT			=> l_amount,
6366 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6367 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6368 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6369 			X_FTE				=> NULL,
6370 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6371 			X_JOB_ID			=> g_sublines_rec.job_id,
6372 			X_POSITION_ID			=>g_sublines_rec.position_id,
6373 			X_GRADE_ID			=> l_old_grade_id,
6374 			X_PEOPLE_GRP_ID		=> NULL,
6375 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6376 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6377 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6378 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6379 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6380 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6381 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6382 			x_attribute1			=> NULL,
6383 			x_attribute2			=> NULL,
6384 			x_attribute3			=> NULL,
6385 			x_attribute4			=> NULL,
6386 			x_attribute5			=> NULL,
6387 			x_attribute6			=> NULL,
6388 			x_attribute7			=> NULL,
6389 			x_attribute8			=> NULL,
6390 			x_attribute9			=> NULL,
6391 			x_attribute10			=> NULL,
6392 			X_MODE				=> 'R');
6393 		l_rowid	:=	NULL;
6394 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6395 			X_ROWID				=> l_rowid,
6396 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6397 			X_REASON_CODE			=> 'GRADE_CHANGE',
6398 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6399 			X_MODE				=> 'R');
6400 
6401 			l_tmp_start_date	:= trunc(l_current_start_date);
6402 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
6403 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6404 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6405 			l_no_of_days	:= 0;
6406 			l_amount	:= 0.00;
6407 			while i <= i2 loop
6408 			l_amount	:= l_amount + daily_calendar(i);
6409 			if work_calendar(i)	= 'Y' then
6410 				l_no_of_days	:= l_no_of_days + 1;
6411 			end if;
6412 			i	:= i + 1;
6413 			end loop;
6414 
6415 			if round(x_balance_amount,g_precision) <> 0.00 then
6416 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6417 			end if;
6418 
6419 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6420 			FROM DUAL;
6421  hr_utility.trace('	inserting into Sublines -3002');
6422 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6423 			X_ROWID				=> l_rowid,
6424 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6425 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6426 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6427 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6428 			X_REASON_CODE			=> 'GRADE_CHANGE',
6429 			X_PAY_AMOUNT			=> l_amount,
6430 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6431 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6432 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6433 			X_FTE				=> NULL,
6434 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6435 			X_JOB_ID			=> g_sublines_rec.job_id,
6436 			X_POSITION_ID			=>g_sublines_rec.position_id,
6437 			X_GRADE_ID			=> l_new_grade_id,
6438 			X_PEOPLE_GRP_ID		=> NULL,
6439 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6440 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6441 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6442 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6443 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6444 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6445 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6446 			x_attribute1			=> NULL,
6447 			x_attribute2			=> NULL,
6448 			x_attribute3			=> NULL,
6449 			x_attribute4			=> NULL,
6450 			x_attribute5			=> NULL,
6451 			x_attribute6			=> NULL,
6452 			x_attribute7			=> NULL,
6453 			x_attribute8			=> NULL,
6454 			x_attribute9			=> NULL,
6455 			x_attribute10			=> NULL,
6456 			X_MODE				=> 'R');
6457 		l_rowid	:=	NULL;
6458 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6459 			X_ROWID				=> l_rowid,
6460 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6461 			X_REASON_CODE			=> 'GRADE_CHANGE',
6462 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6463 			X_MODE				=> 'R');
6464 
6465 
6466 		DELETE psp_payroll_sub_lines
6467 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6468 		end;
6469 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
6470 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
6471 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
6472 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
6473 		begin
6474 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
6475 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
6476 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6477 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6478 		l_no_of_days	:= 0;
6479 		l_amount	:= 0.00;
6480 		while i <= i2 loop
6481 		l_amount	:= l_amount + daily_calendar(i);
6482 		if work_calendar(i)	= 'Y' then
6483 			l_no_of_days	:= l_no_of_days + 1;
6484 		end if;
6485 		i	:= i + 1;
6486 		end loop;
6487 
6488 		if round(x_balance_amount, g_precision) <> 0.00 then
6489 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6490 		end if;
6491 
6492 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6493 			FROM DUAL;
6494  hr_utility.trace('	inserting into Sublines -4002');
6495 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6496 			X_ROWID				=> l_rowid,
6497 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6498 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6499 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6500 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6501 			X_REASON_CODE			=> 'GRADE_CHANGE',
6502 			X_PAY_AMOUNT			=> l_amount,
6503 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6504 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6505 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6506 			X_FTE				=> NULL,
6507 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6508 			X_JOB_ID			=> g_sublines_rec.job_id,
6509 			X_POSITION_ID			=>g_sublines_rec.position_id,
6510 			X_GRADE_ID			=> l_new_grade_id,
6511 			X_PEOPLE_GRP_ID		=> NULL,
6512 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6513 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6514 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6515 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6516 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6517 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6518 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6519 			x_attribute1			=> NULL,
6520 			x_attribute2			=> NULL,
6521 			x_attribute3			=> NULL,
6522 			x_attribute4			=> NULL,
6523 			x_attribute5			=> NULL,
6524 			x_attribute6			=> NULL,
6525 			x_attribute7			=> NULL,
6526 			x_attribute8			=> NULL,
6527 			x_attribute9			=> NULL,
6528 			x_attribute10			=> NULL,
6529 			X_MODE				=> 'R');
6530 		l_rowid	:=	NULL;
6531 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6532 			X_ROWID				=> l_rowid,
6533 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6534 			X_REASON_CODE			=> 'GRADE_CHANGE',
6535 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6536 			X_MODE				=> 'R');
6537 
6538 			l_tmp_start_date	:= trunc(l_current_end_date);
6539 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
6540 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6541 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6542 			l_no_of_days	:= 0;
6543 			l_amount	:= 0.00;
6544 			while i <= i2 loop
6545 			l_amount	:= l_amount + daily_calendar(i);
6546 			if work_calendar(i)	= 'Y' then
6547 				l_no_of_days	:= l_no_of_days + 1;
6548 			end if;
6549 			i	:= i + 1;
6550 			end loop;
6551 
6552 			if round(x_balance_amount, g_precision) <> 0.00 then
6553 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6554 			end if;
6555 
6556 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6557 			FROM DUAL;
6558  hr_utility.trace('	inserting into Sublines -5002');
6559 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6560 			X_ROWID				=> l_rowid,
6561 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6562 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6563 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6564 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6565 			X_REASON_CODE			=> 'GRADE_CHANGE',
6566 			X_PAY_AMOUNT			=> l_amount,
6567 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6568 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6569 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6570 			X_FTE				=> NULL,
6571 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6572 			X_JOB_ID			=> g_sublines_rec.job_id,
6573 			X_POSITION_ID			=>g_sublines_rec.position_id,
6574 			X_GRADE_ID			=> l_old_grade_id,
6575 			X_PEOPLE_GRP_ID		=> NULL,
6576 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6577 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6578 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6579 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6580 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6581 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6582 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6583 			x_attribute1			=> NULL,
6584 			x_attribute2			=> NULL,
6585 			x_attribute3			=> NULL,
6586 			x_attribute4			=> NULL,
6587 			x_attribute5			=> NULL,
6588 			x_attribute6			=> NULL,
6589 			x_attribute7			=> NULL,
6590 			x_attribute8			=> NULL,
6591 			x_attribute9			=> NULL,
6592 			x_attribute10			=> NULL,
6593 			X_MODE				=> 'R');
6594 		l_rowid	:=	NULL;
6595 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6596 			X_ROWID				=> l_rowid,
6597 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6598 			X_REASON_CODE			=> 'GRADE_CHANGE',
6599 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6600 			X_MODE				=> 'R' );
6601 
6602 
6603 		DELETE psp_payroll_sub_lines
6604 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6605 		end;
6606 	else
6607 		begin
6608 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
6609 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
6610 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6611 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6612 		l_no_of_days	:= 0;
6613 		l_amount	:= 0.00;
6614 		while i <= i2 loop
6615 		l_amount	:= l_amount + daily_calendar(i);
6616 		if work_calendar(i)	= 'Y' then
6617 			l_no_of_days	:= l_no_of_days + 1;
6618 		end if;
6619 		i	:= i + 1;
6620 		end loop;
6621 
6622 		if round(x_balance_amount, g_precision) <> 0.00 then
6623 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6624 		end if;
6625 
6626 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6627 			FROM DUAL;
6628  hr_utility.trace('	inserting into Sublines -6002');
6629 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6630 			X_ROWID				=> l_rowid,
6631 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6632 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6633 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6634 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6635 			X_REASON_CODE			=> 'GRADE_CHANGE',
6636 			X_PAY_AMOUNT			=> l_amount,
6637 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6638 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6639 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6640 			X_FTE				=> NULL,
6641 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6642 			X_JOB_ID			=> g_sublines_rec.job_id,
6643 			X_POSITION_ID			=>g_sublines_rec.position_id,
6644 			X_GRADE_ID			=> l_old_grade_id,
6645 			X_PEOPLE_GRP_ID		=> NULL,
6646 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6647 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6648 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6649 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6650 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6651 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6652 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6653 			x_attribute1			=> NULL,
6654 			x_attribute2			=> NULL,
6655 			x_attribute3			=> NULL,
6656 			x_attribute4			=> NULL,
6657 			x_attribute5			=> NULL,
6658 			x_attribute6			=> NULL,
6659 			x_attribute7			=> NULL,
6660 			x_attribute8			=> NULL,
6661 			x_attribute9			=> NULL,
6662 			x_attribute10			=> NULL,
6663 			X_MODE				=> 'R');
6664 		l_rowid	:=	NULL;
6665 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6666 			X_ROWID				=> l_rowid,
6667 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6668 			X_REASON_CODE			=> 'GRADE_CHANGE',
6669 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6670 			X_MODE				=> 'R');
6671 
6672 			l_tmp_start_date	:= trunc(l_current_start_date);
6673 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
6674 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6675 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6676 			l_no_of_days	:= 0;
6677 			l_amount	:= 0.00;
6678 			while i <= i2 loop
6679 			l_amount	:= l_amount + daily_calendar(i);
6680 			if work_calendar(i)	= 'Y' then
6681 				l_no_of_days	:= l_no_of_days + 1;
6682 			end if;
6683 			i	:= i + 1;
6684 			end loop;
6685 
6686 			if round(x_balance_amount, g_precision) <> 0.00 then
6687 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6688 			end if;
6689 
6690 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6691 			FROM DUAL;
6692  hr_utility.trace('	inserting into Sublines -7002');
6693 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6694 			X_ROWID				=> l_rowid,
6695 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6696 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6697 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6698 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6699 			X_REASON_CODE			=> 'GRADE_CHANGE',
6700 			X_PAY_AMOUNT			=> l_amount,
6701 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6702 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6703 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6704 			X_FTE				=> NULL,
6705 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6706 			X_JOB_ID			=> g_sublines_rec.job_id,
6707 			X_POSITION_ID			=> g_sublines_rec.position_id,
6708 			X_GRADE_ID			=> l_new_grade_id,
6709 			X_PEOPLE_GRP_ID		=> NULL,
6710 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6711 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6712 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6713 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6714 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6715 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6716 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6717 			x_attribute1			=> NULL,
6718 			x_attribute2			=> NULL,
6719 			x_attribute3			=> NULL,
6720 			x_attribute4			=> NULL,
6721 			x_attribute5			=> NULL,
6722 			x_attribute6			=> NULL,
6723 			x_attribute7			=> NULL,
6724 			x_attribute8			=> NULL,
6725 			x_attribute9			=> NULL,
6726 			x_attribute10			=> NULL,
6727 			X_MODE				=> 'R');
6728 		l_rowid	:=	NULL;
6729 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6730 			X_ROWID				=> l_rowid,
6731 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6732 			X_REASON_CODE			=> 'GRADE_CHANGE',
6733 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6734 			X_MODE				=> 'R');
6735 
6736 			l_tmp_start_date	:= trunc(l_current_end_date);
6737 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
6738 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6739 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6740 			l_no_of_days	:= 0;
6741 			l_amount	:= 0.00;
6742 			while i <= i2 loop
6743 			l_amount	:= l_amount + daily_calendar(i);
6744 			if work_calendar(i)	= 'Y' then
6745 				l_no_of_days	:= l_no_of_days + 1;
6746 			end if;
6747 			i	:= i + 1;
6748 			end loop;
6749 
6750 			if round(x_balance_amount, g_precision) <> 0.00 then
6751 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6752 			end if;
6753 
6754 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6755 			FROM DUAL;
6756  hr_utility.trace('	inserting into Sublines -8002');
6757 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6758 			X_ROWID				=> l_rowid,
6759 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6760 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6761 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
6762 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6763 			X_REASON_CODE			=> 'GRADE_CHANGE',
6764 			X_PAY_AMOUNT			=> l_amount,
6765 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6766 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6767 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6768 			X_FTE				=> NULL,
6769 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6770 			X_JOB_ID			=> g_sublines_rec.job_id,
6771 			X_POSITION_ID			=> g_sublines_rec.position_id,
6772 			X_GRADE_ID			=> l_old_grade_id,
6773 			X_PEOPLE_GRP_ID		=> NULL,
6774 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6775 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6776 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6777 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6778 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6779 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6780 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6781 			x_attribute1			=> NULL,
6782 			x_attribute2			=> NULL,
6783 			x_attribute3			=> NULL,
6784 			x_attribute4			=> NULL,
6785 			x_attribute5			=> NULL,
6786 			x_attribute6			=> NULL,
6787 			x_attribute7			=> NULL,
6788 			x_attribute8			=> NULL,
6789 			x_attribute9			=> NULL,
6790 			x_attribute10			=> NULL,
6791 			X_MODE				=> 'R');
6792 		l_rowid	:=	NULL;
6793 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6794 			X_ROWID				=> l_rowid,
6795 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6796 			X_REASON_CODE			=> 'GRADE_CHANGE',
6797 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6798 			X_MODE				=> 'R');
6799 
6800 
6801 		DELETE psp_payroll_sub_lines
6802 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6803 		end;
6804 	end if;
6805 	l_old_grade_id	:= l_new_grade_id;
6806 	END LOOP;
6807 	close get_sublines_csr;
6808 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6809 	hr_utility.trace('	Leaving CREATE_SLINE_GRADE_CHANGE');
6810 	EXCEPTION
6811 	WHEN NO_DATA_FOUND then
6812 		x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6813 		close get_sublines_csr;
6814 	WHEN OTHERS then
6815 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_GRADE_CHANGE');
6816 		x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
6817 		close get_sublines_csr;
6818 	end;
6819 	end if;
6820  END LOOP;
6821  close get_assg_csr;
6822  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6823  EXCEPTION
6824 	WHEN NO_DATA_FOUND then
6825 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
6826 	close get_assg_csr;
6827 	WHEN OTHERS then
6828 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_GRADE_CHANGE');
6829 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
6830 	close get_assg_csr;
6831 
6832 end create_sline_grade_change;
6833 
6834 
6835 
6836 
6837 /* new Procedure to split subline by people group added	*/
6838 
6839 --------------------------------CREATE_SLINE_PPGROUP_CHANGE--------------
6840 ---
6841 PROCEDURE CREATE_SLINE_PPGROUP_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
6842 					X_ASSIGNMENT_ID	IN NUMBER,
6843 					X_BALANCE_AMOUNT IN NUMBER,
6844 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
6845 CURSOR get_old_ppgroup_csr IS
6846 SELECT effective_start_date, people_group_id
6847 FROM	per_assignments_f
6848 WHERE assignment_id = x_assignment_id and
6849 	effective_start_date < g_start_date and
6850 	effective_start_date = (select max(effective_start_date) from per_assignments_f
6851 		where assignment_id = x_assignment_id
6852 		AND	assignment_type ='E'	--Added for bug 2624259.
6853 		AND	effective_start_date < g_start_date);
6854 
6855 l_effective_start_date		date;
6856 l_old_ppgroup_id		number(9);
6857 
6858 CURSOR get_assg_csr IS
6859 SELECT effective_start_date, effective_end_date, people_group_id
6860 FROM	per_assignments_f
6861 WHERE assignment_id = x_assignment_id
6862 	AND assignment_type ='E'	--Added for bug 2624259.
6863 	AND
6864 	(g_start_date between effective_start_date and effective_end_date or
6865 	g_end_date	between effective_start_date and effective_end_date or
6866 	(g_start_date <= effective_start_date and g_end_date >= effective_end_date ))
6867 order by effective_start_date;
6868 
6869 l_current_start_date	date;
6870 l_current_end_date	date;
6871 l_new_ppgroup_id		number(9);
6872 
6873 CURSOR get_sublines_csr IS
6874 SELECT *
6875 FROM	psp_payroll_sub_lines
6876 WHERE payroll_line_id	= x_payroll_line_id and
6877 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
6878 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
6879 	(sub_line_start_date <= l_current_start_date and sub_line_end_date >= l_current_end_date))
6880 order by sub_line_start_date;
6881 
6882 g_sublines_rec get_sublines_csr%ROWTYPE;
6883 
6884 l_tmp_start_date	date;
6885 l_tmp_end_date		date;
6886 l_rowid			varchar2(20);
6887 l_sub_line_id		number(9);
6888 i		number(9)	:= 0;
6889 i2		number(9)	:= 0;
6890 l_amount	number(22,2)	:= 0;
6891 l_no_of_days	number(3)	:= 0;
6892 
6893 
6894 begin
6895  hr_utility.trace('	Entering CREATE_SLINE_PPGROUP_CHANGE');
6896  open get_old_ppgroup_csr;
6897  fetch get_old_ppgroup_csr into l_effective_start_date, l_old_ppgroup_id;
6898  if get_old_ppgroup_csr%NOTFOUND then
6899 	l_old_ppgroup_id	:= 0;
6900  end if;
6901 
6902  open get_assg_csr;
6903  LOOP
6904 	fetch get_assg_csr into l_current_start_date, l_current_end_date, l_new_ppgroup_id;
6905 	EXIT WHEN get_assg_csr%NOTFOUND;
6906 	if NVL(l_old_ppgroup_id,0) = 0 or NVL(l_old_ppgroup_id,0) = NVL(l_new_ppgroup_id,0) then
6907 	l_old_ppgroup_id	:= l_new_ppgroup_id;
6908 	else
6909 	begin
6910 	open get_sublines_csr;
6911 	LOOP
6912 	fetch get_sublines_csr into g_sublines_rec;
6913 	EXIT WHEN get_sublines_csr%NOTFOUND;
6914 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
6915 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
6916 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
6917 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
6918 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
6919 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
6920 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
6921 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
6922 		begin
6923 		UPDATE psp_payroll_sub_lines
6924 			set people_group_id = l_new_ppgroup_id
6925 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
6926 		end;
6927 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
6928 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
6929 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
6930 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
6931 		begin
6932 			l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
6933 			l_tmp_end_date	:= trunc(l_current_start_date) - 1;
6934 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6935 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
6936 			l_no_of_days	:= 0;
6937 			l_amount	:= 0.00;
6938 			while i <= i2 loop
6939 			l_amount	:= l_amount + daily_calendar(i);
6940 			if work_calendar(i)	= 'Y' then
6941 				l_no_of_days	:= l_no_of_days + 1;
6942 			end if;
6943 			i	:= i + 1;
6944 			end loop;
6945 
6946 			if round(x_balance_amount, g_precision) <> 0.00 then
6947 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
6948 			end if;
6949 
6950 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
6951 			FROM DUAL;
6952  hr_utility.trace('	inserting into Sublines -9002');
6953 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
6954 			X_ROWID				=> l_rowid,
6955 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6956 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
6957 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
6958 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
6959 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
6960 			X_PAY_AMOUNT			=> l_amount,
6961 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
6962 			X_SALARY_USED			=> g_sublines_rec.salary_used,
6963 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
6964 			X_FTE				=> NULL,
6965 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
6966 			X_JOB_ID			=> g_sublines_rec.job_id,
6967 			X_POSITION_ID			=> g_sublines_rec.position_id,
6968 			X_GRADE_ID			=> g_sublines_rec.grade_id,
6969 			X_PEOPLE_GRP_ID		=> l_old_ppgroup_id,
6970 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
6971 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
6972 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
6973 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
6974 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
6975 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
6976 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
6977 			x_attribute1			=> NULL,
6978 			x_attribute2			=> NULL,
6979 			x_attribute3			=> NULL,
6980 			x_attribute4			=> NULL,
6981 			x_attribute5			=> NULL,
6982 			x_attribute6			=> NULL,
6983 			x_attribute7			=> NULL,
6984 			x_attribute8			=> NULL,
6985 			x_attribute9			=> NULL,
6986 			x_attribute10			=> NULL,
6987 			X_MODE				=> 'R');
6988 		l_rowid	:=	NULL;
6989 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
6990 			X_ROWID				=> l_rowid,
6991 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
6992 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
6993 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
6994 			X_MODE				=> 'R');
6995 
6996 			l_tmp_start_date	:= trunc(l_current_start_date);
6997 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
6998 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
6999 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7000 			l_no_of_days	:= 0;
7001 			l_amount	:= 0.00;
7002 			while i <= i2 loop
7003 			l_amount	:= l_amount + daily_calendar(i);
7004 			if work_calendar(i)	= 'Y' then
7005 				l_no_of_days	:= l_no_of_days + 1;
7006 			end if;
7007 			i	:= i + 1;
7008 			end loop;
7009 
7010 			if round(x_balance_amount, g_precision) <> 0.00 then
7011 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7012 			end if;
7013 
7014 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7015 			FROM DUAL;
7016  hr_utility.trace('	inserting into Sublines -2Y');
7017 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7018 			X_ROWID				=> l_rowid,
7019 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7020 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7021 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7022 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7023 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7024 			X_PAY_AMOUNT			=> l_amount,
7025 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7026 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7027 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7028 			X_FTE				=> NULL,
7029 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7030 			X_JOB_ID			=> g_sublines_rec.job_id,
7031 			X_POSITION_ID			=> g_sublines_rec.position_id,
7032 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7033 			X_PEOPLE_GRP_ID		=> l_new_ppgroup_id,
7034 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7035 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7036 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7037 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7038 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7039 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7040 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7041 			x_attribute1			=> NULL,
7042 			x_attribute2			=> NULL,
7043 			x_attribute3			=> NULL,
7044 			x_attribute4			=> NULL,
7045 			x_attribute5			=> NULL,
7046 			x_attribute6			=> NULL,
7047 			x_attribute7			=> NULL,
7048 			x_attribute8			=> NULL,
7049 			x_attribute9			=> NULL,
7050 			x_attribute10			=> NULL,
7051 			X_MODE				=> 'R');
7052 		l_rowid	:=	NULL;
7053 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7054 			X_ROWID				=> l_rowid,
7055 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7056 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7057 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7058 			X_MODE				=> 'R');
7059 
7060 
7061 		DELETE psp_payroll_sub_lines
7062 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
7063 		end;
7064 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
7065 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
7066 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
7067 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
7068 		begin
7069 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
7070 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
7071 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7072 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7073 		l_no_of_days	:= 0;
7074 		l_amount	:= 0.00;
7075 		while i <= i2 loop
7076 		l_amount	:= l_amount + daily_calendar(i);
7077 		if work_calendar(i)	= 'Y' then
7078 			l_no_of_days	:= l_no_of_days + 1;
7079 		end if;
7080 		i	:= i + 1;
7081 		end loop;
7082 
7083 		if round(x_balance_amount, g_precision) <> 0.00 then
7084 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7085 		end if;
7086 
7087 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7088 			FROM DUAL;
7089  hr_utility.trace('	inserting into Sublines -2OX');
7090 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7091 			X_ROWID				=> l_rowid,
7092 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7093 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7094 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7095 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7096 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7097 			X_PAY_AMOUNT			=> l_amount,
7098 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7099 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7100 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7101 			X_FTE				=> NULL,
7102 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7103 			X_JOB_ID			=> g_sublines_rec.job_id,
7104 			X_POSITION_ID			=> g_sublines_rec.position_id,
7105 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7106 			X_PEOPLE_GRP_ID		=> l_new_ppgroup_id,
7107 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7108 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7109 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7110 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7111 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7112 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7113 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7114 			x_attribute1			=> NULL,
7115 			x_attribute2			=> NULL,
7116 			x_attribute3			=> NULL,
7117 			x_attribute4			=> NULL,
7118 			x_attribute5			=> NULL,
7119 			x_attribute6			=> NULL,
7120 			x_attribute7			=> NULL,
7121 			x_attribute8			=> NULL,
7122 			x_attribute9			=> NULL,
7123 			x_attribute10			=> NULL,
7124 			X_MODE				=> 'R');
7125 		l_rowid	:=	NULL;
7126 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7127 			X_ROWID				=> l_rowid,
7128 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7129 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7130 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7131 			X_MODE				=> 'R');
7132 
7133 			l_tmp_start_date	:= trunc(l_current_end_date);
7134 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
7135 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7136 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7137 			l_no_of_days	:= 0;
7138 			l_amount	:= 0.00;
7139 			while i <= i2 loop
7140 			l_amount	:= l_amount + daily_calendar(i);
7141 			if work_calendar(i)	= 'Y' then
7142 				l_no_of_days	:= l_no_of_days + 1;
7143 			end if;
7144 			i	:= i + 1;
7145 			end loop;
7146 
7147 			if round(x_balance_amount, g_precision) <> 0.00 then
7148 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7149 			end if;
7150 
7151 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7152 			FROM DUAL;
7153  hr_utility.trace('	inserting into Sublines -2LXL');
7154 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7155 			X_ROWID				=> l_rowid,
7156 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7157 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7158 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7159 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7160 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7161 			X_PAY_AMOUNT			=> l_amount,
7162 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7163 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7164 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7165 			X_FTE				=> NULL,
7166 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7167 			X_JOB_ID			=> g_sublines_rec.job_id,
7168 			X_POSITION_ID			=> g_sublines_rec.position_id,
7169 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7170 			X_PEOPLE_GRP_ID		=> l_old_ppgroup_id,
7171 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7172 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7173 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7174 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7175 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7176 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7177 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7178 			x_attribute1			=> NULL,
7179 			x_attribute2			=> NULL,
7180 			x_attribute3			=> NULL,
7181 			x_attribute4			=> NULL,
7182 			x_attribute5			=> NULL,
7183 			x_attribute6			=> NULL,
7184 			x_attribute7			=> NULL,
7185 			x_attribute8			=> NULL,
7186 			x_attribute9			=> NULL,
7187 			x_attribute10			=> NULL,
7188 			X_MODE				=> 'R');
7189 		l_rowid	:=	NULL;
7190 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7191 			X_ROWID				=> l_rowid,
7192 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7193 			X_REASON_CODE			=> 'PPGROUP_CHANGE',
7194 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7195 			X_MODE				=> 'R' );
7196 
7197 
7198 		DELETE psp_payroll_sub_lines
7199 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
7200 		end;
7201 	else
7202 		begin
7203 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
7204 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
7205 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7206 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7207 		l_no_of_days	:= 0;
7208 		l_amount	:= 0.00;
7209 		while i <= i2 loop
7210 		l_amount	:= l_amount + daily_calendar(i);
7211 		if work_calendar(i)	= 'Y' then
7212 			l_no_of_days	:= l_no_of_days + 1;
7213 		end if;
7214 		i	:= i + 1;
7215 		end loop;
7216 
7217 		if round(x_balance_amount, g_precision) <> 0.00 then
7218 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7219 		end if;
7220 
7221 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7222 			FROM DUAL;
7223  hr_utility.trace('	inserting into Sublines -2UIORA');
7224 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7225 			X_ROWID				=> l_rowid,
7226 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7227 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7228 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7229 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7230 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7231 			X_PAY_AMOUNT			=> l_amount,
7232 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7233 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7234 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7235 			X_FTE				=> NULL,
7236 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7237 			X_JOB_ID			=> g_sublines_rec.job_id,
7238 			X_POSITION_ID			=> g_sublines_rec.position_id,
7239 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7240 			X_PEOPLE_GRP_ID		=> l_old_ppgroup_id,
7241 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7242 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7243 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7244 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7245 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7246 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7247 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7248 			x_attribute1			=> NULL,
7249 			x_attribute2			=> NULL,
7250 			x_attribute3			=> NULL,
7251 			x_attribute4			=> NULL,
7252 			x_attribute5			=> NULL,
7253 			x_attribute6			=> NULL,
7254 			x_attribute7			=> NULL,
7255 			x_attribute8			=> NULL,
7256 			x_attribute9			=> NULL,
7257 			x_attribute10			=> NULL,
7258 			X_MODE				=> 'R');
7259 		l_rowid	:=	NULL;
7260 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7261 			X_ROWID				=> l_rowid,
7262 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7263 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7264 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7265 			X_MODE				=> 'R');
7266 
7267 			l_tmp_start_date	:= trunc(l_current_start_date);
7268 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
7269 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7270 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7271 			l_no_of_days	:= 0;
7272 			l_amount	:= 0.00;
7273 			while i <= i2 loop
7274 			l_amount	:= l_amount + daily_calendar(i);
7275 			if work_calendar(i)	= 'Y' then
7276 				l_no_of_days	:= l_no_of_days + 1;
7277 			end if;
7278 			i	:= i + 1;
7279 			end loop;
7280 
7281 			if round(x_balance_amount, g_precision) <> 0.00 then
7282 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7283 			end if;
7284 
7285 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7286 			FROM DUAL;
7287  hr_utility.trace('	inserting into Sublines -2JADF');
7288 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7289 			X_ROWID				=> l_rowid,
7290 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7291 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7292 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7293 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7294 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7295 			X_PAY_AMOUNT			=> l_amount,
7296 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7297 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7298 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7299 			X_FTE				=> NULL,
7300 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7301 			X_JOB_ID			=> g_sublines_rec.job_id,
7302 			X_POSITION_ID			=> g_sublines_rec.position_id,
7303 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7304 			X_PEOPLE_GRP_ID		=> l_new_ppgroup_id,
7305 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7306 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7307 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7308 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7309 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7310 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7311 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7312 			x_attribute1			=> NULL,
7313 			x_attribute2			=> NULL,
7314 			x_attribute3			=> NULL,
7315 			x_attribute4			=> NULL,
7316 			x_attribute5			=> NULL,
7317 			x_attribute6			=> NULL,
7318 			x_attribute7			=> NULL,
7319 			x_attribute8			=> NULL,
7320 			x_attribute9			=> NULL,
7321 			x_attribute10			=> NULL,
7322 			X_MODE				=> 'R');
7323 		l_rowid	:=	NULL;
7324 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7325 			X_ROWID				=> l_rowid,
7326 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7327 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7328 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7329 			X_MODE				=> 'R');
7330 
7331 			l_tmp_start_date	:= trunc(l_current_end_date);
7332 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
7333 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7334 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7335 			l_no_of_days	:= 0;
7336 			l_amount	:= 0.00;
7337 			while i <= i2 loop
7338 			l_amount	:= l_amount + daily_calendar(i);
7339 			if work_calendar(i)	= 'Y' then
7340 				l_no_of_days	:= l_no_of_days + 1;
7341 			end if;
7342 			i	:= i + 1;
7343 			end loop;
7344 
7345 			if round(x_balance_amount, g_precision) <> 0.00 then
7346 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7347 			end if;
7348 
7349 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7350 			FROM DUAL;
7351  hr_utility.trace('	inserting into Sublines -299ek');
7352 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7353 			X_ROWID				=> l_rowid,
7354 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7355 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7356 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7357 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7358 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7359 			X_PAY_AMOUNT			=> l_amount,
7360 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7361 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7362 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7363 			X_FTE				=> NULL,
7364 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7365 			X_JOB_ID			=> g_sublines_rec.job_id,
7366 			X_POSITION_ID			=> g_sublines_rec.position_id,
7367 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7368 			X_PEOPLE_GRP_ID		=> l_old_ppgroup_id,
7369 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7370 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7371 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7372 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7373 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7374 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7375 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7376 			x_attribute1			=> NULL,
7377 			x_attribute2			=> NULL,
7378 			x_attribute3			=> NULL,
7379 			x_attribute4			=> NULL,
7380 			x_attribute5			=> NULL,
7381 			x_attribute6			=> NULL,
7382 			x_attribute7			=> NULL,
7383 			x_attribute8			=> NULL,
7384 			x_attribute9			=> NULL,
7385 			x_attribute10			=> NULL,
7386 			X_MODE				=> 'R');
7387 		l_rowid	:=	NULL;
7388 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7389 			X_ROWID				=> l_rowid,
7390 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7391 			X_REASON_CODE			=> 'PEOPLE_GROUP_CHANGE',
7392 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7393 			X_MODE				=> 'R');
7394 
7395 
7396 		DELETE psp_payroll_sub_lines
7397 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
7398 		end;
7399 	end if;
7400 	l_old_ppgroup_id	:= l_new_ppgroup_id;
7401 	END LOOP;
7402 	close get_sublines_csr;
7403 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
7404 	EXCEPTION
7405 	WHEN NO_DATA_FOUND then
7406 		x_return_status	:= FND_API.G_RET_STS_SUCCESS;
7407 		close get_sublines_csr;
7408 	WHEN OTHERS then
7409 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_POSITION_CHANGE');
7410 		x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
7411 		close get_sublines_csr;
7412 	end;
7413 	end if;
7414  END LOOP;
7415  close get_assg_csr;
7416  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
7417  hr_utility.trace('	Leaving CREATE_SLINE_PPGROUP_CHANGE');
7418  EXCEPTION
7419 	WHEN NO_DATA_FOUND then
7420 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
7421 	close get_assg_csr;
7422 	WHEN OTHERS then
7423 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_PPGROUP_CHANGE');
7424 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
7425 	close get_assg_csr;
7426 
7427 end create_sline_ppgroup_change;
7428 
7429 
7430 
7431 
7432 
7433 
7434 
7435 
7436 ---------------------------------CREATE_SLINE_FTE_CHANGE---------------------
7437 ---
7438 PROCEDURE CREATE_SLINE_FTE_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
7439 					X_ASSIGNMENT_ID	IN NUMBER,
7440 					X_BALANCE_AMOUNT IN NUMBER,
7441 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
7442 l_current_start_date	date;
7443 l_current_end_date	date;
7444 l_new_fte		number(22,2);
7445 
7446 CURSOR get_sublines_csr IS
7447 SELECT *
7448 FROM	psp_payroll_sub_lines
7449 WHERE payroll_line_id	= x_payroll_line_id and
7450 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
7451 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
7452 	(sub_line_start_date <= l_current_start_date and sub_line_end_date >= l_current_end_date))
7453 order by sub_line_start_date;
7454 
7455 g_sublines_rec get_sublines_csr%ROWTYPE;
7456 
7457 
7458 l_tmp_start_date	date;
7459 l_tmp_end_date		date;
7460 l_rowid			varchar2(20);
7461 l_sub_line_id		number(9);
7462 i			number(9)	:= 0;
7463 i2			number(9)	:= 0;
7464 l_amount		number(22,2)	:= 0;
7465 l_no_of_days		number(3)	:= 0;
7466 l_fte_option_value	varchar2(30);
7467 l_fte_value		varchar2(30);
7468 l_cur_handle		integer ;
7469 l_total_rows		integer		:= 0;
7470 l_old_fte		number(22,2)	:= 0;
7471 l_new_fte_temp	VARCHAR2(150);	-- new added for Bug 2023920
7472 l_old_fte_temp	VARCHAR2(150);	-- new added for Bug 2023920
7473 
7474 begin
7475 hr_utility.trace('	Entering CREATE_SLINE_FTE_CHANGE');
7476 -- l_fte_option_value	:= FND_PROFILE.VALue('PSP_FTE_OPTIONS');
7477  l_fte_option_value :=psp_general.get_specific_profile('PSP_FTE_OPTIONS');
7478  if NVL(l_fte_option_value,' ') = 'BUDGET_VALUES' or l_fte_option_value IS NULL then
7479 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
7480 	return;
7481  end if;
7482  ----dbms_output.PUT_LINE('Crossed First if of FTE Change... '|| l_fte_option_value );
7483 -- l_fte_value	:= FND_PROFILE.VALUE('PSP_FTE_ATTRIBUTE');
7484 	l_fte_value:=psp_general.get_specific_profile('PSP_FTE_ATTRIBUTE');
7485  if l_fte_value IS NULL then
7486 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
7487 	return;
7488  end if;
7489  ----dbms_output.PUT_LINE('Crossed Second if of FTE Change...' || l_fte_value);
7490  l_cur_handle := dbms_sql.open_cursor;
7491 
7492  --Added assignment_type ='E' check for bug 2624259.
7493  dbms_sql.parse(l_cur_handle,'SELECT ' || l_fte_value || ' FROM per_assignments_f WHERE assignment_id = ' ||
7494 		to_char(x_assignment_id) || ' and effective_start_date = (select max(effective_start_date)' ||
7495 		' from per_assignments_f where assignment_id = ' || to_char(x_assignment_id)		||
7496 		' AND assignment_type = '||''''||'E'||''''						||
7497 		' and effective_start_date < (select min(effective_start_date) from	per_assignments_f '	||
7498 		' where assignment_id = ' || to_char(x_assignment_id)					||
7499 		' AND assignment_type = '||''''||'E'||''''						||
7500 		' and (( :g_start_date '									||
7501 		' between effective_start_date and effective_end_date) or ( :g_end_date between '	||
7502 		' effective_start_date and effective_end_date) or ( :g_start_date <= effective_start_date' ||
7503 		' and :g_end_date >= effective_end_date )) ))',dbms_sql.V7);
7504 
7505  dbms_sql.bind_variable(l_cur_handle,'g_start_date', g_start_date);
7506  dbms_sql.bind_variable(l_cur_handle,'g_end_date', g_end_date);
7507 	dbms_sql.define_column(l_cur_handle,1,l_old_fte_temp,150);
7508 -- above added for bug fix 2023920
7509 --
7510  l_total_rows := dbms_sql.execute_and_fetch(l_cur_handle);
7511  ----dbms_output.PUT_LINE('Crossed First dbms_sql.execute of FTE Change...');
7512 
7513 /*
7514  if NVL(l_total_rows,0)	= 0 then
7515 	l_old_fte	:= 0;
7516  else
7517 	dbms_sql.column_value(l_cur_handle,1,l_old_fte);
7518  end if;
7519  Commenting out NOCOPY per bug fix 2023920
7520 
7521 */
7522 	dbms_sql.column_value(l_cur_handle,1,l_old_fte_temp); -- added new for bug fix 2022500
7523 	l_old_fte:= to_number(nvl(l_old_fte_temp,0));	-- 2023920
7524 
7525 	l_old_fte:=nvl(l_old_fte_temp,0); -- 2023920
7526 
7527  dbms_sql.close_cursor(l_cur_handle);
7528 
7529 
7530 
7531 --
7532 
7533  l_cur_handle := dbms_sql.open_cursor;
7534 
7535 	--Added assignment_type ='E' for bug 2624259.
7536  dbms_sql.parse(l_cur_handle,'SELECT effective_start_date, effective_end_date, ' || l_fte_value	||
7537 		' FROM	per_assignments_f WHERE assignment_id = ' || to_char(x_assignment_id)	||
7538 		' AND assignment_type = '||''''||'E'||''''						||
7539 		' and (:g_start_date between effective_start_date and effective_end_date or '	||
7540 			':g_end_date between effective_start_date and effective_end_date or (:g_start_date '	||
7541 		' <= effective_start_date and :g_end_date >= effective_end_date )) order by '		||
7542 		' effective_start_date ',dbms_sql.V7);
7543 
7544  dbms_sql.bind_variable(l_cur_handle,'g_start_date', g_start_date);
7545  dbms_sql.bind_variable(l_cur_handle,'g_end_date', g_end_date);
7546 --
7547 /* new added to define columns for above cursor 2023920*/
7548 
7549  dbms_sql.define_column(l_cur_handle, 1, l_current_Start_date);
7550  dbms_sql.define_column(l_cur_handle, 2, l_current_end_date);
7551  dbms_sql.define_column(l_cur_handle, 3, l_new_fte_temp,150);
7552 
7553  l_total_rows := dbms_sql.execute(l_cur_handle);
7554 /*
7555 
7556  Not Required -- Commented out NOCOPY per bug fix 2023920
7557 
7558 
7559  ----dbms_output.PUT_LINE('Crossed First dbms_sql.execute of FTE Change...');
7560 
7561  if NVL(l_total_rows,0)	= 0 then
7562 	l_old_fte	:= 0;
7563  else
7564 	dbms_sql.column_value(l_cur_handle,1,l_old_fte);
7565  end if;
7566 
7567  dbms_sql.close_cursor(l_cur_handle);
7568 */
7569 --
7570  while dbms_sql.fetch_rows(l_cur_handle) > 0
7571  LOOP
7572 	----dbms_output.PUT_LINE('Entered into fetch LOOP of FTE Change...');
7573 	dbms_sql.column_value(l_cur_handle,1,l_current_start_date);
7574 	dbms_sql.column_value(l_cur_handle,2,l_current_end_date);
7575 	dbms_sql.column_value(l_cur_handle,3,l_new_fte_temp); -- new added 2023920
7576 	l_new_fte:=to_number(nvl(l_new_fte_temp,0)); -- 2023920
7577 /*
7578 	if NVL(l_old_fte,0) = 0 o
7579  commented out NOCOPY as part of bug fix 2023920
7580 
7581 */
7582 
7583 
7584  if NVL(l_old_fte,0) = NVL(l_new_fte,0) then
7585 	l_old_fte	:= l_new_fte;
7586 	else
7587 	begin
7588 	open get_sublines_csr;
7589 	LOOP
7590 	fetch get_sublines_csr into g_sublines_rec;
7591 	EXIT WHEN get_sublines_csr%NOTFOUND;
7592 
7593 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
7594 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
7595 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
7596 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
7597 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
7598 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
7599 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
7600 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
7601 		begin
7602 		UPDATE psp_payroll_sub_lines
7603 		set fte = l_new_fte
7604 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
7605 		end;
7606 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
7607 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
7608 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
7609 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
7610 		begin
7611 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
7612 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
7613 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7614 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7615 		l_no_of_days	:= 0;
7616 		l_amount	:= 0.00;
7617 		while i <= i2 loop
7618 			l_amount	:= l_amount + daily_calendar(i);
7619 			if work_calendar(i)	= 'Y' then
7620 				l_no_of_days	:= l_no_of_days + 1;
7621 			end if;
7622 			i	:= i + 1;
7623 		end loop;
7624 
7625 		if round(x_balance_amount, g_precision) <> 0.00 then
7626 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7627 		end if;
7628 
7629 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7630 				FROM DUAL;
7631  hr_utility.trace('	inserting into Sublines -2kdfd');
7632 		PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7633 			X_ROWID				=> l_rowid,
7634 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7635 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7636 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
7637 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7638 			X_REASON_CODE			=> 'FTE_CHANGE',
7639 			X_PAY_AMOUNT			=> l_amount,
7640 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7641 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7642 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7643 			X_FTE				=> l_old_fte,
7644 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7645 			X_JOB_ID			=> g_sublines_rec.job_id,
7646 			X_POSITION_ID			=> g_sublines_rec.position_id,
7647 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7648 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
7649 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7650 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7651 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7652 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7653 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7654 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7655 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7656 			x_attribute1			=> NULL,
7657 			x_attribute2			=> NULL,
7658 			x_attribute3			=> NULL,
7659 			x_attribute4			=> NULL,
7660 			x_attribute5			=> NULL,
7661 			x_attribute6			=> NULL,
7662 			x_attribute7			=> NULL,
7663 			x_attribute8			=> NULL,
7664 			x_attribute9			=> NULL,
7665 			x_attribute10			=> NULL,
7666 			X_MODE				=> 'R');
7667 		l_rowid	:=	NULL;
7668 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7669 			X_ROWID				=> l_rowid,
7670 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7671 			X_REASON_CODE			=> 'FTE_CHANGE',
7672 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7673 			X_MODE				=> 'R');
7674 
7675 			l_tmp_start_date	:= trunc(l_current_start_date);
7676 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
7677 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7678 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7679 			l_no_of_days	:= 0;
7680 			l_amount	:= 0.00;
7681 			while i <= i2 loop
7682 			l_amount	:= l_amount + daily_calendar(i);
7683 			if work_calendar(i)	= 'Y' then
7684 				l_no_of_days	:= l_no_of_days + 1;
7685 			end if;
7686 			i	:= i + 1;
7687 			end loop;
7688 
7689 			if round(x_balance_amount, g_precision) <> 0.00 then
7690 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7691 			end if;
7692 
7693 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7694 			FROM DUAL;
7695  hr_utility.trace('	inserting into Sublines -2LKJL:JL');
7696 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7697 			X_ROWID				=> l_rowid,
7698 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7699 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7700 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7701 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7702 			X_REASON_CODE			=> 'FTE_CHANGE',
7703 			X_PAY_AMOUNT			=> l_amount,
7704 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7705 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7706 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7707 			X_FTE				=> l_new_fte,
7708 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7709 			X_JOB_ID			=> g_sublines_rec.job_id,
7710 			X_POSITION_ID			=> g_sublines_rec.position_id,
7711 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7712 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
7713 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7714 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7715 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7716 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7717 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7718 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7719 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7720 			x_attribute1			=> NULL,
7721 			x_attribute2			=> NULL,
7722 			x_attribute3			=> NULL,
7723 			x_attribute4			=> NULL,
7724 			x_attribute5			=> NULL,
7725 			x_attribute6			=> NULL,
7726 			x_attribute7			=> NULL,
7727 			x_attribute8			=> NULL,
7728 			x_attribute9			=> NULL,
7729 			x_attribute10			=> NULL,
7730 			X_MODE				=> 'R');
7731 			l_rowid	:=	NULL;
7732 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7733 			X_ROWID				=> l_rowid,
7734 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7735 			X_REASON_CODE			=> 'FTE_CHANGE',
7736 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7737 			X_MODE				=> 'R');
7738 			DELETE psp_payroll_sub_lines
7739 			WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
7740 		end;
7741 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
7742 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
7743 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
7744 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
7745 		begin
7746 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
7747 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
7748 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7749 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7750 		l_no_of_days	:= 0;
7751 		l_amount	:= 0.00;
7752 		while i <= i2 loop
7753 		l_amount	:= l_amount + daily_calendar(i);
7754 		if work_calendar(i)	= 'Y' then
7755 			l_no_of_days	:= l_no_of_days + 1;
7756 		end if;
7757 		i	:= i + 1;
7758 		end loop;
7759 
7760 		if round(x_balance_amount, g_precision) <> 0.00 then
7761 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7762 		end if;
7763 
7764 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7765 			FROM DUAL;
7766  hr_utility.trace('	inserting into Sublines -2UUUUUUAA');
7767 		PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7768 			X_ROWID				=> l_rowid,
7769 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7770 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7771 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7772 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7773 			X_REASON_CODE			=> 'FTE_CHANGE',
7774 			X_PAY_AMOUNT			=> l_amount,
7775 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7776 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7777 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7778 			X_FTE				=> l_new_fte,
7779 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7780 			X_JOB_ID			=> g_sublines_rec.job_id,
7781 			X_POSITION_ID			=> g_sublines_rec.position_id,
7782 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7783 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
7784 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7785 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7786 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7787 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7788 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7789 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7790 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7791 			x_attribute1			=> NULL,
7792 			x_attribute2			=> NULL,
7793 			x_attribute3			=> NULL,
7794 			x_attribute4			=> NULL,
7795 			x_attribute5			=> NULL,
7796 			x_attribute6			=> NULL,
7797 			x_attribute7			=> NULL,
7798 			x_attribute8			=> NULL,
7799 			x_attribute9			=> NULL,
7800 			x_attribute10			=> NULL,
7801 			X_MODE				=> 'R');
7802 		l_rowid	:=	NULL;
7803 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7804 			X_ROWID				=> l_rowid,
7805 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7806 			X_REASON_CODE			=> 'FTE_CHANGE',
7807 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7808 			X_MODE				=> 'R');
7809 
7810 			l_tmp_start_date	:= trunc(l_current_end_date);
7811 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
7812 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7813 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7814 			l_no_of_days	:= 0;
7815 			l_amount	:= 0.00;
7816 			while i <= i2 loop
7817 			l_amount	:= l_amount + daily_calendar(i);
7818 			if work_calendar(i)	= 'Y' then
7819 				l_no_of_days	:= l_no_of_days + 1;
7820 			end if;
7821 			i	:= i + 1;
7822 			end loop;
7823 
7824 			if round(x_balance_amount, g_precision) <> 0.00 then
7825 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7826 			end if;
7827 
7828 			SELECT PSP_PAYROLL_LINES_S.NEXTVAL into l_sub_line_id
7829 			FROM DUAL;
7830  hr_utility.trace('	inserting into Sublines -2KKKKK');
7831 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7832 			X_ROWID				=> l_rowid,
7833 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7834 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7835 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7836 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7837 			X_REASON_CODE			=> 'FTE_CHANGE',
7838 			X_PAY_AMOUNT			=> l_amount,
7839 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7840 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7841 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7842 			X_FTE				=> l_old_fte,
7843 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7844 			X_JOB_ID			=> g_sublines_rec.job_id,
7845 			X_POSITION_ID			=> g_sublines_rec.position_id,
7846 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7847 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
7848 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7849 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7850 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7851 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7852 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7853 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7854 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7855 			x_attribute1			=> NULL,
7856 			x_attribute2			=> NULL,
7857 			x_attribute3			=> NULL,
7858 			x_attribute4			=> NULL,
7859 			x_attribute5			=> NULL,
7860 			x_attribute6			=> NULL,
7861 			x_attribute7			=> NULL,
7862 			x_attribute8			=> NULL,
7863 			x_attribute9			=> NULL,
7864 			x_attribute10			=> NULL,
7865 			X_MODE				=> 'R');
7866 			l_rowid	:=	NULL;
7867 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7868 			X_ROWID				=> l_rowid,
7869 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7870 			X_REASON_CODE			=> 'FTE_CHANGE',
7871 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7872 			X_MODE				=> 'R');
7873 
7874 
7875 			DELETE psp_payroll_sub_lines
7876 			WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
7877 		end;
7878 		else
7879 		begin
7880 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
7881 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
7882 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7883 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7884 		l_no_of_days	:= 0;
7885 		l_amount	:= 0.00;
7886 		while i <= i2 loop
7887 		l_amount	:= l_amount + daily_calendar(i);
7888 		if work_calendar(i)	= 'Y' then
7889 			l_no_of_days	:= l_no_of_days + 1;
7890 		end if;
7891 		i	:= i + 1;
7892 		end loop;
7893 
7894 		if round(x_balance_amount, g_precision) <> 0.00 then
7895 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7896 		end if;
7897 
7898 		SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7899 			FROM DUAL;
7900  hr_utility.trace('	inserting into Sublines -2OOOPP888');
7901 		PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7902 			X_ROWID				=> l_rowid,
7903 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7904 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7905 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7906 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7907 			X_REASON_CODE			=> 'FTE_CHANGE',
7908 			X_PAY_AMOUNT			=> l_amount,
7909 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7910 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7911 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7912 			X_FTE				=> l_old_fte,
7913 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7914 			X_JOB_ID			=> g_sublines_rec.job_id,
7915 			X_POSITION_ID			=> g_sublines_rec.position_id,
7916 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7917 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
7918 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7919 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7920 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7921 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7922 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7923 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7924 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7925 			x_attribute1			=> NULL,
7926 			x_attribute2			=> NULL,
7927 			x_attribute3			=> NULL,
7928 			x_attribute4			=> NULL,
7929 			x_attribute5			=> NULL,
7930 			x_attribute6			=> NULL,
7931 			x_attribute7			=> NULL,
7932 			x_attribute8			=> NULL,
7933 			x_attribute9			=> NULL,
7934 			x_attribute10			=> NULL,
7935 			X_MODE				=> 'R');
7936 			l_rowid	:=	NULL;
7937 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
7938 			X_ROWID				=> l_rowid,
7939 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7940 			X_REASON_CODE			=> 'FTE_CHANGE',
7941 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
7942 			X_MODE				=> 'R');
7943 
7944 			l_tmp_start_date	:= trunc(l_current_start_date);
7945 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
7946 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
7947 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
7948 			l_no_of_days	:= 0;
7949 			l_amount	:= 0.00;
7950 			while i <= i2 loop
7951 			l_amount	:= l_amount + daily_calendar(i);
7952 			if work_calendar(i)	= 'Y' then
7953 				l_no_of_days	:= l_no_of_days + 1;
7954 			end if;
7955 			i	:= i + 1;
7956 			end loop;
7957 
7958 			if round(x_balance_amount, g_precision) <> 0.00 then
7959 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
7960 			end if;
7961 
7962 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
7963 			FROM DUAL;
7964  hr_utility.trace('	inserting into Sublines -27777MMMN');
7965 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
7966 			X_ROWID				=> l_rowid,
7967 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
7968 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
7969 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
7970 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
7971 			X_REASON_CODE			=> 'FTE_CHANGE',
7972 			X_PAY_AMOUNT			=> l_amount,
7973 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
7974 			X_SALARY_USED			=> g_sublines_rec.salary_used,
7975 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
7976 			X_FTE				=> l_new_fte,
7977 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
7978 			X_JOB_ID			=> g_sublines_rec.job_id,
7979 			X_POSITION_ID			=> g_sublines_rec.position_id,
7980 			X_GRADE_ID			=> g_sublines_rec.grade_id,
7981 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
7982 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
7983 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
7984 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
7985 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
7986 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
7987 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
7988 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
7989 			x_attribute1			=> NULL,
7990 			x_attribute2			=> NULL,
7991 			x_attribute3			=> NULL,
7992 			x_attribute4			=> NULL,
7993 			x_attribute5			=> NULL,
7994 			x_attribute6			=> NULL,
7995 			x_attribute7			=> NULL,
7996 			x_attribute8			=> NULL,
7997 			x_attribute9			=> NULL,
7998 			x_attribute10			=> NULL,
7999 			X_MODE				=> 'R');
8000 			l_rowid	:=	NULL;
8001 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8002 			X_ROWID				=> l_rowid,
8003 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8004 			X_REASON_CODE			=> 'FTE_CHANGE',
8005 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8006 			X_MODE				=> 'R');
8007 
8008 			l_tmp_start_date	:= trunc(l_current_end_date);
8009 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
8010 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8011 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8012 			l_no_of_days	:= 0;
8013 			l_amount	:= 0.00;
8014 			while i <= i2 loop
8015 			l_amount	:= l_amount + daily_calendar(i);
8016 			if work_calendar(i)	= 'Y' then
8017 				l_no_of_days	:= l_no_of_days + 1;
8018 			end if;
8019 			i	:= i + 1;
8020 			end loop;
8021 
8022 			if round(x_balance_amount, g_precision) <> 0.00 then
8023 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8024 			end if;
8025 
8026 			SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8027 			FROM DUAL;
8028  hr_utility.trace('	inserting into Sublines -2EEEERRSS');
8029 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8030 			X_ROWID				=> l_rowid,
8031 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8032 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8033 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8034 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8035 			X_REASON_CODE			=> 'FTE_CHANGE',
8036 			X_PAY_AMOUNT			=> l_amount,
8037 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8038 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8039 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8040 			X_FTE				=> l_old_fte,
8041 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8042 			X_JOB_ID			=> g_sublines_rec.job_id,
8043 			X_POSITION_ID			=> g_sublines_rec.position_id,
8044 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8045 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8046 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8047 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8048 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8049 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8050 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8051 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8052 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8053 			x_attribute1			=> NULL,
8054 			x_attribute2			=> NULL,
8055 			x_attribute3			=> NULL,
8056 			x_attribute4			=> NULL,
8057 			x_attribute5			=> NULL,
8058 			x_attribute6			=> NULL,
8059 			x_attribute7			=> NULL,
8060 			x_attribute8			=> NULL,
8061 			x_attribute9			=> NULL,
8062 			x_attribute10			=> NULL,
8063 			X_MODE				=> 'R');
8064 			l_rowid	:=	NULL;
8065 			PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8066 			X_ROWID				=> l_rowid,
8067 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8068 			X_REASON_CODE			=> 'FTE_CHANGE',
8069 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8070 			X_MODE				=> 'R');
8071 
8072 
8073 			DELETE psp_payroll_sub_lines
8074 			WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
8075 		end;
8076 	end if;
8077 	l_old_fte	:= l_new_fte;
8078 	END LOOP;
8079 	close get_sublines_csr;
8080 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
8081 	EXCEPTION
8082 	WHEN OTHERS then
8083 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_FTE_CHANGE');
8084 		x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
8085 		close get_sublines_csr;
8086 	end;
8087 	end if;
8088 
8089 	END LOOP;
8090 	dbms_sql.close_cursor(l_cur_handle);
8091 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
8092 	hr_utility.trace('	Leaving CREATE_SLINE_FTE_CHANGE');
8093 	EXCEPTION
8094 	WHEN OTHERS then
8095 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_FTE_CHANGE');
8096 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
8097 	dbms_sql.close_cursor(l_cur_handle);
8098 
8099 end create_sline_fte_change;
8100 
8101 --------------------------------CREATE_SLINE_BUDGET_CHANGE--------------
8102 ---
8103 PROCEDURE CREATE_SLINE_BUDGET_CHANGE(X_PAYROLL_LINE_ID IN NUMBER,
8104 					X_ASSIGNMENT_ID	IN NUMBER,
8105 					X_BALANCE_AMOUNT IN NUMBER,
8106 					X_RETURN_STATUS OUT NOCOPY VARCHAR2) IS
8107 CURSOR get_old_budget_csr IS
8108 SELECT effective_start_date, value
8109 -- FROM	per_assignment_budget_values Comented for bug 4055483
8110 FROM	per_assignment_budget_values_f
8111 WHERE assignment_id = x_assignment_id and unit = 'FTE' and
8112 	effective_start_date =
8113 		(select max(effective_start_date) -- from per_assignment_budget_values Commented for bug 4055483
8114 		from per_assignment_budget_values_f
8115 		where assignment_id = x_assignment_id and	unit = 'FTE' and
8116 		effective_start_date < (select min(effective_start_date)
8117 					--from	per_assignment_budget_values Commented for bug 4055483
8118 						from	per_assignment_budget_values_f
8119 						where assignment_id = x_assignment_id and
8120 						unit = 'FTE' and
8121 						((g_start_date between effective_start_date and effective_end_date) or
8122 						(g_end_date	between effective_start_date and effective_end_date) or
8123 					(g_start_date <= effective_start_date and g_end_date >= effective_end_date )) ));
8124 
8125 l_effective_start_date		date;
8126 --l_old_value		number(9); Commented for Bug 4055483
8127 l_old_value		per_assignment_budget_values_f.value%type;
8128 
8129 CURSOR get_assg_csr IS
8130 SELECT effective_start_date, effective_end_date, value
8131 -- FROM	per_assignment_budget_values Commented for Bug 4055483
8132 FROM	per_assignment_budget_values_f
8133 WHERE assignment_id = x_assignment_id and unit = 'FTE' and
8134 	(g_start_date between effective_start_date and effective_end_date or
8135 	g_end_date	between effective_start_date and effective_end_date or
8136 	(g_start_date <= effective_start_date and g_end_date >= effective_end_date ))
8137 order by effective_start_date;
8138 
8139 l_current_start_date	date;
8140 l_current_end_date	date;
8141 --l_new_value		number(9);Commented for Bug 4055483
8142 l_new_value		per_assignment_budget_values_f.value%type;
8143 
8144 CURSOR get_sublines_csr IS
8145 SELECT *
8146 FROM	psp_payroll_sub_lines
8147 WHERE payroll_line_id	= x_payroll_line_id and
8148 	((sub_line_start_date between l_current_start_date and l_current_end_date) or
8149 	(sub_line_end_date	between l_current_start_date and l_current_end_date) or
8150 	(sub_line_start_date >= l_current_start_date and sub_line_end_date >= l_current_end_date))
8151 order by sub_line_start_date;
8152 
8153 g_sublines_rec get_sublines_csr%ROWTYPE;
8154 
8155 l_tmp_start_date	date;
8156 l_tmp_end_date		date;
8157 l_rowid			varchar2(20);
8158 l_sub_line_id		number(9);
8159 i		number(9)	:= 0;
8160 i2		number(9)	:= 0;
8161 l_amount	number(22,2)	:= 0;
8162 l_no_of_days	number(3)	:= 0;
8163 l_fte_option_value varchar2(30);
8164 
8165 
8166 begin
8167  -- l_fte_option_value	:= FND_PROFILE.value('PSP_FTE_OPTIONS');
8168  --	l_fte_option_value:= psp_general.get_specific_profile('PSP_FTE_OPTIONS'); Commented for bug 4055483
8169  /*
8170  Commented for Bug 4055483
8171  if l_fte_option_value IS NULL or l_fte_option_value <> 'BUDGET_VALUES' then
8172 	x_return_status := FND_API.G_RET_STS_SUCCESS;
8173 	return;
8174  end if;
8175  */
8176 
8177  hr_utility.trace('	Entering CREATE_SLINE_BUDGET_CHANGE');
8178  open get_old_budget_csr;
8179  fetch get_old_budget_csr into l_effective_start_date, l_old_value;
8180  if get_old_budget_csr%NOTFOUND then
8181 	l_old_value	:= 0;
8182  end if;
8183 
8184  open get_assg_csr;
8185  LOOP
8186 	fetch get_assg_csr into l_current_start_date, l_current_end_date, l_new_value;
8187 	EXIT WHEN get_assg_csr%NOTFOUND;
8188 	if NVL(l_old_value,0) = 0 or NVL(l_old_value,0) = NVL(l_new_value,0) then
8189 	l_old_value	:= l_new_value;
8190 	else
8191 	begin
8192 	open get_sublines_csr;
8193 	LOOP
8194 	fetch get_sublines_csr into g_sublines_rec;
8195 	EXIT WHEN get_sublines_csr%NOTFOUND;
8196 	if ((l_current_start_date = g_sublines_rec.sub_line_start_date and
8197 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
8198 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
8199 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
8200 		(l_current_start_date = g_sublines_rec.sub_line_start_date and
8201 		l_current_end_date	> g_sublines_rec.sub_line_end_date) or
8202 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
8203 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
8204 		begin
8205 		UPDATE psp_payroll_sub_lines
8206 			set fte = l_new_value
8207 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
8208 		end;
8209 	elsif ((l_current_start_date > g_sublines_rec.sub_line_start_date and
8210 		l_current_end_date	= g_sublines_rec.sub_line_end_date) or
8211 		(l_current_start_date > g_sublines_rec.sub_line_start_date and
8212 		l_current_end_date	> g_sublines_rec.sub_line_end_date)) then
8213 		begin
8214 			l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
8215 			l_tmp_end_date	:= trunc(l_current_start_date) - 1;
8216 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8217 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8218 			l_no_of_days	:= 0;
8219 			l_amount	:= 0.00;
8220 			while i <= i2 loop
8221 			l_amount	:= l_amount + daily_calendar(i);
8222 			if work_calendar(i)	= 'Y' then
8223 				l_no_of_days	:= l_no_of_days + 1;
8224 			end if;
8225 			i	:= i + 1;
8226 			end loop;
8227 
8228 			if round(x_balance_amount, g_precision) <> 0.00 then
8229 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8230 			end if;
8231 
8232 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8233 			FROM DUAL;
8234  hr_utility.trace('	inserting into Sublines -2WWWEEERR');
8235 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8236 			X_ROWID				=> l_rowid,
8237 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8238 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8239 			X_SUB_LINE_START_DATE		=> g_sublines_rec.sub_line_start_date,
8240 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8241 			X_REASON_CODE			=> 'FTE_CHANGE',
8242 			X_PAY_AMOUNT			=> l_amount,
8243 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8244 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8245 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8246 			X_FTE				=> l_old_value,
8247 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8248 			X_JOB_ID			=> g_sublines_rec.job_id,
8249 			X_POSITION_ID			=> g_sublines_rec.position_id,
8250 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8251 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8252 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8253 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8254 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8255 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8256 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8257 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8258 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8259 			x_attribute1			=> NULL,
8260 			x_attribute2			=> NULL,
8261 			x_attribute3			=> NULL,
8262 			x_attribute4			=> NULL,
8263 			x_attribute5			=> NULL,
8264 			x_attribute6			=> NULL,
8265 			x_attribute7			=> NULL,
8266 			x_attribute8			=> NULL,
8267 			x_attribute9			=> NULL,
8268 			x_attribute10			=> NULL,
8269 			X_MODE				=> 'R');
8270 		l_rowid	:=	NULL;
8271 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8272 			X_ROWID				=> l_rowid,
8273 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8274 			X_REASON_CODE			=> 'FTE_CHANGE',
8275 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8276 			X_MODE				=> 'R');
8277 
8278 			l_tmp_start_date	:= trunc(l_current_start_date);
8279 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
8280 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8281 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8282 			l_no_of_days	:= 0;
8283 			l_amount	:= 0.00;
8284 			while i <= i2 loop
8285 			l_amount	:= l_amount + daily_calendar(i);
8286 			if work_calendar(i)	= 'Y' then
8287 				l_no_of_days	:= l_no_of_days + 1;
8288 			end if;
8289 			i	:= i + 1;
8290 			end loop;
8291 
8292 			if round(x_balance_amount, g_precision) <> 0.00 then
8293 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8294 			end if;
8295 
8296 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8297 			FROM DUAL;
8298  hr_utility.trace('	inserting into Sublines -29999*****888');
8299 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8300 			X_ROWID				=> l_rowid,
8301 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8302 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8303 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8304 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8305 			X_REASON_CODE			=> 'FTE_CHANGE',
8306 			X_PAY_AMOUNT			=> l_amount,
8307 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8308 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8309 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8310 			X_FTE				=> l_new_value,
8311 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8312 			X_JOB_ID			=> g_sublines_rec.job_id,
8313 			X_POSITION_ID			=> g_sublines_rec.position_id,
8314 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8315 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8316 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8317 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8318 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8319 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8320 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8321 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8322 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8323 			x_attribute1			=> NULL,
8324 			x_attribute2			=> NULL,
8325 			x_attribute3			=> NULL,
8326 			x_attribute4			=> NULL,
8327 			x_attribute5			=> NULL,
8328 			x_attribute6			=> NULL,
8329 			x_attribute7			=> NULL,
8330 			x_attribute8			=> NULL,
8331 			x_attribute9			=> NULL,
8332 			x_attribute10			=> NULL,
8333 			X_MODE				=> 'R');
8334 		l_rowid	:=	NULL;
8335 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8336 			X_ROWID				=> l_rowid,
8337 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8338 			X_REASON_CODE			=> 'FTE_CHANGE',
8339 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8340 			X_MODE				=> 'R');
8341 
8342 
8343 		DELETE psp_payroll_sub_lines
8344 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
8345 		end;
8346 	elsif ((l_current_start_date = g_sublines_rec.sub_line_start_date and
8347 		l_current_end_date	< g_sublines_rec.sub_line_end_date) or
8348 		(l_current_start_date < g_sublines_rec.sub_line_start_date and
8349 		l_current_end_date	< g_sublines_rec.sub_line_end_date)) then
8350 		begin
8351 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
8352 		l_tmp_end_date	:= trunc(l_current_end_date) - 1;
8353 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8354 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8355 		l_no_of_days	:= 0;
8356 		l_amount	:= 0.00;
8357 		while i <= i2 loop
8358 		l_amount	:= l_amount + daily_calendar(i);
8359 		if work_calendar(i)	= 'Y' then
8360 			l_no_of_days	:= l_no_of_days + 1;
8361 		end if;
8362 		i	:= i + 1;
8363 		end loop;
8364 
8365 		if round(x_balance_amount, g_precision) <> 0.00 then
8366 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8367 		end if;
8368 
8369 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8370 			FROM DUAL;
8371  hr_utility.trace('	inserting into Sublines -2DDDDDD');
8372 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8373 			X_ROWID				=> l_rowid,
8374 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8375 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8376 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8377 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8378 			X_REASON_CODE			=> 'FTE_CHANGE',
8379 			X_PAY_AMOUNT			=> l_amount,
8380 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8381 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8382 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8383 			X_FTE				=> l_new_value,
8384 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8385 			X_JOB_ID			=> g_sublines_rec.job_id,
8386 			X_POSITION_ID			=> g_sublines_rec.position_id,
8387 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8388 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8389 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8390 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8391 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8392 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8393 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8394 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8395 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8396 			x_attribute1			=> NULL,
8397 			x_attribute2			=> NULL,
8398 			x_attribute3			=> NULL,
8399 			x_attribute4			=> NULL,
8400 			x_attribute5			=> NULL,
8401 			x_attribute6			=> NULL,
8402 			x_attribute7			=> NULL,
8403 			x_attribute8			=> NULL,
8404 			x_attribute9			=> NULL,
8405 			x_attribute10			=> NULL,
8406 			X_MODE				=> 'R');
8407 		l_rowid	:=	NULL;
8408 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8409 			X_ROWID				=> l_rowid,
8410 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8411 			X_REASON_CODE			=> 'FTE_CHANGE',
8412 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8413 			X_MODE				=> 'R');
8414 
8415 			l_tmp_start_date	:= trunc(l_current_end_date);
8416 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
8417 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8418 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8419 			l_no_of_days	:= 0;
8420 			l_amount	:= 0.00;
8421 			while i <= i2 loop
8422 			l_amount	:= l_amount + daily_calendar(i);
8423 			if work_calendar(i)	= 'Y' then
8424 				l_no_of_days	:= l_no_of_days + 1;
8425 			end if;
8426 			i	:= i + 1;
8427 			end loop;
8428 
8429 			if round(x_balance_amount, g_precision) <> 0.00 then
8430 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8431 			end if;
8432 
8433 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8434 			FROM DUAL;
8435  hr_utility.trace('	inserting into Sublines -2UKOSO');
8436 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8437 			X_ROWID				=> l_rowid,
8438 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8439 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8440 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8441 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8442 			X_REASON_CODE			=> 'FTE_CHANGE',
8443 			X_PAY_AMOUNT			=> l_amount,
8444 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8445 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8446 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8447 			X_FTE				=> l_old_value,
8448 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8449 			X_JOB_ID			=> g_sublines_rec.job_id,
8450 			X_POSITION_ID			=> g_sublines_rec.position_id,
8451 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8452 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8453 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8454 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8455 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8456 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8457 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8458 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8459 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8460 			x_attribute1			=> NULL,
8461 			x_attribute2			=> NULL,
8462 			x_attribute3			=> NULL,
8463 			x_attribute4			=> NULL,
8464 			x_attribute5			=> NULL,
8465 			x_attribute6			=> NULL,
8466 			x_attribute7			=> NULL,
8467 			x_attribute8			=> NULL,
8468 			x_attribute9			=> NULL,
8469 			x_attribute10			=> NULL,
8470 			X_MODE				=> 'R');
8471 		l_rowid	:=	NULL;
8472 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8473 			X_ROWID				=> l_rowid,
8474 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8475 			X_REASON_CODE			=> 'FTE_CHANGE',
8476 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8477 			X_MODE				=> 'R' );
8478 
8479 
8480 		DELETE psp_payroll_sub_lines
8481 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
8482 		end;
8483 	else
8484 		begin
8485 		l_tmp_start_date	:= trunc(g_sublines_rec.sub_line_start_date);
8486 		l_tmp_end_date	:= trunc(l_current_start_date) - 1;
8487 		i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8488 		i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8489 		l_no_of_days	:= 0;
8490 		l_amount	:= 0.00;
8491 		while i <= i2 loop
8492 		l_amount	:= l_amount + daily_calendar(i);
8493 		if work_calendar(i)	= 'Y' then
8494 			l_no_of_days	:= l_no_of_days + 1;
8495 		end if;
8496 		i	:= i + 1;
8497 		end loop;
8498 
8499 		if round(x_balance_amount,g_precision) <> 0.00 then
8500 		l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8501 		end if;
8502 
8503 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8504 			FROM DUAL;
8505  hr_utility.trace('	inserting into Sublines -2JYUPA');
8506 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8507 			X_ROWID				=> l_rowid,
8508 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8509 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8510 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8511 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8512 			X_REASON_CODE			=> 'FTE_CHANGE',
8513 			X_PAY_AMOUNT			=> l_amount,
8514 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8515 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8516 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8517 			X_FTE				=> l_old_value,
8518 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8519 			X_JOB_ID			=> g_sublines_rec.job_id,
8520 			X_POSITION_ID			=> g_sublines_rec.position_id,
8521 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8522 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8523 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8524 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8525 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8526 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8527 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8528 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8529 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8530 			x_attribute1			=> NULL,
8531 			x_attribute2			=> NULL,
8532 			x_attribute3			=> NULL,
8533 			x_attribute4			=> NULL,
8534 			x_attribute5			=> NULL,
8535 			x_attribute6			=> NULL,
8536 			x_attribute7			=> NULL,
8537 			x_attribute8			=> NULL,
8538 			x_attribute9			=> NULL,
8539 			x_attribute10			=> NULL,
8540 			X_MODE				=> 'R');
8541 		l_rowid	:=	NULL;
8542 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8543 			X_ROWID				=> l_rowid,
8544 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8545 			X_REASON_CODE			=> 'FTE_CHANGE',
8546 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8547 			X_MODE				=> 'R');
8548 
8549 			l_tmp_start_date	:= trunc(l_current_start_date);
8550 			l_tmp_end_date	:= trunc(l_current_end_date) - 1;
8551 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8552 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8553 			l_no_of_days	:= 0;
8554 			l_amount	:= 0.00;
8555 			while i <= i2 loop
8556 			l_amount	:= l_amount + daily_calendar(i);
8557 			if work_calendar(i)	= 'Y' then
8558 				l_no_of_days	:= l_no_of_days + 1;
8559 			end if;
8560 			i	:= i + 1;
8561 			end loop;
8562 
8563 			if round(x_balance_amount, g_precision) <> 0.00 then
8564 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8565 			end if;
8566 
8567 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8568 			FROM DUAL;
8569  hr_utility.trace('	inserting into Sublines -2NBMM');
8570 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8571 			X_ROWID				=> l_rowid,
8572 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8573 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8574 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8575 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8576 			X_REASON_CODE			=> 'FTE_CHANGE',
8577 			X_PAY_AMOUNT			=> l_amount,
8578 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8579 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8580 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8581 			X_FTE				=> l_new_value,
8582 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8583 			X_JOB_ID			=> g_sublines_rec.job_id,
8584 			X_POSITION_ID			=> g_sublines_rec.position_id,
8585 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8586 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8587 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8588 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8589 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8590 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8591 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8592 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8593 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8594 			x_attribute1			=> NULL,
8595 			x_attribute2			=> NULL,
8596 			x_attribute3			=> NULL,
8597 			x_attribute4			=> NULL,
8598 			x_attribute5			=> NULL,
8599 			x_attribute6			=> NULL,
8600 			x_attribute7			=> NULL,
8601 			x_attribute8			=> NULL,
8602 			x_attribute9			=> NULL,
8603 			x_attribute10			=> NULL,
8604 			X_MODE				=> 'R');
8605 		l_rowid	:=	NULL;
8606 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8607 			X_ROWID				=> l_rowid,
8608 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8609 			X_REASON_CODE			=> 'FTE_CHANGE',
8610 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8611 			X_MODE				=> 'R');
8612 
8613 			l_tmp_start_date	:= trunc(l_current_end_date);
8614 			l_tmp_end_date	:= trunc(g_sublines_rec.sub_line_end_date);
8615 			i	:= (trunc(l_tmp_start_date) - trunc(g_start_date)) + 1;
8616 			i2	:= (trunc(l_tmp_end_date)	- trunc(g_start_date)) + 1;
8617 			l_no_of_days	:= 0;
8618 			l_amount	:= 0.00;
8619 			while i <= i2 loop
8620 			l_amount	:= l_amount + daily_calendar(i);
8621 			if work_calendar(i)	= 'Y' then
8622 				l_no_of_days	:= l_no_of_days + 1;
8623 			end if;
8624 			i	:= i + 1;
8625 			end loop;
8626 
8627 			if round(x_balance_amount,g_precision) <> 0.00 then
8628 			l_amount	:= l_amount + round((x_balance_amount * (l_no_of_days / g_no_of_person_work_days)), g_precision);
8629 			end if;
8630 
8631 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id
8632 			FROM DUAL;
8633  hr_utility.trace('	inserting into Sublines -2TOPP');
8634 			PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8635 			X_ROWID				=> l_rowid,
8636 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8637 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8638 			X_SUB_LINE_START_DATE		=> l_tmp_start_date,
8639 			X_SUB_LINE_END_DATE		=> l_tmp_end_date,
8640 			X_REASON_CODE			=> 'FTE_CHANGE',
8641 			X_PAY_AMOUNT			=> l_amount,
8642 			X_DAILY_RATE			=> g_sublines_rec.daily_rate,
8643 			X_SALARY_USED			=> g_sublines_rec.salary_used,
8644 			X_CURRENT_SALARY		=> g_sublines_rec.current_salary,
8645 			X_FTE				=> l_old_value,
8646 			X_ORGANIZATION_ID		=> g_sublines_rec.organization_id,
8647 			X_JOB_ID			=> g_sublines_rec.job_id,
8648 			X_POSITION_ID			=> g_sublines_rec.position_id,
8649 			X_GRADE_ID			=> g_sublines_rec.grade_id,
8650 			X_PEOPLE_GRP_ID		=> g_sublines_rec.people_group_id,
8651 			X_EMPLOYMENT_BEGIN_DATE		=> g_sublines_rec.employment_begin_date,
8652 			X_EMPLOYMENT_END_DATE		=> g_sublines_rec.employment_end_date,
8653 			X_EMPLOYEE_STATUS_INACTIVE_DAT	=> g_sublines_rec.employee_status_inactive_date,
8654 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> g_sublines_rec.employee_status_active_date,
8655 			X_ASSIGNMENT_BEGIN_DATE		=> g_sublines_rec.assignment_begin_date,
8656 			X_ASSIGNMENT_END_DATE		=> g_sublines_rec.assignment_end_date,
8657 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8658 			x_attribute1			=> NULL,
8659 			x_attribute2			=> NULL,
8660 			x_attribute3			=> NULL,
8661 			x_attribute4			=> NULL,
8662 			x_attribute5			=> NULL,
8663 			x_attribute6			=> NULL,
8664 			x_attribute7			=> NULL,
8665 			x_attribute8			=> NULL,
8666 			x_attribute9			=> NULL,
8667 			x_attribute10			=> NULL,
8668 			X_MODE				=> 'R');
8669 		l_rowid	:=	NULL;
8670 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8671 			X_ROWID				=> l_rowid,
8672 			X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
8673 			X_REASON_CODE			=> 'FTE_CHANGE',
8674 			X_PARENT_LINE_ID		=> g_sublines_rec.payroll_sub_line_id,
8675 			X_MODE				=> 'R');
8676 
8677 
8678 		DELETE psp_payroll_sub_lines
8679 		WHERE payroll_sub_line_id = g_sublines_rec.payroll_sub_line_id;
8680 		end;
8681 	end if;
8682 	l_old_value		:= l_new_value;
8683 	END LOOP;
8684 	close get_sublines_csr;
8685 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
8686 	EXCEPTION
8687 	WHEN NO_DATA_FOUND then
8688 		x_return_status	:= FND_API.G_RET_STS_SUCCESS;
8689 		close get_sublines_csr;
8690 	WHEN OTHERS then
8691 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_BUDGET_CHANGE');
8692 		x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
8693 		close get_sublines_csr;
8694 	end;
8695 	end if;
8696  END LOOP;
8697  close get_assg_csr;
8698  x_return_status	:= FND_API.G_RET_STS_SUCCESS;
8699  hr_utility.trace('	Leaving CREATE_SLINE_BUDGET_CHANGE');
8700  EXCEPTION
8701 	WHEN NO_DATA_FOUND then
8702 	x_return_status	:= FND_API.G_RET_STS_SUCCESS;
8703 	close get_assg_csr;
8704 	WHEN OTHERS then
8705 	fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_SLINE_BUDGET_CHANGE');
8706 	x_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
8707 	close get_assg_csr;
8708 
8709 end create_sline_budget_change;
8710 
8711 
8712 /**********************************************************************************
8713 HISTORY
8714 WHO		WHEN		WHAT
8715 Lveerubh	15-SEP-2001	Added checks to identify Non active assignments
8716 				as part of Bug 1994421-Zero Work Days Build
8717 *************************************************************************************/
8718 PROCEDURE CHECK_ZERO_WORK_DAYS(x_assignment_id IN NUMBER,
8719 				x_costed_value IN NUMBER,
8720 				x_start_date	IN DATE,		-- Bug 5642002: Added parameter
8721 				x_end_date	IN DATE,		-- Bug 5642002: Added parameter
8722 				x_return_status OUT NOCOPY varchar2) IS
8723 l_assignment_number varchar2(30);
8724 
8725 --Bug 1994421 : Zero Work Days Build : New select to identify non active assignment :lveerubh
8726 l_count_asg_active		NUMBER(4);
8727 l_effective_start_date	DATE;
8728 
8729 CURSOR non_active_asg_csr IS
8730 SELECT	count(*)
8731 FROM	per_assignments_f paf,
8732 	per_assignment_status_types	past
8733 WHERE	assignment_id			=		x_assignment_id
8734 AND	g_start_date			<=		effective_end_date
8735 AND	g_end_date			>=		effective_start_date
8736 AND	past.assignment_status_type_id =		paf.assignment_status_type_id
8737 AND	past.per_system_status	NOT IN	('ACTIVE_ASSIGN');
8738 
8739 CURSOR hire_zero_days_csr IS
8740 SELECT	min(paf.effective_start_date)
8741 FROM	per_assignments_f	paf
8742 WHERE	paf.assignment_id	=	x_assignment_id
8743 AND	assignment_type	=	'E'	--Added for bug 2624259.
8744 AND	g_start_date		<=	paf.effective_end_date
8745 AND	g_end_date		>=	paf.effective_start_date
8746 AND	payroll_id = l_payroll_id; ---3922347
8747 
8748 BEGIN
8749 
8750 	hr_utility.trace('	Entering CHECK_ZERO_WORK_DAYS');
8751 	hr_utility.trace('	 zero work days check asg, g_no_of_person_workdays= '||x_assignment_id||','||g_no_of_person_work_days);
8752 	IF g_no_of_person_work_days <= 0 then
8753 
8754 /* The following code is added for the enhancement Zero Work days .This code addition will identify the
8755 	non active assignments and assignments which have started on the last day of payroll , which is a non working day
8756  : Done as part of Bug 1994421 - Zero Work Days Build -lveerubh */
8757 
8758 	OPEN	non_active_asg_csr;
8759 	FETCH	non_active_asg_csr	INTO	l_count_asg_active;
8760 	CLOSE	non_active_asg_csr;
8761 
8762 	IF	l_count_asg_active > 0 THEN
8763 		hr_utility.trace('	 assignment_id l_count_asg_active > 0 asg = '||x_assignment_id);
8764 		g_non_active_flag :=	'Y';
8765 		x_return_status:=FND_API.G_RET_STS_SUCCESS;
8766 		return;
8767 	END IF;
8768 
8769 	OPEN	hire_zero_days_csr;
8770 	FETCH	hire_zero_days_csr	INTO	l_effective_start_date;
8771 	CLOSE	hire_zero_days_csr;
8772 
8773 	/*Bug 5557724: to_char(some_date,'D') returns a number indicating the weekday. However, for a given date, this number
8774 	returned varies with NLS_TERRITORY. So replaced it with to_char(some_date,'DY') that gives the abbreviated day. */
8775 --	IF	to_char(l_effective_start_date,'DY', 'nls_date_language=english') IN ('SUN','SAT') THEN
8776 	IF (psp_general.business_days(l_effective_start_date, l_effective_start_date, x_assignment_id) = 0) THEN
8777 		hr_utility.trace('	 assignment starts in non working day = '||x_assignment_id);
8778 		g_hire_zero_work_days	:=	'Y';
8779 		x_return_status:=FND_API.G_RET_STS_SUCCESS;
8780 		return;
8781 	END IF;
8782 -- End of the changes -lveerubh
8783 
8784 /*Bug 5642002: Added element only on Sat Sun condition*/
8785 	IF trunc(x_end_date) - trunc(x_start_date) <= 1 AND psp_general.business_days(trunc(x_start_date), trunc(x_end_date)) <= 0 THEN
8786 		g_all_holiday_zero_work_days := 'Y';
8787 		x_return_status:=FND_API.G_RET_STS_SUCCESS;
8788 		return;
8789 	END IF;
8790 
8791 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8792 	END IF;
8793 	x_return_status:=FND_API.G_RET_STS_SUCCESS;
8794 
8795 	hr_utility.trace('	Leaving CHECK_ZERO_WORK_DAYS');
8796 
8797 	EXCEPTION
8798 	WHEN OTHERS then
8799 	------dbms_output.put_line('Check_zero_work_days.....'||x_assignment_id||' '||x_costed_value);
8800 		select assignment_number into l_assignment_number from per_assignments_f where assignment_id =x_assignment_id
8801 		and effective_start_date=(select max(effective_start_date) from per_assignments_f where
8802 		assignment_id=x_assignment_id);
8803 		fnd_message.set_name('PSP','PSP_ZERO_WORK_DAYS');
8804 		fnd_message.set_token('ASSIGNMENT_NO',l_assignment_number);
8805 		fnd_message.set_token('LINE_AMT',x_costed_value );
8806 		fnd_msg_pub.add;
8807 
8808 	--	fnd_msg_pub.add_exc_msg('PSP-PAYTRN','CHECK_ZERO_WORK_DAYS','Assg_ID '||x_assignment_id||' Amt '||x_costed_value);
8809 	x_return_status:= FND_API.G_RET_STS_UNEXP_ERROR;
8810 
8811 	END check_zero_work_days;
8812 
8813 /***************************************************************************************************
8814 Created By	:	lveerubh
8815 
8816 Date Created By :	15-SEP-2001
8817 
8818 Purpose	:	Bug 1994421 -Zero Work Days Build
8819 
8820 Know limitations, enhancements or remarks
8821 
8822 Change History
8823 
8824 Who			When		What
8825 lveerubh		15-SEP-2001	Creating the procedure
8826 					This procedure inserts a single line
8827 					into psp_payroll_lines and psp_payroll_sub_lines
8828 					with sub line start date and sub line end date
8829 					as date earned
8830 amakrish		01-Apr-2008     Changed the sub line start date and sub line end date
8831 					to be least of date earned or payroll period end date
8832 					for bug 6886237
8833 
8834 ***************************************************************************************************/
8835 PROCEDURE	CREATE_SLINE_TERM_EMP ( x_payroll_line_id	IN	NUMBER,
8836 					x_reason		IN	VARCHAR2,
8837 					x_return_status	OUT NOCOPY	VARCHAR2)
8838 IS
8839 l_sub_line_id	NUMBER(10);
8840 l_rowid	VARCHAR2(20);
8841 
8842 CURSOR get_payroll_line_csr
8843 IS
8844 SELECT *
8845 FROM	psp_payroll_lines ppl
8846 WHERE	ppl.payroll_line_id	=	x_payroll_line_id;
8847 
8848 g_payroll_line_rec	get_payroll_line_csr%ROWTYPE;
8849 l_tp_end_date           per_time_periods.end_date%TYPE;  -- BUG 6886237
8850 BEGIN
8851 
8852 	hr_utility.trace('	Entering CREATE_SLINE_TERM_EMP');
8853 	OPEN	get_payroll_line_csr;
8854 	FETCH	get_payroll_line_csr INTO	g_payroll_line_rec;
8855 	CLOSE	get_payroll_line_csr;
8856 
8857 	/*Bug 6886237*/
8858 	SELECT end_date
8859 	INTO l_tp_end_date
8860 	FROM per_time_periods
8861 	WHERE time_period_id = (select time_period_id from psp_payroll_controls
8862 	                        where payroll_control_id = (select payroll_control_id from
8863 	                                                    psp_payroll_lines
8864 	                                                    where payroll_line_id = x_payroll_line_id));
8865 
8866 -- Inserting into PSP_SUB_LINES
8867 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id FROM DUAL;
8868  hr_utility.trace('	inserting into Sublines -2UISISI');
8869 	PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW (
8870 			X_ROWID			=> l_rowid,
8871 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
8872 			X_PAYROLL_LINE_ID		=> x_payroll_line_id,
8873 			X_SUB_LINE_START_DATE		=> least(trunc(g_payroll_line_rec.effective_Date), trunc(l_tp_end_date)),  /*Bug 6886237*/
8874 			X_SUB_LINE_END_DATE		=> least(trunc(g_payroll_line_rec.effective_Date), trunc(l_tp_end_date)),  /*Bug 6886237*/
8875 			X_REASON_CODE			=> x_reason,
8876 			X_PAY_AMOUNT			=> g_payroll_line_rec.pay_amount,
8877 			X_DAILY_RATE			=> g_payroll_line_rec.pay_amount,
8878 			X_SALARY_USED			=> g_payroll_line_rec.pay_amount,
8879 			X_CURRENT_SALARY		=> NULL,
8880 			X_FTE				=> NULL,
8881 			X_ORGANIZATION_ID		=> NULL,
8882 			X_JOB_ID			=> NULL,
8883 			X_POSITION_ID			=> NULL,
8884 			X_GRADE_ID			=> NULL,
8885 			X_PEOPLE_GRP_ID		=> NULL,
8886 			X_EMPLOYMENT_BEGIN_DATE	=> NULL,
8887 			X_EMPLOYMENT_END_DATE		=> NULL,
8888 			X_EMPLOYEE_STATUS_INACTIVE_DAT => NULL,
8889 			X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
8890 			X_ASSIGNMENT_BEGIN_DATE	=> NULL,
8891 			X_ASSIGNMENT_END_DATE		=> NULL,
8892 			x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
8893 			x_attribute1			=> NULL,
8894 			x_attribute2			=> NULL,
8895 			x_attribute3			=> NULL,
8896 			x_attribute4			=> NULL,
8897 			x_attribute5			=> NULL,
8898 			x_attribute6			=> NULL,
8899 			x_attribute7			=> NULL,
8900 			x_attribute8			=> NULL,
8901 			x_attribute9			=> NULL,
8902 			x_attribute10			=> NULL,
8903 			X_MODE			=> 'R' );
8904 
8905 --Inserting into PSP_SUB_LINES_REASONS
8906 		l_rowid	:=	NULL;
8907 		PSP_SUB_LINE_REASONS_PKG.INSERT_ROW (
8908 			X_ROWID			=> l_rowid,
8909 			X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
8910 			X_REASON_CODE			=> x_reason,
8911 			X_PARENT_LINE_ID		=> l_sub_line_id,
8912 			X_MODE			=> 'R');
8913 		x_return_status := FND_API.G_RET_STS_SUCCESS;
8914 
8915 		hr_utility.trace('	Leaving CREATE_SLINE_TERM_EMP');
8916 
8917 EXCEPTION
8918  WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8919 	FND_MSG_PUB.ADD_EXC_MSG('PSP_PAYTRN','CREATE_SLINE_TERM_EMP');
8920 	x_return_status	:=	FND_API.G_RET_STS_UNEXP_ERROR;
8921  WHEN OTHERS THEN
8922 	FND_MSG_PUB.ADD_EXC_MSG('PSP_PAYTRN','CREATE_SLINE_TERM_EMP');
8923 	x_return_status	:=	FND_API.G_RET_STS_UNEXP_ERROR;
8924 
8925 END create_sline_term_emp;
8926 --======================= End of procedure =================
8927 
8928 --	Introduced the following procedure for bug fix 2916848
8929 --	Procedure:	CREATE_PRORATE_CALENDAR
8930 --	Purpose:	When User selects Payroll Proration preference for Import Payroll process
8931 --			This procedure is called instead of the default create_prorate_calendar procedure.
8932 --			Payroll proration instead of LD prorating based on salary basis.
8933 
8934 PROCEDURE create_prorate_calendar	(p_start_date		IN	DATE,
8935 					p_end_date		IN	DATE,
8936 					p_pay_amount		IN	NUMBER,
8937 					p_payroll_line_id	IN	NUMBER,
8938 					p_balance_amount	OUT NOCOPY NUMBER,
8939 					p_return_status		OUT NOCOPY VARCHAR2) IS
8940 l_daily_rate		NUMBER;
8941 l_daily_balance		NUMBER;
8942 l_final_daily_rate	NUMBER;
8943 l_total_salary		NUMBER;
8944 l_final_salary		NUMBER;
8945 l_balance_amount	NUMBER;
8946 l_start_date		DATE;
8947 l_end_date		DATE;
8948 i			NUMBER;
8949 j			NUMBER;
8950 l_non_working_day_flag	NUMBER;
8951 l_business_days		NUMBER;
8952 l_sub_line_id		NUMBER;
8953 l_payroll_line_id	NUMBER;
8954 l_rowid			VARCHAR2(20);
8955 l_element_name		pay_element_types_f.element_name%TYPE;
8956 l_temp_start_date	DATE;
8957 l_temp_end_date		DATE;
8958 
8959 BEGIN
8960 	hr_utility.trace('	Entering Create Prorate Calendar st_dt, end_dt, pay_amnt, payroll_line_id, balnce_amt ='||
8961 	p_start_date ||','|| p_end_date||','|| p_pay_amount||','|| p_payroll_line_id ||','|| p_balance_amount);
8962 	hr_utility.trace('	g_st_dt, g_end_dt =' ||g_start_date ||','|| g_end_date);
8963 	l_non_working_day_flag := 0;
8964 	l_start_date := p_start_date;
8965 	l_end_date := p_end_date;
8966 
8967 	IF (((TRUNC(g_end_date) - TRUNC(l_end_date))) < 0) THEN
8968 		l_end_date := g_end_date;
8969 	END IF;
8970 
8971 	i := (TRUNC(l_start_date) - TRUNC(g_start_date)) + 1;
8972 	IF (i < 1) THEN
8973 		i := 1;
8974 		l_start_date := g_start_date;
8975 	END IF;
8976 	hr_utility.trace('	l_st_dt, l_end_dt =' ||l_start_date ||','|| l_end_date);
8977 	l_business_days := psp_general.business_days(l_start_date, l_end_date);
8978 	hr_utility.trace('	l_business_days , g_no_of_days='|| l_business_days||','||g_no_of_days);
8979 
8980 	IF (l_business_days = 0) THEN
8981 		l_non_working_day_flag := 1;
8982 		l_business_days := 1;
8983 	END IF;
8984 
8985 	j := i;
8986 
8987 	WHILE (j <= g_no_of_days)
8988 	LOOP
8989 		hr_utility.trace('	 daily rate 0.0 for j=' ||j);
8990 		daily_calendar(j) := 0.00;
8991 		j := j + 1;
8992 	END LOOP;
8993 
8994 	l_daily_rate	:= 0.00;
8995 	IF (NVL(p_pay_amount, 0) <> 0.00) THEN
8996 		l_daily_rate := p_pay_amount;
8997 		hr_utility.trace('	 p_pay_amount, l_daily_rate=' ||l_daily_rate);
8998 		IF (l_non_working_day_flag = 0) THEN
8999 			l_daily_rate := ROUND((p_pay_amount / l_business_days), g_ext_precision);
9000 			hr_utility.trace('	 l_non_working_day_flag = 0 , l_daily_rate=' ||l_daily_rate);
9001 		END IF;
9002 	END IF;
9003 
9004 	l_total_salary := 0.00;
9005 
9006 	l_temp_start_date:=l_start_date;
9007 	l_temp_end_date:=l_end_date;
9008 
9009 	WHILE TRUNC(l_temp_start_date) <= TRUNC(l_temp_end_date)
9010 	LOOP
9011 		daily_calendar(i) := 0.00;
9012 		IF (work_calendar(i) = 'Y') THEN
9013 			daily_calendar(i) := l_daily_rate;
9014 			IF (l_non_working_day_flag = 1) THEN
9015 				work_calendar(i) := 'N';
9016 				daily_calendar(i) := 0.00;
9017 			END IF;
9018 		END IF;
9019 		l_temp_start_date := TRUNC(l_temp_start_date) + 1;
9020 		l_total_salary := l_total_salary + daily_calendar(i);
9021 		i := i + 1;
9022 
9023 	END LOOP;
9024 
9025 	-- zero work days, (no business days between stdate and enddate)..bug 4670588
9026 	if l_non_working_day_flag = 1 then -- (means no work days and hence all daily
9027 					-- rates in array are zero)
9028 		l_total_Salary	:= p_pay_amount;
9029 		l_end_date := l_start_date;
9030 	end if;
9031 
9032 	l_final_daily_rate := l_daily_rate;
9033 	hr_utility.trace('	l_total__salary = '||l_total_salary);
9034 	l_final_salary := ROUND(l_total_salary, g_precision);
9035 	hr_utility.trace('	l_final_salary = '||l_final_salary);
9036 	l_balance_amount :=0.0;
9037 
9038 
9039 	IF l_final_salary <> ROUND(p_pay_amount, g_precision) THEN
9040 		l_balance_amount := p_pay_amount - l_final_salary;
9041 		hr_utility.trace('	l_balance_amount = '||l_balance_amount);
9042 		l_daily_balance := ROUND((l_balance_amount / l_business_days), g_ext_precision);
9043 		hr_utility.trace('	l_daily_balance = '||l_daily_balance);
9044 		l_final_daily_rate := l_final_daily_rate + l_daily_balance;
9045 		hr_utility.trace('	l_finally_daily_rate 2= '||l_final_daily_rate);
9046 		l_final_salary := round((l_total_salary + l_balance_amount), g_precision);
9047 		hr_utility.trace('	l_finally_salary 2= '||l_final_salary);
9048 	END IF;
9049 
9050 	SELECT PSP_PAYROLL_SUB_LINES_S.NEXTVAL into l_sub_line_id FROM DUAL;
9051 
9052  hr_utility.trace('	inserting into Sublines -2LLLLLLLALALAL');
9053 	PSP_PAYROLL_SUB_LINES_PKG.INSERT_ROW
9054 		(X_ROWID			=> l_rowid,
9055 		X_PAYROLL_SUB_LINE_ID		=> l_sub_line_id,
9056 		X_PAYROLL_LINE_ID		=> p_payroll_line_id,
9057 		X_SUB_LINE_START_DATE		=> l_start_date,
9058 		X_SUB_LINE_END_DATE		=> l_end_date,
9059 		X_REASON_CODE			=> 'SALARY_CHANGE',
9060 		X_PAY_AMOUNT			=> l_final_salary,
9061 		X_DAILY_RATE			=> l_final_daily_rate,
9062 		X_SALARY_USED			=> l_final_salary,
9063 		X_CURRENT_SALARY		=> l_final_salary,
9064 		X_FTE				=> NULL,
9065 		X_ORGANIZATION_ID		=> NULL,
9066 		X_JOB_ID			=> NULL,
9067 		X_POSITION_ID			=> NULL,
9068 		X_GRADE_ID			=> NULL,
9069 		X_PEOPLE_GRP_ID			=> NULL,
9070 		X_EMPLOYMENT_BEGIN_DATE		=> NULL,
9071 		X_EMPLOYMENT_END_DATE		=> NULL,
9072 		X_EMPLOYEE_STATUS_INACTIVE_DAT	=> NULL,
9073 		X_EMPLOYEE_STATUS_ACTIVE_DATE	=> NULL,
9074 		X_ASSIGNMENT_BEGIN_DATE		=> NULL,
9075 		X_ASSIGNMENT_END_DATE		=> NULL,
9076 		x_attribute_category		=> NULL,		-- Introduced DFF parameters for bug fix 2908859
9077 		x_attribute1			=> NULL,
9078 		x_attribute2			=> NULL,
9079 		x_attribute3			=> NULL,
9080 		x_attribute4			=> NULL,
9081 		x_attribute5			=> NULL,
9082 		x_attribute6			=> NULL,
9083 		x_attribute7			=> NULL,
9084 		x_attribute8			=> NULL,
9085 		x_attribute9			=> NULL,
9086 		x_attribute10			=> NULL,
9087 		X_MODE				=> 'R' );
9088 
9089 	l_rowid := NULL;
9090 
9091 	PSP_SUB_LINE_REASONS_PKG.INSERT_ROW
9092 		(X_ROWID		=> l_rowid,
9093 		X_PAYROLL_SUB_LINE_ID	=> l_sub_line_id,
9094 		X_REASON_CODE		=> 'SALARY_CHANGE',
9095 		X_PARENT_LINE_ID	=> l_sub_line_id,
9096 		X_MODE			=> 'R');
9097 
9098 	p_balance_amount :=l_balance_amount;
9099 	p_return_status	:= FND_API.G_RET_STS_SUCCESS;
9100  hr_utility.trace('	Leaving CREATE PRORATE CALENDAR');
9101 EXCEPTION
9102 	WHEN fnd_api.g_exc_unexpected_error THEN
9103 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_PRORATE_CALENDAR');
9104 		p_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
9105 	WHEN OTHERS THEN
9106 		fnd_msg_pub.add_exc_msg('PSP_PAYTRN','CREATE_PRORATE_CALENDAR');
9107 		p_return_status	:= FND_API.G_RET_STS_UNEXP_ERROR;
9108 END create_prorate_calendar;
9109 
9110 END PSP_PAYTRN; -- End of Package Body