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