DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSP_PAYTRN

Source


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