[Home] [Help]
PACKAGE BODY: APPS.PA_FP_CI_MERGE
Source
1 PACKAGE BODY PA_FP_CI_MERGE AS
2 /* $Header: PAFPCIMB.pls 120.14.12010000.2 2008/09/12 22:44:57 skkoppul ship $ */
3 -- Bug Fix: 4569365. Removed MRC code.
4 -- g_mrc_exception EXCEPTION; /* FPB2 */
5
6 l_module_name VARCHAR2(100) := 'pa.plsql.pa_fp_ci_merge';
7 P_PA_DEBUG_MODE varchar2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
8
9 --This record type will contain items for budget version id, ci id and the code which indicates whether
10 --the type of impact that can be implemented into the target version. Bug 3550073
11 --The valid values for impact_type can be
12 ----COST
13 ----REVENUE
14 ----BOTH (If both cost and revenue ci versions can be implemented)
15 ----ALL(If the the ci id has ALL impact and if it can be implemented)
16 ----NONE(Impact can be implemented)
17 --impl_cost_flag and impl_rev_flag will be either Y or N indicating whether the ci id can be implemented in
18 --the budget version id or not
19 TYPE budget_ci_map_rec IS RECORD
20 (budget_version_id pa_budget_versions.budget_version_id%TYPE
21 ,ci_id pa_control_items.ci_id%TYPE
22 ,impact_type_code VARCHAR2(10)
23 ,impl_cost_flag VARCHAR2(1)
24 ,impl_rev_flag VARCHAR2(1));
25
26 TYPE budget_ci_map_rec_tbl_type IS TABLE OF budget_ci_map_rec
27 INDEX BY BINARY_INTEGER;
28
29 --This record type will be used in change order merge. This will help in identifying the target resource assignment
30 --id corresponding to a task id and resource list member id in the target. ra_dml_code can be either INSERT or UPDATE.
31 --INSERT indicates that the target resource assignment has to be inserted . UPDATE indicates that the target
32 --resource assignment already exists.Bug 3678314
33 TYPE res_assmt_map_rec IS RECORD
34 (task_id pa_tasks.task_id%TYPE
35 ,resource_list_member_id pa_resource_list_members.resource_list_member_id%TYPE
36 ,resource_assignment_id pa_resource_assignments.resource_assignment_id%TYPE
37 ,ra_dml_code VARCHAR2(30));
38
39 TYPE res_assmt_map_rec_tbl_type IS TABLE OF res_assmt_map_rec
40 INDEX BY BINARY_INTEGER;
41
42 --This record type will contain key and a value. A pl/sql tbl of this record type can be declared and it can be
43 --used for different purposes. One such case is : if its required to get the top task id for a task id at many
44 --places in the code then instead of firing a select each time we can fetch it and store in this record. The key
45 --will be the task id and the value will be top task id.
46 --Created for bug 3678314
47 TYPE key_value_rec IS RECORD
48 (key NUMBER
49 ,value NUMBER);
50
51 TYPE key_value_rec_tbl_type IS TABLE OF key_value_rec
52 INDEX BY BINARY_INTEGER;
53
54 --Tables for implement_ci_into_single_ver
55 l_src_targ_task_tbl key_value_rec_tbl_type;
56 l_res_assmt_map_rec_tbl res_assmt_map_rec_tbl_type;
57
58
59 --End of tables for implement_ci_into_single_ver
60
61 /*
62 This API will be called when one control item has been
63 merged into another control item or plan version. This
64 API inserts records in the merged control items table
65 and links two control items that have already merged.
66 */
67
68 PROCEDURE FP_CI_LINK_CONTROL_ITEMS
69 (
70 p_project_id IN NUMBER,
71 p_s_fp_version_id IN pa_budget_versions.budget_version_id%TYPE,
72 p_t_fp_version_id IN pa_budget_versions.budget_version_id%TYPE,
73 p_inclusion_method IN VARCHAR2,
74 p_included_by IN NUMBER,
75 --Added for bug 3550073
76 p_version_type IN pa_budget_versions.version_type%TYPE,
77 p_ci_id IN pa_control_items.ci_id%TYPE,
78 p_cost_ppl_qty IN pa_fp_merged_ctrl_items.impl_quantity%TYPE,
79 p_rev_ppl_qty IN pa_fp_merged_ctrl_items.impl_quantity%TYPE,
80 p_cost_equip_qty IN pa_fp_merged_ctrl_items.impl_equipment_quantity%TYPE,
81 p_rev_equip_qty IN pa_fp_merged_ctrl_items.impl_equipment_quantity%TYPE,
82 p_impl_pfc_raw_cost IN pa_fp_merged_ctrl_items.impl_proj_func_raw_cost%TYPE,
83 p_impl_pfc_revenue IN pa_fp_merged_ctrl_items.impl_proj_func_revenue%TYPE,
84 p_impl_pfc_burd_cost IN pa_fp_merged_ctrl_items.impl_proj_func_burdened_cost%TYPE,
85 p_impl_pc_raw_cost IN pa_fp_merged_ctrl_items.impl_proj_raw_cost%TYPE,
86 p_impl_pc_revenue IN pa_fp_merged_ctrl_items.impl_proj_revenue%TYPE,
87 p_impl_pc_burd_cost IN pa_fp_merged_ctrl_items.impl_proj_burdened_cost%TYPE,
88 p_impl_agr_revenue IN pa_fp_merged_ctrl_items.impl_agr_revenue%TYPE,
89 x_return_status OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
90 x_msg_count OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
91 x_msg_data OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
92 )
93 IS
94 -- Local Variable Declaration
95
96 l_last_updated_by NUMBER := FND_GLOBAL.USER_ID;
97 l_created_by NUMBER := FND_GLOBAL.USER_ID;
98 l_creation_date DATE := SYSDATE;
99 l_last_update_date DATE := l_creation_date;
100 l_last_update_login NUMBER := FND_GLOBAL.LOGIN_ID;
101
102 l_s_ci_id pa_budget_versions.ci_id%TYPE;
103 l_included_by NUMBER := 0;
104 l_party_id NUMBER := 0;
105 l_debug_mode VARCHAR2(30);
106 l_module_name VARCHAR2(100):='PAFPCIMB.FP_CI_LINK_CONTROL_ITEMS';
107
108 BEGIN
109 IF p_pa_debug_mode = 'Y' THEN
110 pa_debug.init_err_stack('PAFPCIMB.FP_CI_LINK_CONTROL_ITEMS');
111 END IF;
112 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
113 l_debug_mode := NVL(l_debug_mode, 'Y');
114 IF p_pa_debug_mode = 'Y' THEN
115 PA_DEBUG.Set_Curr_Function( p_function => l_module_name,
116 p_debug_mode => l_debug_mode );
117 END IF;
118 x_return_status := FND_API.G_RET_STS_SUCCESS;
119 x_msg_count := 0;
120 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS - 1');
121 --Check for nulls for mandatory parameters
122 IF p_s_fp_version_id IS NULL THEN
123 PA_UTILS.ADD_MESSAGE
124 ( p_app_short_name => 'PA',
125 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
126
127 /*PA_UTILS.ADD_MESSAGE
128 ( p_app_short_name => 'PA',
129 p_msg_name => 'The source budget version id passed is null');
130 */
131
132 IF p_pa_debug_mode = 'Y' THEN
133 PA_DEBUG.g_err_stage := 'The source budget version id passed is null';
134 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
135 END IF;
136 x_return_status := FND_API.G_RET_STS_ERROR;
137 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS - ***2');
138 IF p_pa_debug_mode = 'Y' THEN
139 PA_DEBUG.Reset_Curr_Function;
140 END IF;
141 RETURN;
142 END IF;
143
144 IF p_t_fp_version_id IS NULL THEN
145 PA_UTILS.ADD_MESSAGE
146 ( p_app_short_name => 'PA',
147 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
148 /*PA_UTILS.ADD_MESSAGE
149 ( p_app_short_name => 'PA',
150 p_msg_name => 'The target budget version id passed is null');
151 */
152 IF p_pa_debug_mode = 'Y' THEN
153 PA_DEBUG.g_err_stage := 'The target budget version id passed is null';
154 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
155 END IF;
156 x_return_status := FND_API.G_RET_STS_ERROR;
157 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS - ***3');
158 IF p_pa_debug_mode = 'Y' THEN
159 PA_DEBUG.Reset_Curr_Function;
160 END IF;
161 RETURN;
162 END IF;
163
164 IF p_project_id IS NULL THEN
165 PA_UTILS.ADD_MESSAGE
166 ( p_app_short_name => 'PA',
167 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
168 /*PA_UTILS.ADD_MESSAGE
169 ( p_app_short_name => 'PA',
170 p_msg_name => 'The project id passed is null');
171 */
172 IF p_pa_debug_mode = 'Y' THEN
173 PA_DEBUG.g_err_stage := 'The project id passed is null';
174 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
175 END IF;
176 x_return_status := FND_API.G_RET_STS_ERROR;
177 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS -*** 4');
178 IF p_pa_debug_mode = 'Y' THEN
179 PA_DEBUG.Reset_Curr_Function;
180 END IF;
181 RETURN;
182 END IF;
183
184 IF p_version_type IS NULL OR
185 p_version_type NOT IN ('COST', 'REVENUE', 'BOTH') THEN
186
187 IF l_debug_mode = 'Y' THEN
188 pa_debug.g_err_stage:='Invalid p_version_type passed is '||p_version_type;
189 pa_debug.write(L_module_name,pa_debug.g_err_stage,5);
190 END IF;
191 PA_UTILS.ADD_MESSAGE
192 ( p_app_short_name => 'PA',
193 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
194 x_return_status := FND_API.G_RET_STS_ERROR;
195 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS -*** 4');
196 IF p_pa_debug_mode = 'Y' THEN
197 PA_DEBUG.Reset_Curr_Function;
198 END IF;
199 RETURN;
200
201
202 END IF;
203
204 -- Get the control item id for the source version
205 -- from the budget version table
206 IF p_ci_id IS NULL THEN
207 BEGIN
208 SELECT
209 bv.ci_id
210 INTO
211 l_s_ci_id
212 FROM pa_budget_versions bv
213 WHERE bv.budget_version_id = p_s_fp_version_id
214 AND bv.project_id = p_project_id;
215 EXCEPTION
216 WHEN NO_DATA_FOUND THEN
217 PA_UTILS.ADD_MESSAGE
218 ( p_app_short_name => 'PA',
219 p_msg_name => 'PA_FP_CI_NO_CI_ID_FOUND');
220 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS - 5****');
221 x_return_status := FND_API.G_RET_STS_ERROR;
222 END;
223 ELSE
224 l_s_ci_id := p_ci_id;
225 END IF;
226
227 IF p_included_by IS NOT NULL THEN
228 l_included_by := p_included_by;
229 ELSE
230 l_included_by := FND_GLOBAL.USER_ID;
231 END IF;
232
233 BEGIN
234 SELECT hp.party_id
235 INTO
236 l_party_id
237 FROM fnd_user fu,
238 hz_parties hp
239 WHERE
240 user_id = l_included_by
241 and employee_id IS NOT NULL
242 and hp.orig_system_reference = 'PER:' || fu.employee_id;
243 EXCEPTION
244 WHEN NO_DATA_FOUND THEN
245 SELECT hp.party_id
246 INTO l_party_id
247 FROM fnd_user fu,
248 hz_parties hp
249 WHERE
250 user_id = l_included_by
251 AND employee_id IS NULL
252 -- Bug 4931044: R12 ATG Mandate: Moving customer_id to
253 -- person_party_id in fnd_user
254 AND hp.party_id = fu.person_party_id;
255 -- AND hp.party_id = fu.customer_id;
256 END;
257
258 -- Insert in the merged control items table
259 IF p_version_type IN ('COST', 'BOTH') THEN
260 INSERT INTO pa_fp_merged_ctrl_items
261 (
262 PROJECT_ID
263 ,PLAN_VERSION_ID
264 ,CI_ID
265 ,CI_PLAN_VERSION_ID
266 ,RECORD_VERSION_NUMBER
267 ,last_update_date
268 ,last_updated_by
269 ,creation_date
270 ,created_by
271 ,last_update_login
272 ,inclusion_method_code
273 ,included_by_person_id
274 --Included for bug 3550073
275 ,version_type
276 ,impl_proj_func_raw_cost
277 ,impl_proj_func_burdened_cost
278 ,impl_proj_func_revenue
279 ,impl_proj_raw_cost
280 ,impl_proj_burdened_cost
281 ,impl_proj_revenue
282 ,impl_quantity
283 ,impl_equipment_quantity
284 ,impl_agr_revenue
285 )
286 VALUES
287 (
288 p_project_id
289 ,p_t_fp_version_id
290 ,l_s_ci_id
291 ,p_s_fp_version_id
292 ,1
293 ,l_last_update_date
294 ,l_last_updated_by
295 ,l_creation_date
296 ,l_created_by
297 ,l_last_update_login
298 ,p_inclusion_method
299 ,l_party_id
300 --Included for bug 3550073
301 ,'COST'
302 ,p_impl_pfc_raw_cost
303 ,p_impl_pfc_burd_cost
304 ,NULL
305 ,p_impl_pc_raw_cost
306 ,p_impl_pc_burd_cost
307 ,NULL
308 ,p_cost_ppl_qty
309 ,p_cost_equip_qty
310 ,NULL
311 );
312 END IF;
313
314 IF p_version_type IN ('REVENUE', 'BOTH') THEN
315 INSERT INTO pa_fp_merged_ctrl_items
316 (
317 PROJECT_ID
318 ,PLAN_VERSION_ID
319 ,CI_ID
320 ,CI_PLAN_VERSION_ID
321 ,RECORD_VERSION_NUMBER
322 ,last_update_date
323 ,last_updated_by
324 ,creation_date
325 ,created_by
326 ,last_update_login
327 ,inclusion_method_code
328 ,included_by_person_id
329 --Included for bug 3550073
330 ,version_type
331 ,impl_proj_func_raw_cost
332 ,impl_proj_func_burdened_cost
333 ,impl_proj_func_revenue
334 ,impl_proj_raw_cost
335 ,impl_proj_burdened_cost
336 ,impl_proj_revenue
337 ,impl_quantity
338 ,impl_equipment_quantity
339 ,impl_agr_revenue
340 )
341 VALUES
342 (
343 p_project_id
344 ,p_t_fp_version_id
345 ,l_s_ci_id
346 ,p_s_fp_version_id
347 ,1
348 ,l_last_update_date
349 ,l_last_updated_by
350 ,l_creation_date
351 ,l_created_by
352 ,l_last_update_login
353 ,p_inclusion_method
354 ,l_party_id
355 --Included for bug 3550073
356 ,'REVENUE'
357 ,NULL
358 ,NULL
359 ,p_impl_pfc_revenue
360 ,NULL
361 ,NULL
362 ,p_impl_pc_revenue
363 ,p_rev_ppl_qty
364 ,p_rev_equip_qty
365 ,p_impl_agr_revenue
366 );
367
368 END IF;
369 IF p_pa_debug_mode = 'Y' THEN
370 PA_DEBUG.Reset_Curr_Function;
371 END IF;
372 EXCEPTION
373 WHEN OTHERS THEN
374 FND_MSG_PUB.add_exc_msg
375 ( p_pkg_name => 'PA_FP_CI_MERGE.' ||
376 'fp_ci_link_control_items'
377 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
378 IF p_pa_debug_mode = 'Y' THEN
379 PA_DEBUG.g_err_stage := 'Unexpected error in fp_ci_link_control_items';
380 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
381 END IF;
382 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
383 --------dbms_output.put_line('FP_CI_LINK_CONTROL_ITEMS - 6****');
384 IF p_pa_debug_mode = 'Y' THEN
385 PA_DEBUG.Reset_Curr_Function;
386 END IF;
387 RAISE;
388
389 END FP_CI_LINK_CONTROL_ITEMS;
390 -- end of fp_ci_link_control_items
391
392 /****************************************************************
393 This API is called to update the estimated amounts for control
394 items budget versions. The main updation in this API is to update
395 the estimated amounts for the target budget version of control item
396 ***************************************************************/
397
398 PROCEDURE FP_CI_UPDATE_EST_AMOUNTS
399 (
400 p_project_id IN pa_budget_versions.project_id%TYPE,
401 p_source_version_id IN pa_budget_versions.budget_version_id%TYPE,
402 p_target_version_id IN pa_budget_versions.budget_version_id%TYPE,
403 p_merge_unmerge_mode IN VARCHAR2 ,
404 p_commit_flag IN VARCHAR2 ,
405 p_init_msg_list IN VARCHAR2 ,
406 p_update_agreement IN VARCHAR2,
407 x_return_status OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
408 x_msg_count OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
409 x_msg_data OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
410 )
411 IS
412 -- Local Variable Declaration
413
414 l_last_updated_by NUMBER := FND_GLOBAL.USER_ID;
415 l_last_update_date DATE := SYSDATE;
416 l_last_update_login NUMBER := FND_GLOBAL.LOGIN_ID;
417
418 l_debug_mode VARCHAR2(30);
419
420 l_target_ver_type pa_budget_versions.version_type%TYPE;
421
422 l_est_project_raw_cost pa_budget_versions.est_project_raw_cost%TYPE;
423 l_est_project_burdened_cost pa_budget_versions.est_project_burdened_cost%TYPE;
424 l_est_project_revenue pa_budget_versions.est_project_revenue%TYPE;
425 l_est_quantity pa_budget_versions.est_quantity%TYPE;
426 l_est_projfunc_raw_cost pa_budget_versions.est_projfunc_raw_cost%TYPE;
427 l_est_projfunc_burdened_cost pa_budget_versions.est_projfunc_burdened_cost%TYPE;
428 l_est_projfunc_revenue pa_budget_versions.est_projfunc_revenue%TYPE;
429 l_agreement_id pa_budget_versions.agreement_id%TYPE;
430 l_est_equipment_quantity pa_budget_versions.est_equipment_quantity%TYPE;
431
432 BEGIN
433 IF p_pa_debug_mode = 'Y' THEN
434 pa_debug.init_err_stack('PAFPCIMB.FP_CI_UPDATE_EST_AMOUNTS');
435 END IF;
436 IF NVL(p_init_msg_list,'N') = 'Y' THEN
437 FND_MSG_PUB.initialize;
438 END IF;
439 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
440 l_debug_mode := NVL(l_debug_mode, 'Y');
441 IF p_pa_debug_mode = 'Y' THEN
442 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
443 END IF;
444 x_return_status := FND_API.G_RET_STS_SUCCESS;
445 x_msg_count := 0;
446 --------dbms_output.put_line('FP_CI_UPDATE_EST_AMOUNTS - 1');
447 --Check for nulls for mandatory parameters
448 IF p_source_version_id IS NULL THEN
449 PA_UTILS.ADD_MESSAGE
450 ( p_app_short_name => 'PA',
451 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
452 IF p_pa_debug_mode = 'Y' THEN
453 PA_DEBUG.g_err_stage := 'The source budget version id passed is null';
454 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
455 END IF;
456 x_return_status := FND_API.G_RET_STS_ERROR;
457 RETURN;
458 END IF;
459
460 IF p_target_version_id IS NULL THEN
461 PA_UTILS.ADD_MESSAGE
462 ( p_app_short_name => 'PA',
463 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
464 IF p_pa_debug_mode = 'Y' THEN
465 PA_DEBUG.g_err_stage := 'The target budget version id passed is null';
466 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
467 END IF;
468 x_return_status := FND_API.G_RET_STS_ERROR;
469 RETURN;
470 END IF;
471
472 IF p_project_id IS NULL THEN
473 PA_UTILS.ADD_MESSAGE
474 ( p_app_short_name => 'PA',
475 p_msg_name => 'PA_FP_CI_NULL_PARAM_PASSED');
476 IF p_pa_debug_mode = 'Y' THEN
477 PA_DEBUG.g_err_stage := 'The project id passed is null';
478 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
479 END IF;
480 x_return_status := FND_API.G_RET_STS_ERROR;
481 RETURN;
482 END IF;
483
484 -- Get the target version type
485 BEGIN
486 SELECT bv.version_type
487 INTO l_target_ver_type
488 FROM pa_budget_versions bv
489 WHERE
490 bv.project_id = p_project_id
491 AND bv.budget_version_id = p_target_version_id;
492 EXCEPTION
493 WHEN NO_DATA_FOUND THEN
494 PA_UTILS.ADD_MESSAGE
495 ( p_app_short_name => 'PA',
496 p_msg_name => 'PA_FP_CI_NO_VERSION_DATA_FOUND');
497 ------dbms_output.put_line('FP_CI_UPDATE_EST_AMOUNTS - 2***');
498 x_return_status := FND_API.G_RET_STS_ERROR;
499 END;
500
501 -- Get the estimated amounts for the source version
502
503 BEGIN
504 SELECT
505 NVL(est_project_raw_cost,0),
506 NVL(est_project_burdened_cost,0),
507 NVL(est_project_revenue,0),
508 NVL(est_quantity,0),
509 NVL(est_projfunc_raw_cost,0),
510 NVL(est_projfunc_burdened_cost,0),
511 NVL(est_projfunc_revenue,0),
512 NVL(est_equipment_quantity,0),
513 agreement_id
514 INTO
515 l_est_project_raw_cost,
516 l_est_project_burdened_cost,
517 l_est_project_revenue,
518 l_est_quantity,
519 l_est_projfunc_raw_cost,
520 l_est_projfunc_burdened_cost,
521 l_est_projfunc_revenue,
522 l_est_equipment_quantity,
523 l_agreement_id
524 FROM PA_BUDGET_VERSIONS bv
525 WHERE
526 bv.project_id = p_project_id
527 AND bv.budget_version_id = p_source_version_id;
528
529 EXCEPTION
530 WHEN NO_DATA_FOUND THEN
531 PA_UTILS.ADD_MESSAGE
532 ( p_app_short_name => 'PA',
533 p_msg_name => 'PA_FP_CI_NO_VERSION_DATA_FOUND');
534 ------dbms_output.put_line('FP_CI_UPDATE_EST_AMOUNTS - 2***');
535 x_return_status := FND_API.G_RET_STS_ERROR;
536 END;
537
538 -- Update the budget versions table for the target version
539 -- based on version type
540 IF(l_target_ver_type = 'ALL') THEN
541 UPDATE PA_BUDGET_VERSIONS bv
542 SET
543 est_project_raw_cost = NVL(est_project_raw_cost,0) + DECODE
544 (p_merge_unmerge_mode,
545 'MERGE', l_est_project_raw_cost,
546 'UNMERGE', (-1 * l_est_project_raw_cost)),
547 est_project_burdened_cost = NVL(est_project_burdened_cost,0) + DECODE
548 (p_merge_unmerge_mode,
549 'MERGE', l_est_project_burdened_cost,
550 'UNMERGE', (-1 * l_est_project_burdened_cost)),
551 est_project_revenue = NVL(est_project_revenue,0) + DECODE
552 (p_merge_unmerge_mode,
553 'MERGE', l_est_project_revenue,
554 'UNMERGE', (-1 * l_est_project_revenue)),
555 est_quantity = NVL(est_quantity,0) + DECODE
556 (p_merge_unmerge_mode,
557 'MERGE', l_est_quantity,
558 'UNMERGE', (-1 * l_est_quantity)),
559 est_equipment_quantity=NVL(est_equipment_quantity,0) + DECODE
560 (p_merge_unmerge_mode,
561 'MERGE', l_est_equipment_quantity,
562 'UNMERGE', (-1 * l_est_equipment_quantity)),
563 est_projfunc_raw_cost = NVL(est_projfunc_raw_cost,0) + DECODE
564 (p_merge_unmerge_mode,
565 'MERGE', l_est_projfunc_raw_cost,
566 'UNMERGE', (-1 * l_est_projfunc_raw_cost)),
567 est_projfunc_burdened_cost = NVL(est_projfunc_burdened_cost,0) + DECODE
568 (p_merge_unmerge_mode,
569 'MERGE', l_est_projfunc_burdened_cost,
570 'UNMERGE', (-1 * l_est_projfunc_burdened_cost)),
571 est_projfunc_revenue = NVL(est_projfunc_revenue,0) + DECODE
572 (p_merge_unmerge_mode,
573 'MERGE', l_est_projfunc_revenue,
574 'UNMERGE', (-1 * l_est_projfunc_revenue))
575 WHERE
576 bv.project_id = p_project_id
577 AND bv.budget_version_id = p_target_version_id;
578 IF (SQL%ROWCOUNT = 0) THEN
579 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
580 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
581 END IF;
582 ELSIF(l_target_ver_type = 'COST') THEN
583 UPDATE PA_BUDGET_VERSIONS bv
584 SET
585 est_project_raw_cost = NVL(est_project_raw_cost,0) + DECODE
586 (p_merge_unmerge_mode,
587 'MERGE', l_est_project_raw_cost,
588 'UNMERGE', (-1 * l_est_project_raw_cost)),
589 est_project_burdened_cost = NVL(est_project_burdened_cost,0) + DECODE
590 (p_merge_unmerge_mode,
591 'MERGE', l_est_project_burdened_cost,
592 'UNMERGE', (-1 * l_est_project_burdened_cost)),
593 est_quantity = NVL(est_quantity,0) + DECODE
594 (p_merge_unmerge_mode,
595 'MERGE', l_est_quantity,
596 'UNMERGE', (-1 * l_est_quantity)),
597 est_projfunc_raw_cost = NVL(est_projfunc_raw_cost,0) + DECODE
598 (p_merge_unmerge_mode,
599 'MERGE', l_est_projfunc_raw_cost,
600 'UNMERGE', (-1 * l_est_projfunc_raw_cost)),
601 est_projfunc_burdened_cost = NVL(est_projfunc_burdened_cost,0) + DECODE
602 (p_merge_unmerge_mode,
603 'MERGE', l_est_projfunc_burdened_cost,
604 'UNMERGE', (-1 * l_est_projfunc_burdened_cost))
605 WHERE
606 bv.project_id = p_project_id
607 AND bv.budget_version_id = p_target_version_id;
608 IF (SQL%ROWCOUNT = 0) THEN
609 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
610 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
611 END IF;
612 ELSIF(l_target_ver_type = 'REVENUE') THEN
613 UPDATE PA_BUDGET_VERSIONS bv
614 SET
615 est_project_revenue = NVL(est_project_revenue,0) + DECODE
616 (p_merge_unmerge_mode,
617 'MERGE', l_est_project_revenue,
618 'UNMERGE', (-1 * l_est_project_revenue)),
619 est_quantity = NVL(est_quantity,0) + DECODE
620 (p_merge_unmerge_mode,
621 'MERGE', l_est_quantity,
622 'UNMERGE', (-1 * l_est_quantity)),
623 est_projfunc_revenue = NVL(est_projfunc_revenue,0) + DECODE
624 (p_merge_unmerge_mode,
625 'MERGE', l_est_projfunc_revenue,
626 'UNMERGE', (-1 * l_est_projfunc_revenue))
627 WHERE
628 bv.project_id = p_project_id
629 AND bv.budget_version_id = p_target_version_id;
630 IF (SQL%ROWCOUNT = 0) THEN
631 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
632 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
633 END IF;
634 END IF;
635
636 IF (p_update_agreement = 'Y') THEN
637 UPDATE PA_BUDGET_VERSIONS bv
638 SET
639 agreement_id = l_agreement_id
640 WHERE
641 bv.project_id = p_project_id
642 AND bv.budget_version_id = p_target_version_id;
643 IF (SQL%ROWCOUNT = 0) THEN
644 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
645 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
646 END IF;
647 END IF;
648 IF NVL(p_commit_flag,'N') = 'Y' THEN
649 COMMIT;
650 END IF;
651 EXCEPTION
652 WHEN OTHERS THEN
653 FND_MSG_PUB.add_exc_msg
654 ( p_pkg_name => 'PA_FP_CI_MERGE.' ||
655 'fp_ci_update_est_amounts'
656 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
657 IF p_pa_debug_mode = 'Y' THEN
658 PA_DEBUG.g_err_stage := 'Unexpected error in FP_CI_UPDATE_EST_AMOUNTS';
659 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
660 END IF;
661 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
662 --------dbms_output.put_line('FP_CI_UPDATE_EST_AMOUNTS - 6****');
663 IF p_pa_debug_mode = 'Y' THEN
664 PA_DEBUG.Reset_Curr_Function;
665 END IF;
666 RAISE;
667
668 END FP_CI_UPDATE_EST_AMOUNTS;
669 -- end of fp_ci_update_est_amounts
670
671 /****************************************************************
672 This API is called to update the financial impact for control
673 items. The main updation in this API is to update the status
674 code of the impact and the person who caused that impact
675 ***************************************************************/
676 --Added p_impact_type_code for bug 3550073.
677 --p_impact_type can be FINPLAN_COST, FINPLAN_REVENUE or
678 --FINPLAN_BOTH in which case both FINPLAN_COST and FINPLAN_REVENUE records will be updated
679 PROCEDURE FP_CI_UPDATE_IMPACT
680 (
681 p_ci_id IN pa_ci_impacts.ci_id%TYPE,
682 p_status_code IN pa_ci_impacts.status_code%TYPE,
683 p_implementation_date IN pa_ci_impacts.implementation_date%TYPE,
684 p_implemented_by IN pa_ci_impacts.implemented_by%TYPE,
685 p_record_version_number IN pa_ci_impacts.record_version_number%TYPE,
686 p_impacted_task_id IN pa_ci_impacts.impacted_task_id%TYPE,
687 p_impact_type_code IN pa_ci_impacts.impact_type_code%TYPE,
688 p_commit_flag IN VARCHAR2 ,
689 p_init_msg_list IN VARCHAR2 ,
690 x_return_status OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
691 x_msg_count OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
692 x_msg_data OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
693 )
694 IS
695 -- Local Variable Declaration
696
697 l_last_updated_by NUMBER := FND_GLOBAL.USER_ID;
698 l_last_update_date DATE := SYSDATE;
699 l_last_update_login NUMBER := FND_GLOBAL.LOGIN_ID;
700
701 l_party_id NUMBER := 0;
702 l_implemented_by NUMBER := 0;
703 l_impact_type_code VARCHAR2(30);
704 l_debug_mode VARCHAR2(30);
705
706 BEGIN
707 IF p_pa_debug_mode = 'Y' THEN
708 pa_debug.init_err_stack('PAFPCIMB.FP_CI_UPDATE_IMPACT');
709 END IF;
710 IF NVL(p_init_msg_list,'N') = 'Y' THEN
711 FND_MSG_PUB.initialize;
712 END IF;
713 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
714 l_debug_mode := NVL(l_debug_mode, 'Y');
715 IF p_pa_debug_mode = 'Y' THEN
716 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
717 END IF;
718 x_return_status := FND_API.G_RET_STS_SUCCESS;
719 x_msg_count := 0;
720 --------dbms_output.put_line('FP_CI_UPDATE_IMPACT - 1');
721 --Checking for a valid implementation date
722 IF (p_implementation_date > SYSDATE) THEN
723 PA_UTILS.Add_Message ( p_app_short_name => 'PA',
724 p_msg_name => 'PA_FP_CI_INV_IMPACT_DATE'
725 );
726 x_return_status := FND_API.G_RET_STS_ERROR;
727 RETURN;
728 END IF;
729
730 --Checking if control item id is null
731 IF p_ci_id IS NULL THEN
732 PA_UTILS.Add_Message ( p_app_short_name => 'PA',
733 p_msg_name => 'PA_FP_CI_NULL_CI_ID'
734 );
735 x_return_status := FND_API.G_RET_STS_ERROR;
736 RETURN;
737 END IF;
738
739 IF p_impact_type_code IS NULL OR
740 p_impact_type_code NOT IN ('FINPLAN_COST', 'FINPLAN_REVENUE', 'FINPLAN_BOTH') THEN
741 PA_UTILS.Add_Message ( p_app_short_name => 'PA',
742 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
743 p_token1=>'PROCEDURENAME',
744 p_value1=>'FP_CI_UPDATE_IMPACT'
745 );
746 x_return_status := FND_API.G_RET_STS_ERROR;
747 RETURN;
748 END IF;
749
750
751 --Setting impact type code to FINPLAN
752 l_impact_type_code := p_impact_type_code;
753
754 IF p_implemented_by IS NOT NULL THEN
755 l_implemented_by := p_implemented_by;
756 ELSE
757 l_implemented_by := FND_GLOBAL.USER_ID;
758 END IF;
759
760 BEGIN
761 SELECT hp.party_id
762 INTO
763 l_party_id
764 FROM fnd_user fu,
765 hz_parties hp
766 WHERE
767 user_id = l_implemented_by
768 and employee_id IS NOT NULL
769 and hp.orig_system_reference = 'PER:' || fu.employee_id;
770 EXCEPTION
771 WHEN NO_DATA_FOUND THEN
772 SELECT hp.party_id
773 INTO
774 l_party_id
775 FROM fnd_user fu,
776 hz_parties hp
777 WHERE
778 user_id = l_implemented_by
779 and employee_id IS NULL
780 -- Bug 4931044: R12 ATG Mandate: Moving customer_id to
781 -- person_party_id in fnd_user
782 and hp.party_id = fu.person_party_id;
783 --and hp.party_id = fu.customer_id;
784 END;
785
786 -- Update the PA_CI_IMPACTS table
787
788 UPDATE PA_CI_IMPACTS
789 SET
790 STATUS_CODE = NVL(p_status_code,status_code),
791 IMPLEMENTATION_DATE = NVL(p_implementation_date,SYSDATE),
792 IMPLEMENTED_BY = l_party_id,
793 IMPACTED_TASK_ID = NVL(p_impacted_task_id,impacted_task_id),
794 LAST_UPDATE_DATE = l_last_update_date,
795 LAST_UPDATED_BY = l_last_updated_by,
796 LAST_UPDATE_LOGIN = l_last_update_login,
797 RECORD_VERSION_NUMBER = NVL(p_record_version_number, record_version_number +1)
798 WHERE ci_id = p_ci_id
799 AND ((l_impact_type_code ='FINPLAN_BOTH' AND impact_type_code IN ('FINPLAN_COST', 'FINPLAN_REVENUE'))
800 OR (impact_type_code = l_impact_type_code));
801 --------dbms_output.put_line('SQL%ROWCOUNT****' || SQL%ROWCOUNT);
802 IF (SQL%ROWCOUNT = 0) THEN
803 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
804 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
805 END IF;
806 IF NVL(p_commit_flag,'N') = 'Y' THEN
807 COMMIT;
808 END IF;
809 EXCEPTION
810 WHEN OTHERS THEN
811 FND_MSG_PUB.add_exc_msg
812 ( p_pkg_name => 'PA_FP_CI_MERGE.' ||
813 'fp_ci_update_impact'
814 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
815 IF p_pa_debug_mode = 'Y' THEN
816 PA_DEBUG.g_err_stage := 'Unexpected error in FP_CI_UPDATE_IMPACT';
817 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
818 END IF;
819 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
820 --------dbms_output.put_line('FP_CI_UPDATE_IMPACT - 6****');
821 IF p_pa_debug_mode = 'Y' THEN
822 PA_DEBUG.Reset_Curr_Function;
823 END IF;
824 RAISE;
825
826 END FP_CI_UPDATE_IMPACT;
827 -- end of fp_ci_update_impact
828
829
830
831 PROCEDURE FP_CI_MERGE_CI_ITEMS
832 (
833 p_project_id IN NUMBER,
834 p_s_fp_ci_id IN pa_budget_versions.ci_id%TYPE,
835 p_t_fp_ci_id IN pa_budget_versions.ci_id%TYPE,
836 p_merge_unmerge_mode IN VARCHAR2 ,
837 p_commit_flag IN VARCHAR2 ,
838 p_init_msg_list IN VARCHAR2 ,
839 p_calling_context IN VARCHAR2,
840 x_warning_flag OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
841 x_msg_count OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
842 x_msg_data OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
843 x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
844 )
845 IS
846 --Defining PL/SQL local variables
847 l_s_fp_ci_id pa_budget_versions.ci_id%TYPE;
848 l_t_fp_ci_id pa_budget_versions.ci_id%TYPE;
849 l_budget_version_id pa_budget_versions.budget_version_id%TYPE;
850 l_target_version_id pa_budget_versions.budget_version_id%TYPE;
851 l_target_version_id_tmp pa_budget_versions.budget_version_id%TYPE;
852 l_source_version_id pa_budget_versions.budget_version_id%TYPE;
853 l_counter NUMBER := 0;
854 l_task_id NUMBER;
855 l_s_version_id pa_budget_versions.budget_version_id%TYPE;
856 l_s_fin_plan_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
857 l_s_multi_curr_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
858 l_s_time_phased_code pa_proj_fp_options. all_time_phased_code%TYPE;
859 l_s_resource_list_id pa_proj_fp_options.all_resource_list_id%TYPE;
860 l_s_fin_plan_level_code pa_proj_fp_options.all_fin_plan_level_code%TYPE;
861 l_s_uncategorized_flag pa_resource_lists_all_bg.uncategorized_flag %TYPE;
862 l_s_group_res_type_id pa_resource_lists_all_bg.group_resource_type_id%TYPE;
863 l_s_version_type pa_budget_versions.version_type%TYPE;
864 l_s_ci_id pa_budget_versions.ci_id%TYPE;
865 l_t_version_id pa_budget_versions.budget_version_id%TYPE;
866 l_t_fin_plan_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
867 l_t_time_phased_code pa_proj_fp_options. all_time_phased_code%TYPE;
868 l_t_resource_list_id pa_proj_fp_options.all_resource_list_id%TYPE;
869 l_t_multi_curr_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
870 l_t_fin_plan_level_code pa_proj_fp_options.all_fin_plan_level_code%TYPE;
871 l_t_uncategorized_flag pa_resource_lists_all_bg.uncategorized_flag %TYPE;
872 l_t_group_res_type_id pa_resource_lists_all_bg.group_resource_type_id%TYPE;
873 l_t_version_type pa_budget_versions.version_type%TYPE;
874 l_t_ci_id pa_budget_versions.ci_id%TYPE;
875 l_source_ver_type pa_budget_versions.version_type%TYPE;
876 l_target_ver_type pa_budget_versions.version_type%TYPE;
877 l_target_plan_type_p_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
878
879 --Defining Local PL/SQL variables for source version
880 l_source_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
881 l_s_fp_version_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
882 l_s_fin_plan_pref_code_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
883 l_s_multi_curr_flag_tbl PA_PLSQL_DATATYPES.Char1TabTyp;
884 l_s_fin_plan_level_code_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
885 l_s_uncategorized_flag_tbl PA_PLSQL_DATATYPES.Char1TabTyp;
886 l_s_group_res_type_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
887 l_s_version_type_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
888 l_s_time_phased_code_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
889 l_source_fp_version_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
890
891 --Defining Local PL/SQL variables for target version
892 l_target_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
893 l_t_fp_version_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
894 l_t_fin_plan_pref_code_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
895 l_t_multi_curr_flag_tbl PA_PLSQL_DATATYPES.Char1TabTyp;
896 l_t_fin_plan_level_code_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
897 l_t_uncategorized_flag_tbl PA_PLSQL_DATATYPES.Char1TabTyp;
898 l_t_version_type_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
899 l_t_group_res_type_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
900 l_t_time_phased_code_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
901 l_target_fp_version_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
902
903 --Other Local Variables
904 l_merge_possible_code_tbl PA_PLSQL_DATATYPES.Char1TabTyp;
905 l_count_merged_versions NUMBER := 0;
906 l_copy_version_flag VARCHAR2(1);
907 l_copy_possible_flag VARCHAR2(1);
908 l_debug_mode VARCHAR2(30);
909 l_bulk_fetch_count NUMBER := 0;
910 l_index NUMBER := 1;
911 l_count NUMBER := 0;
912 l_t_count_versions NUMBER := 0;
913 l_count_projects NUMBER := 0;
914 l_target_plan_types_cnt NUMBER := 0;
915 l_merged_count NUMBER := 0;
916 l_insert_flag VARCHAR2(1) := 'N';
917 l_merge_possible_code VARCHAR2(1);
918 l_s_version_id_count NUMBER := 0;
919 l_update_agreement_flag VARCHAR2(1) := 'N';
920
921 l_ci_id_tbl SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
922 l_ci_cost_version_id_tbl SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
923 l_ci_rev_version_id_tbl SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
924 l_ci_all_version_id_tbl SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
925 l_target_version_id_tbl SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
926 l_impl_cost_flag_tbl SYSTEM.pa_varchar2_1_tbl_type:=SYSTEM.pa_varchar2_1_tbl_type();
927 l_impl_rev_flag_tbl SYSTEM.pa_varchar2_1_tbl_type:=SYSTEM.pa_varchar2_1_tbl_type();
928 l_translated_msgs_tbl SYSTEM.pa_varchar2_2000_tbl_type:=SYSTEM.pa_varchar2_2000_tbl_type();
929 l_translated_err_msg_count NUMBER;
930 l_translated_err_msg_level_tbl SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
931
932 l_impact_record_exists VARCHAR2(1); -- Bug 3677924 Raja 02-Jul-04
933
934 BEGIN
935 IF p_pa_debug_mode = 'Y' THEN
936 pa_debug.init_err_stack('PAFPINCB.FP_CI_MERGE_CI_ITEMS');
937 END IF;
938 IF NVL(p_init_msg_list,'N') = 'Y' THEN
939 FND_MSG_PUB.initialize;
940 END IF;
941 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
942 l_debug_mode := NVL(l_debug_mode, 'Y');
943 IF p_pa_debug_mode = 'Y' THEN
944 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
945 END IF;
946 x_return_status := FND_API.G_RET_STS_SUCCESS;
947 x_msg_count := 0;
948
949 l_target_version_id := NULL;
950 l_update_agreement_flag := 'N';
951 l_copy_version_flag := 'N';
952 x_warning_flag := 'N';
953 savepoint before_fp_ci_copy;
954
955 --Getting the target ci_id from the parameter
956 l_s_fp_ci_id := p_s_fp_ci_id;
957 l_t_fp_ci_id := p_t_fp_ci_id;
958
959 ------dbms_output.put_line('l_s_fp_ci_id : ' || l_s_fp_ci_id);
960 ------dbms_output.put_line('l_t_fp_ci_id : ' || l_t_fp_ci_id);
961
962 --Check if any budget versions exist for the target
963 --control item id or not
964 SELECT COUNT(*) INTO l_t_count_versions
965 FROM pa_budget_versions bv
966 WHERE
967 bv.project_id = p_project_id
968 AND bv.ci_id = l_t_fp_ci_id
969 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
970 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
971
972 --Get number of approved plan types
973 SELECT count(*)
974 INTO l_target_plan_types_cnt
975 FROM pa_proj_fp_options po
976 WHERE
977 project_id = p_project_id
978 and fin_plan_option_level_code = 'PLAN_TYPE'
979 and (NVL(po.approved_rev_plan_type_flag,'N') = 'Y'
980 OR NVL(po.approved_cost_plan_type_flag,'N') = 'Y');
981
982 -- Get the number of source budget versions
983 SELECT count(*)
984 INTO l_s_version_id_count
985 FROM pa_budget_versions bv
986 WHERE
987 bv.project_id = p_project_id
988 AND bv.ci_id = l_s_fp_ci_id
989 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
990 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
991
992 IF (l_s_version_id_count = 1) THEN
993
994 --Get source version id
995 SELECT bv.budget_version_id
996 BULK COLLECT INTO l_source_id_tbl
997 FROM pa_budget_versions bv
998 WHERE
999 bv.project_id = p_project_id
1000 AND bv.ci_id = l_s_fp_ci_id
1001 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1002 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
1003
1004 For i in l_source_id_tbl.FIRST.. l_source_id_tbl.LAST
1005 LOOP
1006 --Get source version id in local variable
1007 l_source_version_id := l_source_id_tbl(i);
1008 END LOOP;
1009
1010 -- Get the source version type
1011 SELECT bv.version_type
1012 INTO l_source_ver_type
1013 FROM pa_budget_versions bv
1014 WHERE
1015 bv.project_id = p_project_id
1016 AND bv.budget_version_id = l_source_version_id;
1017
1018 IF (l_t_count_versions = 1) THEN
1019 --Get target version id
1020 BEGIN
1021 SELECT bv.budget_version_id
1022 INTO l_target_version_id
1023 FROM pa_budget_versions bv
1024 WHERE
1025 bv.project_id = p_project_id
1026 AND bv.ci_id = l_t_fp_ci_id
1027 AND bv.version_type = l_source_ver_type
1028 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1029 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
1030 EXCEPTION
1031 WHEN NO_DATA_FOUND THEN
1032 l_t_count_versions := 0;
1033 END;
1034 END IF;
1035
1036 IF (l_t_count_versions = 0) THEN
1037 l_copy_version_flag := 'Y';
1038 -- We must copy the target version from source version
1039
1040 --Call the check API to see if the copy should
1041 --go through or not
1042
1043 --Before that get details of source version
1044 Pa_Fp_Control_Items_Utils.FP_CI_GET_VERSION_DETAILS
1045 (
1046 p_project_id => p_project_id,
1047 p_budget_version_id => l_source_version_id,
1048 x_fin_plan_pref_code => l_s_fin_plan_pref_code,
1049 x_multi_curr_flag => l_s_multi_curr_flag,
1050 x_fin_plan_level_code => l_s_fin_plan_level_code,
1051 x_resource_list_id => l_s_resource_list_id,
1052 x_time_phased_code => l_s_time_phased_code,
1053 x_uncategorized_flag => l_s_uncategorized_flag,
1054 x_group_res_type_id => l_s_group_res_type_id,
1055 x_version_type => l_s_version_type,
1056 x_ci_id => l_s_ci_id,
1057 x_return_status => x_return_status,
1058 x_msg_count => x_msg_count,
1059 x_msg_data => x_msg_data
1060 ) ;
1061
1062 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1063 RETURN;
1064 END IF;
1065
1066 -- Bug 3677924 Jul 06 2004 Raja
1067 -- Check if target change order has corresponding impact record
1068 -- Note: If the target change order type does not allow the impact, the record
1069 -- would not have been created. For ALL ci version type, there would be two
1070 -- records in the impacts table. If ALL ci version can not be copied
1071 -- then no impact records would be present.
1072 BEGIN
1073 SELECT 'Y'
1074 INTO l_impact_record_exists
1075 FROM DUAL
1076 WHERE EXISTS
1077 (SELECT 1
1078 FROM pa_ci_impacts
1079 WHERE ci_id = l_t_fp_ci_id
1080 AND (l_s_version_type IN ('REVENUE','ALL') AND impact_type_code = 'FINPLAN_REVENUE'
1081 OR l_s_version_type IN ('COST','ALL') AND impact_type_code = 'FINPLAN_COST'));
1082 EXCEPTION
1083 WHEN NO_DATA_FOUND THEN
1084 l_impact_record_exists := 'N';
1085 END;
1086
1087 -- Bug 3677924 If the impact record does not exist do not proceed
1088 IF l_impact_record_exists = 'N' THEN
1089 RETURN;
1090 END IF;
1091
1092 /*** raja 14-Jul-2004 Bug 3677924 Check api need not be called for copy
1093 --Check how many plan types exist
1094 IF( l_target_plan_types_cnt = 1 ) THEN
1095 --Call the check API with source attributes
1096 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_COPY_POSSIBLE
1097 (
1098 p_source_plan_level_code => l_s_fin_plan_level_code,
1099 p_source_time_phased_code => l_s_time_phased_code,
1100 p_source_resource_list_id => l_s_resource_list_id,
1101 p_source_version_type => l_s_version_type,
1102 p_project_id => p_project_id,
1103 p_s_ci_id => l_s_fp_ci_id,
1104 p_multiple_plan_types_flag => 'N',
1105 x_copy_possible_flag => l_copy_possible_flag,
1106 x_return_status => x_return_status,
1107 x_msg_count => x_msg_count,
1108 x_msg_data => x_msg_data
1109 ) ;
1110 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1111 RETURN;
1112 END IF;
1113 ELSIF( l_target_plan_types_cnt = 2 ) THEN
1114 --Call the check API with source attributes
1115 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_COPY_POSSIBLE
1116 (
1117 p_source_plan_level_code => l_s_fin_plan_level_code,
1118 p_source_time_phased_code => l_s_time_phased_code,
1119 p_source_resource_list_id => l_s_resource_list_id,
1120 p_source_version_type => l_s_version_type,
1121 p_project_id => p_project_id,
1122 p_s_ci_id => l_s_fp_ci_id,
1123 p_multiple_plan_types_flag => 'Y',
1124 x_copy_possible_flag => l_copy_possible_flag,
1125 x_return_status => x_return_status,
1126 x_msg_count => x_msg_count,
1127 x_msg_data => x_msg_data
1128 ) ;
1129 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1130 RETURN;
1131 END IF;
1132 END IF;
1133
1134 IF NVL(l_copy_possible_flag,'N') = 'N' THEN
1135 x_warning_flag := 'Y';
1136 x_return_status := FND_API.G_RET_STS_ERROR;
1137 RETURN;
1138 END IF;
1139
1140 ------dbms_output.put_line('Came in target plan type count 1 &&&&&');
1141 ------dbms_output.put_line('l_s_fin_plan_level_code : ' || l_s_fin_plan_level_code);
1142 ------dbms_output.put_line('l_s_time_phased_code : ' || l_s_time_phased_code);
1143 ------dbms_output.put_line('l_s_resource_list_id : ' || l_s_resource_list_id);
1144 ------dbms_output.put_line('l_s_version_type : ' || l_s_version_type);
1145 ------dbms_output.put_line('l_s_fp_ci_id : ' || l_s_fp_ci_id);
1146 ------dbms_output.put_line('l_source_version_id : ' || l_source_version_id);
1147 ------dbms_output.put_line('l_copy_possible_flag : ' || l_copy_possible_flag);
1148 ****/ -- bug 3677924
1149
1150 -- Call Copy version API
1151 PA_FIN_PLAN_PUB.Copy_Version
1152 (p_project_id => p_project_id,
1153 p_source_version_id => l_source_version_id,
1154 p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING,
1155 p_calling_module => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN,
1156 px_target_version_id => l_target_version_id,
1157 x_return_status => x_return_status,
1158 x_msg_count => x_msg_count,
1159 x_msg_data => x_msg_data);
1160
1161 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1162 ROLLBACK TO before_fp_ci_copy;
1163 RETURN;
1164 END IF;
1165
1166 l_update_agreement_flag := 'Y';
1167 --Stamp the Control item ids for these budget versions
1168 UPDATE pa_budget_versions bv
1169 SET CI_ID = l_t_fp_ci_id
1170 ,VERSION_NUMBER = 1 -- bug 3677924
1171 WHERE
1172 p_project_id = bv.project_id
1173 AND bv.budget_version_id = l_target_version_id
1174 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1175 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
1176 ELSE
1177 --Target version already exists
1178 IF (l_t_count_versions = 2) THEN
1179 --Get target version id for correct source version type
1180 BEGIN
1181 SELECT bv.budget_version_id
1182 INTO l_target_version_id
1183 FROM pa_budget_versions bv
1184 WHERE
1185 bv.project_id = p_project_id
1186 AND bv.ci_id = l_t_fp_ci_id
1187 AND bv.version_type = l_source_ver_type
1188 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1189 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
1190 EXCEPTION
1191 WHEN NO_DATA_FOUND THEN
1192 PA_UTILS.ADD_MESSAGE
1193 ( p_app_short_name => 'PA',
1194 p_msg_name => 'PA_FP_CI_C_INV_VER_TYPE_MATCH');
1195 ------dbms_output.put_line('FP_CI_CHECK_COPY_POSSIBLE - 2***');
1196 x_return_status := FND_API.G_RET_STS_ERROR;
1197 END;
1198 END IF;
1199
1200 /* -- Now we have both target and source version so
1201 -- go ahead with the MERGE
1202
1203 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_MERGE_POSSIBLE
1204 (
1205 p_project_id => p_project_id,
1206 p_source_fp_version_id_tbl => l_source_id_tbl,
1207 p_target_fp_version_id => l_target_version_id,
1208 p_calling_mode => 'INCLUDE_CR_TO_CO',
1209 x_s_fp_version_id_tbl => l_s_fp_version_id_tbl,
1210 x_t_fp_version_id_tbl => l_t_fp_version_id_tbl,
1211 x_s_fin_plan_level_tbl => l_s_fin_plan_level_code_tbl,
1212 x_t_fin_plan_level_tbl => l_t_fin_plan_level_code_tbl,
1213 x_s_multi_curr_flag_tbl => l_s_multi_curr_flag_tbl,
1214 x_t_multi_curr_flag_tbl => l_t_multi_curr_flag_tbl,
1215 x_s_fin_plan_pref_code_tbl => l_s_fin_plan_pref_code_tbl,
1216 x_t_fin_plan_pref_code_tbl => l_t_fin_plan_pref_code_tbl,
1217 x_s_uncategorized_flag_tbl => l_s_uncategorized_flag_tbl,
1218 x_t_uncategorized_flag_tbl => l_t_uncategorized_flag_tbl,
1219 x_s_version_type_tbl => l_s_version_type_tbl,
1220 x_t_version_type_tbl => l_t_version_type_tbl,
1221 x_s_time_phased_code_tbl => l_s_time_phased_code_tbl,
1222 x_t_time_phased_code_tbl => l_t_time_phased_code_tbl,
1223 x_merge_possible_code_tbl => l_merge_possible_code_tbl,
1224 x_return_status => x_return_status,
1225 x_msg_count => x_msg_count,
1226 x_msg_data => x_msg_data
1227 );
1228 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 6');
1229 -- LOOP THRU THE PL/SQL MERGE RESULT TABLE
1230 -- Need to do it TWICE
1231
1232 -- First: check for merge possible code for each line in
1233 -- the PL/SQL table. If even one is error code then
1234 -- return to calling program
1235
1236 FOR i in l_s_fp_version_id_tbl.FIRST.. l_s_fp_version_id_tbl.LAST
1237 LOOP
1238 --Assigning merge possible code from the PL/SQL table
1239 l_merge_possible_code := l_merge_possible_code_tbl (i);
1240 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 7');
1241 IF (l_merge_possible_code = 'E') THEN
1242 x_warning_flag := 'Y';
1243 x_return_status := FND_API.G_RET_STS_ERROR;
1244 RETURN;
1245 END IF;
1246 END LOOP;
1247
1248 -- Second: IF merge is possible for each of the source and
1249 -- target version ids then go ahead with the merge
1250 -- one by one
1251
1252 FOR i in l_s_fp_version_id_tbl.FIRST.. l_s_fp_version_id_tbl.LAST
1253 LOOP
1254 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 8');
1255 --Assigning values from the PL/SQL table FOR SOURCE VERSION
1256 l_s_version_id := l_s_fp_version_id_tbl(i);
1257 l_s_fin_plan_pref_code := l_s_fin_plan_pref_code_tbl(i) ;
1258 l_s_multi_curr_flag := l_s_multi_curr_flag_tbl(i) ;
1259 l_s_fin_plan_level_code := l_s_fin_plan_level_code_tbl(i);
1260 l_s_uncategorized_flag := l_s_uncategorized_flag_tbl(i);
1261 l_s_version_type := l_s_version_type_tbl(i);
1262 l_s_time_phased_code := l_s_time_phased_code_tbl(i);
1263 l_t_version_id := l_t_fp_version_id_tbl(i);
1264 l_t_fin_plan_pref_code := l_t_fin_plan_pref_code_tbl(i) ;
1265 l_t_multi_curr_flag := l_t_multi_curr_flag_tbl(i) ;
1266 l_t_fin_plan_level_code := l_t_fin_plan_level_code_tbl(i);
1267 l_t_uncategorized_flag := l_t_uncategorized_flag_tbl(i);
1268 l_t_version_type := l_t_version_type_tbl(i);
1269 l_t_time_phased_code := l_t_time_phased_code_tbl(i);
1270 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 9');
1271 -- Call the Manage Fp_Ci_Merge API for one source and
1272 -- one target version id at a time
1273
1274
1275 ------dbms_output.put_line('IN FP_CI_MERGE_CI_ITEMS');
1276 ------dbms_output.put_line('l_s_version_id :' || l_s_version_id);
1277 ------dbms_output.put_line('l_t_version_id :' || l_t_version_id);
1278 ------dbms_output.put_line('l_s_fin_plan_pref_code :' || l_s_fin_plan_pref_code);
1279 ------dbms_output.put_line('l_t_fin_plan_pref_code :' || l_t_fin_plan_pref_code);
1280 ------dbms_output.put_line('l_s_multi_curr_flag :' || l_s_multi_curr_flag);
1281 ------dbms_output.put_line('l_t_multi_curr_flag :' || l_t_multi_curr_flag);
1282 ------dbms_output.put_line('l_s_fin_plan_level_code :' || l_s_fin_plan_level_code);
1283 ------dbms_output.put_line('l_t_fin_plan_level_code :' || l_t_fin_plan_level_code);
1284 ------dbms_output.put_line('l_s_uncategorized_flag :' || l_s_uncategorized_flag);
1285 ------dbms_output.put_line('l_t_uncategorized_flag :' || l_t_uncategorized_flag);
1286 ------dbms_output.put_line('l_s_version_type :' || l_s_version_type);
1287 ------dbms_output.put_line('l_t_version_type :' || l_t_version_type);*/
1288 l_impl_cost_flag_tbl.extend(1);
1289 l_impl_rev_flag_tbl.extend(1);
1290 l_impl_cost_flag_tbl(1):='N';
1291 l_impl_rev_flag_tbl(1):='N';
1292 l_ci_id_tbl.extend(1); -- Bug 3787567
1293 l_ci_id_tbl(1):=l_s_fp_ci_id;
1294 l_target_version_id_tbl.extend(1); -- Bug 3787567
1295 l_target_version_id_tbl(1):=l_target_version_id;
1296 IF l_source_ver_type ='COST' THEN
1297 l_ci_cost_version_id_tbl.extend(1);
1298 l_ci_cost_version_id_tbl(1):=l_source_version_id;
1299 l_impl_cost_flag_tbl(1):='Y';
1300 ELSIF l_source_ver_type ='REVENUE' THEN
1301 l_ci_rev_version_id_tbl.extend(1);
1302 l_ci_rev_version_id_tbl(1):=l_source_version_id;
1303 l_impl_rev_flag_tbl(1):='Y';
1304 ELSIF l_source_ver_type ='ALL' THEN
1305 l_ci_all_version_id_tbl.extend(1);
1306 l_ci_all_version_id_tbl(1):=l_source_version_id;
1307 l_impl_cost_flag_tbl(1):='Y';
1308 l_impl_rev_flag_tbl(1):='Y';
1309 END IF;
1310
1311 implement_change_document
1312 ( p_context => 'CI_MERGE'
1313 ,p_ci_id_tbl => l_ci_id_tbl
1314 ,p_ci_cost_version_id_tbl => l_ci_cost_version_id_tbl
1315 ,p_ci_rev_version_id_tbl => l_ci_rev_version_id_tbl
1316 ,p_ci_all_version_id_tbl => l_ci_all_version_id_tbl
1317 ,p_budget_version_id_tbl => l_target_version_id_tbl
1318 ,p_impl_cost_flag_tbl => l_impl_cost_flag_tbl
1319 ,p_impl_rev_flag_tbl => l_impl_rev_flag_tbl
1320 ,x_translated_msgs_tbl => l_translated_msgs_tbl
1321 ,x_translated_err_msg_count => l_translated_err_msg_count
1322 ,x_translated_err_msg_level_tbl => l_translated_err_msg_level_tbl
1323 ,x_return_status => x_return_status
1324 ,x_msg_count => x_msg_count
1325 ,x_msg_data => x_msg_data);
1326 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1327 ROLLBACK TO before_fp_ci_copy;
1328 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
1329 RETURN;
1330 END IF;
1331
1332 l_update_agreement_flag := 'N';
1333
1334 /*FP_CI_MANAGE_MERGE
1335 (
1336 p_project_id => p_project_id,
1337 p_s_version_id => l_s_version_id,
1338 p_s_fin_plan_pref_code => l_s_fin_plan_pref_code,
1339 p_s_multi_curr_flag => l_s_multi_curr_flag,
1340 p_s_fin_plan_level_code => l_s_fin_plan_level_code,
1341 p_s_uncategorized_flag => l_s_uncategorized_flag,
1342 p_s_version_type => l_s_version_type,
1343 p_s_time_phased_code => l_s_time_phased_code,
1344 p_t_version_id => l_t_version_id,
1345 p_t_fin_plan_pref_code => l_t_fin_plan_pref_code,
1346 p_t_multi_curr_flag => l_t_multi_curr_flag,
1347 p_t_fin_plan_level_code => l_t_fin_plan_level_code,
1348 p_t_uncategorized_flag => l_t_uncategorized_flag,
1349 p_t_version_type => l_t_version_type,
1350 p_t_time_phased_code => l_t_time_phased_code,
1351 p_merge_unmerge_mode => p_merge_unmerge_mode,
1352 x_return_status => x_return_status,
1353 x_msg_count => x_msg_count,
1354 x_msg_data => x_msg_data
1355 );*/
1356 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 10');
1357 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1358 ROLLBACK TO before_fp_ci_copy;
1359 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
1360 RETURN;
1361 END IF;
1362
1363 /*-- After successful merge one would need
1364 -- to update the control item and financial
1365 -- planning merge record table
1366
1367 --Check if record already exists for the merge
1368 SELECT COUNT(*)
1369 INTO l_count_merged_versions
1370 FROM pa_fp_merged_ctrl_items
1371 WHERE
1372 ci_plan_version_id = l_s_version_id
1373 AND plan_version_id = l_t_version_id
1374 AND project_id = p_project_id;
1375
1376 IF (l_count_merged_versions = 0) THEN
1377 -- record doesn't exist - so insert it
1378 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 12');
1379 FP_CI_LINK_CONTROL_ITEMS
1380 (
1381 p_project_id => p_project_id,
1382 p_s_fp_version_id => l_s_version_id,
1383 p_t_fp_version_id => l_t_version_id,
1384 p_inclusion_method => 'AUTOMATIC',
1385 p_included_by => NULL,
1386 x_return_status => x_return_status,
1387 x_msg_count => x_msg_count,
1388 x_msg_data => x_msg_data
1389 );
1390 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 120');
1391 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1392 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 12****');
1393 ROLLBACK TO before_fp_ci_copy;
1394 RETURN;
1395 END IF;
1396 END IF;
1397
1398 -- Call the convert currency API
1399 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 13');
1400 PA_FP_MULTI_CURRENCY_PKG.convert_txn_currency
1401 (
1402 p_budget_version_id => l_t_version_id
1403 ,p_entire_version => 'Y'
1404 ,x_return_status => x_return_status
1405 ,x_msg_count => x_msg_count
1406 ,x_msg_data => x_msg_data
1407 );
1408 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 130');
1409 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1410 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 13****');
1411 ROLLBACK TO before_fp_ci_copy;
1412 RETURN;
1413 END IF;
1414
1415 -- Call the Roll up budget version API API
1416 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 15');
1417 PA_FP_ROLLUP_PKG.rollup_budget_version
1418 (
1419 p_budget_version_id => l_t_version_id
1420 ,p_entire_version => 'Y'
1421 ,x_return_status => x_return_status
1422 ,x_msg_count => x_msg_count
1423 ,x_msg_data => x_msg_data
1424 );
1425 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150');
1426 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1427 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 15****');
1428 ROLLBACK TO before_fp_ci_copy;
1429 RETURN;
1430 END IF;
1431
1432 END LOOP; */
1433 END IF;
1434
1435 --Call the update estimated amounts API to update the estimated amounts
1436 FP_CI_UPDATE_EST_AMOUNTS
1437 (
1438 p_project_id => p_project_id,
1439 p_source_version_id => l_source_version_id,
1440 p_target_version_id => l_target_version_id,
1441 p_merge_unmerge_mode => p_merge_unmerge_mode ,
1442 p_commit_flag => 'N' ,
1443 p_init_msg_list => 'N',
1444 p_update_agreement => l_update_agreement_flag,
1445 x_return_status => x_return_status,
1446 x_msg_count => x_msg_count,
1447 x_msg_data => x_msg_data
1448 );
1449 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1450 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
1451 ROLLBACK TO before_fp_ci_copy;
1452 RETURN;
1453 END IF;
1454 ELSIF (l_s_version_id_count = 2) THEN
1455 --Get both source version ids
1456 SELECT bv.budget_version_id
1457 BULK COLLECT INTO l_source_fp_version_id_tbl
1458 FROM pa_budget_versions bv
1459 WHERE
1460 bv.project_id = p_project_id
1461 AND bv.ci_id = l_s_fp_ci_id
1462 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1463 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y')
1464 ORDER BY bv.version_type;
1465
1466
1467 IF (l_t_count_versions = 0) THEN
1468 For i in l_source_fp_version_id_tbl.FIRST.. l_source_fp_version_id_tbl.LAST
1469 LOOP
1470 BEGIN
1471 --Get source version id in local variable
1472 l_source_version_id := l_source_fp_version_id_tbl(i);
1473 l_target_version_id := NULL;
1474 -- We must copy the target version from source version
1475
1476 --Before that get details of source version
1477 Pa_Fp_Control_Items_Utils.FP_CI_GET_VERSION_DETAILS
1478 (
1479 p_project_id => p_project_id,
1480 p_budget_version_id => l_source_version_id,
1481 x_fin_plan_pref_code => l_s_fin_plan_pref_code,
1482 x_multi_curr_flag => l_s_multi_curr_flag,
1483 x_fin_plan_level_code => l_s_fin_plan_level_code,
1484 x_resource_list_id => l_s_resource_list_id,
1485 x_time_phased_code => l_s_time_phased_code,
1486 x_uncategorized_flag => l_s_uncategorized_flag,
1487 x_group_res_type_id => l_s_group_res_type_id,
1488 x_version_type => l_s_version_type,
1489 x_ci_id => l_s_ci_id,
1490 x_return_status => x_return_status,
1491 x_msg_count => x_msg_count,
1492 x_msg_data => x_msg_data
1493 ) ;
1494
1495 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1496 RETURN;
1497 END IF;
1498
1499 -- Bug 3677924 Jul 06 2004 Raja
1500 -- Check if target change order has corresponding impact record
1501 -- Note: If the target change order type does not allow the corresponding
1502 -- impact,the impact record would not have been created. The fact that there
1503 -- are two source versions version type would be either cost or rev only.
1504 BEGIN
1505 SELECT 'Y'
1506 INTO l_impact_record_exists
1507 FROM DUAL
1508 WHERE EXISTS
1509 (SELECT 1
1510 FROM pa_ci_impacts
1511 WHERE ci_id = l_t_fp_ci_id
1512 AND (l_s_version_type IN ('REVENUE') AND impact_type_code = 'FINPLAN_REVENUE'
1513 OR l_s_version_type IN ('COST') AND impact_type_code = 'FINPLAN_COST'));
1514 EXCEPTION
1515 WHEN NO_DATA_FOUND THEN
1516 l_impact_record_exists := 'N';
1517 END;
1518
1519 -- Bug 3677924 If the impact record does not exist skip processing
1520 IF l_impact_record_exists = 'Y' THEN
1521
1522 /*** raja 14-Jul-2004 Bug 3677924 Check api need not be called for copy
1523 --Check how many plan types exist
1524 IF( l_target_plan_types_cnt = 2 ) THEN
1525 --Call the check API with source attributes
1526 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_COPY_POSSIBLE
1527 (
1528 p_source_plan_level_code => l_s_fin_plan_level_code,
1529 p_source_time_phased_code => l_s_time_phased_code,
1530 p_source_resource_list_id => l_s_resource_list_id,
1531 p_source_version_type => l_s_version_type,
1532 p_project_id => p_project_id,
1533 p_s_ci_id => l_s_fp_ci_id,
1534 p_multiple_plan_types_flag => 'Y',
1535 x_copy_possible_flag => l_copy_possible_flag,
1536 x_return_status => x_return_status,
1537 x_msg_count => x_msg_count,
1538 x_msg_data => x_msg_data
1539 ) ;
1540 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1541 RETURN;
1542 END IF;
1543 ELSIF( l_target_plan_types_cnt = 1 ) THEN
1544 --Call the check API with source attributes
1545 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_COPY_POSSIBLE
1546 (
1547 p_source_plan_level_code => l_s_fin_plan_level_code,
1548 p_source_time_phased_code => l_s_time_phased_code,
1549 p_source_resource_list_id => l_s_resource_list_id,
1550 p_source_version_type => l_s_version_type,
1551 p_project_id => p_project_id,
1552 p_s_ci_id => l_s_fp_ci_id,
1553 p_multiple_plan_types_flag => 'N',
1554 x_copy_possible_flag => l_copy_possible_flag,
1555 x_return_status => x_return_status,
1556 x_msg_count => x_msg_count,
1557 x_msg_data => x_msg_data
1558 ) ;
1559 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1560 RETURN;
1561 END IF;
1562 END IF;
1563
1564 IF l_copy_possible_flag = 'N' THEN
1565 raise RAISE_COPY_ERROR;
1566 END IF;
1567
1568 ------dbms_output.put_line('Came in target plan type count 2 &&&&&');
1569 ------dbms_output.put_line('l_s_fin_plan_level_code : ' || l_s_fin_plan_level_code);
1570 ------dbms_output.put_line('l_s_time_phased_code : ' || l_s_time_phased_code);
1571 ------dbms_output.put_line('l_s_resource_list_id : ' || l_s_resource_list_id);
1572 ------dbms_output.put_line('l_s_version_type : ' || l_s_version_type);
1573 ------dbms_output.put_line('l_s_fp_ci_id : ' || l_s_fp_ci_id);
1574 ------dbms_output.put_line('l_source_version_id : ' || l_source_version_id);
1575 ------dbms_output.put_line('l_copy_possible_flag : ' || l_copy_possible_flag);
1576 ***/ -- Bug 3677924
1577 -- Call Copy version API
1578 PA_FIN_PLAN_PUB.Copy_Version
1579 (p_project_id => p_project_id,
1580 p_source_version_id => l_source_version_id,
1581 p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING,
1582 p_calling_module => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN,
1583 px_target_version_id => l_target_version_id,
1584 x_return_status => x_return_status,
1585 x_msg_count => x_msg_count,
1586 x_msg_data => x_msg_data);
1587
1588 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1589 ROLLBACK TO before_fp_ci_copy;
1590 RETURN;
1591 END IF;
1592
1593 l_update_agreement_flag := 'Y';
1594
1595 --Stamp the Control item ids for this budget versions
1596 UPDATE pa_budget_versions bv
1597 SET CI_ID = l_t_fp_ci_id
1598 ,version_number = 1 -- Bug 3677924 Jul 06 2004 Raja
1599 WHERE
1600 p_project_id = bv.project_id
1601 AND bv.budget_version_id = l_target_version_id
1602 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1603 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
1604
1605 --Call the update estimated amounts API to update the estimated amounts
1606 FP_CI_UPDATE_EST_AMOUNTS
1607 (
1608 p_project_id => p_project_id,
1609 p_source_version_id => l_source_version_id,
1610 p_target_version_id => l_target_version_id,
1611 p_merge_unmerge_mode => p_merge_unmerge_mode ,
1612 p_commit_flag => 'N' ,
1613 p_init_msg_list => 'N',
1614 p_update_agreement => l_update_agreement_flag,
1615 x_return_status => x_return_status,
1616 x_msg_count => x_msg_count,
1617 x_msg_data => x_msg_data
1618 );
1619 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1620 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
1621 ROLLBACK TO before_fp_ci_copy;
1622 RETURN;
1623 END IF;
1624 END IF; -- if impact record exists copy amounts
1625 EXCEPTION
1626 WHEN RAISE_COPY_ERROR THEN
1627 x_warning_flag := 'Y';
1628 x_return_status := FND_API.G_RET_STS_ERROR;
1629 END;
1630 END LOOP;
1631 ELSIF(l_t_count_versions = 2) THEN
1632 --Get target version id
1633 --Since ordered by version type, the first version should be cost and the second one should be revenue
1634 SELECT bv.budget_version_id
1635 BULK COLLECT INTO l_target_fp_version_id_tbl
1636 FROM pa_budget_versions bv
1637 WHERE
1638 bv.project_id = p_project_id
1639 AND bv.ci_id = l_t_fp_ci_id
1640 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1641 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y')
1642 ORDER BY bv.version_type;
1643
1644
1645 --Prepare the pl/sql tables for change document
1646 l_ci_id_tbl.extend(1);
1647 l_ci_cost_version_id_tbl.extend(1);
1648 l_ci_rev_version_id_tbl.extend(1);
1649 l_ci_id_tbl(1):=l_s_fp_ci_id;
1650 l_ci_cost_version_id_tbl(1):=l_source_fp_version_id_tbl(1);--Cost Version
1651 l_ci_rev_version_id_tbl(1):=l_source_fp_version_id_tbl(2);--Revenue Version
1652
1653
1654 --Prepare pl/sql tbls for target version
1655 l_target_version_id_tbl.extend(2);
1656 l_impl_cost_flag_tbl.extend(2);
1657 l_impl_rev_flag_tbl.extend(2);
1658 l_target_version_id_tbl(1):=l_target_fp_version_id_tbl(1);
1659 l_target_version_id_tbl(2):=l_target_fp_version_id_tbl(2);
1660 l_impl_cost_flag_tbl(1):='Y';
1661 l_impl_rev_flag_tbl(1):='N';
1662 l_impl_cost_flag_tbl(2):='N';
1663 l_impl_rev_flag_tbl(2):='Y';
1664
1665 implement_change_document
1666 ( p_context => 'CI_MERGE'
1667 ,p_ci_id_tbl => l_ci_id_tbl
1668 ,p_ci_cost_version_id_tbl => l_ci_cost_version_id_tbl
1669 ,p_ci_rev_version_id_tbl => l_ci_rev_version_id_tbl
1670 ,p_ci_all_version_id_tbl => l_ci_all_version_id_tbl
1671 ,p_budget_version_id_tbl => l_target_version_id_tbl
1672 ,p_impl_cost_flag_tbl => l_impl_cost_flag_tbl
1673 ,p_impl_rev_flag_tbl => l_impl_rev_flag_tbl
1674 ,x_translated_msgs_tbl => l_translated_msgs_tbl
1675 ,x_translated_err_msg_count => l_translated_err_msg_count
1676 ,x_translated_err_msg_level_tbl => l_translated_err_msg_level_tbl
1677 ,x_return_status => x_return_status
1678 ,x_msg_count => x_msg_count
1679 ,x_msg_data => x_msg_data);
1680 l_update_agreement_flag := 'N';
1681 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1682 ROLLBACK TO before_fp_ci_copy;
1683 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
1684 RETURN;
1685 END IF;
1686
1687 --Bug 4132915. Passing the correct source and target version id.
1688 FOR i IN 1..2
1689 LOOP
1690 FP_CI_UPDATE_EST_AMOUNTS
1691 (
1692 p_project_id => p_project_id,
1693 p_source_version_id => l_source_fp_version_id_tbl(i),
1694 p_target_version_id => l_target_fp_version_id_tbl(i),
1695 p_merge_unmerge_mode => p_merge_unmerge_mode ,
1696 p_commit_flag => 'N' ,
1697 p_init_msg_list => 'N',
1698 p_update_agreement => l_update_agreement_flag,
1699 x_return_status => x_return_status,
1700 x_msg_count => x_msg_count,
1701 x_msg_data => x_msg_data
1702 );
1703 /*FP_CI_UPDATE_EST_AMOUNTS
1704 (
1705 p_project_id => p_project_id,
1706 p_source_version_id => l_s_version_id,
1707 p_target_version_id => l_t_version_id,
1708 p_merge_unmerge_mode => p_merge_unmerge_mode ,
1709 p_commit_flag => 'N' ,
1710 p_init_msg_list => 'N',
1711 p_update_agreement => l_update_agreement_flag,
1712 x_return_status => x_return_status,
1713 x_msg_count => x_msg_count,
1714 x_msg_data => x_msg_data
1715 );*/
1716 END LOOP;
1717
1718 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1719 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
1720 ROLLBACK TO before_fp_ci_copy;
1721 RETURN;
1722 END IF;
1723
1724
1725 /*FOR i in l_source_fp_version_id_tbl.FIRST.. l_source_fp_version_id_tbl.LAST
1726 LOOP
1727 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 2');
1728 l_source_version_id := l_source_fp_version_id_tbl(i);
1729 l_source_id_tbl.DELETE;
1730 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 3');
1731 l_source_id_tbl(1) := l_source_version_id;
1732 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 4');
1733 l_target_version_id := l_target_fp_version_id_tbl(i);
1734 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 5');
1735 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_MERGE_POSSIBLE
1736 (
1737 p_project_id => p_project_id,
1738 p_source_fp_version_id_tbl => l_source_id_tbl,
1739 p_target_fp_version_id => l_target_version_id,
1740 p_calling_mode => 'INCLUDE_CR_TO_CO',
1741 x_s_fp_version_id_tbl => l_s_fp_version_id_tbl,
1742 x_t_fp_version_id_tbl => l_t_fp_version_id_tbl,
1743 x_s_fin_plan_level_tbl => l_s_fin_plan_level_code_tbl,
1744 x_t_fin_plan_level_tbl => l_t_fin_plan_level_code_tbl,
1745 x_s_multi_curr_flag_tbl => l_s_multi_curr_flag_tbl,
1746 x_t_multi_curr_flag_tbl => l_t_multi_curr_flag_tbl,
1747 x_s_fin_plan_pref_code_tbl => l_s_fin_plan_pref_code_tbl,
1748 x_t_fin_plan_pref_code_tbl => l_t_fin_plan_pref_code_tbl,
1749 x_s_uncategorized_flag_tbl => l_s_uncategorized_flag_tbl,
1750 x_t_uncategorized_flag_tbl => l_t_uncategorized_flag_tbl,
1751 x_s_version_type_tbl => l_s_version_type_tbl,
1752 x_t_version_type_tbl => l_t_version_type_tbl,
1753 x_s_time_phased_code_tbl => l_s_time_phased_code_tbl,
1754 x_t_time_phased_code_tbl => l_t_time_phased_code_tbl,
1755 x_merge_possible_code_tbl => l_merge_possible_code_tbl,
1756 x_return_status => x_return_status,
1757 x_msg_count => x_msg_count,
1758 x_msg_data => x_msg_data
1759 );
1760 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 6');
1761 -- LOOP THRU THE PL/SQL MERGE RESULT TABLE
1762 -- Need to do it TWICE
1763
1764 -- First: check for merge possible code for each line in
1765 -- the PL/SQL table. If even one is error code then
1766 -- return to calling program
1767
1768 FOR i in l_s_fp_version_id_tbl.FIRST.. l_s_fp_version_id_tbl.LAST
1769 LOOP
1770 --Assigning merge possible code from the PL/SQL table
1771 l_merge_possible_code := l_merge_possible_code_tbl (i);
1772 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 7');
1773 IF (l_merge_possible_code = 'E') THEN
1774 x_warning_flag := 'Y';
1775 x_return_status := FND_API.G_RET_STS_ERROR;
1776 END IF;
1777 END LOOP;
1778
1779 -- Second: IF merge is possible for the source and
1780 -- target version ids then go ahead with the merge
1781 -- one by one
1782
1783 FOR i in l_s_fp_version_id_tbl.FIRST.. l_s_fp_version_id_tbl.LAST
1784 LOOP
1785 l_merge_possible_code := l_merge_possible_code_tbl (i);
1786 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 7');
1787 IF (l_merge_possible_code <> 'E') THEN
1788 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 8');
1789 --Assigning values from the PL/SQL table FOR SOURCE VERSION
1790 l_s_version_id := l_s_fp_version_id_tbl(i);
1791 l_s_fin_plan_pref_code := l_s_fin_plan_pref_code_tbl(i) ;
1792 l_s_multi_curr_flag := l_s_multi_curr_flag_tbl(i) ;
1793 l_s_fin_plan_level_code := l_s_fin_plan_level_code_tbl(i);
1794 l_s_uncategorized_flag := l_s_uncategorized_flag_tbl(i);
1795 l_s_version_type := l_s_version_type_tbl(i);
1796 l_s_time_phased_code := l_s_time_phased_code_tbl(i);
1797 l_t_version_id := l_t_fp_version_id_tbl(i);
1798 l_t_fin_plan_pref_code := l_t_fin_plan_pref_code_tbl(i) ;
1799 l_t_multi_curr_flag := l_t_multi_curr_flag_tbl(i) ;
1800 l_t_fin_plan_level_code := l_t_fin_plan_level_code_tbl(i);
1801 l_t_uncategorized_flag := l_t_uncategorized_flag_tbl(i);
1802 l_t_version_type := l_t_version_type_tbl(i);
1803 l_t_time_phased_code := l_t_time_phased_code_tbl(i);
1804 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 9');
1805 -- Call the Manage Fp_Ci_Merge API for one source and
1806 -- one target version id at a time
1807
1808
1809 ------dbms_output.put_line('IN FP_CI_MERGE_CI_ITEMS');
1810 ------dbms_output.put_line('l_s_version_id :' || l_s_version_id);
1811 ------dbms_output.put_line('l_t_version_id :' || l_t_version_id);
1812 ------dbms_output.put_line('l_s_fin_plan_pref_code :' || l_s_fin_plan_pref_code);
1813 ------dbms_output.put_line('l_t_fin_plan_pref_code :' || l_t_fin_plan_pref_code);
1814 ------dbms_output.put_line('l_s_multi_curr_flag :' || l_s_multi_curr_flag);
1815 ------dbms_output.put_line('l_t_multi_curr_flag :' || l_t_multi_curr_flag);
1816 ------dbms_output.put_line('l_s_fin_plan_level_code :' || l_s_fin_plan_level_code);
1817 ------dbms_output.put_line('l_t_fin_plan_level_code :' || l_t_fin_plan_level_code);
1818 ------dbms_output.put_line('l_s_uncategorized_flag :' || l_s_uncategorized_flag);
1819 ------dbms_output.put_line('l_t_uncategorized_flag :' || l_t_uncategorized_flag);
1820 ------dbms_output.put_line('l_s_version_type :' || l_s_version_type);
1821 ------dbms_output.put_line('l_t_version_type :' || l_t_version_type);
1822
1823 FP_CI_MANAGE_MERGE
1824 (
1825 p_project_id => p_project_id,
1826 p_s_version_id => l_s_version_id,
1827 p_s_fin_plan_pref_code => l_s_fin_plan_pref_code,
1828 p_s_multi_curr_flag => l_s_multi_curr_flag,
1829 p_s_fin_plan_level_code => l_s_fin_plan_level_code,
1830 p_s_uncategorized_flag => l_s_uncategorized_flag,
1831 p_s_version_type => l_s_version_type,
1832 p_s_time_phased_code => l_s_time_phased_code,
1833 p_t_version_id => l_t_version_id,
1834 p_t_fin_plan_pref_code => l_t_fin_plan_pref_code,
1835 p_t_multi_curr_flag => l_t_multi_curr_flag,
1836 p_t_fin_plan_level_code => l_t_fin_plan_level_code,
1837 p_t_uncategorized_flag => l_t_uncategorized_flag,
1838 p_t_version_type => l_t_version_type,
1839 p_t_time_phased_code => l_t_time_phased_code,
1840 p_merge_unmerge_mode => p_merge_unmerge_mode,
1841 x_return_status => x_return_status,
1842 x_msg_count => x_msg_count,
1843 x_msg_data => x_msg_data
1844 );
1845 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 10');
1846 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1847 ROLLBACK TO before_fp_ci_copy;
1848 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
1849 RETURN;
1850 END IF;
1851
1852 -- After successful merge one would need
1853 -- to update the control item and financial
1854 -- planning merge record table
1855
1856 --Check if record already exists for the merge
1857 SELECT COUNT(*)
1858 INTO l_count_merged_versions
1859 FROM pa_fp_merged_ctrl_items
1860 WHERE
1861 ci_plan_version_id = l_s_version_id
1862 AND plan_version_id = l_t_version_id
1863 AND project_id = p_project_id;
1864
1865 IF (l_count_merged_versions = 0) THEN
1866 -- record doesn't exist - so insert it
1867 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 12');
1868 FP_CI_LINK_CONTROL_ITEMS
1869 (
1870 p_project_id => p_project_id,
1871 p_s_fp_version_id => l_s_version_id,
1872 p_t_fp_version_id => l_t_version_id,
1873 p_inclusion_method => 'AUTOMATIC',
1874 p_included_by => NULL,
1875 x_return_status => x_return_status,
1876 x_msg_count => x_msg_count,
1877 x_msg_data => x_msg_data
1878 );
1879 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 120');
1880 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1881 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 12****');
1882 ROLLBACK TO before_fp_ci_copy;
1883 RETURN;
1884 END IF;
1885 END IF;
1886
1887 -- Call the convert currency API
1888 --------dbms_output.put_line('FP_CI_COPY_CONTROL_ITEMS - 13');
1889 PA_FP_MULTI_CURRENCY_PKG.convert_txn_currency
1890 (
1891 p_budget_version_id => l_t_version_id
1892 ,p_entire_version => 'Y'
1893 ,x_return_status => x_return_status
1894 ,x_msg_count => x_msg_count
1895 ,x_msg_data => x_msg_data
1896 );
1897 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 130');
1898 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1899 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 13****');
1900 ROLLBACK TO before_fp_ci_copy;
1901 RETURN;
1902 END IF;
1903
1904 -- Call the Roll up budget version API API
1905 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 15');
1906 PA_FP_ROLLUP_PKG.rollup_budget_version
1907 (
1908 p_budget_version_id => l_t_version_id
1909 ,p_entire_version => 'Y'
1910 ,x_return_status => x_return_status
1911 ,x_msg_count => x_msg_count
1912 ,x_msg_data => x_msg_data
1913 );
1914 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150');
1915 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1916 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 15****');
1917 ROLLBACK TO before_fp_ci_copy;
1918 RETURN;
1919 END IF;
1920
1921 l_update_agreement_flag := 'N';
1922
1923 --Call the update estimated amounts API to update the estimated amounts
1924 END IF;
1925 END LOOP;
1926 END LOOP;*/
1927 ELSIF(l_t_count_versions = 1) THEN
1928 --Get target version id and version type
1929 SELECT bv.budget_version_id, bv.version_type
1930 INTO l_target_version_id, l_target_ver_type
1931 FROM pa_budget_versions bv
1932 WHERE
1933 bv.project_id = p_project_id
1934 AND bv.ci_id = l_t_fp_ci_id
1935 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
1936 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
1937
1938 l_target_version_id_tmp := l_target_version_id;
1939
1940 IF l_target_ver_type='ALL' THEN
1941
1942 --Prepare the pl/sql tables for change document
1943 l_ci_id_tbl.extend(1);
1944 l_ci_cost_version_id_tbl.extend(1);
1945 l_ci_rev_version_id_tbl.extend(1);
1946 l_ci_id_tbl(1):=l_s_fp_ci_id;
1947 l_ci_cost_version_id_tbl(1):=l_source_fp_version_id_tbl(1);--Cost Version
1948 l_ci_rev_version_id_tbl(1):=l_source_fp_version_id_tbl(2);--Revenue Version
1949
1950
1951 --Prepare pl/sql tbls for target version
1952 l_target_version_id_tbl.extend(1);
1953 l_impl_cost_flag_tbl.extend(1);
1954 l_impl_rev_flag_tbl.extend(1);
1955 l_target_version_id_tbl(1):=l_target_fp_version_id_tbl(1);
1956 l_impl_cost_flag_tbl(1):='Y';
1957 l_impl_rev_flag_tbl(1):='Y';
1958
1959 implement_change_document
1960 ( p_context => 'CI_MERGE'
1961 ,p_ci_id_tbl => l_ci_id_tbl
1962 ,p_ci_cost_version_id_tbl => l_ci_cost_version_id_tbl
1963 ,p_ci_rev_version_id_tbl => l_ci_rev_version_id_tbl
1964 ,p_ci_all_version_id_tbl => l_ci_all_version_id_tbl
1965 ,p_budget_version_id_tbl => l_target_version_id_tbl
1966 ,p_impl_cost_flag_tbl => l_impl_cost_flag_tbl
1967 ,p_impl_rev_flag_tbl => l_impl_rev_flag_tbl
1968 ,x_translated_msgs_tbl => l_translated_msgs_tbl
1969 ,x_translated_err_msg_count => l_translated_err_msg_count
1970 ,x_translated_err_msg_level_tbl => l_translated_err_msg_level_tbl
1971 ,x_return_status => x_return_status
1972 ,x_msg_count => x_msg_count
1973 ,x_msg_data => x_msg_data);
1974 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1975 ROLLBACK TO before_fp_ci_copy;
1976 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
1977 RETURN;
1978 END IF;
1979
1980 l_update_agreement_flag := 'N';
1981
1982 --Bug 4132915. Passing the correct source and target version id.
1983 FOR i IN 1..2
1984 LOOP
1985 FP_CI_UPDATE_EST_AMOUNTS
1986 (
1987 p_project_id => p_project_id,
1988 p_source_version_id => l_source_fp_version_id_tbl(i),
1989 p_target_version_id => l_target_version_id_tbl(1),
1990 p_merge_unmerge_mode => p_merge_unmerge_mode ,
1991 p_commit_flag => 'N' ,
1992 p_init_msg_list => 'N',
1993 p_update_agreement => l_update_agreement_flag,
1994 x_return_status => x_return_status,
1995 x_msg_count => x_msg_count,
1996 x_msg_data => x_msg_data
1997 );
1998 /*FP_CI_UPDATE_EST_AMOUNTS
1999 (
2000 p_project_id => p_project_id,
2001 p_source_version_id => l_s_version_id,
2002 p_target_version_id => l_t_version_id,
2003 p_merge_unmerge_mode => p_merge_unmerge_mode ,
2004 p_commit_flag => 'N' ,
2005 p_init_msg_list => 'N',
2006 p_update_agreement => l_update_agreement_flag,
2007 x_return_status => x_return_status,
2008 x_msg_count => x_msg_count,
2009 x_msg_data => x_msg_data
2010 );*/
2011 END LOOP;
2012
2013 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2014 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
2015 ROLLBACK TO before_fp_ci_copy;
2016 RETURN;
2017 END IF;
2018
2019 ELSE
2020
2021 --Process for each source version id
2022 FOR i in l_source_fp_version_id_tbl.FIRST.. l_source_fp_version_id_tbl.LAST
2023 LOOP
2024 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 2');
2025 l_source_version_id := l_source_fp_version_id_tbl(i);
2026
2027 -- Get the source version type
2028 SELECT bv.version_type
2029 INTO l_source_ver_type
2030 FROM pa_budget_versions bv
2031 WHERE bv.project_id = p_project_id
2032 AND bv.budget_version_id = l_source_version_id;
2033
2034 IF(l_source_ver_type <> l_target_ver_type) THEN
2035 --The target should be copied from the source
2036 BEGIN
2037 --Since the current target is not for the present source
2038 l_target_version_id := NULL;
2039 --Before that get details of source version
2040 Pa_Fp_Control_Items_Utils.FP_CI_GET_VERSION_DETAILS
2041 (
2042 p_project_id => p_project_id,
2043 p_budget_version_id => l_source_version_id,
2044 x_fin_plan_pref_code => l_s_fin_plan_pref_code,
2045 x_multi_curr_flag => l_s_multi_curr_flag,
2046 x_fin_plan_level_code => l_s_fin_plan_level_code,
2047 x_resource_list_id => l_s_resource_list_id,
2048 x_time_phased_code => l_s_time_phased_code,
2049 x_uncategorized_flag => l_s_uncategorized_flag,
2050 x_group_res_type_id => l_s_group_res_type_id,
2051 x_version_type => l_s_version_type,
2052 x_ci_id => l_s_ci_id,
2053 x_return_status => x_return_status,
2054 x_msg_count => x_msg_count,
2055 x_msg_data => x_msg_data
2056 ) ;
2057
2058 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2059 RETURN;
2060 END IF;
2061
2062 -- Bug 3677924 Jul 06 2004 Raja
2063 -- Check if target change order has corresponding impact record
2064 -- Note: If the target change order type does not allow the corresponding
2065 -- impact,the impact record would not have been created. The fact that there
2066 -- are two source versions version type would be either cost or rev only.
2067 BEGIN
2068 SELECT 'Y'
2069 INTO l_impact_record_exists
2070 FROM DUAL
2071 WHERE EXISTS
2072 (SELECT 1
2073 FROM pa_ci_impacts
2074 WHERE ci_id = l_t_fp_ci_id
2075 AND (l_s_version_type IN ('REVENUE') AND impact_type_code = 'FINPLAN_REVENUE'
2076 OR l_s_version_type IN ('COST') AND impact_type_code = 'FINPLAN_COST'));
2077 EXCEPTION
2078 WHEN NO_DATA_FOUND THEN
2079 l_impact_record_exists := 'N';
2080 END;
2081
2082 -- Bug 3677924 If the impact record does not exist skip processing
2083 IF l_impact_record_exists = 'Y' THEN
2084
2085 /*** raja 14-Jul-2004 Bug 3677924 Check api need not be called for copy
2086 --Check how many plan types exist
2087 IF( l_target_plan_types_cnt = 2 ) THEN
2088 --Call the check API with source attributes
2089 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_COPY_POSSIBLE
2090 (
2091 p_source_plan_level_code => l_s_fin_plan_level_code,
2092 p_source_time_phased_code => l_s_time_phased_code,
2093 p_source_resource_list_id => l_s_resource_list_id,
2094 p_source_version_type => l_s_version_type,
2095 p_project_id => p_project_id,
2096 p_s_ci_id => l_s_fp_ci_id,
2097 p_multiple_plan_types_flag => 'Y',
2098 x_copy_possible_flag => l_copy_possible_flag,
2099 x_return_status => x_return_status,
2100 x_msg_count => x_msg_count,
2101 x_msg_data => x_msg_data
2102 ) ;
2103 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2104 RETURN;
2105 END IF;
2106 ELSIF( l_target_plan_types_cnt = 1 ) THEN
2107 --Call the check API with source attributes
2108 Pa_Fp_Control_Items_Utils.FP_CI_CHECK_COPY_POSSIBLE
2109 (
2110 p_source_plan_level_code => l_s_fin_plan_level_code,
2111 p_source_time_phased_code => l_s_time_phased_code,
2112 p_source_resource_list_id => l_s_resource_list_id,
2113 p_source_version_type => l_s_version_type,
2114 p_project_id => p_project_id,
2115 p_s_ci_id => l_s_fp_ci_id,
2116 p_multiple_plan_types_flag => 'N',
2117 x_copy_possible_flag => l_copy_possible_flag,
2118 x_return_status => x_return_status,
2119 x_msg_count => x_msg_count,
2120 x_msg_data => x_msg_data
2121 ) ;
2122 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2123 RETURN;
2124 END IF;
2125 END IF;
2126
2127 IF l_copy_possible_flag = 'N' THEN
2128 raise RAISE_COPY_ERROR;
2129 END IF;
2130
2131 ------dbms_output.put_line('Came in target plan type count 2 &&&&&');
2132 ------dbms_output.put_line('l_s_fin_plan_level_code : ' || l_s_fin_plan_level_code);
2133 ------dbms_output.put_line('l_s_time_phased_code : ' || l_s_time_phased_code);
2134 ------dbms_output.put_line('l_s_resource_list_id : ' || l_s_resource_list_id);
2135 ------dbms_output.put_line('l_s_version_type : ' || l_s_version_type);
2136 ------dbms_output.put_line('l_s_fp_ci_id : ' || l_s_fp_ci_id);
2137 ------dbms_output.put_line('l_source_version_id : ' || l_source_version_id);
2138 ------dbms_output.put_line('l_copy_possible_flag : ' || l_copy_possible_flag);
2139 ***/
2140 -- Call Copy version API
2141 PA_FIN_PLAN_PUB.Copy_Version
2142 (p_project_id => p_project_id,
2143 p_source_version_id => l_source_version_id,
2144 p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING,
2145 p_calling_module => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN,
2146 px_target_version_id => l_target_version_id,
2147 x_return_status => x_return_status,
2148 x_msg_count => x_msg_count,
2149 x_msg_data => x_msg_data);
2150
2151 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2152 ROLLBACK TO before_fp_ci_copy;
2153 RETURN;
2154 END IF;
2155 l_update_agreement_flag := 'Y';
2156 --Stamp the Control item ids for these budget versions
2157 UPDATE pa_budget_versions bv
2158 SET CI_ID = l_t_fp_ci_id
2159 WHERE
2160 p_project_id = bv.project_id
2161 AND bv.budget_version_id = l_target_version_id
2162 AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
2163 OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
2164
2165 --Call the update estimated amounts API to update the estimated amounts
2166 FP_CI_UPDATE_EST_AMOUNTS
2167 (
2168 p_project_id => p_project_id,
2169 p_source_version_id => l_source_version_id,
2170 p_target_version_id => l_target_version_id,
2171 p_merge_unmerge_mode => p_merge_unmerge_mode ,
2172 p_commit_flag => 'N' ,
2173 p_init_msg_list => 'N',
2174 p_update_agreement => l_update_agreement_flag,
2175 x_return_status => x_return_status,
2176 x_msg_count => x_msg_count,
2177 x_msg_data => x_msg_data
2178 );
2179 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2180 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
2181 ROLLBACK TO before_fp_ci_copy;
2182 RETURN;
2183 END IF;
2184
2185 END IF; -- copy only if impact record exists
2186
2187 EXCEPTION
2188 WHEN RAISE_COPY_ERROR THEN
2189 x_warning_flag := 'Y';
2190 x_return_status := FND_API.G_RET_STS_ERROR;
2191 END;
2192 ELSE
2193 --Merge the source into the target
2194 l_source_id_tbl.DELETE;
2195 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 3');
2196 l_source_id_tbl(1) := l_source_version_id;
2197 l_target_version_id := l_target_version_id_tmp;
2198
2199 --Prepare the pl/sql tables for change document
2200 l_ci_id_tbl.extend(1);
2201 l_ci_id_tbl(1):=l_s_fp_ci_id;
2202 IF l_source_ver_type='COST' THEN
2203 l_ci_cost_version_id_tbl.extend(1);
2204 l_ci_cost_version_id_tbl(1):=l_source_fp_version_id_tbl(i);--Cost Version
2205 ELSE
2206 l_ci_rev_version_id_tbl.extend(1);
2207 l_ci_rev_version_id_tbl(1):=l_source_fp_version_id_tbl(i);--Revenue Version
2208 END IF;
2209
2210
2211 --Prepare pl/sql tbls for target version
2212 l_target_version_id_tbl.extend(1);
2213 l_impl_cost_flag_tbl.extend(1);
2214 l_impl_rev_flag_tbl.extend(1);
2215
2216 --l_target_version_id_tbl(1):=l_target_fp_version_id_tbl(1); --Bug 4132915.
2217 l_target_version_id_tbl(1) := l_target_version_id;
2218
2219 l_impl_cost_flag_tbl(1):='Y';
2220 l_impl_rev_flag_tbl(1):='Y';
2221
2222 implement_change_document
2223 ( p_context => 'CI_MERGE'
2224 ,p_ci_id_tbl => l_ci_id_tbl
2225 ,p_ci_cost_version_id_tbl => l_ci_cost_version_id_tbl
2226 ,p_ci_rev_version_id_tbl => l_ci_rev_version_id_tbl
2227 ,p_ci_all_version_id_tbl => l_ci_all_version_id_tbl
2228 ,p_budget_version_id_tbl => l_target_version_id_tbl
2229 ,p_impl_cost_flag_tbl => l_impl_cost_flag_tbl
2230 ,p_impl_rev_flag_tbl => l_impl_rev_flag_tbl
2231 ,x_translated_msgs_tbl => l_translated_msgs_tbl
2232 ,x_translated_err_msg_count => l_translated_err_msg_count
2233 ,x_translated_err_msg_level_tbl => l_translated_err_msg_level_tbl
2234 ,x_return_status => x_return_status
2235 ,x_msg_count => x_msg_count
2236 ,x_msg_data => x_msg_data);
2237 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2238 ROLLBACK TO before_fp_ci_copy;
2239 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
2240 RETURN;
2241 END IF;
2242
2243 l_update_agreement_flag := 'N';
2244
2245 --Bug 4132915. Passing the correct source and target version id.
2246 FP_CI_UPDATE_EST_AMOUNTS
2247 (
2248 p_project_id => p_project_id,
2249 p_source_version_id => l_source_id_tbl(1),
2250 p_target_version_id => l_target_version_id_tbl(1),
2251 p_merge_unmerge_mode => p_merge_unmerge_mode ,
2252 p_commit_flag => 'N' ,
2253 p_init_msg_list => 'N',
2254 p_update_agreement => l_update_agreement_flag,
2255 x_return_status => x_return_status,
2256 x_msg_count => x_msg_count,
2257 x_msg_data => x_msg_data
2258 );
2259 /*FP_CI_UPDATE_EST_AMOUNTS
2260 (
2261 p_project_id => p_project_id,
2262 p_source_version_id => l_s_version_id,
2263 p_target_version_id => l_t_version_id,
2264 p_merge_unmerge_mode => p_merge_unmerge_mode ,
2265 p_commit_flag => 'N' ,
2266 p_init_msg_list => 'N',
2267 p_update_agreement => l_update_agreement_flag,
2268 x_return_status => x_return_status,
2269 x_msg_count => x_msg_count,
2270 x_msg_data => x_msg_data
2271 );*/
2272
2273 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2274 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
2275 ROLLBACK TO before_fp_ci_copy;
2276 RETURN;
2277 END IF;
2278
2279
2280 /*Pa_Fp_Control_Items_Utils.FP_CI_CHECK_MERGE_POSSIBLE
2281 (
2282 p_project_id => p_project_id,
2283 p_source_fp_version_id_tbl => l_source_id_tbl,
2284 p_target_fp_version_id => l_target_version_id,
2285 p_calling_mode => 'INCLUDE_CR_TO_CO',
2286 x_s_fp_version_id_tbl => l_s_fp_version_id_tbl,
2287 x_t_fp_version_id_tbl => l_t_fp_version_id_tbl,
2288 x_s_fin_plan_level_tbl => l_s_fin_plan_level_code_tbl,
2289 x_t_fin_plan_level_tbl => l_t_fin_plan_level_code_tbl,
2290 x_s_multi_curr_flag_tbl => l_s_multi_curr_flag_tbl,
2291 x_t_multi_curr_flag_tbl => l_t_multi_curr_flag_tbl,
2292 x_s_fin_plan_pref_code_tbl => l_s_fin_plan_pref_code_tbl,
2293 x_t_fin_plan_pref_code_tbl => l_t_fin_plan_pref_code_tbl,
2294 x_s_uncategorized_flag_tbl => l_s_uncategorized_flag_tbl,
2295 x_t_uncategorized_flag_tbl => l_t_uncategorized_flag_tbl,
2296 x_s_version_type_tbl => l_s_version_type_tbl,
2297 x_t_version_type_tbl => l_t_version_type_tbl,
2298 x_s_time_phased_code_tbl => l_s_time_phased_code_tbl,
2299 x_t_time_phased_code_tbl => l_t_time_phased_code_tbl,
2300 x_merge_possible_code_tbl => l_merge_possible_code_tbl,
2301 x_return_status => x_return_status,
2302 x_msg_count => x_msg_count,
2303 x_msg_data => x_msg_data
2304 );
2305 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 6');
2306 -- LOOP THRU THE PL/SQL MERGE RESULT TABLE
2307 -- Need to do it TWICE
2308
2309 -- First: check for merge possible code for each line in
2310 -- the PL/SQL table. If even one is error code then
2311 -- return to calling program
2312
2313 FOR i in l_s_fp_version_id_tbl.FIRST.. l_s_fp_version_id_tbl.LAST
2314 LOOP
2315 --Assigning merge possible code from the PL/SQL table
2316 l_merge_possible_code := l_merge_possible_code_tbl (i);
2317 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 7');
2318 IF (l_merge_possible_code = 'E') THEN
2319 x_warning_flag := 'Y';
2320 x_return_status := FND_API.G_RET_STS_ERROR;
2321 END IF;
2322 END LOOP;
2323
2324 -- Second: IF merge is possible for the source and
2325 -- target version ids then go ahead with the merge
2326 -- one by one
2327
2328 FOR i in l_s_fp_version_id_tbl.FIRST.. l_s_fp_version_id_tbl.LAST
2329 LOOP
2330 l_merge_possible_code := l_merge_possible_code_tbl (i);
2331 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 7');
2332 IF (l_merge_possible_code <> 'E') THEN
2333 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 8');
2334 --Assigning values from the PL/SQL table FOR SOURCE VERSION
2335 l_s_version_id := l_s_fp_version_id_tbl(i);
2336 l_s_fin_plan_pref_code := l_s_fin_plan_pref_code_tbl(i) ;
2337 l_s_multi_curr_flag := l_s_multi_curr_flag_tbl(i) ;
2338 l_s_fin_plan_level_code := l_s_fin_plan_level_code_tbl(i);
2339 l_s_uncategorized_flag := l_s_uncategorized_flag_tbl(i);
2340 l_s_version_type := l_s_version_type_tbl(i);
2341 l_s_time_phased_code := l_s_time_phased_code_tbl(i);
2342 l_t_version_id := l_t_fp_version_id_tbl(i);
2343 l_t_fin_plan_pref_code := l_t_fin_plan_pref_code_tbl(i) ;
2344 l_t_multi_curr_flag := l_t_multi_curr_flag_tbl(i) ;
2345 l_t_fin_plan_level_code := l_t_fin_plan_level_code_tbl(i);
2346 l_t_uncategorized_flag := l_t_uncategorized_flag_tbl(i);
2347 l_t_version_type := l_t_version_type_tbl(i);
2348 l_t_time_phased_code := l_t_time_phased_code_tbl(i);
2349 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 9');
2350 -- Call the Manage Fp_Ci_Merge API for one source and
2351 -- one target version id at a time
2352
2353
2354 ------dbms_output.put_line('IN FP_CI_MERGE_CI_ITEMS');
2355 ------dbms_output.put_line('l_s_version_id :' || l_s_version_id);
2356 ------dbms_output.put_line('l_t_version_id :' || l_t_version_id);
2357 ------dbms_output.put_line('l_s_fin_plan_pref_code :' || l_s_fin_plan_pref_code);
2358 ------dbms_output.put_line('l_t_fin_plan_pref_code :' || l_t_fin_plan_pref_code);
2359 ------dbms_output.put_line('l_s_multi_curr_flag :' || l_s_multi_curr_flag);
2360 ------dbms_output.put_line('l_t_multi_curr_flag :' || l_t_multi_curr_flag);
2361 ------dbms_output.put_line('l_s_fin_plan_level_code :' || l_s_fin_plan_level_code);
2362 ------dbms_output.put_line('l_t_fin_plan_level_code :' || l_t_fin_plan_level_code);
2363 ------dbms_output.put_line('l_s_uncategorized_flag :' || l_s_uncategorized_flag);
2364 ------dbms_output.put_line('l_t_uncategorized_flag :' || l_t_uncategorized_flag);
2365 ------dbms_output.put_line('l_s_version_type :' || l_s_version_type);
2366 ------dbms_output.put_line('l_t_version_type :' || l_t_version_type);
2367
2368 FP_CI_MANAGE_MERGE
2369 (
2370 p_project_id => p_project_id,
2371 p_s_version_id => l_s_version_id,
2372 p_s_fin_plan_pref_code => l_s_fin_plan_pref_code,
2373 p_s_multi_curr_flag => l_s_multi_curr_flag,
2374 p_s_fin_plan_level_code => l_s_fin_plan_level_code,
2375 p_s_uncategorized_flag => l_s_uncategorized_flag,
2376 p_s_version_type => l_s_version_type,
2377 p_s_time_phased_code => l_s_time_phased_code,
2378 p_t_version_id => l_t_version_id,
2379 p_t_fin_plan_pref_code => l_t_fin_plan_pref_code,
2380 p_t_multi_curr_flag => l_t_multi_curr_flag,
2381 p_t_fin_plan_level_code => l_t_fin_plan_level_code,
2382 p_t_uncategorized_flag => l_t_uncategorized_flag,
2383 p_t_version_type => l_t_version_type,
2384 p_t_time_phased_code => l_t_time_phased_code,
2385 p_merge_unmerge_mode => p_merge_unmerge_mode,
2386 x_return_status => x_return_status,
2387 x_msg_count => x_msg_count,
2388 x_msg_data => x_msg_data
2389 );
2390 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 10');
2391 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2392 ROLLBACK TO before_fp_ci_copy;
2393 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 11*****');
2394 RETURN;
2395 END IF;
2396
2397 -- After successful merge one would need
2398 -- to update the control item and financial
2399 -- planning merge record table
2400
2401 --Check if record already exists for the merge
2402 SELECT COUNT(*)
2403 INTO l_count_merged_versions
2404 FROM pa_fp_merged_ctrl_items
2405 WHERE
2406 ci_plan_version_id = l_s_version_id
2407 AND plan_version_id = l_t_version_id
2408 AND project_id = p_project_id;
2409
2410 IF (l_count_merged_versions = 0) THEN
2411 -- record doesn't exist - so insert it
2412 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 12');
2413 FP_CI_LINK_CONTROL_ITEMS
2414 (
2415 p_project_id => p_project_id,
2416 p_s_fp_version_id => l_s_version_id,
2417 p_t_fp_version_id => l_t_version_id,
2418 p_inclusion_method => 'AUTOMATIC',
2419 p_included_by => NULL,
2420 x_return_status => x_return_status,
2421 x_msg_count => x_msg_count,
2422 x_msg_data => x_msg_data
2423 );
2424 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 120');
2425 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2426 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 12****');
2427 ROLLBACK TO before_fp_ci_copy;
2428 RETURN;
2429 END IF;
2430 END IF;
2431
2432 -- Call the convert currency API
2433 --------dbms_output.put_line('FP_CI_COPY_CONTROL_ITEMS - 13');
2434 PA_FP_MULTI_CURRENCY_PKG.convert_txn_currency
2435 (
2436 p_budget_version_id => l_t_version_id
2437 ,p_entire_version => 'Y'
2438 ,x_return_status => x_return_status
2439 ,x_msg_count => x_msg_count
2440 ,x_msg_data => x_msg_data
2441 );
2442 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 130');
2443 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2444 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 13****');
2445 ROLLBACK TO before_fp_ci_copy;
2446 RETURN;
2447 END IF;
2448
2449 -- Call the Roll up budget version API API
2450 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 15');
2451 PA_FP_ROLLUP_PKG.rollup_budget_version
2452 (
2453 p_budget_version_id => l_t_version_id
2454 ,p_entire_version => 'Y'
2455 ,x_return_status => x_return_status
2456 ,x_msg_count => x_msg_count
2457 ,x_msg_data => x_msg_data
2458 );
2459 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150');
2460 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2461 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 15****');
2462 ROLLBACK TO before_fp_ci_copy;
2463 RETURN;
2464 END IF;
2465 l_update_agreement_flag := 'N';
2466 --Call the update estimated amounts API to update the estimated amounts
2467 FP_CI_UPDATE_EST_AMOUNTS
2468 (
2469 p_project_id => p_project_id,
2470 p_source_version_id => l_s_version_id,
2471 p_target_version_id => l_t_version_id,
2472 p_merge_unmerge_mode => p_merge_unmerge_mode ,
2473 p_commit_flag => 'N' ,
2474 p_init_msg_list => 'N',
2475 p_update_agreement => l_update_agreement_flag,
2476 x_return_status => x_return_status,
2477 x_msg_count => x_msg_count,
2478 x_msg_data => x_msg_data
2479 );
2480 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2481 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 150****');
2482 ROLLBACK TO before_fp_ci_copy;
2483 RETURN;
2484 END IF;
2485 END IF;
2486 END LOOP;*/
2487 END IF;
2488 END LOOP;
2489 END IF;
2490 END IF;
2491 END IF;
2492 IF NVL(p_commit_flag,'N') = 'Y' THEN
2493 COMMIT;
2494 END IF;
2495 EXCEPTION
2496 WHEN OTHERS THEN
2497 ROLLBACK TO before_fp_ci_copy;
2498 FND_MSG_PUB.add_exc_msg
2499 ( p_pkg_name => 'PA_FP_CI_MERGE.' ||
2500 'fp_ci_merge_ci_items'
2501 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
2502 IF p_pa_debug_mode = 'Y' THEN
2503 PA_DEBUG.g_err_stage := 'Unexpected error in FP_CI_MERGE_CI_ITEMS';
2504 PA_DEBUG.Log_Message(p_message => PA_DEBUG.g_err_stage);
2505 END IF;
2506 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2507 --------dbms_output.put_line('FP_CI_MERGE_CI_ITEMS - 14');
2508 IF p_pa_debug_mode = 'Y' THEN
2509 PA_DEBUG.Reset_Curr_Function;
2510 END IF;
2511 RAISE;
2512 END FP_CI_MERGE_CI_ITEMS;
2513 -- end of fp_ci_merge_ci_items
2514
2515
2516
2517 /*==================================================================
2518 This api copies the merged ctrl items from source budget version
2519 to target budget version.
2520
2521 --###
2522
2523 r11.5 FP.M Developement ----------------------------------
2524
2525 08-JAN-2004 jwhite Bug 3362316
2526
2527 Extensively rewrote copy_merged_ctrl_items
2528 - INSERT INTO pa_fp_merged_ctrl_items (
2529
2530 ==================================================================*/
2531
2532 --Bug 4247703. Added the parameter p_calling_context. The valid values are NULL or GENERATION
2533 PROCEDURE copy_merged_ctrl_items
2534 ( p_project_id IN pa_budget_versions.project_id%TYPE
2535 ,p_source_version_id IN pa_budget_versions.budget_version_id%TYPE
2536 ,p_target_version_id IN pa_budget_versions.budget_version_id%TYPE
2537 ,p_calling_context IN VARCHAR2
2538 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
2539 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
2540 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
2541 AS
2542
2543 l_msg_count NUMBER := 0;
2544 l_data VARCHAR2(2000);
2545 l_msg_data VARCHAR2(2000);
2546 l_msg_index_out NUMBER;
2547 l_return_status VARCHAR2(2000);
2548 l_debug_mode VARCHAR2(30);
2549
2550 BEGIN
2551
2552 x_msg_count := 0;
2553 x_return_status := FND_API.G_RET_STS_SUCCESS;
2554 IF p_pa_debug_mode = 'Y' THEN
2555 pa_debug.set_err_stack('PA_FP_CI_MERGE.copy_merged_ctrl_items');
2556 END IF;
2557 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
2558 l_debug_mode := NVL(l_debug_mode, 'Y');
2559 IF p_pa_debug_mode = 'Y' THEN
2560 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
2561 -- Check for business rules violations
2562
2563 pa_debug.g_err_stage:= 'Validating input parameters';
2564 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
2565 END IF;
2566 --Check if plan version id is null
2567
2568 IF (p_project_id IS NULL) OR
2569 (p_source_version_id IS NULL) OR
2570 (p_target_version_id IS NULL)
2571 THEN
2572 IF p_pa_debug_mode = 'Y' THEN
2573 pa_debug.g_err_stage:= 'p_project_id = '|| p_project_id;
2574 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2575 pa_debug.g_err_stage:= 'p_source_version_id = '|| p_source_version_id;
2576 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2577 pa_debug.g_err_stage:= 'p_target_version_id = '|| p_target_version_id;
2578 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2579 END IF;
2580 PA_UTILS.ADD_MESSAGE
2581 (p_app_short_name => 'PA',
2582 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
2583 IF p_pa_debug_mode = 'Y' THEN
2584 pa_debug.g_err_stage:= 'Invalid Arguments Passed';
2585 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2586 END IF;
2587 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2588
2589 END IF;
2590
2591 IF NVL(p_calling_context,'GENERATION')<>'GENERATION' THEN
2592
2593 IF p_pa_debug_mode = 'Y' THEN
2594 pa_debug.g_err_stage:= 'p_calling_context = '|| p_calling_context;
2595 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2596 END IF;
2597 PA_UTILS.ADD_MESSAGE
2598 (p_app_short_name => 'PA',
2599 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
2600 p_token1 => 'PROCEDURENAME',
2601 p_value1 => 'PAFPCIMB.copy_merged_ctrl_items',
2602 p_token2 => 'STAGE',
2603 p_value2 => 'Invalid p_calling_context '||p_calling_context);
2604
2605 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2606
2607 END IF;
2608
2609 --Bug 4247703. When called in generation flow, the CI links in the source should be inserted into the
2610 --target only if they are not already there in the target. In other flows(copy version) the ci links in the
2611 --target will be deleted before this API is called and hence the check is not required.
2612
2613 IF p_calling_context ='GENERATION' THEN
2614
2615 MERGE INTO pa_fp_merged_ctrl_items target
2616 USING
2617 (SELECT
2618 p_project_id project_id
2619 ,p_target_version_id plan_version_id
2620 ,pmc.ci_id ci_id
2621 ,pmc.ci_plan_version_id ci_plan_version_id
2622 ,1 record_version_number
2623 ,sysdate creation_date
2624 ,fnd_global.user_id created_by
2625 ,fnd_global.login_id last_update_login
2626 ,fnd_global.user_id last_updated_by
2627 ,sysdate last_update_date
2628 ,'COPIED' inclusion_method_code
2629 ,pmc.included_by_person_id included_by_person_id
2630 ,pmc.version_type version_type
2631 ,pmc.impl_proj_func_raw_cost impl_proj_func_raw_cost
2632 ,pmc.impl_proj_func_burdened_cost impl_proj_func_burdened_cost
2633 ,pmc.impl_proj_func_revenue impl_proj_func_revenue
2634 ,pmc.impl_proj_raw_cost impl_proj_raw_cost
2635 ,pmc.impl_proj_burdened_cost impl_proj_burdened_cost
2636 ,pmc.impl_proj_revenue impl_proj_revenue
2637 ,pmc.impl_quantity impl_quantity
2638 ,pmc.impl_equipment_quantity impl_equipment_quantity
2639 ,pmc.impl_agr_revenue impl_agr_revenue
2640 FROM pa_fp_merged_ctrl_items pmc,
2641 pa_budget_versions sourcever,
2642 pa_budget_versions targetver -- Bug 3720445
2643 WHERE plan_version_id = p_source_version_id
2644 AND sourcever.budget_version_id=p_source_version_id
2645 AND targetver.budget_version_id=p_target_version_id -- Bug 3720445
2646 AND pmc.version_type = Decode (targetver.version_type, 'ALL', pmc.version_type,
2647 targetver.version_type)
2648 AND (sourcever.fin_plan_type_id=targetver.fin_plan_type_id OR
2649 EXISTS (SELECT 1
2650 FROM pa_pt_co_impl_statuses ptco,
2651 pa_control_items pci
2652 WHERE ptco.fin_plan_type_id=targetver.fin_plan_type_id
2653 AND pci.ci_id=pmc.ci_id
2654 AND ptco.ci_type_id=pci.ci_type_id
2655 AND ptco.version_type=pmc.version_type
2656 AND ptco.status_code=pci.status_code))) source
2657 ON (target.project_id=source.project_id AND
2658 target.plan_version_id=source.plan_version_id AND
2659 target.ci_id=source.ci_id AND
2660 target.ci_plan_version_id=source.ci_plan_version_id AND
2661 target.version_type=source.version_type)
2662 WHEN MATCHED THEN
2663 UPDATE SET target.last_update_date = sysdate
2664 WHEN NOT MATCHED THEN
2665 INSERT(
2666 target.project_id
2667 ,target.plan_version_id
2668 ,target.ci_id
2669 ,target.ci_plan_version_id
2670 ,target.record_version_number
2671 ,target.creation_date
2672 ,target.created_by
2673 ,target.last_update_login
2674 ,target.last_updated_by
2675 ,target.last_update_date
2676 ,target.inclusion_method_code
2677 ,target.included_by_person_id
2678 ,target.version_type
2679 ,target.impl_proj_func_raw_cost
2680 ,target.impl_proj_func_burdened_cost
2681 ,target.impl_proj_func_revenue
2682 ,target.impl_proj_raw_cost
2683 ,target.impl_proj_burdened_cost
2684 ,target.impl_proj_revenue
2685 ,target.impl_quantity
2686 ,target.impl_equipment_quantity
2687 ,target.impl_agr_revenue
2688 )
2689 VALUES(
2690 source.project_id
2691 ,source.plan_version_id
2692 ,source.ci_id
2693 ,source.ci_plan_version_id
2694 ,source.record_version_number
2695 ,source.creation_date
2696 ,source.created_by
2697 ,source.last_update_login
2698 ,source.last_updated_by
2699 ,source.last_update_date
2700 ,source.inclusion_method_code
2701 ,source.included_by_person_id
2702 ,source.version_type
2703 ,source.impl_proj_func_raw_cost
2704 ,source.impl_proj_func_burdened_cost
2705 ,source.impl_proj_func_revenue
2706 ,source.impl_proj_raw_cost
2707 ,source.impl_proj_burdened_cost
2708 ,source.impl_proj_revenue
2709 ,source.impl_quantity
2710 ,source.impl_equipment_quantity
2711 ,source.impl_agr_revenue);
2712
2713 ELSE--Calling Context is not GENERATION
2714
2715 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
2716 -- The control items which are partially implemented should not be copied. Bug 3550073
2717 -- Bug 3720445, 29-JUL-2004: copy based on ci version type and target version type values
2718 -- Bug 3784823, 29-JUL-2004: It is incorrect not to copy links if ci is partially implemented.
2719 -- Bug 3882920: Links will be copied only if the target version's plan type allows inclusion of CIs. This
2720 -- Bug 4493425: Added another condition in the where clause of select to improve performance.
2721 --check is made only if source/target plan types are different. See bug for details.
2722 INSERT INTO pa_fp_merged_ctrl_items (
2723 project_id
2724 ,plan_version_id
2725 ,ci_id
2726 ,ci_plan_version_id
2727 ,record_version_number
2728 ,creation_date
2729 ,created_by
2730 ,last_update_login
2731 ,last_updated_by
2732 ,last_update_date
2733 ,inclusion_method_code
2734 ,included_by_person_id
2735 ,version_type
2736 ,impl_proj_func_raw_cost
2737 ,impl_proj_func_burdened_cost
2738 ,impl_proj_func_revenue
2739 ,impl_proj_raw_cost
2740 ,impl_proj_burdened_cost
2741 ,impl_proj_revenue
2742 ,impl_quantity
2743 ,impl_equipment_quantity
2744 ,impl_agr_revenue
2745 )
2746 SELECT
2747 p_project_id
2748 ,p_target_version_id
2749 ,pmc.ci_id
2750 ,pmc.ci_plan_version_id
2751 ,1
2752 ,sysdate
2753 ,fnd_global.user_id
2754 ,fnd_global.login_id
2755 ,fnd_global.user_id
2756 ,sysdate
2757 ,'COPIED'
2758 ,pmc.included_by_person_id
2759 ,pmc.version_type
2760 ,pmc.impl_proj_func_raw_cost
2761 ,pmc.impl_proj_func_burdened_cost
2762 ,pmc.impl_proj_func_revenue
2763 ,pmc.impl_proj_raw_cost
2764 ,pmc.impl_proj_burdened_cost
2765 ,pmc.impl_proj_revenue
2766 ,pmc.impl_quantity
2767 ,pmc.impl_equipment_quantity
2768 ,pmc.impl_agr_revenue
2769 FROM pa_fp_merged_ctrl_items pmc,
2770 pa_budget_versions sourcever,
2771 pa_budget_versions targetver -- Bug 3720445
2772 WHERE plan_version_id = p_source_version_id
2773 AND sourcever.budget_version_id=p_source_version_id
2774 AND targetver.budget_version_id=p_target_version_id -- Bug 3720445
2775 AND pmc.project_id = p_project_id -- Bug 4493425
2776 AND pmc.version_type = Decode (targetver.version_type, 'ALL', pmc.version_type,
2777 targetver.version_type)
2778 AND (sourcever.fin_plan_type_id=targetver.fin_plan_type_id OR
2779 EXISTS (SELECT 1
2780 FROM pa_pt_co_impl_statuses ptco,
2781 pa_control_items pci
2782 WHERE ptco.fin_plan_type_id=targetver.fin_plan_type_id
2783 AND pci.ci_id=pmc.ci_id
2784 AND ptco.ci_type_id=pci.ci_type_id
2785 AND ptco.version_type=pmc.version_type
2786 AND ptco.status_code=pci.status_code)); -- Bug 3720445
2787 -- Bug 3784823 AND nvl(civer.rev_partially_impl_flag,'N') <> 'Y';
2788
2789 -- End: Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
2790
2791 END IF;--IF p_calling_context ='GENERATION' THEN
2792
2793 IF p_pa_debug_mode = 'Y' THEN
2794 pa_debug.g_err_stage:= 'Exiting copy_merged_ctrl_items';
2795 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
2796 pa_debug.reset_err_stack;
2797 END IF;
2798
2799 EXCEPTION
2800
2801 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
2802
2803 x_return_status := FND_API.G_RET_STS_ERROR;
2804 l_msg_count := FND_MSG_PUB.count_msg;
2805 IF l_msg_count = 1 THEN
2806 PA_INTERFACE_UTILS_PUB.get_messages
2807 (p_encoded => FND_API.G_TRUE
2808 ,p_msg_index => 1
2809 ,p_msg_count => l_msg_count
2810 ,p_msg_data => l_msg_data
2811 ,p_data => l_data
2812 ,p_msg_index_out => l_msg_index_out);
2813 x_msg_data := l_data;
2814 x_msg_count := l_msg_count;
2815 ELSE
2816 x_msg_count := l_msg_count;
2817 END IF;
2818 IF p_pa_debug_mode = 'Y' THEN
2819 pa_debug.reset_err_stack;
2820 END IF;
2821 RAISE;
2822
2823 WHEN others THEN
2824
2825 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2826 x_msg_count := 1;
2827 x_msg_data := SQLERRM;
2828 FND_MSG_PUB.add_exc_msg
2829 ( p_pkg_name => 'PA_FP_CI_MERGE'
2830 ,p_procedure_name => 'copy_merged_ctrl_items'
2831 ,p_error_text => sqlerrm);
2832 IF p_pa_debug_mode = 'Y' THEN
2833 pa_debug.g_err_stage:= 'Unexpected Error'||SQLERRM;
2834 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2835 pa_debug.reset_err_stack;
2836 END IF;
2837 RAISE;
2838
2839 END copy_merged_ctrl_items;
2840
2841 /*==================================================================
2842 This api is a wrapper API which is called when the user clicks on
2843 Mark As Included button on the page. Included for bug 2681589.
2844 ==================================================================*/
2845 --Changed the API to accept the additional parameters. It now accepts ci version ids for ci id and the version type
2846 --of the target.Based on the version type of target either 1 or 2 records will be created in
2847 --pa_fp_merged_ctrl_items.
2848
2849 -- bug 3978200 29-0ct-04 Donot throw an error if target version is 'ALL' version and
2850 -- change order has no cost/revenue impact. Create a record in pa_fp_merged_ctrl_items
2851 -- only if there is corresponding impact
2852
2853 PROCEDURE FP_CI_MANUAL_MERGE
2854 (
2855 p_project_id IN NUMBER,
2856 p_ci_id IN pa_ci_impacts.ci_id%TYPE,
2857 p_ci_cost_version_id IN pa_budget_versions.budget_version_id%TYPE,
2858 p_ci_rev_version_id IN pa_budget_versions.budget_version_id%TYPE,
2859 p_ci_all_version_id IN pa_budget_versions.budget_version_id%TYPE,
2860 p_t_fp_version_id IN pa_budget_versions.budget_version_id%TYPE,
2861 p_targ_version_type IN pa_budget_versions.version_type%TYPE,
2862 x_return_status OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
2863 x_msg_count OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
2864 x_msg_data OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
2865 )
2866 AS
2867
2868 l_msg_count NUMBER := 0;
2869 l_data VARCHAR2(2000);
2870 l_msg_data VARCHAR2(2000);
2871 l_msg_index_out NUMBER;
2872
2873 l_update_impact_allowed varchar2(1);
2874
2875 l_debug_mode varchar2(1);
2876 l_s_ci_id pa_control_items.ci_id%TYPE;
2877 l_impl_version_type pa_fp_merged_ctrl_items.version_type%TYPE;
2878
2879 --This cursor is introduced for bug 3550073. In manual merge a link will be created which
2880 --indicates that the amounts are copied from the source to the target version. The user has to
2881 CURSOR c_impl_dtls_csr (c_ci_version_id pa_budget_versions.budget_version_id%TYPE)
2882 IS
2883 SELECT pbvs.burdened_cost pfc_burd_cost,
2884 pbvs.revenue pfc_revenue,
2885 pbvs.raw_cost pfc_raw_cost,
2886 pbvs.total_project_raw_cost pc_raw_cost,
2887 pbvs.total_project_burdened_cost pc_burd_cost,
2888 pbvs.total_project_revenue pc_revenue,
2889 DECODE(pbvs.version_type,'REVENUE',NULL,pbvs.labor_quantity) cost_ppl_qty,
2890 DECODE(pbvs.version_type,'REVENUE',NULL,pbvs.equipment_quantity) cost_equip_qty,
2891 DECODE(pbvs.version_type,'REVENUE',pbvs.labor_quantity,NULL) rev_ppl_qty,
2892 DECODE(pbvs.version_type,'REVENUE',pbvs.equipment_quantity,NULL) rev_equip_qty
2893 FROM pa_budget_versions pbvs
2894 WHERE pbvs.budget_version_id=c_ci_version_id;
2895
2896 l_impl_dtls_rec c_impl_dtls_csr%ROWTYPE;
2897
2898 l_upd_cost_impact_allowed VARCHAR2(1);
2899 l_upd_rev_impact_allowed VARCHAR2(1);
2900 --Bug 4136386
2901 l_impact_type_implemented pa_fp_merged_ctrl_items.version_type%TYPE;
2902 l_impl_version_type_tbl SYSTEM.pa_varchar2_30_tbl_type := SYSTEM.pa_varchar2_30_tbl_type();
2903
2904 BEGIN
2905
2906 x_msg_count := 0;
2907 x_return_status := FND_API.G_RET_STS_SUCCESS;
2908 l_debug_mode := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
2909 IF l_debug_mode = 'Y' THEN
2910 pa_debug.set_err_stack('PA_FP_CI_MERGE.FP_CI_MANUAL_MERGE');
2911 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
2912 END IF;
2913
2914 -- Check for business rules violations
2915
2916 IF l_debug_mode = 'Y' THEN
2917 pa_debug.g_err_stage:= 'Validating input parameters';
2918 pa_debug.write(l_module_name,pa_debug.g_err_stage,
2919 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
2920 END IF;
2921
2922 IF (p_project_id IS NULL) OR
2923 (p_ci_id is NULL) OR
2924 (p_t_fp_version_id is NULL) OR
2925 (p_targ_version_type is NULL) THEN
2926
2927 IF l_debug_mode = 'Y' THEN
2928 pa_debug.g_err_stage:= 'p_project_id = '|| p_project_id;
2929 pa_debug.write(l_module_name,pa_debug.g_err_stage,
2930 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2931 pa_debug.g_err_stage:= 'p_ci_id = '|| p_ci_id;
2932 pa_debug.write(l_module_name,pa_debug.g_err_stage,
2933 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2934 pa_debug.g_err_stage:= 'p_t_fp_version_id = '|| p_t_fp_version_id;
2935 pa_debug.write(l_module_name,pa_debug.g_err_stage,
2936 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2937 pa_debug.g_err_stage:= 'p_targ_version_type = '|| p_targ_version_type;
2938 pa_debug.write(l_module_name,pa_debug.g_err_stage,
2939 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2940 END IF;
2941 PA_UTILS.ADD_MESSAGE
2942 (p_app_short_name => 'PA',
2943 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
2944 p_token1 => 'PROCEDURENAME',
2945 p_value1 => 'PAFPCIMB.FP_CI_MANUAL_MERGE');
2946 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2947
2948 END IF;
2949
2950 --Bug 4136386.If either cost or revenue part of the change order impact has already got implemented then the
2951 --impact that got implemented should not be manually merged. This block will find that impact and
2952 --initialize the variable l_impact_type_implemented accordingly
2953 SELECT version_type
2954 BULK COLLECT INTO l_impl_version_type_tbl
2955 FROM pa_fp_merged_ctrl_items
2956 WHERE project_id=p_project_id
2957 AND plan_version_id=p_t_fp_version_id
2958 AND ci_id=p_ci_id
2959 AND ci_plan_version_id IN ( NVL(p_ci_cost_version_id,-99),NVL(p_ci_rev_version_id,-99),NVL(p_ci_all_version_id,-99))
2960 AND version_type IN ('COST','REVENUE');
2961
2962 IF l_impl_version_type_tbl.COUNT=0 THEN
2963
2964 l_impact_type_implemented:='NONE';
2965
2966 ELSIF l_impl_version_type_tbl.COUNT=1 THEN
2967
2968 l_impact_type_implemented := l_impl_version_type_tbl(1);
2969
2970 ELSE
2971
2972 --This is the case where the impact is fully implemented. In this case the api should not have been called
2973 --at all. Hence throw error.
2974 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
2975 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
2976 p_token1 => 'PROCEDURENAME',
2977 p_value1 => 'PAFPCIMB.FP_CI_MANUAL_MERGE',
2978 p_token2 => 'STAGE',
2979 p_value2 => 'Manual merge called for a ci which is fully impl.['||p_ci_id||', '||p_t_fp_version_id||']');
2980
2981 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2982
2983 END IF;
2984
2985 IF p_targ_version_type IN ('ALL','COST')
2986 AND nvl(p_ci_cost_version_id,p_ci_all_version_id) IS NOT NULL -- bug 3978200
2987 AND l_impact_type_implemented <> 'COST' --Bug 4136386
2988 THEN
2989 /* commented for bug 3978200
2990 IF nvl(p_ci_cost_version_id,p_ci_all_version_id) IS NULL THEN
2991 IF l_debug_mode = 'Y' THEN
2992 pa_debug.g_err_stage:= 'p_ci_cost_version_id = '|| p_ci_cost_version_id;
2993 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2994
2995 pa_debug.g_err_stage:= 'p_ci_all_version_id = '|| p_ci_all_version_id;
2996 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
2997
2998 END IF;
2999 PA_UTILS.ADD_MESSAGE
3000 (p_app_short_name => 'PA',
3001 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
3002 p_token1 => 'PROCEDURENAME',
3003 p_value1 => 'PAFPCIMB.FP_CI_MANUAL_MERGE');
3004 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3005 END IF;
3006 */
3007
3008 /* Call FP_CI_LINK_CONTROL_ITEMS*/
3009 IF l_debug_mode = 'Y' THEN
3010 pa_debug.g_err_stage:= 'B F p_ci_cost_version_id = '|| p_ci_cost_version_id;
3011 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3012
3013 pa_debug.g_err_stage:= 'B F p_ci_all_version_id = '|| p_ci_all_version_id;
3014 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3015 END IF;
3016
3017 OPEN c_impl_dtls_csr(NVL(p_ci_cost_version_id,p_ci_all_version_id));
3018 FETCH c_impl_dtls_csr INTO l_impl_dtls_rec ;
3019 CLOSE c_impl_dtls_csr;
3020
3021 IF l_debug_mode = 'Y' THEN
3022 pa_debug.g_err_stage:= 'COST - AFTER FETCH of cursor c_impl_dtls_csr';
3023 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3024 END IF;
3025
3026 --Though all the amounts are passed while calling the FP_CI_LINK_CONTROL_ITEMS, the called API
3027 --will take care of nulling out the amounts depending on the version type. Nulling out of cost amts
3028 --for rev vesion types is not done here as it will be easier to put the logic in FP_CI_LINK_CONTROL_ITEMS
3029 FP_CI_LINK_CONTROL_ITEMS
3030 (
3031 p_project_id => p_project_id
3032 ,p_s_fp_version_id => NVL(p_ci_cost_version_id,p_ci_all_version_id)
3033 ,p_t_fp_version_id => p_t_fp_version_id
3034 ,p_inclusion_method => 'MANUAL'
3035 ,p_included_by => NULL
3036 ,p_version_type => 'COST'
3037 ,p_ci_id => p_ci_id
3038 ,p_cost_ppl_qty => l_impl_dtls_rec.cost_ppl_qty
3039 ,p_rev_ppl_qty => NULL
3040 ,p_cost_equip_qty => l_impl_dtls_rec.cost_equip_qty
3041 ,p_rev_equip_qty => NULL
3042 ,p_impl_pfc_raw_cost => l_impl_dtls_rec.pfc_raw_cost
3043 ,p_impl_pfc_revenue => NULL
3044 ,p_impl_pfc_burd_cost => l_impl_dtls_rec.pfc_burd_cost
3045 ,p_impl_pc_raw_cost => l_impl_dtls_rec.pc_raw_cost
3046 ,p_impl_pc_revenue => NULL
3047 ,p_impl_pc_burd_cost => l_impl_dtls_rec.pc_burd_cost
3048 ,p_impl_agr_revenue => NULL
3049 ,x_return_status => x_return_status
3050 ,x_msg_count => x_msg_count
3051 ,x_msg_data => x_msg_data
3052 );
3053
3054 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
3055 IF l_debug_mode = 'Y' THEN
3056 pa_debug.g_err_stage:= 'Error calling FP_CI_LINK_CONTROL_ITEMS';
3057 pa_debug.write('FP_CI_MANUAL_MERGE: ' || l_module_name,pa_debug.g_err_stage,
3058 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3059 END IF;
3060 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3061 END IF;
3062
3063 END IF;
3064
3065 IF p_targ_version_type IN ('ALL','REVENUE')
3066 AND nvl(p_ci_rev_version_id,p_ci_all_version_id) IS NOT NULL -- bug 3978200
3067 AND l_impact_type_implemented <> 'REVENUE' --Bug 4136386
3068 THEN
3069 /* commented for bug 3978200
3070 IF nvl(p_ci_rev_version_id,p_ci_all_version_id) IS NULL THEN
3071 IF l_debug_mode = 'Y' THEN
3072 pa_debug.g_err_stage:= 'p_ci_rev_version_id = '|| p_ci_rev_version_id;
3073 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3074
3075 pa_debug.g_err_stage:= 'p_ci_all_version_id = '|| p_ci_all_version_id;
3076 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3077
3078 END IF;
3079 PA_UTILS.ADD_MESSAGE
3080 (p_app_short_name => 'PA',
3081 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
3082 p_token1 => 'PROCEDURENAME',
3083 p_value1 => 'PAFPCIMB.FP_CI_MANUAL_MERGE');
3084 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3085 END IF;
3086 */
3087
3088 IF l_debug_mode = 'Y' THEN
3089 pa_debug.g_err_stage:= 'B F p_ci_rev_version_id = '|| p_ci_rev_version_id;
3090 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3091
3092 pa_debug.g_err_stage:= 'B F p_ci_all_version_id = '|| p_ci_all_version_id;
3093 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3094 END IF;
3095
3096 /* Call FP_CI_LINK_CONTROL_ITEMS*/
3097 OPEN c_impl_dtls_csr(NVL(p_ci_rev_version_id,p_ci_all_version_id));
3098 FETCH c_impl_dtls_csr INTO l_impl_dtls_rec ;
3099 CLOSE c_impl_dtls_csr;
3100
3101 IF l_debug_mode = 'Y' THEN
3102 pa_debug.g_err_stage:= 'REV - AFTER FETCH of cursor c_impl_dtls_csr';
3103 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3104 END IF;
3105
3106 --Though all the amounts are passed while calling the FP_CI_LINK_CONTROL_ITEMS, the called API
3107 --will take care of nulling out the amounts depending on the version type. Nulling out of cost amts
3108 --for rev vesion types is not done here as it will be easier to put the logic in FP_CI_LINK_CONTROL_ITEMS
3109 FP_CI_LINK_CONTROL_ITEMS
3110 (
3111 p_project_id => p_project_id
3112 ,p_s_fp_version_id => NVL(p_ci_rev_version_id,p_ci_all_version_id)
3113 ,p_t_fp_version_id => p_t_fp_version_id
3114 ,p_inclusion_method => 'MANUAL'
3115 ,p_included_by => NULL
3116 ,p_version_type => 'REVENUE'
3117 ,p_ci_id => p_ci_id
3118 ,p_cost_ppl_qty => NULL
3119 ,p_rev_ppl_qty => l_impl_dtls_rec.rev_ppl_qty
3120 ,p_cost_equip_qty => NULL
3121 ,p_rev_equip_qty => l_impl_dtls_rec.rev_equip_qty
3122 ,p_impl_pfc_raw_cost => NULL
3123 ,p_impl_pfc_revenue => l_impl_dtls_rec.pfc_revenue
3124 ,p_impl_pfc_burd_cost => NULL
3125 ,p_impl_pc_raw_cost => NULL
3126 ,p_impl_pc_revenue => l_impl_dtls_rec.pc_revenue
3127 ,p_impl_pc_burd_cost => NULL
3128 ,p_impl_agr_revenue => NULL
3129 ,x_return_status => x_return_status
3130 ,x_msg_count => x_msg_count
3131 ,x_msg_data => x_msg_data
3132 );
3133
3134 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
3135 IF l_debug_mode = 'Y' THEN
3136 pa_debug.g_err_stage:= 'Error calling FP_CI_LINK_CONTROL_ITEMS';
3137 pa_debug.write('FP_CI_MANUAL_MERGE: ' || l_module_name,pa_debug.g_err_stage,
3138 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3139 END IF;
3140 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3141 END IF;
3142 END IF;
3143
3144 /*
3145 call Pa_Fp_Control_Items_Utils.FP_CI_VALIDATE_UPDATE_IMPACT to determine whether we can
3146 update impact as implemented or not
3147 */
3148
3149 Pa_Fp_Control_Items_Utils.FP_CI_VALIDATE_UPDATE_IMPACT
3150 (
3151 p_project_id => p_project_id
3152 ,p_ci_id => p_ci_id
3153 ,p_source_version_id => NULL
3154 ,p_target_version_id => p_t_fp_version_id
3155 ,x_upd_cost_impact_allowed => l_upd_cost_impact_allowed
3156 ,x_upd_rev_impact_allowed => l_upd_rev_impact_allowed
3157 ,x_msg_data => x_msg_data
3158 ,x_msg_count => x_msg_count
3159 ,x_return_status => x_return_status
3160 );
3161
3162 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
3163 IF l_debug_mode = 'Y' THEN
3164 pa_debug.g_err_stage:= 'Error calling Pa_Fp_Control_Items_Utils.FP_CI_VALIDATE_UPDATE_IMPACT';
3165 pa_debug.write('FP_CI_MANUAL_MERGE: ' || l_module_name,pa_debug.g_err_stage,
3166 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3167 END IF;
3168 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3169 END IF;
3170
3171 IF l_debug_mode = 'Y' THEN
3172 pa_debug.g_err_stage:= 'l_update_impact_allowed' || l_update_impact_allowed;
3173 pa_debug.write('FP_CI_MANUAL_MERGE: ' || l_module_name,pa_debug.g_err_stage,
3174 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
3175 END IF;
3176
3177 /*
3178 call FP_CI_UPDATE_IMPACT if flag is Y.
3179 pass only ci id and the status code as we need to only them
3180 in this case.
3181 */
3182 IF l_upd_cost_impact_allowed = 'Y' THEN
3183
3184 IF p_targ_version_type IN ('ALL','COST') THEN
3185
3186 FP_CI_UPDATE_IMPACT
3187 (
3188 p_ci_id => p_ci_id
3189 ,p_status_code => 'CI_IMPACT_IMPLEMENTED'
3190 ,p_impact_type_code => 'FINPLAN_COST'
3191 ,p_commit_flag => 'Y'
3192 ,x_return_status => x_return_status
3193 ,x_msg_count => x_msg_count
3194 ,x_msg_data => x_msg_data
3195 );
3196
3197 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
3198 IF l_debug_mode = 'Y' THEN
3199 pa_debug.g_err_stage:= 'Error calling FP_CI_UPDATE_IMPACT';
3200 pa_debug.write('FP_CI_MANUAL_MERGE: ' || l_module_name,pa_debug.g_err_stage,
3201 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3202 END IF;
3203 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3204 END IF;
3205 END IF;
3206
3207 END IF;
3208
3209 IF l_upd_rev_impact_allowed = 'Y' THEN
3210
3211 IF p_targ_version_type IN ('ALL','COST') THEN
3212
3213 FP_CI_UPDATE_IMPACT
3214 (
3215 p_ci_id => p_ci_id
3216 ,p_status_code => 'CI_IMPACT_IMPLEMENTED'
3217 ,p_impact_type_code => 'FINPLAN_REVENUE'
3218 ,p_commit_flag => 'Y'
3219 ,x_return_status => x_return_status
3220 ,x_msg_count => x_msg_count
3221 ,x_msg_data => x_msg_data
3222 );
3223
3224 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
3225 IF l_debug_mode = 'Y' THEN
3226 pa_debug.g_err_stage:= 'Error calling FP_CI_UPDATE_IMPACT';
3227 pa_debug.write('FP_CI_MANUAL_MERGE: ' || l_module_name,pa_debug.g_err_stage,
3228 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3229 END IF;
3230 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3231 END IF;
3232 END IF;
3233 END IF; -- update_impact_allowed = 'Y'
3234
3235 IF l_debug_mode = 'Y' THEN
3236 pa_debug.g_err_stage:= 'Exiting FP_CI_MANUAL_MERGE';
3237 pa_debug.write(l_module_name,pa_debug.g_err_stage,
3238 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
3239 pa_debug.reset_err_stack;
3240
3241 END IF;
3242
3243 EXCEPTION
3244
3245 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
3246
3247 x_return_status := FND_API.G_RET_STS_ERROR;
3248 l_msg_count := FND_MSG_PUB.count_msg;
3249
3250 IF l_msg_count = 1 and x_msg_data IS NULL THEN
3251 PA_INTERFACE_UTILS_PUB.get_messages
3252 (p_encoded => FND_API.G_TRUE
3253 ,p_msg_index => 1
3254 ,p_msg_count => l_msg_count
3255 ,p_msg_data => l_msg_data
3256 ,p_data => l_data
3257 ,p_msg_index_out => l_msg_index_out);
3258 x_msg_data := l_data;
3259 x_msg_count := l_msg_count;
3260 ELSE
3261 x_msg_count := l_msg_count;
3262 END IF;
3263 IF l_debug_mode = 'Y' THEN
3264 pa_debug.reset_err_stack;
3265 END IF;
3266 -- RAISE; /* bug 3978200 Directly called from middle tier donot raise */
3267
3268 WHEN others THEN
3269
3270 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3271 x_msg_count := 1;
3272 x_msg_data := SQLERRM;
3273
3274 FND_MSG_PUB.add_exc_msg
3275 ( p_pkg_name => 'PA_FP_CI_MERGE'
3276 ,p_procedure_name => 'FP_CI_MANUAL_MERGE'
3277 ,p_error_text => x_msg_data);
3278
3279 IF l_debug_mode = 'Y' THEN
3280 pa_debug.g_err_stage:= 'Unexpected Error'||x_msg_data;
3281 pa_debug.write(l_module_name,pa_debug.g_err_stage,
3282 PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
3283 pa_debug.reset_err_stack;
3284
3285 END IF;
3286 RAISE;
3287
3288 END FP_CI_MANUAL_MERGE;
3289
3290
3291 -- Start of functions to be used only in implement_ci_into_single_ver API
3292
3293 FUNCTION get_task_id(p_planning_level IN pa_proj_fp_options.cost_fin_plan_level_code%TYPE,
3294 p_task_id IN pa_resource_assignments.task_id%TYPE)
3295 RETURN NUMBER IS
3296 l_temp NUMBER;
3297 BEGIN
3298 IF P_PA_DEBUG_MODE='Y' THEN
3299 pa_debug.write('PAFPCIMB.get_task_id','p_task_id IS '||p_task_id,3);
3300 pa_debug.write('PAFPCIMB.get_task_id','p_planning_level IS '||p_task_id,3);
3301 END IF;
3302 if p_task_id=0 THEN
3303 return 0;
3304 END IF;
3305
3306 FOR kk IN 1..l_src_targ_task_tbl.COUNT LOOP
3307
3308 IF l_src_targ_task_tbl(kk).key=p_task_id THEN
3309
3310 RETURN l_src_targ_task_tbl(kk).value;
3311
3312 END IF;
3313
3314 END LOOP;
3315
3316 l_temp := l_src_targ_task_tbl.COUNT +1;
3317 l_src_targ_task_tbl(l_temp).key:=p_task_id;
3318 select decode(p_planning_level, 'P',0,'T',pt.top_task_id, pt.task_id)
3319 into l_src_targ_task_tbl(l_temp).value
3320 from pa_tasks pt
3321 where pt.task_id = p_task_id;
3322
3323 IF P_PA_DEBUG_MODE='Y' THEN
3324 pa_debug.write('PAFPCIMB.get_task_id','l_src_targ_task_tbl(l_temp).value is '||l_src_targ_task_tbl(l_temp).value,3);
3325 END IF;
3326 return l_src_targ_task_tbl(l_temp).value;
3327 END;
3328
3329 FUNCTION get_mapped_ra_id(p_task_id IN pa_resource_assignments.task_id%TYPE,
3330 p_rlm_id IN pa_resource_assignments.resource_list_member_id%TYPE,
3331 p_resource_assignment_id IN pa_resource_assignments.resource_assignment_id%TYPE,
3332 p_fin_plan_level_code IN pa_proj_fp_options.cost_fin_plan_level_code%TYPE
3333 )
3334 RETURN NUMBER IS
3335 l_index NUMBER;
3336 l_task_id pa_tasks.task_id%TYPE;
3337 l_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
3338 BEGIN
3339 IF p_resource_assignment_id IS NULL AND p_fin_plan_level_code IS NULL THEN
3340
3341 l_task_id:=p_task_id;
3342 l_rlm_id:=p_rlm_id;
3343
3344 ELSE
3345 SELECT get_task_id(p_fin_plan_level_code,task_id),
3346 resource_list_member_id
3347 INTO l_task_id,
3348 l_rlm_id
3349 FROM pa_resource_assignments
3350 WHERE resource_assignment_id=p_resource_assignment_id;
3351 END IF;
3352
3353 l_index := 1;
3354 LOOP
3355 EXIT WHEN (l_index > l_res_assmt_map_rec_tbl.COUNT) OR
3356 ( l_res_assmt_map_rec_tbl(l_index).task_id=l_task_id AND
3357 l_res_assmt_map_rec_tbl(l_index).resource_list_member_id=l_rlm_id) ;
3358
3359 l_index:=l_index+1;
3360
3361 END LOOP;
3362 IF (l_index<=l_res_assmt_map_rec_tbl.COUNT) THEN
3363
3364 RETURN l_res_assmt_map_rec_tbl(l_index).resource_assignment_id;
3365
3366 ELSE
3367
3368 RETURN NULL;
3369
3370 END IF;
3371 END;
3372
3373 FUNCTION get_mapped_dml_code(p_task_id IN pa_resource_assignments.task_id%TYPE,
3374 p_rlm_id IN pa_resource_assignments.resource_list_member_id%TYPE,
3375 p_resource_assignment_id IN pa_resource_assignments.resource_assignment_id%TYPE,
3376 p_fin_plan_level_code IN pa_proj_fp_options.cost_fin_plan_level_code%TYPE
3377
3378 )
3379 RETURN VARCHAR2 IS
3380 l_index NUMBER;
3381 l_task_id pa_tasks.task_id%TYPE;
3382 l_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
3383
3384 BEGIN
3385 IF p_resource_assignment_id IS NULL AND p_fin_plan_level_code IS NULL THEN
3386
3387 l_task_id:=p_task_id;
3388 l_rlm_id:=p_rlm_id;
3389
3390 ELSE
3391 SELECT get_task_id(p_fin_plan_level_code,task_id),
3392 resource_list_member_id
3393 INTO l_task_id,
3394 l_rlm_id
3395 FROM pa_resource_assignments
3396 WHERE resource_assignment_id=p_resource_assignment_id;
3397 END IF;
3398
3399 l_index := 1;
3400 LOOP
3401 EXIT WHEN (l_index > l_res_assmt_map_rec_tbl.COUNT) OR
3402 ( l_res_assmt_map_rec_tbl(l_index).task_id=l_task_id AND
3403 l_res_assmt_map_rec_tbl(l_index).resource_list_member_id=l_rlm_id) ;
3404
3405 l_index:=l_index+1;
3406 END LOOP;
3407 IF (l_index<=l_res_assmt_map_rec_tbl.COUNT) THEN
3408
3409 RETURN l_res_assmt_map_rec_tbl(l_index).ra_dml_code;
3410
3411 ELSE
3412
3413 RETURN NULL;
3414
3415 END IF;
3416 END;
3417
3418 -- End of functions to be used only in implement_ci_into_single_ver API
3419
3420 -- Implements the impact of the change order into the target budget version id passed
3421
3422 -- Bug 3934574 Oct 14 2004 Added a new parameter p_calling_context that would be populated when
3423 -- called as part of budget/forecast generation
3424
3425 PROCEDURE implement_ci_into_single_ver(p_context IN VARCHAR2
3426 ,p_calling_context IN VARCHAR2 DEFAULT NULL -- bug 3934574
3427 ,P_ci_id IN Pa_control_items.ci_id%TYPE -- The Id of the chg doc that needs to be implemented
3428 ,P_ci_cost_version_id IN Pa_budget_versions.budget_version_id%TYPE DEFAULT NULL -- The cost budget version id corresponding to the p_ci_id passed. This will be derived internally if not passed
3429 ,P_ci_rev_version_id IN Pa_budget_versions.budget_version_id%TYPE DEFAULT NULL -- The rev budget version id corresponding to the p_ci_id passed. This will be derived internally if not passed
3430 ,P_ci_all_version_id IN Pa_budget_versions.budget_version_id%TYPE DEFAULT NULL -- The all budget_version_id corresponding to the p_ci_id passed. This will be derived internally if not passed
3431 ,P_budget_version_id IN Pa_budget_versions.budget_version_id%TYPE -- The Id of the budget version into which the CO needs to be implemented
3432 ,p_fin_plan_type_id IN pa_fin_plan_types_b.fin_plan_type_id%TYPE
3433 ,p_fin_plan_type_name IN pa_fin_plan_types_tl.name%TYPE
3434 ,P_partial_impl_rev_amt IN NUMBER DEFAULT NULL -- The revenue amount that should be implemented into the target. This will be passed only in the case of partial implementation
3435 ,p_cost_impl_flag IN VARCHAR2 -- Can be Y or N. Indicates whether cost can be implemented or not.
3436 ,p_rev_impl_flag IN VARCHAR2 -- Can be Y or N. Indicates whether rev can be implemented or not.
3437 ,P_submit_version_flag IN VARCHAR2 -- Can be Y or N. Indicates whether the version can be submitted for baseline after implementing CO or not.
3438 ,P_agreement_id IN Pa_agreements_all.agreement_id%TYPE DEFAULT NULL -- The id of the agreement that is linked with the CO.
3439 ,P_update_agreement_amt_flag IN VARCHAR2 DEFAULT NULL -- Indicates whether to update the agreement amt or not. Null is considered as N
3440 ,P_funding_category IN VARCHAR2 DEFAULT NULL -- The funding category for the agreement
3441 ,p_raTxn_rollup_api_call_flag IN VARCHAR2 -- Indicates whether the pa_resource_asgn_curr maintenance api should be called
3442 ,x_return_status OUT NOCOPY VARCHAR2 -- Indicates the exit status of the API --File.Sql.39 bug 4440895
3443 ,x_msg_data OUT NOCOPY VARCHAR2 -- Indicates the error occurred --File.Sql.39 bug 4440895
3444 ,X_msg_count OUT NOCOPY NUMBER) -- Indicates the number of error messages --File.Sql.39 bug 4440895
3445 IS
3446
3447 -- Start of variables used for debugging purpose
3448
3449 l_msg_count NUMBER :=0;
3450 l_data VARCHAR2(2000);
3451 l_msg_data VARCHAR2(2000);
3452 l_msg_index_out NUMBER;
3453 l_return_status VARCHAR2(2000);
3454 l_debug_mode VARCHAR2(1) :=P_PA_DEBUG_MODE;
3455 l_debug_level3 CONSTANT NUMBER := 3;
3456 l_debug_level5 CONSTANT NUMBER := 5;
3457 l_module_name VARCHAR2(100) := 'PAFPCIMB.implement_ci_into_single_ver' ;
3458 l_token_name VARCHAR2(30) :='PROCEDURENAME';
3459 l_msg_code VARCHAR2(2000);
3460
3461 -- End of variables used for debugging purpose
3462
3463 l_Projfunc_Currency_Code pa_projects_all.projfunc_currency_code%TYPE := NULL;
3464 l_Project_Currency_Code pa_projects_all.project_currency_code%TYPE := NULL;
3465 l_Txn_Currency_Code pa_projects_all.projfunc_currency_code%TYPE := NULL;
3466 l_baseline_funding_flag pa_projects_all.baseline_funding_flag%TYPE;
3467 l_cost_impl_flag VARCHAR2(1);
3468 l_rev_impl_flag VARCHAR2(1);
3469 l_cost_impact_impl_flag VARCHAR2(1);
3470 l_rev_impact_impl_flag VARCHAR2(1);
3471 l_partially_impl_flag VARCHAR2(1);
3472 l_agreement_num pa_agreements_all.agreement_num%TYPE;
3473 l_approved_fin_pt_id pa_fin_plan_types_b.fin_plan_type_id%TYPE;
3474 l_call_rep_lines_api VARCHAR2(1):='N';
3475 l_id_before_bl_insertion pa_budget_lines.budget_line_id%TYPE;
3476 l_id_after_bl_insertion pa_budget_lines.budget_line_id%TYPE;
3477 l_dummy NUMBER;
3478
3479
3480
3481
3482
3483 I NUMBER;
3484
3485 l_fp_version_ids_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
3486
3487 l_src_ver_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
3488 l_impl_type_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3489 l_impl_qty_tbl SYSTEM.PA_VARCHAR2_1_TBL_TYPE := SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3490
3491 l_impact_type_code pa_ci_impacts.impact_type_code%TYPE;
3492
3493 l_record_version_number pa_budget_versions.record_version_number%TYPE;
3494 l_partial_factor NUMBER := 1;
3495 l_impl_amt pa_fp_merged_ctrl_items.impl_proj_revenue%TYPE;
3496 l_total_amt pa_budget_versions.total_project_revenue%TYPE;
3497 l_total_amt_in_pfc pa_budget_lines.revenue%TYPE;
3498 l_total_amt_in_pc pa_budget_lines.project_revenue%TYPE;
3499
3500 l_src_proj_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
3501 l_src_multi_curr_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
3502 l_src_fin_plan_type_id pa_proj_fp_options.fin_plan_type_id%TYPE;
3503 l_src_time_phased_code pa_proj_fp_options.cost_time_phased_code%TYPE;
3504 l_src_report_lbr_hrs_frm_code pa_proj_fp_options.report_labor_hrs_from_code%TYPE;
3505
3506
3507 l_targ_proj_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
3508 l_targ_multi_curr_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
3509
3510 l_targ_time_phased_code pa_proj_fp_options.cost_time_phased_code%TYPE;
3511 L_REPORT_COST_USING pa_proj_fp_options.report_labor_hrs_from_code%TYPE;
3512 l_targ_app_rev_flag pa_proj_fp_options.report_labor_hrs_from_code%TYPE;
3513 l_copy_pfc_for_txn_amt_flag VARCHAR2(1);
3514
3515 l_project_id pa_proj_fp_options.project_id%TYPE;
3516
3517 l_txn_curr_code_tbl SYSTEM.pa_varchar2_15_tbl_type := SYSTEM.pa_varchar2_15_tbl_type();
3518 l_src_resource_list_id pa_proj_fp_options.cost_resource_list_id%TYPE;
3519 l_targ_resource_list_id pa_proj_fp_options.cost_resource_list_id%TYPE;
3520 l_rbs_version_id pa_proj_fp_options.rbs_version_id%TYPE;
3521 l_targ_plan_level_code pa_proj_fp_options.cost_fin_plan_level_code%TYPE;
3522 l_src_plan_level_code pa_proj_fp_options.cost_fin_plan_level_code%TYPE;
3523
3524 l_txn_source_id_tbl system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3525 l_res_list_member_id_tbl system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3526 l_rbs_element_id_prm_tbl system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3527 l_txn_accum_header_id_prm_tbl system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3528
3529 -- for Start bug 5291484
3530 l_txn_source_id_tbl_1 system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3531 ltxnaccumheader_id_prm_tbl_1 system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3532 l_res_list_member_id_tbl_1 system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3533 l_rbs_element_id_prm_tbl_1 system.PA_NUM_TBL_TYPE:= system.PA_NUM_TBL_TYPE();
3534 -- for End bug 5291484
3535
3536
3537 -- Start of tables used to bulk collect and insert into pa_resource_assignments
3538 L_TARG_RLM_ID_TBL SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3539 L_TARG_RA_ID_TBL SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3540 L_RA_DML_CODE_TBL SYSTEM.PA_VARCHAR2_15_TBL_TYPE:= SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
3541 L_targ_task_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3542 l_src_ra_id_cnt_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3543 l_planning_start_date_tbl SYSTEM.pa_date_tbl_type := SYSTEM.pa_date_tbl_type();
3544 l_planning_end_date_tbl SYSTEM.pa_date_tbl_type := SYSTEM.pa_date_tbl_type();
3545 l_targ_rbs_element_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3546 l_targ_spread_curve_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3547 l_targ_etc_method_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3548 l_targ_fc_res_type_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3549 l_targ_organization_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3550 l_targ_job_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3551 l_targ_person_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3552 l_targ_expenditure_type_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3553 l_targ_expend_category_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3554 l_targ_rev_category_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3555 l_targ_event_type_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3556 l_targ_supplier_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3557 l_targ_project_role_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3558 l_targ_resource_type_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3559 l_targ_person_type_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3560 l_targ_non_labor_resource_tbl SYSTEM.PA_VARCHAR2_20_TBL_TYPE:= SYSTEM.PA_VARCHAR2_20_TBL_TYPE();
3561 l_targ_bom_resource_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3562 l_targ_inventory_item_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3563 l_targ_item_category_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3564 l_targ_INCURED_BY_RES_FLAG_tbl SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3565 l_targ_RATE_BASED_FLAG_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3566 l_targ_RES_RATE_BASED_FLAG_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE(); --IPM Architecture Enhancement
3567 l_targ_RESOURCE_CLASS_FLAG_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3568 l_targ_NAMED_ROLE_tbl SYSTEM.PA_VARCHAR2_80_TBL_TYPE:= SYSTEM.PA_VARCHAR2_80_TBL_TYPE();
3569 l_targ_txn_accum_header_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3570 l_targ_unit_of_measure_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3571 l_targ_RESOURCE_CLASS_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3572 l_targ_assignment_description SYSTEM.PA_VARCHAR2_240_TBL_TYPE:= SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
3573 l_targ_mfc_cost_type_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3574 l_targ_RATE_JOB_ID_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3575 l_targ_RATE_EXPEND_TYPE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3576 l_targ_RATE_EXP_FC_CUR_COD_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3577 l_targ_RATE_EXPEND_ORG_ID_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3578 l_targ_INCR_BY_RES_CLS_COD_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3579 l_targ_INCUR_BY_ROLE_ID_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3580
3581 -- End of tables used to bulk collect and insert into pa_resource_assignments
3582
3583 --These pl/sql tbls will store the data corresponding to the details such as task_id, rate based flag
3584 --etc of RAs that have got updated. Bug 3678314.
3585 l_upd_ra_task_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3586 l_upd_ra_rbs_elem_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3587 l_upd_ra_res_class_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3588 l_upd_ra_rbf_tbl SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3589 l_upd_ra_res_asmt_id_tbl SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3590
3591
3592 l_index NUMBER;
3593 l_matching_index NUMBER;
3594 -- Start of local Variables for calling get_resource_defaults API
3595 l_da_resource_list_members_tab SYSTEM.PA_NUM_TBL_TYPE:=SYSTEM.PA_NUM_TBL_TYPE();
3596 l_da_resource_class_flag_tab SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3597 l_da_resource_class_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3598 l_da_resource_class_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3599 l_da_res_type_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3600 l_da_person_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3601 l_da_job_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3602 l_da_person_type_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3603 l_da_named_role_tab SYSTEM.PA_VARCHAR2_80_TBL_TYPE:= SYSTEM.PA_VARCHAR2_80_TBL_TYPE();
3604 l_da_bom_resource_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3605 l_da_non_labor_resource_tab SYSTEM.PA_VARCHAR2_20_TBL_TYPE:= SYSTEM.PA_VARCHAR2_20_TBL_TYPE();
3606 l_da_inventory_item_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3607 l_da_item_category_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3608 l_da_project_role_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3609 l_da_organization_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3610 l_da_fc_res_type_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3611 l_da_expenditure_type_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3612 l_da_expenditure_category_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3613 l_da_event_type_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3614 l_da_revenue_category_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3615 l_da_supplier_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3616 l_da_spread_curve_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3617 l_da_etc_method_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3618 l_da_mfc_cost_type_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3619 l_da_incurred_by_res_flag_tab SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3620 l_da_incur_by_res_cls_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3621 l_da_incur_by_role_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3622 l_da_unit_of_measure_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3623 l_da_org_id_tab SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3624 l_da_rate_based_flag_tab SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3625 l_da_rate_expenditure_type_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3626 l_da_rate_func_curr_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3627 l_da_incur_by_res_type_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3628
3629 --for Start bug 5291484
3630 lresource_list_members_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3631 lresource_class_flag_tab_1 SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3632 lresource_class_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3633 lresource_class_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3634 lres_type_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3635 lperson_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3636 ljob_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3637 lperson_type_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3638 lnamed_role_tab_1 SYSTEM.PA_VARCHAR2_80_TBL_TYPE:= SYSTEM.PA_VARCHAR2_80_TBL_TYPE();
3639 lbom_resource_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3640 lnon_labor_resource_tab_1 SYSTEM.PA_VARCHAR2_20_TBL_TYPE:= SYSTEM.PA_VARCHAR2_20_TBL_TYPE();
3641 linventory_item_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3642 litem_category_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3643 lproject_role_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3644 lorganization_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3645 lfc_res_type_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3646 lexpenditure_type_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3647 lexpenditure_category_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3648 l_da_event_type_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3649 lrevenue_category_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3650 l_da_supplier_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3651 l_da_spread_curve_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3652 l_da_etc_method_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3653 l_da_mfc_cost_type_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3654 lincurred_by_res_flag_tab_1 SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3655 lincur_by_res_cls_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3656 l_da_incur_by_role_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3657 l_da_unit_of_measure_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3658 l_da_org_id_tab_1 SYSTEM.PA_NUM_TBL_TYPE:= SYSTEM.PA_NUM_TBL_TYPE();
3659 l_da_rate_based_flag_tab_1 SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3660 lrate_expenditure_type_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3661 l_da_rate_func_curr_code_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3662 l_da_incur_by_res_type_tab_1 SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3663 ltxnsrctyp_code_rbs_prm_tbl_1 SYSTEM.pa_varchar2_30_tbl_type:= SYSTEM.pa_varchar2_30_tbl_type();
3664
3665 --for End bug 5291484
3666
3667
3668
3669 -- Endof local Variables for calling get_resource_defaults API
3670
3671 l_project_structure_version_id pa_proj_element_versions.parent_structure_version_id%TYPE;
3672
3673 -- Start of variable to be used in Calculate API Call
3674 l_line_start_date_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3675 l_line_end_date_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3676
3677 l_currency_code_tbl SYSTEM.PA_VARCHAR2_15_TBL_TYPE:= SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
3678 l_total_quantity_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3679 l_total_raw_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3680 l_total_burdened_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3681 l_total_revenue_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3682 l_cost_rate_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3683 l_burden_multiplier_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3684 l_bill_rate_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3685 l_txn_src_typ_code_rbs_prm_tbl SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3686 l_prm_bl_start_date_tbl SYSTEM.PA_DATE_TBL_TYPE :=SYSTEM.PA_DATE_TBL_TYPE();
3687 l_prm_bl_end_date_tbl SYSTEM.PA_DATE_TBL_TYPE :=SYSTEM.PA_DATE_TBL_TYPE();
3688 l_period_name_tbl SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3689 l_pc_raw_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3690 l_pc_burd_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3691 l_pc_revenue_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3692 l_pfc_raw_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3693 l_pfc_burd_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3694 l_pfc_revenue_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3695 l_cost_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3696 l_revenue_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3697 l_burden_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3698 l_other_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3699 l_pc_cur_conv_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3700 l_pfc_cur_conv_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3701 l_pji_prm_task_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3702 l_pji_prm_rbs_elem_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3703 l_pji_prm_res_cls_code_tbl SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3704 l_pji_prm_rbf_tbl SYSTEM.pa_varchar2_1_tbl_type :=SYSTEM.pa_varchar2_1_tbl_type();
3705 l_upd_bl_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3706 l_upd_period_name_tbl SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3707 l_upd_currency_code_tbl SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
3708 l_upd_bl_start_date_tbl SYSTEM.PA_DATE_TBL_TYPE :=SYSTEM.PA_DATE_TBL_TYPE();
3709 l_upd_bl_end_date_tbl SYSTEM.PA_DATE_TBL_TYPE :=SYSTEM.PA_DATE_TBL_TYPE();
3710 l_upd_cost_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3711 l_upd_revenue_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3712 l_upd_burden_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3713 l_upd_other_rejection_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3714 l_upd_pc_cur_conv_rej_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3715 l_upd_pfc_cur_conv_rej_code SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
3716
3717 l_res_assignment_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
3718 l_delete_budget_lines_tbl SYSTEM.pa_varchar2_1_tbl_type:=SYSTEM.pa_varchar2_1_tbl_type();
3719 L_SPREAD_AMOUNT_FLAGS_TBL SYSTEM.pa_varchar2_1_tbl_type:=SYSTEM.pa_varchar2_1_tbl_type();
3720
3721
3722 -- End of variable to be used in Calculate API Call
3723
3724
3725
3726 l_proj_raw_cost pa_resource_assignments.TOTAL_PROJECT_RAW_COST%TYPE;
3727 l_proj_burdened_cost pa_resource_assignments.TOTAL_PROJECT_BURDENED_COST%TYPE;
3728 l_proj_revenue pa_resource_assignments.TOTAL_PROJECT_REVENUE%TYPE;
3729
3730 l_projfunc_raw_cost pa_resource_assignments.TOTAL_PLAN_RAW_COST%TYPE;
3731 l_projfunc_burdened_cost pa_resource_assignments.TOTAL_PLAN_BURDENED_COST%TYPE;
3732 l_projfunc_revenue pa_resource_assignments.TOTAL_PLAN_REVENUE%TYPE;
3733 l_labor_quantity pa_resource_assignments.TOTAL_PLAN_QUANTITY%TYPE;
3734 l_equip_quantity pa_resource_assignments.TOTAL_PLAN_QUANTITY%TYPE;
3735
3736
3737
3738
3739 -- Start of tables prepared to insert/update into pa_budget_lines
3740 l_bl_RESOURCE_ASIGNMENT_ID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3741 l_upd_ra_bl_dml_code_tbl SYSTEM.PA_VARCHAR2_15_TBL_TYPE := SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
3742 l_bl_START_DATE_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3743 l_bl_END_DATE_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3744 l_bl_PERIOD_NAME_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3745 l_bl_QUANTITY_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3746 l_bl_RAW_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3747 l_bl_BURDENED_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3748 l_bl_REVENUE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3749 l_bl_CHANGE_REASON_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3750 l_bl_DESCRIPTION_tbl SYSTEM.PA_VARCHAR2_2000_TBL_TYPE:= SYSTEM.PA_VARCHAR2_2000_TBL_TYPE();
3751 l_bl_ATTRIBUTE_CATEGORY_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3752 l_bl_ATTRIBUTE1_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3753 l_bl_ATTRIBUTE2_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3754 l_bl_ATTRIBUTE3_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3755 l_bl_ATTRIBUTE4_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3756 l_bl_ATTRIBUTE5_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3757 l_bl_ATTRIBUTE6_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3758 l_bl_ATTRIBUTE7_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3759 l_bl_ATTRIBUTE8_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3760 l_bl_ATTRIBUTE9_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3761 l_bl_ATTRIBUTE10_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3762 l_bl_ATTRIBUTE11_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3763 l_bl_ATTRIBUTE12_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3764 l_bl_ATTRIBUTE13_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3765 l_bl_ATTRIBUTE14_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3766 l_bl_ATTRIBUTE15_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3767 l_bl_PM_PRODUCT_CODE_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3768 l_bl_PM_BUDGET_LINE_REF_tbl SYSTEM.PA_VARCHAR2_150_TBL_TYPE:= SYSTEM.PA_VARCHAR2_150_TBL_TYPE();
3769 l_bl_COST_REJECTION_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3770 l_bl_REVENUE_REJ_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3771 l_bl_BURDEN_REJECTION_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3772 l_bl_OTHER_REJECTION_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3773 l_bl_CODE_COMBINATION_ID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3774 l_bl_CCID_GEN_STATUS_CODE_tbl SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3775 l_bl_CCID_GEN_REJ_MESSAGE_tbl SYSTEM.PA_VARCHAR2_2000_TBL_TYPE:= SYSTEM.PA_VARCHAR2_2000_TBL_TYPE();
3776 l_bl_REQUEST_ID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3777 l_bl_BORROWED_REVENUE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3778 l_bl_TP_REVENUE_IN_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3779 l_bl_TP_REVENUE_OUT_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3780 l_bl_REVENUE_ADJ_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3781 l_bl_LENT_RESOURCE_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3782 l_bl_TP_COST_IN_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3783 l_bl_TP_COST_OUT_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3784 l_bl_COST_ADJ_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3785 l_bl_UNASSIGNED_TIME_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3786 l_bl_UTILIZATION_PERCENT_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3787 l_bl_UTILIZATION_HOURS_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3788 l_bl_UTILIZATION_ADJ_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3789 l_bl_CAPACITY_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3790 l_bl_HEAD_COUNT_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3791 l_bl_HEAD_COUNT_ADJ_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3792 l_bl_PROJFUNC_CUR_CODE_tbl SYSTEM.PA_VARCHAR2_15_TBL_TYPE:= SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
3793 l_bl_PROJFUNC_COST_RAT_TYP_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3794 l_bl_PJFN_COST_RAT_DAT_TYP_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3795 l_bl_PROJFUNC_COST_RAT_DAT_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3796 l_bl_PROJFUNC_REV_RATE_TYP_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3797 l_bl_PJFN_REV_RAT_DAT_TYPE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3798 l_bl_PROJFUNC_REV_RAT_DATE_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3799 l_bl_PROJECT_COST_RAT_TYPE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3800 l_bl_PROJ_COST_RAT_DAT_TYP_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3801 l_bl_PROJ_COST_RATE_DATE_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3802 l_bl_PROJECT_RAW_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3803 l_bl_PROJECT_BURDENED_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3804 l_bl_PROJECT_REV_RATE_TYPE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3805 l_bl_PRJ_REV_RAT_DATE_TYPE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3806 l_bl_PROJECT_REV_RATE_DATE SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
3807 l_bl_PROJECT_REVENUE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3808 l_bl_TXN_CURRENCY_CODE_tbl SYSTEM.PA_VARCHAR2_15_TBL_TYPE:= SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
3809 l_bl_TXN_RAW_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3810 l_bl_TXN_BURDENED_COST_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3811 l_bl_TXN_REVENUE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3812 l_bl_BUCKETING_PERIOD_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3813 l_bl_TXN_STD_COST_RATE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3814 l_bl_TXN_COST_RATE_OVERIDE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3815 l_bl_COST_IND_CMPLD_SET_ID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3816 l_bl_TXN_BURDEN_MULTIPLIER_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3817 l_bl_TXN_BRD_MLTIPLI_OVRID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3818 l_bl_TXN_STD_BILL_RATE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3819 l_bl_TXN_BILL_RATE_OVERRID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3820 l_bl_TXN_MARKUP_PERCENT_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3821 l_bl_TXN_MRKUP_PER_OVERIDE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3822 l_bl_TXN_DISC_PERCENTAGE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3823 l_bl_TRANSFER_PRICE_RATE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3824 l_bl_BURDEN_COST_RATE_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3825 l_bl_BURDEN_COST_RAT_OVRID_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
3826 l_bl_PC_CUR_CONV_REJ_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3827 l_bl_PFC_CUR_CONV_REJ_CODE_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE:= SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
3828 l_bl_rbf_flag_tbl SYSTEM.PA_VARCHAR2_1_TBL_TYPE:= SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
3829
3830 -- End of tables prepared to insert/update into pa_budget_lines
3831
3832 l_ci_cost_version_id pa_budget_versions.budget_version_id%TYPE;
3833 l_ci_rev_version_id pa_budget_versions.budget_version_id%TYPE;
3834 l_ci_all_version_id pa_budget_versions.budget_version_id%TYPE;
3835
3836 l_etc_start_date pa_budget_versions.etc_start_date%TYPE;
3837 L_TARG_APP_COST_FLAG pa_proj_fp_options.approved_cost_plan_type_flag%TYPE;
3838
3839 L_SAME_MULTI_CURR_FLAG VARCHAR2(1);
3840 l_amt_used_for_rate_calc NUMBER;
3841
3842 CURSOR c_proj_level_amounts IS
3843 SELECT nvl(total_project_raw_cost,0)
3844 ,nvl(total_project_burdened_cost,0)
3845 ,nvl(total_project_revenue,0)
3846 ,nvl(raw_cost,0)
3847 ,nvl(burdened_cost,0)
3848 ,nvl(revenue,0)
3849 ,nvl(labor_quantity,0)
3850 ,nvl(equipment_quantity,0)
3851 FROM pa_budget_versions
3852 WHERE budget_version_id = p_budget_version_id;
3853
3854
3855 -- Variables for calling FP_CI_LINK_CONTROL_ITEMS
3856 l_version_type pa_budget_versions.version_type%TYPE;
3857 l_cost_ppl_qty pa_fp_merged_ctrl_items.impl_quantity%TYPE;
3858 l_rev_ppl_qty pa_fp_merged_ctrl_items.impl_quantity%TYPE;
3859 l_cost_equip_qty pa_fp_merged_ctrl_items.impl_equipment_quantity%TYPE;
3860 l_rev_equip_qty pa_fp_merged_ctrl_items.impl_equipment_quantity%TYPE;
3861 l_impl_pfc_raw_cost pa_fp_merged_ctrl_items.impl_proj_func_raw_cost%TYPE;
3862 l_impl_pfc_revenue pa_fp_merged_ctrl_items.impl_proj_func_revenue%TYPE;
3863 l_impl_pfc_burd_cost pa_fp_merged_ctrl_items.impl_proj_func_burdened_cost%TYPE;
3864 l_impl_pc_raw_cost pa_fp_merged_ctrl_items.impl_proj_raw_cost%TYPE;
3865 l_impl_pc_revenue pa_fp_merged_ctrl_items.impl_proj_revenue%TYPE;
3866 l_impl_pc_burd_cost pa_fp_merged_ctrl_items.impl_proj_burdened_cost%TYPE;
3867 l_target_version_type pa_budget_versions.version_type%TYPE;
3868 l_baselined_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
3869 l_baselined_version_id pa_budget_versions.budget_version_id%TYPE;
3870 l_orig_record_version_number pa_budget_versions.record_version_number%TYPE;
3871 l_fc_version_created_flag VARCHAR2(1);
3872 l_targ_lab_qty_before_merge pa_budget_versions.labor_quantity%TYPE;
3873 l_targ_eqp_qty_before_merge pa_budget_versions.equipment_quantity%TYPE;
3874 l_targ_pfc_rawc_before_merge pa_budget_versions.raw_cost%TYPE;
3875 l_targ_pfc_burdc_before_merge pa_budget_versions.burdened_cost%TYPE;
3876 l_targ_pfc_rev_before_merge pa_budget_versions.revenue%TYPE;
3877 l_targ_pc_rawc_before_merge pa_budget_versions.total_project_raw_cost%TYPE;
3878 l_targ_pc_burdc_before_merge pa_budget_versions.total_project_burdened_cost%TYPE;
3879 l_targ_pc_rev_before_merge pa_budget_versions.total_project_revenue%TYPE;
3880 l_targ_lab_qty_after_merge pa_budget_versions.labor_quantity%TYPE;
3881 l_targ_eqp_qty_after_merge pa_budget_versions.equipment_quantity%TYPE;
3882 l_targ_pfc_rawc_after_merge pa_budget_versions.raw_cost%TYPE;
3883 l_targ_pfc_burdc_after_merge pa_budget_versions.burdened_cost%TYPE;
3884 l_targ_pfc_rev_after_merge pa_budget_versions.revenue%TYPE;
3885 l_targ_pc_rawc_after_merge pa_budget_versions.total_project_raw_cost%TYPE;
3886 l_targ_pc_burdc_after_merge pa_budget_versions.total_project_burdened_cost%TYPE;
3887 l_targ_pc_rev_after_merge pa_budget_versions.total_project_revenue%TYPE;
3888 l_impl_earlier VARCHAR2(1);
3889 l_total_agr_revenue pa_budget_lines.txn_revenue%TYPE;
3890
3891 l_partial_impl_rev_amt NUMBER;
3892 l_partial_rev_impl_flag VARCHAR2(1);
3893
3894 --Variable used for passing ci id to the change management baseline API.
3895 l_CI_ID_Tab PA_PLSQL_DATATYPES.IdTabTyp;
3896 l_temp NUMBER;
3897 X_Err_Code NUMBER;
3898 l_current_working_flag pa_budget_versions.current_working_flag%TYPE;
3899
3900 -- variables introduced for bug 3934574
3901 l_retain_manual_lines_flag VARCHAR2(1);
3902
3903 -- Start of variables declared for bug 4035856
3904 l_src_delta_amt_adj_task_id pa_tasks.task_id%TYPE;
3905 l_targ_delta_amt_adj_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
3906 l_src_delta_amt_adj_ra_id pa_resource_assignments.resource_assignment_id%TYPE;
3907 l_src_delta_amt_adj_start_date pa_budget_lines.start_date%TYPE;
3908 l_pc_revenue_delta pa_budget_lines.project_revenue%TYPE;
3909 l_pfc_revenue_delta pa_budget_lines.revenue%TYPE;
3910 l_pc_rev_merged pa_budget_lines.project_revenue%TYPE;
3911 l_pfc_rev_merged pa_budget_lines.revenue%TYPE;
3912 l_pc_rev_for_merge pa_budget_lines.project_revenue%TYPE;
3913 l_pfc_rev_for_merge pa_budget_lines.revenue%TYPE;
3914 l_src_dummy1 number;
3915 l_src_dummy2 pa_resource_list_members.alias%TYPE;
3916 l_impl_proj_func_revenue pa_fp_merged_ctrl_items.impl_proj_func_revenue%TYPE;-- bug 4035856
3917 l_impl_proj_revenue pa_fp_merged_ctrl_items.impl_proj_revenue%TYPE;-- bug 4035856
3918 l_impl_quantity pa_fp_merged_ctrl_items.impl_quantity%TYPE;-- bug 4035856
3919 l_agreement_id pa_agreements_all.agreement_id%TYPE;
3920 l_agreement_currency_code pa_agreements_all.agreement_currency_code%TYPE;
3921 l_rounded_bl_id pa_budget_lines.budget_line_id%TYPE;
3922 l_rounded_bl_rbf pa_resource_assignments.rate_based_flag%TYPE;
3923 l_qty_adjusted_flag VARCHAR2(1);
3924 --These variables will be used in calling create_ci_impact_fund_lines
3925 l_impl_pc_rev_amt NUMBER;
3926 l_impl_pfc_rev_amt NUMBER;
3927
3928 --This variable will be used to call pa_resource_asgn_curr maintenance api
3929 l_fp_cols_rec PA_FP_GEN_AMOUNT_UTILS.FP_COLS;
3930
3931 -- Cursor to identify resource assignment id against which the adjustment amount should be placed
3932 -- The idea is to choose the last ra in the edit plan page in the default view for ci version
3933 -- Added a condition to choose only the RA having the budget lines as the LAST RA.This cursor will be
3934 -- used in the case when both source and target have the same resource lists.(Please note that any changes
3935 -- in this cursor might have to be done in src_delta_amt_adj_ra_cur1 also)
3936 CURSOR src_delta_amt_adj_ra_cur
3937 (c_budget_version_id pa_budget_versions.budget_version_id%TYPE)IS
3938 SELECT pra.task_id, pra.resource_list_member_id, pra.resource_assignment_id,
3939 PA_PROJ_ELEMENTS_UTILS.GET_DISPLAY_SEQUENCE(pra.task_id) as dispSeq, rlm.alias
3940 FROM pa_resource_assignments pra, pa_resource_list_members rlm
3941 WHERE pra.budget_version_id = c_budget_version_id
3942 AND rlm.resource_list_member_id = pra.resource_list_member_id
3943 AND EXISTS (SELECT 1
3944 FROM pa_budget_lines pbl
3945 WHERE pbl.resource_assignment_id = pra.resource_assignment_id)
3946 ORDER BY dispSeq DESC , rlm.alias DESC;
3947
3948 --This cursor is same as src_delta_amt_adj_ra_cur. This will be used when the source and target
3949 --have different resource lists.(Please note that any changes in this cursor might have to be
3950 --done in src_delta_amt_adj_ra_cur also)
3951 CURSOR src_delta_amt_adj_ra_cur1
3952 (c_budget_version_id pa_budget_versions.budget_version_id%TYPE)IS
3953 SELECT pra.task_id, tmp4.resource_list_member_id, pra.resource_assignment_id,
3954 PA_PROJ_ELEMENTS_UTILS.GET_DISPLAY_SEQUENCE(pra.task_id) as dispSeq, rlm.alias
3955 FROM pa_resource_assignments pra, pa_resource_list_members rlm,pa_res_list_map_tmp4 tmp4
3956 WHERE pra.budget_version_id = c_budget_version_id
3957 AND pra.resource_assignment_id=tmp4.txn_source_id
3958 AND rlm.resource_list_member_id = tmp4.resource_list_member_id
3959 AND EXISTS (SELECT 1
3960 FROM pa_budget_lines pbl
3961 WHERE pbl.resource_assignment_id = pra.resource_assignment_id)
3962 ORDER BY dispSeq DESC , rlm.alias DESC;
3963
3964 -- Cursor to identify against which period/date the adjustment amount should be placed
3965 -- Note that revenue only change orders can have amounts against agreement currency only.
3966 CURSOR src_delta_amt_adj_date_cur
3967 (c_resource_assignment_id pa_resource_assignments.resource_assignment_id%TYPE)IS
3968 SELECT max(start_date)
3969 FROM pa_budget_lines
3970 WHERE resource_assignment_id = c_resource_assignment_id;
3971
3972
3973 -- End of variables declared for bug 4035856
3974
3975 --For Bug 3980129. These variables will hold the values that indicate whether cost/revenue implementation is OK or NOT
3976 --l_cost_impl_flag , l_rev_impl_flag will also have the values. But l_rev_impl_flag will be set to N when cost
3977 --is being impelemented and l_cost_impl_flag will be set to N when revenue is being implemented. If cost gets
3978 --implemented first then l_rev_impl_flag will be set to l_derv_rev_impl_flag when revenue gets implemented and
3979 --vice-versa.
3980 l_derv_cost_impl_flag VARCHAR2(1);
3981 l_derv_rev_impl_flag VARCHAR2(1);
3982
3983 BEGIN
3984 FND_MSG_PUB.initialize;
3985
3986 IF p_pa_debug_mode = 'Y' THEN
3987 pa_debug.set_curr_function( p_function => 'implement_ci_into_single_ver',
3988 p_debug_mode => P_PA_debug_mode );
3989 END IF;
3990 x_msg_count := 0;
3991 x_return_status := FND_API.G_RET_STS_SUCCESS;
3992
3993 SAVEPOINT implement_ci_into_single_ver;
3994
3995 --dbms_output.put_line('I1');
3996 IF P_PA_debug_mode = 'Y' THEN
3997 pa_debug.g_err_stage:= 'Entering implement_ci_into_single_ver';
3998 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3999 END IF;
4000
4001 --dbms_output.put_line('I2');
4002 -- Derive the version ids for the change order if none of them is passed
4003 IF p_ci_cost_version_id IS NULL AND p_ci_rev_version_id IS NULL AND p_ci_all_version_id IS NULL THEN
4004 IF P_PA_debug_mode = 'Y' THEN
4005 pa_debug.g_err_stage:= 'Calling GET_CI_VERSIONS p_ci_id :'||p_ci_id;
4006 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4007 END IF;
4008 Pa_Fp_Control_Items_Utils.GET_CI_VERSIONS
4009 ( p_ci_id => p_ci_id
4010 ,X_cost_budget_version_id => l_ci_cost_version_id
4011 ,X_rev_budget_version_id => l_ci_rev_version_id
4012 ,X_all_budget_version_id => l_ci_all_version_id
4013 ,x_return_status => l_return_status
4014 ,x_msg_count => l_msg_data
4015 ,x_msg_data => l_msg_count);
4016
4017 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4018 IF P_PA_debug_mode = 'Y' THEN
4019 pa_debug.g_err_stage:= 'Error in GET_CI_VERSIONS';
4020 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4021 END IF;
4022 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4023 END IF;
4024 ELSE
4025 l_ci_cost_version_id := p_ci_cost_version_id;
4026 l_ci_rev_version_id := p_ci_rev_version_id;
4027 l_ci_all_version_id := p_ci_all_version_id;
4028
4029 END IF;
4030
4031 --dbms_output.put_line('I3');
4032 BEGIN
4033 -- Select the details required from pa_budget_versions so that they can be used in the later part of the code
4034 SELECT etc_start_date
4035 ,project_id
4036 ,version_type
4037 ,PA_PROJECT_STRUCTURE_UTILS.GET_FIN_STRUC_VER_ID(project_id )
4038 ,nvl(labor_quantity,0)
4039 ,nvl(equipment_quantity,0)
4040 ,nvl(raw_cost,0)
4041 ,nvl(burdened_cost,0)
4042 ,nvl(revenue,0)
4043 ,nvl(total_project_raw_cost,0)
4044 ,nvl(total_project_burdened_cost,0)
4045 ,nvl(total_project_revenue,0)
4046 ,current_working_flag
4047 into l_etc_start_date
4048 ,l_project_id
4049 ,l_target_version_type
4050 ,l_project_structure_version_id
4051 ,l_targ_lab_qty_before_merge
4052 ,l_targ_eqp_qty_before_merge
4053 ,l_targ_pfc_rawc_before_merge
4054 ,l_targ_pfc_burdc_before_merge
4055 ,l_targ_pfc_rev_before_merge
4056 ,l_targ_pc_rawc_before_merge
4057 ,l_targ_pc_burdc_before_merge
4058 ,l_targ_pc_rev_before_merge
4059 ,l_current_working_flag
4060 from pa_budget_versions
4061 WHERE budget_version_id = p_budget_version_id;
4062
4063 IF P_PA_debug_mode = 'Y' THEN
4064 pa_debug.g_err_stage:= 'Fetching l_etc_start_date :'||l_etc_start_date;
4065 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4066
4067 pa_debug.g_err_stage:= 'Fetching l_project_id :'||l_project_id;
4068 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4069
4070 pa_debug.g_err_stage:= 'Fetching l_target_version_type :'||l_target_version_type;
4071 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4072
4073 pa_debug.g_err_stage:= 'Fetching l_project_structure_version_id :'||l_project_structure_version_id;
4074 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4075 END IF;
4076
4077 -- Select the details required from pa_projects_all so that they can be used in the later part of the code
4078 SELECT project_currency_code
4079 ,projfunc_currency_code
4080 ,nvl(baseline_funding_flag,'N')
4081 INTO l_project_currency_code
4082 ,l_projfunc_currency_code
4083 ,l_baseline_funding_flag
4084 FROM pa_projects_all
4085 WHERE project_id=l_project_id;
4086
4087 IF P_PA_debug_mode = 'Y' THEN
4088 pa_debug.g_err_stage:= 'Fetching l_project_currency_code :'||l_project_currency_code;
4089 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4090
4091 pa_debug.g_err_stage:= 'Fetching l_projfunc_currency_code :'||l_projfunc_currency_code;
4092 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4093
4094 pa_debug.g_err_stage:= 'Fetching l_baseline_funding_flag :'||l_baseline_funding_flag;
4095 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4096 END IF;
4097
4098 -- Select the details required from pa_proj_fp_options so that they can be used in the later part of the code
4099 SELECT proj_fp_options_id,
4100 plan_in_multi_curr_flag,
4101 nvl(cost_time_phased_code,nvl(revenue_time_phased_code,all_time_phased_code)),
4102 margin_derived_from_code,
4103 approved_cost_plan_type_flag,
4104 approved_rev_plan_type_flag,
4105 nvl(cost_resource_list_id,nvl(revenue_resource_list_id,all_resource_list_id)),
4106 rbs_version_id,
4107 nvl(cost_fin_plan_level_code,nvl(revenue_fin_plan_level_code,all_fin_plan_level_code)),
4108 decode(fin_plan_preference_code, 'COST_ONLY', gen_cost_ret_manual_line_flag,
4109 'REVENUE_ONLY', gen_rev_ret_manual_line_flag,
4110 'COST_AND_REV_SAME', gen_all_ret_manual_line_flag)
4111 INTO l_targ_proj_fp_options_id,
4112 l_targ_multi_curr_flag,
4113 l_targ_time_phased_code,
4114 L_REPORT_COST_USING,
4115 l_targ_app_cost_flag,
4116 l_targ_app_rev_flag,
4117 l_targ_resource_list_id,
4118 l_rbs_version_id,
4119 l_targ_plan_level_code,
4120 l_retain_manual_lines_flag -- bug 3934574
4121 FROM pa_proj_fp_options
4122 WHERE fin_plan_version_id = p_budget_version_id
4123 AND fin_plan_type_id = p_fin_plan_type_id;
4124
4125 /*l_copy_pfc_for_txn_amt_flag will be set to Y if the amounts can be entered only in project functinal
4126 *Curreny in target. If the target is a change document then the amounts should always be copied in txn
4127 *currency and hence the flag will be set to N. If the target is not a change document and if it is a
4128 *approved revenue version then the amounts should always be copied in project functional currency and
4129 *hence the flag will be Y.
4130 */
4131 l_copy_pfc_for_txn_amt_flag:='N';
4132 IF p_context = 'CI_MERGE' THEN
4133 l_copy_pfc_for_txn_amt_flag := 'N';
4134 ELSIF l_targ_app_rev_flag='Y' THEN
4135 l_copy_pfc_for_txn_amt_flag :='Y';
4136 END IF;
4137
4138 IF P_PA_debug_mode = 'Y' THEN
4139 pa_debug.g_err_stage:= 'Fetching l_targ_proj_fp_options_id :'||l_targ_proj_fp_options_id;
4140 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4141
4142 pa_debug.g_err_stage:= 'Fetching l_targ_multi_curr_flag :'||l_targ_multi_curr_flag;
4143 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4144
4145 pa_debug.g_err_stage:= 'Fetching l_targ_time_phased_code :'||l_targ_time_phased_code;
4146 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4147
4148 pa_debug.g_err_stage:= 'Fetching L_REPORT_COST_USING :'||L_REPORT_COST_USING;
4149 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4150
4151 pa_debug.g_err_stage:= 'Fetching l_targ_app_cost_flag :'||l_targ_app_cost_flag;
4152 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4153
4154 pa_debug.g_err_stage:= 'Fetching l_targ_app_rev_flag :'||l_targ_app_rev_flag;
4155 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4156
4157 pa_debug.g_err_stage:= 'Fetching l_copy_pfc_for_txn_amt_flag :'||l_copy_pfc_for_txn_amt_flag;
4158 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4159
4160 pa_debug.g_err_stage:= 'Fetching l_targ_resource_list_id :'||l_targ_resource_list_id;
4161 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4162
4163 pa_debug.g_err_stage:= 'Fetching l_rbs_version_id :'||l_rbs_version_id;
4164 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4165
4166 pa_debug.g_err_stage:= 'Fetching l_targ_plan_level_code :'||l_targ_plan_level_code;
4167 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4168 END IF;
4169
4170 EXCEPTION
4171 WHEN NO_DATA_FOUND THEN
4172 IF P_PA_debug_mode = 'Y' THEN
4173 pa_debug.g_err_stage:='NO_DATA_FOUND while getting details required to be used in the later part of the code';
4174 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4175 END IF;
4176 RAISE NO_DATA_FOUND;
4177 END;
4178
4179 --dbms_output.put_line('I4');
4180 --Derive cost/rev impl flags if they are passed as null
4181 IF p_cost_impl_flag IS NULL OR
4182 p_rev_impl_flag IS NULL THEN
4183
4184 IF P_PA_debug_mode = 'Y' THEN
4185 pa_debug.g_err_stage:= 'Calling get_impl_details';
4186 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4187 END IF;
4188
4189 pa_fp_control_items_utils.get_impl_details
4190 ( P_fin_plan_type_id => p_fin_plan_type_id
4191 ,P_project_id => l_project_id
4192 ,P_ci_id => p_ci_id
4193 ,P_ci_cost_version_id => l_ci_cost_version_id
4194 ,P_ci_rev_version_id => l_ci_rev_version_id
4195 ,P_ci_all_version_id => l_ci_all_version_id
4196 ,p_targ_bv_id => p_budget_version_id
4197 ,x_cost_impl_flag => l_cost_impl_flag
4198 ,x_rev_impl_flag => l_rev_impl_flag
4199 ,X_cost_impact_impl_flag => l_cost_impact_impl_flag
4200 ,x_rev_impact_impl_flag => l_rev_impact_impl_flag
4201 ,x_partially_impl_flag => l_partially_impl_flag
4202 ,x_agreement_num => l_agreement_num
4203 ,x_approved_fin_pt_id => l_approved_fin_pt_id
4204 ,x_return_status => l_return_status
4205 ,x_msg_data => l_msg_data
4206 ,x_msg_count => l_msg_count);
4207
4208 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4209 IF P_PA_debug_mode = 'Y' THEN
4210 pa_debug.g_err_stage:= 'pa_fp_control_items_utils.get_impl_details returned error';
4211 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4212 END IF;
4213 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4214 END IF;
4215
4216 END IF;
4217
4218 IF P_PA_debug_mode = 'Y' THEN
4219 pa_debug.g_err_stage:= '--BEFORE IMPL DETAILS-- p_ci_id --'||p_ci_id;
4220 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4221
4222 pa_debug.g_err_stage:= '--BEFORE IMPL DETAILS-- l_cost_impl_flag --'||l_cost_impl_flag;
4223 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4224
4225 pa_debug.g_err_stage:= '--BEFORE IMPL DETAILS-- l_rev_impl_flag --'||l_rev_impl_flag;
4226 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4227 END IF;
4228
4229 IF p_cost_impl_flag IS NULL THEN
4230
4231 --This check is required since get_impl_details can assign values other than Y / N to l_cost_impl_flag
4232 --Refer to the API for the possible values of l_cost_impl_flag
4233 IF l_cost_impl_flag <>'Y' THEN
4234
4235 l_cost_impl_flag :='N';
4236
4237 END IF;
4238
4239 ELSE
4240
4241 l_cost_impl_flag:=p_cost_impl_flag;
4242
4243 END IF;
4244
4245
4246 -- We will consider the value 'R' as 'Y' for l_rev_impl_flag
4247 IF p_rev_impl_flag IS NULL THEN
4248
4249 --This check is required since get_impl_details can assign values other than Y / N to l_rev_impl_flag
4250 --Refer to the API for the possible values of l_rev_impl_flag
4251 IF l_rev_impl_flag NOT IN ('Y','R') THEN
4252
4253 l_rev_impl_flag :='N';
4254
4255 ELSIF l_rev_impl_flag = 'R' THEN
4256
4257 l_rev_impl_flag :='Y';
4258 l_partial_rev_impl_flag := 'R'; --caching this value so that we may use this to skip/execute chunks of code based on its value
4259
4260 END IF;
4261
4262 ELSE
4263
4264 IF p_rev_impl_flag = 'R' THEN
4265 l_rev_impl_flag:='Y';
4266 l_partial_rev_impl_flag := 'R'; --caching this value so that we may use this to skip/execute chunks of code based on its value
4267 ELSE
4268 l_rev_impl_flag:=p_rev_impl_flag;
4269 END IF;
4270
4271 END IF;
4272
4273 --dbms_output.put_line('I5');
4274
4275 IF P_PA_debug_mode = 'Y' THEN
4276 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- p_fin_plan_type_id --'||p_fin_plan_type_id;
4277 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4278
4279 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_project_id --'||l_project_id;
4280 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4281
4282 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- p_ci_id --'||p_ci_id;
4283 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4284
4285 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_ci_cost_version_id --'||l_ci_cost_version_id;
4286 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4287
4288 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_ci_rev_version_id --'||l_ci_rev_version_id;
4289 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4290
4291 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_ci_all_version_id --'||l_ci_all_version_id;
4292 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4293
4294 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_cost_impl_flag --'||l_cost_impl_flag;
4295 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4296
4297 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_rev_impl_flag --'||l_rev_impl_flag;
4298 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4299
4300 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_cost_impact_impl_flag --'||l_cost_impact_impl_flag;
4301 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4302
4303 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_rev_impact_impl_flag --'||l_rev_impact_impl_flag;
4304 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4305
4306 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_partially_impl_flag --'||l_partially_impl_flag;
4307 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4308
4309 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_agreement_num --'||l_agreement_num;
4310 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4311
4312 pa_debug.g_err_stage:= '--AFTER IMPL DETAILS-- l_approved_fin_pt_id --'||l_approved_fin_pt_id;
4313 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4314 END IF;
4315
4316 --Bug 4136238.Moved it to later part of the code
4317 --l_partial_impl_rev_amt := p_partial_impl_rev_amt; -- Bug 3732446
4318
4319 I:=1;
4320 IF l_cost_impl_flag = 'Y' THEN
4321 l_src_ver_id_tbl.extend();
4322 l_impl_type_tbl.extend();
4323 l_impl_qty_tbl.extend();
4324 l_src_ver_id_tbl(i) := nvl(l_ci_cost_version_id, l_ci_all_version_id);
4325 l_impl_type_tbl(i) := 'COST';
4326 l_impl_qty_tbl(i) := 'Y'; -- l_impl_qty_tbl(i) contains whether quantity needs to be implemented or not
4327 I:= I+1;
4328 END IF;
4329
4330 IF l_rev_impl_flag = 'Y' THEN
4331 IF I = 2 THEN
4332 IF l_src_ver_id_tbl(1) <> nvl(l_ci_all_version_id,-99) THEN -- Bug 3662136
4333 l_src_ver_id_tbl.extend();
4334 l_impl_type_tbl.extend();
4335 l_impl_qty_tbl.extend();
4336 l_src_ver_id_tbl(i) := l_ci_rev_version_id;
4337 l_impl_type_tbl(i) := 'REVENUE';
4338 --If the target verison type is ALL then quantity should be merged only with Cost and not with
4339 --Revenue.Hence the impl qty should be N.
4340 IF l_target_version_type ='ALL' THEN
4341 l_impl_qty_tbl(i) := 'N';
4342 ELSE
4343 l_impl_qty_tbl(i) := 'Y';
4344 END IF;
4345 ELSE
4346 l_impl_type_tbl(1) := 'ALL';
4347 END IF;
4348 --Only Revenue impact is being implemented. The target should always be of type REVENUE in this case since
4349 --revenue impact can be implemented either into a ALL or REVENUE version and revenue impact alone can not
4350 --be implemented into an ALL version
4351 ELSE
4352 l_src_ver_id_tbl.extend();
4353 l_impl_type_tbl.extend();
4354 l_impl_qty_tbl.extend();
4355 l_src_ver_id_tbl(i) := nvl(l_ci_rev_version_id, l_ci_all_version_id);
4356 l_impl_type_tbl(i) := 'REVENUE';
4357 --Merge quantity while merging either an ALL CI or a REVENUE CI verison into a revenue target version
4358 l_impl_qty_tbl(i) := 'Y';
4359 END IF;
4360 END IF;
4361
4362 --Bug 3980129. Store the derived values for cost/rev impl flags
4363 l_derv_cost_impl_flag := l_cost_impl_flag;
4364 l_derv_rev_impl_flag := l_rev_impl_flag;
4365 --dbms_output.put_line('I6');
4366 -- For each source version id of the change order for which there is an impact
4367 FOR J IN l_src_ver_id_tbl.FIRST..l_src_ver_id_tbl.LAST LOOP
4368
4369 --Initialize parital factor to 1. It will be derived later
4370 l_partial_factor :=1;
4371
4372 --Bug 3980129.Derive the values for l_cost/rev_impl_flags
4373 --Bug 4136238. Initialized l_partial_impl_rev_amt only in revenue implementation.
4374 IF l_impl_type_tbl(J)= 'COST' THEN
4375
4376 l_cost_impl_flag := l_derv_cost_impl_flag;
4377 l_rev_impl_flag := 'N';
4378 l_partial_impl_rev_amt := NULL;
4379
4380 ELSIF l_impl_type_tbl(J)= 'REVENUE' THEN
4381
4382 l_cost_impl_flag := 'N';
4383 l_rev_impl_flag := l_derv_rev_impl_flag;
4384 l_partial_impl_rev_amt := p_partial_impl_rev_amt;
4385
4386 ELSIF l_impl_type_tbl(J)= 'ALL' THEN
4387
4388 l_cost_impl_flag := l_derv_cost_impl_flag;
4389 l_rev_impl_flag := l_derv_rev_impl_flag;
4390 l_partial_impl_rev_amt := p_partial_impl_rev_amt;
4391
4392 END IF;
4393 --Delete the lables which will be used for caching
4394 l_src_targ_task_tbl.delete;
4395 l_res_assmt_map_rec_tbl.delete;
4396
4397 l_impl_earlier:='N';
4398
4399 --One CO can be implemented more than once into the target version only when it gets
4400 --implemented partially . IN other cases a case will never arise where this API is called for the
4401 --same CO and target version combination for more than once for implementing the same impact.
4402 --In case a CO is getting implemented partially and if a record already exists in pa_fp_mergedc_ctrl_items
4403 --then that existing record should be updated.
4404 --The difference between the amounts existing before merge and the resulting amounts after merge
4405 --will be updated in pa_fp_merged_ctrl_items
4406 IF p_context='PARTIAL_REV' OR
4407 (p_context = 'INCLUDE' AND l_partial_rev_impl_flag = 'R' AND l_impl_type_tbl(j) IN ( 'REVENUE', 'ALL')) THEN
4408
4409 BEGIN
4410
4411 SELECT impl_agr_revenue,
4412 nvl(impl_proj_func_revenue,0), -- bug 4035856
4413 nvl(impl_proj_revenue,0), -- bug 4035856
4414 nvl(impl_quantity,0) -- bug 4035856
4415 INTO l_impl_amt,
4416 l_impl_proj_func_revenue, -- bug 4035856
4417 l_impl_proj_revenue, -- bug 4035856
4418 l_impl_quantity -- bug 4035856
4419 FROM pa_fp_merged_ctrl_items
4420 WHERE project_id=l_project_id
4421 AND plan_version_id=p_budget_version_id
4422 AND ci_id=p_ci_id
4423 AND ci_plan_version_id=l_src_ver_id_tbl(j)
4424 AND version_type='REVENUE';
4425
4426 l_impl_earlier:='Y';
4427 EXCEPTION
4428 WHEN NO_DATA_FOUND THEN
4429 l_impl_amt:=0;
4430 l_impl_proj_func_revenue:=0;
4431 l_impl_proj_revenue :=0;
4432 l_impl_quantity:=0;
4433 l_impl_earlier:='N';
4434 END;
4435
4436
4437 IF p_context = 'PARTIAL_REV' OR l_impl_earlier = 'Y' THEN
4438
4439 BEGIN
4440 SELECT nvl(sum(pbl.txn_revenue),0) total_amt,
4441 nvl(sum(pbl.revenue),0) total_amt_in_pfc,
4442 nvl(sum(pbl.project_revenue),0) total_amt_in_pc
4443 INTO L_total_amt,
4444 l_total_amt_in_pfc,
4445 l_total_amt_in_pc
4446 FROM Pa_budget_lines pbl
4447 WHERE pbl.budget_Version_id= l_src_ver_id_tbl(j);
4448 --IPM Arch Enhancement Bug 4865563
4449 /*
4450 and pbl.cost_rejection_code IS NULL
4451 and pbl.revenue_rejection_code IS NULL
4452 and pbl.burden_rejection_code IS NULL
4453 and pbl.other_rejection_code IS NULL
4454 and pbl.pc_cur_conv_rejection_code IS NULL
4455 and pbl.pfc_cur_conv_rejection_code IS NULL; */
4456
4457
4458 IF P_PA_debug_mode = 'Y' THEN
4459 pa_debug.g_err_stage:='Fetching l_impl_amt'||l_impl_amt;
4460 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4461
4462 pa_debug.g_err_stage:='Fetching L_total_amt'||L_total_amt;
4463 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4464 END IF;
4465
4466 EXCEPTION
4467 WHEN OTHERS THEN
4468 IF P_PA_debug_mode = 'Y' THEN
4469 pa_debug.g_err_stage:='Error while getting total and implemented rev ';
4470 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4471 END IF;
4472 RAISE;
4473 END;
4474
4475 --For bug 3814932
4476 IF l_total_amt = 0 THEN
4477
4478 l_partial_factor:=1;
4479
4480 ELSE
4481
4482 --If l_partial_factor is 0 only Resource assignments will be copied. Control will return
4483 --from API without copying the budget lines.
4484
4485 IF p_context = 'INCLUDE' THEN
4486 l_partial_impl_rev_amt := l_total_amt - l_impl_amt;
4487 END IF;
4488 l_partial_factor:=l_partial_impl_rev_amt/(l_total_amt);
4489
4490 END IF;
4491 END IF;
4492 END IF;
4493
4494 --Bug 4136238. The variable l_partial_impl_rev_amt will always(not only in partial impl case) contain the
4495 --revenue amount in txn currency that will get implemented. The below block of code will take care of
4496 --populating that variable when the revenue gets implemented fully
4497 IF l_impl_type_tbl(J) <>'COST' AND
4498 (p_context = 'IMPL_FIN_IMPACT' OR
4499 (p_context = 'INCLUDE' AND l_impl_earlier ='N')) THEN
4500
4501 IF P_PA_debug_mode = 'Y' THEN
4502 pa_debug.g_err_stage:='Deriving l_partial_impl_rev_amt in FULL Rev impl case ';
4503 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4504 END IF;
4505
4506 SELECT NVL(sum(txn_revenue),0)
4507 INTO l_partial_impl_rev_amt
4508 FROM pa_budget_lines
4509 WHERE budget_version_id=l_src_ver_id_tbl(j);
4510
4511 IF P_PA_debug_mode = 'Y' THEN
4512 pa_debug.g_err_stage:='l_partial_impl_rev_amt derived is '||l_partial_impl_rev_amt;
4513 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4514 END IF;
4515
4516 END IF;
4517
4518
4519 IF P_PA_debug_mode = 'Y' THEN
4520 pa_debug.g_err_stage:='l_partial_factor IS '||l_partial_factor;
4521 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4522 END IF;
4523
4524
4525 BEGIN
4526 SELECT proj_fp_options_id,
4527 plan_in_multi_curr_flag,
4528 fin_plan_type_id,
4529 nvl(cost_time_phased_code,nvl(revenue_time_phased_code,all_time_phased_code)),
4530 report_labor_hrs_from_code,
4531 nvl(cost_resource_list_id,nvl(revenue_resource_list_id,all_resource_list_id)),
4532 nvl(cost_fin_plan_level_code,nvl(revenue_fin_plan_level_code,all_fin_plan_level_code))
4533 INTO l_src_proj_fp_options_id,
4534 l_src_multi_curr_flag,
4535 l_src_fin_plan_type_id,
4536 l_src_time_phased_code,
4537 l_src_report_lbr_hrs_frm_code,
4538 l_src_resource_list_id,
4539 l_src_plan_level_code
4540 FROM pa_proj_fp_options
4541 WHERE fin_plan_version_id = l_src_ver_id_tbl(j);
4542
4543 IF P_PA_debug_mode = 'Y' THEN
4544 pa_debug.g_err_stage:='Fetching l_src_proj_fp_options_id'||l_src_proj_fp_options_id;
4545 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4546
4547 pa_debug.g_err_stage:='Fetching l_src_multi_curr_flag'||l_src_multi_curr_flag;
4548 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4549
4550 pa_debug.g_err_stage:='Fetching l_src_fin_plan_type_id'||l_src_fin_plan_type_id;
4551 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4552
4553 pa_debug.g_err_stage:='Fetching l_src_time_phased_code'||l_src_time_phased_code;
4554 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4555
4556 pa_debug.g_err_stage:='Fetching l_src_report_lbr_hrs_frm_code'||l_src_report_lbr_hrs_frm_code;
4557 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4558
4559 pa_debug.g_err_stage:='Fetching l_src_resource_list_id'||l_src_resource_list_id;
4560 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4561
4562 pa_debug.g_err_stage:='Fetching l_src_plan_level_code'||l_src_plan_level_code;
4563 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4564 END IF;
4565
4566
4567 EXCEPTION
4568 WHEN NO_DATA_FOUND THEN
4569 IF P_PA_debug_mode = 'Y' THEN
4570 pa_debug.g_err_stage:='NO_DATA_FOUND while getting src attributes ';
4571 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4572 END IF;
4573 RAISE NO_DATA_FOUND;
4574 END;
4575
4576 --dbms_output.put_line('I8');
4577 -- Add the currencies in the source which are not there already to PA_FP_TXN_CURRENCIES
4578 IF l_src_multi_curr_flag = 'Y' AND l_targ_multi_curr_flag = 'Y' AND nvl(l_targ_app_rev_flag, 'N') = 'N' THEN
4579
4580 SELECT ptxn_s.txn_currency_code
4581 BULK COLLECT INTO l_txn_curr_code_tbl
4582 FROM pa_fp_txn_currencies ptxn_s
4583 WHERE ptxn_s.proj_fp_options_id=l_src_proj_fp_options_id
4584 AND NOT EXISTS (SELECT 'X'
4585 FROM pa_fp_txn_currencies ptxn_t
4586 WHERE ptxn_t.proj_fp_options_id=l_targ_proj_fp_options_id
4587 AND ptxn_t.txn_currency_code=ptxn_s.txn_currency_code);
4588
4589
4590 IF l_txn_curr_code_tbl.COUNT > 0 THEN
4591 For i in l_txn_curr_code_tbl.FIRST..l_txn_curr_code_tbl.LAST LOOP
4592 IF P_PA_debug_mode = 'Y' THEN
4593 pa_debug.g_err_stage:='INSERTING l_targ_proj_fp_options_id'||l_targ_proj_fp_options_id;
4594 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4595
4596 pa_debug.g_err_stage:='INSERTING l_PROJECT_ID'||l_PROJECT_ID;
4597 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4598
4599 pa_debug.g_err_stage:='INSERTING p_budget_version_id'||p_budget_version_id;
4600 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4601
4602 pa_debug.g_err_stage:='INSERTING l_txn_curr_code_tbl'||l_txn_curr_code_tbl(i);
4603 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4604 END IF;
4605 END LOOP;
4606 END IF;
4607
4608 IF l_txn_curr_code_tbl.COUNT > 0 THEN
4609 Forall jj in l_txn_curr_code_tbl.FIRST..l_txn_curr_code_tbl.LAST
4610 INSERT INTO PA_FP_TXN_CURRENCIES (
4611 fp_txn_currency_id
4612 ,proj_fp_options_id
4613 ,project_id
4614 ,fin_plan_type_id
4615 ,fin_plan_version_id
4616 ,txn_currency_code
4617 ,default_rev_curr_flag
4618 ,default_cost_curr_flag
4619 ,default_all_curr_flag
4620 ,project_currency_flag
4621 ,projfunc_currency_flag
4622 ,last_update_date
4623 ,last_updated_by
4624 ,creation_date
4625 ,created_by
4626 ,last_update_login
4627 ,project_cost_exchange_rate
4628 ,project_rev_exchange_rate
4629 ,projfunc_cost_exchange_Rate
4630 ,projfunc_rev_exchange_Rate
4631 )
4632 VALUES
4633 ( pa_fp_txn_currencies_s.NEXTVAL
4634 , l_targ_proj_fp_options_id
4635 , l_PROJECT_ID
4636 , p_fin_plan_type_id
4637 , p_budget_version_id
4638 , l_txn_curr_code_tbl(jj)
4639 , 'N'
4640 , 'N'
4641 , 'N'
4642 , 'N'
4643 , 'N'
4644 , sysdate
4645 , fnd_global.user_id
4646 , sysdate
4647 , fnd_global.user_id
4648 , fnd_global.login_id
4649 , NULL
4650 , NULL
4651 , NULL
4652 , NULL);
4653
4654 END IF; -- l_txn_curr_code_tbl.COUNT > 0
4655 END IF; -- l_src_multi_curr_flag = 'Y' AND l_targ_multi_curr_flag = 'Y' AND nvl(l_targ_app_rev_flag, 'N') = 'N'
4656
4657 --dbms_output.put_line('I9');
4658 IF l_src_resource_list_id <> l_targ_resource_list_id THEN
4659
4660 -- When the resource lists are different we need to call the mapping API.
4661 PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs(
4662 p_budget_version_id => l_src_ver_id_tbl(j)
4663 ,p_resource_list_id => l_targ_resource_list_id
4664 ,p_calling_process => 'BUDGET_GENERATION'
4665 ,p_calling_context => 'PLSQL'
4666 ,p_process_code => 'RES_MAP'
4667 ,p_calling_mode => 'BUDGET_VERSION'
4668 ,p_init_msg_list_flag => 'N'
4669 ,p_commit_flag => 'N'
4670 ,x_txn_source_id_tab => l_txn_source_id_tbl
4671 ,x_res_list_member_id_tab => l_res_list_member_id_tbl
4672 ,x_rbs_element_id_tab => l_rbs_element_id_prm_tbl
4673 ,x_txn_accum_header_id_tab => l_txn_accum_header_id_prm_tbl
4674 ,x_return_status => l_return_status
4675 ,x_msg_count => l_msg_count
4676 ,x_msg_data => l_msg_data);
4677
4678 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4679 IF P_PA_debug_mode = 'Y' THEN
4680 pa_debug.g_err_stage:= 'PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs returned error';
4681 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
4682 END IF;
4683 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4684 END IF;
4685
4686 -- bug 3934574 In generation context, if retain manual edited lines is 'Y' filter
4687 -- all RAs with null transaction souce code
4688 SELECT rlmap.resource_list_member_id -- rlm id for the target
4689 ,DECODE(prat.resource_assignment_id,null, 'INSERT','UPDATE') --Indicates whether the records needs to be updated/inserted in the target
4690 ,get_task_id(l_targ_plan_level_code,rlmap.task_id),
4691 prat.resource_assignment_id,
4692 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.txn_source_id),null),
4693 min(LEAST(nvl(prat.planning_start_date, rlmap.planning_start_date),rlmap.planning_start_date)),
4694 max(GREATEST(nvl(prat.planning_end_date, rlmap.planning_end_date),rlmap.planning_end_date)),
4695 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.txn_spread_curve_id),null),
4696 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.txn_etc_method_code),null),
4697 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.resource_type_code),null),
4698 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.fc_res_type_code),null),
4699 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.RESOURCE_CLASS_CODE),null),
4700 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.organization_id),null),
4701 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.job_id),null),
4702 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.person_id),null),
4703 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.expenditure_type),null),
4704 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.expenditure_category),null),
4705 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.revenue_category),null),
4706 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.event_type),null),
4707 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.vendor_id),null),
4708 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.project_role_id),null),
4709 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.person_type_code),null),
4710 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.non_labor_resource),null),
4711 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.bom_resource_id),null),
4712 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.inventory_item_id),null),
4713 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.item_category_id),null),
4714 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.mfc_cost_type_id),null),
4715 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.INCURRED_BY_RES_FLAG),null),
4716 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.RESOURCE_CLASS_FLAG),null),
4717 decode(COUNT(rlmap.txn_source_id),1,max(rlmap.NAMED_ROLE),null),
4718 NULL,
4719 NULL,
4720 NULL,
4721 NULL,
4722 NULL,
4723 --The below decodes will return the Rate Based Flag(rbf) and unit of measure(uom) for the target
4724 --resource assignment. These decodes will derive the rbf and uom based on following logic
4725 ------If multiple source planning transactions are being merged into a single target transaction
4726 ----------If the all the source planning transactions have same UOM AND RBF then
4727 --------------if the UOM and RBF are equal to those of target planning transaction then
4728 ------------------take UOM and RBF from the source
4729 --------------else
4730 ------------------take DOLLARS and N for UOM and RBF
4731 ----------else
4732 --------------take DOLLARS and N for UOM and RBF
4733 ------else if there is one to one mapping
4734 ----------If the UOM and RBF of the source and target plannig transactions are same then
4735 --------------take UOM and RBF from source
4736 ----------else
4737 --------------take DOLLARS and N for UOM and RBF
4738 ------else if there is no matching target transaction(In this case one should be inserted into target)
4739 ----------source's RBF and UOM will be compared with the RBF and UOM returned be get_resource_defaults.
4740 ----------This is done below
4741 decode(max(rlmap.rbf),
4742 min(rlmap.rbf),decode(max(rlmap.uom),
4743 min(rlmap.uom),decode(prat.resource_assignment_id,
4744 null, max(rlmap.rbf),
4745 decode(max(rlmap.rbf),
4746 max(prat.rate_based_flag),decode(max(rlmap.uom),
4747 max(prat.unit_of_measure),max(rlmap.rbf),
4748 'N'),
4749 'N')),
4750 'N'),
4751 'N'),
4752 /* bug 5073816: Changed the following */
4753 max(rlmap.rrbf), --IPM Arch Enhancement
4754 decode(max(rlmap.rbf),
4755 min(rlmap.rbf),decode(max(rlmap.uom),
4756 min(rlmap.uom),decode(prat.resource_assignment_id,
4757 null, max(rlmap.uom),
4758 decode(max(rlmap.rbf),
4759 max(prat.rate_based_flag),decode(max(rlmap.uom),
4760 max(prat.unit_of_measure),max(rlmap.uom),
4761 'DOLLARS'),
4762 'DOLLARS')),
4763 'DOLLARS'),
4764 'DOLLARS'),
4765 --Bug 3752352. If the resource lists are differnt then initialise the rbs element id and
4766 --txn accum header tbls .
4767 NULL,
4768 NULL
4769 BULK COLLECT INTO
4770 L_targ_rlm_id_tbl,
4771 L_ra_dml_code_tbl,
4772 L_targ_task_id_tbl,
4773 L_targ_ra_id_tbl,
4774 l_src_ra_id_cnt_tbl,
4775 l_planning_start_date_tbl,
4776 l_planning_end_date_tbl,
4777 l_targ_spread_curve_id_tbl,
4778 l_targ_etc_method_code_tbl,
4779 l_targ_resource_type_code_tbl,
4780 l_targ_fc_res_type_code_tbl,
4781 l_targ_RESOURCE_CLASS_CODE_tbl,
4782 l_targ_organization_id_tbl,
4783 l_targ_job_id_tbl,
4784 l_targ_person_id_tbl,
4785 l_targ_expenditure_type_tbl,
4786 l_targ_expend_category_tbl,
4787 l_targ_rev_category_code_tbl,
4788 l_targ_event_type_tbl,
4789 l_targ_supplier_id_tbl,
4790 l_targ_project_role_id_tbl,
4791 l_targ_person_type_code_tbl,
4792 l_targ_non_labor_resource_tbl,
4793 l_targ_bom_resource_id_tbl,
4794 l_targ_inventory_item_id_tbl,
4795 l_targ_item_category_id_tbl,
4796 l_targ_mfc_cost_type_id_tbl,
4797 l_targ_INCURED_BY_RES_FLAG_tbl,
4798 l_targ_RESOURCE_CLASS_FLAG_tbl,
4799 l_targ_NAMED_ROLE_tbl ,
4800 l_targ_RATE_EXPEND_TYPE_tbl,
4801 l_targ_RATE_EXP_FC_CUR_COD_tbl,
4802 l_targ_RATE_EXPEND_ORG_ID_tbl,
4803 l_targ_INCR_BY_RES_CLS_COD_tbl,
4804 l_targ_INCUR_BY_ROLE_ID_tbl,
4805 l_targ_RATE_BASED_FLAG_tbl,
4806 l_targ_RES_RATE_BASED_FLAG_tbl, --IPM Arch Enhancement
4807 l_targ_unit_of_measure_tbl,
4808 l_targ_rbs_element_id_tbl,
4809 l_targ_txn_accum_header_id_tbl
4810
4811 FROM Pa_resource_assignments prat,
4812 (SELECT
4813 rlmap.txn_spread_curve_id,
4814 rlmap.txn_etc_method_code,
4815 rlmap.resource_type_code,
4816 rlmap.fc_res_type_code,
4817 rlmap.RESOURCE_CLASS_CODE,
4818 rlmap.organization_id,
4819 rlmap.job_id,
4820 rlmap.person_id,
4821 rlmap.expenditure_type,
4822 rlmap.expenditure_category,
4823 rlmap.revenue_category,
4824 rlmap.event_type,
4825 rlmap.vendor_id,
4826 rlmap.project_role_id,
4827 rlmap.person_type_code,
4828 rlmap.non_labor_resource,
4829 rlmap.bom_resource_id,
4830 rlmap.inventory_item_id,
4831 rlmap.item_category_id,
4832 rlmap.mfc_cost_type_id,
4833 rlmap.INCURRED_BY_RES_FLAG,
4834 rlmap.TXN_RATE_BASED_FLAG,
4835 rlmap.RESOURCE_CLASS_FLAG,
4836 rlmap.NAMED_ROLE,
4837 rlmap.txn_source_id,
4838 rlmap.resource_list_member_id,
4839 pra.planning_start_date,
4840 pra.planning_end_date,
4841 pra.task_id,
4842 pra.rate_based_flag as rbf,
4843 pra.resource_rate_based_flag as rrbf, --IPM Arch Enhancement
4844 pra.unit_of_measure as uom
4845 FROM
4846 pa_resource_assignments pra,
4847 pa_res_list_map_tmp4 rlmap
4848 WHERE
4849 pra.resource_assignment_id=rlmap.txn_source_id)rlmap
4850 WHERE prat.budget_version_id(+)=p_budget_version_id
4851 AND prat.resource_list_member_id(+)=rlmap.resource_list_member_id
4852 AND prat.task_id(+)=get_task_id(l_targ_plan_level_code,rlmap.task_id)
4853 AND prat.project_assignment_id(+)=-1
4854 /* Bug 7287101 - skkoppul - commented
4855 AND (prat.resource_assignment_id is null --> target ra doesnot exist
4856 OR decode(p_calling_context,
4857 'BUDGET_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
4858 'FORECAST_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
4859 -99) is not null) -- bug 3934574 */
4860 GROUP BY get_task_id(l_targ_plan_level_code,rlmap.task_id) ,
4861 rlmap.resource_list_member_id, prat.resource_assignment_id;
4862 ELSE
4863
4864 IF P_PA_debug_mode = 'Y' THEN
4865 pa_debug.g_err_stage:= 'About to select the RAs with same res list for INS/UPD';
4866 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
4867 END IF;
4868
4869 -- bug 3934574 In generation context, if retain manual edited lines is 'Y' filter
4870 -- all RAs with null transaction souce code
4871 SELECT pras.resource_list_member_id -- rlm id for the target
4872 ,DECODE(prat.resource_assignment_id,null, 'INSERT','UPDATE') --Indicates whether the records needs to be updated/inserted in the target
4873 , get_task_id(l_targ_plan_level_code,pras.task_id),
4874 prat.resource_assignment_id,
4875 decode(COUNT(pras.resource_assignment_id),1,max(pras.resource_assignment_id),null),
4876 min(LEAST(nvl(prat.planning_start_date, pras.planning_start_date),pras.planning_start_date)),
4877 max(GREATEST(nvl(prat.planning_end_date, pras.planning_end_date),pras.planning_end_date)),
4878 decode(COUNT(pras.resource_assignment_id),1,max(pras.rbs_element_id),null),
4879 decode(COUNT(pras.resource_assignment_id),1,max(pras.spread_curve_id),null),
4880 decode(COUNT(pras.resource_assignment_id),1,max(pras.etc_method_code),null),
4881 decode(COUNT(pras.resource_assignment_id),1,max(pras.fc_res_type_code),null),
4882 decode(COUNT(pras.resource_assignment_id),1,max(pras.organization_id),null),
4883 decode(COUNT(pras.resource_assignment_id),1,max(pras.job_id),null),
4884 decode(COUNT(pras.resource_assignment_id),1,max(pras.person_id),null),
4885 decode(COUNT(pras.resource_assignment_id),1,max(pras.expenditure_type),null),
4886 decode(COUNT(pras.resource_assignment_id),1,max(pras.expenditure_category),null),
4887 decode(COUNT(pras.resource_assignment_id),1,max(pras.revenue_category_code),null),
4888 decode(COUNT(pras.resource_assignment_id),1,max(pras.event_type),null),
4889 decode(COUNT(pras.resource_assignment_id),1,max(pras.supplier_id),null),
4890 decode(COUNT(pras.resource_assignment_id),1,max(pras.project_role_id),null),
4891 decode(COUNT(pras.resource_assignment_id),1,max(pras.res_type_code),null),
4892 decode(COUNT(pras.resource_assignment_id),1,max(pras.person_type_code),null),
4893 decode(COUNT(pras.resource_assignment_id),1,max(pras.non_labor_resource),null),
4894 decode(COUNT(pras.resource_assignment_id),1,max(pras.bom_resource_id),null),
4895 decode(COUNT(pras.resource_assignment_id),1,max(pras.inventory_item_id),null),
4896 decode(COUNT(pras.resource_assignment_id),1,max(pras.item_category_id),null),
4897 decode(COUNT(pras.resource_assignment_id),1,max(pras.INCURRED_BY_RES_FLAG),null),
4898 decode(COUNT(pras.resource_assignment_id),1,max(pras.RESOURCE_CLASS_FLAG),null),
4899 decode(COUNT(pras.resource_assignment_id),1,max(pras.NAMED_ROLE),null),
4900 decode(COUNT(pras.resource_assignment_id),1,max(pras.TXN_ACCUM_HEADER_ID),null),
4901 decode(COUNT(pras.resource_assignment_id),1,max(pras.RESOURCE_CLASS_CODE),null),
4902 decode(COUNT(pras.resource_assignment_id),1,max(pras.ASSIGNMENT_DESCRIPTION),null),
4903 decode(COUNT(pras.resource_assignment_id),1,max(pras.MFC_COST_TYPE_ID),null),
4904 decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_JOB_ID),null),
4905 decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_EXPENDITURE_TYPE),null),
4906 decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_EXP_FUNC_CURR_CODE),null),
4907 decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_EXPENDITURE_ORG_ID),null),
4908 decode(COUNT(pras.resource_assignment_id),1,max(pras.INCUR_BY_RES_CLASS_CODE),null),
4909 decode(COUNT(pras.resource_assignment_id),1,max(pras.INCUR_BY_ROLE_ID),null),
4910 --The below decodes will return the Rate Based Flag(rbf) and unit of measure(uom) for the target
4911 --resource assignment. These decodes will derive the rbf and uom based on following logic
4912 ------If multiple source planning transactions are being merged into a single target transaction
4913 ----------If the all the source planning transactions have same UOM AND RBF then
4914 --------------if the UOM and RBF are equal to those of target planning transaction then
4915 ------------------take UOM and RBF from the source
4916 --------------else
4917 ------------------take DOLLARS and N for UOM and RBF
4918 ----------else
4919 --------------take DOLLARS and N for UOM and RBF
4920 ------else if there is one to one mapping
4921 ----------If the UOM and RBF of the source and target plannig transactions are same then
4922 --------------take UOM and RBF from source
4923 ----------else
4924 --------------take DOLLARS and N for UOM and RBF
4925 ------else if there is no matching target transaction(In this case one should be inserted into target)
4926 ----------source's RBF and UOM will be compared with the RBF and UOM returned be get_resource_defaults.
4927 ----------This is done below
4928 decode(max(pras.rate_based_flag),
4929 min(pras.rate_based_flag),decode(max(pras.unit_of_measure),
4930 min(pras.unit_of_measure),decode(prat.resource_assignment_id,
4931 null, max(pras.rate_based_flag),
4932 decode(max(pras.rate_based_flag),
4933 max(prat.rate_based_flag),decode(max(pras.unit_of_measure),
4934 max(prat.unit_of_measure),max(pras.rate_based_flag),
4935 'N'),
4936 'N')),
4937 'N'),
4938 'N'),
4939 /* bug 5073816: Changed the following */
4940 max(pras.resource_rate_based_flag), --IPM Arch Enhancement Bug 4865563
4941 decode(max(pras.rate_based_flag),
4942 min(pras.rate_based_flag),decode(max(pras.unit_of_measure),
4943 min(pras.unit_of_measure),decode(prat.resource_assignment_id,
4944 null, max(pras.unit_of_measure),
4945 decode(max(pras.rate_based_flag),
4946 max(prat.rate_based_flag),decode(max(pras.unit_of_measure),
4947 max(prat.unit_of_measure),max(pras.unit_of_measure),
4948 'DOLLARS'),
4949 'DOLLARS')),
4950 'DOLLARS'),
4951 'DOLLARS')
4952 BULK COLLECT INTO
4953 L_targ_rlm_id_tbl,
4954 L_ra_dml_code_tbl,
4955 L_targ_task_id_tbl,
4956 L_targ_ra_id_tbl,
4957 l_src_ra_id_cnt_tbl,
4958 l_planning_start_date_tbl,
4959 l_planning_end_date_tbl,
4960 l_targ_rbs_element_id_tbl,
4961 l_targ_spread_curve_id_tbl,
4962 l_targ_etc_method_code_tbl,
4963 l_targ_fc_res_type_code_tbl,
4964 l_targ_organization_id_tbl,
4965 l_targ_job_id_tbl,
4966 l_targ_person_id_tbl,
4967 l_targ_expenditure_type_tbl,
4968 l_targ_expend_category_tbl,
4969 l_targ_rev_category_code_tbl,
4970 l_targ_event_type_tbl,
4971 l_targ_supplier_id_tbl,
4972 l_targ_project_role_id_tbl,
4973 l_targ_resource_type_code_tbl,
4974 l_targ_person_type_code_tbl,
4975 l_targ_non_labor_resource_tbl,
4976 l_targ_bom_resource_id_tbl,
4977 l_targ_inventory_item_id_tbl,
4978 l_targ_item_category_id_tbl,
4979 l_targ_INCURED_BY_RES_FLAG_tbl,
4980 l_targ_RESOURCE_CLASS_FLAG_tbl,
4981 l_targ_NAMED_ROLE_tbl,
4982 l_targ_txn_accum_header_id_tbl,
4983 l_targ_RESOURCE_CLASS_CODE_tbl,
4984 l_targ_assignment_description,
4985 l_targ_mfc_cost_type_id_tbl,
4986 l_targ_RATE_JOB_ID_tbl,
4987 l_targ_RATE_EXPEND_TYPE_tbl,
4988 l_targ_RATE_EXP_FC_CUR_COD_tbl,
4989 l_targ_RATE_EXPEND_ORG_ID_tbl,
4990 l_targ_INCR_BY_RES_CLS_COD_tbl,
4991 l_targ_INCUR_BY_ROLE_ID_tbl,
4992 l_targ_RATE_BASED_FLAG_tbl,
4993 l_targ_RES_RATE_BASED_FLAG_tbl, --IPM Arch Enhancement Bug 4865563
4994 l_targ_unit_of_measure_tbl
4995 FROM pa_resource_assignments pras,
4996 Pa_resource_assignments prat
4997 WHERE pras.budget_version_id=l_src_ver_id_tbl(j)
4998 AND prat.budget_version_id(+)=p_budget_version_id
4999 AND prat.resource_list_member_id(+)=pras.resource_list_member_id
5000 AND prat.task_id(+)=get_task_id(l_targ_plan_level_code,pras.task_id)
5001 AND prat.project_assignment_id(+)=-1
5002 /* Bug 7287101 - skkoppul - commented
5003 AND (prat.resource_assignment_id is null --> target ra doesnot exist
5004 OR decode(p_calling_context,
5005 'BUDGET_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
5006 'FORECAST_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
5007 -99) is not null) -- bug 3934574 */
5008 GROUP BY get_task_id(l_targ_plan_level_code,pras.task_id) , pras.resource_list_member_id,
5009 prat.resource_assignment_id;
5010
5011 IF P_PA_debug_mode = 'Y' THEN
5012 pa_debug.g_err_stage:= ' selected the RAs with same res list for INS/UPD '||l_targ_ra_id_tbl.count;
5013 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5014 END IF;
5015
5016 END IF;
5017
5018 IF P_PA_debug_mode = 'Y' THEN
5019 pa_debug.g_err_stage:= ' Collected the Target Ras that should either be ins or upd. Count is '||l_targ_ra_id_tbl.count;
5020 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5021 END IF;
5022
5023 --dbms_output.put_line('I10 '||l_targ_ra_id_tbl.COUNT);
5024
5025 IF l_targ_ra_id_tbl.COUNT >0 THEN
5026
5027 --The variable can be made Y now as there are some resource assignments that can be merged. Note that even if this variable is Y
5028 --the reporting lines API will not be called if calculate API is called in the flow
5029 l_call_rep_lines_api:='Y';
5030
5031 --dbms_output.put_line('I11');
5032
5033 /* Store the values for target task id, target rlm id and target resource assignment id in the form of a record.
5034 so that it will be easy later to identify the resource assignment id corresponding to the given task id
5035 and resource list member id*/
5036 FOR ind IN L_targ_ra_id_tbl.FIRST..L_targ_ra_id_tbl.LAST LOOP
5037 IF L_targ_ra_id_tbl(ind) IS NULL THEN
5038 SELECT pa_resource_assignments_s.nextval
5039 INTO L_targ_ra_id_tbl(ind)
5040 FROM dual;
5041 END IF;
5042 l_res_assmt_map_rec_tbl(ind).task_id:=l_targ_task_id_tbl(ind);
5043 l_res_assmt_map_rec_tbl(ind).resource_list_member_id:=l_targ_rlm_id_tbl(ind);
5044 l_res_assmt_map_rec_tbl(ind).resource_assignment_id:=L_targ_ra_id_tbl(ind);
5045 l_res_assmt_map_rec_tbl(ind).ra_dml_code:=L_ra_dml_code_tbl(ind);
5046 END LOOP;
5047
5048 l_da_resource_list_members_tab:=SYSTEM.PA_NUM_TBL_TYPE();
5049 l_txn_src_typ_code_rbs_prm_tbl :=SYSTEM.pa_varchar2_30_tbl_type();
5050
5051 --dbms_output.put_line('I12');
5052 IF l_src_resource_list_id = l_targ_resource_list_id THEN
5053 --Calling resource default API
5054
5055 --dbms_output.put_line('I13');
5056 FOR kk in 1 .. L_targ_rlm_id_tbl.count LOOP
5057
5058 --Find the distinct rlms among the resoruce assignments that have to be inserted .
5059 --This is done to call get_resource_defaults only for distinct rlms. Bug 3859738
5060 IF L_ra_dml_code_tbl(kk) = 'INSERT'
5061 AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN
5062
5063 l_temp:= NULL;
5064 FOR LL IN 1..l_da_resource_list_members_tab.COUNT LOOP
5065 IF l_da_resource_list_members_tab(LL)= L_targ_rlm_id_tbl(kk) THEN
5066 l_temp:=LL;
5067 EXIT;
5068 END IF;
5069 END LOOP;
5070
5071 IF l_temp IS NULL THEN
5072 --Indicates that the resource list member is not already selected and hence it has to be
5073 --considered while calling get_resource_defaults.Bug 3859738
5074
5075 l_da_resource_list_members_tab.extend;
5076 l_da_resource_list_members_tab(l_da_resource_list_members_tab.COUNT) := L_targ_rlm_id_tbl(kk);
5077 l_txn_src_typ_code_rbs_prm_tbl.extend;
5078 l_txn_src_typ_code_rbs_prm_tbl(l_txn_src_typ_code_rbs_prm_tbl.COUNT):='RES_ASSIGNMENT';
5079 END IF;
5080 --for Start Bug 5291484
5081 ELSIF L_ra_dml_code_tbl(kk) = 'INSERT'
5082 AND l_src_ra_id_cnt_tbl(KK) IS NOT NULL THEN
5083
5084 l_temp := NULL; --Bug 5532905.
5085 FOR LL IN 1..lresource_list_members_tab_1.COUNT LOOP
5086 IF lresource_list_members_tab_1(LL)= L_targ_rlm_id_tbl(kk) THEN
5087 l_temp:=LL;
5088 EXIT;
5089 END IF;
5090 END LOOP;
5091
5092 IF P_PA_debug_mode = 'Y' THEN
5093 pa_debug.g_err_stage:= 'before check l_temp ' || l_temp;
5094 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5095 END IF;
5096
5097 IF l_temp IS NULL THEN
5098 lresource_list_members_tab_1.extend;
5099 lresource_list_members_tab_1(lresource_list_members_tab_1.COUNT) := L_targ_rlm_id_tbl(kk);
5100 ltxnsrctyp_code_rbs_prm_tbl_1.extend;
5101 ltxnsrctyp_code_rbs_prm_tbl_1(ltxnsrctyp_code_rbs_prm_tbl_1.COUNT) := 'RES_ASSIGNMENT';
5102 lperson_id_tab_1.extend;
5103 lperson_id_tab_1(lperson_id_tab_1.COUNT) := l_targ_person_id_tbl(kk);
5104 ljob_id_tab_1.extend;
5105 ljob_id_tab_1(ljob_id_tab_1.COUNT) := l_targ_job_id_tbl(kk);
5106 lorganization_id_tab_1.extend;
5107 lorganization_id_tab_1(lorganization_id_tab_1.COUNT) := l_targ_organization_id_tbl(kk);
5108 l_da_supplier_id_tab_1.extend;
5109 l_da_supplier_id_tab_1(l_da_supplier_id_tab_1.COUNT) := l_targ_supplier_id_tbl(kk);
5110 lexpenditure_type_tab_1.extend;
5111 lexpenditure_type_tab_1(lexpenditure_type_tab_1.COUNT) := l_targ_expenditure_type_tbl(kk);
5112 l_da_event_type_tab_1.extend;
5113 l_da_event_type_tab_1(l_da_event_type_tab_1.COUNT) := l_targ_event_type_tbl(kk);
5114 lnon_labor_resource_tab_1.extend;
5115 lnon_labor_resource_tab_1(lnon_labor_resource_tab_1.COUNT) := l_targ_non_labor_resource_tbl(kk);
5116 lexpenditure_category_tab_1.extend;
5117 lexpenditure_category_tab_1(lexpenditure_category_tab_1.COUNT) := l_targ_expend_category_tbl(kk);
5118 lrevenue_category_code_tab_1.extend;
5119 lrevenue_category_code_tab_1(lrevenue_category_code_tab_1.COUNT) := l_targ_rev_category_code_tbl(kk);
5120 lproject_role_id_tab_1.extend;
5121 lproject_role_id_tab_1(lproject_role_id_tab_1.COUNT) := l_targ_project_role_id_tbl(kk);
5122 lresource_class_code_tab_1.extend;
5123 lresource_class_code_tab_1(lresource_class_code_tab_1.COUNT) := l_targ_RESOURCE_CLASS_CODE_tbl(kk);
5124 l_da_mfc_cost_type_id_tab_1.extend;
5125 l_da_mfc_cost_type_id_tab_1(l_da_mfc_cost_type_id_tab_1.COUNT) := l_targ_mfc_cost_type_id_tbl(kk);
5126 lresource_class_flag_tab_1.extend;
5127 lresource_class_flag_tab_1(lresource_class_flag_tab_1.COUNT) := l_targ_resource_class_flag_tbl(kk);
5128 lfc_res_type_code_tab_1.extend;
5129 lfc_res_type_code_tab_1(lfc_res_type_code_tab_1.COUNT) := l_targ_fc_res_type_code_tbl(kk);
5130 linventory_item_id_tab_1.extend;
5131 linventory_item_id_tab_1(linventory_item_id_tab_1.COUNT) := l_targ_inventory_item_id_tbl(kk);
5132 litem_category_id_tab_1.extend;
5133 litem_category_id_tab_1(litem_category_id_tab_1.COUNT) := l_targ_item_category_id_tbl(kk);
5134 lperson_type_code_tab_1.extend;
5135 lperson_type_code_tab_1(lperson_type_code_tab_1.COUNT) := l_targ_person_type_code_tbl(kk);
5136 lbom_resource_id_tab_1.extend;
5137 lbom_resource_id_tab_1(lbom_resource_id_tab_1.COUNT) := l_targ_bom_resource_id_tbl(kk);
5138 lnamed_role_tab_1.extend;
5139 lnamed_role_tab_1(lnamed_role_tab_1.COUNT) := l_targ_NAMED_ROLE_tbl(kk);
5140 lincurred_by_res_flag_tab_1.extend;
5141 lincurred_by_res_flag_tab_1(lincurred_by_res_flag_tab_1.COUNT) := l_targ_incured_by_res_flag_tbl(kk);
5142 l_da_rate_based_flag_tab_1.extend;
5143 l_da_rate_based_flag_tab_1(l_da_rate_based_flag_tab_1.COUNT) := l_targ_rate_based_flag_tbl(kk);
5144 END IF;
5145 --for End Bug 5291484
5146
5147 END IF;
5148 END LOOP;
5149
5150 IF P_PA_debug_mode = 'Y' THEN
5151 pa_debug.g_err_stage:= 'Calling res defaults with l_da_resource_list_members_tab '||l_da_resource_list_members_tab.count;
5152 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5153 END IF;
5154
5155
5156 IF l_da_resource_list_members_tab.COUNT > 0 THEN
5157 PA_PLANNING_RESOURCE_UTILS.get_resource_defaults (
5158 P_resource_list_members => l_da_resource_list_members_tab,
5159 P_project_id => l_project_id,
5160 X_resource_class_flag => l_da_resource_class_flag_tab,
5161 X_resource_class_code => l_da_resource_class_code_tab,
5162 X_resource_class_id => l_da_resource_class_id_tab,
5163 X_res_type_code => l_da_res_type_code_tab,
5164 X_incur_by_res_type => l_da_incur_by_res_type_tab,
5165 X_person_id => l_da_person_id_tab,
5166 X_job_id => l_da_job_id_tab,
5167 X_person_type_code => l_da_person_type_code_tab,
5168 X_named_role => l_da_named_role_tab,
5169 X_bom_resource_id => l_da_bom_resource_id_tab,
5170 X_non_labor_resource => l_da_non_labor_resource_tab,
5171 X_inventory_item_id => l_da_inventory_item_id_tab,
5172 X_item_category_id => l_da_item_category_id_tab,
5173 X_project_role_id => l_da_project_role_id_tab,
5174 X_organization_id => l_da_organization_id_tab,
5175 X_fc_res_type_code => l_da_fc_res_type_code_tab,
5176 X_expenditure_type => l_da_expenditure_type_tab,
5177 X_expenditure_category => l_da_expenditure_category_tab,
5178 X_event_type => l_da_event_type_tab,
5179 X_revenue_category_code => l_da_revenue_category_code_tab,
5180 X_supplier_id => l_da_supplier_id_tab,
5181 X_spread_curve_id => l_da_spread_curve_id_tab,
5182 X_etc_method_code => l_da_etc_method_code_tab,
5183 X_mfc_cost_type_id => l_da_mfc_cost_type_id_tab,
5184 X_incurred_by_res_flag => l_da_incurred_by_res_flag_tab,
5185 X_incur_by_res_class_code => l_da_incur_by_res_cls_code_tab,
5186 X_incur_by_role_id => l_da_incur_by_role_id_tab,
5187 X_unit_of_measure => l_da_unit_of_measure_tab,
5188 X_org_id => l_da_org_id_tab,
5189 X_rate_based_flag => l_da_rate_based_flag_tab,
5190 X_rate_expenditure_type => l_da_rate_expenditure_type_tab,
5191 X_rate_func_curr_code => l_da_rate_func_curr_code_tab,
5192 X_msg_data => l_MSG_DATA,
5193 X_msg_count => l_MSG_COUNT,
5194 X_return_status => l_RETURN_STATUS);
5195
5196
5197 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5198 IF P_PA_debug_mode = 'Y' THEN
5199 pa_debug.g_err_stage:= 'Error in get_resource_defaults';
5200 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5201 END IF;
5202 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5203 END IF;
5204
5205 --The above API (resource defaults) returns resource attributes for the distinct resource list members passed.
5206 --The below loop will copy the resource attributes from the distinct resource list members into all the
5207 --resource assignments that have to be copied into the target. Bug 3678314.
5208 IF P_PA_debug_mode = 'Y' THEN
5209 pa_debug.g_err_stage:= 'Same RL About to copy the resource attributes for the distinct rlms into the tbls that will be used copying RAs into target';
5210 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5211 END IF;
5212
5213 FOR kk in 1 .. l_targ_ra_id_tbl.count LOOP
5214
5215 --The attributes returned by the get_resource_defaults should be considered only if
5216 --there is no one to one mapping between source and target (i.e l_src_ra_id_cnt_tbl(KK) is null)
5217 --and the resource assignment has to be inserted into target(i.e L_ra_dml_code_tbl(kk) = 'INSERT')
5218 --In other cases the attributes in the source will be copied into target.
5219 --Bug 3678314
5220 IF L_ra_dml_code_tbl(kk) = 'INSERT'
5221 AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN
5222
5223 l_temp:=1;
5224 FOR LL IN 1..l_da_resource_list_members_tab.COUNT LOOP
5225
5226 IF l_da_resource_list_members_tab(LL)=l_targ_rlm_id_tbl(kk) THEN
5227 l_temp:=LL;
5228 EXIT;
5229 END IF;
5230
5231 END LOOP;
5232
5233 --Raise an error if the resource list member in l_da_resource_list_members_tab does not
5234 --exist in l_targ_rlm_id_tbl (This should never happen). Bug 3678314.
5235 IF l_da_resource_list_members_tab(l_temp)<>l_targ_rlm_id_tbl(kk) THEN
5236
5237 IF P_PA_debug_mode = 'Y' THEN
5238 pa_debug.g_err_stage:= 'Match for l_targ_rlm_id_tbl('||kk||') '||l_targ_rlm_id_tbl(kk) ||' not found in l_da_resource_list_members_tab';
5239 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5240
5241 END IF;
5242 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5243
5244 END IF;
5245
5246 l_targ_RESOURCE_CLASS_FLAG_tbl(kk) := l_da_resource_class_flag_tab(l_temp) ;
5247 l_targ_RESOURCE_CLASS_CODE_tbl(kk) := l_da_resource_class_code_tab(l_temp) ;
5248 -- If incurred_by_res_flag is 'Y', incur_by_res_type should be used
5249 IF nvl(l_da_incurred_by_res_flag_tab(l_temp),'N') = 'Y' THEN
5250 l_targ_resource_type_code_tbl(kk) := l_da_incur_by_res_type_tab(l_temp) ;
5251 ELSE
5252 l_targ_resource_type_code_tbl(kk) := l_da_res_type_code_tab(l_temp) ;
5253 END IF;
5254 l_targ_person_id_tbl(kk) := l_da_person_id_tab(l_temp) ;
5255 l_targ_job_id_tbl(kk) := l_da_job_id_tab(l_temp) ;
5256 l_targ_person_type_code_tbl(kk) := l_da_person_type_code_tab(l_temp) ;
5257 l_targ_NAMED_ROLE_tbl(kk) := l_da_named_role_tab(l_temp) ;
5258 l_targ_bom_resource_id_tbl(kk) := l_da_bom_resource_id_tab(l_temp) ;
5259 l_targ_non_labor_resource_tbl(kk) := l_da_non_labor_resource_tab(l_temp) ;
5260 l_targ_inventory_item_id_tbl(kk) := l_da_inventory_item_id_tab(l_temp) ;
5261 l_targ_item_category_id_tbl(kk) := l_da_item_category_id_tab(l_temp) ;
5262 l_targ_project_role_id_tbl(kk) := l_da_project_role_id_tab(l_temp) ;
5263 l_targ_organization_id_tbl(kk) := l_da_organization_id_tab(l_temp) ;
5264 l_targ_fc_res_type_code_tbl(kk) := l_da_fc_res_type_code_tab(l_temp) ;
5265 l_targ_expenditure_type_tbl(kk) := l_da_expenditure_type_tab(l_temp) ;
5266 l_targ_expend_category_tbl(kk) := l_da_expenditure_category_tab(l_temp) ;
5267 l_targ_event_type_tbl(kk) := l_da_event_type_tab(l_temp) ;
5268 l_targ_rev_category_code_tbl(kk) := l_da_revenue_category_code_tab(l_temp) ;
5269 l_targ_supplier_id_tbl(kk) := l_da_supplier_id_tab(l_temp) ;
5270 l_targ_spread_curve_id_tbl(kk) := l_da_spread_curve_id_tab(l_temp) ;
5271 l_targ_etc_method_code_tbl(kk) := l_da_etc_method_code_tab(l_temp) ;
5272 l_targ_mfc_cost_type_id_tbl(kk) := l_da_mfc_cost_type_id_tab(l_temp) ;
5273 l_targ_INCURED_BY_RES_FLAG_tbl(kk) := l_da_incurred_by_res_flag_tab(l_temp) ;
5274 l_targ_INCR_BY_RES_CLS_COD_tbl(kk) := l_da_incur_by_res_cls_code_tab(l_temp) ;
5275 l_targ_INCUR_BY_ROLE_ID_tbl(kk) := l_da_incur_by_role_id_tab(l_temp) ;
5276 l_targ_RATE_EXPEND_TYPE_tbl(kk) := l_da_rate_expenditure_type_tab(l_temp) ;
5277 l_targ_RATE_EXP_FC_CUR_COD_tbl(kk) := l_da_rate_func_curr_code_tab(l_temp) ;
5278 l_targ_RATE_EXPEND_ORG_ID_tbl(kk) := l_da_org_id_tab(l_temp);
5279 l_targ_res_rate_based_flag_tbl(kk) := l_da_rate_based_flag_tab(l_temp); --IPM Architecture Enhancement. This flag will be the same through out as derived from the resource list
5280
5281 --For the resoruce assignments that should be inserted, the RBF flag and UOM derived from the source
5282 --planning transactions should be equal to the RBF and UOM returned by the get_resource_defaults API.
5283 --If they are not equal then RBF should be inserted as N in the target planning transaction and UOM
5284 --should be inserted as DOLLARS(i.e. Currency). Bug 3621847
5285 IF P_PA_debug_mode = 'Y' THEN
5286 pa_debug.g_err_stage:= 'About to derive the rbs and UOM for the target txn that should be inserted';
5287 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5288 END IF;
5289
5290 IF P_PA_debug_mode = 'Y' THEN
5291 pa_debug.g_err_stage:= 'l_targ_rate_based_flag_tbl('||kk||') '||l_targ_rate_based_flag_tbl(kk);
5292 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5293
5294 pa_debug.g_err_stage:= 'l_targ_unit_of_measure_tbl('||kk||') '||l_targ_unit_of_measure_tbl(kk);
5295 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5296
5297 END IF;
5298
5299 --If there is one to one mapping between source and target then UOM and RBF will be copied directly
5300 --from source. Otherwise, the UOM and RBF derived from source should be compared with the ones returned
5301 --by get_resource_defaults . If the source's UOM/RBF and default UOM/RBF are same then they will be
5302 --copied to target . Otherwise DOLLARS/N will be copied for UOM/RBF
5303
5304 IF P_PA_debug_mode = 'Y' THEN
5305 pa_debug.g_err_stage:= 'l_targ_rate_based_flag_tbl('||kk||') '||l_targ_rate_based_flag_tbl(kk);
5306 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5307
5308 pa_debug.g_err_stage:= 'l_targ_unit_of_measure_tbl('||kk||') '||l_targ_unit_of_measure_tbl(kk);
5309 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5310
5311 END IF;
5312
5313 IF l_targ_rate_based_flag_tbl(kk)=l_da_rate_based_flag_tab(l_temp) AND
5314 l_targ_unit_of_measure_tbl(kk)=l_da_unit_of_measure_tab(l_temp) THEN
5315
5316 NULL;--Do Nothing in this case
5317
5318 ELSE
5319
5320 l_targ_rate_based_flag_tbl(kk):='N';
5321 l_targ_unit_of_measure_tbl(kk):='DOLLARS';
5322
5323 END IF;
5324 IF P_PA_debug_mode = 'Y' THEN
5325 pa_debug.g_err_stage:= 'Al_targ_rate_based_flag_tbl('||kk||') '||l_targ_rate_based_flag_tbl(kk);
5326 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5327
5328 pa_debug.g_err_stage:= 'Al_targ_unit_of_measure_tbl('||kk||') '||l_targ_unit_of_measure_tbl(kk);
5329 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5330
5331 END IF;
5332
5333 END IF; --IF L_ra_dml_code_tbl(kk) = 'INSERT'
5334 --AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN
5335
5336 END LOOP;
5337
5338 --dbms_output.put_line('I14');
5339 IF P_PA_debug_mode = 'Y' THEN
5340 pa_debug.g_err_stage:= 'Done with the loop for preparing the pl/sql tbls for res attrs ';
5341 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5342 END IF;
5343
5344 l_rbs_element_id_prm_tbl.EXTEND(l_da_resource_list_members_tab.COUNT);
5345 l_txn_accum_header_id_prm_tbl.EXTEND(l_da_resource_list_members_tab.COUNT);
5346
5347 IF l_rbs_version_id IS NOT NULL THEN
5348 PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs
5349 (p_budget_version_id => l_src_ver_id_tbl(j)
5350 ,p_rbs_version_id => l_rbs_version_id
5351 ,p_calling_process => 'RBS_REFRESH'
5352 ,p_calling_context => 'PLSQL'
5353 ,p_process_code => 'RBS_MAP'
5354 ,p_calling_mode => 'PLSQL_TABLE'
5355 ,p_init_msg_list_flag => 'N'
5356 ,p_commit_flag => 'N'
5357 ,p_TXN_SOURCE_ID_tab => l_da_resource_list_members_tab
5358 ,p_TXN_SOURCE_TYPE_CODE_tab => l_txn_src_typ_code_rbs_prm_tbl
5359 ,p_PERSON_ID_tab => l_da_person_id_tab
5360 ,p_JOB_ID_tab => l_da_job_id_tab
5361 ,p_ORGANIZATION_ID_tab => l_da_organization_id_tab
5362 ,p_VENDOR_ID_tab => l_da_supplier_id_tab
5363 ,p_EXPENDITURE_TYPE_tab => l_da_expenditure_type_tab
5364 ,p_EVENT_TYPE_tab => l_da_event_type_tab
5365 ,p_NON_LABOR_RESOURCE_tab => l_da_non_labor_resource_tab
5366 ,p_EXPENDITURE_CATEGORY_tab => l_da_expenditure_category_tab
5367 ,p_REVENUE_CATEGORY_CODE_tab => l_da_revenue_category_code_tab
5368 -- ,p_NLR_ORGANIZATION_ID_tab =>
5369 -- ,p_EVENT_CLASSIFICATION_tab =>
5370 -- ,p_SYS_LINK_FUNCTION_tab =>
5371 ,p_PROJECT_ROLE_ID_tab => l_da_project_role_id_tab
5372 ,p_RESOURCE_CLASS_CODE_tab => l_da_resource_class_code_tab
5373 ,p_MFC_COST_TYPE_ID_tab => l_da_mfc_cost_type_id_tab
5374 ,p_RESOURCE_CLASS_FLAG_tab => l_da_resource_class_flag_tab
5375 ,p_FC_RES_TYPE_CODE_tab => l_da_fc_res_type_code_tab
5376 ,p_INVENTORY_ITEM_ID_tab => l_da_inventory_item_id_tab
5377 ,p_ITEM_CATEGORY_ID_tab => l_da_item_category_id_tab
5378 ,p_PERSON_TYPE_CODE_tab => l_da_person_type_code_tab
5379 ,p_BOM_RESOURCE_ID_tab => l_da_bom_resource_id_tab
5380 ,p_NAMED_ROLE_tab => l_da_named_role_tab
5381 ,p_INCURRED_BY_RES_FLAG_tab => l_da_incurred_by_res_flag_tab
5382 ,p_RATE_BASED_FLAG_tab => l_da_rate_based_flag_tab
5383 -- ,p_TXN_TASK_ID_tab =>
5384 -- ,p_TXN_WBS_ELEMENT_VER_ID_tab =>
5385 -- ,p_TXN_RBS_ELEMENT_ID_tab =>
5386 -- ,p_TXN_PLAN_START_DATE_tab =>
5387 -- ,p_TXN_PLAN_END_DATE_tab =>
5388 ,x_txn_source_id_tab => l_txn_source_id_tbl
5389 ,x_res_list_member_id_tab => l_res_list_member_id_tbl
5390 ,x_rbs_element_id_tab => l_rbs_element_id_prm_tbl
5391 ,x_txn_accum_header_id_tab => l_txn_accum_header_id_prm_tbl
5392 ,x_return_status => l_return_status
5393 ,x_msg_count => l_msg_count
5394 ,x_msg_data => l_msg_data);
5395
5396 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5397 IF P_PA_debug_mode = 'Y' THEN
5398 pa_debug.g_err_stage:= 'Error in get_resource_defaults';
5399 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5400 END IF;
5401 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5402 END IF;
5403
5404 IF P_PA_debug_mode = 'Y' THEN
5405 pa_debug.g_err_stage:= 'Returned from PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs for getting rbs elem id for new RAs';
5406 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5407
5408 pa_debug.g_err_stage:= 'l_rbs_element_id_prm_tbl.COUNT '||l_rbs_element_id_prm_tbl.COUNT ||' l_txn_accum_header_id_prm_tbl.COUNT '||l_txn_accum_header_id_prm_tbl.COUNT;
5409 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5410
5411 END IF;
5412
5413 -- The rbs element id and txn accum header id are returned for distinct resource list members. These attributes
5414 -- should be copied for all the target resoruce assignments also. Bug 3678314.
5415 FOR kk in 1 .. l_targ_ra_id_tbl.count LOOP
5416
5417 IF L_ra_dml_code_tbl(kk) = 'INSERT'
5418 AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN
5419
5420 l_temp:=1;
5421 FOR LL IN 1..l_da_resource_list_members_tab.COUNT LOOP
5422
5423 IF l_da_resource_list_members_tab(LL)=l_targ_rlm_id_tbl(kk) THEN
5424 l_temp:=LL;
5425 EXIT;
5426 END IF;
5427
5428 END LOOP;
5429
5430 --Raise an error if the resource list member in l_da_resource_list_members_tab does not
5431 --exist in l_targ_rlm_id_tbl (This should never happen).Bug 3678314.
5432 IF l_da_resource_list_members_tab(l_temp)<>l_targ_rlm_id_tbl(kk) THEN
5433
5434 IF P_PA_debug_mode = 'Y' THEN
5435 pa_debug.g_err_stage:= 'Match for l_targ_rlm_id_tbl('||kk||') '||l_targ_rlm_id_tbl(kk) ||' not found in l_da_resource_list_members_tab';
5436 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5437
5438 END IF;
5439 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5440
5441 END IF;
5442
5443 l_targ_txn_accum_header_id_tbl(kk) := l_txn_accum_header_id_prm_tbl(l_temp);
5444 l_targ_rbs_element_id_tbl(kk) := l_rbs_element_id_prm_tbl(l_temp);
5445
5446 END IF;--IF L_ra_dml_code_tbl(kk) = 'INSERT'
5447 --AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN
5448 END LOOP;
5449
5450 IF P_PA_debug_mode = 'Y' THEN
5451 pa_debug.g_err_stage:= 'Done with preparing tbls of indexed txn accum header and rbs elem ids';
5452 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5453 END IF;
5454
5455 END IF; --IF l_rbs_version_id IS NOT NULL THEN
5456
5457 -- for Start Bug 5291484
5458
5459 ELSIF lresource_list_members_tab_1.COUNT > 0 THEN
5460
5461 l_rbs_element_id_prm_tbl_1.EXTEND(lresource_list_members_tab_1.COUNT);
5462 ltxnaccumheader_id_prm_tbl_1.EXTEND(lresource_list_members_tab_1.COUNT);
5463
5464 IF l_rbs_version_id IS NOT NULL THEN
5465 PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs
5466 (p_budget_version_id => l_src_ver_id_tbl(j)
5467 ,p_rbs_version_id => l_rbs_version_id
5468 ,p_calling_process => 'RBS_REFRESH'
5469 ,p_calling_context => 'PLSQL'
5470 ,p_process_code => 'RBS_MAP'
5471 ,p_calling_mode => 'PLSQL_TABLE'
5472 ,p_init_msg_list_flag => 'N'
5473 ,p_commit_flag => 'N'
5474 ,p_TXN_SOURCE_ID_tab => lresource_list_members_tab_1
5475 ,p_TXN_SOURCE_TYPE_CODE_tab => ltxnsrctyp_code_rbs_prm_tbl_1
5476 ,p_PERSON_ID_tab => lperson_id_tab_1
5477 ,p_JOB_ID_tab => ljob_id_tab_1
5478 ,p_ORGANIZATION_ID_tab => lorganization_id_tab_1
5479 ,p_VENDOR_ID_tab => l_da_supplier_id_tab_1
5480 ,p_EXPENDITURE_TYPE_tab => lexpenditure_type_tab_1
5481 ,p_EVENT_TYPE_tab => l_da_event_type_tab_1
5482 ,p_NON_LABOR_RESOURCE_tab => lnon_labor_resource_tab_1
5483 ,p_EXPENDITURE_CATEGORY_tab => lexpenditure_category_tab_1
5484 ,p_REVENUE_CATEGORY_CODE_tab => lrevenue_category_code_tab_1
5485 ,p_PROJECT_ROLE_ID_tab => lproject_role_id_tab_1
5486 ,p_RESOURCE_CLASS_CODE_tab => lresource_class_code_tab_1
5487 ,p_MFC_COST_TYPE_ID_tab => l_da_mfc_cost_type_id_tab_1
5488 ,p_RESOURCE_CLASS_FLAG_tab => lresource_class_flag_tab_1
5489 ,p_FC_RES_TYPE_CODE_tab => lfc_res_type_code_tab_1
5490 ,p_INVENTORY_ITEM_ID_tab => linventory_item_id_tab_1
5491 ,p_ITEM_CATEGORY_ID_tab => litem_category_id_tab_1
5492 ,p_PERSON_TYPE_CODE_tab => lperson_type_code_tab_1
5493 ,p_BOM_RESOURCE_ID_tab => lbom_resource_id_tab_1
5494 ,p_NAMED_ROLE_tab => lnamed_role_tab_1
5495 ,p_INCURRED_BY_RES_FLAG_tab => lincurred_by_res_flag_tab_1
5496 ,p_RATE_BASED_FLAG_tab => l_da_rate_based_flag_tab_1
5497 ,x_txn_source_id_tab => l_txn_source_id_tbl_1
5498 ,x_res_list_member_id_tab => l_res_list_member_id_tbl_1
5499 ,x_rbs_element_id_tab => l_rbs_element_id_prm_tbl_1
5500 ,x_txn_accum_header_id_tab => ltxnaccumheader_id_prm_tbl_1
5501 ,x_return_status => l_return_status
5502 ,x_msg_count => l_msg_count
5503 ,x_msg_data => l_msg_data);
5504
5505 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5506 IF P_PA_debug_mode = 'Y' THEN
5507 pa_debug.g_err_stage:= 'Error in Map_Rlmi_Rbs';
5508 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5509 END IF;
5510 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5511 END IF;
5512
5513 FOR kk in 1 .. l_targ_ra_id_tbl.count LOOP
5514
5515 IF L_ra_dml_code_tbl(kk) = 'INSERT'
5516 AND l_src_ra_id_cnt_tbl(KK) IS NOT NULL THEN
5517 l_temp:=1;
5518 FOR LL IN 1..lresource_list_members_tab_1.COUNT LOOP
5519
5520 IF lresource_list_members_tab_1(LL)=l_targ_rlm_id_tbl(kk) THEN
5521 l_temp:=LL;
5522 EXIT;
5523 END IF;
5524
5525 END LOOP;
5526
5527 --Raise an error if the resource list member in l_da_resource_list_members_tab does not
5528 --exist in l_targ_rlm_id_tbl (This should never happen).Bug 3678314.
5529 IF lresource_list_members_tab_1(l_temp)<>l_targ_rlm_id_tbl(kk) THEN
5530 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5531 END IF;
5532 l_targ_txn_accum_header_id_tbl(kk) := ltxnaccumheader_id_prm_tbl_1(l_temp);
5533 l_targ_rbs_element_id_tbl(kk) := l_rbs_element_id_prm_tbl_1(l_temp);
5534
5535 END IF;
5536 END LOOP;
5537 END IF;
5538
5539 -- for End Bug 5291484
5540
5541
5542 END IF;--IF l_da_resource_list_members_tab.COUNT > 0
5543
5544
5545 ELSE --Resource lists are different
5546
5547 --dbms_output.put_line('I15');
5548
5549 IF P_PA_debug_mode = 'Y' THEN
5550 pa_debug.g_err_stage:= 'About to prepare input table for get resource defaults API';
5551 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5552 END IF;
5553 l_da_resource_list_members_tab:=SYSTEM.PA_NUM_TBL_TYPE();
5554 l_txn_src_typ_code_rbs_prm_tbl :=SYSTEM.pa_varchar2_30_tbl_type();
5555
5556 FOR kk in 1 .. L_targ_rlm_id_tbl.count LOOP
5557
5558 --Find the distinct rlms among the resoruce assignments that have to be inserted .
5559 --This is done to call get_resource_defaults only for distinct rlms. Bug 3859738
5560 IF L_ra_dml_code_tbl(kk) = 'INSERT' THEN
5561
5562 l_temp:= NULL;
5563 FOR LL IN 1..l_da_resource_list_members_tab.COUNT LOOP
5564 IF l_da_resource_list_members_tab(LL)= L_targ_rlm_id_tbl(kk) THEN
5565 l_temp:=LL;
5566 EXIT;
5567 END IF;
5568 END LOOP;
5569
5570 IF l_temp IS NULL THEN
5571 --Indicates that the resource list member is not already selected and hence it has to be
5572 --considered while calling get_resource_defaults.Bug 3859738
5573
5574 l_da_resource_list_members_tab.extend;
5575 l_da_resource_list_members_tab(l_da_resource_list_members_tab.COUNT) := L_targ_rlm_id_tbl(kk);
5576 l_txn_src_typ_code_rbs_prm_tbl.EXTEND;
5577 l_txn_src_typ_code_rbs_prm_tbl(l_txn_src_typ_code_rbs_prm_tbl.COUNT):='RES_ASSIGNMENT';
5578
5579 END IF;
5580 END IF;
5581 END LOOP;
5582
5583 IF l_da_resource_list_members_tab.COUNT > 0 THEN
5584 PA_PLANNING_RESOURCE_UTILS.get_resource_defaults (
5585 P_resource_list_members => l_da_resource_list_members_tab,
5586 P_project_id => l_project_id,
5587 X_resource_class_flag => l_da_resource_class_flag_tab,
5588 X_resource_class_code => l_da_resource_class_code_tab,
5589 X_resource_class_id => l_da_resource_class_id_tab,
5590 X_res_type_code => l_da_res_type_code_tab,
5591 X_incur_by_res_type => l_da_incur_by_res_type_tab,
5592 X_person_id => l_da_person_id_tab,
5593 X_job_id => l_da_job_id_tab,
5594 X_person_type_code => l_da_person_type_code_tab,
5595 X_named_role => l_da_named_role_tab,
5596 X_bom_resource_id => l_da_bom_resource_id_tab,
5597 X_non_labor_resource => l_da_non_labor_resource_tab,
5598 X_inventory_item_id => l_da_inventory_item_id_tab,
5599 X_item_category_id => l_da_item_category_id_tab,
5600 X_project_role_id => l_da_project_role_id_tab,
5601 X_organization_id => l_da_organization_id_tab,
5602 X_fc_res_type_code => l_da_fc_res_type_code_tab,
5603 X_expenditure_type => l_da_expenditure_type_tab,
5604 X_expenditure_category => l_da_expenditure_category_tab,
5605 X_event_type => l_da_event_type_tab,
5606 X_revenue_category_code => l_da_revenue_category_code_tab,
5607 X_supplier_id => l_da_supplier_id_tab,
5608 X_spread_curve_id => l_da_spread_curve_id_tab,
5609 X_etc_method_code => l_da_etc_method_code_tab,
5610 X_mfc_cost_type_id => l_da_mfc_cost_type_id_tab,
5611 X_incurred_by_res_flag => l_da_incurred_by_res_flag_tab,
5612 X_incur_by_res_class_code => l_da_incur_by_res_cls_code_tab,
5613 X_incur_by_role_id => l_da_incur_by_role_id_tab,
5614 X_unit_of_measure => l_da_unit_of_measure_tab,
5615 X_org_id => l_da_org_id_tab,
5616 X_rate_based_flag => l_da_rate_based_flag_tab,
5617 X_rate_expenditure_type => l_da_rate_expenditure_type_tab,
5618 X_rate_func_curr_code => l_da_rate_func_curr_code_tab,
5619 X_msg_data => l_MSG_DATA,
5620 X_msg_count => l_MSG_COUNT,
5621 X_return_status => l_RETURN_STATUS);
5622
5623
5624 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5625 IF P_PA_debug_mode = 'Y' THEN
5626 pa_debug.g_err_stage:= 'Error in get_resource_defaults';
5627 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5628 END IF;
5629 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5630 END IF;
5631
5632
5633 --The above API (resource defaults) returns resource attributes for the distinct resource list members passed.
5634 --The below loop will copy the resource attributes from the distinct resource list members into all the
5635 --resource assignments that have to be copied into the target. Bug 3678314.
5636 IF P_PA_debug_mode = 'Y' THEN
5637 pa_debug.g_err_stage:= 'Diff RL About to copy the resource attributes for the distinct rlms into the tbls that will be used copying RAs into target';
5638 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5639 END IF;
5640
5641 FOR kk in 1 .. l_targ_ra_id_tbl.count LOOP
5642
5643 --The attributes returned by the get_resource_defaults should be considered only if
5644 --the resource assignment has to be inserted into target(i.e L_ra_dml_code_tbl(kk) = 'INSERT')
5645 --If there is one-one mapping then the attributes in the source can not be used since
5646 --the resource lists are different.
5647 --If the resource assignment is already available then the attributes of the resource assignment
5648 --will not change because of merge.
5649 --Bug 3678314
5650 IF l_ra_dml_code_tbl(kk)='INSERT' THEN
5651 l_temp:=1;
5652 FOR LL IN 1..l_da_resource_list_members_tab.COUNT LOOP
5653
5654 IF l_da_resource_list_members_tab(LL)=l_targ_rlm_id_tbl(kk) THEN
5655 l_temp:=LL;
5656 EXIT;
5657 END IF;
5658
5659 END LOOP;
5660
5661 --Raise an error if the resource list member in l_da_resource_list_members_tab does not
5662 --exist in l_targ_rlm_id_tbl (This should never happen). Bug 3678314.
5663 IF l_da_resource_list_members_tab(l_temp)<>l_targ_rlm_id_tbl(kk) THEN
5664
5665 IF P_PA_debug_mode = 'Y' THEN
5666 pa_debug.g_err_stage:= 'Match for l_targ_rlm_id_tbl('||kk||') '||l_targ_rlm_id_tbl(kk) ||' not found in l_da_resource_list_members_tab';
5667 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5668
5669 END IF;
5670 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5671
5672 END IF;
5673
5674 l_targ_RESOURCE_CLASS_FLAG_tbl(kk) := l_da_resource_class_flag_tab(l_temp) ;
5675 l_targ_RESOURCE_CLASS_CODE_tbl(kk) := l_da_resource_class_code_tab(l_temp) ;
5676 -- If incurred_by_res_flag is 'Y', incur_by_res_type should be used
5677 IF nvl(l_da_incurred_by_res_flag_tab(l_temp),'N') = 'Y' THEN
5678 l_targ_resource_type_code_tbl(kk) := l_da_incur_by_res_type_tab(l_temp) ;
5679 ELSE
5680 l_targ_resource_type_code_tbl(kk) := l_da_res_type_code_tab(l_temp) ;
5681 END IF;
5682 l_targ_person_id_tbl(kk) := l_da_person_id_tab(l_temp) ;
5683 l_targ_job_id_tbl(kk) := l_da_job_id_tab(l_temp) ;
5684 l_targ_person_type_code_tbl(kk) := l_da_person_type_code_tab(l_temp) ;
5685 l_targ_NAMED_ROLE_tbl(kk) := l_da_named_role_tab(l_temp) ;
5686 l_targ_bom_resource_id_tbl(kk) := l_da_bom_resource_id_tab(l_temp) ;
5687 l_targ_non_labor_resource_tbl(kk) := l_da_non_labor_resource_tab(l_temp) ;
5688 l_targ_inventory_item_id_tbl(kk) := l_da_inventory_item_id_tab(l_temp) ;
5689 l_targ_item_category_id_tbl(kk) := l_da_item_category_id_tab(l_temp) ;
5690 l_targ_project_role_id_tbl(kk) := l_da_project_role_id_tab(l_temp) ;
5691 l_targ_organization_id_tbl(kk) := l_da_organization_id_tab(l_temp) ;
5692 l_targ_fc_res_type_code_tbl(kk) := l_da_fc_res_type_code_tab(l_temp) ;
5693 l_targ_expenditure_type_tbl(kk) := l_da_expenditure_type_tab(l_temp) ;
5694 l_targ_expend_category_tbl(kk) := l_da_expenditure_category_tab(l_temp) ;
5695 l_targ_event_type_tbl(kk) := l_da_event_type_tab(l_temp) ;
5696 l_targ_rev_category_code_tbl(kk) := l_da_revenue_category_code_tab(l_temp) ;
5697 l_targ_supplier_id_tbl(kk) := l_da_supplier_id_tab(l_temp) ;
5698 l_targ_spread_curve_id_tbl(kk) := l_da_spread_curve_id_tab(l_temp) ;
5699 l_targ_etc_method_code_tbl(kk) := l_da_etc_method_code_tab(l_temp) ;
5700 l_targ_mfc_cost_type_id_tbl(kk) := l_da_mfc_cost_type_id_tab(l_temp) ;
5701 l_targ_INCURED_BY_RES_FLAG_tbl(kk) := l_da_incurred_by_res_flag_tab(l_temp) ;
5702
5703 l_targ_INCR_BY_RES_CLS_COD_tbl(kk) := l_da_incur_by_res_cls_code_tab(l_temp) ;
5704 l_targ_INCUR_BY_ROLE_ID_tbl(kk) := l_da_incur_by_role_id_tab(l_temp) ;
5705 l_targ_RATE_EXPEND_TYPE_tbl(kk) := l_da_rate_expenditure_type_tab(l_temp) ;
5706 l_targ_RATE_EXP_FC_CUR_COD_tbl(kk) := l_da_rate_func_curr_code_tab(l_temp) ;
5707 l_targ_RATE_EXPEND_ORG_ID_tbl(kk) := l_da_org_id_tab(l_temp);
5708 l_targ_RES_RATE_BASED_FLAG_tbl(kk) := l_targ_rate_based_flag_tbl(l_temp) ; --IPM
5709
5710 --For the resoruce assignments that should be inserted, the RBF flag and UOM derived from the source
5711 --planning transactions should be equal to the RBF and UOM returned by the get_resource_defaults API.
5712 --If they are not equal then RBF should be inserted as N in the target planning transaction and UOM
5713 --should be inserted as DOLLARS(i.e. Currency). Bug 3678314
5714 IF P_PA_debug_mode = 'Y' THEN
5715 pa_debug.g_err_stage:= 'About to derive the rbs and UOM for the target txn that should be inserted';
5716 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5717 END IF;
5718
5719 IF P_PA_debug_mode = 'Y' THEN
5720 pa_debug.g_err_stage:= 'l_targ_rate_based_flag_tbl('||kk||') '||l_targ_rate_based_flag_tbl(kk);
5721 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5722
5723 pa_debug.g_err_stage:= 'l_targ_unit_of_measure_tbl('||kk||') '||l_targ_unit_of_measure_tbl(kk);
5724 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5725
5726 END IF;
5727
5728
5729 --If the RBF/UOM derived through resource list mapping are not same as RBF/UOM returned by get_resource_defaults
5730 --then RBF/UOM should be changed to DOLLARS/N. Bug 3678314
5731 IF P_PA_debug_mode = 'Y' THEN
5732 pa_debug.g_err_stage:= 'l_targ_rate_based_flag_tbl('||kk||') '||l_targ_rate_based_flag_tbl(kk);
5733 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5734
5735 pa_debug.g_err_stage:= 'l_targ_unit_of_measure_tbl('||kk||') '||l_targ_unit_of_measure_tbl(kk);
5736 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5737
5738 END IF;
5739
5740 IF l_targ_rate_based_flag_tbl(kk)=l_da_rate_based_flag_tab(l_temp) AND
5741 l_targ_unit_of_measure_tbl(kk)=l_da_unit_of_measure_tab(l_temp) THEN
5742
5743 NULL;--Do Nothing in this case
5744
5745 ELSE
5746
5747 l_targ_rate_based_flag_tbl(kk):='N';
5748 l_targ_unit_of_measure_tbl(kk):='DOLLARS';
5749
5750 END IF;
5751 IF P_PA_debug_mode = 'Y' THEN
5752 pa_debug.g_err_stage:= 'Al_targ_rate_based_flag_tbl('||kk||') '||l_targ_rate_based_flag_tbl(kk);
5753 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5754
5755 pa_debug.g_err_stage:= 'Al_targ_unit_of_measure_tbl('||kk||') '||l_targ_unit_of_measure_tbl(kk);
5756 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5757
5758 END IF;
5759
5760 END IF;-- IF l_ra_dml_code_tbl(kk)='INSERT' THEN
5761
5762 END LOOP;
5763
5764 l_rbs_element_id_prm_tbl:=SYSTEM.pa_num_tbl_type();
5765 l_txn_accum_header_id_prm_tbl:=SYSTEM.pa_num_tbl_type();
5766 l_rbs_element_id_prm_tbl.EXTEND(l_da_resource_list_members_tab.COUNT);
5767 l_txn_accum_header_id_prm_tbl.EXTEND(l_da_resource_list_members_tab.COUNT);
5768 IF l_rbs_version_id IS NOT NULL THEN
5769
5770 IF P_PA_debug_mode = 'Y' THEN
5771 pa_debug.g_err_stage:= 'About to call PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs when RLS are different for RBS REF';
5772 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5773 END IF;
5774
5775
5776 PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs
5777 (p_budget_version_id => l_src_ver_id_tbl(j)
5778 ,p_rbs_version_id => l_rbs_version_id
5779 ,p_calling_process => 'RBS_REFRESH'
5780 ,p_calling_context => 'PLSQL'
5781 ,p_process_code => 'RBS_MAP'
5782 ,p_calling_mode => 'PLSQL_TABLE'
5783 ,p_init_msg_list_flag => 'N'
5784 ,p_commit_flag => 'N'
5785 ,p_TXN_SOURCE_ID_tab => l_da_resource_list_members_tab
5786 ,p_TXN_SOURCE_TYPE_CODE_tab => l_txn_src_typ_code_rbs_prm_tbl
5787 ,p_PERSON_ID_tab => l_da_person_id_tab
5788 ,p_JOB_ID_tab => l_da_job_id_tab
5789 ,p_ORGANIZATION_ID_tab => l_da_organization_id_tab
5790 ,p_VENDOR_ID_tab => l_da_supplier_id_tab
5791 ,p_EXPENDITURE_TYPE_tab => l_da_expenditure_type_tab
5792 ,p_EVENT_TYPE_tab => l_da_event_type_tab
5793 ,p_NON_LABOR_RESOURCE_tab => l_da_non_labor_resource_tab
5794 ,p_EXPENDITURE_CATEGORY_tab => l_da_expenditure_category_tab
5795 ,p_REVENUE_CATEGORY_CODE_tab => l_da_revenue_category_code_tab
5796 -- ,p_NLR_ORGANIZATION_ID_tab =>
5797 -- ,p_EVENT_CLASSIFICATION_tab =>
5798 -- ,p_SYS_LINK_FUNCTION_tab =>
5799 ,p_PROJECT_ROLE_ID_tab => l_da_project_role_id_tab
5800 ,p_RESOURCE_CLASS_CODE_tab => l_da_resource_class_code_tab
5801 ,p_MFC_COST_TYPE_ID_tab => l_da_mfc_cost_type_id_tab
5802 ,p_RESOURCE_CLASS_FLAG_tab => l_da_resource_class_flag_tab
5803 ,p_FC_RES_TYPE_CODE_tab => l_da_fc_res_type_code_tab
5804 ,p_INVENTORY_ITEM_ID_tab => l_da_inventory_item_id_tab
5805 ,p_ITEM_CATEGORY_ID_tab => l_da_item_category_id_tab
5806 ,p_PERSON_TYPE_CODE_tab => l_da_person_type_code_tab
5807 ,p_BOM_RESOURCE_ID_tab => l_da_bom_resource_id_tab
5808 ,p_NAMED_ROLE_tab => l_da_named_role_tab
5809 ,p_INCURRED_BY_RES_FLAG_tab => l_da_incurred_by_res_flag_tab
5810 ,p_RATE_BASED_FLAG_tab => l_da_rate_based_flag_tab
5811 -- ,p_TXN_TASK_ID_tab =>
5812 -- ,p_TXN_WBS_ELEMENT_VER_ID_tab =>
5813 -- ,p_TXN_RBS_ELEMENT_ID_tab =>
5814 -- ,p_TXN_PLAN_START_DATE_tab =>
5815 -- ,p_TXN_PLAN_END_DATE_tab =>
5816 ,x_txn_source_id_tab => l_txn_source_id_tbl
5817 ,x_res_list_member_id_tab => l_res_list_member_id_tbl
5818 ,x_rbs_element_id_tab => l_rbs_element_id_prm_tbl
5819 ,x_txn_accum_header_id_tab => l_txn_accum_header_id_prm_tbl
5820 ,x_return_status => l_return_status
5821 ,x_msg_count => l_msg_count
5822 ,x_msg_data => l_msg_data);
5823
5824 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5825 IF P_PA_debug_mode = 'Y' THEN
5826 pa_debug.g_err_stage:= 'Error in get_resource_defaults ';
5827 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5828 END IF;
5829 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5830 END IF;
5831
5832 IF P_PA_debug_mode = 'Y' THEN
5833 pa_debug.g_err_stage:= 'Preparing TXN Accum Header Id and RBS Elem Id tbls';
5834 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5835
5836 pa_debug.g_err_stage:= 'l_txn_accum_header_id_prm_tbl.count is '||l_txn_accum_header_id_prm_tbl.count ||' l_rbs_element_id_prm_tbl.count is '||l_rbs_element_id_prm_tbl.count;
5837 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5838
5839 END IF;
5840
5841
5842 -- The rbs element id and txn accum header id are returned for distinct resource list members. These attributes
5843 -- should be copied for all the target resoruce assignments also. Bug 3678314.
5844 FOR kk in 1 .. l_targ_ra_id_tbl.count LOOP
5845
5846 IF l_ra_dml_code_tbl(kk)='INSERT' THEN
5847
5848 l_temp:=1;
5849 FOR LL IN 1..l_da_resource_list_members_tab.COUNT LOOP
5850
5851 IF l_da_resource_list_members_tab(LL)=l_targ_rlm_id_tbl(kk) THEN
5852 l_temp:=LL;
5853 EXIT;
5854 END IF;
5855
5856 END LOOP;
5857
5858 --Raise an error if the resource list member in l_da_resource_list_members_tab does not
5859 --exist in l_targ_rlm_id_tbl (This should never happen).Bug 3678314.
5860 IF l_da_resource_list_members_tab(l_temp)<>l_targ_rlm_id_tbl(kk) THEN
5861
5862 IF P_PA_debug_mode = 'Y' THEN
5863 pa_debug.g_err_stage:= 'Match for l_targ_rlm_id_tbl('||kk||') '||l_targ_rlm_id_tbl(kk) ||' not found in l_da_resource_list_members_tab';
5864 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
5865
5866 END IF;
5867 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5868
5869 END IF;
5870
5871 l_targ_txn_accum_header_id_tbl(kk) := l_txn_accum_header_id_prm_tbl(l_temp);
5872 l_targ_rbs_element_id_tbl(kk) := l_rbs_element_id_prm_tbl(l_temp);
5873
5874 END IF;-- IF l_ra_dml_code_tbl(kk)='INSERT' THEN
5875
5876 END LOOP;
5877
5878 END IF;--IF l_rbs_version_id IS NOT NULL THEN
5879
5880 END IF; -- IF l_da_resource_list_members_tab.COUNT > 0
5881
5882 END IF; --IF l_src_resource_list_id = l_targ_resource_list_id
5883
5884 --dbms_output.put_line('I16');
5885
5886 --dbms_output.put_line('I17');
5887
5888
5889 IF P_PA_debug_mode = 'Y' THEN
5890 pa_debug.g_err_stage:= 'About to bulk insert into PRA';
5891 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5892
5893 IF l_targ_rlm_id_tbl.COUNT>1 THEN
5894 pa_debug.g_err_stage:= 'l_targ_rlm_id_tbl(1) is '||l_targ_rlm_id_tbl(1)||' l_targ_rlm_id_tbl(2) is '||l_targ_rlm_id_tbl(2);
5895 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5896
5897 pa_debug.g_err_stage:= 'L_targ_ra_id_tbl(1) is '||L_targ_ra_id_tbl(1)||' L_targ_ra_id_tbl(2) is '||L_targ_ra_id_tbl(2);
5898 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5899
5900 pa_debug.g_err_stage:= 'L_targ_task_id_tbl(1) is '||L_targ_task_id_tbl(1)||' L_targ_task_id_tbl(2) is '||L_targ_task_id_tbl(2);
5901 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5902
5903 pa_debug.g_err_stage:= 'l_src_ra_id_cnt_tbl(1) is '||l_src_ra_id_cnt_tbl(1)||' l_src_ra_id_cnt_tbl(2) is '||l_src_ra_id_cnt_tbl(2);
5904 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5905
5906 pa_debug.g_err_stage:= 'l_src_resource_list_id is '||l_src_resource_list_id||' l_targ_resource_list_id is '||l_targ_resource_list_id;
5907 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5908
5909 pa_debug.g_err_stage:= 'L_ra_dml_code_tbl(1) is '||L_ra_dml_code_tbl(1)||' L_ra_dml_code_tbl(2) is '||L_ra_dml_code_tbl(2);
5910 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5911
5912 pa_debug.g_err_stage:= 'l_targ_txn_accum_header_id_tbl(1) is '||l_targ_txn_accum_header_id_tbl(1)||' l_targ_txn_accum_header_id_tbl(2) is '||l_targ_txn_accum_header_id_tbl(2);
5913 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5914
5915 pa_debug.g_err_stage:= 'l_targ_rbs_element_id_tbl(1) is '||l_targ_rbs_element_id_tbl(1)||' l_targ_rbs_element_id_tbl(2) is '||l_targ_rbs_element_id_tbl(2);
5916 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
5917
5918
5919 END IF;
5920
5921 END IF;
5922
5923 --dbms_output.put_line('I18');
5924 -- Bug 3934574 The following business rules are incorporated in the insert
5925 -- 1) If p_calling_context is null, insert transaction source code as null
5926 -- 2) If p_calling_context is generation insert transaction source code as 'CHANGE DOCUMENTS'
5927
5928 FORALL kk in L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
5929 INSERT INTO PA_RESOURCE_ASSIGNMENTS (
5930 RESOURCE_ASSIGNMENT_ID,BUDGET_VERSION_ID,PROJECT_ID,TASK_ID,RESOURCE_LIST_MEMBER_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY
5931 ,LAST_UPDATE_LOGIN,UNIT_OF_MEASURE,TRACK_AS_LABOR_FLAG,STANDARD_BILL_RATE,AVERAGE_BILL_RATE,AVERAGE_COST_RATE
5932 ,PROJECT_ASSIGNMENT_ID,PLAN_ERROR_CODE,TOTAL_PLAN_REVENUE,TOTAL_PLAN_RAW_COST,TOTAL_PLAN_BURDENED_COST,TOTAL_PLAN_QUANTITY
5933 ,AVERAGE_DISCOUNT_PERCENTAGE,TOTAL_BORROWED_REVENUE,TOTAL_TP_REVENUE_IN,TOTAL_TP_REVENUE_OUT,TOTAL_REVENUE_ADJ
5934 ,TOTAL_LENT_RESOURCE_COST,TOTAL_TP_COST_IN,TOTAL_TP_COST_OUT,TOTAL_COST_ADJ,TOTAL_UNASSIGNED_TIME_COST
5935 ,TOTAL_UTILIZATION_PERCENT,TOTAL_UTILIZATION_HOURS,TOTAL_UTILIZATION_ADJ,TOTAL_CAPACITY,TOTAL_HEAD_COUNT
5936 ,TOTAL_HEAD_COUNT_ADJ,RESOURCE_ASSIGNMENT_TYPE,TOTAL_PROJECT_RAW_COST,TOTAL_PROJECT_BURDENED_COST,TOTAL_PROJECT_REVENUE
5937 ,PARENT_ASSIGNMENT_ID,WBS_ELEMENT_VERSION_ID,RBS_ELEMENT_ID,PLANNING_START_DATE,PLANNING_END_DATE
5938 ,SPREAD_CURVE_ID,ETC_METHOD_CODE,RES_TYPE_CODE,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5
5939 ,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15
5940 ,ATTRIBUTE16,ATTRIBUTE17,ATTRIBUTE18,ATTRIBUTE19,ATTRIBUTE20,ATTRIBUTE21,ATTRIBUTE22,ATTRIBUTE23,ATTRIBUTE24,ATTRIBUTE25
5941 ,ATTRIBUTE26,ATTRIBUTE27,ATTRIBUTE28,ATTRIBUTE29,ATTRIBUTE30,FC_RES_TYPE_CODE,RESOURCE_CLASS_CODE,ORGANIZATION_ID,JOB_ID
5942 ,PERSON_ID,EXPENDITURE_TYPE,EXPENDITURE_CATEGORY,REVENUE_CATEGORY_CODE,EVENT_TYPE,SUPPLIER_ID,NON_LABOR_RESOURCE
5943 ,BOM_RESOURCE_ID,INVENTORY_ITEM_ID,ITEM_CATEGORY_ID,RECORD_VERSION_NUMBER,BILLABLE_PERCENT
5944 ,TRANSACTION_SOURCE_CODE,MFC_COST_TYPE_ID,PROCURE_RESOURCE_FLAG,ASSIGNMENT_DESCRIPTION
5945 ,INCURRED_BY_RES_FLAG,RATE_JOB_ID,RATE_EXPENDITURE_TYPE,TA_DISPLAY_FLAG
5946 ,SP_FIXED_DATE,PERSON_TYPE_CODE,RATE_BASED_FLAG,RESOURCE_RATE_BASED_FLAG --IPM Arch Enhancement
5947 ,USE_TASK_SCHEDULE_FLAG,RATE_EXP_FUNC_CURR_CODE
5948 ,RATE_EXPENDITURE_ORG_ID,INCUR_BY_RES_CLASS_CODE,INCUR_BY_ROLE_ID
5949 ,PROJECT_ROLE_ID,RESOURCE_CLASS_FLAG,NAMED_ROLE,TXN_ACCUM_HEADER_ID)
5950 SELECT L_targ_ra_id_tbl(kk) -- RESOURCE_ASSIGNMENT_ID
5951 ,p_budget_version_id -- BUDGET_VERSION_ID
5952 ,l_project_id -- PROJECT_ID
5953 ,L_targ_task_id_tbl(kk) -- TASK_ID
5954 ,L_targ_rlm_id_tbl(kk) -- RESOURCE_LIST_MEMBER_ID
5955 ,sysdate -- LAST_UPDATE_DATE
5956 ,fnd_global.user_id -- LAST_UPDATED_BY
5957 ,sysdate -- CREATION_DATE
5958 ,fnd_global.user_id -- CREATED_BY
5959 ,fnd_global.login_id -- LAST_UPDATE_LOGIN
5960 ,l_targ_unit_of_measure_tbl(kk) -- UNIT_OF_MEASURE
5961 ,NULL -- TRACK_AS_LABOR_FLAG
5962 ,NULL -- STANDARD_BILL_RATE
5963 ,NULL -- AVERAGE_BILL_RATE
5964 ,NULL -- AVERAGE_COST_RATE
5965 ,-1 -- PROJECT_ASSIGNMENT_ID
5966 ,NULL -- PLAN_ERROR_CODE
5967 ,NULL -- TOTAL_PLAN_REVENUE
5968 ,NULL -- TOTAL_PLAN_RAW_COST
5969 ,NULL -- TOTAL_PLAN_BURDENED_COST
5970 ,NULL -- TOTAL_PLAN_QUANTITY
5971 ,NULL -- AVERAGE_DISCOUNT_PERCENTAGE
5972 ,NULL -- TOTAL_BORROWED_REVENUE
5973 ,NULL -- TOTAL_TP_REVENUE_IN
5974 ,NULL -- TOTAL_TP_REVENUE_OUT
5975 ,NULL -- TOTAL_REVENUE_ADJ
5976 ,NULL -- TOTAL_LENT_RESOURCE_COST
5977 ,NULL -- TOTAL_TP_COST_IN
5978 ,NULL -- TOTAL_TP_COST_OUT
5979 ,NULL -- TOTAL_COST_ADJ
5980 ,NULL -- TOTAL_UNASSIGNED_TIME_COST
5981 ,NULL -- TOTAL_UTILIZATION_PERCENT
5982 ,NULL -- TOTAL_UTILIZATION_HOURS
5983 ,NULL -- TOTAL_UTILIZATION_ADJ
5984 ,NULL -- TOTAL_CAPACITY
5985 ,NULL -- TOTAL_HEAD_COUNT
5986 ,NULL -- TOTAL_HEAD_COUNT_ADJ
5987 ,'USER_ENTERED' -- RESOURCE_ASSIGNMENT_TYPE
5988 ,NULL -- TOTAL_PROJECT_RAW_COST
5989 ,NULL -- TOTAL_PROJECT_BURDENED_COST
5990 ,NULL -- TOTAL_PROJECT_REVENUE
5991 ,NULL -- PARENT_ASSIGNMENT_ID
5992 ,NULL -- WBS_ELEMENT_VERSION_ID
5993 ,l_targ_rbs_element_id_tbl(kk) -- RBS_ELEMENT_ID
5994 ,l_planning_start_date_tbl(kk) -- PLANNING_START_DATE
5995 ,l_planning_end_date_tbl(kk) -- PLANNING_END_DATE
5996 ,l_targ_spread_curve_id_tbl(kk) -- SPREAD_CURVE_ID
5997 ,l_targ_etc_method_code_tbl(kk) -- ETC_METHOD_CODE
5998 ,l_targ_resource_type_code_tbl(kk) -- RES_TYPE_CODE
5999 ,NULL -- ATTRIBUTE_CATEGORY
6000 ,NULL -- ATTRIBUTE1
6001 ,NULL -- ATTRIBUTE2
6002 ,NULL -- ATTRIBUTE3
6003 ,NULL -- ATTRIBUTE4
6004 ,NULL -- ATTRIBUTE5
6005 ,NULL -- ATTRIBUTE6
6006 ,NULL -- ATTRIBUTE7
6007 ,NULL -- ATTRIBUTE8
6008 ,NULL -- ATTRIBUTE9
6009 ,NULL -- ATTRIBUTE10
6010 ,NULL -- ATTRIBUTE11
6011 ,NULL -- ATTRIBUTE12
6012 ,NULL -- ATTRIBUTE13
6013 ,NULL -- ATTRIBUTE14
6014 ,NULL -- ATTRIBUTE15
6015 ,NULL -- ATTRIBUTE16
6016 ,NULL -- ATTRIBUTE17
6017 ,NULL -- ATTRIBUTE18
6018 ,NULL -- ATTRIBUTE19
6019 ,NULL -- ATTRIBUTE20
6020 ,NULL -- ATTRIBUTE21
6021 ,NULL -- ATTRIBUTE22
6022 ,NULL -- ATTRIBUTE23
6023 ,NULL -- ATTRIBUTE24
6024 ,NULL -- ATTRIBUTE25
6025 ,NULL -- ATTRIBUTE26
6026 ,NULL -- ATTRIBUTE27
6027 ,NULL -- ATTRIBUTE28
6028 ,NULL -- ATTRIBUTE29
6029 ,NULL -- ATTRIBUTE30
6030 ,l_targ_fc_res_type_code_tbl(kk) -- FC_RES_TYPE_CODE
6031 ,l_targ_resource_class_code_tbl(kk) -- RESOURCE_CLASS_CODE
6032 ,l_targ_organization_id_tbl(kk) -- ORGANIZATION_ID
6033 ,l_targ_job_id_tbl(kk) -- JOB_ID
6034 ,l_targ_person_id_tbl(kk) -- PERSON_ID
6035 ,l_targ_expenditure_type_tbl(kk) -- EXPENDITURE_TYPE
6036 ,l_targ_expend_category_tbl(kk) -- EXPENDITURE_CATEGORY
6037 ,l_targ_rev_category_code_tbl(kk) -- REVENUE_CATEGORY_CODE
6038 ,l_targ_event_type_tbl(kk) -- EVENT_TYPE
6039 ,l_targ_supplier_id_tbl(kk) -- SUPPLIER_ID
6040 ,l_targ_non_labor_resource_tbl(kk) -- NON_LABOR_RESOURCE
6041 ,l_targ_bom_resource_id_tbl(kk) -- BOM_RESOURCE_ID
6042 ,l_targ_inventory_item_id_tbl(kk) -- INVENTORY_ITEM_ID
6043 ,l_targ_item_category_id_tbl(kk) -- ITEM_CATEGORY_ID
6044 ,1 -- RECORD_VERSION_NUMBER
6045 ,NULL -- BILLABLE_PERCENT
6046 , Decode(p_calling_context, null, null, -- BUG 3934574
6047 'BUDGET_GENERATION', 'CHANGE_DOCUMENTS',
6048 'FORECAST_GENERATION','CHANGE_DOCUMENTS') -- TRANSACTION_SOURCE_CODE
6049 ,l_targ_mfc_cost_type_id_tbl(kk) -- MFC_COST_TYPE_ID
6050 ,NULL -- PROCURE_RESOURCE_FLAG
6051 ,NULL -- ASSIGNMENT_DESCRIPTION
6052 ,l_targ_incured_by_res_flag_tbl(kk) -- INCURRED_BY_RES_FLAG
6053 ,NULL -- RATE_JOB_ID
6054 ,l_targ_RATE_EXPEND_TYPE_tbl(kk) -- RATE_EXPENDITURE_TYPE
6055 ,NULL -- TA_DISPLAY_FLAG
6056 ,NULL -- SP_FIXED_DATE
6057 ,l_targ_person_type_code_tbl(kk) -- PERSON_TYPE_CODE
6058 ,l_targ_RATE_BASED_FLAG_tbl(kk) -- RATE_BASED_FLAG
6059 ,l_targ_RES_RATE_BASED_FLAG_tbl(kk) -- RESOURCE_RATE_BASED_FLAG IPM Arch Enhancement
6060 ,NULL -- USE_TASK_SCHEDULE_FLAG
6061 ,l_targ_RATE_EXP_FC_CUR_COD_tbl(kk) -- RATE_EXP_FUNC_CURR_CODE
6062 ,l_targ_RATE_EXPEND_ORG_ID_tbl(kk) -- RATE_EXPENDITURE_ORG_ID
6063 ,l_targ_INCR_BY_RES_CLS_COD_tbl(kk) -- INCUR_BY_RES_CLASS_CODE
6064 ,l_targ_INCUR_BY_ROLE_ID_tbl(kk) -- INCUR_BY_ROLE_ID
6065 ,l_targ_project_role_id_tbl(kk) -- PROJECT_ROLE_ID
6066 ,l_targ_RESOURCE_CLASS_FLAG_tbl(kk) -- RESOURCE_CLASS_FLAG
6067 ,l_targ_NAMED_ROLE_tbl(kk) -- NAMED_ROLE
6068 ,l_targ_txn_accum_header_id_tbl(kk) -- TXN ACCUM HEADER ID
6069 FROM dual
6070 WHERE L_ra_dml_code_tbl(kk)='INSERT';
6071
6072
6073 IF P_PA_debug_mode = 'Y' THEN
6074 pa_debug.g_err_stage:= 'Done with bulk insert into PRA';
6075 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6076 END IF;
6077
6078 --dbms_output.put_line('I19');
6079
6080 --The pl/sql tbls prepared thru this DML will be used later while calling the PJI reporting API.
6081 --It is assumed that all the resource assignments that are updated are available in the below
6082 --pl/sql tbls. Hence changing the WHERE clause of this DML will have an impact on the way these
6083 --tbls are used . Bug 3678314
6084
6085 -- Bug 3934574 The following business rules are incorporated in the update
6086 -- 1) If p_calling_context is null, null out transaction source code
6087 -- 2) If p_calling_context is generation
6088 -- a) if retain manually edited lines is Y do not update ras with transaction source code as null
6089 -- b) for ras that can be updated do not override transaction source code if there are already amounts
6090 -- if no amounts stamp transaction source code as 'CHANGE DOCUMENTS'
6091 -- Please note that the select against pa_budget_lines is unnecessary when p_calling_context is null
6092 -- Howeever, in oracle 8i select can not be used inside a decode. So, two sqls are used for better performance
6093 -- Bug 4171006: Updating UOM and rate_based_flag as well with the values already derived.
6094 IF p_calling_context IN ('BUDGET_GENERATION','FORECAST_GENERATION') THEN
6095 FORALL kk IN L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
6096 UPDATE pa_resource_assignments pra
6097 SET PLANNING_START_DATE = l_planning_start_date_tbl(kk),
6098 PLANNING_END_DATE = l_planning_end_date_tbl(kk),
6099 UNIT_OF_MEASURE = l_targ_unit_of_measure_tbl(kk), -- bug 4171006
6100 TRANSACTION_SOURCE_CODE =
6101 (SELECT DECODE(COUNT(*),0,'CHANGE_DOCUMENTS',TRANSACTION_SOURCE_CODE)
6102 FROM pa_budget_lines pbl
6103 WHERE pbl.resource_assignment_id = pra.resource_assignment_id),
6104 RATE_BASED_FLAG = l_targ_RATE_BASED_FLAG_tbl(kk), -- bug 4171006
6105 LAST_UPDATE_DATE = sysdate,
6106 LAST_UPDATED_BY = fnd_global.user_id,
6107 LAST_UPDATE_LOGIN = fnd_global.login_id,
6108 RECORD_VERSION_NUMBER = NVL( RECORD_VERSION_NUMBER, 0 ) + 1
6109 WHERE l_ra_dml_code_tbl (kk)= 'UPDATE' -- Bug 3662136
6110 AND resource_assignment_id=l_targ_ra_id_tbl(kk)
6111 RETURNING
6112 task_id,
6113 rbs_element_id,
6114 resource_class_code,
6115 rate_based_flag,
6116 resource_assignment_id
6117 BULK COLLECT INTO
6118 l_upd_ra_task_id_tbl,
6119 l_upd_ra_rbs_elem_id_tbl,
6120 l_upd_ra_res_class_code_tbl,
6121 l_upd_ra_rbf_tbl,
6122 l_upd_ra_res_asmt_id_tbl;
6123 ELSE
6124 FORALL kk IN L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
6125 UPDATE pa_resource_assignments pra
6126 SET PLANNING_START_DATE = l_planning_start_date_tbl(kk),
6127 PLANNING_END_DATE = l_planning_end_date_tbl(kk),
6128 UNIT_OF_MEASURE = l_targ_unit_of_measure_tbl(kk), -- bug 4171006
6129 TRANSACTION_SOURCE_CODE = null,
6130 RATE_BASED_FLAG = l_targ_RATE_BASED_FLAG_tbl(kk), -- bug 4171006
6131 LAST_UPDATE_DATE = sysdate,
6132 LAST_UPDATED_BY = fnd_global.user_id,
6133 LAST_UPDATE_LOGIN = fnd_global.login_id,
6134 RECORD_VERSION_NUMBER = NVL( RECORD_VERSION_NUMBER, 0 ) + 1
6135 WHERE l_ra_dml_code_tbl (kk)= 'UPDATE' -- Bug 3662136
6136 AND resource_assignment_id=l_targ_ra_id_tbl(kk)
6137 RETURNING
6138 task_id,
6139 rbs_element_id,
6140 resource_class_code,
6141 rate_based_flag,
6142 resource_assignment_id
6143 BULK COLLECT INTO
6144 l_upd_ra_task_id_tbl,
6145 l_upd_ra_rbs_elem_id_tbl,
6146 l_upd_ra_res_class_code_tbl,
6147 l_upd_ra_rbf_tbl,
6148 l_upd_ra_res_asmt_id_tbl;
6149 END IF;
6150 -- For bug 3814932
6151 --At this point in code, l_partial_factor can be 0 only if the user has chosen to implement 0 amount
6152 --into target. Please note that if the total amount in the change order itself is 0 parital factor
6153 --will be 1. It will be 0 only if the user did not chose to transfer amounts from source to target.
6154 --Hence budget lines need not be copied.
6155
6156 IF l_partial_factor<>0 THEN
6157
6158 IF P_PA_debug_mode = 'Y' THEN
6159 pa_debug.g_err_stage:= 'Done with bulk update of PRA';
6160 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6161 END IF;
6162
6163
6164 l_same_multi_curr_flag := 'N';
6165 IF l_src_multi_curr_flag = l_targ_multi_curr_flag THEN
6166 l_same_multi_curr_flag := 'Y';
6167 END IF;
6168
6169 IF P_PA_debug_mode = 'Y' THEN
6170 pa_debug.g_err_stage:= 'Done with deriving elem ver ids.';
6171 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6172 END IF;
6173
6174 --dbms_output.put_line('I20');
6175
6176
6177 --dbms_output.put_line('I22');
6178 IF l_src_time_phased_code = 'N' AND (l_targ_time_phased_code = 'P' OR l_targ_time_phased_code = 'G') THEN
6179
6180 IF l_src_resource_list_id = l_targ_resource_list_id THEN
6181
6182 IF P_PA_debug_mode = 'Y' THEN
6183 pa_debug.g_err_stage:= 'About to fire select for deriving params to calc API. Same Rls';
6184 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6185 END IF;
6186
6187
6188 SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id),
6189 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
6190 DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
6191 'N', --delete
6192 'Y', --spread
6193 decode(l_cost_impl_flag,'Y',pbls.quantity,decode(l_rev_impl_flag,'Y',
6194 decode(l_impl_qty_tbl(j),'Y', nvl(pbls.quantity,0) * l_partial_factor,0),0)) + nvl(pblt.quantity,0), --total
6195 Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.raw_cost,nvl(pbls.txn_raw_cost,0)),
6196 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0),
6197 nvl(pbls.project_raw_cost,nvl(pbls.txn_raw_cost,0)))),0) +
6198 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.raw_cost,nvl(pblt.txn_raw_cost,0)),
6199 DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_raw_cost,0),
6200 nvl(pblt.project_raw_cost,nvl(pblt.txn_raw_cost,0)))) , --total
6201 Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.burdened_cost,nvl(pbls.txn_burdened_cost,0)),
6202 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
6203 nvl(pbls.project_burdened_cost,nvl(pbls.txn_burdened_cost,0)))),0) +
6204 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.burdened_cost,nvl(pblt.txn_burdened_cost,0)),
6205 DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_burdened_cost,0),
6206 nvl(pblt.project_burdened_cost,nvl(pblt.txn_burdened_cost,0)))), --total
6207 Decode(l_rev_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,nvl(pbls.txn_revenue,0)),
6208 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
6209 nvl(pbls.project_revenue,nvl(pbls.txn_revenue,0)))),0)*l_partial_factor +
6210 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.revenue,nvl(pblt.txn_revenue,0)),
6211 DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_revenue,0),
6212 nvl(pblt.project_revenue,nvl(pblt.txn_revenue,0)))), --total
6213 NULL,
6214 NULL,
6215 NULL
6216 BULK COLLECT INTO
6217 l_res_assignment_id_tbl,
6218 l_currency_code_tbl,
6219 l_delete_budget_lines_tbl,
6220 l_spread_amount_flags_tbl,
6221 l_total_quantity_tbl,
6222 l_total_raw_cost_tbl,
6223 l_total_burdened_cost_tbl,
6224 l_total_revenue_tbl,
6225 l_bl_TXN_COST_RATE_OVERIDE_tbl,
6226 l_bl_BURDEN_COST_RAT_OVRID_tbl,
6227 l_bl_TXN_BILL_RATE_OVERRID_tbl
6228 from (SELECT pra.resource_assignment_id resource_assignment_id,
6229 pra.task_id task_id,
6230 pra.resource_list_member_id resource_list_member_id,
6231 sum(quantity) quantity,
6232 sum(pbl.txn_raw_cost) txn_raw_cost,
6233 sum(pbl.txn_burdened_cost) txn_burdened_cost,
6234 sum(pbl.txn_revenue) txn_revenue,
6235 sum(pbl.project_raw_cost) project_raw_cost,
6236 sum(pbl.project_burdened_cost) project_burdened_cost,
6237 sum(pbl.project_revenue) project_revenue,
6238 sum(pbl.raw_cost) raw_cost,
6239 sum(pbl.burdened_cost) burdened_cost,
6240 sum(pbl.revenue) revenue,
6241 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
6242 DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) txn_currency_code
6243 FROM pa_budget_lines pbl,
6244 pa_resource_assignments pra
6245 WHERE pbl.resource_assignment_id = pra.resource_assignment_id
6246 AND pra.budget_version_id=l_src_ver_id_tbl(j)
6247 GROUP BY pra.resource_assignment_id, pra.task_id, pra.resource_list_member_id,
6248 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
6249 DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) ) pbls,
6250 (SELECT pbl.resource_assignment_id,
6251 sum(quantity) quantity,
6252 sum(pbl.txn_raw_cost) txn_raw_cost,
6253 sum(pbl.txn_burdened_cost) txn_burdened_cost,
6254 sum(pbl.txn_revenue) txn_revenue,
6255 sum(pbl.project_raw_cost) project_raw_cost,
6256 sum(pbl.project_burdened_cost) project_burdened_cost,
6257 sum(pbl.project_revenue) project_revenue,
6258 sum(pbl.raw_cost) raw_cost,
6259 sum(pbl.burdened_cost) burdened_cost,
6260 sum(pbl.revenue) revenue,
6261 pbl.txn_currency_code
6262 FROM pa_budget_lines pbl
6263 WHERE pbl.budget_Version_id = p_budget_version_id
6264 GROUP BY pbl.resource_assignment_id, pbl.txn_currency_code)pblt
6265 where get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)=pblt.resource_assignment_id(+)
6266 and pblt.txn_Currency_code(+)= pbls.txn_currency_code;
6267 IF P_PA_debug_mode = 'Y' THEN
6268 pa_debug.g_err_stage:= 'Done with select for deriving params to calc API. Same Rls';
6269 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6270 END IF;
6271
6272
6273 ELSE
6274
6275 IF P_PA_debug_mode = 'Y' THEN
6276 pa_debug.g_err_stage:= 'About to bulk collect BLs with diff RLs for calling calc API';
6277 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6278 END IF;
6279
6280 select get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id),
6281 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
6282 DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
6283 'N', --delete
6284 'Y', --spread
6285 decode(l_cost_impl_flag,'Y',pbls.quantity,decode(l_rev_impl_flag,'Y',
6286 decode(l_impl_qty_tbl(j),'Y', nvl(pbls.quantity,0) * l_partial_factor,0),0)) +
6287 nvl(pblt.quantity,0), --total
6288 Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.raw_cost,nvl(pbls.txn_raw_cost,0)),
6289 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0),
6290 nvl(pbls.project_raw_cost,nvl(pbls.txn_raw_cost,0)))),0) +
6291 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.raw_cost,nvl(pblt.txn_raw_cost,0)),
6292 DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_raw_cost,0),
6293 nvl(pblt.project_raw_cost,nvl(pblt.txn_raw_cost,0)))), --total
6294 Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.burdened_cost,nvl(pbls.txn_burdened_cost,0)),
6295 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
6296 nvl(pbls.project_burdened_cost,nvl(pbls.txn_burdened_cost,0)))),0) +
6297 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.burdened_cost,nvl(pblt.txn_burdened_cost,0)),
6298 DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_burdened_cost,0),
6299 nvl(pblt.project_burdened_cost,nvl(pblt.txn_burdened_cost,0)))), --total
6300 Decode(l_rev_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,nvl(pbls.txn_revenue,0)),
6301 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
6302 nvl(pbls.project_revenue,nvl(pbls.txn_revenue,0)))),0)*l_partial_factor +
6303 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.revenue,nvl(pblt.txn_revenue,0)),
6304 DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_revenue,0),
6305 nvl(pblt.project_revenue,nvl(pblt.txn_revenue,0)))), --total
6306 NULL,
6307 NULL,
6308 NULL
6309 BULK COLLECT INTO
6310 l_res_assignment_id_tbl,
6311 l_currency_code_tbl,
6312 l_delete_budget_lines_tbl,
6313 l_spread_amount_flags_tbl,
6314 l_total_quantity_tbl,
6315 l_total_raw_cost_tbl,
6316 l_total_burdened_cost_tbl,
6317 l_total_revenue_tbl,
6318 l_bl_TXN_COST_RATE_OVERIDE_tbl,
6319 l_bl_BURDEN_COST_RAT_OVRID_tbl,
6320 l_bl_TXN_BILL_RATE_OVERRID_tbl
6321 from (SELECT pra.task_id task_id,
6322 tmp.resource_list_member_id resource_list_member_id,
6323 pra.resource_assignment_id resource_assignment_id,
6324 sum(quantity) quantity,
6325 sum(pbl.txn_raw_cost) txn_raw_cost,
6326 sum(pbl.txn_burdened_cost) txn_burdened_cost,
6327 sum(pbl.txn_revenue) txn_revenue,
6328 sum(pbl.project_raw_cost) project_raw_cost,
6329 sum(pbl.project_burdened_cost) project_burdened_cost,
6330 sum(pbl.project_revenue) project_revenue,
6331 sum(pbl.raw_cost) raw_cost,
6332 sum(pbl.burdened_cost) burdened_cost,
6333 sum(pbl.revenue) revenue,
6334 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
6335 DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) txn_currency_code
6336 FROM pa_resource_assignments pra
6337 ,pa_res_list_map_tmp4 tmp
6338 ,pa_budget_lines pbl
6339 WHERE pra.resource_assignment_id=tmp.txn_source_id
6340 AND pra.budget_version_id=l_src_ver_id_tbl(j)
6341 AND pbl.resource_assignment_id=pra.resource_assignment_id
6342 GROUP BY pra.resource_assignment_id, pra.task_id, tmp.resource_list_member_id,
6343 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
6344 DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) ) pbls,
6345 (SELECT pbl.resource_assignment_id resource_assignment_id,
6346 sum(quantity) quantity,
6347 sum(pbl.txn_raw_cost) txn_raw_cost,
6348 sum(pbl.txn_burdened_cost) txn_burdened_cost,
6349 sum(pbl.txn_revenue) txn_revenue,
6350 sum(pbl.project_raw_cost) project_raw_cost,
6351 sum(pbl.project_burdened_cost) project_burdened_cost,
6352 sum(pbl.project_revenue) project_revenue,
6353 sum(pbl.raw_cost) raw_cost,
6354 sum(pbl.burdened_cost) burdened_cost,
6355 sum(pbl.revenue) revenue,
6356 pbl.txn_currency_code txn_currency_code
6357 FROM pa_budget_lines pbl
6358 WHERE pbl.budget_Version_id = p_budget_version_id
6359 GROUP BY pbl.resource_assignment_id, pbl.txn_currency_code)pblt
6360 where get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)=pblt.resource_assignment_id(+)
6361 and pblt.txn_currency_code(+)= pbls.txn_currency_code;
6362
6363 IF P_PA_debug_mode = 'Y' THEN
6364 pa_debug.g_err_stage:= 'Done with bulk collect BLs with diff RLs for calling calc API';
6365 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6366 END IF;
6367
6368 END IF;
6369
6370 --dbms_output.put_line('I23');
6371
6372 IF l_res_assignment_id_tbl.COUNT>0 THEN
6373
6374 --The below loop will calculate the override rates. These override rates are required because
6375 --the amounts in the source should be added to the corresponding amounts in the target and there
6376 --should not be re-derivation of amounts in the target based on the changed quantity in the target.
6377 --For example, Consider the implementaion of a COST impact into a cost and revenue together
6378 --version. In this case the quantity in the target will change but this in turn should not change
6379 --the revenue amount in the target as only cost amounts should be impacted in the target.
6380
6381 FOR kk IN l_res_assignment_id_tbl.FIRST..l_res_assignment_id_tbl.LAST LOOP
6382
6383 IF P_PA_debug_mode = 'Y' THEN
6384 pa_debug.g_err_stage:= 'Before finding the RBF flag for l_res_assignment_id_tbl('||kk||')'||l_res_assignment_id_tbl(kk);
6385 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6386 END IF;
6387
6388
6389 FOR ww IN l_targ_ra_id_tbl.FIRST..l_targ_ra_id_tbl.LAST LOOP
6390
6391 IF P_PA_debug_mode = 'Y' THEN
6392 pa_debug.g_err_stage:= 'l_targ_ra_id_tbl('||ww||')'||l_targ_ra_id_tbl(ww);
6393 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6394 END IF;
6395
6396 IF l_targ_ra_id_tbl(ww)=l_res_assignment_id_tbl(kk) THEN
6397
6398 IF P_PA_debug_mode = 'Y' THEN
6399 pa_debug.g_err_stage:= 'Exiting with ww '||ww;
6400 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6401 END IF;
6402
6403 l_matching_index := ww;
6404
6405 EXIT;
6406
6407 END IF;
6408
6409 END LOOP;
6410
6411 IF P_PA_debug_mode = 'Y' THEN
6412
6413 pa_debug.g_err_stage:= 'l_matching_index is '||l_matching_index;
6414 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6415
6416 END IF;
6417
6418
6419 IF l_targ_RATE_BASED_FLAG_tbl(l_matching_index)='Y' THEN
6420
6421 l_amt_used_for_rate_calc := l_total_quantity_tbl(kk);
6422
6423 ELSE
6424
6425 l_amt_used_for_rate_calc := l_total_raw_cost_tbl(kk);
6426
6427 END IF;
6428
6429 IF l_amt_used_for_rate_calc=0 THEN
6430
6431 l_bl_TXN_COST_RATE_OVERIDE_tbl(kk):=0;
6432 l_bl_BURDEN_COST_RAT_OVRID_tbl(kk):=0;
6433 l_bl_TXN_BILL_RATE_OVERRID_tbl(kk):=0;
6434
6435 ELSE
6436
6437 l_bl_TXN_COST_RATE_OVERIDE_tbl(kk):=l_total_raw_cost_tbl(kk)/l_amt_used_for_rate_calc;
6438 l_bl_BURDEN_COST_RAT_OVRID_tbl(kk):=l_total_burdened_cost_tbl(kk)/l_amt_used_for_rate_calc;
6439 l_bl_TXN_BILL_RATE_OVERRID_tbl(kk):=l_total_revenue_tbl(kk)/l_amt_used_for_rate_calc;
6440
6441 END IF;
6442
6443
6444 END LOOP;
6445
6446 IF P_PA_debug_mode = 'Y' THEN
6447 pa_debug.g_err_stage:= 'Calling Calc';
6448 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6449
6450 FOR kk IN l_res_assignment_id_tbl.FIRST..l_res_assignment_id_tbl.LAST LOOP
6451
6452 pa_debug.g_err_stage:= 'l_res_assignment_id_tbl('||KK||') IS'||l_res_assignment_id_tbl(kk);
6453 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6454
6455 pa_debug.g_err_stage:= 'l_delete_budget_lines_tbl('||KK||') IS'||l_delete_budget_lines_tbl(kk);
6456 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6457
6458 pa_debug.g_err_stage:= 'l_spread_amount_flags_tbl('||KK||') IS'||l_spread_amount_flags_tbl(kk);
6459 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6460
6461 pa_debug.g_err_stage:= 'l_currency_code_tbl('||KK||') IS'||l_currency_code_tbl(kk);
6462 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6463
6464 pa_debug.g_err_stage:= 'l_total_quantity_tbl('||KK||') IS'||l_total_quantity_tbl(kk);
6465 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6466
6467 pa_debug.g_err_stage:= 'l_total_raw_cost_tbl('||KK||') IS'||l_total_raw_cost_tbl(kk);
6468 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6469
6470 pa_debug.g_err_stage:= 'l_total_burdened_cost_tbl('||KK||') IS'||l_total_burdened_cost_tbl(kk);
6471 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6472
6473 pa_debug.g_err_stage:= 'l_total_revenue_tbl('||KK||') IS'||l_total_revenue_tbl(kk);
6474 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6475
6476 pa_debug.g_err_stage:= 'l_bl_TXN_COST_RATE_OVERIDE_tbl('||KK||') IS'||l_bl_TXN_COST_RATE_OVERIDE_tbl(kk);
6477 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6478
6479 pa_debug.g_err_stage:= 'l_bl_BURDEN_COST_RAT_OVRID_tbl('||KK||') IS'||l_bl_BURDEN_COST_RAT_OVRID_tbl(kk);
6480 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6481
6482 pa_debug.g_err_stage:= 'l_bl_TXN_BILL_RATE_OVERRID_tbl('||KK||') IS'||l_bl_TXN_BILL_RATE_OVERRID_tbl(kk);
6483 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6484
6485 END LOOP;
6486
6487 END IF;
6488
6489 PA_FP_CALC_PLAN_PKG.calculate(
6490 p_project_id => l_project_id
6491 ,p_budget_version_id => p_budget_version_id
6492 ,p_source_context => PA_FP_CONSTANTS_PKG.G_CALC_API_RESOURCE_CONTEXT
6493 ,p_resource_assignment_tab => l_res_assignment_id_tbl
6494 ,p_delete_budget_lines_tab => l_delete_budget_lines_tbl
6495 ,p_spread_amts_flag_tab => l_spread_amount_flags_tbl
6496 ,p_txn_currency_code_tab => l_currency_code_tbl
6497 ,p_total_qty_tab => l_total_quantity_tbl
6498 ,p_total_raw_cost_tab => l_total_raw_cost_tbl -- dervie
6499 ,p_total_burdened_cost_tab => l_total_burdened_cost_tbl -- dervie
6500 ,p_total_revenue_tab => l_total_revenue_tbl -- derive
6501 ,p_rw_cost_rate_override_tab => l_bl_TXN_COST_RATE_OVERIDE_tbl
6502 ,p_b_cost_rate_override_tab => l_bl_BURDEN_COST_RAT_OVRID_tbl
6503 ,p_bill_rate_override_tab => l_bl_TXN_BILL_RATE_OVERRID_tbl
6504 ,p_raTxn_rollup_api_call_flag => p_raTxn_rollup_api_call_flag --Indicates whether the pa_resource_asgn_curr maintenance api should be called
6505 ,x_return_status => l_return_status
6506 ,x_msg_count => l_msg_count
6507 ,x_msg_data => l_msg_data);
6508
6509 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6510 IF P_PA_debug_mode = 'Y' THEN
6511 pa_debug.g_err_stage:= 'Error in calculate';
6512 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6513 END IF;
6514 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6515 END IF;
6516
6517 --dbms_output.put_line('I24');
6518
6519 END IF;--IF l_res_assignment_id_tbl.COUNT>0 THEN
6520
6521 END IF;--IF l_src_time_phased_code = 'N' AND (l_targ_time_phased_code = 'P' OR l_targ_time_phased_code = 'G') THEN
6522
6523 --Get the budget line sequence before inserting data into budget lines. After inserting the budget lines
6524 --the sequence is again compared to see the no. of budget lines that have got inserted. Since pa_budget_lines_s.currval
6525 --is used at a later part of code this SELECT should not be removed
6526 SELECT pa_budget_lines_s.nextval
6527 INTO l_id_before_bl_insertion
6528 FROM DUAL;
6529
6530 --dbms_output.put_line('I25');
6531 IF l_src_time_phased_code = l_targ_time_phased_code OR l_targ_time_phased_code = 'N' THEN
6532 IF l_targ_time_phased_code = 'N' THEN
6533 IF l_src_resource_list_id = l_targ_resource_list_id THEN
6534
6535 IF P_PA_debug_mode = 'Y' THEN
6536 pa_debug.g_err_stage:= 'About to bulk insert Budget lines with same RLs';
6537 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6538 END IF;
6539
6540 --dbms_output.put_line('I26');
6541 FORALL kk in L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
6542 INSERT INTO PA_BUDGET_LINES(
6543 RESOURCE_ASSIGNMENT_ID,
6544 START_DATE,
6545 LAST_UPDATE_DATE,
6546 LAST_UPDATED_BY,
6547 CREATION_DATE,
6548 CREATED_BY,
6549 LAST_UPDATE_LOGIN,
6550 END_DATE,
6551 PERIOD_NAME,
6552 QUANTITY,
6553 RAW_COST,
6554 BURDENED_COST,
6555 REVENUE,
6556 CHANGE_REASON_CODE,
6557 DESCRIPTION,
6558 ATTRIBUTE_CATEGORY,
6559 ATTRIBUTE1,
6560 ATTRIBUTE2,
6561 ATTRIBUTE3,
6562 ATTRIBUTE4,
6563 ATTRIBUTE5,
6564 ATTRIBUTE6,
6565 ATTRIBUTE7,
6566 ATTRIBUTE8,
6567 ATTRIBUTE9,
6568 ATTRIBUTE10,
6569 ATTRIBUTE11,
6570 ATTRIBUTE12,
6571 ATTRIBUTE13,
6572 ATTRIBUTE14,
6573 ATTRIBUTE15,
6574 RAW_COST_SOURCE,
6575 BURDENED_COST_SOURCE,
6576 QUANTITY_SOURCE,
6577 REVENUE_SOURCE,
6578 PM_PRODUCT_CODE,
6579 PM_BUDGET_LINE_REFERENCE,
6580 COST_REJECTION_CODE,
6581 REVENUE_REJECTION_CODE,
6582 BURDEN_REJECTION_CODE,
6583 OTHER_REJECTION_CODE,
6584 CODE_COMBINATION_ID,
6585 CCID_GEN_STATUS_CODE,
6586 CCID_GEN_REJ_MESSAGE,
6587 REQUEST_ID,
6588 BORROWED_REVENUE,
6589 TP_REVENUE_IN,
6590 TP_REVENUE_OUT,
6591 REVENUE_ADJ,
6592 LENT_RESOURCE_COST,
6593 TP_COST_IN,
6594 TP_COST_OUT,
6595 COST_ADJ,
6596 UNASSIGNED_TIME_COST,
6597 UTILIZATION_PERCENT,
6598 UTILIZATION_HOURS,
6599 UTILIZATION_ADJ,
6600 CAPACITY,
6601 HEAD_COUNT,
6602 HEAD_COUNT_ADJ,
6603 PROJFUNC_CURRENCY_CODE,
6604 PROJFUNC_COST_RATE_TYPE,
6605 PROJFUNC_COST_EXCHANGE_RATE,
6606 PROJFUNC_COST_RATE_DATE_TYPE,
6607 PROJFUNC_COST_RATE_DATE,
6608 PROJFUNC_REV_RATE_TYPE,
6609 PROJFUNC_REV_EXCHANGE_RATE,
6610 PROJFUNC_REV_RATE_DATE_TYPE,
6611 PROJFUNC_REV_RATE_DATE,
6612 PROJECT_CURRENCY_CODE,
6613 PROJECT_COST_RATE_TYPE,
6614 PROJECT_COST_EXCHANGE_RATE,
6615 PROJECT_COST_RATE_DATE_TYPE,
6616 PROJECT_COST_RATE_DATE,
6617 PROJECT_RAW_COST,
6618 PROJECT_BURDENED_COST,
6619 PROJECT_REV_RATE_TYPE,
6620 PROJECT_REV_EXCHANGE_RATE,
6621 PROJECT_REV_RATE_DATE_TYPE,
6622 PROJECT_REV_RATE_DATE,
6623 PROJECT_REVENUE,
6624 TXN_CURRENCY_CODE,
6625 TXN_RAW_COST,
6626 TXN_BURDENED_COST,
6627 TXN_REVENUE,
6628 BUCKETING_PERIOD_CODE,
6629 BUDGET_LINE_ID,
6630 BUDGET_VERSION_ID,
6631 TXN_STANDARD_COST_RATE,
6632 TXN_COST_RATE_OVERRIDE,
6633 COST_IND_COMPILED_SET_ID,
6634 -- TXN_BURDEN_MULTIPLIER,
6635 -- TXN_BURDEN_MULTIPLIER_OVERRIDE,
6636 TXN_STANDARD_BILL_RATE,
6637 TXN_BILL_RATE_OVERRIDE,
6638 TXN_MARKUP_PERCENT,
6639 TXN_MARKUP_PERCENT_OVERRIDE,
6640 TXN_DISCOUNT_PERCENTAGE,
6641 TRANSFER_PRICE_RATE,
6642 BURDEN_COST_RATE,
6643 BURDEN_COST_RATE_OVERRIDE,
6644 PC_CUR_CONV_REJECTION_CODE,
6645 PFC_CUR_CONV_REJECTION_CODE
6646 )
6647 SELECT pbl.resource_assignment_id,
6648 l_planning_start_date_tbl(kk) start_date,
6649 pbl.last_update_date,
6650 pbl.last_updated_by,
6651 pbl.creation_date,
6652 pbl.created_by,
6653 pbl.last_update_login,
6654 l_planning_end_date_tbl(kk) end_date,
6655 pbl.period_name,
6656 DECODE(l_targ_rate_based_flag_tbl(kk),
6657 'N',DECODE(l_target_version_type,
6658 'REVENUE',pbl.txn_revenue
6659 ,pbl.txn_raw_cost),
6660 pbl.quantity),
6661 pbl.raw_cost,
6662 pbl.burdened_cost,
6663 pbl.revenue,
6664 pbl.change_reason_code,
6665 pbl.description,
6666 pbl.attribute_category,
6667 pbl.attribute1,
6668 pbl.attribute2,
6669 pbl.attribute3,
6670 pbl.attribute4,
6671 pbl.attribute5,
6672 pbl.attribute6,
6673 pbl.attribute7,
6674 pbl.attribute8,
6675 pbl.attribute9,
6676 pbl.attribute10,
6677 pbl.attribute11,
6678 pbl.attribute12,
6679 pbl.attribute13,
6680 pbl.attribute14,
6681 pbl.attribute15,
6682 pbl.raw_cost_source,
6683 pbl.burdened_cost_source,
6684 pbl.quantity_source,
6685 pbl.revenue_source,
6686 pbl.pm_product_code,
6687 pbl.pm_budget_line_reference,
6688 pbl.cost_rejection_code,
6689 pbl.revenue_rejection_code,
6690 pbl.burden_rejection_code,
6691 pbl.other_rejection_code,
6692 pbl.code_combination_id,
6693 pbl.ccid_gen_status_code,
6694 pbl.ccid_gen_rej_message,
6695 pbl.request_id,
6696 pbl.borrowed_revenue,
6697 pbl.tp_revenue_in,
6698 pbl.tp_revenue_out,
6699 pbl.revenue_adj,
6700 pbl.lent_resource_cost,
6701 pbl.tp_cost_in,
6702 pbl.tp_cost_out,
6703 pbl.cost_adj,
6704 pbl.unassigned_time_cost,
6705 pbl.utilization_percent,
6706 pbl.utilization_hours,
6707 pbl.utilization_adj,
6708 pbl.capacity,
6709 pbl.head_count,
6710 pbl.head_count_adj,
6711 pbl.projfunc_currency_code,
6712 pbl.projfunc_cost_rate_type,
6713 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y',
6714 Decode(decode(l_report_cost_using, 'R', nvl(pbl.txn_raw_cost,0),
6715 'B', nvl(pbl.txn_burdened_cost,0)),0,0,
6716 (decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
6717 'B',nvl(pbl.burdened_cost,0)) /decode(l_report_cost_using,'R', pbl.txn_raw_cost,
6718 'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
6719 pbl.projfunc_cost_rate_date_type,
6720 pbl.projfunc_cost_rate_date,
6721 pbl.projfunc_rev_rate_type,
6722 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,nvl(pbl.revenue,0) / pbl.txn_revenue),Null),Null), --Bug 3839273
6723 pbl.projfunc_rev_rate_date_type,
6724 pbl.projfunc_rev_rate_date,
6725 pbl.project_currency_code,
6726 pbl.project_cost_rate_type,
6727 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
6728 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
6729 'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
6730 'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
6731 pbl.project_cost_rate_date_type,
6732 pbl.project_cost_rate_date,
6733 pbl.project_raw_cost,
6734 pbl.project_burdened_cost,
6735 pbl.project_rev_rate_type,
6736 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,nvl(pbl.project_revenue,0) /pbl.txn_revenue),Null),Null), --Bug 3839273
6737 pbl.project_rev_rate_date_type,
6738 pbl.project_rev_rate_date,
6739 pbl.project_revenue,
6740 pbl.txn_currency_code,
6741 pbl.txn_raw_cost,
6742 pbl.txn_burdened_cost,
6743 pbl.txn_revenue,
6744 pbl.bucketing_period_code,
6745 pa_budget_lines_s.nextval,
6746 pbl.budget_version_id,
6747 pbl.txn_standard_cost_rate,
6748 DECODE(l_target_version_type,
6749 'REVENUE',pbl.txn_cost_rate_override,
6750 DECODE(l_targ_rate_based_flag_tbl(kk),
6751 'N',1,
6752 pbl.txn_cost_rate_override)),
6753 pbl.cost_ind_compiled_set_id,
6754 -- pbl. txn_burden_multiplier,
6755 -- pbl. txn_burden_multiplier_override,
6756 pbl.txn_standard_bill_rate,
6757 DECODE(l_target_version_type,
6758 'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
6759 'N',1,
6760 pbl.txn_bill_rate_override)
6761 ,pbl.txn_bill_rate_override),
6762 pbl.txn_markup_percent,
6763 pbl.txn_markup_percent_override,
6764 pbl.txn_discount_percentage,
6765 pbl.transfer_price_rate,
6766 pbl.burden_cost_rate,
6767 DECODE(l_target_version_type,
6768 'REVENUE',pbl.burden_cost_rate_override,
6769 DECODE(l_targ_rate_based_flag_tbl(kk),
6770 'Y',pbl.burden_cost_rate_override,
6771 DECODE(nvl(pbl.txn_raw_cost,0),
6772 0,null,
6773 pbl.txn_burdened_cost/pbl.txn_raw_cost))),
6774 pbl.pc_cur_conv_rejection_code,
6775 pbl.pfc_cur_conv_rejection_code
6776 FROM
6777 --The entire SELECT is moved to the sub query in FROM clause as nextval would not work with group by
6778 (SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id) resource_assignment_id,
6779 sysdate last_update_date,
6780 fnd_global.user_id last_updated_by,
6781 sysdate creation_date,
6782 fnd_global.user_id created_by,
6783 fnd_global.login_id last_update_login,
6784 NULL period_name,
6785 decode(l_cost_impl_flag,
6786 'Y',sum(pbls.quantity),
6787 decode(l_rev_impl_flag,
6788 'Y',decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),
6789 null)) quantity,
6790 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
6791 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
6792 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue,null))*l_partial_factor revenue,
6793 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
6794 decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
6795 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
6796 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1,
6797 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2,
6798 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3,
6799 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4,
6800 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5,
6801 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6,
6802 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7,
6803 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8,
6804 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9,
6805 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null) attribute10,
6806 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null) attribute11,
6807 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null) attribute12,
6808 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null) attribute13,
6809 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null) attribute14,
6810 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null) attribute15,
6811 'I' raw_cost_source,
6812 'I' burdened_cost_source,
6813 'I' quantity_source,
6814 'I' revenue_source,
6815 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
6816 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
6817 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
6818 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
6819 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
6820 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null)other_rejection_code,
6821 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
6822 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
6823 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
6824 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
6825 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
6826 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
6827 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
6828 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null) revenue_adj,
6829 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
6830 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
6831 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
6832 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
6833 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
6834 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
6835 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
6836 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
6837 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
6838 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
6839 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
6840 l_projfunc_currency_code projfunc_currency_code,
6841 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
6842 null projfunc_cost_exchange_rate, --Bug 3839273
6843 null projfunc_cost_rate_date_type,
6844 null projfunc_cost_rate_date,
6845 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
6846 null projfunc_rev_exchange_rate, --Bug 3839273
6847 null projfunc_rev_rate_date_type,
6848 null projfunc_rev_rate_date,
6849 l_project_currency_code project_currency_code ,
6850 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
6851 null project_cost_exchange_rate, --Bug 3839273
6852 null project_cost_rate_date_type,
6853 null project_cost_rate_date,
6854 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)) project_raw_cost,
6855 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)) project_burdened_cost,
6856 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
6857 null project_rev_exchange_rate, --Bug 3839273
6858 null project_rev_rate_date_type,
6859 null project_rev_rate_date,
6860 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
6861 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,
6862
6863 --Bug 4224757. Code changes for bug#4224757 starts here
6864 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
6865 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
6866 txn_raw_cost,
6867 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
6868 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
6869 nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
6870 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
6871 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
6872 nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
6873 --Bug 4224757.. Code changes for bug#4224757 ends here
6874
6875 null bucketing_period_code,
6876 p_budget_version_id budget_version_id,
6877 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,
6878
6879 --Bug 4224757. Code changes for bug#4224757 starts here
6880 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
6881 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
6882 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
6883 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
6884 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_cost_rate_override,
6885 --Bug 4224757. Code changes for bug#4224757 ends here
6886
6887
6888
6889
6890 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
6891 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
6892 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate ,
6893
6894 --Bug 4224757. Code changes for bug#4224757 starts here
6895 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
6896 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
6897 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
6898 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
6899 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))txn_bill_rate_override,
6900 --Bug 4224757. Code changes for bug#4224757 ends here
6901
6902 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
6903 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
6904 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
6905 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
6906 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,
6907
6908 --Bug 4224757. Code changes for bug#4224757 starts here
6909 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
6910 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag,
6911 'Y', nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
6912 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
6913 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
6914 --Bug 4224757. Code changes for bug#4224757 ends here
6915
6916
6917
6918 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
6919 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
6920 from pa_budget_lines pbls,
6921 pa_resource_assignments pras
6922 where l_ra_dml_code_tbl(kk)='INSERT'
6923 and pras.resource_assignment_id = pbls.resource_assignment_id
6924 and pras.budget_version_id = l_src_ver_id_tbl(j)
6925 and PA_FP_CI_MERGE.get_mapped_ra_id(PA_FP_CI_MERGE.get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id)= L_targ_ra_id_tbl(kk)
6926 --IPM Arch Enhancement Bug 4865563
6927 /*and pbls.cost_rejection_code IS NULL
6928 and pbls.revenue_rejection_code IS NULL
6929 and pbls.burden_rejection_code IS NULL
6930 and pbls.other_rejection_code IS NULL
6931 and pbls.pc_cur_conv_rejection_code IS NULL
6932 and pbls.pfc_cur_conv_rejection_code IS NULL*/
6933 GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id),pras.resource_list_member_id) ,
6934 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)))pbl;
6935
6936 IF P_PA_debug_mode = 'Y' THEN
6937 pa_debug.g_err_stage:= 'After bulk-inserting resource assignments';
6938 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6939 END IF;
6940 --dbms_output.put_line('I27');
6941
6942 ELSE-- Resource lists are different
6943
6944 IF P_PA_debug_mode = 'Y' THEN
6945 pa_debug.g_err_stage:= 'About to bulk insert Budget lines with diff RLs and with targ TP as None';
6946 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6947 END IF;
6948
6949 --dbms_output.put_line('I28');
6950 FORALL kk in L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
6951 INSERT INTO PA_BUDGET_LINES(RESOURCE_ASSIGNMENT_ID,
6952 START_DATE,
6953 LAST_UPDATE_DATE,
6954 LAST_UPDATED_BY,
6955 CREATION_DATE,
6956 CREATED_BY,
6957 LAST_UPDATE_LOGIN,
6958 END_DATE,
6959 PERIOD_NAME,
6960 QUANTITY,
6961 RAW_COST,
6962 BURDENED_COST,
6963 REVENUE,
6964 CHANGE_REASON_CODE,
6965 DESCRIPTION,
6966 ATTRIBUTE_CATEGORY,
6967 ATTRIBUTE1,
6968 ATTRIBUTE2,
6969 ATTRIBUTE3,
6970 ATTRIBUTE4,
6971 ATTRIBUTE5,
6972 ATTRIBUTE6,
6973 ATTRIBUTE7,
6974 ATTRIBUTE8,
6975 ATTRIBUTE9,
6976 ATTRIBUTE10,
6977 ATTRIBUTE11,
6978 ATTRIBUTE12,
6979 ATTRIBUTE13,
6980 ATTRIBUTE14,
6981 ATTRIBUTE15,
6982 RAW_COST_SOURCE,
6983 BURDENED_COST_SOURCE,
6984 QUANTITY_SOURCE,
6985 REVENUE_SOURCE,
6986 PM_PRODUCT_CODE,
6987 PM_BUDGET_LINE_REFERENCE,
6988 COST_REJECTION_CODE,
6989 REVENUE_REJECTION_CODE,
6990 BURDEN_REJECTION_CODE,
6991 OTHER_REJECTION_CODE,
6992 CODE_COMBINATION_ID,
6993 CCID_GEN_STATUS_CODE,
6994 CCID_GEN_REJ_MESSAGE,
6995 REQUEST_ID,
6996 BORROWED_REVENUE,
6997 TP_REVENUE_IN,
6998 TP_REVENUE_OUT,
6999 REVENUE_ADJ,
7000 LENT_RESOURCE_COST,
7001 TP_COST_IN,
7002 TP_COST_OUT,
7003 COST_ADJ,
7004 UNASSIGNED_TIME_COST,
7005 UTILIZATION_PERCENT,
7006 UTILIZATION_HOURS,
7007 UTILIZATION_ADJ,
7008 CAPACITY,
7009 HEAD_COUNT,
7010 HEAD_COUNT_ADJ,
7011 PROJFUNC_CURRENCY_CODE,
7012 PROJFUNC_COST_RATE_TYPE,
7013 PROJFUNC_COST_EXCHANGE_RATE,
7014 PROJFUNC_COST_RATE_DATE_TYPE,
7015 PROJFUNC_COST_RATE_DATE,
7016 PROJFUNC_REV_RATE_TYPE,
7017 PROJFUNC_REV_EXCHANGE_RATE,
7018 PROJFUNC_REV_RATE_DATE_TYPE,
7019 PROJFUNC_REV_RATE_DATE,
7020 PROJECT_CURRENCY_CODE,
7021 PROJECT_COST_RATE_TYPE,
7022 PROJECT_COST_EXCHANGE_RATE,
7023 PROJECT_COST_RATE_DATE_TYPE,
7024 PROJECT_COST_RATE_DATE,
7025 PROJECT_RAW_COST,
7026 PROJECT_BURDENED_COST,
7027 PROJECT_REV_RATE_TYPE,
7028 PROJECT_REV_EXCHANGE_RATE,
7029 PROJECT_REV_RATE_DATE_TYPE,
7030 PROJECT_REV_RATE_DATE,
7031 PROJECT_REVENUE,
7032 TXN_CURRENCY_CODE,
7033 TXN_RAW_COST,
7034 TXN_BURDENED_COST,
7035 TXN_REVENUE,
7036 BUCKETING_PERIOD_CODE,
7037 BUDGET_LINE_ID,
7038 BUDGET_VERSION_ID,
7039 TXN_STANDARD_COST_RATE,
7040 TXN_COST_RATE_OVERRIDE,
7041 COST_IND_COMPILED_SET_ID,
7042 -- TXN_BURDEN_MULTIPLIER,
7043 -- TXN_BURDEN_MULTIPLIER_OVERRIDE,
7044 TXN_STANDARD_BILL_RATE,
7045 TXN_BILL_RATE_OVERRIDE,
7046 TXN_MARKUP_PERCENT,
7047 TXN_MARKUP_PERCENT_OVERRIDE,
7048 TXN_DISCOUNT_PERCENTAGE,
7049 TRANSFER_PRICE_RATE,
7050 BURDEN_COST_RATE,
7051 BURDEN_COST_RATE_OVERRIDE,
7052 PC_CUR_CONV_REJECTION_CODE,
7053 PFC_CUR_CONV_REJECTION_CODE
7054 )
7055 SELECT pbl.resource_assignment_id,
7056 l_planning_start_date_tbl(kk) start_date,
7057 pbl.last_update_date,
7058 pbl.last_updated_by,
7059 pbl.creation_date,
7060 pbl.created_by,
7061 pbl.last_update_login,
7062 l_planning_end_date_tbl(kk) end_date,
7063 pbl.period_name,
7064 DECODE(l_targ_rate_based_flag_tbl(kk),
7065 'N',DECODE(l_target_version_type,
7066 'REVENUE',pbl.txn_revenue
7067 ,pbl.txn_raw_cost),
7068 pbl.quantity),
7069 pbl.raw_cost,
7070 pbl.burdened_cost,
7071 pbl.revenue,
7072 pbl.change_reason_code,
7073 pbl.description,
7074 pbl.attribute_category,
7075 pbl.attribute1,
7076 pbl.attribute2,
7077 pbl.attribute3,
7078 pbl.attribute4,
7079 pbl.attribute5,
7080 pbl.attribute6,
7081 pbl.attribute7,
7082 pbl.attribute8,
7083 pbl.attribute9,
7084 pbl.attribute10,
7085 pbl.attribute11,
7086 pbl.attribute12,
7087 pbl.attribute13,
7088 pbl.attribute14,
7089 pbl.attribute15,
7090 pbl.raw_cost_source,
7091 pbl.burdened_cost_source,
7092 pbl.quantity_source,
7093 pbl.revenue_source,
7094 pbl.pm_product_code,
7095 pbl.pm_budget_line_reference,
7096 pbl.cost_rejection_code,
7097 pbl.revenue_rejection_code,
7098 pbl.burden_rejection_code,
7099 pbl.other_rejection_code,
7100 pbl.code_combination_id,
7101 pbl.ccid_gen_status_code,
7102 pbl.ccid_gen_rej_message,
7103 pbl.request_id,
7104 pbl.borrowed_revenue,
7105 pbl.tp_revenue_in,
7106 pbl.tp_revenue_out,
7107 pbl.revenue_adj,
7108 pbl.lent_resource_cost,
7109 pbl.tp_cost_in,
7110 pbl.tp_cost_out,
7111 pbl.cost_adj,
7112 pbl.unassigned_time_cost,
7113 pbl.utilization_percent,
7114 pbl.utilization_hours,
7115 pbl.utilization_adj,
7116 pbl.capacity,
7117 pbl.head_count,
7118 pbl.head_count_adj,
7119 pbl.projfunc_currency_code,
7120 pbl.projfunc_cost_rate_type,
7121 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
7122 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
7123 'B',nvl(pbl.burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
7124 'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
7125 pbl.projfunc_cost_rate_date_type,
7126 pbl.projfunc_cost_rate_date,
7127 pbl.projfunc_rev_rate_type,
7128 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,nvl(pbl.revenue,0) /pbl.txn_revenue),Null),Null), --Bug 3839273
7129 pbl.projfunc_rev_rate_date_type,
7130 pbl.projfunc_rev_rate_date,
7131 pbl.project_currency_code,
7132 pbl.project_cost_rate_type,
7133 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
7134 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
7135 'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
7136 'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
7137 pbl.project_cost_rate_date_type,
7138 pbl.project_cost_rate_date,
7139 pbl.project_raw_cost,
7140 pbl.project_burdened_cost,
7141 pbl.project_rev_rate_type,
7142 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.project_revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
7143 pbl.project_rev_rate_date_type,
7144 pbl.project_rev_rate_date,
7145 pbl.project_revenue,
7146 pbl.txn_currency_code,
7147 pbl.txn_raw_cost,
7148 pbl.txn_burdened_cost,
7149 pbl.txn_revenue,
7150 pbl.bucketing_period_code,
7151 pa_budget_lines_s.nextval,
7152 pbl.budget_version_id,
7153 pbl.txn_standard_cost_rate,
7154 DECODE(l_target_version_type,
7155 'REVENUE',pbl.txn_cost_rate_override,
7156 DECODE(l_targ_rate_based_flag_tbl(kk),
7157 'N',1,
7158 pbl.txn_cost_rate_override)),
7159 pbl.cost_ind_compiled_set_id,
7160 -- pbl. txn_burden_multiplier,
7161 -- pbl. txn_burden_multiplier_override,
7162 pbl.txn_standard_bill_rate,
7163 DECODE(l_target_version_type,
7164 'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
7165 'N',1,
7166 pbl.txn_bill_rate_override),
7167 pbl.txn_bill_rate_override),
7168 pbl.txn_markup_percent,
7169 pbl.txn_markup_percent_override,
7170 pbl.txn_discount_percentage,
7171 pbl.transfer_price_rate,
7172 pbl.burden_cost_rate,
7173 DECODE(l_target_version_type,
7174 'REVENUE',pbl.burden_cost_rate_override,
7175 DECODE(l_targ_rate_based_flag_tbl(kk),
7176 'Y',pbl.burden_cost_rate_override,
7177 DECODE(nvl(pbl.txn_raw_cost,0),
7178 0,null,
7179 pbl.txn_burdened_cost/pbl.txn_raw_cost))),
7180 pbl.pc_cur_conv_rejection_code,
7181 pbl.pfc_cur_conv_rejection_code
7182 FROM
7183 --The entier SELECT is moved to the sub query in FROM clause as nextval would not work with group by
7184 (SELECT pa_fp_ci_merge.get_mapped_ra_id(pa_fp_ci_merge.get_task_id(l_targ_plan_level_code,pras.task_id), rlmap.resource_list_member_id) resource_assignment_id,
7185 sysdate last_update_date,
7186 fnd_global.user_id last_updated_by,
7187 sysdate creation_date,
7188 fnd_global.user_id created_by,
7189 fnd_global.login_id last_update_login,
7190 NULL period_name,
7191 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7192 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)) quantity,
7193 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
7194 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
7195 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue,null))*l_partial_factor revenue,
7196 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
7197 decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
7198 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
7199 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1 ,
7200 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2 ,
7201 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3 ,
7202 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4 ,
7203 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5 ,
7204 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6 ,
7205 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7 ,
7206 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8 ,
7207 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9 ,
7208 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null)attribute10 ,
7209 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null)attribute11 ,
7210 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null)attribute12 ,
7211 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null)attribute13 ,
7212 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null)attribute14 ,
7213 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null)attribute15 ,
7214 'I' raw_cost_source ,
7215 'I' burdened_cost_source,
7216 'I' quantity_source ,
7217 'I' revenue_source ,
7218 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
7219 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
7220 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
7221 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
7222 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
7223 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null) other_rejection_code,
7224 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
7225 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
7226 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
7227 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
7228 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
7229 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
7230 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
7231 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null)revenue_adj,
7232 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
7233 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
7234 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
7235 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
7236 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
7237 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
7238 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
7239 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
7240 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
7241 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
7242 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
7243 l_projfunc_currency_code projfunc_currency_code,
7244 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
7245 null projfunc_cost_exchange_rate, --Bug 3839273
7246 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null) projfunc_cost_rate_date_type,
7247 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null) projfunc_cost_rate_date,
7248 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
7249 null projfunc_rev_exchange_rate, --Bug 3839273
7250 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null) projfunc_rev_rate_date_type,
7251 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null) projfunc_rev_rate_date,
7252 l_project_currency_code project_currency_code,
7253 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
7254 null project_cost_exchange_rate, --Bug 3839273
7255 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null) project_cost_rate_date_type,
7256 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null) project_cost_rate_date,
7257 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)) project_raw_cost,
7258 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)) project_burdened_cost,
7259 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
7260 null project_rev_exchange_rate, --Bug 3839273
7261 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null) project_rev_rate_date_type,
7262 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null) project_rev_rate_date,
7263 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
7264 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,
7265
7266 --Bug 4224757.. Code changes for bug#4224757 starts here
7267 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
7268 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
7269 txn_raw_cost,
7270 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
7271 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
7272 nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
7273 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
7274 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
7275 nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
7276 --Bug 4224757.. Code changes for bug#4224757 ends here
7277
7278 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null) bucketing_period_code,
7279 p_budget_version_id budget_version_id,
7280 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,
7281
7282 --Bug 4224757. Code changes for bug#4224757 starts here
7283 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
7284 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
7285 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
7286 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7287 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_cost_rate_override,
7288 --Bug 4224757. Code changes for bug#4224757 ends here
7289
7290
7291
7292 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
7293 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
7294
7295 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate,
7296
7297 --Bug 4224757. Code changes for bug#4224757 starts here
7298 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
7299 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
7300 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
7301 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7302 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_bill_rate_override,
7303 --Bug 4224757. Code changes for bug#4224757 ends here
7304
7305 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
7306 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
7307 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
7308 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
7309 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,
7310
7311 --Bug 4224757. Code changes for bug#4224757 starts here
7312 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
7313 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
7314 nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
7315 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7316 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
7317 --Bug 4224757. Code changes for bug#4224757 ends here
7318
7319
7320
7321 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
7322 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
7323 from pa_budget_lines pbls,
7324 pa_resource_assignments pras,
7325 pa_res_list_map_tmp4 rlmap
7326 where l_ra_dml_code_tbl(kk)='INSERT'
7327 and pras.resource_assignment_id = pbls.resource_assignment_id
7328 and pras.budget_version_id = l_src_ver_id_tbl(j)
7329 AND pras.resource_assignment_id=rlmap.txn_source_id
7330 and pa_fp_ci_merge.get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), rlmap.resource_list_member_id)=l_targ_ra_id_tbl(kk)
7331 --IPM Arch Enhancement Bug 4865563
7332 /*and pbls.cost_rejection_code IS NULL
7333 and pbls.revenue_rejection_code IS NULL
7334 and pbls.burden_rejection_code IS NULL
7335 and pbls.other_rejection_code IS NULL
7336 and pbls.pc_cur_conv_rejection_code IS NULL
7337 and pbls.pfc_cur_conv_rejection_code IS NULL*/
7338 GROUP BY pa_fp_ci_merge.get_mapped_ra_id(pa_fp_ci_merge.get_task_id(l_targ_plan_level_code,pras.task_id),rlmap.resource_list_member_id) ,
7339 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)))pbl;
7340
7341 IF P_PA_debug_mode = 'Y' THEN
7342 pa_debug.g_err_stage:= 'Done with bulk insert Budget lines with diff RLs and with targ TP as None';
7343 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
7344 END IF;
7345 --dbms_output.put_line('I29');
7346 END IF;
7347 ELSE -- Time phased code is not N and src time phasing = target time phasing
7348
7349 IF P_PA_debug_mode = 'Y' THEN
7350 pa_debug.g_err_stage:= 'SRC tp =targ TP. same RLS. About to bulk insert BLs';
7351 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
7352 END IF;
7353
7354 --dbms_output.put_line('I30');
7355 IF l_src_resource_list_id = l_targ_resource_list_id THEN
7356 FORALL kk in L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
7357 INSERT INTO PA_BUDGET_LINES(
7358 RESOURCE_ASSIGNMENT_ID,
7359 START_DATE,
7360 LAST_UPDATE_DATE,
7361 LAST_UPDATED_BY,
7362 CREATION_DATE,
7363 CREATED_BY,
7364 LAST_UPDATE_LOGIN,
7365 END_DATE,
7366 PERIOD_NAME,
7367 QUANTITY,
7368 RAW_COST,
7369 BURDENED_COST,
7370 REVENUE,
7371 CHANGE_REASON_CODE,
7372 DESCRIPTION,
7373 ATTRIBUTE_CATEGORY,
7374 ATTRIBUTE1,
7375 ATTRIBUTE2,
7376 ATTRIBUTE3,
7377 ATTRIBUTE4,
7378 ATTRIBUTE5,
7379 ATTRIBUTE6,
7380 ATTRIBUTE7,
7381 ATTRIBUTE8,
7382 ATTRIBUTE9,
7383 ATTRIBUTE10,
7384 ATTRIBUTE11,
7385 ATTRIBUTE12,
7386 ATTRIBUTE13,
7387 ATTRIBUTE14,
7388 ATTRIBUTE15,
7389 RAW_COST_SOURCE,
7390 BURDENED_COST_SOURCE,
7391 QUANTITY_SOURCE,
7392 REVENUE_SOURCE,
7393 PM_PRODUCT_CODE,
7394 PM_BUDGET_LINE_REFERENCE,
7395 COST_REJECTION_CODE,
7396 REVENUE_REJECTION_CODE,
7397 BURDEN_REJECTION_CODE,
7398 OTHER_REJECTION_CODE,
7399 CODE_COMBINATION_ID,
7400 CCID_GEN_STATUS_CODE,
7401 CCID_GEN_REJ_MESSAGE,
7402 REQUEST_ID,
7403 BORROWED_REVENUE,
7404 TP_REVENUE_IN,
7405 TP_REVENUE_OUT,
7406 REVENUE_ADJ,
7407 LENT_RESOURCE_COST,
7408 TP_COST_IN,
7409 TP_COST_OUT,
7410 COST_ADJ,
7411 UNASSIGNED_TIME_COST,
7412 UTILIZATION_PERCENT,
7413 UTILIZATION_HOURS,
7414 UTILIZATION_ADJ,
7415 CAPACITY,
7416 HEAD_COUNT,
7417 HEAD_COUNT_ADJ,
7418 PROJFUNC_CURRENCY_CODE,
7419 PROJFUNC_COST_RATE_TYPE,
7420 PROJFUNC_COST_EXCHANGE_RATE,
7421 PROJFUNC_COST_RATE_DATE_TYPE,
7422 PROJFUNC_COST_RATE_DATE,
7423 PROJFUNC_REV_RATE_TYPE,
7424 PROJFUNC_REV_EXCHANGE_RATE,
7425 PROJFUNC_REV_RATE_DATE_TYPE,
7426 PROJFUNC_REV_RATE_DATE,
7427 PROJECT_CURRENCY_CODE,
7428 PROJECT_COST_RATE_TYPE,
7429 PROJECT_COST_EXCHANGE_RATE,
7430 PROJECT_COST_RATE_DATE_TYPE,
7431 PROJECT_COST_RATE_DATE,
7432 PROJECT_RAW_COST,
7433 PROJECT_BURDENED_COST,
7434 PROJECT_REV_RATE_TYPE,
7435 PROJECT_REV_EXCHANGE_RATE,
7436 PROJECT_REV_RATE_DATE_TYPE,
7437 PROJECT_REV_RATE_DATE,
7438 PROJECT_REVENUE,
7439 TXN_CURRENCY_CODE,
7440 TXN_RAW_COST,
7441 TXN_BURDENED_COST,
7442 TXN_REVENUE,
7443 BUCKETING_PERIOD_CODE,
7444 BUDGET_LINE_ID,
7445 BUDGET_VERSION_ID,
7446 TXN_STANDARD_COST_RATE,
7447 TXN_COST_RATE_OVERRIDE,
7448 COST_IND_COMPILED_SET_ID,
7449 -- TXN_BURDEN_MULTIPLIER,
7450 -- TXN_BURDEN_MULTIPLIER_OVERRIDE,
7451 TXN_STANDARD_BILL_RATE,
7452 TXN_BILL_RATE_OVERRIDE,
7453 TXN_MARKUP_PERCENT,
7454 TXN_MARKUP_PERCENT_OVERRIDE,
7455 TXN_DISCOUNT_PERCENTAGE,
7456 TRANSFER_PRICE_RATE,
7457 BURDEN_COST_RATE,
7458 BURDEN_COST_RATE_OVERRIDE,
7459 PC_CUR_CONV_REJECTION_CODE,
7460 PFC_CUR_CONV_REJECTION_CODE
7461 )
7462 SELECT pbl.resource_assignment_id,
7463 pbl.start_date,
7464 pbl.last_update_date,
7465 pbl.last_updated_by,
7466 pbl.creation_date,
7467 pbl.created_by,
7468 pbl.last_update_login,
7469 pbl.end_date,
7470 pbl.period_name,
7471 DECODE(l_targ_rate_based_flag_tbl(kk),
7472 'N',DECODE(l_target_version_type,
7473 'REVENUE',pbl.txn_revenue
7474 ,pbl.txn_raw_cost),
7475 pbl.quantity),
7476 pbl.raw_cost,
7477 pbl.burdened_cost,
7478 pbl.revenue,
7479 pbl.change_reason_code,
7480 pbl.description,
7481 pbl.attribute_category,
7482 pbl.attribute1,
7483 pbl.attribute2,
7484 pbl.attribute3,
7485 pbl.attribute4,
7486 pbl.attribute5,
7487 pbl.attribute6,
7488 pbl.attribute7,
7489 pbl.attribute8,
7490 pbl.attribute9,
7491 pbl.attribute10,
7492 pbl.attribute11,
7493 pbl.attribute12,
7494 pbl.attribute13,
7495 pbl.attribute14,
7496 pbl.attribute15,
7497 pbl.raw_cost_source,
7498 pbl.burdened_cost_source,
7499 pbl.quantity_source,
7500 pbl.revenue_source,
7501 pbl.pm_product_code,
7502 pbl.pm_budget_line_reference,
7503 pbl.cost_rejection_code,
7504 pbl.revenue_rejection_code,
7505 pbl.burden_rejection_code,
7506 pbl.other_rejection_code,
7507 pbl.code_combination_id,
7508 pbl.ccid_gen_status_code,
7509 pbl.ccid_gen_rej_message,
7510 pbl.request_id,
7511 pbl.borrowed_revenue,
7512 pbl.tp_revenue_in,
7513 pbl.tp_revenue_out,
7514 pbl.revenue_adj,
7515 pbl.lent_resource_cost,
7516 pbl.tp_cost_in,
7517 pbl.tp_cost_out,
7518 pbl.cost_adj,
7519 pbl.unassigned_time_cost,
7520 pbl.utilization_percent,
7521 pbl.utilization_hours,
7522 pbl.utilization_adj,
7523 pbl.capacity,
7524 pbl.head_count,
7525 pbl.head_count_adj,
7526 pbl.projfunc_currency_code,
7527 pbl.projfunc_cost_rate_type,
7528 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
7529 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
7530 'B',nvl(pbl.burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
7531 'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
7532 pbl.projfunc_cost_rate_date_type,
7533 pbl.projfunc_cost_rate_date,
7534 pbl.projfunc_rev_rate_type,
7535 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
7536 pbl.projfunc_rev_rate_date_type,
7537 pbl.projfunc_rev_rate_date,
7538 pbl.project_currency_code,
7539 pbl.project_cost_rate_type,
7540 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
7541 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
7542 'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
7543 'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
7544 pbl.project_cost_rate_date_type,
7545 pbl.project_cost_rate_date,
7546 pbl.project_raw_cost,
7547 pbl.project_burdened_cost,
7548 pbl.project_rev_rate_type,
7549 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.project_revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
7550 pbl.project_rev_rate_date_type,
7551 pbl.project_rev_rate_date,
7552 pbl.project_revenue,
7553 pbl.txn_currency_code,
7554 pbl.txn_raw_cost,
7555 pbl.txn_burdened_cost,
7556 pbl.txn_revenue,
7557 pbl.bucketing_period_code,
7558 pa_budget_lines_s.nextval,
7559 pbl.budget_version_id,
7560 pbl.txn_standard_cost_rate,
7561 DECODE(l_target_version_type,
7562 'REVENUE',pbl.txn_cost_rate_override,
7563 DECODE(l_targ_rate_based_flag_tbl(kk),
7564 'N',1,
7565 pbl.txn_cost_rate_override)),
7566 pbl.cost_ind_compiled_set_id,
7567 -- pbl. txn_burden_multiplier,
7568 -- pbl. txn_burden_multiplier_override,
7569 pbl.txn_standard_bill_rate,
7570 DECODE(l_target_version_type,
7571 'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
7572 'N',1,
7573 pbl.txn_bill_rate_override),
7574 pbl.txn_bill_rate_override),
7575 pbl.txn_markup_percent,
7576 pbl.txn_markup_percent_override,
7577 pbl.txn_discount_percentage,
7578 pbl.transfer_price_rate,
7579 pbl.burden_cost_rate,
7580 DECODE(l_target_version_type,
7581 'REVENUE',pbl.burden_cost_rate_override,
7582 DECODE(l_targ_rate_based_flag_tbl(kk),
7583 'Y',pbl.burden_cost_rate_override,
7584 DECODE(nvl(pbl.txn_raw_cost,0),
7585 0,null,
7586 pbl.txn_burdened_cost/pbl.txn_raw_cost))),
7587 pbl.pc_cur_conv_rejection_code,
7588 pbl.pfc_cur_conv_rejection_code
7589 FROM(SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id) resource_assignment_id,
7590 pbls.start_date start_date,
7591 sysdate last_update_date,
7592 fnd_global.user_id last_updated_by,
7593 sysdate creation_date,
7594 fnd_global.user_id created_by,
7595 fnd_global.login_id last_update_login,
7596 pbls.end_date end_date,
7597 pbls.period_name period_name,
7598 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7599 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)) quantity,
7600 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
7601 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
7602 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor revenue,
7603 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
7604 decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
7605 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
7606 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1,
7607 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2,
7608 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3,
7609 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4,
7610 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5,
7611 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6,
7612 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7,
7613 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8,
7614 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9,
7615 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null) attribute10,
7616 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null) attribute11,
7617 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null) attribute12,
7618 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null) attribute13,
7619 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null) attribute14,
7620 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null) attribute15,
7621 'I' raw_cost_source ,
7622 'I' burdened_cost_source,
7623 'I' quantity_source ,
7624 'I' revenue_source ,
7625 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
7626 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
7627 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
7628 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
7629 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
7630 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null) other_rejection_code,
7631 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
7632 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
7633 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
7634 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
7635 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
7636 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
7637 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
7638 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null) revenue_adj,
7639 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
7640 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
7641 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
7642 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
7643 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
7644 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
7645 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
7646 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
7647 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
7648 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
7649 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
7650 l_projfunc_currency_code projfunc_currency_code,
7651 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
7652 null projfunc_cost_exchange_rate, --Bug 3839273
7653 null projfunc_cost_rate_date_type,
7654 null projfunc_cost_rate_date,
7655 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
7656 null projfunc_rev_exchange_rate, --Bug 3839273
7657 null projfunc_rev_rate_date_type,
7658 null projfunc_rev_rate_date,
7659 l_project_currency_code project_currency_code,
7660 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
7661 null project_cost_exchange_rate, --Bug 3839273
7662 null project_cost_rate_date_type,
7663 null project_cost_rate_date,
7664 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)) project_raw_cost,
7665 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)) project_burdened_cost,
7666 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
7667 null project_rev_exchange_rate, --Bug 3839273
7668 null project_rev_rate_date_type,
7669 null project_rev_rate_date,
7670 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
7671 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,
7672
7673
7674 --Bug 4224757.. Code changes for bug#4224757 starts here
7675 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
7676 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
7677 txn_raw_cost,
7678 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
7679 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
7680 nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
7681 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
7682 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
7683 nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
7684 --Bug 4224757.. Code changes for bug#4224757 ends here
7685
7686 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null) bucketing_period_code,
7687 p_budget_version_id budget_version_id,
7688 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,
7689
7690 --Bug 4224757. Code changes for bug#4224757 starts here
7691 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
7692 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
7693 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
7694 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7695 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_cost_rate_override,
7696 --Bug 4224757. Code changes for bug#4224757 ends here
7697
7698
7699
7700 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
7701 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
7702
7703 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate,
7704
7705 --Bug 4224757. Code changes for bug#4224757 starts here
7706 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
7707 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
7708 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
7709 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7710 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_bill_rate_override,
7711 --Bug 4224757. Code changes for bug#4224757 ends here
7712
7713 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
7714 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
7715 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
7716 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
7717 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,
7718
7719 --Bug 4224757. Code changes for bug#4224757 starts here
7720 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
7721 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag,
7722 'Y', nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
7723 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
7724 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
7725 --Bug 4224757. Code changes for bug#4224757 ends here
7726
7727
7728 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
7729 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
7730 from pa_budget_lines pbls,
7731 pa_resource_assignments pras
7732 where l_ra_dml_code_tbl(kk)='INSERT'
7733 and pras.budget_version_id = l_src_ver_id_tbl(j)
7734 and pras.resource_assignment_id = pbls.resource_assignment_id
7735 and get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id)=L_targ_ra_id_tbl(kk)
7736 --IPM Arch Enhancement Bug 4865563
7737 /*and pbls.cost_rejection_code IS NULL
7738 and pbls.revenue_rejection_code IS NULL
7739 and pbls.burden_rejection_code IS NULL
7740 and pbls.other_rejection_code IS NULL
7741 and pbls.pc_cur_conv_rejection_code IS NULL
7742 and pbls.pfc_cur_conv_rejection_code IS NULL*/
7743 and pbls.start_date >= nvl(l_etc_start_date,pbls.start_date)
7744 GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id),pras.resource_list_member_id) ,
7745 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
7746 ,pbls.start_date,pbls.end_date,pbls.period_name)pbl;
7747
7748 IF P_PA_debug_mode = 'Y' THEN
7749 pa_debug.g_err_stage:= 'SRC tp =targ TP. same RLS.Done with bulk insert BLs';
7750 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
7751 END IF;
7752 --dbms_output.put_line('I31');
7753
7754 ELSE
7755 IF P_PA_debug_mode = 'Y' THEN
7756 pa_debug.g_err_stage:= 'About to bulk insert Budget lines with different RLs and TP not N and src Tp= targ TP';
7757 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
7758
7759 END IF;
7760
7761 --dbms_output.put_line('I32');
7762 FORALL kk in L_targ_ra_id_tbl.FIRST ..L_targ_ra_id_tbl.LAST
7763 INSERT INTO PA_BUDGET_LINES(
7764 RESOURCE_ASSIGNMENT_ID,
7765 START_DATE,
7766 LAST_UPDATE_DATE,
7767 LAST_UPDATED_BY,
7768 CREATION_DATE,
7769 CREATED_BY,
7770 LAST_UPDATE_LOGIN,
7771 END_DATE,
7772 PERIOD_NAME,
7773 QUANTITY,
7774 RAW_COST,
7775 BURDENED_COST,
7776 REVENUE,
7777 CHANGE_REASON_CODE,
7778 DESCRIPTION,
7779 ATTRIBUTE_CATEGORY,
7780 ATTRIBUTE1,
7781 ATTRIBUTE2,
7782 ATTRIBUTE3,
7783 ATTRIBUTE4,
7784 ATTRIBUTE5,
7785 ATTRIBUTE6,
7786 ATTRIBUTE7,
7787 ATTRIBUTE8,
7788 ATTRIBUTE9,
7789 ATTRIBUTE10,
7790 ATTRIBUTE11,
7791 ATTRIBUTE12,
7792 ATTRIBUTE13,
7793 ATTRIBUTE14,
7794 ATTRIBUTE15,
7795 RAW_COST_SOURCE,
7796 BURDENED_COST_SOURCE,
7797 QUANTITY_SOURCE,
7798 REVENUE_SOURCE,
7799 PM_PRODUCT_CODE,
7800 PM_BUDGET_LINE_REFERENCE,
7801 COST_REJECTION_CODE,
7802 REVENUE_REJECTION_CODE,
7803 BURDEN_REJECTION_CODE,
7804 OTHER_REJECTION_CODE,
7805 CODE_COMBINATION_ID,
7806 CCID_GEN_STATUS_CODE,
7807 CCID_GEN_REJ_MESSAGE,
7808 REQUEST_ID,
7809 BORROWED_REVENUE,
7810 TP_REVENUE_IN,
7811 TP_REVENUE_OUT,
7812 REVENUE_ADJ,
7813 LENT_RESOURCE_COST,
7814 TP_COST_IN,
7815 TP_COST_OUT,
7816 COST_ADJ,
7817 UNASSIGNED_TIME_COST,
7818 UTILIZATION_PERCENT,
7819 UTILIZATION_HOURS,
7820 UTILIZATION_ADJ,
7821 CAPACITY,
7822 HEAD_COUNT,
7823 HEAD_COUNT_ADJ,
7824 PROJFUNC_CURRENCY_CODE,
7825 PROJFUNC_COST_RATE_TYPE,
7826 PROJFUNC_COST_EXCHANGE_RATE,
7827 PROJFUNC_COST_RATE_DATE_TYPE,
7828 PROJFUNC_COST_RATE_DATE,
7829 PROJFUNC_REV_RATE_TYPE,
7830 PROJFUNC_REV_EXCHANGE_RATE,
7831 PROJFUNC_REV_RATE_DATE_TYPE,
7832 PROJFUNC_REV_RATE_DATE,
7833 PROJECT_CURRENCY_CODE,
7834 PROJECT_COST_RATE_TYPE,
7835 PROJECT_COST_EXCHANGE_RATE,
7836 PROJECT_COST_RATE_DATE_TYPE,
7837 PROJECT_COST_RATE_DATE,
7838 PROJECT_RAW_COST,
7839 PROJECT_BURDENED_COST,
7840 PROJECT_REV_RATE_TYPE,
7841 PROJECT_REV_EXCHANGE_RATE,
7842 PROJECT_REV_RATE_DATE_TYPE,
7843 PROJECT_REV_RATE_DATE,
7844 PROJECT_REVENUE,
7845 TXN_CURRENCY_CODE,
7846 TXN_RAW_COST,
7847 TXN_BURDENED_COST,
7848 TXN_REVENUE,
7849 BUCKETING_PERIOD_CODE,
7850 BUDGET_LINE_ID,
7851 BUDGET_VERSION_ID,
7852 TXN_STANDARD_COST_RATE,
7853 TXN_COST_RATE_OVERRIDE,
7854 COST_IND_COMPILED_SET_ID,
7855 -- TXN_BURDEN_MULTIPLIER,
7856 -- TXN_BURDEN_MULTIPLIER_OVERRIDE,
7857 TXN_STANDARD_BILL_RATE,
7858 TXN_BILL_RATE_OVERRIDE,
7859 TXN_MARKUP_PERCENT,
7860 TXN_MARKUP_PERCENT_OVERRIDE,
7861 TXN_DISCOUNT_PERCENTAGE,
7862 TRANSFER_PRICE_RATE,
7863 BURDEN_COST_RATE,
7864 BURDEN_COST_RATE_OVERRIDE,
7865 PC_CUR_CONV_REJECTION_CODE,
7866 PFC_CUR_CONV_REJECTION_CODE
7867 )
7868 SELECT pbl.resource_assignment_id,
7869 pbl.start_date,
7870 pbl.last_update_date,
7871 pbl.last_updated_by,
7872 pbl.creation_date,
7873 pbl.created_by,
7874 pbl.last_update_login,
7875 pbl.end_date,
7876 pbl.period_name,
7877 DECODE(l_targ_rate_based_flag_tbl(kk),
7878 'N',DECODE(l_target_version_type,
7879 'REVENUE',pbl.txn_revenue
7880 ,pbl.txn_raw_cost),
7881 pbl.quantity),
7882 pbl.raw_cost,
7883 pbl.burdened_cost,
7884 pbl.revenue,
7885 pbl.change_reason_code,
7886 pbl.description,
7887 pbl.attribute_category,
7888 pbl.attribute1,
7889 pbl.attribute2,
7890 pbl.attribute3,
7891 pbl.attribute4,
7892 pbl.attribute5,
7893 pbl.attribute6,
7894 pbl.attribute7,
7895 pbl.attribute8,
7896 pbl.attribute9,
7897 pbl.attribute10,
7898 pbl.attribute11,
7899 pbl.attribute12,
7900 pbl.attribute13,
7901 pbl.attribute14,
7902 pbl.attribute15,
7903 pbl.raw_cost_source,
7904 pbl.burdened_cost_source,
7905 pbl.quantity_source,
7906 pbl.revenue_source,
7907 pbl.pm_product_code,
7908 pbl.pm_budget_line_reference,
7909 pbl.cost_rejection_code,
7910 pbl.revenue_rejection_code,
7911 pbl.burden_rejection_code,
7912 pbl.other_rejection_code,
7913 pbl.code_combination_id,
7914 pbl.ccid_gen_status_code,
7915 pbl.ccid_gen_rej_message,
7916 pbl.request_id,
7917 pbl.borrowed_revenue,
7918 pbl.tp_revenue_in,
7919 pbl.tp_revenue_out,
7920 pbl.revenue_adj,
7921 pbl.lent_resource_cost,
7922 pbl.tp_cost_in,
7923 pbl.tp_cost_out,
7924 pbl.cost_adj,
7925 pbl.unassigned_time_cost,
7926 pbl.utilization_percent,
7927 pbl.utilization_hours,
7928 pbl.utilization_adj,
7929 pbl.capacity,
7930 pbl.head_count,
7931 pbl.head_count_adj,
7932 pbl.projfunc_currency_code,
7933 pbl.projfunc_cost_rate_type,
7934 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
7935 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
7936 'B',nvl(pbl.burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
7937 'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
7938 pbl.projfunc_cost_rate_date_type,
7939 pbl.projfunc_cost_rate_date,
7940 pbl.projfunc_rev_rate_type,
7941 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
7942 pbl.projfunc_rev_rate_date_type,
7943 pbl.projfunc_rev_rate_date,
7944 pbl.project_currency_code,
7945 pbl.project_cost_rate_type,
7946 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
7947 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
7948 'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
7949 'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
7950 pbl.project_cost_rate_date_type,
7951 pbl.project_cost_rate_date,
7952 pbl.project_raw_cost,
7953 pbl.project_burdened_cost,
7954 pbl.project_rev_rate_type,
7955 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.project_revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
7956 pbl.project_rev_rate_date_type,
7957 pbl.project_rev_rate_date,
7958 pbl.project_revenue,
7959 pbl.txn_currency_code,
7960 pbl.txn_raw_cost,
7961 pbl.txn_burdened_cost,
7962 pbl.txn_revenue,
7963 pbl.bucketing_period_code,
7964 pa_budget_lines_s.nextval,
7965 pbl.budget_version_id,
7966 pbl.txn_standard_cost_rate,
7967 DECODE(l_target_version_type,
7968 'REVENUE',pbl.txn_cost_rate_override,
7969 DECODE(l_targ_rate_based_flag_tbl(kk),
7970 'N',1,
7971 pbl.txn_cost_rate_override)),
7972 pbl.cost_ind_compiled_set_id,
7973 -- pbl. txn_burden_multiplier,
7974 -- pbl. txn_burden_multiplier_override,
7975 pbl.txn_standard_bill_rate,
7976 DECODE(l_target_version_type,
7977 'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
7978 'N',1,
7979 pbl.txn_bill_rate_override),
7980 pbl.txn_bill_rate_override),
7981 pbl.txn_markup_percent,
7982 pbl.txn_markup_percent_override,
7983 pbl.txn_discount_percentage,
7984 pbl.transfer_price_rate,
7985 pbl.burden_cost_rate,
7986 DECODE(l_target_version_type,
7987 'REVENUE',pbl.burden_cost_rate_override,
7988 DECODE(l_targ_rate_based_flag_tbl(kk),
7989 'Y',pbl.burden_cost_rate_override,
7990 DECODE(nvl(pbl.txn_raw_cost,0),
7991 0,null,
7992 pbl.txn_burdened_cost/pbl.txn_raw_cost))),
7993 pbl.pc_cur_conv_rejection_code,
7994 pbl.pfc_cur_conv_rejection_code
7995 FROM(SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,rlmap.task_id), rlmap.resource_list_member_id) resource_assignment_id,
7996 pbls.start_date start_date,
7997 sysdate last_update_date,
7998 fnd_global.user_id last_updated_by,
7999 sysdate creation_date,
8000 fnd_global.user_id created_by,
8001 fnd_global.login_id last_update_login,
8002 pbls.end_date end_date,
8003 pbls.period_name period_name,
8004 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8005 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)) quantity,
8006 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
8007 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
8008 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor revenue,
8009 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
8010 decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
8011 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
8012 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1,
8013 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2,
8014 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3,
8015 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4,
8016 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5,
8017 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6,
8018 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7,
8019 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8,
8020 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9,
8021 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null) attribute10,
8022 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null) attribute11,
8023 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null) attribute12,
8024 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null) attribute13,
8025 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null) attribute14,
8026 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null) attribute15,
8027 'I' raw_cost_source ,
8028 'I' burdened_cost_source,
8029 'I' quantity_source ,
8030 'I' revenue_source ,
8031 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
8032 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
8033 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
8034 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
8035 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
8036 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null) other_rejection_code,
8037 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
8038 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
8039 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
8040 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
8041 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
8042 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
8043 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
8044 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null) revenue_adj,
8045 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
8046 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
8047 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
8048 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
8049 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
8050 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
8051 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
8052 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
8053 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
8054 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
8055 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
8056 l_projfunc_currency_code projfunc_currency_code,
8057 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
8058 null projfunc_cost_exchange_rate, --Bug 3839273
8059 null projfunc_cost_rate_date_type,
8060 null projfunc_cost_rate_date,
8061 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
8062 null projfunc_rev_exchange_rate, --Bug 3839273
8063 null projfunc_rev_rate_date_type,
8064 null projfunc_rev_rate_date,
8065 l_project_currency_code project_currency_code,
8066 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
8067 null project_cost_exchange_rate, --Bug 3839273
8068 null project_cost_rate_date_type,
8069 null project_cost_rate_date,
8070 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost, null)) project_raw_cost,
8071 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost, null)) project_burdened_cost,
8072 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
8073 null project_rev_exchange_rate, --Bug 3839273
8074 null project_rev_rate_date_type ,
8075 null project_rev_rate_date ,
8076 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
8077 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,
8078
8079
8080 --Bug 4224757.. Code changes for bug#4224757 starts here
8081 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
8082 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
8083 txn_raw_cost,
8084 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
8085 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
8086 nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
8087 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
8088 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
8089 nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
8090 --Bug 4224757.. Code changes for bug#4224757 ends here
8091
8092 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null) bucketing_period_code,
8093 p_budget_version_id budget_version_id,
8094 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,
8095
8096 --Bug 4224757. Code changes for bug#4224757 starts here
8097 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8098 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8099 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
8100 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8101 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_cost_rate_override,
8102 --Bug 4224757. Code changes for bug#4224757 ends here
8103
8104 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
8105 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
8106
8107 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate,
8108
8109 --Bug 4224757. Code changes for bug#4224757 starts here
8110 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
8111 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
8112 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
8113 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8114 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_bill_rate_override,
8115 --Bug 4224757. Code changes for bug#4224757 ends here
8116
8117 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
8118 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
8119 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
8120 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
8121 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,
8122
8123 --Bug 4224757. Code changes for bug#4224757 starts here
8124 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8125 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8126 nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
8127 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8128 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
8129 --Bug 4224757. Code changes for bug#4224757 ends here
8130
8131 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
8132 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
8133 from pa_budget_lines pbls,
8134 (SELECT pra.task_id task_id,
8135 tmp4.resource_list_member_id resource_list_member_id,
8136 tmp4.txn_source_id resource_assignment_id
8137 FROM pa_resource_assignments pra,
8138 pa_res_list_map_tmp4 tmp4
8139 WHERE tmp4.txn_source_id=pra.resource_assignment_id) rlmap
8140 where l_ra_dml_code_tbl(kk)='INSERT'
8141 and rlmap.resource_assignment_id = pbls.resource_assignment_id
8142 and get_mapped_ra_id(get_task_id(l_targ_plan_level_code,rlmap.task_id), rlmap.resource_list_member_id)=L_targ_ra_id_tbl(kk)
8143 --IPM Arch Enhancement Bug 4865563
8144 /*and pbls.cost_rejection_code IS NULL
8145 and pbls.revenue_rejection_code IS NULL
8146 and pbls.burden_rejection_code IS NULL
8147 and pbls.other_rejection_code IS NULL
8148 and pbls.pc_cur_conv_rejection_code IS NULL
8149 and pbls.pfc_cur_conv_rejection_code IS NULL*/
8150 and pbls.start_date >= nvl(l_etc_start_date, pbls.start_date)
8151 GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,rlmap.task_id),rlmap.resource_list_member_id) ,
8152 DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
8153 ,pbls.start_date,pbls.end_date,pbls.period_name)pbl;
8154
8155 IF P_PA_debug_mode = 'Y' THEN
8156 pa_debug.g_err_stage:= 'Done with bulk insert Budget lines with different RLs and TP not N and src Tp= targ TP'||SQL%ROWCOUNT;
8157 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8158 END IF;
8159 --dbms_output.put_line('I33');
8160 END IF;
8161 END IF;
8162 --Update
8163
8164 IF l_targ_time_phased_code = 'N' THEN
8165 IF l_src_resource_list_id = l_targ_resource_list_id THEN
8166 IF P_PA_debug_mode = 'Y' THEN
8167 pa_debug.g_err_stage:= 'About to bulk insert resource assignments';
8168 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8169 END IF;
8170
8171 --dbms_output.put_line('I34');
8172 SELECT get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code),
8173 decode(pblt.resource_assignment_id,null, 'INSERT',
8174 decode(pblt.txn_currency_code, null,'INSERT','UPDATE')),
8175 decode(pblt.resource_assignment_id,null, prat.planning_start_date,
8176 decode(pblt.txn_currency_code, null,prat.planning_start_date,pblt.start_date)),
8177 decode(pblt.resource_assignment_id,null, prat.planning_end_date,
8178 decode(pblt.txn_currency_code, null,prat.planning_end_date,pblt.end_date)),
8179 NULL,
8180 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8181 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
8182 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)),
8183 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)),
8184 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor,
8185 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
8186 decode(count(pbls.budget_line_id),1,max(pbls.description),null),
8187 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
8188 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
8189 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
8190 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
8191 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
8192 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
8193 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
8194 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
8195 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
8196
8197 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
8198 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
8199 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
8200 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
8201 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
8202 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
8203 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
8204 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
8205 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
8206 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
8207 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
8208 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
8209 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
8210 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
8211 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
8212 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
8213 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
8214 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
8215 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
8216 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
8217 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
8218 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
8219 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
8220 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
8221 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
8222 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
8223 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
8224 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
8225 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
8226 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
8227 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
8228 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
8229 l_projfunc_currency_code,
8230 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
8231 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
8232 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
8233 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
8234 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
8235 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
8236 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
8237 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
8238 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
8239 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)),
8240 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost, null)),
8241 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
8242 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
8243 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
8244 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
8245 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
8246
8247
8248 --Bug 4224757.. Code changes for bug#4224757 starts here
8249 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
8250 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))) ,
8251 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
8252 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
8253 nvl(pbls.project_burdened_cost,0))))) ,
8254 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
8255 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
8256 nvl(pbls.project_revenue,0)))))*l_partial_factor ,
8257 --Bug 4224757.. Code changes for bug#4224757 ends here
8258
8259 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
8260 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),
8261
8262 --Bug 4224757. Code changes for bug#4224757 starts here
8263 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8264 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8265 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
8266 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8267 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
8268 --Bug 4224757. Code changes for bug#4224757 ends here
8269
8270 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
8271 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
8272
8273 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),
8274
8275 --Bug 4224757. Code changes for bug#4224757 starts here
8276 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
8277 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
8278 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
8279 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8280 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
8281 --Bug 4224757. Code changes for bug#4224757 ends here
8282
8283 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
8284 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
8285 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
8286 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
8287 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),
8288
8289
8290 --Bug 4224757. Code changes for bug#4224757 starts here
8291 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8292 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8293 nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
8294 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8295 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
8296 --Bug 4224757. Code changes for bug#4224757 ends here
8297
8298 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
8299 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
8300 BULK COLLECT INTO
8301 l_bl_RESOURCE_ASIGNMENT_ID_tbl,
8302 l_upd_ra_bl_dml_code_tbl,
8303 l_bl_START_DATE_tbl,
8304 l_bl_END_DATE_tbl,
8305 l_bl_PERIOD_NAME_tbl,
8306 l_bl_QUANTITY_tbl,
8307 l_bl_RAW_COST_tbl,
8308 l_bl_BURDENED_COST_tbl,
8309 l_bl_REVENUE_tbl,
8310 l_bl_CHANGE_REASON_CODE_tbl,
8311 l_bl_DESCRIPTION_tbl,
8312 l_bl_ATTRIBUTE_CATEGORY_tbl,
8313 l_bl_ATTRIBUTE1_tbl,
8314 l_bl_ATTRIBUTE2_tbl,
8315 l_bl_ATTRIBUTE3_tbl,
8316 l_bl_ATTRIBUTE4_tbl,
8317 l_bl_ATTRIBUTE5_tbl,
8318 l_bl_ATTRIBUTE6_tbl,
8319 l_bl_ATTRIBUTE7_tbl,
8320 l_bl_ATTRIBUTE8_tbl,
8321 l_bl_ATTRIBUTE9_tbl,
8322 l_bl_ATTRIBUTE10_tbl,
8323 l_bl_ATTRIBUTE11_tbl,
8324 l_bl_ATTRIBUTE12_tbl,
8325 l_bl_ATTRIBUTE13_tbl,
8326 l_bl_ATTRIBUTE14_tbl,
8327 l_bl_ATTRIBUTE15_tbl,
8328 l_bl_PM_PRODUCT_CODE_tbl,
8329 l_bl_PM_BUDGET_LINE_REF_tbl,
8330 l_bl_COST_REJECTION_CODE_tbl,
8331 l_bl_REVENUE_REJ_CODE_tbl,
8332 l_bl_BURDEN_REJECTION_CODE_tbl,
8333 l_bl_OTHER_REJECTION_CODE_tbl,
8334 l_bl_CODE_COMBINATION_ID_tbl,
8335 l_bl_CCID_GEN_STATUS_CODE_tbl,
8336 l_bl_CCID_GEN_REJ_MESSAGE_tbl,
8337 l_bl_REQUEST_ID_tbl,
8338 l_bl_BORROWED_REVENUE_tbl,
8339 l_bl_TP_REVENUE_IN_tbl,
8340 l_bl_TP_REVENUE_OUT_tbl,
8341 l_bl_REVENUE_ADJ_tbl,
8342 l_bl_LENT_RESOURCE_COST_tbl,
8343 l_bl_TP_COST_IN_tbl,
8344 l_bl_TP_COST_OUT_tbl,
8345 l_bl_COST_ADJ_tbl,
8346 l_bl_UNASSIGNED_TIME_COST_tbl,
8347 l_bl_UTILIZATION_PERCENT_tbl,
8348 l_bl_UTILIZATION_HOURS_tbl,
8349 l_bl_UTILIZATION_ADJ_tbl,
8350 l_bl_CAPACITY_tbl,
8351 l_bl_HEAD_COUNT_tbl,
8352 l_bl_HEAD_COUNT_ADJ_tbl,
8353 l_bl_PROJFUNC_CUR_CODE_tbl,
8354 l_bl_PROJFUNC_COST_RAT_TYP_tbl,
8355 l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
8356 l_bl_PROJFUNC_COST_RAT_DAT_tbl,
8357 l_bl_PROJFUNC_REV_RATE_TYP_tbl,
8358 l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
8359 l_bl_PROJFUNC_REV_RAT_DATE_tbl,
8360 l_bl_PROJECT_COST_RAT_TYPE_tbl,
8361 l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
8362 l_bl_PROJ_COST_RATE_DATE_tbl,
8363 l_bl_PROJECT_RAW_COST_tbl,
8364 l_bl_PROJECT_BURDENED_COST_tbl,
8365 l_bl_PROJECT_REV_RATE_TYPE_tbl,
8366 l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
8367 l_bl_PROJECT_REV_RATE_DATE,
8368 l_bl_PROJECT_REVENUE_tbl,
8369 l_bl_TXN_CURRENCY_CODE_tbl,
8370 l_bl_TXN_RAW_COST_tbl,
8371 l_bl_TXN_BURDENED_COST_tbl,
8372 l_bl_TXN_REVENUE_tbl,
8373 l_bl_BUCKETING_PERIOD_CODE_tbl,
8374 l_bl_TXN_STD_COST_RATE_tbl,
8375 l_bl_TXN_COST_RATE_OVERIDE_tbl,
8376 l_bl_COST_IND_CMPLD_SET_ID_tbl,
8377 -- l_bl_TXN_BURDEN_MULTIPLIER_tbl,
8378 -- l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
8379 l_bl_TXN_STD_BILL_RATE_tbl,
8380 l_bl_TXN_BILL_RATE_OVERRID_tbl,
8381 l_bl_TXN_MARKUP_PERCENT_tbl,
8382 l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
8383 l_bl_TXN_DISC_PERCENTAGE_tbl,
8384 l_bl_TRANSFER_PRICE_RATE_tbl,
8385 l_bl_BURDEN_COST_RATE_tbl,
8386 l_bl_BURDEN_COST_RAT_OVRID_tbl,
8387 l_bl_PC_CUR_CONV_REJ_CODE_tbl,
8388 l_bl_PFC_CUR_CONV_REJ_CODE_tbl
8389 from pa_budget_lines pbls,
8390 pa_budget_lines pblt,
8391 pa_resource_assignments prat
8392 where get_mapped_dml_code(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)='UPDATE'
8393 and pbls.budget_version_id = l_src_ver_id_tbl(j)
8394 and pblt.budget_version_id(+) = p_budget_version_id
8395 and pblt.resource_assignment_id(+)=get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)
8396 AND pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
8397 DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
8398 and prat.resource_assignment_id = get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)
8399 --IPM Arch Enhancement Bug 4865563
8400 /*and pbls.cost_rejection_code IS NULL
8401 and pbls.revenue_rejection_code IS NULL
8402 and pbls.burden_rejection_code IS NULL
8403 and pbls.other_rejection_code IS NULL
8404 and pbls.pc_cur_conv_rejection_code IS NULL
8405 and pbls.pfc_cur_conv_rejection_code IS NULL*/
8406 GROUP BY get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code),
8407 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
8408 pblt.resource_assignment_id,
8409 pblt.txn_currency_code,
8410 pblt.start_date,
8411 pblt.end_date,
8412 prat.planning_start_date,
8413 prat.planning_end_date;
8414
8415 --dbms_output.put_line('I35');
8416
8417 ELSE--Resource lists are different , target time phasing is N and the target resource assignments already exist in prat
8418 IF P_PA_debug_mode = 'Y' THEN
8419 pa_debug.g_err_stage:= 'About to bulk select for ins/upd the budget lins with targ NTP and Diff RLS';
8420 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8421 END IF;
8422 --dbms_output.put_line('I36');
8423
8424 SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id),
8425 decode(pblt.resource_assignment_id,null, 'INSERT',
8426 decode(pblt.txn_currency_code, null,'INSERT','UPDATE')),
8427 decode(pblt.resource_assignment_id,null, prat.planning_start_date,
8428 decode(pblt.txn_currency_code, null,prat.planning_start_date,pblt.start_date)),
8429 decode(pblt.resource_assignment_id,null, prat.planning_end_date,
8430 decode(pblt.txn_currency_code, null,prat.planning_end_date,pblt.end_date)),
8431 NULL,
8432 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8433 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
8434 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)),
8435 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)),
8436 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor,
8437 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
8438 decode(count(pbls.budget_line_id),1,max(pbls.description),null),
8439 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
8440 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
8441 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
8442 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
8443 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
8444 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
8445 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
8446 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
8447 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
8448 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
8449 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
8450 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
8451 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
8452 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
8453 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
8454 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
8455 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
8456 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
8457 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
8458 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
8459 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
8460 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
8461 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
8462 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
8463 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
8464 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
8465 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
8466 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
8467 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
8468 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
8469 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
8470 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
8471 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
8472 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
8473 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
8474 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
8475 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
8476 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
8477 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
8478 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
8479 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
8480 l_projfunc_currency_code,
8481 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
8482 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
8483 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
8484 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
8485 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
8486 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
8487 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
8488 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
8489 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
8490 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost, null)),
8491 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)),
8492 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
8493 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
8494 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
8495 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
8496 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
8497
8498
8499 --Bug 4224757.. Code changes for bug#4224757 starts here
8500 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
8501 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))),
8502 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
8503 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
8504 nvl(pbls.project_burdened_cost,0))))) ,
8505 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
8506 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
8507 nvl(pbls.project_revenue,0)))))*l_partial_factor ,
8508 --Bug 4224757.. Code changes for bug#4224757 ends here
8509
8510 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
8511 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),
8512
8513 --Bug 4224757. Code changes for bug#4224757 starts here
8514 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8515 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8516 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
8517 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8518 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
8519 --Bug 4224757. Code changes for bug#4224757 ends here
8520
8521 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
8522 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
8523
8524 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),
8525
8526 --Bug 4224757. Code changes for bug#4224757 starts here
8527 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
8528 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
8529 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
8530 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8531 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
8532 --Bug 4224757. Code changes for bug#4224757 ends here
8533
8534 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
8535 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
8536 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
8537 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
8538 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),
8539
8540 --Bug 4224757. Code changes for bug#4224757 starts here
8541 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8542 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8543 nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
8544 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8545 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
8546 --Bug 4224757. Code changes for bug#4224757 ends here
8547
8548 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
8549 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
8550 BULK COLLECT INTO
8551 l_bl_RESOURCE_ASIGNMENT_ID_tbl,
8552 l_upd_ra_bl_dml_code_tbl,
8553 l_bl_START_DATE_tbl,
8554 l_bl_END_DATE_tbl,
8555 l_bl_PERIOD_NAME_tbl,
8556 l_bl_QUANTITY_tbl,
8557 l_bl_RAW_COST_tbl,
8558 l_bl_BURDENED_COST_tbl,
8559 l_bl_REVENUE_tbl,
8560 l_bl_CHANGE_REASON_CODE_tbl,
8561 l_bl_DESCRIPTION_tbl,
8562 l_bl_ATTRIBUTE_CATEGORY_tbl,
8563 l_bl_ATTRIBUTE1_tbl,
8564 l_bl_ATTRIBUTE2_tbl,
8565 l_bl_ATTRIBUTE3_tbl,
8566 l_bl_ATTRIBUTE4_tbl,
8567 l_bl_ATTRIBUTE5_tbl,
8568 l_bl_ATTRIBUTE6_tbl,
8569 l_bl_ATTRIBUTE7_tbl,
8570 l_bl_ATTRIBUTE8_tbl,
8571 l_bl_ATTRIBUTE9_tbl,
8572 l_bl_ATTRIBUTE10_tbl,
8573 l_bl_ATTRIBUTE11_tbl,
8574 l_bl_ATTRIBUTE12_tbl,
8575 l_bl_ATTRIBUTE13_tbl,
8576 l_bl_ATTRIBUTE14_tbl,
8577 l_bl_ATTRIBUTE15_tbl,
8578 l_bl_PM_PRODUCT_CODE_tbl,
8579 l_bl_PM_BUDGET_LINE_REF_tbl,
8580 l_bl_COST_REJECTION_CODE_tbl,
8581 l_bl_REVENUE_REJ_CODE_tbl,
8582 l_bl_BURDEN_REJECTION_CODE_tbl,
8583 l_bl_OTHER_REJECTION_CODE_tbl,
8584 l_bl_CODE_COMBINATION_ID_tbl,
8585 l_bl_CCID_GEN_STATUS_CODE_tbl,
8586 l_bl_CCID_GEN_REJ_MESSAGE_tbl,
8587 l_bl_REQUEST_ID_tbl,
8588 l_bl_BORROWED_REVENUE_tbl,
8589 l_bl_TP_REVENUE_IN_tbl,
8590 l_bl_TP_REVENUE_OUT_tbl,
8591 l_bl_REVENUE_ADJ_tbl,
8592 l_bl_LENT_RESOURCE_COST_tbl,
8593 l_bl_TP_COST_IN_tbl,
8594 l_bl_TP_COST_OUT_tbl,
8595 l_bl_COST_ADJ_tbl,
8596 l_bl_UNASSIGNED_TIME_COST_tbl,
8597 l_bl_UTILIZATION_PERCENT_tbl,
8598 l_bl_UTILIZATION_HOURS_tbl,
8599 l_bl_UTILIZATION_ADJ_tbl,
8600 l_bl_CAPACITY_tbl,
8601 l_bl_HEAD_COUNT_tbl,
8602 l_bl_HEAD_COUNT_ADJ_tbl,
8603 l_bl_PROJFUNC_CUR_CODE_tbl,
8604 l_bl_PROJFUNC_COST_RAT_TYP_tbl,
8605 l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
8606 l_bl_PROJFUNC_COST_RAT_DAT_tbl,
8607 l_bl_PROJFUNC_REV_RATE_TYP_tbl,
8608 l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
8609 l_bl_PROJFUNC_REV_RAT_DATE_tbl,
8610 l_bl_PROJECT_COST_RAT_TYPE_tbl,
8611 l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
8612 l_bl_PROJ_COST_RATE_DATE_tbl,
8613 l_bl_PROJECT_RAW_COST_tbl,
8614 l_bl_PROJECT_BURDENED_COST_tbl,
8615 l_bl_PROJECT_REV_RATE_TYPE_tbl,
8616 l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
8617 l_bl_PROJECT_REV_RATE_DATE,
8618 l_bl_PROJECT_REVENUE_tbl,
8619 l_bl_TXN_CURRENCY_CODE_tbl,
8620 l_bl_TXN_RAW_COST_tbl,
8621 l_bl_TXN_BURDENED_COST_tbl,
8622 l_bl_TXN_REVENUE_tbl,
8623 l_bl_BUCKETING_PERIOD_CODE_tbl,
8624 l_bl_TXN_STD_COST_RATE_tbl,
8625 l_bl_TXN_COST_RATE_OVERIDE_tbl,
8626 l_bl_COST_IND_CMPLD_SET_ID_tbl,
8627 -- l_bl_TXN_BURDEN_MULTIPLIER_tbl,
8628 -- l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
8629 l_bl_TXN_STD_BILL_RATE_tbl,
8630 l_bl_TXN_BILL_RATE_OVERRID_tbl,
8631 l_bl_TXN_MARKUP_PERCENT_tbl,
8632 l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
8633 l_bl_TXN_DISC_PERCENTAGE_tbl,
8634 l_bl_TRANSFER_PRICE_RATE_tbl,
8635 l_bl_BURDEN_COST_RATE_tbl,
8636 l_bl_BURDEN_COST_RAT_OVRID_tbl,
8637 l_bl_PC_CUR_CONV_REJ_CODE_tbl,
8638 l_bl_PFC_CUR_CONV_REJ_CODE_tbl
8639 from pa_budget_lines pblt,
8640 pa_resource_assignments prat,
8641 (SELECT pbls.resource_assignment_id
8642 ,pbls.start_date
8643 ,pbls.last_update_date
8644 ,pbls.last_updated_by
8645 ,pbls.creation_date
8646 ,pbls.created_by
8647 ,pbls.last_update_login
8648 ,pbls.end_date
8649 ,pbls.period_name
8650 ,pbls.quantity
8651 ,pbls.raw_cost
8652 ,pbls.burdened_cost
8653 ,pbls.revenue
8654 ,pbls.change_reason_code
8655 ,pbls.description
8656 ,pbls.attribute_category
8657 ,pbls.attribute1
8658 ,pbls.attribute2
8659 ,pbls.attribute3
8660 ,pbls.attribute4
8661 ,pbls.attribute5
8662 ,pbls.attribute6
8663 ,pbls.attribute7
8664 ,pbls.attribute8
8665 ,pbls.attribute9
8666 ,pbls.attribute10
8667 ,pbls.attribute11
8668 ,pbls.attribute12
8669 ,pbls.attribute13
8670 ,pbls.attribute14
8671 ,pbls.attribute15
8672 ,pbls.raw_cost_source
8673 ,pbls.burdened_cost_source
8674 ,pbls.quantity_source
8675 ,pbls.revenue_source
8676 ,pbls.pm_product_code
8677 ,pbls.pm_budget_line_reference
8678 ,pbls.cost_rejection_code
8679 ,pbls.revenue_rejection_code
8680 ,pbls.burden_rejection_code
8681 ,pbls.other_rejection_code
8682 ,pbls.code_combination_id
8683 ,pbls.ccid_gen_status_code
8684 ,pbls.ccid_gen_rej_message
8685 ,pbls.request_id
8686 ,pbls.borrowed_revenue
8687 ,pbls.tp_revenue_in
8688 ,pbls.tp_revenue_out
8689 ,pbls.revenue_adj
8690 ,pbls.lent_resource_cost
8691 ,pbls.tp_cost_in
8692 ,pbls.tp_cost_out
8693 ,pbls.cost_adj
8694 ,pbls.unassigned_time_cost
8695 ,pbls.utilization_percent
8696 ,pbls.utilization_hours
8697 ,pbls.utilization_adj
8698 ,pbls.capacity
8699 ,pbls.head_count
8700 ,pbls.head_count_adj
8701 ,pbls.projfunc_currency_code
8702 ,pbls.projfunc_cost_rate_type
8703 ,pbls.projfunc_cost_exchange_rate
8704 ,pbls.projfunc_cost_rate_date_type
8705 ,pbls.projfunc_cost_rate_date
8706 ,pbls.projfunc_rev_rate_type
8707 ,pbls.projfunc_rev_exchange_rate
8708 ,pbls.projfunc_rev_rate_date_type
8709 ,pbls.projfunc_rev_rate_date
8710 ,pbls.project_currency_code
8711 ,pbls.project_cost_rate_type
8712 ,pbls.project_cost_exchange_rate
8713 ,pbls.project_cost_rate_date_type
8714 ,pbls.project_cost_rate_date
8715 ,pbls.project_raw_cost
8716 ,pbls.project_burdened_cost
8717 ,pbls.project_rev_rate_type
8718 ,pbls.project_rev_exchange_rate
8719 ,pbls.project_rev_rate_date_type
8720 ,pbls.project_rev_rate_date
8721 ,pbls.project_revenue
8722 ,pbls.txn_currency_code
8723 ,pbls.txn_raw_cost
8724 ,pbls.txn_burdened_cost
8725 ,pbls.txn_revenue
8726 ,pbls.bucketing_period_code
8727 ,pbls.budget_line_id
8728 ,pbls.budget_version_id
8729 ,pbls.txn_standard_cost_rate
8730 ,pbls.txn_cost_rate_override
8731 ,pbls.cost_ind_compiled_set_id
8732 ,pbls.txn_standard_bill_rate
8733 ,pbls.txn_bill_rate_override
8734 ,pbls.txn_markup_percent
8735 ,pbls.txn_markup_percent_override
8736 ,pbls.txn_discount_percentage
8737 ,pbls.transfer_price_rate
8738 ,pbls.burden_cost_rate
8739 ,pbls.burden_cost_rate_override
8740 ,pbls.pc_cur_conv_rejection_code
8741 ,pbls.pfc_cur_conv_rejection_code
8742 ,pras.resource_assignment_id
8743 ,pras.task_id
8744 ,tmp4.resource_list_member_id
8745 FROM pa_resource_assignments pras,
8746 pa_res_list_map_tmp4 tmp4,
8747 pa_budget_lines pbls
8748 WHERE tmp4.txn_source_id=pras.resource_assignment_id
8749 AND pbls.resource_assignment_id=pras.resource_assignment_id) pbls
8750 where get_mapped_dml_code(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)='UPDATE'
8751 and pblt.budget_version_id(+) = p_budget_version_id
8752 and pblt.resource_assignment_id(+)=get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id)
8753 AND pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
8754 DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
8755 and prat.resource_assignment_id=get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id)
8756 --IPM Arch Enhancement Bug 4865563
8757 /*and pbls.cost_rejection_code IS NULL
8758 and pbls.revenue_rejection_code IS NULL
8759 and pbls.burden_rejection_code IS NULL
8760 and pbls.other_rejection_code IS NULL
8761 and pbls.pc_cur_conv_rejection_code IS NULL
8762 and pbls.pfc_cur_conv_rejection_code IS NULL*/
8763 GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id), DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code),
8764 pblt.resource_assignment_id,pblt.txn_currency_code,pblt.start_date,prat.planning_start_date, prat.planning_end_date,pblt.end_date ;
8765
8766 IF P_PA_debug_mode = 'Y' THEN
8767 pa_debug.g_err_stage:= 'Done with bulk select for ins/upd the budget lins with targ NTP and Diff RLS';
8768 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8769 END IF;
8770 --dbms_output.put_line('I37');
8771
8772 END IF;
8773
8774
8775 ELSE -- Time phased code is not N and src time phasing = target time phasing
8776 IF l_src_resource_list_id = l_targ_resource_list_id THEN
8777
8778 IF P_PA_debug_mode = 'Y' THEN
8779 pa_debug.g_err_stage:='About to select bls for PA/GL TP and same resource list';
8780 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
8781 END IF;
8782
8783 --dbms_output.put_line('I38');
8784
8785 SELECT get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code),
8786 decode(pblt.resource_assignment_id,null, 'INSERT',
8787 decode(pblt.txn_currency_code, null,'INSERT',
8788 decode(pblt.start_date,null,'INSERT','UPDATE'))),
8789 pbls.start_date,
8790 pbls.end_date,
8791 pbls.period_name,
8792 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8793 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
8794 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)),
8795 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost, null)),
8796 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor,
8797 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
8798 decode(count(pbls.budget_line_id),1,max(pbls.description),null),
8799 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
8800 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
8801 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
8802 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
8803 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
8804 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
8805 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
8806 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
8807 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
8808 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
8809 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
8810 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
8811 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
8812 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
8813 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
8814 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
8815 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
8816 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
8817 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
8818 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
8819 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
8820 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
8821 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
8822 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
8823 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
8824 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
8825 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
8826 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
8827 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
8828 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
8829 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
8830 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
8831 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
8832 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
8833 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
8834 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
8835 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
8836 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
8837 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
8838 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
8839 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
8840 l_projfunc_currency_code,
8841 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
8842 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
8843 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
8844 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
8845 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
8846 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
8847 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
8848 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
8849 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
8850 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)),
8851 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost, null)),
8852 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
8853 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
8854 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
8855 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
8856 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
8857 --Bug 4247568. Code changes for bug 4247568 starts here. If src multi curr flag and targ multi curr flag are -- diff then reutrn project raw cost, project burdened cost and project revenue.
8858 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))),
8859 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
8860 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))))),
8861 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
8862 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor,
8863 --Bug 4247568. Code changes for bug 4247568 ends here.
8864 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
8865 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),
8866
8867 --Bug 4224757. Code changes for bug#4224757 starts here
8868 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8869 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8870 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
8871 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8872 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
8873 --Bug 4224757. Code changes for bug#4224757 ends here
8874
8875 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
8876 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
8877
8878 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),
8879
8880 --Bug 4224757. Code changes for bug#4224757 starts here
8881 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
8882 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
8883 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
8884 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8885 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
8886 --Bug 4224757. Code changes for bug#4224757 ends here
8887
8888
8889 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
8890 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
8891 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
8892 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
8893 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),
8894
8895 --Bug 4224757. Code changes for bug#4224757 starts here
8896 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
8897 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
8898 nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
8899 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
8900 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
8901 --Bug 4224757. Code changes for bug#4224757 ends here
8902
8903 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
8904 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
8905 BULK COLLECT INTO
8906 l_bl_RESOURCE_ASIGNMENT_ID_tbl,
8907 l_upd_ra_bl_dml_code_tbl,
8908 l_bl_START_DATE_tbl,
8909 l_bl_END_DATE_tbl,
8910 l_bl_PERIOD_NAME_tbl,
8911 l_bl_QUANTITY_tbl,
8912 l_bl_RAW_COST_tbl,
8913 l_bl_BURDENED_COST_tbl,
8914 l_bl_REVENUE_tbl,
8915 l_bl_CHANGE_REASON_CODE_tbl,
8916 l_bl_DESCRIPTION_tbl,
8917 l_bl_ATTRIBUTE_CATEGORY_tbl,
8918 l_bl_ATTRIBUTE1_tbl,
8919 l_bl_ATTRIBUTE2_tbl,
8920 l_bl_ATTRIBUTE3_tbl,
8921 l_bl_ATTRIBUTE4_tbl,
8922 l_bl_ATTRIBUTE5_tbl,
8923 l_bl_ATTRIBUTE6_tbl,
8924 l_bl_ATTRIBUTE7_tbl,
8925 l_bl_ATTRIBUTE8_tbl,
8926 l_bl_ATTRIBUTE9_tbl,
8927 l_bl_ATTRIBUTE10_tbl,
8928 l_bl_ATTRIBUTE11_tbl,
8929 l_bl_ATTRIBUTE12_tbl,
8930 l_bl_ATTRIBUTE13_tbl,
8931 l_bl_ATTRIBUTE14_tbl,
8932 l_bl_ATTRIBUTE15_tbl,
8933 l_bl_PM_PRODUCT_CODE_tbl,
8934 l_bl_PM_BUDGET_LINE_REF_tbl,
8935 l_bl_COST_REJECTION_CODE_tbl,
8936 l_bl_REVENUE_REJ_CODE_tbl,
8937 l_bl_BURDEN_REJECTION_CODE_tbl,
8938 l_bl_OTHER_REJECTION_CODE_tbl,
8939 l_bl_CODE_COMBINATION_ID_tbl,
8940 l_bl_CCID_GEN_STATUS_CODE_tbl,
8941 l_bl_CCID_GEN_REJ_MESSAGE_tbl,
8942 l_bl_REQUEST_ID_tbl,
8943 l_bl_BORROWED_REVENUE_tbl,
8944 l_bl_TP_REVENUE_IN_tbl,
8945 l_bl_TP_REVENUE_OUT_tbl,
8946 l_bl_REVENUE_ADJ_tbl,
8947 l_bl_LENT_RESOURCE_COST_tbl,
8948 l_bl_TP_COST_IN_tbl,
8949 l_bl_TP_COST_OUT_tbl,
8950 l_bl_COST_ADJ_tbl,
8951 l_bl_UNASSIGNED_TIME_COST_tbl,
8952 l_bl_UTILIZATION_PERCENT_tbl,
8953 l_bl_UTILIZATION_HOURS_tbl,
8954 l_bl_UTILIZATION_ADJ_tbl,
8955 l_bl_CAPACITY_tbl,
8956 l_bl_HEAD_COUNT_tbl,
8957 l_bl_HEAD_COUNT_ADJ_tbl,
8958 l_bl_PROJFUNC_CUR_CODE_tbl,
8959 l_bl_PROJFUNC_COST_RAT_TYP_tbl,
8960 l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
8961 l_bl_PROJFUNC_COST_RAT_DAT_tbl,
8962 l_bl_PROJFUNC_REV_RATE_TYP_tbl,
8963 l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
8964 l_bl_PROJFUNC_REV_RAT_DATE_tbl,
8965 l_bl_PROJECT_COST_RAT_TYPE_tbl,
8966 l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
8967 l_bl_PROJ_COST_RATE_DATE_tbl,
8968 l_bl_PROJECT_RAW_COST_tbl,
8969 l_bl_PROJECT_BURDENED_COST_tbl,
8970 l_bl_PROJECT_REV_RATE_TYPE_tbl,
8971 l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
8972 l_bl_PROJECT_REV_RATE_DATE,
8973 l_bl_PROJECT_REVENUE_tbl,
8974 l_bl_TXN_CURRENCY_CODE_tbl,
8975 l_bl_TXN_RAW_COST_tbl,
8976 l_bl_TXN_BURDENED_COST_tbl,
8977 l_bl_TXN_REVENUE_tbl,
8978 l_bl_BUCKETING_PERIOD_CODE_tbl,
8979 l_bl_TXN_STD_COST_RATE_tbl,
8980 l_bl_TXN_COST_RATE_OVERIDE_tbl,
8981 l_bl_COST_IND_CMPLD_SET_ID_tbl,
8982 -- l_bl_TXN_BURDEN_MULTIPLIER_tbl,
8983 -- l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
8984 l_bl_TXN_STD_BILL_RATE_tbl,
8985 l_bl_TXN_BILL_RATE_OVERRID_tbl,
8986 l_bl_TXN_MARKUP_PERCENT_tbl,
8987 l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
8988 l_bl_TXN_DISC_PERCENTAGE_tbl,
8989 l_bl_TRANSFER_PRICE_RATE_tbl,
8990 l_bl_BURDEN_COST_RATE_tbl,
8991 l_bl_BURDEN_COST_RAT_OVRID_tbl,
8992 l_bl_PC_CUR_CONV_REJ_CODE_tbl,
8993 l_bl_PFC_CUR_CONV_REJ_CODE_tbl
8994 from pa_budget_lines pbls,
8995 pa_budget_lines pblt
8996 where get_mapped_dml_code(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)='UPDATE'
8997 and pbls.budget_version_id = l_src_ver_id_tbl(j)
8998 and pblt.budget_version_id(+) = p_budget_version_id
8999 and pblt.resource_assignment_id(+)=get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)
9000 AND pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
9001 DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
9002 AND pblt.start_date(+)=pbls.start_date
9003 --IPM Arch Enhancement Bug 4865563
9004 /*and pbls.cost_rejection_code IS NULL
9005 and pbls.revenue_rejection_code IS NULL
9006 and pbls.burden_rejection_code IS NULL
9007 and pbls.other_rejection_code IS NULL
9008 and pbls.pc_cur_conv_rejection_code IS NULL
9009 and pbls.pfc_cur_conv_rejection_code IS NULL*/
9010 and pbls.start_date >= nvl(l_etc_start_date,pbls.start_date)
9011 GROUP BY get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code), DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)
9012 ,pbls.start_date, pbls.period_name,pbls.end_date,pblt.resource_assignment_id,
9013 pblt.start_Date,pblt.txn_currency_code;
9014
9015 IF P_PA_debug_mode = 'Y' THEN
9016 pa_debug.g_err_stage:='selected bls for PA/GL TP and same resource list';
9017 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
9018 END IF;
9019 --dbms_output.put_line('I39');
9020
9021 ELSE--Time phased code is not None and Resource lists are different
9022
9023 --dbms_output.put_line('I40');
9024 SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id),
9025 decode(pblt.resource_assignment_id,null, 'INSERT',
9026 decode(pblt.txn_currency_code, null,'INSERT',
9027 decode(pblt.start_date,null,'INSERT','UPDATE'))),
9028 pbls.start_date,
9029 pbls.end_date,
9030 pbls.period_name,
9031 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
9032 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
9033 sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost, null)),
9034 sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)),
9035 sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue,null))*l_partial_factor,
9036 decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
9037 decode(count(pbls.budget_line_id),1,max(pbls.description),null),
9038 decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
9039 decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
9040 decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
9041 decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
9042 decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
9043 decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
9044 decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
9045 decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
9046 decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
9047 decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
9048 decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
9049 decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
9050 decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
9051 decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
9052 decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
9053 decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
9054 decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
9055 decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
9056 decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
9057 decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
9058 decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
9059 decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
9060 decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
9061 decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
9062 decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
9063 decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
9064 decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
9065 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
9066 decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
9067 decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
9068 decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
9069 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
9070 decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
9071 decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
9072 decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
9073 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
9074 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
9075 decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
9076 decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
9077 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
9078 decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
9079 l_projfunc_currency_code,
9080 DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
9081 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
9082 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
9083 Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
9084 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
9085 decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
9086 DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
9087 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
9088 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
9089 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)),
9090 sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)),
9091 Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
9092 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
9093 decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
9094 sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
9095 DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
9096
9097
9098 --Bug 4224757.. Code changes for bug#4224757 starts here
9099 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
9100 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))),
9101 SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
9102 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
9103 nvl(pbls.project_burdened_cost,0))))) ,
9104 SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
9105 DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
9106 nvl(pbls.project_revenue,0)))))*l_partial_factor ,
9107 --Bug 4224757.. Code changes for bug#4224757 ends here
9108
9109
9110 decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
9111 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),
9112
9113 --Bug 4224757. Code changes for bug#4224757 starts here
9114 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
9115 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
9116 nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
9117 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
9118 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
9119 --Bug 4224757. Code changes for bug#4224757 ends here
9120
9121 decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
9122 -- decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
9123
9124 decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),
9125
9126 --Bug 4224757. Code changes for bug#4224757 starts here
9127 decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
9128 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
9129 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
9130 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
9131 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
9132 --Bug 4224757. Code changes for bug#4224757 ends here
9133
9134 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
9135 decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
9136 decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
9137 decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
9138 decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),
9139
9140 --Bug 4224757. Code changes for bug#4224757 starts here
9141 decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
9142 decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
9143 nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
9144 decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
9145 decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
9146 --Bug 4224757. Code changes for bug#4224757 ends here
9147
9148 decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
9149 decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
9150 BULK COLLECT INTO
9151 l_bl_RESOURCE_ASIGNMENT_ID_tbl,
9152 l_upd_ra_bl_dml_code_tbl,
9153 l_bl_START_DATE_tbl,
9154 l_bl_END_DATE_tbl,
9155 l_bl_PERIOD_NAME_tbl,
9156 l_bl_QUANTITY_tbl,
9157 l_bl_RAW_COST_tbl,
9158 l_bl_BURDENED_COST_tbl,
9159 l_bl_REVENUE_tbl,
9160 l_bl_CHANGE_REASON_CODE_tbl,
9161 l_bl_DESCRIPTION_tbl,
9162 l_bl_ATTRIBUTE_CATEGORY_tbl,
9163 l_bl_ATTRIBUTE1_tbl,
9164 l_bl_ATTRIBUTE2_tbl,
9165 l_bl_ATTRIBUTE3_tbl,
9166 l_bl_ATTRIBUTE4_tbl,
9167 l_bl_ATTRIBUTE5_tbl,
9168 l_bl_ATTRIBUTE6_tbl,
9169 l_bl_ATTRIBUTE7_tbl,
9170 l_bl_ATTRIBUTE8_tbl,
9171 l_bl_ATTRIBUTE9_tbl,
9172 l_bl_ATTRIBUTE10_tbl,
9173 l_bl_ATTRIBUTE11_tbl,
9174 l_bl_ATTRIBUTE12_tbl,
9175 l_bl_ATTRIBUTE13_tbl,
9176 l_bl_ATTRIBUTE14_tbl,
9177 l_bl_ATTRIBUTE15_tbl,
9178 l_bl_PM_PRODUCT_CODE_tbl,
9179 l_bl_PM_BUDGET_LINE_REF_tbl,
9180 l_bl_COST_REJECTION_CODE_tbl,
9181 l_bl_REVENUE_REJ_CODE_tbl,
9182 l_bl_BURDEN_REJECTION_CODE_tbl,
9183 l_bl_OTHER_REJECTION_CODE_tbl,
9184 l_bl_CODE_COMBINATION_ID_tbl,
9185 l_bl_CCID_GEN_STATUS_CODE_tbl,
9186 l_bl_CCID_GEN_REJ_MESSAGE_tbl,
9187 l_bl_REQUEST_ID_tbl,
9188 l_bl_BORROWED_REVENUE_tbl,
9189 l_bl_TP_REVENUE_IN_tbl,
9190 l_bl_TP_REVENUE_OUT_tbl,
9191 l_bl_REVENUE_ADJ_tbl,
9192 l_bl_LENT_RESOURCE_COST_tbl,
9193 l_bl_TP_COST_IN_tbl,
9194 l_bl_TP_COST_OUT_tbl,
9195 l_bl_COST_ADJ_tbl,
9196 l_bl_UNASSIGNED_TIME_COST_tbl,
9197 l_bl_UTILIZATION_PERCENT_tbl,
9198 l_bl_UTILIZATION_HOURS_tbl,
9199 l_bl_UTILIZATION_ADJ_tbl,
9200 l_bl_CAPACITY_tbl,
9201 l_bl_HEAD_COUNT_tbl,
9202 l_bl_HEAD_COUNT_ADJ_tbl,
9203 l_bl_PROJFUNC_CUR_CODE_tbl,
9204 l_bl_PROJFUNC_COST_RAT_TYP_tbl,
9205 l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
9206 l_bl_PROJFUNC_COST_RAT_DAT_tbl,
9207 l_bl_PROJFUNC_REV_RATE_TYP_tbl,
9208 l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
9209 l_bl_PROJFUNC_REV_RAT_DATE_tbl,
9210 l_bl_PROJECT_COST_RAT_TYPE_tbl,
9211 l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
9212 l_bl_PROJ_COST_RATE_DATE_tbl,
9213 l_bl_PROJECT_RAW_COST_tbl,
9214 l_bl_PROJECT_BURDENED_COST_tbl,
9215 l_bl_PROJECT_REV_RATE_TYPE_tbl,
9216 l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
9217 l_bl_PROJECT_REV_RATE_DATE,
9218 l_bl_PROJECT_REVENUE_tbl,
9219 l_bl_TXN_CURRENCY_CODE_tbl,
9220 l_bl_TXN_RAW_COST_tbl,
9221 l_bl_TXN_BURDENED_COST_tbl,
9222 l_bl_TXN_REVENUE_tbl,
9223 l_bl_BUCKETING_PERIOD_CODE_tbl,
9224 l_bl_TXN_STD_COST_RATE_tbl,
9225 l_bl_TXN_COST_RATE_OVERIDE_tbl,
9226 l_bl_COST_IND_CMPLD_SET_ID_tbl,
9227 -- l_bl_TXN_BURDEN_MULTIPLIER_tbl,
9228 -- l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
9229 l_bl_TXN_STD_BILL_RATE_tbl,
9230 l_bl_TXN_BILL_RATE_OVERRID_tbl,
9231 l_bl_TXN_MARKUP_PERCENT_tbl,
9232 l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
9233 l_bl_TXN_DISC_PERCENTAGE_tbl,
9234 l_bl_TRANSFER_PRICE_RATE_tbl,
9235 l_bl_BURDEN_COST_RATE_tbl,
9236 l_bl_BURDEN_COST_RAT_OVRID_tbl,
9237 l_bl_PC_CUR_CONV_REJ_CODE_tbl,
9238 l_bl_PFC_CUR_CONV_REJ_CODE_tbl
9239 from pa_budget_lines pblt,
9240 (SELECT pbls.resource_assignment_id
9241 ,pbls.start_date
9242 ,pbls.last_update_date
9243 ,pbls.last_updated_by
9244 ,pbls.creation_date
9245 ,pbls.created_by
9246 ,pbls.last_update_login
9247 ,pbls.end_date
9248 ,pbls.period_name
9249 ,pbls.quantity
9250 ,pbls.raw_cost
9251 ,pbls.burdened_cost
9252 ,pbls.revenue
9253 ,pbls.change_reason_code
9254 ,pbls.description
9255 ,pbls.attribute_category
9256 ,pbls.attribute1
9257 ,pbls.attribute2
9258 ,pbls.attribute3
9259 ,pbls.attribute4
9260 ,pbls.attribute5
9261 ,pbls.attribute6
9262 ,pbls.attribute7
9263 ,pbls.attribute8
9264 ,pbls.attribute9
9265 ,pbls.attribute10
9266 ,pbls.attribute11
9267 ,pbls.attribute12
9268 ,pbls.attribute13
9269 ,pbls.attribute14
9270 ,pbls.attribute15
9271 ,pbls.raw_cost_source
9272 ,pbls.burdened_cost_source
9273 ,pbls.quantity_source
9274 ,pbls.revenue_source
9275 ,pbls.pm_product_code
9276 ,pbls.pm_budget_line_reference
9277 ,pbls.cost_rejection_code
9278 ,pbls.revenue_rejection_code
9279 ,pbls.burden_rejection_code
9280 ,pbls.other_rejection_code
9281 ,pbls.code_combination_id
9282 ,pbls.ccid_gen_status_code
9283 ,pbls.ccid_gen_rej_message
9284 ,pbls.request_id
9285 ,pbls.borrowed_revenue
9286 ,pbls.tp_revenue_in
9287 ,pbls.tp_revenue_out
9288 ,pbls.revenue_adj
9289 ,pbls.lent_resource_cost
9290 ,pbls.tp_cost_in
9291 ,pbls.tp_cost_out
9292 ,pbls.cost_adj
9293 ,pbls.unassigned_time_cost
9294 ,pbls.utilization_percent
9295 ,pbls.utilization_hours
9296 ,pbls.utilization_adj
9297 ,pbls.capacity
9298 ,pbls.head_count
9299 ,pbls.head_count_adj
9300 ,pbls.projfunc_currency_code
9301 ,pbls.projfunc_cost_rate_type
9302 ,pbls.projfunc_cost_exchange_rate
9303 ,pbls.projfunc_cost_rate_date_type
9304 ,pbls.projfunc_cost_rate_date
9305 ,pbls.projfunc_rev_rate_type
9306 ,pbls.projfunc_rev_exchange_rate
9307 ,pbls.projfunc_rev_rate_date_type
9308 ,pbls.projfunc_rev_rate_date
9309 ,pbls.project_currency_code
9310 ,pbls.project_cost_rate_type
9311 ,pbls.project_cost_exchange_rate
9312 ,pbls.project_cost_rate_date_type
9313 ,pbls.project_cost_rate_date
9314 ,pbls.project_raw_cost
9315 ,pbls.project_burdened_cost
9316 ,pbls.project_rev_rate_type
9317 ,pbls.project_rev_exchange_rate
9318 ,pbls.project_rev_rate_date_type
9319 ,pbls.project_rev_rate_date
9320 ,pbls.project_revenue
9321 ,pbls.txn_currency_code
9322 ,pbls.txn_raw_cost
9323 ,pbls.txn_burdened_cost
9324 ,pbls.txn_revenue
9325 ,pbls.bucketing_period_code
9326 ,pbls.budget_line_id
9327 ,pbls.budget_version_id
9328 ,pbls.txn_standard_cost_rate
9329 ,pbls.txn_cost_rate_override
9330 ,pbls.cost_ind_compiled_set_id
9331 ,pbls.txn_standard_bill_rate
9332 ,pbls.txn_bill_rate_override
9333 ,pbls.txn_markup_percent
9334 ,pbls.txn_markup_percent_override
9335 ,pbls.txn_discount_percentage
9336 ,pbls.transfer_price_rate
9337 ,pbls.burden_cost_rate
9338 ,pbls.burden_cost_rate_override
9339 ,pbls.pc_cur_conv_rejection_code
9340 ,pbls.pfc_cur_conv_rejection_code
9341 ,pras.resource_assignment_id
9342 ,pras.task_id
9343 ,tmp4.resource_list_member_id
9344 FROM pa_resource_assignments pras,
9345 pa_res_list_map_tmp4 tmp4,
9346 pa_budget_lines pbls
9347 WHERE tmp4.txn_source_id=pras.resource_assignment_id
9348 AND pbls.resource_assignment_id=pras.resource_assignment_id) pbls
9349 where get_mapped_dml_code(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)='UPDATE'
9350 and pblt.budget_version_id(+) = p_budget_version_id
9351 and pblt.resource_assignment_id(+)=get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id)
9352 AND pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
9353 DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
9354 AND pblt.start_date(+)=pbls.start_date
9355 --IPM Arch Enhancement Bug 4865563
9356 /*and pbls.cost_rejection_code IS NULL
9357 and pbls.revenue_rejection_code IS NULL
9358 and pbls.burden_rejection_code IS NULL
9359 and pbls.other_rejection_code IS NULL
9360 and pbls.pc_cur_conv_rejection_code IS NULL
9361 and pbls.pfc_cur_conv_rejection_code IS NULL*/
9362 and pbls.start_date >= nvl(l_etc_start_date,pbls.start_date)
9363 GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id), DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)
9364 ,pbls.start_date,pbls.end_date,pbls.period_name,pblt.resource_assignment_id,pblt.txn_currency_code,pblt.start_date;
9365
9366 --dbms_output.put_line('I41');
9367
9368 END IF;
9369 END IF;
9370 END IF;
9371
9372
9373 --Prepare a pl/sql table equal in length to l_upd_ra_bl_dml_code_tbl which contains the rate based flag
9374 --for the resource assignment to which the budget line corresponds. This will help in populating
9375 --correct values in quantity and rate columns of budget lines.Bug 3621847
9376 IF l_upd_ra_bl_dml_code_tbl.COUNT>0 THEN
9377
9378 l_bl_rbf_flag_tbl := SYSTEM.PA_VARCHAR2_1_TBL_TYPE();
9379 l_bl_rbf_flag_tbl.EXTEND(l_bl_RESOURCE_ASIGNMENT_ID_tbl.COUNT);
9380 --dbms_output.put_line('I42');
9381 FOR KK IN l_bl_RESOURCE_ASIGNMENT_ID_tbl.FIRST..l_bl_RESOURCE_ASIGNMENT_ID_tbl.LAST LOOP
9382
9383 FOR jj IN l_targ_ra_id_tbl.FIRST..l_targ_ra_id_tbl.LAST LOOP
9384
9385 IF l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk)=l_targ_ra_id_tbl(jj) THEN
9386
9387 l_bl_rbf_flag_tbl(kk):=l_targ_rate_based_flag_tbl(jj);
9388
9389 EXIT;
9390
9391 END IF;
9392
9393 END LOOP;
9394
9395 END LOOP;
9396
9397 --Round the amounts prepared in the pl/sql tbls in case of partial implementation
9398
9399 IF l_partial_factor <> 1 THEN
9400
9401 IF l_debug_mode = 'Y' THEN
9402 pa_debug.g_err_stage:='Fetching the agreement details';
9403 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
9404 END IF;
9405 -- Select agreement currency code
9406 SELECT agr.agreement_id,
9407 agr.agreement_currency_code
9408 INTO l_agreement_id,
9409 l_agreement_currency_code
9410 FROM pa_budget_versions cibv,
9411 pa_agreements_all agr
9412 WHERE cibv.budget_version_id = l_src_ver_id_tbl(j)
9413 AND cibv.agreement_id = agr.agreement_id;
9414
9415 IF l_debug_mode = 'Y' THEN
9416 pa_debug.g_err_stage:='Calling pa_fp_multi_currency_pkg.round_amounts';
9417 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
9418 END IF;
9419
9420 pa_fp_multi_currency_pkg.round_amounts
9421 ( px_quantity_tbl => l_bl_QUANTITY_tbl
9422 ,p_agr_currency_code => l_agreement_currency_code
9423 ,px_txn_raw_cost_tbl => l_bl_TXN_RAW_COST_tbl
9424 ,px_txn_burdened_cost_tbl => l_bl_TXN_BURDENED_COST_tbl
9425 ,px_txn_revenue_tbl => l_bl_TXN_REVENUE_tbl
9426 ,p_project_currency_code => l_Project_Currency_Code
9427 ,px_project_raw_cost_tbl => l_bl_PROJECT_RAW_COST_tbl
9428 ,px_project_burdened_cost_tbl => l_bl_PROJECT_BURDENED_COST_tbl
9429 ,px_project_revenue_tbl => l_bl_PROJECT_REVENUE_tbl
9430 ,p_projfunc_currency_code => l_Projfunc_Currency_Code
9431 ,px_projfunc_raw_cost_tbl => l_bl_RAW_COST_tbl
9432 ,px_projfunc_burdened_cost_tbl => l_bl_BURDENED_COST_tbl
9433 ,px_projfunc_revenue_tbl => l_bl_REVENUE_tbl
9434 ,x_return_status => x_return_status
9435 ,x_msg_count => x_msg_count
9436 ,x_msg_data => x_msg_data );
9437
9438 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9439
9440 IF P_PA_debug_mode = 'Y' THEN
9441 pa_debug.g_err_stage:= 'pa_fp_multi_currency_pkg.round_amounts returned error';
9442 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
9443 END IF;
9444 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9445
9446 END IF;
9447
9448 END IF; --IF l_partial_factor <> 1
9449
9450 --dbms_output.put_line('I43');
9451 FORALL kk in 1..l_upd_ra_bl_dml_code_tbl.count
9452 INSERT INTO PA_BUDGET_LINES(RESOURCE_ASSIGNMENT_ID,
9453 START_DATE,
9454 LAST_UPDATE_DATE,
9455 LAST_UPDATED_BY,
9456 CREATION_DATE,
9457 CREATED_BY,
9458 LAST_UPDATE_LOGIN,
9459 END_DATE,
9460 PERIOD_NAME,
9461 QUANTITY,
9462 RAW_COST,
9463 BURDENED_COST,
9464 REVENUE,
9465 CHANGE_REASON_CODE,
9466 DESCRIPTION,
9467 ATTRIBUTE_CATEGORY,
9468 ATTRIBUTE1,
9469 ATTRIBUTE2,
9470 ATTRIBUTE3,
9471 ATTRIBUTE4,
9472 ATTRIBUTE5,
9473 ATTRIBUTE6,
9474 ATTRIBUTE7,
9475 ATTRIBUTE8,
9476 ATTRIBUTE9,
9477 ATTRIBUTE10,
9478 ATTRIBUTE11,
9479 ATTRIBUTE12,
9480 ATTRIBUTE13,
9481 ATTRIBUTE14,
9482 ATTRIBUTE15,
9483 RAW_COST_SOURCE,
9484 BURDENED_COST_SOURCE,
9485 QUANTITY_SOURCE,
9486 REVENUE_SOURCE,
9487 PM_PRODUCT_CODE,
9488 PM_BUDGET_LINE_REFERENCE,
9489 COST_REJECTION_CODE,
9490 REVENUE_REJECTION_CODE,
9491 BURDEN_REJECTION_CODE,
9492 OTHER_REJECTION_CODE,
9493 CODE_COMBINATION_ID,
9494 CCID_GEN_STATUS_CODE,
9495 CCID_GEN_REJ_MESSAGE,
9496 REQUEST_ID,
9497 BORROWED_REVENUE,
9498 TP_REVENUE_IN,
9499 TP_REVENUE_OUT,
9500 REVENUE_ADJ,
9501 LENT_RESOURCE_COST,
9502 TP_COST_IN,
9503 TP_COST_OUT,
9504 COST_ADJ,
9505 UNASSIGNED_TIME_COST,
9506 UTILIZATION_PERCENT,
9507 UTILIZATION_HOURS,
9508 UTILIZATION_ADJ,
9509 CAPACITY,
9510 HEAD_COUNT,
9511 HEAD_COUNT_ADJ,
9512 PROJFUNC_CURRENCY_CODE,
9513 PROJFUNC_COST_RATE_TYPE,
9514 PROJFUNC_COST_EXCHANGE_RATE,
9515 PROJFUNC_COST_RATE_DATE_TYPE,
9516 PROJFUNC_COST_RATE_DATE,
9517 PROJFUNC_REV_RATE_TYPE,
9518 PROJFUNC_REV_EXCHANGE_RATE,
9519 PROJFUNC_REV_RATE_DATE_TYPE,
9520 PROJFUNC_REV_RATE_DATE,
9521 PROJECT_CURRENCY_CODE,
9522 PROJECT_COST_RATE_TYPE,
9523 PROJECT_COST_EXCHANGE_RATE,
9524 PROJECT_COST_RATE_DATE_TYPE,
9525 PROJECT_COST_RATE_DATE,
9526 PROJECT_RAW_COST,
9527 PROJECT_BURDENED_COST,
9528 PROJECT_REV_RATE_TYPE,
9529 PROJECT_REV_EXCHANGE_RATE,
9530 PROJECT_REV_RATE_DATE_TYPE,
9531 PROJECT_REV_RATE_DATE,
9532 PROJECT_REVENUE,
9533 TXN_CURRENCY_CODE,
9534 TXN_RAW_COST,
9535 TXN_BURDENED_COST,
9536 TXN_REVENUE,
9537 BUCKETING_PERIOD_CODE,
9538 BUDGET_LINE_ID,
9539 BUDGET_VERSION_ID,
9540 TXN_STANDARD_COST_RATE,
9541 TXN_COST_RATE_OVERRIDE,
9542 COST_IND_COMPILED_SET_ID,
9543 -- TXN_BURDEN_MULTIPLIER,
9544 -- TXN_BURDEN_MULTIPLIER_OVERRIDE,
9545 TXN_STANDARD_BILL_RATE,
9546 TXN_BILL_RATE_OVERRIDE,
9547 TXN_MARKUP_PERCENT,
9548 TXN_MARKUP_PERCENT_OVERRIDE,
9549 TXN_DISCOUNT_PERCENTAGE,
9550 TRANSFER_PRICE_RATE,
9551 BURDEN_COST_RATE,
9552 BURDEN_COST_RATE_OVERRIDE,
9553 PC_CUR_CONV_REJECTION_CODE,
9554 PFC_CUR_CONV_REJECTION_CODE
9555 )
9556 SELECT l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk),
9557 l_bl_START_DATE_tbl(kk),
9558 sysdate,
9559 fnd_global.user_id,
9560 sysdate,
9561 fnd_global.user_id,
9562 fnd_global.login_id,
9563 l_bl_END_DATE_tbl(kk),
9564 l_bl_PERIOD_NAME_tbl(kk),
9565 Decode(l_bl_rbf_flag_tbl(kk),
9566 'N',Decode(l_target_version_type,
9567 'REVENUE',l_bl_TXN_REVENUE_tbl(kk),
9568 l_bl_TXN_RAW_COST_tbl(kk)),
9569 l_bl_QUANTITY_tbl(kk)),
9570 l_bl_RAW_COST_tbl(kk),
9571 l_bl_BURDENED_COST_tbl(kk),
9572 l_bl_REVENUE_tbl(kk),
9573 l_bl_CHANGE_REASON_CODE_tbl(kk),
9574 l_bl_DESCRIPTION_tbl(kk),
9575 l_bl_ATTRIBUTE_CATEGORY_tbl(kk),
9576 l_bl_ATTRIBUTE1_tbl(kk),
9577 l_bl_ATTRIBUTE2_tbl(kk),
9578 l_bl_ATTRIBUTE3_tbl(kk),
9579 l_bl_ATTRIBUTE4_tbl(kk),
9580 l_bl_ATTRIBUTE5_tbl(kk),
9581 l_bl_ATTRIBUTE6_tbl(kk),
9582 l_bl_ATTRIBUTE7_tbl(kk),
9583 l_bl_ATTRIBUTE8_tbl(kk),
9584 l_bl_ATTRIBUTE9_tbl(kk),
9585 l_bl_ATTRIBUTE10_tbl(kk),
9586 l_bl_ATTRIBUTE11_tbl(kk),
9587 l_bl_ATTRIBUTE12_tbl(kk),
9588 l_bl_ATTRIBUTE13_tbl(kk),
9589 l_bl_ATTRIBUTE14_tbl(kk),
9590 l_bl_ATTRIBUTE15_tbl(kk),
9591 'I',
9592 'I',
9593 'I',
9594 'I',
9595 l_bl_PM_PRODUCT_CODE_tbl(kk),
9596 l_bl_PM_BUDGET_LINE_REF_tbl(kk),
9597 l_bl_COST_REJECTION_CODE_tbl(kk),
9598 l_bl_REVENUE_REJ_CODE_tbl(kk),
9599 l_bl_BURDEN_REJECTION_CODE_tbl(kk),
9600 l_bl_OTHER_REJECTION_CODE_tbl(kk),
9601 l_bl_CODE_COMBINATION_ID_tbl(kk),
9602 l_bl_CCID_GEN_STATUS_CODE_tbl(kk),
9603 l_bl_CCID_GEN_REJ_MESSAGE_tbl(kk),
9604 l_bl_REQUEST_ID_tbl(kk),
9605 l_bl_BORROWED_REVENUE_tbl(kk),
9606 l_bl_TP_REVENUE_IN_tbl(kk),
9607 l_bl_TP_REVENUE_OUT_tbl(kk),
9608 l_bl_REVENUE_ADJ_tbl(kk),
9609 l_bl_LENT_RESOURCE_COST_tbl(kk),
9610 l_bl_TP_COST_IN_tbl(kk),
9611 l_bl_TP_COST_OUT_tbl(kk),
9612 l_bl_COST_ADJ_tbl(kk),
9613 l_bl_UNASSIGNED_TIME_COST_tbl(kk),
9614 l_bl_UTILIZATION_PERCENT_tbl(kk),
9615 l_bl_UTILIZATION_HOURS_tbl(kk),
9616 l_bl_UTILIZATION_ADJ_tbl(kk),
9617 l_bl_CAPACITY_tbl(kk),
9618 l_bl_HEAD_COUNT_tbl(kk),
9619 l_bl_HEAD_COUNT_ADJ_tbl(kk),
9620 l_bl_PROJFUNC_CUR_CODE_tbl(kk),
9621 l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),
9622 DECODE(l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),'User', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9623 'B', nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)),0,0,(decode(l_report_cost_using,'R',nvl(l_bl_RAW_COST_tbl(kk),0),
9624 'B',nvl(l_bl_BURDENED_COST_tbl(kk),0)) / (decode(l_report_cost_using,'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9625 'B', nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))))),Null),Null), -- Bug 3839273
9626 l_bl_PJFN_COST_RAT_DAT_TYP_tbl(kk),
9627 l_bl_PROJFUNC_COST_RAT_DAT_tbl(kk),
9628 l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),
9629 Decode(l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),'User',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(l_bl_TXN_REVENUE_tbl(kk),0),0,0,nvl(l_bl_REVENUE_tbl(kk),0) /
9630 nvl(l_bl_TXN_REVENUE_tbl(kk),0)),Null),Null), -- Bug 3839273
9631 l_bl_PJFN_REV_RAT_DAT_TYPE_tbl(kk),
9632 l_bl_PROJFUNC_REV_RAT_DATE_tbl(kk),
9633 l_project_currency_code,
9634 l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),
9635 DECODE(l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),'User', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9636 'B', nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)),0,0,(decode(l_report_cost_using,'R',nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0),
9637 'B',nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0)) / (decode(l_report_cost_using,'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9638 'B',nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))))),Null),Null), -- Bug 3839273
9639 l_bl_PROJ_COST_RAT_DAT_TYP_tbl(kk),
9640 l_bl_PROJ_COST_RATE_DATE_tbl(kk),
9641 l_bl_PROJECT_RAW_COST_tbl(kk),
9642 l_bl_PROJECT_BURDENED_COST_tbl(kk),
9643 l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),
9644 Decode(l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),'User',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(l_bl_TXN_REVENUE_tbl(kk),0),0,0,nvl(l_bl_PROJECT_REVENUE_tbl(kk),0) /
9645 nvl(l_bl_TXN_REVENUE_tbl(kk),0)),Null),Null), -- Bug 3839273
9646 l_bl_PRJ_REV_RAT_DATE_TYPE_tbl(kk),
9647 l_bl_PROJECT_REV_RATE_DATE(kk),
9648 l_bl_PROJECT_REVENUE_tbl(kk),
9649 l_bl_TXN_CURRENCY_CODE_tbl(kk),
9650 l_bl_TXN_RAW_COST_tbl(kk),
9651 l_bl_TXN_BURDENED_COST_tbl(kk),
9652 l_bl_TXN_REVENUE_tbl(kk),
9653 l_bl_BUCKETING_PERIOD_CODE_tbl(kk),
9654 pa_budget_lines_s.nextval,
9655 p_budget_version_id,
9656 l_bl_TXN_STD_COST_RATE_tbl(kk),
9657 DECODE(l_target_version_type,
9658 'REVENUE',l_bl_TXN_COST_RATE_OVERIDE_tbl(kk),
9659 DECODE(l_bl_rbf_flag_tbl(kk),
9660 'N',1,
9661 l_bl_TXN_COST_RATE_OVERIDE_tbl(kk))),
9662 l_bl_COST_IND_CMPLD_SET_ID_tbl(kk),
9663 -- l_bl_TXN_BURDEN_MULTIPLIER_tbl(kk),
9664 -- l_bl_TXN_BRD_MLTIPLI_OVRID_tbl(kk),
9665 l_bl_TXN_STD_BILL_RATE_tbl(kk),
9666 DECODE(l_target_version_type,
9667 'REVENUE',DECODE(l_bl_rbf_flag_tbl(kk),
9668 'N',1,
9669 l_bl_TXN_BILL_RATE_OVERRID_tbl(kk)),
9670 l_bl_TXN_BILL_RATE_OVERRID_tbl(kk)),
9671 l_bl_TXN_MARKUP_PERCENT_tbl(kk),
9672 l_bl_TXN_MRKUP_PER_OVERIDE_tbl(kk),
9673 l_bl_TXN_DISC_PERCENTAGE_tbl(kk),
9674 l_bl_TRANSFER_PRICE_RATE_tbl(kk),
9675 l_bl_BURDEN_COST_RATE_tbl(kk),
9676 DECODE(l_target_version_type,
9677 'REVENUE',l_bl_BURDEN_COST_RAT_OVRID_tbl(kk),
9678 DECODE(l_bl_rbf_flag_tbl(kk),
9679 'Y',l_bl_BURDEN_COST_RAT_OVRID_tbl(kk),
9680 DECODE(nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9681 0,null,
9682 l_bl_TXN_BURDENED_COST_tbl(kk)/l_bl_TXN_RAW_COST_tbl(kk)))),
9683 l_bl_PC_CUR_CONV_REJ_CODE_tbl(kk),
9684 l_bl_PFC_CUR_CONV_REJ_CODE_tbl(kk)
9685 from dual
9686 where l_upd_ra_bl_dml_code_tbl(kk)='INSERT';
9687
9688 --dbms_output.put_line('I43');
9689
9690 --Fix for bug 3734888. Null handled the pl/sql tbls while updating.
9691 FORALL kk in 1..l_upd_ra_bl_dml_code_tbl.count
9692 UPDATE PA_BUDGET_LINES
9693 SET LAST_UPDATE_DATE=sysdate,
9694 LAST_UPDATED_BY=fnd_global.user_id,
9695 LAST_UPDATE_LOGIN=fnd_global.login_id,
9696 QUANTITY= DECODE(l_bl_rbf_flag_tbl(kk),
9697 'N',DECODE(l_target_version_type,
9698 'REVENUE',nvl(TXN_REVENUE,0)+ nvl(l_bl_TXN_REVENUE_tbl(kk),0)
9699 ,nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)),
9700 nvl(QUANTITY,0)+ nvl(l_bl_QUANTITY_tbl(kk),0)),
9701 RAW_COST= nvl(RAW_COST,0) + nvl(l_bl_RAW_COST_tbl(kk),0),
9702 BURDENED_COST= nvl(BURDENED_COST,0) + nvl(l_bl_BURDENED_COST_tbl(kk),0),
9703 REVENUE= nvl(REVENUE,0) + nvl(l_bl_REVENUE_tbl(kk),0),
9704 PROJFUNC_COST_RATE_TYPE= nvl(l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),PROJFUNC_COST_RATE_TYPE),
9705 PROJFUNC_COST_EXCHANGE_RATE= DECODE(nvl(l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),PROJFUNC_COST_RATE_TYPE),'User', Decode(decode(l_report_cost_using, 'R',nvl(nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),0),
9706 'B',nvl(nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0),0) ),0,0,
9707 (decode(l_report_cost_using,'R',nvl(nvl(RAW_COST,0) + nvl(l_bl_RAW_COST_tbl(kk),0),0),
9708 'B',nvl(nvl(BURDENED_COST,0) + nvl(l_bl_BURDENED_COST_tbl(kk),0),0)) / decode(l_report_cost_using,'R', nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9709 'B', nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)))),PROJFUNC_COST_EXCHANGE_RATE),
9710 PROJFUNC_REV_RATE_TYPE= nvl(l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),PROJFUNC_REV_RATE_TYPE),
9711 PROJFUNC_REV_EXCHANGE_RATE= DECODE(nvl(l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),PROJFUNC_REV_RATE_TYPE),'User',
9712 Decode(nvl(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0),0),0,0,
9713 (nvl(nvl(REVENUE,0) + nvl(l_bl_REVENUE_tbl(kk),0),0) /(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0)))),PROJFUNC_REV_EXCHANGE_RATE),
9714 PROJECT_COST_RATE_TYPE= nvl(l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),PROJECT_COST_RATE_TYPE),
9715 PROJECT_COST_EXCHANGE_RATE= DECODE(nvl(l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),PROJECT_COST_RATE_TYPE),'User', Decode(decode(l_report_cost_using, 'R',nvl(nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),0),
9716 'B',nvl(nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0),0) ),0,0,
9717 (decode(l_report_cost_using,'R',nvl(nvl(PROJECT_RAW_COST,0) + nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0),0),
9718 'B',nvl(nvl(PROJECT_BURDENED_COST,0) + nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0),0)) / decode(l_report_cost_using,
9719 'R', nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9720 'B', nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)))),PROJECT_COST_EXCHANGE_RATE),
9721 PROJECT_RAW_COST = nvl(PROJECT_RAW_COST,0) + nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0),
9722 PROJECT_BURDENED_COST = nvl(PROJECT_BURDENED_COST,0) + nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0),
9723 PROJECT_REV_RATE_TYPE = nvl(l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),PROJECT_REV_RATE_TYPE),
9724 PROJECT_REV_EXCHANGE_RATE = DECODE(nvl(l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),PROJECT_REV_RATE_TYPE),'User',
9725 Decode(nvl(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0),0),0,0,
9726 (nvl(nvl(PROJECT_REVENUE,0) + nvl(l_bl_PROJECT_REVENUE_tbl(kk),0),0) /(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0)))),PROJECT_REV_EXCHANGE_RATE),
9727 PROJECT_REVENUE = nvl(PROJECT_REVENUE,0) + nvl(l_bl_PROJECT_REVENUE_tbl(kk),0),
9728 TXN_RAW_COST = nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
9729 TXN_BURDENED_COST= nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0),
9730 TXN_REVENUE = nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0),
9731 TXN_COST_RATE_OVERRIDE = DECODE(l_target_Version_type,
9732 'REVENUE', TXN_COST_RATE_OVERRIDE,
9733 DECODE(l_bl_rbf_flag_tbl(kk),
9734 'N',1,
9735 decode((nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)),0,0,((nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0))/
9736 (nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)))))),
9737 BURDEN_COST_RATE_OVERRIDE = DECODE( l_target_Version_type,
9738 'REVENUE',BURDEN_COST_RATE_OVERRIDE,
9739 DECODE(l_bl_rbf_flag_tbl(kk),
9740 'N',decode((nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)),0,0,((nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))/
9741 (nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)))),
9742 decode((nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)),0,0,((nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))/
9743 (nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)))))),
9744 TXN_BILL_RATE_OVERRIDE = DECODE(l_bl_rbf_flag_tbl(kk),
9745 'N',DECODE(l_target_version_type,
9746 'REVENUE',1,
9747 decode((nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)),0,0,((nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0))/
9748 (nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0))))),
9749 decode((nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)),0,0,((nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0))/
9750 (nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)))))
9751 WHERE l_upd_ra_bl_dml_code_tbl(kk) = 'UPDATE'
9752 AND resource_assignment_id = l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk)
9753 AND start_date = l_bl_START_DATE_tbl(kk)
9754 AND txn_currency_code = l_bl_TXN_CURRENCY_CODE_tbl(kk)
9755 RETURNING
9756 period_name,
9757 txn_currency_code,
9758 start_date,
9759 end_date,
9760 cost_rejection_code,
9761 revenue_rejection_code,
9762 burden_rejection_code,
9763 other_rejection_code,
9764 pc_cur_conv_rejection_code,
9765 pfc_cur_conv_rejection_code,
9766 budget_line_id
9767 BULK COLLECT INTO
9768 l_upd_period_name_tbl,
9769 l_upd_currency_code_tbl,
9770 l_upd_bl_start_date_tbl,
9771 l_upd_bl_end_date_tbl,
9772 l_upd_cost_rejection_code,
9773 l_upd_revenue_rejection_code,
9774 l_upd_burden_rejection_code,
9775 l_upd_other_rejection_code,
9776 l_upd_pc_cur_conv_rej_code,
9777 l_upd_pfc_cur_conv_rej_code,
9778 l_upd_bl_id_tbl;
9779
9780
9781 --dbms_output.put_line('I44');
9782
9783 END IF;-- IF l_upd_ra_bl_dml_code_tbl.COUNT>0 THEN
9784
9785 -- Bug 4035856 Call rounding api if partial implementation has happened
9786 IF l_partial_factor <> 1 THEN
9787 -- Call rounding api
9788 PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts
9789 ( p_budget_version_id => p_budget_version_id
9790 ,p_calling_context => 'CHANGE_ORDER_MERGE'
9791 ,p_bls_inserted_after_id => l_id_before_bl_insertion
9792 ,x_return_status => l_return_status
9793 ,x_msg_count => l_msg_count
9794 ,x_msg_data => l_msg_data);
9795
9796 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9797 IF P_PA_debug_mode = 'Y' THEN
9798 pa_debug.g_err_stage:= 'Error in PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts';
9799 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
9800 END IF;
9801 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9802 END IF;
9803 IF l_debug_mode = 'Y' THEN
9804 pa_debug.g_err_stage:='Start of residual amount logic';
9805 pa_debug.write('Round_Budget_Line_Amounts: ' || l_module_name,pa_debug.g_err_stage,3);
9806 END IF;
9807
9808 Begin
9809
9810 -- Compute the total revenue sum of target budget version in PC,PFC (TXN=PFC)
9811 SELECT nvl(sum(nvl(revenue,0)),0), nvl(sum(nvl(project_revenue,0)),0)
9812 INTO l_targ_pfc_rev_after_merge, l_targ_pc_rev_after_merge
9813 FROM pa_budget_lines
9814 WHERE budget_version_id = p_budget_version_id;
9815
9816 -- Initialise residual amount variables to zero
9817 l_pc_revenue_delta := 0;
9818 l_pfc_revenue_delta := 0;
9819
9820 -- Compute the total implemented amount using already implemented amount and currently
9821 -- implemented amount
9822 l_pc_rev_merged := l_impl_proj_revenue -- already impl amt from pa_fp_merged_ctrl_items
9823 + (l_targ_pc_rev_after_merge - l_targ_pc_rev_before_merge);
9824 l_pfc_rev_merged := l_impl_proj_func_revenue -- already impl amt from pa_fp_merged_ctrl_items
9825 + (l_targ_pfc_rev_after_merge - l_targ_pfc_rev_before_merge);
9826
9827 -- If all the remaining agreement amount is being implemented, make sure that
9828 -- implemeted PC, PFC amounts in pa_fp_merged_ctrl_items tally with ci version totals
9829 IF (nvl(l_impl_amt,0) + nvl(l_partial_impl_rev_amt,0) = nvl(l_total_amt,0)) THEN
9830
9831 l_pfc_revenue_delta := l_total_amt_in_pfc - l_pfc_rev_merged;
9832 l_pc_revenue_delta := l_total_amt_in_pc - l_pc_rev_merged;
9833
9834 ELSE
9835
9836 --Find out the PC, PFC amount that should have got merged. This will be calculated as follows:
9837 --In the CI version, let us say, TotTxnRev is the total revenue in txn currency, TotPfcRev is the
9838 --total revenue in PFC, ParTxnRev is the amount that the user has entered for implementation and
9839 --ParPfcRev is the amount in PFC corresponding to ParTxnRev. If TotPfcRev corresponds to TotTxnRev
9840 --in PFC then ParPfcRev is nothging but ((ParTxnRev + ImplTxnRev) *TotPfcRev)/TotTxnRev. Here ImplTxnRev is
9841 --the revenue amount in txn currency that has already been implemented
9842 --Similary Partial amount in Project currency can also be calculated.
9843 IF l_total_amt_in_pfc = 0 THEN
9844
9845 l_pfc_rev_for_merge := 0;
9846
9847 ELSE
9848
9849 --(l_partial_impl_rev_amt + nvl(l_impl_amt,0) would constitute the total amount in
9850 --txn currency of the source version that has got implemented.
9851 l_pfc_rev_for_merge := ( (l_partial_impl_rev_amt + nvl(l_impl_amt,0)) * l_total_amt_in_pfc )/l_total_amt;
9852 l_pfc_rev_for_merge :=
9853 Pa_currency.round_trans_currency_amt1(l_pfc_rev_for_merge,
9854 l_projfunc_currency_code);
9855
9856 END IF;
9857
9858 IF l_total_amt_in_pc = 0 THEN
9859
9860 l_pc_rev_for_merge := 0;
9861
9862 ELSE
9863
9864 l_pc_rev_for_merge := ((l_partial_impl_rev_amt + nvl(l_impl_amt,0)) * l_total_amt_in_pc )/l_total_amt;
9865 l_pc_rev_for_merge :=
9866 Pa_currency.round_trans_currency_amt1(l_pc_rev_for_merge,
9867 l_project_currency_code);
9868
9869 END IF;
9870
9871 l_pfc_revenue_delta := l_pfc_rev_for_merge - l_pfc_rev_merged;
9872 l_pc_revenue_delta := l_pc_rev_for_merge - l_pc_rev_merged;
9873
9874 END IF;
9875 IF l_debug_mode = 'Y' THEN
9876 pa_debug.g_err_stage:='l_pfc_revenue_delta = '||l_pfc_revenue_delta
9877 || 'l_pc_revenue_delta = ' || l_pc_revenue_delta;
9878 pa_debug.write('Round_Budget_Line_Amounts: ' || l_module_name,pa_debug.g_err_stage,3);
9879 END IF;
9880
9881 IF (l_pfc_revenue_delta <> 0 OR l_pc_revenue_delta <> 0) THEN
9882
9883 -- Find source resource assignment id, budget line start_date into which
9884 -- the residual amount should be added
9885 IF l_src_resource_list_id = l_targ_resource_list_id THEN
9886
9887 OPEN src_delta_amt_adj_ra_cur(l_src_ver_id_tbl(j));
9888 FETCH src_delta_amt_adj_ra_cur INTO
9889 l_src_delta_amt_adj_task_id,
9890 l_targ_delta_amt_adj_rlm_id,
9891 l_src_delta_amt_adj_ra_id,
9892 l_src_dummy1,
9893 l_src_dummy2;
9894 CLOSE src_delta_amt_adj_ra_cur;
9895
9896 ELSE
9897
9898 OPEN src_delta_amt_adj_ra_cur1(l_src_ver_id_tbl(j));
9899 FETCH src_delta_amt_adj_ra_cur1 INTO
9900 l_src_delta_amt_adj_task_id,
9901 l_targ_delta_amt_adj_rlm_id,
9902 l_src_delta_amt_adj_ra_id,
9903 l_src_dummy1,
9904 l_src_dummy2;
9905 CLOSE src_delta_amt_adj_ra_cur1;
9906
9907 END IF;
9908
9909 OPEN src_delta_amt_adj_date_cur(l_src_delta_amt_adj_ra_id);
9910 FETCH src_delta_amt_adj_date_cur
9911 INTO l_src_delta_amt_adj_start_date;
9912 CLOSE src_delta_amt_adj_date_cur;
9913
9914 IF l_debug_mode = 'Y' THEN
9915 pa_debug.g_err_stage:= 'target ra id = '||get_mapped_ra_id(get_task_id(l_targ_plan_level_code,
9916 l_src_delta_amt_adj_task_id), l_targ_delta_amt_adj_rlm_id);
9917 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
9918 pa_debug.g_err_stage:= 'l_src_delta_amt_adj_start_date = '||l_src_delta_amt_adj_start_date;
9919 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
9920 pa_debug.g_err_stage:= 'l_targ_plan_level_code = '||l_targ_plan_level_code
9921 || 'l_src_delta_amt_adj_task_id = '||l_src_delta_amt_adj_task_id ;
9922 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
9923 END IF;
9924
9925 -- Using the source res assigment and target assignment mapping update
9926 -- the target version budget line. Note for AR Versions there can be amounts
9927 -- against txn currency only
9928 UPDATE pa_budget_lines
9929 SET revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0),
9930 txn_revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0), -- TXN and PFC should be same for AR versions
9931 project_revenue = nvl(project_revenue,0) + nvl(l_pc_revenue_delta,0)
9932 WHERE resource_assignment_id =
9933 get_mapped_ra_id(get_task_id(l_targ_plan_level_code,l_src_delta_amt_adj_task_id),
9934 l_targ_delta_amt_adj_rlm_id)
9935 AND l_src_delta_amt_adj_start_date BETWEEN start_date AND end_date
9936 AND budget_version_id = p_budget_version_id
9937 AND rownum < 2 -- not really necessary
9938 RETURNING
9939 budget_line_id
9940 INTO
9941 l_rounded_bl_id;
9942
9943 IF SQL%ROWCOUNT = 0 THEN
9944 -- If no row is updated, target must be None time phased version.
9945 -- So there would be only one line
9946 UPDATE pa_budget_lines
9947 SET revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0),
9948 txn_revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0), -- TXN and PFC should be same for AR versions
9949 project_revenue = nvl(project_revenue,0) + nvl(l_pc_revenue_delta,0)
9950 WHERE resource_assignment_id =
9951 get_mapped_ra_id(get_task_id(l_targ_plan_level_code,l_src_delta_amt_adj_task_id),
9952 l_targ_delta_amt_adj_rlm_id)
9953 AND budget_version_id = p_budget_version_id
9954 AND rownum < 2
9955 RETURNING
9956 budget_line_id
9957 INTO
9958 l_rounded_bl_id;
9959
9960 END IF;
9961
9962 --For non rate-based transaction, quantity should always be same as revenue. In the above update
9963 --revenue is modified. If the revenue is adjusted for non rate-based transaction then the change
9964 --should be made in quantity also. If the budget line is among those that are updated then in the
9965 --below FOR Loop will that budget line would also get updated. If the budget line is among those
9966 --budget lines that are inserted then it will be changed after the FOR loop. This variable
9967 --l_qty_adjusted_flag will be used to track this
9968 l_qty_adjusted_flag:='N';
9969
9970 --Since the amount is changed for a budget line in above update, the change has to be
9971 --propogated to the corresponding entry of pl/sql tbls prepared above
9972 FOR kk IN 1..l_upd_bl_id_tbl.COUNT LOOP
9973
9974 IF l_upd_bl_id_tbl(kk)=l_rounded_bl_id THEN
9975
9976 l_bl_REVENUE_tbl(kk) := nvl(l_bl_REVENUE_tbl(kk),0) + nvl(l_pfc_revenue_delta,0);
9977 l_bl_PROJECT_REVENUE_tbl(kk) := nvl(l_bl_PROJECT_REVENUE_tbl(kk),0) + nvl(l_pc_revenue_delta,0);
9978 l_bl_TXN_REVENUE_tbl(kk) := nvl(l_bl_TXN_REVENUE_tbl(kk),0) + nvl(l_pfc_revenue_delta,0); -- TXN and PFC should be same for AR versions
9979 --For non rate based transactions quantity should be same as revenue
9980 IF l_bl_rbf_flag_tbl(kk) = 'N' THEN
9981
9982 l_bl_QUANTITY_tbl(kk) := nvl(l_bl_TXN_REVENUE_tbl(kk),0) + nvl(l_pfc_revenue_delta,0);
9983
9984 UPDATE pa_budget_lines
9985 SET quantity=txn_revenue
9986 WHERE budget_line_id=l_rounded_bl_id;
9987
9988 l_qty_adjusted_flag:='Y';
9989
9990 END IF;
9991
9992 EXIT;
9993
9994 END IF;
9995
9996 END LOOP;
9997
9998 IF l_qty_adjusted_flag = 'N' THEN
9999
10000 SELECT pra.rate_based_flag
10001 INTO l_rounded_bl_rbf
10002 FROM pa_resource_assignments pra,
10003 pa_budget_lines pbl
10004 WHERE pra.resource_assignment_id = pbl.resource_assignment_id
10005 AND pbl.budget_line_id = l_rounded_bl_id;
10006
10007 IF l_rounded_bl_rbf ='N' THEN
10008
10009 UPDATE pa_budget_lines
10010 SET quantity=txn_revenue
10011 WHERE budget_line_id=l_rounded_bl_id;
10012
10013 END IF;
10014
10015 END IF;
10016
10017
10018 END IF;
10019 Exception
10020 WHEN OTHERS THEN
10021 IF P_PA_DEBUG_MODE = 'Y' THEN
10022 pa_debug.g_err_stage:='Error in residual amount adjust logic'||SQLERRM;
10023 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10024 END IF;
10025 RAISE;
10026 End;
10027
10028 IF l_debug_mode = 'Y' THEN
10029 pa_debug.g_err_stage:='End of residual amount logic';
10030 pa_debug.write('Round_Budget_Line_Amounts: ' || l_module_name,pa_debug.g_err_stage,3);
10031 END IF;
10032
10033 END IF;
10034
10035 --dbms_output.put_line('I45');
10036 -- Needs to execute only when calculate API has not been called
10037 IF NOT (l_src_time_phased_code = 'N' AND (l_targ_time_phased_code = 'P' OR l_targ_time_phased_code = 'G')) THEN
10038
10039 /* Bug 5726773:
10040 Start of coding done for Support of negative quantity/amounts enhancement.
10041 Call to the api CheckZeroQtyNegETC has been commented out below to allow
10042 creation of -ve quantity/amounts in the target version due to the change order
10043 merge. Commented out the delete and forall statements below which populate
10044 pa_fp_spread_calc_tmp with the resource assignment ids and budget version ids
10045 which will be used by the CheckZeroQtyNegETC api.
10046 */
10047 --Check if the budget lines have -Ve ETC because of the change order merge. This need not
10048 --not be done when calculate API is called since calculate API internally calls this API
10049 --Bug 4395494
10050 /*
10051 DELETE FROM pa_fp_spread_calc_tmp;
10052
10053 FORALL kk IN 1..l_targ_ra_id_tbl.COUNT
10054 INSERT INTO pa_fp_spread_calc_tmp
10055 (budget_version_id,
10056 resource_assignment_id)
10057 VALUES
10058 (p_budget_version_id,
10059 l_targ_ra_id_tbl(kk));
10060
10061 PA_FP_CALC_PLAN_PKG.CheckZeroQTyNegETC
10062 (p_budget_version_id => p_budget_version_id
10063 ,p_initialize => 'Y'
10064 ,x_return_status => l_return_status
10065 ,x_msg_count => l_msg_count
10066 ,x_msg_data => l_msg_data);
10067
10068 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10069 IF P_PA_debug_mode = 'Y' THEN
10070 pa_debug.g_err_stage:= 'Error CALLING PAFPCALB.CheckZeroQTyNegETC';
10071 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10072 END IF;
10073 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10074 END IF;
10075 */
10076 /* Bug 5726773: End of coding done for Support of negative quantity/amounts enhancement. */
10077
10078 ----Prepare the pl/sql tbls to call the API in planning transaction utils that calls PJI API
10079 ----plan_update
10080
10081 SELECT pa_budget_lines_s.currval
10082 INTO l_dummy
10083 FROM dual;
10084
10085 IF l_dummy=l_id_before_bl_insertion THEN
10086
10087 l_id_after_bl_insertion := l_id_before_bl_insertion;
10088
10089 ELSE
10090
10091 SELECT pa_budget_lines_s.nextval
10092 INTO l_id_after_bl_insertion
10093 FROM dual;
10094
10095 END IF;
10096
10097 IF l_id_before_bl_insertion <> l_id_after_bl_insertion THEN
10098
10099 IF P_PA_DEBUG_MODE = 'Y' THEN
10100 pa_debug.g_err_stage:='Preparing input tbls for calculate API';
10101 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10102 END IF;
10103
10104 SELECT pra.resource_assignment_id,
10105 'N',
10106 'Y',
10107 pbl.txn_currency_code,
10108 pbl.quantity,
10109 pbl.txn_raw_cost,
10110 pbl.txn_burdened_cost,
10111 pbl.txn_revenue,
10112 pbl.start_date,
10113 pbl.end_date,
10114 pbl.period_name,
10115 pbl.project_raw_cost,
10116 pbl.project_burdened_cost,
10117 pbl.project_revenue,
10118 pbl.raw_cost,
10119 pbl.burdened_cost,
10120 pbl.revenue,
10121 pbl.cost_rejection_code,
10122 pbl.revenue_rejection_code,
10123 pbl.burden_rejection_code,
10124 pbl.other_rejection_code,
10125 pbl.pc_cur_conv_rejection_code,
10126 pbl.pfc_cur_conv_rejection_code,
10127 pra.task_id,
10128 pra.rbs_element_id,
10129 pra.resource_class_code,
10130 pra.rate_based_flag
10131 BULK COLLECT INTO
10132 l_res_assignment_id_tbl,
10133 l_delete_budget_lines_tbl,
10134 l_spread_amount_flags_tbl,
10135 l_currency_code_tbl,
10136 l_total_quantity_tbl,
10137 l_total_raw_cost_tbl,
10138 l_total_burdened_cost_tbl,
10139 l_total_revenue_tbl,
10140 l_prm_bl_start_date_tbl,
10141 l_prm_bl_end_date_tbl,
10142 l_period_name_tbl,
10143 l_pc_raw_cost_tbl,
10144 l_pc_burd_cost_tbl,
10145 l_pc_revenue_tbl,
10146 l_pfc_raw_cost_tbl,
10147 l_pfc_burd_cost_tbl,
10148 l_pfc_revenue_tbl,
10149 l_cost_rejection_code,
10150 l_revenue_rejection_code,
10151 l_burden_rejection_code,
10152 l_other_rejection_code,
10153 l_pc_cur_conv_rejection_code,
10154 l_pfc_cur_conv_rejection_code,
10155 l_pji_prm_task_id_tbl,
10156 l_pji_prm_rbs_elem_id_tbl,
10157 l_pji_prm_res_cls_code_tbl,
10158 l_pji_prm_rbf_tbl
10159 FROM pa_resource_assignments pra,
10160 pa_budget_lines pbl
10161 WHERE pra.resource_assignment_id = pbl.resource_assignment_id
10162 AND (pbl.budget_line_id BETWEEN l_id_before_bl_insertion AND l_id_after_bl_insertion)
10163 AND pra.budget_Version_id=p_budget_version_id;
10164
10165 IF P_PA_DEBUG_MODE = 'Y' THEN
10166 pa_debug.g_err_stage:='l_res_assignment_id_tbl.COUNT IS '||l_res_assignment_id_tbl.COUNT;
10167 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10168
10169 pa_debug.g_err_stage:='l_rev_impl_flag '||l_rev_impl_flag;
10170 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10171
10172 pa_debug.g_err_stage:=' l_impl_qty_tbl('||j || ') is '|| l_impl_qty_tbl(j);
10173 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10174
10175 END IF;
10176
10177 END IF;--IF l_id_before_bl_insertion <> l_id_after_bl_insertion THEN
10178
10179 --Budget lines might have got updated in addition to getting inserted because of merge
10180 --Those budget lines should also be considered while calling PJI API Plan_Update
10181 --Note that l_bl_RESOURCE_ASIGNMENT_ID_tbl will contain BLs corresponding to BLs that got inserted
10182 --as well as updated. Here we should consider only those BLs that have got updated. BLs that
10183 --are inserted are considered in the earlier block
10184
10185 /* Bug 5335211: Removing the check for null rbs_version_id, to populate the variables always
10186 * so that they contain proper values when calling the PJI rollup API, irrespective of whether
10187 * a RBS is present in the target version or not.
10188 IF l_rbs_version_id IS NOT NULL THEN */
10189 IF l_bl_RESOURCE_ASIGNMENT_ID_tbl.COUNT > 0 THEN
10190
10191 IF P_PA_DEBUG_MODE = 'Y' THEN
10192 pa_debug.g_err_stage:='Preparing tbls for for the lines that got update';
10193 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10194 END IF;
10195
10196
10197 --This index will be used for l_updXXX tbls containinng data for the BLs that have got
10198 --updated. As told above l_bl_RESOURCE_ASIGNMENT_ID_tbl contains data for BLs that have
10199 --inserted as well as updated. Here we need to cosider only those rows that have got updated
10200 --Hence differenct index is required
10201 l_index:=0;
10202 FOR kk in l_bl_RESOURCE_ASIGNMENT_ID_tbl.FIRST..l_bl_RESOURCE_ASIGNMENT_ID_tbl.LAST LOOP
10203
10204 IF l_upd_ra_bl_dml_code_tbl(kk) = 'UPDATE' THEN
10205
10206 l_index:=l_index+1;
10207
10208 l_res_assignment_id_tbl.extend;
10209 l_period_name_tbl.extend;
10210 l_currency_code_tbl.extend;
10211 l_total_quantity_tbl.extend;
10212 l_total_raw_cost_tbl.extend;
10213 l_total_burdened_cost_tbl.extend;
10214 l_total_revenue_tbl.extend;
10215 l_prm_bl_start_date_tbl.extend;
10216 l_prm_bl_end_date_tbl.extend;
10217 l_pc_raw_cost_tbl.extend;
10218 l_pc_burd_cost_tbl.extend;
10219 l_pc_revenue_tbl.extend;
10220 l_pfc_raw_cost_tbl.extend;
10221 l_pfc_burd_cost_tbl.extend;
10222 l_pfc_revenue_tbl.extend;
10223 l_cost_rejection_code.extend;
10224 l_revenue_rejection_code.extend;
10225 l_burden_rejection_code.extend;
10226 l_other_rejection_code.extend;
10227 l_pc_cur_conv_rejection_code.extend;
10228 l_pfc_cur_conv_rejection_code.extend;
10229
10230 IF P_PA_DEBUG_MODE = 'Y' THEN
10231 pa_debug.g_err_stage:='Done with tbl extending';
10232 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10233 END IF;
10234
10235
10236 --Here l_res_assignment_id_tbl, l_delete_budget_lines_tbl are already populated above with the
10237 --budget line details that have got inserted. Also all the will have the same length.
10238 --Hence using l_res_assignment_id_tbl.count as index
10239
10240 IF P_PA_DEBUG_MODE = 'Y' THEN
10241 pa_debug.g_err_stage:=' B l_res_assignment_id_tbl.count is '||l_res_assignment_id_tbl.count;
10242 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10243 END IF;
10244
10245 l_res_assignment_id_tbl(l_res_assignment_id_tbl.count) := l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk);
10246
10247 IF P_PA_DEBUG_MODE = 'Y' THEN
10248
10249 pa_debug.g_err_stage:=' A l_res_assignment_id_tbl.count is '||l_res_assignment_id_tbl.count;
10250 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10251
10252 pa_debug.g_err_stage:='Done with l_res_assignment_id_tbl';
10253 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10254
10255 pa_debug.g_err_stage:='l_period_name_tbl.count is '||l_period_name_tbl.count;
10256 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10257
10258 pa_debug.g_err_stage:='l_upd_period_name_tbl('||kk||') is '||l_upd_period_name_tbl(l_index);
10259 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10260
10261
10262 END IF;
10263
10264 l_period_name_tbl(l_period_name_tbl.count) :=l_upd_period_name_tbl(l_index);
10265
10266 IF P_PA_DEBUG_MODE = 'Y' THEN
10267 pa_debug.g_err_stage:='Done with l_period_name_tbl';
10268 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10269 END IF;
10270
10271 l_currency_code_tbl(l_res_assignment_id_tbl.count) := l_upd_currency_code_tbl(l_index);
10272
10273 IF P_PA_DEBUG_MODE = 'Y' THEN
10274 pa_debug.g_err_stage:='Done with l_currency_code_tbl';
10275 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10276 END IF;
10277
10278 l_total_quantity_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_QUANTITY_tbl(kk),0);
10279 l_total_raw_cost_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_TXN_RAW_COST_tbl(kk),0);
10280 l_total_burdened_cost_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0);
10281 l_total_revenue_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_TXN_REVENUE_tbl(kk),0);
10282 l_prm_bl_start_date_tbl(l_res_assignment_id_tbl.count) := l_upd_bl_start_date_tbl(l_index);
10283 l_prm_bl_end_date_tbl(l_res_assignment_id_tbl.count) := l_upd_bl_end_date_tbl(l_index);
10284 l_cost_rejection_code(l_res_assignment_id_tbl.count) := l_upd_cost_rejection_code(l_index);
10285 l_revenue_rejection_code(l_res_assignment_id_tbl.count) := l_upd_revenue_rejection_code(l_index);
10286 l_burden_rejection_code(l_res_assignment_id_tbl.count) := l_upd_burden_rejection_code(l_index);
10287 l_other_rejection_code(l_res_assignment_id_tbl.count) := l_upd_other_rejection_code(l_index);
10288 l_pc_cur_conv_rejection_code(l_res_assignment_id_tbl.count) := l_upd_pc_cur_conv_rej_code(l_index);
10289 l_pfc_cur_conv_rejection_code(l_res_assignment_id_tbl.count):= l_upd_pfc_cur_conv_rej_code(l_index);
10290 l_pc_raw_cost_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0);
10291 l_pc_burd_cost_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0);
10292 l_pc_revenue_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_PROJECT_REVENUE_tbl(kk),0);
10293 l_pfc_raw_cost_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_RAW_COST_tbl(kk),0);
10294 l_pfc_burd_cost_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_BURDENED_COST_tbl(kk),0);
10295 l_pfc_revenue_tbl(l_res_assignment_id_tbl.count) := nvl(l_bl_REVENUE_tbl(kk),0);
10296
10297 IF P_PA_DEBUG_MODE = 'Y' THEN
10298 pa_debug.g_err_stage:='Done with bl tbl copy. Proceeding to get RA attributes';
10299 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10300 END IF;
10301
10302 l_temp:=NULL;
10303 --Loop thru the resource assignments that were updated earlier to get the details
10304 --such as task id, resource class code etc.Bug 3678314
10305 FOR LL IN 1..l_upd_ra_res_asmt_id_tbl.COUNT LOOP
10306 IF l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk)=l_upd_ra_res_asmt_id_tbl(LL) THEN
10307
10308 l_temp:=LL;
10309 EXIT;
10310
10311 END IF;
10312
10313 END LOOP;
10314
10315 --The below condition should never happen since if a budget line gets updated then
10316 --the corresponding RA should also get updated and hence it should be part of l_upd_ra_res_asmt_id_tbl
10317 --Bug 3678314
10318 IF l_temp IS NULL THEN
10319
10320 IF P_PA_DEBUG_MODE = 'Y' THEN
10321 pa_debug.g_err_stage:='RA in l_bl_RESOURCE_ASIGNMENT_ID_tbl '||l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk) ||' doesnt exist in l_upd_ra_res_asmt_id_tbl ';
10322 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10323 END IF;
10324
10325 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10326
10327 END IF;
10328
10329 l_pji_prm_task_id_tbl.extend;
10330 l_pji_prm_rbs_elem_id_tbl.extend;
10331 l_pji_prm_res_cls_code_tbl.extend;
10332 l_pji_prm_rbf_tbl.extend;
10333 l_pji_prm_task_id_tbl(l_res_assignment_id_tbl.count):=l_upd_ra_task_id_tbl(l_temp);
10334 l_pji_prm_rbs_elem_id_tbl(l_res_assignment_id_tbl.count):=l_upd_ra_rbs_elem_id_tbl(l_temp);
10335 l_pji_prm_res_cls_code_tbl(l_res_assignment_id_tbl.count):=l_upd_ra_res_class_code_tbl(l_temp);
10336 l_pji_prm_rbf_tbl(l_res_assignment_id_tbl.count):=l_upd_ra_rbf_tbl(l_temp);
10337
10338 IF P_PA_DEBUG_MODE = 'Y' THEN
10339 pa_debug.g_err_stage:='Done with ra tbl copy';
10340 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10341 END IF;
10342
10343 END IF;
10344
10345 END LOOP;-- FOR kk in l_bl_RESOURCE_ASIGNMENT_ID_tbl.FIRST..l_bl_RESOURCE_ASIGNMENT_ID_tbl..LAST LOOP
10346
10347 END IF;--IF l_bl_RESOURCE_ASIGNMENT_ID_tbl.COUNT>O THEN
10348
10349 /* END IF;--IF l_rbs_version_id IS NOT NULL THEN : Bug 5335211 */
10350
10351 IF P_PA_DEBUG_MODE = 'Y' THEN
10352 pa_debug.g_err_stage:='Calling rollup api ........ ';
10353 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10354 END IF;
10355
10356 PA_FP_ROLLUP_PKG.ROLLUP_BUDGET_VERSION
10357 ( p_budget_version_id => p_budget_version_id
10358 ,p_entire_version => 'Y'
10359 ,x_return_status => l_return_status
10360 ,x_msg_count => l_msg_count
10361 ,x_msg_data => l_msg_data);
10362
10363 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10364 IF P_PA_debug_mode = 'Y' THEN
10365 pa_debug.g_err_stage:= 'Error in ROLLUP_BUDGET_VERSION';
10366 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10367 END IF;
10368 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10369 END IF;
10370
10371 --dbms_output.put_line('I46');
10372
10373 -- Bug Fix: 4569365. Removed MRC code.
10374 /*
10375 IF P_PA_DEBUG_MODE = 'Y' THEN
10376 pa_debug.g_err_stage:='Calling mrc api ........ ';
10377 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10378 END IF;
10379
10380 IF PA_MRC_FINPLAN.g_mrc_enabled_for_budgets IS NULL THEN
10381 PA_MRC_FINPLAN.check_mrc_install
10382 (x_return_status => l_return_status,
10383 x_msg_count => l_msg_count,
10384 x_msg_data => l_msg_data);
10385 END IF;
10386
10387 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10388 IF P_PA_debug_mode = 'Y' THEN
10389 pa_debug.g_err_stage:= 'Error in g_mrc_enabled_for_budgets';
10390 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10391 END IF;
10392 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10393 END IF;
10394
10395 --dbms_output.put_line('I47');
10396
10397 IF PA_MRC_FINPLAN.g_mrc_enabled_for_budgets AND
10398 PA_MRC_FINPLAN.g_finplan_mrc_option_code = 'A' THEN
10399
10400 PA_MRC_FINPLAN.g_calling_module := NULL;
10401
10402 PA_MRC_FINPLAN.maintain_all_mc_budget_lines
10403 (p_fin_plan_version_id => p_budget_version_id,
10404 p_entire_version => 'Y',
10405 x_return_status => x_return_status,
10406 x_msg_count => x_msg_count,
10407 x_msg_data => x_msg_data);
10408
10409
10410 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10411 IF P_PA_debug_mode = 'Y' THEN
10412 pa_debug.g_err_stage:= 'Error in maintain_all_mc_budget_lines';
10413 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10414 END IF;
10415 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10416 END IF;
10417
10418
10419 END IF;
10420 */
10421
10422 --IPM Architecture Enhancement: Start Bug 4865563
10423 -- The PA_RESOURCE_ASGN_CURR maintenance api updates the pa_budget_lines manually.
10424 -- populate_display_quantity populates the display_quantity appropriately
10425
10426 --This api will take care of inserting display_quantity appropriately.Not necessary to insert every time in the budget lines
10427 PA_BUDGET_LINES_UTILS.populate_display_qty
10428 (p_budget_version_id => p_budget_version_id,
10429 p_context => 'FINANCIAL',
10430 --p_use_temp_table_flag => 'N',
10431 --p_resource_assignment_id_tab => l_res_assignment_id_tbl,
10432 p_set_disp_qty_null_for_nrbf => 'Y',
10433 x_return_status => l_return_status);
10434
10435 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10436 IF P_PA_debug_mode = 'Y' THEN
10437 pa_debug.g_err_stage:= 'Error in PA_BUDGET_LINES_UTILS.populate_display_qty';
10438 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10439 END IF;
10440 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10441 END IF;
10442
10443
10444 PA_FP_GEN_AMOUNT_UTILS.GET_PLAN_VERSION_DTLS
10445 (P_BUDGET_VERSION_ID => p_budget_version_id,
10446 X_FP_COLS_REC => l_fp_cols_rec,
10447 X_RETURN_STATUS => l_return_status,
10448 X_MSG_COUNT => l_msg_count,
10449 X_MSG_DATA => l_msg_data);
10450
10451 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10452 IF P_PA_debug_mode = 'Y' THEN
10453 pa_debug.g_err_stage:= 'Error in PA_FP_GEN_AMOUNT_UTILS.GET_PLAN_VERSION_DETAILS';
10454 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10455 END IF;
10456 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10457 END IF;
10458
10459
10460 pa_res_asg_currency_pub.maintain_data
10461 (p_fp_cols_rec => l_fp_cols_rec,
10462 p_calling_module => 'CHANGE_MGT',
10463 p_rollup_flag => 'Y',
10464 p_version_level_flag => 'Y',
10465 p_called_mode => 'SELF_SERVICE',
10466 x_return_status => l_return_status,
10467 x_msg_data => l_msg_data,
10468 x_msg_count => l_msg_count);
10469
10470 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10471 IF P_PA_debug_mode = 'Y' THEN
10472 pa_debug.g_err_stage:= 'Error in PA_RES_ASG_CURRENCY_PUB.MAINTAIN_DATA';
10473 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10474 END IF;
10475 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10476 END IF;
10477
10478 /* bug 5073816: At this point of time, the new entity would have records
10479 * from the resource assignments in the target versions which have amounts.
10480 * it is possible that some of the RAs created in the target version which
10481 * do not have any budget lines would not be inserted into pa_resource_asgn_curr
10482 * by the maintenance API. So to insert those left over RAs, we are calling
10483 * the following.
10484 */
10485 pa_fin_plan_pub.create_default_plan_txn_rec
10486 (p_budget_version_id => p_budget_version_id,
10487 p_calling_module => 'CHANGE_MGT',
10488 x_return_status => l_return_status,
10489 x_msg_count => l_msg_count,
10490 x_msg_data => l_msg_data);
10491
10492 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10493 IF P_PA_debug_mode = 'Y' THEN
10494 pa_debug.g_err_stage:= 'Error in pa_fin_plan_pub.create_default_plan_txn_rec';
10495 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10496 END IF;
10497 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10498 END IF;
10499
10500 --IPM Architecture Enhancement: End Bug 4865563
10501
10502
10503 --Call the PJI Plan Updte API only if the calculate API is not called earlier
10504 IF (NOT (l_src_time_phased_code = 'N' AND (l_targ_time_phased_code = 'P' OR l_targ_time_phased_code = 'G'))) AND
10505 l_call_rep_lines_api ='Y' THEN
10506
10507 -- Bug 5335211: Removing the check for null rbs_version_id
10508 -- IF l_rbs_version_id IS NOT NULL AND -- end bug 5335211
10509 IF l_res_assignment_id_tbl.COUNT>0 THEN
10510
10511 IF P_PA_DEBUG_MODE = 'Y' THEN
10512 pa_debug.g_err_stage := 'Calling pa_planning_transaction_utils.call_update_rep_lines_api';
10513 pa_debug.write( l_module_name,pa_debug.g_err_stage,3);
10514 END IF;
10515 pa_planning_transaction_utils.call_update_rep_lines_api
10516 (
10517 p_source => 'PL-SQL'
10518 ,p_budget_version_id => p_budget_version_id
10519 ,p_resource_assignment_id_tbl => l_res_assignment_id_tbl
10520 ,p_period_name_tbl => l_period_name_tbl
10521 ,p_start_date_tbl => l_prm_bl_start_date_tbl
10522 ,p_end_date_tbl => l_prm_bl_end_date_tbl
10523 ,p_txn_currency_code_tbl => l_currency_code_tbl
10524 ,p_txn_raw_cost_tbl => l_total_raw_cost_tbl
10525 ,p_txn_burdened_cost_tbl => l_total_burdened_cost_tbl
10526 ,p_txn_revenue_tbl => l_total_revenue_tbl
10527 ,p_project_raw_cost_tbl => l_pc_raw_cost_tbl
10528 ,p_project_burdened_cost_tbl => l_pc_burd_cost_tbl
10529 ,p_project_revenue_tbl => l_pc_revenue_tbl
10530 ,p_raw_cost_tbl => l_pfc_raw_cost_tbl
10531 ,p_burdened_cost_tbl => l_pfc_burd_cost_tbl
10532 ,p_revenue_tbl => l_pfc_revenue_tbl
10533 ,p_cost_rejection_code_tbl => l_cost_rejection_code
10534 ,p_revenue_rejection_code_tbl => l_revenue_rejection_code
10535 ,p_burden_rejection_code_tbl => l_burden_rejection_code
10536 ,p_other_rejection_code => l_other_rejection_code
10537 ,p_pc_cur_conv_rej_code_tbl => l_pc_cur_conv_rejection_code
10538 ,p_pfc_cur_conv_rej_code_tbl => l_pfc_cur_conv_rejection_code
10539 ,p_quantity_tbl => l_total_quantity_tbl
10540 ,p_rbs_element_id_tbl => l_pji_prm_rbs_elem_id_tbl
10541 ,p_task_id_tbl => l_pji_prm_task_id_tbl
10542 ,p_res_class_code_tbl => l_pji_prm_res_cls_code_tbl
10543 ,p_rate_based_flag_tbl => l_pji_prm_rbf_tbl
10544 ,x_return_status => x_return_status
10545 ,x_msg_count => x_msg_count
10546 ,x_msg_data => x_msg_data);
10547
10548 IF x_return_Status <> FND_API.G_RET_STS_SUCCESS THEN
10549 IF P_PA_DEBUG_MODE = 'Y' THEN
10550 pa_debug.g_err_stage := 'pa_planning_transaction_utils.call_update_rep_lines_api errored .... ' || x_msg_data;
10551 pa_debug.write( l_module_name,pa_debug.g_err_stage,5);
10552 END IF;
10553 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10554 END IF;
10555
10556 END IF;--IF l_rbs_version_id IS NOT NULL AND
10557
10558 END IF;--IF (NOT (l_src_time_phased_code = 'N' AND (l_targ_time_phased_code = 'P' OR l_targ_time_phased_code = 'G'))) AND
10559 --dbms_output.put_line('I48');
10560 END IF;
10561
10562 --dbms_output.put_line('I49');
10563 IF P_submit_version_flag = 'Y' THEN
10564 IF l_targ_app_rev_flag = 'Y' AND
10565 l_impl_type_tbl(j) <> 'COST' AND
10566 l_rev_impl_flag ='Y' THEN
10567
10568 --In this code to put the residual amount into the last budget line would have got executed and
10569 --hence l_targ_pc/pfc_rev_after_merge and l_pc/pfc_revenue_delta would have got populated above
10570 IF l_partial_factor <> 1 THEN
10571
10572 l_impl_pc_rev_amt := l_targ_pc_rev_after_merge - l_targ_pc_rev_before_merge + l_pc_revenue_delta;
10573 l_impl_pfc_rev_amt := l_targ_pfc_rev_after_merge - l_targ_pfc_rev_before_merge + l_pfc_revenue_delta;
10574
10575 ELSE
10576 --Derive l_pc/pfc_revenue_delta. In this case we have to go to pa_budget_lines since the amounts
10577 --would not have got rolled up
10578 SELECT sum(pbl.project_revenue) - l_targ_pc_rev_before_merge
10579 ,sum(pbl.revenue) - l_targ_pfc_rev_before_merge
10580 INTO l_impl_pc_rev_amt
10581 ,l_impl_pfc_rev_amt
10582 FROM pa_budget_lines pbl
10583 WHERE budget_version_id=p_budget_version_id;
10584
10585 END IF;
10586
10587 pa_fp_ci_implement_pkg.create_ci_impact_fund_lines
10588 (p_project_id => l_project_id,
10589 p_ci_id => p_ci_id,
10590 p_update_agr_amount_flag => P_update_agreement_amt_flag,
10591 p_funding_category => p_funding_category,
10592 p_partial_factor => l_partial_factor,
10593 p_impl_txn_rev_amt => l_partial_impl_rev_amt,
10594 p_impl_pc_rev_amt => l_impl_pc_rev_amt,
10595 p_impl_pfc_rev_amt => l_impl_pfc_rev_amt,
10596 x_msg_data => l_msg_data,
10597 x_msg_count => l_msg_count,
10598 x_return_status => l_return_status);
10599
10600 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10601 IF P_PA_debug_mode = 'Y' THEN
10602 pa_debug.g_err_stage:= 'Error in create_ci_impact_fund_lines';
10603 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10604 END IF;
10605 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10606 END IF;
10607
10608 END IF;
10609
10610 --If the version is approved revenue version and if the project is enabled for auto
10611 --baseline then the version should be baselined
10612 --Submit the version if the project is not enabled for baseline or if the version is not
10613 --an approved revenue version.
10614 --please NOTE that the its not required to check whether the target version is the current
10615 --working version or not as
10616 ----P_submit_version_flag can be Y only when this API is called IMplement Financial Impact
10617 ----page and in that page impact will always be implemented into the current working version.
10618 /*IF l_baseline_funding_flag ='Y' AND
10619 l_targ_app_rev_flag = 'Y' AND
10620 l_impl_type_tbl(j) <> 'COST' AND
10621 l_rev_impl_flag ='Y' THEN
10622
10623 IF P_PA_debug_mode = 'Y' THEN
10624 pa_debug.g_err_stage:= 'Calling the change management baseline API';
10625 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10626 END IF;
10627
10628 l_CI_ID_Tab.delete;
10629 l_CI_ID_Tab(1):=p_ci_id;
10630
10631 pa_baseline_funding_pkg.change_management_baseline
10632 (P_Project_ID => l_project_id,
10633 P_CI_ID_Tab => l_CI_ID_Tab,
10634 X_Err_Code => X_Err_Code,
10635 X_Status => l_return_status);
10636
10637 IF X_Err_Code <> 0 THEN
10638 IF P_PA_debug_mode = 'Y' THEN
10639 pa_debug.g_err_stage:= 'Error in change_management_baseline';
10640 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10641 END IF;
10642 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10643 END IF;
10644
10645 ELSE*/-- Commented as part of bug 3877815, would remove completely, once review is done.
10646
10647 SELECT record_version_number
10648 INTO l_record_version_number
10649 FROM pa_budget_versions
10650 WHERE budget_version_id=p_budget_version_id;
10651
10652 pa_fin_plan_pub.Submit_Current_Working
10653 (p_project_id => l_project_id,
10654 p_budget_version_id => p_budget_version_id,
10655 p_record_version_number => l_record_version_number,
10656 x_return_status => l_return_status,
10657 x_msg_count => l_msg_count,
10658 x_msg_data => l_msg_data);
10659
10660 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10661 IF P_PA_debug_mode = 'Y' THEN
10662 pa_debug.g_err_stage:= 'Error in Submit_Current_Working';
10663 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10664 END IF;
10665 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10666 END IF;
10667
10668 /*END IF;*/
10669
10670 END IF;--IF P_submit_version_flag = 'Y' THEN
10671
10672 END IF;--IF l_partial_factor<>0
10673
10674 END IF;--If l_targ_ra_id_tbl.COUNT>0
10675 --dbms_output.put_line('I50');
10676 -- Preparing input parameters for FP_CI_LINK_CONTROL_ITEMS
10677
10678 /* Opening a cursor to get the project levee amounts. */
10679
10680 OPEN c_proj_level_amounts;
10681
10682
10683
10684 IF P_PA_DEBUG_MODE = 'Y' THEN
10685 pa_debug.g_err_stage := 'fetching project level amounts';
10686 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10687 END IF;
10688
10689
10690
10691 FETCH c_proj_level_amounts INTO
10692 l_targ_pc_rawc_after_merge
10693 ,l_targ_pc_burdc_after_merge
10694 ,l_targ_pc_rev_after_merge
10695 ,l_targ_pfc_rawc_after_merge
10696 ,l_targ_pfc_burdc_after_merge
10697 ,l_targ_pfc_rev_after_merge
10698 ,l_targ_lab_qty_after_merge
10699 ,l_targ_eqp_qty_after_merge;
10700
10701 CLOSE c_proj_level_amounts;
10702
10703
10704 l_cost_ppl_qty := null;
10705 l_rev_ppl_qty := null;
10706 l_cost_equip_qty := null;
10707 l_rev_equip_qty := null;
10708 l_impl_pfc_raw_cost := null;
10709 l_impl_pfc_revenue := null;
10710 l_impl_pfc_burd_cost := null;
10711 l_impl_pc_raw_cost := null;
10712 l_impl_pc_revenue := null;
10713 l_impl_pc_burd_cost := null;
10714
10715 IF l_cost_impl_flag = 'Y' THEN
10716 l_cost_ppl_qty := l_targ_lab_qty_after_merge-l_targ_lab_qty_before_merge;
10717 l_cost_equip_qty := l_targ_eqp_qty_after_merge-l_targ_eqp_qty_before_merge;
10718 l_impl_pfc_raw_cost := l_targ_pfc_rawc_after_merge-l_targ_pfc_rawc_before_merge;
10719 l_impl_pfc_burd_cost := l_targ_pfc_burdc_after_merge-l_targ_pfc_burdc_before_merge;
10720 l_impl_pc_raw_cost := l_targ_pc_rawc_after_merge-l_targ_pc_rawc_before_merge;
10721 l_impl_pc_burd_cost := l_targ_pc_burdc_after_merge-l_targ_pc_burdc_before_merge;
10722 END IF;
10723
10724 IF l_rev_impl_flag = 'Y' THEN
10725 IF l_impl_qty_tbl(j) = 'Y' AND l_impl_type_tbl(j) <> 'ALL' THEN -- Bug 3947169
10726 l_rev_ppl_qty := l_targ_lab_qty_after_merge-l_targ_lab_qty_before_merge;
10727 l_rev_equip_qty := l_targ_eqp_qty_after_merge-l_targ_eqp_qty_before_merge;
10728 END IF;
10729
10730 l_impl_pfc_revenue := l_targ_pfc_rev_after_merge - l_targ_pfc_rev_before_merge;
10731 l_impl_pc_revenue := l_targ_pc_rev_after_merge - l_targ_pc_rev_before_merge;
10732 END IF;
10733
10734 IF l_impl_type_tbl(j) = 'ALL' THEN
10735 l_version_type := 'BOTH';
10736 ELSE
10737 l_version_type := l_impl_type_tbl(j);
10738 END IF;
10739
10740 --dbms_output.put_line('I51');
10741
10742
10743 IF P_PA_debug_mode = 'Y' THEN
10744 pa_debug.g_err_stage:= 'l_cost_ppl_qty '||l_cost_ppl_qty;
10745 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10746
10747 pa_debug.g_err_stage:= 'l_rev_ppl_qty '||l_rev_ppl_qty;
10748 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10749
10750 pa_debug.g_err_stage:= 'l_cost_equip_qty '||l_cost_equip_qty;
10751 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10752
10753 pa_debug.g_err_stage:= 'l_rev_equip_qty '||l_rev_equip_qty;
10754 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10755
10756 pa_debug.g_err_stage:= 'l_impl_pfc_raw_cost '||l_impl_pfc_raw_cost;
10757 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10758
10759 pa_debug.g_err_stage:= 'l_impl_pfc_revenue '||l_impl_pfc_revenue;
10760 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10761
10762 pa_debug.g_err_stage:= 'l_impl_pfc_burd_cost '||l_impl_pfc_burd_cost;
10763 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10764
10765 pa_debug.g_err_stage:= 'l_impl_pc_raw_cost '||l_impl_pc_raw_cost;
10766 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10767
10768 pa_debug.g_err_stage:= 'l_impl_pc_revenue '||l_impl_pc_revenue;
10769 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10770
10771 pa_debug.g_err_stage:= 'l_impl_pc_burd_cost '||l_impl_pc_burd_cost;
10772 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10773
10774 pa_debug.g_err_stage:= 'l_partial_impl_rev_amt '||l_partial_impl_rev_amt;
10775 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10776
10777 END IF;
10778
10779 IF l_impl_earlier='N' THEN
10780
10781 pa_fp_ci_merge.FP_CI_LINK_CONTROL_ITEMS(
10782 p_project_id => l_project_id
10783 ,p_s_fp_version_id => l_src_ver_id_tbl(j)
10784 ,p_t_fp_version_id => p_budget_version_id
10785 ,p_inclusion_method => 'AUTOMATIC'
10786 ,p_included_by => NULL
10787 ,p_version_type => l_version_type
10788 ,p_ci_id => p_ci_id
10789 ,p_cost_ppl_qty => l_cost_ppl_qty
10790 ,p_rev_ppl_qty => l_rev_ppl_qty
10791 ,p_cost_equip_qty => l_cost_equip_qty
10792 ,p_rev_equip_qty => l_rev_equip_qty
10793 ,p_impl_pfc_raw_cost => l_impl_pfc_raw_cost
10794 ,p_impl_pfc_revenue => l_impl_pfc_revenue
10795 ,p_impl_pfc_burd_cost => l_impl_pfc_burd_cost
10796 ,p_impl_pc_raw_cost => l_impl_pc_raw_cost
10797 ,p_impl_pc_revenue => l_impl_pc_revenue
10798 ,p_impl_pc_burd_cost => l_impl_pc_burd_cost
10799 ,p_impl_agr_revenue => l_partial_impl_rev_amt
10800 ,x_return_status => l_return_status
10801 ,x_msg_count => l_msg_count
10802 ,x_msg_data => l_msg_data
10803 ) ;
10804
10805 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10806 IF P_PA_debug_mode = 'Y' THEN
10807 pa_debug.g_err_stage:= 'Error in FP_CI_LINK_CONTROL_ITEMS';
10808 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10809 END IF;
10810 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10811 END IF;
10812
10813 ELSE--IF l_impl_earlier='Y'
10814
10815 IF l_version_type IN ('REVENUE', 'BOTH') THEN
10816
10817 UPDATE pa_fp_merged_ctrl_items
10818 SET impl_proj_func_revenue =nvl(impl_proj_func_revenue,0)+nvl(l_impl_pfc_revenue,0)
10819 ,impl_proj_revenue =nvl(impl_proj_revenue,0)+nvl(l_impl_pc_revenue,0)
10820 ,impl_quantity =nvl(impl_quantity,0)+nvl(l_rev_ppl_qty,0)
10821 ,impl_equipment_quantity =nvl(impl_equipment_quantity,0)+nvl(l_rev_equip_qty,0)
10822 ,impl_agr_revenue =nvl(impl_agr_revenue,0) + nvl(l_partial_impl_rev_amt,0)
10823 ,record_version_number =record_version_number+1
10824 ,last_update_date =sysdate
10825 ,last_update_login =fnd_global.login_id
10826 ,last_updated_by =fnd_global.user_id
10827 WHERE project_id=l_project_id
10828 AND plan_version_id=p_budget_version_id
10829 AND ci_id=p_ci_id
10830 AND ci_plan_version_id=l_src_ver_id_tbl(j)
10831 AND version_type='REVENUE';
10832
10833 END IF;
10834
10835 END IF;
10836
10837 --rev_partially_impl_flag of pa_budget_Versions should be updated in case of partial implementation
10838 --It should be Y if the CO is implemented partially. It should be N if the CO has got fully implemented
10839 -- If the CO has earlier been partially implemented(l_impl_earlier = 'Y'), inclusion will make it fully implemented.
10840 -- So, rev_partially_impl_flag should be set to 'N'
10841 IF p_context='PARTIAL_REV' OR l_impl_earlier = 'Y' THEN
10842
10843 IF nvl(l_impl_amt,0) + l_partial_impl_rev_amt = l_total_amt THEN
10844
10845 UPDATE pa_budget_versions
10846 SET rev_partially_impl_flag ='N'
10847 ,record_version_number =record_version_number+1
10848 ,last_update_date =sysdate
10849 ,last_update_login =fnd_global.login_id
10850 ,last_updated_by =fnd_global.user_id
10851 WHERE budget_version_id = l_src_ver_id_tbl(j);
10852
10853 ELSE
10854
10855 --Update pa_budget_versions only if rev_partially_impl_flag is not already Y
10856 UPDATE pa_budget_versions
10857 SET rev_partially_impl_flag ='Y'
10858 ,record_version_number =record_version_number+1
10859 ,last_update_date =sysdate
10860 ,last_update_login =fnd_global.login_id
10861 ,last_updated_by =fnd_global.user_id
10862 WHERE budget_version_id = l_src_ver_id_tbl(j)
10863 AND nvl(rev_partially_impl_flag,'N')='N';
10864
10865 END IF;
10866
10867 END IF;
10868
10869 --dbms_output.put_line('I52');
10870 IF (l_targ_app_cost_flag = 'Y' OR l_targ_app_rev_flag = 'Y') AND l_current_working_flag = 'Y' THEN
10871 l_impact_type_code := 'FINPLAN_' || l_version_type;
10872 pa_fp_ci_merge.FP_CI_UPDATE_IMPACT
10873 (p_ci_id => p_ci_id
10874 ,p_status_code => 'CI_IMPACT_IMPLEMENTED'
10875 ,p_implemented_by => FND_GLOBAL.USER_ID
10876 ,p_impact_type_code => l_impact_type_code
10877 ,p_commit_flag => 'N'
10878 ,p_init_msg_list => 'N'
10879 ,p_record_version_number => null
10880 ,x_return_status => l_return_status
10881 ,x_msg_count => l_msg_count
10882 ,x_msg_data => l_msg_data
10883 );
10884
10885 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10886 IF P_PA_debug_mode = 'Y' THEN
10887 pa_debug.g_err_stage:= 'Error in FP_CI_UPDATE_IMPACT';
10888 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10889 END IF;
10890 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10891 END IF;
10892
10893
10894 END IF;
10895 --dbms_output.put_line('I53');
10896 END LOOP;
10897
10898 --dbms_output.put_line('I54');
10899 --updating reporting lines. Call is necessary only if calculate API has not been called
10900
10901 IF P_PA_debug_mode = 'Y' THEN
10902 pa_debug.g_err_stage:= 'Exiting implement_ci_into_single_ver';
10903 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
10904 --dbms_output.put_line('I58');
10905 pa_debug.reset_curr_function;
10906 END IF;
10907 EXCEPTION
10908 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
10909 l_msg_count := FND_MSG_PUB.count_msg;
10910
10911 IF l_msg_count = 1 and x_msg_data IS NULL THEN
10912 PA_INTERFACE_UTILS_PUB.get_messages
10913 (p_encoded => FND_API.G_TRUE
10914 ,p_msg_index => 1
10915 ,p_msg_count => l_msg_count
10916 ,p_msg_data => l_msg_data
10917 ,p_data => l_data
10918 ,p_msg_index_out => l_msg_index_out);
10919 x_msg_data := l_data;
10920 x_msg_count := l_msg_count;
10921 ELSE
10922 x_msg_count := l_msg_count;
10923 END IF;
10924 x_return_status := FND_API.G_RET_STS_ERROR;
10925
10926 ROLLBACK TO implement_ci_into_single_ver;
10927 IF p_pa_debug_mode = 'Y' THEN
10928 pa_debug.reset_curr_function;
10929 END IF;
10930 RETURN;
10931
10932 WHEN Others THEN
10933 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10934 x_msg_count := 1;
10935 x_msg_data := SQLERRM;
10936
10937 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'PA_FP_CI_MERGE'
10938 ,p_procedure_name => 'implement_ci_into_single_ver');
10939 IF P_PA_DEBUG_MODE = 'Y' THEN
10940 pa_debug.g_err_stage:='Unexpected Error ' || SQLERRM;
10941 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
10942 END IF;
10943 ROLLBACK TO implement_ci_into_single_ver;
10944 IF p_pa_debug_mode = 'Y' THEN
10945 pa_debug.reset_curr_function;
10946 END IF;
10947 RAISE;
10948
10949
10950 END implement_ci_into_single_ver;
10951
10952 --This is a private API called from the implement change document API. This API will perform all the validationa
10953 --required for deciding whether a CI document can be merged into a target version or not. Bug 3550073
10954 PROCEDURE validate_ci_merge_input_data(
10955 p_context IN VARCHAR2
10956 ,p_ci_id_tbl IN SYSTEM.pa_num_tbl_type
10957 ,p_ci_cost_version_id_tbl IN SYSTEM.pa_num_tbl_type
10958 ,p_ci_rev_version_id_tbl IN SYSTEM.pa_num_tbl_type
10959 ,p_ci_all_version_id_tbl IN SYSTEM.pa_num_tbl_type
10960 ,p_budget_version_id_tbl IN SYSTEM.pa_num_tbl_type
10961 ,p_fin_plan_type_id_tbl IN SYSTEM.pa_num_tbl_type
10962 ,p_fin_plan_type_name_tbl IN SYSTEM.pa_varchar2_150_tbl_type
10963 ,p_impl_cost_flag_tbl IN SYSTEM.pa_varchar2_1_tbl_type
10964 ,p_impl_rev_flag_tbl IN SYSTEM.pa_varchar2_1_tbl_type
10965 ,p_submit_version_flag_tbl IN SYSTEM.pa_varchar2_1_tbl_type
10966 ,px_partial_impl_rev_amt IN OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
10967 ,p_agreement_id IN pa_agreements_all.agreement_id%TYPE
10968 ,p_update_agreement_amt_flag IN VARCHAR2
10969 ,p_funding_category IN VARCHAR2
10970 ,x_ci_id_tbl OUT NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
10971 ,x_ci_cost_version_id_tbl OUT NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
10972 ,x_ci_rev_version_id_tbl OUT NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
10973 ,x_ci_all_version_id_tbl OUT NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
10974 ,x_budget_version_id_tbl OUT NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
10975 ,x_fin_plan_type_id_tbl OUT NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
10976 ,x_fin_plan_type_name_tbl OUT NOCOPY SYSTEM.pa_varchar2_150_tbl_type --File.Sql.39 bug 4440895
10977 ,x_submit_version_flag_tbl OUT NOCOPY SYSTEM.pa_varchar2_1_tbl_type --File.Sql.39 bug 4440895
10978 ,x_ci_number OUT NOCOPY SYSTEM.pa_varchar2_100_tbl_type --File.Sql.39 bug 4440895
10979 ,x_budget_ci_map_rec_tbl OUT NOCOPY budget_ci_map_rec_tbl_type --File.Sql.39 bug 4440895
10980 ,x_agreement_id OUT NOCOPY pa_agreements_all.agreement_id%TYPE --File.Sql.39 bug 4440895
10981 ,x_funding_category OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
10982 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
10983 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
10984 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
10985 IS
10986 --Start of variables used for debugging
10987 l_msg_count NUMBER :=0;
10988 l_data VARCHAR2(2000);
10989 l_msg_data VARCHAR2(2000);
10990 l_error_msg_code VARCHAR2(30);
10991 l_msg_index_out NUMBER;
10992 l_return_status VARCHAR2(2000);
10993 l_debug_mode VARCHAR2(30);
10994 l_module_name VARCHAR2(100):='PAFPCIMB.validate_ci_merge_input_data';
10995 --End of variables used for debugging
10996 i NUMBER;
10997 l_ci_cost_version_id_tbl pa_budget_versions.budget_version_id%TYPE;
10998 l_ci_rev_version_id_tbl pa_budget_versions.budget_version_id%TYPE;
10999 l_ci_all_version_id_tbl pa_budget_versions.budget_version_id%TYPE;
11000 l_out_index NUMBER;
11001 l_error_occurred_flag VARCHAR2(1);
11002 l_budget_status_code pa_budget_versions.budget_status_code%TYPE;
11003 l_ci_cost_version_id pa_budget_versions.budget_version_id%TYPE;
11004 l_ci_rev_version_id pa_budget_versions.budget_version_id%TYPE;
11005 l_ci_all_version_id pa_budget_versions.budget_version_id%TYPE;
11006 l_project_id pa_projects_all.project_id%TYPE;
11007 l_source_version_id_tbl SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
11008 l_calling_mode_for_chk_api VARCHAR2(30);
11009 l_merge_possible_code_tbl SYSTEM.pa_varchar2_1_tbl_type :=SYSTEM.pa_varchar2_1_tbl_type();
11010 l_copy_ci_ver_flag VARCHAR2(1);
11011 l_record_version_number pa_budget_versions.record_Version_number%TYPE;
11012 l_cost_ci_ver_index NUMBER;
11013 l_rev_ci_ver_index NUMBER;
11014 l_all_ci_ver_index NUMBER;
11015 l_index NUMBER:=0;
11016 l_implementable_impact VARCHAR2(10);
11017 l_dummy VARCHAR2(1);
11018 l_ci_number pa_control_items.ci_number%TYPE;
11019
11020 l_cost_impl_flag VARCHAR2(1);
11021 l_rev_impl_flag VARCHAR2(1);
11022 l_cost_impact_impl_flag VARCHAR2(1);
11023 l_rev_impact_impl_flag VARCHAR2(1);
11024 l_partially_impl_flag VARCHAR2(1);
11025 l_agreement_num pa_agreements_all.agreement_num%TYPE;
11026 l_approved_fin_pt_id pa_fin_plan_types_b.fin_plan_type_id%TYPE;
11027 l_impl_cost_flag_tbl SYSTEM.pa_varchar2_1_tbl_type;
11028 l_impl_rev_flag_tbl SYSTEM.pa_varchar2_1_tbl_type;
11029 l_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE;
11030 l_fin_plan_type_name pa_fin_plan_types_tl.name%TYPE;
11031 l_total_amount NUMBER;
11032 l_implemented_amount NUMBER;
11033 l_remaining_amount NUMBER;
11034 l_agr_curr_code pa_agreements_all.agreement_currency_code%TYPE;
11035
11036 CURSOR c_chk_rej_codes (ci_ci_ver_id1 pa_budget_versions.budget_version_id%TYPE,
11037 ci_ci_ver_id2 pa_budget_versions.budget_version_id%TYPE)
11038 IS
11039 SELECT 'Y'
11040 FROM DUAL
11041 WHERE EXISTS (SELECT 1
11042 FROM pa_budget_lines pbl
11043 WHERE pbl.budget_version_id IN (ci_ci_ver_id1, ci_ci_ver_id2)
11044 AND( pbl.cost_rejection_code IS NOT NULL
11045 OR pbl.revenue_rejection_code IS NOT NULL
11046 OR pbl.burden_rejection_code IS NOT NULL
11047 OR pbl.other_rejection_code IS NOT NULL
11048 OR pbl.pc_cur_conv_rejection_code IS NOT NULL
11049 OR pbl.pfc_cur_conv_rejection_code IS NOT NULL));
11050
11051 --These two variables will be used for comparing the no. of error messages in the error message stack when the
11052 --API called and when the API is done with the processing. If the no of messages in the two pl/sql tbls are
11053 --different then the error status will be returned as E from the API. This will be done only when the p_context='CI_MERGE'
11054 l_init_msg_count NUMBER;
11055 l_msg_count_at_end NUMBER;
11056
11057 l_version_type pa_budget_versions.version_type%TYPE;
11058 l_version_type_tbl SYSTEM.pa_varchar2_30_tbl_type :=SYSTEM.pa_varchar2_30_tbl_type();
11059 l_fin_plan_type_name_tbl SYSTEM.pa_varchar2_150_tbl_type :=SYSTEM.pa_varchar2_150_tbl_type();
11060 l_part_impl_err VARCHAR2(1);
11061 l_ci_name VARCHAR2(300);
11062
11063 l_ci_type_class_code pa_ci_types_b.ci_type_class_code%TYPE;
11064
11065 -- Bug 3986129: Added the following
11066 l_targ_ver_plan_prc_code pa_budget_versions.plan_processing_code%TYPE;
11067
11068 BEGIN
11069 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
11070 l_debug_mode := NVL(l_debug_mode, 'Y');
11071 x_msg_count := 0;
11072 x_return_status := FND_API.G_RET_STS_SUCCESS;
11073 IF p_context='CI_MERGE' THEN
11074 l_init_msg_count:= FND_MSG_PUB.count_msg;
11075 END IF;
11076 IF p_pa_debug_mode = 'Y' THEN
11077 PA_DEBUG.Set_Curr_Function( p_function => 'PAFPCIMB.validate_ci_merge_input_data',
11078 p_debug_mode => l_debug_mode );
11079 END IF;
11080 IF l_debug_mode = 'Y' THEN
11081
11082 pa_debug.g_err_stage:= 'Validating the input parameters';
11083 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11084
11085 END IF;
11086 --dbms_output.put_line('1');
11087
11088
11089 --p_context should be valid
11090 IF p_context NOT IN ('IMPL_FIN_IMPACT' , 'INCLUDE', 'PARTIAL_REV', 'CI_MERGE') THEN
11091
11092 IF l_debug_mode = 'Y' THEN
11093
11094 pa_debug.g_err_stage:= 'p_context passed is '|| p_context;
11095 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11096 END IF;
11097 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
11098 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
11099 p_token1 => 'PROCEDURENAME',
11100 p_value1 => l_module_name);
11101 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11102
11103
11104 END IF;
11105
11106
11107 --The no. of elements in ci_id tbl and the ci version id tbls should always be same
11108 IF ((p_ci_cost_version_id_tbl.COUNT <> 0 AND
11109 (p_ci_id_tbl.COUNT <> p_ci_cost_version_id_tbl.COUNT))OR
11110 (p_ci_rev_version_id_tbl.COUNT <> 0 AND
11111 (p_ci_id_tbl.COUNT <> p_ci_rev_version_id_tbl.COUNT)) OR
11112 (p_ci_all_version_id_tbl.COUNT <> 0 AND
11113 (p_ci_id_tbl.COUNT <> p_ci_all_version_id_tbl.COUNT ))) THEN
11114
11115 IF l_debug_mode = 'Y' THEN
11116
11117 pa_debug.g_err_stage:= 'p_ci_id_tbl.COUNT '|| p_ci_id_tbl.COUNT;
11118 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11119
11120 pa_debug.g_err_stage:= 'p_ci_cost_version_id_tbl.COUNT '|| p_ci_cost_version_id_tbl.COUNT;
11121 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11122
11123 pa_debug.g_err_stage:= 'p_ci_rev_version_id_tbl.COUNT '|| p_ci_rev_version_id_tbl.COUNT;
11124 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11125
11126 pa_debug.g_err_stage:= 'p_ci_all_version_id_tbl.COUNT '|| p_ci_all_version_id_tbl.COUNT;
11127 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11128
11129 END IF;
11130
11131 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
11132 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
11133 p_token1 => 'PROCEDURENAME',
11134 p_value1 => l_module_name);
11135 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11136
11137 END IF;
11138 --dbms_output.put_line('2');
11139
11140 --The no of elements in the p_fin_plan_type_id_tbl, p_fin_plan_type_name_tbl p_impl_cost_flag_tbl
11141 --p_impl_rev_flag_tbl,p_submit_version_flag_tbl
11142 IF (p_fin_plan_type_id_tbl.COUNT <> 0 AND p_fin_plan_type_id_tbl.COUNT<>p_budget_version_id_tbl.COUNT) OR
11143 (p_fin_plan_type_name_tbl.COUNT <> 0 AND p_fin_plan_type_name_tbl.COUNT<>p_budget_version_id_tbl.COUNT) OR
11144 (p_impl_cost_flag_tbl.COUNT <> 0 AND p_impl_cost_flag_tbl.COUNT <> p_budget_version_id_tbl.COUNT) OR
11145 (p_impl_rev_flag_tbl.COUNT <> 0 AND p_impl_rev_flag_tbl.COUNT <> p_budget_version_id_tbl.COUNT) OR
11146 (p_submit_version_flag_tbl.COUNT<> 0 AND p_submit_version_flag_tbl.COUNT<> p_budget_version_id_tbl.COUNT) THEN
11147
11148 IF l_debug_mode = 'Y' THEN
11149
11150 pa_debug.g_err_stage:= 'p_fin_plan_type_id_tbl.COUNT '|| p_fin_plan_type_id_tbl.COUNT;
11151 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11152
11153 pa_debug.g_err_stage:= 'p_fin_plan_type_name_tbl.COUNT '|| p_fin_plan_type_name_tbl.COUNT;
11154 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11155
11156 pa_debug.g_err_stage:= 'p_impl_cost_flag_tbl.COUNT '|| p_impl_cost_flag_tbl.COUNT;
11157 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11158
11159 pa_debug.g_err_stage:= 'p_impl_rev_flag_tbl.COUNT '|| p_impl_rev_flag_tbl.COUNT;
11160 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11161
11162 pa_debug.g_err_stage:= 'p_submit_version_flag_tbl.COUNT '|| p_submit_version_flag_tbl.COUNT;
11163 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11164
11165 pa_debug.g_err_stage:= 'p_budget_version_id_tbl.COUNT '|| p_budget_version_id_tbl.COUNT;
11166 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11167
11168 END IF;
11169
11170 PA_UTILS.ADD_MESSAGE
11171 (p_app_short_name => 'PA',
11172 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
11173 p_token1 => 'PROCEDURENAME',
11174 p_value1 => l_module_name);
11175 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11176
11177 END IF;
11178
11179 --dbms_output.put_line('3');
11180 --In case of partial implementation the ci id tbl and target budget version id tbls should have
11181 --only one record
11182 IF p_context='PARTIAL_REV' THEN
11183 IF (p_ci_id_tbl.COUNT <>1 OR
11184 p_budget_version_id_tbl.COUNT <>1) THEN
11185
11186 IF l_debug_mode = 'Y' THEN
11187
11188 pa_debug.g_err_stage:= 'p_ci_id_tbl.COUNT in partial implementation context '|| p_ci_id_tbl.COUNT;
11189 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11190
11191 pa_debug.g_err_stage:= 'p_budget_version_id_tbl.COUNT in partial implementation context '|| p_budget_version_id_tbl.COUNT;
11192 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11193
11194 END IF;
11195
11196 PA_UTILS.ADD_MESSAGE
11197 (p_app_short_name => 'PA',
11198 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
11199 p_token1 => 'PROCEDURENAME',
11200 p_value1 => l_module_name);
11201 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11202
11203 END IF;
11204
11205 IF (p_impl_cost_flag_tbl(1) ='Y' OR
11206 p_impl_rev_flag_tbl(1) = 'N') THEN
11207
11208 IF l_debug_mode = 'Y' THEN
11209
11210 pa_debug.g_err_stage:= 'p_cost_impl_flag passed in partial implementation case is '|| p_impl_cost_flag_tbl(1);
11211 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11212
11213 pa_debug.g_err_stage:= 'p_rev_impl_flag passed in partial implementation case is '|| p_impl_rev_flag_tbl(1);
11214 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11215
11216 END IF;
11217
11218 PA_UTILS.ADD_MESSAGE
11219 (p_app_short_name => 'PA',
11220 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
11221 p_token1 => 'PROCEDURENAME',
11222 p_value1 => l_module_name);
11223 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11224
11225 END IF;
11226
11227 END IF;
11228 --Initialise all the out put pl/sql tables
11229 x_ci_id_tbl :=SYSTEM.pa_num_tbl_type();
11230 x_ci_cost_version_id_tbl :=SYSTEM.pa_num_tbl_type();
11231 x_ci_rev_version_id_tbl :=SYSTEM.pa_num_tbl_type();
11232 x_ci_all_version_id_tbl :=SYSTEM.pa_num_tbl_type();
11233 x_budget_version_id_tbl :=SYSTEM.pa_num_tbl_type();
11234 x_ci_number :=SYSTEM.pa_varchar2_100_tbl_type();
11235 l_impl_cost_flag_tbl :=SYSTEM.pa_varchar2_1_tbl_type();
11236 l_impl_rev_flag_tbl :=SYSTEM.pa_varchar2_1_tbl_type();
11237 x_submit_version_flag_tbl :=SYSTEM.pa_varchar2_1_tbl_type();
11238 x_fin_plan_type_id_tbl :=SYSTEM.pa_num_tbl_type();
11239 x_fin_plan_type_name_tbl :=SYSTEM.pa_varchar2_150_tbl_type();
11240 IF p_funding_category IS NULL THEN
11241 x_funding_category := 'ADDITIONAL';
11242 -- Bug 3749322- adding the else clause to pass the value of
11243 -- p_funding_category as it is passed
11244 ELSE
11245 x_funding_category := p_funding_category;
11246 END IF;
11247 x_agreement_id :=p_agreement_id;
11248
11249 --Derive the calling context that should be passed to the check merge possible API
11250 IF p_context='IMPL_FIN_IMPACT' OR
11251 p_context='PARTIAL_REV' THEN
11252
11253 l_calling_mode_for_chk_api:='IMPLEMENT';
11254
11255 ELSIF p_context='INCLUDE' THEN
11256
11257 l_calling_mode_for_chk_api:='INCLUDE';
11258
11259 ELSIF p_context='CI_MERGE' THEN
11260 l_calling_mode_for_chk_api:= 'INCLUDE_CR_TO_CO';
11261
11262 END IF;
11263
11264 IF l_debug_mode = 'Y' THEN
11265
11266 pa_debug.g_err_stage:= 'Calling mode for the chk API derived is '||l_calling_mode_for_chk_api;
11267 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11268
11269 pa_debug.g_err_stage:= 'Validating the the CIs passed';
11270 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11271
11272
11273 END IF;
11274
11275 IF p_ci_id_tbl.COUNT=0 OR
11276 p_budget_version_id_tbl.COUNT=0 THEN
11277
11278 IF l_debug_mode = 'Y' THEN
11279
11280 pa_debug.g_err_stage:= 'CI Ids/BV Ids are not passed for merge. Returning';
11281 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11282 pa_debug.reset_curr_function;
11283 END IF;
11284 RETURN;
11285
11286 END IF;
11287 --dbms_output.put_line('4');
11288
11289 FOR i IN p_ci_id_tbl.FIRST..p_ci_id_tbl.LAST LOOP
11290
11291 IF p_ci_id_tbl(i) IS NULL THEN
11292
11293 IF l_debug_mode = 'Y' THEN
11294
11295 pa_debug.g_err_stage:= 'p_ci_id_tbl('||i||') IS '|| p_ci_id_tbl(i);
11296 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11297
11298 END IF;
11299 PA_UTILS.ADD_MESSAGE
11300 (p_app_short_name => 'PA',
11301 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
11302 p_token1 => 'PROCEDURENAME',
11303 p_value1 => l_module_name);
11304 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11305
11306 END IF;
11307
11308 l_copy_ci_ver_flag:='Y';
11309
11310 l_ci_cost_version_id:=NULL;
11311 l_ci_rev_version_id:=NULL;
11312 l_ci_all_version_id:=NULL;
11313 IF ((NOT p_ci_cost_version_id_tbl.EXISTS(i)) OR p_ci_cost_version_id_tbl(i) IS NULL) AND
11314 ((NOT p_ci_rev_version_id_tbl.EXISTS(i)) OR p_ci_rev_version_id_tbl(i) IS NULL) AND
11315 ((NOT p_ci_all_version_id_tbl.EXISTS(i)) OR p_ci_all_version_id_tbl(i) IS NULL)THEN
11316
11317 IF l_debug_mode = 'Y' THEN
11318 pa_debug.g_err_stage:= 'Calling Pa_Fp_Control_Items_Utils.get_ci_versions';
11319 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11320 END IF;
11321
11322 Pa_Fp_Control_Items_Utils.get_ci_versions
11323 ( p_ci_id => p_ci_id_tbl(i)
11324 ,X_cost_budget_version_id => l_ci_cost_version_id
11325 ,X_rev_budget_version_id => l_ci_rev_version_id
11326 ,X_all_budget_version_id => l_ci_all_version_id
11327 ,x_return_status => x_return_status
11328 ,x_msg_count => x_msg_count
11329 ,x_msg_data => x_msg_data);
11330
11331 --ci id will be skipped. Processing will continue with other cis
11332 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
11333 l_copy_ci_ver_flag:='N';
11334 END IF;
11335 ELSE
11336
11337 IF p_ci_cost_version_id_tbl.EXISTS(i) THEN
11338 l_ci_cost_version_id:= p_ci_cost_version_id_tbl(i);
11339 END IF;
11340
11341 IF p_ci_rev_version_id_tbl.EXISTS(i) THEN
11342 l_ci_rev_version_id:=p_ci_rev_version_id_tbl(i);
11343 END IF;
11344
11345 IF p_ci_all_version_id_tbl.EXISTS(i) THEN
11346 l_ci_all_version_id:=p_ci_all_version_id_tbl(i);
11347 END IF;
11348
11349
11350 END IF;
11351
11352 --Check for the existence of rejection lines in the change order versions. If the rejection codes exist
11353 --then the change order is not eligible for merge.Derive ci number as it has to be passed as token to
11354 --error messages
11355 SELECT pci.ci_number,
11356 pct.ci_type_class_code
11357 INTO l_ci_number,
11358 l_ci_type_class_code
11359 FROM pa_control_items pci,
11360 pa_ci_types_b pct
11361 WHERE pci.ci_id = p_ci_id_tbl(i)
11362 AND pci.ci_type_id=pct.ci_type_id;
11363
11364 IF l_copy_ci_ver_flag='Y' THEN
11365
11366 IF l_debug_mode = 'Y' THEN
11367 pa_debug.g_err_stage:= 'Checking for the existence of budget lines with rejection codes in ci version';
11368 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11369 END IF;
11370
11371 OPEN c_chk_rej_codes(NVL(l_ci_cost_version_id,NVL(l_ci_all_version_id,l_ci_rev_version_id)),
11372 NVL(l_ci_rev_version_id,NVL(l_ci_all_version_id,l_ci_cost_version_id)));
11373 FETCH c_chk_rej_codes INTO l_dummy;
11374 IF c_chk_rej_codes%FOUND THEN
11375
11376 IF l_debug_mode = 'Y' THEN
11377 pa_debug.g_err_stage:= 'budget lines with rejection codes EXIST in ci version';
11378 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11379 END IF;
11380
11381 IF l_ci_type_class_code='CHANGE_ORDER' THEN
11382 PA_UTILS.ADD_MESSAGE
11383 (p_app_short_name => 'PA',
11384 p_msg_name => 'PA_FP_IMPL_CO_REJ_CODES_EXST',
11385 p_token1 => 'CI_NUMBER',
11386 p_value1 => l_ci_number);
11387 ELSE
11388
11389 PA_UTILS.ADD_MESSAGE
11390 (p_app_short_name => 'PA',
11391 p_msg_name => 'PA_FP_IMPL_CR_REJ_CODES_EXST',
11392 p_token1 => 'CI_NUMBER',
11393 p_value1 => l_ci_number);
11394
11395 END IF;
11396
11397 l_copy_ci_ver_flag:='N';
11398
11399 END IF;
11400
11401 CLOSE c_chk_rej_codes;
11402
11403 END IF;
11404
11405 -- For bug 3814932
11406 IF l_copy_ci_ver_flag='Y' THEN
11407
11408 IF p_context = 'PARTIAL_REV' Then
11409
11410 IF l_debug_mode = 'Y' THEN
11411 pa_debug.g_err_stage:= 'In the context of PARTIAL_REV';
11412 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11413 END IF;
11414
11415 If px_partial_impl_rev_amt is null Then
11416
11417 PA_UTILS.ADD_MESSAGE
11418 (p_app_short_name => 'PA',
11419 p_msg_name => 'PA_CI_PAR_REV_IMPL_AMT_NULL');
11420
11421 IF l_debug_mode = 'Y' THEN
11422 pa_debug.g_err_stage:= 'px_partial_impl_rev_amt is null.';
11423 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11424 END IF;
11425
11426 l_copy_ci_ver_flag:='N';
11427
11428 End If;
11429
11430 IF l_copy_ci_ver_flag <> 'N' THEN
11431
11432 -- Get the project id
11433
11434 SELECT project_id
11435 INTO l_project_id
11436 FROM pa_budget_versions
11437 WHERE budget_version_id=p_budget_version_id_tbl(i);
11438
11439
11440 IF l_debug_mode = 'Y' THEN
11441 pa_debug.g_err_stage:= 'Project id is:' ||l_project_id;
11442 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11443 END IF;
11444
11445 --To get the total amount.
11446 SELECT (sum(nvl(txn_revenue,0)) )
11447 INTO l_total_amount
11448 FROM pa_budget_lines
11449 WHERE budget_version_id = NVL(l_ci_all_version_id,l_ci_rev_version_id);
11450
11451 IF l_debug_mode = 'Y' THEN
11452 pa_debug.g_err_stage:= 'Total Planned Revenue amount is:' ||l_total_amount;
11453 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11454 END IF;
11455
11456 --To get implemented amount.
11457 l_implemented_amount := Pa_Fp_Control_Items_Utils.get_impl_agr_revenue(
11458 p_project_id => l_project_id,
11459 p_ci_id => p_ci_id_tbl(i) );
11460
11461 IF l_debug_mode = 'Y' THEN
11462 pa_debug.g_err_stage:= 'Implemented Amount is:' ||l_implemented_amount;
11463 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11464 END IF;
11465
11466 If l_total_amount = 0 Then
11467
11468 If(px_partial_impl_rev_amt<>0) Then
11469 --Error
11470 PA_UTILS.ADD_MESSAGE
11471 (p_app_short_name => 'PA',
11472 p_msg_name => 'PA_CI_PAR_REV_AMT_NOT_ZERO');
11473
11474 IF l_debug_mode = 'Y' THEN
11475 pa_debug.g_err_stage:= 'Partial implementation revenue cannot be anything other than 0';
11476 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11477 END IF;
11478
11479 l_copy_ci_ver_flag:='N';
11480
11481 End If;--If(px_partial_impl_rev_amt<>0) Then
11482
11483 End If; --End of l_total_amount = 0
11484
11485 End If;--IF l_copy_ci_ver_flag <> 'N' THEN
11486
11487
11488 If l_copy_ci_ver_flag <> 'N' Then
11489
11490 If abs(l_implemented_amount)>abs(l_total_amount) Then
11491
11492 IF l_debug_mode = 'Y' THEN
11493 pa_debug.g_err_stage:= 'Implemented amount is greater than total amount.';
11494 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11495 END IF;
11496
11497 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11498
11499 End If;
11500
11501 End If;
11502
11503 If l_copy_ci_ver_flag <> 'N' Then
11504
11505 If l_total_amount >0 Then
11506
11507 If px_partial_impl_rev_amt <0 Then
11508 --Error;
11509 PA_UTILS.ADD_MESSAGE
11510 (p_app_short_name => 'PA',
11511 p_msg_name => 'PA_CI_PAR_REV_AMT_NOT_POS');
11512
11513 IF l_debug_mode = 'Y' THEN
11514 pa_debug.g_err_stage:= 'Partial implementation revenue amount is negetive';
11515 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11516 END IF;
11517
11518 l_copy_ci_ver_flag:='N';
11519
11520 End If;--End of px_partial_impl_rev_amt <0
11521
11522 If l_copy_ci_ver_flag<>'N' Then
11523
11524 l_remaining_amount:=l_total_amount-l_implemented_amount;
11525
11526 IF l_debug_mode = 'Y' THEN
11527 pa_debug.g_err_stage:= 'Remaining amount to be implemented is:' || l_remaining_amount;
11528 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11529 END IF;
11530
11531 If px_partial_impl_rev_amt>l_remaining_amount Then
11532 --Error;
11533 PA_UTILS.ADD_MESSAGE
11534 (p_app_short_name => 'PA',
11535 p_msg_name => 'PA_CI_PAR_REV_IMPL_AMT_GREATER');
11536
11537 IF l_debug_mode = 'Y' THEN
11538 pa_debug.g_err_stage:= 'Partial impl rev is > Reamaining amount to be implemented';
11539 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11540 END IF;
11541
11542 l_copy_ci_ver_flag:='N';
11543
11544 End If; --End of px_partial_impl_rev_amt>l_remaining_amount
11545
11546 End If; --End of l_copy_ci_ver_flag<>'N'
11547
11548 End If; --End of l_total_amount>0
11549
11550 End If;
11551
11552 If l_copy_ci_ver_flag<>'N' Then
11553
11554 If l_total_amount<0 Then
11555
11556 If px_partial_impl_rev_amt>0 Then
11557 --Error;
11558 PA_UTILS.ADD_MESSAGE
11559 (p_app_short_name => 'PA',
11560 p_msg_name => 'PA_CI_PAR_REV_AMT_NOT_NEG');
11561
11562 IF l_debug_mode = 'Y' THEN
11563 pa_debug.g_err_stage:= 'Partial implementation revenue amount is positive';
11564 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11565 END IF;
11566
11567 l_copy_ci_ver_flag:='N';
11568
11569 End If; --End of px_partial_impl_rev_amt>0
11570
11571 If l_copy_ci_ver_flag<>'N' Then
11572
11573 l_remaining_amount:=l_total_amount-l_implemented_amount;
11574
11575 IF l_debug_mode = 'Y' THEN
11576 pa_debug.g_err_stage:= 'Remaining amount to be implemented is:' || l_remaining_amount;
11577 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11578 END IF;
11579
11580 If abs(px_partial_impl_rev_amt)>abs(l_remaining_amount) Then
11581 --Error;
11582 PA_UTILS.ADD_MESSAGE
11583 (p_app_short_name => 'PA',
11584 p_msg_name => 'PA_CI_PAR_REV_IMPL_AMT_GREATER');
11585
11586 IF l_debug_mode = 'Y' THEN
11587 pa_debug.g_err_stage:= 'Partial impl rev is > Reamaining amount to be implemented';
11588 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11589 END IF;
11590
11591 l_copy_ci_ver_flag:='N';
11592
11593 End If;-- End of abs(px_partial_impl_rev_amt)>abs(l_remaining_amount)
11594
11595 End If; --End of l_copy_ci_ver_flag<>'N'
11596
11597 End If; --l_total_amount<0
11598
11599 End If;
11600
11601 End If; --end of p_context 'PARTIAL_REV'
11602
11603 End If; --End of bug 3814932
11604
11605
11606 IF l_copy_ci_ver_flag='Y' THEN
11607
11608 IF l_debug_mode = 'Y' THEN
11609 pa_debug.g_err_stage:= 'l_copy_ci_ver_flag is Y Copying';
11610 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11611 END IF;
11612
11613 x_ci_id_tbl.EXTEND(1);
11614 x_ci_cost_version_id_tbl.EXTEND(1);
11615 x_ci_rev_version_id_tbl.EXTEND(1);
11616 x_ci_all_version_id_tbl.EXTEND(1);
11617 x_ci_number.EXTEND(1);
11618 x_ci_id_tbl(x_ci_id_tbl.COUNT):=p_ci_id_tbl(i);
11619 x_ci_cost_version_id_tbl(x_ci_cost_version_id_tbl.COUNT):=l_ci_cost_version_id;
11620 x_ci_rev_version_id_tbl(x_ci_rev_version_id_tbl.COUNT):=l_ci_rev_version_id;
11621 x_ci_all_version_id_tbl(x_ci_all_version_id_tbl.COUNT):=l_ci_all_version_id;
11622
11623 --Derive the ci number in case the API is called from the include change orders page
11624 IF (p_context = 'INCLUDE') THEN
11625
11626 x_ci_number(x_ci_number.COUNT):=l_ci_number;
11627
11628 ELSIF (p_context = 'IMPL_FIN_IMPACT' OR
11629 p_context = 'PARTIAL_REV') THEN
11630
11631 --In this context only one ci id will be passed always and hence we can fetch the agreement id
11632 --into the scalar variable
11633 IF x_agreement_id IS NULL AND
11634 nvl(l_ci_rev_version_id, l_ci_all_version_id) IS NOT NULL THEN
11635
11636 SELECT agreement_id
11637 INTO x_agreement_id
11638 FROM pa_budget_Versions
11639 WHERE budget_Version_id=nvl(l_ci_rev_version_id, l_ci_all_version_id);
11640
11641 END IF;
11642
11643 END IF;
11644
11645 END IF;--IF l_copy_ci_ver_flag='Y' THEN
11646
11647 END LOOP;
11648
11649 --dbms_output.put_line('5');
11650
11651 IF l_debug_mode = 'Y' THEN
11652 pa_debug.g_err_stage:= 'Proceeding with the budget version loopn with count '||p_budget_version_id_tbl.count;
11653 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11654 END IF;
11655
11656 --dbms_output.put_line('6');
11657
11658 --Validate the passed target budget version ids. The budget version ids should not be in a submitted status and
11659 --and the version should not be already locked by some other user.
11660 FOR i IN p_budget_version_id_tbl.FIRST..p_budget_version_id_tbl.LAST LOOP
11661
11662 IF l_debug_mode = 'Y' THEN
11663 pa_debug.g_err_stage:= 'p_budget_version_id_tbl ('||i||') is'||p_budget_version_id_tbl(i);
11664 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11665 END IF;
11666
11667 --Derive the fin plan type name and id if they are not passed
11668 IF ((NOT p_fin_plan_type_id_tbl.EXISTS(i)) OR p_fin_plan_type_id_tbl(i) IS NULL) OR
11669 ((NOT p_fin_plan_type_name_tbl.EXISTS(i)) OR p_fin_plan_type_name_tbl(i) IS NULL) THEN
11670
11671 SELECT fin.name,
11672 fin.fin_plan_type_id
11673 INTO l_fin_plan_type_name,
11674 l_fin_plan_type_id
11675 FROM pa_fin_plan_types_vl fin,
11676 pa_budget_versions pbv
11677 WHERE fin.fin_plan_type_id=pbv.fin_plan_type_id
11678 AND pbv.budget_version_id=p_budget_version_id_tbl(i);
11679 ELSE
11680 l_fin_plan_type_name := p_fin_plan_type_name_tbl(i);
11681 l_fin_plan_type_id := p_fin_plan_type_id_tbl(i);
11682 END IF;
11683
11684 l_error_occurred_flag:='N';
11685
11686 --dbms_output.put_line('6.1 '||p_budget_version_id_tbl(i));
11687 IF NVL(p_budget_version_id_tbl(i),-1)=-1 THEN
11688 --The current working version does not exist
11689 IF l_debug_mode = 'Y' THEN
11690 pa_debug.g_err_stage:= 'CWV doest not exist.adding msg to stack';
11691 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11692 END IF;
11693
11694 PA_UTILS.ADD_MESSAGE
11695 (p_app_short_name => 'PA',
11696 p_msg_name => 'PA_FP_CI_MRG_NO_CW_VER',
11697 p_token1 => 'PLAN_TYPE',
11698 p_value1 => l_fin_plan_type_name);
11699
11700 IF l_debug_mode = 'Y' THEN
11701 pa_debug.g_err_stage:= 'CWV doest not exist.added message to stack '|| l_fin_plan_type_name;
11702 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11703 END IF;
11704
11705 l_error_occurred_flag:='Y';
11706 END IF;
11707
11708 IF l_error_occurred_flag='N' THEN
11709
11710 IF l_debug_mode = 'Y' THEN
11711 pa_debug.g_err_stage:= 'Checking for S status';
11712 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11713 END IF;
11714
11715
11716 SELECT budget_status_code,
11717 record_version_number,
11718 project_id,
11719 version_type,
11720 plan_processing_code
11721 INTO l_budget_status_code,
11722 l_record_version_number,
11723 l_project_id,
11724 l_version_type,
11725 l_targ_ver_plan_prc_code -- for Bug 3986129
11726 FROM pa_budget_versions pbv
11727 WHERE pbv.budget_version_id=p_budget_version_id_tbl(i);
11728
11729
11730 IF l_budget_status_code ='S' THEN
11731
11732 IF p_context='IMPL_FIN_IMPACT' OR
11733 p_context='PARTIAL_REV' THEN
11734
11735 PA_UTILS.ADD_MESSAGE
11736 (p_app_short_name => 'PA',
11737 p_msg_name => 'PA_FP_MERGE_SUBMIT',
11738 p_token1 => 'PLAN_TYPE',
11739 p_value1 => l_fin_plan_type_name);
11740
11741 ELSIF p_context ='INCLUDE' THEN
11742
11743 PA_UTILS.ADD_MESSAGE
11744 (p_app_short_name => 'PA',
11745 p_msg_name => 'PA_FP_MERGE_ALL_SUBMIT');
11746
11747
11748 END IF;
11749 l_error_occurred_flag:='Y';
11750
11751 END IF;
11752
11753 -- Bug 3986129: Added the following check. If the target plan version is locked for concurrent
11754 -- processing or the concurrent processing for the version has failed, then merge should not be allowed.
11755 IF l_targ_ver_plan_prc_code = 'XLUP' THEN
11756 IF l_debug_mode = 'Y' THEN
11757 pa_debug.g_err_stage:= 'Version is locked for conc processing';
11758 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11759 END IF;
11760
11761 PA_UTILS.ADD_MESSAGE
11762 (p_app_short_name => 'PA',
11763 p_msg_name => 'PA_FP_LOCKED_BY_PROCESSING');
11764
11765 l_error_occurred_flag := 'Y';
11766
11767 ELSIF l_targ_ver_plan_prc_code = 'XLUE' THEN
11768 IF l_debug_mode = 'Y' THEN
11769 pa_debug.g_err_stage:= 'Conc process for version has failed';
11770 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11771 END IF;
11772
11773 PA_UTILS.ADD_MESSAGE
11774 (p_app_short_name => 'PA',
11775 p_msg_name => 'PA_FP_WA_CONC_PRC_FAILURE_MSG');
11776
11777 l_error_occurred_flag := 'Y';
11778 END IF; -- Bug 3986129: end.
11779
11780 END IF;
11781
11782 IF l_error_occurred_flag='N' THEN
11783 -- Partial Implementation is not allowed into a target 'ALL' version
11784 IF p_context='PARTIAL_REV' AND l_version_type = 'ALL' THEN
11785 IF l_debug_mode = 'Y' THEN
11786 pa_debug.g_err_stage:= 'Partial Implementation is not allowed into a target ALL version';
11787 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11788 END IF;
11789
11790 PA_UTILS.ADD_MESSAGE
11791 (p_app_short_name => 'PA',
11792 p_msg_name => 'PA_FP_NO_PART_INTO_TRG_ALL_PT',
11793 p_token1 => 'PLAN_TYPE',
11794 p_value1 => l_fin_plan_type_name);
11795
11796 l_error_occurred_flag := 'Y';
11797 END IF;
11798 END IF;
11799
11800 IF l_error_occurred_flag='N' THEN
11801
11802 IF l_debug_mode = 'Y' THEN
11803 pa_debug.g_err_stage:= 'calling lock unlock versions';
11804 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11805 END IF;
11806
11807 --Acquire a lock on the target budget version.
11808 pa_fin_plan_pvt.lock_unlock_version
11809 ( p_budget_version_id => p_budget_version_id_tbl(i)
11810 ,p_record_version_number => l_record_version_number
11811 ,p_action => 'L'
11812 ,p_user_id => fnd_global.user_id
11813 ,p_person_id => NULL
11814 ,x_return_status => x_return_status
11815 ,x_msg_count => x_msg_count
11816 ,x_msg_data => x_msg_data );
11817
11818 --plan type id will be skipped. Processing will continue with other plan types
11819 IF x_return_status <> 'S' THEN
11820 l_error_occurred_flag:='Y';
11821 END IF;
11822
11823 END IF;
11824
11825 IF l_debug_mode = 'Y' THEN
11826 pa_debug.g_err_stage:= 'After lock unlock verson msg pub count'||FND_MSG_PUB.count_msg;
11827 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11828
11829 pa_debug.g_err_stage:= 'After lock unlock verson x_msg_data '||x_msg_data;
11830 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11831
11832 END IF;
11833
11834 --Check if the settings of the source and target version allow merge or not
11835 IF l_error_occurred_flag='N' THEN
11836
11837 IF l_debug_mode = 'Y' THEN
11838 pa_debug.g_err_stage:= 'Valid BV. About to include in o/p';
11839 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11840 END IF;
11841
11842 x_budget_version_id_tbl.extend(1);
11843 l_impl_cost_flag_tbl.extend(1);
11844 l_impl_rev_flag_tbl.extend(1);
11845 x_submit_version_flag_tbl.extend(1);
11846 x_fin_plan_type_id_tbl.extend(1);
11847 x_fin_plan_type_name_tbl.extend(1);
11848 x_budget_version_id_tbl(x_budget_version_id_tbl.COUNT) := p_budget_version_id_tbl(i);
11849 l_version_type_tbl.extend(1);
11850 l_version_type_tbl(l_version_type_tbl.COUNT) := l_version_type;
11851 l_fin_plan_type_name_tbl.extend(1);
11852 l_fin_plan_type_name_tbl(l_fin_plan_type_name_tbl.COUNT) := l_fin_plan_type_name;
11853
11854
11855 IF l_debug_mode = 'Y' THEN
11856
11857 pa_debug.g_err_stage:= 'About to assign vars';
11858 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11859
11860 END IF;
11861
11862 IF p_impl_cost_flag_tbl.EXISTS(i) THEN
11863 l_impl_cost_flag_tbl(l_impl_cost_flag_tbl.COUNT) := p_impl_cost_flag_tbl(i);
11864 END IF;
11865
11866 IF p_impl_rev_flag_tbl.EXISTS(i) THEN
11867 l_impl_rev_flag_tbl(l_impl_rev_flag_tbl.COUNT) := p_impl_rev_flag_tbl(i);
11868 END IF;
11869
11870 IF p_submit_version_flag_tbl.EXISTS(i) THEN
11871 x_submit_version_flag_tbl(x_submit_version_flag_tbl.COUNT) := p_submit_version_flag_tbl(i);
11872 END IF;
11873
11874 x_fin_plan_type_name_tbl(x_fin_plan_type_name_tbl.COUNT):=l_fin_plan_type_name;
11875 x_fin_plan_type_id_tbl(x_fin_plan_type_id_tbl.COUNT):=l_fin_plan_type_id;
11876
11877 END IF;
11878
11879 END LOOP; --The loop for the budget versions
11880
11881 --dbms_output.put_line('7');
11882
11883 IF l_debug_mode = 'Y' THEN
11884
11885 pa_debug.g_err_stage:= 'About to check for possibility of merge';
11886 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11887
11888 END IF;
11889
11890
11891 --Check if the merge of ci into the target versions is possible or not
11892 IF x_ci_id_tbl.COUNT>0 AND x_budget_version_id_tbl.COUNT>0 THEN
11893
11894 FOR i IN x_ci_id_tbl.FIRST..x_ci_id_tbl.LAST LOOP
11895
11896 IF l_debug_mode = 'Y' THEN
11897
11898 pa_debug.g_err_stage:= 'x_ci_cost_version_id_tbl('||i||') '||x_ci_cost_version_id_tbl(i);
11899 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11900
11901 pa_debug.g_err_stage:= 'x_ci_rev_version_id_tbl('||i||') '||x_ci_rev_version_id_tbl(i);
11902 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11903
11904 pa_debug.g_err_stage:= 'x_ci_all_version_id_tbl('||i||') '||x_ci_all_version_id_tbl(i);
11905 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11906
11907 END IF;
11908
11909 FOR j IN x_budget_version_id_tbl.FIRST..x_budget_version_id_tbl.LAST LOOP
11910
11911 --Prepare pl/sql tbl so that it can be passed to check_mrg_possible API to check whether
11912 --the merge is possible between the source and target versions
11913 --The order is important here. The order will COST REVENUE and ALL.
11914 --The index in the source version id tbl for COST is 1, REVENUE will be
11915 l_source_version_id_tbl :=SYSTEM.pa_num_tbl_type();
11916
11917 IF l_impl_cost_flag_tbl(j) IS NULL AND
11918 l_impl_rev_flag_tbl(j) IS NULL THEN
11919
11920 IF l_debug_mode = 'Y' THEN
11921 pa_debug.g_err_stage:= 'calling get_impl_details';
11922 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11923 END IF;
11924
11925 pa_fp_control_items_utils.get_impl_details
11926 ( P_fin_plan_type_id => x_fin_plan_type_id_tbl(j)
11927 ,P_project_id => l_project_id
11928 ,P_ci_id => x_ci_id_tbl(i)
11929 ,P_ci_cost_version_id => x_ci_cost_version_id_tbl(i)
11930 ,P_ci_rev_version_id => x_ci_rev_version_id_tbl(i)
11931 ,P_ci_all_version_id => x_ci_all_version_id_tbl(i)
11932 ,p_targ_bv_id => x_budget_version_id_tbl(j)
11933 ,x_cost_impl_flag => l_cost_impl_flag
11934 ,x_rev_impl_flag => l_rev_impl_flag
11935 ,X_cost_impact_impl_flag => l_cost_impact_impl_flag
11936 ,x_rev_impact_impl_flag => l_rev_impact_impl_flag
11937 ,x_partially_impl_flag => l_partially_impl_flag
11938 ,x_agreement_num => l_agreement_num
11939 ,x_approved_fin_pt_id => l_approved_fin_pt_id
11940 ,x_return_status => l_return_status
11941 ,x_msg_data => l_msg_data
11942 ,x_msg_count => l_msg_count);
11943
11944 --Return status check can be done in this case as the above should never return
11945 --a return status of E.
11946 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
11947 IF P_PA_debug_mode = 'Y' THEN
11948 pa_debug.g_err_stage:= 'pa_fp_control_items_utils.get_impl_details returned error';
11949 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
11950 END IF;
11951 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
11952 END IF;
11953 ELSE
11954
11955 l_cost_impl_flag:=nvl(l_impl_cost_flag_tbl(j),'N');
11956 l_rev_impl_flag:=nvl(l_impl_rev_flag_tbl(j),'N');
11957
11958 END IF;
11959
11960 IF l_debug_mode = 'Y' THEN
11961
11962 pa_debug.g_err_stage:= 'l_cost_impl_flag '||l_cost_impl_flag;
11963 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11964
11965 pa_debug.g_err_stage:= 'l_rev_impl_flag '||l_rev_impl_flag;
11966 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11967
11968 END IF;
11969
11970 l_part_impl_err := 'N';
11971
11972 --Bug 4351878. If the target version type is ALL then only cost and revenue together change orders
11973 --can be merged into those versions.
11974 IF l_version_type_tbl(j) = 'ALL' AND
11975 (x_ci_all_version_id_tbl(i) IS NULL OR
11976 NVL(l_cost_impl_flag,'N') <> 'Y' OR
11977 (NVL(l_rev_impl_flag,'N') <> 'Y' AND
11978 NVL(l_rev_impl_flag,'N') <> 'R')) THEN
11979
11980 IF l_debug_mode = 'Y' THEN
11981 pa_debug.g_err_stage:= 'Implementation of cost or revenue alone is not allowed into a target ALL version';
11982 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
11983 END IF;
11984 IF p_context = 'IMPL_FIN_IMPACT' THEN
11985
11986 PA_UTILS.ADD_MESSAGE
11987 (p_app_short_name => 'PA',
11988 p_msg_name => 'PA_FP_ALL_CO_REQ_FOR_ALL_PT',
11989 p_token1 => 'PLAN_TYPE',
11990 p_value1 => l_fin_plan_type_name_tbl(j));
11991
11992 ELSIF p_context = 'INCLUDE' THEN
11993
11994 PA_UTILS.ADD_MESSAGE
11995 (p_app_short_name => 'PA',
11996 p_msg_name => 'PA_FP_ALL_CO_REQ_FOR_VER');
11997
11998 /*SELECT cit.name INTO l_ci_name
11999 FROM pa_control_items pci, pa_ci_types_tl cit
12000 WHERE pci.ci_id= x_ci_id_tbl(i)
12001 AND pci.ci_type_id=cit.ci_type_id
12002 AND cit.language=userenv('LANG');
12003
12004 l_ci_name := l_ci_name ||' ('|| x_ci_number(i) || ')';
12005
12006 IF l_cost_impl_flag <> 'Y' THEN
12007
12008 PA_UTILS.ADD_MESSAGE
12009 (p_app_short_name => 'PA',
12010 p_msg_name => 'PA_FP_NO_REV_INTO_TRG_ALL_CO',
12011 p_token1 => 'CHG_ORDER',
12012 p_value1 => l_ci_name);
12013
12014 ELSE
12015
12016 PA_UTILS.ADD_MESSAGE
12017 (p_app_short_name => 'PA',
12018 p_msg_name => 'PA_FP_NO_COST_INTO_TRG_ALL_CO',
12019 p_token1 => 'CHG_ORDER',
12020 p_value1 => l_ci_name);
12021
12022 END IF;*/
12023
12024 END IF;
12025
12026 l_part_impl_err := 'Y';
12027
12028 END IF;
12029
12030 IF l_part_impl_err = 'N' THEN
12031 IF NVL(x_ci_cost_version_id_tbl(i),-1)<>-1 AND l_cost_impl_flag = 'Y' THEN
12032
12033 l_source_version_id_tbl.EXTEND(1);
12034 l_cost_ci_ver_index:=l_source_version_id_tbl.COUNT;
12035 l_source_version_id_tbl(l_source_version_id_tbl.COUNT):=x_ci_cost_version_id_tbl(i);
12036
12037 END IF;
12038
12039 IF NVL(x_ci_rev_version_id_tbl(i),-1)<>-1 AND l_rev_impl_flag IN ('Y','R') THEN -- Bug 3732446 : Need to consider l_rev_impl_flag = 'R' also
12040
12041 l_source_version_id_tbl.EXTEND(1);
12042 l_rev_ci_ver_index:=l_source_version_id_tbl.COUNT;
12043 l_source_version_id_tbl(l_source_version_id_tbl.COUNT):=x_ci_rev_version_id_tbl(i);
12044
12045 END IF;
12046
12047 IF NVL(x_ci_all_version_id_tbl(i),-1)<>-1 AND
12048 (l_cost_impl_flag = 'Y' OR l_rev_impl_flag IN ('Y','R') )THEN -- Bug 3732446 : Need to consider l_rev_impl_flag = 'R' also
12049
12050 l_source_version_id_tbl.EXTEND(1);
12051 l_all_ci_ver_index:=l_source_version_id_tbl.COUNT;
12052 l_source_version_id_tbl(l_source_version_id_tbl.COUNT):=x_ci_all_version_id_tbl(i);
12053
12054 END IF;
12055
12056 IF l_debug_mode = 'Y' THEN
12057
12058 pa_debug.g_err_stage:= 'Calling fp_ci_check_merge_possible';
12059 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12060
12061 END IF;
12062
12063 IF l_source_version_id_tbl.COUNT>0 THEN
12064
12065 IF l_debug_mode = 'Y' THEN
12066 pa_debug.g_err_stage:= 'calling fp_ci_check_merge_possible';
12067 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12068 END IF;
12069
12070 pa_fp_control_items_utils.fp_ci_check_merge_possible(
12071 p_project_id => l_project_id
12072 ,p_source_fp_version_id_tbl => l_source_version_id_tbl
12073 ,p_target_fp_version_id => x_budget_version_id_tbl(j)
12074 ,p_calling_mode => l_calling_mode_for_chk_api
12075 ,x_merge_possible_code_tbl => l_merge_possible_code_tbl
12076 ,x_return_status => x_return_status
12077 ,x_msg_count => x_msg_count
12078 ,x_msg_data => x_msg_data );
12079 END IF;
12080
12081 -- Return status check is not/should not be done since it would be E if merge is not possble.!
12082
12083 --Populate the record type tbl x_budget_ci_map_rec_tbl with the impact of the ci_id that can be
12084 --implemented into the target budget version id
12085 l_implementable_impact := 'NONE';
12086 IF NVL(x_ci_cost_version_id_tbl(i),-1)<>-1 AND l_cost_impl_flag = 'Y' THEN
12087
12088 IF l_merge_possible_code_tbl(l_cost_ci_ver_index)='Y' THEN
12089 l_implementable_impact:='COST';
12090 END IF;
12091
12092 END IF;
12093
12094 IF NVL(x_ci_rev_version_id_tbl(i),-1)<>-1 AND l_rev_impl_flag IN ('Y','R') THEN -- Bug 3732446 : Need to consider l_rev_impl_flag = 'R' also
12095
12096 IF l_merge_possible_code_tbl(l_rev_ci_ver_index)='Y' THEN
12097
12098 IF l_implementable_impact='COST' THEN
12099 --The COST impact is implementable. Since REVENUE is also implementable now
12100 --the implementation code will be BOTH now
12101 l_implementable_impact:='BOTH';
12102 ELSE
12103 l_implementable_impact:='REVENUE';
12104 END IF;
12105
12106 END IF;
12107
12108 END IF;
12109
12110 IF NVL(x_ci_all_version_id_tbl(i),-1)<>-1 AND
12111 (l_cost_impl_flag = 'Y' OR l_rev_impl_flag IN ('Y','R') )THEN -- Bug 3732446 : Need to consider l_rev_impl_flag = 'R' also
12112
12113 IF l_merge_possible_code_tbl(l_all_ci_ver_index)='Y' THEN
12114 l_implementable_impact:='ALL';
12115 END IF;
12116
12117 END IF;
12118 END IF;
12119
12120 l_index:= l_index+1;
12121 -- Prevent the implementation of only cost or revenue into an all version
12122 IF l_part_impl_err = 'Y' THEN
12123 l_implementable_impact := 'NONE';
12124 END IF;
12125
12126 --Record this impact in the output plsql tbl used for mapping the budget version id and ci id
12127 IF l_debug_mode = 'Y' THEN
12128
12129 pa_debug.g_err_stage:= 'About to assign to the rec type';
12130 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12131
12132 END IF;
12133
12134 x_budget_ci_map_rec_tbl(l_index).budget_version_id:=x_budget_version_id_tbl(j);
12135 x_budget_ci_map_rec_tbl(l_index).ci_id:=x_ci_id_tbl(i);
12136 x_budget_ci_map_rec_tbl(l_index).impact_type_code:=l_implementable_impact;
12137 x_budget_ci_map_rec_tbl(l_index).impl_cost_flag:=l_cost_impl_flag;
12138 x_budget_ci_map_rec_tbl(l_index).impl_rev_flag:=l_rev_impl_flag;
12139
12140 END LOOP;--Budget version loop
12141
12142 END LOOP;--ci Loop
12143
12144 END IF;--IF x_ci_id_tbl.COUNT>0 AND x_budget_version_id_tbl.COUNT>0 THEN
12145
12146 --dbms_output.put_line('8');
12147 IF l_debug_mode = 'Y' THEN
12148
12149 pa_debug.g_err_stage:= 'Exiting validate_ci_merge_input_data';
12150 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12151
12152 END IF;
12153
12154 --Round the Partial revenue amount based on the agreement currency.
12155 IF p_context='PARTIAL_REV' AND px_partial_impl_rev_amt <> 0 THEN
12156
12157 SELECT agreement_currency_code
12158 INTO l_agr_curr_code
12159 FROM pa_agreements_all
12160 WHERE agreement_id=x_agreement_id;
12161
12162 px_partial_impl_rev_amt :=Pa_currency.round_trans_currency_amt1(px_partial_impl_rev_amt,
12163 l_agr_curr_code);
12164
12165 END IF;
12166
12167 -- For Bug 3855500
12168 IF p_context='CI_MERGE' THEN
12169 l_msg_count_at_end := fnd_msg_pub.count_msg;
12170 IF l_init_msg_count <> l_msg_count_at_end THEN
12171
12172 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12173
12174 ELSE
12175
12176 x_return_status:='S';
12177
12178 END IF;
12179 ELSE
12180
12181 --This is required as the x_return_status can be reset by the APIs being called from this API. The return status
12182 --will be E when the Invalid_Args_Exception is thrown and in this case the processing will be stopped
12183 x_return_status := 'S' ;
12184 END IF;
12185
12186 IF p_pa_debug_mode = 'Y' THEN
12187 pa_debug.reset_curr_function;
12188 END IF;
12189 --dbms_output.put_line('9');
12190
12191 EXCEPTION
12192
12193 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
12194 l_msg_count := FND_MSG_PUB.count_msg;
12195 IF l_msg_count = 1 THEN
12196 PA_INTERFACE_UTILS_PUB.get_messages
12197 (p_encoded => FND_API.G_TRUE
12198 ,p_msg_index => 1
12199 ,p_msg_count => l_msg_count
12200 ,p_msg_data => l_msg_data
12201 ,p_data => l_data
12202 ,p_msg_index_out => l_msg_index_out);
12203 x_msg_data := l_data;
12204 x_msg_count := l_msg_count;
12205
12206 ELSE
12207 x_msg_count := l_msg_count;
12208 END IF;
12209 x_return_status := FND_API.G_RET_STS_ERROR;
12210 IF p_pa_debug_mode = 'Y' THEN
12211 pa_debug.reset_curr_function;
12212 END IF;
12213 WHEN OTHERS THEN
12214
12215 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
12216 x_msg_count := 1;
12217 x_msg_data := SQLERRM;
12218 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'PA_FP_CI_MERGE'
12219 ,p_procedure_name => 'validate_ci_merge_input_data');
12220
12221 IF l_debug_mode = 'Y' THEN
12222 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
12223 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
12224 pa_debug.reset_curr_function;
12225 END IF;
12226 RAISE;
12227
12228 END validate_ci_merge_input_data;
12229
12230
12231 /*--------------------------------------------------------------------------------------------------------
12232 * Bug 3877815: New procedure introduced, to be called for merge of CIs for auto baseline enabled projects
12233 * This api does the followings:
12234 * i. Copies the CI links of the current working version from the pa_fp_merged_ctrl_items(if there is any
12235 * record present for that version) to temporary nested pl/sql tables.
12236 * ii. Call is made to pa_fp_ci_implement_pkg.create_ci_impact_fund_lines and pa_baseline_funding_pkg.change_management_baseline.
12237 * iii. Insert 2 records into pa_fp_merged_ctrl_items for newly created current working version and the
12238 * baselied version with all the attributes of the record stored in the nested tables except the
12239 * inclusion_method_code, which would be 'COPIED' for the current working version and 'AUTOMATIC' for the baselined version.
12240 * iv. Call is made to pa_fp_ci_merge.FP_CI_UPDATE_IMPACT.
12241 *--------------------------------------------------------------------------------------------------------*/
12242
12243 PROCEDURE impl_ci_into_autobaseline_proj( p_ci_id IN Pa_control_items.ci_id%TYPE -- The Id of the chg doc that needs to be implemented
12244 ,p_ci_rev_version_id IN Pa_budget_versions.budget_version_id%TYPE DEFAULT NULL -- The rev budget version id corresponding to the p_ci_id passed. This will be derived internally if not passed
12245 ,p_budget_version_id IN Pa_budget_versions.budget_version_id%TYPE -- The Id of the budget version into which the CO needs to be implemented
12246 ,p_fin_plan_type_id IN pa_fin_plan_types_b.fin_plan_type_id%TYPE
12247 ,p_partial_impl_rev_amt IN NUMBER DEFAULT NULL -- The revenue amount that should be implemented into the target. This will be passed only in the case of partial implementation
12248 ,p_agreement_id IN Pa_agreements_all.agreement_id%TYPE DEFAULT NULL -- The id of the agreement that is linked with the CO.
12249 ,p_update_agreement_amt_flag IN VARCHAR2 DEFAULT NULL -- Indicates whether to update the agreement amt or not. Null is considered as N
12250 ,p_funding_category IN VARCHAR2 DEFAULT NULL -- The funding category for the agreement
12251 ,x_return_status OUT NOCOPY VARCHAR2 -- Indicates the exit status of the API --File.Sql.39 bug 4440895
12252 ,x_msg_data OUT NOCOPY VARCHAR2 -- Indicates the error occurred --File.Sql.39 bug 4440895
12253 ,x_msg_count OUT NOCOPY NUMBER) -- Indicates the number of error messages --File.Sql.39 bug 4440895
12254 IS
12255 --Start of variables used for debugging
12256 l_msg_count NUMBER :=0;
12257 l_data VARCHAR2(2000);
12258 l_msg_data VARCHAR2(2000);
12259 l_error_msg_code VARCHAR2(30);
12260 l_msg_index_out NUMBER;
12261 l_return_status VARCHAR2(2000);
12262 l_debug_mode VARCHAR2(30);
12263 l_module_name VARCHAR2(100):='PAFPCIMB.impl_ci_into_autobaseline_proj';
12264 l_debug_level5 NUMBER := 5;
12265 --End of variables used for debugging
12266
12267 l_project_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12268 l_plan_version_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12269 l_ci_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12270 l_ci_plan_ver_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12271 l_record_ver_number_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12272 l_creation_date_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
12273 l_created_by_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12274 l_last_update_login_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12275 l_last_updated_by_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12276 l_last_update_date_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
12277 l_incl_method_code_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
12278 l_incl_by_person_id_tbl SYSTEM.PA_NUM_TBL_TYPE :=SYSTEM.PA_NUM_TBL_TYPE();
12279 l_version_type_tbl SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
12280 l_impl_proj_func_raw_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12281 l_impl_proj_func_burd_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12282 l_impl_proj_func_revenue_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12283 l_impl_proj_raw_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12284 l_impl_proj_burd_cost_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12285 l_impl_proj_revenue_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12286 l_impl_quantity_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12287 l_impl_equipment_quant_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12288 l_impl_agr_revenue_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
12289
12290 l_project_id pa_projects_all.project_id%TYPE;
12291
12292 --Variable used for passing ci id to the change management baseline API.
12293 l_CI_ID_Tab PA_PLSQL_DATATYPES.IdTabTyp;
12294 X_Err_Code NUMBER;
12295
12296 l_new_cw_version_id pa_budget_versions.budget_version_id%TYPE;
12297 l_baseline_version_id pa_budget_versions.budget_version_id%TYPE;
12298 l_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
12299 -- Variable to be used for calling FP_CI_LINK_CONTROL_ITEMS
12300 l_rev_ppl_quantity NUMBER;
12301 l_rev_equip_quantity NUMBER;
12302 l_impl_pfc_revenue NUMBER;
12303 l_impl_pc_revenue NUMBER;
12304
12305 -- variables to hold the amounts before merge and after merge
12306 l_rev_ppl_quantity_bf_mg NUMBER;
12307 l_rev_equip_quantity_bf_mg NUMBER;
12308 l_impl_pfc_revenue_bf_mg NUMBER;
12309 l_impl_pc_revenue_bf_mg NUMBER;
12310
12311 l_rev_ppl_quantity_af_mg NUMBER;
12312 l_rev_equip_quantity_af_mg NUMBER;
12313 l_impl_pfc_revenue_af_mg NUMBER;
12314 l_impl_pc_revenue_af_mg NUMBER;
12315
12316 -- Variables used for partial revenue implementation
12317 l_partial_factor NUMBER;
12318 l_total_amount NUMBER;
12319 l_total_amount_in_pfc NUMBER;
12320 l_total_amount_in_pc NUMBER;
12321 l_impl_pc_rev_amt NUMBER;
12322 l_impl_pfc_rev_amt NUMBER;
12323 l_implemented_amt NUMBER := 0;
12324 l_implemented_pc_amt NUMBER;
12325 l_implemented_pfc_amt NUMBER;
12326 l_project_currency_code pa_projects_all.project_currency_code%TYPE;
12327 l_projfunc_currency_code pa_projects_all.project_currency_code%TYPE;
12328 l_ci_already_impl_flag VARCHAR2(1) := 'N';
12329
12330 l_final_rev_par_impl_flag pa_budget_versions.rev_partially_impl_flag%TYPE;
12331 --Bug 4136238
12332 l_partial_impl_rev_amt pa_budget_lines.txn_revenue%TYPE;
12333
12334 BEGIN
12335 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
12336 l_debug_mode := NVL(l_debug_mode, 'Y');
12337 x_msg_count := 0;
12338 x_return_status := FND_API.G_RET_STS_SUCCESS;
12339
12340 IF p_pa_debug_mode = 'Y' THEN
12341 PA_DEBUG.Set_Curr_Function( p_function => l_module_name,
12342 p_debug_mode => l_debug_mode );
12343
12344 END IF;
12345 FND_MSG_PUB.initialize;
12346
12347 IF l_debug_mode = 'Y' THEN
12348 pa_debug.g_err_stage:= 'Entering impl_ci_into_autobaseline_proj';
12349 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12350 pa_debug.g_err_stage:= 'Copying data from pa_fp_merged_ctrl_items';
12351 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12352 END IF;
12353
12354 SELECT
12355 project_id,
12356 plan_version_id,
12357 ci_id,
12358 ci_plan_version_id,
12359 record_version_number,
12360 creation_date,
12361 created_by,
12362 last_update_login,
12363 last_updated_by,
12364 last_update_date,
12365 inclusion_method_code,
12366 included_by_person_id,
12367 version_type,
12368 impl_proj_func_raw_cost,
12369 impl_proj_func_burdened_cost,
12370 impl_proj_func_revenue,
12371 impl_proj_raw_cost,
12372 impl_proj_burdened_cost,
12373 impl_proj_revenue,
12374 impl_quantity,
12375 impl_equipment_quantity,
12376 impl_agr_revenue
12377 BULK COLLECT INTO
12378 l_project_id_tbl,
12379 l_plan_version_id_tbl,
12380 l_ci_id_tbl,
12381 l_ci_plan_ver_id_tbl,
12382 l_record_ver_number_tbl,
12383 l_creation_date_tbl,
12384 l_created_by_tbl,
12385 l_last_update_login_tbl,
12386 l_last_updated_by_tbl,
12387 l_last_update_date_tbl,
12388 l_incl_method_code_tbl,
12389 l_incl_by_person_id_tbl,
12390 l_version_type_tbl,
12391 l_impl_proj_func_raw_cost_tbl,
12392 l_impl_proj_func_burd_cost_tbl,
12393 l_impl_proj_func_revenue_tbl,
12394 l_impl_proj_raw_cost_tbl,
12395 l_impl_proj_burd_cost_tbl,
12396 l_impl_proj_revenue_tbl,
12397 l_impl_quantity_tbl,
12398 l_impl_equipment_quant_tbl,
12399 l_impl_agr_revenue_tbl
12400 FROM pa_fp_merged_ctrl_items
12401 WHERE plan_version_id = p_budget_version_id;
12402
12403 IF l_debug_mode = 'Y' THEN
12404 pa_debug.g_err_stage:= 'Copy from pa_fp_merged_ctrl_items done';
12405 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12406 pa_debug.g_err_stage:= 'No. of records copied: ' || l_plan_version_id_tbl.COUNT;
12407 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12408 END IF;
12409
12410 IF l_debug_mode = 'Y' THEN
12411 pa_debug.g_err_stage:= 'Checking if the CI has been implemented before';
12412 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12413 END IF;
12414
12415 --Bug 4153570.
12416 l_implemented_pc_amt :=0;
12417 l_implemented_pfc_amt := 0;
12418
12419 IF l_plan_version_id_tbl.COUNT > 0 THEN
12420 FOR i IN l_plan_version_id_tbl.FIRST .. l_plan_version_id_tbl.LAST
12421 LOOP
12422 IF l_ci_id_tbl(i) = p_ci_id AND
12423 l_version_type_tbl(i) = 'REVENUE' THEN
12424 l_ci_already_impl_flag := 'Y';
12425 l_implemented_amt := l_impl_agr_revenue_tbl(i);
12426 l_implemented_pc_amt := l_impl_proj_revenue_tbl(i);
12427 l_implemented_pfc_amt := l_impl_proj_func_revenue_tbl(i);
12428 EXIT;
12429 END IF;
12430 END LOOP;
12431 END IF;
12432 l_implemented_amt := nvl(l_implemented_amt,0);
12433
12434 IF l_ci_already_impl_flag = 'Y'THEN
12435 IF l_debug_mode = 'Y' THEN
12436 pa_debug.g_err_stage:= 'The CI has been implemented before';
12437 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12438 END IF;
12439 ELSE
12440 IF l_debug_mode = 'Y' THEN
12441 pa_debug.g_err_stage:= 'The CI has NOT been implemented before';
12442 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12443 END IF;
12444 END IF;
12445
12446 IF l_debug_mode = 'Y' THEN
12447 pa_debug.g_err_stage:= 'Getting the amounts of budget version before merge';
12448 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12449 END IF;
12450
12451
12452 SELECT Nvl(pbv.labor_quantity, 0),
12453 Nvl(pbv.equipment_quantity, 0),
12454 Nvl(pbv.revenue, 0),
12455 Nvl(pbv.total_project_revenue, 0),
12456 pbv.project_id,
12457 p.project_currency_code,
12458 p.projfunc_currency_code
12459 INTO l_rev_ppl_quantity_bf_mg,
12460 l_rev_equip_quantity_bf_mg,
12461 l_impl_pfc_revenue_bf_mg,
12462 l_impl_pc_revenue_bf_mg,
12463 l_project_id,
12464 l_project_currency_code,
12465 l_projfunc_currency_code
12466 FROM pa_budget_versions pbv,
12467 pa_projects_all p
12468 WHERE pbv.project_id = p.project_id
12469 AND pbv.budget_version_id = p_budget_version_id;
12470
12471 IF l_debug_mode = 'Y' THEN
12472 pa_debug.g_err_stage:= 'Deriving l_partial_factor';
12473 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12474 END IF;
12475
12476 --Bug 4136238. Find out the total amounts for CI in pc/pfc/txn amounts. This will be used in deriving the amounts
12477 --that will be finally implemented.
12478 SELECT nvl(sum(txn_revenue),0) total_amt
12479 ,nvl(sum(revenue),0) total_amt_in_pfc
12480 ,nvl(sum(project_revenue),0) total_amt_in_pc
12481 INTO l_total_amount,
12482 l_total_amount_in_pfc,
12483 l_total_amount_in_pc
12484 FROM pa_budget_lines
12485 WHERE budget_version_id = p_ci_rev_version_id;
12486
12487 --Bug 4136238. p_partial_impl_rev_amt will be NULL or 0 only if the full impact is being implemented. In this
12488 --funding lines should be created for the whole amount in the CI version.
12489 IF p_partial_impl_rev_amt IS NULL OR
12490 p_partial_impl_rev_amt = 0 THEN
12491 l_partial_factor := 1;
12492 l_partial_impl_rev_amt := l_total_amount;
12493 l_impl_pc_rev_amt := l_total_amount_in_pc;
12494 l_impl_pfc_rev_amt := l_total_amount_in_pfc;
12495
12496 ELSE
12497 --This means that the total revenue amount for implementation is also 0 . It could be that
12498 --BLs exist with +ve and -ve amounts with the total sum being 0.
12499 IF l_total_amount = 0 THEN
12500 l_partial_factor := 1;
12501 l_impl_pc_rev_amt := l_total_amount_in_pc;
12502 l_impl_pfc_rev_amt := l_total_amount_in_pfc;
12503 ELSE
12504 l_partial_factor := p_partial_impl_rev_amt/(l_total_amount);
12505
12506 --In case of last implementation i.e. all the amount that is left is being implemented, the pc/pfc amounts
12507 --should be the <total amount> -<amount already implemented>
12508 IF Nvl(l_implemented_amt, 0) + p_partial_impl_rev_amt = l_total_amount THEN
12509
12510 l_impl_pc_rev_amt := l_total_amount_in_pc - l_implemented_pc_amt;
12511 l_impl_pfc_rev_amt := l_total_amount_in_pfc - l_implemented_pfc_amt;
12512
12513 ELSE
12514
12515 l_impl_pc_rev_amt := Pa_currency.round_trans_currency_amt1(l_total_amount_in_pc * l_partial_factor,
12516 l_project_currency_code);
12517 l_impl_pfc_rev_amt :=Pa_currency.round_trans_currency_amt1(l_total_amount_in_pfc * l_partial_factor,
12518 l_projfunc_currency_code);
12519 END IF;
12520 END IF;
12521 --Bug 4136238
12522 l_partial_impl_rev_amt := p_partial_impl_rev_amt;
12523 END IF;
12524
12525 IF l_debug_mode = 'Y' THEN
12526 pa_debug.g_err_stage:= 'l_partial_factor derivation done and is: ' || l_partial_factor;
12527 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12528 END IF;
12529
12530
12531 IF l_debug_mode = 'Y' THEN
12532 pa_debug.g_err_stage:= 'Got the amounts of budget version before merge';
12533 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12534 pa_debug.g_err_stage:= 'Calling pa_fp_ci_implement_pkg.create_ci_impact_fund_lines';
12535 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12536 END IF;
12537
12538 pa_fp_ci_implement_pkg.create_ci_impact_fund_lines
12539 (p_project_id => l_project_id,
12540 p_ci_id => p_ci_id,
12541 p_update_agr_amount_flag => P_update_agreement_amt_flag,
12542 p_funding_category => p_funding_category,
12543 p_partial_factor => l_partial_factor,
12544 p_impl_txn_rev_amt => l_partial_impl_rev_amt,
12545 p_impl_pc_rev_amt => l_impl_pc_rev_amt,
12546 p_impl_pfc_rev_amt => l_impl_pfc_rev_amt,
12547 x_msg_data => l_msg_data,
12548 x_msg_count => l_msg_count,
12549 x_return_status => l_return_status);
12550
12551 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12552 IF P_PA_debug_mode = 'Y' THEN
12553 pa_debug.g_err_stage:= 'Error in create_ci_impact_fund_lines';
12554 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
12555 END IF;
12556 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12557 END IF;
12558
12559 IF l_debug_mode = 'Y' THEN
12560 pa_debug.g_err_stage:= 'Call to pa_fp_ci_implement_pkg.create_ci_impact_fund_lines done';
12561 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12562 END IF;
12563
12564 IF l_debug_mode = 'Y' THEN
12565 pa_debug.g_err_stage:= 'Calling pa_baseline_funding_pkg.change_management_baseline';
12566 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12567 END IF;
12568
12569 l_CI_ID_Tab.delete;
12570 l_CI_ID_Tab(1):=p_ci_id;
12571
12572 pa_baseline_funding_pkg.change_management_baseline
12573 (P_Project_ID => l_project_id,
12574 P_CI_ID_Tab => l_CI_ID_Tab,
12575 X_Err_Code => X_Err_Code,
12576 X_Status => l_return_status);
12577
12578 IF X_Err_Code <> 0 THEN
12579 IF P_PA_debug_mode = 'Y' THEN
12580 pa_debug.g_err_stage:= 'Error in change_management_baseline';
12581 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
12582 END IF;
12583 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12584 END IF;
12585
12586 IF l_debug_mode = 'Y' THEN
12587 pa_debug.g_err_stage:= 'Call to pa_baseline_funding_pkg.change_management_baseline done';
12588 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12589 END IF;
12590
12591 IF l_debug_mode = 'Y' THEN
12592 pa_debug.g_err_stage:= 'Deriving new budget version ids';
12593 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12594 END IF;
12595
12596 /* Calling the following apis with hard coded version_type as this api would be
12597 * only called for merge of revenue impacts into the revenue current working/baselined
12598 * versions of an autobaselined enabled project
12599 */
12600 pa_fin_plan_utils.Get_Curr_Working_Version_Info
12601 (p_project_id => l_project_id
12602 ,p_fin_plan_type_id => p_fin_plan_type_id
12603 ,p_version_type => 'REVENUE'
12604 ,x_fp_options_id => l_fp_options_id
12605 ,x_fin_plan_version_id => l_new_cw_version_id
12606 ,x_return_status => l_return_status
12607 ,x_msg_count => l_msg_count
12608 ,x_msg_data => l_msg_data);
12609
12610 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12611 IF P_PA_debug_mode = 'Y' THEN
12612 pa_debug.g_err_stage:= 'Error in Get_Curr_Working_Version_Info';
12613 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
12614 END IF;
12615 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12616 END IF;
12617
12618 IF l_debug_mode = 'Y' THEN
12619 pa_debug.g_err_stage:= 'New current working version id' || l_new_cw_version_id ;
12620 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12621 END IF;
12622
12623 pa_fin_plan_utils.Get_Baselined_Version_Info
12624 (p_project_id => l_project_id
12625 ,p_fin_plan_type_id => p_fin_plan_type_id
12626 ,p_version_type => 'REVENUE'
12627 ,x_fp_options_id => l_fp_options_id
12628 ,x_fin_plan_version_id => l_baseline_version_id
12629 ,x_return_status => l_return_status
12630 ,x_msg_count => l_msg_count
12631 ,x_msg_data => l_msg_data);
12632
12633 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12634 IF P_PA_debug_mode = 'Y' THEN
12635 pa_debug.g_err_stage:= 'Error in Get_Baselined_Version_Info';
12636 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
12637 END IF;
12638 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12639 END IF;
12640
12641 IF l_debug_mode = 'Y' THEN
12642 pa_debug.g_err_stage:= 'New baseline version id' || l_baseline_version_id ;
12643 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12644 END IF;
12645
12646 IF l_plan_version_id_tbl.COUNT > 0 THEN
12647 IF l_debug_mode = 'Y' THEN
12648 pa_debug.g_err_stage:= 'Inserting into pa_fp_merged_ctrl_items with old data';
12649 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12650 END IF;
12651 -- For the current working version
12652 FORALL i IN l_plan_version_id_tbl.FIRST .. l_plan_version_id_tbl.LAST
12653 INSERT INTO pa_fp_merged_ctrl_items
12654 (project_id,
12655 plan_version_id,
12656 ci_id,
12657 ci_plan_version_id,
12658 record_version_number,
12659 creation_date,
12660 created_by,
12661 last_update_login,
12662 last_updated_by,
12663 last_update_date,
12664 inclusion_method_code,
12665 included_by_person_id,
12666 version_type,
12667 impl_proj_func_raw_cost,
12668 impl_proj_func_burdened_cost,
12669 impl_proj_func_revenue,
12670 impl_proj_raw_cost,
12671 impl_proj_burdened_cost,
12672 impl_proj_revenue,
12673 impl_quantity,
12674 impl_equipment_quantity,
12675 impl_agr_revenue)
12676 VALUES (l_project_id_tbl(i),
12677 l_new_cw_version_id, -- The new current working version id
12678 l_ci_id_tbl(i),
12679 l_ci_plan_ver_id_tbl(i),
12680 1, -- Bug 3877815: Review comment
12681 l_creation_date_tbl(i),
12682 l_created_by_tbl(i),
12683 FND_GLOBAL.login_id,
12684 FND_GLOBAL.user_id,
12685 SYSDATE,
12686 l_incl_method_code_tbl(i),
12687 l_incl_by_person_id_tbl(i),
12688 l_version_type_tbl(i),
12689 l_impl_proj_func_raw_cost_tbl(i),
12690 l_impl_proj_func_burd_cost_tbl(i),
12691 l_impl_proj_func_revenue_tbl(i),
12692 l_impl_proj_raw_cost_tbl(i),
12693 l_impl_proj_burd_cost_tbl(i),
12694 l_impl_proj_revenue_tbl(i),
12695 l_impl_quantity_tbl(i),
12696 l_impl_equipment_quant_tbl(i),
12697 l_impl_agr_revenue_tbl(i));
12698
12699 -- For the baseline version
12700
12701 FORALL i IN l_plan_version_id_tbl.FIRST .. l_plan_version_id_tbl.LAST
12702 INSERT INTO pa_fp_merged_ctrl_items
12703 (project_id,
12704 plan_version_id,
12705 ci_id,
12706 ci_plan_version_id,
12707 record_version_number,
12708 creation_date,
12709 created_by,
12710 last_update_login,
12711 last_updated_by,
12712 last_update_date,
12713 inclusion_method_code,
12714 included_by_person_id,
12715 version_type,
12716 impl_proj_func_raw_cost,
12717 impl_proj_func_burdened_cost,
12718 impl_proj_func_revenue,
12719 impl_proj_raw_cost,
12720 impl_proj_burdened_cost,
12721 impl_proj_revenue,
12722 impl_quantity,
12723 impl_equipment_quantity,
12724 impl_agr_revenue)
12725 VALUES (l_project_id_tbl(i),
12726 l_baseline_version_id, -- The baseline version id
12727 l_ci_id_tbl(i),
12728 l_ci_plan_ver_id_tbl(i),
12729 1,
12730 SYSDATE,
12731 FND_GLOBAL.user_id,
12732 FND_GLOBAL.login_id,
12733 FND_GLOBAL.user_id,
12734 SYSDATE,
12735 'AUTOMATIC', -- Bug 3877815: Review comment
12736 l_incl_by_person_id_tbl(i),
12737 l_version_type_tbl(i),
12738 l_impl_proj_func_raw_cost_tbl(i),
12739 l_impl_proj_func_burd_cost_tbl(i),
12740 l_impl_proj_func_revenue_tbl(i),
12741 l_impl_proj_raw_cost_tbl(i),
12742 l_impl_proj_burd_cost_tbl(i),
12743 l_impl_proj_revenue_tbl(i),
12744 l_impl_quantity_tbl(i),
12745 l_impl_equipment_quant_tbl(i),
12746 l_impl_agr_revenue_tbl(i));
12747 ELSE
12748 IF l_debug_mode = 'Y' THEN
12749 pa_debug.g_err_stage:= 'No Data stored in tmp tables';
12750 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12751 END IF;
12752 END IF;
12753
12754 IF l_debug_mode = 'Y' THEN
12755 pa_debug.g_err_stage:= 'Getting the amounts after merge for the budget version';
12756 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12757 END IF;
12758
12759 SELECT Nvl(labor_quantity, 0),
12760 Nvl(equipment_quantity, 0),
12761 Nvl(revenue, 0),
12762 Nvl(total_project_revenue, 0),
12763 Nvl(rev_partially_impl_flag, 'N')
12764 INTO l_rev_ppl_quantity_af_mg,
12765 l_rev_equip_quantity_af_mg,
12766 l_impl_pfc_revenue_af_mg,
12767 l_impl_pc_revenue_af_mg,
12768 l_final_rev_par_impl_flag
12769 FROM pa_budget_versions
12770 WHERE project_id = l_project_id
12771 AND budget_version_id = l_new_cw_version_id;
12772
12773 IF l_debug_mode = 'Y' THEN
12774 pa_debug.g_err_stage:= 'Values obtained after merge for the budget version';
12775 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12776 pa_debug.g_err_stage:= 'Getting the diff of amounts before and after merge for the budget version';
12777 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12778 END IF;
12779
12780 l_rev_ppl_quantity := l_rev_ppl_quantity_af_mg - l_rev_ppl_quantity_bf_mg;
12781 l_rev_equip_quantity := l_rev_equip_quantity_af_mg - l_rev_equip_quantity_bf_mg;
12782 l_impl_pfc_revenue := l_impl_pfc_revenue_af_mg - l_impl_pfc_revenue_bf_mg;
12783 l_impl_pc_revenue := l_impl_pc_revenue_af_mg - l_impl_pc_revenue_bf_mg;
12784
12785 IF l_ci_already_impl_flag = 'Y' THEN
12786 IF l_debug_mode = 'Y' THEN
12787 pa_debug.g_err_stage:= 'Updating record if there is a record for the CI';
12788 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12789 END IF;
12790
12791 -- For Current working version
12792 UPDATE pa_fp_merged_ctrl_items
12793 SET impl_proj_func_revenue = (Nvl(impl_proj_func_revenue,0) + l_impl_pfc_revenue),
12794 impl_proj_revenue = (Nvl(impl_proj_revenue,0) + l_impl_pc_revenue),
12795 impl_quantity = (Nvl(impl_quantity,0) + l_rev_ppl_quantity),
12796 impl_equipment_quantity = (Nvl(impl_equipment_quantity,0) + l_rev_equip_quantity),
12797 impl_agr_revenue = (Nvl(l_implemented_amt,0) + Nvl(l_partial_impl_rev_amt,0)),
12798 record_version_number = (Nvl(record_version_number, 0) + 1),
12799 last_update_login = FND_GLOBAL.login_id,
12800 last_updated_by = FND_GLOBAL.user_id,
12801 last_update_date = SYSDATE
12802 WHERE project_id = l_project_id
12803 AND ci_id = p_ci_id
12804 AND plan_version_id = l_new_cw_version_id
12805 AND version_type = 'REVENUE';
12806
12807 -- For baselined version
12808 UPDATE pa_fp_merged_ctrl_items
12809 SET impl_proj_func_revenue = (Nvl(impl_proj_func_revenue,0) + l_impl_pfc_revenue),
12810 impl_proj_revenue = (Nvl(impl_proj_revenue,0) + l_impl_pc_revenue),
12811 impl_quantity = (Nvl(impl_quantity,0) + l_rev_ppl_quantity),
12812 impl_equipment_quantity = (Nvl(impl_equipment_quantity,0) + l_rev_equip_quantity),
12813 impl_agr_revenue = (Nvl(l_implemented_amt,0) + Nvl(l_partial_impl_rev_amt,0)),
12814 record_version_number = (Nvl(record_version_number, 0) + 1),
12815 last_update_login = FND_GLOBAL.login_id,
12816 last_updated_by = FND_GLOBAL.user_id,
12817 last_update_date = SYSDATE
12818 WHERE project_id = l_project_id
12819 AND ci_id = p_ci_id
12820 AND plan_version_id = l_baseline_version_id
12821 AND version_type = 'REVENUE';
12822
12823 IF l_debug_mode = 'Y' THEN
12824 pa_debug.g_err_stage:= 'Updation of record is done for the CI';
12825 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12826 END IF;
12827
12828 ELSE -- There is no record present in pa_fp_merged_ctrl_items for the ci_id
12829 IF l_debug_mode = 'Y' THEN
12830 pa_debug.g_err_stage:= 'Calling FP_CI_LINK_CONTROL_ITEMS for the CI which has been merged';
12831 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12832 END IF;
12833 -- For the current working version
12834 FP_CI_LINK_CONTROL_ITEMS
12835 (
12836 p_project_id => l_project_id
12837 ,p_s_fp_version_id => p_ci_rev_version_id
12838 ,p_t_fp_version_id => l_new_cw_version_id
12839 ,p_inclusion_method => 'COPIED'
12840 ,p_included_by => NULL
12841 ,p_version_type => 'REVENUE'
12842 ,p_ci_id => p_ci_id
12843 ,p_cost_ppl_qty => NULL
12844 ,p_rev_ppl_qty => l_rev_ppl_quantity
12845 ,p_cost_equip_qty => NULL
12846 ,p_rev_equip_qty => l_rev_equip_quantity
12847 ,p_impl_pfc_raw_cost => NULL
12848 ,p_impl_pfc_revenue => l_impl_pfc_revenue
12849 ,p_impl_pfc_burd_cost => NULL
12850 ,p_impl_pc_raw_cost => NULL
12851 ,p_impl_pc_revenue => l_impl_pc_revenue
12852 ,p_impl_pc_burd_cost => NULL
12853 ,p_impl_agr_revenue => Nvl(l_partial_impl_rev_amt,0) --Bug 3877815: Review comment
12854 ,x_return_status => l_return_status
12855 ,x_msg_count => l_msg_count
12856 ,x_msg_data => l_msg_data);
12857
12858 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
12859 IF l_debug_mode = 'Y' THEN
12860 pa_debug.g_err_stage:= 'Error calling FP_CI_LINK_CONTROL_ITEMS';
12861 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
12862 END IF;
12863 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12864 END IF;
12865
12866 -- For the baseline version
12867 FP_CI_LINK_CONTROL_ITEMS
12868 (
12869 p_project_id => l_project_id
12870 ,p_s_fp_version_id => p_ci_rev_version_id
12871 ,p_t_fp_version_id => l_baseline_version_id
12872 ,p_inclusion_method => 'AUTOMATIC'
12873 ,p_included_by => NULL
12874 ,p_version_type => 'REVENUE'
12875 ,p_ci_id => p_ci_id
12876 ,p_cost_ppl_qty => NULL
12877 ,p_rev_ppl_qty => l_rev_ppl_quantity
12878 ,p_cost_equip_qty => NULL
12879 ,p_rev_equip_qty => l_rev_equip_quantity
12880 ,p_impl_pfc_raw_cost => NULL
12881 ,p_impl_pfc_revenue => l_impl_pfc_revenue
12882 ,p_impl_pfc_burd_cost => NULL
12883 ,p_impl_pc_raw_cost => NULL
12884 ,p_impl_pc_revenue => l_impl_pc_revenue
12885 ,p_impl_pc_burd_cost => NULL
12886 ,p_impl_agr_revenue => Nvl(l_partial_impl_rev_amt,0) --Bug 3877815: Review comment
12887 ,x_return_status => l_return_status
12888 ,x_msg_count => l_msg_count
12889 ,x_msg_data => l_msg_data);
12890
12891 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
12892 IF l_debug_mode = 'Y' THEN
12893 pa_debug.g_err_stage:= 'Error calling FP_CI_LINK_CONTROL_ITEMS';
12894 pa_debug.write(l_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
12895 END IF;
12896 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12897 END IF;
12898
12899 IF l_debug_mode = 'Y' THEN
12900 pa_debug.g_err_stage:= 'Call to FP_CI_LINK_CONTROL_ITEMS DONE';
12901 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12902 END IF;
12903 END IF;
12904
12905 IF l_debug_mode = 'Y' THEN
12906 pa_debug.g_err_stage:= 'Calling pa_fp_ci_merge.FP_CI_UPDATE_IMPACT';
12907 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12908 END IF;
12909
12910 pa_fp_ci_merge.FP_CI_UPDATE_IMPACT
12911 (p_ci_id => p_ci_id
12912 ,p_status_code => 'CI_IMPACT_IMPLEMENTED'
12913 ,p_implemented_by => FND_GLOBAL.USER_ID
12914 ,p_impact_type_code => 'FINPLAN_REVENUE'
12915 ,p_commit_flag => 'N'
12916 ,p_init_msg_list => 'N'
12917 ,p_record_version_number => null
12918 ,x_return_status => l_return_status
12919 ,x_msg_count => l_msg_count
12920 ,x_msg_data => l_msg_data);
12921
12922 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12923 IF P_PA_debug_mode = 'Y' THEN
12924 pa_debug.g_err_stage:= 'Error in FP_CI_UPDATE_IMPACT';
12925 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
12926 END IF;
12927 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
12928 END IF;
12929 IF l_debug_mode = 'Y' THEN
12930 pa_debug.g_err_stage:= 'Call to pa_fp_ci_merge.FP_CI_UPDATE_IMPACT done';
12931 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12932 END IF;
12933 -- Bug 3877815: Review comment
12934
12935 IF l_debug_mode = 'Y' THEN
12936 pa_debug.g_err_stage:= '-------l_implemented_amt is: ' || l_implemented_amt;
12937 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12938 pa_debug.g_err_stage:= '-------l_partial_impl_rev_amt is: ' || l_partial_impl_rev_amt;
12939 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12940 pa_debug.g_err_stage:= '-------l_total_amount is: ' || l_total_amount;
12941 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12942 END IF;
12943 IF (Nvl(l_implemented_amt,0) + Nvl(l_partial_impl_rev_amt,0)) = l_total_amount THEN
12944 --setting rev impl flag to N.
12945 IF l_debug_mode = 'Y' THEN
12946 pa_debug.g_err_stage:='Setting rev_impl_flag to N after autobaseline call';
12947 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12948 END IF;
12949 UPDATE pa_budget_versions
12950 SET rev_partially_impl_flag ='N'
12951 ,record_version_number = record_version_number+1
12952 ,last_update_date = sysdate
12953 ,last_update_login = fnd_global.login_id
12954 ,last_updated_by = fnd_global.user_id
12955 WHERE budget_version_id = p_ci_rev_version_id;
12956
12957 IF l_debug_mode = 'Y' THEN
12958 pa_debug.g_err_stage:='rev_impl_flag set to N ';
12959 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12960 END IF;
12961 ELSE
12962 IF l_final_rev_par_impl_flag <> 'Y' THEN
12963 IF l_debug_mode = 'Y' THEN
12964 pa_debug.g_err_stage:='Setting rev_impl_flag to Y after autobaseline call';
12965 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12966 END IF;
12967 UPDATE pa_budget_versions
12968 SET rev_partially_impl_flag ='Y'
12969 ,record_version_number = record_version_number+1
12970 ,last_update_date = sysdate
12971 ,last_update_login = fnd_global.login_id
12972 ,last_updated_by = fnd_global.user_id
12973 WHERE budget_version_id = p_ci_rev_version_id;
12974
12975 IF l_debug_mode = 'Y' THEN
12976 pa_debug.g_err_stage:='rev_impl_flag set to Y ';
12977 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12978 END IF;
12979 END IF;
12980 END IF;
12981
12982 IF l_debug_mode = 'Y' THEN
12983 pa_debug.g_err_stage:= 'Exiting impl_ci_into_autobaseline_proj';
12984 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
12985 pa_debug.reset_curr_function;
12986 END IF;
12987 EXCEPTION
12988 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
12989 l_msg_count := FND_MSG_PUB.count_msg;
12990 IF l_msg_count = 1 THEN
12991 PA_INTERFACE_UTILS_PUB.get_messages
12992 (p_encoded => FND_API.G_TRUE
12993 ,p_msg_index => 1
12994 ,p_msg_count => l_msg_count
12995 ,p_msg_data => l_msg_data
12996 ,p_data => l_data
12997 ,p_msg_index_out => l_msg_index_out);
12998 x_msg_data := l_data;
12999 x_msg_count := l_msg_count;
13000 ELSE
13001 x_msg_count := l_msg_count;
13002 END IF;
13003
13004 x_return_status := FND_API.G_RET_STS_ERROR;
13005 IF p_pa_debug_mode = 'Y' THEN
13006 pa_debug.reset_curr_function;
13007 END IF;
13008 WHEN OTHERS THEN
13009 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13010 x_msg_count := 1;
13011 x_msg_data := SQLERRM;
13012 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'PA_FP_CI_MERGE'
13013 ,p_procedure_name => 'impl_ci_into_autobaseline_proj');
13014
13015 IF l_debug_mode = 'Y' THEN
13016 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
13017 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13018 pa_debug.reset_curr_function;
13019 END IF;
13020 RAISE;
13021 END impl_ci_into_autobaseline_proj;
13022
13023 ----------------------------------------------------------------------------------------------------------
13024 --1.p_context can be PARTIAL_REV( When called from implement partial revenue page )
13025 ----IMPL_FIN_IMPACT(when called from implement financial impact page)
13026 ----INCLUDE(when called from the include change documents page)
13027 ----CI_MERGE(When called for mergind a CI into a CO/CR)
13028 --2.p_ci_id_tbl, p_ci_cost_version_id_tbl, p_ci_rev_version_id_tbl and p_ci_all_version_id_tbl if passed should
13029 ----contain same number of records. p_ci_id_tbl is mandatory. The version ids for the ci_id will be derived if not
13030 ----passed. Either all the version ids for the CI should be passed or none of them should be passed
13031 --3.p_fin_plan_type_id_tbl, p_fin_plan_type_name_tbl, p_impl_cost_flag_tbl, p_impl_rev_flag_tbl,
13032 ----p_submit_version_flag_tbl should contain same number of records.
13033 ----p_fin_plan_type_id_tbl,p_fin_plan_type_name_tbl contains the fin plan type id and name for the
13034 ----corresponding element in p_budget_version_id_tbl
13035 ----p_impl_cost_flag_tbl, p_impl_rev_flag_tbl can have values of Y or N. They indicate whether the cost/revenue
13036 ----impact can be implemented into the corresponding element in p_budget_version_id_tbl
13037 ----p_submit_version_flag_tbl can contain Y or N, if passed. It indicates whether the target budget version id
13038 ----should be baselined after implementation or not
13039 --4.p_agreement_id, p_update_agreement_amt_flag, p_funding_category are related to the agreement chosen
13040 --5.p_add_msg_to_stack lets the API know whether the error messages should be added to the fnd_msg_pub or not. If
13041 ----Y the messages will be added. They will not be added otherwise
13042 --6.x_translated_msgs_tbl contains the translated error messages. x_translated_err_msg_count indicates the no. of
13043 ----elements in x_translated_err_msg_count. x_translated_err_msg_level indicates whether the level of the message is
13044 ----EXCEPTION, WARNING OR INFORMATION. They will be populated only if p_add_msg_to_stack is N
13045 --7.p_commit_flag can be Y or N. This is defaulted to N. If passed as Y then the commit will be executed after
13046 ----every implementation/inclusion i.e. after one ci has got implemented into the target budget version.
13047
13048 --The processing goes like this
13049 ----Each ci_id will be implemented in every version id in p_budget_version_id_tbl. If p_impl_cost_flag_tbl is Y cost
13050 ----will be implemented. If p_impl_rev_flag_tbl is Y revenue will be implemented.
13051
13052 -- Bug 3934574 Oct 14 2004 Added a new parameter p_calling_context that would be populated when
13053 -- called as part of budget/forecast generation
13054
13055 PROCEDURE implement_change_document
13056 ( p_context IN VARCHAR2
13057 ,p_calling_context IN VARCHAR2 --DEFAULT NULL --bug 3934574
13058 ,p_commit_flag IN VARCHAR2
13059 ,p_ci_id_tbl IN SYSTEM.pa_num_tbl_type
13060 ,p_ci_cost_version_id_tbl IN SYSTEM.pa_num_tbl_type
13061 ,p_ci_rev_version_id_tbl IN SYSTEM.pa_num_tbl_type
13062 ,p_ci_all_version_id_tbl IN SYSTEM.pa_num_tbl_type
13063 ,p_fin_plan_type_id_tbl IN SYSTEM.pa_num_tbl_type
13064 ,p_fin_plan_type_name_tbl IN SYSTEM.pa_varchar2_150_tbl_type
13065 ,p_budget_version_id_tbl IN SYSTEM.pa_num_tbl_type
13066 ,p_impl_cost_flag_tbl IN SYSTEM.pa_varchar2_1_tbl_type
13067 ,p_impl_rev_flag_tbl IN SYSTEM.pa_varchar2_1_tbl_type
13068 ,p_submit_version_flag_tbl IN SYSTEM.pa_varchar2_1_tbl_type
13069 ,p_partial_impl_rev_amt IN NUMBER
13070 ,p_agreement_id IN pa_agreements_all.agreement_id%TYPE
13071 ,p_update_agreement_amt_flag IN VARCHAR2
13072 ,p_funding_category IN VARCHAR2
13073 ,p_raTxn_rollup_api_call_flag IN VARCHAR2 --IPM Arch Enhancement Bug 4865563
13074 ,p_add_msg_to_stack IN VARCHAR2
13075 ,x_translated_msgs_tbl OUT NOCOPY SYSTEM.pa_varchar2_2000_tbl_type --File.Sql.39 bug 4440895
13076 ,x_translated_err_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
13077 ,x_translated_err_msg_level_tbl OUT NOCOPY SYSTEM.pa_varchar2_30_tbl_type --File.Sql.39 bug 4440895
13078 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
13079 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
13080 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
13081 IS
13082 --Start of variables used for debugging
13083 l_msg_count NUMBER :=0;
13084 l_data VARCHAR2(2000);
13085 l_msg_data VARCHAR2(2000);
13086 l_error_msg_code VARCHAR2(30);
13087 l_msg_index_out NUMBER;
13088 l_return_status VARCHAR2(2000);
13089 l_debug_mode VARCHAR2(30);
13090 l_module_name VARCHAR2(100):='PAFPCIMB.implement_change_document';
13091 --End of variables used for debugging
13092
13093 --Variables used for getting the translated error messages
13094 l_msg_counter NUMBER;
13095 l_encoded_msg VARCHAR2(4000);
13096 l_decoded_msg VARCHAR2(4000);
13097 l_translated_msg VARCHAR2(4000);
13098
13099 i NUMBER;
13100 l_ci_id_tbl SYSTEM.pa_num_tbl_type :=SYSTEM.pa_num_tbl_type();
13101 l_ci_cost_version_id_tbl SYSTEM.pa_num_tbl_type :=SYSTEM.pa_num_tbl_type();
13102 l_ci_rev_version_id_tbl SYSTEM.pa_num_tbl_type :=SYSTEM.pa_num_tbl_type();
13103 l_ci_all_version_id_tbl SYSTEM.pa_num_tbl_type :=SYSTEM.pa_num_tbl_type();
13104 l_budget_version_id_tbl SYSTEM.pa_num_tbl_type :=SYSTEM.pa_num_tbl_type();
13105 l_impl_cost_flag_tbl SYSTEM.pa_varchar2_1_tbl_type :=SYSTEM.pa_varchar2_1_tbl_type();
13106 l_impl_rev_flag_tbl SYSTEM.pa_varchar2_1_tbl_type :=SYSTEM.pa_varchar2_1_tbl_type();
13107 l_submit_version_flag_tbl SYSTEM.pa_varchar2_1_tbl_type :=SYSTEM.pa_varchar2_1_tbl_type();
13108 l_fin_plan_type_id_tbl SYSTEM.pa_num_tbl_type :=SYSTEM.pa_num_tbl_type();
13109 l_fin_plan_type_name_tbl SYSTEM.pa_varchar2_150_tbl_type :=SYSTEM.pa_varchar2_150_tbl_type();
13110 l_succ_impl_plan_types SYSTEM.pa_varchar2_150_tbl_type :=SYSTEM.pa_varchar2_150_tbl_type();
13111 l_succ_impl_cos SYSTEM.pa_varchar2_150_tbl_type :=SYSTEM.pa_varchar2_150_tbl_type();
13112 l_ci_number SYSTEM.pa_varchar2_100_tbl_type :=SYSTEM.pa_varchar2_100_tbl_type();
13113 l_plan_type_collection VARCHAR2(2000);
13114 l_ci_number_collection VARCHAR2(2000);
13115 l_partial_impl_succeeded VARCHAR2(1);
13116 l_ci_bv_merge_possible_map_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
13117 l_index NUMBER;
13118 l_cost_ci_version_id pa_budget_Versions.budget_version_id%TYPE;
13119 l_rev_ci_version_id pa_budget_Versions.budget_version_id%TYPE;
13120 l_all_ci_version_id pa_budget_Versions.budget_version_id%TYPE;
13121 l_budget_ci_map_rec_tbl budget_ci_map_rec_tbl_type;
13122 l_impl_impact_type_code VARCHAR2(10);
13123 l_agreement_id pa_agreements_all.agreement_id%TYPE;
13124 l_funding_category VARCHAR2(30);
13125 l_partial_impl_rev_amt pa_budget_lines.txn_revenue%TYPE;
13126
13127 --These two variables will be used for comparing the no. of error messages in the error message stack when the
13128 --API called and when the API is done with the processing. If the no of messages in the two pl/sql tbls are
13129 --different then the error status will be returned as E from the API
13130 l_init_msg_count NUMBER;
13131 l_msg_count_at_end NUMBER;
13132
13133 -- Bug 3877815: Additional local variables declared
13134 l_baseline_api_called VARCHAR2(1);
13135 l_targ_app_cost_flag VARCHAR2(1);
13136 l_targ_app_rev_flag VARCHAR2(1);
13137 l_baseline_funding_flag VARCHAR2(1);
13138
13139
13140 BEGIN
13141 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
13142 l_debug_mode := NVL(l_debug_mode, 'Y');
13143 x_msg_count := 0;
13144 x_return_status := FND_API.G_RET_STS_SUCCESS;
13145 l_init_msg_count:= FND_MSG_PUB.count_msg;
13146 IF p_pa_debug_mode = 'Y' THEN
13147 PA_DEBUG.Set_Curr_Function( p_function => l_module_name,
13148 p_debug_mode => l_debug_mode );
13149 END IF;
13150 -- For bug 3866629
13151 FND_MSG_PUB.initialize;
13152
13153 --dbms_output.put_line('M1');
13154
13155 --If p_commit_flag is N then all the changes done thru this API should be rolled back whenever an error occurs.
13156 --Otherwise only those changes that happened in the merge which failed will be rolled back and all other
13157 --successful merges will be committed.
13158 IF p_commit_flag ='N' THEN
13159 SAVEPOINT implement_change_document;
13160 END IF;
13161
13162 IF l_debug_mode = 'Y' THEN
13163
13164 pa_debug.g_err_stage:= 'Validating the input parameters';
13165 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13166
13167 END IF;
13168
13169 IF p_ci_id_tbl.COUNT =0 OR
13170 p_budget_version_id_tbl.COUNT = 0 THEN
13171
13172 IF l_debug_mode = 'Y' THEN
13173
13174 pa_debug.g_err_stage:= 'p_ci_id_tbl.COUNT is '||p_ci_id_tbl.COUNT;
13175 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13176
13177 pa_debug.g_err_stage:= 'p_budget_version_id_tbl.COUNT is '||p_budget_version_id_tbl.COUNT;
13178 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13179
13180 pa_debug.g_err_stage:= 'Returning-->';
13181 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13182 pa_debug.reset_curr_function;
13183 END IF;
13184 RETURN;
13185
13186 END IF;
13187
13188 IF l_debug_mode = 'Y' THEN
13189
13190 pa_debug.g_err_stage:= 'Calling validate_ci_merge_input_data';
13191 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13192
13193 END IF;
13194
13195 --dbms_output.put_line('M2');
13196 l_partial_impl_rev_amt := p_partial_impl_rev_amt;
13197 validate_ci_merge_input_data(
13198 p_context => p_context
13199 ,p_ci_id_tbl => p_ci_id_tbl
13200 ,p_ci_cost_version_id_tbl => p_ci_cost_version_id_tbl
13201 ,p_ci_rev_version_id_tbl => p_ci_rev_version_id_tbl
13202 ,p_ci_all_version_id_tbl => p_ci_all_version_id_tbl
13203 ,p_budget_version_id_tbl => p_budget_version_id_tbl
13204 ,p_fin_plan_type_id_tbl => p_fin_plan_type_id_tbl
13205 ,p_fin_plan_type_name_tbl => p_fin_plan_type_name_tbl
13206 ,p_impl_cost_flag_tbl => p_impl_cost_flag_tbl
13207 ,p_impl_rev_flag_tbl => p_impl_rev_flag_tbl
13208 ,p_submit_version_flag_tbl => p_submit_version_flag_tbl
13209 ,px_partial_impl_rev_amt => l_partial_impl_rev_amt
13210 ,p_agreement_id => p_agreement_id
13211 ,p_update_agreement_amt_flag => p_update_agreement_amt_flag
13212 ,p_funding_category => p_funding_category
13213 ,x_ci_id_tbl => l_ci_id_tbl
13214 ,x_ci_cost_version_id_tbl => l_ci_cost_version_id_tbl
13215 ,x_ci_rev_version_id_tbl => l_ci_rev_version_id_tbl
13216 ,x_ci_all_version_id_tbl => l_ci_all_version_id_tbl
13217 ,x_ci_number => l_ci_number
13218 ,x_budget_version_id_tbl => l_budget_version_id_tbl
13219 ,x_fin_plan_type_id_tbl => l_fin_plan_type_id_tbl
13220 ,x_fin_plan_type_name_tbl => l_fin_plan_type_name_tbl
13221 ,x_submit_version_flag_tbl => l_submit_version_flag_tbl
13222 ,x_budget_ci_map_rec_tbl => l_budget_ci_map_rec_tbl
13223 ,x_agreement_id => l_agreement_id
13224 ,x_funding_category => l_funding_category
13225 ,x_return_status => x_return_status
13226 ,x_msg_count => x_msg_count
13227 ,x_msg_data => x_msg_data );
13228
13229 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13230 IF l_debug_mode = 'Y' THEN
13231 pa_debug.g_err_stage:='Called API validate_ci_merge_input_data returned error';
13232 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13233 END IF;
13234 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
13235
13236 END IF;
13237
13238 --dbms_output.put_line('M3');
13239 IF l_debug_mode = 'Y' THEN
13240 pa_debug.g_err_stage:='l_agreement_id derived is '||l_agreement_id||' l_funding_category is '||l_funding_category;
13241 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13242
13243 pa_debug.g_err_stage:='Looping for Calling the merge into single version API';
13244 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13245 END IF;
13246
13247
13248 x_translated_msgs_tbl := SYSTEM.pa_varchar2_2000_tbl_type();
13249 x_translated_err_msg_level_tbl := SYSTEM.pa_varchar2_30_tbl_type();
13250
13251 IF p_add_msg_to_stack='N' THEN
13252
13253 --Add the messages from the error stack to the output translated error messages table. These error messages
13254 --will be displayed on the OA pages
13255 l_msg_count := fnd_msg_pub.count_msg;
13256
13257 IF l_debug_mode = 'Y' THEN
13258 pa_debug.g_err_stage:='Inside Loop for l_msg_count : '||l_msg_count;
13259 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13260 END IF;
13261
13262 FOR l_msg_counter IN REVERSE 1..l_msg_count LOOP
13263
13264 IF l_debug_mode = 'Y' THEN
13265 pa_debug.g_err_stage:='Inside l_msg_counter IN REVERSE l_msg_counter : '||l_msg_counter;
13266 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13267 END IF;
13268 PA_UTILS.Get_Encoded_Msg(p_index => l_msg_counter,
13269 p_msg_out => l_encoded_msg);
13270 fnd_message.set_encoded(l_encoded_msg);
13271 l_decoded_msg := fnd_message.get;
13272 l_translated_msg := nvl(l_decoded_msg, l_encoded_msg);
13273
13274 x_translated_msgs_tbl.EXTEND(1);
13275 x_translated_err_msg_level_tbl.EXTEND(1);
13276 x_translated_msgs_tbl(x_translated_msgs_tbl.COUNT):=l_translated_msg;
13277 x_translated_err_msg_level_tbl(x_translated_err_msg_level_tbl.COUNT):='ERROR';
13278
13279 END LOOP;
13280
13281 --Initialise the msg pub so that these errors will not get added again to the translated err msg table
13282 FND_MSG_PUB.initialize;
13283
13284 END IF;
13285
13286 IF l_debug_mode = 'Y' THEN
13287 pa_debug.g_err_stage:='Looping for Calling the merge into single version API';
13288 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13289 END IF;
13290 --Initialise the pl/sql tbls.
13291 l_succ_impl_plan_types := SYSTEM.pa_varchar2_150_tbl_type();
13292 l_succ_impl_cos := SYSTEM.pa_varchar2_150_tbl_type();
13293
13294
13295 --dbms_output.put_line('M4');
13296 --Call the Merge API
13297 IF l_ci_id_tbl.COUNT>0 AND l_budget_version_id_tbl.COUNT>0 THEN
13298
13299 FOR i IN l_ci_id_tbl.FIRST..l_ci_id_tbl.LAST LOOP
13300
13301 FOR j IN l_budget_version_id_tbl.FIRST..l_budget_version_id_tbl.LAST LOOP
13302
13303 l_index:= 1;
13304
13305 --Loop thru the l_budget_ci_map_rec_tbl to find out the record containing the ci id and the
13306 --budget version id combination for which the implementation is being considered
13307 LOOP
13308 EXIT WHEN (l_budget_ci_map_rec_tbl(l_index).budget_version_id=l_budget_version_id_tbl(j) AND
13309 l_budget_ci_map_rec_tbl(l_index).ci_id=l_ci_id_tbl(i));
13310 l_index:=l_index+1;
13311 END LOOP;
13312 l_impl_impact_type_code:=l_budget_ci_map_rec_tbl(l_index).impact_type_code;
13313
13314 IF l_debug_mode = 'Y' THEN
13315 pa_debug.g_err_stage:='l_impl_impact_type_code IS '||l_impl_impact_type_code;
13316 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13317 END IF;
13318
13319
13320 IF l_impl_impact_type_code <> 'NONE' THEN
13321
13322 l_cost_ci_version_id:=NULL;
13323 l_rev_ci_version_id:=NULL;
13324 l_all_ci_version_id:=NULL;
13325
13326 IF l_impl_impact_type_code IN ('COST', 'BOTH') THEN
13327
13328 l_cost_ci_version_id:=l_ci_cost_version_id_tbl(i);
13329
13330 END IF;
13331
13332 IF l_impl_impact_type_code IN ('REVENUE', 'BOTH') THEN
13333
13334 l_rev_ci_version_id:=l_ci_rev_version_id_tbl(i);
13335
13336 END IF;
13337
13338 IF l_impl_impact_type_code = 'ALL' THEN
13339
13340 l_all_ci_version_id:=l_ci_all_version_id_tbl(i);
13341
13342 END IF;
13343
13344 /* Bug 3731975: impl_cost_flag and impl_rev_flag returned by get_impl_details is relevant to a plan type
13345 context. But this API is called in the context of a single version. For example, it could be that for the
13346 plan type impl_cost_flag and impl_rev_flag are 'Y' (COST_AND_REV_SEP) ,
13347 but for the version (either COST or REVENUE) one of them doesnt make sense. */
13348
13349 IF l_impl_impact_type_code = 'COST' THEN
13350
13351 l_budget_ci_map_rec_tbl(l_index).impl_rev_flag:='N';
13352
13353 END IF;
13354
13355 IF l_impl_impact_type_code = 'REVENUE' THEN
13356
13357 l_budget_ci_map_rec_tbl(l_index).impl_cost_flag:= 'N';
13358
13359 END IF;
13360
13361 -- End of code for Bug 3731975
13362
13363 /* Bug 3877815: Checking if the project is autobaselined enabled, if yes
13364 * a separate api would be called to take care of merge for autobaselined projects
13365 */
13366 IF l_debug_mode = 'Y' THEN
13367 pa_debug.g_err_stage:='Bug Fixing started-------';
13368 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13369 END IF;
13370 BEGIN
13371 SELECT Nvl(bv.approved_cost_plan_type_flag, 'N'),
13372 Nvl(bv.approved_rev_plan_type_flag, 'N'),
13373 Nvl(pj.baseline_funding_flag, 'N')
13374 INTO l_targ_app_cost_flag,
13375 l_targ_app_rev_flag,
13376 l_baseline_funding_flag
13377 FROM pa_projects_all pj,
13378 pa_budget_versions bv
13379 WHERE bv.budget_version_id = l_budget_version_id_tbl(j)
13380 AND bv.project_id = pj.project_id;
13381 EXCEPTION
13382 WHEN OTHERS THEN
13383 IF P_PA_debug_mode = 'Y' THEN
13384 pa_debug.g_err_stage:='Error while getting baseline_funding_flag';
13385 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13386 END IF;
13387 RAISE;
13388 END;
13389
13390 l_baseline_api_called := 'N';
13391
13392 --If the version is approved revenue version and if the project is enabled for auto
13393 --baseline then the version should be baselined
13394
13395 IF l_baseline_funding_flag ='Y' AND
13396 l_targ_app_rev_flag = 'Y' AND
13397 l_budget_ci_map_rec_tbl(l_index).impl_rev_flag = 'Y' AND -- Bug 3877815: Review comment
13398 p_context IN ('IMPL_FIN_IMPACT','PARTIAL_REV') THEN
13399
13400 l_baseline_api_called := 'Y';
13401 IF l_debug_mode = 'Y' THEN
13402 pa_debug.g_err_stage:='Calling impl_ci_into_autobaseline_proj for autobaselined projects';
13403 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13404 END IF;
13405 impl_ci_into_autobaseline_proj( p_ci_id => l_ci_id_tbl(i)
13406 ,p_ci_rev_version_id => l_rev_ci_version_id
13407 ,p_budget_version_id => l_budget_version_id_tbl(j)
13408 ,p_fin_plan_type_id => l_fin_plan_type_id_tbl(j)
13409 ,p_partial_impl_rev_amt => l_partial_impl_rev_amt
13410 ,p_agreement_id => l_agreement_id
13411 ,p_update_agreement_amt_flag => p_update_agreement_amt_flag
13412 ,p_funding_category => l_funding_category
13413 ,x_return_status => x_return_status
13414 ,x_msg_data => x_msg_data
13415 ,x_msg_count => x_msg_count);
13416
13417 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13418 IF l_debug_mode = 'Y' THEN
13419 pa_debug.g_err_stage:='--Call to impl_ci_into_autobaseline_proj returned with ERROR';
13420 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13421 END IF;
13422 IF p_context ='PARTIAL_REV' THEN
13423 l_partial_impl_succeeded:='N';
13424 END IF;
13425 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
13426 ELSE
13427 --Record that this implementation is successful
13428 IF p_context='IMPL_FIN_IMPACT' THEN
13429 l_succ_impl_plan_types.EXTEND(1);
13430 l_succ_impl_plan_types(l_succ_impl_plan_types.COUNT):=l_fin_plan_type_name_tbl(j);
13431 ELSIF p_context='PARTIAL_REV' THEN
13432 l_partial_impl_succeeded:='Y';
13433 END IF;
13434 END IF;
13435 END IF;
13436
13437 IF l_baseline_api_called ='N' OR
13438 l_budget_ci_map_rec_tbl(l_index).impl_cost_flag = 'Y' THEN -- Bug 3877815: Review comment
13439 --dbms_output.put_line('M5');
13440 IF l_debug_mode = 'Y' THEN
13441 pa_debug.g_err_stage:='Calling implement_ci_into_single_ver';
13442 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13443 END IF;
13444 implement_ci_into_single_ver
13445 (p_context => p_context
13446 ,p_calling_context => p_calling_context -- bug 3934574
13447 ,p_ci_id => l_ci_id_tbl(i)
13448 ,p_ci_cost_version_id => l_cost_ci_version_id
13449 ,p_ci_rev_version_id => l_rev_ci_version_id
13450 ,p_ci_all_version_id => l_all_ci_version_id
13451 ,p_budget_version_id => l_budget_version_id_tbl(j)
13452 ,p_fin_plan_type_id => l_fin_plan_type_id_tbl(j)
13453 ,p_fin_plan_type_name => l_fin_plan_type_name_tbl(j)
13454 ,p_partial_impl_rev_amt => l_partial_impl_rev_amt
13455 ,p_cost_impl_flag => l_budget_ci_map_rec_tbl(l_index).impl_cost_flag
13456 ,p_rev_impl_flag => l_budget_ci_map_rec_tbl(l_index).impl_rev_flag
13457 ,p_submit_version_flag => l_submit_version_flag_tbl(j)
13458 ,p_agreement_id => l_agreement_id
13459 ,p_update_agreement_amt_flag => p_update_agreement_amt_flag
13460 ,p_funding_category => l_funding_category
13461 ,p_raTxn_rollup_api_call_flag => p_raTxn_rollup_api_call_flag --IPM Arch Enhancement Bug 4865563
13462 ,x_return_status => x_return_status
13463 ,x_msg_data => x_msg_data
13464 ,x_msg_count => x_msg_count);
13465
13466 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13467 IF l_debug_mode = 'Y' THEN
13468 pa_debug.g_err_stage:='Called API PAFPCIMB.implement_ci_into_single_ver error';
13469 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13470 END IF;
13471
13472 IF p_context ='PARTIAL_REV' THEN
13473 l_partial_impl_succeeded:='N';
13474 END IF;
13475
13476 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
13477
13478 ELSE
13479 --Record that this implementation is successful
13480 IF p_context='IMPL_FIN_IMPACT' THEN
13481 l_succ_impl_plan_types.EXTEND(1);
13482 l_succ_impl_plan_types(l_succ_impl_plan_types.COUNT):=l_fin_plan_type_name_tbl(j);
13483 ELSIF p_context='INCLUDE' THEN
13484 l_succ_impl_cos.EXTEND(1);
13485 l_succ_impl_cos(l_succ_impl_cos.COUNT):=l_ci_number(i);
13486 ELSIF p_context='PARTIAL_REV' THEN
13487 l_partial_impl_succeeded:='Y';
13488 END IF;
13489 END IF;
13490 END IF; -- Merge Done
13491
13492 IF p_commit_flag ='Y' THEN
13493 IF l_debug_mode = 'Y' THEN
13494 pa_debug.g_err_stage:='About to commit data';
13495 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13496 END IF;
13497
13498 COMMIT;
13499 END IF;
13500
13501 --dbms_output.put_line('M6');
13502 IF l_debug_mode = 'Y' THEN
13503 pa_debug.g_err_stage:='l_impl_impact_type_code IS '||l_impl_impact_type_code;
13504 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13505 END IF;
13506
13507
13508 IF p_add_msg_to_stack='N' THEN
13509
13510 --Add the messages from the error stack to the output translated error messages table. These error messages
13511 --will be displayed on the OA pages
13512 l_msg_count := fnd_msg_pub.count_msg;
13513 FOR l_msg_counter IN REVERSE 1..l_msg_count LOOP
13514
13515 PA_UTILS.Get_Encoded_Msg(p_index => l_msg_counter,
13516 p_msg_out => l_encoded_msg);
13517 fnd_message.set_encoded(l_encoded_msg);
13518 l_decoded_msg := fnd_message.get;
13519 l_translated_msg := nvl(l_decoded_msg, l_encoded_msg);
13520
13521 x_translated_msgs_tbl.EXTEND(1);
13522 x_translated_err_msg_level_tbl.EXTEND(1);
13523 x_translated_msgs_tbl(x_translated_msgs_tbl.COUNT):=l_translated_msg;
13524 x_translated_err_msg_level_tbl(x_translated_err_msg_level_tbl.COUNT):='ERROR';
13525
13526 END LOOP;
13527
13528 --Initialise the msg pub so that these errors will not get added again to the translated err msg table
13529 FND_MSG_PUB.initialize;
13530
13531 END IF;
13532
13533 END IF;--IF l_ci_bv_merge_possible_map_tbl(l_index) <> 'NONE' THEN
13534
13535 END LOOP;--Budget version loop
13536
13537 END LOOP;--Ci Loop
13538
13539 END IF;--IF l_ci_id_tbl.COUNT>0 AND l_budget_version_id_tbl.COUNT>0 THEN
13540
13541 IF l_debug_mode = 'Y' THEN
13542 pa_debug.g_err_stage:='About to add success msg '||l_succ_impl_plan_types.COUNT;
13543 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13544 END IF;
13545
13546 IF p_context='IMPL_FIN_IMPACT' THEN
13547
13548 IF l_succ_impl_plan_types.COUNT>0 THEN
13549
13550 FOR i IN l_succ_impl_plan_types.FIRST..l_succ_impl_plan_types.LAST LOOP
13551
13552 IF l_debug_mode = 'Y' THEN
13553 pa_debug.g_err_stage:='l_plan_type_collection '||l_plan_type_collection;
13554 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13555 END IF;
13556
13557
13558 IF l_plan_type_collection IS NOT NULL THEN
13559
13560 l_plan_type_collection:=l_plan_type_collection||', ';
13561
13562 END IF;
13563
13564 l_plan_type_collection := l_plan_type_collection || l_succ_impl_plan_types(i);
13565 END LOOP;
13566
13567 IF l_debug_mode = 'Y' THEN
13568 pa_debug.g_err_stage:='l_plan_type_collection a '||l_plan_type_collection;
13569 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13570 END IF;
13571
13572 IF l_plan_type_collection IS NOT NULL THEN
13573 l_plan_type_collection:= '[' || l_plan_type_collection || ']';
13574
13575
13576 PA_UTILS.ADD_MESSAGE
13577 (p_app_short_name => 'PA',
13578 --p_msg_name => 'PA_FP_IMPL_SUCC_PLAN_TYPE',--For bug 3829002
13579 p_msg_name => 'PA_FP_IMPL_OPT_SUCC_IMPL',
13580 p_token1 => 'SUCC_PTS',
13581 p_value1 => l_plan_type_collection );
13582 END IF;
13583
13584 END IF;--IF l_succ_impl_plan_types.COUNT>0 THEN
13585
13586
13587 ELSIF p_context='INCLUDE' THEN
13588
13589 IF l_succ_impl_cos.COUNT>0 THEN
13590 FOR i IN l_succ_impl_cos.FIRST..l_succ_impl_cos.LAST LOOP
13591
13592 IF l_ci_number_collection IS NOT NULL THEN
13593
13594 l_ci_number_collection:=l_ci_number_collection||', ';
13595
13596 END IF;
13597
13598 l_ci_number_collection := l_ci_number_collection || l_succ_impl_cos(i);
13599
13600 END LOOP;
13601
13602 IF l_ci_number_collection IS NOT NULL THEN
13603 l_ci_number_collection:= '[' || l_ci_number_collection || ']';
13604
13605
13606 PA_UTILS.ADD_MESSAGE
13607 (p_app_short_name => 'PA',
13608 p_msg_name => 'PA_FP_INCL_SUCC_CHG_DOC',
13609 p_token1 => 'SUCC_CIS',
13610 p_value1 => l_ci_number_collection );
13611 END IF;
13612
13613 END IF;--IF l_succ_impl_cos.COUNT>0 THEN
13614
13615 ELSIF l_partial_impl_succeeded='Y' THEN
13616
13617 --dbms_output.put_line('M7');
13618 PA_UTILS.ADD_MESSAGE
13619 (p_app_short_name => 'PA',
13620 p_msg_name => 'PA_FP_PARTIAL_IMPL_SUCC');
13621 END IF;
13622
13623 IF l_debug_mode = 'Y' THEN
13624 pa_debug.g_err_stage:='Populating the error msgs at the end';
13625 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13626 END IF;
13627
13628
13629 IF p_add_msg_to_stack='N' THEN
13630
13631 --Add the messages from the error stack to the output translated error messages table. These error messages
13632 --will be displayed on the OA pages
13633 l_msg_count := fnd_msg_pub.count_msg;
13634 FOR l_msg_counter IN REVERSE 1..l_msg_count LOOP
13635
13636 PA_UTILS.Get_Encoded_Msg(p_index => l_msg_counter,
13637 p_msg_out => l_encoded_msg);
13638 fnd_message.set_encoded(l_encoded_msg);
13639 l_decoded_msg := fnd_message.get;
13640 l_translated_msg := nvl(l_decoded_msg, l_encoded_msg);
13641
13642 x_translated_msgs_tbl.EXTEND(1);
13643 x_translated_err_msg_level_tbl.EXTEND(1);
13644 x_translated_msgs_tbl(x_translated_msgs_tbl.COUNT):=l_translated_msg;
13645 x_translated_err_msg_level_tbl(x_translated_err_msg_level_tbl.COUNT):='INFORMATION';
13646
13647 END LOOP;
13648 --Initialise the msg pub so that these errors will not get added again to the translated err msg table
13649 FND_MSG_PUB.initialize;
13650
13651 END IF;
13652
13653 --dbms_output.put_line('M8');
13654 IF l_debug_mode = 'Y' THEN
13655 pa_debug.g_err_stage:='Setting the return status';
13656 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13657 END IF;
13658
13659 --Set the return status depending upon the parameter p_add_msg_to_stack
13660 IF p_add_msg_to_stack='N' THEN
13661
13662 --Set the return status always to S as the calling API should look into the transalted error messages tbl
13663 --for the errors
13664 --Also Initialize x_translated_err_msg_count and clear the out variables
13665 x_translated_err_msg_count:=x_translated_msgs_tbl.count;
13666 x_return_status:='S';
13667 x_msg_data:=null;
13668 x_msg_count:=0;
13669
13670
13671
13672 ELSE
13673 l_msg_count_at_end := fnd_msg_pub.count_msg;
13674
13675 /* -- Commenting out this code for Setting the x_return_status as this would be taken
13676 -- care in the Calling Module. (This Else Part is primarily when this API is called
13677 -- from Generation Flow -- Bug 3749556
13678 IF l_init_msg_count <> l_msg_count_at_end THEN
13679
13680 x_return_status :='E';
13681
13682 ELSE
13683
13684 x_return_status:='S';
13685
13686 END IF;
13687 */
13688 END IF;
13689
13690
13691 IF l_debug_mode = 'Y' THEN
13692
13693 pa_debug.g_err_stage:= 'Exiting implement_change_document count :' || fnd_msg_pub.count_msg;
13694 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
13695 pa_debug.reset_curr_function;
13696 END IF;
13697 EXCEPTION
13698 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
13699 l_msg_count := FND_MSG_PUB.count_msg;
13700 IF l_msg_count = 1 THEN
13701 PA_INTERFACE_UTILS_PUB.get_messages
13702 (p_encoded => FND_API.G_TRUE
13703 ,p_msg_index => 1
13704 ,p_msg_count => l_msg_count
13705 ,p_msg_data => l_msg_data
13706 ,p_data => l_data
13707 ,p_msg_index_out => l_msg_index_out);
13708 x_msg_data := l_data;
13709 x_msg_count := l_msg_count;
13710
13711 ELSE
13712 x_msg_count := l_msg_count;
13713 END IF;
13714
13715 IF p_commit_flag ='N' THEN
13716 ROLLBACK TO implement_change_document;
13717 END IF;
13718
13719 x_return_status := FND_API.G_RET_STS_ERROR;
13720 IF p_pa_debug_mode = 'Y' THEN
13721 pa_debug.reset_curr_function;
13722 END IF;
13723 WHEN OTHERS THEN
13724
13725 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13726 x_msg_count := 1;
13727 x_msg_data := SQLERRM;
13728 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'PA_FP_CI_MERGE'
13729 ,p_procedure_name => 'implement_change_document');
13730
13731 IF l_debug_mode = 'Y' THEN
13732 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
13733 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
13734 END IF;
13735
13736 IF p_commit_flag ='N' THEN
13737 ROLLBACK TO implement_change_document;
13738 END IF;
13739
13740 IF p_pa_debug_mode = 'Y' THEN
13741 pa_debug.reset_curr_function;
13742 END IF;
13743 RAISE;
13744
13745 END implement_change_document;
13746
13747 END PA_FP_CI_MERGE;
13748 --end of PACKAGE pa_fp_ci_merge