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