DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSP_ENC_LIQ_TRAN

Source


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