DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMS_BUDGET_PUB

Source


1 package body GMS_BUDGET_PUB as
2 /* $Header: gmsmbupb.pls 120.14.12020000.2 2012/07/18 09:33:11 admarath ship $ */
3 
4 /* package global to be used during updates */
5 
6 -- To check on, whether to print debug messages in log file or not
7 L_DEBUG varchar2(1) := NVL(FND_PROFILE.value('GMS_ENABLE_DEBUG_MODE'), 'N');
8 
9 G_USER_ID  		CONSTANT NUMBER := FND_GLOBAL.user_id;
10 G_LOGIN_ID		CONSTANT NUMBER := FND_GLOBAL.login_id;
11 
12 ----------------------------------------------------------------------------------------
13 
14  function G_PA_MISS_NUM return number
15  is
16  begin
17  	return GMS_BUDGET_PUB.G_MISS_NUM;
18  end;
19 
20  function G_PA_MISS_CHAR return varchar2
21  is
22  begin
23  	return GMS_BUDGET_PUB.G_MISS_CHAR;
24  end;
25 
26  function G_PA_MISS_DATE return date
27  is
28  begin
29  	return GMS_BUDGET_PUB.G_MISS_DATE;
30  end;
31 
32  function G_GMS_FALSE return varchar2
33  is
34  begin
35  	return GMS_BUDGET_PUB.G_FALSE;
36  end;
37 
38  function G_GMS_TRUE return varchar2
39  is
40  begin
41  	return GMS_BUDGET_PUB.G_TRUE;
42  end;
43 
44 -----------------------------------------------------------------------------------
45 
46 PROCEDURE convert_projnum_to_id
47 (p_project_number_in 	IN VARCHAR2  	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
48 ,p_project_id_in        	IN NUMBER    	:= GMS_BUDGET_PUB.G_PA_MISS_NUM
49 ,p_project_id_out       	OUT NOCOPY NUMBER
50 ,x_err_code 		IN OUT NOCOPY NUMBER
51 ,x_err_stage		IN OUT NOCOPY VARCHAR2
52 ,x_err_stack		IN OUT NOCOPY VARCHAR2)
53 
54 IS
55 
56 cursor 	l_project_id_csr(p_project_id_in NUMBER)
57 IS
58 select 	'X'
59 from	pa_projects
60 where   project_id = p_project_id_in;
61 
62 cursor	l_project_number_csr(p_project_number_in VARCHAR2)
63 is
64 select project_id
65 from pa_projects
66 where segment1 = p_project_number_in;
67 
68 l_dummy				VARCHAR2(1);
69 l_old_stack			VARCHAR2(630);
70 
71 BEGIN
72 
73  x_err_code := 0;
74  l_old_stack := x_err_stack;
75  x_err_stack := x_err_stack ||'-> convert_projnum_to_id';
76 
77     IF p_project_id_in  <>  GMS_BUDGET_PUB.G_PA_MISS_NUM
78     AND p_project_id_in IS NOT NULL
79     THEN
80 
81       	--check validity of this ID
82       	OPEN l_project_id_csr (p_project_id_in);
83       	FETCH l_project_id_csr INTO l_dummy;
84 
85       	IF l_project_id_csr%NOTFOUND
86       	THEN
87 		CLOSE l_project_id_csr;
88 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_PROJ_ID',
89 					x_err_code => x_err_code,
90 					x_err_buff => x_err_stage);
91 
92 		APP_EXCEPTION.RAISE_EXCEPTION;
93       	END IF;
94 
95       	CLOSE l_project_id_csr;
96       	p_project_id_out := p_project_id_in;
97 
98     ELSIF  p_project_number_in <>  GMS_BUDGET_PUB.G_PA_MISS_CHAR
99        AND p_project_number_in IS NOT NULL
100     THEN
101 	OPEN l_project_number_csr(p_project_number_in);
102 	FETCH l_project_number_csr INTO p_project_id_out;
103 
104       	IF l_project_number_csr%NOTFOUND
105       	THEN
106 		CLOSE l_project_number_csr;
107 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_PROJ_NUM',
108 					x_err_code => x_err_code,
109 					x_err_buff => x_err_stage);
110 
111 		APP_EXCEPTION.RAISE_EXCEPTION;
112       	END IF;
113 
114       	CLOSE l_project_number_csr;
115 
116      ELSE
117 	gms_error_pkg.gms_message(x_err_name => 'GMS_PROJECT_REF_AND_ID_MISSING',
118 				x_err_code => x_err_code,
119 				x_err_buff => x_err_stage);
120 
121 	APP_EXCEPTION.RAISE_EXCEPTION;
122     END IF;
123 
124     x_err_stack := l_old_stack;
125 
126 EXCEPTION
127 	WHEN OTHERS
128 	THEN
129 	gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
130 				x_token_name1 => 'SQLCODE',
131 				x_token_val1 => sqlcode,
132 				x_token_name2 => 'SQLERRM',
133 				x_token_val2 => sqlerrm,
134 				x_err_code => x_err_code,
135 				x_err_buff => x_err_stage);
136 
137 	APP_EXCEPTION.RAISE_EXCEPTION;
138 
139 END convert_projnum_to_id;
140 -------------------------------------------------------------------------
141 PROCEDURE convert_tasknum_to_id
142 (p_project_id_in 	IN NUMBER
143 ,p_task_id_in        	IN NUMBER    	:= GMS_BUDGET_PUB.G_PA_MISS_NUM
144 ,p_task_number_in      	IN VARCHAR2    	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
145 ,p_task_id_out       OUT NOCOPY NUMBER
146 ,x_err_code 		IN OUT NOCOPY NUMBER
147 ,x_err_stage		IN OUT NOCOPY VARCHAR2
148 ,x_err_stack		IN OUT NOCOPY VARCHAR2)
149 
150 IS
151 
152 cursor 	l_task_id_csr(p_project_id_in NUMBER,
153 			p_task_id_in NUMBER)
154 IS
155 select 	'X'
156 from	pa_tasks
157 where   project_id = p_project_id_in
158 and	task_id = p_task_id_in;
159 
160 cursor	l_task_number_csr(p_project_id_in NUMBER,
161 			p_task_number_in VARCHAR2)
162 is
163 select task_id
164 from pa_tasks
165 where task_number = p_task_number_in
166 and project_id = p_project_id_in;
167 
168 l_dummy				VARCHAR2(1);
169 l_old_stack			VARCHAR2(630);
170 
171 BEGIN
172 
173  x_err_code := 0;
174  l_old_stack := x_err_stack;
175  x_err_stack := x_err_stack ||'-> convert_tasknum_to_id';
176 
177     IF p_task_id_in  <>  GMS_BUDGET_PUB.G_PA_MISS_NUM
178     AND p_task_id_in IS NOT NULL
179     THEN
180 
181       	--check validity of this ID
182       	OPEN l_task_id_csr (p_project_id_in, p_task_id_in);
183       	FETCH l_task_id_csr INTO l_dummy;
184 
185       	IF l_task_id_csr%NOTFOUND
186       	THEN
187 		CLOSE l_task_id_csr;
188 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_PROJ_TASK_ID',
189 					x_err_code => x_err_code,
190 					x_err_buff => x_err_stage);
191 
192 		APP_EXCEPTION.RAISE_EXCEPTION;
193       	END IF;
194 
195       	CLOSE l_task_id_csr;
196       	p_task_id_out := p_task_id_in;
197 
198     ELSIF  p_task_number_in <>  GMS_BUDGET_PUB.G_PA_MISS_CHAR
199        AND p_task_number_in IS NOT NULL
200     THEN
201 	OPEN l_task_number_csr(p_project_id_in, p_task_number_in);
202 	FETCH l_task_number_csr INTO p_task_id_out;
203 
204       	IF l_task_number_csr%NOTFOUND
205       	THEN
206 		CLOSE l_task_number_csr;
207 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_PROJ_TASK_NUM',
208 					x_err_code => x_err_code,
209 					x_err_buff => x_err_stage);
210 
211 		APP_EXCEPTION.RAISE_EXCEPTION;
212       	END IF;
213 
214       	CLOSE l_task_number_csr;
215 
216      ELSE
217 	gms_error_pkg.gms_message(x_err_name => 'GMS_TASK_NUM_AND_ID_MISSING',
218 				x_err_code => x_err_code,
219 				x_err_buff => x_err_stage);
220 
221 	APP_EXCEPTION.RAISE_EXCEPTION;
222     END IF;
223 
224     x_err_stack := l_old_stack;
225 
226 EXCEPTION
227 	WHEN OTHERS
228 	THEN
229 	gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
230 				x_token_name1 => 'SQLCODE',
231 				x_token_val1 => sqlcode,
232 				x_token_name2 => 'SQLERRM',
233 				x_token_val2 => sqlerrm,
234 				x_err_code => x_err_code,
235 				x_err_buff => x_err_stage);
236 
237 	APP_EXCEPTION.RAISE_EXCEPTION;
238 
239 
240 END convert_tasknum_to_id;
241 
242 -------------------------------------------------------------------------
243 
244 PROCEDURE convert_awardnum_to_id
245 (p_award_number_in 	IN VARCHAR2  	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
246 ,p_award_id_in        	IN NUMBER    	:= GMS_BUDGET_PUB.G_PA_MISS_NUM
247 ,p_award_id_out       	OUT NOCOPY NUMBER
248 ,x_err_code 		IN OUT NOCOPY NUMBER
249 ,x_err_stage		IN OUT NOCOPY VARCHAR2
250 ,x_err_stack		IN OUT NOCOPY VARCHAR2)
251 
252 IS
253 
254 cursor 	l_award_id_csr(p_award_id_in NUMBER)
255 IS
256 select 	'X'
257 from	gms_awards
258 where   award_id = p_award_id_in;
259 
260 cursor	l_award_number_csr(p_award_number_in VARCHAR2)
261 is
262 select award_id
263 from gms_awards
264 where award_number = p_award_number_in;
265 
266 l_dummy				VARCHAR2(1);
267 l_old_stack			VARCHAR2(630);
268 
269 BEGIN
270 
271  x_err_code := 0;
272  l_old_stack := x_err_stack;
273  x_err_stack := x_err_stack ||'-> convert_awardnum_to_id';
274 
275     IF p_award_id_in  <>  GMS_BUDGET_PUB.G_PA_MISS_NUM
276     AND p_award_id_in IS NOT NULL
277     THEN
278 
279       	--check validity of this ID
280       	OPEN l_award_id_csr (p_award_id_in);
281       	FETCH l_award_id_csr INTO l_dummy;
282 
283       	IF l_award_id_csr%NOTFOUND
284       	THEN
285 		CLOSE l_award_id_csr;
286 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_AWARD_ID',
287 					x_err_code => x_err_code,
288 					x_err_buff => x_err_stage);
289 
290 		APP_EXCEPTION.RAISE_EXCEPTION;
291       	END IF;
292 
293       	CLOSE l_award_id_csr;
294       	p_award_id_out := p_award_id_in;
295 
296     ELSIF  p_award_number_in <>  GMS_BUDGET_PUB.G_PA_MISS_CHAR
297        AND p_award_number_in IS NOT NULL
298     THEN
299 	OPEN l_award_number_csr(p_award_number_in);
300 	FETCH l_award_number_csr INTO p_award_id_out;
301 
302       	IF l_award_number_csr%NOTFOUND
303       	THEN
304 		CLOSE l_award_number_csr;
305 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_AWARD_NUM',
306 					x_err_code => x_err_code,
307 					x_err_buff => x_err_stage);
308 
309 		APP_EXCEPTION.RAISE_EXCEPTION;
310       	END IF;
311 
312       	CLOSE l_award_number_csr;
313 
314      ELSE
315 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_AND_ID_MISSING',
316 				x_err_code => x_err_code,
317 				x_err_buff => x_err_stage);
318 
319 	APP_EXCEPTION.RAISE_EXCEPTION;
320     END IF;
321 
322     x_err_stack := l_old_stack;
323 
324 EXCEPTION
325 	WHEN OTHERS
326 	THEN
327 	gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
328 				x_token_name1 => 'SQLCODE',
329 				x_token_val1 => sqlcode,
330 				x_token_name2 => 'SQLERRM',
331 				x_token_val2 => sqlerrm,
332 				x_err_code => x_err_code,
333 				x_err_buff => x_err_stage);
334 
335 	APP_EXCEPTION.RAISE_EXCEPTION;
336 
337 END convert_awardnum_to_id;
338 ----------------------------------------------------------------------
339 PROCEDURE convert_reslistname_to_id
340 (p_resource_list_name_in 	IN VARCHAR2  	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
341 ,p_resource_list_id_in        	IN NUMBER    	:= GMS_BUDGET_PUB.G_PA_MISS_NUM
342 ,p_resource_list_id_out       	OUT NOCOPY NUMBER
343 ,x_err_code 		IN OUT NOCOPY NUMBER
344 ,x_err_stage		IN OUT NOCOPY VARCHAR2
345 ,x_err_stack		IN OUT NOCOPY VARCHAR2)
346 
347 IS
348 
349 cursor 	l_resource_list_id_csr(p_resource_list_id_in NUMBER)
350 IS
351 select 	'X'
352 from	pa_resource_lists
353 where   resource_list_id = p_resource_list_id_in;
354 
355 cursor	l_resource_list_name_csr(p_resource_list_name_in VARCHAR2)
356 is
357 select resource_list_id
358 from pa_resource_lists
359 where name = p_resource_list_name_in
360 and  NVL(migration_code,'M') ='M'; -- Bug 3626671
361 
362 l_dummy				VARCHAR2(1);
363 l_old_stack			VARCHAR2(630);
364 
365 BEGIN
366 
367  x_err_code := 0;
368  l_old_stack := x_err_stack;
369  x_err_stack := x_err_stack ||'-> convert_reslistname_to_id';
370 
371     IF p_resource_list_id_in  <>  GMS_BUDGET_PUB.G_PA_MISS_NUM
372     AND p_resource_list_id_in IS NOT NULL
373     THEN
374 
375       	--check validity of this ID
376       	OPEN l_resource_list_id_csr (p_resource_list_id_in);
377       	FETCH l_resource_list_id_csr INTO l_dummy;
378 
379       	IF l_resource_list_id_csr%NOTFOUND
380       	THEN
381 		CLOSE l_resource_list_id_csr;
382 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_RESLIST_ID',
383 					x_err_code => x_err_code,
384 					x_err_buff => x_err_stage);
385 
386 		APP_EXCEPTION.RAISE_EXCEPTION;
387       	END IF;
388 
389       	CLOSE l_resource_list_id_csr;
390       	p_resource_list_id_out := p_resource_list_id_in;
391 
392     ELSIF  p_resource_list_name_in <>  GMS_BUDGET_PUB.G_PA_MISS_CHAR
393        AND p_resource_list_name_in IS NOT NULL
394     THEN
395 	OPEN l_resource_list_name_csr(p_resource_list_name_in);
396 	FETCH l_resource_list_name_csr INTO p_resource_list_id_out;
397 
398       	IF l_resource_list_name_csr%NOTFOUND
399       	THEN
400 		CLOSE l_resource_list_name_csr;
401 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_RESLIST_NAME',
402 					x_err_code => x_err_code,
403 					x_err_buff => x_err_stage);
404 
405 		APP_EXCEPTION.RAISE_EXCEPTION;
406       	END IF;
407 
408       	CLOSE l_resource_list_name_csr;
409 
410      ELSE
411 	gms_error_pkg.gms_message(x_err_name => 'GMS_RESNAME_AND_ID_MISSING',
412 				x_err_code => x_err_code,
413 				x_err_buff => x_err_stage);
414 
415 	APP_EXCEPTION.RAISE_EXCEPTION;
416     END IF;
417 
418     x_err_stack := l_old_stack;
419 
420 EXCEPTION
421 	WHEN OTHERS
422 	THEN
423 	gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
424 				x_token_name1 => 'SQLCODE',
425 				x_token_val1 => sqlcode,
426 				x_token_name2 => 'SQLERRM',
427 				x_token_val2 => sqlerrm,
428 				x_err_code => x_err_code,
429 				x_err_buff => x_err_stage);
430 
431 	APP_EXCEPTION.RAISE_EXCEPTION;
432 
433 END convert_reslistname_to_id;
434 -------------------------------------------------------------------------------
435 
436 PROCEDURE convert_listmem_alias_to_id
437 (p_resource_list_id_in			IN NUMBER
438 ,p_reslist_member_alias_in 	IN VARCHAR2  	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
439 ,p_resource_list_member_id_in        	IN NUMBER    	:= GMS_BUDGET_PUB.G_PA_MISS_NUM
440 ,p_resource_list_member_id_out       	OUT NOCOPY NUMBER
441 ,x_err_code 		IN OUT NOCOPY NUMBER
442 ,x_err_stage		IN OUT NOCOPY VARCHAR2
443 ,x_err_stack		IN OUT NOCOPY VARCHAR2)
444 
445 IS
446 
447 cursor 	l_resource_list_member_id_csr(p_resource_list_member_id_in NUMBER)
448 IS
449 select 	'X'
450 from	pa_resource_list_members
451 where   resource_list_member_id = p_resource_list_member_id_in;
452 
453 cursor	l_reslist_member_alias_csr(p_resource_list_id_in NUMBER
454                                 , p_reslist_member_alias_in VARCHAR2)
455 is
456 select resource_list_member_id
457 from pa_resource_list_members
458 where alias = p_reslist_member_alias_in
459 and resource_list_id = p_resource_list_id_in
460 and NVL(migration_code,'M') ='M'; -- Bug 3626671
461 
462 l_dummy				VARCHAR2(1);
463 l_old_stack			VARCHAR2(630);
464 
465 BEGIN
466 
467  x_err_code := 0;
468  l_old_stack := x_err_stack;
469  x_err_stack := x_err_stack ||'-> convert_listmem_alias_to_id';
470 
471     IF p_resource_list_member_id_in  <>  GMS_BUDGET_PUB.G_PA_MISS_NUM
472     AND p_resource_list_member_id_in IS NOT NULL
473     THEN
474 
475       	--check validity of this ID
476       	OPEN l_resource_list_member_id_csr (p_resource_list_member_id_in);
477       	FETCH l_resource_list_member_id_csr INTO l_dummy;
478 
479       	IF l_resource_list_member_id_csr%NOTFOUND
480       	THEN
481 		CLOSE l_resource_list_member_id_csr;
482 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_RESLIST_MEM_ID',
483 					x_err_code => x_err_code,
484 					x_err_buff => x_err_stage);
485 
486 		APP_EXCEPTION.RAISE_EXCEPTION;
487       	END IF;
488 
489       	CLOSE l_resource_list_member_id_csr;
490       	p_resource_list_member_id_out := p_resource_list_member_id_in;
491 
492     ELSIF  p_reslist_member_alias_in <>  GMS_BUDGET_PUB.G_PA_MISS_CHAR
493        AND p_reslist_member_alias_in IS NOT NULL
494     THEN
495 	OPEN l_reslist_member_alias_csr(p_resource_list_id_in, p_reslist_member_alias_in);
496 	FETCH l_reslist_member_alias_csr INTO p_resource_list_member_id_out;
497 
498       	IF l_reslist_member_alias_csr%NOTFOUND
499       	THEN
500 		CLOSE l_reslist_member_alias_csr;
501 		gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_RESLIST_ALIAS',
502 					x_err_code => x_err_code,
503 					x_err_buff => x_err_stage);
504 
505 		APP_EXCEPTION.RAISE_EXCEPTION;
506       	END IF;
507 
508       	CLOSE l_reslist_member_alias_csr;
509 
510      ELSE
511 		gms_error_pkg.gms_message(x_err_name => 'GMS_RES_ALIAS_AND_ID_MISSING',
512 					x_err_code => x_err_code,
513 					x_err_buff => x_err_stage);
514 
515 		APP_EXCEPTION.RAISE_EXCEPTION;
516     END IF;
517 
518     x_err_stack := l_old_stack;
519 
520 EXCEPTION
521 	WHEN OTHERS
522 	THEN
523 	gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
524 				x_token_name1 => 'SQLCODE',
525 				x_token_val1 => sqlcode,
526 				x_token_name2 => 'SQLERRM',
527 				x_token_val2 => sqlerrm,
528 				x_err_code => x_err_code,
529 				x_err_buff => x_err_stage);
530 
531 	APP_EXCEPTION.RAISE_EXCEPTION;
532 
533 END convert_listmem_alias_to_id;
534 ------------------------------------------------------------------------------------------
535 
536 procedure compare_amount_with_txns( p_award_id 			in 	NUMBER,
537 				p_project_id 			in	NUMBER,
538 				p_task_id 			in 	NUMBER,
539 				p_resource_list_member_id 	in	NUMBER,
540 				p_start_date			in	DATE,
541 				p_draft_burdened_cost 		in	NUMBER,
542 				p_fc_required 			out NOCOPY 	BOOLEAN) is
543 
544 CURSOR l_txns_csr (	p_award_id 	in 	NUMBER,
545 			p_project_id 	in 	NUMBER,
546 			p_task_id	in	NUMBER,
547 			p_resource_list_member_id in	NUMBER,
548 			p_start_date	in	DATE) is
549 
550 select  (nvl(gbal.actual_period_to_date,0) + nvl(gbal.encumb_period_to_date,0))
551 from    gms_budget_versions gbv,
552         gms_budget_lines gbl,
553         gms_resource_assignments gra,
554         gms_balances gbal
555 where   gbv.budget_version_id = gra.budget_version_id
556 and     gra.resource_assignment_id = gbl.resource_assignment_id
557 and     gbal.award_id = gbv.award_id
558 and     gbal.project_id = gbv.project_id
559 and     gbal.budget_version_id = gbv.budget_version_id
560 and     gbal.task_id = gra.task_id
561 --and     gbal.resource_list_member_id = gra.resource_list_member_id
562 --and     gbal.start_date = gbl.start_date
563 and     gbv.award_id = p_award_id
564 and     gbv.project_id = p_project_id
565 and	gbl.start_date = p_start_date
566 and	gra.resource_list_member_id = p_resource_list_member_id
567 and	gra.task_id = p_task_id
568 and     gbv.budget_status_code = 'B'
569 and     gbv.current_flag ='Y'
570 and     gbal.balance_type in ('REQ', 'PO', 'AP', 'ENC', 'EXP');
571 
572 l_txn_amount 	NUMBER;
573 
574 begin
575 	open l_txns_csr (p_award_id => p_award_id,
576 			p_project_id => p_project_id,
577 			p_task_id => p_task_id,
578 			p_resource_list_member_id => p_resource_list_member_id,
579 			p_start_date => p_start_date);
580 	loop
581 		fetch l_txns_csr
582 		into l_txn_amount;
583 		exit when l_txns_csr%NOTFOUND;
584 
585 		if p_draft_burdened_cost < l_txn_amount
586 		then
587 			p_fc_required := TRUE;
588 			return;
589 		else
590 			p_fc_required := FALSE;
591 		end if;
592 
593 	end loop;
594 
595 	close l_txns_csr;
596 
597 end compare_amount_with_txns;
598 
599 -------------------------------------------------------------------------------
600 -- This Function is used while Submitting and Baselining a Budget to see if
601 -- Funds checking (FC) is required for this Budget.
602 
603 -- Conditions for FC requirement is:
604 -- 1. If Budget Entry Method has been changed in the new draft budget.
605 -- 2. If Resource List has been changed in the new draft budget.
606 -- 3. If Budgetted amount is decreased for a particular Resource
607 -- 4. If a new resource is added to the budget.
608 
609 FUNCTION is_fc_required (p_project_id IN NUMBER,
610                                            p_award_id IN NUMBER)
611 RETURN boolean IS
612 
613 l_draft_entry_method varchar2(30);
614 l_draft_res_list_id number;
615 l_draft_res_assignment number;
616 l_draft_burdened_cost number;
617 
618 l_baselined_entry_method varchar2(30);
619 l_baselined_res_list_id number;
620 l_baselined_res_assignment number;
621 l_project_id number;
622 l_task_id number;
623 l_res_list_member number;
624 l_baselined_burdened_cost number;
625 
626 l_amount_diff number;
627 l_start_date date;
628 l_period_name varchar2(15);
629 
630 l_fc_required boolean;
631 l_dummy number;
632 
633 CURSOR l_budgetary_controls_csr(p_project_id IN NUMBER,
634                               p_award_id IN NUMBER)
635 IS
636 select 	1
637 from 	dual
638 where exists(
639 	select 	'x'
640 	from 	gms_budgetary_controls
641 	where	project_id = p_project_id
642 	and	award_id = p_award_id
643 	and 	funds_control_level_code = 'B');
644 
645 
646 CURSOR l_budget_csr(p_project_id IN NUMBER,
647                               p_award_id IN NUMBER)
648 IS
649 select
650         draft_array.budget_entry_method_code,
651         baselined_array.budget_entry_method_code,
652         draft_array.resource_list_id,
653         baselined_array.resource_list_id,
654         draft_array.resource_list_member_id,
655         draft_array.project_id,
656         draft_array.task_id,
657         draft_array.start_date,
658         draft_array.period_name,
659         baselined_array.burdened_cost,
660         draft_array.burdened_cost,
661         nvl(draft_array.burdened_cost,0) - nvl(baselined_array.burdened_cost,0) amt_diff
662 from
663         (select gra_b.resource_list_member_id resource_list_member_id,
664                 gra_b.project_id project_id,
665                 gra_b.task_id task_id,
666                 gbl_b.burdened_cost burdened_cost,
667                 gbl_b.start_date start_date,
668                 gbl_b.period_name period_name,
669                 gbv_b.budget_entry_method_code budget_entry_method_code,
670                 gbv_b.resource_list_id resource_list_id
671         from    gms_budget_versions gbv_b,
672                 gms_budget_lines gbl_b,
673                 gms_resource_assignments gra_b
674         where   gbv_b.budget_version_id = gra_b.budget_version_id
675         and     gra_b.resource_assignment_id = gbl_b.resource_assignment_id
676         and     gbv_b.award_id = p_award_id
677         and     gbv_b.project_id = p_project_id
678         and     gbv_b.budget_status_code = 'B'
679         and     gbv_b.current_flag ='Y'
680 ) baselined_array,
681         (select gra_d.resource_list_member_id resource_list_member_id,
682                 gra_d.project_id project_id,
683                 gra_d.task_id task_id,
684                 gbl_d.burdened_cost burdened_cost,
685                 gbl_d.start_date start_date,
686                 gbl_d.period_name period_name,
687                 gbv_d.budget_entry_method_code budget_entry_method_code,
688                 gbv_d.resource_list_id resource_list_id
689         from    gms_budget_versions gbv_d,
690                 gms_budget_lines gbl_d,
691                 gms_resource_assignments gra_d
692         where   gbv_d.budget_version_id = gra_d.budget_version_id
693         and     gra_d.resource_assignment_id = gbl_d.resource_assignment_id
694         and     gbv_d.award_id = p_award_id
695         and     gbv_d.project_id = p_project_id
696         and     gbv_d.budget_status_code in ('W','S')
697 ) draft_array
698 where   baselined_array.project_id = draft_array.project_id(+)
699 and     baselined_array.resource_list_member_id = draft_array.resource_list_member_id (+)
700 and     baselined_array.task_id = draft_array.task_id(+)
701 and     baselined_array.start_date = draft_array.start_date(+);
702 
703 
704 BEGIN
705 
706 	IF L_DEBUG = 'Y' THEN
707 	   gms_error_pkg.gms_debug('*** Start of IS_FC_REQUIRED ***','C');
708 	END IF;
709 
710 	open 	l_budgetary_controls_csr(p_project_id, p_award_id);
711 	fetch 	l_budgetary_controls_csr
712 	into	l_dummy;
713 
714 	if l_budgetary_controls_csr%NOTFOUND
715 	then
716 		return FALSE;
717 	end if;
718 
719 	close 	l_budgetary_controls_csr;
720 
721 open l_budget_csr (p_project_id, p_award_id);
722 loop
723         fetch   l_budget_csr
724         into    l_draft_entry_method,
725                 l_baselined_entry_method,
726                 l_draft_res_list_id,
727                 l_baselined_res_list_id,
728                 l_res_list_member,
729                 l_project_id,
730                 l_task_id,
731                 l_start_date,
732                 l_period_name,
733                 l_baselined_burdened_cost,
734                 l_draft_burdened_cost,
735                 l_amount_diff;
736                 exit when l_budget_csr%NOTFOUND;
737 
738 -- Check to see if Budget Entry Method has been changed in Draft Budget
739 
740                 if nvl(l_draft_entry_method,'x') <> nvl(l_baselined_entry_method,'x')
741                 then
742                         return TRUE; -- FC reqd.
743                 end if;
744 -- Check to see if Resource List has been changed in Draft Budget
745 
746                 if nvl(l_draft_res_list_id,0) <> nvl(l_baselined_res_list_id,0)
747                 then
748                         return TRUE; -- FC reqd.
749                 end if;
750 
751 -- Check to see if Budget Amount has been changed in Draft Budget
752 
753 		if nvl(l_draft_burdened_cost,0) <
754 		   nvl(l_baselined_burdened_cost,0) then
755 		   	return TRUE; -- FC reqd.
756 		end if;
757 
758 -- Check to see if Budget line has been changed in Draft Budget
759 /** -- To be enabled later ....
760                 if ((l_amount_diff < 0) and (l_res_list_member is null)) then
761                         return FALSE; -- FC not reqd.
762 		        close l_budget_csr;
763                 elsif (l_amount_diff < 0) and (l_res_list_member is not null) then
764 			compare_amount_with_txns( p_award_id => p_award_id,
765 						p_project_id => l_project_id,
766 						p_task_id => l_task_id,
767 						p_resource_list_member_id => l_res_list_member,
768 						p_start_date => l_start_date,
769 						p_draft_burdened_cost => l_draft_burdened_cost,
770 						p_fc_required => l_fc_required);
771 
772 			if l_fc_required then
773                         	return TRUE; -- FC reqd.
774                         else
775                         	return FALSE; -- FC not reqd.
776                         end if;
777 		        close l_budget_csr;
778                 end if;
779 
780 .......**/
781 
782 end loop;
783 
784 close l_budget_csr;
785 return FALSE;
786 
787 END is_fc_required;
788 -------------------------------------------------------------------------------
789  procedure summerize_project_totals (x_budget_version_id   in     number,
790 		    		      x_err_code            in out NOCOPY number,
791 		    		      x_err_stage	    in out NOCOPY varchar2,
792 		    		      x_err_stack           in out NOCOPY varchar2)
793   is
794      x_created_by number;
795      x_last_update_login number;
796      l_old_stack  varchar2(630);
797   begin
798 
799      IF L_DEBUG = 'Y' THEN
800 	gms_error_pkg.gms_debug('*** Start of GMS_BUDGET_PUB.SUMMERIZE_PROJECT_TOTALS ***','C');
801      END IF;
802 
803      x_err_code := 0;
804      l_old_stack := x_err_stack;
805      x_err_stack := x_err_stack || '->summerize_project_totals';
806 
807      x_created_by := FND_GLOBAL.USER_ID;
808      x_last_update_login := FND_GLOBAL.LOGIN_ID;
809 
810      -- Get the project_totals
811      x_err_stage := 'get project totals <' || to_char(x_budget_version_id)
812 		    || '>';
813 
814      update gms_budget_versions v
815      set    (labor_quantity,
816 	     labor_unit_of_measure,
817 	     raw_cost,
818 	     burdened_cost,
819 	     last_update_date,
820 	     last_updated_by,
821 	     last_update_login
822             )
823      =
824        (select sum(nvl(to_number(decode(a.track_as_labor_flag,
825 					'Y', l.quantity, NULL)),0)),
826 --             decode(a.track_as_labor_flag, 'Y', a.unit_of_measure, NULL),
827 	       'HOURS',       -- V4 uses HOURS as the only labor unit
828 	       pa_currency.round_currency_amt(sum(nvl(l.raw_cost, 0))),
829 	       pa_currency.round_currency_amt(sum(nvl(l.burdened_cost, 0))),
830 	       SYSDATE,
831 	       x_created_by,
832 	       x_last_update_login
833 	from   gms_resource_assignments a,
834 	       gms_budget_lines l
835 	where  a.budget_version_id = v.budget_version_id
836 	and    a.resource_assignment_id = l.resource_assignment_id
837        )
838      where  budget_version_id = x_budget_version_id;
839 
840      x_err_stack := l_old_stack;
841 
842      IF L_DEBUG = 'Y' THEN
843 	gms_error_pkg.gms_debug('*** End of GMS_BUDGET_PUB.SUMMERIZE_PROJECT_TOTALS ***','C');
844      END IF;
845 
846   exception
847       when others then
848         -- Modified for bug 2587078
849 	--x_err_code := SQLCODE;
850         x_err_stage := 'GMS_BUDGET_PUB.SUMMERIZE_PROJECT_TOTALS - In when others exception';
851         gms_error_pkg.gms_message( x_err_name => 'GMS_BU_SUMM_BUDG_LINES_FAIL',
852  	 		          x_err_code => x_err_code,
853 			          x_err_buff => x_err_stage);
854        fnd_msg_pub.add;
855        return;
856 
857   end summerize_project_totals;
858 ----------------------------------------------------------------------------------------
859 procedure validate_budget(  x_budget_version_id in NUMBER,
860 			    x_award_id in NUMBER,
861                             x_project_id in NUMBER,
862                             x_task_id in NUMBER default NULL,
863                             x_resource_list_member_id in NUMBER default NULL,
864                             x_start_date in DATE,
865                             x_end_date in DATE,
866                             x_return_status in out NOCOPY NUMBER,
867 			    x_calling_form in VARCHAR2 default NULL)
868 
869 is
870 TYPE Install_Rec is RECORD( INSTALLMENT_ID NUMBER,
871                             TOTAL_FUNDING_AMOUNT NUMBER,
872                             INSTALL_BALANCE NUMBER,
873                             INSTALL_START_DATE DATE,
874                             INSTALL_END_DATE DATE);
875 
876 TYPE Install_tab is TABLE OF Install_Rec
877                  INDEX BY BINARY_INTEGER;
878 
879 X_Install_Total     Install_tab;
880 
881 TYPE Budget_Rec is RECORD(  BUDG_PERIOD_START_DATE DATE,
882                             BUDG_PERIOD_END_DATE DATE,
883                             BUDGET_AMOUNT NUMBER);
884 
885 TYPE Budget_tab is TABLE OF Budget_Rec
886                  INDEX BY BINARY_INTEGER;
887 
888 X_Budget_Total     Budget_tab;
889 
890 x_funding_level  varchar2(1);
891 x_top_task_id    number;
892 x_budget_funding_level varchar2(1);
893 x_entry_level_code varchar2(1);
894 x_period_name varchar2(20);
895 x_resource_name pa_resource_list_members.alias%type;   /*Modified for bug 4614242*/
896 x_project_number varchar2(25); -- Added for Bug:2269791
897 x_period_type	varchar2(1);
898 x_categorization_code varchar2(30);
899 
900 CURSOR  x_install_cursor (x_award_id in NUMBER,
901                         x_project_id in NUMBER,
902                         x_task_id in NUMBER default NULL,
903                         x_start_date in DATE,
904                         x_end_date in DATE)
905 IS
906 select  gi.installment_id,
907         gspf.total_funding_amount total_funding_amount,
908         trunc(gi.start_date_active) start_date_active,
909         nvl(trunc(ga.preaward_date),trunc(gi.start_date_active)) start_date_active_preawd, -- for Bug: 1906414
910         trunc(gi.end_date_active) end_date_active
911 from    gms_installments gi,
912 	gms_awards ga,
913         gms_summary_project_fundings gspf
914 where   gi.installment_id = gspf.installment_id
915 and	ga.award_id = gi.award_id
916 and     gi.award_id = x_award_id
917 and     gspf.project_id = x_project_id
918 and     ( (x_budget_funding_level = 'T' and gspf.task_id = x_top_task_id)
919          or x_budget_funding_level = 'P')
920 order by trunc(gi.end_date_active) , trunc(gi.start_date_active),sign(total_funding_amount) desc; ---Modified for bug#12398545
921 
922 -- For Bug:2395386 - created 2 Budget cursors - one ordered by Amount and the other by Installment Dates
923 -- Bug Fix 2912108 Added NVL clause for the burdened_cost column in the following cursors, as it is
924 --                 resulting into an error, when amounts are saved in the budget form.
925 
926 CURSOR  x_budget_cursor_by_date (  x_award_id in NUMBER,
927                         x_project_id in NUMBER,
928                         x_task_id in NUMBER default NULL,
929                         x_start_date in DATE,
930                         x_end_date in DATE)
931 IS
932 select  trunc(gbl.start_date) start_date,
933         trunc(gbl.end_date) end_date,
934         sum(NVL(gbl.burdened_cost,0)) burdened_cost,
935         decode(sum(NVL(gbl.burdened_cost,0)), abs(sum(NVL(gbl.burdened_cost,0))), 1, 0) N
936 from    gms_budget_versions gbv,
937         gms_resource_assignments gra,
938         gms_budget_lines gbl
939 where   gbv.budget_version_id = gra.budget_version_id
940 and     gra.resource_assignment_id = gbl.resource_assignment_id
941 and     gbv.project_id = x_project_id
942 and     gbv.award_id = x_award_id
943 and     budget_status_code = 'W' -- since we are dealing with a draft budget ONLY
944 and     ( x_budget_funding_level = 'T'  and exists (select 1 from pa_tasks pat
945                                             where  pat.top_task_id = x_top_task_id
946                                             and    pat.task_id = gra.task_id)
947          or x_budget_funding_level = 'P')
948 group by trunc(start_date), trunc(end_date)
949 order by 4,1,2 asc;   /* 6846582, also added decode(Column 'N') in select clause */
950 
951 
952 
953 CURSOR  x_budget_cursor_by_amount (  x_award_id in NUMBER,
954                         x_project_id in NUMBER,
955                         x_task_id in NUMBER default NULL,
956                         x_start_date in DATE,
957                         x_end_date in DATE)
958 IS
959 select  trunc(gbl.start_date) start_date,
960         trunc(gbl.end_date) end_date,
961         sum(NVL(gbl.burdened_cost,0)) burdened_cost
962 from    gms_budget_versions gbv,
963         gms_resource_assignments gra,
964         gms_budget_lines gbl
965 where   gbv.budget_version_id = gra.budget_version_id
966 and     gra.resource_assignment_id = gbl.resource_assignment_id
967 and     gbv.project_id = x_project_id
968 and     gbv.award_id = x_award_id
969 and     budget_status_code = 'W' -- since we are dealing with a draft budget ONLY
970 and     ( x_budget_funding_level = 'T'  and exists (select 1 from pa_tasks pat
971                                             where  pat.top_task_id = x_top_task_id
972                                             and    pat.task_id = gra.task_id)
973          or x_budget_funding_level = 'P')
974 group by trunc(start_date), trunc(end_date)
975 order by sum(gbl.burdened_cost) asc;
976 
977 i   NUMBER;
978 j   NUMBER;
979 x_budget_rowcount   NUMBER;
980 x_install_rowcount  NUMBER;
981 x_install_balance   NUMBER;
982 x_carry_over_budget NUMBER;
983 
984 x_override_validation VARCHAR2(1);
985 
986 l_total_budget_amount NUMBER;
987 l_total_funding_amount NUMBER;
988 
989 x_err_code  NUMBER;
990 x_err_stage VARCHAR2(630);
991 
992 begin
993     	x_return_status := 0;
994 
995 	-- For Bug:2395386
996 	gms_client_extn_budget.override_inst_date_validation (p_award_id => x_award_id,
997 							      p_project_id => x_project_id,
998 							      p_override_validation => x_override_validation);
999 
1000 -- Added for fixing bug:1794776 -- ABLE TO BUDGET FOR MORE THAN FUNDED IF A NEGATIVE INSTALLMENT WAS APPLIED
1001 
1002 -- Check if the total budget amount exceeds total funding amount.
1003 -- If yes, then error out NOCOPY and do not proceed further.
1004 -- Begin, exception and end blocks added for bug 3895592
1005 
1006        Begin
1007         select  nvl(burdened_cost,0)
1008         into    l_total_budget_amount
1009         from    gms_budget_versions
1010         where  -- budget_status_code in ('W','S') commented for the bug 6860267 and added below condition
1011                 budget_version_id = x_budget_version_id
1012         and	award_id = x_award_id
1013         and     project_id = x_project_id;
1014        exception
1015           when no_data_found then
1016 	    null;
1017        end;
1018 
1019         select  sum(nvl(total_funding_amount,0))
1020         into    l_total_funding_amount
1021         from    gms_summary_project_fundings gspf,
1022                 gms_installments gi
1023         where   gspf.installment_id = gi.installment_id
1024         and     gi.award_id = x_award_id
1025         and     gspf.project_id = x_project_id;
1026 
1027         if l_total_budget_amount > l_total_funding_amount then
1028 	        if (x_calling_form ='GMSAWEAW') then/*bug 4965360*/
1029                         x_return_status := 1 ;
1030                        return;
1031                  end if ;
1032 
1033 	        gms_error_pkg.gms_message(x_err_name => 'GMS_BU_BUDGAMT_FAILURE',
1034  						x_err_code => x_err_code,
1035 						x_err_buff => x_err_stage);
1036 
1037 		x_return_status := 1; -- validation FAILED
1038 		app_exception.raise_exception;
1039 
1040         end if;
1041 
1042 -- Initializing the pl/sql tables
1043 
1044     	X_Install_Total.delete;
1045     	X_Budget_Total.delete;
1046 
1047     	if nvl(x_task_id,0) = 0 then  /*bug 4965360 */
1048         	null;
1049     	else
1050         	select top_Task_id
1051         	into   x_top_task_id
1052         	from   pa_tasks
1053         	where task_id = x_task_id;
1054     	end if;
1055 
1056 	select 	decode(entry_level_code, 'P','P','T')
1057     	into   	x_entry_level_code
1058     	from 	gms_budget_versions gbv,
1059          	pa_budget_entry_methods pbem
1060     	where 	gbv.budget_Version_id = x_budget_version_id
1061     	and   	pbem.budget_entry_method_code = gbv.budget_entry_method_code;
1062 
1063 	select  decode (task_id, NULL, 'P','T')
1064     	into    x_funding_level
1065     	from    gms_installments gi,
1066 		gms_summary_project_fundings gspf
1067     	where   gi.installment_id = gspf.installment_id
1068     	and     gi.award_id     = x_award_id
1069     	and     gspf.project_id = x_project_id
1070     	and     rownum = 1;
1071 
1072     	if x_entry_level_code = 'T' and x_funding_level = 'T' then
1073 		x_budget_funding_level := 'T';
1074     	else
1075           	x_budget_funding_level := 'P';
1076     	end if;
1077 
1078 	select 	alias
1079 	into	x_resource_name
1080 	from 	pa_resource_list_members
1081 	where	resource_list_member_id = x_resource_List_Member_Id;
1082 
1083 -- Added for Bug: 2269791
1084 	select 	segment1
1085 	into	x_project_number
1086 	from 	pa_projects
1087 	where	project_id = x_project_id;
1088 
1089 	select 	time_phased_type_code, categorization_code
1090 	into	x_period_type, x_categorization_code
1091 	from 	pa_budget_entry_methods pbem,
1092 		gms_budget_versions gbv
1093 	where	gbv.budget_entry_method_code = pbem.budget_entry_method_code
1094 	and	gbv.budget_version_id = x_budget_version_id;
1095 
1096 -- Added the IF condition for Bug: 1422606
1097 -- Bug 1555396 : x_start_date and x_end_date should be not null
1098 	if x_period_type in ('G','P') AND x_start_date IS NOT NULL AND x_end_date IS NOT NULL then
1099 		select 	period_name
1100 		into 	x_period_name
1101 		from 	pa_budget_periods_v
1102 		where	period_start_date = x_start_date
1103 		and	period_end_date = x_end_date
1104 		and	period_type_code = x_period_type;
1105 	end if;
1106 
1107 ------------------------------------------------------
1108 -- Loading the Installment pl/sql table
1109     	i := 0;
1110 
1111     	for ins_rec in x_install_cursor (    x_award_id => x_award_id,
1112         	                                x_project_id => x_project_id,
1113                 	                        x_task_id => x_task_id,
1114                         	                x_start_date => x_start_date,
1115                                 	        x_end_date => x_end_date)
1116     	loop
1117         	X_Install_Total(i).INSTALLMENT_ID := ins_rec.installment_id;
1118         	X_Install_Total(i).TOTAL_FUNDING_AMOUNT := ins_rec.total_funding_amount;
1119         	X_Install_Total(i).INSTALL_BALANCE := ins_rec.total_funding_amount; -- to begin with, balance = total funding
1120 
1121 		-- The following IF statement is added for Bug: 1906414
1122 		--if i = 0 then BUG:13844807 removed the condition
1123 		if ins_rec.start_date_active_preawd <= ins_rec.start_date_active then --BUG:13844807 Added the condition
1124 			X_Install_Total(i).INSTALL_START_DATE := ins_rec.start_date_active_preawd;
1125         	else
1126 			X_Install_Total(i).INSTALL_START_DATE := ins_rec.start_date_active;
1127 		end if;
1128 
1129         	X_Install_Total(i).INSTALL_END_DATE := ins_rec.end_date_active;
1130 
1131         	i := i + 1;
1132     	end loop;
1133 ------------------------------------------------------
1134 -- Loading the Budget pl/sql table
1135 
1136 -- Bug:2395386 - the order of records in the Budget pl/sql table depends
1137 --		 on the value of x_override_validation.
1138 
1139     	j := 0;
1140 
1141 	if x_override_validation = 'Y' then
1142 
1143     		for budg_rec in x_budget_cursor_by_amount(    x_award_id => x_award_id,
1144         	                                x_project_id => x_project_id,
1145                 	                        x_task_id => x_task_id,
1146                         	                x_start_date => x_start_date,
1147                                 	        x_end_date => x_end_date)
1148     		loop
1149         		X_Budget_Total(j).BUDG_PERIOD_START_DATE := budg_rec.start_date;
1150         		X_Budget_Total(j).BUDG_PERIOD_END_DATE := budg_rec.end_date;
1151         		X_Budget_Total(j).BUDGET_AMOUNT := budg_rec.burdened_cost;
1152 
1153         		j := j + 1;
1154     		end loop;
1155 	else
1156     		for budg_rec in x_budget_cursor_by_date(    x_award_id => x_award_id,
1157         	                                x_project_id => x_project_id,
1158                 	                        x_task_id => x_task_id,
1159                         	                x_start_date => x_start_date,
1160                                 	        x_end_date => x_end_date)
1161     		loop
1162         		X_Budget_Total(j).BUDG_PERIOD_START_DATE := budg_rec.start_date;
1163         		X_Budget_Total(j).BUDG_PERIOD_END_DATE := budg_rec.end_date;
1164         		X_Budget_Total(j).BUDGET_AMOUNT := budg_rec.burdened_cost;
1165 
1166         		j := j + 1;
1167     		end loop;
1168 
1169 	end if;
1170 
1171 ----------------------------------------------------------------------------
1172 
1173 -- Getting the number of records in the Budget and Installment pl/sql tables
1174 
1175     	x_budget_rowcount := X_Budget_Total.count;
1176     	x_install_rowcount := X_Install_Total.count;
1177 ----------------------------------------------------------------------------
1178 
1179     	for Budg_Rec_Count in 0..x_budget_rowcount-1
1180     	loop
1181 		x_carry_over_budget := X_Budget_Total(Budg_Rec_Count).budget_amount;
1182 
1183         	for Inst_Rec_Count in 0..x_install_rowcount-1
1184         	loop
1185 
1186 -- Bug:2395386 -- Added check to find the value of x_override_validation.
1187 
1188             		if  (x_override_validation = 'Y') or ((trunc(X_Install_Total(Inst_Rec_Count).install_start_date) <= trunc(X_Budget_Total(Budg_Rec_Count).budg_period_end_date))
1189                 	and (trunc(X_Install_Total(Inst_Rec_Count).install_end_date) >= trunc(X_Budget_Total(Budg_Rec_Count).budg_period_start_date))) then
1190 
1191 	                	if x_carry_over_budget <= X_Install_Total(Inst_Rec_Count).install_balance then
1192         	            		X_Install_Total(Inst_Rec_Count).install_balance := X_Install_Total(Inst_Rec_Count).install_balance - x_carry_over_budget;
1193                 	    		x_carry_over_budget := 0;
1194                     			exit; -- exit installment loop
1195                 		else
1196                     			x_carry_over_budget := x_carry_over_budget - X_Install_Total(Inst_Rec_Count).install_balance;
1197                     			X_Install_Total(Inst_Rec_Count).install_balance := 0;
1198                 		end if;
1199 
1200              		end if;
1201         	end loop; -- for Installment loop
1202 
1203         -- At the end of the installment loop if the carry over is greater than 0 or if the balance in the
1204         -- installment plsql table is less than 0 then stop and error out.
1205 
1206 		if x_carry_over_budget > 0 then
1207                       if (x_calling_form ='GMSAWEAW') then  /*bug 4965360*/
1208                              x_return_status := 1 ;
1209                              return;
1210                        end if ;
1211 			if x_categorization_code = 'R' then
1212 				if x_period_type = 'R' then -- for a Date Range Budget
1213 					gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_VALIDATE_FAIL_RES_DR',
1214 							x_token_name1 => 'X_START_DATE',
1215 							x_token_val1 => x_start_date,
1216 							x_token_name2 => 'X_END_DATE',
1217 							x_token_val2 => x_end_date,
1218 							x_token_name3 => 'X_RES_NAME',
1219 							x_token_val3 => x_resource_name,
1220 							x_token_name4 => 'X_OVERFLOW_AMT',
1221 							x_token_val4 => to_char(x_carry_over_budget),
1222 							x_token_name5 => 'X_PROJECT_NUM',
1223 							x_token_val5 => x_project_number,
1224 	 						x_err_code => x_err_code,
1225 							x_err_buff => x_err_stage);
1226 				elsif x_period_type = 'N' then -- for a No Time Phased budget
1227 					gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_VALIDATE_FAIL_RES_NT',
1228 							x_token_name1 => 'X_RES_NAME',
1229 							x_token_val1 => x_resource_name,
1230 							x_token_name2 => 'X_OVERFLOW_AMT',
1231 							x_token_val2 => to_char(x_carry_over_budget),
1232                                                         x_token_name3 => 'X_PROJECT_NUM',
1233                                                         x_token_val3 => x_project_number,
1234 	 						x_err_code => x_err_code,
1235 							x_err_buff => x_err_stage);
1236 				else -- for either GL or PA period
1237 					gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_VALIDATE_FAIL_RES',
1238 							x_token_name1 => 'X_PERIOD_NAME',
1239 							x_token_val1 => x_period_name,
1240 							x_token_name2 => 'X_RES_NAME',
1241 							x_token_val2 => x_resource_name,
1242 							x_token_name3 => 'X_OVERFLOW_AMT',
1243 							x_token_val3 => to_char(x_carry_over_budget),
1244                                                         x_token_name4 => 'X_PROJECT_NUM',
1245                                                         x_token_val4 => x_project_number,
1246 	 						x_err_code => x_err_code,
1247 							x_err_buff => x_err_stage);
1248 
1249 				end if;
1250 			else
1251 				if x_period_type = 'R' then -- for a Date Range Budget
1252 					gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_VALID_FAIL_NO_RES_DR',
1253 						x_token_name1 => 'X_START_DATE',
1254 						x_token_val1 => x_start_date,
1255 						x_token_name2 => 'X_END_DATE',
1256 						x_token_val2 => x_end_date,
1257 						x_token_name3 => 'X_OVERFLOW_AMT',
1258 						x_token_val3 =>to_char(x_carry_over_budget),
1259                                                 x_token_name4 => 'X_PROJECT_NUM',
1260                                                 x_token_val4 => x_project_number,
1261  						x_err_code => x_err_code,
1262 						x_err_buff => x_err_stage);
1263 				elsif x_period_type = 'N' then -- for a No Time Phased budget
1264 					gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_VALID_FAIL_NO_RES_NT',
1265 						x_token_name1 => 'X_OVERFLOW_AMT',
1266 						x_token_val1 =>to_char(x_carry_over_budget),
1267                                                 x_token_name2 => 'X_PROJECT_NUM',
1268                                                 x_token_val2 => x_project_number,
1269  						x_err_code => x_err_code,
1270 						x_err_buff => x_err_stage);
1271 				else -- for either GL or PA period
1272 					gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_VALIDATE_FAIL_NO_RES',
1273 						x_token_name1 => 'X_PERIOD_NAME',
1274 						x_token_val1 => x_period_name,
1275 						x_token_name2 => 'X_OVERFLOW_AMT',
1276 						x_token_val2 =>to_char(x_carry_over_budget),
1277                                                 x_token_name3 => 'X_PROJECT_NUM',
1278                                                 x_token_val3 => x_project_number,
1279  						x_err_code => x_err_code,
1280 						x_err_buff => x_err_stage);
1281 				end if;
1282 			end if;
1283 
1284             		x_return_status := 1; -- validation FAILED
1285 			app_exception.raise_exception;
1286         	end if;
1287 
1288     	end loop;
1289 
1290 end validate_budget;
1291 ----------------------------------------------------------------------------------------
1292  procedure validate_budget_mf(  x_budget_version_id in NUMBER,
1293 			    x_award_id in NUMBER,
1294                             x_project_id in NUMBER,
1295                             x_task_id in NUMBER default NULL,
1296                             x_resource_list_member_id in NUMBER default NULL,
1297                             x_start_date in DATE,
1298                             x_end_date in DATE,
1299                             x_return_status in out NOCOPY NUMBER)
1300  is
1301   x_time_phased_type_code varchar2(30);
1302   x_err_code number;
1303   x_err_stage varchar2(630);
1304 
1305   cursor get_curr_date_range_csr (p_project_id in NUMBER
1306   				, p_award_id in NUMBER
1307   				, p_task_id in NUMBER
1308   				, p_resource_list_member_id in NUMBER)
1309   is
1310   select gbv.budget_version_id
1311   ,	 gbl.start_date
1312   ,	 gbl.end_date
1313   from   gms_budget_versions 		gbv
1314   ,	 gms_resource_assignments 	gra
1315   ,	 gms_budget_lines		gbl
1316   where  gbv.budget_version_id = gra.budget_version_id
1317   and	 gra.resource_assignment_id = gbl.resource_assignment_id
1318   and	 gbv.project_id = p_project_id
1319   and	 gbv.award_id = p_award_id
1320   and    gra.task_id = p_task_id
1321   and    gra.resource_list_member_id = p_resource_list_member_id
1322   and     gbv.current_flag = 'Y';/* bug 6444258*/
1323 
1324   cursor get_other_date_range_csr ( p_project_id in NUMBER
1325   				, p_award_id in NUMBER
1326   				, p_task_id in NUMBER
1327   				, p_resource_list_member_id in NUMBER)
1328   is
1329   select gbv.budget_version_id
1330   ,	 gbl.start_date
1331   ,	 gbl.end_date
1332   from   gms_budget_versions 		gbv
1333   ,	 gms_resource_assignments 	gra
1334   ,	 gms_budget_lines		gbl
1335   where  gbv.budget_version_id = gra.budget_version_id
1336   and	 gra.resource_assignment_id = gbl.resource_assignment_id
1337   and	 gbv.project_id = p_project_id
1338   and	 gbv.award_id <> p_award_id
1339   and    gra.task_id = p_task_id
1340   and    gra.resource_list_member_id = p_resource_list_member_id
1341   and 	 gbv.current_flag = 'Y';
1342 
1343   cursor time_phased_type_csr ( p_budget_version_id in NUMBER)
1344   is
1345   select 	time_phased_type_code
1346   from 		gms_budget_versions gbv,
1347   		pa_budget_entry_methods pbem
1348   where 	gbv.budget_entry_method_code = pbem.budget_entry_method_code
1349   and		gbv.budget_version_id = p_budget_version_id;
1350 
1351 
1352 
1353   begin
1354 
1355 	x_return_status := 0; -- Initializing x_return_status
1356 
1357   	open time_phased_type_csr (p_budget_version_id => x_budget_version_id);
1358 
1359   	fetch time_phased_type_csr into x_time_phased_type_code;
1360   	close time_phased_type_csr;
1361 
1362 	if x_time_phased_type_code = 'R' then
1363 
1364 		FOR other_date_range_rec IN get_other_date_range_csr (p_project_id => x_project_id
1365   									, p_award_id => x_award_id
1366   									, p_task_id => x_task_id
1367   									, p_resource_list_member_id => x_resource_list_member_id)
1368 		LOOP
1369         	exit when get_other_date_range_csr%NOTFOUND;
1370 
1371         		FOR curr_date_range_rec IN get_curr_date_range_csr (p_project_id => x_project_id
1372   										, p_award_id => x_award_id
1373   										, p_task_id => x_task_id
1374   										, p_resource_list_member_id => x_resource_list_member_id)
1375 			LOOP
1376 				exit when get_curr_date_range_csr%NOTFOUND;
1377 
1378 			        if (curr_date_range_rec.start_date < other_date_range_rec.start_date and curr_date_range_rec.end_date < other_date_range_rec.start_date) OR
1379         			   (curr_date_range_rec.start_date > other_date_range_rec.end_date and curr_date_range_rec.end_date > other_date_range_rec.end_date)OR
1380 				   (curr_date_range_rec.start_date = other_date_range_rec.start_date and curr_date_range_rec.end_date = other_date_range_rec.end_date) then
1381           				null;
1382 		        	else
1383 					gms_error_pkg.gms_message(x_err_name => 'GMS_BU_DATE_OVERLAP',
1384 								x_err_code => x_err_code,
1385 								x_err_buff => x_err_stage);
1386 
1387 					x_return_status := 1; -- validation failed
1388 					app_exception.raise_exception;
1389 		        	end if;
1390 
1391 		        END LOOP;
1392       		END LOOP;
1393 
1394 	end if;
1395   exception
1396 	when NO_DATA_FOUND then
1397 	NULL;
1398 
1399 	when OTHERS then
1400 	fnd_message.set_name('GMS','GMS_UNEXPECTED_ERROR');
1401 	fnd_message.set_token('SQLCODE', sqlcode);
1402 	fnd_message.set_token('SQLERRM', sqlerrm);
1403 	raise;
1404 
1405   end validate_budget_mf;
1406 -----------------------------------------------------------------------------------------
1407 --Bug 2830539
1408 PROCEDURE validate_bem_resource_list (p_project_id IN NUMBER,
1409 				 p_award_id   IN NUMBER,
1410 				 p_budget_entry_method_code IN VARCHAR2,
1411 				 p_resource_list_id IN NUMBER)
1412 IS
1413 
1414 l_dummy NUMBER:=0;
1415 l_categorization_code VARCHAR2(1);
1416 l_uncategorized_flag  VARCHAR2(1);
1417 l_resource_list_id    NUMBER;
1418 l_budget_entry_method_code1 VARCHAR2(30);
1419 l_budget_entry_method_code VARCHAR2(30);
1420 
1421 x_err_code NUMBER;
1422 x_err_stage VARCHAR2(630);
1423 
1424 
1425 cursor multifunding_csr(p_project_id IN NUMBER,
1426 			p_award_id   IN NUMBER)
1427 IS
1428   select  budget_version_id,budget_entry_method_code
1429   from    gms_budget_versions
1430   where   project_id = p_project_id
1431   and     award_id <> p_award_id
1432   and     budget_status_code = 'B'
1433   and 	  current_flag = 'Y';
1434 
1435 cursor entry_method_csr (p_project_id IN NUMBER,
1436 		       p_award_id   IN NUMBER)
1437 IS
1438   select budget_entry_method_code
1439   from 	 gms_budget_versions
1440   where	 project_id = p_project_id
1441   and 	 award_id = p_award_id
1442   and 	 budget_status_code in ('W','S');
1443 
1444 cursor entry_method_detail_csr(p_budget_entry_method_code IN VARCHAR2)
1445 IS
1446   select  categorization_code
1447   from 	  pa_budget_entry_methods
1448   where   budget_entry_method_code = p_budget_entry_method_code;
1449 
1450 cursor resource_list_csr (p_project_id IN NUMBER,
1451 			  p_award_id   IN NUMBER)
1452 IS
1453   select resource_list_id
1454   from 	 gms_budget_versions
1455   where  project_id = p_project_id
1456   and 	 award_id = p_award_id
1457   and 	 budget_status_code in ('W','S');
1458 
1459 cursor resource_list_detail_csr(p_resource_list_id IN NUMBER)
1460 IS
1461   select  uncategorized_flag
1462   from    pa_resource_lists prl,
1463           pa_implementations pi
1464   where   prl.business_group_id = pi.business_group_id
1465   and     prl.resource_list_id = p_resource_list_id;
1466 
1467 cursor baselined_budg_csr (p_project_id IN NUMBER,
1468 		           p_award_id   IN NUMBER)
1469 IS
1470   select  budget_version_id
1471   from 	  gms_budget_versions
1472   where	  budget_status_code = 'B'
1473   and	  project_id = p_project_id
1474   and	  award_id = p_award_id;
1475 
1476 BEGIN
1477 
1478 ----------------------------------------------------------------------------
1479 -- For multi-funding scenarios, update to Budget Entry Method should not
1480 -- be allowed.
1481 	open multifunding_csr(p_project_id => p_project_id,
1482 			      p_award_id => p_award_id);
1483 	fetch multifunding_csr into l_dummy,l_budget_entry_method_code1;
1484 	close multifunding_csr;
1485 
1486 		open entry_method_csr(p_project_id => p_project_id,
1487 					     p_award_id => p_award_id);
1488 
1489 		fetch entry_method_csr into l_budget_entry_method_code;
1490 		close entry_method_csr;
1491 
1492 	if l_dummy > 0 and   l_budget_entry_method_code1 <> p_budget_entry_method_code then
1493 
1494        -- Midified for GMS enhancement 5583170 as we are allowing user to enter different BEM
1495        -- in Award budget form.
1496             NULL ;
1497       /*
1498 	        gms_error_pkg.gms_message(x_err_name => 'GMS_CANT_CHANGE_BEM',
1499        		                          x_err_code => x_err_code,
1500 					  x_err_buff => x_err_stage);
1501 
1502 	        APP_EXCEPTION.RAISE_EXCEPTION;
1503        */
1504 	end if;
1505 
1506 ----------------------------------------------------------------------------
1507 -- Everytime the Budget Entry Method or Resource List is changed they should be
1508 -- validated against each other.
1509 
1510 	if p_budget_entry_method_code = GMS_BUDGET_PUB.G_MISS_CHAR then
1511 
1512 		open entry_method_csr(p_project_id => p_project_id,
1513 					     p_award_id => p_award_id);
1514 
1515 		fetch entry_method_csr into l_budget_entry_method_code;
1516 		close entry_method_csr;
1517 	else
1518 		l_budget_entry_method_code := p_budget_entry_method_code;
1519 
1520 	end if;
1521 
1522 	if p_resource_list_id = GMS_BUDGET_PUB.G_MISS_NUM then
1523 
1524 		open resource_list_csr (p_project_id => p_project_id,
1525 					       p_award_id => p_award_id);
1526 
1527 		fetch resource_list_csr into l_resource_list_id;
1528 		close resource_list_csr;
1529 	else
1530 		l_resource_list_id := p_resource_list_id;
1531 
1532 	end if;
1533 
1534 	open entry_method_detail_csr(p_budget_entry_method_code => l_budget_entry_method_code);
1535 	fetch entry_method_detail_csr into l_categorization_code;
1536 	close entry_method_detail_csr;
1537 
1538 	open resource_list_detail_csr (p_resource_list_id => l_resource_list_id);
1539 	fetch resource_list_detail_csr into l_uncategorized_flag;
1540 	close resource_list_detail_csr;
1541 
1542 	if ((l_categorization_code = 'N' and l_uncategorized_flag <> 'Y') or
1543 	   (l_categorization_code = 'R' and l_uncategorized_flag = 'Y')) then
1544 
1545                 gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_BEM_RESOURCE_LIST',
1546                                           x_err_code => x_err_code,
1547                                           x_err_buff => x_err_stage);
1548 
1549                 APP_EXCEPTION.RAISE_EXCEPTION;
1550 
1551 	end if;
1552 
1553 end validate_bem_resource_list;
1554 ----------------------------------------------------------------------------------------
1555 
1556 --Name:               create_draft_budget
1557 --Type:               Procedure
1558 --Description:        This procedure can be used to create a draft budget.
1559 --
1560 --
1561 --Called subprograms:
1562 --			gms_budget_utils.check_overlapping_dates
1563 --
1564 --
1565 --History:
1566 --
1567 
1568 PROCEDURE create_draft_budget
1569 ( p_api_version_number		IN	NUMBER
1570  ,x_err_code			IN OUT NOCOPY	NUMBER
1571  ,x_err_stage			IN OUT NOCOPY	VARCHAR2
1572  ,x_err_stack			IN OUT NOCOPY	VARCHAR2
1573  ,p_commit			IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
1574  ,p_init_msg_list		IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
1575  ,p_pm_product_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1576  ,p_pm_budget_reference		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1577 , p_budget_version_name         IN      VARCHAR2                := GMS_BUDGET_PUB.G_PA_MISS_CHAR
1578  ,p_project_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
1579  ,p_project_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1580  ,p_award_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
1581  ,p_award_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1582  ,p_budget_type_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1583  ,p_change_reason_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1584  ,p_description			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1585  ,p_entry_method_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1586  ,p_resource_list_name		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1587  ,p_resource_list_id		IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
1588  ,p_attribute_category		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1589  ,p_attribute1			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1590  ,p_attribute2			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1591  ,p_attribute3			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1592  ,p_attribute4			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1593  ,p_attribute5			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1594  ,p_attribute6			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1595  ,p_attribute7			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1596  ,p_attribute8			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1597  ,p_attribute9			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1598  ,p_attribute10			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1599  ,p_attribute11			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1600  ,p_attribute12			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1601  ,p_attribute13			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1602  ,p_attribute14			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1603  ,p_attribute15			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
1604  ,p_first_budget_period         IN      VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR -- Bug 3104308
1605 )
1606 IS
1607 
1608    CURSOR	l_budget_entry_method_csr
1609    		(p_budget_entry_method_code pa_budget_entry_methods.budget_entry_method_code%type )
1610    IS
1611    SELECT *
1612    FROM   pa_budget_entry_methods
1613    WHERE  budget_entry_method_code = p_budget_entry_method_code
1614    AND 	  trunc(sysdate) BETWEEN trunc(start_date_active) and trunc(nvl(end_date_active,sysdate));
1615 
1616 
1617    CURSOR	l_budget_amount_code_csr
1618    		( p_budget_type_code	VARCHAR2 )
1619    IS
1620    SELECT budget_amount_code
1621    FROM	  pa_budget_types
1622    WHERE  budget_type_code = p_budget_type_code;
1623 
1624 
1625    CURSOR	l_budget_change_reason_csr ( p_change_reason_code VARCHAR2 )
1626    IS
1627    SELECT 'x'
1628    FROM   pa_lookups
1629    WHERE  lookup_type = 'BUDGET CHANGE REASON'
1630    AND    lookup_code = p_change_reason_code;
1631 
1632    CURSOR l_budget_version_csr
1633    	 ( p_project_id NUMBER
1634    	 , p_award_id NUMBER
1635    	 , p_budget_type_code VARCHAR2	)
1636    IS
1637    SELECT budget_version_id
1638    ,      budget_status_code
1639    FROM gms_budget_versions
1640    WHERE project_id = p_project_id
1641    AND   award_id = p_award_id
1642    AND   budget_type_code = p_budget_type_code
1643    AND   budget_status_code IN ('W','S');
1644 
1645    CURSOR l_lock_old_budget_csr( p_budget_version_id NUMBER )
1646    IS
1647    SELECT 'x'
1648    FROM   gms_budget_versions bv
1649    ,      gms_resource_assignments ra
1650    ,      gms_budget_lines bl
1651    WHERE  bv.budget_version_id = p_budget_version_id
1652    AND    bv.budget_version_id = ra.budget_version_id (+)
1653    AND    ra.resource_assignment_id = bl.resource_assignment_id (+)
1654    FOR UPDATE OF bv.budget_version_id,ra.budget_version_id,bl.resource_assignment_id NOWAIT;
1655 
1656    -- Bug 3104308 :
1657 
1658    CURSOR	l_budget_periods_csr
1659    		(p_period_name 		VARCHAR2
1660    		,p_period_type_code	VARCHAR2	)
1661    IS
1662    SELECT period_name
1663    FROM   pa_budget_periods_v
1664    WHERE  period_name = p_period_name
1665    AND 	  period_type_code = p_period_type_code;
1666 
1667 
1668    l_api_name			CONSTANT	VARCHAR2(30) 		:= 'create_draft_budget';
1669 
1670    l_project_id					NUMBER;
1671    l_award_id					NUMBER;
1672    l_resource_list_id				NUMBER;
1673    l_old_budget_version_id			NUMBER;
1674    i						NUMBER;
1675 
1676    l_budget_entry_method_rec			pa_budget_entry_methods%rowtype;
1677    l_budget_amount_code				pa_budget_types.budget_amount_code%type;
1678    l_description				VARCHAR2(255);
1679    l_dummy					VARCHAR2(1);
1680    l_attribute_category				VARCHAR2(30);
1681    l_attribute1					VARCHAR2(150);
1682    l_attribute2					VARCHAR2(150);
1683    l_attribute3					VARCHAR2(150);
1684    l_attribute4					VARCHAR2(150);
1685    l_attribute5					VARCHAR2(150);
1686    l_attribute6					VARCHAR2(150);
1687    l_attribute7					VARCHAR2(150);
1688    l_attribute8					VARCHAR2(150);
1689    l_attribute9					VARCHAR2(150);
1690    l_attribute10				VARCHAR2(150);
1691    l_attribute11				VARCHAR2(150);
1692    l_attribute12				VARCHAR2(150);
1693    l_attribute13				VARCHAR2(150);
1694    l_attribute14				VARCHAR2(150);
1695    l_attribute15				VARCHAR2(150);
1696    l_budget_status_code				VARCHAR2(30);
1697    l_old_stack					VARCHAR2(630);
1698    l_function_allowed				VARCHAR2(1);
1699    l_resp_id					NUMBER := 0;
1700    l_user_id		                        NUMBER := 0;
1701    l_login_id					NUMBER := 0;
1702    l_module_name                                VARCHAR2(80);
1703    l_pm_budget_reference			VARCHAR2(30);
1704    l_budget_version_name 			VARCHAR2(60);
1705    l_uncategorized_list_id			NUMBER;
1706    l_uncategorized_rlmid                        NUMBER;
1707    l_uncategorized_resid                        NUMBER;
1708    l_track_as_labor_flag                        VARCHAR2(1);
1709    l_baselined_version_id 			NUMBER;
1710    l_baselined_resource_list_id 		NUMBER;
1711    l_baselined_exists				BOOLEAN;
1712    l_old_draft_version_id    			NUMBER;
1713    l_first_budget_period			VARCHAR2(30);  -- Bug 3104308
1714 
1715 -- p_multiple_task_msg  VARCHAR2(1) := 'T';
1716 
1717 BEGIN  -- create_draft_budget
1718 
1719 	x_err_code := 0;
1720 	l_old_stack := x_err_stack;
1721 	x_err_stack := x_err_stack ||'-> create_draft_budget';
1722 
1723     --	Initialize the message table if requested.
1724 
1725     IF FND_API.TO_BOOLEAN( p_init_msg_list )
1726     THEN
1727 
1728 	FND_MSG_PUB.initialize;
1729 
1730     END IF;
1731 
1732 
1733 --  Standard begin of API savepoint
1734 
1735     SAVEPOINT create_draft_budget_pub;
1736 
1737 
1738 --  Standard call to check for call compatibility.
1739 
1740     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
1741     	    	    	    	    	 p_api_version_number	,
1742     	    	    	    	    	 l_api_name 	    	,
1743     	    	    	    	    	 G_PKG_NAME 	    	)
1744     THEN
1745 
1746 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
1747 				x_err_code => x_err_code,
1748 				x_err_buff => x_err_stage);
1749 
1750 	APP_EXCEPTION.RAISE_EXCEPTION;
1751 
1752     END IF;
1753 
1754 
1755     -- product_code is mandatory
1756 
1757     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
1758     OR p_pm_product_code IS NULL
1759     THEN
1760 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_IS_MISSING',
1761 				x_err_code => x_err_code,
1762 				x_err_buff => x_err_stage);
1763 
1764 	APP_EXCEPTION.RAISE_EXCEPTION;
1765 
1766     END IF;
1767 
1768 ----------------------------------------------------------------------------
1769 -- If award_id is passed in then use it otherwise use the award_number
1770 -- that is passed in to fetch value of award_id from gms_awards table
1771 -- If both are missing then raise an error.
1772 
1773     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
1774         AND p_award_number IS NOT NULL)
1775     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
1776         AND p_award_id IS NOT NULL)
1777     THEN
1778 
1779    	convert_awardnum_to_id(p_award_number_in => p_award_number
1780    	                      ,p_award_id_in => p_award_id
1781    			      ,p_award_id_out => l_award_id
1782    			      ,x_err_code => x_err_code
1783    			      ,x_err_stage => x_err_stage
1784    			      ,x_err_stack => x_err_stack);
1785 
1786    	IF x_err_code <> 0
1787 	THEN
1788 		return;
1789 	END IF;
1790     ELSE
1791 
1792 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
1793 				x_err_code => x_err_code,
1794 				x_err_buff => x_err_stage);
1795 
1796 	APP_EXCEPTION.RAISE_EXCEPTION;
1797 
1798    END IF;
1799 --------------------------------------------------------------------------------
1800 
1801     l_resp_id := FND_GLOBAL.Resp_id;
1802     l_user_id := FND_GLOBAL.User_id;
1803     l_login_id := FND_GLOBAL.Login_id;
1804 
1805     l_module_name := 'GMS_PM_CREATE_DRAFT_BUDGET';
1806 
1807     -- As part of enforcing award security, which would determine
1808     -- whether the user has the necessary privileges to update the award
1809     -- If a user does not have privileges to update the award, then
1810     -- cannot create a budget
1811     -- need to call the gms_security package
1812 
1813     gms_security.initialize (X_user_id        => l_user_id,
1814                             X_calling_module => l_module_name);
1815 
1816     -- Actions performed using the APIs would be subject to
1817     -- function security. If the responsibility does not allow
1818     -- such functions to be executed, the API should not proceed further
1819     -- since the user does not have access to such functions
1820 
1821 
1822 --------------------------------------------------------------------------------
1823 -- If project_id is passed in then use it otherwise use the project_number
1824 -- (segment1) that is passed in to fetch value of project_id from pa_projects
1825 -- table. If both are missing then raise an error.
1826 
1827 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
1828         AND p_project_number IS NOT NULL)
1829     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
1830         AND p_project_id IS NOT NULL)
1831    	THEN
1832    		convert_projnum_to_id(p_project_number_in => p_project_number
1833    		                      ,p_project_id_in => p_project_id
1834    				      ,p_project_id_out => l_project_id
1835    				      ,x_err_code => x_err_code
1836    				      ,x_err_stage => x_err_stage
1837    				      ,x_err_stack => x_err_stack);
1838 
1839 	   	IF x_err_code <> 0
1840     		THEN
1841 			return;
1842     		END IF;
1843 
1844 	ELSE
1845 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_NUM_ID_MISSING',
1846 					x_err_code => x_err_code,
1847 					x_err_buff => x_err_stage);
1848 
1849 		APP_EXCEPTION.RAISE_EXCEPTION;
1850 	END IF;
1851 -------------------------------------------------------------------------------
1852 
1853       -- Now verify whether award security allows the user to update
1854       -- the award
1855       -- If a user does not have privileges to update the award, then
1856       -- cannot create a budget
1857 
1858 --  dbms_output.put_line('Before award security');
1859 
1860       IF gms_security.allow_query (x_award_id => l_award_id ) = 'N' THEN
1861 
1862          -- The user does not have query privileges on this award
1863          -- Hence, cannot create a draft budget.Raise error
1864 
1865 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_QRY',
1866 					x_err_code => x_err_code,
1867 					x_err_buff => x_err_stage);
1868 
1869 		APP_EXCEPTION.RAISE_EXCEPTION;
1870 
1871       ELSE
1872             -- If the user has query privileges, then check whether
1873             -- update privileges are also available
1874          IF gms_security.allow_update (x_award_id => l_award_id ) = 'N' THEN
1875 
1876             -- The user does not have update privileges on this award
1877             -- Hence , raise error
1878 
1879 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_UPD',
1880 					x_err_code => x_err_code,
1881 					x_err_buff => x_err_stage);
1882 
1883 		APP_EXCEPTION.RAISE_EXCEPTION;
1884 
1885         END IF;
1886      END IF;
1887 
1888 
1889  -- budget type code is mandatory
1890 
1891      IF p_budget_type_code IS NULL
1892      OR p_budget_type_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
1893      THEN
1894 
1895 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_MISSING',
1896 				x_err_code => x_err_code,
1897 				x_err_buff => x_err_stage);
1898 
1899 	APP_EXCEPTION.RAISE_EXCEPTION;
1900 
1901      ELSE
1902      		OPEN l_budget_amount_code_csr( p_budget_type_code );
1903 
1904 		FETCH l_budget_amount_code_csr
1905 		INTO l_budget_amount_code;     		--will be used later on during validation of Budget lines.
1906 
1907 		IF l_budget_amount_code_csr%NOTFOUND
1908 		THEN
1909 			CLOSE l_budget_amount_code_csr;
1910 			gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_INVALID',
1911 						x_err_code => x_err_code,
1912 						x_err_buff => x_err_stage);
1913 
1914 			APP_EXCEPTION.RAISE_EXCEPTION;
1915 		END IF;
1916 
1917 		CLOSE l_budget_amount_code_csr;
1918 
1919      END IF;
1920 
1921  -- entry method code is mandatory
1922 
1923      IF p_entry_method_code IS NULL
1924      OR p_entry_method_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
1925      THEN
1926 		gms_error_pkg.gms_message(x_err_name => 'GMS_ENTRY_METHOD_IS_MISSING',
1927 					x_err_code => x_err_code,
1928 					x_err_buff => x_err_stage);
1929 
1930 		APP_EXCEPTION.RAISE_EXCEPTION;
1931      END IF;
1932 
1933  -- check validity of this budget entry method code, and store associated fields in record
1934 
1935 
1936     OPEN l_budget_entry_method_csr(p_entry_method_code);
1937     FETCH l_budget_entry_method_csr INTO l_budget_entry_method_rec;
1938 
1939     IF   l_budget_entry_method_csr%NOTFOUND
1940     THEN
1941 
1942 	CLOSE l_budget_entry_method_csr;
1943 	gms_error_pkg.gms_message(x_err_name => 'GMS_ENTRY_METHOD_IS_INVALID',
1944 				x_err_code => x_err_code,
1945 				x_err_buff => x_err_stage);
1946 
1947 	APP_EXCEPTION.RAISE_EXCEPTION;
1948 
1949     END IF;
1950 
1951     CLOSE l_budget_entry_method_csr;
1952 
1953     IF l_budget_entry_method_rec.categorization_code = 'N' THEN
1954 
1955        pa_get_resource.Get_Uncateg_Resource_Info
1956                         (p_resource_list_id          => l_uncategorized_list_id,
1957                          p_resource_list_member_id   => l_uncategorized_rlmid,
1958                          p_resource_id               => l_uncategorized_resid,
1959                          p_track_as_labor_flag       => l_track_as_labor_flag,
1960                          p_err_code                  => x_err_code,
1961                          p_err_stage                 => x_err_stage,
1962                          p_err_stack                 => x_err_stack );
1963        IF x_err_code <> 0 THEN
1964 		gms_error_pkg.gms_message(x_err_name => 'GMS_NO_UNCATEGORIZED_LIST',
1965 					x_err_code => x_err_code,
1966 					x_err_buff => x_err_stage);
1967 
1968 		APP_EXCEPTION.RAISE_EXCEPTION;
1969        END IF;
1970 
1971        l_resource_list_id := l_uncategorized_list_id;
1972 
1973     ELSIF l_budget_entry_method_rec.categorization_code = 'R' THEN
1974 
1975 ------------------------------------------------------------------------------
1976 -- If resource_list_id is passed in then use it otherwise use the resource_list
1977 -- name (NAME) that is passed in to fetch value of resource_list_id from
1978 -- pa_resource_lists table. If both are missing then raise an error.
1979 
1980 	IF (p_resource_list_name <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
1981         	AND p_resource_list_name IS NOT NULL)
1982     	OR (p_resource_list_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
1983         	AND p_resource_list_id IS NOT NULL)
1984         THEN
1985    		convert_reslistname_to_id(p_resource_list_name_in => p_resource_list_name
1986    				      ,p_resource_list_id_in => p_resource_list_id
1987    				      ,p_resource_list_id_out => l_resource_list_id
1988    				      ,x_err_code => x_err_code
1989    				      ,x_err_stage => x_err_stage
1990    				      ,x_err_stack => x_err_stack);
1991 
1992 	   	IF x_err_code <> 0
1993     		THEN
1994 			gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_RESOURCE_LIST_NAME',
1995 						x_err_code => x_err_code,
1996 						x_err_buff => x_err_stage);
1997 
1998 			APP_EXCEPTION.RAISE_EXCEPTION;
1999     		END IF;
2000 
2001    	ELSE
2002 			gms_error_pkg.gms_message(x_err_name => 'GMS_RESLIST_ID_NAME_MISSING',
2003 						x_err_code => x_err_code,
2004 						x_err_buff => x_err_stage);
2005 
2006 			APP_EXCEPTION.RAISE_EXCEPTION;
2007 	END IF;
2008 ------------------------------------------------------------------------------
2009 /*
2010          IF (p_resource_list_name <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
2011              AND p_resource_list_name IS NOT NULL)
2012          OR (p_resource_list_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
2013             AND p_resource_list_id IS NOT NULL) THEN
2014 
2015         -- convert resource_list_name to resource_list_id
2016 
2017      	        pa_resource_pub.Convert_List_name_to_id
2018      		(p_resource_list_name    =>  p_resource_list_name,
2019          	 p_resource_list_id      =>  p_resource_list_id,
2020          	 p_out_resource_list_id  =>  l_resource_list_id,
2021          	 p_return_status         =>  l_return_status );
2022 
2023      	        IF l_return_status =  FND_API.G_RET_STS_UNEXP_ERROR THEN
2024          	   p_return_status := l_return_status;
2025          	   RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
2026      	        ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2027          	   p_return_status             := l_return_status;
2028          	   RAISE  FND_API.G_EXC_ERROR;
2029      	        END IF;
2030 
2031          ELSE -- There is no valid resource list id
2032 	     fnd_message.set_name('GMS', 'GMS_RESOURCE_LIST_IS_MISSING');
2033      	     RAISE FND_API.G_EXC_ERROR;
2034 
2035          END IF;
2036 */
2037 
2038     END IF ; -- If l_budget_entry_method_rec.categorization_code = 'N
2039 
2040 
2041      -- check validity of the budget change reason code, passing NULL is OK
2042 
2043      IF (p_change_reason_code IS NOT NULL AND
2044          p_change_reason_code  <> GMS_BUDGET_PUB.G_PA_MISS_CHAR) THEN
2045      	OPEN l_budget_change_reason_csr( p_change_reason_code );
2046      	FETCH l_budget_change_reason_csr INTO l_dummy;
2047 
2048      	IF l_budget_change_reason_csr%NOTFOUND THEN
2049 
2050      		CLOSE l_budget_change_reason_csr;
2051 		gms_error_pkg.gms_message(x_err_name => 'GMS_CHANGE_REASON_INVALID',
2052 					x_err_code => x_err_code,
2053 					x_err_buff => x_err_stage);
2054 
2055 		APP_EXCEPTION.RAISE_EXCEPTION;
2056 
2057      	END IF;
2058 
2059 	CLOSE l_budget_change_reason_csr;
2060 
2061      END IF;
2062 
2063      --When description is not passed, set value to NULL
2064 
2065      IF p_description = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2066      THEN
2067      	l_description := NULL;
2068      ELSE
2069 	l_description := p_description;
2070      END IF;
2071 
2072 --  dbms_output.put_line('Before setting flex fields to NULL, when not passed');
2073 
2074      --When descriptive flex fields are not passed set them to NULL
2075      IF p_attribute_category = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2076      THEN
2077      	l_attribute_category := NULL;
2078      ELSE
2079 	l_attribute_category := p_attribute_category;
2080      END IF;
2081      IF p_attribute1 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2082      THEN
2083      	l_attribute1 := NULL;
2084      ELSE
2085 	l_attribute1 := p_attribute1;
2086      END IF;
2087      IF p_attribute2 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2088      THEN
2089      	l_attribute2 := NULL;
2090      ELSE
2091 	l_attribute2 := p_attribute2;
2092      END IF;
2093      IF p_attribute3 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2094      THEN
2095      	l_attribute3 := NULL;
2096      ELSE
2097 	l_attribute3 := p_attribute3;
2098      END IF;
2099      IF p_attribute4 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2100      THEN
2101      	l_attribute4 := NULL;
2102      ELSE
2103 	l_attribute4 := p_attribute4;
2104      END IF;
2105 
2106      IF p_attribute5 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2107      THEN
2108      	l_attribute5 := NULL;
2109      ELSE
2110 	l_attribute5 := p_attribute5;
2111      END IF;
2112 
2113      IF p_attribute6 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2114      THEN
2115      	l_attribute6 := NULL;
2116      ELSE
2117 	l_attribute6 := p_attribute6;
2118      END IF;
2119 
2120      IF p_attribute7 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2121      THEN
2122      	l_attribute7 := NULL;
2123      ELSE
2124 	l_attribute7 := p_attribute7;
2125      END IF;
2126 
2127      IF p_attribute8 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2128      THEN
2129      	l_attribute8 := NULL;
2130      ELSE
2131 	l_attribute8 := p_attribute8;
2132      END IF;
2133      IF p_attribute9 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2134      THEN
2135      	l_attribute9 := NULL;
2136      ELSE
2137 	l_attribute9 := p_attribute9;
2138      END IF;
2139      IF p_attribute10 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2140      THEN
2141      	l_attribute10 := NULL;
2142      ELSE
2143 	l_attribute10 := p_attribute10;
2144      END IF;
2145      IF p_attribute11 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2146      THEN
2147      	l_attribute11 := NULL;
2148      ELSE
2149 	l_attribute11 := p_attribute11;
2150      END IF;
2151      IF p_attribute12 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2152      THEN
2153      	l_attribute12 := NULL;
2154      ELSE
2155 	l_attribute12 := p_attribute12;
2156      END IF;
2157      IF p_attribute13 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2158      THEN
2159      	l_attribute13 := NULL;
2160      ELSE
2161 	l_attribute13 := p_attribute13;
2162      END IF;
2163      IF p_attribute14 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2164      THEN
2165      	l_attribute14:= NULL;
2166      ELSE
2167 	l_attribute14:= p_attribute14;
2168      END IF;
2169 
2170      IF p_attribute15 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2171      THEN
2172      	l_attribute15 := NULL;
2173      ELSE
2174 	l_attribute15 := p_attribute15;
2175      END IF;
2176 
2177      -- Get the ID of the old draft budget and then
2178      -- Lock the old draft budget and it budget lines (if it exists)
2179      --,because it will be deleted by create_draft.
2180 
2181     OPEN l_budget_version_csr( l_project_id, l_award_id, p_budget_type_code );
2182     FETCH l_budget_version_csr INTO l_old_budget_version_id, l_budget_status_code;
2183     CLOSE l_budget_version_csr;
2184 
2185     --if working bugdet is submitted no new working budget can be created
2186 
2187     IF l_budget_status_code = 'S'
2188     THEN
2189 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_IS_SUBMITTED',
2190 					x_err_code => x_err_code,
2191 					x_err_buff => x_err_stage);
2192 
2193 		APP_EXCEPTION.RAISE_EXCEPTION;
2194     END IF;
2195 
2196     IF p_pm_budget_reference =  GMS_BUDGET_PUB.G_PA_MISS_CHAR
2197     THEN
2198        l_pm_budget_reference := NULL;
2199     ELSE
2200        l_pm_budget_reference := p_pm_budget_reference;
2201     END IF;
2202 
2203     IF p_budget_version_name =  GMS_BUDGET_PUB.G_PA_MISS_CHAR
2204     THEN
2205        l_budget_version_name := NULL;
2206     ELSE
2207        l_budget_version_name := p_budget_version_name;
2208     END IF;
2209 
2210     -- Bug 3104308 : Validation for p_first_budget_period .This will be fired only for
2211     --               GL/PA budget periods.
2212 
2213     IF p_first_budget_period =  GMS_BUDGET_PUB.G_PA_MISS_CHAR  THEN -- Bug 3104308
2214        l_first_budget_period := NULL;
2215     ELSIF (p_first_budget_period IS NOT NULL AND l_budget_entry_method_rec.time_phased_type_code IN ('G','P')) THEN
2216 
2217        OPEN  l_budget_periods_csr(p_first_budget_period,l_budget_entry_method_rec.time_phased_type_code);
2218        FETCH l_budget_periods_csr into l_first_budget_period;
2219        IF   l_budget_periods_csr%NOTFOUND THEN
2220 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_PERIOD_IS_INVALID',
2221 					x_err_code => x_err_code,
2222 					x_err_buff => x_err_stage);
2223 
2224 		APP_EXCEPTION.RAISE_EXCEPTION;
2225     	END IF;
2226     	CLOSE l_budget_periods_csr;
2227     END IF;
2228 
2229 
2230     OPEN l_lock_old_budget_csr( l_old_budget_version_id );
2231     CLOSE l_lock_old_budget_csr; 				--FYI, does not release locks
2232 
2233 -- Creating a draft budget ....
2234 
2235      gms_budget_utils.get_baselined_version_id(l_project_id,
2236                                          l_award_id,
2237 					 p_budget_type_code,
2238 					 l_baselined_version_id,
2239 					 x_err_code,
2240 					 x_err_stage,
2241 					 x_err_stack
2242 					);
2243 
2244 
2245      if (x_err_code > 0) then
2246 
2247 	-- baseline version does not exist
2248         l_baselined_exists := FALSE;
2249 	x_err_code := 0;
2250 
2251      elsif (x_err_code = 0) then
2252         -- baseliend budget exists, verify if resource lists are the same
2253         -- resource list used in accumulation
2254 
2255 	select resource_list_id
2256 	into   l_baselined_resource_list_id
2257         from   gms_budget_versions
2258         where  budget_version_id = l_baselined_version_id;
2259 
2260         if (l_resource_list_id <> l_baselined_resource_list_id) then
2261 		gms_error_pkg.gms_message(x_err_name => 'GMS_BU_BASE_RES_LIST_EXISTS',
2262 					x_err_code => x_err_code,
2263 					x_err_buff => x_err_stage);
2264 
2265 		APP_EXCEPTION.RAISE_EXCEPTION;
2266         end if;
2267 
2268         l_baselined_exists := TRUE;
2269 
2270      else
2271         -- x_err_code < 0
2272 	return;
2273      end if;
2274 
2275      gms_budget_utils.get_draft_version_id(l_project_id,
2276                                          l_award_id,
2277 					 p_budget_type_code,
2278 					 l_old_draft_version_id,
2279 					 x_err_code,
2280 					 x_err_stage,
2281 					 x_err_stack
2282 					);
2283 
2284      -- if draft exist, delete it
2285      if (x_err_code = 0) then
2286 
2287 	gms_budget_pub.delete_draft_budget
2288 	( p_api_version_number => 1.0
2289 	 ,p_pm_product_code => 'GMS'
2290 	 ,p_project_id => l_project_id
2291 	 ,p_award_id => l_award_id
2292 	 ,p_budget_type_code => p_budget_type_code
2293 	 ,x_err_code => x_err_code
2294 	 ,x_err_stage => x_err_stage  --x_err_stage => x_err_code -- bug fix : 3004115
2295 	 ,x_err_stack => x_err_stack);
2296 
2297 	if x_err_code <> 0 -- this err code is from delete_draft_budget
2298 	then
2299 		gms_error_pkg.gms_message(x_err_name => 'GMS_DELETE_DRAFT_FAIL',
2300 					x_err_code => x_err_code,
2301 					x_err_buff => x_err_stage);
2302 
2303 		APP_EXCEPTION.RAISE_EXCEPTION;
2304 	end if;
2305 
2306      elsif (x_err_code > 0) then
2307 	-- reset x_err_code
2308 	x_err_code := 0;
2309 
2310      else
2311      -- if oracle error, return
2312 	return;
2313      end if;
2314 
2315      insert into gms_budget_versions(
2316             budget_version_id,
2317             project_id,
2318             award_id,
2319             budget_type_code,
2320             version_number,
2321             budget_status_code,
2322             last_update_date,
2323             last_updated_by,
2324             creation_date,
2325             created_by,
2326             last_update_login,
2327             current_flag,
2328             original_flag,
2329             current_original_flag,
2330             resource_accumulated_flag,
2331             resource_list_id,
2332             version_name,
2333             budget_entry_method_code,
2334             baselined_by_person_id,
2335             baselined_date,
2336             change_reason_code,
2337             labor_quantity,
2338             labor_unit_of_measure,
2339             raw_cost,
2340             burdened_cost,
2341             description,
2342             attribute_category,
2343             attribute1,
2344             attribute2,
2345             attribute3,
2346             attribute4,
2347             attribute5,
2348             attribute6,
2349             attribute7,
2350             attribute8,
2351             attribute9,
2352             attribute10,
2353             attribute11,
2354             attribute12,
2355             attribute13,
2356             attribute14,
2357             attribute15,
2358 	    pm_product_code,
2359 	    pm_budget_reference,
2360 		wf_status_code,
2361 	    first_budget_period ) -- Bug 3104308
2362          select
2363             gms_budget_versions_s.nextval,
2364             l_project_id,
2365             l_award_id,
2366             p_budget_type_code,
2367             1,
2368             'W',
2369             SYSDATE,
2370 	    l_user_id,
2371             SYSDATE,
2372 	    l_user_id,
2373 	    l_login_id,
2374             'N',
2375             'N',
2376             'N',
2377             'N',
2378             l_resource_list_id,
2379             l_budget_version_name,
2380             p_entry_method_code,
2381             NULL,
2382             NULL,
2383             p_change_reason_code,
2384             NULL,
2385             NULL,
2386             NULL,
2387             NULL,
2388             l_description,
2389             l_attribute_category,
2390             l_attribute1,
2391             l_attribute2,
2392             l_attribute3,
2393             l_attribute4,
2394             l_attribute5,
2395             l_attribute6,
2396             l_attribute7,
2397             l_attribute8,
2398             l_attribute9,
2399             l_attribute10,
2400             l_attribute11,
2401             l_attribute12,
2402             l_attribute13,
2403             l_attribute14,
2404             l_attribute15,
2405 	    p_pm_product_code,
2406 	    p_pm_budget_reference,
2407 	    NULL,
2408 	    l_first_budget_period -- Bug 3104308
2409 	from sys.dual;
2410 
2411 ----------------------------------------------------------------------------------------------
2412 
2413 -- temporary solution
2414 -- COMMIT in DELETE_DRAFT removes all savepoints!!!
2415 
2416     SAVEPOINT create_draft_budget_pub;
2417 
2418   IF FND_API.TO_BOOLEAN( p_commit )
2419   THEN
2420 	COMMIT;
2421   END IF;
2422 
2423   x_err_stack := l_old_stack;
2424 
2425 EXCEPTION
2426 
2427 	WHEN OTHERS
2428 	THEN
2429 		ROLLBACK TO create_draft_budget_pub;
2430 		RAISE;
2431 
2432 END create_draft_budget;
2433 ----------------------------------------------------------------------------------------
2434 -- Name:               	Submit_Budg_Conc_Process
2435 -- Type:               	Procedure
2436 -- Description:
2437 --
2438 --
2439 --
2440 --
2441 -- Called subprograms: 	fnd_request.submit_request()
2442 --
2443 --
2444 --
2445 --
2446 -- History:
2447 --
2448 
2449 PROCEDURE submit_budg_conc_process
2450 ( p_reqid			OUT NOCOPY	NUMBER,
2451   p_project_id			IN	NUMBER,
2452   p_award_id			IN	NUMBER,
2453   p_mark_as_original		IN	VARCHAR
2454 )
2455 IS
2456 l_award_number   gms_awards_all.award_number%type ; /*bug 3651888*/
2457 l_org_id         gms_awards_all.org_id%type ; /*bug 4864049 */
2458 begin
2459 /* Bug 3651888 */
2460         Select award_number ,org_id
2461          into  l_award_number ,l_org_id
2462         from   gms_awards_all
2463         where  award_id = p_award_id;
2464 
2465         --Bug 486404: Shared Service Enhancement :Set the ORG_ID context before invoking Concurrent programs
2466         FND_REQUEST.SET_ORG_ID(l_org_id);
2467 
2468 
2469 	p_reqid := fnd_request.submit_request(	'GMS',
2470 						'GMSBUDSB',
2471 						 NULL,NULL,NULL,
2472 						p_project_id,
2473 						l_award_number,  /* Bug3651888 */
2474 						p_mark_as_original);
2475 
2476 -- Bug 	3037125 :Introduced the commit
2477 IF NVL(p_reqid,0) <> 0 THEN
2478     COMMIT;
2479 END IF;
2480 
2481 end;
2482 ----------------------------------------------------------------------------------------
2483 -- Name:               	Submit_Baseline_Budget
2484 -- Type:               	Procedure
2485 -- Description:        	This procedure is a wrapper for the baseline_budget
2486 --			and this is used as a concurrent process. It will be called
2487 --			by the Award Budgets form (GMSBUEBU)
2488 --
2489 --
2490 -- Called subprograms: 	gms_budget_pub.baseline_budget
2491 --
2492 --
2493 --
2494 --
2495 -- History:
2496 --
2497 
2498 PROCEDURE submit_baseline_budget
2499 ( ERRBUFF			IN OUT NOCOPY	VARCHAR2
2500  ,RETCODE			IN OUT NOCOPY  VARCHAR2
2501  ,p_project_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
2502  ,p_award_number		IN	VARCHAR2  /*bug 3651888			:= GMS_BUDGET_PUB.G_PA_MISS_NUM*/
2503  ,p_mark_as_original		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR)
2504 
2505 IS
2506 
2507   l_err_code		number;
2508   l_err_stage		varchar2(630); -- Bug 2587078
2509   l_err_stack		varchar2(630);
2510   l_award_id            number ;
2511   l_workflow_started	varchar2(1);
2512 
2513 begin
2514 
2515 	IF L_DEBUG = 'Y' THEN
2516 	   gms_error_pkg.gms_debug('*** Start of GMS_BUDGET_PUB.SUBMIT_BASELINE_BUDGET ***','C');
2517 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.SUBMIT_BASELINE_BUDGET - Calling gms_budget_pub.baseline_budget','C');
2518 	END IF;
2519 
2520 /* Bug 3651888 */
2521         Select award_id
2522          into  l_award_id
2523         from   gms_awards_all
2524         where  award_number = p_award_number;
2525 
2526 	gms_budget_pub.baseline_budget(	p_api_version_number => 1.0,
2527 					x_err_code => l_err_code,
2528 					x_err_stage => l_err_stage,
2529 					x_err_stack => l_err_stack,
2530 					p_commit => 'T',
2531 					p_init_msg_list => 'T',
2532 					p_workflow_started => l_workflow_started,
2533 					p_pm_product_code => 'GMS',
2534 					p_project_id => p_project_id,
2535 					p_award_id => l_award_Id,
2536 					p_budget_type_code => 'AC',
2537 					p_mark_as_original => p_mark_as_original);
2538 
2539 	IF L_DEBUG = 'Y' THEN
2540    	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.SUBMIT_BASELINE_BUDGET - Call to gms_budget_pub.baseline_budget returned l_err_code : '||l_err_code,'C');
2541 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.SUBMIT_BASELINE_BUDGET - Call to gms_budget_pub.baseline_budget returned l_err_stage : '||l_err_stage,'C');
2542 	END IF;
2543 
2544 	-- Bug 3022766  : Introduced error code = 3 to represent fundscheck failure status.
2545 	-- Baseline_budget procedure returns following statuses
2546 	-- x_err_code =0 represents success
2547 	-- x_err_code =1 represents unexpected error
2548 	-- x_err_code =2 represents expected error
2549 	-- x_err_code =3 represents Fundscheck failure
2550 	-- x_err_code =4 represents warning
2551 
2552 	if l_err_code = 0 or  l_err_code = 3 -- Bug 3022766
2553 	then
2554 		RETCODE := 0;
2555 		ERRBUFF := l_err_stage;
2556 
2557 	elsif l_err_code = 4 then
2558 
2559 		RETCODE := 1;
2560 		ERRBUFF := l_err_stage;
2561 
2562 	else
2563 
2564 		RETCODE := 2;
2565 		ERRBUFF := l_err_stage;
2566 
2567 	end if;
2568 
2569 	IF L_DEBUG = 'Y' THEN
2570            gms_error_pkg.gms_debug('*** End of GMS_BUDGET_PUB.SUBMIT_BASELINE_BUDGET ***','C');
2571 	END IF;
2572 
2573 exception
2574 when OTHERS then
2575 	RETCODE := 2;
2576 	ERRBUFF := SQLCODE ||'-'||SQLERRM;
2577 	IF L_DEBUG = 'Y' THEN
2578 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.SUBMIT_BASELINE_BUDGET - Exception :'||ERRBUFF,'C');
2579 	END IF;
2580 
2581 end;
2582 
2583 ----------------------------------------------------------------------------------------
2584 
2585 --Name:               Baseline_Budget
2586 --Type:               Procedure
2587 --Description:        This procedure can be used to baseline
2588 --		      a budget for a given project.
2589 --
2590 --
2591 --Called subprograms: gms_budget_core.verify
2592 --		      gms_budget_core.baseline
2593 --
2594 --
2595 --
2596 --History:
2597 --
2598 
2599 PROCEDURE baseline_budget
2600 ( p_api_version_number		IN	NUMBER
2601  ,x_err_code			IN OUT NOCOPY	NUMBER
2602  ,x_err_stage			IN OUT NOCOPY	VARCHAR2
2603  ,x_err_stack			IN OUT NOCOPY	VARCHAR2
2604  ,p_commit			IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
2605  ,p_init_msg_list		IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
2606  ,p_workflow_started		OUT NOCOPY	VARCHAR2
2607  ,p_pm_product_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
2608  ,p_project_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
2609  ,p_project_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
2610  ,p_award_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
2611  ,p_award_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
2612  ,p_budget_type_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
2613  ,p_mark_as_original		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR	)
2614 
2615 IS
2616 
2617     CURSOR	l_budget_types_csr
2618     		( p_budget_type_code	VARCHAR2 )
2619     IS
2620       SELECT 1
2621       FROM   pa_budget_types
2622       WHERE  budget_type_code = p_budget_type_code;
2623 
2624     CURSOR l_resource_assignments_csr
2625     		( p_budget_version_id NUMBER )
2626     IS
2627       SELECT 1
2628       FROM gms_resource_assignments
2629       WHERE budget_version_id = p_budget_version_id;
2630 
2631     CURSOR l_budget_versions_csr
2632     		( p_project_id NUMBER
2633     		, p_award_id NUMBER
2634     		, p_budget_type_code VARCHAR2 )
2635 
2636     IS
2637       SELECT budget_version_id, budget_status_code
2638       FROM   gms_budget_versions
2639       WHERE project_id 		= p_project_id
2640       AND   award_id            = p_award_id
2641       AND   budget_type_code 	= p_budget_type_code
2642       AND   budget_status_code 	in ('W','S');
2643 
2644 
2645 
2646     CURSOR l_baselined_csr
2647     		( p_project_id NUMBER
2648     		, p_award_id NUMBER
2649     		, p_budget_type_code VARCHAR2 )
2650 
2651     IS
2652       SELECT 1
2653       FROM   gms_budget_versions
2654       WHERE project_id 		= p_project_id
2655       AND   award_id            = p_award_id
2656       AND   budget_type_code 	= p_budget_type_code
2657       AND   budget_status_code 	= 'B';
2658 
2659 
2660 -- Cursor for Verify_Budget_Rules
2661 /** Modified so that we get group_resource_type_id which is used
2662 --  by GMS_BUDG_CONT_SETUP()
2663 
2664     CURSOR	l_budget_rules_csr(p_draft_version_id NUMBER)
2665     IS
2666     SELECT 	v.resource_list_id,
2667 	    	t.project_type_class_code
2668     FROM   	pa_project_types t,
2669 	    	pa_projects p,
2670 	    	gms_budget_versions v
2671     WHERE  	v.budget_version_id = p_draft_version_id
2672     AND		v.project_id = p.project_id
2673     AND 	p.project_type = t.project_type;
2674 
2675 **/
2676 
2677     CURSOR	l_budget_rules_csr(p_draft_version_id NUMBER)
2678     IS
2679     SELECT 	v.resource_list_id,
2680 	    	t.project_type_class_code,
2681 		prl.group_resource_type_id
2682     FROM   	pa_project_types t,
2683 	    	pa_projects p,
2684 	    	pa_resource_lists prl,
2685 	    	gms_budget_versions v
2686     WHERE  	v.budget_version_id = p_draft_version_id
2687     AND		v.project_id = p.project_id
2688     AND		prl.resource_list_id = v.resource_list_id
2689     AND 	p.project_type = t.project_type;
2690 
2691     CURSOR l_time_phased_type_csr(p_budget_version_id IN NUMBER)
2692     IS
2693     SELECT 	pbem.time_phased_type_code, pbem.entry_level_code
2694     FROM 	gms_budget_versions gbv,
2695 		pa_budget_entry_methods pbem
2696     WHERE	gbv.budget_version_id = p_budget_version_id
2697     AND		gbv.budget_entry_method_code = pbem.budget_entry_method_code;
2698 
2699 -- Required to obtain Award and Project Numbers to be used in error messages
2700 
2701     CURSOR l_award_csr(p_award_id IN NUMBER)
2702     IS
2703     SELECT 	award_number
2704     FROM 	gms_awards_v
2705     WHERE	award_id = p_award_id;
2706 
2707     CURSOR l_project_csr(p_project_id IN NUMBER)
2708     IS
2709     SELECT 	segment1
2710     FROM 	pa_projects
2711     WHERE	project_id = p_project_id;
2712 
2713     CURSOR l_wf_notif_role_csr(p_award_id IN NUMBER)
2714     IS
2715     SELECT 	1
2716     FROM 	gms_notifications
2717     WHERE	award_id = p_award_id
2718     AND		event_type = 'BUDGET_BASELINE';
2719 
2720    /*Fix for bug 5620089*/
2721    CURSOR l_wf_enabled_csr(p_award_id IN NUMBER)
2722     IS
2723     SELECT      BUDGET_WF_ENABLED_FLAG
2724     FROM        gms_awards
2725     WHERE       award_id = p_award_id;
2726     /*End of fix for bug 5620089*/
2727 
2728 -- ROW LOCKING ---------------------------------------------------------------
2729 
2730 	CURSOR l_lock_budget_csr (p_budget_version_id NUMBER)
2731 	IS
2732 	SELECT 'x'
2733 	FROM 	gms_budget_versions
2734 	WHERE budget_version_id = p_budget_version_id
2735 	FOR UPDATE NOWAIT;
2736 
2737 ------------------------------------------------------------------------------
2738 
2739    l_prev_entry_level_code pa_budget_entry_methods.entry_level_code%type;
2740 
2741 
2742    l_api_name			CONSTANT	VARCHAR2(30) 		:= 'baseline_budget';
2743    l_award_id					NUMBER;
2744    l_project_id					NUMBER;
2745    l_award_number				VARCHAR2(15); -- Used to display in Error Messages only
2746    l_project_number				VARCHAR2(25); -- Used to display in Error Messages only
2747    l_budget_version_id				NUMBER;
2748    l_baselined_version_id			NUMBER;
2749    l_prev_baselined_version_id			NUMBER;
2750    l_budget_status_code				VARCHAR2(30);
2751    l_time_phased_type_code			VARCHAR2(1);
2752    l_mark_as_original				gms_budget_versions.current_original_flag%TYPE;
2753    i						NUMBER;
2754    l_row_found					NUMBER;
2755    l_function_allowed				VARCHAR2(1);
2756    l_resp_id					NUMBER := 0;
2757    l_user_id		                        NUMBER := 0;
2758    l_login_id					NUMBER := 0;
2759    l_module_name                                VARCHAR2(80);
2760 
2761    l_workflow_is_used 				VARCHAR2(1)	:= NULL;
2762    l_resource_list_id				NUMBER;
2763 
2764    l_group_resource_type_id			NUMBER; 	-- Used for Budgetary Control Setup.
2765    l_entry_level_code				VARCHAR2(30); 	-- Used for Budgetary Control Setup.
2766 
2767    l_project_type_class_code 			pa_project_types.project_type_class_code%TYPE;
2768 
2769    l_warnings_only_flag				VARCHAR2(1) := 'Y';
2770    l_err_msg_count				NUMBER	:= 0;
2771    l_old_stack					VARCHAR2(630);
2772    l_fc_return_code 				VARCHAR2(1);
2773    l_app_short_name				VARCHAR2(30); -- used for summarizing project budgets
2774    l_return_status				VARCHAR2(30); -- used for summarizing project budgets and gms_sweeping
2775    l_dummy_num					NUMBER;
2776    l_dummy_char					VARCHAR2(255);
2777    l_conc_request_id				NUMBER := FND_GLOBAL.CONC_REQUEST_ID;
2778    l_packet_id					NUMBER;
2779    v_project_start_date				DATE;
2780    v_project_completion_date			DATE;
2781    l_user_profile_value1                        VARCHAR2(30);
2782    l_set_profile_success1                       BOOLEAN := FALSE;
2783    l_user_profile_value2                        VARCHAR2(30);
2784    l_set_profile_success2                       BOOLEAN := FALSE;
2785    l_funds_check_at_submit                      VARCHAR2(1) := NVL(FND_PROFILE.value('GMS_ENABLE_FUNDS_CHECK_AT_SUBMIT'),'Y'); -- Bug 2290959
2786    l_wf_enabled_flag                            VARCHAR2(1);--Added for bug 5620089
2787 BEGIN
2788 
2789 	gms_error_pkg.set_debug_context; -- Added for Bug: 2510024
2790 
2791 	IF L_DEBUG = 'Y' THEN
2792            gms_error_pkg.gms_debug('*** Start of GMS_BUDGET_PUB.BASELINE_BUDGET ***','C');
2793 	END IF;
2794 
2795 	x_err_code := 0;
2796         x_err_stage := NULL; -- Bug 2587078
2797 	l_old_stack := x_err_stack;
2798 	x_err_stack := x_err_stack ||'-> Baseline_budget';
2799 
2800     --	Initialize the message table if requested.
2801 
2802     IF FND_API.TO_BOOLEAN( p_init_msg_list )
2803     THEN
2804 
2805 	FND_MSG_PUB.initialize;
2806 
2807     END IF;
2808 
2809 --  Standard begin of API savepoint
2810 
2811     SAVEPOINT baseline_budget_pub;
2812 
2813 --  Standard call to check for call compatibility.
2814 
2815     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
2816     	    	    	    	    	 p_api_version_number	,
2817     	    	    	    	    	 l_api_name 	    	,
2818     	    	    	    	    	 G_PKG_NAME 	    	)
2819     THEN
2820         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in FND_API.Compatible_API_Call';
2821 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
2822 				x_err_code => x_err_code,
2823 				x_err_buff => x_err_stage);
2824       fnd_msg_pub.add; -- Bug 2587078
2825 
2826 
2827 	APP_EXCEPTION.RAISE_EXCEPTION;
2828 
2829     END IF;
2830 
2831     --product_code is mandatory
2832 
2833     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2834     OR p_pm_product_code IS NULL
2835     THEN
2836         x_err_stage := 'Error occured while validating product_code';
2837 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_IS_MISSING',
2838 				x_err_code => x_err_code,
2839 				x_err_buff => x_err_stage);
2840         fnd_msg_pub.add; -- Bug 2587078
2841 	APP_EXCEPTION.RAISE_EXCEPTION;
2842 
2843     END IF;
2844 
2845 ----------------------------------------------------------------------------
2846 -- If award_id is passed in then use it otherwise use the award_number
2847 -- that is passed in to fetch value of award_id from gms_awards table
2848 -- If both are missing then raise an error.
2849 
2850     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
2851         AND p_award_number IS NOT NULL)
2852     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
2853         AND p_award_id IS NOT NULL)
2854     THEN
2855 
2856         IF L_DEBUG = 'Y' THEN
2857 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling convert_awardnum_to_id','C');
2858         END IF;
2859 
2860    	convert_awardnum_to_id(p_award_number_in => p_award_number
2861    	                      ,p_award_id_in => p_award_id
2862    			      ,p_award_id_out => l_award_id
2863    			      ,x_err_code => x_err_code
2864    			      ,x_err_stage => x_err_stage
2865    			      ,x_err_stack => x_err_stack);
2866 
2867    	IF x_err_code <> 0
2868 	THEN
2869            IF L_DEBUG = 'Y' THEN
2870 	      gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Call to convert_awardnum_to_id returned x_err_code : '||x_err_code ||' x_err_stage :'||x_err_stage,'C');
2871            END IF;
2872  	   return;
2873 	END IF;
2874     ELSE
2875         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Award information';
2876 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
2877 				x_err_code => x_err_code,
2878 				x_err_buff => x_err_stage);
2879         fnd_msg_pub.add; -- Bug 2587078
2880 	APP_EXCEPTION.RAISE_EXCEPTION;
2881    END IF;
2882 --------------------------------------------------------------------------------
2883 -- getting the award number to be used in Error Messages...
2884 
2885     open l_award_csr(l_award_id);
2886     fetch l_award_csr into l_award_number;
2887     close l_award_csr;
2888 
2889     l_resp_id := FND_GLOBAL.Resp_id;
2890     l_user_id := FND_GLOBAL.User_id;
2891     l_login_id := FND_GLOBAL.Login_id;
2892 
2893     l_module_name := 'GMS_PM_BASELINE_BUDGET';
2894 
2895     -- As part of enforcing award security, which would determine
2896     -- whether the user has the necessary privileges to update the award
2897     -- need to call the gms_security package
2898     -- If a user does not have privileges to update the award, then
2899     -- cannot baseline the budget
2900 
2901     IF L_DEBUG = 'Y' THEN
2902        gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_security.initialize','C');
2903     END IF;
2904 
2905     gms_security.initialize (X_user_id        => l_user_id,
2906                             X_calling_module => l_module_name);
2907 
2908     -- Actions performed using the APIs would be subject to
2909     -- function security. If the responsibility does not allow
2910     -- such functions to be executed, the API should not proceed further
2911     -- since the user does not have access to such functions
2912 
2913     -- Initialize New OUT-parameter to indicate workflow status
2914 
2915 -- Set Worflow Started Status -------------------------------------------------
2916 
2917     p_workflow_started		:= 'N';
2918 ------------------------------------------------------------------------------------
2919 
2920 -- If project_id is passed in then use it otherwise use the project_number
2921 -- (segment1) that is passed in to fetch value of project_id from pa_projects
2922 -- table. If both are missing then raise an error.
2923 
2924 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
2925         AND p_project_number IS NOT NULL)
2926     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
2927         AND p_project_id IS NOT NULL)
2928    	THEN
2929                 IF L_DEBUG = 'Y' THEN
2930 	            gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling convert_projnum_to_id','C');
2931                 END IF;
2932    		convert_projnum_to_id(p_project_number_in => p_project_number
2933    		                      ,p_project_id_in => p_project_id
2934    				      ,p_project_id_out => l_project_id
2935    				      ,x_err_code => x_err_code
2936    				      ,x_err_stage => x_err_stage
2937    				      ,x_err_stack => x_err_stack);
2938 
2939 	   	IF x_err_code <> 0
2940     		THEN
2941 	           IF L_DEBUG = 'Y' THEN
2942 		      gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Call to convert_projnum_to_id returned x_err_code : '||x_err_code ||' x_err_stage :'||x_err_stage,'C');
2943 	           END IF;
2944 		   return;
2945     		END IF;
2946 
2947 	ELSE
2948                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Project information';
2949 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJECT_IS_MISSING', -- 'GMS_PROJ_NUM_ID_MISSING', Bug 2587078
2950 					x_err_code => x_err_code,
2951 					x_err_buff => x_err_stage);
2952                 fnd_msg_pub.add; -- Bug 2587078
2953 		APP_EXCEPTION.RAISE_EXCEPTION;
2954 
2955 	END IF;
2956 
2957 -------------------------------------------------------------------------------
2958 
2959 -- getting the project number (segment1) to be used in Error Messages...
2960 
2961     open l_project_csr(l_project_id);
2962     fetch l_project_csr into l_project_number;
2963     close l_project_csr;
2964 
2965 	IF l_project_id IS NULL   --never happens because previous procedure checks this.
2966 	THEN
2967                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Project information';
2968 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_REF_AND_ID_MISSING', --'GMS_INVALID_PROJ_NUMBER', bug 2587078
2969 					x_err_code => x_err_code,
2970 			 		x_err_buff => x_err_stage);
2971                 fnd_msg_pub.add; -- Bug 2587078
2972 		APP_EXCEPTION.RAISE_EXCEPTION;
2973      	END IF;
2974 
2975  -- budget type code is mandatory
2976 
2977      IF p_budget_type_code IS NULL
2978      OR p_budget_type_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
2979      THEN
2980                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Budget type information';
2981 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_MISSING',
2982 					x_err_code => x_err_code,
2983 			 		x_err_buff => x_err_stage);
2984                 fnd_msg_pub.add; -- Bug 2587078
2985 		APP_EXCEPTION.RAISE_EXCEPTION;
2986 
2987      ELSE
2988      		OPEN l_budget_types_csr( p_budget_type_code );
2989 
2990 		FETCH l_budget_types_csr
2991 		INTO l_row_found;
2992 
2993 		IF l_budget_types_csr%NOTFOUND
2994 		THEN
2995 
2996 			CLOSE l_budget_types_csr;
2997                         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Budget type information';
2998 			gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_INVALID',
2999 						x_err_code => x_err_code,
3000 				 		x_err_buff => x_err_stage);
3001                         fnd_msg_pub.add; -- Bug 2587078
3002 			APP_EXCEPTION.RAISE_EXCEPTION;
3003 
3004 		END IF;
3005 
3006 		CLOSE l_budget_types_csr;
3007 
3008      END IF;
3009 
3010  -- mark_as_original defaults to YES ('Y') when this is the first time this budget is baselined
3011  -- otherwise it will default to NO ('N')
3012 
3013     IF p_mark_as_original IS NULL
3014     OR p_mark_as_original = GMS_BUDGET_PUB.G_PA_MISS_CHAR
3015     OR UPPER(p_mark_as_original) NOT IN ('N','Y')
3016     THEN
3017 
3018 	OPEN l_baselined_csr( l_project_id
3019 	                     ,l_award_id
3020 			     ,p_budget_type_code );
3021 
3022 	FETCH l_baselined_csr INTO l_row_found;
3023 
3024 	IF l_baselined_csr%NOTFOUND
3025 	THEN
3026        		l_mark_as_original := 'Y';
3027     	ELSE
3028     		l_mark_as_original := 'N';
3029     	END IF;
3030 
3031     	CLOSE l_baselined_csr;
3032 
3033     ELSE
3034     	l_mark_as_original := UPPER(p_mark_as_original);
3035 
3036     END IF;
3037 
3038     IF L_DEBUG = 'Y' THEN
3039     	gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - l_mark_as_original : '||l_mark_as_original,'C');
3040     END IF;
3041 
3042  -- get the budget version ID associated with this project / budget_type_code combination
3043 
3044     OPEN l_budget_versions_csr ( l_project_id
3045                                 ,l_award_id
3046     				,p_budget_type_code );
3047 
3048     FETCH l_budget_versions_csr
3049     INTO l_budget_version_id, l_budget_status_code;
3050 
3051     IF l_budget_versions_csr%NOTFOUND
3052     THEN
3053 	CLOSE l_budget_versions_csr;
3054         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Budget version information';
3055 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_VERSION',
3056 				x_err_code => x_err_code,
3057 		 		x_err_buff => x_err_stage);
3058         fnd_msg_pub.add; -- Bug 2587078
3059 	APP_EXCEPTION.RAISE_EXCEPTION;
3060     END IF;
3061 
3062     CLOSE l_budget_versions_csr;
3063 
3064  -- check for budget lines in gms_resource_assignments,
3065  -- we only permit submit/baseline action when there are budget lines
3066 
3067     OPEN l_resource_assignments_csr(l_budget_version_id);
3068 
3069     FETCH l_resource_assignments_csr
3070     INTO l_row_found;
3071 
3072     IF l_resource_assignments_csr%NOTFOUND
3073     THEN
3074 	CLOSE l_resource_assignments_csr;
3075         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Budget lines information';
3076 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_LINES',
3077 				x_err_code => x_err_code,
3078 		 		x_err_buff => x_err_stage);
3079         fnd_msg_pub.add; -- Bug 2587078
3080 	APP_EXCEPTION.RAISE_EXCEPTION;
3081     END IF;
3082 
3083     CLOSE l_resource_assignments_csr;
3084 
3085     OPEN l_time_phased_type_csr(l_budget_version_id);
3086     FETCH l_time_phased_type_csr
3087     INTO l_time_phased_type_code, l_entry_level_code ; -- l_entry_level_code for Budgetary Controls
3088 
3089     IF l_time_phased_type_csr%NOTFOUND
3090     THEN
3091 	CLOSE l_time_phased_type_csr;
3092         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Time phase information';
3093 	gms_error_pkg.gms_message(x_err_name => 'GMS_TIME_PHASED_TYPE_CODE_MISS',
3094 				x_err_code => x_err_code,
3095 		 		x_err_buff => x_err_stage);
3096         fnd_msg_pub.add; -- Bug 2587078
3097 	APP_EXCEPTION.RAISE_EXCEPTION;
3098     END IF;
3099 
3100 -- Dummy call !
3101 
3102     IF L_DEBUG = 'Y' THEN
3103        gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_budget_core.verify', 'C');
3104     END IF;
3105 
3106     gms_budget_core.verify( x_budget_version_id  => l_budget_version_id
3107        		         ,x_err_code		=> x_err_code
3108 			 ,x_err_stage		=> x_err_stage
3109 			 ,x_err_stack		=> x_err_stack	);
3110 
3111     IF x_err_code <> 0
3112     THEN
3113         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in gms_budget_core.verify';
3114 	gms_error_pkg.gms_message(x_err_name => 'GMS_VERIFY_FAILED',
3115 				x_err_code => x_err_code,
3116 		 		x_err_buff => x_err_stage);
3117         fnd_msg_pub.add; -- Bug 2587078
3118 	APP_EXCEPTION.RAISE_EXCEPTION;
3119     END IF;
3120 
3121 -- ------------------------------------------------------------------------------------
3122 --  Added SUBMISSION/BASELINE RULES and WORFLOW
3123 -- ------------------------------------------------------------------------------------
3124 
3125 -- Retrieve Required IN-parameters for Verify_Budget_Rules Calls
3126 
3127      OPEN l_budget_rules_csr(l_budget_version_id);
3128 
3129      FETCH l_budget_rules_csr
3130      INTO	l_resource_list_id
3131 		, l_project_type_class_code
3132 		, l_group_resource_type_id;
3133 
3134      IF ( l_budget_rules_csr%NOTFOUND)
3135     THEN
3136 
3137 	CLOSE l_budget_rules_csr;
3138         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured while validating Budget rules information';
3139 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_RULES_ATTR',
3140 				x_err_code => x_err_code,
3141 		 		x_err_buff => x_err_stage);
3142         fnd_msg_pub.add; -- Bug 2587078
3143 	APP_EXCEPTION.RAISE_EXCEPTION;
3144 
3145     END IF;
3146 
3147     CLOSE l_budget_rules_csr;
3148 
3149 
3150 ----------------------------------------------------------------------------
3151 -- The budget will be Submitted or Baselined depending on the value
3152 -- of l_budget_status_code and if workflow is enabled or not
3153 --
3154 -- if status is 'W' then
3155 -- 	if workflow enabled then
3156 --		start WF process for Submit and Baseline
3157 --	else
3158 --		set the appropriate status flags and return control
3159 --		to calling program (Form)
3160 --	end if
3161 -- elseif status is 'S' then
3162 --	Baseline (assuming that WF is not enabled)
3163 -- end if
3164 ----------------------------------------------------------------------------
3165 ----------------------------------------------------------------------------
3166 --	Conditional Funds Checking.
3167 -- 	if is_fc_required returns TRUE then
3168 -- 	update GMS_BUDGET_VERSIONS table and set FC_REQUIRED_FLAG = 'Y'
3169 --	The Funds Checking process is run only if this flag is 'Y'
3170 ----------------------------------------------------------------------------
3171 
3172 	if is_fc_required (p_project_id => l_project_id,
3173 			p_award_id => l_award_id)
3174 	then
3175 		IF L_DEBUG = 'Y' THEN
3176 		  gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Call to is_fc_required returned TRUE ', 'C');
3177 		END IF;
3178 
3179 		UPDATE 	gms_budget_versions
3180 		SET 	fc_required_flag = 'Y'
3181 		WHERE 	award_id = l_award_id
3182 		AND	project_id = l_project_id
3183 		AND	budget_type_code = p_budget_type_code
3184 		AND	budget_status_code in ('W','S');
3185 	else
3186 		IF L_DEBUG = 'Y' THEN
3187 		  gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Call to is_fc_required returned FALSE ', 'C');
3188 		END IF;
3189 
3190 		UPDATE 	gms_budget_versions
3191 		SET 	fc_required_flag = 'N'
3192 		WHERE 	award_id = l_award_id
3193 		AND	project_id = l_project_id
3194 		AND	budget_type_code = p_budget_type_code
3195 		AND	budget_status_code in ('W','S');
3196 	end if;
3197 
3198 
3199    IF l_budget_status_code = 'W'
3200    THEN
3201 
3202 	IF L_DEBUG = 'Y' THEN
3203 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Start of Submit process', 'C');
3204 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling GMS_BUDGET_UTILS.VERIFY_BUDGET_RULES - Submit mode', 'C');
3205 	END IF;
3206 
3207 -- this is also a dummy call ...
3208      GMS_BUDGET_UTILS.VERIFY_BUDGET_RULES
3209     (p_draft_version_id		=>	l_budget_version_id
3210     , p_mark_as_original  	=>	l_mark_as_original
3211     , p_event			=>	'SUBMIT'
3212     , p_project_id		=>	l_project_id
3213     , p_award_id		=>	l_award_id
3214     , p_budget_type_code	=>	p_budget_type_code
3215     , p_resource_list_id	=>	l_resource_list_id
3216     , p_project_type_class_code	=>	l_project_type_class_code
3217     , p_created_by 		=>	G_USER_ID
3218     , p_calling_module		=>	'GMSMBUPB'
3219     , p_warnings_only_flag	=> 	l_warnings_only_flag
3220     , p_err_msg_count		=> 	l_err_msg_count
3221     , p_err_code		=> 	x_err_code
3222     , p_err_stage		=> 	x_err_stage
3223     , p_err_stack		=> 	x_err_stack
3224     );
3225 
3226 -- Warnings-OK Concept -----------------------------------
3227 
3228 -- Bug 2587078 : Replacing chekc from l_err_msg_count > 0 to x_err_code <> 0
3229 -- as the l_err_msg_count is not set in all the error cases .
3230 
3231 --IF (l_err_msg_count > 0)
3232 IF (x_err_code <> 0)
3233  THEN
3234 	IF (l_warnings_only_flag 	<> 'Y')
3235 	THEN
3236                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in GMS_BUDGET_UTILS.VERIFY_BUDGET_RULES - Submit';
3237 		gms_error_pkg.gms_message(x_err_name => 'GMS_VERIFY_BUDGET_FAIL_S',
3238 					x_err_code => x_err_code,
3239 			 		x_err_buff => x_err_stage);
3240                 fnd_msg_pub.add; -- Bug 25870708
3241 		APP_EXCEPTION.RAISE_EXCEPTION;
3242 	END IF;
3243 END IF;
3244 
3245 
3246 -- LOCK DRAFT BUDGET VERSION Since Primary Verification Finished
3247     IF L_DEBUG = 'Y' THEN
3248     	gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Locking the budget', 'C');
3249     END IF;
3250 
3251     OPEN l_lock_budget_csr(l_budget_version_id);
3252     CLOSE l_lock_budget_csr;
3253 
3254 -- BASELINE RULES -------------------------------------------------------------
3255 
3256     IF L_DEBUG = 'Y' THEN
3257        gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling GMS_BUDGET_UTILS.VERIFY_BUDGET_RULES - Baseline mode', 'C');
3258     END IF;
3259 
3260 GMS_BUDGET_UTILS.VERIFY_BUDGET_RULES
3261     (p_draft_version_id		=>	l_budget_version_id
3262     , p_mark_as_original  	=>	l_mark_as_original
3263     , p_event			=> 	'BASELINE'
3264     , p_project_id		=>	l_project_id
3265     , p_award_id		=>	l_award_id
3266     , p_budget_type_code	=>	p_budget_type_code
3267     , p_resource_list_id	=>	l_resource_list_id
3268     , p_project_type_class_code	=>	l_project_type_class_code
3269     , p_created_by 		=>	G_USER_ID
3270     , p_calling_module		=>	'GMSMBUPB'
3271     , p_warnings_only_flag	=> 	l_warnings_only_flag
3272     , p_err_msg_count		=> 	l_err_msg_count
3273     , p_err_code		=> 	x_err_code
3274     , p_err_stage		=> 	x_err_stage
3275     , p_err_stack		=> 	x_err_stack
3276     );
3277 
3278 
3279 -- Warnings-OK Concept -----------------------------------
3280 -- Bug 2587078 : Replacing chekc from l_err_msg_count > 0 to x_err_code <> 0
3281 -- as the l_err_msg_count is not set in all the error cases .
3282 
3283 --IF (l_err_msg_count > 0)
3284 IF (x_err_code <> 0)
3285  THEN
3286 	IF (l_warnings_only_flag <> 'Y')
3287 	THEN
3288         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in GMS_BUDGET_UTILS.VERIFY_BUDGET_RULES - Baseline ';
3289 	gms_error_pkg.gms_message(x_err_name => 'GMS_VERIFY_BUDGET_FAIL_B',
3290 				x_err_code => x_err_code,
3291 		 		x_err_buff => x_err_stage);
3292         fnd_msg_pub.add; -- Bug 2587078
3293 	APP_EXCEPTION.RAISE_EXCEPTION;
3294 
3295 	END IF;
3296 END IF;
3297 
3298 -- CHECKING IF WORKFLOW IS ENABLED FOR THIS AWARD
3299 
3300 IF L_DEBUG = 'Y' THEN
3301  gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_wf_pkg.is_budget_wf_used', 'C');
3302 END IF;
3303 
3304 GMS_WF_PKG.Is_Budget_Wf_Used
3305 ( p_project_id 			=>	l_project_id
3306 , p_award_id 			=>	l_award_id
3307 , p_budget_type_code		=>	p_budget_type_code
3308 , p_pm_product_code		=>	p_pm_product_code
3309 , p_result			=>	l_workflow_is_used
3310 , p_err_code             	=>	x_err_code
3311 , p_err_stage         		=> 	x_err_stage
3312 , p_err_stack			=>	x_err_stack
3313 );
3314 
3315 	IF (x_err_code <> 0)
3316 	THEN
3317                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in gms_wf_pkg.is_budget_wf_used';
3318 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_WF_CHECK_FAIL',
3319 					x_err_code => x_err_code,
3320 		 			x_err_buff => x_err_stage);
3321                 fnd_msg_pub.add; -- Bug 2587078
3322 		APP_EXCEPTION.RAISE_EXCEPTION;
3323 	END IF;
3324 
3325     IF L_DEBUG = 'Y' THEN
3326        gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - l_workflow_is_used : '||l_workflow_is_used, 'C');
3327     END IF;
3328 
3329 IF (l_workflow_is_used = 'T' ) THEN -- WORKFLOW IS ENABLED FOR THIS AWARD
3330 
3331 	-- when the client extension returns 'T',
3332 	-- the baseline action will be skipped here, since the baselining is done later
3333 	-- by the baseliner as part of the workflow process.
3334 
3335 	UPDATE gms_budget_versions
3336     	SET 	--budget_status_code = 'S',
3337     	WF_status_code = 'IN_ROUTE',
3338     	conc_request_id = l_conc_request_id
3339     	WHERE budget_version_id = l_budget_version_id;
3340 
3341         IF L_DEBUG = 'Y' THEN
3342            gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_wf_pkg.start_budget_wf', 'C');
3343         END IF;
3344 
3345      	GMS_WF_PKG.Start_Budget_Wf
3346 	( p_draft_version_id		=> 	l_budget_version_id
3347 	, p_project_id			=>	l_project_id
3348 	, p_award_id			=>	l_award_id
3349 	, p_budget_type_code		=>	p_budget_type_code
3350 	, p_mark_as_original		=>	l_mark_as_original
3351 	, p_err_code             	=>	x_err_code
3352 	, p_err_stage         		=> 	x_err_stage
3353 	, p_err_stack			=>	x_err_stack
3354 	);
3355 
3356     IF (x_err_code <> 0)
3357     THEN
3358         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in gms_wf_pkg.start_budget_wf';
3359 	gms_error_pkg.gms_message(x_err_name => 'GMS_START_BUDG_WF_FAIL',
3360 				x_err_code => x_err_code,
3361 		 		x_err_buff => x_err_stage);
3362         fnd_msg_pub.add; -- Bug 2587078
3363 	APP_EXCEPTION.RAISE_EXCEPTION;
3364     END IF;
3365 
3366 	p_workflow_started		:= 'Y';
3367 
3368 -- NOTE: A commit is required to actually start/activate  the workflow instance opened
3369 -- by the previous Start_Budget_WF procedure.
3370 
3371 
3372 	IF FND_API.TO_BOOLEAN( p_commit )
3373     	THEN
3374 		COMMIT;
3375 	END IF;
3376 
3377         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Budget workflow started ';
3378 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_WF_STARTED',
3379 					x_token_name1 => 'AWARD_NUMBER',
3380 					x_token_val1 =>	l_award_number,
3381 					x_token_name2 => 'PROJECT_NUMBER',
3382 					x_token_val2 => l_project_number,
3383 					x_exec_type => 'C', -- for concurrent process
3384 					x_err_code => x_err_code,
3385 					x_err_buff => x_err_stage);
3386         fnd_msg_pub.add; --2587078
3387 	x_err_code := 0; -- setting x_err_code to zero since this is not an error condition.
3388 
3389 	--fnd_file.put_line(FND_FILE.OUTPUT, x_err_stage);
3390 	gms_error_pkg.gms_output(x_output => x_err_stage);
3391 
3392 ELSE -- WORKFLOW IS NOT ENABLED FOR THIS AWARD
3393 
3394       IF L_DEBUG = 'Y' THEN
3395 	 gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - l_funds_check_at_submit : '||l_funds_check_at_submit,'C');
3396       END IF;
3397 
3398       IF l_funds_check_at_submit = 'Y' THEN --Bug 2290959 : Perform fundscheck only if the profile 'GMS : Enable funds check for budget Submission' is set to Yes.
3399 
3400 -- CALLING THE FUNDSCHECK PROCESS ...
3401         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - In gms_budget_balance.update_gms_balance';
3402 	gms_budget_balance.update_gms_balance( x_project_id => l_project_id
3403 					     , x_award_id => l_award_id
3404 					     , x_mode => 'S'
3405 					     , ERRBUF => x_err_stage
3406 					     , RETCODE => l_fc_return_code);
3407 
3408 -- Redefining the savepoint because gms_budget_balance.update_gms_balance() clears the
3409 -- original savepoint by issuing commits within it.
3410 
3411 	SAVEPOINT baseline_budget_pub;
3412 
3413 	IF L_DEBUG = 'Y' THEN
3414 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - l_fc_return_code : '||l_fc_return_code, 'C');
3415 	END IF;
3416 
3417 
3418       END IF; --Bug 2290959
3419 
3420 	IF ((l_fc_return_code = 'S' AND l_funds_check_at_submit = 'Y') OR l_funds_check_at_submit = 'N' )THEN --Bug 2290959
3421 
3422         	IF L_DEBUG = 'Y' THEN
3423 		   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating Budget to Submitted status', 'C');
3424 	        END IF;
3425 
3426 		UPDATE 	gms_budget_versions
3427     		SET 	budget_status_code = 'S',
3428     			WF_status_code = NULL,
3429     			conc_request_id = l_conc_request_id,
3430     			current_original_flag = l_mark_as_original -- Added for Bug:1578992
3431     		WHERE budget_version_id = l_budget_version_id;
3432                 x_err_stage := NULL;
3433 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_SUBMITTED',
3434 					x_token_name1 => 'AWARD_NUMBER',
3435 					x_token_val1 =>	l_award_number,
3436 					x_token_name2 => 'PROJECT_NUMBER',
3437 					x_token_val2 => l_project_number,
3438 					x_exec_type => 'C', -- for concurrent process
3439 					x_err_code => x_err_code,
3440 					x_err_buff => x_err_stage);
3441 
3442 		x_err_code := 0; -- setting x_err_code to zero since this is not an error condition.
3443 
3444 		--fnd_file.put_line(FND_FILE.OUTPUT, x_err_stage);
3445 		gms_error_pkg.gms_output(x_output => x_err_stage);
3446 
3447 	ELSE
3448                 x_err_stage := NULL;
3449 		gms_error_pkg.gms_message(x_err_name => 'GMS_FC_FAIL_SUBMIT',
3450 					x_token_name1 => 'AWARD_NUMBER',
3451 					x_token_val1 => l_award_number,
3452 					x_token_name2 => 'PROJECT_NUMBER',
3453 					x_token_val2 => l_project_number,
3454 					x_exec_type => 'C', -- for concurrent process
3455 					x_err_code => x_err_code,
3456 			 		x_err_buff => x_err_stage);
3457 		-- Bug 3022766 : Introduced error code = 3 to represent fundscheck failure status
3458 		-- and commented below code.
3459 		--x_err_code := 0; -- Since we don't have to error out NOCOPY the Concurrent Process.
3460 		x_err_code := 3;
3461 
3462 		-- End of code changes done for bug 3022766
3463 
3464 		--fnd_file.put_line(FND_FILE.OUTPUT, x_err_stage);
3465 		gms_error_pkg.gms_output(x_output => x_err_stage);
3466 		rollback to baseline_budget_pub;
3467 
3468         	IF L_DEBUG = 'Y' THEN
3469 	           gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - End of Submit process', 'C');
3470                 END IF;
3471 		return;
3472 	END IF;
3473 
3474 END IF; -- (l_workflow_is_used = 'T' )
3475 IF L_DEBUG = 'Y' THEN
3476    gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - End of Submit process', 'C');
3477 END IF;
3478 ---------------------------------------------------------------------------------------
3479 ELSE -- Budget status is 'S', so Baseline the budget
3480 
3481         IF L_DEBUG = 'Y' THEN
3482           gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Start of Baseline process', 'C');
3483           gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_budget_core.baseline', 'C');
3484         END IF;
3485 	gms_budget_core.baseline ( x_draft_version_id 	=> l_budget_version_id
3486 				,x_mark_as_original	=> l_mark_as_original
3487 				,x_verify_budget_rules 	=> 'N'
3488 				,x_err_code		=> x_err_code
3489 				,x_err_stage		=> x_err_stage
3490 				,x_err_stack		=> x_err_stack		);
3491 
3492 		IF x_err_code <> 0
3493 		THEN
3494                         x_err_stage := 	'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in gms_budget_core.baseline';
3495 			gms_error_pkg.gms_message(x_err_name => 'GMS_BASELINE_FAILED',
3496 						x_err_code => x_err_code,
3497 				 		x_err_buff => x_err_stage);
3498                         fnd_msg_pub.add; -- Bug 2587078
3499 			APP_EXCEPTION.RAISE_EXCEPTION;
3500 		END IF;
3501 
3502 -- Bug 5162777 : Derive the the budget_version_id of the previously baselined budget before creating new BC records.
3503 ----------- DERIVING THE BUDGET_VERSION_ID OF THE PREVIOUSLY BASELINED BUDGET -----------------
3504 
3505 -- Bug 2386041
3506 	begin
3507 	-- First get the budget_version_id of the previously baselined budget. In case there is an error we need to set the current_flag
3508 	-- for this line to Y
3509 
3510               IF L_DEBUG = 'Y' THEN
3511 	          gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Fetching previous budget_version_id', 'C');
3512               END IF;
3513 
3514 
3515 	      select	bv.budget_version_id,
3516 	                bem.entry_level_code
3517 	        into    l_prev_baselined_version_id,
3518 		        l_prev_entry_level_code
3519 	        from    gms_budget_versions bv,
3520 		        pa_budget_entry_methods bem
3521 		where 	bv.award_id = l_award_id
3522 		and 	bv.project_id = l_project_id
3523 		and	bv.budget_type_code = p_budget_type_code
3524 		and 	bv.budget_status_code = 'B'
3525 		and 	bv.current_flag = 'R'
3526 		and     bv.budget_entry_method_code = bem.budget_entry_method_code;
3527 
3528 	     IF L_DEBUG = 'Y' THEN
3529 	          gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Fetched previous budget_version_id '||l_prev_baselined_version_id, 'C');
3530               END IF;
3531 
3532 
3533 	exception
3534 	when NO_DATA_FOUND then
3535               -- this means that there did not exist any baselined budget earlier
3536               l_prev_baselined_version_id := null;
3537 	      l_prev_entry_level_code := null;
3538               IF L_DEBUG = 'Y' THEN
3539 	          gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - There exists no baselined budget earlier', 'C');
3540               END IF;
3541 
3542 	when OTHERS then
3543            x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - While fetching previous version id, when others exception ';
3544            gms_error_pkg.gms_message( x_err_name => 'GMS_UNEXPECTED_ERROR',
3545 	 	   		      x_token_name1 => 'SQLCODE',
3546 	 			      x_token_val1 => sqlcode,
3547 	 			      x_token_name2 => 'SQLERRM',
3548 	 			      x_token_val2 => sqlerrm,
3549 	 			      x_err_code => x_err_code,
3550 	 			      x_err_buff => x_err_stage);
3551 
3552            fnd_msg_pub.add;
3553 	   APP_EXCEPTION.RAISE_EXCEPTION;
3554 	end;
3555        -- Bug 2386041
3556 
3557 ---------------------------------------------------------------------------------------------------------
3558 
3559 -- Bug 5162777 : The budgetary control records are created before invoking fundscheck process.
3560 ----------------------- START  OF BC RECORD CREATION -------------------------
3561 
3562 			gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_budg_cont_setup.bud_ctrl_create', 'C');
3563 			gms_budg_cont_setup.bud_ctrl_create(p_project_id => l_project_id
3564 							   ,p_award_id => l_award_id
3565 							   ,p_prev_entry_level_code => l_prev_entry_level_code
3566 							   ,p_entry_level_code => l_entry_level_code
3567 							   ,p_resource_list_id => l_resource_list_id
3568 							   ,p_group_resource_type_id => l_group_resource_type_id
3569 							   ,x_err_code => x_err_code
3570 							   ,x_err_stage => x_err_stage);
3571 
3572 			if x_err_code <> 0
3573 			then
3574                                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occurred in gms_budg_cont_setup.bud_ctrl_create';
3575 				gms_error_pkg.gms_message(x_err_name => 'GMS_BUDG_CONTROL_SETUP_FAIL',
3576 							x_err_code => x_err_code,
3577 			 				x_err_buff => x_err_stage);
3578 
3579 				SAVEPOINT baseline_budget_pub;
3580                                 fnd_msg_pub.add; -- Bug 2587078
3581 				APP_EXCEPTION.RAISE_EXCEPTION;
3582 				-- Bug 2386041
3583 			end if;
3584 ----------------------- END OF BC RECORD CREATION -------------------------
3585 
3586 -- CALLING THE FUNDSCHECK PROCESS ...
3587 	IF L_DEBUG = 'Y' THEN
3588 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_budget_balance.update_gms_balance','C');
3589 	END IF;
3590 
3591 	gms_budget_balance.update_gms_balance( x_project_id => l_project_id
3592 					     , x_award_id => l_award_id
3593 					     , x_mode => 'B'
3594 					     , ERRBUF => x_err_stage
3595 					     , RETCODE => l_fc_return_code);
3596 
3597 -- Redefining the savepoint because gms_budget_balance.update_gms_balance() clears the
3598 -- original savepoint by issuing commits within it.
3599 
3600 	SAVEPOINT baseline_budget_pub;
3601 
3602 	IF L_DEBUG = 'Y' THEN
3603 	   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - l_fc_return_code : '||l_fc_return_code, 'C');
3604 	END IF;
3605 
3606 	IF l_fc_return_code = 'S'
3607 	THEN  -- Funds check passed
3608 
3609 -- after calling BASELINE, set the budget_status_code back to 'W' (Working)
3610 -- the concept of submitting budget is not available in the public API's!
3611 
3612         	IF L_DEBUG = 'Y' THEN
3613 		  gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating Budget to Working status', 'C');
3614 	        END IF;
3615 
3616 		UPDATE gms_budget_versions
3617 		SET budget_status_code = 'W', conc_request_id = l_conc_request_id
3618 		WHERE budget_version_id = l_budget_version_id;
3619 
3620 -- 29-May-2000------------------------------------------------------------------------------------
3621 -- if Funds check (during baselining, only) was successful then we have to:
3622 -- 	1. set the current_flag = 'N' for the previously baselined budget (whose current_flag was set to 'R')
3623 -- 	2. set the current_flag = 'Y' for the newly created budget,
3624 -- 	3. Summarize the Project Budget and
3625 -- 	4. Run the default setup for Budgetary Control (if budget is baselined for the first time)
3626 --      5. call sweeper - added for Bug: 1666853
3627 -- 	6. call Workflow process to send notification
3628 --------------------------------------------------------------------------------------------------
3629 
3630 -- 	1. set the current_flag = 'N' for the previously baselined budget (whose current_flag was set to 'R' earlier)
3631 
3632                 IF L_DEBUG = 'Y' THEN
3633 	            gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current flag to N on previous baselined budget version', 'C');
3634                 END IF;
3635 
3636 		update 	gms_budget_versions
3637 		set 	current_flag = 'N'
3638 		where 	award_id = l_award_id
3639 		and 	project_id = l_project_id
3640 		and	budget_type_code = p_budget_type_code
3641 		and 	budget_status_code = 'B'
3642 		and 	current_flag = 'R';
3643 
3644 -- 	2. set the current_flag = 'Y' for the newly created budget.
3645 
3646 		-- Corrected the query for Bug:2542827
3647 
3648                 IF L_DEBUG = 'Y' THEN
3649 	            gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current flag to Y on newly created budget version', 'C');
3650                 END IF;
3651 
3652 		update 	gms_budget_versions
3653 		set	current_flag = 'Y'
3654 		where 	budget_version_id = (	select 	max(budget_version_id)
3655 						from 	gms_budget_versions
3656 						where 	award_id = l_award_id
3657 						and 	project_id = l_project_id
3658 						and 	budget_type_code = p_budget_type_code);
3659 
3660 --------------------------------------------------------------------------------------------------
3661         -- Bug 2386041
3662 	-- 	After updating the newly created budget we have to get the budget_version_id of this budget
3663 	-- 	which is going to be used by the Project Budget Summarization and Default Budgetary Control
3664 	--	Setup programs
3665 
3666 		begin
3667 			select 	budget_version_id
3668 			into 	l_baselined_version_id
3669 			from 	gms_budget_versions
3670 			where	award_id = l_award_id
3671 			and	project_id = l_project_id
3672 			and 	budget_type_code = p_budget_type_code
3673 			and	budget_status_code = 'B'
3674 			and	current_flag = 'Y';
3675 
3676                 IF L_DEBUG = 'Y' THEN
3677 	           gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - l_baselined_version_id '||l_baselined_version_id, 'C');
3678                 END IF;
3679 
3680 		exception
3681 		when OTHERS
3682 		then
3683                    x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - While fetching baselined version id, when others exception ';
3684 	           gms_error_pkg.gms_message( x_err_name => 'GMS_UNEXPECTED_ERROR',
3685 		 	   		      x_token_name1 => 'SQLCODE',
3686 	 				      x_token_val1 => sqlcode,
3687 	 				      x_token_name2 => 'SQLERRM',
3688 	 				      x_token_val2 => sqlerrm,
3689 		 			      x_err_code => x_err_code,
3690 		 			      x_err_buff => x_err_stage);
3691 
3692 	           fnd_msg_pub.add;
3693 		   APP_EXCEPTION.RAISE_EXCEPTION;
3694 		end;
3695 
3696 -- Bug 2587078 :The Project budget summarization code is shifted after call to sweeper process .
3697 
3698 -- 	3. The Budgetary Control records are created before the fundscheck process is invoked.
3699 
3700 
3701 --      4. call gms_sweeper - added for Bug: 1666853
3702 
3703 		IF L_DEBUG = 'Y' THEN
3704 			gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_sweeper.upd_act_enc_bal', 'C');
3705 		END IF;
3706 
3707 
3708 	        -- get the packet id for the budget and pass it on to the sweeper process.
3709 	        -- locking issue addressed as the scope of locking is limited to the packet.
3710     	        -- if there are no transactions then no point calling sweeper process. We'll skip it.
3711 	        -- Bug : 2821482.
3712 
3713                 begin
3714                   select distinct packet_id
3715                     into l_packet_id
3716                     from gms_bc_packets
3717                    where budget_version_id = l_baselined_version_id;
3718                 exception
3719                   -- no data will be found if there are no transactions.
3720                   when no_data_found then
3721                     l_packet_id := null;
3722                 end;
3723 	        -- end bug 2821482 changes.
3724 
3725       		if l_packet_id is not null then --> call sweeper if txns exist..bug 2821482.
3726 
3727 		gms_sweeper.upd_act_enc_bal(errbuf => x_err_stage,
3728 					retcode => x_err_code,
3729 					x_mode => 'B',
3730                                         x_packet_id => l_packet_id,  --> bug 2821482
3731 					x_project_id => l_project_id,
3732 					x_award_id => l_award_id);
3733 
3734 		if x_err_code <> 0 then -- Changed from 'S' to 0 (zero) for Bug:2464800
3735                         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occurred in gms_sweeper.upd_act_enc_bal';
3736 			gms_error_pkg.gms_message(x_err_name => 'GMS_BU_SWEEP_FAILED',
3737 					x_err_code => x_err_code,
3738 	 				x_err_buff => x_err_stage);
3739 
3740  			IF L_DEBUG = 'Y' THEN
3741          		   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current flag to Y on previous baselined budget version', 'C');
3742 			END IF;
3743 
3744 	 		-- Bug 2386041
3745 	 		update 	gms_budget_versions
3746 			set 	current_flag = 'Y'
3747 			where 	budget_version_id = l_prev_baselined_version_id;
3748 
3749 		        IF L_DEBUG = 'Y' THEN
3750        			   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current flag to N on newly baselined budget version id', 'C');
3751 		        END IF;
3752 
3753 			update 	gms_budget_versions
3754 			set 	current_flag = 'N'
3755 			where 	budget_version_id = l_baselined_version_id;
3756 
3757 		        IF L_DEBUG = 'Y' THEN
3758        			   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating budget to submitted status', 'C');
3759      	                END IF;
3760 
3761 			UPDATE gms_budget_versions
3762 			SET budget_status_code = 'S'
3763 			WHERE budget_version_id = l_budget_version_id;
3764 
3765 			commit;
3766 			SAVEPOINT baseline_budget_pub;
3767                         fnd_msg_pub.add; -- Bug 2587078
3768 			APP_EXCEPTION.RAISE_EXCEPTION;
3769 			-- Bug 2386041
3770 		end if;
3771 
3772       		end if; -- l_packet_id not null. Bug 2821482
3773 
3774 -- Bug 2587078 :The Project budget summarization code is shifted here so that project budget summarization
3775 --              is done after Award budget baselining process is completed successfully.
3776 
3777          -- Bug 2386041
3778 
3779 -- 	5. Summarize the Project Budget.
3780 
3781 		IF L_DEBUG = 'Y' THEN
3782 		   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Start of Project Budget Summarization ', 'C');
3783 		END IF;
3784 
3785 		-- Bug 2386041
3786 		    l_user_profile_value1 := fnd_profile.value_specific('PA_SUPER_PROJECT', fnd_global.user_id, fnd_global.resp_id, fnd_global.resp_appl_id);
3787                 if ((l_user_profile_value1 = 'N') OR  (l_user_profile_value1 is null)) then
3788 
3789                    BEGIN
3790 
3791                       SELECT profile_option_value
3792                       INTO   l_user_profile_value1
3793                       FROM   fnd_profile_options       p,
3794                              fnd_profile_option_values v
3795                       WHERE  p.profile_option_name = 'PA_SUPER_PROJECT'
3796                       AND    v.profile_option_id = p.profile_option_id
3797                       AND    v.level_id = 10004
3798                       AND    v.level_value = fnd_global.user_id;
3799 
3800                    EXCEPTION
3801 
3802                       WHEN no_data_found THEN
3803                          l_user_profile_value1 := null;
3804 
3805                       WHEN others THEN
3806                          l_user_profile_value1 := null;
3807 
3808                    END;
3809 
3810                    l_set_profile_success1 :=  fnd_profile.save('PA_SUPER_PROJECT', 'Y', 'USER', fnd_global.user_id);
3811                 end if;
3812 
3813                 l_user_profile_value2 := fnd_profile.value_specific('PA_SUPER_PROJECT_VIEW', fnd_global.user_id, fnd_global.resp_id, fnd_global.resp_appl_id);
3814                 if ((l_user_profile_value2 = 'N') OR  (l_user_profile_value2 is null)) then
3815 
3816                    BEGIN
3817 
3818                       SELECT profile_option_value
3819                       INTO   l_user_profile_value2
3820                       FROM   fnd_profile_options       p,
3821                              fnd_profile_option_values v
3822                       WHERE  p.profile_option_name = 'PA_SUPER_PROJECT_VIEW'
3823                       AND    v.profile_option_id = p.profile_option_id
3824                       AND    v.level_id = 10004
3825                       AND    v.level_value = fnd_global.user_id;
3826 
3827                    EXCEPTION
3828 
3829                       WHEN no_data_found THEN
3830                          l_user_profile_value2 := null;
3831 
3832                       WHEN others THEN
3833                          l_user_profile_value2 := null;
3834 
3835                    END;
3836 
3837                    l_set_profile_success2 :=  fnd_profile.save('PA_SUPER_PROJECT_VIEW', 'Y', 'USER', fnd_global.user_id);
3838 
3839                 end if;
3840 
3841 
3842 		IF L_DEBUG = 'Y' THEN
3843   		    gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_summarize_budgets.summarize_baselined_versions', 'C');
3844 		END IF;
3845 
3846 	        -- Bug 2386041
3847 		gms_summarize_budgets.summarize_baselined_versions( x_project_id => l_project_id
3848 								  , x_time_phased_type_code => l_time_phased_type_code
3849 								  , x_app_short_name => l_app_short_name
3850 								  , RETCODE => l_return_status
3851 								  , ERRBUF => x_err_stage);
3852 
3853 		-- Bug 2386041
3854 	         if (l_set_profile_success1 = TRUE) then
3855                      l_set_profile_success1 :=  fnd_profile.save('PA_SUPER_PROJECT', l_user_profile_value1, 'USER', fnd_global.user_id);
3856                  end if;
3857                  if (l_set_profile_success2 = TRUE) then
3858                      l_set_profile_success2 :=  fnd_profile.save('PA_SUPER_PROJECT_VIEW', l_user_profile_value2, 'USER', fnd_global.user_id);
3859                  end if;
3860 	        -- Bug 2386041
3861 
3862                 -- Fix for bug : 5511910. We retrun stasus values as 'P' if summarization does not happen.
3863 		--IF l_return_status <> 'S'
3864                   IF l_return_status  NOT in ( 'S','X') THEN
3865 
3866        	                x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occured in gms_summarize_budgets.summarize_baselined_versions';
3867 			gms_error_pkg.gms_message(x_err_name => 'GMS_SUMMARIZE_PA_BUDG_FAIL',
3868 						x_err_code => x_err_code,
3869 		 				x_err_buff => x_err_stage);
3870 
3871  			IF L_DEBUG = 'Y' THEN
3872          		   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current flag to Y on previous baselined budget version', 'C');
3873 			END IF;
3874 
3875 		 	-- Bug 2386041
3876 			update 	gms_budget_versions
3877 			set 	current_flag = 'Y'
3878 			where 	budget_version_id = l_prev_baselined_version_id;
3879 
3880 		        IF L_DEBUG = 'Y' THEN
3881        			   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current flag to N on newly baselined budget version id', 'C');
3882 		        END IF;
3883 
3884 			update 	gms_budget_versions
3885 			set 	current_flag = 'N'
3886 			where 	budget_version_id = l_baselined_version_id;
3887 
3888 		        IF L_DEBUG = 'Y' THEN
3889        			   gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating budget to submitted status', 'C');
3890      	                END IF;
3891 
3892 			UPDATE gms_budget_versions
3893 			SET budget_status_code = 'S'
3894 			WHERE budget_version_id = l_budget_version_id;
3895 
3896 			commit;
3897 			SAVEPOINT baseline_budget_pub;
3898                         fnd_msg_pub.add; -- Bug 2587078
3899 			APP_EXCEPTION.RAISE_EXCEPTION;
3900 			-- Bug 2386041
3901 
3902 		END IF;
3903 
3904 -- 	6. call Workflow process to send notification
3905 
3906 	IF L_DEBUG = 'Y' THEN
3907 		gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET -Sending workflow notifictaion', 'C');
3908 	END IF;
3909 
3910         open l_wf_notif_role_csr (p_award_id => l_award_id);
3911 	fetch l_wf_notif_role_csr into l_row_found;
3912 
3913         /*Added for bug 5620089*/
3914         open l_wf_enabled_csr (p_award_id => l_award_id);
3915         fetch l_wf_enabled_csr into l_wf_enabled_flag;
3916         /*End of fix for bug 5620089*/
3917 
3918         if l_wf_notif_role_csr%FOUND AND l_wf_enabled_flag = 'Y' then --One more condition added for bug 5620089
3919 
3920 		IF L_DEBUG = 'Y' THEN
3921 			gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Calling gms_wf_pkg.start_budget_wf_ntfy_only', 'C');
3922 		END IF;
3923 
3924      		GMS_WF_PKG.Start_Budget_Wf_Ntfy_Only
3925 		( p_draft_version_id		=> 	l_budget_version_id
3926 		, p_project_id			=>	l_project_id
3927 		, p_award_id			=>	l_award_id
3928 		, p_budget_type_code		=>	p_budget_type_code
3929 		, p_mark_as_original		=>	l_mark_as_original
3930 		, p_err_code             	=>	x_err_code
3931 		, p_err_stage         		=> 	x_err_stage
3932 		, p_err_stack			=>	x_err_stack);
3933 
3934 		if (x_err_code <> 0) then
3935                         x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Error occurred in gms_wf_pkg.start_budget_wf_ntfy_only' ;
3936 			gms_error_pkg.gms_message(x_err_name => 'GMS_BU_WF_NTFY_FAIL', -- 'GMS_NTFY_BUDG_WF_FAIL', Bug 2587078
3937 					x_err_code => x_err_code,
3938 		 			x_err_buff => x_err_stage,
3939 					x_exec_type => 'C');
3940 			x_err_code := 4; -- to show a WARNING in the concurrent request window.
3941 
3942 			--fnd_file.put_line(FND_FILE.OUTPUT, x_err_stage);
3943 			gms_error_pkg.gms_output(x_output => x_err_stage);
3944 			return;
3945 
3946 			-- We don't have to stop the baseline process if the WF Notification process fails.
3947 			-- APP_EXCEPTION.RAISE_EXCEPTION;
3948 		end if;
3949 
3950 	end if;
3951 
3952 	close l_wf_notif_role_csr;
3953 
3954 --------------------------------------------- ----------------------------------------------------------------------------------
3955 -- GMS enhancement for R12 : 5583170
3956 gms_error_pkg.gms_debug('GMS_SUMMARIZE_BUDGETS.SUMMARIZE_BASELINED_VERSIONS - l_return_status IS  ==== : '|| l_return_status,'C');
3957               If l_return_status  = 'S' then
3958                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Baselining successful ' ;
3959 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_BASELINED',
3960 					x_token_name1 => 'PROJECT_NUMBER',
3961 					x_token_val1 => l_project_number,
3962 					x_exec_type => 'C', -- for concurrent process
3963 					x_err_code => x_err_code,
3964 					x_err_buff => x_err_stage);
3965 
3966 		x_err_code := 0; -- setting x_err_code to zero since this is not an error condition.
3967                 gms_error_pkg.gms_output(x_output => x_err_stage);
3968                 end if ;
3969 
3970                if l_return_status = 'X' then -- fix for bug : 5511910
3971                          gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_BASELINED_ONLY',
3972                                         x_exec_type => 'C', -- for concurrent process
3973                                         x_err_code => x_err_code,
3974                                         x_err_buff => x_err_stage);
3975 
3976 		x_err_code := 0; -- setting x_err_code to zero since this is not an error condition.
3977 		gms_error_pkg.gms_output(x_output => x_err_stage);
3978 
3979                end if;
3980 --   end of GMS enhancement
3981 
3982 
3983 -- The following ELSIF condition for (l_fc_return_code = 'F') is added for Bug: 2510024
3984 
3985 	ELSIF l_fc_return_code = 'F' then 	-- l_fc_return_code = 'F' - Funds check Failed
3986 
3987 -- 	since Funds check failed the previously baselined budget (whose current_flag was set to 'R' earlier) has to be restored
3988 
3989 		IF L_DEBUG = 'Y' THEN
3990 			gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current_flag to Y on previously baselined budget', 'C');
3991 		END IF;
3992 
3993 		update 	gms_budget_versions
3994 		set 	current_flag = 'Y'
3995 		where 	award_id = l_award_id
3996 		and 	project_id = l_project_id
3997 		and	budget_type_code = p_budget_type_code
3998 		and 	budget_status_code = 'B'
3999 		and 	current_flag = 'R';
4000 
4001 --	The above update should be committed explicitly since the following error handling routine will rollback.
4002 
4003 		commit;
4004 
4005 -- 	Redefining the savepoint since the above commit will clear all previously defined savepoints
4006 
4007 		SAVEPOINT baseline_budget_pub;
4008 		x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET - Fundscheck failed' ;
4009 		gms_error_pkg.gms_message(x_err_name => 'GMS_FC_FAIL_BASELINE',
4010 					x_token_name1 => 'AWARD_NUMBER',
4011 					x_token_val1 => l_award_number,
4012 					x_token_name2 => 'PROJECT_NUMBER',
4013 					x_token_val2 => l_project_number,
4014 					x_exec_type => 'C', -- for concurrent process
4015 					x_err_code => x_err_code,
4016 			 		x_err_buff => x_err_stage);
4017                 fnd_msg_pub.add; -- Bug 2587078
4018 		--fnd_file.put_line(FND_FILE.OUTPUT, x_err_stage);
4019 		gms_error_pkg.gms_output(x_output => x_err_stage);
4020 
4021 		-- Bug 3022766 : Introduced error code = 3 to represent fundscheck failure status
4022 		-- and commented below code.
4023 		--x_err_code := 0; -- Since we don't have to error out NOCOPY the Concurrent Process.
4024 		x_err_code := 3;
4025 
4026 		-- End of code changes done for bug 3022766
4027 
4028 		rollback to baseline_budget_pub;
4029 		return;
4030 
4031         ELSE -- l_fc_return_code = 'H' or 'L'  - Unexpected Error Occured
4032 
4033 		IF L_DEBUG = 'Y' THEN
4034 			gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - Updating current_flag to Y on previously baselined budget', 'C');
4035 		END IF;
4036 
4037 --      since Funds check failed the previously baselined budget (whose current_flag was set to 'R' earlier) has to be restored
4038 
4039                 update  gms_budget_versions
4040                 set     current_flag = 'Y'
4041                 where   award_id = l_award_id
4042                 and     project_id = l_project_id
4043                 and     budget_type_code = p_budget_type_code
4044                 and     budget_status_code = 'B'
4045                 and     current_flag = 'R';
4046 
4047 --      The above update should be committed explicitly since the following error handling routine will rollback.
4048 
4049                 commit;
4050 
4051 --      Redefining the savepoint since the above commit will clear all previously defined savepoints
4052 
4053                 SAVEPOINT baseline_budget_pub;
4054                 x_err_stage := 'GMS_BUDGET_PUB.BASELINE_BUDGET -Unexpected error' ;
4055 	        gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
4056                                 x_token_name1 => 'SQLCODE',
4057                                 x_token_val1 => sqlcode,
4058                                 x_token_name2 => 'SQLERRM',
4059                                 x_token_val2 => sqlerrm,
4060                                 x_err_code => x_err_code,
4061                                 x_err_buff => x_err_stage);
4062                 fnd_msg_pub.add; -- Bug 2587078
4063                 --fnd_file.put_line(FND_FILE.OUTPUT, x_err_stage);
4064                 gms_error_pkg.gms_output(x_output => x_err_stage);
4065 
4066                 rollback to baseline_budget_pub;
4067                 return;
4068 
4069 	END IF;
4070 
4071 	IF L_DEBUG = 'Y' THEN
4072 	    gms_error_pkg.gms_debug('GMS_BUDGET_PUB.BASELINE_BUDGET - End of Baseline process', 'C');
4073 	END IF;
4074 
4075 END IF; -- <l_budget_status_code = 'W'>
4076 
4077 IF L_DEBUG = 'Y' THEN
4078     gms_error_pkg.gms_debug('*** End of GMS_BUDGET_PUB.BASELINE_BUDGET ***','C');
4079 END IF;
4080 
4081 EXCEPTION
4082 	WHEN OTHERS
4083 	THEN
4084 	        x_err_stage :='GMS_BUDGET_PUB.BASELINE_BUDGET - In when others exception';
4085 
4086 	        gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_FAILED', -- Bug 2587078
4087                                 x_err_code => x_err_code,
4088                                 x_err_buff => x_err_stage);
4089                 fnd_msg_pub.add;
4090 		ROLLBACK TO baseline_budget_pub;
4091 		RAISE;
4092 
4093 END baseline_budget;
4094 
4095 ----------------------------------------------------------------------------------------
4096 --Name:               add_budget_line
4097 --Type:               Procedure
4098 --Description:        This procedure can be used to add a budgetline to an
4099 --                    existing WORKING budget.
4100 --
4101 --Called subprograms:
4102 --			gms_budget_utils.check_overlapping_dates()
4103 --			gms_budget_pub.summerize_project_totals()
4104 --
4105 --
4106 --
4107 --History:
4108 --
4109 
4110 PROCEDURE add_budget_line
4111 ( p_api_version_number		IN	NUMBER
4112  ,x_err_code			IN OUT NOCOPY	NUMBER
4113  ,x_err_stage			IN OUT NOCOPY	VARCHAR2
4114  ,x_err_stack			IN OUT NOCOPY	VARCHAR2
4115  ,p_commit			IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
4116  ,p_init_msg_list		IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
4117  ,p_pm_product_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4118  ,p_project_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4119  ,p_project_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4120  ,p_award_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4121  ,p_award_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4122  ,p_budget_type_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4123  ,p_task_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4124  ,p_task_number			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4125  ,p_resource_alias		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4126  ,p_resource_list_member_id	IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4127  ,p_budget_start_date		IN	DATE			:= GMS_BUDGET_PUB.G_PA_MISS_DATE
4128  ,p_budget_end_date		IN	DATE			:= GMS_BUDGET_PUB.G_PA_MISS_DATE
4129  ,p_period_name			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4130  ,p_description			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4131  ,p_change_reason_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4132  ,p_raw_cost			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4133  ,p_burdened_cost		IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4134  ,p_quantity			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
4135  ,p_unit_of_measure		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4136  ,p_track_as_labor_flag		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4137  ,p_pm_budget_line_reference	IN      VARCHAR2                := GMS_BUDGET_PUB.G_PA_MISS_CHAR
4138  ,p_attribute_category		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4139  ,p_attribute1			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4140  ,p_attribute2			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4141  ,p_attribute3			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4142  ,p_attribute4			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4143  ,p_attribute5			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4144  ,p_attribute6			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4145  ,p_attribute7			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4146  ,p_attribute8			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4147  ,p_attribute9			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4148  ,p_attribute10			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4149  ,p_attribute11			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4150  ,p_attribute12			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4151  ,p_attribute13			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4152  ,p_attribute14			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4153  ,p_attribute15			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4154  ,p_raw_cost_source		IN 	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4155  ,p_burdened_cost_source	IN 	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4156  ,p_quantity_source		IN 	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
4157  )
4158 IS
4159 
4160 
4161    -- needed to get the fields associated to a budget entry method
4162 
4163    CURSOR	l_budget_entry_method_csr
4164    		(p_budget_entry_method_code pa_budget_entry_methods.budget_entry_method_code%type )
4165    IS
4166    SELECT *
4167    FROM   pa_budget_entry_methods
4168    WHERE  budget_entry_method_code = p_budget_entry_method_code
4169    AND 	  trunc(sysdate) BETWEEN trunc(start_date_active) and trunc(nvl(end_date_active,sysdate));
4170 
4171    -- needed to get budget_type_code and award_id based on the budget_version_id
4172 
4173    CURSOR l_budget_version_csr (p_project_id 	NUMBER
4174    				,p_award_id 	NUMBER
4175    				,p_budget_type_code	VARCHAR2)
4176    IS
4177    SELECT budget_version_id, budget_entry_method_code, resource_list_id
4178    FROM gms_budget_versions
4179    WHERE project_id = p_project_id
4180    AND award_id = p_award_id
4181    AND budget_status_code = 'W';
4182 
4183 
4184    -- needed to do validation on mandatory fields for budget lines
4185 
4186    CURSOR	l_budget_amount_code_csr
4187    		( p_budget_type_code	VARCHAR2 )
4188    IS
4189    SELECT budget_amount_code
4190    FROM	  pa_budget_types
4191    WHERE  budget_type_code = p_budget_type_code;
4192 
4193 -----------------
4194 
4195    l_api_name			CONSTANT	VARCHAR2(30) 		:= 'add_budget_line';
4196    i						NUMBER;
4197 
4198    l_award_id					NUMBER;
4199    l_project_id					NUMBER;
4200    l_task_id					NUMBER;
4201    l_budget_version_id				NUMBER;
4202    l_return_status_task				NUMBER;
4203    l_budget_entry_method_code			VARCHAR2(30);
4204    l_resource_list_id				NUMBER;
4205    l_period_name				VARCHAR2(20);
4206    l_budget_start_date				DATE;
4207    l_budget_end_date				DATE;
4208    l_resource_assignment_id			NUMBER;
4209    l_member_id					NUMBER;
4210 ---------------
4211    l_description				VARCHAR2(255);
4212    l_quantity					NUMBER;
4213    l_raw_cost					NUMBER;
4214    l_burdened_cost				NUMBER;
4215    l_unit_of_measure				VARCHAR2(30);
4216    l_track_as_labor_flag			VARCHAR2(1);
4217    l_attribute_category				VARCHAR2(30);
4218    l_attribute1					VARCHAR2(150);
4219    l_attribute2					VARCHAR2(150);
4220    l_attribute3					VARCHAR2(150);
4221    l_attribute4					VARCHAR2(150);
4222    l_attribute5					VARCHAR2(150);
4223    l_attribute6					VARCHAR2(150);
4224    l_attribute7					VARCHAR2(150);
4225    l_attribute8					VARCHAR2(150);
4226    l_attribute9					VARCHAR2(150);
4227    l_attribute10				VARCHAR2(150);
4228    l_attribute11				VARCHAR2(150);
4229    l_attribute12				VARCHAR2(150);
4230    l_attribute13				VARCHAR2(150);
4231    l_attribute14				VARCHAR2(150);
4232    l_attribute15				VARCHAR2(150);
4233 ---------------
4234    l_budget_entry_method_rec			pa_budget_entry_methods%rowtype;
4235    l_budget_amount_code				pa_budget_types.budget_amount_code%type;
4236    l_resource_name				pa_resource_list_members.alias%type;   /*Changed for bug 4614242*/
4237    l_function_allowed				VARCHAR2(1);
4238    l_resp_id					NUMBER := 0;
4239    l_user_id		                        NUMBER := 0;
4240    l_login_id					NUMBER := 0;
4241    l_module_name                                VARCHAR2(80);
4242    l_old_stack					VARCHAR2(630);
4243 
4244 BEGIN
4245 
4246 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - start');
4247 
4248 	x_err_code := 0;
4249 	l_old_stack := x_err_stack;
4250 	x_err_stack := x_err_stack ||'-> Add_Budget_Line';
4251 
4252     --	Initialize the message table if requested.
4253 
4254     IF FND_API.TO_BOOLEAN( p_init_msg_list )
4255     THEN
4256 
4257 	FND_MSG_PUB.initialize;
4258 
4259     END IF;
4260 
4261 --  Standard begin of API savepoint
4262 
4263     SAVEPOINT add_budget_line_pub;
4264 
4265 
4266 --  Standard call to check for call compatibility.
4267 
4268     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
4269     	    	    	    	    	 p_api_version_number	,
4270     	    	    	    	    	 l_api_name 	    	,
4271     	    	    	    	    	 G_PKG_NAME 	    	)
4272     THEN
4273 
4274 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
4275 				x_err_code => x_err_code,
4276 				x_err_buff => x_err_stage);
4277 
4278 	APP_EXCEPTION.RAISE_EXCEPTION;
4279 
4280     END IF;
4281 
4282     l_resp_id := FND_GLOBAL.Resp_id;
4283     l_user_id := FND_GLOBAL.User_id;
4284     l_login_id := FND_GLOBAL.Login_id;
4285     l_module_name := 'GMS_PM_ADD_BUDGET_LINE';
4286 
4287     -- As part of enforcing award security, which would determine
4288     -- whether the user has the necessary privileges to update the award
4289     -- need to call the gms_security package
4290     -- If a user does not have privileges to update the award, then
4291     -- cannot add a budget line
4292 
4293     gms_security.initialize (X_user_id        => l_user_id,
4294                             X_calling_module => l_module_name);
4295 
4296 
4297 --CHECK FOR MANDATORY FIELDS and CONVERT VALUES to ID's
4298 
4299     --product_code is mandatory
4300 
4301     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4302     OR p_pm_product_code IS NULL
4303     THEN
4304 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_MISSING',
4305 				x_err_code => x_err_code,
4306 				x_err_buff => x_err_stage);
4307 
4308 	APP_EXCEPTION.RAISE_EXCEPTION;
4309    END IF;
4310 ----------------------------------------------------------------------------
4311 -- If award_id is passed in then use it otherwise use the award_number
4312 -- that is passed in to fetch value of award_id from gms_awards table
4313 -- If both are missing then raise an error.
4314 
4315     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
4316         AND p_award_number IS NOT NULL)
4317     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
4318         AND p_award_id IS NOT NULL)
4319     THEN
4320    	convert_awardnum_to_id(p_award_number_in => p_award_number
4321    	                      ,p_award_id_in => p_award_id
4322    			      ,p_award_id_out => l_award_id
4323    			      ,x_err_code => x_err_code
4324    			      ,x_err_stage => x_err_stage
4325    			      ,x_err_stack => x_err_stack);
4326 
4327    	IF x_err_code <> 0
4328 	THEN
4329 		return;
4330 	END IF;
4331     ELSE
4332 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
4333 				x_err_code => x_err_code,
4334 				x_err_buff => x_err_stage);
4335 
4336 	APP_EXCEPTION.RAISE_EXCEPTION;
4337    END IF;
4338 --------------------------------------------------------------------------------
4339 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after award info validation');
4340 
4341 -- If project_id is passed in then use it otherwise use the project_number
4342 -- (segment1) that is passed in to fetch value of project_id from pa_projects
4343 -- table. If both are missing then raise an error.
4344 
4345 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
4346         AND p_project_number IS NOT NULL)
4347     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
4348         AND p_project_id IS NOT NULL)
4349    	THEN
4350    		convert_projnum_to_id(p_project_number_in => p_project_number
4351    		                      ,p_project_id_in => p_project_id
4352    				      ,p_project_id_out => l_project_id
4353    				      ,x_err_code => x_err_code
4354    				      ,x_err_stage => x_err_stage
4355    				      ,x_err_stack => x_err_stack);
4356 
4357 	   	IF x_err_code <> 0
4358     		THEN
4359 			return;
4360     		END IF;
4361 
4362 	ELSE
4363 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_NUM_ID_MISSING',
4364 					x_err_code => x_err_code,
4365 					x_err_buff => x_err_stage);
4366 
4367 		APP_EXCEPTION.RAISE_EXCEPTION;
4368 	END IF;
4369 
4370 -------------------------------------------------------------------------------
4371 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after project info validation');
4372 
4373      IF l_project_id IS NULL
4374      THEN
4375 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJECT_IS_MISSING',
4376 					x_err_code => x_err_code,
4377 					x_err_buff => x_err_stage);
4378 
4379 		APP_EXCEPTION.RAISE_EXCEPTION;
4380      END IF;
4381 
4382       -- Now verify whether award security allows the user to update
4383       -- the award
4384       -- If a user does not have privileges to update the award, then
4385       -- cannot add a budget line
4386 
4387 	IF gms_security.allow_query (x_award_id => l_award_id ) = 'N' THEN
4388 
4389          -- The user does not have query privileges on this award
4390          -- Hence, cannot update the award. Raise error
4391 
4392 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_QRY',
4393 					x_err_code => x_err_code,
4394 					x_err_buff => x_err_stage);
4395 
4396 		APP_EXCEPTION.RAISE_EXCEPTION;
4397 
4398       ELSE
4399             -- If the user has query privileges, then check whether
4400             -- update privileges are also available
4401          IF gms_security.allow_update (x_award_id => l_award_id ) = 'N' THEN
4402 
4403             -- The user does not have update privileges on this award
4404             -- Hence , raise error
4405 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_UPD',
4406 					x_err_code => x_err_code,
4407 					x_err_buff => x_err_stage);
4408 
4409 		APP_EXCEPTION.RAISE_EXCEPTION;
4410         END IF;
4411      END IF;
4412 
4413 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after award security validation');
4414 
4415  -- budget type code is mandatory
4416 
4417      IF p_budget_type_code IS NULL
4418      THEN
4419 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_MISSING',
4420 				x_err_code => x_err_code,
4421 				x_err_buff => x_err_stage);
4422 
4423 	APP_EXCEPTION.RAISE_EXCEPTION;
4424      ELSE
4425      		OPEN l_budget_amount_code_csr( p_budget_type_code );
4426 
4427 		FETCH l_budget_amount_code_csr
4428 		INTO l_budget_amount_code;     		--will be used later on during validation of Budget lines.
4429 
4430 		IF l_budget_amount_code_csr%NOTFOUND
4431 		THEN
4432 			CLOSE l_budget_amount_code_csr;
4433 			gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_INVALID',
4434 						x_err_code => x_err_code,
4435 						x_err_buff => x_err_stage);
4436 
4437 			APP_EXCEPTION.RAISE_EXCEPTION;
4438 		END IF;
4439 
4440 		CLOSE l_budget_amount_code_csr;
4441 
4442      END IF;
4443 
4444 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after budget_amount_code_csr');
4445 
4446  -- Get the budget_version, budget_entry_method_code and resource_list_id from table gms_budget_versions
4447 
4448     OPEN l_budget_version_csr(l_project_id, l_award_id, p_budget_type_code);
4449     FETCH l_budget_version_csr
4450     INTO  l_budget_version_id
4451     ,     l_budget_entry_method_code
4452     ,     l_resource_list_id;
4453 
4454     IF l_budget_version_csr%NOTFOUND
4455     THEN
4456 	CLOSE l_budget_version_csr;
4457 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_VERSION',
4458 				x_err_code => x_err_code,
4459 				x_err_buff => x_err_stage);
4460 
4461 	APP_EXCEPTION.RAISE_EXCEPTION;
4462     END IF;
4463 
4464     CLOSE l_budget_version_csr;
4465 
4466 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after budget_version_csr');
4467 
4468 -- entry method code is mandatory (and a nullible field in table gms_budget_versions)
4469 
4470      IF l_budget_entry_method_code IS NULL
4471      THEN
4472 	gms_error_pkg.gms_message(x_err_name => 'GMS_ENTRY_METHOD_IS_MISSING',
4473 				x_err_code => x_err_code,
4474 				x_err_buff => x_err_stage);
4475 
4476 	APP_EXCEPTION.RAISE_EXCEPTION;
4477      END IF;
4478 
4479  -- check validity of this budget entry method code, and store associated fields in record
4480 
4481     OPEN l_budget_entry_method_csr(l_budget_entry_method_code);
4482     FETCH l_budget_entry_method_csr INTO l_budget_entry_method_rec;
4483 
4484     IF   l_budget_entry_method_csr%NOTFOUND
4485     THEN
4486 	CLOSE l_budget_entry_method_csr;
4487 	gms_error_pkg.gms_message(x_err_name => 'GMS_ENTRY_METHOD_IS_INVALID',
4488 				x_err_code => x_err_code,
4489 				x_err_buff => x_err_stage);
4490 
4491 	APP_EXCEPTION.RAISE_EXCEPTION;
4492     END IF;
4493 
4494     CLOSE l_budget_entry_method_csr;
4495 
4496 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after budget_entry_method_csr');
4497 
4498 -- if both task id and reference are NULL or not passed, we will assume that budgetting is
4499 -- done at the project level and that requires l_task_id to be '0'
4500 -- if budgeting at the project level,then ignore all tasks
4501 
4502 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - entry_lvl_code = '||l_budget_entry_method_rec.entry_level_code);
4503 
4504         IF l_budget_entry_method_rec.entry_level_code = 'P' THEN
4505            l_task_id := 0;
4506         END IF;
4507 
4508 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - before convert_tasknum_to_id = '||to_char(l_project_id));
4509 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - before convert_tasknum_to_id = '||to_char(p_task_id));
4510 
4511         IF l_budget_entry_method_rec.entry_level_code in ('T','L','M')
4512         THEN
4513 		convert_tasknum_to_id ( p_project_id_in => l_project_id
4514 				,p_task_id_in => p_task_id
4515 				,p_task_number_in => p_task_number
4516 				,p_task_id_out => l_task_id
4517 				,x_err_code => x_err_code
4518 				,x_err_stage => x_err_stage
4519 				,x_err_stack => x_err_stack);
4520 
4521 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after convert_tasknum_to_id = '||to_char(l_task_id));
4522 
4523 		IF x_err_code <> 0
4524 		THEN
4525 			gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_TASK_NUMBER',
4526 						x_err_code => x_err_code,
4527 						x_err_buff => x_err_stage);
4528 
4529 			APP_EXCEPTION.RAISE_EXCEPTION;
4530 		END IF;
4531 
4532    	END IF;
4533 
4534 	IF l_budget_entry_method_rec.entry_level_code = 'T' THEN -- then check whether it is top task
4535 
4536 	   IF l_task_id <> pa_task_utils.get_top_task_id( l_task_id ) THEN
4537 		gms_error_pkg.gms_message(x_err_name => 'GMS_TASK_IS_NOT_TOP',
4538 					x_err_code => x_err_code,
4539 					x_err_buff => x_err_stage);
4540 
4541 		APP_EXCEPTION.RAISE_EXCEPTION;
4542 	   END IF;
4543 
4544 	ELSIF l_budget_entry_method_rec.entry_level_code = 'L' -- then check whether it is lowest task
4545 	  THEN
4546 	    pa_tasks_pkg.verify_lowest_level_task( l_return_status_task,
4547 						   l_task_id);
4548 		IF l_return_status_task <> 0 THEN
4549 			gms_error_pkg.gms_message(x_err_name => 'GMS_TASK_IS_NOT_LOWEST',
4550 						x_err_code => x_err_code,
4551 						x_err_buff => x_err_stage);
4552 
4553 			APP_EXCEPTION.RAISE_EXCEPTION;
4554 		END IF;
4555 
4556 	ELSIF l_budget_entry_method_rec.entry_level_code = 'M' -- then check whether it is a top or
4557 				       -- lowest level tasks
4558 	    THEN
4559 	      IF l_task_id <> pa_task_utils.get_top_task_id( l_task_id ) THEN
4560 		 pa_tasks_pkg.verify_lowest_level_task( l_return_status_task
4561 						     	, l_task_id);
4562 		 IF l_return_status_task <> 0 THEN
4563 			gms_error_pkg.gms_message(x_err_name => 'GMS_TASK_IS_NOT_TOP_OR_LOWEST',
4564 						x_err_code => x_err_code,
4565 						x_err_buff => x_err_stage);
4566 
4567 			APP_EXCEPTION.RAISE_EXCEPTION;
4568                  END IF;
4569 	      END IF;
4570 
4571 	END IF;  -- If l_budget_entry_method_rec.entry_level_code = 'T'
4572 
4573         gms_budget_utils.get_valid_period_dates
4574                   (p_project_id		     => l_project_id
4575     		  ,p_task_id		     => l_task_id
4576 		  ,p_award_id		     => l_award_id	-- Added for Bug 2200867
4577     		  ,p_time_phased_type_code   => l_budget_entry_method_rec.time_phased_type_code
4578     		  ,p_entry_level_code	     => l_budget_entry_method_rec.entry_level_code
4579     		  ,p_period_name_in	     => p_period_name
4580     		  ,p_budget_start_date_in    => p_budget_start_date
4581     		  ,p_budget_end_date_in	     => p_budget_end_date
4582     		  ,p_period_name_out	     => l_period_name -- p_period_name
4583     		  ,p_budget_start_date_out   => l_budget_start_date -- p_budget_start_date
4584     		  ,p_budget_end_date_out     => l_budget_end_date -- p_budget_end_date
4585     		  ,x_err_code		     => x_err_code
4586     		  ,x_err_stage		     => x_err_stage  );
4587 
4588 		IF x_err_code <> 0
4589 		THEN
4590 			gms_error_pkg.gms_message(x_err_name => 'GMS_GET_PERIOD_DATE_FAIL',
4591 						x_err_code => x_err_code,
4592 						x_err_buff => x_err_stage);
4593 
4594 			APP_EXCEPTION.RAISE_EXCEPTION;
4595 		END IF;
4596 
4597 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after gms_budget_utils.get_valid_period_dates');
4598 
4599 -- every budget line need to be checked for it's amount values.
4600 
4601     gms_budget_utils.check_entry_method_flags
4602              (  p_budget_amount_code 		=> l_budget_amount_code
4603 	       ,p_budget_entry_method_code	=> l_budget_entry_method_code
4604 	       ,p_quantity			=> p_quantity
4605 	       ,p_raw_cost			=> p_raw_cost
4606 	       ,p_burdened_cost		        => p_burdened_cost
4607 	       ,x_err_code		        => x_err_code
4608 	       ,x_err_stage			=> x_err_stage	);
4609 
4610 	IF x_err_code <> 0
4611 	THEN
4612 		gms_error_pkg.gms_message(x_err_name => 'GMS_CHK_ENTRYMETHOD_FAIL',
4613 					x_err_code => x_err_code,
4614 					x_err_buff => x_err_stage);
4615 
4616 		APP_EXCEPTION.RAISE_EXCEPTION;
4617 	END IF;
4618 
4619 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after gms_budget_utils.check_entry_method_flags');
4620 
4621 /*
4622 	We don't have to validate/convert resource_list info
4623 	since we fetch it using cursor ...
4624 
4625     -- convert resource_list name to id
4626     IF (p_resource_list_name <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
4627         AND p_resource_list_name IS NOT NULL)
4628     OR (p_resource_list_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
4629         AND p_resource_list_id IS NOT NULL)
4630     THEN
4631     	convert_reslist_name_to_id
4632     		(p_resource_list_name_in => p_resource_list_name
4633     		,p_resource_list_id_in => p_resource_list_id
4634     		,p_resource_list_id_out => l_resource_list_id
4635     		,x_err_code => x_err_code
4636     		,x_err_stage => x_err_stage
4637     		,x_err_stack => x_err_stack);
4638 
4639 	    IF x_err_code <> 0
4640     	THEN
4641     		x_err_stage := 'GMS_....';
4642     		return;
4643     	END IF;
4644 
4645     END IF;
4646 */
4647 
4648     -- convert resource alias to (resource) member id
4649 
4650     -- if resource alias is (passed and not NULL)
4651     -- and resource member is (passed and not NULL)
4652     -- then we convert the alias to the id
4653     -- else we default to the uncategorized resource member
4654 
4655    IF (p_resource_alias <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
4656        AND p_resource_alias IS NOT NULL)
4657 
4658    OR (p_resource_list_member_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
4659        AND p_resource_list_member_id IS NOT NULL)
4660    THEN
4661      	convert_listmem_alias_to_id
4662      		(p_resource_list_id_in	=> l_resource_list_id 	-- IN
4663 	     	,p_reslist_member_alias_in => p_resource_alias 	-- IN
4664 	     	,p_resource_list_member_id_in => p_resource_list_member_id
4665 	     	,p_resource_list_member_id_out	=> l_member_id
4666 	     	,x_err_code => x_err_code
4667 	     	,x_err_stage => x_err_stage
4668 	     	,x_err_stack => x_err_stack);
4669 
4670      	IF x_err_code <> 0
4671      	THEN
4672 		return;
4673      	END IF;
4674 
4675     ELSE
4676 	gms_error_pkg.gms_message(x_err_name => 'GMS_RESOURCE_MISSING',
4677 				x_err_code => x_err_code,
4678 				x_err_buff => x_err_stage);
4679 
4680 	APP_EXCEPTION.RAISE_EXCEPTION;
4681     END IF;
4682 
4683 
4684      --When budget line description is not passed, set value to NULL
4685 
4686      IF p_description = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4687      THEN
4688      	l_description := NULL;
4689      ELSE
4690      	l_description := p_description;
4691      END IF;
4692 
4693      IF p_period_name = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4694      THEN
4695      	l_period_name := NULL;
4696      ELSE
4697      	l_period_name := p_period_name;
4698      END IF;
4699 
4700      --When descriptive flex fields are not passed set them to NULL
4701      IF p_attribute_category = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4702      THEN
4703      	l_attribute_category := NULL;
4704      ELSE
4705 	l_attribute_category := p_attribute_category;
4706      END IF;
4707      IF p_attribute1 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4708      THEN
4709      	l_attribute1 := NULL;
4710      ELSE
4711 	l_attribute1 := p_attribute1;
4712      END IF;
4713      IF p_attribute2 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4714      THEN
4715      	l_attribute2 := NULL;
4716      ELSE
4717 	l_attribute2 := p_attribute2;
4718      END IF;
4719      IF p_attribute3 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4720      THEN
4721      	l_attribute3 := NULL;
4722      ELSE
4723 	l_attribute3 := p_attribute3;
4724      END IF;
4725      IF p_attribute4 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4726      THEN
4727      	l_attribute4 := NULL;
4728      ELSE
4729 	l_attribute4 := p_attribute4;
4730      END IF;
4731 
4732      IF p_attribute5 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4733      THEN
4734      	l_attribute5 := NULL;
4735      ELSE
4736 	l_attribute5 := p_attribute5;
4737      END IF;
4738 
4739      IF p_attribute6 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4740      THEN
4741      	l_attribute6 := NULL;
4742      ELSE
4743 	l_attribute6 := p_attribute6;
4744      END IF;
4745 
4746      IF p_attribute7 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4747      THEN
4748      	l_attribute7 := NULL;
4749      ELSE
4750 	l_attribute7 := p_attribute7;
4751      END IF;
4752 
4753      IF p_attribute8 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4754      THEN
4755      	l_attribute8 := NULL;
4756      ELSE
4757 	l_attribute8 := p_attribute8;
4758      END IF;
4759      IF p_attribute9 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4760      THEN
4761      	l_attribute9 := NULL;
4762      ELSE
4763 	l_attribute9 := p_attribute9;
4764      END IF;
4765      IF p_attribute10 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4766      THEN
4767      	l_attribute10 := NULL;
4768      ELSE
4769 	l_attribute10 := p_attribute10;
4770      END IF;
4771      IF p_attribute11 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4772      THEN
4773      	l_attribute11 := NULL;
4774      ELSE
4775 	l_attribute11 := p_attribute11;
4776      END IF;
4777      IF p_attribute12 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4778      THEN
4779      	l_attribute12 := NULL;
4780      ELSE
4781 	l_attribute12 := p_attribute12;
4782      END IF;
4783      IF p_attribute13 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4784      THEN
4785      	l_attribute13 := NULL;
4786      ELSE
4787 	l_attribute13 := p_attribute13;
4788      END IF;
4789      IF p_attribute14 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4790      THEN
4791      	l_attribute14:= NULL;
4792      ELSE
4793 	l_attribute14:= p_attribute14;
4794      END IF;
4795 
4796      IF p_attribute15 = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4797      THEN
4798      	l_attribute15 := NULL;
4799      ELSE
4800 	l_attribute15 := p_attribute15;
4801      END IF;
4802 
4803      IF p_unit_of_measure = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4804      THEN
4805      	l_unit_of_measure := NULL;
4806      ELSE
4807 	l_unit_of_measure := p_unit_of_measure;
4808      END IF;
4809 
4810      IF p_track_as_labor_flag = GMS_BUDGET_PUB.G_PA_MISS_CHAR
4811      THEN
4812      	l_track_as_labor_flag := NULL;
4813      ELSE
4814 	l_track_as_labor_flag := p_track_as_labor_flag;
4815      END IF;
4816 
4817 --Remove big numbers in case parameters were not passed, default to NULL; Assign Valid
4818 -- Values to local variables.
4819 
4820      IF p_quantity = GMS_BUDGET_PUB.G_PA_MISS_NUM
4821      THEN
4822      	l_quantity := null;
4823       ELSE
4824 	l_quantity := p_quantity;
4825       END IF;
4826 
4827      IF p_raw_cost = GMS_BUDGET_PUB.G_PA_MISS_NUM
4828      THEN
4829      	l_raw_cost := null;
4830       ELSE
4831 	l_raw_cost := p_raw_cost;
4832       END IF;
4833 
4834      IF p_burdened_cost = GMS_BUDGET_PUB.G_PA_MISS_NUM
4835      THEN
4836      	l_burdened_cost := null;
4837       ELSE
4838 	l_burdened_cost := p_burdened_cost;
4839       END IF;
4840 ---------------------------
4841 
4842      IF (p_quantity IS NULL AND p_raw_cost IS NULL AND p_burdened_cost IS NULL AND l_budget_amount_code = 'C')
4843      THEN
4844 	NULL;  --we don't insert budget lines with all zero's
4845      ELSE
4846 
4847    begin
4848 	select resource_assignment_id
4849 	into   l_resource_assignment_id
4850 	from   gms_resource_assignments
4851 	where  budget_version_id = l_budget_version_id
4852 	and    project_id = l_project_id
4853 	and    NVL(task_id, 0) = NVL(l_task_id, 0) -- was p_pa_task_id
4854 	and    resource_list_member_id = p_resource_list_member_id;
4855 
4856    exception
4857 	   when NO_DATA_FOUND then
4858               x_err_stage := 'create new resource assignment <'
4859 		    || to_char(l_budget_version_id) || '><'
4860 		    || to_char(l_project_id) || '><'
4861 		    || to_char(l_task_id) || '><'
4862 		    || to_char(p_resource_list_member_id)
4863 		    || '>';
4864 
4865 	      select gms_resource_assignments_s.nextval
4866 	      into   l_resource_assignment_id
4867 	      from   sys.dual;
4868 
4869 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after selecting from sequence');
4870 
4871 	      -- create a new resource assignment
4872               insert into gms_resource_assignments
4873 	             (resource_assignment_id,
4874 	              budget_version_id,
4875 	              project_id,
4876 	              task_id,
4877 	              resource_list_member_id,
4878 	              last_update_date,
4879 	              last_updated_by,
4880 	              creation_date,
4881 	              created_by,
4882 	              last_update_login,
4883 	              unit_of_measure,
4884 	              track_as_labor_flag)
4885                  values ( l_resource_assignment_id,
4886 	                l_budget_version_id,
4887 	                l_project_id,
4888 	                l_task_id,
4889 --	                p_resource_list_member_id, commented for bug 3891250
4890 			l_member_id,      -- Added for bug 3891250
4891 	                SYSDATE,
4892 			l_user_id,
4893 	                SYSDATE,
4894 			l_user_id,
4895 			l_login_id,
4896 	                l_unit_of_measure,
4897 	                l_track_as_labor_flag);
4898 
4899 	   when OTHERS then
4900 		gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
4901 					x_token_name1 => 'SQLCODE',
4902 					x_token_val1 => sqlcode,
4903 					x_token_name2 => 'SQLERRM',
4904 					x_token_val2 => sqlerrm,
4905 					x_err_code => x_err_code,
4906 					x_err_buff => x_err_stage);
4907 
4908 		APP_EXCEPTION.RAISE_EXCEPTION;
4909    end ;
4910 
4911 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after insert into gms_resource_assignments');
4912 
4913     -- Copy raw cost into burdened cost if budrened cost is null.
4914     -- If the resource UOM is currency and raw cost is null then
4915     -- copy value of quantity amt into raw cost and also set quantity
4916     -- amt to null.
4917 
4918      if gms_budget_utils.get_budget_amount_code(p_budget_type_code) = 'C' then
4919         -- Cost Budget
4920 
4921        if gms_budget_utils.check_currency_uom(p_unit_of_measure) = 'Y' then
4922 
4923          if l_raw_cost is null then
4924            l_raw_cost := l_quantity;
4925           end if;
4926           l_quantity := null;
4927        end if;
4928 
4929        if  l_burdened_cost is null then
4930           l_burdened_cost := l_raw_cost;
4931        end if;
4932 
4933      end if;
4934 
4935 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - before insert into gms_budget_lines');
4936 
4937      insert into gms_budget_lines
4938 	       (resource_assignment_id,
4939 	        start_date,
4940 		last_update_date,
4941                 last_updated_by,
4942                 creation_date,
4943                 created_by,
4944                 last_update_login,
4945 	        end_date,
4946 	        period_name,
4947 	        quantity,
4948 	        raw_cost,
4949 	        burdened_cost,
4950                 change_reason_code,
4951                 description,
4952                 attribute_category,
4953                 attribute1,
4954                 attribute2,
4955                 attribute3,
4956                 attribute4,
4957                 attribute5,
4958                 attribute6,
4959                 attribute7,
4960                 attribute8,
4961                 attribute9,
4962                 attribute10,
4963                 attribute11,
4964                 attribute12,
4965                 attribute13,
4966                 attribute14,
4967                 attribute15,
4968 		pm_product_code,
4969 		pm_budget_line_reference,
4970 		quantity_source,
4971 		raw_cost_source,
4972 		burdened_cost_source
4973                 )
4974              values (
4975 		l_resource_assignment_id,
4976 	        l_budget_start_date,
4977 		SYSDATE,
4978 		l_user_id,
4979                 SYSDATE,
4980 		l_user_id,
4981 		l_login_id,
4982 	        l_budget_end_date,
4983 	        l_period_name,
4984 	        l_quantity,
4985 	        pa_currency.round_currency_amt(l_raw_cost),
4986 	        pa_currency.round_currency_amt(l_burdened_cost),
4987 --                p_change_reason_code,
4988 		NULL, -- change_reason_code only applicable upon update
4989 	        l_description,
4990                 l_attribute_category,
4991                 l_attribute1,
4992                 l_attribute2,
4993                 l_attribute3,
4994                 l_attribute4,
4995                 l_attribute5,
4996                 l_attribute6,
4997                 l_attribute7,
4998                 l_attribute8,
4999                 l_attribute9,
5000                 l_attribute10,
5001                 l_attribute11,
5002                 l_attribute12,
5003                 l_attribute13,
5004                 l_attribute14,
5005                 l_attribute15,
5006 		p_pm_product_code,
5007 		p_pm_budget_line_reference,
5008 		p_quantity_source,
5009 		p_raw_cost_source,
5010 		p_burdened_cost_source
5011                  );
5012 
5013 -- dbms_output.put_line('GMS_BUDGET_PUB.ADD_BUDGET_LINE - after insert into gms_budget_lines');
5014 
5015      end if;
5016 
5017 -------------------------------------------------------------------------------------------
5018 
5019 -- check for overlapping dates
5020 -- Added the following IF Stmt for Bug: 2791285
5021 
5022     if l_budget_entry_method_rec.time_phased_type_code in ('G','P','R') then
5023 
5024       gms_budget_utils.check_overlapping_dates( x_budget_version_id => l_budget_version_id		--IN
5025     						  ,x_resource_name	=> l_resource_name		--OUT
5026     						  ,x_err_code		=> x_err_code		);
5027 
5028       IF x_err_code <> 0
5029       THEN
5030   	gms_error_pkg.gms_message(x_err_name => 'GMS_CHECK_DATES_FAILED',
5031   				x_err_code => x_err_code,
5032   				x_err_buff => x_err_stage);
5033 
5034 	APP_EXCEPTION.RAISE_EXCEPTION;
5035       END IF;
5036 
5037    end if; -- Time Phased type code
5038 
5039 -- summarizing the totals in the table gms_budget_versions
5040 
5041     GMS_BUDGET_PUB.summerize_project_totals( x_budget_version_id => l_budget_version_id
5042     					    , x_err_code	  => x_err_code
5043 					    , x_err_stage	  => x_err_stage
5044 					    , x_err_stack	  => x_err_stack		);
5045 
5046 --   dbms_output.put_line('After summerize_project_totals');
5047 --   dbms_output.put_line('Error code: '||l_err_code);
5048 --   dbms_output.put_line('Error Stage: '||l_err_stage);
5049 --   dbms_output.put_line('Error Stack: '||l_err_stack);
5050 
5051 
5052     IF x_err_code <> 0
5053     THEN
5054 	gms_error_pkg.gms_message(x_err_name => 'GMS_SUMMERIZE_TOTALS_FAILED',
5055 				x_err_code => x_err_code,
5056 				x_err_buff => x_err_stage);
5057 
5058 	APP_EXCEPTION.RAISE_EXCEPTION;
5059     END IF;
5060 
5061 ------------------------------------------------------------------------------------
5062 -- Added for Bug:1325015
5063 
5064 	validate_budget(  x_budget_version_id => l_budget_version_id,
5065 			    x_award_id => l_award_id,
5066                             x_project_id => l_project_id,
5067                             x_task_id => l_task_id,
5068                             x_resource_list_member_id => p_resource_list_member_id,
5069                             x_start_date => l_budget_start_date,
5070                             x_end_date => l_budget_end_date,
5071                             x_return_status => x_err_code);
5072 
5073 	if x_err_code <> 0 then
5074 		ROLLBACK TO add_budget_line_pub;
5075 	end if;
5076  -- Commented out this call for GMS enhancement : 5583170 as we don't validates across awards with this enahncement.
5077 
5078 /*	validate_budget_mf(  x_budget_version_id => l_budget_version_id,
5079 			    x_award_id => l_award_id,
5080                             x_project_id => l_project_id,
5081                             x_task_id => l_task_id,
5082                             x_resource_list_member_id => p_resource_list_member_id,
5083                             x_start_date => l_budget_start_date,
5084                             x_end_date => l_budget_end_date,
5085                             x_return_status => x_err_code);
5086 
5087 	if x_err_code <> 0 then
5088 		ROLLBACK TO add_budget_line_pub;
5089 	end if;
5090 */
5091 ------------------------------------------------------------------------------------
5092 
5093 
5094     IF FND_API.TO_BOOLEAN( p_commit )
5095     THEN
5096 	COMMIT;
5097     END IF;
5098 
5099    x_err_stack := l_old_stack;
5100 
5101 EXCEPTION
5102 
5103 	WHEN OTHERS
5104 	THEN
5105 		-- Bug 1831151 : Commented out NOCOPY the following line and added simple roll back statement as
5106 		-- the copy actual functionality was erroring out NOCOPY with error 'save point never established'
5107 		-- ROLLBACK to add_budget_line_pub ;
5108 		ROLLBACK ;
5109 		RAISE;
5110 
5111 END add_budget_line;
5112 
5113 
5114 ----------------------------------------------------------------------------------------
5115 -- Name:               delete_draft_budget
5116 -- Type:               Procedure
5117 -- Description:        This procedure can be used to delete a draft budget
5118 --
5119 --
5120 -- Called subprograms:
5121 --
5122 --
5123 --
5124 --History:
5125 --
5126 
5127 PROCEDURE delete_draft_budget
5128 ( p_api_version_number			IN	NUMBER
5129  ,x_err_code				IN OUT NOCOPY	NUMBER
5130  ,x_err_stage				IN OUT NOCOPY	VARCHAR2
5131  ,x_err_stack				IN OUT NOCOPY	VARCHAR2
5132  ,p_commit				IN	VARCHAR2	:= GMS_BUDGET_PUB.G_GMS_FALSE
5133  ,p_init_msg_list			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_GMS_FALSE
5134  ,p_pm_product_code			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5135  ,p_project_id				IN	NUMBER		:= GMS_BUDGET_PUB.G_PA_MISS_NUM
5136  ,p_project_number			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5137  ,p_award_id				IN	NUMBER		:= GMS_BUDGET_PUB.G_PA_MISS_NUM
5138  ,p_award_number			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5139  ,p_budget_type_code			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR	)
5140 
5141 IS
5142 
5143    CURSOR l_budget_version_csr
5144    	 ( p_project_id NUMBER
5145    	 , p_award_id NUMBER
5146    	 , p_budget_type_code VARCHAR2	)
5147    IS
5148    SELECT budget_version_id
5149    FROM gms_budget_versions
5150    WHERE project_id = p_project_id
5151    AND   award_id   = p_award_id
5152    AND   budget_type_code = p_budget_type_code
5153    AND   budget_status_code in ('W','S');-- Bug 1831122
5154 
5155    CURSOR l_budget_type_csr
5156    	 ( p_budget_type_code VARCHAR2 )
5157    IS
5158    SELECT 1
5159    FROM   pa_budget_types
5160    WHERE  budget_type_code = p_budget_type_code;
5161 
5162 
5163    CURSOR l_lock_budget_csr( p_budget_version_id NUMBER )
5164    IS
5165    SELECT 'x'
5166    FROM   gms_budget_versions bv
5167    ,      gms_resource_assignments ra
5168    ,      gms_budget_lines bl
5169    WHERE  bv.budget_version_id = p_budget_version_id
5170    AND    bv.budget_version_id = ra.budget_version_id (+)
5171    AND    ra.resource_assignment_id = bl.resource_assignment_id (+)
5172    FOR UPDATE OF bv.budget_version_id,ra.budget_version_id,bl.resource_assignment_id NOWAIT;
5173 
5174    l_api_name		CONSTANT	VARCHAR2(30) 		:= 'delete_draft_budget';
5175    i					NUMBER;
5176    l_dummy				NUMBER;
5177    l_budget_version_id			NUMBER;
5178    l_award_id				NUMBER;
5179    l_project_id				NUMBER;
5180    l_budget_type_code			VARCHAR2(30);
5181    l_function_allowed			VARCHAR2(1);
5182    l_resp_id				NUMBER := 0;
5183    l_user_id		                NUMBER := 0;
5184    l_module_name                        VARCHAR2(80);
5185    l_old_stack				VARCHAR2(630);
5186 
5187 BEGIN
5188 
5189 	x_err_code := 0;
5190 	l_old_stack := x_err_stack;
5191 	x_err_stack := x_err_stack ||'-> Delete_Draft_Budget';
5192 
5193 --  Initialize the message table if requested.
5194 
5195     IF FND_API.TO_BOOLEAN( p_init_msg_list )
5196     THEN
5197 
5198 	FND_MSG_PUB.initialize;
5199 
5200     END IF;
5201 
5202 --  Standard begin of API savepoint
5203 
5204     SAVEPOINT delete_draft_budget_pub;
5205 
5206 --  Standard call to check for call compatibility.
5207 
5208     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
5209     	    	    	    	    	 p_api_version_number	,
5210     	    	    	    	    	 l_api_name 	    	,
5211     	    	    	    	    	 G_PKG_NAME 	    	)
5212     THEN
5213 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
5214 				x_err_code => x_err_code,
5215 				x_err_buff => x_err_stage);
5216 
5217 	APP_EXCEPTION.RAISE_EXCEPTION;
5218     END IF;
5219 
5220 --  product_code is mandatory
5221 
5222     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
5223     OR p_pm_product_code IS NULL
5224     THEN
5225 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_IS_MISSING',
5226 				x_err_code => x_err_code,
5227 				x_err_buff => x_err_stage);
5228 
5229 	APP_EXCEPTION.RAISE_EXCEPTION;
5230     END IF;
5231 
5232 ----------------------------------------------------------------------------
5233 -- If award_id is passed in then use it otherwise use the award_number
5234 -- that is passed in to fetch value of award_id from gms_awards table
5235 -- If both are missing then raise an error.
5236 
5237     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
5238         AND p_award_number IS NOT NULL)
5239     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
5240         AND p_award_id IS NOT NULL)
5241     THEN
5242 
5243    	convert_awardnum_to_id(p_award_number_in => p_award_number
5244    	                      ,p_award_id_in => p_award_id
5245    			      ,p_award_id_out => l_award_id
5246    			      ,x_err_code => x_err_code
5247    			      ,x_err_stage => x_err_stage
5248    			      ,x_err_stack => x_err_stack);
5249 
5250    	IF x_err_code <> 0
5251 	THEN
5252 		return;
5253 	END IF;
5254     ELSE
5255 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
5256 				x_err_code => x_err_code,
5257 				x_err_buff => x_err_stage);
5258 
5259 	APP_EXCEPTION.RAISE_EXCEPTION;
5260    END IF;
5261 --------------------------------------------------------------------------------
5262 
5263     l_resp_id := FND_GLOBAL.Resp_id;
5264     l_user_id := FND_GLOBAL.User_id;
5265     l_module_name := 'GMS_PM_DELETE_DRAFT_BUDGET';
5266 
5267     -- As part of enforcing award security, which would determine
5268     -- whether the user has the necessary privileges to update the award
5269     -- need to call the gms_security package
5270     -- If a user does not have privileges to update the award, then
5271     -- cannot delete a budget
5272 
5273     gms_security.initialize (X_user_id        => l_user_id,
5274                             X_calling_module => l_module_name);
5275 
5276     -- Actions performed using the APIs would be subject to
5277     -- function security. If the responsibility does not allow
5278     -- such functions to be executed, the API should not proceed further
5279     -- since the user does not have access to such functions
5280 
5281 -----------------------------------------------------------------------------
5282 
5283 -- If project_id is passed in then use it otherwise use the project_number
5284 -- (segment1) that is passed in to fetch value of project_id from pa_projects
5285 -- table. If both are missing then raise an error.
5286 
5287 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
5288         AND p_project_number IS NOT NULL)
5289     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
5290         AND p_project_id IS NOT NULL)
5291    	THEN
5292    		convert_projnum_to_id(p_project_number_in => p_project_number
5293    		                      ,p_project_id_in => p_project_id
5294    				      ,p_project_id_out => l_project_id
5295    				      ,x_err_code => x_err_code
5296    				      ,x_err_stage => x_err_stage
5297    				      ,x_err_stack => x_err_stack);
5298 
5299 	   	IF x_err_code <> 0
5300     		THEN
5301 			return;
5302     		END IF;
5303 
5304 	ELSE
5305 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_NUM_ID_MISSING',
5306          				x_err_code => x_err_code,
5307 					x_err_buff => x_err_stage);
5308 
5309 		APP_EXCEPTION.RAISE_EXCEPTION;
5310 	END IF;
5311 -------------------------------------------------------------------------------
5312 
5313       -- Now verify whether award security allows the user to update
5314       -- award
5315       -- If a user does not have privileges to update the award, then
5316       -- cannot delete a budget
5317 
5318       IF gms_security.allow_query (x_award_id => l_award_id ) = 'N' THEN
5319 
5320          -- The user does not have query privileges on this award
5321          -- Hence, cannot update the award. Raise error
5322 
5323 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_QRY',
5324 				x_err_code => x_err_code,
5325 				x_err_buff => x_err_stage);
5326 
5327 	APP_EXCEPTION.RAISE_EXCEPTION;
5328 
5329       ELSE
5330             -- If the user has query privileges, then check whether
5331             -- update privileges are also available
5332          IF gms_security.allow_update (x_award_id => l_award_id ) = 'N' THEN
5333 
5334             -- The user does not have update privileges on this award
5335             -- Hence , raise error
5336 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_UPD',
5337 					x_err_code => x_err_code,
5338 					x_err_buff => x_err_stage);
5339 
5340 		APP_EXCEPTION.RAISE_EXCEPTION;
5341 
5342 	END IF;
5343      END IF;
5344 
5345 
5346 -- budget code is mandatory
5347 
5348      IF p_budget_type_code IS NULL
5349      OR p_budget_type_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
5350      THEN
5351 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_MISSING',
5352 					x_err_code => x_err_code,
5353 					x_err_buff => x_err_stage);
5354 
5355 		APP_EXCEPTION.RAISE_EXCEPTION;
5356 
5357      ELSE
5358      		OPEN l_budget_type_csr( p_budget_type_code );
5359 
5360 		FETCH l_budget_type_csr INTO l_dummy;
5361 
5362 		IF l_budget_type_csr%NOTFOUND
5363 		THEN
5364 			CLOSE l_budget_type_csr;
5365 			gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_INVALID',
5366 						x_err_code => x_err_code,
5367 						x_err_buff => x_err_stage);
5368 
5369 			APP_EXCEPTION.RAISE_EXCEPTION;
5370 		END IF;
5371 
5372 		CLOSE l_budget_type_csr;
5373 
5374      END IF;
5375 
5376 
5377 
5378 --  get the corresponding budget_version_id
5379 
5380     OPEN l_budget_version_csr
5381     	(p_project_id 		=> l_project_id
5382     	,p_award_id             => l_award_id
5383     	,p_budget_type_code	=> p_budget_type_code );
5384 
5385     FETCH l_budget_version_csr INTO l_budget_version_id;
5386 
5387     IF l_budget_version_csr%NOTFOUND
5388     THEN
5389 
5390 	CLOSE l_budget_version_csr;
5391 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_VERSION',
5392 				x_err_code => x_err_code,
5393 				x_err_buff => x_err_stage);
5394 
5395 	APP_EXCEPTION.RAISE_EXCEPTION;
5396 
5397     END IF;
5398 
5399     CLOSE l_budget_version_csr;
5400 
5401     OPEN l_lock_budget_csr( l_budget_version_id );
5402 
5403 
5404 -----------------------------------------------------------------------------
5405 
5406 /**	for b1_rec in (	select rowid
5407 		from gms_budget_lines
5408 		where resource_assignment_id
5409 		in
5410 			(select resource_assignment_id
5411 			from gms_resource_assignments
5412 			where budget_version_id = l_budget_version_id))
5413 **/
5414 	for b1_rec in ( select 	gbl.rowid,
5415 				gra.resource_list_member_id,
5416 				gra.task_id,
5417 				gbl.start_date,
5418 				gbl.period_name
5419 			from 	gms_resource_assignments gra,
5420 				gms_budget_lines gbl
5421 			where	gbl.resource_assignment_id = gra.resource_assignment_id
5422 			and	gra.budget_version_id = l_budget_version_id )
5423 
5424 	loop
5425 
5426 		gms_budget_pub.delete_budget_line
5427 		( p_api_version_number => 1.0
5428 		 ,p_pm_product_code => 'GMS'
5429 		 ,p_project_id => l_project_id
5430 		 ,p_award_id => l_award_id
5431 		 ,p_budget_type_code =>	p_budget_type_code
5432 		 ,p_task_id => 	b1_rec.task_id
5433 		 ,p_resource_list_member_id => b1_rec.resource_list_member_id
5434 		 ,p_start_date => b1_rec.start_date
5435 		 ,p_period_name	=> b1_rec.period_name
5436 		 ,x_err_code => x_err_code
5437 		 ,x_err_stage => x_err_stage
5438 		 ,x_err_stack => x_err_stack);
5439 
5440 	if x_err_code <> 0
5441 	then
5442 		gms_error_pkg.gms_message(x_err_name => 'GMS_DELETE_BUDGET_LINE_FAIL',
5443 					x_err_code => x_err_code,
5444 					x_err_buff => x_err_stage);
5445 
5446 		APP_EXCEPTION.RAISE_EXCEPTION;
5447 	end if;
5448 
5449 	end loop;
5450 
5451 	begin
5452 		delete gms_budget_versions
5453 		where budget_version_id = l_budget_version_id;
5454 	exception
5455 	when NO_DATA_FOUND
5456 	then
5457 		gms_error_pkg.gms_message(x_err_name => 'GMS_DELETE_DRAFT_FAIL',
5458 			x_err_code => x_err_code,
5459 			x_err_buff => x_err_stage);
5460 
5461 		APP_EXCEPTION.RAISE_EXCEPTION;
5462 	end;
5463 
5464     --!!! temporary solution, because delete_draft has commit
5465 
5466     SAVEPOINT delete_draft_budget_pub;
5467 
5468     CLOSE l_lock_budget_csr; --FYI, does not release locks
5469 
5470     IF fnd_api.to_boolean(p_commit)
5471     THEN
5472     	COMMIT;
5473     END IF;
5474 
5475     x_err_stack := l_old_stack;
5476 
5477 EXCEPTION
5478 	WHEN OTHERS
5479 	THEN
5480 		ROLLBACK TO delete_draft_budget_pub;
5481 		RAISE;
5482 
5483 END delete_draft_budget;
5484 
5485 
5486 ----------------------------------------------------------------------------------------
5487 -- Name:               delete_budget_line
5488 -- Type:               Procedure
5489 -- Description:        This procedure can be used to delete a budget_line of a draft budget
5490 --
5491 --
5492 -- Called subprograms:
5493 --
5494 --
5495 --
5496 -- History:
5497 --
5498 --
5499 
5500 PROCEDURE delete_budget_line
5501 ( p_api_version_number			IN	NUMBER
5502  ,x_err_code				IN OUT NOCOPY	NUMBER
5503  ,x_err_stage				IN OUT NOCOPY	VARCHAR2
5504  ,x_err_stack				IN OUT NOCOPY	VARCHAR2
5505  ,p_commit				IN	VARCHAR2	:= GMS_BUDGET_PUB.G_GMS_FALSE
5506  ,p_init_msg_list			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_GMS_FALSE
5507  ,p_pm_product_code			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5508  ,p_project_id				IN	NUMBER		:= GMS_BUDGET_PUB.G_PA_MISS_NUM
5509  ,p_project_number			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5510  ,p_award_id				IN	NUMBER		:= GMS_BUDGET_PUB.G_PA_MISS_NUM
5511  ,p_award_number			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5512  ,p_budget_type_code			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5513  ,p_task_id				IN	NUMBER		:= GMS_BUDGET_PUB.G_PA_MISS_NUM
5514  ,p_task_number				IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5515  ,p_resource_alias			IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
5516  ,p_resource_list_member_id		IN	NUMBER		:= GMS_BUDGET_PUB.G_PA_MISS_NUM
5517  ,p_start_date				IN	DATE		:= GMS_BUDGET_PUB.G_PA_MISS_DATE
5518  ,p_period_name				IN	VARCHAR2	:= GMS_BUDGET_PUB.G_PA_MISS_CHAR	)
5519 
5520 IS
5521 
5522    CURSOR l_budget_version_csr
5523    	 ( p_project_id NUMBER
5524    	 , p_award_id   NUMBER
5525    	 , p_budget_type_code VARCHAR2	)
5526    IS
5527    SELECT budget_version_id
5528    ,      resource_list_id
5529    ,	  budget_entry_method_code
5530    FROM   gms_budget_versions
5531    WHERE  project_id = p_project_id
5532    AND    award_id   = p_award_id
5533    AND    budget_type_code = p_budget_type_code
5534    AND    budget_status_code in ('W','S');--Bug 1831122
5535 
5536    CURSOR l_budget_type_csr
5537    	 ( p_budget_type_code VARCHAR2 )
5538    IS
5539    SELECT 1
5540    FROM   pa_budget_types
5541    WHERE  budget_type_code = p_budget_type_code;
5542 
5543    CURSOR l_resource_assignment_csr
5544    	  (p_budget_version_id	NUMBER
5545    	  ,p_task_id		NUMBER
5546    	  ,p_member_id		NUMBER	)
5547    IS
5548    SELECT resource_assignment_id
5549    FROM   gms_resource_assignments
5550    WHERE  budget_version_id = p_budget_version_id
5551    AND	  task_id = p_task_id
5552    AND	  resource_list_member_id = p_member_id;
5553 
5554    CURSOR l_budget_line_rowid_csr
5555    	 ( p_resource_assignment_id NUMBER
5556    	 , p_start_date		    DATE	)
5557    IS
5558    SELECT rowidtochar(rowid)
5559    FROM   gms_budget_lines
5560    WHERE  resource_assignment_id = p_resource_assignment_id
5561    AND    trunc(start_date) = nvl(trunc(p_start_date),trunc(start_date));
5562 
5563    CURSOR l_uncategorized_list_csr
5564    IS
5565    SELECT prlm.resource_list_member_id
5566    FROM   pa_resource_lists prl
5567    ,      pa_resource_list_members prlm
5568    ,	  pa_implementations pi
5569    WHERE  prl.resource_list_id = prlm.resource_list_id
5570    AND	  prl.business_group_id = pi.business_group_id
5571    AND    prl.uncategorized_flag='Y'
5572    and    NVL(prl.migration_code,'M') ='M' -- Bug 3626671
5573    and    NVL(prlm.migration_code,'M') ='M'; -- Bug 3626671;
5574 
5575    -- needed to get the start_date of a period
5576 
5577    CURSOR	l_budget_entry_method_csr
5578 		(p_budget_entry_method_code	VARCHAR2)
5579    IS
5580    SELECT time_phased_type_code
5581    FROM	  pa_budget_entry_methods
5582    WHERE  budget_entry_method_code = p_budget_entry_method_code;
5583 
5584    -- needed to get the budget_start_date of a period
5585 
5586    CURSOR	l_budget_periods_csr
5587    		(p_period_name 			VARCHAR2
5588    		,p_time_phased_type_code	VARCHAR2	)
5589    IS
5590    SELECT trunc(period_start_date), trunc(period_end_date) -- added end_date which is required in validate_budget()
5591    FROM   pa_budget_periods_v
5592    WHERE  period_name = p_period_name
5593    AND 	  period_type_code = p_time_phased_type_code;
5594 
5595    --needed to validate to given start_date
5596 
5597    CURSOR	l_start_date_csr
5598 		(p_start_date			DATE
5599 		,p_time_phased_type_code	VARCHAR2	)
5600    IS
5601    SELECT 1
5602    FROM   pa_budget_periods_v
5603    WHERE  trunc(period_start_date) = trunc(p_start_date)
5604    AND	  period_type_code = p_time_phased_type_code;
5605 
5606    --needed to lock the budget line row
5607    CURSOR l_lock_budget_line_csr( p_budget_line_rowid VARCHAR2)
5608    IS
5609    SELECT 'x'
5610    FROM   gms_budget_lines
5611    WHERE  rowid = p_budget_line_rowid
5612    FOR UPDATE NOWAIT;
5613 
5614    l_api_name		CONSTANT	VARCHAR2(30) 		:= 'delete_budget_line';
5615    i					NUMBER;
5616    l_dummy				NUMBER;
5617    l_budget_version_id			NUMBER;
5618    l_project_id				NUMBER;
5619    l_award_id				NUMBER;
5620    l_budget_type_code			VARCHAR2(30);
5621    l_resource_list_id			NUMBER;
5622    l_task_id				NUMBER;
5623    l_resource_list_member_id		NUMBER;
5624    l_budget_line_rowid			VARCHAR2(20);
5625    l_alias_not_found_ok	CONSTANT	VARCHAR2(1)		:= 'N';
5626    l_start_date				DATE;
5627    l_end_date				DATE;
5628    l_budget_entry_method_code		VARCHAR2(30);
5629    l_time_phased_type_code		VARCHAR2(30);
5630    l_function_allowed		        VARCHAR2(1);
5631    l_resp_id			        NUMBER := 0;
5632    l_user_id		                NUMBER := 0;
5633    l_login_id		                NUMBER := 0;
5634    l_module_name                        VARCHAR2(80);
5635 
5636    l_raw_cost				NUMBER;
5637    l_burdened_cost			NUMBER;
5638    l_quantity				NUMBER;
5639    l_resource_assignment_id		NUMBER;
5640    l_track_as_labor_flag		VARCHAR2(2);
5641    l_last_updated_by			NUMBER;
5642    l_last_update_login			NUMBER;
5643 
5644    l_old_stack				VARCHAR2(630);
5645 
5646 BEGIN
5647 
5648 	x_err_code := 0;
5649 	l_old_stack := x_err_stack;
5650 	x_err_stack := x_err_stack ||'-> Delete_Budget_Line';
5651 
5652 --  Initialize the message table if requested.
5653 
5654     IF FND_API.TO_BOOLEAN( p_init_msg_list )
5655     THEN
5656 
5657 	FND_MSG_PUB.initialize;
5658 
5659     END IF;
5660 
5661 --  Standard begin of API savepoint
5662 
5663     SAVEPOINT delete_budget_line_pub;
5664 
5665 --  Standard call to check for call compatibility.
5666 
5667     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
5668     	    	    	    	    	 p_api_version_number	,
5669     	    	    	    	    	 l_api_name 	    	,
5670     	    	    	    	    	 G_PKG_NAME 	    	)
5671     THEN
5672 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
5673  				x_err_code => x_err_code,
5674 				x_err_buff => x_err_stage);
5675 
5676 	APP_EXCEPTION.RAISE_EXCEPTION;
5677     END IF;
5678 
5679 --  product_code is mandatory
5680 
5681     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
5682     OR p_pm_product_code IS NULL
5683     THEN
5684 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_IS_MISSING',
5685  				x_err_code => x_err_code,
5686 				x_err_buff => x_err_stage);
5687 
5688 	APP_EXCEPTION.RAISE_EXCEPTION;
5689     END IF;
5690 
5691 ----------------------------------------------------------------------------
5692 -- If award_id is passed in then use it otherwise use the award_number
5693 -- that is passed in to fetch value of award_id from gms_awards table
5694 -- If both are missing then raise an error.
5695 
5696     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
5697         AND p_award_number IS NOT NULL)
5698     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
5699         AND p_award_id IS NOT NULL)
5700     THEN
5701    	convert_awardnum_to_id(p_award_number_in => p_award_number
5702    	                      ,p_award_id_in => p_award_id
5703    			      ,p_award_id_out => l_award_id
5704    			      ,x_err_code => x_err_code
5705    			      ,x_err_stage => x_err_stage
5706    			      ,x_err_stack => x_err_stack);
5707 
5708    	IF x_err_code <> 0
5709 	THEN
5710 		return;
5711 	END IF;
5712     ELSE
5713 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
5714  				x_err_code => x_err_code,
5715 				x_err_buff => x_err_stage);
5716 
5717 	APP_EXCEPTION.RAISE_EXCEPTION;
5718    END IF;
5719 --------------------------------------------------------------------------------
5720 
5721     l_resp_id := FND_GLOBAL.Resp_id;
5722     l_user_id := FND_GLOBAL.User_id;
5723     l_login_id := FND_GLOBAL.Login_id;
5724     l_module_name := 'GMS_PM_DELETE_BUDGET_LINE';
5725 
5726     -- As part of enforcing award security, which would determine
5727     -- whether the user has the necessary privileges to update the award
5728     -- need to call the gms_security package
5729     -- If a user does not have privileges to update the award, then
5730     -- cannot delete a budget line
5731 
5732     gms_security.initialize (X_user_id        => l_user_id,
5733                             X_calling_module => l_module_name);
5734 
5735 -----------------------------------------------------------------------------
5736 
5737 -- If project_id is passed in then use it otherwise use the project_number
5738 -- (segment1) that is passed in to fetch value of project_id from pa_projects
5739 -- table. If both are missing then raise an error.
5740 
5741 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
5742         AND p_project_number IS NOT NULL)
5743     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
5744         AND p_project_id IS NOT NULL)
5745    	THEN
5746    		convert_projnum_to_id(p_project_number_in => p_project_number
5747    		                      ,p_project_id_in => p_project_id
5748    				      ,p_project_id_out => l_project_id
5749    				      ,x_err_code => x_err_code
5750    				      ,x_err_stage => x_err_stage
5751    				      ,x_err_stack => x_err_stack);
5752 
5753 	   	IF x_err_code <> 0
5754     		THEN
5755 			return;
5756     		END IF;
5757 
5758 	ELSE
5759 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_NUM_ID_MISSING',
5760  					x_err_code => x_err_code,
5761 					x_err_buff => x_err_stage);
5762 
5763 		APP_EXCEPTION.RAISE_EXCEPTION;
5764 	END IF;
5765 -------------------------------------------------------------------------------
5766 
5767       -- Now verify whether award security allows the user to update
5768       -- award
5769       -- If a user does not have privileges to update the award, then
5770       -- cannot delete a budget line
5771 
5772       IF gms_security.allow_query (x_award_id => l_award_id ) = 'N' THEN
5773 
5774          -- The user does not have query privileges on this award
5775          -- Hence, cannot update the award. Raise error
5776 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_QRY',
5777  				x_err_code => x_err_code,
5778 				x_err_buff => x_err_stage);
5779 
5780 	APP_EXCEPTION.RAISE_EXCEPTION;
5781 
5782       ELSE
5783             -- If the user has query privileges, then check whether
5784             -- update privileges are also available
5785          IF gms_security.allow_update (x_award_id => l_award_id ) = 'N' THEN
5786 
5787             -- The user does not have update privileges on this award
5788             -- Hence , raise error
5789 
5790 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_UPD',
5791  					x_err_code => x_err_code,
5792 					x_err_buff => x_err_stage);
5793 
5794 		APP_EXCEPTION.RAISE_EXCEPTION;
5795 
5796         END IF;
5797      END IF;
5798 
5799 
5800 -- budget code is mandatory
5801 
5802      IF p_budget_type_code IS NULL
5803      OR p_budget_type_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
5804      THEN
5805 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_MISSING',
5806  				x_err_code => x_err_code,
5807 				x_err_buff => x_err_stage);
5808 
5809 	APP_EXCEPTION.RAISE_EXCEPTION;
5810      ELSE
5811      		OPEN l_budget_type_csr( p_budget_type_code );
5812 
5813 		FETCH l_budget_type_csr INTO l_dummy;
5814 
5815 		IF l_budget_type_csr%NOTFOUND
5816 		THEN
5817 			CLOSE l_budget_type_csr;
5818 			x_err_code := 10;
5819 			fnd_message.set_name('GMS','GMS_BUDGET_TYPE_IS_INVALID');
5820 			return;
5821 		END IF;
5822 
5823 		CLOSE l_budget_type_csr;
5824 
5825      END IF;
5826 
5827 
5828 --  get the corresponding budget_version_id
5829     OPEN l_budget_version_csr
5830     	(p_project_id 		=> l_project_id
5831     	,p_award_id		=> l_award_id
5832     	,p_budget_type_code	=> p_budget_type_code );
5833 
5834     FETCH l_budget_version_csr INTO l_budget_version_id
5835 				  , l_resource_list_id
5836 				  , l_budget_entry_method_code;
5837 
5838     IF l_budget_version_csr%NOTFOUND
5839     THEN
5840 	CLOSE l_budget_version_csr;
5841 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_VERSION',
5842  				x_err_code => x_err_code,
5843 				x_err_buff => x_err_stage);
5844 
5845 	APP_EXCEPTION.RAISE_EXCEPTION;
5846     END IF;
5847 
5848     CLOSE l_budget_version_csr;
5849 
5850 -- convert pm_task_reference to pa_task_id
5851 -- if both task_id and task_reference are not passed or NULL, then we will default to 0, because this
5852 -- is the value of task_id when budgetting is done at the project level.
5853 
5854    IF (p_task_id = GMS_BUDGET_PUB.G_PA_MISS_NUM
5855        OR p_task_id IS NULL OR p_task_id = 0)
5856    AND (p_task_number = GMS_BUDGET_PUB.G_PA_MISS_CHAR
5857         OR p_task_number IS NULL )
5858 
5859    THEN
5860 
5861    	l_task_id := 0;
5862 
5863    ELSE
5864 	convert_tasknum_to_id ( p_project_id_in => l_project_id
5865 				,p_task_id_in => p_task_id
5866 				,p_task_number_in => p_task_number
5867 				,p_task_id_out => l_task_id
5868 				,x_err_code => x_err_code
5869 				,x_err_stage => x_err_stage
5870 				,x_err_stack => x_err_stack);
5871 	IF x_err_code <> 0
5872 	THEN
5873 		gms_error_pkg.gms_message(x_err_name => 'GMS_TASK_VALIDATE_FAIL',  -- jjj - check message tag
5874  					x_err_code => x_err_code,
5875 					x_err_buff => x_err_stage);
5876 
5877 		APP_EXCEPTION.RAISE_EXCEPTION;
5878 
5879 	END IF;
5880    END IF;
5881 
5882 -- convert resource alias to (resource) member id if passed and NOT NULL
5883 
5884     -- convert resource alias to (resource) member id
5885 
5886     -- if resource alias is (passed and not NULL)
5887     -- and resource member is (passed and not NULL)
5888     -- then we convert the alias to the id
5889     -- else we default to the uncategorized resource member
5890 
5891    IF (p_resource_alias <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
5892        AND p_resource_alias IS NOT NULL)
5893    OR (p_resource_list_member_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
5894        AND p_resource_list_member_id IS NOT NULL)
5895    THEN
5896      	convert_listmem_alias_to_id
5897      		(p_resource_list_id_in	=> l_resource_list_id 	-- IN
5898 	     	,p_reslist_member_alias_in => p_resource_alias 	-- IN
5899 	     	,p_resource_list_member_id_in => p_resource_list_member_id
5900 	     	,p_resource_list_member_id_out	=> l_resource_list_member_id
5901 	     	,x_err_code => x_err_code
5902 	     	,x_err_stage => x_err_stage
5903 	     	,x_err_stack => x_err_stack);
5904 
5905      	IF x_err_code <> 0
5906      	THEN
5907 		gms_error_pkg.gms_message(x_err_name => 'GMS_RES_VALIDATE_FAIL',
5908  					x_err_code => x_err_code,
5909 					x_err_buff => x_err_stage);
5910 
5911 		APP_EXCEPTION.RAISE_EXCEPTION;
5912      	END IF;
5913 
5914     ELSE
5915 
5916    	   OPEN l_uncategorized_list_csr;
5917    	   FETCH l_uncategorized_list_csr INTO l_resource_list_member_id;
5918    	   CLOSE l_uncategorized_list_csr;
5919 
5920    END IF;
5921 
5922 
5923    OPEN l_resource_assignment_csr
5924    	(l_budget_version_id
5925    	,l_task_id
5926    	,l_resource_list_member_id);
5927 
5928    FETCH l_resource_assignment_csr INTO l_resource_assignment_id;
5929 
5930    IF l_resource_assignment_csr%NOTFOUND
5931    THEN
5932 	CLOSE l_resource_assignment_csr;
5933 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_RESOURCE_ASSIGNMENT',
5934  				x_err_code => x_err_code,
5935 				x_err_buff => x_err_stage);
5936 
5937 	APP_EXCEPTION.RAISE_EXCEPTION;
5938    END IF;
5939 
5940    CLOSE l_resource_assignment_csr;
5941 
5942    OPEN l_budget_entry_method_csr( p_budget_entry_method_code => l_budget_entry_method_code );
5943    FETCH l_budget_entry_method_csr INTO l_time_phased_type_code;
5944    CLOSE l_budget_entry_method_csr;
5945 
5946 
5947    IF p_period_name IS NOT NULL
5948    AND p_period_name <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
5949    THEN
5950 
5951 
5952 	OPEN l_budget_periods_csr( p_period_name => p_period_name
5953 				 , p_time_phased_type_code => l_time_phased_type_code );
5954 
5955 	FETCH l_budget_periods_csr INTO l_start_date, l_end_date;
5956 
5957       	IF l_budget_periods_csr%NOTFOUND
5958    	THEN
5959 		CLOSE l_budget_periods_csr;
5960 		gms_error_pkg.gms_message(x_err_name => 'GMS_PERIOD_NAME_INVALID',
5961  					x_err_code => x_err_code,
5962 					x_err_buff => x_err_stage);
5963 
5964 		APP_EXCEPTION.RAISE_EXCEPTION;
5965    	END IF;
5966 	CLOSE l_budget_periods_csr;
5967 
5968    ELSIF p_start_date IS NOT NULL
5969    AND   p_start_date <> GMS_BUDGET_PUB.G_PA_MISS_DATE
5970    THEN
5971 
5972 --  Condition for 'G' or 'P' time-phased-type code as only
5973 --  required for period phased budgets.
5974 
5975          IF (l_time_phased_type_code IN ('G', 'P') )  THEN
5976 
5977 	OPEN l_start_date_csr(   p_start_date			=> p_start_date
5978 			 	,p_time_phased_type_code	=> l_time_phased_type_code );
5979 
5980 	FETCH l_start_date_csr INTO l_dummy;
5981 
5982    	IF l_start_date_csr%NOTFOUND
5983    	THEN
5984 		CLOSE l_start_date_csr;
5985 		gms_error_pkg.gms_message(x_err_name => 'GMS_START_DATE_INVALID',
5986  					x_err_code => x_err_code,
5987 					x_err_buff => x_err_stage);
5988 
5989 		APP_EXCEPTION.RAISE_EXCEPTION;
5990    	END IF;
5991 
5992 	CLOSE l_start_date_csr;
5993 
5994 	END IF;
5995 
5996 	l_start_date := p_start_date;
5997    ELSE
5998 	l_start_date := NULL;  	--when no start_date or period_name is passed or both are NULL
5999 				--, then all periods will be deleted
6000    END IF;
6001 
6002 
6003    OPEN l_budget_line_rowid_csr( l_resource_assignment_id
6004    				,l_start_date			);
6005 
6006    FETCH l_budget_line_rowid_csr INTO l_budget_line_rowid;
6007 
6008    IF l_budget_line_rowid_csr%NOTFOUND
6009    THEN
6010 	CLOSE l_budget_line_rowid_csr;
6011 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_LINE_NOT_FOUND',
6012  				x_err_code => x_err_code,
6013 				x_err_buff => x_err_stage);
6014 
6015 	APP_EXCEPTION.RAISE_EXCEPTION;
6016    END IF;
6017 
6018 
6019    WHILE l_budget_line_rowid_csr%FOUND LOOP
6020 
6021    	BEGIN
6022 
6023 	OPEN l_lock_budget_line_csr( l_budget_line_rowid );
6024 	CLOSE l_lock_budget_line_csr;
6025 
6026 	select 	l.raw_cost,
6027 		l.burdened_cost,
6028 		l.quantity,
6029 		l.resource_assignment_id,
6030 		a.track_as_labor_flag
6031 	into	l_raw_cost,
6032 		l_burdened_cost,
6033 		l_quantity,
6034 		l_resource_assignment_id,
6035 		l_track_as_labor_flag
6036 	from 	gms_resource_assignments a,
6037 		gms_budget_lines l
6038 	where 	l.rowid = l_budget_line_rowid
6039 	and 	l.resource_assignment_id = a.resource_assignment_id;
6040 
6041 	delete from gms_budget_lines
6042 	where rowid = l_budget_line_rowid;
6043 
6044 	l_last_updated_by := fnd_global.user_id;
6045 	l_last_update_login := fnd_global.login_id;
6046 
6047 	select 	budget_version_id
6048 	into 	l_budget_version_id
6049 	from 	gms_resource_assignments
6050 	where	resource_assignment_id = l_resource_assignment_id;
6051 
6052     -- clean up gms_resource_assignments if necessary
6053 
6054 	delete gms_resource_assignments
6055 	where  resource_assignment_id = l_resource_assignment_id
6056 	and    not exists
6057 	       (select 1
6058 	        from   gms_budget_lines
6059 	        where  resource_assignment_id = l_resource_assignment_id);
6060 
6061        -- Update gms_budget_versions only if the denormalized totals are
6062        -- not being maintained in the form. Example the Copy Actual
6063        -- process.
6064 
6065 	update gms_budget_versions
6066 	set    	raw_cost = pa_currency.round_currency_amt(nvl(raw_cost,0) - nvl(l_raw_cost,0) ),
6067 		burdened_cost = pa_currency.round_currency_amt(nvl(burdened_cost,0) - nvl(l_burdened_cost,0) ),
6068 		labor_quantity = (to_number(
6069 			      decode(l_track_as_labor_flag,
6070 			         'Y', nvl(labor_quantity,0) - nvl(l_quantity,0),
6071 			          nvl(labor_quantity,0))) ),
6072 	   last_update_date = SYSDATE,
6073 	   last_update_login = l_last_update_login,
6074 	   last_updated_by = l_last_updated_by
6075      where  budget_version_id = l_budget_version_id;
6076 
6077 	    if (SQL%NOTFOUND) then
6078 	      Raise NO_DATA_FOUND;
6079 	    end if;
6080 --end if;
6081 
6082 --------------------------------------------------------------------------------
6083 
6084 
6085 
6086 	--this exception part is here because this procedure doesn't handle the exceptions itself.
6087    	EXCEPTION
6088 
6089    	WHEN ROW_ALREADY_LOCKED THEN RAISE;
6090 
6091 	WHEN OTHERS
6092 	THEN
6093 		CLOSE l_budget_line_rowid_csr;
6094 
6095 		gms_error_pkg.gms_message(x_err_name => 'GMS_UNEXPECTED_ERROR',
6096 					x_token_name1 => 'SQLCODE',
6097 					x_token_val1 => sqlcode,
6098 					x_token_name2 => 'SQLERRM',
6099 					x_token_val2 => sqlerrm,
6100 					x_err_code => x_err_code,
6101 					x_err_buff => x_err_stage);
6102 
6103 		APP_EXCEPTION.RAISE_EXCEPTION;
6104 
6105 	END;
6106 
6107    	FETCH l_budget_line_rowid_csr INTO l_budget_line_rowid;
6108 
6109    END LOOP;
6110 
6111    CLOSE l_budget_line_rowid_csr;
6112 
6113 
6114 --summarizing the totals in the table gms_budget_versions
6115 
6116     GMS_BUDGET_PUB.summerize_project_totals( x_budget_version_id => l_budget_version_id
6117     					    , x_err_code	  => x_err_code
6118 					    , x_err_stage	  => x_err_stage
6119 					    , x_err_stack	  => x_err_stack		);
6120 
6121 
6122     IF x_err_code <> 0
6123     THEN
6124 		gms_error_pkg.gms_message(x_err_name => 'GMS_SUMMERIZE_TOTALS_FAILED',
6125 					x_err_code => x_err_code,
6126 					x_err_buff => x_err_stage);
6127 
6128 		APP_EXCEPTION.RAISE_EXCEPTION;
6129     END IF;
6130 
6131 ------------------------------------------------------------------------------------
6132 -- Added for Bug:1325015
6133 
6134 	validate_budget(  x_budget_version_id => l_budget_version_id,
6135 			    x_award_id => l_award_id,
6136                             x_project_id => l_project_id,
6137                             x_task_id => l_task_id,
6138                             x_resource_list_member_id => p_resource_list_member_id,
6139                             x_start_date => l_start_date,
6140                             x_end_date => l_end_date,
6141                             x_return_status => x_err_code);
6142 
6143 	if x_err_code <> 0 then
6144 		ROLLBACK TO delete_budget_line_pub;
6145 	end if;
6146  -- Commented out this call for GMS enhancement : 5583170 as we don't validates across awards with this enahncement.
6147 /*
6148 	validate_budget_mf(  x_budget_version_id => l_budget_version_id,
6149 			    x_award_id => l_award_id,
6150                             x_project_id => l_project_id,
6151                             x_task_id => l_task_id,
6152                             x_resource_list_member_id => p_resource_list_member_id,
6153                             x_start_date => l_start_date,
6154                             x_end_date => l_end_date,
6155                             x_return_status => x_err_code);
6156 
6157 	if x_err_code <> 0 then
6158 		ROLLBACK TO delete_budget_line_pub;
6159 	end if;
6160 */
6161 ------------------------------------------------------------------------------------
6162 
6163     IF fnd_api.to_boolean(p_commit)
6164     THEN
6165     	COMMIT;
6166     END IF;
6167 
6168 	x_err_stack := l_old_stack;
6169 
6170 EXCEPTION
6171 	WHEN OTHERS
6172 	THEN
6173 		ROLLBACK TO delete_budget_line_pub;
6174 		RAISE;
6175 
6176 END delete_budget_line;
6177 
6178 ----------------------------------------------------------------------------------------
6179 -- Name:               update_budget
6180 -- Type:               Procedure
6181 -- Description:        This procedure can be used to update a working budget.
6182 --
6183 -- Called subprograms:
6184 --
6185 --
6186 --
6187 -- History:
6188 --
6189 
6190 PROCEDURE update_budget
6191 ( p_api_version_number		IN	NUMBER
6192  ,x_err_code			IN OUT NOCOPY 	NUMBER
6193  ,x_err_stage			IN OUT NOCOPY	VARCHAR2
6194  ,x_err_stack			IN OUT NOCOPY	VARCHAR2
6195  ,p_commit			IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
6196  ,p_init_msg_list		IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
6197  ,p_pm_product_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6198  ,p_project_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6199  ,p_project_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6200  ,p_award_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6201  ,p_award_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6202  ,p_budget_type_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6203  ,p_change_reason_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6204  ,p_description			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6205  ,p_budget_status_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6206  ,p_version_number		IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6207  ,p_current_flag		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6208  ,p_original_flag		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6209  ,p_current_original_flag	IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6210  ,p_resource_accumulated_flag	IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6211  ,p_resource_list_id		IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6212  ,p_version_name		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6213  ,p_budget_entry_method_code	IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6214  ,p_baselined_by_person_id	IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6215  ,p_baselined_date		IN	DATE			:= GMS_BUDGET_PUB.G_PA_MISS_DATE
6216  ,p_quantity			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6217  ,p_unit_of_measure		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6218  ,p_raw_cost			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6219  ,p_burdened_cost		IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6220  ,p_attribute_category		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6221  ,p_attribute1			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6222  ,p_attribute2			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6223  ,p_attribute3			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6224  ,p_attribute4			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6225  ,p_attribute5			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6226  ,p_attribute6			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6227  ,p_attribute7			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6228  ,p_attribute8			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6229  ,p_attribute9			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6230  ,p_attribute10			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6231  ,p_attribute11			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6232  ,p_attribute12			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6233  ,p_attribute13			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6234  ,p_attribute14			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6235  ,p_attribute15			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6236  ,p_first_budget_period		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6237  ,p_wf_status_code 		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR)
6238 
6239 IS
6240 
6241 
6242    --needed to check the validity of the incoming budget type
6243 
6244    CURSOR l_budget_type_csr
6245    	  (p_budget_type_code	VARCHAR2 )
6246    IS
6247    SELECT budget_amount_code
6248    FROM	  pa_budget_types
6249    WHERE  budget_type_code = p_budget_type_code;
6250 
6251    --needed to check whether budget line already exists
6252 
6253    CURSOR l_budget_line_csr
6254    	  (p_resource_assignment_id NUMBER
6255    	  ,p_budget_start_date	   DATE )
6256    IS
6257    SELECT 'X'
6258    FROM   gms_budget_lines
6259    WHERE  resource_assignment_id = p_resource_assignment_id
6260    AND    start_date = p_budget_start_date;
6261 
6262    --needed to get the current budget version data
6263 
6264    CURSOR l_budget_version_csr
6265           ( p_project_id NUMBER
6266           , p_award_id NUMBER
6267           , p_budget_type_code VARCHAR2 )
6268    IS
6269    SELECT budget_version_id
6270    ,      budget_entry_method_code
6271    ,      resource_list_id
6272    ,      change_reason_code
6273    ,      description
6274    FROM   gms_budget_versions
6275    WHERE  project_id 		= p_project_id
6276    AND    award_id              = p_award_id
6277    AND    budget_type_code	= p_budget_type_code
6278    AND    budget_status_code	in ('W','S');
6279 
6280    --needed to get the current budget entry method data
6281 
6282    CURSOR l_budget_entry_method_csr
6283           ( p_budget_entry_method_code VARCHAR2)
6284    IS
6285    SELECT time_phased_type_code
6286    ,	  entry_level_code
6287    ,	  categorization_code
6288    FROM   pa_budget_entry_methods
6289    WHERE  budget_entry_method_code = p_budget_entry_method_code;
6290 
6291    --needed to get the resource assignment for this budget_version / task / member combination
6292 
6293    CURSOR l_resource_assignment_csr
6294    	  (p_budget_version_id	NUMBER
6295    	  ,p_task_id		NUMBER
6296    	  ,p_member_id		NUMBER	)
6297    IS
6298    SELECT resource_assignment_id
6299    FROM   gms_resource_assignments
6300    WHERE  budget_version_id = p_budget_version_id
6301    AND	  task_id = p_task_id
6302    AND	  resource_list_member_id = p_member_id;
6303 
6304    -- needed to get the budget_start_date of a period
6305 
6306    CURSOR	l_budget_periods_csr
6307    		(p_period_name 		VARCHAR2
6308    		,p_period_type_code	VARCHAR2	)
6309    IS
6310    SELECT period_name
6311    FROM   pa_budget_periods_v
6312    WHERE  period_name = p_period_name
6313    AND 	  period_type_code = p_period_type_code;
6314 
6315    -- the uncategorized resource list
6316 
6317    CURSOR l_uncategorized_list_csr
6318    IS
6319    SELECT prlm.resource_list_member_id
6320    FROM   pa_resource_lists prl
6321    ,      pa_resource_list_members prlm
6322    ,	  pa_implementations pi
6323    WHERE  prl.resource_list_id = prlm.resource_list_id
6324    AND	  prl.business_group_id = pi.business_group_id
6325    AND    prl.uncategorized_flag='Y'
6326    and    NVL(prl.migration_code,'M') ='M' -- Bug 3626671
6327    and    NVL(prlm.migration_code,'M') ='M'; -- Bug 3626671;
6328 
6329 
6330    CURSOR	l_budget_change_reason_csr ( p_change_reason_code VARCHAR2 )
6331    IS
6332    SELECT 'x'
6333    FROM   pa_lookups
6334    WHERE  lookup_type = 'BUDGET CHANGE REASON'
6335    AND    lookup_code = p_change_reason_code;
6336 
6337    --needed for locking of budget rows
6338 
6339    CURSOR l_lock_budget_csr( p_budget_version_id NUMBER )
6340    IS
6341    SELECT 'x'
6342    FROM   gms_budget_versions bv
6343    ,      gms_resource_assignments ra
6344    ,      gms_budget_lines bl
6345    WHERE  bv.budget_version_id = p_budget_version_id
6346    AND    bv.budget_version_id = ra.budget_version_id (+)
6347    AND    ra.resource_assignment_id = bl.resource_assignment_id (+)
6348    FOR UPDATE OF bv.budget_version_id,ra.budget_version_id,bl.resource_assignment_id NOWAIT;
6349 
6350    l_api_name			CONSTANT	VARCHAR2(30) 		:= 'update_budget';
6351 
6352 
6353    l_project_id					NUMBER;
6354    l_task_id					NUMBER;
6355    l_award_id					NUMBER;
6356    l_dummy					VARCHAR2(1);
6357    l_budget_version_id				NUMBER;
6358    l_budget_entry_method_code			VARCHAR2(30);
6359    l_change_reason_code				VARCHAR2(30);
6360    l_description				VARCHAR2(255);
6361    l_budget_line_index				NUMBER;
6362 --   l_budget_line_in_rec				gms_budget_pub.budget_line_in_rec_type;
6363    l_time_phased_type_code			VARCHAR2(30);
6364    l_resource_assignment_id			NUMBER;
6365    l_budget_start_date				DATE;
6366    l_resource_list_id				NUMBER;
6367    l_resource_list_member_id			NUMBER;
6368    l_resource_name				pa_resource_list_members.alias%type; /*Changed for bug 4614242*/
6369    l_budget_amount_code				VARCHAR2(30);
6370    l_entry_level_code				VARCHAR2(30);
6371    l_categorization_code			VARCHAR2(30);
6372    l_resp_id					NUMBER := 0;
6373    l_user_id		                        NUMBER := 0;
6374    l_login_id					NUMBER := 0;
6375    l_baselined_by_person_id			NUMBER;
6376    l_baselined_date				DATE;
6377    l_module_name                                VARCHAR2(80);
6378 
6379    l_unit_of_measure				pa_resources.unit_of_measure%type;
6380    l_quantity					NUMBER;
6381    l_raw_cost					NUMBER;
6382    l_burdened_cost				NUMBER;
6383    l_attribute_category				VARCHAR2(30);
6384    l_attribute1					VARCHAR2(150);
6385    l_attribute2					VARCHAR2(150);
6386    l_attribute3					VARCHAR2(150);
6387    l_attribute4					VARCHAR2(150);
6388    l_attribute5					VARCHAR2(150);
6389    l_attribute6					VARCHAR2(150);
6390    l_attribute7					VARCHAR2(150);
6391    l_attribute8					VARCHAR2(150);
6392    l_attribute9					VARCHAR2(150);
6393    l_attribute10				VARCHAR2(150);
6394    l_attribute11				VARCHAR2(150);
6395    l_attribute12				VARCHAR2(150);
6396    l_attribute13				VARCHAR2(150);
6397    l_attribute14				VARCHAR2(150);
6398    l_attribute15				VARCHAR2(150);
6399    l_first_budget_period			VARCHAR2(30);
6400    l_wf_status_code 				VARCHAR2(30);
6401    l_old_stack					VARCHAR2(630);
6402 
6403    --used by dynamic SQL
6404    l_statement					VARCHAR2(2000);
6405    l_update_yes_flag				VARCHAR2(1);
6406    l_cursor_id					NUMBER;
6407    l_rows					NUMBER;
6408    l_new_resource_assignment			BOOLEAN;
6409    l_function_allowed				VARCHAR2(1);
6410    l_budget_rlmid                               NUMBER;
6411  /*  l_budget_alias                               VARCHAR2(30);    Commented for bug 4614242 as this is not used anymore */
6412    l_uncategorized_list_id			NUMBER;
6413    l_uncategorized_rlmid                        NUMBER;
6414    l_uncategorized_resid                        NUMBER;
6415    l_track_as_labor_flag                        VARCHAR2(1);
6416 
6417 
6418 -- p_multiple_task_msg     VARCHAR2(1) := 'T';
6419 
6420 BEGIN
6421 
6422  -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET - start');
6423 
6424 	x_err_code := 0;
6425 	l_old_stack := x_err_stack;
6426 	x_err_stack := x_err_stack ||'-> Update_budget';
6427 
6428 --	Initialize the message table if requested.
6429 
6430     IF FND_API.TO_BOOLEAN( p_init_msg_list )
6431     THEN
6432 
6433 	FND_MSG_PUB.initialize;
6434 
6435     END IF;
6436 
6437 --  Standard begin of API savepoint
6438 
6439     SAVEPOINT update_budget_pub;
6440 
6441 --  Standard call to check for call compatibility.
6442 
6443     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
6444     	    	    	    	    	 p_api_version_number	,
6445     	    	    	    	    	 l_api_name 	    	,
6446     	    	    	    	    	 G_PKG_NAME 	    	)
6447     THEN
6448 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
6449 				x_err_code => x_err_code,
6450 				x_err_buff => x_err_stage);
6451 
6452 	APP_EXCEPTION.RAISE_EXCEPTION;
6453     END IF;
6454 
6455     --product_code is mandatory
6456 
6457     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
6458     OR p_pm_product_code IS NULL
6459     THEN
6460 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_IS_MISSING',
6461 				x_err_code => x_err_code,
6462 				x_err_buff => x_err_stage);
6463 
6464 	APP_EXCEPTION.RAISE_EXCEPTION;
6465     END IF;
6466 
6467 ----------------------------------------------------------------------------
6468 -- If award_id is passed in then use it otherwise use the award_number
6469 -- that is passed in to fetch value of award_id from gms_awards table
6470 -- If both are missing then raise an error.
6471 
6472     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
6473         AND p_award_number IS NOT NULL)
6474     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
6475         AND p_award_id IS NOT NULL)
6476         THEN
6477    	convert_awardnum_to_id(p_award_number_in => p_award_number
6478    	                      ,p_award_id_in => p_award_id
6479    			      ,p_award_id_out => l_award_id
6480    			      ,x_err_code => x_err_code
6481    			      ,x_err_stage => x_err_stage
6482    			      ,x_err_stack => x_err_stack);
6483 
6484    	IF x_err_code <> 0
6485 	THEN
6486 		return;
6487 	END IF;
6488     ELSE
6489 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
6490 				x_err_code => x_err_code,
6491 				x_err_buff => x_err_stage);
6492 
6493 	APP_EXCEPTION.RAISE_EXCEPTION;
6494    END IF;
6495 --------------------------------------------------------------------------------
6496  -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET - after award info validation');
6497 
6498     l_resp_id := FND_GLOBAL.Resp_id;
6499     l_user_id := FND_GLOBAL.User_id;
6500     l_login_id := FND_GLOBAL.Login_id;
6501 
6502     l_module_name := 'GMS_PM_UPDATE_BUDGET';
6503 
6504     -- As part of enforcing award security, which would determine
6505     -- whether the user has the necessary privileges to update the award
6506     -- need to call the gms_security package
6507     -- If a user does not have privileges to update the award, then
6508     -- cannot update a budget
6509 
6510     gms_security.initialize (X_user_id        => l_user_id,
6511                             X_calling_module => l_module_name);
6512 
6513     -- Actions performed using the APIs would be subject to
6514     -- function security. If the responsibility does not allow
6515     -- such functions to be executed, the API should not proceed further
6516     -- since the user does not have access to such functions
6517 
6518 ---------------------------------------------------------------------------
6519 
6520 -- If project_id is passed in then use it otherwise use the project_number
6521 -- (segment1) that is passed in to fetch value of project_id from pa_projects
6522 -- table. If both are missing then raise an error.
6523 
6524 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
6525         AND p_project_number IS NOT NULL)
6526     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
6527         AND p_project_id IS NOT NULL)
6528    	THEN
6529    		convert_projnum_to_id(p_project_number_in => p_project_number
6530    		                      ,p_project_id_in => p_project_id
6531    				      ,p_project_id_out => l_project_id
6532    				      ,x_err_code => x_err_code
6533    				      ,x_err_stage => x_err_stage
6534    				      ,x_err_stack => x_err_stack);
6535 
6536 	   	IF x_err_code <> 0
6537     		THEN
6538 			return;
6539     		END IF;
6540 
6541 	ELSE
6542 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_NUM_ID_MISSING',
6543 					x_err_code => x_err_code,
6544 					x_err_buff => x_err_stage);
6545 
6546 		APP_EXCEPTION.RAISE_EXCEPTION;
6547 	END IF;
6548 -------------------------------------------------------------------------------
6549  -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET - after project info validation');
6550 
6551       -- Now verify whether award security allows the user to update
6552       -- award
6553       -- If a user does not have privileges to update the award, then
6554       -- cannot update a budget
6555 
6556       IF gms_security.allow_query (x_award_id => l_award_id ) = 'N' THEN
6557 
6558          -- The user does not have query privileges on this award
6559          -- Hence, cannot update the award. Raise error
6560 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_QRY',
6561 				x_err_code => x_err_code,
6562 				x_err_buff => x_err_stage);
6563 
6564 	APP_EXCEPTION.RAISE_EXCEPTION;
6565 
6566       ELSE
6567             -- If the user has query privileges, then check whether
6568             -- update privileges are also available
6569 
6570          IF gms_security.allow_update (x_award_id => l_award_id ) = 'N' THEN
6571 
6572             -- The user does not have update privileges on this award
6573             -- Hence , raise error
6574 
6575 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_UPD',
6576 					x_err_code => x_err_code,
6577 					x_err_buff => x_err_stage);
6578 
6579 		APP_EXCEPTION.RAISE_EXCEPTION;
6580         END IF;
6581      END IF;
6582 
6583 
6584  -- budget type code is mandatory
6585 
6586      IF p_budget_type_code IS NULL
6587      OR p_budget_type_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
6588      THEN
6589 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_MISSING',
6590 				x_err_code => x_err_code,
6591 				x_err_buff => x_err_stage);
6592 
6593 	APP_EXCEPTION.RAISE_EXCEPTION;
6594 
6595      ELSE
6596      		OPEN l_budget_type_csr( p_budget_type_code );
6597 
6598 		FETCH l_budget_type_csr INTO l_budget_amount_code;     -- used later for budget lines
6599 
6600 		IF l_budget_type_csr%NOTFOUND
6601 		THEN
6602 
6603 			CLOSE l_budget_type_csr;
6604 			gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_INVALID',
6605 						x_err_code => x_err_code,
6606 						x_err_buff => x_err_stage);
6607 
6608 			APP_EXCEPTION.RAISE_EXCEPTION;
6609 
6610 		END IF;
6611 
6612 		CLOSE l_budget_type_csr;
6613 
6614      END IF;
6615 
6616 
6617    OPEN l_budget_version_csr( l_project_id
6618    			    , l_award_id
6619    			    , p_budget_type_code );
6620 
6621    FETCH l_budget_version_csr INTO l_budget_version_id
6622    				 , l_budget_entry_method_code
6623    				 , l_resource_list_id
6624    				 , l_change_reason_code
6625    				 , l_description;
6626 
6627    IF l_budget_version_csr%NOTFOUND
6628    THEN
6629 	CLOSE l_budget_version_csr;
6630 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_VERSION',
6631 				x_err_code => x_err_code,
6632 				x_err_buff => x_err_stage);
6633 
6634 	APP_EXCEPTION.RAISE_EXCEPTION;
6635    END IF;
6636 
6637    CLOSE l_budget_version_csr;
6638 
6639 
6640    OPEN l_budget_entry_method_csr(l_budget_entry_method_code);
6641 
6642    FETCH l_budget_entry_method_csr into l_time_phased_type_code,
6643 					l_entry_level_code,
6644 					l_categorization_code;
6645    CLOSE l_budget_entry_method_csr;
6646 
6647  -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET - after locking budget');
6648 -----------------------------------------------------------------------------------------
6649 -- Start of change for Bug:2830539
6650 
6651 -- Validate the Change Reason Code passed in as a parameter
6652 
6653      IF (p_change_reason_code <> GMS_BUDGET_PUB.G_PA_MISS_CHAR) THEN
6654 
6655 	OPEN l_budget_change_reason_csr (p_change_reason_code);
6656 	FETCH l_budget_change_reason_csr INTO l_dummy;
6657 
6658 	IF l_budget_change_reason_csr%NOTFOUND THEN
6659 
6660        	CLOSE l_budget_change_reason_csr;
6661         	gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_CHANGE_REASON',
6662                	                 x_err_code => x_err_code,
6663                	                 x_err_buff => x_err_stage);
6664 
6665         	APP_EXCEPTION.RAISE_EXCEPTION;
6666    	END IF;
6667 
6668        	CLOSE l_budget_change_reason_csr;
6669      END IF;
6670 
6671 -- Validate the Budget Entry Method and Resource List passed in as a parameter.
6672 -- Even if either Budget Entry Method or Resource List is passed in then we
6673 -- have to validate against each other.
6674 
6675      IF ((p_budget_entry_method_code <> GMS_BUDGET_PUB.G_PA_MISS_CHAR) or (p_resource_list_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM)) THEN
6676 
6677 	validate_bem_resource_list(p_project_id => l_project_id,
6678 				   p_award_id => l_award_id,
6679 				   p_budget_entry_method_code => p_budget_entry_method_code,
6680 				   p_resource_list_id => p_resource_list_id);
6681 
6682      END IF;
6683 
6684 -- Once the above validations have passed update the GMS_BUDGET_VERSIONS table
6685 -- with the appropriate values.
6686 
6687     -- Bug 3104308 : Validation for p_first_budget_period .This will be fired only for
6688     --               GL/PA budget periods.
6689 
6690     IF  (p_first_budget_period <> GMS_BUDGET_PUB.G_PA_MISS_CHAR AND p_first_budget_period IS NOT NULL
6691           AND l_time_phased_type_code IN ('G','P')) THEN
6692 
6693        OPEN  l_budget_periods_csr(p_first_budget_period,l_time_phased_type_code);
6694        FETCH l_budget_periods_csr into l_first_budget_period;
6695        IF   l_budget_periods_csr%NOTFOUND THEN
6696 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_PERIOD_IS_INVALID',
6697 					x_err_code => x_err_code,
6698 					x_err_buff => x_err_stage);
6699 
6700 		APP_EXCEPTION.RAISE_EXCEPTION;
6701     	END IF;
6702     	CLOSE l_budget_periods_csr;
6703     END IF;
6704 
6705     OPEN l_lock_budget_csr( l_budget_version_id );
6706 
6707     UPDATE  GMS_BUDGET_VERSIONS
6708     SET     change_reason_code = decode(p_change_reason_code,
6709                                         GMS_BUDGET_PUB.G_MISS_CHAR,
6710                                         change_reason_code,
6711                                         p_change_reason_code),
6712             budget_entry_method_code = decode(p_budget_entry_method_code,
6713                                         GMS_BUDGET_PUB.G_MISS_CHAR,
6714                                         budget_entry_method_code,
6715                                         p_budget_entry_method_code),
6716             resource_list_id = decode(p_resource_list_id,
6717                                       GMS_BUDGET_PUB.G_MISS_NUM,
6718                                       resource_list_id,
6719                                       p_resource_list_id),
6720             current_original_flag = decode(p_current_original_flag,
6721                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6722                                       current_original_flag,
6723                                       p_current_original_flag),
6724             budget_status_code = decode(p_budget_status_code,
6725                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6726                                       budget_status_code,
6727                                       p_budget_status_code),
6728             version_name = decode(p_version_name,
6729                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6730                                       version_name,
6731                                       p_version_name),
6732             description = decode(p_description,
6733                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6734                                       description,
6735                                       p_description),
6736             attribute_category = decode(p_attribute_category,
6737                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6738                                       attribute_category,
6739                                       p_attribute_category),
6740             attribute1 = decode(p_attribute1,
6741                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6742                                       attribute1,
6743                                       p_attribute1),
6744             attribute2 = decode(p_attribute2,
6745                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6746                                       attribute2,
6747                                       p_attribute2),
6748             attribute3 = decode(p_attribute3,
6749                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6750                                       attribute3,
6751                                       p_attribute3),
6752             attribute4 = decode(p_attribute4,
6753                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6754                                       attribute4,
6755                                       p_attribute4),
6756             attribute5 = decode(p_attribute5,
6757                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6758                                       attribute5,
6759                                       p_attribute5),
6760             attribute6 = decode(p_attribute6,
6761                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6762                                       attribute6,
6763                                       p_attribute6),
6764             attribute7 = decode(p_attribute7,
6765                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6766                                       attribute7,
6767                                       p_attribute7),
6768             attribute8 = decode(p_attribute8,
6769                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6770                                       attribute8,
6771                                       p_attribute8),
6772             attribute9 = decode(p_attribute9,
6773                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6774                                       attribute9,
6775                                       p_attribute9),
6776             attribute10 = decode(p_attribute10,
6777                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6778                                       attribute10,
6779                                       p_attribute10),
6780             attribute11 = decode(p_attribute11,
6781                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6782                                       attribute11),
6783             attribute12 = decode(p_attribute12,
6784                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6785                                       attribute12,
6786                                       p_attribute12),
6787             attribute13 = decode(p_attribute13,
6788                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6789                                       attribute13,
6790                                       p_attribute13),
6791             attribute14 = decode(p_attribute14,
6792                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6793                                       attribute14,
6794                                       p_attribute14),
6795             attribute15 = decode(p_attribute15,
6796                                       GMS_BUDGET_PUB.G_MISS_CHAR,
6797                                       attribute15,
6798                                       p_attribute15),
6799 	    last_update_date = SYSDATE,
6800 	    last_updated_by = G_USER_ID,
6801 	    last_update_login = G_LOGIN_ID,
6802 	    first_budget_period = decode(p_first_budget_period,
6803 	                                 GMS_BUDGET_PUB.G_MISS_CHAR,
6804 					 first_budget_period,
6805 					 p_first_budget_period ) --Bug 3104308 : Added first_budget_period column in update
6806     WHERE   budget_version_id = l_budget_version_id;
6807 
6808    CLOSE l_lock_budget_csr;
6809 
6810 -- End of changes for Bug: 2830539
6811 -------------------------------------------------------------------
6812 
6813 -- check for overlapping dates
6814 -- Added the following IF Stmt for Bug: 2791285
6815 
6816    if l_time_phased_type_code in ('G','P','R') then
6817 
6818       gms_budget_utils.check_overlapping_dates( x_budget_version_id 	=> l_budget_version_id		--IN
6819     						  ,x_resource_name	=> l_resource_name		--OUT
6820     						  ,x_err_code		=> x_err_code		);
6821 
6822       IF x_err_code <> 0
6823       THEN
6824   	  gms_error_pkg.gms_message(x_err_name => 'GMS_CHECK_DATES_FAILED',
6825 				x_err_code => x_err_code,
6826 				x_err_buff => x_err_stage);
6827 
6828 	  APP_EXCEPTION.RAISE_EXCEPTION;
6829       END IF;
6830 
6831    end if; -- l_time_phased_type_code
6832 
6833         --summarizing the totals in the table gms_budget_versions
6834 
6835         gms_budget_pub.summerize_project_totals( x_budget_version_id => l_budget_version_id
6836     	    				        , x_err_code	  => x_err_code
6837 					    	, x_err_stage	  => x_err_stage
6838 					    	, x_err_stack	  => x_err_stack		);
6839 
6840 
6841 
6842     	IF x_err_code <> 0
6843     	THEN
6844 		gms_error_pkg.gms_message(x_err_name => 'GMS_SUMMERIZE_TOTALS_FAILED',
6845 					x_err_code => x_err_code,
6846 					x_err_buff => x_err_stage);
6847 
6848 		APP_EXCEPTION.RAISE_EXCEPTION;
6849     	END IF;
6850 
6851 
6852 --    END IF;  --if there are budget lines
6853 
6854 
6855     IF FND_API.TO_BOOLEAN( p_commit )
6856     THEN
6857 	COMMIT;
6858     END IF;
6859 
6860     x_err_stack := l_old_stack;
6861 
6862 EXCEPTION
6863 
6864 	WHEN OTHERS
6865 	THEN
6866 		ROLLBACK TO update_budget_pub;
6867 		RAISE;
6868 
6869 END update_budget;
6870 
6871 ----------------------------------------------------------------------------------------
6872 -- Name:               update_budget_line
6873 -- Type:               Procedure
6874 -- Description:        This procedure can be used to update a budgetline of an
6875 --                    existing WORKING budget.
6876 --
6877 --
6878 -- History:
6879 --
6880 
6881 PROCEDURE update_budget_line
6882 ( p_api_version_number		IN	NUMBER
6883  ,x_err_code			IN OUT NOCOPY	NUMBER
6884  ,x_err_stage			IN OUT NOCOPY	VARCHAR2
6885  ,x_err_stack			IN OUT NOCOPY	VARCHAR2
6886  ,p_commit			IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
6887  ,p_init_msg_list		IN	VARCHAR2 		:= GMS_BUDGET_PUB.G_GMS_FALSE
6888  ,p_pm_product_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6889  ,p_project_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6890  ,p_project_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6891  ,p_budget_type_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6892  ,p_task_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6893  ,p_task_number			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6894  ,p_award_id			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6895  ,p_award_number		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6896  ,p_resource_alias		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6897  ,p_resource_list_member_id	IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6898  ,p_budget_start_date		IN	DATE			:= GMS_BUDGET_PUB.G_PA_MISS_DATE
6899  ,p_budget_end_date		IN	DATE			:= GMS_BUDGET_PUB.G_PA_MISS_DATE
6900  ,p_period_name			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6901  ,p_description			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6902  ,p_change_reason_code		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6903  ,p_raw_cost			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6904  ,p_burdened_cost		IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6905  ,p_quantity			IN	NUMBER			:= GMS_BUDGET_PUB.G_PA_MISS_NUM
6906  ,p_unit_of_measure		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6907  ,p_track_as_labor_flag		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6908  ,p_attribute_category		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6909  ,p_attribute1			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6910  ,p_attribute2			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6911  ,p_attribute3			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6912  ,p_attribute4			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6913  ,p_attribute5			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6914  ,p_attribute6			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6915  ,p_attribute7			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6916  ,p_attribute8			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6917  ,p_attribute9			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6918  ,p_attribute10			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6919  ,p_attribute11			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6920  ,p_attribute12			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6921  ,p_attribute13			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6922  ,p_attribute14			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6923  ,p_attribute15			IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6924  ,p_raw_cost_source		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6925  ,p_burdened_cost_source	IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6926  ,p_quantity_source		IN	VARCHAR2		:= GMS_BUDGET_PUB.G_PA_MISS_CHAR
6927  )
6928 IS
6929 
6930 
6931   --and check for valid resource_list / member combination
6932 
6933    CURSOR	l_resource_csr
6934 		(p_resource_list_member_id NUMBER
6935 		,p_resource_list_id	   NUMBER)
6936    IS
6937    SELECT 'X'
6938    FROM   pa_resource_list_members
6939    WHERE  resource_list_id = p_resource_list_id
6940    AND    resource_list_member_id = p_resource_list_member_id;
6941 
6942    -- needed to get the fields associated to a budget entry method
6943 
6944    CURSOR	l_budget_entry_method_csr
6945    		(p_budget_entry_method_code pa_budget_entry_methods.budget_entry_method_code%type )
6946    IS
6947    SELECT *
6948    FROM   pa_budget_entry_methods
6949    WHERE  budget_entry_method_code = p_budget_entry_method_code
6950    AND 	  trunc(sysdate) BETWEEN trunc(start_date_active) and trunc(nvl(end_date_active,sysdate));
6951 
6952    -- needed to do validation on mandatory fields for budget lines
6953 
6954    CURSOR	l_budget_amount_code_csr
6955    		( p_budget_type_code	VARCHAR2 )
6956    IS
6957    SELECT budget_amount_code
6958    FROM	  pa_budget_types
6959    WHERE  budget_type_code = p_budget_type_code;
6960 
6961    -- Added for Bug:2830539
6962    -- needed to validate the change reason code for the Budget Line
6963    CURSOR	l_budget_change_reason_csr ( p_change_reason_code VARCHAR2 )
6964    IS
6965    SELECT 'x'
6966    FROM   pa_lookups
6967    WHERE  lookup_type = 'BUDGET CHANGE REASON'
6968    AND    lookup_code = p_change_reason_code;
6969 
6970    -- needed to get the budget_start_date of a period
6971 
6972    CURSOR	l_budget_periods_csr
6973    		(p_period_name 		VARCHAR2
6974    		,p_period_type_code	VARCHAR2	)
6975    IS
6976    SELECT trunc(period_start_date), trunc(period_end_date)
6977    FROM   pa_budget_periods_v
6978    WHERE  period_name = p_period_name
6979    AND 	  period_type_code = p_period_type_code;
6980 
6981 
6982    -- needed to get the related budget_version, entry_method and resource_list
6983 
6984    CURSOR	l_budget_version_csr
6985    		( p_project_id		NUMBER
6986    		, p_award_id		NUMBER
6987    		, p_budget_type_code	VARCHAR2)
6988    IS
6989    SELECT budget_version_id
6990    ,      budget_entry_method_code
6991    ,      resource_list_id
6992    FROM   gms_budget_versions
6993    WHERE  project_id 		= p_project_id
6994    AND    award_id 	        = p_award_id
6995    AND	  budget_type_code	= p_budget_type_code
6996    AND    budget_status_code	IN ('W','S');
6997 
6998 
6999    -- needed to get the member id of the uncategorized resource list
7000 
7001    CURSOR l_uncat_list_member_csr
7002    IS
7003    SELECT prlm.resource_list_member_id
7004    FROM   pa_resource_lists prl
7005    ,      pa_resource_list_members prlm
7006    ,	  pa_implementations pi
7007    WHERE  prl.resource_list_id = prlm.resource_list_id
7008    AND    prl.business_group_id = pi.business_group_id
7009    AND    prl.uncategorized_flag='Y'
7010    and    NVL(prl.migration_code,'M') ='M' -- Bug 3626671
7011    and    NVL(prlm.migration_code,'M') ='M'; -- Bug 3626671;
7012 
7013 
7014 
7015    --needed to get the resource assignment for this budget_version / task / member combination
7016 
7017    CURSOR l_resource_assignment_csr
7018    	  (p_budget_version_id	NUMBER
7019    	  ,p_task_id		NUMBER
7020    	  ,p_member_id		NUMBER	)
7021    IS
7022    SELECT resource_assignment_id
7023    FROM   gms_resource_assignments
7024    WHERE  budget_version_id = p_budget_version_id
7025    AND	  task_id = p_task_id
7026    AND	  resource_list_member_id = p_member_id;
7027 
7028 
7029    --needed to check whether budget line already exists
7030 
7031    CURSOR l_budget_line_csr
7032    	  (p_resource_assigment_id NUMBER
7033    	  ,p_budget_start_date	   DATE )
7034    IS
7035    SELECT rowidtochar(rowid)
7036    FROM   gms_budget_lines
7037    WHERE  resource_assignment_id = p_resource_assigment_id
7038    AND    trunc(start_date) = nvl(trunc(p_budget_start_date),trunc(start_date));
7039 
7040    --needed to lock the budget line row
7041    CURSOR l_lock_budget_line_csr( p_budget_line_rowid VARCHAR2)
7042    IS
7043    SELECT 'x'
7044    FROM   gms_budget_lines
7045    WHERE  rowid = p_budget_line_rowid
7046    FOR UPDATE NOWAIT;
7047 ---------------------------------------------------------------
7048    l_api_name			CONSTANT	VARCHAR2(30) 		:= 'update_budget_line';
7049    i						NUMBER;
7050 
7051    l_project_id					NUMBER;
7052    l_task_id					NUMBER;
7053    l_award_id					NUMBER;
7054    l_alias_not_found_ok		CONSTANT	VARCHAR2(1)		:= 'Y';
7055    l_budget_version_id				NUMBER;
7056    l_budget_entry_method_code			VARCHAR2(30);
7057    l_resource_list_id				NUMBER;
7058    l_time_phased_type_code			VARCHAR2(30);
7059    l_resource_list_member_id			NUMBER;
7060    l_period_name				VARCHAR2(20);
7061    l_budget_start_date				DATE;
7062    l_budget_end_date				DATE;
7063    l_raw_cost					NUMBER;
7064    l_burdened_cost				NUMBER;
7065    l_quantity					NUMBER;
7066    l_unit_of_measure				pa_resources.unit_of_measure%type;
7067    l_track_as_labor_flag			pa_resource_list_members.track_as_labor_flag%type;
7068    l_resource_assignment_id			gms_resource_assignments.resource_assignment_id%type;
7069    l_budget_entry_method_rec			pa_budget_entry_methods%rowtype;
7070    l_wbs_level					NUMBER;
7071    l_return_status_task				NUMBER;
7072    l_budget_amount_code				pa_budget_types.budget_amount_code%type;
7073    l_description				VARCHAR2(255);
7074    l_change_reason_code				VARCHAR2(30); -- NUMBER; BUG 2739513, this should be varchar2 not number
7075    l_project_start_date				DATE;
7076    l_project_end_date				DATE;
7077    l_task_start_date				DATE;
7078    l_task_end_date				DATE;
7079  /*  l_resource_name				VARCHAR2(30);      Commented for bug 4614242 as this is not used anywhere */
7080    l_dummy					VARCHAR2(1);
7081    l_budget_line_rowid				VARCHAR(20);
7082    l_function_allowed				VARCHAR2(1);
7083    l_resp_id					NUMBER := 0;
7084    l_user_id		                        NUMBER := 0;
7085    l_login_id					NUMBER := 0;
7086    l_module_name                                VARCHAR2(80);
7087    l_attribute_category				VARCHAR2(30);
7088    l_attribute1					VARCHAR2(150);
7089    l_attribute2					VARCHAR2(150);
7090    l_attribute3					VARCHAR2(150);
7091    l_attribute4					VARCHAR2(150);
7092    l_attribute5					VARCHAR2(150);
7093    l_attribute6					VARCHAR2(150);
7094    l_attribute7					VARCHAR2(150);
7095    l_attribute8					VARCHAR2(150);
7096    l_attribute9					VARCHAR2(150);
7097    l_attribute10				VARCHAR2(150);
7098    l_attribute11				VARCHAR2(150);
7099    l_attribute12				VARCHAR2(150);
7100    l_attribute13				VARCHAR2(150);
7101    l_attribute14				VARCHAR2(150);
7102    l_attribute15				VARCHAR2(150);
7103    l_old_stack					VARCHAR2(630);
7104 
7105 BEGIN -- update_budget_line
7106 
7107 -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET_LINE - start');
7108 
7109 	x_err_code := 0;
7110 	l_old_stack := x_err_stack;
7111 	x_err_stack := x_err_stack ||'-> Update_Budget_Line';
7112 
7113 --	Initialize the message table if requested.
7114 
7115     IF FND_API.TO_BOOLEAN( p_init_msg_list )
7116     THEN
7117 
7118 	FND_MSG_PUB.initialize;
7119 
7120     END IF;
7121 
7122 --  Standard begin of API savepoint
7123 
7124     SAVEPOINT update_budget_line_pub;
7125 
7126 
7127 --  Standard call to check for call compatibility.
7128 
7129     IF NOT FND_API.Compatible_API_Call ( g_api_version_number	,
7130     	    	    	    	    	 p_api_version_number	,
7131     	    	    	    	    	 l_api_name 	    	,
7132     	    	    	    	    	 G_PKG_NAME 	    	)
7133     THEN
7134 	gms_error_pkg.gms_message(x_err_name => 'GMS_INCOMPATIBLE_API_CALL',
7135 				x_err_code => x_err_code,
7136 				x_err_buff => x_err_stage);
7137 
7138 	APP_EXCEPTION.RAISE_EXCEPTION;
7139     END IF;
7140 
7141     --product_code is mandatory
7142 
7143     IF p_pm_product_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
7144     OR p_pm_product_code IS NULL
7145     THEN
7146 	gms_error_pkg.gms_message(x_err_name => 'GMS_PRODUCT_CODE_MISSING',
7147 				x_err_code => x_err_code,
7148 				x_err_buff => x_err_stage);
7149 
7150 	APP_EXCEPTION.RAISE_EXCEPTION;
7151     END IF;
7152 
7153 ----------------------------------------------------------------------------
7154 -- If award_id is passed in then use it otherwise use the award_number
7155 -- that is passed in to fetch value of award_id from gms_awards table
7156 -- If both are missing then raise an error.
7157 
7158     IF (p_award_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
7159         AND p_award_number IS NOT NULL)
7160     OR (p_award_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
7161         AND p_award_id IS NOT NULL)
7162         THEN
7163    	convert_awardnum_to_id(p_award_number_in => p_award_number
7164    	                      ,p_award_id_in => p_award_id
7165    			      ,p_award_id_out => l_award_id
7166    			      ,x_err_code => x_err_code
7167    			      ,x_err_stage => x_err_stage
7168    			      ,x_err_stack => x_err_stack);
7169 
7170    	IF x_err_code <> 0
7171 	THEN
7172 		return;
7173 	END IF;
7174     ELSE
7175 	gms_error_pkg.gms_message(x_err_name => 'GMS_AWARD_NUM_ID_MISSING',
7176 				x_err_code => x_err_code,
7177 				x_err_buff => x_err_stage);
7178 
7179 	APP_EXCEPTION.RAISE_EXCEPTION;
7180    END IF;
7181 --------------------------------------------------------------------------------
7182 
7183 -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET_LINE - after award info validation');
7184 
7185     l_resp_id := FND_GLOBAL.Resp_id;
7186     l_user_id := FND_GLOBAL.User_id;
7187     l_login_id := FND_GLOBAL.login_id;
7188 
7189     l_module_name := 'GMS_PM_UPDATE_BUDGET_LINE';
7190 
7191     -- As part of enforcing award security, which would determine
7192     -- whether the user has the necessary privileges to update the award
7193     -- need to call the gms_security package
7194     -- If a user does not have privileges to update the award, then
7195     -- cannot update a budget line
7196 
7197     gms_security.initialize (X_user_id        => l_user_id,
7198                             X_calling_module => l_module_name);
7199 
7200 --------------------------------------------------------------------------------
7201 
7202 -- If project_id is passed in then use it otherwise use the project_number
7203 -- (segment1) that is passed in to fetch value of project_id from pa_projects
7204 -- table. If both are missing then raise an error.
7205 
7206 	IF (p_project_number <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
7207         AND p_project_number IS NOT NULL)
7208     	OR (p_project_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
7209         AND p_project_id IS NOT NULL)
7210    	THEN
7211    		convert_projnum_to_id(p_project_number_in => p_project_number
7212    		                      ,p_project_id_in => p_project_id
7213    				      ,p_project_id_out => l_project_id
7214    				      ,x_err_code => x_err_code
7215    				      ,x_err_stage => x_err_stage
7216    				      ,x_err_stack => x_err_stack);
7217 
7218 	   	IF x_err_code <> 0
7219     		THEN
7220 			return;
7221     		END IF;
7222 
7223 	ELSE
7224 		gms_error_pkg.gms_message(x_err_name => 'GMS_PROJ_NUM_ID_MISSING',
7225 					x_err_code => x_err_code,
7226 					x_err_buff => x_err_stage);
7227 
7228 		APP_EXCEPTION.RAISE_EXCEPTION;
7229 	END IF;
7230 -------------------------------------------------------------------------------
7231 
7232 -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET_LINE - after project info validation');
7233 
7234      IF l_project_id IS NULL
7235      THEN
7236 	gms_error_pkg.gms_message(x_err_name => 'GMS_PROJECT_MISSING',
7237 				x_err_code => x_err_code,
7238 				x_err_buff => x_err_stage);
7239 
7240 	APP_EXCEPTION.RAISE_EXCEPTION;
7241      END IF;
7242 
7243       -- Now verify whether award security allows the user to update
7244       -- award
7245       -- If a user does not have privileges to update the award, then
7246       -- cannot update a budget line
7247 
7248       IF gms_security.allow_query (x_award_id => l_award_id ) = 'N' THEN
7249 
7250          -- The user does not have query privileges on this award
7251          -- Hence, cannot update the award. Raise error
7252 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_QRY',
7253 					x_err_code => x_err_code,
7254 					x_err_buff => x_err_stage);
7255 
7256 		APP_EXCEPTION.RAISE_EXCEPTION;
7257       ELSE
7258             -- If the user has query privileges, then check whether
7259             -- update privileges are also available
7260 
7261          IF gms_security.allow_update (x_award_id => l_award_id ) = 'N' THEN
7262 
7263             -- The user does not have update privileges on this award
7264             -- Hence , raise error
7265 
7266 		gms_error_pkg.gms_message(x_err_name => 'GMS_AWD_SECURITY_ENFORCED_UPD',
7267 					x_err_code => x_err_code,
7268 					x_err_buff => x_err_stage);
7269 
7270 		APP_EXCEPTION.RAISE_EXCEPTION;
7271 
7272         END IF;
7273      END IF;
7274 
7275 
7276  -- budget type code is mandatory
7277 --  dbms_output.put_line('Checking budget type code');
7278 
7279      IF p_budget_type_code IS NULL
7280      OR p_budget_type_code = GMS_BUDGET_PUB.G_PA_MISS_CHAR
7281      THEN
7282 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_MISSING',
7283 				x_err_code => x_err_code,
7284 				x_err_buff => x_err_stage);
7285 
7286 	APP_EXCEPTION.RAISE_EXCEPTION;
7287      ELSE
7288 	OPEN l_budget_amount_code_csr( p_budget_type_code );
7289 
7290 	FETCH l_budget_amount_code_csr
7291 	INTO l_budget_amount_code;     		--will be used later on during validation of Budget lines.
7292 
7293 		IF l_budget_amount_code_csr%NOTFOUND
7294 		THEN
7295 			gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_TYPE_IS_INVALID',
7296 					x_err_code => x_err_code,
7297 					x_err_buff => x_err_stage);
7298 
7299 			APP_EXCEPTION.RAISE_EXCEPTION;
7300 		END IF;
7301 
7302 		CLOSE l_budget_amount_code_csr;
7303 
7304      END IF;
7305 
7306  -- Get the budget_version_id, budget_entry_method_code and resource_list_id from table pa_budget_version
7307 
7308 --  dbms_output.put_line('Get budget version, entry method and resource list');
7309 
7310     OPEN l_budget_version_csr( l_project_id
7311                              , l_award_id
7312     			     , p_budget_type_code );
7313     FETCH l_budget_version_csr
7314     INTO  l_budget_version_id
7315     ,     l_budget_entry_method_code
7316     ,     l_resource_list_id;
7317 
7318     IF l_budget_version_csr%NOTFOUND
7319     THEN
7320 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_BUDGET_VERSION',
7321 				x_err_code => x_err_code,
7322 				x_err_buff => x_err_stage);
7323 
7324 	APP_EXCEPTION.RAISE_EXCEPTION;
7325     END IF;
7326 
7327     CLOSE l_budget_version_csr;
7328 
7329 
7330  -- entry method code is mandatory (and a nullible field in table pa_budget_versions)
7331 
7332     IF l_budget_entry_method_code IS NULL
7333     THEN
7334 	gms_error_pkg.gms_message(x_err_name => 'GMS_ENTRY_METHOD_IS_MISSING',
7335 				x_err_code => x_err_code,
7336 				x_err_buff => x_err_stage);
7337 
7338 	APP_EXCEPTION.RAISE_EXCEPTION;
7339     END IF;
7340 
7341 -- check validity of this budget entry method code, and store associated fields in record
7342 -- dbms_output.put_line('check validity of entry method');
7343 
7344     OPEN l_budget_entry_method_csr(l_budget_entry_method_code);
7345     FETCH l_budget_entry_method_csr INTO l_budget_entry_method_rec;
7346 
7347     IF   l_budget_entry_method_csr%NOTFOUND
7348     THEN
7349 	gms_error_pkg.gms_message(x_err_name => 'GMS_ENTRY_METHOD_IS_INVALID',
7350 				x_err_code => x_err_code,
7351 				x_err_buff => x_err_stage);
7352 
7353 	APP_EXCEPTION.RAISE_EXCEPTION;
7354     END IF;
7355 
7356     CLOSE l_budget_entry_method_csr;
7357 
7358     IF p_period_name <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
7359     AND p_period_name IS NOT NULL
7360     THEN
7361 
7362     	OPEN l_budget_periods_csr( p_period_name
7363     				  ,l_budget_entry_method_rec.time_phased_type_code);
7364 
7365     	FETCH l_budget_periods_csr INTO l_budget_start_date, l_budget_end_date; -- l_budget_end_date added new
7366 
7367     	IF   l_budget_periods_csr%NOTFOUND
7368     	THEN
7369 		gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_PERIOD_IS_INVALID',
7370 					x_err_code => x_err_code,
7371 					x_err_buff => x_err_stage);
7372 
7373 		APP_EXCEPTION.RAISE_EXCEPTION;
7374     	END IF;
7375 
7376     	CLOSE l_budget_periods_csr;
7377 
7378     ELSIF  p_budget_start_date <> GMS_BUDGET_PUB.G_PA_MISS_DATE
7379        AND p_budget_start_date IS NOT NULL
7380     THEN
7381 
7382     	l_budget_start_date := trunc(p_budget_start_date);
7383 
7384 -- if a valid p_budget_end_date is passed in then use it to update the table
7385 
7386 		IF  p_budget_end_date <> GMS_BUDGET_PUB.G_PA_MISS_DATE AND p_budget_end_date IS NOT NULL
7387        		THEN
7388        			l_budget_end_date := trunc(p_budget_end_date);
7389        		END IF;
7390     ELSE
7391 	gms_error_pkg.gms_message(x_err_name => 'GMS_START_DATE_MISSING',
7392 				x_err_code => x_err_code,
7393 				x_err_buff => x_err_stage);
7394 
7395 	APP_EXCEPTION.RAISE_EXCEPTION;
7396     END IF;
7397 
7398 
7399         -- convert p_task_number to p_task_id
7400 	-- if both task id and number are not passed or NULL, we will assume that budgetting is
7401 	-- done at the project level and that requires l_task_id to be '0'
7402 
7403 
7404         IF (p_task_id = GMS_BUDGET_PUB.G_PA_MISS_NUM
7405             OR p_task_id IS NULL OR p_task_id = 0 )
7406         AND (p_task_number = GMS_BUDGET_PUB.G_PA_MISS_CHAR
7407              OR p_task_number IS NULL )
7408         THEN
7409 
7410         	l_task_id := 0;
7411         ELSE
7412 		convert_tasknum_to_id ( p_project_id_in => l_project_id
7413 				,p_task_id_in => p_task_id
7414 				,p_task_number_in => p_task_number
7415 				,p_task_id_out => l_task_id
7416 				,x_err_code => x_err_code
7417 				,x_err_stage => x_err_stage
7418 				,x_err_stack => x_err_stack);
7419 
7420 		IF x_err_code <> 0
7421 		THEN
7422 			gms_error_pkg.gms_message(x_err_name => 'GMS_TASK_VALIDATE_FAIL',  -- jjj - check message tag
7423  						x_err_code => x_err_code,
7424 						x_err_buff => x_err_stage);
7425 
7426 			APP_EXCEPTION.RAISE_EXCEPTION;
7427 		END IF;
7428 
7429         END IF;
7430 
7431     -- convert resource alias to (resource) member id
7432 
7433     -- if resource alias is (passed and not NULL)
7434     -- and resource member is (passed and not NULL)
7435     -- then we convert the alias to the id
7436     -- else we default to the uncategorized resource member
7437 
7438    IF (p_resource_alias <> GMS_BUDGET_PUB.G_PA_MISS_CHAR
7439        AND p_resource_alias IS NOT NULL)
7440 
7441    OR (p_resource_list_member_id <> GMS_BUDGET_PUB.G_PA_MISS_NUM
7442        AND p_resource_list_member_id IS NOT NULL)
7443    THEN
7444      	convert_listmem_alias_to_id
7445      		(p_resource_list_id_in	=> l_resource_list_id 	-- IN
7446 	     	,p_reslist_member_alias_in => p_resource_alias 	-- IN
7447 	     	,p_resource_list_member_id_in => p_resource_list_member_id
7448 	     	,p_resource_list_member_id_out	=> l_resource_list_member_id
7449 	     	,x_err_code => x_err_code
7450 	     	,x_err_stage => x_err_stage
7451 	     	,x_err_stack => x_err_stack);
7452 
7453      	IF x_err_code <> 0
7454      	THEN
7455 		gms_error_pkg.gms_message(x_err_name => 'GMS_RES_VALIDATE_FAIL',  -- jjj - check message tag
7456 					x_err_code => x_err_code,
7457 					x_err_buff => x_err_stage);
7458 
7459 		APP_EXCEPTION.RAISE_EXCEPTION;
7460 
7461      	END IF;
7462 
7463 
7464    ELSE
7465 
7466 	-- if the budget is not categorized by resource (categorization_code = 'N')
7467 	-- then get the member id for the uncategorized resource list
7468 
7469     	IF l_budget_entry_method_rec.categorization_code = 'N'
7470     	THEN
7471 
7472 		OPEN l_uncat_list_member_csr;
7473 		FETCH l_uncat_list_member_csr INTO l_resource_list_member_id;
7474 		CLOSE l_uncat_list_member_csr;
7475 
7476 	ELSIF l_budget_entry_method_rec.categorization_code = 'R'
7477 	THEN
7478 		gms_error_pkg.gms_message(x_err_name => 'GMS_RESOURCE_IS_MISSING',
7479 					x_err_code => x_err_code,
7480 					x_err_buff => x_err_stage);
7481 
7482 		APP_EXCEPTION.RAISE_EXCEPTION;
7483 	END IF;
7484 
7485    END IF;
7486 
7487     --check whether this is a valid member for this list
7488 
7489     OPEN l_resource_csr( l_resource_list_member_id
7490     			,l_resource_list_id	);
7491 
7492     FETCH l_resource_csr INTO l_dummy;
7493 
7494     IF l_resource_csr%NOTFOUND
7495     THEN
7496 
7497 	CLOSE l_resource_csr;
7498 		gms_error_pkg.gms_message(x_err_name => 'GMS_LIST_MEMBER_INVALID',
7499 					x_err_code => x_err_code,
7500 					x_err_buff => x_err_stage);
7501 
7502 		APP_EXCEPTION.RAISE_EXCEPTION;
7503     END IF;
7504 
7505     CLOSE l_resource_csr;
7506 
7507 -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET_LINE - after resource info validation');
7508 
7509     --get the resource assignment id
7510 
7511     OPEN l_resource_assignment_csr( l_budget_version_id
7512     				   ,l_task_id
7513     				   ,l_resource_list_member_id		);
7514 
7515     FETCH l_resource_assignment_csr INTO l_resource_assignment_id;
7516 
7517     IF l_resource_assignment_csr%NOTFOUND
7518     THEN
7519 	CLOSE l_resource_assignment_csr;
7520 	gms_error_pkg.gms_message(x_err_name => 'GMS_NO_RESOURCE_ASSIGNMENT',
7521 				x_err_code => x_err_code,
7522 				x_err_buff => x_err_stage);
7523 
7524 	APP_EXCEPTION.RAISE_EXCEPTION;
7525     END IF;
7526 
7527     CLOSE l_resource_assignment_csr;
7528 
7529 -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET_LINE - after checking existence of resource assignment');
7530 
7531 --  dbms_output.put_line('Checking existence of budget line');
7532     OPEN l_budget_line_csr( l_resource_assignment_id
7533     			   ,l_budget_start_date	);
7534 
7535     FETCH l_budget_line_csr INTO l_budget_line_rowid;
7536 
7537     IF l_budget_line_csr%NOTFOUND
7538     THEN
7539 
7540 	CLOSE l_budget_line_csr;
7541 	gms_error_pkg.gms_message(x_err_name => 'GMS_BUDGET_LINE_NOT_FOUND',
7542 				x_err_code => x_err_code,
7543 				x_err_buff => x_err_stage);
7544 
7545 	APP_EXCEPTION.RAISE_EXCEPTION;
7546 
7547     END IF;
7548 
7549     CLOSE l_budget_line_csr;
7550 ------------------------------------------------------------------------------------------------------
7551 -- Start of changes for Bug:2830539
7552 
7553     IF p_change_reason_code <> GMS_BUDGET_PUB.G_PA_MISS_CHAR THEN
7554 
7555 	OPEN l_budget_change_reason_csr (p_change_reason_code);
7556 	FETCH l_budget_change_reason_csr INTO l_dummy;
7557 
7558 	IF l_budget_change_reason_csr%NOTFOUND THEN
7559 
7560        	        CLOSE l_budget_change_reason_csr;
7561         	gms_error_pkg.gms_message(x_err_name => 'GMS_INVALID_CHANGE_REASON',
7562                	                 x_err_code => x_err_code,
7563                	                 x_err_buff => x_err_stage);
7564 
7565         	APP_EXCEPTION.RAISE_EXCEPTION;
7566    	END IF;
7567 
7568        	CLOSE l_budget_change_reason_csr;
7569 
7570     END IF;
7571 
7572 -- dbms_output.put_line('GMS_BUDGET_PUB.UPDATE_BUDGET_LINE - after checking existence of budget line');
7573 
7574 -- Once the above validations have passed update the GMS_BUDGET_LINES table
7575 -- with the appropriate values.
7576 
7577     OPEN l_lock_budget_line_csr( l_budget_line_rowid );
7578 
7579     UPDATE  GMS_BUDGET_LINES
7580     SET     change_reason_code = decode(p_change_reason_code,
7581                                         GMS_BUDGET_PUB.G_MISS_CHAR,
7582                                         change_reason_code,
7583                                         p_change_reason_code),
7584             burdened_cost = decode(p_burdened_cost,
7585                                         GMS_BUDGET_PUB.G_MISS_NUM,
7586                                         burdened_cost,
7587                                         p_burdened_cost),
7588             description = decode(p_description,
7589                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7590                                       description,
7591                                       p_description),
7592             attribute_category = decode(p_attribute_category,
7593                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7594                                       attribute_category,
7595                                       p_attribute_category),
7596             attribute1 = decode(p_attribute1,
7597                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7598                                       attribute1,
7599                                       p_attribute1),
7600             attribute2 = decode(p_attribute2,
7601                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7602                                       attribute2,
7603                                       p_attribute2),
7604             attribute3 = decode(p_attribute3,
7605                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7606                                       attribute3,
7607                                       p_attribute3),
7608             attribute4 = decode(p_attribute4,
7609                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7610                                       attribute4,
7611                                       p_attribute4),
7612             attribute5 = decode(p_attribute5,
7613                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7614                                       attribute5,
7615                                       p_attribute5),
7616             attribute6 = decode(p_attribute6,
7617                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7618                                       attribute6,
7619                                       p_attribute6),
7620             attribute7 = decode(p_attribute7,
7621                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7622                                       attribute7,
7623                                       p_attribute7),
7624             attribute8 = decode(p_attribute8,
7625                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7626                                       attribute8,
7627                                       p_attribute8),
7628             attribute9 = decode(p_attribute9,
7629                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7630                                       attribute9,
7631                                       p_attribute9),
7632             attribute10 = decode(p_attribute10,
7633                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7634                                       attribute10,
7635                                       p_attribute10),
7636             attribute11 = decode(p_attribute11,
7637                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7638                                       attribute11),
7639             attribute12 = decode(p_attribute12,
7640                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7641                                       attribute12,
7642                                       p_attribute12),
7643             attribute13 = decode(p_attribute13,
7644                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7645                                       attribute13,
7646                                       p_attribute13),
7647             attribute14 = decode(p_attribute14,
7648                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7649                                       attribute14,
7650                                       p_attribute14),
7651             attribute15 = decode(p_attribute15,
7652                                       GMS_BUDGET_PUB.G_MISS_CHAR,
7653                                       attribute15,
7654                                       p_attribute15),
7655 	    last_update_date = SYSDATE,
7656 	    last_updated_by = G_USER_ID,
7657 	    last_update_login = G_LOGIN_ID
7658     WHERE   resource_assignment_id = l_resource_assignment_id
7659     AND	    start_date = l_budget_start_date
7660     AND     end_date = l_budget_end_date;
7661 
7662     CLOSE l_lock_budget_line_csr;
7663 
7664 -- End of changes for Bug:2830539
7665 ----------------------------------------------------------------------------------
7666 
7667 --We don't have to check for overlapping dates because begin and and date can not be changed.
7668 
7669             GMS_BUDGET_PUB.summerize_project_totals( x_budget_version_id => l_budget_version_id
7670     	    				            , x_err_code	  => x_err_code
7671 					    	    , x_err_stage	  => x_err_stage
7672 					    	    , x_err_stack	  => x_err_stack		);
7673 
7674 
7675     	IF x_err_code <> 0
7676     	THEN
7677 		gms_error_pkg.gms_message(x_err_name => 'GMS_SUMMERIZE_TOTALS_FAILED',
7678 					x_err_code => x_err_code,
7679 					x_err_buff => x_err_stage);
7680 
7681 		APP_EXCEPTION.RAISE_EXCEPTION;
7682     	END IF;
7683 
7684 ------------------------------------------------------------------------------------
7685 -- Added for Bug:1325015
7686 
7687 	validate_budget(  x_budget_version_id => l_budget_version_id,
7688 			    x_award_id => l_award_id,
7689                             x_project_id => l_project_id,
7690                             x_task_id => l_task_id,
7691                             x_resource_list_member_id => p_resource_list_member_id,
7692                             x_start_date => l_budget_start_date,
7693                             x_end_date => l_budget_end_date,
7694                             x_return_status => x_err_code);
7695 
7696 	if x_err_code <> 0 then
7697 		ROLLBACK TO update_budget_line_pub;
7698 	END IF;
7699  -- Commented out this call for GMS enhancement : 5583170 as we don't validates across awards with this enahncement.
7700 /*
7701 	validate_budget_mf(  x_budget_version_id => l_budget_version_id,
7702 			    x_award_id => l_award_id,
7703                             x_project_id => l_project_id,
7704                             x_task_id => l_task_id,
7705                             x_resource_list_member_id => p_resource_list_member_id,
7706                             x_start_date => l_budget_start_date,
7707                             x_end_date => l_budget_end_date,
7708                             x_return_status => x_err_code);
7709 
7710 	if x_err_code <> 0 then
7711 		ROLLBACK TO update_budget_line_pub;
7712 	end if;
7713 */
7714 ------------------------------------------------------------------------------------
7715 
7716     IF FND_API.TO_BOOLEAN( p_commit )
7717     THEN
7718 	COMMIT;
7719     END IF;
7720 
7721     x_err_stack := l_old_stack;
7722 
7723 EXCEPTION
7724 
7725 	WHEN OTHERS
7726 	THEN
7727 		ROLLBACK TO update_budget_line_pub;
7728 		RAISE;
7729 
7730 END update_budget_line;
7731 ----------------------------------------------------------------------------------------
7732 
7733 end GMS_BUDGET_PUB;