DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSP_ENC_SUM_TRAN

Source


1 PACKAGE BODY PSP_ENC_SUM_TRAN AS
2 /* $Header: PSPENSTB.pls 120.13 2007/07/19 09:23:08 amakrish noship $ */
3 
4 --	##########################################################################
5 --	This procedure initiates the encumbrance summarization processes gl/ogm
6 --	##########################################################################
7 g_control_rec_found VARCHAR2(10) := 'TRUE';
8 l_phase_status      number := 0 ;
9 g_fatal number;
10 g_payroll_action_id number; /* Bug 2030232 */
11 
12 g_currency_code VARCHAR(15); -- for Bug 2478000 Qubec fix
13 
14 g_susp_prob varchar2(5) :=  NULL;    --- 2479579
15 
16 g_insert_str	varchar2(5000);	-- Introduced for bug fix 3233373
17 g_warning_message	VARCHAR2(5000);
18 
19 g_dff_grouping_option	CHAR(1);		-- Introduced for bug fix 2908859
20 
21 g_def_end_date	DATE;
22 
23 g_precision		NUMBER;
24 g_ext_precision	NUMBER;
25 g_suspense_failed	VARCHAR2(15);
26 g_process_complete	BOOLEAN;
27 g_sa_autopop		BOOLEAN;
28 
29 PROCEDURE	move_rej_lines_to_arch (p_payroll_action_id	IN	NUMBER);
30 
31 PROCEDURE create_sum_lines	(p_payroll_action_id	IN		NUMBER,
32 				p_return_status		OUT NOCOPY	VARCHAR2);
33 
34 PROCEDURE update_hierarchy_dates (p_payroll_action_id	IN	NUMBER,
35 					p_return_status		OUT NOCOPY	VARCHAR2);
36 
37 PROCEDURE	add_st_warnings(p_start_date	IN	DATE	DEFAULT NULL,
38 						p_end_date			IN	DATE	DEFAULT NULL,
39 						p_assignment_id		IN	NUMBER	DEFAULT NULL,
40 						p_payroll_id		IN	NUMBER	DEFAULT NULL,
41 						p_element_type_id	IN	NUMBER	DEFAULT NULL,
42 						p_gl_ccid			IN	NUMBER	DEFAULT NULL,
43 						p_project_id		IN	NUMBER	DEFAULT NULL,
44 						p_task_id			IN	NUMBER	DEFAULT NULL,
45 						p_award_id			IN	NUMBER	DEFAULT NULL,
46 						p_exp_org_id		IN	NUMBER	DEFAULT NULL,
47 						p_exp_type			IN	VARCHAR2	DEFAULT NULL,
48 						p_effective_date	IN	DATE	DEFAULT NULL,
49 						p_error_status		IN	VARCHAR2	DEFAULT NULL);
50 
51 PROCEDURE log_st_warnings;
52 
53 TYPE t_num_15_type 	IS TABLE OF NUMBER(15) 		INDEX BY BINARY_INTEGER;
54 TYPE t_varchar_50_type 	IS TABLE OF VARCHAR2(50) 	INDEX BY BINARY_INTEGER;
55 TYPE t_varchar_150_type	IS TABLE OF VARCHAR2(150) 	INDEX BY BINARY_INTEGER;
56 TYPE t_num_10d2_type 	IS TABLE OF NUMBER	 	INDEX BY BINARY_INTEGER;
57 TYPE t_date_type 	IS TABLE OF DATE 		INDEX BY BINARY_INTEGER;
58 
59 TYPE r_enc_rec IS RECORD
60 	(assignment_id		t_num_15_type,
61 	payroll_id			t_num_15_type,
62 	element_type_id		t_num_15_type,
63 	hierarchy_code		t_varchar_50_type,
64 	gl_ccid				t_num_15_type,
65 	project_id			t_num_15_type,
66 	task_id				t_num_15_type,
67 	award_id			t_num_15_type,
68 	exp_org_id			t_num_15_type,
69 	exp_type			t_varchar_50_type,
70 	enc_start_date		t_date_type,
71 	enc_end_date		t_date_type);
72 
73 t_enc_lines			r_enc_rec;
74 t_enc_nlines		r_enc_rec;
75 
76 TYPE r_asg_rec IS RECORD
77 	(assignment_id		t_num_15_type,
78 	payroll_id			t_num_15_type);
79 
80 l_asgs			r_asg_rec;
81 
82 TYPE r_enc_susp_rec IS RECORD
83 	(row_id					t_num_15_type,
84 	encumbrance_amount		t_num_10d2_type,
85 	enc_start_date			t_date_type,
86 	enc_end_date			t_date_type);
87 t_enc_susp_lines	r_enc_susp_rec;
88 
89 TYPE r_warning_rec IS RECORD
90 	(start_date		t_date_type,
91 	end_date		t_date_type,
92 	assignment_id	t_num_15_type,
93 	payroll_id		t_num_15_type,
94 	element_type_id	t_num_15_type,
95 	gl_ccid			t_num_15_type,
96 	project_id		t_num_15_type,
97 	task_id			t_num_15_type,
98 	award_id		t_num_15_type,
99 	exp_org_id		t_num_15_type,
100 	exp_type		t_varchar_150_type,
101 	effective_date	t_date_type,
102 	error_status	t_varchar_150_type);
103 st_warnings		r_warning_rec;
104 
105 PROCEDURE enc_sum_trans(errbuf	           OUT NOCOPY VARCHAR2,
106                         retcode	           OUT NOCOPY VARCHAR2,
107                         p_payroll_action_id	    IN NUMBER,
108 			p_business_group_id IN NUMBER,
109 			p_set_of_books_id   IN NUMBER) IS
110 
111 l_return_status			VARCHAR2(1);
112 l_msg_count				NUMBER;
113 l_msg_data				VARCHAR2(2000);
114 l_liq_check				NUMBER;
115 l_gl_check				NUMBER;
116 l_gms_check				NUMBER;
117 l_last_update_date		DATE;
118 l_last_updated_by		NUMBER;
119 l_last_updated_login	NUMBER;
120 l_request_id			NUMBER;
121 l_sa_autopop			VARCHAR2(1);
122 
123 CURSOR	autopop_config_cur IS
124 SELECT	pcv_information7 suspense_account
125 FROM	pqp_configuration_values
126 WHERE	pcv_information_category = 'PSP_ENABLE_AUTOPOPULATION'
127 AND	legislation_code IS NULL
128 AND	NVL(business_group_id, p_business_group_id) = p_business_group_id
129 ORDER BY business_group_id;
130 
131 CURSOR	liq_check_cur IS
132 SELECT	COUNT(1)
133 FROM	psp_enc_processes
134 WHERE	payroll_action_id = p_payroll_action_id
135 AND	process_phase = 'liquidate';
136 
137 CURSOR	st_asgs_cur IS
138 SELECT	DISTINCT assignment_id,
139 	payroll_id
140 FROM	psp_enc_summary_lines pesl
141 WHERE	payroll_action_id = p_payroll_action_id
142 AND	superceded_line_id IS NULL
143 AND	status_code = 'N';
144 
145 CURSOR	def_end_date_cur IS
146 SELECT	peed.period_end_date
147 FROM	psp_enc_end_dates peed
148 WHERE	peed.business_group_id = p_business_group_id
149 AND	peed.set_of_books_id   = p_set_of_books_id
150 AND	peed.default_org_flag  = 'Y';
151 
152 CURSOR	check_gl_lines IS
153 SELECT	COUNT(1)
154 FROM	psp_enc_summary_lines
155 WHERE	payroll_action_id = p_payroll_action_id
156 AND	superceded_line_id IS NULL
157 AND	gl_code_combination_id IS NOT NULL
158 AND	status_code = 'N';
159 
160 CURSOR	check_gms_lines IS
161 SELECT	COUNT(1)
162 FROM	psp_enc_summary_lines
163 WHERE	payroll_action_id = p_payroll_action_id
164 AND	superceded_line_id IS NULL
165 AND	award_id IS NOT NULL
166 AND	status_code = 'N';
167 BEGIN
168 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering enc_sum_trans p_payroll_action_id: ' || p_payroll_action_id || '
169 	p_business_group_id: ' || p_business_group_id || '
170 	p_set_of_books_id: ' || p_set_of_books_id);
171 
172    g_error_api_path := '';
173    fnd_msg_pub.initialize;
174    psp_general.TRANSACTION_CHANGE_PURGEBLE;  --2431917
175    g_business_group_id := p_business_group_id;
176    g_set_of_books_id := p_set_of_books_id;
177    g_payroll_action_id      := p_payroll_action_id; /* for Bug 2030232 */
178 
179 	g_currency_code := psp_general.get_currency_code(p_business_group_id);-- For bug 2478000 Qubec fix
180 
181 	psp_general.get_currency_precision(g_currency_code, g_precision, g_ext_precision);
182 
183 	g_dff_grouping_option := psp_general.get_enc_dff_grouping_option(p_business_group_id);	-- Introduced for bug fix 2908859
184 	g_suspense_failed := 'FALSE';
185 	g_process_complete := TRUE;
186 
187 	OPEN autopop_config_cur;
188 	FETCH autopop_config_cur INTO l_sa_autopop;
189 	IF (autopop_config_cur%ROWCOUNT = 0) THEN
190 		l_sa_autopop := 'N';
191 	END IF;
192 	CLOSE autopop_config_cur;
193 
194 	g_sa_autopop := FALSE;
195 	IF (l_sa_autopop = 'Y') THEN
196 		g_sa_autopop := TRUE;
197 	END IF;
198 
199 	OPEN def_end_date_cur;
200 	FETCH def_end_date_cur INTO g_def_end_date;
201 	CLOSE def_end_date_cur;
202 
203 	l_last_update_date := SYSDATE;
204 	l_last_updated_by := NVL(FND_GLOBAL.USER_ID, -1);
205 	l_last_updated_login := NVL(FND_GLOBAL.LOGIN_ID, -1);
206 	l_request_id := fnd_global.conc_request_id;
207 
208 	INSERT INTO psp_enc_processes
209 		(request_id,			process_code,			payroll_action_id,
210 		process_status,			process_phase,			business_group_id,
211 		set_of_books_id,		creation_date,			created_by,
212 		last_update_date,		last_updated_by,	last_update_login)
213 	SELECT	l_request_id,		'ST',				p_payroll_action_id,
214 			'I',				process_phase,		p_business_group_id,
215 			p_set_of_books_id,	l_last_update_date,	l_last_updated_by,
216 			l_last_update_date,	l_last_updated_by,	l_last_updated_login
217 	FROM	psp_enc_processes pep
218 	WHERE	process_code IN ('CEL', 'LET')
219 	AND		payroll_action_id = p_payroll_action_id
220 	AND		NOT EXISTS	(SELECT	1
221 						FROM	psp_enc_processes pep2
222 						WHERE	pep2.payroll_action_id = p_payroll_action_id
223 						AND		pep2.process_code = 'ST');
224 
225 	UPDATE	psp_enc_processes
226 	SET		process_status = 'S',
227 			process_phase = 'completed'
228 	WHERE	payroll_action_id = p_payroll_action_id
229 	AND		process_code IN ('CEL', 'LET');
230 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated original and current process status in psp_enc_processes');
231 
232 	OPEN st_asgs_cur;
233 	FETCH st_asgs_cur BULK COLLECT INTO l_asgs.assignment_id, l_asgs.payroll_id;
234 	CLOSE st_asgs_cur;
235 
236 	move_rej_lines_to_arch(p_payroll_action_id);
237 
238 	OPEN liq_check_cur;
239 	FETCH liq_check_cur INTO l_liq_check;
240 	CLOSE liq_check_cur;
241 
242 	IF (l_liq_check > 0) THEN
243 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling psp_enc_liq_tran.enc_liq_trans');
244 		psp_enc_liq_tran.enc_liq_trans(p_payroll_action_id, p_business_group_id, p_set_of_books_id, l_return_status);
245 
246 		IF l_return_status NOT IN (fnd_api.g_ret_sts_error, fnd_api.g_ret_sts_success) THEN
247 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
248 		END IF;
249 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After psp_enc_liq_tran.enc_liq_trans');
250 	END IF;
251 
252 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling enc_batch_begin');
253    	enc_batch_begin(p_payroll_action_id, l_return_status);
254 
255 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
256 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
257 	END IF;
258 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After enc_batch_begin');
259 
260 	IF g_control_rec_found = 'FALSE' THEN
261 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling enc_batch_end');
262 		enc_batch_end(p_payroll_action_id, l_return_status);
263 
264 		IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
265 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
266 		END IF;
267 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After enc_batch_end');
268 		retcode := FND_API.G_RET_STS_SUCCESS;
269 
270             psp_message_s.print_error(p_mode=>FND_FILE.log,
271                                       p_print_header=>FND_API.G_FALSE);
272 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving enc_sum_trans p_payroll_action_id: ' || p_payroll_action_id || '
273 	p_business_group_id: ' || p_business_group_id || '
274 	p_set_of_books_id: ' || p_set_of_books_id);
275           PSP_MESSAGE_S.Print_success;
276 	  return;
277     END IF;
278 
279 -- Enh  2505778  LD, GMS Integration with PQH
280 
281      if fnd_profile.value('PSP_ENC_ENABLE_PQH') ='Y' then
282 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling pqh_psp_integration.relieve_budget_commitments');
283         pqh_psp_integration.relieve_budget_commitments( 'S', l_return_status);
284         If l_return_status<>FND_API.G_RET_STS_SUCCESS THEN
285 	  	fnd_message.set_name('PSP','PSP_ENC_PQH_ERROR');
286 		fnd_msg_pub.add;
287             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
288         end if;
289 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After pqh_psp_integration.relieve_budget_commitments');
290      end if;
291 
292     -- FIRST NORMAL RUN
293     -- initiate the gl encumbrance summarization and transfer
294     -- call the user extension to populate attribute1 through attribute30
295     IF FND_PROFILE.VALUE('PSP_ST_EXTENSION_ENABLE') = 'Y' THEN
296       -- 2968684 added params to following proc
297 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling psp_st_ext.summary_ext_encumber');
298         psp_st_ext.summary_ext_encumber(p_payroll_action_id ,
299                                         p_business_group_id,
300                                         p_set_of_books_id);
301 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After psp_st_ext.summary_ext_encumber');
302     END IF;
303 
304 	OPEN check_gl_lines;
305 	FETCH check_gl_lines INTO l_gl_check;
306 	CLOSE check_gl_lines;
307 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_gl_check: ' || l_gl_check);
308 
309 	IF (l_gl_check > 0) THEN
310 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling tr_to_gl_int');
311 		tr_to_gl_int(p_payroll_action_id, l_return_status);
312 
313 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
314 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
315 		END IF;
316 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After tr_to_gl_int');
317 	END IF;
318 
319      -- call the user extension to populate attribute1 through attribute30
320     IF FND_PROFILE.VALUE('PSP_ST_EXTENSION_ENABLE') = 'Y' THEN
321       -- 2968684 added params to following proc
322 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling psp_st_ext.summary_ext_encumber');
323         psp_st_ext.summary_ext_encumber(p_payroll_action_id ,
324                                         p_business_group_id,
325                                         p_set_of_books_id);
326 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After psp_st_ext.summary_ext_encumber');
327     END IF;
328 
329     -- initiate the ogm encumbrance summarization and transfer
330 	OPEN check_gms_lines;
331 	FETCH check_gms_lines INTO l_gms_check;
332 	CLOSE check_gms_lines;
333 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_gms_check: ' || l_gms_check);
334 
335 	IF (l_gms_check > 0) THEN
336 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling tr_to_gms_int');
337 		tr_to_gms_int(p_payroll_action_id, l_return_status);
338 
339 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
340 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
341 		END IF;
342 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After tr_to_gms_int');
343 	END IF;
344 
345     -- SECOND RUN TO TAKE CARE OF TIE-BACK
346     -- initiate the suspense lines summarization
347 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling create_sum_lines');
348     create_sum_lines(p_payroll_action_id, l_return_status);
349 
350 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
351 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
352 	END IF;
353 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After create_sum_lines');
354 
355         -- call the user extension to populate attribute1 through attribute30
356     IF FND_PROFILE.VALUE('PSP_ST_EXTENSION_ENABLE') = 'Y' THEN
357       -- 2968684 added params to following proc
358 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling psp_st_ext.summary_ext_encumber');
359         psp_st_ext.summary_ext_encumber(p_payroll_action_id ,
360                                         p_business_group_id,
361                                         p_set_of_books_id);
362 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After psp_st_ext.summary_ext_encumber');
363     END IF;
364 
365 	OPEN check_gl_lines;
366 	FETCH check_gl_lines INTO l_gl_check;
367 	CLOSE check_gl_lines;
368 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_gl_check: ' || l_gl_check);
369 
370 	IF (l_gl_check > 0) THEN
371 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling tr_to_gl_int');
372 		tr_to_gl_int(p_payroll_action_id, l_return_status);
373 
374 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
375 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
376 		END IF;
377 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After tr_to_gl_int');
378 	END IF;
379 
380     -- call the user extension to populate attribute1 through attribute30
381     IF FND_PROFILE.VALUE('PSP_ST_EXTENSION_ENABLE') = 'Y' THEN
382       -- 2968684 added params to following proc
383 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling psp_st_ext.summary_ext_encumber');
384         psp_st_ext.summary_ext_encumber(p_payroll_action_id ,
385                                         p_business_group_id,
386                                         p_set_of_books_id);
387 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After psp_st_ext.summary_ext_encumber');
388     END IF;
389 
390 	OPEN check_gms_lines;
391 	FETCH check_gms_lines INTO l_gms_check;
392 	CLOSE check_gms_lines;
393 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_gms_check: ' || l_gms_check);
394 
395 	IF (l_gms_check > 0) THEN
396 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling tr_to_gms_int');
397 		tr_to_gms_int(p_payroll_action_id, l_return_status);
398 
399 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
400 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
401 		END IF;
402 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After tr_to_gms_int');
403 	END IF;
404 
405 	g_suspense_failed := 'TRUE';
406 	DELETE	psp_enc_summary_lines
407 	WHERE	payroll_action_id = p_payroll_action_id
408 	AND	superceded_line_id IS NULL
409 	AND	status_code = 'N';
410 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted un-imported summary lines (' || SQL%ROWCOUNT || ')');
411 
412 	UPDATE	psp_enc_lines
413 	SET	suspense_org_account_id = NULL,
414 		gl_code_combination_id = orig_gl_code_combination_id,
415 		project_id = orig_project_id,
416 		task_id = orig_task_id,
417 		award_id = orig_award_id,
418 		expenditure_organization_id = orig_expenditure_org_id,
419 		expenditure_type = orig_expenditure_type,
420 		gl_project_flag = decode(orig_gl_code_combination_id,NULL,'P','G'),
421 		encumbrance_date = prev_effective_date
422 	WHERE	payroll_action_id = p_payroll_action_id
423 	AND		suspense_reason_code like 'ES:%';
424 
425 	UPDATE	psp_enc_lines
426 	SET	orig_gl_code_combination_id = NULL,
427 		orig_project_id = NULL,
428 		orig_task_id = NULL,
429 		orig_award_id = NULL,
430 		orig_expenditure_org_id = NULL,
431 		orig_expenditure_type = NULL,
432 		suspense_reason_code = NULL
433 	WHERE	suspense_reason_code like 'ES:%'
434 	AND		payroll_action_id = p_payroll_action_id;
435 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Reverted un-imported suspense postings posted in this process (' || SQL%ROWCOUNT || ')');
436 
437 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling create_sum_lines');
438     create_sum_lines(p_payroll_action_id, l_return_status);
439 
440 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
441 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
442 	END IF;
443 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After create_sum_lines');
444 
445 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling enc_batch_end');
446     enc_batch_end(p_payroll_action_id, l_return_status);
447 
448     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
449       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
450     END IF;
451 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	After enc_batch_end');
452 	retcode := FND_API.G_RET_STS_SUCCESS;
453 
454 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving enc_sum_trans p_payroll_action_id: ' || p_payroll_action_id || '
455 	p_business_group_id: ' || p_business_group_id || '
456 	p_set_of_books_id: ' || p_set_of_books_id);
457           PSP_MESSAGE_S.Print_success;
458  EXCEPTION
459     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
460       ROLLBACK;   --Introduced as part of bug fix 1776606
461       g_error_api_path := 'ENC_SUM_TRANS:'||g_error_api_path;
462       fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','ENC_SUM_TRANS');
463       retcode := 2;
464 
465 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving enc_sum_trans p_payroll_action_id: ' || p_payroll_action_id || '
466 	p_business_group_id: ' || p_business_group_id || '
467 	p_set_of_books_id: ' || p_set_of_books_id);
468           psp_message_s.print_error(p_mode => FND_FILE.LOG,
469                                   p_print_header => FND_API.G_TRUE);
470           return;
471 
472     WHEN OTHERS THEN
473       ROLLBACK;   --Introduced as part of bug fix 1776606
474       g_error_api_path := 'ENC_SUM_TRANS:'||g_error_api_path;
475       fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','ENC_SUM_TRANS');
476       retcode := 2;
477 
478 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving enc_sum_trans p_payroll_action_id: ' || p_payroll_action_id || '
479 	p_business_group_id: ' || p_business_group_id || '
480 	p_set_of_books_id: ' || p_set_of_books_id);
481           psp_message_s.print_error(p_mode => FND_FILE.LOG,
482                                   p_print_header => FND_API.G_TRUE);
483           return;
484   END;
485 
486 --	##########################################################################
487 --	This procedure begins the encumbrance summarization process
488 --	This procedure generates a RUN_ID and updates PSP_ENC_CONTROLS table with
489 --	the RUN_ID and sets the ACTION_CODE = 'I' where
490 --	ACTION_TYPE in ('N', 'Q', 'U') and ACTION_CODE = 'N'
491 --	Included 'Q' for Quick Update Enh. 2143723
492 --	##########################################################################
493 
494  PROCEDURE enc_batch_begin(p_payroll_action_id IN NUMBER,
495 			p_return_status  OUT NOCOPY VARCHAR2
496 			) IS
497 
498 CURSOR	enc_control_cur IS
499 SELECT	enc_control_id,
500 	payroll_id,
501 	time_period_id
502 FROM 	psp_enc_controls
503 WHERE	payroll_action_id = p_payroll_action_id
504 --   	WHERE  	payroll_id = nvl(p_payroll_id, payroll_id)
505 AND	(total_dr_amount IS NOT NULL OR total_cr_amount IS NOT NULL)
506 AND	action_type IN ('N', 'Q', 'U') -- Included 'Q' for Quick Upd. Enh. 2143723
507 AND	action_code in ('N','I')   --- 2444657
508 AND	business_group_id = g_business_group_id
509 AND	set_of_books_id = g_set_of_books_id;
510 
511 enc_control_rec		enc_control_cur%ROWTYPE;
512 l_bg_id			NUMBER := g_business_group_id;
513 BEGIN
514 	SELECT psp_st_run_id_s.nextval INTO g_run_id FROM dual;
515 
516 	OPEN enc_control_cur;
517 	LOOP
518 		FETCH enc_control_cur INTO enc_control_rec;
519 		IF enc_control_cur%rowcount = 0 THEN
520 			g_control_rec_found := 'FALSE';
521 			fnd_message.set_name('PSP','PSP_ENC_NO_SUMM_REC_FOUND');
522 			fnd_msg_pub.add;
523 		--			p_return_status	:= fnd_api.g_ret_sts_unexp_error;
524 --   for bug fix 1868338 -- Subha
525 			p_return_status	:= fnd_api.g_ret_sts_success;
526 			CLOSE enc_control_cur;
527 			EXIT;
528 		END IF;
529 		IF enc_control_cur%NOTFOUND THEN
530 			CLOSE enc_control_cur;
531 			p_return_status	:= fnd_api.g_ret_sts_success;
532 			EXIT;
533 		END IF;
534 
535 		UPDATE psp_enc_controls
536 		SET action_code = 'I',
537 		run_id = g_run_id
538 		WHERE enc_control_id = enc_control_rec.enc_control_id
539 		AND time_period_id = enc_control_rec.time_period_id;
540 	END LOOP;
541 EXCEPTION
542 /* Introduced as part of bug fix #1776606 */
543 	when others then
544 		g_error_api_path := 'ENC_BATCH_BEGIN:'||g_error_api_path;
545 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','ENC_BATCH_BEGIN');
546 		p_return_status := fnd_api.g_ret_sts_unexp_error;
547 		RAISE;
548 END;
549 --	##########################################################################
550 --	This procedure ends the encumbrance summarization process
551 
552 --      This procedure updates the table PSP_ENC_CONTROLS with ACTION_CODE = 'P',
553 --      if the program is completed with a return code of success and if the
554 --      return code is failed it updates ACTION_CODE = 'N'.
555 
556 --	When the program returns a failure status, it also updates PSP_ENC_LINES
557 --	with STATUS_CODE = 'N' and PSP_ENC_SUMMARY_LINES with STATUS_CODE = 'R'
558 
559 --	##########################################################################
560 
561 PROCEDURE enc_batch_end	(p_payroll_action_id IN NUMBER,
562 			p_return_status  OUT NOCOPY VARCHAR2) IS
563 CURSOR	pending_line_cur IS
564 SELECT	COUNT(1)
565 FROM	psp_enc_summary_lines pesl
566 WHERE	pesl.payroll_action_id = p_payroll_action_id
567 AND	pesl.status_code = 'N';
568 
569 CURSOR	check_enc_lines IS
570 SELECT	COUNT(1)
571 FROM	psp_enc_lines
572 WHERE	payroll_action_id = p_payroll_action_id
573 AND		enc_start_date <= g_def_end_date;
574 
575 l_pending_line_count	NUMBER;
576 l_enc_lines_cnt			NUMBER;
577 l_return_status			VARCHAR2(1);
578 BEGIN
579 	update_hierarchy_dates(p_payroll_action_id	=>	p_payroll_action_id,
580 				p_return_status		=>	l_return_status);
581 
582 	IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
583 		RAISE fnd_api.g_exc_unexpected_error;
584 	END IF;
585 
586 	log_st_warnings;
587 
588 	IF (g_process_complete) THEN
589 		OPEN check_enc_lines;
590 		FETCH check_enc_lines INTO l_enc_lines_cnt;
591 		CLOSE check_enc_lines;
592 
593 		IF (l_enc_lines_cnt = 0) THEN
594 			DELETE	psp_enc_lines
595 			WHERE	payroll_action_id = p_payroll_action_id;
596 		END IF;
597 
598 		move_rej_lines_to_arch(p_payroll_action_id);
599 	END IF;
600 
601 	UPDATE	psp_enc_controls pec
602 	SET	action_code = 'P'
603 	WHERE	payroll_action_id = p_payroll_action_id
604 	AND	NOT EXISTS	(SELECT	1
605 				FROM	psp_enc_summary_lines pesl
606 				WHERE	pesl.payroll_action_id = p_payroll_action_id
607 				AND	pesl.enc_control_id = pec.enc_control_id
608 				AND	pesl.status_code = 'N');
609 	IF (SQL%ROWCOUNT > 0) THEN
610 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated action_code to ''P''');
611 	END IF;
612 
613 	UPDATE	psp_enc_processes
614 	SET	process_status = 'P', process_phase = 'completed'
615 	WHERE	payroll_action_id = p_payroll_action_id
616 	AND	process_code = 'ST'
617 	AND	NOT EXISTS	(SELECT	1
618 				FROM	psp_enc_summary_lines pesl
619 				WHERE	pesl.payroll_action_id = p_payroll_action_id
620 				AND	pesl.status_code = 'N');
621 	IF (SQL%ROWCOUNT > 0) THEN
622 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated process_phase to completed as no summarize and transfer is required');
623 	END IF;
624 
625 	UPDATE	psp_enc_processes
626 	SET	process_phase = 'summarize_transfer'
627 	WHERE	payroll_action_id = p_payroll_action_id
628 	AND		process_code = 'ST'
629 	AND	EXISTS	(SELECT	1
630 			FROM	psp_enc_lines pel
631 			WHERE	pel.payroll_action_id = p_payroll_action_id);
632 	IF (SQL%ROWCOUNT > 0) THEN
633 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated process_phase to summarize and transfer re-processing');
634 	END IF;
635 
636 	UPDATE	psp_enc_processes
637 	SET	process_phase = 'liquidate'
638 	WHERE	payroll_action_id = p_payroll_action_id
639 	AND	process_code = 'ST'
640 	AND	EXISTS	(SELECT	1
641 			FROM	psp_enc_summary_lines pesl
642 			WHERE	pesl.payroll_action_id = p_payroll_action_id
643 			AND	pesl.status_code = 'N'
644 			AND	pesl.superceded_line_id IS NOT NULL);
645 	IF (SQL%ROWCOUNT > 0) THEN
646 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated process_phase to liquidate for liquidation re-processing');
647 	END IF;
648 
649 	UPDATE	psp_enc_process_assignments pepa
650 	SET	assignment_status = 'P'
651 	WHERE	payroll_action_id = p_payroll_action_id
652 	AND	NOT EXISTS	(SELECT	1
653 				FROM	psp_enc_summary_lines pesl
654 				WHERE	pesl.payroll_action_id = p_payroll_action_id
655 				AND	pesl.assignment_id = pepa.assignment_id
656 				AND	pesl.payroll_id = pepa.payroll_id
657 				AND	pesl.status_code = 'N');
658 	IF (SQL%ROWCOUNT > 0) THEN
659 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated assignment_status to processed for summarized and transferred assignments');
660 	END IF;
661 
662 	UPDATE	psp_enc_process_assignments pepa
663 	SET	assignment_status = 'S'
664 	WHERE	payroll_action_id = p_payroll_action_id
665 	AND	EXISTS	(SELECT	1
666 			FROM	psp_enc_summary_lines pesl
667 			WHERE	pesl.payroll_action_id = p_payroll_action_id
668 			AND	pesl.assignment_id = pepa.assignment_id
669 			AND	pesl.payroll_id = pepa.payroll_id
670 			AND	pesl.status_code = 'N'
671 			AND	pesl.superceded_line_id IS NULL);
672 	IF (SQL%ROWCOUNT > 0) THEN
673 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated assignment_status to summarize and transfer for assignments to be summarized and transferred');
674 	END IF;
675 
676 	UPDATE	psp_enc_process_assignments pepa
677 	SET	assignment_status = 'L'
678 	WHERE	payroll_action_id = p_payroll_action_id
679 	AND	EXISTS	(SELECT	1
680 			FROM	psp_enc_summary_lines pesl
681 			WHERE	pesl.payroll_action_id = p_payroll_action_id
682 			AND	pesl.assignment_id = pepa.assignment_id
683 			AND	pesl.payroll_id = pepa.payroll_id
684 			AND	pesl.status_code = 'N'
685 			AND	pesl.superceded_line_id IS NOT NULL);
686 	IF (SQL%ROWCOUNT > 0) THEN
687 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated assignment_status to liquidate for assignments to be liquidated');
688 	END IF;
689 
690   	COMMIT;
691 
692 	OPEN pending_line_cur;
693 	FETCH pending_line_cur INTO l_pending_line_count;
694 	CLOSE pending_line_cur;
695 
696 	IF (l_pending_line_count > 0) THEN
697 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Need to re-process');
698 		RAISE fnd_api.g_exc_unexpected_error;
699 	END IF;
700 	p_return_status	:= fnd_api.g_ret_sts_success;
701 EXCEPTION
702 	WHEN OTHERS THEN
703 		g_error_api_path := 'ENC_BATCH_END:'||g_error_api_path;
704 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','ENC_BATCH_END');
705 		p_return_status := fnd_api.g_ret_sts_unexp_error;
706 END enc_batch_end;
707 
708 /*****	Commented for Create and Update multi thread enh.
709  PROCEDURE enc_batch_end(p_payroll_action_id IN NUMBER,
710 		p_return_status  OUT NOCOPY VARCHAR2
711 			) IS
712 
713    	CURSOR 	enc_control_cur IS
714    	SELECT 	enc_control_id,
715           	payroll_id,
716           	time_period_id,
717             gl_phase,
718             gms_phase
719    	FROM   	psp_enc_controls
720    	WHERE 	payroll_action_id = p_payroll_action_id
721 --   	WHERE 	payroll_id = nvl(p_payroll_id, payroll_id)
722 	AND	(total_dr_amount IS NOT NULL OR total_cr_amount IS NOT NULL)
723    	AND	action_type IN ('N', 'Q', 'U') -- Included 'Q' for Quick Upd. Enh. 2143723.
724    	AND    	action_code = 'I'
725    	AND    	run_id = nvl(g_run_id, run_id)
726    	AND	business_group_id = g_business_group_id
727 	AND	set_of_books_id = g_set_of_books_id;
728 
729    	CURSOR 	new_enc_summary_lines_cur(P_ENC_CONTROL_ID  IN  NUMBER) IS
730    	SELECT 	enc_summary_line_id
731    	FROM 	psp_enc_summary_lines
732    	WHERE 	enc_control_id = p_enc_control_id
733    	AND   	status_code = 'N';
734 
735    	enc_control_rec		enc_control_cur%ROWTYPE;
736    	 / * Included as part of Bug fix #1776606 * /
737    	CURSOR  gl_gms_line_count_cur IS
738    	SELECT  count(*)
739      	FROM 	psp_enc_lines  pel
740 --      	,psp_enc_controls    pec
741      	WHERE pel.enc_control_id=  enc_control_rec.enc_control_id
742      	AND pel.time_period_id =   enc_control_rec.time_period_id
743         AND pel.encumbrance_amount<>0
744 	AND pel.business_group_id = g_business_group_id
745 	AND pel.set_of_books_id = g_set_of_books_id;
746 
747    	l_status_code		VARCHAR2(1);
748    	/ * Commented as part of Bug fix #1776606 * /
749 --   	l_o_enc_sum			NUMBER;
750    	l_enc_summary_line_id		NUMBER(10);
751  	l_bg_id			NUMBER := g_business_group_id;
752  	/ * Included as part of Bug fix #1776606 * /
753    	l_line_count   		        NUMBER(10);
754 
755 	BEGIN
756 
757  		OPEN enc_control_cur;
758   		LOOP
759 
760    			FETCH enc_control_cur INTO enc_control_rec;
761    			IF enc_control_cur%NOTFOUND THEN
762      			CLOSE enc_control_cur;
763      			EXIT;
764 
765    			END IF;
766 
767    -- This part is used to mark the status_code of non-transferred summary lines to 'R'
768    -- and mark the corresponding status_code of encumbrance lines back to 'N'
769 
770             IF (enc_control_rec.gl_phase is null and enc_control_rec.gms_phase is null) then
771                 rollback;
772             / * ELSIF (enc_control_rec.gl_phase = 'Transfer' or enc_control_rec.gms_phase = 'Transfer') then
773                 update psp_enc_controls
774                    set action_code = 'I'
775                  where enc_control_id = enc_control_rec.enc_control_id; * / --- commented for 2479579
776             ELSE
777 
778                 UPDATE 	psp_enc_summary_lines
779     			SET 	status_code = 'R'
780     			WHERE 	enc_control_id = enc_control_rec.enc_control_id
781     			AND 	status_code = 'N';
782 
783    -- This part is used to delete the rejected summary lines, mark the status_code
784    -- in psp_enc_controls to 'P' or 'N'
785                 / * Commented as part of bug fix #1776606
786        		SELECT 	nvl(sum(encumbrance_amount),0)
787      		INTO 	l_o_enc_sum
788      		FROM 	psp_enc_lines  pel
789 --          		,psp_enc_controls    pec
790      		WHERE pel.enc_control_id = enc_control_rec.enc_control_id
791      		AND pel.time_period_id = enc_control_rec.time_period_id
792 		AND pel.business_group_id = g_business_group_id
793 		AND pel.set_of_books_id = g_set_of_books_id;  * /
794 
795 		OPEN gl_gms_line_count_cur;
796 		FETCH gl_gms_line_count_cur INTO l_line_count;
797 		CLOSE gl_gms_line_count_cur;
798 
799 		/ * Included as part of bug fix #1776606 * /
800 		IF l_line_count = 0 THEN
801                         / * commented for 2445196: preserving this lines useful for debugging purposes
802 			DELETE 	FROM psp_enc_summary_lines
803         		WHERE 	enc_control_id = enc_control_rec.enc_control_id
804         		AND 	status_code = 'R'; * /
805 
806 			UPDATE 	psp_enc_controls
807         		SET 	action_code = 'P',
808             			run_id = NULL
809         		WHERE 	enc_control_id = enc_control_rec.enc_control_id;
810 
811      		ELSE
812 			UPDATE 	psp_enc_controls
813         		SET 	action_code = 'N',
814             			run_id = NULL
815         		WHERE 	enc_control_id = enc_control_rec.enc_control_id;
816                END IF;
817                 / * Commented as part of Bug fix #1776606 * /
818 	/ *	IF l_o_enc_sum = 0 THEN
819 			DELETE 	FROM psp_enc_summary_lines
820         		WHERE 	enc_control_id = enc_control_rec.enc_control_id
821         		AND 	status_code = 'R';
822 
823 			UPDATE 	psp_enc_controls
824         		SET 	action_code = 'P',
825             			run_id = NULL
826         		WHERE 	enc_control_id = enc_control_rec.enc_control_id;
827 
828      		ELSE
829 			UPDATE 	psp_enc_controls
830         		SET 	action_code = 'N',
831             			run_id = NULL
832         		WHERE 	enc_control_id = enc_control_rec.enc_control_id;
833               END IF;   * /
834        END IF; -- IF PHASES ARE OTHER THAN NULL OR TRANSFER
835      END LOOP;
836 
837 	UPDATE	psp_enc_processes
838 	SET		process_status = 'P', process_phase = 'completed'
839 	WHERE	payroll_action_id = p_payroll_action_id
840 	AND		NOT EXISTS	(SELECT	1
841 						FROM	psp_enc_summary_lines pesl
842 						WHERE	pesl.payroll_action_id = p_payroll_action_id
843 						AND		pesl.status_code = 'N');
844 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated process_phase to completed as no summarize and transfer is required');
845 
846 	UPDATE	psp_enc_processes
847 	SET		process_phase = 'summarize_transfer'
848 	WHERE	payroll_action_id = p_payroll_action_id
849 	AND		EXISTS	(SELECT	1
850 						FROM	psp_enc_summary_lines pesl
851 						WHERE	pesl.payroll_action_id = p_payroll_action_id
852 						AND		pesl.status_code = 'N'
853 						AND		pesl.superceded_line_id IS NULL);
854 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated process_phase to summarize and transfer re-processing');
855 
856 	UPDATE	psp_enc_processes
857 	SET		process_phase = 'liquidate'
858 	WHERE	payroll_action_id = p_payroll_action_id
859 	AND		EXISTS	(SELECT	1
860 						FROM	psp_enc_summary_lines pesl
861 						WHERE	pesl.payroll_action_id = p_payroll_action_id
862 						AND		pesl.status_code = 'N'
863 						AND		pesl.superceded_line_id IS NOT NULL);
864 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated process_phase to liquidate for liqduidation re-processing');
865 
866   	COMMIT;
867 	p_return_status	:= fnd_api.g_ret_sts_success;
868  EXCEPTION
869 	/ * Introduced as part of Bug fix #1776606 * /
870 	WHEN others then
871      		g_error_api_path := 'ENC_BATCH_END:'||g_error_api_path;
872 	        fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','ENC_BATCH_END');
873      		p_return_status := fnd_api.g_ret_sts_unexp_error;
874  END;
875 	End of comment for Create and Update multi thread enh.	*****/
876 
877 --	##########################################################################
878 --	This procedure summarizes all the lines from psp_enc_lines
879 --		and inserts the summarized lines into psp_enc_summary_lines
880 
881 --	Depending on the setup options, this procedure groups transactions from
882 --	PSP_ENC_LINES and inserts the summarized lines into PSP_ENC_SUMMARY_LINES
883 
884 --	There are two setup options in PSP_ENC_SETUP_OPTIONS table called 'TIME_BASED_SUMM'
885 --	and 'CI_BASED_SUMM_GL' on which the procedure depends.
886 
887 --	If the 'TIME_BASED_SUMM' = 1 and 'CI_BASED_SUMM_GL' = 3
888 --	then the summarization is done upto the assignment level for each time period
889 
890 --	If the 'TIME_BASED_SUMM' = 1 and 'CI_BASED_SUMM_GL' = 2
891 --	then the summarization is done upto the employee level for each time period
892 
893 --	If the 'TIME_BASED_SUMM' = 1 and 'CI_BASED_SUMM_GL' = 1
894 --	then the summarization is done upto the code combination level for each time period
895 
896 --	If the 'TIME_BASED_SUMM' = 2 and 'CI_BASED_SUMM_GL' = 3
897 --	then the summarization is done upto the assignment level for each GL period
898 
899 --	If the 'TIME_BASED_SUMM' = 2 and 'CI_BASED_SUMM_GL' = 2
900 --	then the summarization is done upto the employee level for each GL period
901 
902 --	If the 'TIME_BASED_SUMM' = 2 and 'CI_BASED_SUMM_GL' = 1
903 --	then the summarization is done upto the code combination level for each GL period
904 
905 --	##########################################################################
906 
907 /*****	Commented for Create and Update multi thread enh.
908 PROCEDURE create_gl_enc_sum_lines(p_payroll_id IN NUMBER,
909 			p_return_status	OUT NOCOPY  VARCHAR2
910 				) IS
911 
912 	CURSOR 	enc_control_cur IS
913    	SELECT 	enc_control_id,
914           	payroll_id,
915           	time_period_id
916    	FROM   	psp_enc_controls
917    	WHERE 	payroll_id = nvl(p_payroll_id, payroll_id)
918 	AND	(total_dr_amount IS NOT NULL OR total_cr_amount IS NOT NULL)
919    	AND	action_type IN ('N', 'Q', 'U') -- Included 'Q' for Quick Upd. Enh. 2143723.
920    	AND    	action_code = 'I'
921    	AND    	run_id = g_run_id
922    	AND	business_group_id = g_business_group_id
923 	AND	set_of_books_id = g_set_of_books_id
924         AND     (gl_phase is null or gl_phase = 'TieBack');    --- 2444657
925 
926    	CURSOR 	enc_sum_lines_p1_cur(p_enc_control_id	IN  NUMBER) IS
927    	SELECT
928 --		ptp.end_date eff_dt,  bug fix 1971612
929                 pel.encumbrance_date eff_dt,
930 		pel.dr_cr_flag,
931 		sum(pel.encumbrance_amount) sum_amt,
932 		pel.gl_project_flag,
933 		pel.person_id,
934 		pel.assignment_id,
935 --		pel.gl_code_combination_id gl_ccid  Commented out for Bug 3194807
936 --		sob.set_of_books_id,
937 / * Uncommented the decode statement for Bug 3194807 * /
938 		decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id) gl_ccid,
939 --		Introduced DFF columns for bug fix 2908859
940 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute_category, pos.attribute_category), NULL) attribute_category,
941 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute1, pos.attribute1), NULL) attribute1,
942 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute2, pos.attribute2), NULL) attribute2,
943 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute3, pos.attribute3), NULL) attribute3,
944 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute4, pos.attribute4), NULL) attribute4,
945 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute5, pos.attribute5), NULL) attribute5,
946 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute6, pos.attribute6), NULL) attribute6,
947 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute7, pos.attribute7), NULL) attribute7,
948 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute8, pos.attribute8), NULL) attribute8,
949 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute9, pos.attribute9), NULL) attribute9,
950 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute10, pos.attribute10), NULL) attribute10
951    	FROM		PSP_ENC_LINES  		PEL,
952 			PER_TIME_PERIODS	PTP,
953 --			,GL_SETS_OF_BOOKS SOB,
954 --			GL_CODE_COMBINATIONS GCC,
955 			PSP_ORGANIZATION_ACCOUNTS POS
956    	WHERE 		PEL.TIME_PERIOD_ID = PTP.TIME_PERIOD_ID
957 --	AND		PEL.ENCUMBRANCE_DATE BETWEEN PTP.START_DATE AND PTP.END_DATE
958 --         Commented out for bug fix 1971612
959 	AND		PEL.GL_PROJECT_FLAG = 'G'
960    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
961 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
962 --	AND		pel.gl_code_combination_id = gcc.code_combination_id
963 --   	AND		gcc.chart_of_accounts_id = sob.chart_of_accounts_id
964    	AND		pel.suspense_org_account_id = pos.organization_account_id(+)
965 	GROUP BY
966     --	ptp.end_date, -- for bug fix 1971612
967                         pel.encumbrance_date,
968 			pel.person_id,
969 			pel.assignment_id,
970 			pel.dr_cr_flag,
971 			pel.gl_project_flag,
972 --			pel.gl_code_combination_id; Commented out for Bug 3194807
973 --			sob.set_of_books_id,
974 			DECODE(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id),
975 --		Introduced DFF columns for bug fix 2908859
976 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute_category, pos.attribute_category), NULL),
977 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute1, pos.attribute1), NULL),
978 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute2, pos.attribute2), NULL),
979 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute3, pos.attribute3), NULL),
980 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute4, pos.attribute4), NULL),
981 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute5, pos.attribute5), NULL),
982 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute6, pos.attribute6), NULL),
983 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute7, pos.attribute7), NULL),
984 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute8, pos.attribute8), NULL),
985 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute9, pos.attribute9), NULL),
986 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute10, pos.attribute10), NULL);
987 / *	Commented the following Cursors as part of Enh. 2143723
988 	CURSOR 	enc_sum_lines_p2_cur(p_enc_control_id	IN  NUMBER) IS
989    	SELECT
990   ---	ptp.end_date eff_dt,   for bug fix 1971612
991                 pel.encumbrance_date eff_dt,
992 		pel.dr_cr_flag,
993 		sum(pel.encumbrance_amount) sum_amt,
994 		pel.gl_project_flag,
995 		pel.person_id,
996 		pel.gl_code_combination_id gl_ccid
997 --		sob.set_of_books_id,
998 --		decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id) gl_ccid
999    	FROM		PSP_ENC_LINES  		PEL,
1000 			PER_TIME_PERIODS	PTP
1001 --			,GL_SETS_OF_BOOKS SOB,
1002 --			GL_CODE_COMBINATIONS GCC,
1003 --			PSP_ORGANIZATION_ACCOUNTS POS
1004    	WHERE 		PEL.TIME_PERIOD_ID = PTP.TIME_PERIOD_ID
1005 --	AND		PEL.ENCUMBRANCE_DATE BETWEEN PTP.START_DATE AND PTP.END_DATE
1006 --         Commented out for bug fix 1971612
1007 	AND		PEL.GL_PROJECT_FLAG = 'G'
1008    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
1009 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
1010 --   	AND 		pel.gl_code_combination_id = gcc.code_combination_id
1011 --   	AND		gcc.chart_of_accounts_id = sob.chart_of_accounts_id
1012 --   	AND		pel.suspense_org_account_id = pos.organization_account_id(+)
1013 	GROUP BY
1014       --	ptp.end_date,   for bug fix 1971612
1015                         pel.encumbrance_date,
1016 			pel.person_id,
1017 			pel.dr_cr_flag,
1018 			pel.gl_project_flag,
1019 			pel.gl_code_combination_id;
1020 --			,sob.set_of_books_id,
1021 --			decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id);
1022 
1023 	CURSOR 	enc_sum_lines_p3_cur(p_enc_control_id	IN  NUMBER) IS
1024    	SELECT
1025 --	ptp.end_date eff_dt,    for bug fix 1971612
1026                 pel.encumbrance_date eff_dt,
1027 		pel.dr_cr_flag,
1028 		sum(pel.encumbrance_amount) sum_amt,
1029 		pel.gl_project_flag,
1030 		pel.gl_code_combination_id gl_ccid
1031 --		sob.set_of_books_id,
1032 --		decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id) gl_ccid
1033    	FROM		PSP_ENC_LINES  		PEL,
1034 			PER_TIME_PERIODS	PTP
1035 --			,GL_SETS_OF_BOOKS SOB,
1036 --			GL_CODE_COMBINATIONS GCC,
1037 --			PSP_ORGANIZATION_ACCOUNTS POS
1038    	WHERE 		PEL.TIME_PERIOD_ID = PTP.TIME_PERIOD_ID
1039 --	AND		PEL.ENCUMBRANCE_DATE BETWEEN PTP.START_DATE AND PTP.END_DATE
1040 --         Commented out for bug fix 1971612
1041 	AND		PEL.GL_PROJECT_FLAG = 'G'
1042    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
1043 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
1044 --   	AND		pel.suspense_org_account_id = pos.organization_account_id(+)
1045 	GROUP BY
1046 --	ptp.end_date,   for bug fix 1971612
1047                         pel.encumbrance_date,
1048 			pel.dr_cr_flag,
1049 			pel.gl_project_flag,
1050 			pel.gl_code_combination_id;
1051 --			,sob.set_of_books_id,
1052 --			decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id);
1053 
1054 End of Enh. fix 2143723 *** /
1055 
1056 / ******************************************************************************
1057 
1058 
1059 The Summarize by Gl period option is obsoleted
1060 per bug fix 1971612 /bug 1831493
1061 
1062 	CURSOR 	enc_sum_lines_g1_cur(p_enc_control_id	IN  NUMBER) IS
1063    	SELECT 	glp.end_date eff_dt,
1064 		pel.dr_cr_flag,
1065 		sum(pel.encumbrance_amount) sum_amt,
1066 		pel.gl_project_flag,
1067 		pel.person_id,
1068 		pel.assignment_id,
1069 		pel.gl_code_combination_id gl_ccid
1070 --		,sob.set_of_books_id,
1071 --		decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id) gl_ccid
1072    	FROM		PSP_ENC_LINES  		PEL,
1073 			GL_PERIODS	GLP,
1074 			GL_SETS_OF_BOOKS SOB,
1075 --			,GL_CODE_COMBINATIONS GCC,
1076 --			PSP_ORGANIZATION_ACCOUNTS POS
1077    	WHERE		sob.accounted_period_type = glp.period_type
1078 	AND		sob.set_of_books_id = g_set_of_books_id
1079    	AND 		PEL.GL_PROJECT_FLAG = 'G'
1080    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
1081 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
1082 	AND		PEL.ENCUMBRANCE_DATE BETWEEN GLP.START_DATE AND GLP.END_DATE
1083    	AND 		pel.gl_code_combination_id = gcc.code_combination_id
1084 --   	AND		gcc.chart_of_accounts_id = sob.chart_of_accounts_id
1085 --	AND		pel.suspense_org_account_id = pos.organization_account_id(+)
1086 	GROUP BY	sob.set_of_books_id,
1087 			glp.end_date,
1088 			pel.person_id,
1089 			pel.assignment_id,
1090 			pel.dr_cr_flag,
1091 			pel.gl_project_flag,
1092 			pel.gl_code_combination_id;
1093 --			decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id);
1094 
1095 	CURSOR 	enc_sum_lines_g2_cur(p_enc_control_id	IN  NUMBER) IS
1096    	SELECT 	sob.set_of_books_id,
1097 		glp.end_date eff_dt,
1098 		pel.dr_cr_flag,
1099 		sum(pel.encumbrance_amount) sum_amt,
1100 		pel.gl_project_flag,
1101 		pel.person_id,
1102 		pel.gl_code_combination_id gl_ccid
1103 --		,decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id) gl_ccid
1104    	FROM		PSP_ENC_LINES  		PEL,
1105 			GL_PERIODS	GLP,
1106 			GL_SETS_OF_BOOKS SOB
1107 --			,GL_CODE_COMBINATIONS GCC,
1108 --			PSP_ORGANIZATION_ACCOUNTS POS
1109 	WHERE		sob.set_of_books_id = g_set_of_books_id
1110    	AND		sob.accounted_period_type = glp.period_type
1111    	AND 		PEL.GL_PROJECT_FLAG = 'G'
1112    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
1113 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
1114 	AND		PEL.ENCUMBRANCE_DATE BETWEEN GLP.START_DATE AND GLP.END_DATE
1115 --	AND		pel.suspense_org_account_id = pos.organization_account_id(+)
1116 --   	AND 		pel.gl_code_combination_id = gcc.code_combination_id
1117 --   	AND		gcc.chart_of_accounts_id = sob.chart_of_accounts_id
1118 	GROUP BY	sob.set_of_books_id,
1119 			glp.end_date,
1120 			pel.person_id,
1121 			pel.dr_cr_flag,
1122 			pel.gl_project_flag,
1123 			pel.gl_code_combination_id;
1124 --			decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id);
1125 
1126 	CURSOR 	enc_sum_lines_g3_cur(p_enc_control_id	IN  NUMBER) IS
1127    	SELECT 	sob.set_of_books_id,
1128 		glp.end_date eff_dt,
1129 		pel.dr_cr_flag,
1130 		sum(pel.encumbrance_amount) sum_amt,
1131 		pel.gl_project_flag,
1132 		pel.gl_code_combination_id gl_ccid
1133 --		,decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id) gl_ccid
1134    	FROM		PSP_ENC_LINES  		PEL,
1135 			GL_PERIODS	GLP,
1136 			GL_SETS_OF_BOOKS SOB
1137 --			,GL_CODE_COMBINATIONS GCC,
1138 --			PSP_ORGANIZATION_ACCOUNTS POS
1139 	WHERE		sob.set_of_books_id = g_set_of_books_id
1140    	AND		sob.accounted_period_type = glp.period_type
1141    	AND 		PEL.GL_PROJECT_FLAG = 'G'
1142    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
1143 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
1144 	AND		PEL.ENCUMBRANCE_DATE BETWEEN GLP.START_DATE AND GLP.END_DATE
1145 --   	AND 		pel.gl_code_combination_id = gcc.code_combination_id
1146 --   	AND		gcc.chart_of_accounts_id = sob.chart_of_accounts_id
1147 --	AND		pel.suspense_org_account_id = pos.organization_account_id(+)
1148 	GROUP BY	sob.set_of_books_id,
1149 			glp.end_date,
1150 			pel.dr_cr_flag,
1151 			pel.gl_project_flag,
1152 			pel.gl_code_combination_id;
1153 --			,decode(suspense_org_account_id, null, pel.gl_code_combination_id, pos.gl_code_combination_id);
1154 
1155 	l_time_para_value		VARCHAR2(1);
1156 	l_gl_para_value			VARCHAR2(1);
1157 	commented above variables as part of enh. Quick Upd. Enc., bug 2143723
1158 
1159 ************************************************************************************** /
1160 
1161 	enc_sum_lines_p1_rec		enc_sum_lines_p1_cur%ROWTYPE;
1162 
1163 / ***********************************************************************************
1164 	Commented cursors p2_cur and p3_cur as part of Enh. 2143723
1165 
1166 	enc_sum_lines_p2_rec		enc_sum_lines_p2_cur%ROWTYPE;
1167 	enc_sum_lines_p3_rec		enc_sum_lines_p3_cur%ROWTYPE;
1168 	enc_sum_lines_g1_rec		enc_sum_lines_g1_cur%ROWTYPE;
1169 	enc_sum_lines_g2_rec		enc_sum_lines_g2_cur%ROWTYPE;
1170 	enc_sum_lines_g3_rec		enc_sum_lines_g3_cur%ROWTYPE;
1171 
1172 
1173  Commented out as part of bug fix 1971612/1831493 --gl period option obsolete
1174 *************************************************************************************** /
1175 
1176 	l_bg_id				NUMBER(15) := g_business_group_id;
1177 	l_set_of_books_id		NUMBER(15);
1178 	l_enc_summary_line_id		NUMBER(10);
1179 	l_return_status			VARCHAR2(10);
1180 	enc_control_rec			enc_control_cur%ROWTYPE;
1181    	l_error			VARCHAR2(100);
1182 	l_product		VARCHAR2(3);
1183 	l_gl_ccid	NUMBER(15);
1184 BEGIN
1185  --insert_into_psp_stout( 'create gl_enc_sum_lines' );
1186 / *	Commenting out the following code as Enc. Sum. and Tr. will not be based on Setup options
1187 	but based on Person, Assignment and CI for each time period for Enh. 2143723
1188 	BEGIN
1189  	SELECT 	parameter_value
1190  	INTO	l_time_para_value
1191  	FROM	psp_enc_setup_options
1192  	WHERE	setup_parameter = 'TIME_BASED_SUMM'
1193 	AND	business_group_id = l_bg_id;
1194 	EXCEPTION
1195 		WHEN NO_DATA_FOUND THEN
1196 		l_error := 'TIME_BASED_SUMM';
1197 		l_product := 'PSP';
1198 		fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
1199 		fnd_message.set_token('ERROR',l_error);
1200 		fnd_message.set_token('PRODUCT',l_product);
1201 		fnd_msg_pub.add;
1202 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1203 	END;
1204 
1205   	BEGIN
1206 	SELECT 	parameter_value
1207 	INTO	l_gl_para_value
1208 	FROM	psp_enc_setup_options
1209 	WHERE	setup_parameter = 'CI_BASED_SUMM_GL'
1210 	AND	business_group_id = l_bg_id;
1211 	EXCEPTION
1212 		WHEN NO_DATA_FOUND THEN
1213 		l_error := 'CI_BASED_SUMM_GL';
1214 		l_product := 'PSP';
1215 		fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
1216 		fnd_message.set_token('ERROR',l_error);
1217 		fnd_message.set_token('PRODUCT',l_product);
1218 		fnd_msg_pub.add;
1219 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1220 	END;
1221 
1222      	IF	l_time_para_value = '1' and l_gl_para_value = '3' THEN
1223 
1224 End of Enh. fix 2143723	* /
1225 
1226 	OPEN enc_control_cur;
1227   	LOOP
1228      	    	FETCH enc_control_cur INTO enc_control_rec;
1229    		IF enc_control_cur%NOTFOUND THEN
1230      		CLOSE enc_control_cur;
1231      		EXIT;
1232    		END IF;
1233 
1234 		OPEN enc_sum_lines_p1_cur(enc_control_rec.enc_control_id);
1235 		LOOP
1236 			FETCH enc_sum_lines_p1_cur INTO enc_sum_lines_p1_rec;
1237 			IF enc_sum_lines_p1_cur%ROWCOUNT = 0 THEN
1238 			  CLOSE enc_sum_lines_p1_cur;
1239 			  EXIT;
1240     			ELSIF enc_sum_lines_p1_cur%NOTFOUND THEN
1241                 	   update psp_enc_controls
1242                    	      set gl_phase = 'Summarize' ---NULL ... for 2444657
1243                  	    where enc_control_id = enc_control_rec.enc_control_id;
1244        			CLOSE enc_sum_lines_p1_cur;
1245        			EXIT;
1246      			END IF;
1247 
1248 			insert_into_enc_sum_lines(
1249 							l_enc_summary_line_id,
1250 							l_bg_id,
1251 							enc_control_rec.enc_control_id,
1252 							enc_control_rec.time_period_id,
1253 							enc_sum_lines_p1_rec.person_id,
1254 							enc_sum_lines_p1_rec.assignment_id,
1255                 					enc_sum_lines_p1_rec.eff_dt,
1256 --							enc_sum_lines_p1_rec.set_of_books_id,
1257 							g_set_of_books_id,
1258 							enc_sum_lines_p1_rec.gl_ccid,
1259 							NULL,
1260  							NULL,
1261  							NULL,
1262  							NULL,
1263  							NULL,
1264  							enc_sum_lines_p1_rec.sum_amt,
1265  							enc_sum_lines_p1_rec.dr_cr_flag,
1266 							'N',
1267 							enc_control_rec.payroll_id,
1268  							NULL,
1269 							enc_sum_lines_p1_rec.gl_project_flag,
1270 							enc_sum_lines_p1_rec.attribute_category,	-- Introduced DFF columns for bug fix 2908859
1271 							enc_sum_lines_p1_rec.attribute1,
1272 							enc_sum_lines_p1_rec.attribute2,
1273 							enc_sum_lines_p1_rec.attribute3,
1274 							enc_sum_lines_p1_rec.attribute4,
1275 							enc_sum_lines_p1_rec.attribute5,
1276 							enc_sum_lines_p1_rec.attribute6,
1277 							enc_sum_lines_p1_rec.attribute7,
1278 							enc_sum_lines_p1_rec.attribute8,
1279 							enc_sum_lines_p1_rec.attribute9,
1280 							enc_sum_lines_p1_rec.attribute10,
1281 							l_return_status);
1282 
1283 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1284 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1285 				END IF;
1286 
1287 			IF (g_dff_grouping_option = 'N') THEN	-- Introduced for bug fix 2908859
1288 				UPDATE 	psp_enc_lines
1289          			SET 	enc_summary_line_id = l_enc_summary_line_id
1290          			WHERE 	enc_control_id = enc_control_rec.enc_control_id
1291          			AND	payroll_id = enc_control_rec.payroll_id
1292 				AND	time_period_id = enc_control_rec.time_period_id
1293          			AND	person_id = enc_sum_lines_p1_rec.person_id
1294          			AND	assignment_id = enc_sum_lines_p1_rec.assignment_id
1295          			AND	dr_cr_flag = enc_sum_lines_p1_rec.dr_cr_flag
1296          			AND	gl_project_flag = enc_sum_lines_p1_rec.gl_project_flag
1297                         	AND     trunc(encumbrance_date) = trunc(enc_sum_lines_p1_rec.eff_dt)  --- added for 3462452
1298 --	Enhanced the following check to accomodate suspense postings done in this process for bug fix 3194807.
1299 --                        ANd gl_code_combination_id =enc_sum_lines_p1_rec.gl_ccid;
1300 				AND	(	(suspense_org_account_id IS NOT NULL
1301 						AND	suspense_reason_code like 'ES:%'
1302 						AND	EXISTS	(SELECT	1	FROM psp_organization_accounts poa
1303 								WHERE	poa.organization_account_id = suspense_org_account_id
1304 								AND	poa.gl_code_combination_id = enc_sum_lines_p1_rec.gl_ccid))
1305 					OR	gl_code_combination_id = enc_sum_lines_p1_rec.gl_ccid);
1306 --	Introduced ELSE portion for bug fix 2908859
1307 			ELSE
1308 				UPDATE 	psp_enc_lines
1309          			SET 	enc_summary_line_id = l_enc_summary_line_id
1310          			WHERE 	enc_control_id = enc_control_rec.enc_control_id
1311          			AND	payroll_id = enc_control_rec.payroll_id
1312 				AND	time_period_id = enc_control_rec.time_period_id
1313          			AND	person_id = enc_sum_lines_p1_rec.person_id
1314          			AND	assignment_id = enc_sum_lines_p1_rec.assignment_id
1315          			AND	dr_cr_flag = enc_sum_lines_p1_rec.dr_cr_flag
1316          			AND	gl_project_flag = enc_sum_lines_p1_rec.gl_project_flag
1317                         	AND     trunc(encumbrance_date) = trunc(enc_sum_lines_p1_rec.eff_dt)  --- added for 3462452
1318 				AND	(	(suspense_org_account_id IS NOT NULL
1319 						AND	suspense_reason_code like 'ES:%'
1320 						AND	EXISTS	(SELECT	1	FROM psp_organization_accounts poa
1321 								WHERE	poa.organization_account_id = suspense_org_account_id
1322 								AND	poa.gl_code_combination_id = enc_sum_lines_p1_rec.gl_ccid
1323 								AND	NVL(poa.attribute_category, 'NULL') =
1324 									NVL(enc_sum_lines_p1_rec.attribute_category, 'NULL')
1325 								AND	NVL(poa.attribute1, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute1, 'NULL')
1326 								AND	NVL(poa.attribute2, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute2, 'NULL')
1327 								AND	NVL(poa.attribute3, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute3, 'NULL')
1328 								AND	NVL(poa.attribute4, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute4, 'NULL')
1329 								AND	NVL(poa.attribute5, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute5, 'NULL')
1330 								AND	NVL(poa.attribute6, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute6, 'NULL')
1331 								AND	NVL(poa.attribute7, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute7, 'NULL')
1332 								AND	NVL(poa.attribute8, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute8, 'NULL')
1333 								AND	NVL(poa.attribute9, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute9, 'NULL')
1334 								AND	NVL(poa.attribute10, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute10, 'NULL')))
1335 					OR (	gl_code_combination_id = enc_sum_lines_p1_rec.gl_ccid
1336 						AND	NVL(attribute_category, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute_category, 'NULL')
1337 						AND	NVL(attribute1, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute1, 'NULL')
1338 						AND	NVL(attribute2, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute2, 'NULL')
1339 						AND	NVL(attribute3, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute3, 'NULL')
1340 						AND	NVL(attribute4, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute4, 'NULL')
1341 						AND	NVL(attribute5, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute5, 'NULL')
1342 						AND	NVL(attribute6, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute6, 'NULL')
1343 						AND	NVL(attribute7, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute7, 'NULL')
1344 						AND	NVL(attribute8, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute8, 'NULL')
1345 						AND	NVL(attribute9, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute9, 'NULL')
1346 						AND	NVL(attribute10, 'NULL') = NVL(enc_sum_lines_p1_rec.attribute10, 'NULL')));
1347 --	Introduced ELSE portion for bug fix 2908859
1348 			END IF;
1349 / *  added the check on gl_code_combination_id since group by clause has it * /
1350 
1351 		END LOOP;
1352 
1353 	END LOOP;
1354 
1355 / *	Commenting the following as Enc Sum. and Tr. options is now obsolete for Enh. 2143723
1356 
1357 	ELSIF	l_time_para_value = '1' and l_gl_para_value = '2' THEN
1358 	OPEN enc_control_cur;
1359   	LOOP
1360     	FETCH enc_control_cur INTO enc_control_rec;
1361    		IF enc_control_cur%NOTFOUND THEN
1362      		CLOSE enc_control_cur;
1363      		EXIT;
1364    		END IF;
1365 
1366 		OPEN enc_sum_lines_p2_cur(enc_control_rec.enc_control_id);
1367 		LOOP
1368      			FETCH enc_sum_lines_p2_cur INTO enc_sum_lines_p2_rec;
1369 			IF enc_sum_lines_p2_cur%ROWCOUNT = 0 THEN
1370 			  CLOSE enc_sum_lines_p2_cur;
1371 			  EXIT;
1372     			ELSIF enc_sum_lines_p2_cur%NOTFOUND THEN
1373                 	   update psp_enc_controls
1374                    	      set gl_phase = 'Summarize' ---NULL  for 2444657
1375                  	    where enc_control_id = enc_control_rec.enc_control_id;
1376        			CLOSE enc_sum_lines_p2_cur;
1377        			EXIT;
1378      			END IF;
1379 					insert_into_enc_sum_lines(
1380 							l_enc_summary_line_id,
1381 							l_bg_id,
1382 							enc_control_rec.enc_control_id,
1383 							enc_control_rec.time_period_id,
1384 							enc_sum_lines_p2_rec.person_id,
1385 							NULL,
1386                 					enc_sum_lines_p2_rec.eff_dt,
1387 --							enc_sum_lines_p2_rec.set_of_books_id,
1388 							g_set_of_books_id,
1389 							enc_sum_lines_p2_rec.gl_ccid,
1390 							NULL,
1391  							NULL,
1392  							NULL,
1393  							NULL,
1394  							NULL,
1395  							enc_sum_lines_p2_rec.sum_amt,
1396  							enc_sum_lines_p2_rec.dr_cr_flag,
1397 							'N',
1398 							enc_control_rec.payroll_id,
1399  							NULL,
1400 							enc_sum_lines_p2_rec.gl_project_flag,
1401 							l_return_status);
1402 
1403 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1404 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1405 				END IF;
1406 
1407 			UPDATE 	psp_enc_lines
1408          		SET 	enc_summary_line_id = l_enc_summary_line_id
1409          		WHERE 	enc_control_id = enc_control_rec.enc_control_id
1410          		AND	payroll_id = enc_control_rec.payroll_id
1411 			ANd	time_period_id = enc_control_rec.time_period_id
1412 --                       added check on gl_ccid - subha 22 Mar
1413 			AND	gl_code_combination_id = enc_sum_lines_p2_rec.gl_ccid
1414          		AND	person_id = enc_sum_lines_p2_rec.person_id
1415          		AND	dr_cr_flag = enc_sum_lines_p2_rec.dr_cr_flag
1416          		AND	gl_project_flag = enc_sum_lines_p2_rec.gl_project_flag;
1417 
1418      		END LOOP;
1419 
1420 	END LOOP;
1421 	ELSIF	l_time_para_value = '1' and l_gl_para_value = '1' THEN
1422 	OPEN enc_control_cur;
1423   	LOOP
1424      	    	FETCH enc_control_cur INTO enc_control_rec;
1425 
1426    		IF enc_control_cur%NOTFOUND THEN
1427      		CLOSE enc_control_cur;
1428      		EXIT;
1429    		END IF;
1430 
1431 		OPEN enc_sum_lines_p3_cur(enc_control_rec.enc_control_id);
1432 		LOOP
1433 			FETCH enc_sum_lines_p3_cur INTO enc_sum_lines_p3_rec;
1434 			IF enc_sum_lines_p3_cur%ROWCOUNT = 0 THEN
1435 			  CLOSE enc_sum_lines_p3_cur;
1436 			  EXIT;
1437     			ELSIF enc_sum_lines_p3_cur%NOTFOUND THEN
1438                 	   update psp_enc_controls
1439                    	      set gl_phase = 'Summarize' ---NULL commented for 2444657
1440                  	    where enc_control_id = enc_control_rec.enc_control_id;
1441        			CLOSE enc_sum_lines_p3_cur;
1442        			EXIT;
1443      			END IF;
1444 				insert_into_enc_sum_lines(
1445 							l_enc_summary_line_id,
1446 							l_bg_id,
1447 							enc_control_rec.enc_control_id,
1448 							enc_control_rec.time_period_id,
1449 							NULL,
1450 							NULL,
1451 							enc_sum_lines_p3_rec.eff_dt,
1452 --							enc_sum_lines_p3_rec.set_of_books_id,
1453 							g_set_of_books_id,
1454 							enc_sum_lines_p3_rec.gl_ccid,
1455 							NULL,
1456  							NULL,
1457  							NULL,
1458  							NULL,
1459  							NULL,
1460  							enc_sum_lines_p3_rec.sum_amt,
1461  							enc_sum_lines_p3_rec.dr_cr_flag,
1462 							'N',
1463 							enc_control_rec.payroll_id,
1464  							NULL,
1465 							enc_sum_lines_p3_rec.gl_project_flag,
1466 							l_return_status);
1467 
1468 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1469 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1470 				END IF;
1471 
1472 			UPDATE 	psp_enc_lines
1473          		SET 	enc_summary_line_id = l_enc_summary_line_id
1474          		WHERE 	enc_control_id = enc_control_rec.enc_control_id
1475 			AND	time_period_id = enc_control_rec.time_period_id
1476 			AND	payroll_id = enc_control_rec.payroll_id
1477          		AND	dr_cr_flag = enc_sum_lines_p3_rec.dr_cr_flag
1478          		AND	gl_code_combination_id = enc_sum_lines_p3_rec.gl_ccid
1479          		AND	gl_project_flag = enc_sum_lines_p3_rec.gl_project_flag;
1480 
1481      		END LOOP;
1482 
1483 	END LOOP;
1484 
1485 / *
1486 
1487  This code is obsolete and the summarize by gl_period option is no longer supported  refer bug 1831493
1488 
1489 
1490 	ELSIF	l_time_para_value = '2' and l_gl_para_value = '3' THEN
1491 	OPEN enc_control_cur;
1492   	LOOP
1493      	    	FETCH enc_control_cur INTO enc_control_rec;
1494    		IF enc_control_cur%NOTFOUND THEN
1495      		CLOSE enc_control_cur;
1496      		EXIT;
1497    		END IF;
1498 
1499 		OPEN enc_sum_lines_g1_cur(enc_control_rec.enc_control_id);
1500 		LOOP
1501 			FETCH enc_sum_lines_g1_cur INTO enc_sum_lines_g1_rec;
1502 			IF enc_sum_lines_g1_cur%ROWCOUNT = 0 THEN
1503 			  CLOSE enc_sum_lines_g1_cur;
1504 			  EXIT;
1505     			ELSIF enc_sum_lines_g1_cur%NOTFOUND THEN
1506                 	   update psp_enc_controls
1507                    	      set gl_phase = 'Summarize' --- replaced NULL for 2444657
1508                  	    where enc_control_id = enc_control_rec.enc_control_id;
1509        			CLOSE enc_sum_lines_g1_cur;
1510        			EXIT;
1511      			END IF;
1512 			insert_into_enc_sum_lines(
1513 							l_enc_summary_line_id,
1514 							l_bg_id,
1515 							enc_control_rec.enc_control_id,
1516 							enc_control_rec.time_period_id,
1517 							enc_sum_lines_g1_rec.person_id,
1518 							enc_sum_lines_g1_rec.assignment_id,
1519                 					enc_sum_lines_g1_rec.eff_dt,
1520 							g_set_of_books_id,
1521 							enc_sum_lines_g1_rec.gl_ccid,
1522 							NULL,
1523  							NULL,
1524  							NULL,
1525  							NULL,
1526  							NULL,
1527  							enc_sum_lines_g1_rec.sum_amt,
1528  							enc_sum_lines_g1_rec.dr_cr_flag,
1529 							'N',
1530 							enc_control_rec.payroll_id,
1531  							NULL,
1532 							enc_sum_lines_g1_rec.gl_project_flag,
1533 							l_return_status);
1534 
1535 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1536 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1537 				END IF;
1538 
1539 			UPDATE 	psp_enc_lines
1540          		SET 	enc_summary_line_id = l_enc_summary_line_id
1541          		WHERE 	enc_control_id = enc_control_rec.enc_control_id
1542 			AND	time_period_id = enc_control_rec.time_period_id
1543 			AND	payroll_id = enc_control_rec.payroll_id
1544          		AND	person_id = enc_sum_lines_g1_rec.person_id
1545          		AND	assignment_id = enc_sum_lines_g1_rec.assignment_id
1546          		AND	dr_cr_flag = enc_sum_lines_g1_rec.dr_cr_flag
1547          		AND	gl_code_combination_id = enc_sum_lines_g1_rec.gl_ccid
1548          		AND	gl_project_flag = enc_sum_lines_g1_rec.gl_project_flag;
1549 
1550 		END LOOP;
1551 
1552 	END LOOP;
1553 	ELSIF	l_time_para_value = '2' and l_gl_para_value = '2' THEN
1554 	OPEN enc_control_cur;
1555   	LOOP
1556      	    	FETCH enc_control_cur INTO enc_control_rec;
1557    		IF enc_control_cur%NOTFOUND THEN
1558      		CLOSE enc_control_cur;
1559      		EXIT;
1560    		END IF;
1561 
1562 		OPEN enc_sum_lines_g2_cur(enc_control_rec.enc_control_id);
1563 		LOOP
1564      			FETCH enc_sum_lines_g2_cur INTO enc_sum_lines_g2_rec;
1565 			IF enc_sum_lines_g2_cur%ROWCOUNT = 0 THEN
1566 			  CLOSE enc_sum_lines_g2_cur;
1567 			  EXIT;
1568     			ELSIF enc_sum_lines_g2_cur%NOTFOUND THEN
1569                 	   update psp_enc_controls
1570                    	      set gl_phase = 'Summarize'  ---replaced NULL  for 2444657
1571                  	    where enc_control_id = enc_control_rec.enc_control_id;
1572        			CLOSE enc_sum_lines_g2_cur;
1573        			EXIT;
1574      			END IF;
1575 
1576 			insert_into_enc_sum_lines(
1577 							l_enc_summary_line_id,
1578 							l_bg_id,
1579 							enc_control_rec.enc_control_id,
1580 							enc_control_rec.time_period_id,
1581 							enc_sum_lines_g2_rec.person_id,
1582 							NULL,
1583                 					enc_sum_lines_g2_rec.eff_dt,
1584 							enc_sum_lines_g2_rec.set_of_books_id,
1585 							enc_sum_lines_g2_rec.gl_ccid,
1586 							NULL,
1587  							NULL,
1588  							NULL,
1589  							NULL,
1590  							NULL,
1591  							enc_sum_lines_g2_rec.sum_amt,
1592  							enc_sum_lines_g2_rec.dr_cr_flag,
1593 							'N',
1594 							enc_control_rec.payroll_id,
1595  							NULL,
1596 							enc_sum_lines_g2_rec.gl_project_flag,
1597 							l_return_status);
1598 
1599 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1600 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1601 				END IF;
1602 
1603 			UPDATE 	psp_enc_lines
1604          		SET 	enc_summary_line_id = l_enc_summary_line_id
1605          		WHERE 	enc_control_id = enc_control_rec.enc_control_id
1606          		AND	payroll_id = enc_control_rec.payroll_id
1607 			AND	time_period_id = enc_control_rec.time_period_id
1608          		AND	person_id = enc_sum_lines_g2_rec.person_id
1609          		AND	dr_cr_flag = enc_sum_lines_g2_rec.dr_cr_flag
1610          		AND	gl_code_combination_id = enc_sum_lines_g2_rec.gl_ccid
1611          		AND	gl_project_flag = enc_sum_lines_g2_rec.gl_project_flag;
1612 
1613    		END LOOP;
1614 
1615 	END LOOP;
1616 	ELSIF	l_time_para_value = '2' and l_gl_para_value = '1' THEN
1617 	OPEN enc_control_cur;
1618   	LOOP
1619      	    	FETCH enc_control_cur INTO enc_control_rec;
1620    		IF enc_control_cur%NOTFOUND THEN
1621      		CLOSE enc_control_cur;
1622      		EXIT;
1623    		END IF;
1624 
1625 		OPEN enc_sum_lines_g3_cur(enc_control_rec.enc_control_id);
1626 		LOOP
1627      			FETCH enc_sum_lines_g3_cur INTO enc_sum_lines_g3_rec;
1628 			IF enc_sum_lines_g3_cur%ROWCOUNT = 0 THEN
1629 			  CLOSE enc_sum_lines_g3_cur;
1630 			  EXIT;
1631     			ELSIF enc_sum_lines_g3_cur%NOTFOUND THEN
1632                 	   update psp_enc_controls
1633                    	      set gl_phase =  'Summarize' -- replaced NULL for 2444657
1634                  	    where enc_control_id = enc_control_rec.enc_control_id;
1635        			CLOSE enc_sum_lines_g3_cur;
1636        			EXIT;
1637      			END IF;
1638 
1639         		insert_into_enc_sum_lines(
1640 							l_enc_summary_line_id,
1641 							l_bg_id,
1642 							enc_control_rec.enc_control_id,
1643 							enc_control_rec.time_period_id,
1644 							NULL,
1645 							NULL,
1646 							enc_sum_lines_g3_rec.eff_dt,
1647 							enc_sum_lines_g3_rec.set_of_books_id,
1648 							enc_sum_lines_g3_rec.gl_ccid,
1649 							NULL,
1650  							NULL,
1651  							NULL,
1652  							NULL,
1653  							NULL,
1654  							enc_sum_lines_g3_rec.sum_amt,
1655  							enc_sum_lines_g3_rec.dr_cr_flag,
1656 							'N',
1657 							enc_control_rec.payroll_id,
1658  							NULL,
1659 							enc_sum_lines_g3_rec.gl_project_flag,
1660 							l_return_status);
1661 
1662 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1663 					RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1664 				END IF;
1665 
1666 			UPDATE 	psp_enc_lines
1667          		SET 	enc_summary_line_id = l_enc_summary_line_id
1668          		WHERE 	enc_control_id = enc_control_rec.enc_control_id
1669          		AND	payroll_id = enc_control_rec.payroll_id
1670 			AND	time_period_id = enc_control_rec.time_period_id
1671          		AND	dr_cr_flag = enc_sum_lines_g3_rec.dr_cr_flag
1672          	AND	gl_code_combination_id = enc_sum_lines_g3_rec.gl_ccid
1673          		AND	gl_project_flag = enc_sum_lines_g3_rec.gl_project_flag;
1674 
1675      		END LOOP;
1676 
1677      	END LOOP;
1678 
1679 	END IF; -- Commented this END IF as part of Enh. 2143723
1680 *************************************************************************************************** /
1681 
1682 	p_return_status	:= fnd_api.g_ret_sts_success;
1683 
1684 EXCEPTION
1685 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1686      		g_error_api_path := 'CREATE_GL_ENC_SUM_LINES:'||g_error_api_path;
1687      		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','ENC_SUM_TRANS');
1688       		p_return_status := fnd_api.g_ret_sts_unexp_error;
1689 	WHEN OTHERS THEN
1690      		g_error_api_path := 'CREATE_GL_ENC_SUM_LINES:'||g_error_api_path;
1691      		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','CREATE_GL_ENC_SUM_LINES');
1692      		p_return_status := fnd_api.g_ret_sts_unexp_error;
1693 END;
1694 	End of comment for Create and Update enh.	*****/
1695 
1696 --	##########################################################################
1697 --	This procedure inserts records into psp_enc_summary_lines
1698 --	##########################################################################
1699 
1700 PROCEDURE insert_into_enc_sum_lines(
1701 				p_enc_summary_line_id	OUT NOCOPY NUMBER,
1702 				p_business_group_id	IN  NUMBER,
1703 				p_enc_control_id	IN  NUMBER,
1704 				p_time_period_id	IN  NUMBER,
1705 				p_person_id		IN  NUMBER,
1706 				p_assignment_id		IN  NUMBER,
1707 				p_effective_date	IN  DATE,
1708 				p_set_of_books_id	IN  NUMBER,
1709 				p_gl_code_combination_id IN  NUMBER,
1710 				p_project_id		IN  NUMBER,
1711 				p_expenditure_organization_id IN  NUMBER,
1712 				p_expenditure_type	IN  VARCHAR2,
1713 				p_task_id		IN  NUMBER,
1714 				p_award_id		IN  NUMBER,
1715 				p_summary_amount	IN  NUMBER,
1716 				p_dr_cr_flag		IN  VARCHAR2,
1717 				p_status_code		IN  VARCHAR2,
1718 				p_payroll_id		IN  NUMBER,
1719 				p_gl_period_id		IN  NUMBER,
1720 				p_gl_project_flag	IN  VARCHAR2,
1721 				p_attribute_category	IN	VARCHAR2,	-- Introduced DFF columns for bug fix 2908859
1722 				p_attribute1		IN	VARCHAR2,
1723 				p_attribute2		IN	VARCHAR2,
1724 				p_attribute3		IN	VARCHAR2,
1725 				p_attribute4		IN	VARCHAR2,
1726 				p_attribute5		IN	VARCHAR2,
1727 				p_attribute6		IN	VARCHAR2,
1728 				p_attribute7		IN	VARCHAR2,
1729 				p_attribute8		IN	VARCHAR2,
1730 				p_attribute9		IN	VARCHAR2,
1731 				p_attribute10		IN	VARCHAR2,
1732 				p_return_status		OUT NOCOPY  VARCHAR2
1733 				) IS
1734 BEGIN
1735 	SELECT PSP_ENC_SUMMARY_LINES_S.NEXTVAL
1736     	INTO P_ENC_SUMMARY_LINE_ID
1737     	FROM DUAL;
1738     		INSERT INTO PSP_ENC_SUMMARY_LINES(
1739 						ENC_SUMMARY_LINE_ID,
1740 						BUSINESS_GROUP_ID,
1741 						ENC_CONTROL_ID,
1742 						TIME_PERIOD_ID,
1743 						PERSON_ID,
1744 						ASSIGNMENT_ID,
1745 						EFFECTIVE_DATE,
1746 						SET_OF_BOOKS_ID,
1747 						GL_CODE_COMBINATION_ID,
1748 						PROJECT_ID,
1749 						EXPENDITURE_ORGANIZATION_ID,
1750 						EXPENDITURE_TYPE,
1751 						TASK_ID,
1752 						AWARD_ID,
1753 						SUMMARY_AMOUNT,
1754 						DR_CR_FLAG,
1755 						STATUS_CODE,
1756 						PAYROLL_ID,
1757 						GL_PERIOD_ID,
1758 						GL_PROJECT_FLAG,
1759 						ATTRIBUTE_CATEGORY,		-- Introduced DFF columns for bug fix 2908859
1760 						ATTRIBUTE1,
1761 						ATTRIBUTE2,
1762 						ATTRIBUTE3,
1763 						ATTRIBUTE4,
1764 						ATTRIBUTE5,
1765 						ATTRIBUTE6,
1766 						ATTRIBUTE7,
1767 						ATTRIBUTE8,
1768 						ATTRIBUTE9,
1769 						ATTRIBUTE10,
1770 						LAST_UPDATE_DATE,
1771 						LAST_UPDATED_BY,
1772 						LAST_UPDATE_LOGIN,
1773 						CREATED_BY,
1774 						CREATION_DATE)
1775     					VALUES(
1776 						p_enc_summary_line_id,
1777 						p_business_group_id,
1778 						p_enc_control_id,
1779 						p_time_period_id,
1780 						nvl(p_person_id,NULL),
1781 						nvl(p_assignment_id,NULL),
1782 						p_effective_date,
1783 						p_set_of_books_id,
1784 						p_gl_code_combination_id,
1785 						p_project_id,
1786 						p_expenditure_organization_id,
1787 						p_expenditure_type,
1788 						p_task_id,
1789 						p_award_id,
1790 						p_summary_amount,
1791 						p_dr_cr_flag,
1792 						p_status_code,
1793 						p_payroll_id,
1794 						p_gl_period_id,
1795 						p_gl_project_flag,
1796 						p_attribute_category,		-- Introduced DFF columns for bug fix 2908859
1797 						p_attribute1,
1798 						p_attribute2,
1799 						p_attribute3,
1800 						p_attribute4,
1801 						p_attribute5,
1802 						p_attribute6,
1803 						p_attribute7,
1804 						p_attribute8,
1805 						p_attribute9,
1806 						p_attribute10,
1807 						SYSDATE,
1808 						FND_GLOBAL.USER_ID,
1809 						FND_GLOBAL.LOGIN_ID,
1810 						FND_GLOBAL.USER_ID,
1811 						SYSDATE);
1812 		p_return_status	:= fnd_api.g_ret_sts_success;
1813 EXCEPTION
1814 	WHEN OTHERS THEN
1815      		g_error_api_path := 'INSERT_INTO_ENC_SUM_LINES:'||g_error_api_path;
1816      		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','INSERT_INTO_ENC_SUM_LINES');
1817      		p_return_status := fnd_api.g_ret_sts_unexp_error;
1818 END;
1819 
1820 --	##########################################################################
1821 --	This procedure transfers the summarized lines from psp_enc_summary_lines
1822 --		with gl_project_flag = 'G' to gl_interface
1823 
1824 --	This procedure transfers the summarized lines from PSP_ENC_SUMMARY_LINES table
1825 --	to GL_INTERFACE table and kicks off the JOURNAL IMPORT program in GL and sends
1826 --	ENC_CONTROL_ID and END_DATE for the relevant TIME_PERIOD_ID
1827 --	and GROUP_ID into the tie back procedure
1828 --	##########################################################################
1829 /******	Commented for Create and Update multi thread enh.
1830 PROCEDURE tr_to_gl_int(p_payroll_id IN NUMBER,
1831 			p_return_status	OUT NOCOPY  VARCHAR2
1832 			) IS
1833 
1834 	CURSOR 	enc_control_cur IS
1835    	SELECT 	enc_control_id,
1836           	payroll_id,
1837 		time_period_id,
1838                 gl_phase                       --- added for 2444657
1839    	FROM   	psp_enc_controls
1840    	WHERE 	payroll_id = nvl(p_payroll_id, payroll_id)
1841 	AND	(total_dr_amount IS NOT NULL OR total_cr_amount IS NOT NULL)
1842    	AND	action_type IN ('N', 'Q', 'U') -- Included 'Q' for Quick Upd. Enh. 2143723.
1843    	AND    	action_code = 'I'
1844    	AND    	run_id = g_run_id
1845    	AND	business_group_id = g_business_group_id
1846 	AND	set_of_books_id = g_set_of_books_id
1847         AND     gl_phase in ('Summarize', 'Transfer');
1848 
1849 	CURSOR	int_cur(l_enc_control_id IN NUMBER) IS
1850 	SELECT	pesl.enc_summary_line_id,
1851 		pesl.effective_date,
1852 		pesl.gl_code_combination_id,
1853 		pesl.summary_amount,
1854 		pesl.dr_cr_flag,
1855 		pesl.set_of_books_id,
1856 	  pesl.time_period_id,
1857 	  pesl.attribute1,
1858           pesl.attribute2,
1859           pesl.attribute3,
1860           pesl.attribute4,
1861           pesl.attribute5,
1862           pesl.attribute6,
1863           pesl.attribute7,
1864           pesl.attribute8,
1865           pesl.attribute9,
1866           pesl.attribute10,
1867           pesl.attribute11,
1868           pesl.attribute12,
1869           pesl.attribute13,
1870           pesl.attribute14,
1871           pesl.attribute15,
1872           pesl.attribute16,
1873           pesl.attribute17,
1874           pesl.attribute18,
1875           pesl.attribute19,
1876           pesl.attribute20,
1877           pesl.attribute21,
1878           pesl.attribute22,
1879           pesl.attribute23,
1880           pesl.attribute24,
1881           pesl.attribute25,
1882           pesl.attribute26,
1883           pesl.attribute27,
1884           pesl.attribute28,
1885           pesl.attribute29,
1886           pesl.attribute30
1887 	FROM	psp_enc_summary_lines pesl
1888 	WHERE 	pesl.status_code = 'N'
1889 	AND	pesl.enc_control_id = l_enc_control_id
1890 	AND	pesl.payroll_id = p_payroll_id
1891 	AND	pesl.gl_code_combination_id is NOT NULL;
1892 
1893 	enc_control_rec		enc_control_cur%ROWTYPE;
1894 	int_rec			int_cur%ROWTYPE;
1895 
1896 	l_bg_id			NUMBER(15) := g_business_group_id;
1897 	l_sob_id		NUMBER(15);
1898 	l_status		VARCHAR2(50);
1899 	l_acc_date		DATE;
1900 	l_user_je_cat	 	VARCHAR2(25);
1901 	l_user_je_source	VARCHAR2(25);
1902 	l_period_name		VARCHAR2(35);
1903 	l_period_end_dt		DATE;
1904 	l_enc_type_id		NUMBER(15);
1905 	l_ent_dr		NUMBER;
1906 	l_ent_cr		NUMBER;
1907 	l_group_id		NUMBER;
1908 	l_int_run_id		NUMBER;
1909 	l_ref1			VARCHAR2(100);
1910 	l_ref4			VARCHAR2(100);
1911 
1912 	l_return_status		VARCHAR2(10);
1913 	req_id			NUMBER(15);
1914 	call_status		BOOLEAN;
1915 	rphase			VARCHAR2(30);
1916 	rstatus			VARCHAR2(30);
1917 	dphase			VARCHAR2(30);
1918 	dstatus			VARCHAR2(30);
1919 	message			VARCHAR2(240);
1920 	p_errbuf		VARCHAR2(32767);
1921 	p_retcode		VARCHAR2(32767);
1922 	return_back		EXCEPTION;
1923 	l_rec_count		NUMBER := 0;
1924 	l_error			VARCHAR2(100);
1925 	l_product		VARCHAR2(3);
1926 	l_value			VARCHAR2(200);
1927 	l_table			VARCHAR2(100);
1928 	l_rec_no 		number := 0;
1929         / * Following variable is added for Enh.Encumbrance Redesign Prorata * /
1930 
1931     	l_summarization_option VARCHAR2 (1) :=  nvl (fnd_profile.value('PSP_ENABLE_ENC_SUMM_GL'),'N');
1932 
1933 	TYPE GL_TIE_RECTYPE IS RECORD (
1934 		R_CONTROL_ID	NUMBER,
1935 		R_END_DATE	DATE,
1936                 R_GROUP_ID      NUMBER);   ---- added group_id for 2444657, Summ. and Transfer will scoop all
1937                                            --- controls with 'I', 'N'. Those with 'N' will have
1938                                        -- new group_id, where as once with 'I' have old group_id
1939 
1940 
1941 	GL_TIE_REC	GL_TIE_RECTYPE;
1942 
1943 	TYPE GL_TIE_TABTYPE IS TABLE OF GL_TIE_REC%TYPE
1944 		INDEX BY BINARY_INTEGER;
1945 
1946 	GL_TIE_TAB	GL_TIE_TABTYPE;
1947 
1948 --	Introduced the following for bug fix 4507892
1949 	TYPE t_number_15_type IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
1950 	TYPE r_enc_control_rec IS RECORD (enc_control_id	t_number_15_type);
1951 	r_enc_controls	r_enc_control_rec;
1952 
1953 	CURSOR	enc_control_id_cur IS
1954 	SELECT	DISTINCT enc_control_id
1955 	FROM	psp_enc_summary_lines
1956 	WHERE	group_id = l_group_id;
1957 --	End of changes for bug fix 4507892
1958 BEGIN
1959 	gl_tie_tab.delete;
1960 
1961 	gl_je_source(	l_user_je_source,
1962 			l_return_status);
1963 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1964 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1965 	END IF;
1966 
1967 	gl_je_cat(	l_user_je_cat,
1968 			l_return_status);
1969 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1970 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1971 	END IF;
1972 
1973 	enc_type(	l_enc_type_id,
1974 			l_return_status);
1975 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1976 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1977 	END IF;
1978 
1979 	SELECT 	gl_interface_control_s.nextval
1980 	INTO	l_group_id
1981 	FROM 	dual;
1982 
1983 	OPEN enc_control_cur;
1984   	LOOP
1985    		FETCH enc_control_cur INTO enc_control_rec;
1986    		IF enc_control_cur%NOTFOUND THEN
1987      		CLOSE enc_control_cur;
1988      		EXIT;
1989    		END IF;
1990 
1991 / *	Moved this portion of the code outside the loop so as to take care of control record
1992 	with no child records, Fixed as part of Enh. 2143723 (base bug 2124607).
1993 		l_rec_no := l_rec_no +1;
1994 
1995 		gl_tie_tab(l_rec_no).r_control_id := enc_control_rec.enc_control_id;
1996 
1997 		UPDATE	psp_enc_summary_lines
1998 		SET	group_id = l_group_id
1999 		WHERE	status_code = 'N'
2000 		AND	gl_code_combination_id is NOT NULL
2001 		AND	enc_control_id = enc_control_rec.enc_control_id;
2002 End of enh. fix 2143723	* /
2003 
2004 -- For Bug 2478000
2005 -- The following was commented
2006 / *
2007 		BEGIN
2008 			SELECT	currency_code
2009 			INTO	l_cur_code
2010 			FROM 	gl_sets_of_books
2011 			WHERE	set_of_books_id = g_set_of_books_id;
2012 		EXCEPTION
2013 			WHEN NO_DATA_FOUND THEN
2014 			l_error := 'CURRENCY CODE';
2015 			l_product := 'GL';
2016 			fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
2017 			fnd_message.set_token('ERROR',l_error);
2018 			fnd_message.set_token('PRODUCT',l_product);
2019 			fnd_msg_pub.add;
2020 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2021 		END;  * /
2022 
2023 --End of bug 2478000
2024 
2025 		BEGIN
2026 			SELECT	period_name, end_date
2027 			INTO	l_period_name, l_period_end_dt
2028 			FROM 	per_time_periods
2029 			WHERE	time_period_id = enc_control_rec.time_period_id;
2030 		EXCEPTION
2031 			WHEN NO_DATA_FOUND THEN
2032 			l_value := 'time period id =';
2033 			l_table := 'PER_TIME_PERIODS';
2034 			fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
2035 			fnd_message.set_token('VALUE','l_value');
2036 			fnd_message.set_token('TABLE','l_table');
2037 			fnd_msg_pub.add;
2038 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2039 		END;
2040 
2041 		---l_rec_count := 0; --  commented for 2444657
2042              if enc_control_rec.gl_phase = 'Summarize' then   ---2444657
2043 		OPEN int_cur (enc_control_rec.enc_control_id);
2044 		---l_rec_count := 0;
2045 		LOOP
2046 			FETCH int_cur into int_rec;
2047 			IF int_cur%NOTFOUND THEN
2048 			CLOSE int_cur;
2049 			EXIT;
2050 			END IF;
2051 
2052 		l_sob_id := int_rec.set_of_books_id;
2053 
2054 			l_ref1          :=      l_period_name;
2055        		         l_ref4          :=      'LD ENCUMBRANCE';
2056 
2057 			l_rec_count 	:=	l_rec_count + 1;
2058 
2059 			IF int_rec.dr_cr_flag = 'D' THEN
2060 				l_ent_dr	:=	int_rec.summary_amount;
2061 				l_ent_cr	:=	NULL;
2062 			ELSIF int_rec.dr_cr_flag = 'C' THEN
2063 				l_ent_dr	:=	NULL;
2064 				l_ent_cr	:=	int_rec.summary_amount;
2065 			END IF;
2066 
2067 				insert_into_gl_int(
2068 						INT_REC.SET_OF_BOOKS_ID,
2069 						INT_REC.EFFECTIVE_DATE,
2070 						G_CURRENCY_CODE,
2071                 				L_USER_JE_CAT,
2072 						L_USER_JE_SOURCE,
2073 						L_ENC_TYPE_ID,
2074 		    				INT_REC.GL_CODE_COMBINATION_ID,
2075 						L_ENT_DR,
2076 						L_ENT_CR,
2077                 				L_GROUP_ID,
2078 						L_REF1,
2079 						L_REF1,
2080 						L_REF4,
2081                 				'E:' || INT_REC.ENC_SUMMARY_LINE_ID,
2082 	                			L_REF4,
2083 						INT_REC.ATTRIBUTE1,
2084 						INT_REC.ATTRIBUTE2,
2085                 				INT_REC.ATTRIBUTE3,
2086 						INT_REC.ATTRIBUTE4,
2087                 				INT_REC.ATTRIBUTE5,
2088 						INT_REC.ATTRIBUTE6,
2089 		    				INT_REC.ATTRIBUTE7,
2090 						INT_REC.ATTRIBUTE8,
2091                 				INT_REC.ATTRIBUTE9,
2092 						INT_REC.ATTRIBUTE10,
2093                 				INT_REC.ATTRIBUTE11,
2094 						INT_REC.ATTRIBUTE12,
2095                 				INT_REC.ATTRIBUTE13,
2096 						INT_REC.ATTRIBUTE14,
2097                 				INT_REC.ATTRIBUTE15,
2098 						INT_REC.ATTRIBUTE16,
2099 		    				INT_REC.ATTRIBUTE17,
2100 						INT_REC.ATTRIBUTE18,
2101                 				INT_REC.ATTRIBUTE19,
2102 						INT_REC.ATTRIBUTE20,
2103                 				INT_REC.ATTRIBUTE21,
2104 						INT_REC.ATTRIBUTE22,
2105                 				INT_REC.ATTRIBUTE23,
2106 						INT_REC.ATTRIBUTE24,
2107                 				INT_REC.ATTRIBUTE25,
2108 						INT_REC.ATTRIBUTE26,
2109 		    				INT_REC.ATTRIBUTE27,
2110 						INT_REC.ATTRIBUTE28,
2111                 				INT_REC.ATTRIBUTE29,
2112 						INT_REC.ATTRIBUTE30,
2113                 				L_RETURN_STATUS);
2114 
2115        			IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2116          		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2117        			END IF;
2118 		END LOOP;	--int_cur loop
2119             end if;           --- 2444657
2120 		/ * Commented out as part of bug fix #2142865
2121 		gl_tie_tab(l_rec_no).r_end_date := l_period_end_dt;* /
2122 --		Introduced the following as part of Enh. 2143723 (base bug 2124607)
2123 --		(Code moved from inside int_cur loop to here)
2124 		IF enc_control_rec.gl_phase = 'Summarize'  THEN
2125 			UPDATE	psp_enc_summary_lines
2126 			SET	group_id = l_group_id
2127 			WHERE   status_code = 'N'
2128 			AND     gl_code_combination_id is NOT NULL
2129 			AND     enc_control_id = enc_control_rec.enc_control_id;
2130                         if sql%rowcount > 0 then --- 2444657
2131 			  l_rec_no := l_rec_no +1;
2132 			  gl_tie_tab(l_rec_no).r_control_id := enc_control_rec.enc_control_id;
2133 			  gl_tie_tab(l_rec_no).r_end_date := l_period_end_dt;
2134                           gl_tie_tab(l_rec_no).r_group_id := l_group_id; --- added for 2444657
2135                         end if;
2136                 ELSE
2137 			l_rec_no := l_rec_no +1;
2138                         gl_tie_tab(l_rec_no).r_control_id := enc_control_rec.enc_control_id;
2139 			gl_tie_tab(l_rec_no).r_end_date := l_period_end_dt;
2140                         select group_id
2141                         into gl_tie_tab(l_rec_no).r_group_id
2142                         from psp_enc_summary_lines
2143                         where gl_code_combination_id is NOT NULL
2144                           AND enc_control_id = enc_control_rec.enc_control_id
2145                           AND rownum =1;
2146 		END IF;
2147 
2148            	END LOOP;	-- enc_cur
2149 
2150      		IF l_rec_count > 0 THEN    --- replaced l_rec_no with l_rec_count ..2444657
2151 
2152      		SELECT 	GL_JOURNAL_IMPORT_S.NEXTVAL
2153      		INTO 	l_int_run_id
2154      		FROM 	dual;
2155 
2156      			insert into gl_interface_control(
2157          					je_source_name,
2158         					status,
2159       						interface_run_id,
2160         					group_id,
2161                   				set_of_books_id)
2162        					VALUES (
2163                   				l_user_je_source,
2164          					'S',
2165                   				l_int_run_id,
2166                   				l_group_id,
2167                   				l_sob_id
2168           	       				);
2169 -- Commented out the commit as we commit after submitting the request, 11i
2170 
2171 --     	 COMMIT;
2172      			req_id := fnd_request.submit_request(
2173 	    							'SQLGL',
2174          							'GLLEZL',
2175          							'',
2176          							'',
2177          							FALSE,
2178            							to_char(l_int_run_id),
2179             							to_char(l_sob_id),
2180            							'N',
2181           							'',
2182             							'',
2183           							l_summarization_option, --Added for Enh. Enc Redesign, Bug #2259310.
2184            							'W');	-- Changed 'n' to 'W' for bug fix 2908859
2185 
2186      		IF req_id = 0 THEN
2187 
2188        		fnd_message.set_name('PSP','PSP_TR_GL_IMP_FAILED');
2189        		fnd_msg_pub.add;
2190        		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2191 
2192      		ELSE
2193 / *****	Converted the following UPDATE to BULK for R12 performance fixes
2194             UPDATE psp_enc_controls
2195                SET gl_phase = 'Transfer'
2196              WHERE enc_control_id in (select distinct enc_control_id
2197                                         from psp_enc_summary_lines
2198                                        where group_id = l_group_id);
2199 	End of comment for bug fix 4507892	***** /
2200 
2201 --	Introduced the following for bug fix 4507892
2202 		OPEN enc_control_id_cur;
2203 		FETCH enc_control_id_cur BULK COLLECT INTO r_enc_controls.enc_control_id;
2204 		CLOSE enc_control_id_cur;
2205 
2206 		FORALL I IN 1..r_enc_controls.enc_control_id.COUNT
2207 		UPDATE	psp_enc_controls
2208 		SET	gl_phase = 'Transfer'
2209 		WHERE	enc_control_id = r_enc_controls.enc_control_id(I);
2210 
2211 		r_enc_controls.enc_control_id.DELETE;
2212 --	End of changes for bug fix 4507892
2213 
2214        		COMMIT;
2215       		call_status := fnd_concurrent.wait_for_request(req_id, 20, 0,
2216                 rphase, rstatus, dphase, dstatus, message);
2217 
2218        			IF call_status = FALSE then
2219          		   fnd_message.set_name('PSP','PSP_TR_GL_IMP_FAILED');
2220          		   fnd_msg_pub.add;
2221          		   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2222        			END IF;
2223      		END IF;
2224 		END IF;	-- l_rec_count > 0    --- moved from below ... for 2444657
2225 
2226 		for i in 1..gl_tie_tab.count
2227 		loop
2228 		        / * Commented as part of bug fix #1776606
2229      			gl_enc_tie_back(gl_tie_tab(i).r_control_id,
2230 			gl_tie_tab(i).r_end_date, l_group_id, g_business_group_id, g_set_of_books_id, l_return_status);  * /
2231 
2232 			/ * Included as part of Bug fix # 1776606 * /
2233      			gl_enc_tie_back(gl_tie_tab(i).r_control_id,
2234 			gl_tie_tab(i).r_end_date,
2235                         gl_tie_tab(i).r_group_id,  --- replaced l_group_id for 2444657,
2236                          g_business_group_id, g_set_of_books_id, 'N',
2237 			 l_return_status);
2238      		       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2239                 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2240      	        	END IF;
2241 
2242 		end loop;
2243 / *
2244      		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2245         	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2246      		END IF;
2247  -- moved inside the loop
2248 
2249  For Bug fix 1776606
2250 * /
2251 
2252  --- added this wrapper loop on delete gl_interface for 2444657
2253   --- this is to ensure that all interface recs are purged, incase
2254   -- the previous Ssummarize and Transfer did not
2255  for i in 1..gl_tie_tab.count
2256  loop
2257    if gl_tie_tab(i).r_group_id is not null then
2258     delete gl_interface
2259     where group_id = gl_tie_tab(i).r_group_id
2260     and user_je_source_name = l_user_je_source
2261     and set_of_books_id = l_sob_id;
2262 
2263         for k in 1..gl_tie_tab.count
2264         loop
2265           if gl_tie_tab(i).r_group_id = gl_tie_tab(k).r_group_id and
2266              i <> k then
2267                gl_tie_tab(k).r_group_id := null;
2268           end if;
2269         end loop;
2270 
2271         gl_tie_tab(i).r_group_id := null;
2272     end if;
2273  end loop;
2274      COMMIT; -- moved the commit from above for 2479579
2275     if g_susp_prob = 'Y' then   -- introduced this IF stmnt for 2479579
2276          enc_batch_end(g_payroll_action_id,
2277                        l_return_status);
2278         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2279     end if;
2280 
2281    p_return_status := fnd_api.g_ret_sts_success;
2282 
2283 EXCEPTION
2284    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2285      	g_error_api_path := 'TR_TO_GL_INT:'||g_error_api_path;
2286      	p_return_status := fnd_api.g_ret_sts_unexp_error;
2287 
2288    WHEN RETURN_BACK THEN
2289      	p_return_status := fnd_api.g_ret_sts_success;
2290 
2291    WHEN OTHERS THEN
2292      	g_error_api_path := 'TR_TO_GL_INT:'||g_error_api_path;
2293      	fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','TR_TO_GL_INT');
2294      	p_return_status := fnd_api.g_ret_sts_unexp_error;
2295 END;
2296 	End of comment for Create and Update multi thread enh.	*****/
2297 
2298 --	Introduced the following modified tr_to_gl_int procedure for Create and Update multi thread enh.
2299 PROCEDURE tr_to_gl_int( p_payroll_action_id	IN		NUMBER,
2300 			p_return_status		OUT NOCOPY	VARCHAR2) IS
2301 l_user_je_cat	 	VARCHAR2(25);
2302 l_user_je_source	VARCHAR2(25);
2303 l_enc_type_id		NUMBER(15);
2304 l_group_id		NUMBER;
2305 l_int_run_id		NUMBER;
2306 l_return_status		VARCHAR2(10);
2307 req_id			NUMBER(15);
2308 call_status		BOOLEAN;
2309 rphase			VARCHAR2(30);
2310 rstatus			VARCHAR2(30);
2311 dphase			VARCHAR2(30);
2312 dstatus			VARCHAR2(30);
2313 message			VARCHAR2(240);
2314 l_tie_back_failed	VARCHAR2(1);
2315 l_summarization_option VARCHAR2 (1);
2316 
2317 TYPE t_number_15 IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
2318 
2319 TYPE r_enc_controls_rec IS RECORD (enc_control_id	t_number_15);
2320 r_enc_controls	r_enc_controls_rec;
2321 
2322 TYPE r_group_rec IS RECORD (group_id	t_number_15);
2323 r_groups	r_group_rec;
2324 
2325 l_created_by	NUMBER(15);
2326 
2327 CURSOR	gl_group_id_cur IS
2328 SELECT	DISTINCT group_id
2329 FROM	psp_enc_summary_lines pesl
2330 WHERE	payroll_action_id = p_payroll_action_id
2331 AND	status_code = 'N'
2332 AND	superceded_line_id IS NULL
2333 AND	gl_code_combination_id IS NOT NULL;
2334 
2335 CURSOR	enc_control_id_cur IS
2336 SELECT	enc_control_id
2337 FROM	psp_enc_controls
2338 WHERE	payroll_action_id = p_payroll_action_id;
2339 BEGIN
2340 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering Transfer to GL Interface');
2341 
2342 	l_created_by := fnd_global.user_id;
2343 	l_tie_back_failed := NULL;
2344 	l_summarization_option :=  NVL(fnd_profile.value('PSP_ENABLE_ENC_SUMM_GL'),'N');
2345 
2346 	gl_je_source(	l_user_je_source,
2347 			l_return_status);
2348 
2349 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2350 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2351 	END IF;
2352 
2353 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_user_je_source: ' || l_user_je_source);
2354 
2355 	gl_je_cat(	l_user_je_cat,
2356 			l_return_status);
2357 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2358 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2359 	END IF;
2360 
2361 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_user_je_cat: ' || l_user_je_cat);
2362 
2363 	enc_type(	l_enc_type_id,
2364 			l_return_status);
2365 	IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2366 	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2367 	END IF;
2368 
2369 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_enc_type_id: ' || l_enc_type_id);
2370 
2371 	SELECT 	gl_interface_control_s.nextval
2372 	INTO	l_group_id
2373 	FROM 	dual;
2374 
2375 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_group_id: ' || l_group_id);
2376 
2377 	UPDATE	psp_enc_summary_lines pesl
2378 	SET	group_id = l_group_id
2379 	WHERE 	status_code = 'N'
2380 	AND	gl_code_combination_id IS NOT NULL
2381 	AND	group_id IS NULL
2382 	AND	superceded_line_id IS NULL
2383 	AND	NOT EXISTS	(SELECT	1
2384 				FROM	psp_enc_summary_lines pesl2
2385 				WHERE	pesl2.payroll_action_id = p_payroll_action_id
2386 				AND	pesl2.assignment_id = pesl.assignment_id
2387 				AND	pesl2.time_period_id = pesl.time_period_id
2388 				AND	pesl2.status_code IN ('N', 'R')
2389 				AND	pesl2.superceded_line_id IS NOT NULL)
2390 	AND	payroll_action_id = p_payroll_action_id;
2391 
2392 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated group_id in psp_enc_summary_lines for new liquidation lines');
2393 
2394 	INSERT INTO gl_interface
2395 		(status,		set_of_books_id,		accounting_date,
2396 		currency_code,		date_created,			created_by,
2397 		actual_flag,		user_je_category_name,		user_je_source_name,
2398 		encumbrance_type_id,	code_combination_id,		entered_dr,
2399 		entered_cr,		group_id,			reference1,
2400 		reference2,		reference4,			reference6,
2401 		reference10,		attribute1,			attribute2,
2402 		attribute3,		attribute4,			attribute5,
2403 		attribute6,		attribute7,			attribute8,
2404 		attribute9,		attribute10,			attribute11,
2405 		attribute12,		attribute13,			attribute14,
2406 		attribute15,		attribute16,			attribute17,
2407 		attribute18,		attribute19,			attribute20,
2408 		reference21,		reference22,			reference23,
2409 		reference24,		reference25,			reference26,
2410 		reference27,		reference28,			reference29,
2411 		reference30)
2412 	SELECT	'NEW',			pesl.set_of_books_id,		pesl.effective_date,
2413 		DECODE(pec.uom, 'M', g_currency_code, 'STAT'),	SYSDATE,	l_created_by,
2414 		'E',			l_user_je_cat,			l_user_je_source,
2415 		l_enc_type_id,		pesl.gl_code_combination_id,
2416 			TO_NUMBER(DECODE(dr_cr_flag, 'D', pesl.summary_amount, NULL)) debit_amount,
2417 		TO_NUMBER(DECODE(dr_cr_flag, 'C', pesl.summary_amount, NULL)) credit_amount,
2418 					l_group_id,			pesl.enc_control_id,
2419 		pesl.enc_control_id,	'LD ENCUMBRANCE',		'E:' || pesl.enc_summary_line_id,
2420 		'LD ENCUMBRANCE',	pesl.attribute1,		pesl.attribute2,
2421 		pesl.attribute3,	pesl.attribute4,		pesl.attribute5,
2422 		pesl.attribute6,	pesl.attribute7,		pesl.attribute8,
2423 		pesl.attribute9,	pesl.attribute10,		pesl.attribute11,
2424 		pesl.attribute12,	pesl.attribute13,		pesl.attribute14,
2425 		pesl.attribute15,	pesl.attribute16,		pesl.attribute17,
2426 		pesl.attribute18,	pesl.attribute19,		pesl.attribute20,
2427 		pesl.attribute21,	pesl.attribute22,		pesl.attribute23,
2428 		pesl.attribute24,	pesl.attribute25,		pesl.attribute26,
2429 		pesl.attribute27,	pesl.attribute28,		pesl.attribute29,
2430 		pesl.attribute30
2431 	FROM	psp_enc_summary_lines pesl,
2432 		psp_enc_controls pec
2433 	WHERE	pec.enc_control_id = pesl.enc_control_id
2434 	AND	pec.payroll_action_id = p_payroll_action_id
2435 	AND	pesl.status_code = 'N'
2436 	AND	pesl.gl_code_combination_id is NOT NULL
2437 	AND	pesl.superceded_line_id IS NULL
2438 	AND	pesl.group_id = l_group_id
2439 	AND	pesl.payroll_action_id = p_payroll_action_id;
2440 
2441 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Number of records inserted into GL_INTERFACE: ' || SQL%ROWCOUNT);
2442 
2443 	IF (SQL%ROWCOUNT > 0) THEN
2444 		SELECT 	GL_JOURNAL_IMPORT_S.NEXTVAL
2445 		INTO 	l_int_run_id
2446 		FROM 	DUAL;
2447 
2448 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_int_run_id: ' || l_int_run_id);
2449 
2450 		INSERT INTO gl_interface_control
2451 			(je_source_name,	status,		interface_run_id,
2452 			group_id,		set_of_books_id)
2453 		VALUES (l_user_je_source,	'S',		l_int_run_id,
2454 			l_group_id,		g_set_of_books_id);
2455 
2456 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Inserted control record into gl_interface_control');
2457 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Before submitting Journal Import');
2458 
2459 		req_id := fnd_request.submit_request(	'SQLGL',
2460 							'GLLEZL',
2461 							'',
2462 							'',
2463 							FALSE,
2464 							TO_CHAR(l_int_run_id),
2465 							TO_CHAR(g_set_of_books_id),
2466 							'N',
2467 							'',
2468 							'',
2469 							l_summarization_option,
2470 							'W');
2471 
2472 		IF req_id = 0 THEN
2473 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Journal Import submission failed');
2474 			fnd_message.set_name('PSP','PSP_TR_GL_IMP_FAILED');
2475 			fnd_msg_pub.add;
2476 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2477 		ELSE
2478 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Submitted Journal Import (req_id: ' || req_id || ')');
2479 			OPEN enc_control_id_cur;
2480 			FETCH enc_control_id_cur BULK COLLECT INTO r_enc_controls.enc_control_id;
2481 			CLOSE enc_control_id_cur;
2482 
2483 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_enc_controls.enc_control_id.COUNT: ' || r_enc_controls.enc_control_id.COUNT);
2484 
2485 			FORALL I IN 1..r_enc_controls.enc_control_id.COUNT
2486 			UPDATE	psp_enc_controls
2487 			SET	gl_phase = 'Transfer'
2488 			WHERE	enc_control_id = r_enc_controls.enc_control_id(I);
2489 
2490 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated gl_phase to ''Transfer'' in psp_enc_controls');
2491 
2492 			r_enc_controls.enc_control_id.DELETE;
2493 
2494 			COMMIT;
2495 
2496 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling gather_table_stats for psp_enc_summary_lines');
2497 			fnd_stats.gather_table_stats('PSP', 'PSP_ENC_SUMMARY_LINES');
2498 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Completed gather_table_stats for psp_enc_summary_lines');
2499 
2500 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Waiting for Journal Import request to complete');
2501 
2502 			call_status := fnd_concurrent.wait_for_request(req_id, 10, 0, rphase, rstatus, dphase, dstatus, message);
2503 
2504 			IF call_status = FALSE THEN
2505 				fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Journal Import failed');
2506 				fnd_message.set_name('PSP','PSP_TR_GL_IMP_FAILED');
2507 				fnd_msg_pub.add;
2508 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2509 			END IF;
2510 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Journal Import completed');
2511 		END IF;
2512 	END IF;
2513 
2514 	OPEN gl_group_id_cur;
2515 	FETCH gl_group_id_cur BULK COLLECT INTO r_groups.group_id;
2516 	CLOSE gl_group_id_cur;
2517 
2518 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_groups.group_id.COUNT: ' || r_groups.group_id.COUNT);
2519 
2520 	FOR recno IN 1..r_groups.group_id.COUNT
2521 	LOOP
2522 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling gl_enc_tie_back for group_id: ' || r_groups.group_id(recno));
2523 
2524 		gl_enc_tie_back(p_payroll_action_id,
2525 						r_groups.group_id(recno),
2526 						g_business_group_id,
2527 						g_set_of_books_id,
2528 						'N',
2529 						l_return_status);
2530 
2531 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2532 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2533 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	gl_enc_tie_back failed for group_id: ' || r_groups.group_id(recno));
2534 		ELSE
2535 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	gl_enc_tie_back successful for group_id: ' || r_groups.group_id(recno));
2536 		END IF;
2537 	END LOOP;
2538 
2539 	FORALL recno IN 1..r_groups.group_id.COUNT
2540 	DELETE	gl_interface
2541 	WHERE	group_id = r_groups.group_id(recno)
2542 	AND	user_je_source_name = l_user_je_source
2543 	AND	set_of_books_id = g_set_of_books_id;
2544 
2545 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted groups from gl_interface for which gl_enc_tie_back is complete');
2546 
2547 	FORALL recno IN 1..r_groups.group_id.COUNT
2548 	UPDATE	psp_enc_summary_lines
2549 	SET	group_id = NULL
2550 	WHERE	group_id = r_groups.group_id(recno)
2551 	AND	status_code = 'N';
2552 
2553 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Set the un-imported summary lines to New status');
2554 
2555 	COMMIT;
2556 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	COMMITted gl_enc_tie_back');
2557 
2558 	p_return_status := fnd_api.g_ret_sts_success;
2559 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving TR_TO_GL_INT');
2560 EXCEPTION
2561 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2562 		g_error_api_path := 'TR_TO_GL_INT:'||g_error_api_path;
2563 		p_return_status := fnd_api.g_ret_sts_unexp_error;
2564 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving TR_TO_GL_INT');
2565 	WHEN OTHERS THEN
2566 		g_error_api_path := 'TR_TO_GL_INT:'||g_error_api_path;
2567 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','TR_TO_GL_INT');
2568 		p_return_status := fnd_api.g_ret_sts_unexp_error;
2569 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving TR_TO_GL_INT');
2570 END tr_to_gl_int;
2571 --	End of changes for Create and Update multi thread enh.
2572 
2573 --	##########################################################################
2574 --	This procedure retrieves the user_je_source_name from gl_je_sources
2575 --	##########################################################################
2576 
2577 PROCEDURE gl_je_source(	P_USER_JE_SOURCE_NAME  OUT NOCOPY  VARCHAR2,
2578                         P_RETURN_STATUS        OUT NOCOPY  VARCHAR2) IS
2579    l_error	VARCHAR2(100);
2580    l_product	VARCHAR2(3);
2581  BEGIN
2582    SELECT user_je_source_name
2583    INTO   p_user_je_source_name
2584    FROM   gl_je_sources
2585    WHERE  je_source_name = 'OLD';
2586  EXCEPTION
2587   WHEN NO_DATA_FOUND THEN
2588    l_error := 'JE SOURCES = OLD';
2589    l_product := 'GL';
2590    fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
2591    fnd_message.set_token('ERROR',l_error);
2592    fnd_message.set_token('PRODUCT',l_product);
2593    fnd_msg_pub.add;
2594    p_return_status := fnd_api.g_ret_sts_unexp_error;
2595   WHEN OTHERS THEN
2596     g_error_api_path := 'gl_je_source:'||g_error_api_path;
2597     fnd_msg_pub.add_exc_msg('psp_enc_sum_tran','gl_je_source');
2598     p_return_status := fnd_api.g_ret_sts_unexp_error;
2599  END;
2600 
2601 --	##########################################################################
2602 --	This procedure retrieves the user_je_category_name from gl_je_categories
2603 --	##########################################################################
2604 
2605 PROCEDURE gl_je_cat(	P_USER_JE_CATEGORY_NAME  OUT NOCOPY  VARCHAR2,
2606                         P_RETURN_STATUS          OUT NOCOPY  VARCHAR2) IS
2607    l_error	VARCHAR2(100);
2608    l_product	VARCHAR2(3);
2609  BEGIN
2610    SELECT user_je_category_name
2611    INTO   p_user_je_category_name
2612    FROM   gl_je_categories
2613    WHERE  je_category_name = 'OLD';
2614  EXCEPTION
2615   WHEN NO_DATA_FOUND THEN
2616    l_error := 'JE CATEGORY = OLD';
2617    l_product := 'GL';
2618    fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
2619    fnd_message.set_token('ERROR',l_error);
2620    fnd_message.set_token('PRODUCT',l_product);
2621    fnd_msg_pub.add;
2622    p_return_status := fnd_api.g_ret_sts_unexp_error;
2623   WHEN OTHERS THEN
2624     g_error_api_path := 'gl_je_cat:'||g_error_api_path;
2625     fnd_msg_pub.add_exc_msg('psp_enc_sum_tran','gl_je_cat');
2626     p_return_status := fnd_api.g_ret_sts_unexp_error;
2627  END;
2628 
2629 --	##########################################################################
2630 --	This procedure retrieves the encumbrance_type_id from gl_encumbrance_types
2631 --	##########################################################################
2632 
2633 PROCEDURE enc_type(	P_ENCUMBRANCE_TYPE_ID  OUT NOCOPY  VARCHAR2,
2634                         P_RETURN_STATUS        OUT NOCOPY  VARCHAR2) IS
2635    l_error	VARCHAR2(100);
2636    l_product	VARCHAR2(3);
2637 
2638  BEGIN
2639    SELECT encumbrance_type_id
2640    INTO   p_encumbrance_type_id
2641    FROM   gl_encumbrance_types
2642    WHERE  encumbrance_type = 'OLD'
2643    AND    enabled_flag = 'Y';
2644 
2645  EXCEPTION
2646   WHEN NO_DATA_FOUND THEN
2647    l_error := 'ENCUMBRANCE TYPE = OLD';
2648    l_product := 'GL';
2649    fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
2650    fnd_message.set_token('ERROR',l_error);
2651    fnd_message.set_token('PRODUCT',l_product);
2652    fnd_msg_pub.add;
2653    p_return_status := fnd_api.g_ret_sts_unexp_error;
2654   WHEN OTHERS THEN
2655     g_error_api_path := 'enc_type:'||g_error_api_path;
2656     fnd_msg_pub.add_exc_msg('psp_enc_sum_tran','enc_type');
2657     p_return_status := fnd_api.g_ret_sts_unexp_error;
2658 
2659 END;
2660 
2661 --	##########################################################################
2662 --	This procedure ties back all the transactions posted into Oracle General Ledger
2663 --		with Oracle Labor Distribution where the journal import is successful.
2664 --	In case of failure the transactions in Oracle Labor Distribution are turned
2665 --		back into their original state.
2666 --	##########################################################################
2667 
2668 /*****	Commented for Create and Update multi thread enh.
2669 PROCEDURE       gl_enc_tie_back(
2670                 p_enc_control_id        IN  NUMBER,
2671                 p_period_end_date       IN  DATE,
2672                 p_group_id              IN  NUMBER,
2673                 p_business_group_id     IN  NUMBER,
2674                 p_set_of_books_id       IN  NUMBER,
2675                 p_mode			IN  VARCHAR2,   -- Included as part of Bug fix #1776606s
2676 		p_return_status		OUT NOCOPY VARCHAR2
2677 				)IS
2678 / *
2679    CURSOR enc_control_cur IS
2680    SELECT enc_control_id,
2681           time_period_id
2682      FROM psp_enc_controls
2683     WHERE payroll_id = nvl(p_payroll_id, payroll_id)
2684 	  AND (total_dr_amount IS NOT NULL OR total_cr_amount IS NOT NULL)
2685    	  AND action_type IN ('N', 'Q', 'U') -- Included 'Q' for Quick Upd. Enh. 2143723.
2686    	  AND action_code = 'I'
2687    	  AND run_id = nvl(g_run_id, run_id)
2688       AND gl_phase = 'Transfer'
2689    	  AND business_group_id = nvl(g_business_group_id, business_group_id)
2690 	  AND set_of_books_id = nvl(g_set_of_books_id, set_of_books_id);
2691 * /
2692    CURSOR gl_tie_back_success_cur IS
2693    SELECT enc_summary_line_id,
2694           dr_cr_flag,
2695 	  summary_amount
2696    FROM   psp_enc_summary_lines
2697    WHERE  group_id = p_group_id
2698    and enc_control_id = p_enc_control_id;
2699 
2700 
2701    CURSOR gl_tie_back_reject_cur IS
2702    SELECT status,
2703           reference6
2704    FROM   gl_interface
2705    WHERE  user_je_source_name = 'OLD'
2706      AND  set_of_books_id = p_set_of_books_id
2707      AND  group_id = p_group_id
2708      AND  reference6 IN (SELECT 'E:' || enc_summary_line_id -- Introduced for bug fix 3953230
2709                          FROM  psp_enc_summary_lines pesl
2710                          WHERE pesl.enc_control_id = p_enc_control_id);
2711 
2712    CURSOR assign_susp_ac_cur(P_ENC_LINE_ID	IN	NUMBER) IS
2713    SELECT pel.rowid,
2714           pel.encumbrance_date,
2715           pel.suspense_org_account_id
2716    FROM   psp_enc_lines pel
2717    WHERE  pel.enc_summary_line_id = p_enc_line_id
2718    and enc_control_id=p_enc_control_id ;  -- this added to fix suspense ac postings
2719 -- bug fix 1671938
2720 
2721 -- Get the Organization details ...
2722 
2723    CURSOR get_susp_org_cur(P_ORG_ID	IN	VARCHAR2) IS
2724    SELECT hou.organization_id, hou.name, poa.gl_code_combination_id
2725      FROM hr_all_organization_units hou, psp_organization_accounts poa
2726     WHERE hou.organization_id = poa.organization_id
2727       AND poa.business_group_id = p_business_group_id
2728       AND poa.set_of_books_id = p_set_of_books_id
2729       AND poa.organization_account_id = p_org_id;
2730 / *
2731    CURSOR get_org_id_cur(P_LINE_ID	IN	NUMBER) IS
2732    SELECT hou.organization_id, hou.name
2733    FROM   hr_all_organization_units hou,
2734   	      per_assignments_f paf,
2735           psp_enc_lines pel
2736    WHERE  pel.enc_summary_line_id = p_line_id
2737    AND    pel.assignment_id = paf.assignment_id
2738    AND    pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
2739    AND    paf.organization_id = hou.organization_id
2740    AND    pel.encumbrance_date between
2741 		  hou.date_from and nvl(hou.date_to,pel.encumbrance_date);
2742 * /
2743 
2744 
2745    CURSOR get_org_id_cur(P_ROWID IN ROWID) IS
2746    SELECT hou.organization_id, hou.name
2747    FROM   hr_all_organization_units hou,
2748   	      per_assignments_f paf,
2749           psp_enc_lines pel
2750    WHERE
2751 -- pel.enc_summary_line_id = p_line_id
2752     pel.rowid=p_rowid
2753    AND    pel.assignment_id = paf.assignment_id
2754    AND    pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
2755    AND    paf.organization_id = hou.organization_id
2756    AND    pel.encumbrance_date between
2757 		  hou.date_from and nvl(hou.date_to,pel.encumbrance_date);
2758 
2759 -- bug fix 1671938
2760   l_orig_org_name		hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
2761   l_orig_org_id			number;
2762 
2763 -- End of Get org id cursor  Ravindra
2764 / *
2765    CURSOR assign_susp_ac_cur(P_ENC_SUMMARY_LINE_ID	IN	NUMBER) IS
2766    SELECT hou.name,
2767           hou.organization_id,
2768           pel.rowid,
2769           pel.assignment_id,
2770           pel.encumbrance_date,
2771           pel.suspense_org_account_id,
2772           pel.gl_code_combination_id
2773    FROM   hr_organization_units hou,
2774           per_assignments_f paf,
2775           psp_enc_lines pel
2776    WHERE  pel.enc_summary_line_id = p_enc_summary_line_id
2777    AND    pel.assignment_id = paf.assignment_id
2778    AND    pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
2779    AND    paf.organization_id = hou.organization_id
2780    AND	  pel.business_group_id = g_business_group_id
2781    AND	  pel.set_of_books_id = g_set_of_books_id
2782    AND    pel.encumbrance_date between hou.date_from and nvl(hou.date_to,pel.encumbrance_date);
2783 * /
2784 
2785    CURSOR org_susp_ac_cur(P_ORGANIZATION_ID	IN	NUMBER,
2786                           P_ENCUMBRANCE_DATE	IN	DATE) IS
2787    SELECT poa.organization_account_id,
2788           poa.gl_code_combination_id,
2789           poa.project_id,
2790 	  poa.expenditure_organization_id,
2791 	  poa.expenditure_type,
2792           poa.award_id,
2793 	  poa.task_id
2794    FROM   psp_organization_accounts poa
2795    WHERE  poa.organization_id = p_organization_id
2796    AND	  poa.business_group_id = p_business_group_id
2797    AND	  poa.set_of_books_id = p_set_of_books_id
2798    AND    poa.account_type_code = 'S'
2799    AND    p_encumbrance_date BETWEEN poa.start_date_active AND
2800                                       nvl(poa.end_date_active,p_encumbrance_date);
2801 
2802 -- CURSOR global_susp_ac_cur(P_ENCUMBRANCE_DATE	IN	DATE) IS
2803    CURSOR global_susp_ac_cur(P_ORGANIZATION_ACCOUNT_ID  IN	NUMBER) IS  --BUG 2056877
2804    SELECT poa.organization_account_id,
2805           poa.gl_code_combination_id,
2806           poa.project_id,
2807 	  poa.expenditure_organization_id,
2808 	  poa.expenditure_type,
2809           poa.award_id,
2810 	  poa.task_id
2811    FROM   psp_organization_accounts poa
2812    WHERE
2813        / * poa.account_type_code = 'G'
2814    AND	  poa.business_group_id = p_business_group_id
2815    AND	  poa.set_of_books_id = p_set_of_books_id
2816    AND    p_distribution_date BETWEEN poa.start_date_active AND
2817                                       nvl(poa.end_date_active,p_distribution_date);  Bug 2056877.* /
2818          organization_account_id = p_organization_account_id; --Added for bug 2056877.
2819    l_organization_name		hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
2820    l_organization_id		NUMBER(15);
2821    l_rowid				ROWID;
2822    l_assignment_id		NUMBER(9);
2823    l_encumbrance_date		DATE;
2824    l_suspense_org_account_id  NUMBER(9);
2825    l_lines_glccid			NUMBER(15);
2826    l_organization_account_id	NUMBER(9);
2827    l_susp_glccid			NUMBER(15);
2828    l_project_id			NUMBER(15);
2829    l_expenditure_organization_id NUMBER(15);
2830    l_expenditure_type		VARCHAR2(30);
2831    l_award_id			NUMBER(15);
2832    l_task_id			NUMBER(15);
2833    l_status				VARCHAR2(50);
2834    l_reference6			VARCHAR2(100);
2835    l_enc_ref			VARCHAR2(100);
2836    l_cnt_gl_interface		NUMBER;
2837    l_enc_summary_line_id		NUMBER(10);
2838    l_gl_project_flag		VARCHAR2(1);
2839    l_suspense_ac_failed		VARCHAR2(1) := 'N';
2840    l_suspense_ac_not_found	VARCHAR2(1) := 'N';
2841    l_susp_ac_found		VARCHAR2(10) := 'TRUE';
2842    l_summary_amount		NUMBER;
2843    l_dr_summary_amount		NUMBER := 0;
2844    l_cr_summary_amount		NUMBER := 0;
2845    l_dr_cr_flag			VARCHAR2(1);
2846    l_effective_date		DATE;
2847    x_susp_failed_org_name	hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
2848    x_susp_failed_status		VARCHAR2(50);
2849    x_susp_failed_date		DATE;
2850    x_lines_glccid			NUMBER(15);
2851    x_susp_nf_org_name		hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
2852    x_susp_nf_date			DATE;
2853    l_return_status		VARCHAR2(10);
2854    l_group_id               NUMBER:=p_group_id;  -- bug fix 1570575
2855    l_rec_cnt                NUMBER := 0;
2856 	x	varchar2(2000);
2857    l_return_value               VARCHAR2(30); --Added for bug 2056877.
2858    no_profile_exists            EXCEPTION;    --Added for bug 2056877.
2859    no_val_date_matches          EXCEPTION;    --Added for bug 2056877.
2860    no_global_acct_exists        EXCEPTION;    --Added for bug 2056877.
2861    l_susp_exception varchar2(50) := NULL; -- 2479579
2862 
2863 
2864 
2865  FUNCTION PROCESS_COMPLETE RETURN BOOLEAN IS
2866   l_cnt     NUMBER := 0;
2867   l_status  VARCHAR2(30);
2868  begin
2869    select count(*)
2870      into l_cnt
2871      from gl_interface
2872     where user_je_source_name = 'OLD'
2873       and set_of_books_id = p_set_of_books_id
2874       and group_id = p_group_id
2875       and status = 'NEW';
2876 
2877    if l_cnt = 0 then
2878      return TRUE;
2879    elsif l_cnt > 0 then
2880 -- -------------------------------------------------------------------------------------------
2881 -- If status = 'NEW' then the journal import process did not kick off
2882 -- for some reason. Return FALSE in this case. So cleanup the tables and try to transfer
2883 -- again after summarization in the second pass.
2884 -- -------------------------------------------------------------------------------------------
2885 
2886      delete from gl_interface
2887       where user_je_source_name = 'OLD'
2888         and set_of_books_id = p_set_of_books_id
2889         and group_id = p_group_id;
2890 
2891      delete from psp_enc_summary_lines
2892       where group_id = p_group_id
2893 	and enc_control_id = p_enc_control_id;
2894 
2895      return FALSE;
2896    end if;
2897 
2898  exception
2899  when others then
2900       return TRUE;
2901  end PROCESS_COMPLETE;
2902 
2903  BEGIN
2904 
2905    IF (PROCESS_COMPLETE) THEN
2906 
2907    SELECT count(*)
2908      INTO l_cnt_gl_interface
2909      FROM gl_interface
2910     WHERE user_je_source_name = 'OLD'
2911       AND set_of_books_id = p_set_of_books_id
2912       AND group_id = p_group_id;
2913 
2914    IF l_cnt_gl_interface > 0 THEN
2915      / * Start bug#2142865 Moved the code after loop to above * /
2916      UPDATE psp_enc_controls
2917      SET gl_phase = 'TieBack'
2918      WHERE  run_id = g_run_id;
2919      / * End bug#2142865 * /
2920      OPEN gl_tie_back_reject_cur;
2921      LOOP
2922        FETCH gl_tie_back_reject_cur INTO l_status,l_enc_ref;
2923 	   IF gl_tie_back_reject_cur%NOTFOUND THEN
2924          CLOSE gl_tie_back_reject_cur;
2925          EXIT;
2926        END IF;
2927 
2928        l_reference6 := substr(l_enc_ref, 3);
2929 
2930        UPDATE 	psp_enc_summary_lines
2931        SET 	interface_status = l_status,
2932 		status_code = 'R'
2933        WHERE 	enc_summary_line_id = to_number(l_reference6);
2934 
2935        OPEN assign_susp_ac_cur(to_number(l_reference6));
2936        LOOP
2937          FETCH assign_susp_ac_cur INTO l_rowid, l_encumbrance_date,l_suspense_org_account_id;
2938 
2939          IF assign_susp_ac_cur%NOTFOUND THEN
2940            CLOSE assign_susp_ac_cur;
2941            EXIT;
2942          END IF;
2943 
2944  	       if l_suspense_org_account_id is not null  then
2945 	         OPEN get_susp_org_cur(l_suspense_org_account_id);
2946 	         FETCH get_susp_org_cur into l_organization_id, l_organization_name,
2947 				                         l_lines_glccid;
2948 	         CLOSE get_susp_org_cur;
2949 	       end if;
2950 
2951 / * --- This is not needed as the enc lines are always in status 'N'
2952 * /
2953 
2954          IF l_status = 'P' OR substr(l_status,1,1) = 'W'  THEN
2955              null;
2956 ---  fIx for bug 1671938/1888408
2957 
2958 / *
2959 	        UPDATE psp_enc_lines
2960             SET status_code = 'N'
2961             WHERE rowid = l_rowid;
2962 	-- if the suspense a/c failed,update the status of the whole batch and display the error
2963 
2964 	 ELSIF l_suspense_org_account_id IS NOT NULL AND  *** /
2965 
2966 	 ELSIF l_suspense_org_account_id IS NOT NULL AND
2967                (l_status <> 'P' OR substr(l_status,1,1) <> 'W')  THEN
2968 	   x_susp_failed_org_name := l_organization_name;
2969            x_susp_failed_status   := l_status;
2970            x_susp_failed_date     := l_encumbrance_date;
2971            l_suspense_ac_failed := 'Y';
2972 
2973 / *        Commented the following for Bug 3194807
2974 
2975 	    UPDATE psp_enc_lines
2976             SET suspense_reason_code = l_status,
2977                 status_code = 'N'
2978             WHERE rowid = l_rowid;
2979 
2980 * /
2981 
2982          ELSE
2983 
2984            l_susp_ac_found := 'TRUE';
2985 
2986 	       OPEN get_org_id_cur(l_rowid);
2987 	       FETCH get_org_id_cur into l_orig_org_id, l_orig_org_name;
2988                close get_org_id_cur;
2989 
2990            OPEN org_susp_ac_cur(l_orig_org_id,l_encumbrance_date);
2991            FETCH org_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,
2992 			l_expenditure_organization_id, l_expenditure_type, l_award_id,l_task_id;
2993 
2994 --           OPEN org_susp_ac_cur(l_organization_id,l_encumbrance_date);
2995 --           FETCH org_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,l_award_id, l_task_id;
2996            IF org_susp_ac_cur%NOTFOUND  THEN
2997            / * Following code is added for bug 2056877 ,Added validation for generic suspense account * /
2998               l_return_value := psp_general.find_global_suspense(l_encumbrance_date,
2999 							  p_business_group_id,
3000                                                           p_set_of_books_id,
3001                                                           l_organization_account_id );
3002       	  / * --------------------------------------------------------------------
3003       	   Valid return values are
3004       	   PROFILE_VAL_DATE_MATCHES       Profile and Value and Date matching 'G'
3005       	   NO_PROFILE_EXISTS              No Profile
3006        	   NO_VAL_DATE_MATCHES            Profile and Either Value/date do not
3007             		                  match with 'G'
3008    	   NO_GLOBAL_ACCT_EXISTS          No 'G' exists
3009      	    ---------------------------------------------------------------------- * /
3010               / * start added for  bug # 2142865 * /
3011 	   / *    IF l_return_value <> 'PROFILE_VAL_DATE_MATCHES' THEN
3012 	        IF p_mode='N' THEN
3013 	          enc_batch_end(g_payroll_id ,l_return_status);
3014 	        END IF;
3015 	       END IF ;    commented for  2479579 * /
3016              / * end for bug # 2142865 * /
3017 
3018               IF l_return_value = 'PROFILE_VAL_DATE_MATCHES' THEN
3019            ----	 OPEN global_susp_ac_cur(l_encumbrance_date);
3020                  OPEN global_susp_ac_cur(l_organization_account_id); --Bug 2056877
3021             	 FETCH global_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,
3022 		 l_expenditure_organization_id, l_expenditure_type, l_award_id, l_task_id;
3023 
3024            	 IF global_susp_ac_cur%NOTFOUND THEN
3025 	      	  / *	l_susp_ac_found := 'FALSE';
3026               		l_suspense_ac_not_found := 'Y';
3027               		x_susp_nf_org_name := l_orig_org_name;
3028              		x_susp_nf_date     := l_encumbrance_date;  Commented for bug 2056877 * /
3029                         -- commented following line and added two new lines for 2479579
3030              		-- RAISE no_global_acct_exists; --Added for bug 2056877
3031                          l_suspense_ac_not_found := 'Y';
3032                          l_susp_ac_found := 'NO_G_AC';
3033            	 END IF;
3034             	 CLOSE global_susp_ac_cur;
3035              ELSIF l_return_value = 'NO_GLOBAL_ACCT_EXISTS' THEN
3036     		     -- RAISE no_global_acct_exists; commented this line and added two new lines for 2479579
3037                      l_suspense_ac_not_found := 'Y';
3038                      l_susp_ac_found := 'NO_G_AC';
3039              ELSIF l_return_value = 'NO_VAL_DATE_MATCHES' THEN
3040          	    -- RAISE no_val_date_matches; commented this line and added two new lines for 2479579
3041                      l_suspense_ac_not_found := 'Y';
3042                      l_susp_ac_found := 'NO_DT_MCH';
3043              ELSIF l_return_value = 'NO_PROFILE_EXISTS' THEN
3044          	    -- RAISE no_profile_exists; commented this line and added two new lines for 2479579
3045                          l_suspense_ac_not_found := 'Y';
3046                          l_susp_ac_found := 'NO_PROFL';
3047              END IF; -- Bug 2056877.
3048          END IF;
3049          CLOSE org_susp_ac_cur;
3050 
3051            IF l_susp_ac_found = 'TRUE' THEN
3052 
3053              IF l_susp_glccid IS NOT NULL THEN
3054                l_gl_project_flag := 'G';
3055                l_effective_date := p_period_end_date;
3056              ELSE
3057                l_gl_project_flag := 'P';
3058 
3059                psp_general.poeta_effective_date(l_encumbrance_date,
3060                                     l_project_id,
3061                                     l_award_id,
3062                                     l_task_id,
3063                                     l_effective_date,
3064                                     l_return_status);
3065                IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3066                  --dbms_output.put_line('poeta call failed     ');
3067                    --insert_into_psp_stout( 'poeta call failed      ');
3068 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3069                END IF;
3070 
3071              END IF;
3072 
3073              -- assign the organization suspense account and gl status
3074   / * For Bug  fix 3194807 * /
3075 
3076 	      UPDATE 	psp_enc_lines
3077 	      SET   	prev_effective_date =  encumbrance_date
3078 	      WHERE	rowid = l_rowid;
3079   / * End of changes for Bug fix 3194807 * /
3080 
3081 	      UPDATE psp_enc_lines
3082               SET suspense_org_account_id = l_organization_account_id,
3083                   suspense_reason_code = 'ES:' || l_status,
3084                   gl_project_flag = l_gl_project_flag,
3085 --                encumbrance_date = l_encumbrance_date, for Bug 3194807
3086 		  encumbrance_date = l_effective_date,
3087 / *	Commented for Bug fix 3194807
3088 		  schedule_line_id = null,
3089 		  org_schedule_id = null,
3090 		  default_org_account_id = null,
3091 		  element_account_id = null,
3092 		  gl_code_combination_id = decode(l_gl_project_flag, 'P', null, l_susp_glccid),
3093 		  project_id = decode(l_gl_project_flag, 'P', l_project_id, null),
3094 		  expenditure_organization_id = decode(l_gl_project_flag, 'P', l_expenditure_organization_id, null),
3095 		  expenditure_type = decode(l_gl_project_flag, 'P', l_expenditure_type, null),
3096 		  task_id = decode(l_gl_project_flag, 'P', l_task_id, null),
3097 		  award_id = decode(l_gl_project_flag, 'P', l_award_id, null), commented for bug 3194807 * /
3098                   status_code = 'N'
3099               WHERE rowid = l_rowid;
3100            ELSE -- 2479579 added this else stmnt
3101                 l_susp_exception := l_susp_ac_found;
3102            END IF;
3103          END IF;
3104        END LOOP;
3105      END LOOP;
3106       / * Commented as a part of bug#2142865
3107         Moved the same code up
3108       UPDATE psp_enc_controls
3109 		SET gl_phase = 'TieBack'
3110       WHERE enc_control_id = p_enc_control_id;* /
3111 / * GL encumbrance does not have reversal lines: bug 2030232
3112      IF l_reversal_ac_failed = 'Y' THEN
3113        fnd_message.set_name('PSP','PSP_GL_REVERSE_AC_REJECT');
3114        fnd_message.set_token('GLCCID',x_lines_glccid);
3115        fnd_msg_pub.add;
3116        -- Included the following check as part of Bug fix #1776606 --
3117        IF p_mode = 'N' THEN
3118        	RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3119        END IF;
3120      END IF;
3121 * /
3122 
3123      IF l_suspense_ac_failed = 'Y' THEN
3124        g_susp_prob := 'Y';     -- for 2479579
3125        fnd_message.set_name('PSP','PSP_TR_GL_SUSP_AC_REJECT');
3126        fnd_message.set_token('ORG_NAME',x_susp_failed_org_name);
3127        fnd_message.set_token('PAYROLL_DATE',x_susp_failed_date);
3128        fnd_message.set_token('ERROR_MSG',x_susp_failed_status);
3129        fnd_msg_pub.add;
3130 
3131 
3132        / * Added the following for Bug 3194807 * /
3133 
3134 	UPDATE 	psp_enc_lines
3135 	SET	suspense_org_account_id = NULL,
3136 		suspense_reason_code = NULL,
3137 		gl_project_flag = decode(gl_code_combination_id,NULL,'P','G'),
3138 		encumbrance_date = prev_effective_date
3139 	WHERE 	suspense_reason_code like 'ES:%'
3140 	AND	enc_summary_line_id
3141 		IN (SELECT enc_summary_line_id
3142 		    FROM   psp_enc_summary_lines
3143 	 	    WHERE  enc_control_id = p_enc_control_id);
3144 
3145 
3146 	/ * End of code changes for Bug 3194807 * /
3147 
3148      END IF;
3149     -- uncommented for 2479579, which was earlier commented   for bug # 2142865
3150      IF l_suspense_ac_not_found = 'Y' THEN
3151         g_susp_prob := 'Y';     -- for 2479579
3152        / * commented this message stack for 2479579
3153        fnd_message.set_name('PSP','PSP_LD_SUSPENSE_AC_NOT_EXIST');
3154        fnd_message.set_token('ORG_NAME',x_susp_nf_org_name);
3155        fnd_message.set_token('PAYROLL_DATE',x_susp_nf_date);
3156        fnd_msg_pub.add; * /
3157         ---added following if stmnt for 2479579
3158         IF    l_susp_exception = 'NO_G_AC' then
3159             RAISE no_global_acct_exists;
3160         ELSIF l_susp_exception = 'NO_DT_MCH' then
3161              RAISE no_val_date_matches;
3162         ELSIF l_susp_exception = 'NO_PROFL' then
3163               RAISE no_profile_exists;
3164         END IF;
3165 
3166      END IF;
3167 
3168    ELSIF l_cnt_gl_interface = 0 THEN
3169      --
3170      OPEN gl_tie_back_success_cur;
3171      LOOP
3172        FETCH gl_tie_back_success_cur INTO l_enc_summary_line_id,
3173        l_dr_cr_flag,l_summary_amount;
3174        IF gl_tie_back_success_cur%NOTFOUND THEN
3175          CLOSE gl_tie_back_success_cur;
3176          EXIT;
3177        END IF;
3178 
3179        l_rec_cnt := l_rec_cnt + 1;
3180        -- update records in psp_enc_summary_lines as 'A'
3181        UPDATE psp_enc_summary_lines
3182        SET status_code = 'A'
3183        WHERE enc_summary_line_id = l_enc_summary_line_id;
3184 
3185        IF l_dr_cr_flag = 'D' THEN
3186          l_dr_summary_amount := l_dr_summary_amount + l_summary_amount;
3187        ELSIF l_dr_cr_flag = 'C' THEN
3188          l_cr_summary_amount := l_cr_summary_amount + l_summary_amount;
3189        END IF;
3190 
3191          UPDATE psp_enc_lines
3192             SET status_code = 'A'
3193 	  WHERE enc_summary_line_id = l_enc_summary_line_id
3194 	    AND enc_control_id = p_enc_control_id;
3195 
3196 / * Introduced this cursor for Bug fix 3194807 * /
3197         UPDATE 	psp_enc_lines
3198 	SET	gl_code_combination_id =	(SELECT	poa.gl_code_combination_id
3199                                           	FROM	psp_organization_accounts poa
3200                                           	where	poa.organization_account_id = suspense_org_account_id),
3201 		project_id = NULL,
3202                 task_id  = NULL,
3203                 award_id = NULL,
3204                 expenditure_organization_id = NULL,
3205                 expenditure_type = NULL
3206           WHERE	enc_summary_line_id = l_enc_summary_line_id
3207 	  AND	suspense_reason_code LIKE 'ES:%';
3208 / * End of code Changes for Bug fix  3194807 * /
3209 
3210 
3211          -- move the transferred records to psp_enc_lines_history
3212 	 -- Added enc_start_date ,enc_end_date columns for Enh. Enc Redesign Prorata,Bug #2259310.
3213 	-- Introduced DFF columns for bug fix 2908859
3214          INSERT INTO psp_enc_lines_history
3215          (enc_line_id,business_group_id,enc_element_type_id,encumbrance_date,
3216           dr_cr_flag,encumbrance_amount,status_code,enc_line_type,schedule_line_id,org_schedule_id,
3217 	  default_org_account_id,suspense_org_account_id,element_account_id,gl_project_flag,
3218 	  enc_summary_line_id,person_id,assignment_id,award_id,task_id,expenditure_type,
3219 	  expenditure_organization_id,project_id,gl_code_combination_id,time_period_id,payroll_id,
3220 	  set_of_books_id,default_reason_code,suspense_reason_code,enc_control_id,change_flag,last_update_date,
3221 	  last_updated_by,last_update_login,created_by,creation_date,enc_start_date,enc_end_date,
3222 	attribute_category,	attribute1,		attribute2,		attribute3,
3223 	attribute4,		attribute5,		attribute6,		attribute7,
3224 	attribute8,		attribute9,		attribute10)
3225          SELECT enc_line_id,business_group_id,enc_element_type_id,encumbrance_date,
3226           dr_cr_flag,encumbrance_amount,status_code,enc_line_type,schedule_line_id,org_schedule_id,
3227 	  default_org_account_id,suspense_org_account_id,element_account_id,gl_project_flag,
3228 	  enc_summary_line_id,person_id,assignment_id,award_id,task_id,expenditure_type,
3229 	  expenditure_organization_id,project_id,gl_code_combination_id,time_period_id,payroll_id,
3230 	  set_of_books_id,default_reason_code,suspense_reason_code,enc_control_id,change_flag,last_update_date,
3231 	  last_updated_by,last_update_login,created_by,creation_date,enc_start_date,enc_end_date,
3232 	attribute_category,	attribute1,		attribute2,		attribute3,
3233 	attribute4,		attribute5,		attribute6,		attribute7,
3234 	attribute8,		attribute9,		attribute10
3235          FROM psp_enc_lines
3236          WHERE status_code = 'A'
3237          AND enc_summary_line_id = l_enc_summary_line_id
3238 	 AND enc_control_id = p_enc_control_id;
3239 
3240          DELETE FROM psp_enc_lines
3241          WHERE status_code = 'A'
3242          AND enc_summary_line_id = l_enc_summary_line_id
3243 	 AND enc_control_id = p_enc_control_id;
3244 
3245      END LOOP;
3246 
3247      UPDATE psp_enc_controls
3248 	SET summ_gl_dr_amount = l_dr_summary_amount,
3249             summ_gl_cr_amount = l_cr_summary_amount,
3250             gl_phase = 'TieBack'
3251       WHERE enc_control_id = p_enc_control_id;
3252        l_rec_cnt := 0;
3253    END IF;
3254 --   END LOOP; -- ENC_CONTROL_CUR
3255    END IF; -- If (PROCESS_COMPLETE)
3256    p_return_status := fnd_api.g_ret_sts_success;
3257  EXCEPTION
3258    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3259 	g_error_api_path := 'GL_ENC_TIE_BACK:'||g_error_api_path;
3260      p_return_status := fnd_api.g_ret_sts_unexp_error;
3261 
3262    / * Added Exceptions for bug 2056877 * /
3263    WHEN NO_PROFILE_EXISTS THEN
3264       g_error_api_path := SUBSTR('GL_ENC_TIE_BACK:'||g_error_api_path,1,230);
3265       fnd_message.set_name('PSP','PSP_NO_PROFILE_EXISTS');
3266       fnd_msg_pub.add;
3267      -- p_return_status := fnd_api.g_ret_sts_unexp_error;  commented and intro success for 2479579
3268       p_return_status := fnd_api.g_ret_sts_success;
3269 
3270    WHEN NO_VAL_DATE_MATCHES THEN
3271       g_error_api_path := SUBSTR('GL_ENC_TIE_BACK:'||g_error_api_path,1,230);
3272       fnd_message.set_name('PSP','PSP_NO_VAL_DATE_MATCHES');
3273       fnd_message.set_token('ORG_NAME',l_orig_org_name);
3274       fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
3275       fnd_msg_pub.add;
3276      -- p_return_status := fnd_api.g_ret_sts_unexp_error;  commented and intro success for 2479579
3277       p_return_status := fnd_api.g_ret_sts_success;
3278 
3279    WHEN NO_GLOBAL_ACCT_EXISTS THEN
3280       g_error_api_path := SUBSTR('GL_ENC_TIE_BACK:'||g_error_api_path,1,230);
3281       fnd_message.set_name('PSP','PSP_NO_GLOBAL_ACCT_EXISTS');
3282       fnd_message.set_token('ORG_NAME',l_orig_org_name);
3283       fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
3284       fnd_msg_pub.add;
3285      -- p_return_status := fnd_api.g_ret_sts_unexp_error;  commented and intro success for 2479579
3286       p_return_status := fnd_api.g_ret_sts_success;
3287 
3288    WHEN OTHERS THEN
3289       g_error_api_path := 'GL_ENC_TIE_BACK:'||g_error_api_path;
3290 	fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','GL_ENC_TIE_BACK');
3291       p_return_status := fnd_api.g_ret_sts_unexp_error;
3292 
3293 END;
3294 	End of comment for Create and Update multi thread enh.	*****/
3295 
3296 --	Introduced the following modified gl_enc_tie_back procedure for Create and Update multi thread enh.
3297 PROCEDURE gl_enc_tie_back(	p_payroll_action_id	IN		NUMBER,
3298 				p_group_id		IN		NUMBER,
3299 				p_business_group_id	IN		NUMBER,
3300 				p_set_of_books_id	IN		NUMBER,
3301 				p_mode			IN		VARCHAR2,
3302 				p_return_status		OUT NOCOPY	VARCHAR2) IS
3303 CURSOR	int_count_cur IS
3304 SELECT	COUNT(1)
3305 FROM	gl_interface
3306 WHERE	user_je_source_name = 'OLD'
3307 AND	set_of_books_id = p_set_of_books_id
3308 AND	group_id = p_group_id;
3309 
3310 CURSOR	gl_tie_back_success_cur IS
3311 SELECT	enc_summary_line_id,
3312 	enc_control_id,
3313 	dr_cr_flag,
3314 	summary_amount
3315 FROM	psp_enc_summary_lines
3316 WHERE	group_id = p_group_id;
3317 
3318 CURSOR	gl_tie_back_reject_cur IS
3319 SELECT	status,
3320 	TO_NUMBER(trim(substr(reference6,3)))
3321 FROM	gl_interface
3322 WHERE	user_je_source_name = 'OLD'
3323 AND	set_of_books_id = p_set_of_books_id
3324 AND	group_id = p_group_id;
3325 
3326 CURSOR	assign_susp_ac_cur IS
3327 SELECT	pel.rowid,
3328 	pel.encumbrance_date,
3329 	pel.enc_start_date,
3330 	pel.enc_end_date,
3331 	pel.assignment_id,
3332 	pel.payroll_id,
3333 	pel.enc_element_type_id,
3334 	pel.gl_code_combination_id,
3335 	pel.suspense_org_account_id,
3336 	pesl.interface_status,
3337 	ptp.end_date
3338 FROM	psp_enc_lines pel,
3339 	psp_enc_summary_lines pesl,
3340 	per_time_periods ptp
3341 WHERE	pel.payroll_action_id = p_payroll_action_id
3342 AND	pel.enc_summary_line_id = pesl.enc_summary_line_id
3343 AND	pesl.payroll_action_id = p_payroll_action_id
3344 AND	pesl.status_code = 'R'
3345 AND	pesl.group_id = p_group_id
3346 AND	ptp.time_period_id = pel.time_period_id
3347 ORDER BY 5, 6, 7, 8, 3;
3348 
3349 CURSOR	get_susp_org_cur(P_ORG_ID	IN	VARCHAR2) IS
3350 SELECT	hou.organization_id, hou.name, poa.gl_code_combination_id
3351 FROM	hr_all_organization_units hou,
3352 	psp_organization_accounts poa
3353 WHERE	hou.organization_id = poa.organization_id
3354 AND	poa.business_group_id = p_business_group_id
3355 AND	poa.set_of_books_id = p_set_of_books_id
3356 AND	poa.organization_account_id = p_org_id;
3357 
3358 CURSOR	get_org_id_cur(P_ROWID IN ROWID) IS
3359 SELECT	hou.organization_id, hou.name
3360 FROM	hr_all_organization_units hou,
3361 	per_assignments_f paf,
3362 	psp_enc_lines pel
3363 WHERE	pel.rowid=p_rowid
3364 AND	pel.assignment_id = paf.assignment_id
3365 AND	pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
3366 AND	paf.organization_id = hou.organization_id
3367 AND	pel.encumbrance_date BETWEEN hou.date_from AND NVL(hou.date_to, pel.encumbrance_date);
3368 
3369 CURSOR	org_susp_ac_cur(P_ORGANIZATION_ID	IN	NUMBER,
3370                           P_ENCUMBRANCE_DATE	IN	DATE) IS
3371 SELECT	poa.organization_account_id,
3372 	poa.gl_code_combination_id,
3373 	poa.project_id,
3374 	poa.expenditure_organization_id,
3375 	poa.expenditure_type,
3376 	poa.award_id,
3377 	poa.task_id
3378 FROM	psp_organization_accounts poa
3379 WHERE	poa.organization_id = p_organization_id
3380 AND	poa.business_group_id = p_business_group_id
3381 AND	poa.set_of_books_id = p_set_of_books_id
3382 AND	poa.account_type_code = 'S'
3383 AND	p_encumbrance_date BETWEEN poa.start_date_active AND NVL(poa.end_date_active, p_encumbrance_date);
3384 
3385 CURSOR	global_susp_ac_cur(P_ORGANIZATION_ACCOUNT_ID IN NUMBER) IS
3386 SELECT	poa.organization_account_id,
3387 	poa.gl_code_combination_id,
3388 	poa.project_id,
3389 	poa.expenditure_organization_id,
3390 	poa.expenditure_type,
3391 	poa.award_id,
3392 	poa.task_id
3393 FROM	psp_organization_accounts poa
3394 WHERE	organization_account_id = p_organization_account_id;
3395 
3396 l_encumbrance_date			DATE;
3397 l_lines_glccid				NUMBER(15);
3398 l_organization_account_id	NUMBER(9);
3399 l_susp_glccid				NUMBER(15);
3400 l_orig_org_name				hr_all_organization_units_tl.name%TYPE;
3401 l_orig_org_id				NUMBER(15);
3402 l_cnt_gl_interface			NUMBER;
3403 l_gl_project_flag			VARCHAR2(1);
3404 l_suspense_ac_failed		VARCHAR2(1);
3405 l_suspense_ac_not_found		VARCHAR2(1);
3406 l_susp_ac_found				VARCHAR2(10);
3407 l_organization_name			hr_all_organization_units_tl.name%TYPE;
3408 l_organization_id			NUMBER(15);
3409 l_return_value				VARCHAR2(30);
3410 l_effective_date			DATE;
3411 no_profile_exists			EXCEPTION;
3412 no_val_date_matches			EXCEPTION;
3413 no_global_acct_exists		EXCEPTION;
3414 l_susp_exception			VARCHAR2(50);
3415 l_project_id				NUMBER(15);
3416 l_expenditure_organization_id	NUMBER(15);
3417 l_expenditure_type			VARCHAR2(30);
3418 l_award_id					NUMBER(15);
3419 l_task_id					NUMBER(15);
3420 l_return_status				VARCHAR2(1);
3421 
3422 TYPE t_rowid IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
3423 TYPE t_date IS TABLE OF DATE INDEX BY BINARY_INTEGER;
3424 TYPE t_number IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3425 TYPE t_number_15 IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
3426 TYPE t_char_300 IS TABLE OF VARCHAR2(300) INDEX BY BINARY_INTEGER;
3427 
3428 TYPE r_interface_rec IS RECORD
3429 	(status			t_char_300,
3430 	enc_summary_line_id	t_number_15,
3431 	dr_cr_flag		t_char_300,
3432 	summary_amount		t_number,
3433 	enc_control_id		t_number_15);
3434 r_interface	r_interface_rec;
3435 
3436 TYPE r_suspense_ac_rec IS RECORD
3437 	(row_id					t_rowid,
3438 	encumbrance_date		t_date,
3439 	enc_start_date			t_date,
3440 	enc_end_date			t_date,
3441 	assignment_id			t_number_15,
3442 	element_type_id			t_number_15,
3443 	payroll_id				t_number_15,
3444 	gl_code_combination_id	t_number_15,
3445 	suspense_org_account_id	t_number_15,
3446 	interface_status		t_char_300,
3447 	end_date				t_date);
3448 r_suspense_ac	r_suspense_ac_rec;
3449 
3450 FUNCTION PROCESS_COMPLETE RETURN BOOLEAN IS
3451 l_cnt	NUMBER;
3452 CURSOR	int_count_cur IS
3453 SELECT	COUNT(1)
3454 FROM	gl_interface
3455 WHERE	user_je_source_name = 'OLD'
3456 AND	set_of_books_id = p_set_of_books_id
3457 AND	group_id = p_group_id
3458 AND	status = 'NEW';
3459 
3460 TYPE t_number_15 IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
3461 
3462 TYPE r_enc_control_rec IS RECORD
3463 	(enc_control_id	t_number_15);
3464 r_enc_controls	r_enc_control_rec;
3465 
3466 TYPE r_superceded_line_rec IS RECORD (superceded_line_id	t_number_15);
3467 r_superceded_lines	r_superceded_line_rec;
3468 
3469 CURSOR	enc_controls_cur IS
3470 SELECT	DISTINCT enc_control_id
3471 FROM	psp_enc_summary_lines
3472 WHERE	group_id = p_group_id;
3473 BEGIN
3474 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering GL_ENC_TIE_BACK.PROCESS_COMPLETE');
3475 
3476 	OPEN int_count_cur;
3477 	FETCH int_count_cur INTO l_cnt;
3478 	CLOSE int_count_cur;
3479 
3480 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_cnt: ' || l_cnt);
3481 
3482 	IF l_cnt = 0 THEN
3483 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GL_ENC_TIE_BACK.PROCESS_COMPLETE');
3484 		RETURN TRUE;
3485 	ELSIF l_cnt > 0 THEN
3486 		DELETE FROM gl_interface
3487 		WHERE	user_je_source_name = 'OLD'
3488 		AND	set_of_books_id = p_set_of_books_id
3489 		AND	group_id = p_group_id;
3490 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted from gl_interface');
3491 		DELETE FROM psp_enc_summary_lines
3492 		WHERE	group_id = p_group_id;
3493 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted from psp_enc_summary_lines');
3494 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GL_ENC_TIE_BACK.PROCESS_COMPLETE');
3495 		RETURN FALSE;
3496 	END IF;
3497 EXCEPTION
3498 	WHEN OTHERS THEN
3499 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GL_ENC_TIE_BACK.PROCESS_COMPLETE');
3500 		RETURN TRUE;
3501 END	PROCESS_COMPLETE;
3502 
3503 BEGIN
3504 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering GL_ENC_TIE_BACK procedure');
3505 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	p_group_id: ' || p_group_id);
3506 	l_suspense_ac_failed := 'N';
3507 	l_susp_ac_found := 'TRUE';
3508 	l_susp_exception := NULL;
3509 	l_suspense_ac_not_found := 'N';
3510 
3511 	IF (PROCESS_COMPLETE) THEN
3512 		OPEN int_count_cur;
3513 		FETCH int_count_cur INTO l_cnt_gl_interface;
3514 		CLOSE int_count_cur;
3515 
3516 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_cnt_gl_interface: ' || l_cnt_gl_interface);
3517 
3518 		IF (l_cnt_gl_interface > 0) THEN
3519 			OPEN gl_tie_back_reject_cur;
3520 			FETCH gl_tie_back_reject_cur BULK COLLECT INTO r_interface.status, r_interface.enc_summary_line_id;
3521 			CLOSE gl_tie_back_reject_cur;
3522 
3523 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_interface.status.COUNT: ' || r_interface.status.COUNT);
3524 
3525 			FORALL recno IN 1..r_interface.status.COUNT
3526 			UPDATE	psp_enc_summary_lines
3527 			SET	interface_status = r_interface.status(recno),
3528 				status_code = 'R'
3529 			WHERE	enc_summary_line_id = r_interface.enc_summary_line_id(recno)
3530 			AND	r_interface.status(recno) <> 'P'
3531 			AND	SUBSTR(r_interface.status(recno), 1, 1) <> 'W';
3532 
3533 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated rejected lines status in psp_enc_summary_lines');
3534 
3535 			OPEN assign_susp_ac_cur;
3536 			FETCH assign_susp_ac_cur BULK COLLECT INTO r_suspense_ac.row_id, r_suspense_ac.encumbrance_date,
3537 				r_suspense_ac.enc_start_date, r_suspense_ac.enc_end_date, r_suspense_ac.assignment_id,
3538 				r_suspense_ac.payroll_id, r_suspense_ac.element_type_id,
3539 				r_suspense_ac.gl_code_combination_id, r_suspense_ac.suspense_org_account_id,
3540 				r_suspense_ac.interface_status, r_suspense_ac.end_date;
3541 			CLOSE assign_susp_ac_cur;
3542 
3543 			FOR recno IN 1..r_suspense_ac.row_id.COUNT
3544 			LOOP
3545 				IF r_suspense_ac.suspense_org_account_id(recno) IS NOT NULL THEN
3546 					OPEN get_susp_org_cur(r_suspense_ac.suspense_org_account_id(recno));
3547 					FETCH get_susp_org_cur INTO l_organization_id, l_organization_name, l_lines_glccid;
3548 					CLOSE get_susp_org_cur;
3549 
3550 					l_suspense_ac_failed	:= 'Y';
3551 					g_susp_prob := 'Y';
3552 					fnd_message.set_name('PSP', 'PSP_TR_GL_SUSP_AC_REJECT');
3553 					fnd_message.set_token('ORG_NAME', l_organization_name);
3554 					fnd_message.set_token('PAYROLL_DATE', r_suspense_ac.encumbrance_date(recno));
3555 					fnd_message.set_token('ERROR_MSG', r_suspense_ac.interface_status(recno));
3556 					fnd_msg_pub.add;
3557 				ELSE
3558 					l_susp_ac_found := 'TRUE';
3559 
3560 					OPEN get_org_id_cur(r_suspense_ac.row_id(recno));
3561 					FETCH get_org_id_cur INTO l_orig_org_id, l_orig_org_name;
3562 					CLOSE get_org_id_cur;
3563 
3564 					OPEN org_susp_ac_cur(l_orig_org_id, r_suspense_ac.encumbrance_date(recno));
3565 					FETCH org_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,
3566 						l_expenditure_organization_id, l_expenditure_type, l_award_id, l_task_id;
3567 
3568 					IF org_susp_ac_cur%NOTFOUND THEN
3569 						l_return_value := psp_general.find_global_suspense(r_suspense_ac.encumbrance_date(recno),
3570 								p_business_group_id,
3571 								p_set_of_books_id,
3572 								l_organization_account_id);
3573 
3574 						IF l_return_value = 'PROFILE_VAL_DATE_MATCHES' THEN
3575 							OPEN global_susp_ac_cur(l_organization_account_id);
3576 							FETCH global_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,
3577 								l_expenditure_organization_id, l_expenditure_type, l_award_id, l_task_id;
3578 
3579 							IF global_susp_ac_cur%NOTFOUND THEN
3580 								l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
3581 								l_suspense_ac_not_found := 'Y';
3582 								l_susp_ac_found := 'NO_G_AC';
3583 							END IF;
3584 							CLOSE global_susp_ac_cur;
3585 						ELSIF l_return_value = 'NO_GLOBAL_ACCT_EXISTS' THEN
3586 							l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
3587 							l_suspense_ac_not_found := 'Y';
3588 							l_susp_ac_found := 'NO_G_AC';
3589 						ELSIF l_return_value = 'NO_VAL_DATE_MATCHES' THEN
3590 							l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
3591 							l_suspense_ac_not_found := 'Y';
3592 							l_susp_ac_found := 'NO_DT_MCH';
3593 						ELSIF l_return_value = 'NO_PROFILE_EXISTS' THEN
3594 							l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
3595 							l_suspense_ac_not_found := 'Y';
3596 							l_susp_ac_found := 'NO_PROFL';
3597 						END IF;
3598 					END IF;
3599 					CLOSE org_susp_ac_cur;
3600 
3601 					IF l_susp_ac_found = 'TRUE' THEN
3602 						IF l_susp_glccid IS NOT NULL THEN
3603 							l_gl_project_flag := 'G';
3604 							l_effective_date := r_suspense_ac.end_date(recno);
3605 						ELSE
3606 							l_gl_project_flag := 'P';
3607 							psp_general.poeta_effective_date(r_suspense_ac.encumbrance_date(recno),
3608 								l_project_id, l_award_id, l_task_id, l_effective_date,
3609 								l_return_status);
3610 							IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3611 								RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3612 							END IF;
3613 						END IF;
3614 
3615 						UPDATE	psp_enc_lines
3616 						SET	prev_effective_date = encumbrance_date,
3617 							orig_gl_code_combination_id = gl_code_combination_id,
3618 							orig_project_id = project_id,
3619 							orig_task_id = task_id,
3620 							orig_award_id = award_id,
3621 							orig_expenditure_org_id = expenditure_organization_id,
3622 							orig_expenditure_type = expenditure_type
3623 						WHERE	rowid = r_suspense_ac.row_id(recno)
3624 						AND		enc_start_date <= g_def_end_date;
3625 
3626 						UPDATE	psp_enc_lines
3627 						SET	suspense_org_account_id = l_organization_account_id,
3628 							gl_code_combination_id = l_susp_glccid,
3629 							project_id = l_project_id,
3630 							task_id = l_task_id,
3631 							award_id = l_award_id,
3632 							expenditure_organization_id = l_expenditure_organization_id,
3633 							expenditure_type = l_expenditure_type,
3634 							suspense_reason_code = 'ES:' || r_suspense_ac.interface_status(recno),
3635 							gl_project_flag = l_gl_project_flag,
3636 							encumbrance_date = l_effective_date,
3637 							status_code = 'N'
3638 						WHERE	rowid = r_suspense_ac.row_id(recno)
3639 						AND		enc_start_date <= g_def_end_date;
3640 
3641 						add_st_warnings(p_assignment_id	=>	r_suspense_ac.assignment_id(recno),
3642 								p_payroll_id		=>	r_suspense_ac.payroll_id(recno),
3643 								p_element_type_id	=>	r_suspense_ac.element_type_id(recno),
3644 								p_start_date		=>	r_suspense_ac.enc_start_date(recno),
3645 								p_end_date			=>	r_suspense_ac.enc_end_date(recno),
3646 								p_effective_date	=>	r_suspense_ac.encumbrance_date(recno),
3647 								p_gl_ccid			=>	r_suspense_ac.gl_code_combination_id(recno),
3648 								p_error_status		=>	r_suspense_ac.interface_status(recno));
3649 					ELSE
3650 						l_susp_exception := l_susp_ac_found;
3651 					END IF;
3652 				END IF;
3653 			END LOOP;
3654 
3655 			IF l_suspense_ac_failed = 'Y' THEN
3656 				UPDATE	psp_enc_lines
3657 				SET	suspense_org_account_id = NULL,
3658 					gl_code_combination_id = orig_gl_code_combination_id,
3659 					project_id = orig_project_id,
3660 					task_id = orig_task_id,
3661 					award_id = orig_award_id,
3662 					expenditure_organization_id = orig_expenditure_org_id,
3663 					expenditure_type = orig_expenditure_type,
3664 					gl_project_flag = decode(orig_gl_code_combination_id,NULL,'P','G'),
3665 					encumbrance_date = prev_effective_date
3666 				WHERE	suspense_reason_code like 'ES:%'
3667 				AND	enc_summary_line_id IN	(SELECT	enc_summary_line_id
3668 								FROM	psp_enc_summary_lines pesl
3669 								WHERE	pesl.payroll_action_id = p_payroll_action_id
3670 								AND	pesl.group_id = p_group_id
3671 								AND	status_code = 'R');
3672 				UPDATE	psp_enc_lines
3673 				SET	orig_gl_code_combination_id = NULL,
3674 					orig_project_id = NULL,
3675 					orig_task_id = NULL,
3676 					orig_award_id = NULL,
3677 					orig_expenditure_org_id = NULL,
3678 					orig_expenditure_type = NULL,
3679 					suspense_reason_code = NULL
3680 				WHERE	suspense_reason_code like 'ES:%'
3681 				AND	enc_summary_line_id IN	(SELECT	enc_summary_line_id
3682 								FROM	psp_enc_summary_lines pesl
3683 								WHERE	pesl.payroll_action_id = p_payroll_action_id
3684 								AND	pesl.group_id = p_group_id
3685 								AND	status_code = 'R');
3686 			END IF;
3687 
3688 			IF l_suspense_ac_not_found = 'Y' THEN
3689 				g_susp_prob := 'Y';
3690 				IF l_susp_exception = 'NO_G_AC' THEN
3691 					RAISE no_global_acct_exists;
3692 				ELSIF l_susp_exception = 'NO_DT_MCH' THEN
3693 					RAISE no_val_date_matches;
3694 				ELSIF l_susp_exception = 'NO_PROFL' THEN
3695 					RAISE no_profile_exists;
3696 				END IF;
3697 			END IF;
3698 
3699 			FORALL recno IN 1..r_interface.status.COUNT
3700 			UPDATE	psp_enc_controls
3701 			SET	gl_phase = 'TieBack'
3702 			WHERE	enc_control_id IN	(SELECT	pesl.enc_control_id
3703 							FROM	psp_enc_summary_lines pesl
3704 							WHERE	pesl.enc_summary_line_id = r_interface.enc_summary_line_id(recno));
3705 
3706 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	TieBack SQL%ROWCOUNT: ' || SQL%ROWCOUNT);
3707 
3708 			FORALL recno IN 1..r_interface.status.COUNT
3709 			UPDATE	psp_enc_controls
3710 			SET	gl_phase = 'Summarize'
3711 			WHERE	enc_control_id IN	(SELECT	pesl.enc_control_id
3712 							FROM	psp_enc_summary_lines pesl
3713 							WHERE	pesl.enc_summary_line_id = r_interface.enc_summary_line_id(recno)
3714 							AND	pesl.status_code = 'N');
3715 
3716 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Summarize SQL%ROWCOUNT: ' || SQL%ROWCOUNT);
3717 		ELSIF (l_cnt_gl_interface = 0) THEN
3718 			OPEN gl_tie_back_success_cur;
3719 			FETCH gl_tie_back_success_cur BULK COLLECT INTO r_interface.enc_summary_line_id, r_interface.enc_control_id, r_interface.dr_cr_flag, r_interface.summary_amount;
3720 			CLOSE gl_tie_back_success_cur;
3721 
3722 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_interface.enc_summary_line_id.COUNT: ' || r_interface.enc_summary_line_id.COUNT);
3723 
3724 			FORALL recno IN 1..r_interface.enc_summary_line_id.COUNT
3725 			UPDATE	psp_enc_summary_lines
3726 			SET	status_code = 'A'
3727 			WHERE	enc_summary_line_id = r_interface.enc_summary_line_id(recno);
3728 
3729 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated status_code to ''A'' in psp_enc_summary_lines');
3730 
3731 			FORALL recno IN 1..r_interface.enc_summary_line_id.COUNT
3732 			INSERT INTO psp_enc_lines_history
3733 				(enc_line_id,			business_group_id,	enc_element_type_id,	encumbrance_date,
3734 				dr_cr_flag,			encumbrance_amount,	status_code,		enc_line_type,
3735 				schedule_line_id,		org_schedule_id,	default_org_account_id,	suspense_org_account_id,
3736 				element_account_id,		gl_project_flag,	enc_summary_line_id,	person_id,
3737 				assignment_id,			award_id,		task_id,		expenditure_type,
3738 				expenditure_organization_id,	project_id,		gl_code_combination_id,	time_period_id,
3739 				payroll_id,			set_of_books_id,	default_reason_code,	suspense_reason_code,
3740 				enc_control_id,			change_flag,		last_update_date,	last_updated_by,
3741 				last_update_login,		created_by,		creation_date,		enc_start_date,
3742 				enc_end_date,			attribute_category,	attribute1,		attribute2,
3743 				attribute3,			attribute4,		attribute5,		attribute6,
3744 				attribute7,			attribute8,		attribute9,		attribute10,
3745 				payroll_action_id,	hierarchy_code,	hierarchy_start_date,	hierarchy_end_date,
3746 				orig_gl_code_combination_id,	orig_project_id,	orig_task_id,	orig_award_id,
3747 				orig_expenditure_org_id,		orig_expenditure_type)
3748 			SELECT	enc_line_id,			business_group_id,	enc_element_type_id,	encumbrance_date,
3749 				dr_cr_flag,			encumbrance_amount,	'A',		enc_line_type,
3750 				schedule_line_id,		org_schedule_id,	default_org_account_id,	suspense_org_account_id,
3751 				element_account_id,		gl_project_flag,	enc_summary_line_id,	person_id,
3752 				assignment_id,			award_id,		task_id,		expenditure_type,
3753 				expenditure_organization_id,	project_id,		gl_code_combination_id,	time_period_id,
3754 				payroll_id,			set_of_books_id,	default_reason_code,	suspense_reason_code,
3755 				enc_control_id,			change_flag,		last_update_date,	last_updated_by,
3756 				last_update_login,		created_by,		creation_date,		enc_start_date,
3757 				enc_end_date,			attribute_category,	attribute1,		attribute2,
3758 				attribute3,			attribute4,		attribute5,		attribute6,
3759 				attribute7,			attribute8,		attribute9,		attribute10,
3760 				payroll_action_id,	hierarchy_code,	hierarchy_start_date,	hierarchy_end_date,
3761 				orig_gl_code_combination_id,	orig_project_id,	orig_task_id,	orig_award_id,
3762 				orig_expenditure_org_id,		orig_expenditure_type
3763 			FROM	psp_enc_lines
3764 			WHERE	enc_summary_line_id = r_interface.enc_summary_line_id(recno);
3765 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Copied successfully summarized and transferred lines into psp_enc_lines_history');
3766 
3767 			FORALL recno IN 1..r_interface.enc_summary_line_id.COUNT
3768 			DELETE FROM psp_enc_lines
3769 			WHERE	enc_summary_line_id = r_interface.enc_summary_line_id(recno);
3770 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted lines from psp_enc_lines that are summarized and trasnferred to target systems');
3771 
3772 			FORALL recno IN 1..r_interface.enc_control_id.COUNT
3773 			UPDATE	psp_enc_controls pec
3774 			SET	gl_phase = 'TieBack',
3775 				summ_gl_dr_amount = NVL(summ_gl_dr_amount, 0) + DECODE(r_interface.dr_cr_flag(recno), 'D', r_interface.summary_amount(recno), 0),
3776 				summ_gl_cr_amount = NVL(summ_gl_cr_amount, 0) + DECODE(r_interface.dr_cr_flag(recno), 'C', r_interface.summary_amount(recno), 0)
3777 			WHERE	enc_control_id = r_interface.enc_control_id(recno);
3778 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated gl_phase, summ_gl_dr_amount, summ_gl_cr_amount in psp_enc_controls');
3779 		END IF;
3780 	ELSE
3781 		g_process_complete := FALSE;
3782 	END IF;
3783 
3784 	p_return_status := fnd_api.g_ret_sts_success;
3785 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GL_ENC_TIE_BACK');
3786 EXCEPTION
3787 	WHEN NO_PROFILE_EXISTS THEN
3788 		g_error_api_path := SUBSTR('GL_ENC_TIE_BACK:'||g_error_api_path,1,230);
3789 		fnd_message.set_name('PSP','PSP_NO_PROFILE_EXISTS');
3790 		fnd_msg_pub.add;
3791 		p_return_status := fnd_api.g_ret_sts_success;
3792 	WHEN NO_VAL_DATE_MATCHES THEN
3793 		g_error_api_path := SUBSTR('GL_ENC_TIE_BACK:'||g_error_api_path,1,230);
3794 		fnd_message.set_name('PSP','PSP_NO_VAL_DATE_MATCHES');
3795 		fnd_message.set_token('ORG_NAME',l_orig_org_name);
3796 		fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
3797 		fnd_msg_pub.add;
3798 		p_return_status := fnd_api.g_ret_sts_success;
3799 	WHEN NO_GLOBAL_ACCT_EXISTS THEN
3800 		g_error_api_path := SUBSTR('GL_ENC_TIE_BACK:'||g_error_api_path,1,230);
3801 		fnd_message.set_name('PSP','PSP_NO_GLOBAL_ACCT_EXISTS');
3802 		fnd_message.set_token('ORG_NAME',l_orig_org_name);
3803 		fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
3804 		fnd_msg_pub.add;
3805 		p_return_status := fnd_api.g_ret_sts_success;
3806 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3807 		g_error_api_path := 'GL_ENC_TIE_BACK:'||g_error_api_path;
3808 		p_return_status := fnd_api.g_ret_sts_unexp_error;
3809 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GL_ENC_TIE_BACK');
3810 	WHEN OTHERS THEN
3811 		g_error_api_path := 'GL_ENC_TIE_BACK:'||g_error_api_path;
3812 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','GL_ENC_TIE_BACK');
3813 		p_return_status := fnd_api.g_ret_sts_unexp_error;
3814 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GL_ENC_TIE_BACK');
3815 END gl_enc_tie_back;
3816 --	End of changes for Create and Update multi thread enh.
3817 
3818 --	##########################################################################
3819 --	This procedure inserts data into gl_interface
3820 --	##########################################################################
3821 
3822 
3823 PROCEDURE insert_into_gl_int (
3824 			P_SET_OF_BOOKS_ID 		IN	NUMBER,
3825 			P_ACCOUNTING_DATE			IN	DATE,
3826 			P_CURRENCY_CODE			IN	VARCHAR2,
3827 			P_USER_JE_CATEGORY_NAME		IN	VARCHAR2,
3828 			P_USER_JE_SOURCE_NAME		IN	VARCHAR2,
3829 			P_ENCUMBRANCE_TYPE_ID		IN	NUMBER,
3830 			P_CODE_COMBINATION_ID		IN	NUMBER,
3831 			P_ENTERED_DR			IN	NUMBER,
3832 			P_ENTERED_CR			IN	NUMBER,
3833 			P_GROUP_ID				IN	NUMBER,
3834 			P_REFERENCE1			IN	VARCHAR2,
3835 			P_REFERENCE2			IN	VARCHAR2,
3836 			P_REFERENCE4			IN	VARCHAR2,
3837 			P_REFERENCE6			IN	VARCHAR2,
3838 			P_REFERENCE10			IN	VARCHAR2,
3839 			P_ATTRIBUTE1			IN	VARCHAR2,
3840 			P_ATTRIBUTE2			IN	VARCHAR2,
3841 			P_ATTRIBUTE3			IN	VARCHAR2,
3842 			P_ATTRIBUTE4			IN	VARCHAR2,
3843 			P_ATTRIBUTE5			IN	VARCHAR2,
3844 			P_ATTRIBUTE6			IN	VARCHAR2,
3845 			P_ATTRIBUTE7			IN	VARCHAR2,
3846 			P_ATTRIBUTE8			IN	VARCHAR2,
3847 			P_ATTRIBUTE9			IN	VARCHAR2,
3848 			P_ATTRIBUTE10			IN	VARCHAR2,
3849 			P_ATTRIBUTE11			IN	VARCHAR2,
3850 			P_ATTRIBUTE12			IN	VARCHAR2,
3851 			P_ATTRIBUTE13			IN	VARCHAR2,
3852 			P_ATTRIBUTE14			IN	VARCHAR2,
3853 			P_ATTRIBUTE15			IN	VARCHAR2,
3854 			P_ATTRIBUTE16			IN	VARCHAR2,
3855 			P_ATTRIBUTE17			IN	VARCHAR2,
3856 			P_ATTRIBUTE18			IN	VARCHAR2,
3857 			P_ATTRIBUTE19			IN	VARCHAR2,
3858 			P_ATTRIBUTE20			IN	VARCHAR2,
3859 			P_ATTRIBUTE21			IN	VARCHAR2,
3860 			P_ATTRIBUTE22			IN	VARCHAR2,
3861 			P_ATTRIBUTE23			IN	VARCHAR2,
3862 			P_ATTRIBUTE24			IN	VARCHAR2,
3863 			P_ATTRIBUTE25			IN	VARCHAR2,
3864 			P_ATTRIBUTE26			IN	VARCHAR2,
3865 			P_ATTRIBUTE27			IN	VARCHAR2,
3866 			P_ATTRIBUTE28			IN	VARCHAR2,
3867 			P_ATTRIBUTE29			IN	VARCHAR2,
3868 			P_ATTRIBUTE30			IN	VARCHAR2,
3869 			P_RETURN_STATUS			OUT NOCOPY	VARCHAR2) IS
3870  BEGIN
3871 
3872    INSERT INTO GL_INTERFACE(
3873 	STATUS,
3874 	SET_OF_BOOKS_ID,
3875 	ACCOUNTING_DATE,
3876 	CURRENCY_CODE,
3877 	DATE_CREATED,
3878 	CREATED_BY,
3879 	ACTUAL_FLAG,
3880 	USER_JE_CATEGORY_NAME,
3881 	USER_JE_SOURCE_NAME,
3882 	ENCUMBRANCE_TYPE_ID,
3883 	CODE_COMBINATION_ID,
3884 	ENTERED_DR,
3885 	ENTERED_CR,
3886 	GROUP_ID,
3887 	REFERENCE1,
3888 	REFERENCE2,
3889 	REFERENCE4,
3890 	REFERENCE6,
3891 	REFERENCE10,
3892 	ATTRIBUTE1,
3893 	ATTRIBUTE2,
3894 	ATTRIBUTE3,
3895 	ATTRIBUTE4,
3896 	ATTRIBUTE5,
3897 	ATTRIBUTE6,
3898 	ATTRIBUTE7,
3899 	ATTRIBUTE8,
3900 	ATTRIBUTE9,
3901 	ATTRIBUTE10,
3902 	ATTRIBUTE11,
3903 	ATTRIBUTE12,
3904 	ATTRIBUTE13,
3905 	ATTRIBUTE14,
3906 	ATTRIBUTE15,
3907 	ATTRIBUTE16,
3908 	ATTRIBUTE17,
3909 	ATTRIBUTE18,
3910 	ATTRIBUTE19,
3911 	ATTRIBUTE20,
3912 	REFERENCE21,
3913 	REFERENCE22,
3914 	REFERENCE23,
3915 	REFERENCE24,
3916 	REFERENCE25,
3917 	REFERENCE26,
3918 	REFERENCE27,
3919 	REFERENCE28,
3920 	REFERENCE29,
3921 	REFERENCE30)
3922    VALUES(
3923 	'NEW',
3924 	P_SET_OF_BOOKS_ID,
3925 	P_ACCOUNTING_DATE,
3926 	P_CURRENCY_CODE,
3927 	SYSDATE,
3928 	FND_GLOBAL.USER_ID,
3929 	'E',
3930 	P_USER_JE_CATEGORY_NAME,
3931 	P_USER_JE_SOURCE_NAME,
3932 	P_ENCUMBRANCE_TYPE_ID,
3933 	P_CODE_COMBINATION_ID,
3934 	P_ENTERED_DR,
3935 	P_ENTERED_CR,
3936 	P_GROUP_ID,
3937 	P_REFERENCE1,
3938 	P_REFERENCE2,
3939 	P_REFERENCE4,
3940 	P_REFERENCE6,
3941 	P_REFERENCE10,
3942 	P_ATTRIBUTE1,
3943 	P_ATTRIBUTE2,
3944 	P_ATTRIBUTE3,
3945 	P_ATTRIBUTE4,
3946 	P_ATTRIBUTE5,
3947 	P_ATTRIBUTE6,
3948 	P_ATTRIBUTE7,
3949 	P_ATTRIBUTE8,
3950 	P_ATTRIBUTE9,
3951 	P_ATTRIBUTE10,
3952 	P_ATTRIBUTE11,
3953 	P_ATTRIBUTE12,
3954 	P_ATTRIBUTE13,
3955 	P_ATTRIBUTE14,
3956 	P_ATTRIBUTE15,
3957 	P_ATTRIBUTE16,
3958 	P_ATTRIBUTE17,
3959 	P_ATTRIBUTE18,
3960 	P_ATTRIBUTE19,
3961 	P_ATTRIBUTE20,
3962 	P_ATTRIBUTE21,
3963 	P_ATTRIBUTE22,
3964 	P_ATTRIBUTE23,
3965 	P_ATTRIBUTE24,
3966 	P_ATTRIBUTE25,
3967 	P_ATTRIBUTE26,
3968 	P_ATTRIBUTE27,
3969 	P_ATTRIBUTE28,
3970 	P_ATTRIBUTE29,
3971 	P_ATTRIBUTE30);
3972 
3973     p_return_status := fnd_api.g_ret_sts_success;
3974 
3975 EXCEPTION
3976    WHEN OTHERS THEN
3977    --   dbms_output.put_line('Error while inserting into gl_interface..........');
3978       g_error_api_path := 'insert_into_gl_int:'||g_error_api_path;
3979       fnd_msg_pub.add_exc_msg('psp_enc_sum_tran','insert_into_gl_int');
3980       p_return_status := fnd_api.g_ret_sts_unexp_error;
3981 
3982 
3983 END;
3984 
3985 --	##########################################################################
3986 --	This procedure summarizes all the lines from psp_enc_lines
3987 --		where gl_project_flag = 'P' and inserts the summarized lines
3988 --			into psp_enc_summary_lines
3989 
3990 --	Depending on the setup options, this procedure groups transactions from
3991 --	PSP_ENC_LINES and inserts the summarized lines into PSP_ENC_SUMMARY_LINES
3992 
3993 --	There are two setup options in PSP_ENC_SETUP_OPTIONS table called 'TIME_BASED_SUMM'
3994 --	and 'CI_BASED_SUMM_OGM' on which the procedure depends.
3995 
3996 --	If the 'TIME_BASED_SUMM' = 1 and 'CI_BASED_SUMM_OGM' = 1
3997 --	then the summarization is done upto the employee level for each time period
3998 
3999 --	If the 'TIME_BASED_SUMM' = 2 and 'CI_BASED_SUMM_OGM' = 1
4000 --	then the summarization is done upto the employee level for each GL period
4001 
4002 --	##########################################################################
4003 
4004 /****	Commented for Create and Update Multi thread
4005 PROCEDURE create_gms_enc_sum_lines(	p_payroll_id IN NUMBER,
4006 					p_return_status	OUT NOCOPY  VARCHAR2
4007 					) IS
4008 
4009 	CURSOR 	enc_control_cur IS
4010    	SELECT 	enc_control_id,
4011           	payroll_id,
4012           	time_period_id
4013    	FROM   	psp_enc_controls
4014    	WHERE 	payroll_id = nvl(p_payroll_id, payroll_id)
4015 	AND	(total_dr_amount IS NOT NULL OR total_cr_amount IS NOT NULL)
4016    	AND	action_type IN ('N', 'Q', 'U') -- Included 'Q' for Quick Upd. Enh. 2143723.
4017    	AND    	action_code = 'I'
4018    	AND    	run_id = g_run_id
4019    	AND	business_group_id = g_business_group_id
4020 	AND	set_of_books_id = g_set_of_books_id
4021         AND     (gms_phase is null or gms_phase = 'TieBack');    --- 2444657
4022 
4023    	CURSOR 	enc_sum_lines_p_cur(
4024 					p_enc_control_id	IN  NUMBER
4025 					)IS
4026    	SELECT
4027 --	ptp.end_date eff_dt,   for bug fix 1971612
4028                 pel.encumbrance_date eff_dt,
4029 		pel.dr_cr_flag,
4030 		sum(pel.encumbrance_amount) sum_amt,
4031 		pel.gl_project_flag,
4032 		pel.person_id,
4033 		pel.assignment_id,	-- Included for Enh. 2143723
4034 		decode(suspense_org_account_id,NULL,pel.project_id,poa.project_id) project_id,
4035 		decode(suspense_org_account_id,NULL,pel.task_id,poa.task_id) task_id ,
4036 		decode(suspense_org_account_id,NULL,pel.award_id,poa.award_id)award_id ,
4037 		decode(suspense_org_account_id,NULL,pel.expenditure_type,poa.expenditure_type) expenditure_type ,
4038 		decode(suspense_org_account_id,NULL,pel.expenditure_organization_id,poa.expenditure_organization_id)
4039 		expenditure_organization_id,
4040 --		Introduced DFF columns for bug fix 2908859
4041 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute_category, poa.attribute_category), NULL) attribute_category,
4042 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute1, poa.attribute1), NULL) attribute1,
4043 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute2, poa.attribute2), NULL) attribute2,
4044 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute3, poa.attribute3), NULL) attribute3,
4045 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute4, poa.attribute4), NULL) attribute4,
4046 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute5, poa.attribute5), NULL) attribute5,
4047 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute6, poa.attribute6), NULL) attribute6,
4048 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute7, poa.attribute7), NULL) attribute7,
4049 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute8, poa.attribute8), NULL) attribute8,
4050 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute9, poa.attribute9), NULL) attribute9,
4051 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute10, poa.attribute10), NULL) attribute10
4052 / *		pel.project_id,
4053 		pel.task_id,
4054 		pel.award_id,
4055 		pel.expenditure_type,
4056 		pel.expenditure_organization_id * /
4057 --		,pai.set_of_books_id
4058    	FROM		PSP_ENC_LINES  		PEL,
4059 			PER_TIME_PERIODS	PTP,
4060 			PSP_ORGANIZATION_ACCOUNTS POA
4061 --			,PA_IMPLEMENTATIONS_ALL	PAI
4062    	WHERE 		PEL.TIME_PERIOD_ID = PTP.TIME_PERIOD_ID
4063 --	AND		PEL.ENCUMBRANCE_DATE BETWEEN PTP.START_DATE AND PTP.END_DATE
4064 --         Commented out for bug fix 1971612
4065 	AND		PEL.GL_PROJECT_FLAG = 'P'
4066    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
4067 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
4068 --	Refined the following condition for bug fix 3233373
4069 	AND		(	(suspense_org_account_id IS NULL AND PEL.AWARD_ID IS NOT NULL)
4070 			OR	(poa.award_id IS NOT NULL))
4071 --	End of bug fix 3233373
4072 	AND		PEL.SUSPENSE_ORG_ACCOUNT_ID = POA.ORGANIZATION_ACCOUNT_ID(+)
4073 --   	AND 		PEL.BUSINESS_GROUP_ID = PAI.BUSINESS_GROUP_ID
4074 --	AND		PAI.SET_OF_BOOKS_ID = g_set_of_books_id
4075 	GROUP BY
4076 --	ptp.end_date,
4077                         pel.encumbrance_date,
4078 --			pel.project_id,
4079 --			pel.task_id,
4080 --			pel.award_id,
4081 --			pel.expenditure_type,
4082 --			pel.expenditure_organization_id,
4083 			DECODE(suspense_org_account_id,NULL,pel.project_id,poa.project_id),
4084 	                DECODE(suspense_org_account_id,NULL,pel.task_id,poa.task_id),
4085         	        DECODE(suspense_org_account_id,NULL,pel.award_id,poa.award_id) ,
4086                 	DECODE(suspense_org_account_id,NULL,pel.expenditure_type,poa.expenditure_type) ,
4087                 	DECODE(suspense_org_account_id,NULL,pel.expenditure_organization_id,poa.expenditure_organization_id),
4088 			pel.person_id,
4089 			pel.assignment_id,	-- Included for Enh. 2143723
4090 			pel.dr_cr_flag,
4091 			pel.gl_project_flag,
4092 --		Introduced DFF columns for bug fix 2908859
4093 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute_category, poa.attribute_category), NULL),
4094 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute1, poa.attribute1), NULL),
4095 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute2, poa.attribute2), NULL),
4096 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute3, poa.attribute3), NULL),
4097 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute4, poa.attribute4), NULL),
4098 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute5, poa.attribute5), NULL),
4099 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute6, poa.attribute6), NULL),
4100 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute7, poa.attribute7), NULL),
4101 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute8, poa.attribute8), NULL),
4102 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute9, poa.attribute9), NULL),
4103 		DECODE(g_dff_grouping_option, 'Y', DECODE(suspense_org_account_id, NULL, pel.attribute10, poa.attribute10), NULL);
4104 --			,pai.set_of_books_id;
4105 
4106 / *
4107 Code commented  out as this  is obsolete now
4108  Bug fix 1971612/1831493
4109 
4110 	CURSOR 	enc_sum_lines_g_cur(
4111 					p_enc_control_id	IN  NUMBER
4112 					) IS
4113    	SELECT 	glp.end_date eff_dt,
4114 		pel.dr_cr_flag,
4115 		sum(pel.encumbrance_amount) sum_amt,
4116 		pel.gl_project_flag,
4117 		pel.person_id,
4118 		pel.project_id,
4119 		pel.task_id,
4120 		pel.award_id,
4121 		pel.expenditure_type,
4122 		pel.expenditure_organization_id,
4123 		pai.set_of_books_id
4124    	FROM		PSP_ENC_LINES  		PEL,
4125 			GL_PERIODS		GLP,
4126 			PA_IMPLEMENTATIONS_ALL	PAI
4127    	WHERE 		PEL.BUSINESS_GROUP_ID = PAI.BUSINESS_GROUP_ID
4128    	AND		GLP.PERIOD_TYPE = PAI.PA_PERIOD_TYPE
4129    	AND 		PEL.ENCUMBRANCE_DATE BETWEEN GLP.START_DATE AND GLP.END_DATE
4130 	AND		PEL.GL_PROJECT_FLAG = 'P'
4131    	AND		PEL.ENCUMBRANCE_AMOUNT <> 0
4132 	AND		PEL.ENC_CONTROL_ID = p_enc_control_id
4133 	AND		PAI.SET_OF_BOOKS_ID = g_set_of_books_id
4134 	AND		PEL.AWARD_ID IS NOT NULL
4135 	GROUP BY	glp.end_date,
4136 			pel.project_id,
4137 			pel.task_id,
4138 			pel.award_id,
4139 			pel.expenditure_type,
4140 			pel.expenditure_organization_id,
4141 			pel.person_id,
4142 			pel.dr_cr_flag,
4143 			pel.gl_project_flag,
4144 			pai.set_of_books_id;
4145 
4146 
4147 	l_time_para_value		VARCHAR2(1);
4148 	l_ogm_para_value			VARCHAR2(1);
4149 
4150 	commented the above variable as part of Enh. 2143723
4151 * /
4152 
4153 	l_bg_id				NUMBER := g_business_group_id;
4154 	enc_control_rec			enc_control_cur%ROWTYPE;
4155      	enc_sum_lines_p_rec		enc_sum_lines_p_cur%ROWTYPE;
4156 
4157 /**************************************************************************
4158 	enc_sum_lines_g_rec		enc_sum_lines_g_cur%ROWTYPE;
4159 
4160  Bug fix 1971613 /Bug 1831493
4161 ***************************************************************************** /
4162 
4163 	l_enc_summary_line_id		NUMBER(10);
4164 	l_return_status			VARCHAR2(10);
4165 	l_error			VARCHAR2(100);
4166 	l_product		VARCHAR2(3);
4167 
4168 BEGIN
4169 
4170 / *	Commented the following code as Enc. Sum. and Tr. setup options are obsolete as part of Enh. 2143723
4171 
4172 	BEGIN
4173 	SELECT 	parameter_value
4174  	INTO	l_time_para_value
4175  	FROM	psp_enc_setup_options
4176  	WHERE	setup_parameter = 'TIME_BASED_SUMM'
4177 	AND	business_group_id = l_bg_id;
4178 	EXCEPTION
4179 		WHEN NO_DATA_FOUND THEN
4180 		l_error := 'TIME_BASED_SUMM';
4181 		l_product := 'PSP';
4182 		fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
4183 		fnd_message.set_token('ERROR',l_error);
4184 		fnd_message.set_token('PRODUCT',l_product);
4185 		fnd_msg_pub.add;
4186 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4187 	END;
4188 
4189 	BEGIN
4190 	SELECT 	parameter_value
4191 	INTO	l_ogm_para_value
4192 	FROM	psp_enc_setup_options
4193 	WHERE	setup_parameter = 'CI_BASED_SUMM_OGM'
4194 	AND	business_group_id = l_bg_id;
4195 	EXCEPTION
4196 		WHEN NO_DATA_FOUND THEN
4197 		l_error := 'CI_BASED_SUMM_OGM';
4198 		l_product := 'PSP';
4199 		fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
4200 		fnd_message.set_token('ERROR',l_error);
4201 		fnd_message.set_token('PRODUCT',l_product);
4202 		fnd_msg_pub.add;
4203 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4204 	END;
4205 
4206      	IF	l_time_para_value = '1' and l_ogm_para_value = '1' THEN
4207 End of Enh. fix 2143723	* /
4208 
4209 	OPEN enc_control_cur;
4210   	LOOP
4211    		FETCH enc_control_cur INTO enc_control_rec;
4212    		IF enc_control_cur%NOTFOUND THEN
4213      		CLOSE enc_control_cur;
4214      		EXIT;
4215    		END IF;
4216 
4217 		OPEN enc_sum_lines_p_cur(enc_control_rec.enc_control_id);
4218 		LOOP
4219 			FETCH enc_sum_lines_p_cur INTO enc_sum_lines_p_rec;
4220     			IF enc_sum_lines_p_cur%ROWCOUNT = 0  THEN
4221        			CLOSE enc_sum_lines_p_cur;
4222        			EXIT;
4223 			ELSIF enc_sum_lines_p_cur%NOTFOUND THEN
4224                 	   update psp_enc_controls
4225                    	      set gms_phase = 'Summarize'  ---NULL commented for 2444657
4226                  	    where enc_control_id = enc_control_rec.enc_control_id;
4227        			CLOSE enc_sum_lines_p_cur;
4228        			EXIT;
4229      			END IF;
4230 
4231 			IF enc_sum_lines_p_rec.dr_cr_flag = 'C' THEN
4232 				enc_sum_lines_p_rec.sum_amt := 0 - enc_sum_lines_p_rec.sum_amt;
4233 			END IF;
4234     				insert_into_enc_sum_lines(
4235 							l_enc_summary_line_id,
4236 							L_BG_ID,
4237 							enc_control_rec.enc_control_id,
4238 							enc_control_rec.time_period_id,
4239 							enc_sum_lines_p_rec.person_id,
4240 							enc_sum_lines_p_rec.assignment_id, --Included for Enh. 2143723
4241                 					enc_sum_lines_p_rec.eff_dt,
4242 --							enc_sum_lines_p_rec.set_of_books_id,
4243 							g_set_of_books_id,
4244 							NULL,
4245  							enc_sum_lines_p_rec.project_id,
4246  							enc_sum_lines_p_rec.expenditure_organization_id,
4247  							enc_sum_lines_p_rec.expenditure_type,
4248 							enc_sum_lines_p_rec.task_id,
4249  							enc_sum_lines_p_rec.award_id,
4250  							enc_sum_lines_p_rec.sum_amt,
4251  							enc_sum_lines_p_rec.dr_cr_flag,
4252 							'N',
4253 							enc_control_rec.payroll_id,
4254  							NULL,
4255 							enc_sum_lines_p_rec.gl_project_flag,
4256 							enc_sum_lines_p_rec.attribute_category,	-- Introduced DFF columns for bug fix 2908859
4257 							enc_sum_lines_p_rec.attribute1,
4258 							enc_sum_lines_p_rec.attribute2,
4259 							enc_sum_lines_p_rec.attribute3,
4260 							enc_sum_lines_p_rec.attribute4,
4261 							enc_sum_lines_p_rec.attribute5,
4262 							enc_sum_lines_p_rec.attribute6,
4263 							enc_sum_lines_p_rec.attribute7,
4264 							enc_sum_lines_p_rec.attribute8,
4265 							enc_sum_lines_p_rec.attribute9,
4266 							enc_sum_lines_p_rec.attribute10,
4267 							p_return_status);
4268 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4269          			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4270 				END IF;
4271 
4272 			IF (g_dff_grouping_option = 'N') THEN	-- Introduced for bug fix 2908859
4273 				UPDATE 	psp_enc_lines
4274          			SET 	enc_summary_line_id = l_enc_summary_line_id
4275          			WHERE 	-- project_id = enc_sum_lines_p_rec.project_id	Commented for bug fix 3194807
4276 --	Introduced the suspense_org_account verification for bug fix 3194807
4277 					(	(suspense_org_account_id IS NOT NULL
4278 						AND	suspense_reason_code like 'ES:%'
4279 						AND	EXISTS	(SELECT	1	FROM psp_organization_accounts poa
4280 								WHERE	poa.organization_account_id = suspense_org_account_id
4281 								AND	poa.project_id = enc_sum_lines_p_rec.project_id
4282 								AND	poa.task_id = enc_sum_lines_p_rec.task_id
4283 								AND	poa.expenditure_organization_id = enc_sum_lines_p_rec.expenditure_organization_id
4284 								AND	poa.expenditure_type = enc_sum_lines_p_rec.expenditure_type
4285 								AND	poa.award_id = enc_sum_lines_p_rec.award_id))
4286 					OR	(project_id = enc_sum_lines_p_rec.project_id
4287 						AND	task_id = enc_sum_lines_p_rec.task_id
4288 						AND	expenditure_organization_id = enc_sum_lines_p_rec.expenditure_organization_id
4289 						AND	expenditure_type = enc_sum_lines_p_rec.expenditure_type
4290 						AND	award_id = enc_sum_lines_p_rec.award_id))
4291 --         		AND	task_id = enc_sum_lines_p_rec.task_id	Commented for bug fix 3194807
4292 				AND	enc_control_id = enc_control_rec.enc_control_id
4293 				AND	time_period_id = enc_control_rec.time_period_id
4294 	--         		AND	award_id = enc_sum_lines_p_rec.award_id	Commented for bug fix 3194807
4295 --         		AND	expenditure_type = enc_sum_lines_p_rec.expenditure_type	Commented for bug fix 3194807
4296 --         		AND	expenditure_organization_id = enc_sum_lines_p_rec.expenditure_organization_id	Commented for bug fix 3194807
4297          			AND	person_id = enc_sum_lines_p_rec.person_id
4298 --	Included the following chek for Enh. 2143723
4299          			AND	assignment_id = enc_sum_lines_p_rec.assignment_id
4300          			AND	dr_cr_flag = enc_sum_lines_p_rec.dr_cr_flag
4301          			AND	gl_project_flag = enc_sum_lines_p_rec.gl_project_flag
4302                         	AND     trunc(encumbrance_date) = trunc(enc_sum_lines_p_rec.eff_dt);   ---- bug 3462452
4303 		--	AND	set_of_books_id = enc_sum_lines_p_rec.set_of_books_id;
4304 --	Introduced ELSE portion for bug fix 2908859
4305 			ELSE
4306 				UPDATE 	psp_enc_lines
4307          			SET 	enc_summary_line_id = l_enc_summary_line_id
4308          			WHERE 	enc_control_id = enc_control_rec.enc_control_id
4309          			AND	payroll_id = enc_control_rec.payroll_id
4310 				AND	time_period_id = enc_control_rec.time_period_id
4311          			AND	person_id = enc_sum_lines_p_rec.person_id
4312          			AND	assignment_id = enc_sum_lines_p_rec.assignment_id
4313          			AND	dr_cr_flag = enc_sum_lines_p_rec.dr_cr_flag
4314          			AND	gl_project_flag = enc_sum_lines_p_rec.gl_project_flag
4315                         	AND     trunc(encumbrance_date) = trunc(enc_sum_lines_p_rec.eff_dt)  --- added for 3462452
4316 				AND	(	(suspense_org_account_id IS NOT NULL
4317 						AND	suspense_reason_code like 'ES:%'
4318 						AND	EXISTS	(SELECT	1	FROM psp_organization_accounts poa
4319 								WHERE	poa.organization_account_id = suspense_org_account_id
4320 								AND	poa.project_id = enc_sum_lines_p_rec.project_id
4321 								AND	poa.task_id = enc_sum_lines_p_rec.task_id
4322 								AND	poa.expenditure_organization_id = enc_sum_lines_p_rec.expenditure_organization_id
4323 								AND	poa.expenditure_type = enc_sum_lines_p_rec.expenditure_type
4324 								AND	poa.award_id = enc_sum_lines_p_rec.award_id
4325 								AND	NVL(poa.attribute_category, 'NULL') =
4326 									NVL(enc_sum_lines_p_rec.attribute_category, 'NULL')
4327 								AND	NVL(poa.attribute1, 'NULL') = NVL(enc_sum_lines_p_rec.attribute1, 'NULL')
4328 								AND	NVL(poa.attribute2, 'NULL') = NVL(enc_sum_lines_p_rec.attribute2, 'NULL')
4329 								AND	NVL(poa.attribute3, 'NULL') = NVL(enc_sum_lines_p_rec.attribute3, 'NULL')
4330 								AND	NVL(poa.attribute4, 'NULL') = NVL(enc_sum_lines_p_rec.attribute4, 'NULL')
4331 								AND	NVL(poa.attribute5, 'NULL') = NVL(enc_sum_lines_p_rec.attribute5, 'NULL')
4332 								AND	NVL(poa.attribute6, 'NULL') = NVL(enc_sum_lines_p_rec.attribute6, 'NULL')
4333 								AND	NVL(poa.attribute7, 'NULL') = NVL(enc_sum_lines_p_rec.attribute7, 'NULL')
4334 								AND	NVL(poa.attribute8, 'NULL') = NVL(enc_sum_lines_p_rec.attribute8, 'NULL')
4335 								AND	NVL(poa.attribute9, 'NULL') = NVL(enc_sum_lines_p_rec.attribute9, 'NULL')
4336 								AND	NVL(poa.attribute10, 'NULL') = NVL(enc_sum_lines_p_rec.attribute10, 'NULL')))
4337 					OR (	project_id = enc_sum_lines_p_rec.project_id
4338 						AND	task_id = enc_sum_lines_p_rec.task_id
4339 						AND	expenditure_organization_id = enc_sum_lines_p_rec.expenditure_organization_id
4340 						AND	expenditure_type = enc_sum_lines_p_rec.expenditure_type
4341 						AND	award_id = enc_sum_lines_p_rec.award_id
4342 						AND	NVL(attribute_category, 'NULL') = NVL(enc_sum_lines_p_rec.attribute_category, 'NULL')
4343 						AND	NVL(attribute1, 'NULL') = NVL(enc_sum_lines_p_rec.attribute1, 'NULL')
4344 						AND	NVL(attribute2, 'NULL') = NVL(enc_sum_lines_p_rec.attribute2, 'NULL')
4345 						AND	NVL(attribute3, 'NULL') = NVL(enc_sum_lines_p_rec.attribute3, 'NULL')
4346 						AND	NVL(attribute4, 'NULL') = NVL(enc_sum_lines_p_rec.attribute4, 'NULL')
4347 						AND	NVL(attribute5, 'NULL') = NVL(enc_sum_lines_p_rec.attribute5, 'NULL')
4348 						AND	NVL(attribute6, 'NULL') = NVL(enc_sum_lines_p_rec.attribute6, 'NULL')
4349 						AND	NVL(attribute7, 'NULL') = NVL(enc_sum_lines_p_rec.attribute7, 'NULL')
4350 						AND	NVL(attribute8, 'NULL') = NVL(enc_sum_lines_p_rec.attribute8, 'NULL')
4351 						AND	NVL(attribute9, 'NULL') = NVL(enc_sum_lines_p_rec.attribute9, 'NULL')
4352 						AND	NVL(attribute10, 'NULL') = NVL(enc_sum_lines_p_rec.attribute10, 'NULL')));
4353 --	Introduced ELSE portion for bug fix 2908859
4354 			END IF;
4355      		END LOOP;
4356 
4357 	END LOOP;
4358 
4359 
4360 / *********************************************************************************************
4361 
4362  THe Summarize  by gl _period option is obsolete nad no longer supported  , refer bug
4363 	ELSIF	l_time_para_value = '2' and l_ogm_para_value = '1' THEN
4364 
4365 	OPEN enc_control_cur;
4366   	LOOP
4367    		FETCH enc_control_cur INTO enc_control_rec;
4368    		IF enc_control_cur%NOTFOUND THEN
4369      		CLOSE enc_control_cur;
4370      		EXIT;
4371    		END IF;
4372 
4373 		OPEN enc_sum_lines_g_cur(enc_control_rec.enc_control_id);
4374 		LOOP
4375      			FETCH enc_sum_lines_g_cur INTO enc_sum_lines_g_rec;
4376 			IF enc_sum_lines_g_cur%ROWCOUNT = 0 THEN
4377 			  CLOSE enc_sum_lines_g_cur;
4378 			  EXIT;
4379      			ELSIF enc_sum_lines_g_cur%NOTFOUND THEN
4380                 	   update psp_enc_controls
4381                    	      set gms_phase = NULL
4382                  	    where enc_control_id = enc_control_rec.enc_control_id;
4383        			CLOSE enc_sum_lines_g_cur;
4384        			EXIT;
4385      			END IF;
4386    				insert_into_enc_sum_lines(
4387 							l_enc_summary_line_id,
4388 							l_bg_id,
4389 							enc_control_rec.enc_control_id,
4390 							enc_control_rec.time_period_id,
4391 							enc_sum_lines_g_rec.person_id,
4392                 					NULL,
4393                 					enc_sum_lines_g_rec.eff_dt,
4394 							enc_sum_lines_g_rec.set_of_books_id,
4395 							NULL,
4396 							enc_sum_lines_g_rec.project_id,
4397  							enc_sum_lines_g_rec.expenditure_organization_id,
4398  							enc_sum_lines_g_rec.expenditure_type,
4399  							enc_sum_lines_g_rec.task_id,
4400  							enc_sum_lines_g_rec.award_id,
4401  							enc_sum_lines_g_rec.sum_amt,
4402  							enc_sum_lines_g_rec.dr_cr_flag,
4403 							'N',
4404 							enc_control_rec.payroll_id,
4405  							NULL,
4406 							enc_sum_lines_g_rec.gl_project_flag,
4407 							l_return_status);
4408      				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4409          			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4410 				END IF;
4411 
4412 			UPDATE 	psp_enc_lines
4413          		SET 	enc_summary_line_id = l_enc_summary_line_id
4414          		WHERE 	project_id = enc_sum_lines_g_rec.project_id
4415          		AND	task_id = enc_sum_lines_g_rec.task_id
4416 			AND	enc_control_id = enc_control_rec.enc_control_id
4417 			AND	time_period_id = enc_control_rec.time_period_id
4418          		AND	award_id = enc_sum_lines_g_rec.award_id
4419          		AND	expenditure_type = enc_sum_lines_g_rec.expenditure_type
4420          		AND	expenditure_organization_id = enc_sum_lines_g_rec.expenditure_organization_id
4421          		AND	person_id = enc_sum_lines_g_rec.person_id
4422          		AND	dr_cr_flag = enc_sum_lines_g_rec.dr_cr_flag
4423          		AND	gl_project_flag = enc_sum_lines_g_rec.gl_project_flag;
4424 			--AND	set_of_books_id = enc_sum_lines_g_rec.set_of_books_id;
4425        		END LOOP;
4426 
4427 	END LOOP;
4428 	END IF; Commented this END IF as part of Enh. 2143723
4429 ********************************************************************************** /
4430 
4431 	--COMMIT;
4432 	p_return_status	:= fnd_api.g_ret_sts_success;
4433 
4434 EXCEPTION
4435 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4436      		g_error_api_path := 'CREATE_GMS_ENC_SUM_LINES:'||g_error_api_path;
4437      		p_return_status := fnd_api.g_ret_sts_unexp_error;
4438 
4439 	WHEN OTHERS THEN
4440      		g_error_api_path := 'CREATE_GMS_ENC_SUM_LINES:'||g_error_api_path;
4441      		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','CREATE_GMS_ENC_SUM_LINES');
4442      		p_return_status := fnd_api.g_ret_sts_unexp_error;
4443 
4444 END;
4445 	End of comment for Create and Update multi thread	*****/
4446 
4447 --	##########################################################################
4448 --	This procedure transfers summarized lines from psp_enc_summary_lines
4449 --		with gl_project_flag = 'P' to pa_transaction_interface
4450 
4451 --	This procedure transfers lines from PSP_ENC_SUMMARY_LINES into PA_TRANSACTION_INTERFACE,
4452 --	kicks off the TRANSACTION IMPORT program in GMS and sends ENC_CONTROL_ID, END_DATE for
4453 --	the relevant TIME_PERIOD_ID and GMS_BATCH_NAME into the tie back procedure.
4454 --	##########################################################################
4455 --	Introduced the following modified procedure for Create and Update multi thread
4456 PROCEDURE tr_to_gms_int(p_payroll_action_id    IN NUMBER,
4457 			p_return_status	OUT NOCOPY  VARCHAR2) IS
4458 l_tr_source			VARCHAR2(30);
4459 l_exp_end_dt			DATE;
4460 l_return_status			VARCHAR2(50);
4461 req_id				NUMBER(15);
4462 call_status			BOOLEAN;
4463 rphase				VARCHAR2(30);
4464 rstatus				VARCHAR2(30);
4465 dphase				VARCHAR2(30);
4466 dstatus				VARCHAR2(30);
4467 message				VARCHAR2(240);
4468 p_errbuf			VARCHAR2(32767);
4469 p_retcode			VARCHAR2(32767);
4470 return_back			EXCEPTION;
4471 l_rec_count			NUMBER;
4472 l_error				VARCHAR2(100);
4473 l_product			VARCHAR2(3);
4474 l_value				VARCHAR2(200);
4475 l_table				VARCHAR2(100);
4476 l_rec_no			NUMBER;
4477 l_effective_date		DATE;
4478 l_tie_back_failed		VARCHAR2(1);
4479 l_gms_batch_name		VARCHAR2(10);
4480 l_raise_error			BOOLEAN;
4481 
4482 CURSOR	int_cur IS
4483 SELECT	pa_txn_interface_s.NEXTVAL,
4484 	pesl.enc_summary_line_id,
4485 	pesl.effective_date,
4486 	pesl.time_period_id,
4487 	pesl.person_id,
4488 	pesl.project_id,
4489 	pesl.task_id,
4490 	pesl.award_id,
4491 	pesl.expenditure_type,
4492 	pesl.expenditure_organization_id,
4493 	DECODE(pec.uom, 'M', g_currency_code, 'STAT') currency_code,
4494 	TO_NUMBER(DECODE(pec.uom, 'H', pesl.summary_amount, 1)) quantity,
4495 	TO_NUMBER(DECODE(pec.uom, 'M', pesl.summary_amount, 0)) summary_amount,
4496 	pesl.dr_cr_flag,
4497 	pesl.attribute2,
4498 	pesl.attribute3,
4499 	pesl.attribute6,
4500 	pesl.attribute7,
4501 	pesl.attribute8,
4502 	pesl.attribute9,
4503 	pesl.attribute10,
4504 	pesl.expenditure_item_id,
4505 	hou.name exp_org_name,
4506 	ppa.segment1 project_number,
4507 	ppa.org_id operating_unit,
4508 	pt.task_number,
4509 	TO_CHAR(pesl.enc_control_id) || ':' || ptp.period_name expenditure_comment,
4510 	ptp.period_name,
4511 	ptp.end_date,
4512 	pesl.effective_date,
4513 	pesl.gms_batch_name,
4514 	DECODE(pec.uom, 'H', DECODE(SIGN(summary_amount), -1, 'Y')) unmatched_nve_txn_flag  --6242618
4515 FROM	psp_enc_summary_lines pesl,
4516 	hr_organization_units hou,
4517 	pa_projects_all ppa,
4518 	pa_tasks pt,
4519 	per_time_periods ptp,
4520 	psp_enc_controls pec
4521 WHERE 	pec.payroll_action_id = p_payroll_action_id
4522 AND	pec.enc_control_id = pesl.enc_control_id
4523 AND	pesl.status_code = 'N'
4524 AND	pesl.gl_code_combination_id IS NULL
4525 AND	pesl.award_id IS NOT NULL
4526 AND	pesl.superceded_line_id IS NULL
4527 AND	pesl.expenditure_organization_id = hou.organization_id (+)
4528 AND	pesl.project_id = ppa.project_id (+)
4529 AND	pesl.task_id = pt.task_id (+)
4530 AND	pesl.time_period_id = ptp.time_period_id
4531 AND	gms_batch_name IS NOT NULL;
4532 
4533 TYPE GMS_TIE_RECTYPE IS RECORD
4534 	(R_CONTROL_ID		NUMBER,
4535 	R_END_DATE		DATE,
4536 	R_GMS_BATCH_NAME	VARCHAR2(80));
4537 
4538 GMS_TIE_REC     GMS_TIE_RECTYPE;
4539 
4540 TYPE GMS_TIE_TABTYPE IS TABLE OF GMS_TIE_REC%TYPE INDEX BY BINARY_INTEGER;
4541 
4542 GMS_TIE_TAB     GMS_TIE_TABTYPE;
4543 gms_rec		gms_transaction_interface_all%ROWTYPE;
4544 l_txn_source	varchar2(30);
4545 l_gms_transaction_source VARCHAR2(30);
4546 l_org_id	NUMBER(15);
4547 l_txn_interface_id	NUMBER;
4548 l_gms_install	BOOLEAN	DEFAULT	gms_install.enabled;
4549 
4550 TYPE t_number IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
4551 TYPE t_number_15 IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
4552 TYPE t_char_300 IS TABLE OF VARCHAR2(300) INDEX BY BINARY_INTEGER;
4553 TYPE t_date IS TABLE OF DATE INDEX BY BINARY_INTEGER;
4554 
4555 TYPE r_enc_control_rec IS RECORD (enc_control_id	t_number_15);
4556 r_enc_controls	r_enc_control_rec;
4557 
4558 CURSOR	enc_control_id_cur IS
4559 SELECT	DISTINCT enc_control_id
4560 FROM	psp_enc_summary_lines
4561 WHERE	payroll_action_id = p_payroll_action_id
4562 AND	superceded_line_id IS NULL
4563 AND	gms_batch_name IS NOT NULL;
4564 
4565 CURSOR	transaction_source_cur IS
4566 SELECT	transaction_source
4567 FROM	pa_transaction_sources
4568 WHERE	transaction_source = 'GOLDE';
4569 
4570 CURSOR	gms_batch_name_cur IS
4571 SELECT	DISTINCT gms_batch_name
4572 FROM	psp_enc_summary_lines pesl
4573 WHERE	payroll_action_id = p_payroll_action_id
4574 AND	status_code = 'N'
4575 AND	superceded_line_id IS NULL
4576 AND	gl_code_combination_id IS NULL;
4577 
4578 CURSOR	employee_number_cur IS
4579 SELECT	DISTINCT pesl.person_id,
4580 	papf.employee_number
4581 FROM	per_all_people_f papf,
4582 	psp_enc_summary_lines pesl
4583 WHERE	pesl.payroll_action_id = p_payroll_action_id
4584 AND	papf.person_id = pesl.person_id
4585 AND	pesl.superceded_line_id IS NULL
4586 AND	pesl.gms_batch_name IS NOT NULL
4587 AND	pesl.effective_date BETWEEN papf.effective_start_date AND papf.effective_end_date;
4588 
4589 TYPE r_gms_batch_rec IS RECORD (gms_batch_name	t_char_300);
4590 r_gms_batch	r_gms_batch_rec;
4591 
4592 TYPE t_person IS RECORD
4593 	(person_id	t_number_15,
4594 	employee_number	t_char_300);
4595 r_person	t_person;
4596 
4597 TYPE t_interface IS RECORD
4598 	(txn_interface_id		t_number_15,
4599 	enc_summary_line_id		t_number_15,
4600 	effective_date			t_date,
4601 	time_period_id			t_number_15,
4602 	person_id			t_number_15,
4603 	project_id			t_number_15,
4604 	task_id				t_number_15,
4605 	award_id			t_number_15,
4606 	expenditure_type		t_char_300,
4607 	expenditure_organization_id	t_number_15,
4608 	currency_code			t_char_300,
4609 	quantity			t_number,
4610 	summary_amount			t_number,
4611 	unmatched_nve_txn_flag		t_char_300,
4612 	dr_cr_flag			t_char_300,
4613 	attribute2			t_char_300,
4614 	attribute3			t_char_300,
4615 	attribute6			t_char_300,
4616 	attribute7			t_char_300,
4617 	attribute8			t_char_300,
4618 	attribute9			t_char_300,
4619 	attribute10			t_char_300,
4620 	expenditure_item_id		t_number_15,
4621 	employee_number			t_char_300,
4622 	exp_org_name			t_char_300,
4623 	project_number			t_char_300,
4624 	operating_unit			t_char_300,
4625 	task_number			t_char_300,
4626 	expenditure_comment		t_char_300,
4627 	period_name			t_char_300,
4628 	end_date			t_date,
4629 	gms_overriding_date		t_date,
4630 	exp_end_date			t_date,
4631 	gms_batch_name                  t_char_300);
4632 
4633 r_interface	t_interface;
4634 
4635  -- R12 MOAC Uptake
4636 TYPE org_id_type IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
4637 org_id_tab    org_id_type;
4638 
4639 TYPE gms_batch_name_type IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER;
4640 gms_batch_name_tab gms_batch_name_type;
4641 
4642 TYPE req_id_TYPE is TABLE OF 	NUMBER(15) INDEX BY BINARY_INTEGER;
4643 req_id_tab req_id_TYPE;
4644 
4645 TYPE call_status_TYPE IS TABLE OF BOOLEAN INDEX BY BINARY_INTEGER;
4646 call_status_tab call_status_TYPE;
4647 
4648 CURSOR	operating_unit_csr IS
4649 SELECT	DISTINCT org_id
4650 FROM	psp_enc_summary_lines
4651 WHERE	status_code = 'N'
4652 AND	gl_code_combination_id IS NULL
4653 AND	gms_batch_name IS NULL
4654 AND	payroll_action_id = p_payroll_action_id;
4655 
4656 BEGIN
4657 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering TR_TO_GMS_INT');
4658 
4659 	l_tie_back_failed:= NULL;
4660 	l_rec_no := 0;
4661 	l_rec_count := 0;
4662 
4663 	IF (l_gms_install) THEN
4664 		OPEN transaction_source_cur;
4665 		FETCH transaction_source_cur INTO l_gms_transaction_source;
4666 		CLOSE transaction_source_cur;
4667 
4668 		IF (l_gms_transaction_source IS NULL) THEN
4669 			fnd_message.set_name('PSP','PSP_TR_NOT_SET_UP');
4670 			fnd_message.set_token('ERROR','TRANSACTION SOURCE = GOLDE');
4671 			fnd_message.set_token('PRODUCT','GMS');
4672 			fnd_msg_pub.add;
4673 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4674 		END IF;
4675 	END IF;
4676 
4677 	 -- R12 MOAC Uptake
4678 	org_id_tab.delete;
4679 	gms_batch_name_tab.delete;
4680 	req_id_tab.delete;
4681 	call_status_tab.delete;
4682 
4683 	OPEN operating_unit_csr;
4684 	FETCH operating_unit_csr BULK COLLECT INTO org_id_tab;
4685 	CLOSE operating_unit_csr;
4686 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	org_id_tab.COUNT: ' || org_id_tab.COUNT);
4687 
4688 	FOR I in 1..org_id_tab.COUNT
4689 	LOOP
4690 		SELECT	TO_CHAR(psp_gms_batch_name_s.NEXTVAL)
4691 		INTO	gms_batch_name_tab(i)
4692 		FROM	DUAL;
4693 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	gms_batch_name_tab(' || I || '): ' || gms_batch_name_tab(i));
4694 	END LOOP;
4695 
4696 
4697 	FORALL I IN 1..org_id_tab.count
4698 	UPDATE	psp_enc_summary_lines pesl
4699 	SET	gms_batch_name = gms_batch_name_tab(i)
4700 	WHERE	status_code = 'N'
4701 	AND	gl_code_combination_id IS NULL
4702 	AND	gms_batch_name IS NULL
4703 	ANd	superceded_line_id IS NULL
4704 	AND	NOT EXISTS	(SELECT	1
4705 				FROM	psp_enc_summary_lines pesl2
4706 				WHERE	pesl2.payroll_action_id = p_payroll_action_id
4707 				AND	pesl2.assignment_id = pesl.assignment_id
4708 				AND	pesl2.time_period_id = pesl.time_period_id
4709 				AND	pesl2.status_code IN ('N', 'R')
4710 				AND	pesl2.superceded_line_id IS NOT NULL)
4711 	AND	payroll_action_id = p_payroll_action_id
4712 	AND     org_id = org_id_tab(i);
4713 
4714 	OPEN int_cur;
4715 	FETCH int_cur BULK COLLECT INTO r_interface.txn_interface_id,	r_interface.enc_summary_line_id,
4716 		r_interface.effective_date,		r_interface.time_period_id,
4717 		r_interface.person_id,			r_interface.project_id,
4718 		r_interface.task_id,			r_interface.award_id,
4719 		r_interface.expenditure_type,		r_interface.expenditure_organization_id,
4720 		r_interface.currency_code,		r_interface.quantity,
4721 		r_interface.summary_amount,		r_interface.dr_cr_flag,
4722 		r_interface.attribute2,			r_interface.attribute3,
4723 		r_interface.attribute6,			r_interface.attribute7,
4724 		r_interface.attribute8,			r_interface.attribute9,
4725 		r_interface.attribute10,		r_interface.expenditure_item_id,
4726 		r_interface.exp_org_name,		r_interface.project_number,
4727 		r_interface.operating_unit,		r_interface.task_number,
4728 		r_interface.expenditure_comment,	r_interface.period_name,
4729 		r_interface.end_date,			r_interface.gms_overriding_date,
4730 		r_interface.gms_batch_name,r_interface.unmatched_nve_txn_flag;
4731 	CLOSE int_cur;
4732 
4733 /*
4734 	FOR I IN 1..r_interface.txn_interface_id.count
4735 	LOOP
4736 		FOR J IN 1..org_id_tab.count
4737 		LOOP
4738 			IF org_id_tab(J) = r_interface.operating_unit(I) THEN
4739 				r_interface.gms_batch_name(I) := gms_batch_name_tab(J);
4740 				EXIT;
4741 			END IF;
4742 		END LOOP;
4743 	END LOOP;
4744 */
4745 
4746 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_interface.txn_interface_id.COUNT: ' || r_interface.txn_interface_id.COUNT);
4747 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Verifying interface records for errors');
4748 
4749 	OPEN employee_number_cur;
4750 	FETCH employee_number_cur BULK COLLECT INTO r_person.person_id, r_person.employee_number;
4751 	CLOSE employee_number_cur;
4752 
4753 	l_raise_error := FALSE;
4754 	FOR recno IN 1..r_interface.txn_interface_id.COUNT
4755 	LOOP
4756 		FOR emp_recno IN 1..r_person.person_id.COUNT
4757 		LOOP
4758 			IF (r_interface.person_id(recno) = r_person.person_id(emp_recno)) THEN
4759 				r_interface.employee_number(recno) := r_person.employee_number(emp_recno);
4760 				EXIT;
4761 			END IF;
4762 		END LOOP;
4763 
4764 		IF r_interface.employee_number(recno) IS NULL THEN
4765 			fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
4766 			fnd_message.set_token('VALUE', 'person_id: ' || r_interface.person_id(recno));
4767 			fnd_message.set_token('TABLE', 'PER_PEOPLE_F');
4768 			fnd_msg_pub.add;
4769 			l_raise_error := TRUE;
4770 		END IF;
4771 
4772 		IF r_interface.exp_org_name(recno) IS NULL THEN
4773 			fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
4774 			fnd_message.set_token('VALUE', 'org_id: ' || r_interface.expenditure_organization_id(recno));
4775 			fnd_message.set_token('TABLE', 'HR_ORGANIZATION_UNITS');
4776 			fnd_msg_pub.add;
4777 			l_raise_error := TRUE;
4778 		END IF;
4779 
4780 		IF r_interface.operating_unit(recno) IS NULL THEN
4781 			fnd_message.set_name('PSP','PSP_ORG_VALUE_NOT_FOUND');
4782 			fnd_message.set_token('VALUE', 'project_id: ' || r_interface.project_id(recno));
4783 			fnd_message.set_token('TABLE', 'PA_PROJECTS_ALL');
4784 			fnd_msg_pub.add;
4785 			l_raise_error := TRUE;
4786 		END IF;
4787 
4788 		IF r_interface.project_number(recno) IS NULL THEN
4789 			fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
4790 			fnd_message.set_token('VALUE', 'project_id: ' || r_interface.project_id(recno));
4791 			fnd_message.set_token('TABLE', 'PA_PROJECTS_ALL');
4792 			fnd_msg_pub.add;
4793 			l_raise_error := TRUE;
4794 		END IF;
4795 
4796 		IF r_interface.task_number(recno) IS NULL THEN
4797 			fnd_message.set_name('PSP','PSP_TR_VALUE_NOT_FOUND');
4798 			fnd_message.set_token('VALUE', 'task_id: ' || r_interface.task_id(recno));
4799 			fnd_message.set_token('TABLE', 'PA_TASKS');
4800 			fnd_msg_pub.add;
4801 			l_raise_error := TRUE;
4802 		END IF;
4803 	END LOOP;
4804 
4805 	IF l_raise_error THEN
4806 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Interface records have errors');
4807 		RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4808 	END IF;
4809 
4810 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Completed interface records for errors');
4811 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Computing PA week ending date(s)');
4812 
4813 	FOR recno IN 1..r_interface.txn_interface_id.COUNT
4814 	LOOP
4815 		psp_general.get_gms_effective_date(r_interface.person_id(recno), r_interface.gms_overriding_date(recno));
4816 		-- set the context to single to call pa_utils function
4817 		mo_global.set_policy_context('S', r_interface.operating_unit(recno) );
4818 		r_interface.exp_end_date(recno) := pa_utils.getweekending(r_interface.gms_overriding_date(recno));
4819 	END LOOP;
4820 	-- set the context again to multiple
4821 	mo_global.set_policy_context('M', null);
4822 
4823 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Completed computation of PA week ending date(s)');
4824 
4825 	FORALL recno IN 1..r_interface.txn_interface_id.COUNT
4826 	UPDATE	psp_enc_summary_lines pesl
4827 	SET	gms_posting_override_date = r_interface.gms_overriding_date(recno)
4828 	WHERE	pesl.enc_summary_line_id = r_interface.enc_summary_line_id(recno)
4829 	AND	TRUNC(r_interface.effective_date(recno)) <> TRUNC(r_interface.gms_overriding_date(recno));
4830 
4831 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated GMS Override Date');
4832 
4833 	FORALL recno IN 1..r_interface.txn_interface_id.COUNT
4834 	INSERT INTO pa_transaction_interface_all
4835 		(txn_interface_id,				transaction_source,
4836 		batch_name,					expenditure_ending_date,
4837 		employee_number,				organization_name,
4838 		expenditure_item_date,				project_number,
4839 		task_number,					expenditure_type,
4840 		quantity,					raw_cost,
4841 		expenditure_comment,				transaction_status_code,
4842 		orig_transaction_reference,			org_id,
4843 		denom_currency_code,				denom_raw_cost,
4844 		attribute1,					attribute2,
4845 		attribute3,					attribute6,
4846 		attribute7,					attribute8,
4847 		attribute9,					attribute10,
4848 		person_business_group_id,unmatched_negative_txn_flag)
4849 	VALUES	(r_interface.txn_interface_id(recno),		l_gms_transaction_source,
4850 		r_interface.gms_batch_name(recno),		r_interface.exp_end_date(recno),
4851 		r_interface.employee_number(recno),		r_interface.exp_org_name(recno),
4852 		r_interface.gms_overriding_date(recno),		r_interface.project_number(recno),
4853 		r_interface.task_number(recno),			r_interface.expenditure_type(recno),
4854 		1,						r_interface.summary_amount(recno),
4855 		r_interface.expenditure_comment(recno),		'P',
4856 		'E:' || r_interface.enc_summary_line_id(recno),	r_interface.operating_unit(recno),
4857 		g_currency_code,				r_interface.summary_amount(recno),
4858 		NULL,						NULL,
4859 		r_interface.attribute3(recno),			r_interface.attribute6(recno),
4860 		r_interface.attribute7(recno),			r_interface.attribute8(recno),
4861 		r_interface.attribute9(recno),			r_interface.attribute10(recno),
4862 		g_business_group_id,r_interface.unmatched_nve_txn_flag(recno));
4863 
4864 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Inserted into pa_transaction_interface_all');
4865 
4866 	FOR recno IN 1..r_interface.txn_interface_id.COUNT
4867 	LOOP
4868 		GMS_REC.TXN_INTERFACE_ID		:= r_interface.txn_interface_id(recno);
4869 		GMS_REC.BATCH_NAME			:= r_interface.gms_batch_name(recno);
4870 		GMS_REC.TRANSACTION_SOURCE		:= l_gms_transaction_source;
4871 		GMS_REC.EXPENDITURE_ENDING_DATE		:= r_interface.exp_end_date(recno);
4872 		GMS_REC.EXPENDITURE_ITEM_DATE		:= r_interface.effective_date(recno);
4873 		GMS_REC.PROJECT_NUMBER			:= r_interface.project_number(recno);
4874 		GMS_REC.TASK_NUMBER			:= r_interface.task_number(recno);
4875 		GMS_REC.AWARD_ID			:= r_interface.award_id(recno);
4876 		GMS_REC.EXPENDITURE_TYPE		:= r_interface.expenditure_type(recno);
4877 		GMS_REC.TRANSACTION_STATUS_CODE		:= 'P';
4878 		GMS_REC.ORIG_TRANSACTION_REFERENCE	:= 'E:'|| r_interface.enc_summary_line_id(recno);
4879 		GMS_REC.ORG_ID				:= r_interface.operating_unit(recno);
4880 		GMS_REC.SYSTEM_LINKAGE			:= NULL;
4881 		GMS_REC.USER_TRANSACTION_SOURCE		:= NULL;
4882 		GMS_REC.TRANSACTION_TYPE		:= NULL;
4883 		GMS_REC.BURDENABLE_RAW_COST		:= r_interface.summary_amount(recno);
4884 		GMS_REC.FUNDING_PATTERN_ID		:= NULL;
4885 		GMS_REC.ORIGINAL_ENCUMBRANCE_ITEM_ID	:= r_interface.expenditure_item_id(recno);
4886 
4887 		gms_transactions_pub.LOAD_GMS_XFACE_API(gms_rec, l_return_status);
4888 
4889 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4890 			fnd_message.set_name('PSP','PSP_GMS_XFACE_FAILED');
4891 			fnd_msg_pub.add;
4892 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4893 		END IF;
4894 	END LOOP;
4895 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Inserted into gms_transaction_interface_all');
4896 	IF r_interface.txn_interface_id.COUNT > 0 THEN
4897 
4898 		FOR request_counter IN 1..org_id_tab.count
4899 		LOOP
4900 			-- set the context to single to call submit_request
4901 			mo_global.set_policy_context('S', org_id_tab(request_counter) );
4902 			fnd_request.set_org_id (org_id_tab(request_counter) );
4903 
4904 			req_id_tab(request_counter) := fnd_request.submit_request
4905 					('PA',
4906 					'PAXTRTRX',
4907 					NULL,
4908 					NULL,
4909 					FALSE,
4910 					l_gms_transaction_source,
4911 					gms_batch_name_tab(request_counter));
4912 
4913 			IF req_id_tab(request_counter) = 0 THEN
4914 				fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Submission of Transaction Import Failed');
4915 				fnd_message.set_name('PSP','PSP_TR_GMS_IMP_FAILED');
4916 				fnd_msg_pub.add;
4917 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4918 			ELSE
4919 				fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Submitted Transaction Import');
4920 
4921 				OPEN enc_control_id_cur;
4922 				FETCH enc_control_id_cur BULK COLLECT INTO r_enc_controls.enc_control_id;
4923 				CLOSE enc_control_id_cur;
4924 
4925 				FORALL I IN 1..r_enc_controls.enc_control_id.COUNT
4926 				UPDATE	psp_enc_controls
4927 				SET	gms_phase = 'Transfer'
4928 				WHERE	enc_control_id = r_enc_controls.enc_control_id(I);
4929 
4930 				fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated gms_phase to ''Transfer'' in psp_enc_controls SQL%ROWCOUNT: ' || SQL%ROWCOUNT);
4931 
4932 				r_enc_controls.enc_control_id.DELETE;
4933 			END IF;
4934 		END LOOP;
4935        		COMMIT;
4936 		-- set the context again to multiple
4937 		mo_global.set_policy_context('M', null);
4938 
4939 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling gather_table_stats for psp_enc_summary_lines');
4940 		fnd_stats.gather_table_stats('PSP', 'PSP_ENC_SUMMARY_LINES');
4941 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Completed gather_table_stats for psp_enc_summary_lines');
4942 
4943 		FOR I IN 1..org_id_tab.count
4944 		LOOP
4945 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Waiting for comlpetion of Transaction Import');
4946        			call_status := fnd_concurrent.wait_for_request(req_id_tab(I), 10, 0, rphase, rstatus, dphase, dstatus, message);
4947 
4948 			IF call_status = FALSE then
4949 				fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Transaction Import failed');
4950 				fnd_message.set_name('PSP','PSP_TR_GMS_IMP_FAILED');
4951 				fnd_msg_pub.add;
4952 				RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4953 			END IF;
4954 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Transaction Import completed');
4955 		END LOOP;
4956 	END IF;
4957 
4958 	OPEN gms_batch_name_cur;
4959 	FETCH gms_batch_name_cur BULK COLLECT INTO r_gms_batch.gms_batch_name;
4960 	CLOSE gms_batch_name_cur;
4961 
4962 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_gms_batch.gms_batch_name.COUNT: ' || r_gms_batch.gms_batch_name.COUNT);
4963 
4964 	FOR recno IN 1..r_gms_batch.gms_batch_name.COUNT
4965 	LOOP
4966 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Calling gms_enc_tie_back for gms_batch_name: ' || r_gms_batch.gms_batch_name(recno));
4967 		gms_enc_tie_back(p_payroll_action_id,
4968 				r_gms_batch.gms_batch_name(recno),
4969 				g_business_group_id,
4970 				g_set_of_books_id,
4971 				l_return_status);
4972 
4973 		IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4974 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	gms_enc_tie_back failed for gms_batch_name: ' || r_gms_batch.gms_batch_name(recno));
4975 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4976 		END IF;
4977 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	gms_enc_tie_back successful for gms_batch_name: ' || r_gms_batch.gms_batch_name(recno));
4978 	END LOOP;
4979 
4980 	FORALL recno IN 1..r_gms_batch.gms_batch_name.COUNT
4981 	UPDATE	psp_enc_summary_lines pesl
4982 	SET	(pesl.expenditure_id, pesl.expenditure_item_id, pesl.expenditure_ending_date,
4983 		pesl.txn_interface_id, pesl.interface_id) =
4984 			(SELECT	ptxn.expenditure_id, ptxn.expenditure_item_id, ptxn.expenditure_ending_date,
4985 				ptxn.txn_interface_id, ptxn.interface_id
4986 			FROM	pa_transaction_interface_all ptxn
4987 			WHERE	ptxn.transaction_source = 'GOLDE'
4988 			AND	ptxn.batch_name = r_gms_batch.gms_batch_name(recno)
4989 			AND	ptxn.orig_transaction_reference = 'E:' || TO_CHAR(pesl.enc_summary_line_id))
4990 	WHERE	pesl.gms_batch_name = r_gms_batch.gms_batch_name(recno);
4991 
4992 	FORALL recno IN 1..r_gms_batch.gms_batch_name.COUNT
4993 	DELETE	pa_transaction_interface_all
4994 	WHERE	batch_name = r_gms_batch.gms_batch_name(recno)
4995 	AND	transaction_source = 'GOLDE';
4996 
4997 	FORALL recno IN 1..r_gms_batch.gms_batch_name.COUNT
4998 	DELETE	gms_transaction_interface_all
4999 	WHERE	batch_name = r_gms_batch.gms_batch_name(recno)
5000 	AND	transaction_source = 'GOLDE';
5001 
5002 	FORALL recno IN 1..r_gms_batch.gms_batch_name.COUNT
5003 	UPDATE	psp_enc_summary_lines
5004 	SET	gms_batch_name = NULL
5005 	WHERE	gms_batch_name = r_gms_batch.gms_batch_name(recno)
5006 	AND	status_code = 'N';
5007 
5008 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Set the un-imported summary lines to New status');
5009 
5010 	COMMIT;
5011 
5012 	p_return_status := fnd_api.g_ret_sts_success;
5013 EXCEPTION
5014 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5015 		g_error_api_path := 'TR_TO_GMS_INT:'||g_error_api_path;
5016 		p_return_status := fnd_api.g_ret_sts_unexp_error;
5017 
5018 	WHEN RETURN_BACK THEN
5019 		p_return_status := fnd_api.g_ret_sts_success;
5020 
5021 	WHEN OTHERS THEN
5022 		g_error_api_path := 'TR_TO_GMS_INT:'||g_error_api_path;
5023 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','TR_TO_GMS_INT');
5024 		p_return_status := fnd_api.g_ret_sts_unexp_error;
5025 END	tr_to_gms_int;
5026 --	End of comment for Create and Update multi thread
5027 
5028 --	##########################################################################
5029 --	This procedure ties back all the transactions posted into Oracle Grants Mgmt.
5030 --		with Oracle Labor Distribution where the import is successful.
5031 --	In case of failure the transactions in Oracle Labor Distribution are turned
5032 --		back into their original state.
5033 --	##########################################################################
5034 
5035 /*****	Commented for Create and Update multi thread enh.
5036 PROCEDURE gms_enc_tie_back( p_enc_control_id	IN  NUMBER,
5037 			    p_period_end_date   IN  DATE,
5038                             p_gms_batch_name	IN  VARCHAR2,
5039                             p_business_group_id IN  NUMBER,
5040                             p_set_of_books_id   IN  NUMBER,
5041                             p_mode		IN  VARCHAR2,   -- Included as part of Bug fix #1776606
5042                             p_return_status     OUT NOCOPY  VARCHAR2) IS
5043 
5044    CURSOR gms_tie_back_success_cur IS
5045    SELECT enc_summary_line_id,
5046           dr_cr_flag,
5047 	  summary_amount
5048    FROM   psp_enc_summary_lines
5049    WHERE  gms_batch_name = p_gms_batch_name
5050    and    enc_control_id = p_enc_control_id;
5051 
5052    CURSOR gms_tie_back_reject_cur IS
5053    SELECT nvl(transaction_rejection_code,'P'),
5054           orig_transaction_reference,
5055           transaction_status_code
5056    FROM   pa_transaction_interface_all
5057    WHERE  transaction_source = 'GOLDE'
5058      AND  batch_name = p_gms_batch_name
5059       AND  orig_transaction_reference IN (SELECT 'E:' || enc_summary_line_id --added subqry for 3953230
5060                                             FROM  psp_enc_summary_lines pesl
5061                                            WHERE  pesl.enc_control_id = p_enc_control_id);
5062 
5063    CURSOR assign_susp_ac_cur(P_ENC_LINE_ID	IN	NUMBER) IS
5064    SELECT pel.rowid,
5065           pel.encumbrance_date,
5066           pel.suspense_org_account_id
5067    FROM   psp_enc_lines pel
5068    WHERE  pel.enc_summary_line_id = p_enc_line_id
5069    and    pel.enc_control_id=p_enc_control_id;
5070 -- bUg fix 1671938
5071 
5072 -- Get the Organization details ...
5073 
5074    CURSOR get_susp_org_cur(P_ORG_ID	IN	VARCHAR2) IS
5075    SELECT hou.organization_id, hou.name
5076      FROM hr_all_organization_units hou, psp_organization_accounts poa
5077     WHERE hou.organization_id = poa.organization_id
5078       AND poa.business_group_id = p_business_group_id
5079       AND poa.set_of_books_id = p_set_of_books_id
5080       AND poa.organization_account_id = p_org_id;
5081 / *
5082    CURSOR get_org_id_cur(P_LINE_ID	IN	NUMBER) IS
5083    SELECT hou.organization_id, hou.name
5084    FROM   hr_all_organization_units hou,
5085   	      per_assignments_f paf,
5086           psp_enc_lines pel
5087    WHERE  pel.enc_summary_line_id = p_line_id
5088    AND    pel.assignment_id = paf.assignment_id
5089    AND    pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
5090    AND    paf.organization_id = hou.organization_id
5091    AND    pel.encumbrance_date between
5092 		  hou.date_from and nvl(hou.date_to,pel.encumbrance_date);
5093 -- bUg fIx 1671938
5094 * /
5095 
5096    CURSOR get_org_id_cur(P_ROWID IN ROWID) IS
5097    SELECT hou.organization_id, hou.name
5098    FROM   hr_all_organization_units hou,
5099   	      per_assignments_f paf,
5100           psp_enc_lines pel
5101    WHERE
5102 -- pel.enc_summary_line_id = p_line_id
5103    pel.rowid=p_rowid
5104    AND    pel.assignment_id = paf.assignment_id
5105    AND    pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
5106    AND    paf.organization_id = hou.organization_id
5107    AND    pel.encumbrance_date between
5108 		  hou.date_from and nvl(hou.date_to,pel.encumbrance_date);
5109 
5110 
5111 
5112   l_orig_org_name		hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
5113   l_orig_org_id			number;
5114 
5115 -- End of Get org id cursor  Ravindra
5116 / *   CURSOR assign_susp_ac_cur(P_ENC_SUMMARY_LINE_ID	IN	NUMBER) IS
5117    SELECT hou.name,
5118           hou.organization_id,
5119           pel.rowid,
5120           pel.assignment_id,
5121           pel.encumbrance_date,
5122           pel.suspense_org_account_id
5123    FROM   hr_organization_units hou,
5124           per_assignments_f paf,
5125           psp_enc_lines pel,
5126    WHERE  pel.enc_summary_line_id = p_enc_summary_line_id
5127    AND    pel.assignment_id = paf.assignment_id
5128    AND    pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
5129    AND	  pel.business_group_id = g_business_group_id
5130    AND	  pel.set_of_books_id = g_set_of_books_id
5131    AND    paf.organization_id = hou.organization_id;
5132 * /
5133 
5134    CURSOR org_susp_ac_cur(P_ORGANIZATION_ID	IN	NUMBER,
5135                           P_ENCUMBRANCE_DATE	IN	DATE) IS
5136    SELECT poa.organization_account_id,
5137           poa.gl_code_combination_id,
5138           poa.project_id,
5139 	  poa.expenditure_organization_id,
5140 	  poa.expenditure_type,
5141           poa.award_id,
5142 	  poa.task_id
5143    FROM   psp_organization_accounts poa
5144    WHERE  poa.organization_id = p_organization_id
5145    AND	  poa.business_group_id = p_business_group_id
5146    AND	  poa.set_of_books_id = p_set_of_books_id
5147    AND    poa.account_type_code = 'S'
5148 --   AND	  poa.award_id is not null   for Bug Fix 1776606
5149    AND    p_encumbrance_date BETWEEN poa.start_date_active AND
5150                                       nvl(poa.end_date_active,p_encumbrance_date);
5151 
5152 -- CURSOR global_susp_ac_cur(P_ENCUMBRANCE_DATE	IN	DATE) IS
5153    CURSOR global_susp_ac_cur(P_ORGANIZATION_ACCOUNT_ID	IN	NUMBER) IS --BUG 2056877.
5154    SELECT poa.organization_account_id,
5155           poa.gl_code_combination_id,
5156           poa.project_id,
5157 	  poa.expenditure_organization_id,
5158 	  poa.expenditure_type,
5159           poa.award_id,
5160 	  poa.task_id
5161    FROM   psp_organization_accounts poa
5162    WHERE
5163     / *    poa.account_type_code = 'G'
5164      AND  poa.business_group_id = p_business_group_id
5165      AND  poa.set_of_books_id = p_set_of_books_id
5166 --   AND  poa.award_id is not null    For Bug fix 1776606
5167      AND    p_encumbrance_date BETWEEN poa.start_date_active AND
5168                                       nvl(poa.end_date_active,p_encumbrance_date); Bug 2056877 * /
5169           organization_account_id = p_organization_account_id;   --Added for bug 2056877.
5170 
5171 
5172    l_organization_name		hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
5173    l_organization_id		NUMBER(15);
5174    l_rowid				ROWID;
5175    l_assignment_id		NUMBER(9);
5176    l_encumbrance_date		DATE;
5177    l_suspense_org_account_id  NUMBER(9);
5178 
5179    l_organization_account_id	NUMBER(9);
5180    l_gl_code_combination_id   NUMBER(15);
5181    l_project_id			NUMBER(15);
5182    l_expenditure_organization_id NUMBER(15);
5183    l_expenditure_type		VARCHAR2(30);
5184    l_award_id			NUMBER(15);
5185    l_task_id			NUMBER(15);
5186    l_cnt_gms_interface		NUMBER;
5187    l_enc_summary_line_id		NUMBER(10);
5188    l_gl_project_flag		VARCHAR2(1);
5189    l_suspense_ac_failed		VARCHAR2(1) := 'N';
5190    l_suspense_ac_not_found	VARCHAR2(1) := 'N';
5191    l_susp_ac_found		VARCHAR2(10) := 'TRUE';
5192    l_summary_amount		NUMBER;
5193    l_dr_summary_amount		NUMBER := 0;
5194    l_cr_summary_amount		NUMBER := 0;
5195    l_dr_cr_flag			VARCHAR2(1);
5196    l_trx_status_code		VARCHAR2(2); / * Bug 2030232:Gms bug 1961436 * /
5197    l_trx_reject_code		VARCHAR2(30);
5198    l_orig_trx_reference		VARCHAR2(30);
5199    l_enc_ref			VARCHAR2(30);
5200    l_effective_date		DATE;
5201 
5202    x_susp_failed_org_name	hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
5203    x_susp_failed_reject_code	VARCHAR2(30);
5204    x_susp_failed_date		DATE;
5205    x_susp_nf_org_name		hr_all_organization_units_tl.name%TYPE; -- Bug 2447912: Modified declaration
5206    x_susp_nf_date		DATE;
5207    l_return_status		VARCHAR2(10);
5208    l_no_run			NUMBER;
5209    l_susp_glccid		NUMBER(15);
5210    l_no_complete		NUMBER;
5211    l_return_value               VARCHAR2(30);  --Added for bug 2056877.
5212    no_profile_exists            EXCEPTION;     --Added for bug 2056877.
5213    no_val_date_matches          EXCEPTION;     --Added for bug 2056877.
5214    no_global_acct_exists        EXCEPTION;     --Added for bug 2056877.
5215    l_susp_exception  varchar2(50);       -- added for 2479579
5216 
5217 
5218  FUNCTION PROCESS_COMPLETE RETURN VARCHAR2 IS
5219     l_cnt       NUMBER;
5220     l_status    VARCHAR2(30);
5221  begin
5222 
5223    select count(*), transaction_status_code
5224      into l_cnt, l_status
5225      from pa_transaction_interface_all
5226     where transaction_source = 'GOLDE'
5227       and batch_name = (select distinct gms_batch_name
5228                           from psp_enc_summary_lines
5229                          where enc_control_id = p_enc_control_id
5230                            and gms_batch_name is not null)
5231       and transaction_status_code in ('P', 'I')
5232     group by transaction_status_code  ;
5233 
5234    if l_cnt = 0 then
5235      return 'COMPLETE';
5236    elsif l_cnt > 0 then
5237      if l_status = 'P' then
5238 
5239 -- -------------------------------------------------------------------------------------------
5240 -- If transaction_status_code = 'P' then the transaction import process did not kick off
5241 -- for some reason. Return 'NOT_RUN' in this case. So cleanup the tables and try to transfer
5242 -- again after summarization in the second pass.
5243 -- -------------------------------------------------------------------------------------------
5244 
5245         delete from pa_transaction_interface_all
5246          where transaction_source = 'GOLDE'
5247            and batch_name = p_gms_batch_name;
5248 
5249         delete from gms_transaction_interface_all
5250          where transaction_source = 'GOLDE'
5251            and batch_name = p_gms_batch_name;
5252 
5253         delete from psp_enc_summary_lines
5254          where gms_batch_name = p_gms_batch_name
5255            and enc_control_id = p_enc_control_id;
5256 
5257         return 'NOT_RUN';
5258 
5259      elsif l_status = 'I' then
5260 
5261 -- -------------------------------------------------------------------------------------------
5262 -- If transaction_status_code = 'I' then the transaction import process did not complete
5263 -- the Post Processing extension. So return 'NOT_COMPLETE' in this case. User needs to complete
5264 -- this process by running the transaction import manually and re-start the LD process.
5265 -- -------------------------------------------------------------------------------------------
5266 
5267         return 'NOT_COMPLETE';
5268 
5269      end if;
5270    end if;
5271 
5272  exception
5273  when others then
5274    return 'COMPLETE';
5275  end PROCESS_COMPLETE;
5276 
5277  BEGIN
5278 
5279    if (PROCESS_COMPLETE not in ('NOT_COMPLETE', 'NOT_RUN')) then
5280 
5281    SELECT count(*)
5282      INTO l_cnt_gms_interface
5283      FROM pa_transaction_interface_all
5284     WHERE transaction_source = 'GOLDE'
5285       AND batch_name = p_gms_batch_name
5286       AND transaction_status_code in ('R', 'PI', 'PR', 'PO');
5287 
5288    IF l_cnt_gms_interface > 0 THEN
5289      / * Start bug#2142865 Added  the code to update the gms_phase * /
5290      UPDATE psp_enc_controls
5291      SET gms_phase = 'TieBack'
5292      WHERE  run_id = g_run_id;
5293      / * End bug#2142865 * /
5294      OPEN gms_tie_back_reject_cur;
5295      LOOP               --loop1 count in pa_tr_int > 1
5296        FETCH gms_tie_back_reject_cur INTO l_trx_reject_code, l_enc_ref, l_trx_status_code;
5297        IF gms_tie_back_reject_cur%NOTFOUND THEN
5298          CLOSE gms_tie_back_reject_cur;
5299          EXIT;
5300        END IF;
5301 
5302 	l_orig_trx_reference := substr(l_enc_ref, 3);
5303 
5304       IF l_trx_status_code in ('R', 'PI', 'PR', 'PO') THEN
5305          UPDATE psp_enc_summary_lines
5306        SET interface_status = l_trx_reject_code, status_code = 'R'
5307        WHERE enc_summary_line_id = to_number(l_orig_trx_reference);
5308       ELSIF l_trx_status_code = 'A' THEN
5309         UPDATE psp_enc_summary_lines
5310         SET interface_status = l_trx_reject_code, status_code = 'A'
5311         WHERE enc_summary_line_id = to_number(l_orig_trx_reference);
5312       -- END IF;
5313 
5314 	SELECT summary_amount, dr_cr_flag
5315 	INTO l_summary_amount, l_dr_cr_flag
5316 	FROM psp_enc_summary_lines
5317 	WHERE enc_summary_line_id = to_number(l_orig_trx_reference);
5318 
5319 	IF l_dr_cr_flag = 'D' THEN
5320 	 l_dr_summary_amount := l_dr_summary_amount + l_summary_amount;
5321 	 ELSIF l_dr_cr_flag = 'C' THEN
5322 	 l_cr_summary_amount := l_cr_summary_amount - l_summary_amount;
5323 	 END IF;
5324 
5325 	END IF;
5326 
5327        OPEN assign_susp_ac_cur(l_orig_trx_reference);
5328        LOOP		--loop2		assign suspense account
5329 
5330          FETCH assign_susp_ac_cur INTO l_rowid, l_encumbrance_date, l_suspense_org_account_id;
5331 
5332          IF assign_susp_ac_cur%NOTFOUND THEN
5333            CLOSE assign_susp_ac_cur;
5334            EXIT;
5335          END IF;
5336 
5337      IF l_trx_status_code = 'A'  THEN
5338 
5339 	    UPDATE psp_enc_lines
5340             SET status_code = 'A'
5341             WHERE rowid = l_rowid;
5342 
5343             -- move the transferred records to psp_enc_lines_history
5344            -- Added enc_start_date ,enc_end_date columns for Enh. Enc Redesign Prorata,Bug #2259310
5345          --dbms_output.put_line('moving rec into enc lines hist');
5346        	     --insert_into_psp_stout( 'moving rec into enc lines hist');
5347 	-- Introduced DFF columns for bug fix 2908859
5348          INSERT INTO psp_enc_lines_history
5349          (enc_line_id,business_group_id,enc_element_type_id,encumbrance_date,
5350           dr_cr_flag,encumbrance_amount,status_code,enc_line_type,schedule_line_id,org_schedule_id,
5351 	  default_org_account_id,suspense_org_account_id,element_account_id,gl_project_flag,
5352 	  enc_summary_line_id,person_id,assignment_id,award_id,task_id,expenditure_type,
5353 	  expenditure_organization_id,project_id,gl_code_combination_id,time_period_id,payroll_id,
5354 	  set_of_books_id,default_reason_code,suspense_reason_code,enc_control_id,change_flag,last_update_date,
5355 	  last_updated_by,last_update_login,created_by,creation_date,enc_start_date,enc_end_date,
5356 	attribute_category,	attribute1,		attribute2,		attribute3,
5357 	attribute4,		attribute5,		attribute6,		attribute7,
5358 	attribute8,		attribute9,		attribute10)
5359          SELECT enc_line_id,business_group_id,enc_element_type_id,encumbrance_date,
5360           dr_cr_flag,encumbrance_amount,status_code,enc_line_type,schedule_line_id,org_schedule_id,
5361 	  default_org_account_id,suspense_org_account_id,element_account_id,gl_project_flag,
5362 	  enc_summary_line_id,person_id,assignment_id,award_id,task_id,expenditure_type,
5363 	  expenditure_organization_id,project_id,gl_code_combination_id,time_period_id,payroll_id,
5364 	  set_of_books_id,default_reason_code,suspense_reason_code,enc_control_id,change_flag,last_update_date,
5365 	  last_updated_by,last_update_login,created_by,creation_date,enc_start_date,enc_end_date,
5366 	attribute_category,	attribute1,		attribute2,		attribute3,
5367 	attribute4,		attribute5,		attribute6,		attribute7,
5368 	attribute8,		attribute9,		attribute10
5369          FROM psp_enc_lines
5370          WHERE status_code = 'A'
5371          AND  enc_summary_line_id = to_number(l_orig_trx_reference)
5372 	 AND  enc_control_id = p_enc_control_id;
5373 
5374          DELETE FROM psp_enc_lines
5375          WHERE status_code = 'A'
5376          AND enc_summary_line_id = to_number(l_orig_trx_reference)
5377 	 AND enc_control_id = p_enc_control_id;
5378 
5379 / **************************************************************************************
5380 For Bug 2290051 - Commenting out purging of Interface tables for accepted Summary Lines
5381 --    purge the interface tables for Accepted summary lines
5382 
5383 	 DELETE from pa_transaction_interface_all
5384 	  where transaction_source = 'GOLDE'
5385 	    and batch_name = p_gms_batch_name
5386 	    and transaction_status_code = 'A'
5387 	    and orig_transaction_reference =  l_enc_ref;
5388 
5389 	 DELETE from gms_transaction_interface_all
5390 	  where transaction_source = 'GOLDE'
5391 	    and batch_name = p_gms_batch_name
5392 	    and transaction_status_code = 'A'
5393 	    and orig_transaction_reference = l_enc_ref;
5394 
5395 **************************************************************************************** /
5396 
5397            -- if a suspense a/c failed,update the status of the whole batch and display the error
5398 
5399 	  ELSIF l_suspense_org_account_id IS NOT NULL AND l_trx_status_code <> 'A'  THEN
5400 
5401 	    OPEN get_susp_org_cur(l_suspense_org_account_id);
5402 	    FETCH get_susp_org_cur into l_organization_id, l_organization_name;
5403 	    CLOSE get_susp_org_cur;
5404 
5405            x_susp_failed_org_name    := l_organization_name;
5406            x_susp_failed_reject_code := l_trx_reject_code;
5407            x_susp_failed_date        := l_encumbrance_date;
5408            l_suspense_ac_failed := 'Y';
5409 
5410 
5411    / *Commented for Bug 3914807
5412 	    UPDATE psp_enc_lines
5413             SET suspense_reason_code = 'ES:' || l_trx_reject_code,
5414                 status_code = 'N'
5415             WHERE rowid = l_rowid; * /
5416 
5417          ELSE
5418            l_susp_ac_found := 'TRUE';
5419 	       OPEN get_org_id_cur(l_rowid);
5420 	       FETCH get_org_id_cur into l_orig_org_id, l_orig_org_name;
5421 
5422 	   --    IF get_org_id_cur%NOTFOUND then
5423 	           CLOSE get_org_id_cur;
5424 	    --   END IF;
5425 
5426            OPEN org_susp_ac_cur(l_orig_org_id, l_encumbrance_date);
5427            FETCH org_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id, l_expenditure_organization_id, l_expenditure_type, l_award_id,l_task_id;
5428 
5429            IF org_susp_ac_cur%NOTFOUND  THEN
5430 		/ * Following code is added for bug 2056877 ,Added validation for generic suspense account * /
5431 		l_return_value := psp_general.find_global_suspense(l_encumbrance_date,
5432 							  p_business_group_id,
5433                                                           p_set_of_books_id,
5434                                                           l_organization_account_id);
5435       	  / * --------------------------------------------------------------------
5436       	   Valid return values are
5437       	   PROFILE_VAL_DATE_MATCHES       Profile and Value and Date matching 'G'
5438       	   NO_PROFILE_EXISTS              No Profile
5439        	   NO_VAL_DATE_MATCHES            Profile and Either Value/date do not
5440             		                  match with 'G'
5441    	   NO_GLOBAL_ACCT_EXISTS          No 'G' exists
5442      	    ---------------------------------------------------------------------- * /
5443                / *start Added for Bug#2142685. * /
5444                / * IF  l_return_value <> 'PROFILE_VAL_DATE_MATCHES' THEN
5445                  IF p_mode='N' THEN
5446                     enc_batch_end(g_payroll_id,l_return_status);
5447                  END IF;
5448                END IF;    2479579 * /
5449 	       / * End Bug#2142865 * /
5450                IF  l_return_value = 'PROFILE_VAL_DATE_MATCHES' THEN
5451             	--	OPEN global_susp_ac_cur(l_encumbrance_date);
5452             	 	OPEN global_susp_ac_cur(l_organization_account_id); -- Bug 2056877.
5453             		FETCH global_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,
5454 	    		l_project_id, l_expenditure_organization_id, l_expenditure_type, l_award_id,l_task_id;
5455            		    IF global_susp_ac_cur%NOTFOUND THEN
5456               		     / *	  l_susp_ac_found := 'FALSE';
5457 	            		  l_suspense_ac_not_found := 'Y';
5458            		          x_susp_nf_org_name := l_orig_org_name;
5459               		          x_susp_nf_date     := l_encumbrance_date;  Bug 2056877* /
5460                                    -- added following two lines for 2479579
5461                                    l_suspense_ac_not_found := 'Y';
5462                                    l_susp_ac_found := 'NO_G_AC';
5463            		    END IF;
5464             		CLOSE global_susp_ac_cur;
5465                 ELSIF l_return_value = 'NO_GLOBAL_ACCT_EXISTS' THEN
5466                      -- RAISE no_global_acct_exists; commented this line and added two new lines for 2479579
5467                      l_suspense_ac_not_found := 'Y';
5468                      l_susp_ac_found := 'NO_G_AC';
5469                 ELSIF l_return_value = 'NO_VAL_DATE_MATCHES' THEN
5470                     -- RAISE no_val_date_matches; commented this line and added two new lines for 2479579
5471                      l_suspense_ac_not_found := 'Y';
5472                      l_susp_ac_found := 'NO_DT_MCH';
5473                  ELSIF l_return_value = 'NO_PROFILE_EXISTS' THEN
5474                     -- RAISE no_profile_exists; commented this line and added two new lines for 2479579
5475                          l_suspense_ac_not_found := 'Y';
5476                          l_susp_ac_found := 'NO_PROFL';
5477                END IF; -- Bug 2056877.
5478            END IF;
5479            CLOSE org_susp_ac_cur;
5480 
5481 
5482            IF l_susp_ac_found = 'TRUE' THEN
5483 
5484              --CLOSE org_susp_ac_cur;
5485             IF l_susp_glccid IS NOT NULL THEN
5486               l_gl_project_flag := 'G';
5487               l_effective_date := p_period_end_date;
5488             ELSE
5489               l_gl_project_flag := 'P';
5490               psp_general.poeta_effective_date(l_encumbrance_date,
5491                                    l_project_id,
5492                                    l_award_id,
5493                                    l_task_id,
5494                                    l_effective_date,
5495                                    l_return_status);
5496               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5497                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5498               END IF;
5499 
5500             END IF;
5501 	/ * For Bug fix 3194807 * /
5502 
5503 	     UPDATE 	psp_enc_lines
5504 	     SET	prev_effective_date = encumbrance_date
5505 	     WHERE	rowid = l_rowid;
5506 	/ * End of Bug fix 3198407 * /
5507 
5508              UPDATE psp_enc_lines
5509               SET suspense_org_account_id = l_organization_account_id,
5510                   suspense_reason_code = 'ES:' || l_trx_reject_code,
5511                   gl_project_flag = l_gl_project_flag,
5512 --		  encumbrance_date = l_encumbrance_date, Commented for Bug 3194807
5513                   encumbrance_date = l_effective_date,
5514 / *Commented for Bug 3194807
5515 		  schedule_line_id = null,
5516 		  org_schedule_id = null,
5517 		  default_org_account_id = null,
5518 		  element_account_id = null,
5519 		  gl_code_combination_id = decode(l_gl_project_flag, 'P', null, l_susp_glccid),
5520 		  project_id = decode(l_gl_project_flag, 'P', l_project_id, null),
5521 		  expenditure_organization_id = decode(l_gl_project_flag, 'P', l_expenditure_organization_id, null),
5522 		  expenditure_type = decode(l_gl_project_flag, 'P', l_expenditure_type, null),
5523 		  task_id = decode(l_gl_project_flag, 'P', l_task_id, null),
5524 		  award_id = decode(l_gl_project_flag, 'P', l_award_id, null), * /
5525                   status_code = 'N'
5526               WHERE rowid = l_rowid;
5527             else -- 2479579
5528               l_susp_exception := l_susp_ac_found;
5529             END IF;
5530          END IF;
5531 
5532        END LOOP;	--end loop2 assign suspense account
5533      END LOOP;		-- end loop1
5534 
5535     UPDATE psp_enc_controls
5536        SET summ_ogm_dr_amount = l_dr_summary_amount,
5537            summ_ogm_cr_amount = l_cr_summary_amount
5538          --gms_phase = 'TieBack' Commented for Bug#2142865 , same moved above
5539      WHERE enc_control_id = p_enc_control_id;
5540 
5541      --COMMIT;
5542 
5543      IF l_suspense_ac_failed = 'Y' THEN
5544        g_susp_prob := 'Y';     -- for 2479579
5545        fnd_message.set_name('PSP','PSP_TR_GMS_SUSP_AC_REJECT');
5546        fnd_message.set_token('ORG_NAME',x_susp_failed_org_name);
5547        fnd_message.set_token('PAYROLL_DATE',x_susp_failed_date);
5548        fnd_message.set_token('ERROR_MSG',x_susp_failed_reject_code);
5549        fnd_msg_pub.add;
5550 
5551 
5552 	 / * Added the following for Bug 3194807 * /
5553 
5554         UPDATE  psp_enc_lines
5555         SET     suspense_org_account_id = NULL,
5556                 suspense_reason_code = NULL,
5557                 gl_project_flag = decode(gl_code_combination_id,NULL,'P','G'),
5558 	 	encumbrance_date = prev_effective_date
5559         WHERE   suspense_reason_code like 'ES:%'
5560         AND     enc_summary_line_id
5561                 IN (SELECT enc_summary_line_id
5562                     FROM   psp_enc_summary_lines
5563                     WHERE  enc_control_id = p_enc_control_id);
5564 
5565 
5566         / * End of code changes for Bug 3194807 * /
5567 
5568      END IF;
5569 
5570 
5571        -- uncommented for 2479579, which was earlier commented   for bug # 2142865
5572      IF l_suspense_ac_not_found = 'Y' THEN
5573        g_susp_prob := 'Y';     -- for 2479579
5574        / * commented this message stack for 2479579
5575        fnd_message.set_name('PSP','PSP_LD_SUSPENSE_AC_NOT_EXIST');
5576        fnd_message.set_token('ORG_NAME',x_susp_nf_org_name);
5577        fnd_message.set_token('PAYROLL_DATE',x_susp_nf_date);
5578        fnd_msg_pub.add; * /
5579        / * Included the following check as part of Bug fix #1776606 * /
5580         ---added following if stmnt for 2479579
5581         IF    l_susp_exception = 'NO_G_AC' then
5582             RAISE no_global_acct_exists;
5583         ELSIF l_susp_exception = 'NO_DT_MCH' then
5584              RAISE no_val_date_matches;
5585         ELSIF l_susp_exception = 'NO_PROFL' then
5586              RAISE no_profile_exists;
5587         END IF;
5588 
5589      END IF;
5590 
5591 
5592    ELSIF l_cnt_gms_interface = 0 THEN
5593 
5594      OPEN gms_tie_back_success_cur;
5595      LOOP
5596        FETCH gms_tie_back_success_cur INTO l_enc_summary_line_id,
5597         l_dr_cr_flag,l_summary_amount;
5598 
5599        IF gms_tie_back_success_cur%NOTFOUND THEN
5600          CLOSE gms_tie_back_success_cur;
5601          EXIT;
5602        END IF;
5603        -- update records in psp_summary_lines as 'A'
5604 
5605        UPDATE psp_enc_summary_lines
5606        SET status_code = 'A'
5607        WHERE enc_summary_line_id = l_enc_summary_line_id;
5608 
5609        IF l_dr_cr_flag = 'D' THEN
5610          l_dr_summary_amount := l_dr_summary_amount + l_summary_amount;
5611        ELSIF l_dr_cr_flag = 'C' THEN
5612          -- credit is marked as -ve for posting to Oracle Projects
5613          l_cr_summary_amount := l_cr_summary_amount - l_summary_amount;
5614        END IF;
5615 
5616 	 UPDATE psp_enc_lines
5617             SET status_code = 'A'
5618           WHERE enc_summary_line_id = l_enc_summary_line_id
5619 	    AND enc_control_id = p_enc_control_id;
5620 
5621          / * Introduced this cursor for Bug fix 3194807 * /
5622 
5623           UPDATE psp_enc_lines
5624           SET   (gl_code_combination_id,project_id,task_id,award_id,expenditure_organization_id,expenditure_type)
5625 		= (select NULL,poa.project_id,poa.task_id,poa.award_id,poa.expenditure_organization_id,poa.expenditure_type
5626                    from   psp_organization_accounts poa
5627                    where  poa.organization_account_id = suspense_org_account_id
5628 		   and 	  enc_summary_line_id = l_enc_summary_line_id)
5629 	  WHERE enc_summary_line_id= l_enc_summary_line_id
5630 	  AND   suspense_reason_code like 'ES:%';
5631 
5632 
5633 	/ * End of code Changes for Bug fix  3194807 * /
5634 
5635 
5636 	  -- move the transferred records to psp_enc_lines_history
5637 	  -- Added enc_start_date ,enc_end_date columns for Enh. Enc Redesign Prorata,Bug #2259310
5638 	-- Introduced DFF columns for bug fix 2908859
5639          INSERT INTO psp_enc_lines_history
5640          (enc_line_id,business_group_id,enc_element_type_id,encumbrance_date,
5641           dr_cr_flag,encumbrance_amount,status_code,enc_line_type,schedule_line_id,org_schedule_id,
5642 	  default_org_account_id,suspense_org_account_id,element_account_id,gl_project_flag,
5643 	  enc_summary_line_id,person_id,assignment_id,award_id,task_id,expenditure_type,
5644 	  expenditure_organization_id,project_id,gl_code_combination_id,time_period_id,payroll_id,
5645 	  set_of_books_id,default_reason_code,suspense_reason_code,enc_control_id,change_flag,last_update_date,
5646 	  last_updated_by,last_update_login,created_by,creation_date,enc_start_date,enc_end_date,
5647 	attribute_category,	attribute1,		attribute2,		attribute3,
5648 	attribute4,		attribute5,		attribute6,		attribute7,
5649 	attribute8,		attribute9,		attribute10)
5650          SELECT enc_line_id,business_group_id,enc_element_type_id,encumbrance_date,
5651           dr_cr_flag,encumbrance_amount,status_code,enc_line_type,schedule_line_id,org_schedule_id,
5652 	  default_org_account_id,suspense_org_account_id,element_account_id,gl_project_flag,
5653 	  enc_summary_line_id,person_id,assignment_id,award_id,task_id,expenditure_type,
5654 	  expenditure_organization_id,project_id,gl_code_combination_id,time_period_id,payroll_id,
5655 	  set_of_books_id,default_reason_code,suspense_reason_code,enc_control_id,change_flag,last_update_date,
5656 	  last_updated_by,last_update_login,created_by,creation_date,enc_start_date,enc_end_date,
5657 	attribute_category,	attribute1,		attribute2,		attribute3,
5658 	attribute4,		attribute5,		attribute6,		attribute7,
5659 	attribute8,		attribute9,		attribute10
5660          FROM psp_enc_lines
5661          WHERE status_code = 'A'
5662          AND  enc_summary_line_id = l_enc_summary_line_id
5663 	 AND  enc_control_id = p_enc_control_id;
5664 
5665          DELETE FROM psp_enc_lines
5666          WHERE status_code = 'A'
5667          AND enc_summary_line_id = l_enc_summary_line_id
5668 	 AND enc_control_id = p_enc_control_id;
5669 
5670          -- commented For Bug 2290051
5671 	 / * DELETE from pa_transaction_interface_all
5672 	  where transaction_source = 'GOLDE'
5673 	    and batch_name = p_gms_batch_name
5674 	    and transaction_status_code = 'A'
5675 	    and orig_transaction_reference =  'E:' || to_char(l_enc_summary_line_id);
5676 
5677 	 DELETE from gms_transaction_interface_all
5678 	  where transaction_source = 'GOLDE'
5679 	    and batch_name = p_gms_batch_name
5680 	    and transaction_status_code = 'A'
5681 	    and orig_transaction_reference =  'E:' || to_char(l_enc_summary_line_id); * /
5682      END LOOP;
5683 
5684     UPDATE psp_enc_controls
5685        SET summ_ogm_dr_amount = l_dr_summary_amount,
5686            summ_ogm_cr_amount = l_cr_summary_amount,
5687            gms_phase = 'TieBack'
5688      WHERE enc_control_id = p_enc_control_id;
5689 
5690    END IF;
5691    END IF; -- IF (PROCESS_COMPLETE)
5692 
5693    p_return_status := fnd_api.g_ret_sts_success;
5694  EXCEPTION
5695    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5696      g_error_api_path := 'GMS_ENC_TIE_BACK:'||g_error_api_path;
5697      p_return_status := fnd_api.g_ret_sts_unexp_error;
5698 
5699    / * Added Exceptions for bug 2056877 * /
5700    WHEN NO_PROFILE_EXISTS THEN
5701       g_error_api_path := SUBSTR('GMS_ENC_TIE_BACK:'||g_error_api_path,1,230);
5702       fnd_message.set_name('PSP','PSP_NO_PROFILE_EXISTS');
5703       fnd_msg_pub.add;
5704       --p_return_status := fnd_api.g_ret_sts_unexp_error; commented and intro success for 2479579
5705    p_return_status := fnd_api.g_ret_sts_success;
5706 
5707    WHEN NO_VAL_DATE_MATCHES THEN
5708       g_error_api_path := SUBSTR('GMS_ENC_TIE_BACK:'||g_error_api_path,1,230);
5709       fnd_message.set_name('PSP','PSP_NO_VAL_DATE_MATCHES');
5710       fnd_message.set_token('ORG_NAME',l_orig_org_name);
5711       fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
5712       fnd_msg_pub.add;
5713       --p_return_status := fnd_api.g_ret_sts_unexp_error;  commented and intro success for 2479579
5714    p_return_status := fnd_api.g_ret_sts_success;
5715 
5716    WHEN NO_GLOBAL_ACCT_EXISTS THEN
5717       g_error_api_path := SUBSTR('GMS_ENC_TIE_BACK:'||g_error_api_path,1,230);
5718       fnd_message.set_name('PSP','PSP_NO_GLOBAL_ACCT_EXISTS');
5719       fnd_message.set_token('ORG_NAME',l_orig_org_name);
5720       fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
5721       fnd_msg_pub.add;
5722      -- p_return_status := fnd_api.g_ret_sts_unexp_error;  commented and intro success for 2479579
5723    p_return_status := fnd_api.g_ret_sts_success;
5724 
5725    WHEN OTHERS THEN
5726       g_error_api_path := 'GMS_ENC_TIE_BACK:'||g_error_api_path;
5727       fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','GMS_ENC_TIE_BACK');
5728       p_return_status := fnd_api.g_ret_sts_unexp_error;
5729 
5730 END;
5731 	End of comment for Create and Update multi thread enh.	*****/
5732 --	Introduced the following modified gms_enc_tie_back procedure for Create and Update multi thread enh.
5733 PROCEDURE gms_enc_tie_back(	p_payroll_action_id	IN		NUMBER,
5734 				p_gms_batch_name	IN		VARCHAR2,
5735 				p_business_group_id	IN		NUMBER,
5736 				p_set_of_books_id	IN		NUMBER,
5737 				p_return_status		OUT NOCOPY	VARCHAR2) IS
5738 CURSOR	gms_tie_back_success_cur IS
5739 SELECT	enc_control_id,
5740 	enc_summary_line_id,
5741 	dr_cr_flag,
5742 	TO_NUMBER(DECODE(dr_cr_flag, 'C', -summary_amount, summary_amount)) summary_amount
5743 FROM	psp_enc_summary_lines
5744 WHERE	gms_batch_name = p_gms_batch_name;
5745 
5746 CURSOR	gms_tie_back_reject_cur IS
5747 SELECT	NVL(transaction_rejection_code,'P'),
5748 	TO_NUMBER(SUBSTR(orig_transaction_reference, 3)),
5749 	transaction_status_code
5750 FROM	pa_transaction_interface_all
5751 WHERE	transaction_source = 'GOLDE'
5752 AND	batch_name = p_gms_batch_name;
5753 
5754 CURSOR	assign_susp_ac_cur IS
5755 SELECT	pel.rowid,
5756 	pel.encumbrance_date,
5757 	pel.enc_start_date,
5758 	pel.enc_end_date,
5759 	pel.person_id,
5760 	pel.assignment_id,
5761 	pel.payroll_id,
5762 	pel.enc_element_type_id,
5763 	pel.project_id,
5764 	pel.task_id,
5765 	pel.award_id,
5766 	pel.expenditure_organization_id,
5767 	pel.expenditure_type,
5768 	pel.suspense_org_account_id,
5769 	pesl.interface_status,
5770 	ptp.end_date
5771 FROM	psp_enc_lines pel,
5772 	psp_enc_summary_lines pesl,
5773 	per_time_periods ptp
5774 WHERE	pel.payroll_action_id = p_payroll_action_id
5775 AND	pel.enc_summary_line_id = pesl.enc_summary_line_id
5776 AND	pesl.payroll_action_id = p_payroll_action_id
5777 AND	pesl.status_code = 'R'
5778 AND	pesl.gms_batch_name = p_gms_batch_name
5779 AND	ptp.time_period_id = pel.time_period_id
5780 ORDER BY 5, 6, 7, 8, 9, 10, 11, 12, 3;
5781 
5782 CURSOR	get_susp_org_cur(P_ORG_ID	IN	VARCHAR2) IS
5783 SELECT	hou.organization_id, hou.name, poa.gl_code_combination_id
5784 FROM	hr_all_organization_units hou,
5785 	psp_organization_accounts poa
5786 WHERE	hou.organization_id = poa.organization_id
5787 AND	poa.business_group_id = p_business_group_id
5788 AND	poa.set_of_books_id = p_set_of_books_id
5789 AND	poa.organization_account_id = p_org_id;
5790 
5791 CURSOR	get_org_id_cur(P_ROWID IN ROWID) IS
5792 SELECT	hou.organization_id, hou.name
5793 FROM	hr_all_organization_units hou,
5794 	per_assignments_f paf,
5795 	psp_enc_lines pel
5796 WHERE	pel.rowid=p_rowid
5797 AND	pel.assignment_id = paf.assignment_id
5798 AND	pel.encumbrance_date BETWEEN paf.effective_start_date AND paf.effective_end_date
5799 AND	paf.organization_id = hou.organization_id
5800 AND	pel.encumbrance_date BETWEEN hou.date_from AND NVL(hou.date_to, pel.encumbrance_date);
5801 
5802 CURSOR	org_susp_ac_cur(P_ORGANIZATION_ID	IN	NUMBER,
5803                           P_ENCUMBRANCE_DATE	IN	DATE) IS
5804 SELECT	poa.organization_account_id,
5805 	poa.gl_code_combination_id,
5806 	poa.project_id,
5807 	poa.expenditure_organization_id,
5808 	poa.expenditure_type,
5809 	poa.award_id,
5810 	poa.task_id
5811 FROM	psp_organization_accounts poa
5812 WHERE	poa.organization_id = p_organization_id
5813 AND	poa.business_group_id = p_business_group_id
5814 AND	poa.set_of_books_id = p_set_of_books_id
5815 AND	poa.account_type_code = 'S'
5816 AND	p_encumbrance_date BETWEEN poa.start_date_active AND NVL(poa.end_date_active, p_encumbrance_date);
5817 
5818 CURSOR	global_susp_ac_cur(P_ORGANIZATION_ACCOUNT_ID IN NUMBER) IS
5819 SELECT	poa.organization_account_id,
5820 	poa.gl_code_combination_id,
5821 	poa.project_id,
5822 	poa.expenditure_organization_id,
5823 	poa.expenditure_type,
5824 	poa.award_id,
5825 	poa.task_id
5826 FROM	psp_organization_accounts poa
5827 WHERE	organization_account_id = p_organization_account_id;
5828 
5829 CURSOR	txn_interface_count_cur IS
5830 SELECT	COUNT(1)
5831 FROM	pa_transaction_interface_all
5832 WHERE	transaction_source = 'GOLDE'
5833 AND	batch_name = p_gms_batch_name
5834 AND	transaction_status_code in ('R', 'PI', 'PO', 'PR');
5835 
5836 CURSOR	get_success_recs_cur IS
5837 SELECT	enc_control_id,
5838 	enc_summary_line_id,
5839 	dr_cr_flag,
5840 	TO_NUMBER(DECODE(dr_cr_flag, 'C', -summary_amount, summary_amount)) summary_amount
5841 FROM	psp_enc_summary_lines
5842 WHERE	gms_batch_name = p_gms_batch_name
5843 AND	status_code = 'A';
5844 
5845 l_encumbrance_date				DATE;
5846 l_lines_glccid					NUMBER(15);
5847 l_organization_account_id		NUMBER(9);
5848 l_susp_glccid					NUMBER(15);
5849 l_new_gl_code_combination_id	NUMBER(15);
5850 l_orig_org_name					hr_all_organization_units_tl.name%TYPE;
5851 l_orig_org_id					NUMBER(15);
5852 l_cnt_gl_interface				NUMBER;
5853 l_autopop_status				VARCHAR2(1);
5854 l_gl_project_flag				VARCHAR2(1);
5855 l_suspense_ac_failed			VARCHAR2(1);
5856 l_suspense_ac_not_found			VARCHAR2(1);
5857 l_susp_ac_found					VARCHAR2(10);
5858 l_organization_name				hr_all_organization_units_tl.name%TYPE;
5859 l_organization_id				NUMBER(15);
5860 l_return_value					VARCHAR2(30);
5861 l_autopop_error					VARCHAR2(30);
5862 l_effective_date				DATE;
5863 no_profile_exists				EXCEPTION;
5864 no_val_date_matches				EXCEPTION;
5865 no_global_acct_exists			EXCEPTION;
5866 suspense_autopop_failed			EXCEPTION;
5867 l_susp_exception				VARCHAR2(50);
5868 l_project_id					NUMBER(15);
5869 l_expenditure_organization_id	NUMBER(15);
5870 l_expenditure_type				VARCHAR2(30);
5871 l_new_expenditure_type			VARCHAR2(30);
5872 l_award_id						NUMBER(15);
5873 l_task_id						NUMBER(15);
5874 l_return_status					VARCHAR2(1);
5875 l_cnt_gms_interface				NUMBER;
5876 l_project_number				pa_projects_all.segment1%TYPE;
5877 l_task_number					pa_tasks.task_number%TYPE;
5878 l_award_number					gms_awards_all.award_number%TYPE;
5879 l_exp_org_name					hr_organization_units.name%TYPE;
5880 l_gl_description				VARCHAR2(4000);
5881 
5882 CURSOR	project_number_cur IS
5883 SELECT	SEGMENT1
5884 FROM	pa_projects_all
5885 WHERE	project_id = l_project_id;
5886 
5887 CURSOR	award_number_cur IS
5888 SELECT	award_number
5889 FROM	gms_awards_all
5890 WHERE	award_id = l_award_id;
5891 
5892 CURSOR	task_number_cur Is
5893 SELECT	task_number
5894 FROM	pa_tasks
5895 WHERE	task_id = l_task_id;
5896 
5897 CURSOR	exp_org_name_cur IS
5898 SELECT	name
5899 FROM	hr_organization_units
5900 WHERE	organization_id = l_expenditure_organization_id;
5901 
5902 TYPE t_rowid IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
5903 TYPE t_date IS TABLE OF DATE INDEX BY BINARY_INTEGER;
5904 TYPE t_number IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
5905 TYPE t_number_15 IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
5906 TYPE t_char_300 IS TABLE OF VARCHAR2(300) INDEX BY BINARY_INTEGER;
5907 
5908 TYPE r_tieback_rec IS RECORD
5909 	(enc_summary_line_id	t_number_15,
5910 	enc_control_id		t_number_15,
5911 	reason_code		t_char_300,
5912 	txn_status_code		t_char_300,
5913 	dr_cr_flag		t_char_300,
5914 	summary_amount		t_number);
5915 
5916 r_reject_recs	r_tieback_rec;
5917 r_success_recs	r_tieback_rec;
5918 
5919 TYPE r_interface_rec IS RECORD
5920 	(status			t_char_300,
5921 	enc_summary_line_id	t_number_15,
5922 	dr_cr_flag		t_char_300,
5923 	summary_amount		t_number,
5924 	enc_control_id		t_number_15);
5925 r_interface	r_interface_rec;
5926 
5927 TYPE r_suspense_ac_rec IS RECORD
5928 	(row_id					t_rowid,
5929 	encumbrance_date		t_date,
5930 	enc_start_date			t_date,
5931 	enc_end_date			t_date,
5932 	person_id				t_number_15,
5933 	assignment_id			t_number_15,
5934 	element_type_id			t_number_15,
5935 	payroll_id				t_number_15,
5936 	project_id				t_number_15,
5937 	task_id					t_number_15,
5938 	award_id				t_number_15,
5939 	expenditure_organization_id	t_number_15,
5940 	expenditure_type		t_char_300,
5941 	suspense_org_account_id	t_number_15,
5942 	interface_status		t_char_300,
5943 	end_date				t_date);
5944 r_suspense_ac	r_suspense_ac_rec;
5945 
5946 FUNCTION PROCESS_COMPLETE RETURN BOOLEAN IS
5947 l_cnt	NUMBER;
5948 l_status	VARCHAR2(30);
5949 
5950 TYPE t_number_15 IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
5951 TYPE r_superceded_line_rec IS RECORD (superceded_line_id	t_number_15);
5952 r_superceded_lines	r_superceded_line_rec;
5953 
5954 CURSOR	transaction_status_cur IS
5955 SELECT	COUNT(*),
5956 	transaction_status_code
5957 FROM	pa_transaction_interface_all
5958 WHERE	transaction_source='GOLDE'
5959 AND	batch_name = p_gms_batch_name
5960 AND	transaction_Status_code in ('P','I')
5961 GROUP BY transaction_status_code;
5962 BEGIN
5963 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering GMS_ENC_TIE_BACK.PROCESS_COMPLETE');
5964 
5965 	OPEN transaction_status_cur;
5966 	FETCH transaction_status_cur INTO l_cnt, l_status;
5967 	IF (transaction_status_cur%ROWCOUNT = 0) THEN
5968 		l_cnt := 0;
5969 	END IF;
5970 	CLOSE transaction_status_cur;
5971 
5972 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_cnt: ' || l_cnt);
5973 
5974 	IF l_cnt = 0 THEN
5975 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GMS_ENC_TIE_BACK.PROCESS_COMPLETE');
5976 		RETURN TRUE;
5977 	ELSIF l_cnt > 0 THEN
5978 		IF l_status = 'P' THEN
5979 			DELETE FROM pa_transaction_interface_all
5980 			WHERE	transaction_source = 'GOLDE'
5981 			AND	batch_name = p_gms_batch_name;
5982 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted from pa_trancsaction_interface_all');
5983 
5984 			DELETE FROM gms_transaction_interface_all
5985 			WHERE	transaction_source = 'GOLDE'
5986 			AND	batch_name = p_gms_batch_name;
5987 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted from gms_trancsaction_interface_all');
5988 
5989 			DELETE FROM psp_enc_summary_lines
5990 			WHERE	gms_batch_name = p_gms_batch_name;
5991 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted from psp_enc_summary_lines');
5992 
5993 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GMS_ENC_TIE_BACK.PROCESS_COMPLETE');
5994 			RETURN FALSE;
5995 		ELSIF l_status = 'I' THEN
5996 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GMS_ENC_TIE_BACK.PROCESS_COMPLETE');
5997 			RETURN FALSE;
5998 		END IF;
5999 	END IF;
6000 EXCEPTION
6001 	WHEN OTHERS THEN
6002 		RETURN TRUE;
6003 END	PROCESS_COMPLETE;
6004 BEGIN
6005 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering GMS_ENC_TIE_BACK');
6006 
6007 	IF (PROCESS_COMPLETE) THEN
6008 		OPEN txn_interface_count_cur;
6009 		FETCH txn_interface_count_cur INTO l_cnt_gms_interface;
6010 		CLOSE txn_interface_count_cur;
6011 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	l_cnt_gms_interface: ' || l_cnt_gms_interface);
6012 
6013 		IF l_cnt_gms_interface > 0 THEN
6014 			OPEN gms_tie_back_reject_cur;
6015 			FETCH gms_tie_back_reject_cur BULK COLLECT INTO r_reject_recs.reason_code, r_reject_recs.enc_summary_line_id,
6016 				r_reject_recs.txn_status_code;
6017 			CLOSE gms_tie_back_reject_cur;
6018 
6019 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_reject_recs.enc_summary_line_id.COUNT: ' || r_reject_recs.enc_summary_line_id.COUNT);
6020 
6021 			FORALL recno IN 1..r_reject_recs.enc_summary_line_id.COUNT
6022 			UPDATE	psp_enc_summary_lines
6023 			SET	interface_status = r_reject_recs.reason_code(recno),
6024 				status_code = 'R'
6025 			WHERE	enc_summary_line_id = r_reject_recs.enc_summary_line_id(recno)
6026 			AND	r_reject_recs.txn_status_code(recno) IN ('R', 'PI', 'PO', 'PR');
6027 
6028 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated interface_status with reject reason code in psp_enc_summary_lines');
6029 
6030 			FORALL recno IN 1..r_reject_recs.enc_summary_line_id.COUNT
6031 			UPDATE	psp_enc_summary_lines
6032 			SET	interface_status = r_reject_recs.reason_code(recno),
6033 				status_code = 'A'
6034 			WHERE	enc_summary_line_id = r_reject_recs.enc_summary_line_id(recno)
6035 			AND	r_reject_recs.txn_status_code(recno) = 'A';
6036 
6037 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated status_code to ''A'' for accepted records in psp_enc_summary_lines');
6038 
6039 			OPEN get_success_recs_cur;
6040 			FETCH get_success_recs_cur BULK COLLECT INTO r_success_recs.enc_control_id, r_success_recs.enc_summary_line_id,
6041 				r_success_recs.dr_cr_flag, r_success_recs.summary_amount;
6042 			CLOSE get_success_recs_cur;
6043 
6044 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_success_recs.enc_summary_line_id.COUNT: ' || r_success_recs.enc_summary_line_id.COUNT);
6045 
6046 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6047 			INSERT INTO psp_enc_lines_history
6048 				(enc_line_id,			business_group_id,	enc_element_type_id,	encumbrance_date,
6049 				dr_cr_flag,			encumbrance_amount,	status_code,		enc_line_type,
6050 				schedule_line_id,		org_schedule_id,	default_org_account_id,	suspense_org_account_id,
6051 				element_account_id,		gl_project_flag,	enc_summary_line_id,	person_id,
6052 				assignment_id,			award_id,		task_id,		expenditure_type,
6053 				expenditure_organization_id,	project_id,		gl_code_combination_id,	time_period_id,
6054 				payroll_id,			set_of_books_id,	default_reason_code,	suspense_reason_code,
6055 				enc_control_id,			change_flag,		last_update_date,	last_updated_by,
6056 				last_update_login,		created_by,		creation_date,		enc_start_date,
6057 				enc_end_date,			attribute_category,	attribute1,		attribute2,
6058 				attribute3,			attribute4,		attribute5,		attribute6,
6059 				attribute7,			attribute8,		attribute9,		attribute10,
6060 				payroll_action_id,	hierarchy_code,	hierarchy_start_date,	hierarchy_end_date,
6061 				orig_gl_code_combination_id,	orig_project_id,	orig_task_id,	orig_award_id,
6062 				orig_expenditure_org_id,		orig_expenditure_type)
6063 			SELECT	enc_line_id,			business_group_id,	enc_element_type_id,	encumbrance_date,
6064 				dr_cr_flag,			encumbrance_amount,	'A',		enc_line_type,
6065 				schedule_line_id,		org_schedule_id,	default_org_account_id,	suspense_org_account_id,
6066 				element_account_id,		gl_project_flag,	enc_summary_line_id,	person_id,
6067 				assignment_id,			award_id,		task_id,		expenditure_type,
6068 				expenditure_organization_id,	project_id,		gl_code_combination_id,	time_period_id,
6069 				payroll_id,			set_of_books_id,	default_reason_code,	suspense_reason_code,
6070 				enc_control_id,			change_flag,		last_update_date,	last_updated_by,
6071 				last_update_login,		created_by,		creation_date,		enc_start_date,
6072 				enc_end_date,			attribute_category,	attribute1,		attribute2,
6073 				attribute3,			attribute4,		attribute5,		attribute6,
6074 				attribute7,			attribute8,		attribute9,		attribute10,
6075 				payroll_action_id,	hierarchy_code,	hierarchy_start_date,	hierarchy_end_date,
6076 				orig_gl_code_combination_id,	orig_project_id,	orig_task_id,	orig_award_id,
6077 				orig_expenditure_org_id,		orig_expenditure_type
6078 			FROM	psp_enc_lines
6079 			WHERE	enc_summary_line_id = r_success_recs.enc_summary_line_id(recno);
6080 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Copied successfully summarized and transferred lines into psp_enc_lines_history');
6081 
6082 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6083 			DELETE FROM psp_enc_lines
6084 			WHERE	enc_summary_line_id = r_success_recs.enc_summary_line_id(recno);
6085 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted lines from psp_enc_lines that are summarized and trasnferred to target systems');
6086 
6087 			OPEN assign_susp_ac_cur;
6088 			FETCH assign_susp_ac_cur BULK COLLECT INTO r_suspense_ac.row_id, r_suspense_ac.encumbrance_date,
6089 				r_suspense_ac.enc_start_date, r_suspense_ac.enc_end_date, r_suspense_ac.person_id,
6090 				r_suspense_ac.assignment_id, r_suspense_ac.payroll_id, r_suspense_ac.element_type_id,
6091 				r_suspense_ac.project_id, r_suspense_ac.task_id, r_suspense_ac.award_id,
6092 				r_suspense_ac.expenditure_organization_id, r_suspense_ac.expenditure_type,
6093 				r_suspense_ac.suspense_org_account_id, r_suspense_ac.interface_status,
6094 				r_suspense_ac.end_date;
6095 			CLOSE assign_susp_ac_cur;
6096 
6097 			FOR recno IN 1..r_suspense_ac.row_id.COUNT
6098 			LOOP
6099 				IF r_suspense_ac.suspense_org_account_id(recno) IS NOT NULL THEN
6100 					OPEN get_susp_org_cur(r_suspense_ac.suspense_org_account_id(recno));
6101 					FETCH get_susp_org_cur INTO l_organization_id, l_organization_name, l_lines_glccid;
6102 					CLOSE get_susp_org_cur;
6103 
6104 					l_suspense_ac_failed	:= 'Y';
6105 					g_susp_prob := 'Y';
6106 					fnd_message.set_name('PSP', 'PSP_TR_GMS_SUSP_AC_REJECT');
6107 					fnd_message.set_token('ORG_NAME', l_organization_name);
6108 					fnd_message.set_token('PAYROLL_DATE', r_suspense_ac.encumbrance_date(recno));
6109 					fnd_message.set_token('ERROR_MSG', r_suspense_ac.interface_status(recno));
6110 					fnd_msg_pub.add;
6111 				ELSE
6112 					l_susp_ac_found := 'TRUE';
6113 
6114 					OPEN get_org_id_cur(r_suspense_ac.row_id(recno));
6115 					FETCH get_org_id_cur INTO l_orig_org_id, l_orig_org_name;
6116 					CLOSE get_org_id_cur;
6117 
6118 					OPEN org_susp_ac_cur(l_orig_org_id, r_suspense_ac.encumbrance_date(recno));
6119 					FETCH org_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,
6120 						l_expenditure_organization_id, l_expenditure_type, l_award_id, l_task_id;
6121 
6122 					IF org_susp_ac_cur%NOTFOUND THEN
6123 						l_return_value := psp_general.find_global_suspense(r_suspense_ac.encumbrance_date(recno),
6124 								p_business_group_id,
6125 								p_set_of_books_id,
6126 								l_organization_account_id);
6127 
6128 						IF l_return_value = 'PROFILE_VAL_DATE_MATCHES' THEN
6129 							OPEN global_susp_ac_cur(l_organization_account_id);
6130 							FETCH global_susp_ac_cur INTO l_organization_account_id,l_susp_glccid,l_project_id,
6131 								l_expenditure_organization_id, l_expenditure_type, l_award_id, l_task_id;
6132 
6133 							IF global_susp_ac_cur%NOTFOUND THEN
6134 								l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
6135 								l_suspense_ac_not_found := 'Y';
6136 								l_susp_ac_found := 'NO_G_AC';
6137 							END IF;
6138 							CLOSE global_susp_ac_cur;
6139 						ELSIF l_return_value = 'NO_GLOBAL_ACCT_EXISTS' THEN
6140 							l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
6141 							l_suspense_ac_not_found := 'Y';
6142 							l_susp_ac_found := 'NO_G_AC';
6143 						ELSIF l_return_value = 'NO_VAL_DATE_MATCHES' THEN
6144 							l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
6145 							l_suspense_ac_not_found := 'Y';
6146 							l_susp_ac_found := 'NO_DT_MCH';
6147 						ELSIF l_return_value = 'NO_PROFILE_EXISTS' THEN
6148 							l_encumbrance_date := r_suspense_ac.encumbrance_date(recno);
6149 							l_suspense_ac_not_found := 'Y';
6150 							l_susp_ac_found := 'NO_PROFL';
6151 						END IF;
6152 					END IF;
6153 					CLOSE org_susp_ac_cur;
6154 
6155 					IF l_susp_ac_found = 'TRUE' THEN
6156 						IF l_susp_glccid IS NOT NULL THEN
6157 							l_gl_project_flag := 'G';
6158 							l_effective_date := r_suspense_ac.end_date(recno);
6159 
6160 							IF (g_sa_autopop) THEN
6161 								psp_autopop.main(p_acct_type		=> 'N',
6162 									p_person_id			=> r_suspense_ac.person_id(recno),
6163 									p_assignment_id			=> r_suspense_ac.assignment_id(recno),
6164 									p_element_type_id		=> r_suspense_ac.element_type_id(recno),
6165 									p_project_id			=> l_project_id,
6166 									p_expenditure_organization_id	=> l_expenditure_organization_id,
6167 									p_task_id			=> l_task_id,
6168 									p_award_id			=> l_award_id,
6169 									p_expenditure_type		=> l_expenditure_type,
6170 									p_gl_code_combination_id	=> l_susp_glccid,
6171 									p_payroll_date			=> l_effective_date,
6172 									p_set_of_books_id		=> g_set_of_books_id,
6173 									p_business_group_id		=> g_business_group_id,
6174 									ret_expenditure_type		=> l_new_expenditure_type,
6175 									ret_gl_code_combination_id	=> l_new_gl_code_combination_id,
6176 									retcode				=> l_autopop_status);
6177 
6178 								IF (l_autopop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
6179 									(l_autopop_status = FND_API.G_RET_STS_ERROR) THEN
6180 									l_susp_exception := 'AUTOPOP';
6181 									l_suspense_ac_not_found := 'Y';
6182 									l_autopop_error := 'AUTO_POP_EXP_ERROR';
6183 									IF (l_autopop_status = FND_API.G_RET_STS_ERROR) THEN
6184 										l_autopop_error := 'AUTO_POP_NO_VALUE';
6185 									END IF;
6186 									l_gl_description := psp_general.get_gl_values(g_set_of_books_id, l_susp_glccid);
6187 									fnd_message.set_name('PSP', 'PSP_SUSPENSE_REASON_AUTOPOP');
6188 									fnd_message.set_token('START_DATE', l_effective_date);
6189 									fnd_message.set_token('END_DATE', l_effective_date);
6190 									fnd_message.set_token('GL', l_gl_description);
6191 									fnd_message.set_token('AUTOPOP_STATUS', l_autopop_error);
6192 									g_warning_message := fnd_message.get;
6193 									fnd_file.put_line(fnd_file.log, g_warning_message);
6194 								ELSE
6195 									l_susp_glccid := l_new_gl_code_combination_id;
6196 								END IF;
6197 							END IF;
6198 						ELSE
6199 							l_gl_project_flag := 'P';
6200 							psp_general.poeta_effective_date(r_suspense_ac.encumbrance_date(recno),
6201 								l_project_id, l_award_id, l_task_id, l_effective_date,
6202 								l_return_status);
6203 							IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6204 								RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6205 							END IF;
6206 							IF (g_sa_autopop) THEN
6207 								psp_autopop.main(p_acct_type		=> 'E',
6208 									p_person_id			=> r_suspense_ac.person_id(recno),
6209 									p_assignment_id			=> r_suspense_ac.assignment_id(recno),
6210 									p_element_type_id		=> r_suspense_ac.element_type_id(recno),
6211 									p_project_id			=> l_project_id,
6212 									p_expenditure_organization_id	=> l_expenditure_organization_id,
6213 									p_task_id			=> l_task_id,
6214 									p_award_id			=> l_award_id,
6215 									p_expenditure_type		=> l_expenditure_type,
6216 									p_gl_code_combination_id	=> l_susp_glccid,
6217 									p_payroll_date			=> l_effective_date,
6218 									p_set_of_books_id		=> g_set_of_books_id,
6219 									p_business_group_id		=> g_business_group_id,
6220 									ret_expenditure_type		=> l_new_expenditure_type,
6221 									ret_gl_code_combination_id	=> l_new_gl_code_combination_id,
6222 									retcode				=> l_autopop_status);
6223 
6224 								IF (l_autopop_status = FND_API.G_RET_STS_UNEXP_ERROR) OR
6225 									(l_autopop_status = FND_API.G_RET_STS_ERROR) THEN
6226 									l_susp_exception := 'AUTOPOP';
6227 									l_suspense_ac_not_found := 'Y';
6228 									l_autopop_error := 'AUTO_POP_EXP_ERROR';
6229 									IF (l_autopop_status = FND_API.G_RET_STS_ERROR) THEN
6230 										l_autopop_error := 'AUTO_POP_NO_VALUE';
6231 									END IF;
6232 									OPEN project_number_cur;
6233 									FETCH project_number_cur INTO l_project_number;
6234 									CLOSE project_number_cur;
6235 
6236 									OPEN award_number_cur;
6237 									FETCH award_number_cur INTO l_award_number;
6238 									CLOSE award_number_cur;
6239 
6240 									OPEN task_number_cur;
6241 									FETCH task_number_cur INTO l_task_number;
6242 									CLOSE task_number_cur;
6243 
6244 									OPEN exp_org_name_cur;
6245 									FETCH exp_org_name_cur INTO l_exp_org_name;
6246 									CLOSE exp_org_name_cur;
6247 
6248 									fnd_message.set_name('PSP', 'PSP_SUSPENSE_REASON_AP_PATEO');
6249 									fnd_message.set_token('START_DATE', l_effective_date);
6250 									fnd_message.set_token('END_DATE', l_effective_date);
6251 									fnd_message.set_token('PJ', l_project_number);
6252 									fnd_message.set_token('TK', l_task_number);
6253 									fnd_message.set_token('AW', l_award_number);
6254 									fnd_message.set_token('EO', l_exp_org_name);
6255 									fnd_message.set_token('ET', l_expenditure_type);
6256 									fnd_message.set_token('AUTOPOP_STATUS', l_autopop_error);
6257 									g_warning_message := fnd_message.get;
6258 									fnd_file.put_line(fnd_file.log, g_warning_message);
6259 								ELSE
6260 									l_expenditure_type := l_new_expenditure_type;
6261 								END IF;
6262 							END IF;
6263 						END IF;
6264 
6265 						UPDATE	psp_enc_lines
6266 						SET	prev_effective_date = encumbrance_date,
6267 							prev_enc_end_date = enc_end_date,
6268 							prev_encumbrance_amount = encumbrance_amount,
6269 							orig_gl_code_combination_id = gl_code_combination_id,
6270 							orig_project_id = project_id,
6271 							orig_task_id = task_id,
6272 							orig_award_id = award_id,
6273 							orig_expenditure_org_id = expenditure_organization_id,
6274 							orig_expenditure_type = expenditure_type
6275 						WHERE	rowid = r_suspense_ac.row_id(recno);
6276 
6277 						UPDATE	psp_enc_lines
6278 						SET	suspense_org_account_id = l_organization_account_id,
6279 							gl_code_combination_id = l_susp_glccid,
6280 							project_id = l_project_id,
6281 							task_id = l_task_id,
6282 							award_id = l_award_id,
6283 							expenditure_organization_id = l_expenditure_organization_id,
6284 							expenditure_type = l_expenditure_type,
6285 							suspense_reason_code = 'ES:' || r_suspense_ac.interface_status(recno),
6286 							gl_project_flag = l_gl_project_flag,
6287 							encumbrance_date = l_effective_date,
6288 							enc_end_date = LEAST(enc_end_date, g_def_end_date),
6289 							encumbrance_amount = (encumbrance_amount * (psp_general.business_days(enc_start_date, LEAST(enc_end_date, g_def_end_date)) / psp_general.business_days(enc_start_date, enc_end_date))),
6290 							status_code = 'N'
6291 						WHERE	rowid = r_suspense_ac.row_id(recno);
6292 
6293 						add_st_warnings(p_assignment_id	=>	r_suspense_ac.assignment_id(recno),
6294 								p_payroll_id		=>	r_suspense_ac.payroll_id(recno),
6295 								p_element_type_id	=>	r_suspense_ac.element_type_id(recno),
6296 								p_start_date		=>	r_suspense_ac.enc_start_date(recno),
6297 								p_end_date			=>	r_suspense_ac.enc_end_date(recno),
6298 								p_effective_date	=>	r_suspense_ac.encumbrance_date(recno),
6299 								p_project_id		=>	r_suspense_ac.project_id(recno),
6300 								p_task_id			=>	r_suspense_ac.task_id(recno),
6301 								p_award_id			=>	r_suspense_ac.award_id(recno),
6302 								p_exp_org_id		=>	r_suspense_ac.expenditure_organization_id(recno),
6303 								p_exp_type			=>	r_suspense_ac.expenditure_type(recno),
6304 								p_error_status		=>	r_suspense_ac.interface_status(recno));
6305 					ELSE
6306 						l_susp_exception := l_susp_ac_found;
6307 					END IF;
6308 				END IF;
6309 			END LOOP;
6310 
6311 			IF l_suspense_ac_failed = 'Y' THEN
6312 				UPDATE	psp_enc_lines
6313 				SET	suspense_org_account_id = NULL,
6314 					gl_code_combination_id = orig_gl_code_combination_id,
6315 					project_id = orig_project_id,
6316 					task_id = orig_task_id,
6317 					award_id = orig_award_id,
6318 					expenditure_organization_id = orig_expenditure_org_id,
6319 					expenditure_type = orig_expenditure_type,
6320 					gl_project_flag = decode(orig_gl_code_combination_id,NULL,'P','G'),
6321 					encumbrance_date = prev_effective_date,
6322 					enc_end_date = NVL(prev_enc_end_date, enc_end_date),
6323 					encumbrance_amount = NVL(prev_encumbrance_amount, encumbrance_amount)
6324 				WHERE	suspense_reason_code like 'ES:%'
6325 				AND	enc_summary_line_id IN	(SELECT	enc_summary_line_id
6326 								FROM	psp_enc_summary_lines pesl
6327 								WHERE	pesl.payroll_action_id = p_payroll_action_id
6328 								AND	pesl.gms_batch_name = p_gms_batch_name
6329 								AND	status_code = 'R');
6330 				UPDATE	psp_enc_lines
6331 				SET	orig_gl_code_combination_id = NULL,
6332 					orig_project_id = NULL,
6333 					orig_task_id = NULL,
6334 					orig_award_id = NULL,
6335 					orig_expenditure_org_id = NULL,
6336 					orig_expenditure_type = NULL,
6337 					suspense_reason_code = NULL,
6338 					prev_enc_end_date = NULL,
6339 					prev_encumbrance_amount = NULL
6340 				WHERE	suspense_reason_code like 'ES:%'
6341 				AND	enc_summary_line_id IN	(SELECT	enc_summary_line_id
6342 								FROM	psp_enc_summary_lines pesl
6343 								WHERE	pesl.payroll_action_id = p_payroll_action_id
6344 								AND	pesl.gms_batch_name = p_gms_batch_name
6345 								AND	status_code = 'R');
6346 			END IF;
6347 
6348 			IF l_suspense_ac_not_found = 'Y' THEN
6349 				g_susp_prob := 'Y';
6350 				IF l_susp_exception = 'NO_G_AC' THEN
6351 					RAISE no_global_acct_exists;
6352 				ELSIF l_susp_exception = 'NO_DT_MCH' THEN
6353 					RAISE no_val_date_matches;
6354 				ELSIF l_susp_exception = 'NO_PROFL' THEN
6355 					RAISE no_profile_exists;
6356 				ELSIF l_susp_exception = 'AUTOPOP' THEN
6357 					RAISE suspense_autopop_failed;
6358 				END IF;
6359 			END IF;
6360 
6361 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6362 			UPDATE	psp_enc_controls pec
6363 			SET	summ_ogm_dr_amount = NVL(pec.summ_ogm_dr_amount, 0) + DECODE(r_success_recs.dr_cr_flag(recno), 'D', r_success_recs.summary_amount(recno), 0),
6364 				summ_ogm_cr_amount = NVL(pec.summ_ogm_cr_amount, 0) + DECODE(r_success_recs.dr_cr_flag(recno), 'C', r_success_recs.summary_amount(recno), 0)
6365 			WHERE	enc_control_id = r_success_recs.enc_control_id(recno);
6366 
6367 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Update summ_ogm_cr_amount, summ_ogm_dr_amount in psp_enc_controls');
6368 
6369 			r_reject_recs.enc_summary_line_id.DELETE;
6370 			r_reject_recs.enc_control_id.DELETE;
6371 			r_reject_recs.reason_code.DELETE;
6372 			r_reject_recs.txn_status_code.DELETE;
6373 			r_success_recs.enc_summary_line_id.DELETE;
6374 			r_success_recs.enc_control_id.DELETE;
6375 			r_success_recs.reason_code.DELETE;
6376 			r_success_recs.txn_status_code.DELETE;
6377 		ELSIF l_cnt_gms_interface = 0 THEN
6378 			OPEN gms_tie_back_success_cur;
6379 			FETCH gms_tie_back_success_cur BULK COLLECT INTO r_success_recs.enc_control_id, r_success_recs.enc_summary_line_id,
6380 				r_success_recs.dr_cr_flag, r_success_recs.summary_amount;
6381 			CLOSE gms_tie_back_success_cur;
6382 
6383 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	r_success_recs.enc_summary_line_id.COUNT: ' || r_success_recs.enc_summary_line_id.COUNT);
6384 
6385 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6386 			UPDATE	psp_enc_summary_lines
6387 			SET	status_code = 'A'
6388 			WHERE	enc_summary_line_id = r_success_recs.enc_summary_line_id(recno);
6389 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated status_code to ''A'' in psp_enc_summary_lines');
6390 
6391 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6392 			INSERT INTO psp_enc_lines_history
6393 				(enc_line_id,			business_group_id,	enc_element_type_id,	encumbrance_date,
6394 				dr_cr_flag,			encumbrance_amount,	status_code,		enc_line_type,
6395 				schedule_line_id,		org_schedule_id,	default_org_account_id,	suspense_org_account_id,
6396 				element_account_id,		gl_project_flag,	enc_summary_line_id,	person_id,
6397 				assignment_id,			award_id,		task_id,		expenditure_type,
6398 				expenditure_organization_id,	project_id,		gl_code_combination_id,	time_period_id,
6399 				payroll_id,			set_of_books_id,	default_reason_code,	suspense_reason_code,
6400 				enc_control_id,			change_flag,		last_update_date,	last_updated_by,
6401 				last_update_login,		created_by,		creation_date,		enc_start_date,
6402 				enc_end_date,			attribute_category,	attribute1,		attribute2,
6403 				attribute3,			attribute4,		attribute5,		attribute6,
6404 				attribute7,			attribute8,		attribute9,		attribute10,
6405 				payroll_action_id,	hierarchy_code,	hierarchy_start_date,	hierarchy_end_date)
6406 			SELECT	enc_line_id,			business_group_id,	enc_element_type_id,	encumbrance_date,
6407 				dr_cr_flag,			encumbrance_amount,	'A',		enc_line_type,
6408 				schedule_line_id,		org_schedule_id,	default_org_account_id,	suspense_org_account_id,
6409 				element_account_id,		gl_project_flag,	enc_summary_line_id,	person_id,
6410 				assignment_id,			award_id,		task_id,		expenditure_type,
6411 				expenditure_organization_id,	project_id,		gl_code_combination_id,	time_period_id,
6412 				payroll_id,			set_of_books_id,	default_reason_code,	suspense_reason_code,
6413 				enc_control_id,			change_flag,		last_update_date,	last_updated_by,
6414 				last_update_login,		created_by,		creation_date,		enc_start_date,
6415 				enc_end_date,			attribute_category,	attribute1,		attribute2,
6416 				attribute3,			attribute4,		attribute5,		attribute6,
6417 				attribute7,			attribute8,		attribute9,		attribute10,
6418 				payroll_action_id,	hierarchy_code,	hierarchy_start_date,	hierarchy_end_date
6419 			FROM	psp_enc_lines
6420 			WHERE	enc_summary_line_id = r_success_recs.enc_summary_line_id(recno);
6421 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Copied successfully summarized and transferred lines into psp_enc_lines_history');
6422 
6423 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6424 			DELETE FROM psp_enc_lines
6425 			WHERE	enc_summary_line_id = r_success_recs.enc_summary_line_id(recno);
6426 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Deleted lines from psp_enc_lines that are summarized and trasnferred to target systems');
6427 
6428 			FORALL recno IN 1..r_success_recs.enc_summary_line_id.COUNT
6429 			UPDATE	psp_enc_controls pec
6430 			SET	gms_phase = 'TieBack',
6431 				summ_ogm_dr_amount = NVL(pec.summ_ogm_dr_amount, 0) + DECODE(r_success_recs.dr_cr_flag(recno), 'D', r_success_recs.summary_amount(recno), 0),
6432 				summ_ogm_cr_amount = NVL(pec.summ_ogm_cr_amount, 0) + DECODE(r_success_recs.dr_cr_flag(recno), 'C', r_success_recs.summary_amount(recno), 0)
6433 			WHERE	enc_control_id = r_success_recs.enc_control_id(recno);
6434 
6435 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Updated summ_ogm_cr_amount, summ_ogm_dr_amount, gms_phase in psp_enc_controls');
6436 
6437 			r_success_recs.enc_summary_line_id.DELETE;
6438 			r_success_recs.enc_control_id.DELETE;
6439 			r_success_recs.reason_code.DELETE;
6440 			r_success_recs.txn_status_code.DELETE;
6441 		END IF;
6442 	ELSE
6443 		g_process_complete := FALSE;
6444 	END IF;
6445 
6446 	p_return_status := fnd_api.g_ret_sts_success;
6447 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GMS_ENC_TIE_BACK');
6448 EXCEPTION
6449 	WHEN NO_PROFILE_EXISTS THEN
6450 		g_error_api_path := SUBSTR('GMS_ENC_TIE_BACK:'||g_error_api_path,1,230);
6451 		fnd_message.set_name('PSP','PSP_NO_PROFILE_EXISTS');
6452 		fnd_msg_pub.add;
6453 		p_return_status := fnd_api.g_ret_sts_success;
6454 	WHEN NO_VAL_DATE_MATCHES THEN
6455 		g_error_api_path := SUBSTR('GMS_ENC_TIE_BACK:'||g_error_api_path,1,230);
6456 		fnd_message.set_name('PSP','PSP_NO_VAL_DATE_MATCHES');
6457 		fnd_message.set_token('ORG_NAME',l_orig_org_name);
6458 		fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
6459 		fnd_msg_pub.add;
6460 		p_return_status := fnd_api.g_ret_sts_success;
6461 	WHEN NO_GLOBAL_ACCT_EXISTS THEN
6462 		g_error_api_path := SUBSTR('GMS_ENC_TIE_BACK:'||g_error_api_path,1,230);
6463 		fnd_message.set_name('PSP','PSP_NO_GLOBAL_ACCT_EXISTS');
6464 		fnd_message.set_token('ORG_NAME',l_orig_org_name);
6465 		fnd_message.set_token('PAYROLL_DATE',l_encumbrance_date);
6466 		fnd_msg_pub.add;
6467 		p_return_status := fnd_api.g_ret_sts_success;
6468 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6469 		g_error_api_path := 'GMS_ENC_TIE_BACK:'||g_error_api_path;
6470 		p_return_status := fnd_api.g_ret_sts_unexp_error;
6471 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GMS_ENC_TIE_BACK');
6472 	WHEN OTHERS THEN
6473 		g_error_api_path := 'GMS_ENC_TIE_BACK:'||g_error_api_path;
6474 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN','GMS_ENC_TIE_BACK');
6475 		p_return_status := fnd_api.g_ret_sts_unexp_error;
6476 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving GMS_ENC_TIE_BACK');
6477 END	gms_enc_tie_back;
6478 --	End of changes for Create and Update multi thread enh.
6479 
6480 PROCEDURE create_sum_lines	(p_payroll_action_id	IN		NUMBER,
6481 				p_return_status		OUT NOCOPY	VARCHAR2) IS
6482 l_last_updated_by	NUMBER(15);
6483 l_last_update_login	NUMBER(15);
6484 
6485 CURSOR	sum_lines_cur IS
6486 SELECT	pel.enc_control_id,
6487 	pel.time_period_id,
6488 	pel.person_id,
6489 	pel.assignment_id,
6490 	pel.payroll_id,
6491 	pel.encumbrance_date,
6492 	pel.gl_code_combination_id,
6493 	pel.project_id,
6494 	pel.task_id,
6495 	pel.award_id,
6496 	pel.expenditure_type,
6497 	pel.expenditure_organization_id,
6498 	SUM(pel.encumbrance_amount),
6499 	pel.dr_cr_flag,
6500 	pel.gl_project_flag,
6501 	DECODE(g_dff_grouping_option, 'Y', pel.attribute_category, NULL) attribute_category,
6502 	DECODE(g_dff_grouping_option, 'Y', pel.attribute1, NULL) attribute1,
6503 	DECODE(g_dff_grouping_option, 'Y', pel.attribute2, NULL) attribute2,
6504 	DECODE(g_dff_grouping_option, 'Y', pel.attribute3, NULL) attribute3,
6505 	DECODE(g_dff_grouping_option, 'Y', pel.attribute4, NULL) attribute4,
6506 	DECODE(g_dff_grouping_option, 'Y', pel.attribute5, NULL) attribute5,
6507 	DECODE(g_dff_grouping_option, 'Y', pel.attribute6, NULL) attribute6,
6508 	DECODE(g_dff_grouping_option, 'Y', pel.attribute7, NULL) attribute7,
6509 	DECODE(g_dff_grouping_option, 'Y', pel.attribute8, NULL) attribute8,
6510 	DECODE(g_dff_grouping_option, 'Y', pel.attribute9, NULL) attribute9,
6511 	DECODE(g_dff_grouping_option, 'Y', pel.attribute10, NULL) attribute10,
6512 	pa.org_id
6513 FROM	PSP_ENC_LINES pel,
6514 	pa_projects_all pa
6515 WHERE 	pel.ENCUMBRANCE_AMOUNT <> 0
6516 AND	pel.payroll_action_id = p_payroll_action_id
6517 AND	(g_suspense_failed = 'TRUE' OR pel.suspense_reason_code LIKE 'ES:%')
6518 AND	(g_suspense_failed = 'TRUE' OR enc_start_date <= g_def_end_date)
6519 AND	pa.project_id (+) = pel.project_id
6520 GROUP BY	pel.enc_control_id,
6521 	pel.time_period_id,
6522 	pel.person_id,
6523 	pel.assignment_id,
6524 	pel.payroll_id,
6525 	pel.encumbrance_date,
6526 	pel.gl_code_combination_id,
6527 	pel.project_id,
6528 	pel.task_id,
6529 	pel.award_id,
6530 	pel.expenditure_type,
6531 	pel.expenditure_organization_id,
6532 	pel.dr_cr_flag,
6533 	pel.gl_project_flag,
6534 	DECODE(g_dff_grouping_option, 'Y', pel.attribute_category, NULL),
6535 	DECODE(g_dff_grouping_option, 'Y', pel.attribute1, NULL),
6536 	DECODE(g_dff_grouping_option, 'Y', pel.attribute2, NULL),
6537 	DECODE(g_dff_grouping_option, 'Y', pel.attribute3, NULL),
6538 	DECODE(g_dff_grouping_option, 'Y', pel.attribute4, NULL),
6539 	DECODE(g_dff_grouping_option, 'Y', pel.attribute5, NULL),
6540 	DECODE(g_dff_grouping_option, 'Y', pel.attribute6, NULL),
6541 	DECODE(g_dff_grouping_option, 'Y', pel.attribute7, NULL),
6542 	DECODE(g_dff_grouping_option, 'Y', pel.attribute8, NULL),
6543 	DECODE(g_dff_grouping_option, 'Y', pel.attribute9, NULL),
6544 	DECODE(g_dff_grouping_option, 'Y', pel.attribute10, NULL),
6545 	pa.org_id;
6546 
6547 TYPE sum_lines_rec is RECORD
6548 	(enc_summary_line_id		t_num_15_type,
6549 	enc_control_id			t_num_15_type,
6550 	time_period_id			t_num_15_type,
6551 	person_id			t_num_15_type,
6552 	assignment_id			t_num_15_type,
6553 	payroll_id			t_num_15_type,
6554 	effective_date			t_date_type,
6555 	gl_code_combination_id		t_num_15_type,
6556 	project_id			t_num_15_type,
6557 	task_id				t_num_15_type,
6558 	award_id			t_num_15_type,
6559 	expenditure_organization_id	t_num_15_type,
6560 	expenditure_type		t_varchar_50_type,
6561 	summary_amount			t_num_10d2_type,
6562 	dr_cr_flag			t_varchar_50_type,
6563 	gl_project_flag			t_varchar_50_type,
6564 	attribute_category		t_varchar_50_type,
6565 	attribute1			t_varchar_150_type,
6566 	attribute2			t_varchar_150_type,
6567 	attribute3			t_varchar_150_type,
6568 	attribute4			t_varchar_150_type,
6569 	attribute5			t_varchar_150_type,
6570 	attribute6			t_varchar_150_type,
6571 	attribute7			t_varchar_150_type,
6572 	attribute8			t_varchar_150_type,
6573 	attribute9			t_varchar_150_type,
6574 	attribute10			t_varchar_150_type,
6575 	org_id				t_num_15_type);
6576 t_sum_lines		sum_lines_rec;
6577 BEGIN
6578 	l_last_updated_by := fnd_global.user_id;
6579 	l_last_update_login := fnd_global.login_id;
6580 
6581 	OPEN sum_lines_cur;
6582 	FETCH sum_lines_cur BULK COLLECT INTO t_sum_lines.enc_control_id,
6583 		t_sum_lines.time_period_id,			t_sum_lines.person_id,
6584 		t_sum_lines.assignment_id,			t_sum_lines.payroll_id,
6585 		t_sum_lines.effective_date,			t_sum_lines.gl_code_combination_id,
6586 		t_sum_lines.project_id,				t_sum_lines.task_id,
6587 		t_sum_lines.award_id,				t_sum_lines.expenditure_type,
6588 		t_sum_lines.expenditure_organization_id,	t_sum_lines.summary_amount,
6589 		t_sum_lines.dr_cr_flag,				t_sum_lines.gl_project_flag,
6590 		t_sum_lines.attribute_category,			t_sum_lines.attribute1,
6591 		t_sum_lines.attribute2,				t_sum_lines.attribute3,
6592 		t_sum_lines.attribute4,				t_sum_lines.attribute5,
6593 		t_sum_lines.attribute6,				t_sum_lines.attribute7,
6594 		t_sum_lines.attribute8,				t_sum_lines.attribute9,
6595 		t_sum_lines.attribute10,			t_sum_lines.org_id;
6596 	CLOSE sum_lines_cur;
6597 
6598 	FOR recno IN 1..t_sum_lines.enc_control_id.COUNT
6599 	LOOP
6600 		SELECT psp_enc_summary_lines_s.NEXTVAL INTO t_sum_lines.enc_summary_line_id(recno) FROM DUAL;
6601 	END LOOP;
6602 
6603 	FORALL recno IN 1..t_sum_lines.enc_control_id.COUNT
6604 	INSERT INTO psp_enc_summary_lines
6605 		(enc_summary_line_id,		business_group_id,	enc_control_id,
6606 		time_period_id,			person_id,		assignment_id,
6607 		effective_date,			set_of_books_id,	gl_code_combination_id,
6608 		project_id,			task_id,		award_id,
6609 		expenditure_organization_id,	expenditure_type,	summary_amount,
6610 		dr_cr_flag,			status_code,		payroll_id,
6611 		gl_project_flag,
6612 		attribute_category,		attribute1,		attribute2,
6613 		attribute3,			attribute4,		attribute5,
6614 		attribute6,			attribute7,		attribute8,
6615 		attribute9,			attribute10,		org_id,
6616 		payroll_action_id,		last_update_date,	last_updated_by,
6617 		last_update_login,		created_by,		creation_date)
6618 	VALUES	(t_sum_lines.enc_summary_line_id(recno),	g_business_group_id,
6619 		t_sum_lines.enc_control_id(recno),		t_sum_lines.time_period_id(recno),
6620 		t_sum_lines.person_id(recno),			t_sum_lines.assignment_id(recno),
6621 		t_sum_lines.effective_date(recno),		g_set_of_books_id,
6622 		t_sum_lines.gl_code_combination_id(recno),	t_sum_lines.project_id(recno),
6623 		t_sum_lines.task_id(recno),			t_sum_lines.award_id(recno),
6624 		t_sum_lines.expenditure_organization_id(recno),	t_sum_lines.expenditure_type(recno),
6625 		t_sum_lines.summary_amount(recno),		t_sum_lines.dr_cr_flag(recno),
6626 		'N',		t_sum_lines.payroll_id(recno),	t_sum_lines.gl_project_flag(recno),
6627 		t_sum_lines.attribute_category(recno),		t_sum_lines.attribute1(recno),
6628 		t_sum_lines.attribute2(recno),			t_sum_lines.attribute3(recno),
6629 		t_sum_lines.attribute4(recno),			t_sum_lines.attribute5(recno),
6630 		t_sum_lines.attribute6(recno),			t_sum_lines.attribute7(recno),
6631 		t_sum_lines.attribute8(recno),			t_sum_lines.attribute9(recno),
6632 		t_sum_lines.attribute10(recno),			t_sum_lines.org_id(recno),
6633 		p_payroll_action_id,				SYSDATE,
6634 		l_last_updated_by,				l_last_update_login,
6635 		l_last_updated_by,				SYSDATE);
6636 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	No of Summary lines created (t_sum_lines.enc_control_id.COUNT): ' || t_sum_lines.enc_control_id.COUNT);
6637 
6638 	IF (g_dff_grouping_option = 'Y') THEN
6639 		FORALL recno IN 1..t_sum_lines.enc_summary_line_id.COUNT
6640 		UPDATE	psp_enc_lines pel
6641 		SET	enc_summary_line_id =	t_sum_lines.enc_summary_line_id(recno)
6642 		WHERE	payroll_action_id = p_payroll_action_id
6643 		AND	pel.enc_control_id = t_sum_lines.enc_control_id(recno)
6644 		AND	pel.time_period_id = t_sum_lines.time_period_id(recno)
6645 		AND	pel.person_id = t_sum_lines.person_id(recno)
6646 		AND	pel.encumbrance_date = t_sum_lines.effective_date(recno)
6647 		AND	NVL(pel.gl_code_combination_id, -99) = NVL(t_sum_lines.gl_code_combination_id(recno), -99)
6648 		AND	NVL(pel.project_id, -99) = NVL(t_sum_lines.project_id(recno), -99)
6649 		AND	NVL(pel.task_id, -99) = NVL(t_sum_lines.task_id(recno), -99)
6650 		AND	NVL(pel.award_id, -99) = NVL(t_sum_lines.award_id(recno), -99)
6651 		AND	NVL(pel.expenditure_type, 'NULL') = NVL(t_sum_lines.expenditure_type(recno), 'NULL')
6652 		AND	NVL(pel.expenditure_organization_id, -99) = NVL(t_sum_lines.expenditure_organization_id(recno), -99)
6653 		AND	pel.dr_cr_flag = t_sum_lines.dr_cr_flag(recno)
6654 		AND	pel.gl_project_flag = t_sum_lines.gl_project_flag(recno)
6655 		AND	NVL(pel.attribute_category, 'NULL') = NVL(t_sum_lines.attribute_category(recno), 'NULL')
6656 		AND	NVL(pel.attribute1, 'NULL') = NVL(t_sum_lines.attribute1(recno), 'NULL')
6657 		AND	NVL(pel.attribute2, 'NULL') = NVL(t_sum_lines.attribute2(recno), 'NULL')
6658 		AND	NVL(pel.attribute3, 'NULL') = NVL(t_sum_lines.attribute3(recno), 'NULL')
6659 		AND	NVL(pel.attribute4, 'NULL') = NVL(t_sum_lines.attribute4(recno), 'NULL')
6660 		AND	NVL(pel.attribute5, 'NULL') = NVL(t_sum_lines.attribute5(recno), 'NULL')
6661 		AND	NVL(pel.attribute6, 'NULL') = NVL(t_sum_lines.attribute6(recno), 'NULL')
6662 		AND	NVL(pel.attribute7, 'NULL') = NVL(t_sum_lines.attribute7(recno), 'NULL')
6663 		AND	NVL(pel.attribute8, 'NULL') = NVL(t_sum_lines.attribute8(recno), 'NULL')
6664 		AND	NVL(pel.attribute9, 'NULL') = NVL(t_sum_lines.attribute9(recno), 'NULL')
6665 		AND	NVL(pel.attribute10, 'NULL') = NVL(t_sum_lines.attribute10(recno), 'NULL');
6666 	ELSE
6667 		FORALL recno IN 1..t_sum_lines.enc_summary_line_id.COUNT
6668 		UPDATE	psp_enc_lines pel
6669 		SET	enc_summary_line_id =	t_sum_lines.enc_summary_line_id(recno)
6670 		WHERE	payroll_action_id = p_payroll_action_id
6671 		AND	pel.enc_control_id = t_sum_lines.enc_control_id(recno)
6672 		AND	pel.time_period_id = t_sum_lines.time_period_id(recno)
6673 		AND	pel.person_id = t_sum_lines.person_id(recno)
6674 		AND	pel.encumbrance_date = t_sum_lines.effective_date(recno)
6675 		AND	NVL(pel.gl_code_combination_id, -99) = NVL(t_sum_lines.gl_code_combination_id(recno), -99)
6676 		AND	NVL(pel.project_id, -99) = NVL(t_sum_lines.project_id(recno), -99)
6677 		AND	NVL(pel.task_id, -99) = NVL(t_sum_lines.task_id(recno), -99)
6678 		AND	NVL(pel.award_id, -99) = NVL(t_sum_lines.award_id(recno), -99)
6679 		AND	NVL(pel.expenditure_type, 'NULL') = NVL(t_sum_lines.expenditure_type(recno), 'NULL')
6680 		AND	NVL(pel.expenditure_organization_id, -99) = NVL(t_sum_lines.expenditure_organization_id(recno), -99)
6681 		AND	pel.dr_cr_flag = t_sum_lines.dr_cr_flag(recno)
6682 		AND	pel.gl_project_flag = t_sum_lines.gl_project_flag(recno);
6683 	END IF;
6684 	p_return_status := fnd_api.g_ret_sts_success;
6685 EXCEPTION
6686 	WHEN OTHERS THEN
6687 		g_error_api_path := SUBSTR('CREATE_SUM_LINES:' || g_error_api_path,1,230);
6688 		fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN', 'CREATE_SUM_LINES');
6689 		p_return_status := fnd_api.g_ret_sts_unexp_error;
6690 END create_sum_lines;
6691 
6692 PROCEDURE update_hierarchy_dates (p_payroll_action_id	IN	NUMBER,
6693 					p_return_status		OUT NOCOPY	VARCHAR2) IS
6694 CURSOR	hierarchy_dates_cur (p_assignment_id	IN	NUMBER,
6695 							p_payroll_id		IN	NUMBER) IS
6696 SELECT	DISTINCT enc_element_type_id,
6697 	hierarchy_code,
6698 	NVL(gl_code_combination_id, -99),
6699 	NVL(project_id, -99),
6700 	NVL(task_id, -99),
6701 	NVL(award_id, -99),
6702 	NVL(expenditure_organization_id, -99),
6703 	NVL(expenditure_type, '-99'),
6704 	enc_start_date,
6705 	enc_end_date
6706 FROM	psp_enc_lines_history pelh
6707 WHERE	change_flag = 'N'
6708 AND	assignment_id = p_assignment_id
6709 AND	payroll_id = p_payroll_id
6710 ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
6711 
6712 l_nlines_counter	NUMBER(15);
6713 BEGIN
6714 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Entering UPDATE_HIERARCHY_DATES');
6715 	l_nlines_counter := 0;
6716 
6717 	FOR asg_no IN 1..l_asgs.payroll_id.COUNT
6718 	LOOP
6719 		UPDATE	psp_enc_lines_history pelh
6720 		SET	change_flag = 'N'
6721 		WHERE	EXISTS	(SELECT	1
6722 				FROM	psp_enc_summary_lines pesl
6723 				WHERE	pesl.enc_summary_line_id = pelh.enc_summary_line_id
6724 				AND	status_code = 'A')
6725 		AND	assignment_id = l_asgs.assignment_id(asg_no)
6726 		AND	payroll_id = l_asgs.payroll_id(asg_no);
6727 
6728 		UPDATE	psp_enc_lines_history pelh
6729 		SET	hierarchy_code = 'SA'
6730 		WHERE	change_flag = 'N'
6731 		AND	hierarchy_code <> 'SA'
6732 		AND	suspense_org_account_id IS NOT NULL
6733 		AND	assignment_id = l_asgs.assignment_id(asg_no)
6734 		AND	payroll_id = l_asgs.payroll_id(asg_no);
6735 
6736 		OPEN hierarchy_dates_cur(l_asgs.assignment_id(asg_no),
6737 					l_asgs.payroll_id(asg_no));
6738 		FETCH hierarchy_dates_cur BULK COLLECT INTO t_enc_lines.element_type_id,
6739 			t_enc_lines.hierarchy_code,	t_enc_lines.gl_ccid,	t_enc_lines.project_id,
6740 			t_enc_lines.task_id,		t_enc_lines.award_id,	t_enc_lines.exp_org_id,
6741 			t_enc_lines.exp_type,		t_enc_lines.enc_start_date, t_enc_lines.enc_end_date;
6742 		CLOSE hierarchy_dates_cur;
6743 
6744 		IF (t_enc_lines.element_type_id.COUNT > 0) THEN
6745 			l_nlines_counter := l_nlines_counter + 1;
6746 			t_enc_nlines.assignment_id(l_nlines_counter) := l_asgs.assignment_id(asg_no);
6747 			t_enc_nlines.payroll_id(l_nlines_counter) := l_asgs.payroll_id(asg_no);
6748 			t_enc_nlines.element_type_id(l_nlines_counter) := t_enc_lines.element_type_id(1);
6749 			t_enc_nlines.hierarchy_code(l_nlines_counter) := t_enc_lines.hierarchy_code(1);
6750 			t_enc_nlines.gl_ccid(l_nlines_counter) := t_enc_lines.gl_ccid(1);
6751 			t_enc_nlines.project_id(l_nlines_counter) := t_enc_lines.project_id(1);
6752 			t_enc_nlines.task_id(l_nlines_counter) := t_enc_lines.task_id(1);
6753 			t_enc_nlines.award_id(l_nlines_counter) := t_enc_lines.award_id(1);
6754 			t_enc_nlines.exp_org_id(l_nlines_counter) := t_enc_lines.exp_org_id(1);
6755 			t_enc_nlines.exp_type(l_nlines_counter) := t_enc_lines.exp_type(1);
6756 			t_enc_nlines.enc_start_date(l_nlines_counter) := t_enc_lines.enc_start_date(1);
6757 			t_enc_nlines.enc_end_date(l_nlines_counter) := t_enc_lines.enc_end_date(1);
6758 			FOR recno IN 2..t_enc_lines.element_type_id.COUNT
6759 			LOOP
6760 				IF (t_enc_lines.element_type_id(recno) = t_enc_lines.element_type_id(recno-1) AND
6761 					t_enc_lines.hierarchy_code(recno) = t_enc_lines.hierarchy_code(recno-1) AND
6762 					t_enc_lines.gl_ccid(recno) = t_enc_lines.gl_ccid(recno-1) AND
6763 					t_enc_lines.project_id(recno) = t_enc_lines.project_id(recno-1) AND
6764 					t_enc_lines.task_id(recno) = t_enc_lines.task_id(recno-1) AND
6765 					t_enc_lines.award_id(recno) = t_enc_lines.award_id(recno-1) AND
6766 					t_enc_lines.exp_org_id(recno) = t_enc_lines.exp_org_id(recno-1) AND
6767 					t_enc_lines.exp_type(recno) = t_enc_lines.exp_type(recno-1) AND
6768 					t_enc_lines.enc_start_date(recno) -1 <= t_enc_lines.enc_end_date(recno-1)) THEN
6769 					t_enc_nlines.enc_end_date(l_nlines_counter) := GREATEST(t_enc_lines.enc_end_date(recno), t_enc_lines.enc_end_date(recno-1));
6770 				ELSE
6771 					l_nlines_counter := l_nlines_counter + 1;
6772 					t_enc_nlines.assignment_id(l_nlines_counter) := l_asgs.assignment_id(asg_no);
6773 					t_enc_nlines.payroll_id(l_nlines_counter) := l_asgs.payroll_id(asg_no);
6774 					t_enc_nlines.element_type_id(l_nlines_counter) := t_enc_lines.element_type_id(recno);
6775 					t_enc_nlines.hierarchy_code(l_nlines_counter) := t_enc_lines.hierarchy_code(recno);
6776 					t_enc_nlines.gl_ccid(l_nlines_counter) := t_enc_lines.gl_ccid(recno);
6777 					t_enc_nlines.project_id(l_nlines_counter) := t_enc_lines.project_id(recno);
6778 					t_enc_nlines.task_id(l_nlines_counter) := t_enc_lines.task_id(recno);
6779 					t_enc_nlines.award_id(l_nlines_counter) := t_enc_lines.award_id(recno);
6780 					t_enc_nlines.exp_org_id(l_nlines_counter) := t_enc_lines.exp_org_id(recno);
6781 					t_enc_nlines.exp_type(l_nlines_counter) := t_enc_lines.exp_type(recno);
6782 					t_enc_nlines.enc_start_date(l_nlines_counter) := t_enc_lines.enc_start_date(recno);
6783 					t_enc_nlines.enc_end_date(l_nlines_counter) := t_enc_lines.enc_end_date(recno);
6784 				END IF;
6785 			END LOOP;
6786 		END IF;
6787 
6788 		t_enc_lines.assignment_id.DELETE;
6789 		t_enc_lines.payroll_id.DELETE;
6790 		t_enc_lines.element_type_id.DELETE;
6791 		t_enc_lines.hierarchy_code.DELETE;
6792 		t_enc_lines.gl_ccid.DELETE;
6793 		t_enc_lines.project_id.DELETE;
6794 		t_enc_lines.task_id.DELETE;
6795 		t_enc_lines.award_id.DELETE;
6796 		t_enc_lines.exp_org_id.DELETE;
6797 		t_enc_lines.exp_type.DELETE;
6798 		t_enc_lines.enc_start_date.DELETE;
6799 		t_enc_lines.enc_end_date.DELETE;
6800 	END LOOP;
6801 
6802 	FOR recno IN 1..t_enc_nlines.element_type_id.COUNT
6803 	LOOP
6804 		IF (t_enc_nlines.gl_ccid(recno) = -99) THEN
6805 			t_enc_nlines.gl_ccid(recno) := NULL;
6806 		ELSE
6807 			t_enc_nlines.project_id(recno) := NULL;
6808 			t_enc_nlines.task_id(recno) := NULL;
6809 			t_enc_nlines.award_id(recno) := NULL;
6810 			t_enc_nlines.exp_org_id(recno) := NULL;
6811 			t_enc_nlines.exp_type(recno) := NULL;
6812 		END IF;
6813 	END LOOP;
6814 
6815 	FORALL recno IN 1..t_enc_nlines.element_type_id.COUNT
6816 	UPDATE	psp_enc_lines_history
6817 	SET	hierarchy_start_date = t_enc_nlines.enc_start_date(recno),
6818 		hierarchy_end_date = t_enc_nlines.enc_end_date(recno)
6819 	WHERE	assignment_id = t_enc_nlines.assignment_id(recno)
6820 	AND	payroll_id = t_enc_nlines.payroll_id(recno)
6821 	AND	change_flag = 'N'
6822 	AND	enc_element_type_id = t_enc_nlines.element_type_id(recno)
6823 	AND	hierarchy_code = t_enc_nlines.hierarchy_code(recno)
6824 	AND	(	(	gl_code_combination_id IS NOT NULL
6825 			AND	gl_code_combination_id = t_enc_nlines.gl_ccid(recno))
6826 		OR	(	project_id = t_enc_nlines.project_id(recno)
6827 			AND	task_id = t_enc_nlines.task_id(recno)
6828 			AND	award_id = t_enc_nlines.award_id(recno)
6829 			AND	expenditure_organization_id = t_enc_nlines.exp_org_id(recno)
6830 			AND	expenditure_type = t_enc_nlines.exp_type(recno)))
6831 	AND	enc_start_date <= t_enc_nlines.enc_end_date(recno)
6832 	AND	enc_end_date >= t_enc_nlines.enc_start_date(recno);
6833 
6834 	p_return_status := fnd_api.g_ret_sts_success;
6835 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving UPDATE_HIERARCHY_DATES');
6836 EXCEPTION
6837 	WHEN OTHERS THEN
6838         g_error_api_path := SUBSTR(' UPDATE_HIERARCHY_DATES:'||g_error_api_path,1,230);
6839         fnd_msg_pub.add_exc_msg('PSP_ENC_SUM_TRAN', ' UPDATE_HIERARCHY_DATES');
6840         p_return_status := fnd_api.g_ret_sts_unexp_error;
6841 		fnd_file.put_line(fnd_file.log, 'SQLCODE: ' || SQLCODE || ' SQLERRM: ' || SQLERRM);
6842 		fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE) || '	Leaving UPDATE_HIERARCHY_DATES');
6843 END update_hierarchy_dates;
6844 
6845 PROCEDURE log_st_warnings IS
6846 l_request_id			NUMBER(15);
6847 l_person_id				NUMBER(15);
6848 l_organization_id		NUMBER(15);
6849 l_assignment_number		per_all_assignments_f.assignment_number%TYPE;
6850 l_payroll_name			pay_all_payrolls_f.payroll_name%TYPE;
6851 l_full_name				per_all_people_f.full_name%TYPE;
6852 l_organization_name		hr_organization_units.name%TYPE;
6853 l_element_name			pay_element_types_f.element_name%TYPE;
6854 l_project_number		pa_projects_all.segment1%TYPE;
6855 l_task_number			pa_tasks.task_number%TYPE;
6856 l_award_number			gms_awards_all.award_number%TYPE;
6857 l_exp_org_name			hr_organization_units.name%TYPE;
6858 l_gl_description		VARCHAR2(4000);
6859 l_return_status			VARCHAR2(1);
6860 
6861 CURSOR	asg_number_cur (p_assignment_id		IN	NUMBER,
6862 						p_payroll_id		IN	NUMBER,
6863 						p_effective_date	IN	DATE) IS
6864 SELECT	assignment_number,
6865 	person_id,
6866 	organization_id
6867 FROM	per_all_assignments_f
6868 WHERE	assignment_id = p_assignment_id
6869 AND	payroll_id = p_payroll_id
6870 AND	effective_end_date >= p_effective_date
6871 AND	ROWNUM = 1;
6872 
6873 CURSOR	payroll_name_cur (p_payroll_id IN NUMBER) IS
6874 SELECT	payroll_name
6875 FROM	pay_all_payrolls_f
6876 WHERE	payroll_id = p_payroll_id
6877 AND	business_group_id = g_business_group_id
6878 AND	gl_set_of_books_id = g_set_of_books_id;
6879 
6880 CURSOR	person_name_cur (p_effective_date IN DATE) IS
6881 SELECT	full_name
6882 FROM	per_all_people_f
6883 WHERE	person_id = l_person_id
6884 AND	effective_end_date >= p_effective_date
6885 AND	ROWNUM = 1;
6886 
6887 CURSOR	org_name_cur IS
6888 SELECT	name
6889 FROM	hr_organization_units
6890 WHERE	organization_id = l_organization_id;
6891 
6892 CURSOR	project_number_cur (p_project_id IN NUMBER) IS
6893 SELECT	SEGMENT1
6894 FROM	pa_projects_all
6895 WHERE	project_id = p_project_id;
6896 
6897 CURSOR	award_number_cur (p_award_id IN NUMBER) IS
6898 SELECT	award_number
6899 FROM	gms_awards_all
6900 WHERE	award_id = p_award_id;
6901 
6902 CURSOR	task_number_cur (p_task_id IN NUMBER) IS
6903 SELECT	task_number
6904 FROM	pa_tasks
6905 WHERE	task_id = p_task_id;
6906 
6907 CURSOR	exp_org_name_cur (p_expenditure_org_id IN NUMBER) IS
6908 SELECT	name
6909 FROM	hr_organization_units
6910 WHERE	organization_id = p_expenditure_org_id;
6911 
6912 CURSOR	element_name_cur (p_element_type_id IN NUMBER) IS
6913 SELECT	element_name
6914 FROM	pay_element_types_f
6915 WHERE	element_type_id = p_element_type_id
6916 AND		ROWNUM = 1;
6917 BEGIN
6918 	l_request_id := fnd_global.conc_request_id;
6919 
6920 	FOR recno IN 1..st_warnings.assignment_id.COUNT
6921 	LOOP
6922 		OPEN asg_number_cur(st_warnings.assignment_id(recno), st_warnings.payroll_id(recno), st_warnings.start_date(recno));
6923 		FETCH asg_number_cur INTO l_assignment_number, l_person_id, l_organization_id;
6924 		CLOSE asg_number_cur;
6925 
6926 		OPEN payroll_name_cur(st_warnings.payroll_id(recno));
6927 		FETCH payroll_name_cur INTO l_payroll_name;
6928 		CLOSE payroll_name_cur;
6929 
6930 		OPEN person_name_cur(st_warnings.start_date(recno));
6931 		FETCH person_name_cur INTO l_full_name;
6932 		CLOSE person_name_cur;
6933 
6934 		OPEN org_name_cur;
6935 		FETCH org_name_cur INTO l_organization_name;
6936 		CLOSE org_name_cur;
6937 
6938 		OPEN element_name_cur(st_warnings.element_type_id(recno));
6939 		FETCH element_name_cur INTO l_element_name;
6940 		CLOSE element_name_cur;
6941 
6942 		IF (st_warnings.project_id(recno) IS NOT NULL) THEN
6943 			OPEN project_number_cur(st_warnings.project_id(recno));
6944 			FETCH project_number_cur INTO l_project_number;
6945 			CLOSE project_number_cur;
6946 
6947 			OPEN award_number_cur(st_warnings.award_id(recno));
6948 			FETCH award_number_cur INTO l_award_number;
6949 			CLOSE award_number_cur;
6950 
6951 			OPEN task_number_cur(st_warnings.task_id(recno));
6952 			FETCH task_number_cur INTO l_task_number;
6953 			CLOSE task_number_cur;
6954 
6955 			OPEN exp_org_name_cur(st_warnings.exp_org_id(recno));
6956 			FETCH exp_org_name_cur INTO l_exp_org_name;
6957 			CLOSE exp_org_name_cur;
6958 
6959 			fnd_message.set_name('PSP', 'PSP_SUSPENSE_REASON_INV_PATEO');
6960 			fnd_message.set_token('PJ', l_project_number);
6961 			fnd_message.set_token('TK', l_task_number);
6962 			fnd_message.set_token('AW', l_award_number);
6963 			fnd_message.set_token('EO', l_exp_org_name);
6964 			fnd_message.set_token('ET', st_warnings.exp_type(recno));
6965 			fnd_message.set_token('START_DATE', st_warnings.start_date(recno));
6966 			fnd_message.set_token('END_DATE', st_warnings.end_date(recno));
6967 			fnd_message.set_token('EFFECTIVE_DATE', st_warnings.effective_date(recno));
6968 			fnd_message.set_token('ERROR_STATUS', st_warnings.error_status(recno));
6969 			g_warning_message := fnd_message.get;
6970 		ELSE
6971 			l_gl_description := psp_general.get_gl_description(g_set_of_books_id, st_warnings.gl_ccid(recno));
6972 
6973 			fnd_message.set_name('PSP', 'PSP_SUSPENSE_REASON_INV_GL');
6974 			fnd_message.set_token('GL', l_gl_description);
6975 			fnd_message.set_token('START_DATE', st_warnings.start_date(recno));
6976 			fnd_message.set_token('END_DATE', st_warnings.end_date(recno));
6977 			fnd_message.set_token('EFFECTIVE_DATE', st_warnings.effective_date(recno));
6978 			fnd_message.set_token('ERROR_STATUS', st_warnings.error_status(recno));
6979 			g_warning_message := fnd_message.get;
6980 		END IF;
6981 
6982 		psp_general.add_report_error
6983 				(p_request_id		=>	l_request_id,
6984 				p_message_level		=>	'W',
6985 				p_source_id			=>	st_warnings.assignment_id(recno),
6986 				p_source_name		=>	l_assignment_number,
6987 				p_parent_source_id	=>	l_person_id,
6988 				p_parent_source_name	=>	l_full_name,
6989 				p_error_message		=>	g_warning_message,
6990 				p_payroll_action_id	=>	g_payroll_action_id,
6991 				p_value1			=>	st_warnings.payroll_id(recno),
6992 				p_information1		=>	l_payroll_name,
6993 				p_value2			=>	l_organization_id,
6994 				p_value3			=>	st_warnings.element_type_id(recno),
6995 				p_information2		=>	l_organization_name,
6996 				p_information3		=>	l_element_name,
6997 				p_information4		=>	fnd_date.date_to_canonical(st_warnings.start_date(recno)),
6998 				p_information5		=>	fnd_date.date_to_canonical(st_warnings.end_date(recno)),
6999 				p_information6		=>	'SA',
7000 				p_return_status		=>	l_return_status);
7001 	END LOOP;
7002 END log_st_warnings;
7003 
7004 PROCEDURE	add_st_warnings(p_start_date	IN	DATE	DEFAULT NULL,
7005 						p_end_date			IN	DATE	DEFAULT NULL,
7006 						p_assignment_id		IN	NUMBER	DEFAULT NULL,
7007 						p_payroll_id		IN	NUMBER	DEFAULT NULL,
7008 						p_element_type_id	IN	NUMBER	DEFAULT NULL,
7009 						p_gl_ccid			IN	NUMBER	DEFAULT NULL,
7010 						p_project_id		IN	NUMBER	DEFAULT NULL,
7011 						p_task_id			IN	NUMBER	DEFAULT NULL,
7012 						p_award_id			IN	NUMBER	DEFAULT NULL,
7013 						p_exp_org_id		IN	NUMBER	DEFAULT NULL,
7014 						p_exp_type			IN	VARCHAR2	DEFAULT NULL,
7015 						p_effective_date	IN	DATE	DEFAULT NULL,
7016 						p_error_status		IN	VARCHAR2	DEFAULT NULL) IS
7017 l_warning_ind		NUMBER(15);
7018 BEGIN
7019 	l_warning_ind := st_warnings.start_date.COUNT;
7020 	fnd_file.put_line(fnd_file.log, 'Entering add_st_warnings');
7021 	hr_utility.trace('p_start_date: ' || p_start_date || ' p_end_date: ' || p_end_date ||
7022 		' p_assignment_id: ' || p_assignment_id || ' p_payroll_id: ' || p_payroll_id ||
7023 		' p_element_type_id: ' || p_element_type_id || ' p_gl_ccid: ' || p_gl_ccid ||
7024 		' p_project_id: ' || p_project_id || ' p_task_id: ' || p_task_id ||
7025 		' p_award_id:' || p_award_id || ' p_exp_org_id: ' || p_exp_org_id ||
7026 		' p_exp_type: ' || p_exp_type || ' p_effective_date: ' || p_effective_date ||
7027 		' p_error_status: ' || p_error_status);
7028 
7029 	IF (p_project_id IS NOT NULL) THEN
7030 		LOOP
7031 			EXIT WHEN l_warning_ind = 0;
7032 			EXIT WHEN ((	(st_warnings.end_date(l_warning_ind) = (p_start_date -1) OR
7033 							(	(st_warnings.end_date(l_warning_ind) >= p_start_date) AND
7034 								(st_warnings.start_date(l_warning_ind) <= p_end_date)))) AND
7035 				(st_warnings.assignment_id(l_warning_ind) = p_assignment_id) AND
7036 				(st_warnings.payroll_id(l_warning_ind) = p_payroll_id) AND
7037 				(st_warnings.element_type_id(l_warning_ind) = p_element_type_id) AND
7038 				(st_warnings.project_id(l_warning_ind) = p_project_id) AND
7039 				(st_warnings.task_id(l_warning_ind) = p_task_id) AND
7040 				(st_warnings.award_id(l_warning_ind) = p_award_id) AND
7041 				(st_warnings.exp_org_id(l_warning_ind) = p_exp_org_id) AND
7042 				(st_warnings.exp_type(l_warning_ind) = p_exp_type) AND
7043 				(st_warnings.error_status(l_warning_ind) = p_error_status));
7044 			l_warning_ind := l_warning_ind - 1;
7045 		END LOOP;
7046 	ELSE
7047 		LOOP
7048 			EXIT WHEN l_warning_ind = 0;
7049 			EXIT WHEN ((	(st_warnings.end_date(l_warning_ind) = (p_start_date -1) OR
7050 							(	(st_warnings.end_date(l_warning_ind) >= p_start_date) AND
7051 								(st_warnings.start_date(l_warning_ind) <= p_end_date)))) AND
7052 				(st_warnings.gl_ccid(l_warning_ind) = p_gl_ccid) AND
7053 				(st_warnings.error_status(l_warning_ind) = p_error_status));
7054 			l_warning_ind := l_warning_ind - 1;
7055 		END LOOP;
7056 	END IF;
7057 
7058 	IF (l_warning_ind = 0) THEN
7059 		l_warning_ind := st_warnings.start_date.COUNT + 1;
7060 		st_warnings.start_date(l_warning_ind) := p_start_date;
7061 		st_warnings.end_date(l_warning_ind) := p_end_date;
7062 		st_warnings.assignment_id(l_warning_ind) := p_assignment_id;
7063 		st_warnings.payroll_id(l_warning_ind) := p_payroll_id;
7064 		st_warnings.element_type_id(l_warning_ind) := p_element_type_id;
7065 		st_warnings.gl_ccid(l_warning_ind) := p_gl_ccid;
7066 		st_warnings.project_id(l_warning_ind) := p_project_id;
7067 		st_warnings.task_id(l_warning_ind) := p_task_id;
7068 		st_warnings.award_id(l_warning_ind) := p_award_id;
7069 		st_warnings.exp_org_id(l_warning_ind) := p_exp_org_id;
7070 		st_warnings.exp_type(l_warning_ind) := p_exp_type;
7071 		st_warnings.effective_date(l_warning_ind) := p_effective_date;
7072 		st_warnings.error_status(l_warning_ind) := p_error_status;
7073 	ELSE
7074 		st_warnings.end_date(l_warning_ind) := p_end_date;
7075 		st_warnings.effective_date(l_warning_ind) := p_effective_date;
7076 	END IF;
7077 
7078 	hr_utility.trace('st_warnings.start_date.COUNT: ' || st_warnings.start_date.COUNT);
7079 	fnd_file.put_line(fnd_file.log, 'Leaving add_st_warnings');
7080 END	add_st_warnings;
7081 
7082 PROCEDURE	move_rej_lines_to_arch (p_payroll_action_id	IN	NUMBER) IS
7083 BEGIN
7084 	INSERT	INTO PSP_ENC_SUMMARY_LINES_ARCH
7085 		(enc_summary_line_id,		business_group_id,		gms_batch_name,
7086 		time_period_id,			person_id,			assignment_id,
7087 		effective_date,			set_of_books_id,		gl_code_combination_id,
7088 		project_id,			expenditure_organization_id,	expenditure_type,
7089 		task_id,			award_id,			summary_amount,
7090 		dr_cr_flag,			group_id,			interface_status,
7091 		payroll_id,			gl_period_id,			gl_project_flag,
7092 		attribute_category,		attribute1,			attribute2,
7093 		attribute3,			attribute4,			attribute5,
7094 		attribute6,			attribute7,			attribute8,
7095 		attribute9,			attribute10,			attribute11,
7096 		attribute12,			attribute13,			attribute14,
7097 		attribute15,			attribute16,			attribute17,
7098 		attribute18,			attribute19,			attribute20,
7099 		attribute21,			attribute22,			attribute23,
7100 		attribute24,			attribute25,			attribute26,
7101 		attribute27,			attribute28,			attribute29,
7102 		attribute30,			reject_reason_code,		enc_control_id,
7103 		status_code,			last_update_date,		last_updated_by,
7104 		last_update_login,		created_by,			creation_date,
7105 		suspense_org_account_id,	superceded_line_id,		gms_posting_override_date,
7106 		gl_posting_override_date,	expenditure_id,			expenditure_item_id,
7107 		expenditure_ending_date,	interface_id,			txn_interface_id,
7108 		payroll_action_id,		liquidate_request_id,		proposed_termination_date,
7109 		update_flag)
7110 	SELECT	enc_summary_line_id,		business_group_id,		gms_batch_name,
7111 		time_period_id,			person_id,			assignment_id,
7112 		effective_date,			set_of_books_id,		gl_code_combination_id,
7113 		project_id,			expenditure_organization_id,	expenditure_type,
7114 		task_id,			award_id,			summary_amount,
7115 		dr_cr_flag,			group_id,			interface_status,
7116 		payroll_id,			gl_period_id,			gl_project_flag,
7117 		attribute_category,		attribute1,			attribute2,
7118 		attribute3,			attribute4,			attribute5,
7119 		attribute6,			attribute7,			attribute8,
7120 		attribute9,			attribute10,			attribute11,
7121 		attribute12,			attribute13,			attribute14,
7122 		attribute15,			attribute16,			attribute17,
7123 		attribute18,			attribute19,			attribute20,
7124 		attribute21,			attribute22,			attribute23,
7125 		attribute24,			attribute25,			attribute26,
7126 		attribute27,			attribute28,			attribute29,
7127 		attribute30,			reject_reason_code,		enc_control_id,
7128 		status_code,			last_update_date,		last_updated_by,
7129 		last_update_login,		created_by,			creation_date,
7130 		suspense_org_account_id,	superceded_line_id,		gms_posting_override_date,
7131 		gl_posting_override_date,	expenditure_id,			expenditure_item_id,
7132 		expenditure_ending_date,	interface_id,			txn_interface_id,
7133 		payroll_action_id,		liquidate_request_id,		proposed_termination_date,
7134 		update_flag
7135 	FROM	psp_enc_summary_lines
7136 	WHERE	payroll_action_id = p_payroll_action_id
7137 	AND	status_code = 'R';
7138 
7139 	IF (SQL%ROWCOUNT > 0) THEN
7140 		fnd_file.put_line(fnd_file.log, 'Moved rejected lines (if any) to archival table as they are no longer useful');
7141 	END IF;
7142 
7143 	DELETE	psp_enc_summary_lines
7144 	WHERE	payroll_action_id = p_payroll_action_id
7145 	AND	status_code = 'R';
7146 
7147 END move_rej_lines_to_arch;
7148 END psp_enc_sum_tran;