[Home] [Help]
PACKAGE BODY: APPS.PA_FP_COPY_FROM_PKG
Source
1 PACKAGE BODY pa_fp_copy_from_pkg AS
2 /* $Header: PAFPCPFB.pls 120.20.12010000.2 2008/09/10 23:53:41 skkoppul ship $*/
3
4 g_plsql_max_array_size NUMBER := 200;
5 g_module_name VARCHAR2(100) := 'pa.plsql.pa_fp_copy_from_pkg';
6
7 -- Bug Fix: 4569365. Removed MRC code.
8 -- g_mrc_exception EXCEPTION;
9
10 TYPE g_period_profile_tbl_typ IS TABLE OF
11 pa_budget_versions.period_profile_id%TYPE INDEX BY BINARY_INTEGER;
12
13 g_source_period_profile_tbl g_period_profile_tbl_typ;
14 g_target_period_profile_tbl g_period_profile_tbl_typ;
15
16
17 --Constants used for mapping (bug 3354518)
18 ELEMENT_TASK_MAP CONSTANT VARCHAR2(30):='Element_Task_Map';
19 ELEMENT_ELEMENT_MAP CONSTANT VARCHAR2(30):='Element_Element_Map';
20
21
22 /*========================================================================
23 This procedure is used to acquie required locks for copy_plan
24 =======================================================================*/
25
26 P_PA_DEBUG_MODE varchar2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
27
28 PROCEDURE Acquire_Locks_For_Copy_Plan(
29 p_source_plan_version_id IN NUMBER
30 ,p_target_plan_version_id IN NUMBER
31 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
32 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
33 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
34 AS
35
36 l_msg_count NUMBER :=0;
37 l_data VARCHAR2(2000);
38 l_msg_data VARCHAR2(2000);
39 l_msg_index_out NUMBER;
40 l_debug_mode VARCHAR2(30);
41
42 --rel_lock NUMBER;
43 --l_locked_by_person_id pa_budget_versions.locked_by_person_id%TYPE;
44 Resource_Busy EXCEPTION;
45 PRAGMA exception_init(Resource_Busy,-00054);
46
47 CURSOR source_fp_opt_cur IS
48 SELECT record_version_number
49 FROM PA_PROJ_FP_OPTIONS
50 WHERE fin_plan_version_id = p_source_plan_version_id
51 FOR UPDATE NOWAIT;
52
53 CURSOR source_bdgt_vers_cur IS
54 SELECT record_version_number
55 FROM PA_BUDGET_VERSIONS
56 WHERE budget_version_id = p_source_plan_version_id
57 FOR UPDATE NOWAIT;
58
59 CURSOR target_fp_opt_cur IS
60 SELECT record_version_number
61 FROM PA_PROJ_FP_OPTIONS
62 WHERE fin_plan_version_id = p_target_plan_version_id
63 FOR UPDATE NOWAIT;
64
65 CURSOR target_bdgt_vers_cur IS
66 SELECT record_version_number
67 FROM PA_BUDGET_VERSIONS
68 WHERE budget_version_id = p_target_plan_version_id
69 FOR UPDATE NOWAIT;
70 BEGIN
71
72 x_msg_count := 0;
73 x_return_status := FND_API.G_RET_STS_SUCCESS;
74
75 IF P_PA_DEBUG_MODE = 'Y' THEN
76 pa_debug.set_err_stack('Acquire_Locks_For_Copy_Plan');
77 END IF;
78 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
79 l_debug_mode := NVL(l_debug_mode, 'Y');
80 IF P_PA_DEBUG_MODE = 'Y' THEN
81 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
82 END IF;
83 /*
84 * Acquire lock on pa_proj_fp_options and pa_budget_versions so that
85 * no other process would be able to modify these tables and all
86 * underlying child tables
87 */
88
89 IF P_PA_DEBUG_MODE = 'Y' THEN
90 pa_debug.g_err_stage:='Acquiring lock on pa_proj_fp_options';
91 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
92 END IF;
93
94 OPEN source_fp_opt_cur;
95
96 OPEN target_fp_opt_cur;
97
98 IF P_PA_DEBUG_MODE = 'Y' THEN
99 pa_debug.g_err_stage:='Acquiring lock on pa_budget_versions';
100 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
101 END IF;
102
103 OPEN source_bdgt_vers_cur;
104
105 OPEN target_bdgt_vers_cur;
106
107 /*
108 * Increment the record_version_number of target version in
109 * pa_budget_versions and pa_proj_fp_options
110 */
111
112 IF P_PA_DEBUG_MODE = 'Y' THEN
113 pa_debug.g_err_stage:='Incrementing record version number of target version in pa_proj_fp_options';
114 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
115 END IF;
116
117 UPDATE PA_PROJ_FP_OPTIONS
118 SET record_version_number = record_version_number+1
119 WHERE fin_plan_version_id=p_target_plan_version_id;
120
121 IF P_PA_DEBUG_MODE = 'Y' THEN
122 pa_debug.g_err_stage:='Incrementing record version number of target version in pa_budget_versions';
123 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
124 END IF;
125
126 UPDATE PA_BUDGET_VERSIONS
127 SET record_version_number = record_version_number+1
128 WHERE budget_version_id = p_target_plan_version_id;
129
130 IF P_PA_DEBUG_MODE = 'Y' THEN
131 pa_debug.g_err_stage:='Closing all the cursors ';
132 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
133 END IF;
134
135 CLOSE target_bdgt_vers_cur;
136 CLOSE source_bdgt_vers_cur;
137 CLOSE target_fp_opt_cur;
138 CLOSE source_fp_opt_cur;
139 IF P_PA_DEBUG_MODE = 'Y' THEN
140 pa_debug.reset_err_stack;
141 END IF;
142 EXCEPTION
143 WHEN Resource_Busy THEN
144 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
145 p_msg_name => 'PA_UTIL_USER_LOCK_FAILED');
146
147 IF P_PA_DEBUG_MODE = 'Y' THEN
148 pa_debug.g_err_stage:='Can not acquire lock.. exiting copy plan';
149 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
150 END IF;
151
152 IF source_fp_opt_cur%ISOPEN THEN
153 CLOSE source_fp_opt_cur;
154 END IF;
155
156 IF source_bdgt_vers_cur%ISOPEN THEN
157 CLOSE source_bdgt_vers_cur;
158 END IF;
159
160 IF target_fp_opt_cur%ISOPEN THEN
161 CLOSE target_fp_opt_cur;
162 END IF;
163
164 IF target_bdgt_vers_cur%ISOPEN THEN
165 CLOSE target_bdgt_vers_cur;
166 END IF;
167
168 l_msg_count := FND_MSG_PUB.count_msg;
169 IF l_msg_count = 1 THEN
170 PA_INTERFACE_UTILS_PUB.get_messages
171 (p_encoded => FND_API.G_TRUE
172 ,p_msg_index => 1
173 ,p_msg_count => l_msg_count
174 ,p_msg_data => l_msg_data
175 ,p_data => l_data
176 ,p_msg_index_out => l_msg_index_out);
177 x_msg_data := l_data;
178 x_msg_count := l_msg_count;
179 ELSE
180 x_msg_count := l_msg_count;
181 END IF;
182
183 x_return_status:= FND_API.G_RET_STS_ERROR;
184 IF P_PA_DEBUG_MODE = 'Y' THEN
185 pa_debug.reset_err_stack;
186 END IF;
187 RAISE;
188
189 WHEN OTHERS THEN
190
191 IF P_PA_DEBUG_MODE = 'Y' THEN
192 pa_debug.g_err_stage:='Can not acquire lock.. exiting copy plan';
193 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
194 END IF;
195
196 IF source_fp_opt_cur%ISOPEN THEN
197 CLOSE source_fp_opt_cur;
198 END IF;
199
200 IF source_bdgt_vers_cur%ISOPEN THEN
201 CLOSE source_bdgt_vers_cur;
202 END IF;
203
204 IF target_fp_opt_cur%ISOPEN THEN
205 CLOSE target_fp_opt_cur;
206 END IF;
207
208 IF target_bdgt_vers_cur%ISOPEN THEN
209 CLOSE target_bdgt_vers_cur;
210 END IF;
211
212 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
213 x_msg_count := 1;
214 x_msg_data := SQLERRM;
215 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
216 ,p_procedure_name => 'ACQUIRE_LOCKS_FOR_COPY_PLAN');
217 IF P_PA_DEBUG_MODE = 'Y' THEN
218 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
219 pa_debug.write('Acquire_Locks_For_Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
220
221 pa_debug.reset_err_stack;
222 END IF;
223 RAISE;
224 END Acquire_Locks_For_Copy_Plan;
225
226 /* =======================================================================
227 This is a main api which does the processing specific to copy
228 plan and then will call copy_version and delete version helper apis.
229
230 4/16/2004 Raja FP M Phase II Copy Plan does not copy 'rate schedules',
231 and 'Generation Options' sub tab data.
232 ========================================================================*/
233
234 PROCEDURE Copy_Plan(
235 p_source_plan_version_id IN NUMBER
236 ,p_target_plan_version_id IN NUMBER
237 ,p_adj_percentage IN NUMBER
238 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
239 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
240 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
241 AS
242
243 l_adj_percentage NUMBER;
244 l_msg_count NUMBER :=0;
245 l_data VARCHAR2(2000);
246 l_msg_data VARCHAR2(2000);
247 l_error_msg_code VARCHAR2(2000);
248 l_msg_index_out NUMBER;
249 l_return_status VARCHAR2(2000);
250 l_debug_mode VARCHAR2(30);
251
252 l_source_fp_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE ;
253 l_target_fp_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE ;
254 --l_locked_by_person_id pa_budget_versions.locked_by_person_id%TYPE;
255 l_project_id pa_projects_all.project_id%TYPE;
256 l_source_resource_list_id pa_budget_versions.resource_list_id%TYPE;
257 l_baselined_resource_list_id pa_budget_versions.resource_list_id%TYPE;
258
259 --This variable contains the resource list id of baselined version
260
261 l_baselined_version_id pa_budget_versions.budget_version_id%TYPE;
262 l_target_plan_version_id pa_budget_versions.budget_version_id%TYPE;
263 l_version_type pa_budget_versions.version_type%TYPE;
264 l_fin_plan_type_id pa_budget_versions.fin_plan_type_id%TYPE;
265 l_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
266 l_target_appr_rev_plan_flag pa_budget_versions.approved_rev_plan_type_flag%TYPE;
267
268 -- Start of Variables defined for bug 2729498
269
270 l_target_fin_plan_type_id pa_budget_versions.fin_plan_type_id%TYPE;
271 l_target_version_type pa_budget_versions.version_type%TYPE;
272
273 -- End of variables defined for bug 2729498
274
275 Resource_Busy EXCEPTION;
276 pragma exception_init(Resource_Busy,-00054);
277
278 -- Start of plsql tables defined for bug#2729191
279
280 TYPE txn_currency_code_tbl_typ IS TABLE OF
281 pa_fp_txn_currencies.txn_currency_code%TYPE INDEX BY BINARY_INTEGER;
282 TYPE default_rev_curr_flag_tbl_typ IS TABLE OF
283 pa_fp_txn_currencies.default_rev_curr_flag%TYPE INDEX BY BINARY_INTEGER;
284 TYPE default_cost_curr_flag_tbl_typ IS TABLE OF
285 pa_fp_txn_currencies.default_cost_curr_flag%TYPE INDEX BY BINARY_INTEGER;
286 TYPE default_all_curr_flag_tbl_typ IS TABLE OF
287 pa_fp_txn_currencies.default_all_curr_flag%TYPE INDEX BY BINARY_INTEGER;
288 TYPE project_currency_flag_tbl_typ IS TABLE OF
289 pa_fp_txn_currencies.project_currency_flag%TYPE INDEX BY BINARY_INTEGER;
290 TYPE projfunc_currency_flag_tbl_typ IS TABLE OF
291 pa_fp_txn_currencies.projfunc_currency_flag%TYPE INDEX BY BINARY_INTEGER;
292 TYPE pc_cost_exchange_rate_tbl_typ IS TABLE OF
293 pa_fp_txn_currencies.project_cost_exchange_rate%TYPE INDEX BY BINARY_INTEGER;
294 TYPE pc_rev_exchange_rate_tbl_typ IS TABLE OF
295 pa_fp_txn_currencies.project_rev_exchange_rate%TYPE INDEX BY BINARY_INTEGER;
296 TYPE pfc_cost_exchange_rate_tbl_typ IS TABLE OF
297 pa_fp_txn_currencies.projfunc_cost_exchange_rate%TYPE INDEX BY BINARY_INTEGER;
298 TYPE pfc_rev_exchange_rate_tbl_typ IS TABLE OF
299 pa_fp_txn_currencies.projfunc_rev_exchange_rate%TYPE INDEX BY BINARY_INTEGER;
300
301 l_txn_currency_code_tbl txn_currency_code_tbl_typ;
302 l_default_rev_curr_flag_tbl default_rev_curr_flag_tbl_typ;
303 l_default_cost_curr_flag_tbl default_cost_curr_flag_tbl_typ;
304 l_default_all_curr_flag_tbl default_all_curr_flag_tbl_typ;
305 l_project_currency_flag_tbl project_currency_flag_tbl_typ;
306 l_projfunc_currency_flag_tbl projfunc_currency_flag_tbl_typ;
307 l_pc_cost_exchange_rate_tbl pc_cost_exchange_rate_tbl_typ;
308 l_pc_rev_exchange_rate_tbl pc_rev_exchange_rate_tbl_typ;
309 l_pfc_cost_exchange_rate_tbl pfc_cost_exchange_rate_tbl_typ;
310 l_pfc_rev_exchange_rate_tbl pfc_rev_exchange_rate_tbl_typ;
311
312 l_source_plan_in_mc_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
313 l_source_appr_rev_plan_flag pa_proj_fp_options.approved_rev_plan_type_flag%TYPE; /* Bug 3276128 */
314
315 -- End of plsql tables defined for bug#2729191
316
317 -- Start of cursors defined for bug#2729191
318
319 CURSOR target_fp_options_cur IS
320 SELECT proj_fp_options_id
321 ,project_id
322 ,fin_plan_type_id
323 ,plan_in_multi_curr_flag
324 ,projfunc_cost_rate_type
325 ,projfunc_cost_rate_date_type
326 ,projfunc_cost_rate_date
327 ,projfunc_rev_rate_type
328 ,projfunc_rev_rate_date_type
329 ,projfunc_rev_rate_date
330 ,project_cost_rate_type
331 ,project_cost_rate_date_type
332 ,project_cost_rate_date
333 ,project_rev_rate_type
334 ,project_rev_rate_date_type
335 ,project_rev_rate_date
336 FROM PA_PROJ_FP_OPTIONS
337 WHERE fin_plan_version_id = p_target_plan_version_id;
338
339 target_fp_options_rec target_fp_options_cur%ROWTYPE;
340
341 CURSOR target_txn_currencies_cur IS
342 SELECT txn_currency_code
343 ,default_rev_curr_flag
344 ,default_cost_curr_flag
345 ,default_all_curr_flag
346 ,project_currency_flag
347 ,projfunc_currency_flag
348 ,project_cost_exchange_rate
349 ,project_rev_exchange_rate
350 ,projfunc_cost_exchange_rate
351 ,projfunc_rev_exchange_rate
352 FROM PA_FP_TXN_CURRENCIES
353 WHERE fin_plan_version_id = p_target_plan_version_id
354 AND proj_fp_options_id = target_fp_options_rec.proj_fp_options_id; -- bug 2779637
355
356 -- End of cursors defined for bug#2729191
357 BEGIN
358
359 FND_MSG_PUB.INITIALIZE;
360 x_msg_count := 0;
361 x_return_status := FND_API.G_RET_STS_SUCCESS;
362
363 IF P_PA_DEBUG_MODE = 'Y' THEN
364 pa_debug.init_err_stack('PA_FP_COPY_FROM_PKG.Copy_Plan');
365 END IF;
366 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
367 l_debug_mode := NVL(l_debug_mode, 'Y');
368 IF P_PA_DEBUG_MODE = 'Y' THEN
369 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
370 END IF;
371 /*
372 * Check if source_verion_id, target_version_id are NULL, if so throw
373 * an error message
374 */
375
376 IF P_PA_DEBUG_MODE = 'Y' THEN
377 pa_debug.g_err_stage := 'Checking for valid parameters:';
378 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
379 END IF;
380
381 IF (p_source_plan_version_id IS NULL) OR
382 (p_target_plan_version_id IS NULL)
383 THEN
384 IF P_PA_DEBUG_MODE = 'Y' THEN
385 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
386 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
387 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
388 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
389 END IF;
390
391 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
392 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
393 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
394 END IF;
395
396 l_adj_percentage := NVL(p_adj_percentage,0);
397
398 -- Doing business validations before proceeding furthur
399
400 IF P_PA_DEBUG_MODE = 'Y' THEN
401 pa_debug.g_err_stage:='Fetching the source plan preference code';
402 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
403 END IF;
404
405 SELECT fin_plan_preference_code
406 ,plan_in_multi_curr_flag -- Bug#2729191
407 ,nvl(approved_rev_plan_type_flag,'N') /* Bug#3276128 */
408 INTO l_source_fp_pref_code
409 ,l_source_plan_in_mc_flag -- Bug#2729191
410 ,l_source_appr_rev_plan_flag /* Bug#3276128 */
411 FROM pa_proj_fp_options
412 WHERE fin_plan_version_id=p_source_plan_version_id;
413
414 IF P_PA_DEBUG_MODE = 'Y' THEN
415 pa_debug.g_err_stage:='Fetching the target plan preference code';
416 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
417 END IF;
418
419 SELECT fin_plan_preference_code,nvl(approved_rev_plan_type_flag,'N')
420 INTO l_target_fp_pref_code,l_target_appr_rev_plan_flag
421 FROM pa_proj_fp_options
422 WHERE fin_plan_version_id=p_target_plan_version_id;
423
424 IF P_PA_DEBUG_MODE = 'Y' THEN
425 pa_debug.g_err_stage:='Checking the compatability of the plans';
426 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
427 END IF;
428
429 IF (l_source_fp_pref_code = PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY AND
430 l_target_fp_pref_code = PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY)
431 OR ( l_source_fp_pref_code = PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY AND
432 l_target_fp_pref_code = PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY)
433 OR (l_target_fp_pref_code = PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SEP)
434 OR (l_source_fp_pref_code = PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SEP)
435 THEN
436 IF P_PA_DEBUG_MODE = 'Y' THEN
437 pa_debug.g_err_stage:='Versions are incompatible';
438 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
439 END IF;
440
441 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
442 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
443 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
444 END IF;
445
446 /* Bug 3149010 - Included the following validation */
447 /* Bug 3276128 - Included source appr rev plan flag condition.
448 If source plan is appr rev, then, no issues in copying
449 from the source to any type of version */
450 /* 3156057: Commenting the following code as from FP.M it is allowed to copy
451 mc enabled budget version into approved revenue budget versions **
452
453
454 IF l_source_appr_rev_plan_flag = 'N' and l_source_plan_in_mc_flag = 'Y' and l_target_appr_rev_plan_flag = 'Y' THEN
455 IF P_PA_DEBUG_MODE = 'Y' THEN
456 pa_debug.g_err_stage:='Cannot copy a mc enabled version into a appr rev plan type version. Bug 3149010';
457 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
458 END IF;
459
460 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
461 p_msg_name => 'PA_FP_CP_INV_MC_TO_APPR_REV');
462 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
463
464 END IF; */
465
466 IF P_PA_DEBUG_MODE = 'Y' THEN
467 pa_debug.g_err_stage := 'Parameter validation complete';
468 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
469 END IF;
470
471 /* Bug #2616445: Commented out the following code for checking the lock as the
472 user will be able to edit plan only if it is not locked by somebody else.
473
474 --Checking if target version is locked or not
475
476 IF P_PA_DEBUG_MODE = 'Y' THEN
477 pa_debug.g_err_stage:='Checking if pa_budget_versions is locked';
478 END IF;
479 IF P_PA_DEBUG_MODE = 'Y' THEN
480 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
481 END IF;
482
483 SELECT locked_by_person_id
484 ,project_id
485 INTO l_locked_by_person_id
486 ,l_project_id
487 FROM PA_BUDGET_VERSIONS
488 WHERE budget_version_id = p_target_plan_version_id;
489
490 IF l_locked_by_person_id IS NOT NULL THEN
491 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
492 p_msg_name => 'PA_FP_VERSION_ALREADY_LOCKED');
493 RAISE Resource_Busy;
494 END IF; */
495
496 IF P_PA_DEBUG_MODE = 'Y' THEN
497 pa_debug.g_err_stage:='Getting the project id';
498 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
499 END IF;
500
501 SELECT project_id
502 INTO l_project_id
503 FROM PA_BUDGET_VERSIONS
504 WHERE budget_version_id = p_target_plan_version_id;
505
506 --Acquire lock on pa_proj_fp_options and pa_budget_versions so that
507 --no other process would be able to modify these tables and all
508 --underlying child tables
509
510 Acquire_Locks_For_Copy_Plan(
511 p_source_plan_version_id => p_source_plan_version_id
512 ,p_target_plan_version_id => p_target_plan_version_id
513 ,x_return_status => l_return_status
514 ,x_msg_count => l_msg_count
515 ,x_msg_data => l_msg_data );
516
517 -- Start of changes for bug 2729191
518
519 -- target_fp_options_rec contains the mc flag and also the mc conversion
520 -- attributes stored in the options table
521
522 OPEN target_fp_options_cur;
523 FETCH target_fp_options_cur INTO target_fp_options_rec;
524 CLOSE target_fp_options_cur;
525
526 /* If target version has MC enabled and the source version isn't MC
527 enabled then the target version should preserve its MC attributes
528 and txn currencies. But, delete_version_helper followed by copy_version
529 override the MC flag and txn currencies for the target version.
530 Since this being a specific case to copy plan, store the required data
531 locally and update the target version once copy_version is complete */
532
533 IF ((target_fp_options_rec.plan_in_multi_curr_flag = 'Y' AND l_source_plan_in_mc_flag = 'N') OR
534 (l_source_plan_in_mc_flag = 'Y' and l_target_appr_rev_plan_flag = 'Y' )) -- added for 3156057
535 THEN
536
537 OPEN target_txn_currencies_cur;
538 IF P_PA_DEBUG_MODE = 'Y' THEN
539 pa_debug.g_err_stage:='target_txn_currencies_cur is opened';
540 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
541 END IF;
542
543 FETCH target_txn_currencies_cur BULK COLLECT INTO
544 l_txn_currency_code_tbl
545 ,l_default_rev_curr_flag_tbl
546 ,l_default_cost_curr_flag_tbl
547 ,l_default_all_curr_flag_tbl
548 ,l_project_currency_flag_tbl
549 ,l_projfunc_currency_flag_tbl
550 ,l_pc_cost_exchange_rate_tbl
551 ,l_pc_rev_exchange_rate_tbl
552 ,l_pfc_cost_exchange_rate_tbl
553 ,l_pfc_rev_exchange_rate_tbl;
554
555 IF P_PA_DEBUG_MODE = 'Y' THEN
556 pa_debug.g_err_stage:='no of txn currencies fetched are '||SQL%ROWCOUNT;
557 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
558 END IF;
559 CLOSE target_txn_currencies_cur;
560
561 IF P_PA_DEBUG_MODE = 'Y' THEN
562 pa_debug.g_err_stage:='target_txn_currencies_cur is closed';
563 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
564 END IF;
565
566 END IF;
567 -- End of changes for bug 2729191
568
569 -- Calling an api to delete the existing records of target_version in
570 -- pa_proj_periods_denorm, p_fin_plan_adj_lines, pa_fp_adj_elements,
571 -- pa_budget_lines,pa_resource_assignments
572
573 IF P_PA_DEBUG_MODE = 'Y' THEN
574 pa_debug.g_err_stage:='Calling the delete version api';
575 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
576 END IF;
577
578 PA_FIN_PLAN_PUB.DELETE_VERSION_HELPER(
579 p_budget_version_id => p_target_plan_version_id
580 ,x_return_status => l_return_status
581 ,x_msg_count => l_msg_count
582 ,x_msg_data => l_msg_data );
583
584 /* Bug# 2647047 - Raise if return status is not success */
585 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
586 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
587 END IF;
588
589 --Calling the api to copy source version to target version
590
591 l_target_plan_version_id := p_target_plan_version_id;
592
593 IF P_PA_DEBUG_MODE = 'Y' THEN
594 pa_debug.g_err_stage:='Calling the copy version api';
595 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
596 END IF;
597
598 PA_FIN_PLAN_PUB.COPY_VERSION(
599 p_project_id => l_project_id
600 ,p_source_version_id => p_source_plan_version_id
601 ,p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING
602 ,px_target_version_id => l_target_plan_version_id
603 ,p_adj_percentage => l_adj_percentage
604 ,p_calling_module => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN
605 ,x_return_status => l_return_status
606 ,x_msg_count => l_msg_count
607 ,x_msg_data => l_msg_data);
608
609 /* Bug# 2647047 - Raise if return status is not success */
610 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
611 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
612 END IF;
613
614 -- Start of changes for bug 2729191
615
616 IF target_fp_options_rec.plan_in_multi_curr_flag = 'Y' AND
617 l_source_plan_in_mc_flag = 'N'
618 THEN
619
620 -- Delete the txn currencies that are copied from source version to target version
621
622 IF P_PA_DEBUG_MODE = 'Y' THEN
623 pa_debug.g_err_stage:='Deleting the txn currencies of the target version after copy_version';
624 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
625 END IF;
626
627 DELETE FROM pa_fp_txn_currencies
628 WHERE fin_plan_version_id = p_target_plan_version_id
629 AND proj_fp_options_id = target_fp_options_rec.proj_fp_options_id; -- bug 2779637
630
631 -- Update the Multi_Curr_Flag and the MC attributes of the target fp option
632
633 IF P_PA_DEBUG_MODE = 'Y' THEN
634 pa_debug.g_err_stage:='Updating the target proj fp option with the MC attributes';
635 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
636 END IF;
637
638 UPDATE PA_PROJ_FP_OPTIONS
639 SET plan_in_multi_curr_flag = target_fp_options_rec.plan_in_multi_curr_flag
640 ,projfunc_cost_rate_type = target_fp_options_rec.projfunc_cost_rate_type
641 ,projfunc_cost_rate_date_type = target_fp_options_rec.projfunc_cost_rate_date_type
642 ,projfunc_cost_rate_date = target_fp_options_rec.projfunc_cost_rate_date
643 ,projfunc_rev_rate_type = target_fp_options_rec.projfunc_rev_rate_type
644 ,projfunc_rev_rate_date_type = target_fp_options_rec.projfunc_rev_rate_date_type
645 ,projfunc_rev_rate_date = target_fp_options_rec.projfunc_rev_rate_date
646 ,project_cost_rate_type = target_fp_options_rec.project_cost_rate_type
647 ,project_cost_rate_date_type = target_fp_options_rec.project_cost_rate_date_type
648 ,project_cost_rate_date = target_fp_options_rec.project_cost_rate_date
649 ,project_rev_rate_type = target_fp_options_rec.project_rev_rate_type
650 ,project_rev_rate_date_type = target_fp_options_rec.project_rev_rate_date_type
651 ,project_rev_rate_date = target_fp_options_rec.project_rev_rate_date
652 WHERE fin_plan_version_id = p_target_plan_version_id;
653
654 -- Insert the txn currencies of the target version present earlier to copy version
655 -- which are stored in the plsql tables
656
657 IF NVL(l_txn_currency_code_tbl.last,0) > 0 THEN
658
659 IF P_PA_DEBUG_MODE = 'Y' THEN
660 pa_debug.g_err_stage:='Inserting the txn currencies of the target version
661 present earlier to copy version';
662 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
663 END IF;
664
665 FORALL i IN l_txn_currency_code_tbl.first..l_txn_currency_code_tbl.last
666 INSERT INTO PA_FP_TXN_CURRENCIES (
667 fp_txn_currency_id
668 ,proj_fp_options_id
669 ,project_id
670 ,fin_plan_type_id
671 ,fin_plan_version_id
672 ,txn_currency_code
673 ,default_rev_curr_flag
674 ,default_cost_curr_flag
675 ,default_all_curr_flag
676 ,project_currency_flag
677 ,projfunc_currency_flag
678 ,last_update_date
679 ,last_updated_by
680 ,creation_date
681 ,created_by
682 ,last_update_login
683 ,project_cost_exchange_rate
684 ,project_rev_exchange_rate
685 ,projfunc_cost_exchange_rate
686 ,projfunc_rev_exchange_rate )
687 SELECT
688 pa_fp_txn_currencies_s.NEXTVAL
689 ,target_fp_options_rec.proj_fp_options_id
690 ,target_fp_options_rec.project_id
691 ,target_fp_options_rec.fin_plan_type_id
692 ,p_target_plan_version_id
693 ,l_txn_currency_code_tbl(i)
694 ,l_default_rev_curr_flag_tbl(i)
695 ,l_default_cost_curr_flag_tbl(i)
696 ,l_default_all_curr_flag_tbl(i)
697 ,l_project_currency_flag_tbl(i)
698 ,l_projfunc_currency_flag_tbl(i)
699 ,SYSDATE
700 ,fnd_global.user_id
701 ,SYSDATE
702 ,fnd_global.user_id
703 ,fnd_global.login_id
704 ,l_pc_cost_exchange_rate_tbl(i)
705 ,l_pc_rev_exchange_rate_tbl(i)
706 ,l_pfc_cost_exchange_rate_tbl(i)
707 ,l_pfc_rev_exchange_rate_tbl(i)
708 FROM DUAL;
709 END IF;
710 END IF;
711 -- End of changes for bug 2729191
712
713 IF P_PA_DEBUG_MODE = 'Y' THEN
714 pa_debug.g_err_stage:='Exiting Copy_Plan';
715 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,3);
716 pa_debug.reset_err_stack;
717 END IF;
718 EXCEPTION
719 WHEN resource_busy THEN
720 IF P_PA_DEBUG_MODE = 'Y' THEN
721 pa_debug.g_err_stage:='Can not acquire lock.. exiting copy plan';
722 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
723 END IF;
724
725 l_msg_count := FND_MSG_PUB.count_msg;
726 IF l_msg_count = 1 THEN
727 PA_INTERFACE_UTILS_PUB.get_messages
728 (p_encoded => FND_API.G_TRUE
729 ,p_msg_index => 1
730 ,p_msg_count => l_msg_count
731 ,p_msg_data => l_msg_data
732 ,p_data => l_data
733 ,p_msg_index_out => l_msg_index_out);
734 x_msg_data := l_data;
735 x_msg_count := l_msg_count;
736 ELSE
737 x_msg_count := l_msg_count;
738 END IF;
739
740 ROLLBACK;
741 x_return_status:= FND_API.G_RET_STS_ERROR;
742 IF P_PA_DEBUG_MODE = 'Y' THEN
743 pa_debug.reset_err_stack;
744 END IF;
745 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
746 l_msg_count := FND_MSG_PUB.count_msg;
747 IF l_msg_count = 1 THEN
748 PA_INTERFACE_UTILS_PUB.get_messages
749 (p_encoded => FND_API.G_TRUE
750 ,p_msg_index => 1
751 ,p_msg_count => l_msg_count
752 ,p_msg_data => l_msg_data
753 ,p_data => l_data
754 ,p_msg_index_out => l_msg_index_out);
755 x_msg_data := l_data;
756 x_msg_count := l_msg_count;
757 ELSE
758 x_msg_count := l_msg_count;
759 END IF;
760
761 ROLLBACK;
762 x_return_status:= FND_API.G_RET_STS_ERROR;
763 IF P_PA_DEBUG_MODE = 'Y' THEN
764 pa_debug.reset_err_stack;
765 END IF;
766 WHEN Others THEN
767 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
768 x_msg_count := 1;
769 x_msg_data := SQLERRM;
770 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
771 ,p_procedure_name => 'COPY_PLAN');
772 IF P_PA_DEBUG_MODE = 'Y' THEN
773 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
774 pa_debug.write('Copy_Plan: ' || g_module_name,pa_debug.g_err_stage,5);
775 pa_debug.reset_err_stack;
776 END IF;
777 ROLLBACK;
778 RAISE;
779 END Copy_Plan;
780
781 /*===========================================================================
782 This function is used to return fin plan amount type for given plan version
783 ===========================================================================*/
784 FUNCTION Get_Fin_Plan_Amount_Type (
785 p_fin_plan_version_id IN pa_proj_fp_options.fin_plan_version_id%TYPE)
786 RETURN VARCHAR2
787 IS
788 l_amount_type VARCHAR2(30);
789 BEGIN
790 SELECT DECODE(fin_plan_preference_code
791 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME, 'A'
792 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY, 'R'
793 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY, 'C')
794 INTO l_amount_type
795 FROM PA_PROJ_FP_OPTIONS
796 WHERE fin_plan_version_id = p_fin_plan_version_id;
797
798 RETURN l_amount_type;
799 END Get_Fin_Plan_Amount_Type;
800
801
802 /*=============================================================================
803 This procedure is used to acquire all the required locks for copy_actual
804 ==============================================================================*/
805
806 PROCEDURE Acquire_Locks_For_Copy_Actual(
807 p_plan_version_id IN pa_proj_fp_options.fin_plan_version_id%TYPE
808 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
809 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
810 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
811 AS
812 l_msg_count NUMBER :=0;
813 l_data VARCHAR2(2000);
814 l_msg_data VARCHAR2(2000);
815 l_msg_index_out NUMBER;
816 l_debug_mode VARCHAR2(30);
817 Resource_Busy EXCEPTION;
818 pragma exception_init(Resource_Busy,-00054);
819
820 CURSOR fp_opt_cur IS
821 SELECT record_version_number
822 FROM PA_PROJ_FP_OPTIONS
823 WHERE fin_plan_version_id = p_plan_version_id
824 FOR UPDATE NOWAIT;
825
826 CURSOR bdgt_ver_cur IS
827 SELECT record_version_number
828 FROM PA_BUDGET_VERSIONS
829 WHERE budget_version_id = p_plan_version_id
830 FOR UPDATE NOWAIT;
831 BEGIN
832
833 x_msg_count := 0;
834 x_return_status := FND_API.G_RET_STS_SUCCESS;
835
836 IF P_PA_DEBUG_MODE = 'Y' THEN
837 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Acquire_Lock_For_Copy_Actual');
838 END IF;
839 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
840 l_debug_mode := NVL(l_debug_mode, 'Y');
841
842 /*
843 * Acquire lock on pa_proj_fp_options and pa_budget_versions so that
844 * no other process would be able to modify these tables and all
845 * underlying child tables
846 */
847
848 IF P_PA_DEBUG_MODE = 'Y' THEN
849 pa_debug.g_err_stage:='Acquiring lock on pa_proj_fp_options';
850 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,3);
851 END IF;
852
853 OPEN fp_opt_cur;
854
855 IF P_PA_DEBUG_MODE = 'Y' THEN
856 pa_debug.g_err_stage:='Acquiring lock on pa_budget_versions';
857 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,3);
858 END IF;
859
860 OPEN bdgt_ver_cur;
861
862 --Increment the record_version_number in pa_budget_versions and
863 --pa_proj_fp_options
864
865 IF P_PA_DEBUG_MODE = 'Y' THEN
866 pa_debug.g_err_stage:='Incrementing record version number of plan version pa_proj_fp_options';
867 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,3);
868 END IF;
869
870 UPDATE PA_PROJ_FP_OPTIONS
871 SET record_version_number = record_version_number+1
872 WHERE fin_plan_version_id=p_plan_version_id;
873
874 IF P_PA_DEBUG_MODE = 'Y' THEN
875 pa_debug.g_err_stage:='Incrementing record version number of plan version in pa_budget_versions';
876 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,3);
877 END IF;
878
879 UPDATE PA_BUDGET_VERSIONS
880 SET record_version_number = record_version_number+1
881 WHERE budget_version_id = p_plan_version_id ;
882
883 IF P_PA_DEBUG_MODE = 'Y' THEN
884 pa_debug.g_err_stage:='Closing fp_opt_cur and bdgt_ver_cur cursors';
885 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,3);
886 END IF;
887
888 CLOSE fp_opt_cur;
889 CLOSE bdgt_ver_cur;
890 IF P_PA_DEBUG_MODE = 'Y' THEN
891 pa_debug.reset_err_stack;
892 END IF;
893 EXCEPTION
894
895 WHEN Resource_Busy THEN
896 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
897 p_msg_name => 'PA_UTIL_USER_LOCK_FAILED');
898
899 IF fp_opt_cur%ISOPEN THEN
900 CLOSE fp_opt_cur;
901 END IF;
902
903 IF bdgt_ver_cur%ISOPEN THEN
904 CLOSE bdgt_ver_cur;
905 END IF;
906
907 IF P_PA_DEBUG_MODE = 'Y' THEN
908 pa_debug.g_err_stage:='Unable to acquire lock';
909 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,5);
910 END IF;
911
912 x_return_status := FND_API.G_RET_STS_ERROR;
913 l_msg_count := FND_MSG_PUB.count_msg;
914 IF l_msg_count = 1 THEN
915 PA_INTERFACE_UTILS_PUB.get_messages
916 (p_encoded => FND_API.G_TRUE
917 ,p_msg_index => 1
918 ,p_msg_count => l_msg_count
919 ,p_msg_data => l_msg_data
920 ,p_data => l_data
921 ,p_msg_index_out => l_msg_index_out);
922 x_msg_data := l_data;
923 x_msg_count := l_msg_count;
924 ELSE
925 x_msg_count := l_msg_count;
926 END IF;
927 IF P_PA_DEBUG_MODE = 'Y' THEN
928 pa_debug.reset_err_stack;
929 END IF;
930 RAISE;
931
932 WHEN Others THEN
933 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
934 x_msg_count := 1;
935 x_msg_data := SQLERRM;
936 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
937 ,p_procedure_name => 'ACQUIRE_LOCKS_FOR_COPY_ACTUAL');
938
939 IF P_PA_DEBUG_MODE = 'Y' THEN
940 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
941 pa_debug.write('Acquire_Locks_For_Copy_Actual: ' || g_module_name,pa_debug.g_err_stage,5);
942 pa_debug.reset_err_stack;
943 END IF;
944 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
945
946 END Acquire_Locks_For_Copy_Actual;
947
948
949 /*=========================================================================
950 This api will be used for two cases.
951 Case 1: When a new budget version is to be created from a source version.
952 px_target_version_id is passed as null in this case
953 Case 2: When the target budget version needs to be modified as the
954 specified source budget version.
955 Non_null value for px_target_version_id is passed in this case.
956 If the adjustment percentage is zero, the amounts are copied as they are.
957 If adjustment percentage is non-zero, then amount coluns are copied as
958 null and rollup api takes care of them.
959
960 --
961 --
962 -- 26-JUN-2003 jwhite - Plannable Task Dev Effort:
963 -- Make code changes Copy_Budget_Version
964 -- procedure to
965 -- enable population of new parameters on
966 -- insert pa_budget_versions
967 --
968 -- 01-AUG-2003 jwhite - Bug 3079891
969 -- For Copy_Budget_Version, hardcoded
970 -- the following columns to NULL:
971 -- - request_id
972 -- - plan_processing_code
973 --
974
975
976
977 r11.5 FP.M Developement ----------------------------------
978
979 08-JAN-2004 jwhite Bug 3362316
980
981 Extensively rewrote Copy_Budget_Version
982 - CURSOR l_bv_csr IS
983 - INSERT INTO PA_BUDGET_VERSIONS (
984 - UPDATE pa_budget_versions
985
986 29-JAN-2004 sgoteti Bug 3354518: Added the parameter
987 p_struct_elem_version_id
988
989 16-APR-2004 rravipat Bug 3354518 FP M Phase II Development
990 When copy_budget_version is called during copy plan, amount
991 generation related columnslike last_amt_gen_date would be
992 updated as null. This is because none of the init columns are
993 copied from source version to target.
994
995 10-Jun-05 Bug 4337221: dbora
996 if the calling context is workplan, then derive the adjustment percentage
997 always as 0, so that the version level rolled up quantity and cost amounts get
998 copied from the source version, as it is to the target version.
999 --Bug 4290043.Included parameter to indicate whether to copy actual info or not.
1000 =========================================================================*/
1001
1002 PROCEDURE Copy_Budget_Version(
1003 p_source_project_id IN NUMBER
1004 ,p_target_project_id IN NUMBER
1005 ,p_source_version_id IN NUMBER
1006 ,p_copy_mode IN VARCHAR2
1007 ,p_adj_percentage IN NUMBER
1008 ,p_calling_module IN VARCHAR2
1009 ,p_shift_days IN NUMBER
1010 ,p_copy_actuals_flag IN VARCHAR2
1011 ,px_target_version_id IN OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1012 ,p_struct_elem_version_id IN pa_budget_versions.budget_version_id%TYPE --Bug 3354518
1013 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1014 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
1015 ,x_msg_data OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
1016 AS
1017
1018 -- Variables to be used for debugging purpose
1019
1020 l_msg_count NUMBER := 0;
1021 l_data VARCHAR2(2000);
1022 l_msg_data VARCHAR2(2000);
1023 l_error_msg_code VARCHAR2(2000);
1024 l_msg_index_out NUMBER;
1025 l_return_status VARCHAR2(2000);
1026 l_debug_mode VARCHAR2(30);
1027
1028 l_adj_percentage NUMBER;
1029 l_source_project_id pa_projects_all.project_id%TYPE;
1030 l_target_project_id pa_projects_all.project_id%TYPE;
1031 l_version_name pa_budget_versions.version_name%TYPE;
1032 l_fin_plan_type_id pa_proj_fp_options.fin_plan_type_id%TYPE;
1033 l_current_profile_id pa_budget_versions.period_profile_id%TYPE;
1034 l_max_version pa_budget_versions.version_number%TYPE;
1035 l_version_number pa_budget_versions.version_number%TYPE;
1036 l_version_type pa_budget_versions.version_type%TYPE;
1037 l_budget_version_id pa_budget_versions.budget_version_id%TYPE;
1038 l_budget_status_code pa_budget_versions.budget_status_code%TYPE;
1039 l_current_flag pa_budget_versions.current_flag%TYPE;
1040 l_current_working_flag pa_budget_versions.current_working_flag%TYPE;
1041 l_baselined_by_person_id pa_budget_versions.baselined_by_person_id%TYPE;
1042 l_baselined_date pa_budget_versions.baselined_date%TYPE;
1043
1044 l_cost_flag VARCHAR2(1);
1045 l_revenue_flag VARCHAR2(1);
1046
1047 l_ci_id NUMBER;
1048
1049 -- jwhite, 26-JUN-2003: Added for Plannable Task Dev Effort ------------------
1050
1051 l_refresh_required_flag VARCHAR2(1) := NULL;
1052 l_process_code VARCHAR2(30) := NULL;
1053
1054 -- rravipat 3/26/2004 Added for FP M Phase II copy project impact
1055
1056 l_wbs_struct_version_id pa_budget_versions.project_structure_version_id%TYPE;
1057 l_source_cur_planning_period pa_budget_versions.current_planning_period%TYPE;
1058 l_target_cur_planning_period pa_budget_versions.current_planning_period%TYPE;
1059 l_time_phased_code pa_proj_fp_options.cost_time_phased_code%TYPE;
1060
1061 l_gl_start_period gl_periods.period_name%TYPE;
1062 l_gl_end_period gl_periods.period_name%TYPE;
1063 l_gl_start_Date VARCHAR2(100);
1064 l_pa_start_period pa_periods_all.period_name%TYPE;
1065 l_pa_end_period pa_periods_all.period_name%TYPE;
1066 l_pa_start_date VARCHAR2(100);
1067 l_plan_version_exists_flag VARCHAR2(1);
1068 l_prj_start_date VARCHAR2(100);
1069 l_prj_end_date VARCHAR2(100);
1070
1071 -- ---------------------------------------------------------------------------
1072
1073
1074
1075 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
1076
1077 CURSOR l_bv_csr IS
1078 SELECT resource_list_id /* Added for bug# 2757847 */
1079 ,labor_quantity /* Added for the bug #2645579. */
1080 ,raw_cost
1081 ,burdened_cost
1082 ,revenue
1083 ,pm_product_code
1084 ,pm_budget_reference
1085 ,wf_status_code
1086 ,adw_notify_flag
1087 ,NULL --prc_generated_flag --Bug 5099353
1088 ,plan_run_date
1089 ,plan_processing_code
1090 ,total_borrowed_revenue
1091 ,total_revenue_adj
1092 ,total_lent_resource_cost
1093 ,total_cost_adj
1094 ,total_unassigned_time_cost
1095 ,total_utilization_percent
1096 ,total_utilization_hours
1097 ,total_utilization_adj
1098 ,total_capacity
1099 ,total_head_count
1100 ,total_head_count_adj
1101 ,total_tp_cost_in
1102 ,total_tp_cost_out
1103 ,total_tp_revenue_in
1104 ,total_tp_revenue_out
1105 ,total_project_raw_cost
1106 ,total_project_burdened_cost
1107 ,total_project_revenue
1108 ,period_profile_id /* Added for #2587671 */
1109 ,object_type_code
1110 ,object_id
1111 -- ,primary_cost_forecast_flag FP M Phase II Dev changes this column should not be updated
1112 -- ,primary_rev_forecast_flag FP M Phase II Dev changes this column should not be updated
1113 -- ,rev_partially_impl_flag FP M Phase II Dev changes this column should not be updated
1114 ,equipment_quantity
1115 ,pji_summarized_flag
1116 ,wp_version_flag
1117 ,current_planning_period
1118 ,period_mask_id
1119 ,last_amt_gen_date
1120 ,actual_amts_thru_period
1121 ,project_structure_version_id
1122 ,etc_start_date --Bug 3927244
1123 FROM pa_budget_versions
1124 WHERE budget_version_id = p_source_version_id;
1125
1126 -- ---------------------------------------------------------------------------
1127
1128
1129 l_bv_rec l_bv_csr%ROWTYPE;
1130
1131 -- Bug 3927244
1132 l_src_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
1133 l_trg_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
1134
1135 CURSOR get_plan_class_code_csr(c_budget_version_id pa_budget_versions.budget_version_id%TYPE) IS
1136 SELECT pfb.plan_class_code,pbv.project_id
1137 FROM pa_fin_plan_types_b pfb,
1138 pa_budget_versions pbv
1139 WHERE pbv.budget_version_id = c_budget_version_id
1140 AND pbv.fin_plan_type_id = pfb.fin_plan_type_id;
1141 -- Bug 3927244
1142
1143
1144 BEGIN
1145
1146 x_msg_count := 0;
1147 x_return_status := FND_API.G_RET_STS_SUCCESS;
1148 IF p_pa_debug_mode = 'Y' THEN
1149 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Budget_Version');
1150 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
1151 l_debug_mode := NVL(l_debug_mode, 'Y');
1152 pa_debug.set_process('PLSQL','LOG',p_pa_debug_mode);
1153 END IF;
1154
1155 --Check if source_verion_id is NULL, if so throw an error message
1156
1157 IF P_PA_DEBUG_MODE = 'Y' THEN
1158 pa_debug.g_err_stage := 'Parameter Validation';
1159 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1160 END IF;
1161
1162 IF (p_source_version_id IS NULL) OR
1163 (p_calling_module IS NULL)
1164 THEN
1165 IF P_PA_DEBUG_MODE = 'Y' THEN
1166 pa_debug.g_err_stage := 'Source_plan='||p_source_version_id;
1167 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1168 pa_debug.g_err_stage := 'Calling_module='||p_calling_module;
1169 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1170 END IF;
1171
1172 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
1173 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
1174
1175 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1176
1177 END IF;
1178
1179 --Throw an error if the struct element version id is not passed in workplan context
1180 IF p_calling_module=PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_WORKPLAN AND
1181 p_struct_elem_version_id IS NULL THEN
1182
1183 IF P_PA_DEBUG_MODE = 'Y' THEN
1184 pa_debug.g_err_stage := 'In workplan context p_struct_elem_version_id passed is '||p_struct_elem_version_id;
1185 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1186 END IF;
1187 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
1188 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
1189
1190 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1191 END IF;
1192
1193 IF P_PA_DEBUG_MODE = 'Y' THEN
1194 pa_debug.g_err_stage := 'Parameter validation complete';
1195 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1196 END IF;
1197
1198 IF p_calling_module = PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_WORKPLAN THEN
1199 -- Bug 4337221:
1200 l_adj_percentage := 0;
1201 ELSE
1202 -- Make the adjustment percentage zero if it is null
1203
1204 l_adj_percentage := NVL(p_adj_percentage,0);
1205 END IF;
1206
1207 IF p_pa_debug_mode = 'Y' THEN
1208 pa_debug.g_err_stage := 'Source_plan='||p_source_version_id;
1209 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1210 pa_debug.g_err_stage := 'Target_plan='||px_target_version_id;
1211 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1212 pa_debug.g_err_stage := 'Calling_module='||p_calling_module;
1213 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1214 pa_debug.g_err_stage := 'Adj_percentage='||l_adj_percentage;
1215 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1216 END IF;
1217
1218 -- Get the fin plan type id, source version name, project id from
1219 -- pa_budget_versions using source_version_id
1220
1221 IF px_target_version_id IS NULL THEN
1222
1223 IF P_PA_DEBUG_MODE = 'Y' THEN
1224 pa_debug.g_err_stage := 'Fetching version name,fin_plan_type_id of source version';
1225 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1226 END IF;
1227
1228 SELECT NVL(p_target_project_id,project_id)
1229 ,NVL(p_source_project_id,project_id)
1230 ,version_name
1231 ,fin_plan_type_id
1232 ,version_type
1233 ,ci_id
1234 ,current_planning_period
1235 INTO l_target_project_id
1236 ,l_source_project_id
1237 ,l_version_name
1238 ,l_fin_plan_type_id
1239 ,l_version_type
1240 ,l_ci_id
1241 ,l_source_cur_planning_period
1242 FROM pa_budget_versions
1243 WHERE budget_version_id = p_source_version_id;
1244
1245 -- 3/30/2004 Raja FP M Phase II Dev Changes
1246 -- If source project and target project are different do not copy
1247 -- the current planning period from souce version. They should be
1248 -- defaulted to PA/GL period inwhich nvl(project start date, sysdate)
1249 -- falls
1250
1251 IF l_source_project_id <> l_target_project_id THEN
1252
1253 --Bug 4200168. Call Pa_Prj_Period_Profile_Utils.Get_Prj_Defaults only if source
1254 --current planning period is not null and target time phased code is P or G.
1255 l_time_phased_code := PA_FIN_PLAN_UTILS.Get_Time_Phased_code(p_source_version_id);
1256 IF ( (l_time_phased_code = 'P' OR l_time_phased_code = 'G') AND l_source_cur_planning_period IS NOT NULL) THEN
1257 Pa_Prj_Period_Profile_Utils.Get_Prj_Defaults(
1258 p_project_id => p_target_project_id
1259 ,p_info_flag => 'ALL'
1260 ,p_create_defaults => 'N'
1261 ,x_gl_start_period => l_gl_start_period
1262 ,x_gl_end_period => l_gl_end_period
1263 ,x_gl_start_Date => l_gl_start_Date
1264 ,x_pa_start_period => l_pa_start_period
1265 ,x_pa_end_period => l_pa_end_period
1266 ,x_pa_start_date => l_pa_start_date
1267 ,x_plan_version_exists_flag => l_plan_version_exists_flag
1268 ,x_prj_start_date => l_prj_start_date
1269 ,x_prj_end_date => l_prj_end_date );
1270 END IF;
1271
1272 --l_time_phased_code := PA_FIN_PLAN_UTILS.Get_Time_Phased_code(p_source_version_id);
1273
1274 IF l_source_cur_planning_period IS NOT NULL THEN
1275
1276 IF l_time_phased_code = 'P' THEN
1277 l_target_cur_planning_period := l_pa_start_period;
1278 ELSIF l_time_phased_code = 'G' THEN
1279 l_target_cur_planning_period := l_gl_start_period;
1280 END IF;
1281
1282 END IF;
1283 ELSE
1284 l_target_cur_planning_period := l_source_cur_planning_period;
1285 END IF;
1286
1287 --Get the version_number, version_name
1288
1289 IF P_PA_DEBUG_MODE = 'Y' THEN
1290 pa_debug.g_err_stage := 'Fetch the maximum version number';
1291 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1292 END IF;
1293
1294 IF p_copy_mode = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING THEN
1295
1296 -- Get the max version number of working versions for this plan type
1297 --start of changes for bug:- 2570250
1298 /*
1299 SELECT NVL(MAX(version_number),0)
1300 INTO l_max_version
1301 FROM pa_budget_versions
1302 WHERE project_id = l_project_id
1303 AND fin_plan_type_id = l_fin_plan_type_id
1304 AND budget_status_code IN (PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING,
1305 PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_SUBMITTED); */
1306 PA_FIN_PLAN_UTILS.Get_Max_Budget_Version_Number
1307 (p_project_id => l_target_project_id
1308 ,p_fin_plan_type_id => l_fin_plan_type_id
1309 ,p_version_type => l_version_type
1310 ,p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING
1311 ,p_ci_id => l_ci_id /* FP M changes */
1312 ,p_lock_required_flag => 'Y'
1313 ,x_version_number => l_max_version
1314 ,x_return_status => l_return_status
1315 ,x_msg_count => l_msg_count
1316 ,x_msg_data => l_msg_data );
1317
1318 --end of changes for bug :- 2570250
1319
1320 l_version_number := l_max_version + 1;
1321 l_budget_status_code := PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING;
1322 l_current_flag := 'N';
1323
1324 -- baselined info should be null for a working version
1325
1326 l_baselined_date := NULL;
1327 l_baselined_by_person_id := NULL;
1328
1329 /* #2634622: The version name will not be appended with 'Copy' from now on.
1330 From any calling place, where the version name is expected to be different,
1331 an update would be done to the pa_budget_versions directly.
1332
1333 FND_MESSAGE.SET_NAME('PA','PA_FP_COPY_MESSAGE');
1334 l_version_name:= l_version_name ||'-'||FND_MESSAGE.GET;
1335 */
1336
1337 IF l_version_number = 1 AND l_ci_id is null THEN
1338 l_current_working_flag := 'Y';
1339 ELSE
1340 l_current_working_flag := 'N';
1341 END IF;
1342
1343 ELSIF p_copy_mode = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED THEN
1344
1345 -- Get the max version number of baselined versions for this plan type
1346
1347 --start of changes for bug :- 2570250
1348 /*
1349 SELECT NVL(MAX(version_number),0)
1350 INTO l_max_version
1351 FROM pa_budget_versions
1352 WHERE project_id = l_project_id
1353 AND fin_plan_type_id = l_fin_plan_type_id
1354 AND budget_status_code = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED;
1355 */
1356
1357 PA_FIN_PLAN_UTILS.Get_Max_Budget_Version_Number
1358 (p_project_id => l_target_project_id
1359 ,p_fin_plan_type_id => l_fin_plan_type_id
1360 ,p_version_type => l_version_type
1361 ,p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED
1362 ,p_ci_id => l_ci_id /* FP M changes */
1363 ,p_lock_required_flag => 'Y'
1364 ,x_version_number => l_max_version
1365 ,x_return_status => l_return_status
1366 ,x_msg_count => l_msg_count
1367 ,x_msg_data => l_msg_data );
1368
1369 --end of changes for bug :- 2570250
1370
1371 l_version_number := l_max_version+1;
1372 l_budget_status_code := PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED;
1373 l_current_flag := 'Y';
1374
1375 -- For bug 3858601
1376 -- Stamp employee_id in baseliend_by_person_id of pa_budget_versions table when
1377 -- a budget version is baselined instead of user id.
1378
1379 l_baselined_date := SYSDATE;
1380 --l_baselined_by_person_id := FND_GLOBAL.USER_ID;
1381
1382 SELECT employee_id
1383 INTO l_baselined_by_person_id
1384 FROM fnd_user
1385 where user_id = FND_GLOBAL.USER_ID;
1386 --End of bug 3858601
1387
1388 -- Bug # 2615988. The message 'Copy' Should not be suffixed to
1389 -- the version name when the mode is 'B'.
1390 -- FND_MESSAGE.SET_NAME('PA','PA_FP_COPY_MESSAGE');
1391 -- l_version_name:= l_version_name ||'-'||FND_MESSAGE.GET;
1392
1393 END IF;
1394
1395 -- Fetch new budget_version_id
1396
1397 IF P_PA_DEBUG_MODE = 'Y' THEN
1398 pa_debug.g_err_stage := 'Fetch new budget version id';
1399 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1400 END IF;
1401
1402 SELECT pa_budget_versions_s.NEXTVAL
1403 INTO px_target_version_id
1404 FROM DUAL;
1405
1406 -- For workplan context project structure version id should be populated
1407 -- For Finplan the column is not maintained
1408
1409 IF p_struct_elem_version_id IS NOT NULL AND
1410 p_calling_module=PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_WORKPLAN
1411 THEN
1412 l_wbs_struct_version_id := p_struct_elem_version_id;
1413
1414 ELSE
1415 l_wbs_struct_version_id := NULL;
1416 END IF;
1417
1418 /* This fix is done during IB1 testing of FP M. There are some flows, which
1419 * * are creation more than one budget version for the same workplan version.
1420 * To
1421 * * identify such flows, the following check is being made so that dev can
1422 * fix
1423 * * such issues */
1424
1425 Declare
1426 l_exists varchar2(1);
1427 Begin
1428 Select 'Y'
1429 Into l_exists
1430 From pa_budget_versions a
1431 Where project_structure_version_id = l_wbs_struct_version_id
1432 And wp_version_flag = 'Y'
1433 And exists (select 'x' from pa_budget_versions b where b.budget_version_id = p_source_version_id and b.wp_version_flag = 'Y') ;
1434
1435 IF P_PA_DEBUG_MODE = 'Y' THEN
1436 pa_debug.g_err_stage:='proj sv id = ' || l_wbs_struct_version_id;
1437 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1438 pa_debug.g_err_stage:='calling module = ' || p_calling_module;
1439 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1440 pa_debug.g_err_stage:='copy mode = ' || p_copy_mode;
1441 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1442 pa_debug.g_err_stage:='source version id = ' || p_source_version_id;
1443 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1444 pa_debug.g_err_stage:='source project id / target project id = ' || l_source_project_id || ' / ' || l_target_project_id;
1445 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1446 END IF;
1447 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
1448 p_msg_name => 'DUPLICATE_WP_BEING_CREATED');
1449 IF P_PA_DEBUG_MODE = 'Y' THEN
1450 pa_debug.g_err_stage:='Invalid Arguments Passed';
1451 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1452 END IF;
1453 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1454 Exception
1455 When No_Data_Found Then
1456 Null;
1457 End;
1458
1459 -- Insert a new row in pa_budget_versions
1460
1461 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
1462
1463 INSERT INTO PA_BUDGET_VERSIONS (
1464 budget_version_id
1465 ,project_id
1466 ,budget_type_code
1467 ,version_number
1468 ,budget_status_code
1469 ,last_update_date
1470 ,last_updated_by
1471 ,creation_date
1472 ,created_by
1473 ,last_update_login
1474 ,current_flag
1475 ,original_flag
1476 ,current_original_flag
1477 ,resource_accumulated_flag
1478 ,resource_list_id
1479 ,version_name
1480 ,budget_entry_method_code
1481 ,baselined_by_person_id
1482 ,baselined_date
1483 ,change_reason_code
1484 ,labor_quantity
1485 ,labor_unit_of_measure
1486 ,raw_cost
1487 ,burdened_cost
1488 ,revenue
1489 ,description
1490 ,attribute_category
1491 ,attribute1
1492 ,attribute2
1493 ,attribute3
1494 ,attribute4
1495 ,attribute5
1496 ,attribute6
1497 ,attribute7
1498 ,attribute8
1499 ,attribute9
1500 ,attribute10
1501 ,attribute11
1502 ,attribute12
1503 ,attribute13
1504 ,attribute14
1505 ,attribute15
1506 ,first_budget_period
1507 ,pm_product_code
1508 ,pm_budget_reference
1509 ,wf_status_code
1510 ,adw_notify_flag
1511 ,prc_generated_flag
1512 ,plan_run_date
1513 ,plan_processing_code
1514 ,period_profile_id
1515 ,fin_plan_type_id
1516 ,parent_plan_version_id
1517 ,project_structure_version_id
1518 ,current_working_flag
1519 ,total_borrowed_revenue
1520 ,total_revenue_adj
1521 ,total_lent_resource_cost
1522 ,total_cost_adj
1523 ,total_unassigned_time_cost
1524 ,total_utilization_percent
1525 ,total_utilization_hours
1526 ,total_utilization_adj
1527 ,total_capacity
1528 ,total_head_count
1529 ,total_head_count_adj
1530 ,version_type
1531 ,total_tp_cost_in
1532 ,total_tp_cost_out
1533 ,total_tp_revenue_in
1534 ,total_tp_revenue_out
1535 ,record_version_number
1536 ,request_id
1537 ,total_project_raw_cost
1538 ,total_project_burdened_cost
1539 ,total_project_revenue
1540 ,locked_by_person_id
1541 ,approved_cost_plan_type_flag
1542 ,approved_rev_plan_type_flag
1543 ,process_update_wbs_flag
1544 ,object_type_code
1545 ,object_id
1546 ,primary_cost_forecast_flag
1547 ,primary_rev_forecast_flag
1548 ,rev_partially_impl_flag
1549 ,equipment_quantity
1550 ,pji_summarized_flag
1551 ,wp_version_flag
1552 ,current_planning_period
1553 ,period_mask_id
1554 ,last_amt_gen_date
1555 ,actual_amts_thru_period
1556 ,ci_id -- Raja FP M 06 JUl 04 bug 3677924
1557 ,etc_start_date -- Bug 3763322
1558 )
1559 SELECT px_target_version_id
1560 ,l_target_project_id
1561 ,pbv.budget_type_code
1562 ,l_version_number --local_variable
1563 ,l_budget_status_code --local_variable
1564 ,sysdate
1565 ,fnd_global.user_id
1566 ,sysdate
1567 ,fnd_global.user_id
1568 ,fnd_global.login_id
1569 ,l_current_flag --local_variable
1570 ,DECODE(p_copy_mode, PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING ,'N',
1571 DECODE (l_version_number,1,'Y','N')) --original_flag
1572 ,DECODE(p_copy_mode, PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING ,'N',
1573 DECODE (l_version_number,1,'Y','N')) --current_original_flag
1574 ,'N' --resource_accumulated_flag
1575 ,pbv.resource_list_id
1576 ,SUBSTR(l_version_name,1,60) --local_variable
1577 ,pbv.budget_entry_method_code
1578 ,l_baselined_by_person_id --local_variable
1579 ,l_baselined_date --local_variable
1580 ,pbv.change_reason_code
1581 ,pbv.labor_quantity
1582 ,pbv.labor_unit_of_measure
1583 ,DECODE(l_adj_percentage, 0, pbv.raw_cost, NULL)
1584 ,DECODE(l_adj_percentage, 0, pbv.burdened_cost, NULL)
1585 ,DECODE(l_adj_percentage, 0, pbv.revenue, NULL)
1586 ,pbv.description
1587 ,pbv.attribute_category
1588 ,pbv.attribute1
1589 ,pbv.attribute2
1590 ,pbv.attribute3
1591 ,pbv.attribute4
1592 ,pbv.attribute5
1593 ,pbv.attribute6
1594 ,pbv.attribute7
1595 ,pbv.attribute8
1596 ,pbv.attribute9
1597 ,pbv.attribute10
1598 ,pbv.attribute11
1599 ,pbv.attribute12
1600 ,pbv.attribute13
1601 ,pbv.attribute14
1602 ,pbv.attribute15
1603 ,pbv.first_budget_period
1604 ,pbv.pm_product_code
1605 ,pbv.pm_budget_reference
1606 ,NULL --Bug 5532326 : wf_status_code is not copied
1607 ,pbv.adw_notify_flag
1608 ,NULL --pbv.prc_generated_flag --Bug 5099353
1609 ,pbv.plan_run_date
1610 ,NULL -- bug 3079891, 01-AUG-03, jwhite: replaced pbv.plan_processing_code
1611 ,period_profile_id
1612 ,pbv.fin_plan_type_id
1613 ,pbv.parent_plan_version_id
1614 ,nvl(l_wbs_struct_version_id,project_structure_version_id) -- Raja nvl should be removed post april 07
1615 ,l_current_working_flag --local_variable
1616 ,pbv.total_borrowed_revenue
1617 ,pbv.total_revenue_adj
1618 ,pbv.total_lent_resource_cost
1619 ,pbv.total_cost_adj
1620 ,pbv.total_unassigned_time_cost
1621 ,pbv.total_utilization_percent
1622 ,pbv.total_utilization_hours
1623 ,pbv.total_utilization_adj
1624 ,pbv.total_capacity
1625 ,pbv.total_head_count
1626 ,pbv.total_head_count_adj
1627 ,pbv.version_type
1628 ,pbv.total_tp_cost_in
1629 ,pbv.total_tp_cost_out
1630 ,pbv.total_tp_revenue_in
1631 ,pbv.total_tp_revenue_out
1632 ,1 --record_version_number
1633 ,NULL -- bug 3079891, 01-AUG-03, jwhite: replaced fnd_global.conc_request_id
1634 ,DECODE(l_adj_percentage, 0,
1635 pbv.total_project_raw_cost, NULL)
1636 ,DECODE(l_adj_percentage, 0,
1637 pbv.total_project_burdened_cost, NULL)
1638 ,DECODE(l_adj_percentage, 0,
1639 pbv.total_project_revenue, NULL)
1640 ,NULL --locked_by_person_id
1641 ,approved_cost_plan_type_flag
1642 ,approved_rev_plan_type_flag
1643 ,l_refresh_required_flag
1644 ,pbv.object_type_code
1645 ,l_target_project_id -- object_id bug 3594111
1646 ,pbv.primary_cost_forecast_flag
1647 ,pbv.primary_rev_forecast_flag
1648 ,pbv.rev_partially_impl_flag
1649 ,pbv.equipment_quantity
1650 ,'N'--This should always be N as the PJI API will be called later and that API will look at this flag
1651 --Summarization will happen only if this flag has 'N' as value.
1652 ,pbv.wp_version_flag
1653 ,l_target_cur_planning_period -- 3/30/2004 FP M Phase II Dev Changes
1654 ,pbv.period_mask_id
1655 ,pbv.last_amt_gen_date --Bug 4228859
1656 ,decode(p_copy_actuals_flag,'N',null,pbv.actual_amts_thru_period) -- Bug 3927244
1657 ,l_ci_id -- Raja FP M 06 JUl 04 bug 3677924
1658 ,decode(p_copy_actuals_flag,'N',null,pbv.etc_start_date) -- Bug 3927244
1659 FROM PA_BUDGET_VERSIONS pbv
1660 WHERE pbv.budget_version_id = p_source_version_id;
1661
1662 -- End, jwhite, 26-JUN-2003: Plannable Task Effort --------------------------------
1663
1664 -- End: Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
1665
1666
1667 ELSE --if target_version_id is passed then we update the version
1668
1669 IF p_calling_module = PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN THEN
1670
1671 --To decide what amounts are to be copied from source to target
1672 --version set local flags using target fin plan preference code
1673
1674
1675 IF P_PA_DEBUG_MODE = 'Y' THEN
1676 pa_debug.g_err_stage := 'Get values into local flags';
1677 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1678 END IF;
1679
1680
1681 /* UT Fix : decoded G_PREF_COST_AND_REV_SAME as Y for revenue_flag */
1682
1683 SELECT DECODE(fin_plan_preference_code,
1684 PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY, 'Y',
1685 PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY, 'N',
1686 PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME, 'Y') --cost_flag
1687 ,DECODE(fin_plan_preference_code,
1688 PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY, 'N',
1689 PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY, 'Y',
1690 PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME, 'Y') --revenue_flag
1691 INTO l_cost_flag
1692 ,l_revenue_flag
1693 FROM pa_proj_fp_options
1694 WHERE fin_plan_version_id = px_target_version_id;
1695
1696 --Set the cost and revenue flags to 'N' if adj percentage is nonzero.
1697
1698 IF l_adj_percentage <> 0 THEN
1699
1700 l_cost_flag := 'N';
1701 l_revenue_flag := 'N';
1702
1703 END IF;
1704
1705 --Update target version using source version values
1706
1707
1708 IF P_PA_DEBUG_MODE = 'Y' THEN
1709 pa_debug.g_err_stage := 'Updating target version';
1710 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1711 END IF;
1712
1713 OPEN l_bv_csr;
1714
1715
1716 IF P_PA_DEBUG_MODE = 'Y' THEN
1717 pa_debug.g_err_stage := 'l_bv_csr is opened';
1718 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1719 END IF;
1720
1721 FETCH l_bv_csr INTO l_bv_rec;
1722
1723 -- Bug 3927244: Actuals need to be copied from budget to budget or forecast to forecast
1724 -- within the same project for FINPLAN versions
1725
1726 OPEN get_plan_class_code_csr(p_source_version_id);
1727 FETCH get_plan_class_code_csr
1728 INTO l_src_plan_class_code,l_source_project_id;
1729 CLOSE get_plan_class_code_csr;
1730
1731 OPEN get_plan_class_code_csr(px_target_version_id);
1732 FETCH get_plan_class_code_csr
1733 INTO l_trg_plan_class_code,l_target_project_id;
1734 CLOSE get_plan_class_code_csr;
1735
1736 l_source_project_id := NVL(p_source_project_id,l_source_project_id);
1737 l_target_project_id := NVL(p_target_project_id,l_target_project_id);
1738
1739 -- End: Bug 3927244
1740
1741 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
1742
1743
1744 IF l_bv_csr%FOUND THEN
1745
1746 UPDATE pa_budget_versions
1747 SET resource_list_id = l_bv_rec.resource_list_id /* Added for bug# 2757847 */
1748 ,labor_quantity = l_bv_rec.labor_quantity /* Added for bug# 2645579 */
1749 ,raw_cost = DECODE(l_adj_percentage, 0, DECODE(l_cost_flag,'Y',l_bv_rec.raw_cost,NULL), NULL)
1750 ,burdened_cost = DECODE(l_adj_percentage, 0, DECODE(l_cost_flag,'Y',l_bv_rec.burdened_cost,NULL), NULL)
1751 ,revenue = DECODE(l_adj_percentage, 0, DECODE(l_revenue_flag,'Y',l_bv_rec.revenue,NULL), NULL)
1752 ,pm_product_code = l_bv_rec.pm_product_code
1753 ,pm_budget_reference = l_bv_rec.pm_budget_reference
1754 -- Bug 5532326. This column should not be copied in copy flow
1755 --,wf_status_code = l_bv_rec.wf_status_code
1756 ,adw_notify_flag = l_bv_rec.adw_notify_flag
1757 ,prc_generated_flag = NULL --l_bv_rec.prc_generated_flag --Bug 5099353
1758 ,plan_run_date = l_bv_rec.plan_run_date
1759 ,plan_processing_code = NULL --l_bv_rec.plan_processing_code fix for bug 4463404
1760 ,total_borrowed_revenue = l_bv_rec.total_borrowed_revenue
1761 ,total_revenue_adj = l_bv_rec.total_revenue_adj
1762 ,total_lent_resource_cost = l_bv_rec.total_lent_resource_cost
1763 ,total_cost_adj = l_bv_rec.total_cost_adj
1764 ,total_unassigned_time_cost = l_bv_rec.total_unassigned_time_cost
1765 ,total_utilization_percent = l_bv_rec.total_utilization_percent
1766 ,total_utilization_hours = l_bv_rec.total_utilization_hours
1767 ,total_utilization_adj = l_bv_rec.total_utilization_adj
1768 ,total_capacity = l_bv_rec.total_capacity
1769 ,total_head_count = l_bv_rec.total_head_count
1770 ,total_head_count_adj = l_bv_rec.total_head_count_adj
1771 ,total_tp_cost_in = l_bv_rec.total_tp_cost_in
1772 ,total_tp_cost_out = l_bv_rec.total_tp_cost_out
1773 ,total_tp_revenue_in = l_bv_rec.total_tp_revenue_in
1774 ,total_tp_revenue_out = l_bv_rec.total_tp_revenue_out
1775 ,record_version_number = record_version_number + 1
1776 ,request_id = NULL --FND_GLOBAL.conc_request_id fix for bug 4463404
1777 ,total_project_raw_cost = DECODE(l_adj_percentage, 0, DECODE(l_cost_flag,'Y',l_bv_rec.total_project_raw_cost,NULL), NULL)
1778 ,total_project_burdened_cost = DECODE(l_adj_percentage, 0, DECODE(l_cost_flag,'Y',l_bv_rec.total_project_burdened_cost,NULL), NULL)
1779 ,total_project_revenue = DECODE(l_adj_percentage, 0, DECODE(l_revenue_flag,'Y',l_bv_rec.total_project_revenue,NULL), NULL)
1780 ,object_type_code = l_bv_rec.object_type_code
1781 ,object_id = l_bv_rec.object_id
1782 -- FP M Phase II ,primary_cost_forecast_flag = l_bv_rec.primary_cost_forecast_flag
1783 -- FP M Phase II ,primary_rev_forecast_flag = l_bv_rec.primary_rev_forecast_flag
1784 -- FP M Phase II ,rev_partially_impl_flag = l_bv_rec.rev_partially_impl_flag
1785 ,equipment_quantity = l_bv_rec.equipment_quantity
1786 ,pji_summarized_flag = l_bv_rec.pji_summarized_flag
1787 ,wp_version_flag = l_bv_rec.wp_version_flag
1788 ,current_planning_period = l_bv_rec.current_planning_period
1789 ,period_mask_id = l_bv_rec.period_mask_id
1790 -- Bug 3927244
1791 ,last_amt_gen_date = l_bv_rec.last_amt_gen_date --Bug 4228859
1792 ,actual_amts_thru_period = decode(p_copy_actuals_flag,'N',null,l_bv_rec.actual_amts_thru_period)
1793 ,etc_start_date = decode(p_copy_actuals_flag,'N',null,l_bv_rec.etc_start_date)
1794 -- End: Bug 3927244
1795 ,project_structure_version_id = l_bv_rec.project_structure_version_id
1796 WHERE budget_version_id = px_target_version_id;
1797
1798 -- END: Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
1799
1800
1801 END IF;
1802
1803 CLOSE l_bv_csr;
1804
1805
1806 IF P_PA_DEBUG_MODE = 'Y' THEN
1807 pa_debug.g_err_stage := 'l_bv_csr is closed';
1808 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1809 END IF;
1810
1811 END IF; -- p_calling_module
1812
1813 END IF;
1814 -- bug fix 2933695
1815 -- Copy attachments which are associated with the budget version
1816 fnd_attached_documents2_pkg.copy_attachments
1817 (X_from_entity_name => 'PA_BUDGET_VERSIONS',
1818 X_from_pk1_value => to_char(p_source_version_id),
1819 X_to_entity_name => 'PA_BUDGET_VERSIONS',
1820 X_to_pk1_value => px_target_version_id,
1821 X_created_by => FND_GLOBAL.USER_ID,
1822 X_last_update_login => FND_GLOBAL.LOGIN_ID,
1823 X_program_application_id => FND_GLOBAL.PROG_APPL_ID);
1824
1825
1826 IF P_PA_DEBUG_MODE = 'Y' THEN
1827 pa_debug.g_err_stage := 'Exiting copy_budget_version';
1828 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
1829 pa_debug.reset_err_stack;
1830 END IF;
1831
1832 EXCEPTION
1833
1834 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
1835 l_msg_count := FND_MSG_PUB.count_msg;
1836 IF l_msg_count = 1 THEN
1837 PA_INTERFACE_UTILS_PUB.get_messages
1838 (p_encoded => FND_API.G_TRUE
1839 ,p_msg_index => 1
1840 ,p_msg_count => l_msg_count
1841 ,p_msg_data => l_msg_data
1842 ,p_data => l_data
1843 ,p_msg_index_out => l_msg_index_out);
1844 x_msg_data := l_data;
1845 x_msg_count := l_msg_count;
1846 ELSE
1847 x_msg_count := l_msg_count;
1848 END IF;
1849 x_return_status := FND_API.G_RET_STS_ERROR;
1850
1851 IF P_PA_DEBUG_MODE = 'Y' THEN
1852 pa_debug.g_err_stage:='Invalid Arguments Passed';
1853 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1854 pa_debug.reset_err_stack;
1855 END IF;
1856 RAISE;
1857
1858 WHEN Others THEN
1859 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1860 x_msg_count := 1;
1861 x_msg_data := SQLERRM;
1862 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'PA_FP_COPY_FROM_PKG'
1863 ,p_procedure_name => 'COPY_BUDGET_VERSION');
1864
1865 IF P_PA_DEBUG_MODE = 'Y' THEN
1866 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
1867 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
1868 pa_debug.reset_err_stack;
1869 END IF;
1870
1871 RAISE;
1872
1873 END Copy_Budget_Version;
1874
1875
1876
1877 /*====================================================================================
1878 Bug 3354518 - FP M changes - This is an overloaded API. This API will be called
1879 from pa_fp_planning_transaction_pub.copy_planning_transactions.This API will be used
1880 to populate the global temporary table PA_FP_RA_MAP_TEMP which will be used for
1881 the creation of target resource assignment records.
1882
1883 New columns in pa_fp_ra_map_tmp that will be used for FP M are given below
1884 planning_start_Date -> planning_start_date for target resource assignment id
1885 planning_end_Date -> planning_end_date for target resource assignment id
1886 schedule_start_Date -> schedule_start_date for target resource assignment id .. For TA specifically..
1887 schedule_end_Date -> schedule_end_date for target resource assignment id .. For TA specifically..
1888 system_reference1 -> source element version id
1889 system_reference2 -> target element version id
1890 system_reference3 -> project assignment id for the target resoruce assignment id
1891 system_reference4 -> resource list member id for the target resoruce assignment id
1892
1893 p_src_ra_id_tbl -> The tbl containing the source ra ids which should be copied into the target
1894 p_src_elem_ver_id_tbl -> source element version ids which should be copied into the target
1895 p_targ_elem_ver_id_tbl -> target element version ids corresponding to the source element version ids
1896 p_targ_proj_assmt_id_tbl -> target project assignment ids corresponding to the source resource assignment ids
1897 p_targ_rlm_id_tbl -> target resource list member ids corresponding to the source resource assignment ids
1898
1899 Bug 3622134 May 12 2004 Raja
1900 When target element version id is 0 target task id should be
1901 initialised as 0. Select should not be fired
1902 Bug 3615617 - FP M IB2 changes - Raja
1903 For workplan context target rlm id would be passed for each source resource assignment
1904 =====================================================================================*/
1905 PROCEDURE create_res_task_maps(
1906 p_context IN VARCHAR2 --Can be WORKPLAN, BUDGET
1907 ,p_src_ra_id_tbl IN SYSTEM.PA_NUM_TBL_TYPE
1908 ,p_src_elem_ver_id_tbl IN SYSTEM.PA_NUM_TBL_TYPE
1909 ,p_targ_elem_ver_id_tbl IN SYSTEM.PA_NUM_TBL_TYPE
1910 ,p_targ_proj_assmt_id_tbl IN SYSTEM.PA_NUM_TBL_TYPE
1911 ,p_targ_rlm_id_tbl IN SYSTEM.PA_NUM_TBL_TYPE -- Bug 3615617
1912 ,p_planning_start_date_tbl IN SYSTEM.PA_DATE_TBL_TYPE
1913 ,p_planning_end_date_tbl IN SYSTEM.PA_DATE_TBL_TYPE
1914 ,p_schedule_start_date_tbl IN SYSTEM.PA_DATE_TBL_TYPE
1915 ,p_schedule_end_date_tbl IN SYSTEM.PA_DATE_TBL_TYPE
1916 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
1917 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
1918 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
1919 IS
1920 i NUMBER;
1921 l_targ_proj_element_id pa_proj_elements.proj_element_id%TYPE;
1922 --Start of variables used for debugging
1923 l_return_status VARCHAR2(1);
1924 l_msg_count NUMBER := 0;
1925 l_msg_data VARCHAR2(2000);
1926 l_data VARCHAR2(2000);
1927 l_msg_index_out NUMBER;
1928 l_debug_mode VARCHAR2(30);
1929 l_debug_level3 CONSTANT NUMBER :=3;
1930 l_debug_level5 CONSTANT NUMBER :=5;
1931 l_module_name VARCHAR2(200) := g_module_name || '.create_res_task_maps';
1932 l_schedule_start_date_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
1933 l_schedule_end_date_tbl SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
1934 --End of variables used for debugging
1935 --Bug 4201936
1936 l_temp VARCHAR2(15);
1937 l_src_elem_ver_id pa_proj_element_versions.element_version_id%TYPE;
1938 l_targ_elem_ver_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
1939 TYPE src_elem_targ_elem_map_tbl_typ IS TABLE OF NUMBER INDEX BY VARCHAR2(15);
1940 l_src_elem_targ_elem_map_tbl src_elem_targ_elem_map_tbl_typ;
1941
1942 BEGIN
1943
1944 x_msg_count := 0;
1945 x_return_status := FND_API.G_RET_STS_SUCCESS;
1946
1947 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
1948 l_debug_mode := NVL(l_debug_mode, 'Y');
1949
1950 -- Set curr function
1951 IF l_debug_mode = 'Y' THEN
1952 pa_debug.set_curr_function(
1953 p_function =>'pa_fp_copy_from_pkg.create_res_task_maps'
1954 ,p_debug_mode => l_debug_mode );
1955
1956 -- Check for business rules violations
1957 pa_debug.g_err_stage:='Validating input parameters';
1958 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
1959 END IF;
1960
1961 IF p_context IS NULL THEN
1962
1963 IF l_debug_mode = 'Y' THEN
1964 pa_debug.g_err_stage:='p_context is '||p_context;
1965 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
1966 END IF;
1967
1968 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
1969 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
1970
1971 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1972
1973 END IF;
1974
1975 --If the no of elements in source and target element version id tbls are not same, throw error
1976 IF p_src_elem_ver_id_tbl.count <> p_targ_elem_ver_id_tbl.count THEN
1977
1978 IF l_debug_mode = 'Y' THEN
1979 pa_debug.g_err_stage:='The count in source elem ver id tbl and targ elem ver id tbl is not equal';
1980 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
1981 END IF;
1982 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
1983 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
1984
1985 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1986 END IF;
1987
1988 --If the no of elements in source ra id and target project assignment id tbls are not same, throw error
1989 IF p_targ_proj_assmt_id_tbl.count <> p_src_ra_id_tbl.count OR
1990 p_targ_rlm_id_tbl.count <> p_src_ra_id_tbl.count OR -- Bug 3615617
1991 p_planning_start_date_tbl.count <> p_src_ra_id_tbl.count OR
1992 p_planning_end_date_tbl.count <> p_src_ra_id_tbl.count OR
1993 (p_schedule_start_date_tbl.count <> 0 AND
1994 p_schedule_start_date_tbl.count <> p_src_ra_id_tbl.count) OR
1995 p_schedule_start_date_tbl.count <> p_schedule_end_date_tbl.count THEN
1996
1997 IF l_debug_mode = 'Y' THEN
1998 pa_debug.g_err_stage:='The count in source ra id tbl and targ proj assmt is not equal';
1999 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2000 END IF;
2001 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
2002 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
2003
2004 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2005 END IF;
2006
2007 IF p_src_ra_id_tbl.count=0 THEN
2008
2009 IF l_debug_mode = 'Y' THEN
2010 pa_debug.g_err_stage:='The source resource assignment id table is emtpy. Returning';
2011 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2012 pa_debug.reset_curr_function;
2013 END IF;
2014 RETURN;
2015 END IF;
2016
2017 IF p_schedule_start_date_tbl.count = 0 THEN
2018 l_schedule_start_date_tbl := p_planning_start_date_tbl;
2019 l_schedule_end_date_tbl := p_planning_end_date_tbl;
2020 ELSE
2021 l_schedule_start_date_tbl := p_schedule_start_date_tbl;
2022 l_schedule_end_date_tbl := p_schedule_end_date_tbl;
2023 END IF;
2024
2025 IF l_debug_mode = 'Y' THEN
2026 pa_debug.g_err_stage:='About to create the mapping between source and target element version ids';
2027 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2028 END IF;
2029
2030 DELETE FROM pa_fp_ra_map_tmp;
2031
2032
2033 --When p_context is BUDGET then the copy will not happen accorss projects. The task id in the source and
2034 --target would be same for the corresponding resource assignments. Hence the FOR loop which creates the tbl
2035 --for mapping the task ids need not be executed.
2036
2037 --Create the mapping between the source element version id and target element version id
2038 --,target proj element id and target project assignment id
2039
2040 --Bug 4201936. Prepare tbls for source/target element version id both having same no. of elements as in
2041 --p_src_ra_id_tbl so that they can be used below for BULK insert
2042 IF NVL(p_context,'-99')<>'BUDGET' THEN
2043
2044 l_targ_elem_ver_id_tbl.extend(p_src_ra_id_tbl.count);
2045 FOR i IN p_src_ra_id_tbl.first..p_src_ra_id_tbl.last LOOP
2046
2047 SELECT wbs_element_version_id
2048 INTO l_src_elem_ver_id
2049 FROM pa_resource_assignments
2050 WHERE resource_assignment_id=p_src_ra_id_tbl(i);
2051
2052 l_temp := TO_CHAR(l_src_elem_ver_id);
2053 IF l_src_elem_targ_elem_map_tbl.EXISTS(l_temp) THEN
2054
2055 l_targ_elem_ver_id_tbl(i):=l_src_elem_targ_elem_map_tbl(l_temp);
2056
2057 ELSE
2058
2059 FOR j IN p_src_elem_ver_id_tbl.first..p_src_elem_ver_id_tbl.last LOOP
2060
2061 IF l_src_elem_ver_id=p_src_elem_ver_id_tbl(j) THEN
2062
2063 l_targ_elem_ver_id_tbl(i):=p_targ_elem_ver_id_tbl(j);
2064 l_src_elem_targ_elem_map_tbl(l_temp):=p_targ_elem_ver_id_tbl(j);
2065 EXIT;
2066
2067 END IF;
2068
2069 END LOOP;--FOR j IN p_src_elem_ver_id_tbl.first..p_src_elem_ver_id_tbl.last
2070
2071 END IF;
2072
2073 END LOOP;--FOR i IN p_src_ra_id_tbl.first..p_src_ra_id_tbl.last LOOP
2074
2075 END IF;--IF NVL(p_context,'-99')<>'BUDGET' THEN
2076
2077 IF l_debug_mode = 'Y' THEN
2078 pa_debug.g_err_stage:='About to bulk insert into pa_fp_ra_map_tmp';
2079 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2080 END IF;
2081
2082 --Bulk insert into the pa_fp_ra_map_tmp table
2083
2084 -- Bug 4187294: performance fix-splitting the below insert into 2 statments
2085 -- depending upon the context to avoid inner decode statements
2086
2087 IF p_context = 'BUDGET' THEN
2088 FORALL i in p_src_ra_id_tbl.first..p_src_ra_id_tbl.last
2089 INSERT INTO pa_fp_ra_map_tmp
2090 ( source_res_assignment_id
2091 ,target_res_assignment_id
2092 ,source_task_id
2093 ,target_task_id
2094 ,system_reference1
2095 ,system_reference2
2096 ,system_reference3
2097 ,planning_start_date
2098 ,planning_end_date
2099 ,schedule_start_date
2100 ,schedule_end_date
2101 ,system_reference4 -- Bug 3615617
2102 )
2103 SELECT pra.resource_assignment_id
2104 ,pa_resource_assignments_s.nextval
2105 ,pra.task_id
2106 ,pra.task_id
2107 ,NULL
2108 ,NULL
2109 ,p_targ_proj_assmt_id_tbl(i)
2110 ,p_planning_start_date_tbl(i)
2111 ,p_planning_end_date_tbl(i)
2112 ,l_schedule_start_date_tbl(i)
2113 ,l_schedule_end_date_tbl(i)
2114 ,p_targ_rlm_id_tbl(i) -- Bug 3615617
2115 FROM pa_resource_assignments pra
2116 WHERE pra.resource_assignment_id = p_src_ra_id_tbl(i);
2117 ELSE
2118
2119 --Bug 4187294: Removed the calls to get_mapped_id.Used the pl/sql tbl l_targ_elem_ver_id_tbl
2120 --derived above.
2121 FORALL i in p_src_ra_id_tbl.first..p_src_ra_id_tbl.last
2122 INSERT INTO pa_fp_ra_map_tmp
2123 ( source_res_assignment_id
2124 ,target_res_assignment_id
2125 ,source_task_id
2126 ,target_task_id
2127 ,system_reference1
2128 ,system_reference2
2129 ,system_reference3
2130 ,planning_start_date
2131 ,planning_end_date
2132 ,schedule_start_date
2133 ,schedule_end_date
2134 ,system_reference4 -- Bug 3615617
2135 )
2136 SELECT pra.resource_assignment_id
2137 ,pa_resource_assignments_s.nextval
2138 ,pra.task_id
2139 ,pelm.proj_element_id
2140 ,pra.wbs_element_version_id
2141 ,l_targ_elem_ver_id_tbl(i)
2142 ,p_targ_proj_assmt_id_tbl(i)
2143 ,p_planning_start_date_tbl(i)
2144 ,p_planning_end_date_tbl(i)
2145 ,l_schedule_start_date_tbl(i)
2146 ,l_schedule_end_date_tbl(i)
2147 ,p_targ_rlm_id_tbl(i) -- Bug 3615617
2148 FROM pa_resource_assignments pra
2149 ,pa_proj_element_versions pelm
2150 WHERE pra.resource_assignment_id = p_src_ra_id_tbl(i)
2151 AND pelm.element_version_id=l_targ_elem_ver_id_tbl(i);
2152 END IF; -- p_context
2153
2154 IF l_debug_mode = 'Y' THEN
2155 pa_debug.g_err_stage:='Exiting create_res_task_maps';
2156 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2157 pa_debug.reset_curr_function;
2158 END IF;
2159 EXCEPTION
2160
2161 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
2162 l_msg_count := FND_MSG_PUB.count_msg;
2163 IF l_msg_count = 1 THEN
2164 PA_INTERFACE_UTILS_PUB.get_messages
2165 (p_encoded => FND_API.G_TRUE
2166 ,p_msg_index => 1
2167 ,p_msg_count => l_msg_count
2168 ,p_msg_data => l_msg_data
2169 ,p_data => l_data
2170 ,p_msg_index_out => l_msg_index_out);
2171
2172 x_msg_data := l_data;
2173 x_msg_count := l_msg_count;
2174 ELSE
2175 x_msg_count := l_msg_count;
2176 END IF;
2177
2178 x_return_status := FND_API.G_RET_STS_ERROR;
2179
2180 IF l_debug_mode = 'Y' THEN
2181 pa_debug.g_err_stage:='Invalid Arguments Passed Or called api raised an error';
2182 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
2183 -- reset curr function
2184 pa_debug.reset_curr_function();
2185 END IF;
2186 RETURN;
2187
2188 WHEN OTHERS THEN
2189 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2190 x_msg_count := 1;
2191 x_msg_data := SQLERRM;
2192
2193 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'pa_fp_copy_from_pkg'
2194 ,p_procedure_name => 'create_res_task_maps');
2195
2196 IF l_debug_mode = 'Y' THEN
2197 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
2198 pa_debug.write( l_module_name,pa_debug.g_err_stage,5);
2199 -- reset curr function
2200 pa_debug.Reset_Curr_Function();
2201 END IF;
2202 RAISE;
2203
2204 END create_res_task_maps;
2205
2206
2207 /*=========================================================================
2208 This api will insert resource_assignments for the target_version based
2209 upon the PA_FP_RA_MAP_TABLE which contains both source_res_assignment_id,
2210 its parent and the corresponding target_res_assignment_id.This api will
2211 populate appropriate amounts based upon the target version plan
2212 preference code.If adjustment percentage is not zero then all amounts
2213 will be copied as null and will be populated by the rollup api
2214
2215
2216 --r11.5 FP.M Developement ----------------------------------
2217 --
2218 --08-JAN-04 jwhite - Bug 3362316
2219 -- Rewrote Copy_Resource_Assignments
2220 -- for new FP.M columns.
2221 --
2222
2223 3/28/2004 Raja FP M Phase II Dev Effort Copy Project Impact
2224 If resource list is a project specific resource list, target resource
2225 list member id should be derived using resource alias and target project id
2226
2227 5/13/2004 Raja FP M IB2 changes Bug 3615617
2228 Logic to derive target resource list memer id has been moved to
2229 create_res_task_maps api. Target resource list member id is part
2230 of pa_fp_ra_map_tmp table. System_reference4 column has the value.
2231
2232 --Added parameter p_rbs_map_diff_flag for Bug 3974569. This parameter can be passed as Y if the RBS mapping of
2233 --the target resource assignments is different from that of the source resource assignments.If this is passed as Y then
2234 ---->1.copy resource assignments will look at pa_rbs_plans_out_tmp table for rbs_element_id and txn_accum_header_id
2235 ---->of target resource assignments and it assumes that source_id in pa_rbs_plans_out_tmp corresponds to the
2236 ----> resource_assignment_id in the source budget version.
2237
2238 --Bug 3948128. Included scheduled_delay in the list of columns that would get copied.
2239 --Bug 4200168: Changed the logic so that the copy is not based on pa_fp_ra_map_tmp when
2240 --the API is called for copying resource assignments between budget versions
2241 ===========================================================================*/
2242
2243 PROCEDURE Copy_Resource_Assignments(
2244 p_source_plan_version_id IN NUMBER
2245 ,p_target_plan_version_id IN NUMBER
2246 ,p_adj_percentage IN NUMBER
2247 ,p_rbs_map_diff_flag IN VARCHAR2 DEFAULT 'N'
2248 ,p_calling_context IN VARCHAR2 DEFAULT NULL -- Bug 4065314
2249 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
2250 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
2251 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
2252 AS
2253 l_msg_count NUMBER :=0;
2254 l_data VARCHAR2(2000);
2255 l_msg_data VARCHAR2(2000);
2256 l_error_msg_code VARCHAR2(2000);
2257 l_msg_index_out NUMBER;
2258 l_return_status VARCHAR2(2000);
2259 l_debug_mode VARCHAR2(30);
2260
2261 l_adj_percentage NUMBER ;
2262 l_target_project_id pa_projects.project_id%TYPE;
2263 l_cost_flag pa_fin_plan_amount_sets.raw_cost_flag%TYPE;
2264 l_revenue_flag pa_fin_plan_amount_sets.revenue_flag%TYPE;
2265
2266 l_tmp NUMBER;
2267 l_source_project_id pa_projects_all.project_id%TYPE;
2268 l_fin_plan_level_code pa_proj_fp_options.cost_fin_plan_level_code%TYPE;
2269 l_control_flag pa_resource_lists_all_bg.control_flag%TYPE;
2270 l_resource_list_id pa_proj_fp_options.cost_resource_list_id%TYPE;
2271
2272 l_project_org pa_projects_all.carrying_out_organization_id%TYPE; -- bug 6161031
2273
2274
2275 BEGIN
2276 x_msg_count := 0;
2277 x_return_status := FND_API.G_RET_STS_SUCCESS;
2278 IF P_PA_DEBUG_MODE = 'Y' THEN
2279 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Resource_Assignments');
2280 END IF;
2281 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
2282 l_debug_mode := NVL(l_debug_mode, 'Y');
2283 IF P_PA_DEBUG_MODE = 'Y' THEN
2284 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
2285 END IF;
2286
2287
2288 /*
2289 * Check if source_verion_id, target_version_id are NULL, if so throw
2290 * an error message
2291 */
2292
2293 IF P_PA_DEBUG_MODE = 'Y' THEN
2294 pa_debug.g_err_stage := 'Checking for valid parameters:';
2295 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2296 END IF;
2297
2298 IF (p_source_plan_version_id IS NULL) OR
2299 (p_target_plan_version_id IS NULL)
2300 THEN
2301
2302 IF P_PA_DEBUG_MODE = 'Y' THEN
2303 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
2304 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
2305
2306 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
2307 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
2308 END IF;
2309
2310 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
2311 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
2312 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2313 END IF;
2314
2315 IF P_PA_DEBUG_MODE = 'Y' THEN
2316 pa_debug.g_err_stage := 'Parameter validation complete';
2317 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2318 END IF;
2319
2320 --If adj_percentage is null make it zero
2321
2322 l_adj_percentage := NVL(p_adj_percentage,0);
2323
2324 --Fetching the flags of target version using fin_plan_prefernce_code
2325
2326 IF P_PA_DEBUG_MODE = 'Y' THEN
2327 pa_debug.g_err_stage:='Fetching the raw_cost,burdened_cost and revenue flags of target_version';
2328 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2329 END IF;
2330
2331 SELECT DECODE(pfot.fin_plan_preference_code
2332 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY ,'Y'
2333 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME , 'Y','N') --cost_flag
2334 ,DECODE(pfot.fin_plan_preference_code
2335 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY ,'Y'
2336 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME ,'Y','N')--revenue_flag
2337 ,pfot.project_id
2338 ,pfos.project_id
2339 ,nvl(pfos.cost_fin_plan_level_code, nvl(pfos.revenue_fin_plan_level_code,pfos.all_fin_plan_level_code))
2340 ,nvl(pfos.cost_resource_list_id, nvl(pfos.revenue_resource_list_id,pfos.all_resource_list_id))
2341 ,nvl(rl.control_flag,'N')
2342 INTO l_cost_flag
2343 ,l_revenue_flag
2344 ,l_target_project_id
2345 ,l_source_project_id
2346 ,l_fin_plan_level_code
2347 ,l_resource_list_id
2348 ,l_control_flag
2349 FROM pa_proj_fp_options pfot,--target
2350 pa_proj_fp_options pfos,--source
2351 pa_resource_lists_all_bg rl
2352 WHERE pfot.fin_plan_version_id=p_target_plan_version_id
2353 AND pfos.fin_plan_version_id=p_source_plan_version_id
2354 AND rl.resource_list_id=nvl(pfot.cost_resource_list_id, nvl(pfot.revenue_resource_list_id,pfot.all_resource_list_id));
2355
2356 /*
2357 IF P_PA_DEBUG_MODE = 'Y' THEN
2358 pa_debug.g_err_stage:='l_cost_flag ='||l_cost_flag;
2359 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2360 pa_debug.g_err_stage:='l_revenue_flag ='||l_revenue_flag;
2361 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2362 pa_debug.g_err_stage:='l_target_project_id ='||l_target_project_id;
2363 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2364 END IF;
2365 */
2366 --Inserting records into pa_resource_assignments using pa_fp_ra_map_tmp
2367
2368 IF P_PA_DEBUG_MODE = 'Y' THEN
2369 pa_debug.g_err_stage:='Copying the source version records as target version records';
2370 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2371 END IF;
2372 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
2373
2374 --Bug 3974569. Need not have pa_rbs_plans_out_tmp in the FROM clause if the parameter is N
2375 IF P_PA_DEBUG_MODE = 'Y' THEN
2376 pa_debug.g_err_stage:='p_rbs_map_diff_flag '||p_rbs_map_diff_flag;
2377 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2378 END IF;
2379
2380 IF (p_calling_context='WORKPLAN' AND nvl(p_rbs_map_diff_flag,'N') ='N') OR
2381 p_calling_context='CI' THEN
2382
2383 IF P_PA_DEBUG_MODE = 'Y' THEN
2384 pa_debug.g_err_stage:='Using the First RA Insert';
2385 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2386 END IF;
2387
2388 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
2389 resource_assignment_id
2390 ,budget_version_id
2391 ,project_id
2392 ,task_id
2393 ,resource_list_member_id
2394 ,last_update_date
2395 ,last_updated_by
2396 ,creation_date
2397 ,created_by
2398 ,last_update_login
2399 ,unit_of_measure
2400 ,track_as_labor_flag
2401 ,total_plan_revenue
2402 ,total_plan_raw_cost
2403 ,total_plan_burdened_cost
2404 ,total_plan_quantity
2405 ,resource_assignment_type
2406 ,total_project_raw_cost
2407 ,total_project_burdened_cost
2408 ,total_project_revenue
2409 ,standard_bill_rate
2410 ,average_bill_rate
2411 ,average_cost_rate
2412 ,project_assignment_id
2413 ,plan_error_code
2414 ,average_discount_percentage
2415 ,total_borrowed_revenue
2416 ,total_revenue_adj
2417 ,total_lent_resource_cost
2418 ,total_cost_adj
2419 ,total_unassigned_time_cost
2420 ,total_utilization_percent
2421 ,total_utilization_hours
2422 ,total_utilization_adj
2423 ,total_capacity
2424 ,total_head_count
2425 ,total_head_count_adj
2426 ,total_tp_revenue_in
2427 ,total_tp_revenue_out
2428 ,total_tp_cost_in
2429 ,total_tp_cost_out
2430 ,parent_assignment_id
2431 ,wbs_element_version_id
2432 ,rbs_element_id
2433 ,planning_start_date
2434 ,planning_end_date
2435 ,schedule_start_date
2436 ,schedule_end_date
2437 ,spread_curve_id
2438 ,etc_method_code
2439 ,res_type_code
2440 ,attribute_category
2441 ,attribute1
2442 ,attribute2
2443 ,attribute3
2444 ,attribute4
2445 ,attribute5
2446 ,attribute6
2447 ,attribute7
2448 ,attribute8
2449 ,attribute9
2450 ,attribute10
2451 ,attribute11
2452 ,attribute12
2453 ,attribute13
2454 ,attribute14
2455 ,attribute15
2456 ,attribute16
2457 ,attribute17
2458 ,attribute18
2459 ,attribute19
2460 ,attribute20
2461 ,attribute21
2462 ,attribute22
2463 ,attribute23
2464 ,attribute24
2465 ,attribute25
2466 ,attribute26
2467 ,attribute27
2468 ,attribute28
2469 ,attribute29
2470 ,attribute30
2471 ,fc_res_type_code
2472 ,resource_class_code
2473 ,organization_id
2474 ,job_id
2475 ,person_id
2476 ,expenditure_type
2477 ,expenditure_category
2478 ,revenue_category_code
2479 ,event_type
2480 ,supplier_id
2481 ,non_labor_resource
2482 ,bom_resource_id
2483 ,inventory_item_id
2484 ,item_category_id
2485 ,record_version_number
2486 ,transaction_source_code
2487 ,mfc_cost_type_id
2488 ,procure_resource_flag
2489 ,assignment_description
2490 ,incurred_by_res_flag
2491 ,rate_job_id
2492 ,rate_expenditure_type
2493 ,ta_display_flag
2494 ,sp_fixed_date
2495 ,person_type_code
2496 ,rate_based_flag
2497 ,resource_rate_based_flag --IPM Arch Enhancements Bug 4865563
2498 ,use_task_schedule_flag
2499 ,rate_exp_func_curr_code
2500 ,rate_expenditure_org_id
2501 ,incur_by_res_class_code
2502 ,incur_by_role_id
2503 ,project_role_id
2504 ,resource_class_flag
2505 ,named_role
2506 ,txn_accum_header_id
2507 ,scheduled_delay --For Bug 3948128
2508 )
2509 SELECT /*+ ORDERED USE_NL(PFRMT,PRA) INDEX(PRA PA_RESOURCE_ASSIGNMENTS_U1)*/ pfrmt.target_res_assignment_id --Bug 2814165
2510 ,p_target_plan_version_id
2511 ,l_target_project_id
2512 ,pfrmt.target_task_id
2513 ,pfrmt.system_reference4 -- Bug 3615617 resource_list_member_id
2514 ,sysdate
2515 ,fnd_global.user_id
2516 ,sysdate
2517 ,fnd_global.user_id
2518 ,fnd_global.login_id
2519 ,pra.unit_of_measure
2520 ,pra.track_as_labor_flag
2521 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
2522 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
2523 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
2524 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
2525 ,pra.resource_assignment_type
2526 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
2527 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
2528 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
2529 ,standard_bill_rate
2530 ,average_bill_rate
2531 ,average_cost_rate
2532 ,pfrmt.system_reference3 -- Project assignment id of the target (Bug 3354518)
2533 ,plan_error_code
2534 ,average_discount_percentage
2535 ,total_borrowed_revenue
2536 ,total_revenue_adj
2537 ,total_lent_resource_cost
2538 ,total_cost_adj
2539 ,total_unassigned_time_cost
2540 ,total_utilization_percent
2541 ,total_utilization_hours
2542 ,total_utilization_adj
2543 ,total_capacity
2544 ,total_head_count
2545 ,total_head_count_adj
2546 ,total_tp_revenue_in
2547 ,total_tp_revenue_out
2548 ,total_tp_cost_in
2549 ,total_tp_cost_out
2550 --parent assignment id in the target resource assignments contain source resource assignment id
2551 --Bug 4200168
2552 ,pra.resource_assignment_id
2553 ,pfrmt.system_reference2 -- element version id of the target. (Bug 3354518)
2554 ,pra.rbs_element_id
2555 ,pfrmt.planning_start_date -- Planning start date of the target (Bug 3354518)
2556 ,pfrmt.planning_end_date -- Planning end date of the target (Bug 3354518)
2557 ,pfrmt.schedule_start_date
2558 ,pfrmt.schedule_end_date
2559 ,pra.spread_curve_id
2560 ,pra.etc_method_code
2561 ,pra.res_type_code
2562 ,pra.attribute_category
2563 ,pra.attribute1
2564 ,pra.attribute2
2565 ,pra.attribute3
2566 ,pra.attribute4
2567 ,pra.attribute5
2568 ,pra.attribute6
2569 ,pra.attribute7
2570 ,pra.attribute8
2571 ,pra.attribute9
2572 ,pra.attribute10
2573 ,pra.attribute11
2574 ,pra.attribute12
2575 ,pra.attribute13
2576 ,pra.attribute14
2577 ,pra.attribute15
2578 ,pra.attribute16
2579 ,pra.attribute17
2580 ,pra.attribute18
2581 ,pra.attribute19
2582 ,pra.attribute20
2583 ,pra.attribute21
2584 ,pra.attribute22
2585 ,pra.attribute23
2586 ,pra.attribute24
2587 ,pra.attribute25
2588 ,pra.attribute26
2589 ,pra.attribute27
2590 ,pra.attribute28
2591 ,pra.attribute29
2592 ,pra.attribute30
2593 ,pra.fc_res_type_code
2594 ,pra.resource_class_code
2595 ,pra.organization_id
2596 ,pra.job_id
2597 ,pra.person_id
2598 ,pra.expenditure_type
2599 ,pra.expenditure_category
2600 ,pra.revenue_category_code
2601 ,pra.event_type
2602 ,pra.supplier_id
2603 ,pra.non_labor_resource
2604 ,pra.bom_resource_id
2605 ,pra.inventory_item_id
2606 ,pra.item_category_id
2607 ,1 -- should be 1 in the target version being created
2608 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
2609 ,pra.mfc_cost_type_id
2610 ,pra.procure_resource_flag
2611 ,pra.assignment_description
2612 ,pra.incurred_by_res_flag
2613 ,pra.rate_job_id
2614 ,pra.rate_expenditure_type
2615 ,pra.ta_display_flag
2616 -- Bug 3820625 sp_fixed_date should also move as per planning_start_date
2617 -- Least and greatest are used to make sure that sp_fixed_date is with in planning start and end dates
2618 ,greatest(least(pra.sp_fixed_date + (pfrmt.planning_start_date - pra.planning_start_date),
2619 pfrmt.planning_end_date),
2620 pfrmt.planning_start_date)
2621 ,pra.person_type_code
2622 ,pra.rate_based_flag
2623 ,pra.resource_rate_based_flag --IPM Arch Enhacement Bug 4865563
2624 ,pra.use_task_schedule_flag
2625 ,pra.rate_exp_func_curr_code
2626 ,pra.rate_expenditure_org_id
2627 ,pra.incur_by_res_class_code
2628 ,pra.incur_by_role_id
2629 ,pra.project_role_id
2630 ,pra.resource_class_flag
2631 ,pra.named_role
2632 ,pra.txn_accum_header_id
2633 ,scheduled_delay --For Bug 3948128
2634 FROM PA_FP_RA_MAP_TMP pfrmt --Bug 2814165
2635 ,PA_RESOURCE_ASSIGNMENTS pra
2636 WHERE pra.resource_assignment_id = pfrmt.source_res_assignment_id
2637 AND pra.budget_version_id = p_source_plan_version_id ;
2638
2639
2640 --For Bug 3974569. Take rbs_element_id and txn_accum_header_id from pa_rbs_plans_out_tmp
2641 --API is called for in WORKPLAN CONTEXT for copying from source to target with different RBSs or Resource Lists
2642 ELSIF p_calling_context='WORKPLAN' AND p_rbs_map_diff_flag ='Y' THEN --IF p_rbs_map_diff_flag ='N' THEN
2643
2644 IF P_PA_DEBUG_MODE = 'Y' THEN
2645
2646 pa_debug.g_err_stage:='Using the Second RA Insert';
2647 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2648
2649
2650 SELECT COUNT(*)
2651 INTO l_tmp
2652 FROM PA_FP_RA_MAP_TMP;
2653
2654 pa_debug.g_err_stage:='PA_FP_RA_MAP_TMP count '||l_tmp;
2655 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2656
2657 SELECT COUNT(*)
2658 INTO l_tmp
2659 FROM pa_rbs_plans_out_tmp;
2660
2661 pa_debug.g_err_stage:='pa_rbs_plans_out_tmp count '||l_tmp;
2662 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2663
2664 END IF;
2665
2666 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
2667 resource_assignment_id
2668 ,budget_version_id
2669 ,project_id
2670 ,task_id
2671 ,resource_list_member_id
2672 ,last_update_date
2673 ,last_updated_by
2674 ,creation_date
2675 ,created_by
2676 ,last_update_login
2677 ,unit_of_measure
2678 ,track_as_labor_flag
2679 ,total_plan_revenue
2680 ,total_plan_raw_cost
2681 ,total_plan_burdened_cost
2682 ,total_plan_quantity
2683 ,resource_assignment_type
2684 ,total_project_raw_cost
2685 ,total_project_burdened_cost
2686 ,total_project_revenue
2687 ,standard_bill_rate
2688 ,average_bill_rate
2689 ,average_cost_rate
2690 ,project_assignment_id
2691 ,plan_error_code
2692 ,average_discount_percentage
2693 ,total_borrowed_revenue
2694 ,total_revenue_adj
2695 ,total_lent_resource_cost
2696 ,total_cost_adj
2697 ,total_unassigned_time_cost
2698 ,total_utilization_percent
2699 ,total_utilization_hours
2700 ,total_utilization_adj
2701 ,total_capacity
2702 ,total_head_count
2703 ,total_head_count_adj
2704 ,total_tp_revenue_in
2705 ,total_tp_revenue_out
2706 ,total_tp_cost_in
2707 ,total_tp_cost_out
2708 ,parent_assignment_id
2709 ,wbs_element_version_id
2710 ,rbs_element_id
2711 ,planning_start_date
2712 ,planning_end_date
2713 ,schedule_start_date
2714 ,schedule_end_date
2715 ,spread_curve_id
2716 ,etc_method_code
2717 ,res_type_code
2718 ,attribute_category
2719 ,attribute1
2720 ,attribute2
2721 ,attribute3
2722 ,attribute4
2723 ,attribute5
2724 ,attribute6
2725 ,attribute7
2726 ,attribute8
2727 ,attribute9
2728 ,attribute10
2729 ,attribute11
2730 ,attribute12
2731 ,attribute13
2732 ,attribute14
2733 ,attribute15
2734 ,attribute16
2735 ,attribute17
2736 ,attribute18
2737 ,attribute19
2738 ,attribute20
2739 ,attribute21
2740 ,attribute22
2741 ,attribute23
2742 ,attribute24
2743 ,attribute25
2744 ,attribute26
2745 ,attribute27
2746 ,attribute28
2747 ,attribute29
2748 ,attribute30
2749 ,fc_res_type_code
2750 ,resource_class_code
2751 ,organization_id
2752 ,job_id
2753 ,person_id
2754 ,expenditure_type
2755 ,expenditure_category
2756 ,revenue_category_code
2757 ,event_type
2758 ,supplier_id
2759 ,non_labor_resource
2760 ,bom_resource_id
2761 ,inventory_item_id
2762 ,item_category_id
2763 ,record_version_number
2764 ,transaction_source_code
2765 ,mfc_cost_type_id
2766 ,procure_resource_flag
2767 ,assignment_description
2768 ,incurred_by_res_flag
2769 ,rate_job_id
2770 ,rate_expenditure_type
2771 ,ta_display_flag
2772 ,sp_fixed_date
2773 ,person_type_code
2774 ,rate_based_flag
2775 ,resource_rate_based_flag -- IPM Arch Enhacements Bug 4865563
2776 ,use_task_schedule_flag
2777 ,rate_exp_func_curr_code
2778 ,rate_expenditure_org_id
2779 ,incur_by_res_class_code
2780 ,incur_by_role_id
2781 ,project_role_id
2782 ,resource_class_flag
2783 ,named_role
2784 ,txn_accum_header_id
2785 ,scheduled_delay --For Bug 3948128
2786 )
2787 SELECT /*+ ORDERED USE_NL(PFRMT,PRA,RMAP) INDEX(PRA PA_RESOURCE_ASSIGNMENTS_U1)*/ pfrmt.target_res_assignment_id --Bug 2814165
2788 ,p_target_plan_version_id
2789 ,l_target_project_id
2790 ,pfrmt.target_task_id
2791 ,pfrmt.system_reference4 -- Bug 3615617 resource_list_member_id
2792 ,sysdate
2793 ,fnd_global.user_id
2794 ,sysdate
2795 ,fnd_global.user_id
2796 ,fnd_global.login_id
2797 ,pra.unit_of_measure
2798 ,pra.track_as_labor_flag
2799 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
2800 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
2801 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
2802 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
2803 ,pra.resource_assignment_type
2804 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
2805 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
2806 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
2807 ,standard_bill_rate
2808 ,average_bill_rate
2809 ,average_cost_rate
2810 ,pfrmt.system_reference3 -- Project assignment id of the target (Bug 3354518)
2811 ,plan_error_code
2812 ,average_discount_percentage
2813 ,total_borrowed_revenue
2814 ,total_revenue_adj
2815 ,total_lent_resource_cost
2816 ,total_cost_adj
2817 ,total_unassigned_time_cost
2818 ,total_utilization_percent
2819 ,total_utilization_hours
2820 ,total_utilization_adj
2821 ,total_capacity
2822 ,total_head_count
2823 ,total_head_count_adj
2824 ,total_tp_revenue_in
2825 ,total_tp_revenue_out
2826 ,total_tp_cost_in
2827 ,total_tp_cost_out
2828 --parent assignment id in the target resource assignments contain source resource assignment id
2829 --Bug 4200168
2830 ,pra.resource_assignment_id
2831 ,pfrmt.system_reference2 -- element version id of the target. (Bug 3354518)
2832 ,rmap.rbs_element_id
2833 ,pfrmt.planning_start_date -- Planning start date of the target (Bug 3354518)
2834 ,pfrmt.planning_end_date -- Planning end date of the target (Bug 3354518)
2835 ,pfrmt.schedule_start_date
2836 ,pfrmt.schedule_end_date
2837 ,pra.spread_curve_id
2838 ,pra.etc_method_code
2839 ,pra.res_type_code
2840 ,pra.attribute_category
2841 ,pra.attribute1
2842 ,pra.attribute2
2843 ,pra.attribute3
2844 ,pra.attribute4
2845 ,pra.attribute5
2846 ,pra.attribute6
2847 ,pra.attribute7
2848 ,pra.attribute8
2849 ,pra.attribute9
2850 ,pra.attribute10
2851 ,pra.attribute11
2852 ,pra.attribute12
2853 ,pra.attribute13
2854 ,pra.attribute14
2855 ,pra.attribute15
2856 ,pra.attribute16
2857 ,pra.attribute17
2858 ,pra.attribute18
2859 ,pra.attribute19
2860 ,pra.attribute20
2861 ,pra.attribute21
2862 ,pra.attribute22
2863 ,pra.attribute23
2864 ,pra.attribute24
2865 ,pra.attribute25
2866 ,pra.attribute26
2867 ,pra.attribute27
2868 ,pra.attribute28
2869 ,pra.attribute29
2870 ,pra.attribute30
2871 ,pra.fc_res_type_code
2872 ,pra.resource_class_code
2873 ,pra.organization_id
2874 ,pra.job_id
2875 ,pra.person_id
2876 ,pra.expenditure_type
2877 ,pra.expenditure_category
2878 ,pra.revenue_category_code
2879 ,pra.event_type
2880 ,pra.supplier_id
2881 ,pra.non_labor_resource
2882 ,pra.bom_resource_id
2883 ,pra.inventory_item_id
2884 ,pra.item_category_id
2885 ,1 -- should be 1 in the target version being created
2886 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
2887 ,pra.mfc_cost_type_id
2888 ,pra.procure_resource_flag
2889 ,pra.assignment_description
2890 ,pra.incurred_by_res_flag
2891 ,pra.rate_job_id
2892 ,pra.rate_expenditure_type
2893 ,pra.ta_display_flag
2894 -- Bug 3820625 sp_fixed_date should also move as per planning_start_date
2895 -- Least and greatest are used to make sure that sp_fixed_date is with in planning start and end dates
2896 ,greatest(least(pra.sp_fixed_date + (pfrmt.planning_start_date - pra.planning_start_date),
2897 pfrmt.planning_end_date),
2898 pfrmt.planning_start_date)
2899 ,pra.person_type_code
2900 ,pra.rate_based_flag
2901 ,pra.resource_rate_based_flag --IPM Arch Enhancement Bug 4865563
2902 ,pra.use_task_schedule_flag
2903 ,pra.rate_exp_func_curr_code
2904 ,pra.rate_expenditure_org_id
2905 ,pra.incur_by_res_class_code
2906 ,pra.incur_by_role_id
2907 ,pra.project_role_id
2908 ,pra.resource_class_flag
2909 ,pra.named_role
2910 ,rmap.txn_accum_header_id
2911 ,scheduled_delay --For Bug 3948128
2912 FROM PA_FP_RA_MAP_TMP pfrmt --Bug 2814165
2913 ,PA_RESOURCE_ASSIGNMENTS pra
2914 ,pa_rbs_plans_out_tmp rmap
2915 WHERE pra.resource_assignment_id = pfrmt.source_res_assignment_id
2916 AND pra.budget_version_id = p_source_plan_version_id
2917 AND rmap.source_id = pra.resource_assignment_id;
2918
2919 --Copying BUDGET versions within a project. OR
2920 --Copying Budget versions across 2 projects with the planning level being project and
2921 ---->with the resource list being a centrally controlled one
2922 ELSIF ((p_calling_context IS NULL OR p_calling_context='CREATE_VERSION') AND l_source_project_id=l_target_project_id) OR
2923 ((p_calling_context IS NULL OR p_calling_context='CREATE_VERSION') AND l_source_project_id<>l_target_project_id
2924 AND l_fin_plan_level_code='P' AND l_control_flag='Y' ) THEN
2925
2926 IF P_PA_DEBUG_MODE = 'Y' THEN
2927 pa_debug.g_err_stage:='Using the Third RA Insert';
2928 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
2929 END IF;
2930
2931 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
2932 resource_assignment_id
2933 ,budget_version_id
2934 ,project_id
2935 ,task_id
2936 ,resource_list_member_id
2937 ,last_update_date
2938 ,last_updated_by
2939 ,creation_date
2940 ,created_by
2941 ,last_update_login
2942 ,unit_of_measure
2943 ,track_as_labor_flag
2944 ,total_plan_revenue
2945 ,total_plan_raw_cost
2946 ,total_plan_burdened_cost
2947 ,total_plan_quantity
2948 ,resource_assignment_type
2949 ,total_project_raw_cost
2950 ,total_project_burdened_cost
2951 ,total_project_revenue
2952 ,standard_bill_rate
2953 ,average_bill_rate
2954 ,average_cost_rate
2955 ,project_assignment_id
2956 ,plan_error_code
2957 ,average_discount_percentage
2958 ,total_borrowed_revenue
2959 ,total_revenue_adj
2960 ,total_lent_resource_cost
2961 ,total_cost_adj
2962 ,total_unassigned_time_cost
2963 ,total_utilization_percent
2964 ,total_utilization_hours
2965 ,total_utilization_adj
2966 ,total_capacity
2967 ,total_head_count
2968 ,total_head_count_adj
2969 ,total_tp_revenue_in
2970 ,total_tp_revenue_out
2971 ,total_tp_cost_in
2972 ,total_tp_cost_out
2973 ,parent_assignment_id
2974 ,wbs_element_version_id
2975 ,rbs_element_id
2976 ,planning_start_date
2977 ,planning_end_date
2978 ,schedule_start_date
2979 ,schedule_end_date
2980 ,spread_curve_id
2981 ,etc_method_code
2982 ,res_type_code
2983 ,attribute_category
2984 ,attribute1
2985 ,attribute2
2986 ,attribute3
2987 ,attribute4
2988 ,attribute5
2989 ,attribute6
2990 ,attribute7
2991 ,attribute8
2992 ,attribute9
2993 ,attribute10
2994 ,attribute11
2995 ,attribute12
2996 ,attribute13
2997 ,attribute14
2998 ,attribute15
2999 ,attribute16
3000 ,attribute17
3001 ,attribute18
3002 ,attribute19
3003 ,attribute20
3004 ,attribute21
3005 ,attribute22
3006 ,attribute23
3007 ,attribute24
3008 ,attribute25
3009 ,attribute26
3010 ,attribute27
3011 ,attribute28
3012 ,attribute29
3013 ,attribute30
3014 ,fc_res_type_code
3015 ,resource_class_code
3016 ,organization_id
3017 ,job_id
3018 ,person_id
3019 ,expenditure_type
3020 ,expenditure_category
3021 ,revenue_category_code
3022 ,event_type
3023 ,supplier_id
3024 ,non_labor_resource
3025 ,bom_resource_id
3026 ,inventory_item_id
3027 ,item_category_id
3028 ,record_version_number
3029 ,transaction_source_code
3030 ,mfc_cost_type_id
3031 ,procure_resource_flag
3032 ,assignment_description
3033 ,incurred_by_res_flag
3034 ,rate_job_id
3035 ,rate_expenditure_type
3036 ,ta_display_flag
3037 ,sp_fixed_date
3038 ,person_type_code
3039 ,rate_based_flag
3040 ,resource_rate_based_flag --IPM Arch Enhacements Bug 4865563
3041 ,use_task_schedule_flag
3042 ,rate_exp_func_curr_code
3043 ,rate_expenditure_org_id
3044 ,incur_by_res_class_code
3045 ,incur_by_role_id
3046 ,project_role_id
3047 ,resource_class_flag
3048 ,named_role
3049 ,txn_accum_header_id
3050 ,scheduled_delay --For Bug 3948128
3051 )
3052 SELECT
3053 pa_resource_assignments_s.nextval
3054 ,p_target_plan_version_id
3055 ,l_target_project_id
3056 ,pra.task_id
3057 ,pra.resource_list_member_id
3058 ,sysdate
3059 ,fnd_global.user_id
3060 ,sysdate
3061 ,fnd_global.user_id
3062 ,fnd_global.login_id
3063 ,pra.unit_of_measure
3064 ,pra.track_as_labor_flag
3065 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
3066 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
3067 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
3068 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
3069 ,pra.resource_assignment_type
3070 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
3071 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
3072 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
3073 ,standard_bill_rate
3074 ,average_bill_rate
3075 ,average_cost_rate
3076 ,pra.project_assignment_id
3077 ,plan_error_code
3078 ,average_discount_percentage
3079 ,total_borrowed_revenue
3080 ,total_revenue_adj
3081 ,total_lent_resource_cost
3082 ,total_cost_adj
3083 ,total_unassigned_time_cost
3084 ,total_utilization_percent
3085 ,total_utilization_hours
3086 ,total_utilization_adj
3087 ,total_capacity
3088 ,total_head_count
3089 ,total_head_count_adj
3090 ,total_tp_revenue_in
3091 ,total_tp_revenue_out
3092 ,total_tp_cost_in
3093 ,total_tp_cost_out
3094 --parent assignment id in the target resource assignments contain source resource assignment id
3095 --Bug 4200168
3096 ,pra.resource_assignment_id
3097 ,pra.wbs_element_version_id
3098 ,pra.rbs_element_id
3099 ,pra.planning_start_date -- Planning start date of the target (Bug 3354518)
3100 ,pra.planning_end_date -- Planning end date of the target (Bug 3354518)
3101 ,pra.schedule_start_date
3102 ,pra.schedule_end_date
3103 ,pra.spread_curve_id
3104 ,pra.etc_method_code
3105 ,pra.res_type_code
3106 ,pra.attribute_category
3107 ,pra.attribute1
3108 ,pra.attribute2
3109 ,pra.attribute3
3110 ,pra.attribute4
3111 ,pra.attribute5
3112 ,pra.attribute6
3113 ,pra.attribute7
3114 ,pra.attribute8
3115 ,pra.attribute9
3116 ,pra.attribute10
3117 ,pra.attribute11
3118 ,pra.attribute12
3119 ,pra.attribute13
3120 ,pra.attribute14
3121 ,pra.attribute15
3122 ,pra.attribute16
3123 ,pra.attribute17
3124 ,pra.attribute18
3125 ,pra.attribute19
3126 ,pra.attribute20
3127 ,pra.attribute21
3128 ,pra.attribute22
3129 ,pra.attribute23
3130 ,pra.attribute24
3131 ,pra.attribute25
3132 ,pra.attribute26
3133 ,pra.attribute27
3134 ,pra.attribute28
3135 ,pra.attribute29
3136 ,pra.attribute30
3137 ,pra.fc_res_type_code
3138 ,pra.resource_class_code
3139 ,pra.organization_id
3140 ,pra.job_id
3141 ,pra.person_id
3142 ,pra.expenditure_type
3143 ,pra.expenditure_category
3144 ,pra.revenue_category_code
3145 ,pra.event_type
3146 ,pra.supplier_id
3147 ,pra.non_labor_resource
3148 ,pra.bom_resource_id
3149 ,pra.inventory_item_id
3150 ,pra.item_category_id
3151 ,1 -- should be 1 in the target version being created
3152 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
3153 ,pra.mfc_cost_type_id
3154 ,pra.procure_resource_flag
3155 ,pra.assignment_description
3156 ,pra.incurred_by_res_flag
3157 ,pra.rate_job_id
3158 ,pra.rate_expenditure_type
3159 ,pra.ta_display_flag
3160 ,pra.sp_fixed_date
3161 ,pra.person_type_code
3162 ,pra.rate_based_flag
3163 ,pra.resource_rate_based_flag --IPM Arch Enhacement Bug 4865563
3164 ,pra.use_task_schedule_flag
3165 ,pra.rate_exp_func_curr_code
3166 ,pra.rate_expenditure_org_id
3167 ,pra.incur_by_res_class_code
3168 ,pra.incur_by_role_id
3169 ,pra.project_role_id
3170 ,pra.resource_class_flag
3171 ,pra.named_role
3172 ,pra.txn_accum_header_id
3173 ,scheduled_delay --For Bug 3948128
3174 FROM PA_RESOURCE_ASSIGNMENTS pra
3175 WHERE pra.budget_version_id = p_source_plan_version_id
3176 AND pra.project_id = l_source_project_id ; -- Bug 4493425
3177
3178 --API is called for copying resource assignments between plan versions that dont belong to the same project
3179 ELSIF (p_calling_context IS NULL OR p_calling_context='CREATE_VERSION') AND l_source_project_id<>l_target_project_id THEN
3180
3181 IF l_fin_plan_level_code ='P' THEN
3182
3183 IF l_control_flag ='N' THEN
3184
3185
3186 IF P_PA_DEBUG_MODE = 'Y' THEN
3187 pa_debug.g_err_stage:='Using the Fourth RA Insert';
3188 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
3189 END IF;
3190
3191 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
3192 resource_assignment_id
3193 ,budget_version_id
3194 ,project_id
3195 ,task_id
3196 ,resource_list_member_id
3197 ,last_update_date
3198 ,last_updated_by
3199 ,creation_date
3200 ,created_by
3201 ,last_update_login
3202 ,unit_of_measure
3203 ,track_as_labor_flag
3204 ,total_plan_revenue
3205 ,total_plan_raw_cost
3206 ,total_plan_burdened_cost
3207 ,total_plan_quantity
3208 ,resource_assignment_type
3209 ,total_project_raw_cost
3210 ,total_project_burdened_cost
3211 ,total_project_revenue
3212 ,standard_bill_rate
3213 ,average_bill_rate
3214 ,average_cost_rate
3215 ,project_assignment_id
3216 ,plan_error_code
3217 ,average_discount_percentage
3218 ,total_borrowed_revenue
3219 ,total_revenue_adj
3220 ,total_lent_resource_cost
3221 ,total_cost_adj
3222 ,total_unassigned_time_cost
3223 ,total_utilization_percent
3224 ,total_utilization_hours
3225 ,total_utilization_adj
3226 ,total_capacity
3227 ,total_head_count
3228 ,total_head_count_adj
3229 ,total_tp_revenue_in
3230 ,total_tp_revenue_out
3231 ,total_tp_cost_in
3232 ,total_tp_cost_out
3233 ,parent_assignment_id
3234 ,wbs_element_version_id
3235 ,rbs_element_id
3236 ,planning_start_date
3237 ,planning_end_date
3238 ,schedule_start_date
3239 ,schedule_end_date
3240 ,spread_curve_id
3241 ,etc_method_code
3242 ,res_type_code
3243 ,attribute_category
3244 ,attribute1
3245 ,attribute2
3246 ,attribute3
3247 ,attribute4
3248 ,attribute5
3249 ,attribute6
3250 ,attribute7
3251 ,attribute8
3252 ,attribute9
3253 ,attribute10
3254 ,attribute11
3255 ,attribute12
3256 ,attribute13
3257 ,attribute14
3258 ,attribute15
3259 ,attribute16
3260 ,attribute17
3261 ,attribute18
3262 ,attribute19
3263 ,attribute20
3264 ,attribute21
3265 ,attribute22
3266 ,attribute23
3267 ,attribute24
3268 ,attribute25
3269 ,attribute26
3270 ,attribute27
3271 ,attribute28
3272 ,attribute29
3273 ,attribute30
3274 ,fc_res_type_code
3275 ,resource_class_code
3276 ,organization_id
3277 ,job_id
3278 ,person_id
3279 ,expenditure_type
3280 ,expenditure_category
3281 ,revenue_category_code
3282 ,event_type
3283 ,supplier_id
3284 ,non_labor_resource
3285 ,bom_resource_id
3286 ,inventory_item_id
3287 ,item_category_id
3288 ,record_version_number
3289 ,transaction_source_code
3290 ,mfc_cost_type_id
3291 ,procure_resource_flag
3292 ,assignment_description
3293 ,incurred_by_res_flag
3294 ,rate_job_id
3295 ,rate_expenditure_type
3296 ,ta_display_flag
3297 ,sp_fixed_date
3298 ,person_type_code
3299 ,rate_based_flag
3300 ,resource_rate_based_flag --IPM Arch Enhacements Bug 4865563
3301 ,use_task_schedule_flag
3302 ,rate_exp_func_curr_code
3303 ,rate_expenditure_org_id
3304 ,incur_by_res_class_code
3305 ,incur_by_role_id
3306 ,project_role_id
3307 ,resource_class_flag
3308 ,named_role
3309 ,txn_accum_header_id
3310 ,scheduled_delay --For Bug 3948128
3311 )
3312 SELECT
3313 pa_resource_assignments_s.nextval
3314 ,p_target_plan_version_id
3315 ,l_target_project_id
3316 ,pra.task_id
3317 ,prlmt.resource_list_member_id
3318 ,sysdate
3319 ,fnd_global.user_id
3320 ,sysdate
3321 ,fnd_global.user_id
3322 ,fnd_global.login_id
3323 ,pra.unit_of_measure
3324 ,pra.track_as_labor_flag
3325 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
3326 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
3327 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
3328 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
3329 ,pra.resource_assignment_type
3330 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
3331 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
3332 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
3333 ,standard_bill_rate
3334 ,average_bill_rate
3335 ,average_cost_rate
3336 ,pra.project_assignment_id
3337 ,plan_error_code
3338 ,average_discount_percentage
3339 ,total_borrowed_revenue
3340 ,total_revenue_adj
3341 ,total_lent_resource_cost
3342 ,total_cost_adj
3343 ,total_unassigned_time_cost
3344 ,total_utilization_percent
3345 ,total_utilization_hours
3346 ,total_utilization_adj
3347 ,total_capacity
3348 ,total_head_count
3349 ,total_head_count_adj
3350 ,total_tp_revenue_in
3351 ,total_tp_revenue_out
3352 ,total_tp_cost_in
3353 ,total_tp_cost_out
3354 --parent assignment id in the target resource assignments contain source resource assignment id
3355 --Bug 4200168
3356 ,pra.resource_assignment_id
3357 ,pra.wbs_element_version_id
3358 ,pra.rbs_element_id
3359 ,pra.planning_start_date -- Planning start date of the target (Bug 3354518)
3360 ,pra.planning_end_date -- Planning end date of the target (Bug 3354518)
3361 ,pra.schedule_start_date
3362 ,pra.schedule_end_date
3363 ,pra.spread_curve_id
3364 ,pra.etc_method_code
3365 ,pra.res_type_code
3366 ,pra.attribute_category
3367 ,pra.attribute1
3368 ,pra.attribute2
3369 ,pra.attribute3
3370 ,pra.attribute4
3371 ,pra.attribute5
3372 ,pra.attribute6
3373 ,pra.attribute7
3374 ,pra.attribute8
3375 ,pra.attribute9
3376 ,pra.attribute10
3377 ,pra.attribute11
3378 ,pra.attribute12
3379 ,pra.attribute13
3380 ,pra.attribute14
3381 ,pra.attribute15
3382 ,pra.attribute16
3383 ,pra.attribute17
3384 ,pra.attribute18
3385 ,pra.attribute19
3386 ,pra.attribute20
3387 ,pra.attribute21
3388 ,pra.attribute22
3389 ,pra.attribute23
3390 ,pra.attribute24
3391 ,pra.attribute25
3392 ,pra.attribute26
3393 ,pra.attribute27
3394 ,pra.attribute28
3395 ,pra.attribute29
3396 ,pra.attribute30
3397 ,pra.fc_res_type_code
3398 ,pra.resource_class_code
3399 ,pra.organization_id
3400 ,pra.job_id
3401 ,pra.person_id
3402 ,pra.expenditure_type
3403 ,pra.expenditure_category
3404 ,pra.revenue_category_code
3405 ,pra.event_type
3406 ,pra.supplier_id
3407 ,pra.non_labor_resource
3408 ,pra.bom_resource_id
3409 ,pra.inventory_item_id
3410 ,pra.item_category_id
3411 ,1 -- should be 1 in the target version being created
3412 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
3413 ,pra.mfc_cost_type_id
3414 ,pra.procure_resource_flag
3415 ,pra.assignment_description
3416 ,pra.incurred_by_res_flag
3417 ,pra.rate_job_id
3418 ,pra.rate_expenditure_type
3419 ,pra.ta_display_flag
3420 ,pra.sp_fixed_date
3421 ,pra.person_type_code
3422 ,pra.rate_based_flag
3423 ,pra.resource_rate_based_flag --IPM Arch Enhancement Bug 4865563
3424 ,pra.use_task_schedule_flag
3425 ,pra.rate_exp_func_curr_code
3426 ,pra.rate_expenditure_org_id
3427 ,pra.incur_by_res_class_code
3428 ,pra.incur_by_role_id
3429 ,pra.project_role_id
3430 ,pra.resource_class_flag
3431 ,pra.named_role
3432 ,pra.txn_accum_header_id
3433 ,scheduled_delay --For Bug 3948128
3434 FROM PA_RESOURCE_ASSIGNMENTS pra,
3435 pa_resource_list_members prlms,
3436 pa_resource_list_members prlmt
3437 WHERE pra.budget_version_id = p_source_plan_version_id
3438 AND prlms.resource_list_member_id=pra.resource_list_member_id
3439 AND prlms.resource_list_id=l_resource_list_id
3440 AND prlms.object_id=l_source_project_id
3441 AND prlms.object_type='PROJECT'
3442 AND prlmt.resource_list_id=l_resource_list_id
3443 AND prlmt.object_id=l_target_project_id
3444 AND prlmt.object_type='PROJECT'
3445 AND prlmt.alias=prlms.alias;
3446
3447 END IF;--IF l_control_flag ='N' THEN
3448
3449 ELSIF l_fin_plan_level_code <> 'P' THEN
3450
3451 IF l_control_flag ='N' THEN
3452
3453
3454 IF P_PA_DEBUG_MODE = 'Y' THEN
3455 pa_debug.g_err_stage:='Using the FIFTH RA Insert';
3456 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
3457 END IF;
3458
3459 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
3460 resource_assignment_id
3461 ,budget_version_id
3462 ,project_id
3463 ,task_id
3464 ,resource_list_member_id
3465 ,last_update_date
3466 ,last_updated_by
3467 ,creation_date
3468 ,created_by
3469 ,last_update_login
3470 ,unit_of_measure
3471 ,track_as_labor_flag
3472 ,total_plan_revenue
3473 ,total_plan_raw_cost
3474 ,total_plan_burdened_cost
3475 ,total_plan_quantity
3476 ,resource_assignment_type
3477 ,total_project_raw_cost
3478 ,total_project_burdened_cost
3479 ,total_project_revenue
3480 ,standard_bill_rate
3481 ,average_bill_rate
3482 ,average_cost_rate
3483 ,project_assignment_id
3484 ,plan_error_code
3485 ,average_discount_percentage
3486 ,total_borrowed_revenue
3487 ,total_revenue_adj
3488 ,total_lent_resource_cost
3489 ,total_cost_adj
3490 ,total_unassigned_time_cost
3491 ,total_utilization_percent
3492 ,total_utilization_hours
3493 ,total_utilization_adj
3494 ,total_capacity
3495 ,total_head_count
3496 ,total_head_count_adj
3497 ,total_tp_revenue_in
3498 ,total_tp_revenue_out
3499 ,total_tp_cost_in
3500 ,total_tp_cost_out
3501 ,parent_assignment_id
3502 ,wbs_element_version_id
3503 ,rbs_element_id
3504 ,planning_start_date
3505 ,planning_end_date
3506 ,schedule_start_date
3507 ,schedule_end_date
3508 ,spread_curve_id
3509 ,etc_method_code
3510 ,res_type_code
3511 ,attribute_category
3512 ,attribute1
3513 ,attribute2
3514 ,attribute3
3515 ,attribute4
3516 ,attribute5
3517 ,attribute6
3518 ,attribute7
3519 ,attribute8
3520 ,attribute9
3521 ,attribute10
3522 ,attribute11
3523 ,attribute12
3524 ,attribute13
3525 ,attribute14
3526 ,attribute15
3527 ,attribute16
3528 ,attribute17
3529 ,attribute18
3530 ,attribute19
3531 ,attribute20
3532 ,attribute21
3533 ,attribute22
3534 ,attribute23
3535 ,attribute24
3536 ,attribute25
3537 ,attribute26
3538 ,attribute27
3539 ,attribute28
3540 ,attribute29
3541 ,attribute30
3542 ,fc_res_type_code
3543 ,resource_class_code
3544 ,organization_id
3545 ,job_id
3546 ,person_id
3547 ,expenditure_type
3548 ,expenditure_category
3549 ,revenue_category_code
3550 ,event_type
3551 ,supplier_id
3552 ,non_labor_resource
3553 ,bom_resource_id
3554 ,inventory_item_id
3555 ,item_category_id
3556 ,record_version_number
3557 ,transaction_source_code
3558 ,mfc_cost_type_id
3559 ,procure_resource_flag
3560 ,assignment_description
3561 ,incurred_by_res_flag
3562 ,rate_job_id
3563 ,rate_expenditure_type
3564 ,ta_display_flag
3565 ,sp_fixed_date
3566 ,person_type_code
3567 ,rate_based_flag
3568 ,resource_rate_based_flag --IPM Arch Enhancements Bug 4865563
3569 ,use_task_schedule_flag
3570 ,rate_exp_func_curr_code
3571 ,rate_expenditure_org_id
3572 ,incur_by_res_class_code
3573 ,incur_by_role_id
3574 ,project_role_id
3575 ,resource_class_flag
3576 ,named_role
3577 ,txn_accum_header_id
3578 ,scheduled_delay --For Bug 3948128
3579 )
3580 SELECT
3581 pa_resource_assignments_s.nextval
3582 ,p_target_plan_version_id
3583 ,l_target_project_id
3584 ,pelm.target_task_id
3585 ,prlmt.resource_list_member_id
3586 ,sysdate
3587 ,fnd_global.user_id
3588 ,sysdate
3589 ,fnd_global.user_id
3590 ,fnd_global.login_id
3591 ,pra.unit_of_measure
3592 ,pra.track_as_labor_flag
3593 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
3594 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
3595 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
3596 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
3597 ,pra.resource_assignment_type
3598 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
3599 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
3600 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
3601 ,standard_bill_rate
3602 ,average_bill_rate
3603 ,average_cost_rate
3604 ,pra.project_assignment_id
3605 ,plan_error_code
3606 ,average_discount_percentage
3607 ,total_borrowed_revenue
3608 ,total_revenue_adj
3609 ,total_lent_resource_cost
3610 ,total_cost_adj
3611 ,total_unassigned_time_cost
3612 ,total_utilization_percent
3613 ,total_utilization_hours
3614 ,total_utilization_adj
3615 ,total_capacity
3616 ,total_head_count
3617 ,total_head_count_adj
3618 ,total_tp_revenue_in
3619 ,total_tp_revenue_out
3620 ,total_tp_cost_in
3621 ,total_tp_cost_out
3622 --parent assignment id in the target resource assignments contain source resource assignment id
3623 --Bug 4200168
3624 ,pra.resource_assignment_id
3625 ,pra.wbs_element_version_id
3626 ,pra.rbs_element_id
3627 ,pra.planning_start_date -- Planning start date of the target (Bug 3354518)
3628 ,pra.planning_end_date -- Planning end date of the target (Bug 3354518)
3629 ,pra.schedule_start_date
3630 ,pra.schedule_end_date
3631 ,pra.spread_curve_id
3632 ,pra.etc_method_code
3633 ,pra.res_type_code
3634 ,pra.attribute_category
3635 ,pra.attribute1
3636 ,pra.attribute2
3637 ,pra.attribute3
3638 ,pra.attribute4
3639 ,pra.attribute5
3640 ,pra.attribute6
3641 ,pra.attribute7
3642 ,pra.attribute8
3643 ,pra.attribute9
3644 ,pra.attribute10
3645 ,pra.attribute11
3646 ,pra.attribute12
3647 ,pra.attribute13
3648 ,pra.attribute14
3649 ,pra.attribute15
3650 ,pra.attribute16
3651 ,pra.attribute17
3652 ,pra.attribute18
3653 ,pra.attribute19
3654 ,pra.attribute20
3655 ,pra.attribute21
3656 ,pra.attribute22
3657 ,pra.attribute23
3658 ,pra.attribute24
3659 ,pra.attribute25
3660 ,pra.attribute26
3661 ,pra.attribute27
3662 ,pra.attribute28
3663 ,pra.attribute29
3664 ,pra.attribute30
3665 ,pra.fc_res_type_code
3666 ,pra.resource_class_code
3667 ,pra.organization_id
3668 ,pra.job_id
3669 ,pra.person_id
3670 ,pra.expenditure_type
3671 ,pra.expenditure_category
3672 ,pra.revenue_category_code
3673 ,pra.event_type
3674 ,pra.supplier_id
3675 ,pra.non_labor_resource
3676 ,pra.bom_resource_id
3677 ,pra.inventory_item_id
3678 ,pra.item_category_id
3679 ,1 -- should be 1 in the target version being created
3680 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
3681 ,pra.mfc_cost_type_id
3682 ,pra.procure_resource_flag
3683 ,pra.assignment_description
3684 ,pra.incurred_by_res_flag
3685 ,pra.rate_job_id
3686 ,pra.rate_expenditure_type
3687 ,pra.ta_display_flag
3688 ,pra.sp_fixed_date
3689 ,pra.person_type_code
3690 ,pra.rate_based_flag
3691 ,pra.resource_rate_based_flag --IPM Arch Enhancements Bug 4865563
3692 ,pra.use_task_schedule_flag
3693 ,pra.rate_exp_func_curr_code
3694 ,pra.rate_expenditure_org_id
3695 ,pra.incur_by_res_class_code
3696 ,pra.incur_by_role_id
3697 ,pra.project_role_id
3698 ,pra.resource_class_flag
3699 ,pra.named_role
3700 ,pra.txn_accum_header_id
3701 ,scheduled_delay --For Bug 3948128
3702 FROM PA_RESOURCE_ASSIGNMENTS pra,
3703 (SELECT TO_NUMBER(attribute15) source_task_id,
3704 proj_element_id target_task_id
3705 FROM pa_proj_elements
3706 WHERE project_id = l_target_project_id
3707 AND object_type = 'PA_TASKS'
3708 UNION ALL
3709 SELECT 0 source_task_id,
3710 0 target_task_id
3711 FROM dual) pelm,
3712 pa_resource_list_members prlms,
3713 pa_resource_list_members prlmt
3714 WHERE pra.budget_version_id = p_source_plan_version_id
3715 AND prlms.resource_list_member_id=pra.resource_list_member_id
3716 AND prlms.resource_list_id=l_resource_list_id
3717 AND prlms.object_id=l_source_project_id
3718 AND prlms.object_type='PROJECT'
3719 AND prlmt.resource_list_id=l_resource_list_id
3720 AND prlmt.object_id=l_target_project_id
3721 AND prlmt.object_type='PROJECT'
3722 AND prlmt.alias=prlms.alias
3723 AND pelm.source_task_id=pra.task_id;
3724
3725 ELSE --Control Flag is Y and Planning Level is not project
3726
3727 IF P_PA_DEBUG_MODE = 'Y' THEN
3728 pa_debug.g_err_stage:='Using the Sixth RA Insert';
3729 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
3730 END IF;
3731
3732 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
3733 resource_assignment_id
3734 ,budget_version_id
3735 ,project_id
3736 ,task_id
3737 ,resource_list_member_id
3738 ,last_update_date
3739 ,last_updated_by
3740 ,creation_date
3741 ,created_by
3742 ,last_update_login
3743 ,unit_of_measure
3744 ,track_as_labor_flag
3745 ,total_plan_revenue
3746 ,total_plan_raw_cost
3747 ,total_plan_burdened_cost
3748 ,total_plan_quantity
3749 ,resource_assignment_type
3750 ,total_project_raw_cost
3751 ,total_project_burdened_cost
3752 ,total_project_revenue
3753 ,standard_bill_rate
3754 ,average_bill_rate
3755 ,average_cost_rate
3756 ,project_assignment_id
3757 ,plan_error_code
3758 ,average_discount_percentage
3759 ,total_borrowed_revenue
3760 ,total_revenue_adj
3761 ,total_lent_resource_cost
3762 ,total_cost_adj
3763 ,total_unassigned_time_cost
3764 ,total_utilization_percent
3765 ,total_utilization_hours
3766 ,total_utilization_adj
3767 ,total_capacity
3768 ,total_head_count
3769 ,total_head_count_adj
3770 ,total_tp_revenue_in
3771 ,total_tp_revenue_out
3772 ,total_tp_cost_in
3773 ,total_tp_cost_out
3774 ,parent_assignment_id
3775 ,wbs_element_version_id
3776 ,rbs_element_id
3777 ,planning_start_date
3778 ,planning_end_date
3779 ,schedule_start_date
3780 ,schedule_end_date
3781 ,spread_curve_id
3782 ,etc_method_code
3783 ,res_type_code
3784 ,attribute_category
3785 ,attribute1
3786 ,attribute2
3787 ,attribute3
3788 ,attribute4
3789 ,attribute5
3790 ,attribute6
3791 ,attribute7
3792 ,attribute8
3793 ,attribute9
3794 ,attribute10
3795 ,attribute11
3796 ,attribute12
3797 ,attribute13
3798 ,attribute14
3799 ,attribute15
3800 ,attribute16
3801 ,attribute17
3802 ,attribute18
3803 ,attribute19
3804 ,attribute20
3805 ,attribute21
3806 ,attribute22
3807 ,attribute23
3808 ,attribute24
3809 ,attribute25
3810 ,attribute26
3811 ,attribute27
3812 ,attribute28
3813 ,attribute29
3814 ,attribute30
3815 ,fc_res_type_code
3816 ,resource_class_code
3817 ,organization_id
3818 ,job_id
3819 ,person_id
3820 ,expenditure_type
3821 ,expenditure_category
3822 ,revenue_category_code
3823 ,event_type
3824 ,supplier_id
3825 ,non_labor_resource
3826 ,bom_resource_id
3827 ,inventory_item_id
3828 ,item_category_id
3829 ,record_version_number
3830 ,transaction_source_code
3831 ,mfc_cost_type_id
3832 ,procure_resource_flag
3833 ,assignment_description
3834 ,incurred_by_res_flag
3835 ,rate_job_id
3836 ,rate_expenditure_type
3837 ,ta_display_flag
3838 ,sp_fixed_date
3839 ,person_type_code
3840 ,rate_based_flag
3841 ,resource_rate_based_flag --IPM Arch Enhancements Bug 4865563
3842 ,use_task_schedule_flag
3843 ,rate_exp_func_curr_code
3844 ,rate_expenditure_org_id
3845 ,incur_by_res_class_code
3846 ,incur_by_role_id
3847 ,project_role_id
3848 ,resource_class_flag
3849 ,named_role
3850 ,txn_accum_header_id
3851 ,scheduled_delay --For Bug 3948128
3852 )
3853 SELECT
3854 pa_resource_assignments_s.nextval
3855 ,p_target_plan_version_id
3856 ,l_target_project_id
3857 ,pelm.target_task_id
3858 ,pra.resource_list_member_id
3859 ,sysdate
3860 ,fnd_global.user_id
3861 ,sysdate
3862 ,fnd_global.user_id
3863 ,fnd_global.login_id
3864 ,pra.unit_of_measure
3865 ,pra.track_as_labor_flag
3866 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
3867 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
3868 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
3869 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
3870 ,pra.resource_assignment_type
3871 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
3872 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
3873 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
3874 ,standard_bill_rate
3875 ,average_bill_rate
3876 ,average_cost_rate
3877 ,pra.project_assignment_id
3878 ,plan_error_code
3879 ,average_discount_percentage
3880 ,total_borrowed_revenue
3881 ,total_revenue_adj
3882 ,total_lent_resource_cost
3883 ,total_cost_adj
3884 ,total_unassigned_time_cost
3885 ,total_utilization_percent
3886 ,total_utilization_hours
3887 ,total_utilization_adj
3888 ,total_capacity
3889 ,total_head_count
3890 ,total_head_count_adj
3891 ,total_tp_revenue_in
3892 ,total_tp_revenue_out
3893 ,total_tp_cost_in
3894 ,total_tp_cost_out
3895 --parent assignment id in the target resource assignments contain source resource assignment id
3896 --Bug 4200168
3897 ,pra.resource_assignment_id
3898 ,pra.wbs_element_version_id
3899 ,pra.rbs_element_id
3900 ,pra.planning_start_date -- Planning start date of the target (Bug 3354518)
3901 ,pra.planning_end_date -- Planning end date of the target (Bug 3354518)
3902 ,pra.schedule_start_date
3903 ,pra.schedule_end_date
3904 ,pra.spread_curve_id
3905 ,pra.etc_method_code
3906 ,pra.res_type_code
3907 ,pra.attribute_category
3908 ,pra.attribute1
3909 ,pra.attribute2
3910 ,pra.attribute3
3911 ,pra.attribute4
3912 ,pra.attribute5
3913 ,pra.attribute6
3914 ,pra.attribute7
3915 ,pra.attribute8
3916 ,pra.attribute9
3917 ,pra.attribute10
3918 ,pra.attribute11
3919 ,pra.attribute12
3920 ,pra.attribute13
3921 ,pra.attribute14
3922 ,pra.attribute15
3923 ,pra.attribute16
3924 ,pra.attribute17
3925 ,pra.attribute18
3926 ,pra.attribute19
3927 ,pra.attribute20
3928 ,pra.attribute21
3929 ,pra.attribute22
3930 ,pra.attribute23
3931 ,pra.attribute24
3932 ,pra.attribute25
3933 ,pra.attribute26
3934 ,pra.attribute27
3935 ,pra.attribute28
3936 ,pra.attribute29
3937 ,pra.attribute30
3938 ,pra.fc_res_type_code
3939 ,pra.resource_class_code
3940 ,pra.organization_id
3941 ,pra.job_id
3942 ,pra.person_id
3943 ,pra.expenditure_type
3944 ,pra.expenditure_category
3945 ,pra.revenue_category_code
3946 ,pra.event_type
3947 ,pra.supplier_id
3948 ,pra.non_labor_resource
3949 ,pra.bom_resource_id
3950 ,pra.inventory_item_id
3951 ,pra.item_category_id
3952 ,1 -- should be 1 in the target version being created
3953 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
3954 ,pra.mfc_cost_type_id
3955 ,pra.procure_resource_flag
3956 ,pra.assignment_description
3957 ,pra.incurred_by_res_flag
3958 ,pra.rate_job_id
3959 ,pra.rate_expenditure_type
3960 ,pra.ta_display_flag
3961 ,pra.sp_fixed_date
3962 ,pra.person_type_code
3963 ,pra.rate_based_flag
3964 ,pra.resource_rate_based_flag --IPM Arch Enhancements Bug 4865563
3965 ,pra.use_task_schedule_flag
3966 ,pra.rate_exp_func_curr_code
3967 ,pra.rate_expenditure_org_id
3968 ,pra.incur_by_res_class_code
3969 ,pra.incur_by_role_id
3970 ,pra.project_role_id
3971 ,pra.resource_class_flag
3972 ,pra.named_role
3973 ,pra.txn_accum_header_id
3974 ,scheduled_delay --For Bug 3948128
3975 FROM PA_RESOURCE_ASSIGNMENTS pra,
3976 (SELECT TO_NUMBER(attribute15) source_task_id,
3977 proj_element_id target_task_id
3978 FROM pa_proj_elements
3979 WHERE project_id = l_target_project_id
3980 AND object_type='PA_TASKS'
3981 UNION ALL
3982 SELECT 0 source_task_id,
3983 0 target_task_id
3984 FROM dual) pelm
3985 WHERE pra.budget_version_id= p_source_plan_version_id
3986 AND pelm.source_task_id=pra.task_id;
3987
3988 END IF;--IF l_control_flag ='N' THEN
3989
3990 END IF;--ELSIF l_fin_plan_level_code <> 'P' THEN
3991
3992 END IF;--IF p_rbs_map_diff_flag ='N' THEN
3993
3994 l_tmp := SQL%ROWCOUNT;
3995 IF P_PA_DEBUG_MODE = 'Y' THEN
3996 pa_debug.g_err_stage:='No. of records inserted into PRA '||l_tmp;
3997 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
3998 END IF;
3999 /** Bug 6161031 When we copy the resource assignments ideally we should call the
4000 PA_PLANNING_RESOURCE_UTILS.get_resource_defaults and use the new
4001 attributes. But organization_id is the only column which is depending
4002 on the project when the resource format contains job and doesn't contain organization_id.
4003 So for all resource assignments with resource format having job in workplan if the
4004 organiztion_id is null in the pa_resource_list_members we are overriding
4005 with current project carrying_out_organization_id.
4006 */
4007 IF p_calling_context='WORKPLAN' THEN
4008
4009 select ppa.carrying_out_organization_id
4010 into l_project_org
4011 from pa_projects_all ppa,
4012 pa_budget_versions pbv
4013 where pbv.budget_version_id = p_target_plan_version_id
4014 and pbv.project_id = ppa.project_id;
4015
4016 update pa_resource_assignments
4017 set organization_id=l_project_org
4018 where resource_assignment_id in
4019 (select pra.resource_assignment_id
4020 from pa_resource_assignments pra,
4021 pa_resource_list_members prlm
4022 where pra.budget_version_id=p_target_plan_version_id
4023 and pra.resource_list_member_id=prlm.resource_list_member_id
4024 and pra.job_id = prlm.job_id
4025 and prlm.organization_id is null);
4026 END IF;
4027
4028 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
4029 IF P_PA_DEBUG_MODE = 'Y' THEN
4030 pa_debug.g_err_stage:='Exiting Copy_Resource_Assignments';
4031 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
4032 pa_debug.reset_err_stack; -- bug:- 2815593
4033 END IF;
4034 EXCEPTION
4035
4036 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
4037 l_msg_count := FND_MSG_PUB.count_msg;
4038 IF l_msg_count = 1 THEN
4039 PA_INTERFACE_UTILS_PUB.get_messages
4040 (p_encoded => FND_API.G_TRUE
4041 ,p_msg_index => 1
4042 ,p_msg_count => l_msg_count
4043 ,p_msg_data => l_msg_data
4044 ,p_data => l_data
4045 ,p_msg_index_out => l_msg_index_out);
4046 x_msg_data := l_data;
4047 x_msg_count := l_msg_count;
4048 ELSE
4049 x_msg_count := l_msg_count;
4050 END IF;
4051 x_return_status := FND_API.G_RET_STS_ERROR;
4052
4053 IF P_PA_DEBUG_MODE = 'Y' THEN
4054 pa_debug.g_err_stage:='Invalid Arguments Passed';
4055 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
4056 pa_debug.reset_err_stack;
4057 END IF;
4058 RAISE;
4059
4060 WHEN Others THEN
4061 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4062 x_msg_count := 1;
4063 x_msg_data := SQLERRM;
4064 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
4065 ,p_procedure_name => 'COPY_RESOURCE_ASSIGNMENTS');
4066
4067 IF P_PA_DEBUG_MODE = 'Y' THEN
4068 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
4069 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
4070 pa_debug.reset_err_stack;
4071 END IF;
4072 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4073
4074 END Copy_Resource_Assignments;
4075
4076 --Bug 4290043.This private API will be called from copy_budget_lines and Copy_Budget_Lines_Appr_Rev in this package
4077 --This API will
4078 ----1. Call pa_fp_upgrade_pkg.Apply_Calculate_FPM_Rules to get the missing amounts/rates in the target version
4079 ----2. Call PA_FP_CALC_PLAN_PKG.CheckZeroQTyNegETC to check for the negative ETC/Qty in the target version
4080 ----3. Update rate based flag for RAs in the target version if any RAs have to be converted to non rate based
4081 ----4. Update the budget lines with the missing amounts
4082 PROCEDURE derv_missing_amts_chk_neg_qty
4083 (p_budget_version_id IN pa_budget_versions.budget_version_id%TYPE,
4084 p_targ_pref_code IN pa_proj_fp_options.fin_plan_preference_code%TYPE,
4085 p_source_version_type IN pa_budget_versions.version_type%TYPE,
4086 p_target_version_type IN pa_budget_versions.version_type%TYPE,
4087 p_src_plan_class_code IN pa_fin_plan_types_b.plan_class_code%TYPE,
4088 p_derv_rates_missing_amts_flag IN VARCHAR2,
4089 p_adj_percentage IN NUMBER,
4090 x_return_status OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
4091 x_msg_count OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
4092 x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
4093 IS
4094
4095 l_msg_count NUMBER ;
4096 l_data VARCHAR2(2000);
4097 l_msg_data VARCHAR2(2000);
4098 l_error_msg_code VARCHAR2(2000);
4099 l_msg_index_out NUMBER;
4100 l_return_status VARCHAR2(2000);
4101 l_debug_mode VARCHAR2(30);
4102 l_module_name VARCHAR2(100);
4103
4104 l_bl_id_tbl SYSTEM.pa_num_tbl_type;
4105 l_ra_id_tbl SYSTEM.pa_num_tbl_type;
4106 l_quantity_tbl SYSTEM.pa_num_tbl_type;
4107 l_txn_raw_cost_tbl SYSTEM.pa_num_tbl_type;
4108 l_txn_burdened_cost_tbl SYSTEM.pa_num_tbl_type;
4109 l_txn_revenue_tbl SYSTEM.pa_num_tbl_type;
4110 l_rate_based_flag_tbl SYSTEM.pa_varchar2_1_tbl_type;
4111 l_raw_cost_override_rate_tbl SYSTEM.pa_num_tbl_type;
4112 l_burd_cost_override_rate_tbl SYSTEM.pa_num_tbl_type;
4113 l_bill_override_rate_tbl SYSTEM.pa_num_tbl_type;
4114 l_non_rb_ra_id_tbl SYSTEM.pa_num_tbl_type;
4115 l_bl_rb_flag_chg_tbl SYSTEM.pa_varchar2_1_tbl_type;
4116 l_target_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
4117 l_prev_ra_id pa_resource_assignments.resource_assignment_id%TYPE;
4118 l_temp_flag VARCHAR2(1);
4119 l_init_quantity_tbl SYSTEM.pa_num_tbl_type;
4120 l_txn_currency_code_tbl SYSTEM.pa_varchar2_15_tbl_type;
4121 l_temp NUMBER;
4122
4123 /* Bug 5078538 --Added the out variables to avoid the uninitialized collection
4124 error. Note that this error is caused when the same variables are passed as
4125 In and In Out parameters in a api call.
4126 */
4127 l_quantity_out_tbl SYSTEM.pa_num_tbl_type;
4128 l_txn_raw_cost_out_tbl SYSTEM.pa_num_tbl_type;
4129 l_txn_burdened_cost_out_tbl SYSTEM.pa_num_tbl_type;
4130 l_txn_revenue_out_tbl SYSTEM.pa_num_tbl_type;
4131
4132 BEGIN
4133
4134 x_msg_count := 0;
4135 x_return_status := FND_API.G_RET_STS_SUCCESS;
4136
4137 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
4138 l_debug_mode := NVL(l_debug_mode, 'Y');
4139 l_module_name := 'PAFPCPFB.mis_amts_chk_neg_qty';
4140
4141 -- Set curr function
4142 IF l_debug_mode='Y' THEN
4143 pa_debug.set_curr_function(
4144 p_function =>'PAFPCPFB.mis_amts_chk_neg_qty'
4145 ,p_debug_mode => l_debug_mode );
4146
4147 pa_debug.g_err_stage:= 'Validation Input Parameters';
4148 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4149
4150 END IF;
4151
4152
4153 IF p_budget_version_id IS NULL OR
4154 p_targ_pref_code IS NULL OR
4155 p_source_version_type IS NULL OR
4156 p_target_version_type IS NULL OR
4157 p_src_plan_class_code IS NULL OR
4158 p_derv_rates_missing_amts_flag IS NULL THEN
4159
4160 IF l_debug_mode='Y' THEN
4161
4162 pa_debug.g_err_stage:= 'p_budget_version_id '|| p_budget_version_id;
4163 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4164
4165 pa_debug.g_err_stage:= 'p_targ_pref_code '|| p_targ_pref_code;
4166 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4167
4168 pa_debug.g_err_stage:= 'p_source_version_type '|| p_source_version_type;
4169 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4170
4171 pa_debug.g_err_stage:= 'p_target_version_type '|| p_target_version_type;
4172 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4173
4174 pa_debug.g_err_stage:= 'p_src_plan_class_code '|| p_src_plan_class_code;
4175 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4176
4177 pa_debug.g_err_stage:= 'p_derv_rates_missing_amts_flag '|| p_derv_rates_missing_amts_flag;
4178 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4179
4180 END IF;
4181
4182 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
4183 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
4184 p_token1 => 'PROCEDURENAME',
4185 p_value1 => l_module_name,
4186 p_token2 => 'STAGE',
4187 p_value2 => 'Invalid Input Params');
4188
4189
4190 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4191
4192 END IF;
4193
4194
4195 --Select the budget lines in the target that should be processed for missing amounts and negative ETC/Qty Check
4196 SELECT bl.budget_line_id
4197 ,bl.resource_assignment_id
4198 ,nvl(bl.quantity,0)
4199 ,nvl(bl.txn_raw_cost,0)
4200 ,nvl(bl.txn_burdened_cost,0)
4201 ,nvl(bl.txn_revenue,0)
4202 ,nvl(ra.rate_based_flag,'N') rate_based_flag
4203 ,nvl(bl.init_quantity,0)
4204 ,bl.txn_currency_code
4205 BULK COLLECT INTO
4206 l_bl_id_tbl
4207 ,l_ra_id_tbl
4208 ,l_quantity_tbl
4209 ,l_txn_raw_cost_tbl
4210 ,l_txn_burdened_cost_tbl
4211 ,l_txn_revenue_tbl
4212 ,l_rate_based_flag_tbl
4213 ,l_init_quantity_tbl
4214 ,l_txn_currency_code_tbl
4215 FROM pa_budget_lines bl
4216 ,pa_resource_assignments ra
4217 WHERE bl.resource_assignment_id=ra.resource_assignment_id
4218 AND bl.budget_version_id=p_budget_version_id
4219 AND ra.budget_version_id=p_budget_version_id
4220 ORDER BY bl.resource_assignment_id ,bl.quantity NULLS FIRST;
4221
4222 --Retrun if no budget lines exist in the target
4223 IF l_bl_id_tbl.COUNT =0 THEN
4224
4225 IF l_debug_mode='Y' THEN
4226
4227 pa_debug.g_err_stage:= 'Budget Line count is 0';
4228 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4229
4230 pa_debug.reset_curr_function;
4231 END IF;
4232
4233 RETURN;
4234
4235 END IF;
4236
4237 --Derive the missing amounts/rates in the target.
4238 IF p_derv_rates_missing_amts_flag='Y' THEN
4239
4240 IF l_debug_mode='Y' THEN
4241
4242 pa_debug.g_err_stage:= 'Calling pa_fp_upgrade_pkg.Apply_Calculate_FPM_Rules';
4243 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4244
4245 END IF;
4246
4247 pa_fp_upgrade_pkg.Apply_Calculate_FPM_Rules
4248 ( p_preference_code => p_targ_pref_code
4249 ,p_resource_assignment_id_tbl => l_ra_id_tbl
4250 ,p_rate_based_flag_tbl => l_rate_based_flag_tbl
4251 ,p_quantity_tbl => l_quantity_tbl
4252 ,p_txn_raw_cost_tbl => l_txn_raw_cost_tbl
4253 ,p_txn_burdened_cost_tbl => l_txn_burdened_cost_tbl
4254 ,p_txn_revenue_tbl => l_txn_revenue_tbl
4255 ,x_quantity_tbl => l_quantity_out_tbl --Bug 5078538
4256 ,x_txn_raw_cost_tbl => l_txn_raw_cost_out_tbl --Bug 5078538
4257 ,x_txn_burdened_cost_tbl => l_txn_burdened_cost_out_tbl --Bug 5078538
4258 ,x_txn_revenue_tbl => l_txn_revenue_out_tbl --Bug 5078538
4259 ,x_raw_cost_override_rate_tbl => l_raw_cost_override_rate_tbl
4260 ,x_burd_cost_override_rate_tbl => l_burd_cost_override_rate_tbl
4261 ,x_bill_override_rate_tbl => l_bill_override_rate_tbl
4262 ,x_non_rb_ra_id_tbl => l_non_rb_ra_id_tbl
4263 ,x_return_status => l_return_status
4264 ,x_msg_count => l_msg_count
4265 ,x_msg_data => l_msg_data);
4266
4267 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4268 IF l_debug_mode = 'Y' THEN
4269 pa_debug.g_err_stage:= 'Error in pa_fp_upgrade_pkg.Apply_Calculate_FPM_Rules';
4270 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4271 END IF;
4272 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4273 END IF;
4274
4275 l_quantity_tbl := l_quantity_out_tbl; --Bug 5078538
4276 l_txn_raw_cost_tbl := l_txn_raw_cost_out_tbl; --Bug 5078538
4277 l_txn_burdened_cost_tbl := l_txn_burdened_cost_out_tbl; --Bug 5078538
4278 l_txn_revenue_tbl := l_txn_revenue_out_tbl; --Bug 5078538
4279
4280 IF p_source_version_type<>'ALL' AND
4281 p_src_plan_class_code <>'FORECAST' AND
4282 l_non_rb_ra_id_tbl.COUNT > 0 THEN
4283
4284
4285 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
4286 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
4287 p_token1 => 'PROCEDURENAME',
4288 p_value1 => l_module_name,
4289 p_token2 => 'STAGE',
4290 p_value2 => 'l_non_rb_ra_id_tbl.count for Non All Fcst version is '||l_non_rb_ra_id_tbl.COUNT);
4291
4292
4293 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4294
4295 END IF;
4296
4297 END IF;--IF p_derv_rates_missing_amts_flag='Y' THEN
4298
4299 /*
4300 Bug 5726773: Commented out the below debug statement as the call to api PA_FP_CALC_PLAN_PKG.CheckZeroQTyNegETC
4301 has been commented out.
4302 */
4303 /*
4304
4305 IF l_debug_mode='Y' THEN
4306
4307 pa_debug.g_err_stage:= 'Calling PA_FP_CALC_PLAN_PKG.CheckZeroQTyNegETC';
4308 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4309
4310 END IF;
4311 */
4312
4313 /* Bug 5726773:
4314 Start of coding done for Support of negative quantity/amounts enhancement.
4315 Call to the API CheckZeroQtyNegETC has been commented out below to allow
4316 copying of -ve quantity/amounts from the source version to target version.
4317 */
4318
4319 --Negative ETC/Qty for the budget lines in the target will be performed whenever the amounts in the source
4320 --or not copied directly (i.e. if the amounts in the source are modified while copying into target either
4321 --for deriving missing amounts or because of applying adj % )
4322 /*
4323 IF p_adj_percentage <> 0 OR
4324 p_derv_rates_missing_amts_flag ='Y' THEN
4325
4326 --Call the API to check for Negative ETC. Bug 4290043
4327 PA_FP_CALC_PLAN_PKG.CheckZeroQTyNegETC(
4328 p_calling_context => 'PLS_TBL'
4329 ,p_budget_version_id => p_budget_version_id
4330 ,p_initialize => 'Y'
4331 ,p_resource_assignment_id_tbl => l_ra_id_tbl
4332 ,p_quantity_tbl => l_quantity_tbl
4333 ,p_init_quantity_tbl => l_init_quantity_tbl
4334 ,p_txn_currency_code_tbl => l_txn_currency_code_tbl
4335 ,x_return_status => l_return_status
4336 ,x_msg_count => l_msg_count
4337 ,x_msg_data => l_msg_data);
4338
4339 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4340 IF l_debug_mode = 'Y' THEN
4341 pa_debug.g_err_stage:= 'Error in PA_FP_CALC_PLAN_PKG.CheckZeroQTyNegETC';
4342 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4343 END IF;
4344 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4345 END IF;
4346
4347 END IF;--IF p_adj_percentage <> 0 OR
4348 */
4349 /* Bug 5726773: End of coding done for Support of negative quantity/amounts enhancement. */
4350
4351 --Update the budget lines with the missing amounts/rates derived above.In the update the amount/rate
4352 --returned by the Apply_Calculate_FPM_Rules will be stamped on budget lines only when the rejection
4353 --codes do not exist for those budget lines.
4354 IF p_derv_rates_missing_amts_flag='Y' THEN
4355
4356 IF l_debug_mode='Y' THEN
4357
4358 pa_debug.g_err_stage:= 'p_source_version_type '||p_source_version_type;
4359 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4360
4361 pa_debug.g_err_stage:= 'p_target_version_type '||p_target_version_type;
4362 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4363
4364 END IF;
4365
4366 IF p_source_version_type='COST' THEN
4367
4368 IF p_target_version_type='COST' THEN
4369
4370 FORALL kk IN 1..l_bl_id_tbl.COUNT
4371
4372 UPDATE pa_budget_lines
4373 SET txn_cost_rate_override = DECODE(cost_rejection_code, NULL,l_raw_cost_override_rate_tbl(kk),txn_cost_rate_override),
4374 burden_cost_rate_override = DECODE(burden_rejection_code, NULL,l_burd_cost_override_rate_tbl(kk),burden_cost_rate_override)
4375 WHERE budget_line_id = l_bl_id_tbl(kk);
4376
4377 ELSIF p_target_version_type='ALL' THEN
4378
4379 FORALL kk IN 1..l_bl_id_tbl.COUNT
4380
4381 UPDATE pa_budget_lines
4382 SET txn_cost_rate_override = DECODE(cost_rejection_code, NULL,l_raw_cost_override_rate_tbl(kk),txn_cost_rate_override),
4383 burden_cost_rate_override = DECODE(burden_rejection_code, NULL,l_burd_cost_override_rate_tbl(kk),burden_cost_rate_override),
4384 txn_revenue = DECODE(revenue_rejection_code, NULL,l_txn_revenue_tbl(kk),txn_revenue),
4385 txn_bill_rate_override = DECODE(revenue_rejection_code, NULL,l_bill_override_rate_tbl(kk),txn_bill_rate_override)
4386 WHERE budget_line_id = l_bl_id_tbl(kk);
4387
4388 END IF;
4389
4390 ELSIF p_source_version_type='REVENUE' THEN
4391
4392 IF p_target_version_type='REVENUE' THEN
4393
4394 FORALL kk IN 1..l_bl_id_tbl.COUNT
4395
4396 UPDATE pa_budget_lines
4397 SET txn_bill_rate_override = DECODE(revenue_rejection_code, NULL,l_bill_override_rate_tbl(kk),txn_bill_rate_override)
4398 WHERE budget_line_id = l_bl_id_tbl(kk);
4399
4400 ELSIF p_target_version_type='ALL' THEN
4401
4402 FORALL kk IN 1..l_bl_id_tbl.COUNT
4403
4404 UPDATE pa_budget_lines
4405 SET quantity = l_quantity_tbl(kk),
4406 txn_raw_cost = DECODE(cost_rejection_code, NULL,l_txn_raw_cost_tbl(kk),txn_raw_cost),
4407 txn_burdened_cost = DECODE(burden_rejection_code, NULL,l_txn_burdened_cost_tbl(kk),txn_burdened_cost),
4408 txn_cost_rate_override = DECODE(cost_rejection_code, NULL,l_raw_cost_override_rate_tbl(kk),txn_cost_rate_override),
4409 burden_cost_rate_override = DECODE(burden_rejection_code, NULL,l_burd_cost_override_rate_tbl(kk),burden_cost_rate_override),
4410 txn_bill_rate_override = DECODE(revenue_rejection_code, NULL,l_bill_override_rate_tbl(kk),txn_bill_rate_override)
4411 WHERE budget_line_id = l_bl_id_tbl(kk);
4412
4413 END IF;
4414
4415 ELSIF p_source_version_type='ALL' THEN
4416
4417 --In case of an All Forecast version, there can be budget lines with actuals in which revenue
4418 --alone is populated and other amounts are null. When these budget lines are copied into a
4419 --version which is not an All Forecats version then the corresponding resource assignments in the
4420 --target will be made non rate based. The below DML updates all such resource assignments to non rate based
4421
4422 --Update the rate based flag to N for the ids in l_non_rb_ra_id_tbl
4423 FORALL kk IN 1..l_non_rb_ra_id_tbl.COUNT
4424
4425 UPDATE pa_resource_assignments
4426 SET rate_based_flag = 'N'
4427 ,unit_of_measure = 'DOLLARS'
4428 WHERE resource_assignment_id=l_non_rb_ra_id_tbl(kk);
4429
4430 --The pa_fp_upgrade_pkg.Apply_Calculate_FPM_Rules API will return a pl-sql tbl of RA ids which can
4431 --be made non rate based. Note that this might not be equal in length to the input l_ra_id_tbl to that API
4432 --The below block will prepare a pl-sql tbl l_bl_rb_flag_chg_tbl which will be equal in length to l_ra_id_tbl
4433 --This tbl will have Y if the ra id is made non rate based . Otherwise it will contain N
4434 l_bl_rb_flag_chg_tbl := SYSTEM.pa_varchar2_1_tbl_type();
4435 IF p_src_plan_class_code = 'FORECAST' THEN
4436
4437 IF l_debug_mode='Y' THEN
4438
4439 FOR kk IN 1..l_non_rb_ra_id_tbl.COUNT LOOP
4440
4441 pa_debug.g_err_stage:= 'l_non_rb_ra_id_tbl('||kk||')'||l_non_rb_ra_id_tbl(kk);
4442 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4443
4444 END LOOP;
4445
4446 FOR kk IN 1..l_ra_id_tbl.COUNT LOOP
4447
4448 pa_debug.g_err_stage:= 'l_ra_id_tbl('||kk||')'||l_ra_id_tbl(kk);
4449 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4450 END LOOP;
4451
4452 END IF;
4453
4454 l_temp:=1;
4455 FOR kk IN 1..l_non_rb_ra_id_tbl.COUNT LOOP
4456
4457 LOOP
4458 EXIT WHEN l_non_rb_ra_id_tbl(kk)= l_ra_id_tbl(l_temp);
4459 l_bl_rb_flag_chg_tbl.extend;
4460 l_bl_rb_flag_chg_tbl(l_temp):='N';
4461 l_temp := l_temp+1;
4462 END LOOP;
4463
4464 l_prev_ra_id := l_ra_id_tbl(l_temp);
4465 LOOP
4466 l_bl_rb_flag_chg_tbl.extend;
4467 l_bl_rb_flag_chg_tbl(l_temp) := 'Y';
4468 l_temp := l_temp + 1;
4469 EXIT WHEN l_temp > l_ra_id_tbl.COUNT OR l_ra_id_tbl(l_temp) <> l_prev_ra_id;
4470
4471 END LOOP;
4472
4473 END LOOP;
4474
4475 END IF;
4476
4477 IF l_debug_mode='Y' THEN
4478
4479 pa_debug.g_err_stage:= 'l_bl_rb_flag_chg_tbl.COUNT '||l_bl_rb_flag_chg_tbl.COUNT;
4480 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4481
4482 END IF;
4483
4484 FOR kk IN l_bl_rb_flag_chg_tbl.COUNT+1..l_ra_id_tbl.COUNT LOOP
4485
4486 l_bl_rb_flag_chg_tbl.extend;
4487 l_bl_rb_flag_chg_tbl(kk):='N';
4488
4489 END LOOP;
4490
4491 IF l_debug_mode='Y' THEN
4492
4493 pa_debug.g_err_stage:= 'l_bl_rb_flag_chg_tbl.COUNT '||l_bl_rb_flag_chg_tbl.COUNT;
4494 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4495
4496 pa_debug.g_err_stage:= 'l_ra_id_tbl.COUNT '||l_ra_id_tbl.COUNT;
4497 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4498
4499 FOR kk IN 1..l_bl_rb_flag_chg_tbl.COUNT LOOP
4500
4501 pa_debug.g_err_stage:= 'l_bl_rb_flag_chg_tbl('||kk||')'||l_bl_rb_flag_chg_tbl(kk);
4502 pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4503 END LOOP;
4504
4505 END IF;
4506
4507
4508 --The below block will update the budget lines with missing amounts.
4509 ----If the resource assignment assignment is made non rate based then the amount returned by the
4510 ----Apply_Calculate_FPM_Rules will be stamped on budget lines. Also the rejection codes for that amount
4511 ----will be NULLed out accordingly
4512 IF p_target_version_type='COST' THEN
4513
4514 FORALL kk IN 1..l_bl_id_tbl.COUNT
4515
4516 UPDATE pa_budget_lines
4517 SET quantity = l_quantity_tbl(kk),
4518 txn_raw_cost = DECODE (l_bl_rb_flag_chg_tbl(kk),
4519 'Y',l_txn_raw_cost_tbl(kk),
4520 DECODE(cost_rejection_code,
4521 NULL,l_txn_raw_cost_tbl(kk),
4522 txn_raw_cost)),
4523 txn_burdened_cost = DECODE (l_bl_rb_flag_chg_tbl(kk),
4524 'Y',l_txn_burdened_cost_tbl(kk),
4525 DECODE(burden_rejection_code,
4526 NULL,l_txn_burdened_cost_tbl(kk),
4527 txn_burdened_cost)),
4528 txn_cost_rate_override = DECODE (l_bl_rb_flag_chg_tbl(kk),
4529 'Y',l_raw_cost_override_rate_tbl(kk),
4530 DECODE(cost_rejection_code,
4531 NULL,l_raw_cost_override_rate_tbl(kk),
4532 txn_cost_rate_override)),
4533 burden_cost_rate_override = DECODE (l_bl_rb_flag_chg_tbl(kk),
4534 'Y',l_burd_cost_override_rate_tbl(kk),
4535 DECODE(burden_rejection_code,
4536 NULL,l_burd_cost_override_rate_tbl(kk),
4537 burden_cost_rate_override)),
4538 cost_rejection_code = DECODE (l_bl_rb_flag_chg_tbl(kk),
4539 'Y',NULL,
4540 cost_rejection_code),
4541 burden_rejection_code = DECODE (l_bl_rb_flag_chg_tbl(kk),
4542 'Y',NULL,
4543 burden_rejection_code)
4544 WHERE budget_line_id = l_bl_id_tbl(kk);
4545
4546
4547
4548 ELSIF p_target_version_type='REVENUE' THEN
4549
4550 FORALL kk IN 1..l_bl_id_tbl.COUNT
4551
4552 UPDATE pa_budget_lines
4553 SET quantity = l_quantity_tbl(kk),
4554 txn_revenue = DECODE (l_bl_rb_flag_chg_tbl(kk),
4555 'Y',l_txn_revenue_tbl(kk),
4556 DECODE(revenue_rejection_code,
4557 NULL,l_txn_revenue_tbl(kk),
4558 txn_revenue)),
4559 txn_bill_rate_override = DECODE (l_bl_rb_flag_chg_tbl(kk),
4560 'Y',l_bill_override_rate_tbl(kk),
4561 DECODE(revenue_rejection_code,
4562 NULL,l_bill_override_rate_tbl(kk),
4563 txn_bill_rate_override)),
4564 revenue_rejection_code = DECODE (l_bl_rb_flag_chg_tbl(kk),
4565 'Y',NULL,
4566 revenue_rejection_code)
4567 WHERE budget_line_id = l_bl_id_tbl(kk);
4568
4569 ELSIF p_target_version_type='ALL' THEN
4570
4571 FORALL kk IN 1..l_bl_id_tbl.COUNT
4572
4573 UPDATE pa_budget_lines
4574 SET quantity = l_quantity_tbl(kk),
4575 txn_raw_cost = DECODE (l_bl_rb_flag_chg_tbl(kk),
4576 'Y',l_txn_raw_cost_tbl(kk),
4577 DECODE(cost_rejection_code,
4578 NULL,l_txn_raw_cost_tbl(kk),
4579 txn_raw_cost)),
4580 txn_burdened_cost = DECODE (l_bl_rb_flag_chg_tbl(kk),
4581 'Y',l_txn_burdened_cost_tbl(kk),
4582 DECODE(burden_rejection_code,
4583 NULL,l_txn_burdened_cost_tbl(kk),
4584 txn_burdened_cost)),
4585 txn_revenue = DECODE (l_bl_rb_flag_chg_tbl(kk),
4586 'Y',l_txn_revenue_tbl(kk),
4587 DECODE(revenue_rejection_code,
4588 NULL,l_txn_revenue_tbl(kk),
4589 txn_revenue)),
4590 txn_cost_rate_override = DECODE (l_bl_rb_flag_chg_tbl(kk),
4591 'Y',l_raw_cost_override_rate_tbl(kk),
4592 DECODE(cost_rejection_code,
4593 NULL,l_raw_cost_override_rate_tbl(kk),
4594 txn_cost_rate_override)),
4595 burden_cost_rate_override = DECODE (l_bl_rb_flag_chg_tbl(kk),
4596 'Y',l_burd_cost_override_rate_tbl(kk),
4597 DECODE(burden_rejection_code,
4598 NULL,l_burd_cost_override_rate_tbl(kk),
4599 burden_cost_rate_override)),
4600 txn_bill_rate_override = DECODE (l_bl_rb_flag_chg_tbl(kk),
4601 'Y',l_bill_override_rate_tbl(kk),
4602 DECODE(revenue_rejection_code,
4603 NULL,l_bill_override_rate_tbl(kk),
4604 txn_bill_rate_override)),
4605 cost_rejection_code = DECODE (l_bl_rb_flag_chg_tbl(kk),
4606 'Y',NULL,
4607 cost_rejection_code),
4608 burden_rejection_code = DECODE (l_bl_rb_flag_chg_tbl(kk),
4609 'Y',NULL,
4610 burden_rejection_code),
4611 revenue_rejection_code = DECODE (l_bl_rb_flag_chg_tbl(kk),
4612 'Y',NULL,
4613 revenue_rejection_code)
4614
4615 WHERE budget_line_id = l_bl_id_tbl(kk);
4616
4617 END IF;
4618
4619 END IF;--IF l_source_version_type='COST' THEN
4620
4621 END IF;--IF p_derv_rates_missing_amts_flag='Y' THEN
4622
4623 IF l_debug_mode='Y' THEN
4624
4625 pa_debug.g_err_stage:= 'Leaving '||l_module_name;
4626 pa_debug.write(l_module_name,pa_debug.g_err_stage,5);
4627
4628 pa_debug.reset_curr_function;
4629 END IF;
4630
4631 EXCEPTION
4632 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
4633 l_msg_count := FND_MSG_PUB.count_msg;
4634 IF l_msg_count = 1 THEN
4635 PA_INTERFACE_UTILS_PUB.get_messages
4636 (p_encoded => FND_API.G_TRUE
4637 ,p_msg_index => 1
4638 ,p_msg_count => l_msg_count
4639 ,p_msg_data => l_msg_data
4640 ,p_data => l_data
4641 ,p_msg_index_out => l_msg_index_out);
4642
4643 x_msg_data := l_data;
4644 x_msg_count := l_msg_count;
4645 ELSE
4646 x_msg_count := l_msg_count;
4647 END IF;
4648 x_return_status := FND_API.G_RET_STS_ERROR;
4649
4650 IF l_debug_mode = 'Y' THEN
4651 pa_debug.g_err_stage:='Invalid Arguments Passed Or called api raised an error';
4652 pa_debug.write( l_module_name,pa_debug.g_err_stage,5);
4653 -- reset curr function
4654 pa_debug.reset_curr_function();
4655 END IF;
4656 RETURN;
4657 WHEN OTHERS THEN
4658 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4659 x_msg_count := 1;
4660 x_msg_data := SQLERRM;
4661
4662 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'pa_fp_copy_from_pkg'
4663 ,p_procedure_name => 'derv_missing_amts_chk_neg_qty');
4664
4665 IF l_debug_mode = 'Y' THEN
4666 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
4667 pa_debug.write( l_module_name,pa_debug.g_err_stage,5);
4668 -- reset curr function
4669 pa_debug.reset_curr_function();
4670 END IF;
4671 RAISE;
4672
4673 END derv_missing_amts_chk_neg_qty;
4674
4675
4676
4677 /*=========================================================================
4678 This api inserts budget lines for target using source budget lines. If
4679 the adjustment percentage is zero, this api will copy from source to
4680 target version without modifying any amounts. If adjustment percentage is
4681 non-zero,then we don't copy project and project functional columns as
4682 these need to be converted again and might cause rounding issues
4683 This is an overloaded procedure
4684
4685 -- r11.5 FP.M Developement ----------------------------------
4686 --
4687 -- 08-JAN-04 jwhite - Bug 3362316
4688 -- Rewrote Copy_Budget_Lines
4689 --
4690 --Bug 4290043. Introduced the paramters p_copy_actuals_flag and p_derv_rates_missing_amts_flag.
4691 --These will be passed from copy_version API. p_copy_actuals_flag indicates whether to copy the
4692 --actuals from the source version or not. p_derv_rates_missing_amts_flag indicates whether the
4693 --target version contains missing amounts rates which should be derived after copy
4694 =========================================================================*/
4695
4696 PROCEDURE Copy_Budget_Lines(
4697 p_source_plan_version_id IN NUMBER
4698 ,p_target_plan_version_id IN NUMBER
4699 ,p_adj_percentage IN NUMBER
4700 ,p_copy_actuals_flag IN VARCHAR2
4701 ,p_derv_rates_missing_amts_flag IN VARCHAR2
4702 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4703 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
4704 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
4705 AS
4706
4707 l_msg_count NUMBER :=0;
4708 l_data VARCHAR2(2000);
4709 l_msg_data VARCHAR2(2000);
4710 l_error_msg_code VARCHAR2(2000);
4711 l_msg_index_out NUMBER;
4712 l_return_status VARCHAR2(2000);
4713 l_debug_mode VARCHAR2(30);
4714
4715 l_source_period_profile_id pa_budget_versions.period_profile_id%TYPE;
4716 l_target_period_profile_id pa_budget_versions.period_profile_id%TYPE;
4717
4718 l_revenue_flag pa_fin_plan_amount_sets.revenue_flag%type;
4719 l_cost_flag pa_fin_plan_amount_sets.raw_cost_flag%type;
4720
4721 l_adj_percentage NUMBER ;
4722 l_period_profiles_same_flag VARCHAR2(1);
4723
4724 l_src_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
4725 l_trg_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
4726 l_wp_version_flag pa_budget_versions.wp_version_flag%TYPE;
4727
4728 l_etc_start_date pa_budget_versions.etc_start_date%TYPE;
4729 l_temp NUMBER;
4730
4731 l_source_version_type pa_budget_versions.version_type%TYPE;
4732 l_target_version_type pa_budget_versions.version_type%TYPE;
4733 l_source_project_id pa_budget_versions.project_id%TYPE; -- Bug 4493425
4734 l_target_project_id pa_budget_versions.project_id%TYPE; -- Bug 4493425
4735
4736 -- Bug 4493425: Added pbv.project_id in the select.
4737 CURSOR get_plan_class_code_csr(c_budget_version_id pa_budget_versions.budget_version_id%TYPE) IS
4738 SELECT pfb.plan_class_code,nvl(pbv.wp_version_flag,'N'),etc_start_date,pbv.version_type,pbv.project_id
4739 FROM pa_fin_plan_types_b pfb,
4740 pa_budget_versions pbv
4741 WHERE pbv.budget_version_id = c_budget_version_id
4742 AND pbv.fin_plan_type_id = pfb.fin_plan_type_id;
4743 -- Bug 3927244
4744
4745 --Bug 4290043
4746 l_target_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
4747
4748
4749 BEGIN
4750
4751 x_msg_count := 0;
4752 x_return_status := FND_API.G_RET_STS_SUCCESS;
4753 IF P_PA_DEBUG_MODE = 'Y' THEN
4754 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Budget_Lines');
4755 END IF;
4756 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
4757 l_debug_mode := NVL(l_debug_mode, 'Y');
4758 IF P_PA_DEBUG_MODE = 'Y' THEN
4759 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
4760 END IF;
4761 -- Checking for all valid input parametrs
4762
4763 IF P_PA_DEBUG_MODE = 'Y' THEN
4764 pa_debug.g_err_stage := 'Checking for valid parameters:';
4765 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4766 END IF;
4767
4768 IF (p_source_plan_version_id IS NULL) OR
4769 (p_target_plan_version_id IS NULL)
4770 THEN
4771
4772 IF P_PA_DEBUG_MODE = 'Y' THEN
4773 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
4774 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
4775 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
4776 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
4777 END IF;
4778
4779 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
4780 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
4781
4782 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4783
4784 END IF;
4785
4786 IF P_PA_DEBUG_MODE = 'Y' THEN
4787 pa_debug.g_err_stage := 'Parameter validation complete';
4788 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4789 END IF;
4790 /*
4791 pa_debug.g_err_stage:='Source fin plan version id'||p_source_plan_version_id;
4792 IF P_PA_DEBUG_MODE = 'Y' THEN
4793 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4794 END IF;
4795 pa_debug.g_err_stage:='Target fin plan version id'||p_target_plan_version_id;
4796 IF P_PA_DEBUG_MODE = 'Y' THEN
4797 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4798 END IF;
4799 */
4800 --make adj percentage zero if passed as null
4801
4802 l_adj_percentage := NVL(p_adj_percentage,0);
4803 /*
4804 pa_debug.g_err_stage:='Adj_percentage'||l_adj_percentage;
4805 IF P_PA_DEBUG_MODE = 'Y' THEN
4806 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4807 END IF;
4808 */
4809 -- Fetching the flags of target version using fin_plan_prefernce_code
4810
4811
4812 IF P_PA_DEBUG_MODE = 'Y' THEN
4813 pa_debug.g_err_stage:='Fetching the raw_cost,burdened_cost and revenue flags of target_version';
4814 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4815 END IF;
4816
4817 --Bug 4290043. Selected preference code for the target version
4818 SELECT DECODE(fin_plan_preference_code -- l_revenue_flag
4819 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY ,'Y'
4820 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME ,'Y','N')
4821 ,DECODE(fin_plan_preference_code -- l_cost_flag
4822 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY ,'Y'
4823 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME , 'Y','N')
4824 ,fin_plan_preference_code
4825 INTO l_revenue_flag
4826 ,l_cost_flag
4827 ,l_target_pref_code
4828 FROM pa_proj_fp_options
4829 WHERE fin_plan_version_id=p_target_plan_version_id;
4830 /*
4831 pa_debug.g_err_stage:='l_revenue_flag ='||l_revenue_flag;
4832 IF P_PA_DEBUG_MODE = 'Y' THEN
4833 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4834 END IF;
4835 pa_debug.g_err_stage:='l_cost_flag ='||l_cost_flag;
4836 IF P_PA_DEBUG_MODE = 'Y' THEN
4837 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4838 END IF;
4839 */
4840 -- Checking if source and target version period profiles match
4841
4842 /* FPB2: REVIEW */
4843
4844
4845 IF P_PA_DEBUG_MODE = 'Y' THEN
4846 pa_debug.g_err_stage:='Inserting budget_lines';
4847 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
4848 END IF;
4849
4850 -- Bug 3927244: Actuals need to be copied from forecast to forecast within the same project for FINPLAN versions
4851
4852 -- Bug 4493425: Added l_source_project_id in the INTO clause.
4853 OPEN get_plan_class_code_csr(p_source_plan_version_id);
4854 FETCH get_plan_class_code_csr
4855 INTO l_src_plan_class_code,l_wp_version_flag,l_etc_start_date,l_source_version_type,l_source_project_id;
4856 CLOSE get_plan_class_code_csr;
4857
4858 -- Bug 4493425: Added l_target_project_id in the INTO clause.
4859 OPEN get_plan_class_code_csr(p_target_plan_version_id);
4860 FETCH get_plan_class_code_csr
4861 INTO l_trg_plan_class_code,l_wp_version_flag,l_etc_start_date,l_target_version_type,l_target_project_id;
4862 CLOSE get_plan_class_code_csr;
4863
4864
4865 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
4866 --Bug 4052403. For non rate-based transactions quantity should be same as raw cost if the version type is COST/ALL or
4867 --it should be revenue if the version type is REVENUE. This business rule will be taken care by the API
4868 --PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts which is called after this INSERT. Note that this has to be done only
4869 --when adjustment% is not null since the amounts in the source will be altered only when the user enters some adj %
4870 --Bug 4188225. PC/PFC buckets will be copied unconditionally (Removed the condition that checks for l_adj_percentage
4871 --being greater than 0 in order to copy)
4872
4873 --Bug 4290043.Used p_copy_actuals_flag and p_derv_rates_missing_amts_flag to decide on copying actuals/rates
4874 --If p_derv_rates_missing_amts_flag is Y then rates will not be copied and the derv_missing_amts_chk_neg_qty
4875 --API called later on will stamp them on budget lines
4876 --Display_quantity is being set in copy_version and copy_finplans_from_project api as well
4877 INSERT INTO PA_BUDGET_LINES(
4878 budget_line_id /* FPB2 */
4879 ,budget_version_id /* FPB2 */
4880 ,resource_assignment_id
4881 ,start_date
4882 ,last_update_date
4883 ,last_updated_by
4884 ,creation_date
4885 ,created_by
4886 ,last_update_login
4887 ,end_date
4888 ,period_name
4889 ,quantity
4890 ,display_quantity --IPM Arch Enhancement Bug 4865563.
4891 ,raw_cost
4892 ,burdened_cost
4893 ,revenue
4894 ,change_reason_code
4895 ,description
4896 ,attribute_category
4897 ,attribute1
4898 ,attribute2
4899 ,attribute3
4900 ,attribute4
4901 ,attribute5
4902 ,attribute6
4903 ,attribute7
4904 ,attribute8
4905 ,attribute9
4906 ,attribute10
4907 ,attribute11
4908 ,attribute12
4909 ,attribute13
4910 ,attribute14
4911 ,attribute15
4912 ,raw_cost_source
4913 ,burdened_cost_source
4914 ,quantity_source
4915 ,revenue_source
4916 ,pm_product_code
4917 ,pm_budget_line_reference
4918 ,cost_rejection_code
4919 ,revenue_rejection_code
4920 ,burden_rejection_code
4921 ,other_rejection_code
4922 ,code_combination_id
4923 ,ccid_gen_status_code
4924 ,ccid_gen_rej_message
4925 ,request_id
4926 ,borrowed_revenue
4927 ,tp_revenue_in
4928 ,tp_revenue_out
4929 ,revenue_adj
4930 ,lent_resource_cost
4931 ,tp_cost_in
4932 ,tp_cost_out
4933 ,cost_adj
4934 ,unassigned_time_cost
4935 ,utilization_percent
4936 ,utilization_hours
4937 ,utilization_adj
4938 ,capacity
4939 ,head_count
4940 ,head_count_adj
4941 ,projfunc_currency_code
4942 ,projfunc_cost_rate_type
4943 ,projfunc_cost_exchange_rate
4944 ,projfunc_cost_rate_date_type
4945 ,projfunc_cost_rate_date
4946 ,projfunc_rev_rate_type
4947 ,projfunc_rev_exchange_rate
4948 ,projfunc_rev_rate_date_type
4949 ,projfunc_rev_rate_date
4950 ,project_currency_code
4951 ,project_cost_rate_type
4952 ,project_cost_exchange_rate
4953 ,project_cost_rate_date_type
4954 ,project_cost_rate_date
4955 ,project_raw_cost
4956 ,project_burdened_cost
4957 ,project_rev_rate_type
4958 ,project_rev_exchange_rate
4959 ,project_rev_rate_date_type
4960 ,project_rev_rate_date
4961 ,project_revenue
4962 ,txn_raw_cost
4963 ,txn_burdened_cost
4964 ,txn_currency_code
4965 ,txn_revenue
4966 ,bucketing_period_code
4967 ,transfer_price_rate
4968 ,init_quantity
4969 ,init_quantity_source
4970 ,init_raw_cost
4971 ,init_burdened_cost
4972 ,init_revenue
4973 ,init_raw_cost_source
4974 ,init_burdened_cost_source
4975 ,init_revenue_source
4976 ,project_init_raw_cost
4977 ,project_init_burdened_cost
4978 ,project_init_revenue
4979 ,txn_init_raw_cost
4980 ,txn_init_burdened_cost
4981 ,txn_init_revenue
4982 ,txn_markup_percent
4983 ,txn_markup_percent_override
4984 ,txn_discount_percentage
4985 ,txn_standard_bill_rate
4986 ,txn_standard_cost_rate
4987 ,txn_cost_rate_override
4988 ,burden_cost_rate
4989 ,txn_bill_rate_override
4990 ,burden_cost_rate_override
4991 ,cost_ind_compiled_set_id
4992 ,pc_cur_conv_rejection_code
4993 ,pfc_cur_conv_rejection_code
4994 )
4995 SELECT pa_budget_lines_s.nextval /* FPB2 */
4996 ,p_target_plan_version_id /* FPB2 */
4997 ,pra.resource_assignment_id
4998 ,pbl.start_date
4999 ,sysdate
5000 ,fnd_global.user_id
5001 ,sysdate
5002 ,fnd_global.user_id
5003 ,fnd_global.login_id
5004 ,pbl.end_date
5005 ,pbl.period_name
5006 ,pbl.quantity
5007 ,pbl.display_quantity --IPM Arch Enhancement Bug 4865563.
5008 ,DECODE(l_cost_flag,'Y', raw_cost,NULL)
5009 ,DECODE(l_cost_flag,'Y', burdened_cost,NULL)
5010 ,DECODE(l_revenue_flag,'Y', revenue,NULL)
5011 ,pbl.change_reason_code
5012 ,description
5013 ,pbl.attribute_category
5014 ,pbl.attribute1
5015 ,pbl.attribute2
5016 ,pbl.attribute3
5017 ,pbl.attribute4
5018 ,pbl.attribute5
5019 ,pbl.attribute6
5020 ,pbl.attribute7
5021 ,pbl.attribute8
5022 ,pbl.attribute9
5023 ,pbl.attribute10
5024 ,pbl.attribute11
5025 ,pbl.attribute12
5026 ,pbl.attribute13
5027 ,pbl.attribute14
5028 ,pbl.attribute15
5029 ,DECODE(l_cost_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --raw_cost_souce
5030 ,DECODE(l_cost_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --burdened_cost_source
5031 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P --quantity_source
5032 ,DECODE(l_revenue_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --revenue source
5033 ,pbl.pm_product_code
5034 ,pbl.pm_budget_line_reference
5035 ,DECODE(l_cost_flag, 'Y',cost_rejection_code, NULL)
5036 ,DECODE(l_revenue_flag, 'Y',revenue_rejection_code, NULL)
5037 ,DECODE(l_cost_flag,'Y',burden_rejection_code, NULL)
5038 ,other_rejection_code
5039 ,code_combination_id
5040 ,ccid_gen_status_code
5041 ,ccid_gen_rej_message
5042 ,fnd_global.conc_request_id
5043 ,borrowed_revenue
5044 ,tp_revenue_in
5045 ,tp_revenue_out
5046 ,revenue_adj
5047 ,lent_resource_cost
5048 ,tp_cost_in
5049 ,tp_cost_out
5050 ,cost_adj
5051 ,unassigned_time_cost
5052 ,utilization_percent
5053 ,utilization_hours
5054 ,utilization_adj
5055 ,capacity
5056 ,head_count
5057 ,head_count_adj
5058 ,projfunc_currency_code
5059 ,DECODE(l_cost_flag,'Y',projfunc_cost_rate_type,NULL)
5060 ,DECODE(l_cost_flag,'Y',projfunc_cost_exchange_rate,NULL)
5061 ,DECODE(l_cost_flag,'Y',projfunc_cost_rate_date_type,NULL)
5062 ,DECODE(l_cost_flag,'Y',projfunc_cost_rate_date,NULL)
5063 ,DECODE(l_revenue_flag,'Y',projfunc_rev_rate_type,NULL)
5064 ,DECODE(l_revenue_flag,'Y',projfunc_rev_exchange_rate,NULL)
5065 ,DECODE(l_revenue_flag,'Y',projfunc_rev_rate_date_type,NULL)
5066 ,DECODE(l_revenue_flag,'Y',projfunc_rev_rate_date,NULL)
5067 ,project_currency_code
5068 ,DECODE(l_cost_flag,'Y',project_cost_rate_type,NULL)
5069 ,DECODE(l_cost_flag,'Y',project_cost_exchange_rate,NULL)
5070 ,DECODE(l_cost_flag,'Y',project_cost_rate_date_type,NULL)
5071 ,DECODE(l_cost_flag,'Y',project_cost_rate_date,NULL)
5072 ,DECODE(l_cost_flag,'Y', project_raw_cost,NULL)
5073 ,DECODE(l_cost_flag,'Y', project_burdened_cost,NULL)
5074 ,DECODE(l_revenue_flag,'Y',project_rev_rate_type,NULL)
5075 ,DECODE(l_revenue_flag,'Y',project_rev_exchange_rate,NULL)
5076 ,DECODE(l_revenue_flag,'Y',project_rev_rate_date_type,NULL)
5077 ,DECODE(l_revenue_flag,'Y',project_rev_rate_date,NULL)
5078 ,DECODE(l_revenue_flag,'Y', project_revenue,NULL)
5079 ,DECODE(l_cost_flag,'Y',
5080 decode(GREATEST(pbl.start_date,NVL(l_etc_start_date,pbl.start_date)),pbl.start_date,txn_raw_cost*(1+l_adj_percentage),txn_raw_cost),NULL)
5081 ,DECODE(l_cost_flag,'Y',
5082 decode(GREATEST(pbl.start_date,NVL(l_etc_start_date,pbl.start_date)),pbl.start_date,txn_burdened_cost*(1+l_adj_percentage),txn_burdened_cost),NULL)
5083 ,txn_currency_code
5084 ,DECODE(l_revenue_flag,'Y',
5085 decode(GREATEST(pbl.start_date,NVL(l_etc_start_date,pbl.start_date)),pbl.start_date,txn_revenue*(1+l_adj_percentage),txn_revenue),NULL)
5086 ,DECODE(l_period_profiles_same_flag,'Y',bucketing_period_code,NULL)
5087 ,transfer_price_rate
5088 ,decode(p_copy_actuals_flag,'N',NULL,pbl.init_quantity) --init_quantity
5089 ,decode(p_copy_actuals_flag,'N',NULL,pbl.init_quantity_source) --init_quantity_source
5090 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.init_raw_cost),NULL) --init_raw_cost
5091 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.init_burdened_cost),NULL) --init_burdened_cost
5092 ,DECODE(l_revenue_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.init_revenue),NULL) --init_revenue
5093 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.init_raw_cost_source),NULL) --init_raw_cost_source
5094 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.init_burdened_cost_source),NULL) --init_burdened_cost_source
5095 ,DECODE(l_revenue_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.init_revenue_source),NULL) --init_revenue_source
5096 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.project_init_raw_cost),NULL) --project_init_raw_cost
5097 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.project_init_burdened_cost),NULL) --project_init_burdened_cost
5098 ,DECODE(l_revenue_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.project_init_revenue),NULL) --project_init_revenue
5099 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.txn_init_raw_cost),NULL) --txn_init_raw_cost
5100 ,DECODE(l_cost_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.txn_init_burdened_cost),NULL) --txn_init_burdened_cost
5101 ,DECODE(l_revenue_flag,'Y',decode(p_copy_actuals_flag,'N',NULL,pbl.txn_init_revenue),NULL) --txn_init_revenue
5102 ,txn_markup_percent
5103 ,txn_markup_percent_override
5104 ,txn_discount_percentage
5105 ,Decode(l_revenue_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',txn_standard_bill_rate,NULL),NULL) --txn_standard_bill_rate
5106 ,Decode(l_cost_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',txn_standard_cost_rate,NULL),NULL) --txn_standard_cost_rate
5107 ,Decode(l_cost_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',txn_cost_rate_override,NULL),NULL) --txn_cost_rate_override
5108 ,Decode(l_cost_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',burden_cost_rate,NULL),NULL) --burden_cost_rate
5109 ,Decode(l_revenue_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',txn_bill_rate_override,NULL),NULL) --txn_bill_rate_override
5110 ,Decode(l_cost_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',burden_cost_rate_override,NULL),NULL) --burden_cost_rate_override
5111 ,cost_ind_compiled_set_id
5112 ,Decode(l_adj_percentage,0,pc_cur_conv_rejection_code,null)
5113 ,Decode(l_adj_percentage,0,pfc_cur_conv_rejection_code,null)
5114 FROM PA_BUDGET_LINES pbl
5115 ,pa_resource_assignments pra
5116 WHERE pbl.resource_assignment_id = pra.parent_assignment_id
5117 AND pbl.budget_version_id = p_source_plan_version_id
5118 AND pra.budget_version_id = p_target_plan_version_id
5119 AND pra.project_id = l_target_project_id; -- Bug 4493425.
5120
5121 l_temp:=SQL%ROWCOUNT;
5122
5123 IF P_PA_DEBUG_MODE = 'Y' THEN
5124 pa_debug.g_err_stage:='No. of Budget lines inserted '||l_temp;
5125 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5126 END IF;
5127
5128 --Populate the pa_fp_bl_map_tmp table so that the MRC API can have the mapping readily defined.
5129 --The logic of inserting into pa_budget_lines using pa_fp_bl_map_tmp is removed for bug 4224703
5130 --The below table need not be popluated for worplan versions since MRC is not maintained for
5131 --workplan versions
5132 IF l_wp_version_flag='N' THEN
5133
5134 INSERT INTO pa_fp_bl_map_tmp
5135 (source_budget_line_id,
5136 target_budget_line_id)
5137 SELECT pbls.budget_line_id,
5138 pblt.budget_line_id
5139 FROM pa_budget_lines pblt,
5140 pa_budget_lines pbls,
5141 pa_resource_assignments prat
5142 WHERE pblt.budget_version_id=p_target_plan_version_id
5143 AND prat.budget_version_id=p_target_plan_version_id
5144 AND prat.project_id = l_target_project_id -- Bug 4493425.
5145 AND prat.resource_assignment_id=pblt.resource_assignment_id
5146 AND prat.parent_assignment_id=pbls.resource_assignment_id
5147 AND pblt.start_date=pbls.start_date
5148 AND pblt.txn_currency_code=pbls.txn_currency_code;
5149 l_temp:=SQL%ROWCOUNT;
5150
5151 IF P_PA_DEBUG_MODE = 'Y' THEN
5152 pa_debug.g_err_stage:='No. of mrc mappling lines inserted '||l_temp;
5153 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5154 END IF;
5155
5156 END IF;
5157
5158
5159 -- End, Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
5160
5161 -- Bug 4035856 Call rounding api if l_adj_percentage is not zero
5162 IF l_adj_percentage <> 0 THEN
5163 PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts
5164 ( p_budget_version_id => p_target_plan_version_id
5165 ,p_calling_context => 'COPY_VERSION'
5166 ,x_return_status => l_return_status
5167 ,x_msg_count => l_msg_count
5168 ,x_msg_data => l_msg_data);
5169
5170 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5171 IF P_PA_debug_mode = 'Y' THEN
5172 pa_debug.g_err_stage:= 'Error in PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts';
5173 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5174 END IF;
5175 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5176 END IF;
5177 END IF;
5178
5179 --Bug 4290043. Call the API to correct the missing amounts in the target version in case it can have
5180 --missing amounts/rates
5181 IF p_derv_rates_missing_amts_flag = 'Y' OR
5182 l_adj_percentage <> 0 THEN
5183
5184
5185 derv_missing_amts_chk_neg_qty
5186 (p_budget_version_id => p_target_plan_version_id,
5187 p_targ_pref_code => l_target_pref_code,
5188 p_source_version_type => l_source_version_type,
5189 p_target_version_type => l_target_version_type,
5190 p_src_plan_class_code => l_src_plan_class_code,
5191 p_derv_rates_missing_amts_flag => p_derv_rates_missing_amts_flag,
5192 p_adj_percentage => l_adj_percentage,
5193 x_return_status => l_return_status,
5194 x_msg_count => l_msg_count,
5195 x_msg_data => l_msg_data);
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 derv_missing_amts_chk_neg_qty';
5200 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5201 END IF;
5202 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5203
5204 END IF;
5205
5206 END IF;--IF p_derv_rates_missing_amts_flag = 'Y' THEN
5207
5208 IF P_PA_DEBUG_MODE = 'Y' THEN
5209 pa_debug.g_err_stage:='Exiting Copy_Budget_Lines';
5210 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5211 pa_debug.reset_err_stack; -- bug:- 2815593
5212 END IF;
5213 EXCEPTION
5214
5215 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
5216 l_msg_count := FND_MSG_PUB.count_msg;
5217 IF l_msg_count = 1 THEN
5218 PA_INTERFACE_UTILS_PUB.get_messages
5219 (p_encoded => FND_API.G_TRUE
5220 ,p_msg_index => 1
5221 ,p_msg_count => l_msg_count
5222 ,p_msg_data => l_msg_data
5223 ,p_data => l_data
5224 ,p_msg_index_out => l_msg_index_out);
5225 x_msg_data := l_data;
5226 x_msg_count := l_msg_count;
5227 ELSE
5228 x_msg_count := l_msg_count;
5229 END IF;
5230 x_return_status := FND_API.G_RET_STS_ERROR;
5231
5232 IF P_PA_DEBUG_MODE = 'Y' THEN
5233 pa_debug.g_err_stage:='Invalid arguments passed';
5234 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5235 pa_debug.reset_err_stack;
5236 END IF;
5237 RAISE;
5238
5239 WHEN Others THEN
5240 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5241 x_msg_count := 1;
5242 x_msg_data := SQLERRM;
5243 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
5244 ,p_procedure_name => 'COPY_BUDGET_LINES');
5245
5246 IF P_PA_DEBUG_MODE = 'Y' THEN
5247 pa_debug.g_err_stage:='Unexpected error'||SQLERRM;
5248 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,6);
5249 pa_debug.reset_err_stack;
5250 END IF;
5251 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5252 END Copy_Budget_Lines;
5253
5254 /*===========================================================================
5255 This api copies proj period denorm res_assignment records from source
5256 version to target version.This api would be called only when the adjustment
5257 percentage is zero and period profile ids of the source and target versions
5258 are same.
5259 ==========================================================================*/
5260
5261 PROCEDURE Copy_Periods_Denorm(
5262 p_source_plan_version_id IN NUMBER
5263 ,p_target_plan_version_id IN NUMBER
5264 ,p_calling_module IN VARCHAR2
5265 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5266 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
5267 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
5268 AS
5269
5270 l_msg_count NUMBER :=0;
5271 l_data VARCHAR2(2000);
5272 l_msg_data VARCHAR2(2000);
5273 l_error_msg_code VARCHAR2(2000);
5274 l_msg_index_out NUMBER;
5275 l_return_status VARCHAR2(2000);
5276 l_debug_mode VARCHAR2(30);
5277 l_ignore_amount_type pa_proj_periods_denorm.amount_type_code%TYPE;
5278 l_target_project_id pa_projects.project_id%TYPE;
5279
5280 BEGIN
5281
5282 x_msg_count := 0;
5283 x_return_status := FND_API.G_RET_STS_SUCCESS;
5284 IF P_PA_DEBUG_MODE = 'Y' THEN
5285 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Periods_Denorm');
5286 END IF;
5287 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
5288 l_debug_mode := NVL(l_debug_mode, 'Y');
5289 IF P_PA_DEBUG_MODE = 'Y' THEN
5290 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
5291 END IF;
5292 -- Checking for all valid input parametrs
5293
5294
5295 IF P_PA_DEBUG_MODE = 'Y' THEN
5296 pa_debug.g_err_stage := 'Checking for valid parameters:';
5297 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5298 END IF;
5299
5300 IF (p_source_plan_version_id IS NULL) OR
5301 (p_target_plan_version_id IS NULL) OR
5302 (p_calling_module IS NULL)
5303 THEN
5304
5305
5306 IF P_PA_DEBUG_MODE = 'Y' THEN
5307 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
5308 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5309 pa_debug.g_err_stage := 'Target_plan = '||p_target_plan_version_id;
5310 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5311 pa_debug.g_err_stage := 'Calling_module = '||p_calling_module;
5312 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5313 END IF;
5314
5315 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
5316 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
5317
5318 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5319
5320 END IF;
5321
5322 IF P_PA_DEBUG_MODE = 'Y' THEN
5323 pa_debug.g_err_stage := 'Parameter validation complete';
5324 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5325 END IF;
5326 /*
5327 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
5328 IF P_PA_DEBUG_MODE = 'Y' THEN
5329 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5330 END IF;
5331 pa_debug.g_err_stage := 'Target_plan = '||p_target_plan_version_id;
5332 IF P_PA_DEBUG_MODE = 'Y' THEN
5333 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5334 END IF;
5335 pa_debug.g_err_stage := 'Calling_module = '||p_calling_module;
5336 IF P_PA_DEBUG_MODE = 'Y' THEN
5337 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5338 END IF;
5339 */
5340 -- Evaluating which records are to be copied using amount type code of
5341 -- pa_proj_periods_denorm and fin paln preference code of the target version
5342
5343 IF P_PA_DEBUG_MODE = 'Y' THEN
5344 pa_debug.g_err_stage:='Evaluating which records are to be copied';
5345 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5346 END IF;
5347
5348 SELECT DECODE(fin_plan_preference_code
5349 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY ,PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE
5350 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY ,PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST
5351 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME ,'-99') --copy both cost and revenue
5352 ,project_id
5353 INTO l_ignore_amount_type
5354 ,l_target_project_id
5355 FROM pa_proj_fp_options
5356 WHERE fin_plan_version_id=p_target_plan_version_id;
5357 /*
5358 pa_debug.g_err_stage:='l_ignore_amount_type = '||l_ignore_amount_type;
5359 IF P_PA_DEBUG_MODE = 'Y' THEN
5360 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5361 END IF;
5362 pa_debug.g_err_stage := 'l_target_project_id = '||l_target_project_id;
5363 IF P_PA_DEBUG_MODE = 'Y' THEN
5364 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5365 END IF;
5366 */
5367 INSERT INTO PA_PROJ_PERIODS_DENORM(
5368 budget_version_id
5369 ,project_id
5370 ,resource_assignment_id
5371 ,object_id
5372 ,object_type_code
5373 ,period_profile_id
5374 ,amount_type_code
5375 ,amount_subtype_code
5376 ,amount_type_id
5377 ,amount_subtype_id
5378 ,currency_type
5379 ,currency_code
5380 ,preceding_periods_amount
5381 ,succeeding_periods_amount
5382 ,prior_period_amount
5383 ,period_amount1
5384 ,period_amount2
5385 ,period_amount3
5386 ,period_amount4
5387 ,period_amount5
5388 ,period_amount6
5389 ,period_amount7
5390 ,period_amount8
5391 ,period_amount9
5392 ,period_amount10
5393 ,period_amount11
5394 ,period_amount12
5395 ,period_amount13
5396 ,period_amount14
5397 ,period_amount15
5398 ,period_amount16
5399 ,period_amount17
5400 ,period_amount18
5401 ,period_amount19
5402 ,period_amount20
5403 ,period_amount21
5404 ,period_amount22
5405 ,period_amount23
5406 ,period_amount24
5407 ,period_amount25
5408 ,period_amount26
5409 ,period_amount27
5410 ,period_amount28
5411 ,period_amount29
5412 ,period_amount30
5413 ,period_amount31
5414 ,period_amount32
5415 ,period_amount33
5416 ,period_amount34
5417 ,period_amount35
5418 ,period_amount36
5419 ,period_amount37
5420 ,period_amount38
5421 ,period_amount39
5422 ,period_amount40
5423 ,period_amount41
5424 ,period_amount42
5425 ,period_amount43
5426 ,period_amount44
5427 ,period_amount45
5428 ,period_amount46
5429 ,period_amount47
5430 ,period_amount48
5431 ,period_amount49
5432 ,period_amount50
5433 ,period_amount51
5434 ,period_amount52
5435 ,last_update_date
5436 ,last_updated_by
5437 ,creation_date
5438 ,created_by
5439 ,last_update_login
5440 ,parent_assignment_id)
5441 SELECT p_target_plan_version_id --budget_version_id
5442 ,l_target_project_id --project_id
5443 ,pfrmt.target_res_assignment_id --resource_assignment_id
5444 /* Bug# 2677867 - Object_id shoudl always be res assgnmnt id irrespect of FP or ORG_FCST
5445 ,DECODE(p_calling_module
5446 ,PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_ORG_FORECAST ,pfrmt.target_res_assignment_id
5447 ,PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN , -1) --object_id
5448 */
5449 ,pfrmt.target_res_assignment_id
5450 ,PA_FP_CONSTANTS_PKG.G_OBJECT_TYPE_RES_ASSIGNMENT --object_type_code
5451 ,period_profile_id
5452 ,amount_type_code
5453 ,amount_subtype_code
5454 ,amount_type_id
5455 ,amount_subtype_id
5456 ,currency_type
5457 ,currency_code
5458 ,preceding_periods_amount
5459 ,succeeding_periods_amount
5460 ,prior_period_amount
5461 ,period_amount1
5462 ,period_amount2
5463 ,period_amount3
5464 ,period_amount4
5465 ,period_amount5
5466 ,period_amount6
5467 ,period_amount7
5468 ,period_amount8
5469 ,period_amount9
5470 ,period_amount10
5471 ,period_amount11
5472 ,period_amount12
5473 ,period_amount13
5474 ,period_amount14
5475 ,period_amount15
5476 ,period_amount16
5477 ,period_amount17
5478 ,period_amount18
5479 ,period_amount19
5480 ,period_amount20
5481 ,period_amount21
5482 ,period_amount22
5483 ,period_amount23
5484 ,period_amount24
5485 ,period_amount25
5486 ,period_amount26
5487 ,period_amount27
5488 ,period_amount28
5489 ,period_amount29
5490 ,period_amount30
5491 ,period_amount31
5492 ,period_amount32
5493 ,period_amount33
5494 ,period_amount34
5495 ,period_amount35
5496 ,period_amount36
5497 ,period_amount37
5498 ,period_amount38
5499 ,period_amount39
5500 ,period_amount40
5501 ,period_amount41
5502 ,period_amount42
5503 ,period_amount43
5504 ,period_amount44
5505 ,period_amount45
5506 ,period_amount46
5507 ,period_amount47
5508 ,period_amount48
5509 ,period_amount49
5510 ,period_amount50
5511 ,period_amount51
5512 ,period_amount52
5513 ,sysdate
5514 ,fnd_global.user_id
5515 ,sysdate
5516 ,fnd_global.user_id
5517 ,fnd_global.login_id
5518 ,pfrmt.parent_assignment_id --parent_assignment_id
5519 FROM PA_PROJ_PERIODS_DENORM pppd
5520 ,PA_FP_RA_MAP_TMP pfrmt
5521 WHERE budget_version_id = p_source_plan_version_id
5522 AND pppd.resource_assignment_id = pfrmt.source_res_assignment_id
5523 AND pppd.object_type_code = PA_FP_CONSTANTS_PKG.G_OBJECT_TYPE_RES_ASSIGNMENT
5524 AND pppd.amount_type_code <> l_ignore_amount_type;
5525
5526 IF P_PA_DEBUG_MODE = 'Y' THEN
5527 pa_debug.g_err_stage:='Exiting Copy_Periods_Denorm';
5528 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5529 pa_debug.reset_err_stack; --bug:- 2815593
5530 END IF;
5531 EXCEPTION
5532
5533 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
5534 l_msg_count := FND_MSG_PUB.count_msg;
5535 IF l_msg_count = 1 THEN
5536 PA_INTERFACE_UTILS_PUB.get_messages
5537 (p_encoded => FND_API.G_TRUE
5538 ,p_msg_index => 1
5539 ,p_msg_count => l_msg_count
5540 ,p_msg_data => l_msg_data
5541 ,p_data => l_data
5542 ,p_msg_index_out => l_msg_index_out);
5543 x_msg_data := l_data;
5544 x_msg_count := l_msg_count;
5545 ELSE
5546 x_msg_count := l_msg_count;
5547 END IF;
5548 x_return_status := FND_API.G_RET_STS_ERROR;
5549
5550 IF P_PA_DEBUG_MODE = 'Y' THEN
5551 pa_debug.g_err_stage:='Invalid arguments passed';
5552 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5553 pa_debug.reset_err_stack;
5554 END IF;
5555 RAISE;
5556
5557 WHEN Others THEN
5558 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5559 x_msg_count := 1;
5560 x_msg_data := SQLERRM;
5561 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
5562 ,p_procedure_name => 'Copy_Periods_Denorm');
5563
5564 IF P_PA_DEBUG_MODE = 'Y' THEN
5565 pa_debug.g_err_stage:='Unexpected error'||SQLERRM;
5566 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,6);
5567 pa_debug.reset_err_stack;
5568 END IF;
5569 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5570
5571 END Copy_Periods_Denorm;
5572
5573
5574
5575
5576 /*===================================================================
5577 This api copies all the budgets from source project to target
5578 project.this api only take care of the non upgraded budget versions
5579 and is based on the existing logic in pa_project_core1.copy_project.
5580 The output error parameters are designed to be in sync with existing
5581 code in pa_project_core1.copy_project
5582 ===================================================================*/
5583
5584 PROCEDURE Copy_Budgets_From_Project(
5585 p_from_project_id IN NUMBER
5586 ,p_to_project_id IN NUMBER
5587 ,p_delta IN NUMBER
5588 ,p_orig_template_flag IN VARCHAR2
5589 ,p_agreement_amount IN NUMBER -- Added for bug 2986930
5590 ,p_baseline_funding_flag IN VARCHAR2 -- Added for bug 2986930
5591 ,x_err_code OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
5592 ,x_err_stage OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5593 ,x_err_stack OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
5594 AS
5595
5596 l_return_status VARCHAR2(2000);
5597 l_msg_count NUMBER :=0;
5598 l_msg_data VARCHAR2(2000);
5599 x_delta NUMBER;
5600 x_new_project_id pa_projects.project_id%TYPE;
5601 x_orig_project_id pa_projects.project_id%TYPE;
5602 x_orig_template_flag pa_projects.template_flag%TYPE;
5603 l_agreement_amount NUMBER; -- Added for bug 2986930
5604 l_baseline_funding_flag VARCHAR2(1); -- Added for bug 2986930
5605 BEGIN
5606
5607 --Initialise the variables
5608
5609 x_orig_project_id := p_from_project_id;
5610 x_new_project_id := p_to_project_id;
5611 x_delta := p_delta;
5612 x_orig_template_flag := p_orig_template_flag;
5613
5614 /*=============================================================
5615 The following code has been moved from copy project
5616 =============================================================*/
5617
5618 -- Copy budgets: For each budget type, get baselined budget
5619 -- version id of the original project. If baselined budget verion
5620 -- id is null, then get draft budget version id. Copy the baselined
5621 -- budget or draft budget (if no baselined budget) of the original
5622 -- project into a new draft budget for the new project.
5623
5624 --EH Changes
5625
5626 BEGIN
5627 PA_BUDGET_FUND_PKG.Copy_Budgetary_Controls
5628 (p_from_project_id => x_orig_project_id,
5629 p_to_project_id => x_new_project_id,
5630 x_return_status => l_return_status,
5631 x_msg_count => l_msg_count,
5632 x_msg_data => l_msg_data);
5633
5634 IF (l_return_status <> 'S') Then
5635 x_err_code := 725;
5636 -- x_err_stage := 'PA_NO_PROJ_CREATED';
5637 x_err_stage := pa_project_core1.get_message_from_stack('PA_ERR_COPY_BUDGT_CONTRL');
5638
5639 x_err_stack := x_err_stack||'->PA_BUDGET_FUND_PKG.Copy_Budgetary_Controls';
5640 -- bug 3163280 rollback to copy_project;
5641 return;
5642 END IF;
5643
5644 EXCEPTION WHEN OTHERS THEN
5645
5646 x_err_code := 725;
5647 x_err_stage := pa_project_core1.get_message_from_stack( null );
5648 IF x_err_stage IS NULL
5649 THEN
5650 x_err_stage := 'API: '||'PA_BUDGET_FUND_PKG.Copy_Budgetary_Controls'||
5651 ' SQL error message: '||SUBSTR( SQLERRM,1,1900);
5652 END IF;
5653 -- bug 3163280 rollback to copy_project;
5654 return;
5655 END;
5656
5657 DECLARE
5658 CURSOR agmt is
5659 SELECT 1
5660 FROM pa_project_fundings
5661 WHERE project_id = x_new_project_id;
5662
5663 CURSOR c1 is
5664 /* Bug 3106741
5665 Reframed the select to use EXISTS instead of DISTINCT
5666 */
5667 SELECT t.budget_type_code
5668 ,t.budget_amount_code
5669 FROM pa_budget_types t
5670 WHERE EXISTS ( SELECT 1
5671 FROM pa_budget_versions v
5672 WHERE v.project_id = x_orig_project_id
5673 AND v.budget_type_code = t.budget_type_code)
5674 ORDER BY t.budget_type_code;
5675
5676 c1_rec c1%rowtype;
5677 x_budget_version_id number;
5678 x_new_budget_ver_id number;
5679 with_funding number := 0;
5680 x_mark_as_original varchar2(2);
5681
5682 BEGIN
5683 l_baseline_funding_flag := NVL(p_baseline_funding_flag,'N'); -- Added for bug 2986930
5684 OPEN agmt;
5685 FETCH agmt into with_funding;
5686 IF agmt%notfound THEN
5687 with_funding := 0;
5688 END IF;
5689
5690 CLOSE agmt;
5691
5692 OPEN c1;
5693
5694 LOOP
5695
5696 x_err_stage := 'fetch budget type code';
5697
5698 FETCH c1 INTO c1_rec;
5699 EXIT WHEN c1%notfound;
5700
5701 /* Added the below if condition for bug 2986930 */
5702 --Bug 5378256: Prevent copy and baseline of AR budget when 'baseline funding without budget' is enabled for target.
5703 If NOT(l_baseline_funding_flag = 'Y' and c1_rec.budget_type_code = 'AR' )
5704 then
5705
5706 x_budget_version_id := null;
5707 x_mark_as_original := 'N';
5708 -- get latest baselined version id of the original project
5709 -- with the budget type of c1_rec.budget_type_code
5710 x_err_stage :=
5711 'get latest baselined version id of project '||
5712 x_orig_project_id ||' with budget type of '||
5713 c1_rec.budget_type_code;
5714 --EH Changes
5715 BEGIN
5716 pa_budget_utils.get_baselined_version_id
5717 (x_project_id => x_orig_project_id,
5718 x_budget_type_code => c1_rec.budget_type_code,
5719 x_budget_version_id => x_budget_version_id,
5720 x_err_code => x_err_code,
5721 x_err_stage => x_err_stage,
5722 x_err_stack => x_err_stack);
5723
5724
5725 x_err_stage :=
5726 'after get latest baselined version id of project '||
5727 x_orig_project_id ||' with budget type of '||
5728 c1_rec.budget_type_code;
5729
5730 IF ( x_err_code < 0 ) THEN -- Oracle error
5731 x_err_code := 750;
5732 IF x_err_stage IS NULL
5733 THEN
5734 x_err_stage := pa_project_core1.get_message_from_stack( 'PA_ERR_GET_BASLIN_VER_ID');
5735 END IF;
5736 x_err_stack := x_err_stack||'->pa_budget_utils.get_baselined_version_id';
5737 -- bug 3163280 ROLLBACK TO copy_project;
5738 RETURN;
5739 END IF;
5740 EXCEPTION WHEN OTHERS THEN
5741 x_err_code := 750;
5742 -- x_err_stage := pa_project_core1.get_message_from_stack( null );
5743 IF x_err_stage IS NULL
5744 THEN
5745 x_err_stage := 'API: '||'pa_budget_utils.get_baselined_version_id'||
5746 ' SQL error message: '||SUBSTR( SQLERRM,1,1900);
5747 END IF;
5748 -- bug 3163280 rollback to copy_project;
5749 return;
5750 END;
5751
5752 IF ( x_err_code = 0 ) THEN -- got baselined budget
5753 x_mark_as_original := 'Y';
5754 END IF;
5755
5756 IF (x_err_code = 10) THEN
5757 -- no baselined budget
5758 -- get draft version id of the original project
5759 -- with the budget type of c1_rec.budget_type_code
5760 x_err_stage :=
5761 'get draft version id of project '||
5762 x_orig_project_id ||' with budget type of '||
5763 c1_rec.budget_type_code;
5764 --EH Changes
5765 BEGIN
5766 pa_budget_utils.get_draft_version_id
5767 (x_project_id => x_orig_project_id,
5768 x_budget_type_code => c1_rec.budget_type_code,
5769 x_budget_version_id => x_budget_version_id,
5770 x_err_code => x_err_code,
5771 x_err_stage => x_err_stage,
5772 x_err_stack => x_err_stack);
5773
5774 IF ( x_err_code < 0 ) THEN -- Oracle error
5775 x_err_code := 755;
5776 IF x_err_stage IS NULL
5777 THEN
5778 x_err_stage := pa_project_core1.get_message_from_stack('PA_ERR_GET_DRFT_VER_ID');
5779 END IF;
5780 x_err_stack := x_err_stack||'->pa_budget_utils.get_draft_version_id';
5781 -- bug 3163280 ROLLBACK TO copy_project;
5782 RETURN;
5783 END IF;
5784 EXCEPTION WHEN OTHERS THEN
5785 x_err_code := 755;
5786 -- x_err_stage := pa_project_core1.get_message_from_stack( null );
5787 IF x_err_stage IS NULL
5788 THEN
5789 x_err_stage := 'API: '||'pa_budget_utils.get_draft_version_id'||
5790 ' SQL error message: '||SUBSTR( SQLERRM,1,1900);
5791 END IF;
5792 -- bug 3163280 ROLLBACK TO copy_project;
5793 RETURN;
5794 END;
5795 END IF;
5796
5797 IF (x_err_code = 0) THEN
5798 IF (x_budget_version_id is not null) THEN
5799
5800 -- copy budget for new project
5801 x_err_stage := 'create draft budget for new project '||
5802 x_new_project_id || ' with budget type of '||
5803 c1_rec.budget_type_code;
5804 --EH Changes
5805
5806 BEGIN
5807
5808 pa_budget_core.copy(
5809 x_src_version_id => x_budget_version_id,
5810 x_amount_change_pct => 1,
5811 x_rounding_precision => 5,
5812 x_shift_days => nvl(x_delta, 0),
5813 x_dest_project_id => x_new_project_id,
5814 x_dest_budget_type_code => c1_rec.budget_type_code,
5815 x_err_code => x_err_code,
5816 x_err_stage => x_err_stage,
5817 x_err_stack => x_err_stack );
5818
5819 if ( x_err_code > 0 or x_err_code < 0 ) then
5820 x_err_code := 760;
5821 IF x_err_stage IS NULL
5822 THEN
5823 x_err_stage := pa_project_core1.get_message_from_stack( 'PA_ERR_BUDGT_CORE_COPY');
5824 END IF;
5825 x_err_stack := x_err_stack||'->pa_budget_core.copy';
5826 -- bug 3163280 rollback to copy_project;
5827 return; -- Application or Oracle error
5828 end if;
5829 EXCEPTION WHEN OTHERS THEN
5830 x_err_code := 760;
5831 -- x_err_stage := pa_project_core1.get_message_from_stack( null );
5832 IF x_err_stage IS NULL
5833 THEN
5834 x_err_stage := 'API: '||'pa_budget_core.copy'||
5835 ' SQL error message: '||SUBSTR( SQLERRM,1,1900);
5836 END IF;
5837 -- bug 3163280 rollback to copy_project;
5838 return;
5839 END;
5840
5841 IF NOT PA_BUDGET_FUND_PKG.Is_bdgt_intg_enabled (p_project_id => x_orig_project_id,p_mode => 'A') THEN
5842
5843 -- 1. Submit/Baseline budget if the original template
5844 -- has baselined budget with the same budget type.
5845 -- 2. Display warning message if no baselined cost
5846 -- budget for PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST based revenue accrual project and
5847 -- try to baseline its revenue budget.
5848
5849 IF (x_mark_as_original = 'Y' and x_orig_template_flag = 'Y' and
5850 (with_funding = 1 or
5851 c1_rec.budget_amount_code <> 'R')) THEN
5852
5853 x_err_stage :=
5854 'get draft budget version for new project'
5855 || x_new_project_id;
5856
5857 SELECT budget_version_id
5858 INTO x_new_budget_ver_id
5859 FROM pa_budget_versions
5860 WHERE project_id = x_new_project_id
5861 AND budget_status_code = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING
5862 AND budget_type_code = c1_rec.budget_type_code;
5863
5864 x_err_stage :=
5865 'submit revenue budget for new project'
5866 || x_new_project_id;
5867
5868 savepoint before_bill_baseline;
5869 /*Bug 5378256: This condition added thru the bug 2986930, has been moved down
5870 to prevent baseline alone when agreement amt is entered through quick agreement*/
5871 If NOT(p_agreement_amount > 0 and c1_rec.budget_type_code = 'AR' )
5872 then
5873 --EH Changes
5874 BEGIN
5875
5876 pa_budget_utils2.submit_budget(x_budget_version_id => x_new_budget_ver_id,
5877 x_err_code => x_err_code,
5878 x_err_stage => x_err_stage,
5879 x_err_stack => x_err_stack);
5880
5881 IF ( x_err_code <> 0 ) THEN
5882 x_err_code := 785;
5883 IF x_err_stage IS NULL
5884 THEN
5885 x_err_stage := pa_project_core1.get_message_from_stack( 'PA_ERR_SUBMIT_BUDGT');
5886 END IF;
5887 x_err_stack := x_err_stack||'->pa_budget_utils2.submit_budget';
5888 ROLLBACK TO before_bill_baseline;
5889 RETURN; -- Application or Oracle error
5890 END IF;
5891 EXCEPTION WHEN OTHERS THEN
5892 x_err_code := 785;
5893 -- x_err_stage := pa_project_core1.get_message_from_stack( null );
5894 IF x_err_stage IS NULL
5895 THEN
5896 x_err_stage := 'API: '||'pa_budget_utils2.submit_budget'||
5897 ' SQL error message: '||SUBSTR( SQLERRM,1,1900);
5898 END IF;
5899 ROLLBACK TO before_bill_baseline;
5900 RETURN;
5901 END;
5902
5903 x_err_stage :=
5904 'baseline revenue budget for new project'
5905 || x_new_project_id;
5906
5907 pa_budget_core.baseline(
5908 x_draft_version_id=> x_new_budget_ver_id,
5909 x_mark_as_original=> x_mark_as_original,
5910 x_verify_budget_rules => 'Y',
5911 x_err_code => x_err_code,
5912 x_err_stage => x_err_stage,
5913 x_err_stack => x_err_stack);
5914
5915 if ( x_err_code > 0 and
5916 x_err_stage = 'PA_BU_NO_BASE_COST_BUDGET') then
5917 rollback to before_bill_baseline;
5918 x_err_code := 0;
5919 elsif ( x_err_code <> 0 ) then
5920 return; -- Application or Oracle error
5921 end if;
5922
5923 x_err_stage :=
5924 'reset revenue budget to working for new project'
5925 || x_new_project_id;
5926 --EH Changes
5927 BEGIN
5928
5929 pa_budget_utils2.rework_budget(x_budget_version_id => x_new_budget_ver_id,
5930 x_err_code => x_err_code,
5931 x_err_stage => x_err_stage,
5932 x_err_stack => x_err_stack);
5933
5934 IF ( x_err_code <> 0 ) THEN
5935 x_err_code := 790;
5936 IF x_err_stage IS NULL
5937 THEN
5938 x_err_stage := pa_project_core1.get_message_from_stack( 'PA_ERR_REWORK_BUDGT');
5939 END IF;
5940 x_err_stack := x_err_stack||'->pa_budget_utils2.rework_budget';
5941 ROLLBACK TO before_bill_baseline;
5942 RETURN; -- Application or Oracle error
5943 END IF;
5944 EXCEPTION WHEN OTHERS THEN
5945 x_err_code := 790;
5946 -- x_err_stage := pa_project_core1.get_message_from_stack( null );
5947 IF x_err_stage IS NULL
5948 THEN
5949 x_err_stage := 'API: '||'pa_budget_utils2.rework_budget'||
5950 ' SQL error message: '||SUBSTR( SQLERRM,1,1900);
5951 END IF;
5952 ROLLBACK TO before_bill_baseline;
5953 RETURN;
5954 END;
5955
5956 End if; --Bug 5378256: Prevent baseline of AR budget when agreement amount is entered.
5957
5958 END IF;
5959
5960 END IF;
5961
5962 END IF;
5963 END IF;
5964 END IF; -- Added for bug 2986930
5965 END LOOP;
5966 CLOSE C1;
5967
5968 -- pa_budget_core.get_draft_version_id returns x_err_code = 10
5969 -- when no budget version id is found, which is fine.
5970 IF (x_err_code = 10) THEN
5971 x_err_code := 0;
5972 END IF;
5973 END;
5974
5975 END Copy_Budgets_From_Project;
5976
5977 /*===================================================================
5978 This is a main api used for copying the financila related entities
5979 fromsource project or template. This api takes care of the upgraded
5980 budget versions and takes care of all the business rules that relate
5981 to new financial planning module. This api would be called from
5982 PA_PROJECT_CORE!.COPY_PROJECT after call to
5983 PA_BUDGET_CORE.COPY_BUDGETS_FROM_PROJECT
5984 Bug# - 2981655 - Please see bug for the complete discussion about
5985 this bug. The core is, when copy_project is done with copy_budget_flag
5986 as N, we still have to copy the header level informations
5987 pa_proj_fp_options, pa_fp_txn_currencies, period profile information.
5988 Also, we should not be copying the planning elements for any of the
5989 copied options since when copy_budget_flag is N, tasks may not have
5990 been copied from the source project to the target project.
5991
5992 --
5993 -- 14-JUL-2003 jwhite - Bug 3045668
5994 -- As directed by Venkatesh, added a
5995 -- simple update near the end of the
5996 -- Copy_Finplans_From_Project to set the
5997 -- process_update_wbs_flag = 'N when
5998 -- p_copy_version_and_elements = N.
5999
6000 =====================================================================*/
6001
6002 PROCEDURE Copy_Finplans_From_Project (
6003 p_source_project_id IN NUMBER
6004 ,p_target_project_id IN NUMBER
6005 ,p_shift_days IN NUMBER
6006 ,p_copy_version_and_elements IN VARCHAR2
6007 ,p_agreement_amount IN NUMBER -- Added for bug 2986930
6008 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
6009 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
6010 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
6011 AS
6012 l_return_status VARCHAR2(2000);
6013 l_msg_count NUMBER :=0;
6014 l_msg_data VARCHAR2(2000);
6015 l_data VARCHAR2(2000);
6016 l_msg_index_out NUMBER;
6017 l_err_code NUMBER;
6018 l_err_stage VARCHAR2(2000);
6019 l_err_stack VARCHAR2(2000);
6020
6021 l_index NUMBER;
6022 l_shift_days NUMBER;
6023 l_period_type VARCHAR2(15);
6024
6025 l_proj_fp_options_id_tbl PA_FP_COPY_FROM_PKG.PROJ_FP_OPTIONS_ID_TBL_TYP;
6026
6027 l_source_template_flag pa_projects_all.template_flag%TYPE;
6028 l_source_current_flag pa_budget_versions.current_flag%TYPE;
6029 l_source_version_id pa_budget_versions.budget_version_id%TYPE;
6030 l_source_fp_preference_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
6031 l_source_record_version_num pa_budget_versions.record_version_number%TYPE;
6032 l_source_fin_plan_type_id pa_proj_fp_options.fin_plan_type_id%TYPE;
6033
6034 l_time_phased_code pa_proj_fp_options.all_time_phased_code%TYPE;
6035
6036 l_target_version_id pa_budget_versions.budget_version_id%TYPE;
6037 l_target_profile_id pa_budget_versions.period_profile_id%TYPE;
6038 l_target_proj_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
6039 l_target_record_version_num pa_budget_versions.record_version_number%TYPE;
6040 l_version_type pa_budget_versions.version_type%TYPE;
6041 l_funding_exists_flag VARCHAR2(1);
6042
6043
6044 l_fp_option_level_code pa_proj_fp_options.fin_plan_option_level_code%TYPE;
6045 l_plan_in_multi_curr_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
6046 l_appr_cost_plan_type_flag pa_proj_fp_options.approved_cost_plan_type_flag%TYPE;
6047 l_appr_rev_plan_type_flag pa_proj_fp_options.approved_rev_plan_type_flag%TYPE;
6048 l_struct_elem_version_id pa_proj_element_versions.element_version_id%TYPE;
6049 l_budget_version_ids SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
6050 l_src_budget_version_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
6051
6052
6053 /* Code addition for bug 2986930 starts */
6054 CURSOR c_ar_chk( p_source_ver_id pa_budget_versions.budget_version_id%TYPE) IS
6055 SELECT 'Y'
6056 FROM dual
6057 WHERE EXISTS(SELECT NULL
6058 FROM pa_budget_versions
6059 WHERE budget_version_id = p_source_ver_id
6060 AND approved_rev_plan_type_flag = 'Y');
6061
6062 CURSOR c_bfl IS
6063 SELECT baseline_funding_flag
6064 FROM pa_projects
6065 WHERE project_id = p_source_project_id;
6066
6067 l_ar_exists VARCHAR2(1);
6068 l_baseline_funding_flag VARCHAR2(1);
6069 l_fc_version_created_flag VARCHAR2(1);
6070 /* Code addition for bug 2986930 ends */
6071 -- IPM Arch Enhancement - Bug 4865563
6072 l_fp_cols_rec PA_FP_GEN_AMOUNT_UTILS.FP_COLS; --This variable will be used to call pa_resource_asgn_curr maintenance api
6073 l_debug_level5 NUMBER:=5;
6074
6075 BEGIN
6076
6077 FND_MSG_PUB.INITIALIZE;
6078 x_msg_count := 0;
6079 x_return_status := FND_API.G_RET_STS_SUCCESS;
6080
6081 IF P_PA_DEBUG_MODE = 'Y' THEN
6082 pa_debug.init_err_stack('PA_FP_COPY_FROM_PKG.Copy_Finplans_From_Project');
6083 pa_debug.set_process('PLSQL','LOG',p_pa_debug_mode);
6084 -- Check if source project id is NULL,if so throw an error message
6085 pa_debug.g_err_stage := 'Checking for valid parameters:';
6086 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6087 END IF;
6088
6089 IF (p_source_project_id IS NULL) OR
6090 (p_target_project_id IS NULL) OR
6091 (p_copy_version_and_elements IS NULL)
6092 THEN
6093
6094 IF P_PA_DEBUG_MODE = 'Y' THEN
6095 pa_debug.g_err_stage := 'Source_project='||p_source_project_id;
6096 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6097 pa_debug.g_err_stage := 'Target_project='||p_target_project_id;
6098 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6099 pa_debug.g_err_stage := 'p_copy_version_and_elements='||p_copy_version_and_elements;
6100 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6101 END IF;
6102
6103 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
6104 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
6105 p_token1 => 'PROCEDURENAME',
6106 p_value1 => 'PA_FP_COPY_FROM_PKG.Copy_Finplans_From_Project');
6107 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6108
6109 END IF;
6110
6111 IF P_PA_DEBUG_MODE = 'Y' THEN
6112 pa_debug.g_err_stage := 'Parameter validation complete';
6113 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6114 END IF;
6115
6116 --IF shift_days i/p is NULL then make it zero.
6117
6118 l_shift_days := NVL(p_shift_days,0);
6119
6120 --Get the structure version id of the financial structure
6121 l_struct_elem_version_id := PA_PROJECT_STRUCTURE_UTILS.GET_FIN_STRUC_VER_ID(p_project_id => p_target_project_id );
6122
6123 --Checking if source project is template
6124
6125 IF P_PA_DEBUG_MODE = 'Y' THEN
6126 pa_debug.g_err_stage := 'Fetching source project template flag';
6127 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6128 END IF;
6129
6130 SELECT template_flag
6131 INTO l_source_template_flag
6132 FROM pa_projects_all
6133 WHERE project_id = p_source_project_id;
6134
6135 --Fetch project_level_funding_flag for target project to
6136 --baseline it or not
6137
6138 IF P_PA_DEBUG_MODE = 'Y' THEN
6139 pa_debug.g_err_stage := 'Fetching target funding flag';
6140 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6141 END IF;
6142
6143 /* 2616032: Modified the way the project level funding flag is got.
6144 This flag indicates if funding exists for the Target Project. */
6145
6146 BEGIN
6147 SELECT 'Y'
6148 INTO l_funding_exists_flag
6149 FROM DUAL
6150 WHERE EXISTS (SELECT 1
6151 FROM pa_project_fundings
6152 WHERE project_id = p_target_project_id);
6153 EXCEPTION
6154 WHEN NO_DATA_FOUND THEN
6155 l_funding_exists_flag := 'N';
6156 END;
6157
6158 /* Code addition for bug 2986930 starts */
6159 OPEN c_bfl;
6160 FETCH c_bfl into l_baseline_funding_flag;
6161 CLOSE c_bfl;
6162 /* Code addition for bug 2986930 ends */
6163
6164 IF p_copy_version_and_elements = 'Y' THEN /* Bug 2981655 */
6165
6166 --First Copy the budgets which aren't upgraded from source project to target project
6167
6168 Copy_Budgets_From_Project(
6169 p_from_project_id => p_source_project_id
6170 ,p_to_project_id => p_target_project_id
6171 ,p_delta => l_shift_days
6172 ,p_orig_template_flag => l_source_template_flag
6173 ,p_agreement_amount => p_agreement_amount -- Added for bug 2986930
6174 ,p_baseline_funding_flag => l_baseline_funding_flag -- Added for bug 2986930
6175 ,x_err_code => l_err_code
6176 ,x_err_stage => l_err_stage
6177 ,x_err_stack => l_err_stack);
6178
6179 IF l_err_code <> 0 THEN
6180
6181 /* Bug# 2636723 - Error messages printed and "Raised" and not "Returned" */
6182
6183 IF P_PA_DEBUG_MODE = 'Y' THEN
6184 pa_debug.g_err_stage := 'Err code returned by copy_budgets_from_project api is ' || TO_CHAR(l_err_code);
6185 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6186 pa_debug.g_err_stage := 'Err stage returned by copy_budgets_from_project api is ' || l_err_stage;
6187 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6188 pa_debug.g_err_stage := 'Err stack returned by copy_budgets_from_project api is ' || l_err_stack;
6189 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6190 END IF;
6191
6192 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6193
6194 /* Bug# 2636723
6195 RETURN; -- Application or Oracle error */
6196
6197 END IF; /* l_err_code <> 0 */
6198
6199 END IF; /* p_copy_version_and_elements = 'Y' */
6200
6201 --Fetch all the fp options ids to be copied from source project to
6202 --target into a plsql table.
6203 --For this call get_fp_options_to_be_copied api.
6204
6205 IF P_PA_DEBUG_MODE = 'Y' THEN
6206 pa_debug.g_err_stage := 'Calling Get_Fp_Options_To_Be_Copied api';
6207 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6208 END IF;
6209
6210 PA_FP_COPY_FROM_PKG.Get_Fp_Options_To_Be_Copied(
6211 p_source_project_id => p_source_project_id
6212 ,p_copy_versions => p_copy_version_and_elements /* Bug 2981655 */
6213 ,x_fp_options_ids_tbl => l_proj_fp_options_id_tbl
6214 ,x_return_status => l_return_status
6215 ,x_msg_count => l_msg_count
6216 ,x_msg_data => l_msg_data );
6217
6218 /* Added the following check for the NOCOPY changes. */
6219
6220 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6221 raise PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6222 END IF;
6223
6224 --Bug :- 2570874
6225 IF NVL(l_proj_fp_options_id_tbl.first,0) >0 THEN --only if something to be copied
6226 FOR l_index IN l_proj_fp_options_id_tbl.first..l_proj_fp_options_id_tbl.last
6227 LOOP
6228
6229 --Null out local variables used previously
6230
6231 l_target_version_id := NULL;
6232 l_target_proj_fp_options_id := NULL;
6233
6234 --Fetch option level code of the options_id
6235
6236 IF P_PA_DEBUG_MODE = 'Y' THEN
6237 pa_debug.g_err_stage := 'Fetching option level code ';
6238 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6239 END IF;
6240
6241 SELECT fin_plan_option_level_code
6242 ,fin_plan_version_id
6243 ,fin_plan_preference_code
6244 ,fin_plan_type_id
6245 ,plan_in_multi_curr_flag
6246 INTO l_fp_option_level_code
6247 ,l_source_version_id
6248 ,l_source_fp_preference_code
6249 ,l_source_fin_plan_type_id
6250 ,l_plan_in_multi_curr_flag
6251 FROM pa_proj_fp_options
6252 WHERE proj_fp_options_id = l_proj_fp_options_id_tbl(l_index);
6253
6254 IF P_PA_DEBUG_MODE = 'Y' THEN
6255 pa_debug.g_err_stage := 'Option level code = '||l_fp_option_level_code;
6256 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6257 END IF;
6258
6259
6260 --Copy the budget version if option level code is plan version
6261 --We call the api with .99999 as adj_percentage to prevent
6262 --population of amount columns
6263
6264 IF l_fp_option_level_code = PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_VERSION THEN
6265
6266 /* Code addition for Bug 2986930 starts */
6267 OPEN c_ar_chk(l_source_version_id);
6268 FETCH c_ar_chk INTO l_ar_exists;
6269 CLOSE c_ar_chk;
6270
6271 IF ( NVL(p_agreement_amount,-1) > 0 and nvl(l_ar_exists,'N') <> 'Y' ) OR
6272 ( NVL(p_agreement_amount,-1) < 0 and ( NVL(l_baseline_funding_flag,'N') = 'Y' AND NVl(l_ar_exists,'N') <> 'Y' ) ) OR
6273 ( NVL(p_agreement_amount,-1) < 0 and NVL(l_baseline_funding_flag,'N') = 'N' )
6274 THEN
6275 /* Code addition for Bug 2986930 ends */
6276
6277 IF P_PA_DEBUG_MODE = 'Y' THEN
6278 pa_debug.g_err_stage := 'Calling Copy_Budget_Version';
6279 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6280 END IF;
6281
6282 l_target_version_id := NULL;
6283
6284 PA_FP_COPY_FROM_PKG.Copy_Budget_Version(
6285 p_source_project_id => p_source_project_id
6286 ,p_target_project_id => p_target_project_id
6287 ,p_source_version_id => l_source_version_id
6288 ,p_copy_mode => PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_WORKING
6289 ,p_adj_percentage => .99999
6290 ,p_calling_module => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN
6291 ,p_struct_elem_version_id => l_struct_elem_version_id
6292 ,p_shift_days => l_shift_days
6293 ,px_target_version_id => l_target_version_id
6294 ,x_return_status => l_return_status
6295 ,x_msg_count => l_msg_count
6296 ,x_msg_data => l_msg_data );
6297
6298 IF P_PA_DEBUG_MODE = 'Y' THEN
6299 pa_debug.g_err_stage := 'l_target_version_id = '||l_target_version_id;
6300 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6301 END IF;
6302
6303 END IF;/* Added for bug 2986930 */
6304 END IF;
6305
6306 IF l_fp_option_level_code <> PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_VERSION THEN
6307 --Create equivalent fp option in pa_proj_fp_options for target
6308
6309 IF P_PA_DEBUG_MODE = 'Y' THEN
6310 pa_debug.g_err_stage := 'Calling Create_Fp_Option';
6311 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6312 END IF;
6313
6314 PA_PROJ_FP_OPTIONS_PUB.Create_Fp_Option (
6315 px_target_proj_fp_option_id => l_target_proj_fp_options_id
6316 ,p_source_proj_fp_option_id => l_proj_fp_options_id_tbl(l_index)
6317 ,p_target_fp_option_level_code => l_fp_option_level_code --same as source
6318 ,p_target_fp_preference_code => l_source_fp_preference_code
6319 ,p_target_fin_plan_version_id => l_target_version_id
6320 ,p_target_plan_type_id => l_source_fin_plan_type_id --same as source
6321 ,p_target_project_id => p_target_project_id
6322 ,x_return_status => l_return_status
6323 ,x_msg_count => l_msg_count
6324 ,x_msg_data => l_msg_data);
6325
6326 IF P_PA_DEBUG_MODE = 'Y' THEN
6327 pa_debug.g_err_stage := 'Calling Copy_Fp_Txn_Currencies api';
6328 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6329 END IF;
6330
6331 PA_FP_TXN_CURRENCIES_PUB.Copy_Fp_Txn_Currencies(
6332 p_source_fp_option_id => l_proj_fp_options_id_tbl(l_index)
6333 ,p_target_fp_option_id => l_target_proj_fp_options_id
6334 ,p_target_fp_preference_code => NULL
6335 ,p_plan_in_multi_curr_flag => l_plan_in_multi_curr_flag
6336 ,x_return_status => l_return_status
6337 ,x_msg_count => l_msg_count
6338 ,x_msg_data => l_msg_data);
6339
6340 ELSIF l_fp_option_level_code = PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_VERSION THEN
6341
6342 /* Code addition for Bug 2986930 starts */
6343
6344 IF ( NVL(p_agreement_amount,-1) > 0 AND nvl(l_ar_exists,'N') <> 'Y' ) OR
6345 ( NVL(p_agreement_amount,-1) < 0 AND ( NVL(l_baseline_funding_flag,'N') = 'Y' AND NVl(l_ar_exists,'N') <> 'Y' ) ) OR
6346 ( NVL(p_agreement_amount,-1) < 0 AND NVL(l_baseline_funding_flag,'N') = 'N' )
6347 THEN
6348 /* Code addition for Bug 2986930 ends */
6349 --Create equivalent fp option in pa_proj_fp_options for target
6350
6351 IF P_PA_DEBUG_MODE = 'Y' THEN
6352 pa_debug.g_err_stage := 'Calling Create_Fp_Option';
6353 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6354 END IF;
6355
6356 PA_PROJ_FP_OPTIONS_PUB.Create_Fp_Option (
6357 px_target_proj_fp_option_id => l_target_proj_fp_options_id
6358 ,p_source_proj_fp_option_id => l_proj_fp_options_id_tbl(l_index)
6359 ,p_target_fp_option_level_code => l_fp_option_level_code --same as source
6360 ,p_target_fp_preference_code => l_source_fp_preference_code
6361 ,p_target_fin_plan_version_id => l_target_version_id
6362 ,p_target_plan_type_id => l_source_fin_plan_type_id --same as source
6363 ,p_target_project_id => p_target_project_id
6364 ,x_return_status => l_return_status
6365 ,x_msg_count => l_msg_count
6366 ,x_msg_data => l_msg_data);
6367
6368 -- Call copy fp txn currencies api unconditionally
6369 IF P_PA_DEBUG_MODE = 'Y' THEN
6370 pa_debug.g_err_stage := 'Calling Copy_Fp_Txn_Currencies api';
6371 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6372 END IF;
6373
6374 PA_FP_TXN_CURRENCIES_PUB.Copy_Fp_Txn_Currencies(
6375 p_source_fp_option_id => l_proj_fp_options_id_tbl(l_index)
6376 ,p_target_fp_option_id => l_target_proj_fp_options_id
6377 ,p_target_fp_preference_code => NULL
6378 ,p_plan_in_multi_curr_flag => l_plan_in_multi_curr_flag
6379 ,x_return_status => l_return_status
6380 ,x_msg_count => l_msg_count
6381 ,x_msg_data => l_msg_data);
6382
6383
6384 --Copy resource assignments for the target plan version
6385
6386 IF P_PA_DEBUG_MODE = 'Y' THEN
6387 pa_debug.g_err_stage := 'Calling Copy_Resource_Assignments';
6388 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6389 END IF;
6390
6391 PA_FP_COPY_FROM_PKG.Copy_Resource_Assignments(
6392 p_source_plan_version_id => l_source_version_id
6393 ,p_target_plan_version_id => l_target_version_id
6394 ,p_adj_percentage => 0.99999
6395 ,x_return_status => l_return_status
6396 ,x_msg_count => l_msg_count
6397 ,x_msg_data => l_msg_data);
6398
6399 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6400 IF P_PA_DEBUG_MODE = 'Y' THEN
6401 pa_debug.write(g_module_name,' Return status from copy RA api is ' || l_Return_Status,3);
6402 END IF;
6403 raise PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6404 END IF;
6405
6406 -- Copying budget_lines from source to target
6407
6408 IF P_PA_DEBUG_MODE = 'Y' THEN
6409 pa_debug.g_err_stage := 'Calling Copy_Budget_Lines';
6410 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6411 END IF;
6412
6413 PA_FP_COPY_FROM_PKG.Copy_Budget_Lines(
6414 p_source_project_id => p_source_project_id
6415 ,p_target_project_id => p_target_project_id
6416 ,p_source_plan_version_id => l_source_version_id
6417 ,p_target_plan_version_id => l_target_version_id
6418 ,p_shift_days => l_shift_days
6419 ,x_return_status => l_return_status
6420 ,x_msg_count => l_msg_count
6421 ,x_msg_data => l_msg_data );
6422
6423 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6424 IF P_PA_DEBUG_MODE = 'Y' THEN
6425 pa_debug.write(g_module_name,' Return status from copy bl api is ' || l_Return_Status,3);
6426 END IF;
6427 raise PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6428 END IF;
6429
6430 --Calling Convert_Txn_Currency api to complete budget lines
6431 --in all respects
6432
6433 IF P_PA_DEBUG_MODE = 'Y' THEN
6434 pa_debug.g_err_stage := 'Calling Convert_Txn_Currency';
6435 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6436 END IF;
6437
6438 PA_FP_MULTI_CURRENCY_PKG.Convert_Txn_Currency(
6439 p_budget_version_id => l_target_version_id
6440 ,p_entire_version => 'Y'
6441 ,x_return_status => l_return_status
6442 ,x_msg_count => l_msg_count
6443 ,x_msg_data => l_msg_data);
6444
6445 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN -- Bug# 2634726
6446 raise PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6447 END IF;
6448
6449 -- Bug Fix: 4569365. Removed MRC code.
6450 -- FPB2: MRC - Calling MRC APIs
6451 /*
6452
6453 IF P_PA_DEBUG_MODE = 'Y' THEN
6454 pa_debug.g_err_stage:='Calling mrc api ........ ';
6455 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6456 END IF;
6457
6458 IF PA_MRC_FINPLAN. g_mrc_enabled_for_budgets IS NULL THEN
6459 PA_MRC_FINPLAN.check_mrc_install
6460 (x_return_status => l_return_status,
6461 x_msg_count => l_msg_count,
6462 x_msg_data => l_msg_data);
6463 END IF;
6464
6465 IF PA_MRC_FINPLAN.g_mrc_enabled_for_budgets AND
6466 PA_MRC_FINPLAN.g_finplan_mrc_option_code = 'A' THEN
6467
6468 PA_MRC_FINPLAN.g_calling_module := PA_MRC_FINPLAN.g_copy_projects; -- FPB2
6469
6470 PA_MRC_FINPLAN.maintain_all_mc_budget_lines
6471 (p_fin_plan_version_id => l_target_version_id,
6472 p_entire_version => 'Y',
6473 x_return_status => x_return_status,
6474 x_msg_count => x_msg_count,
6475 x_msg_data => x_msg_data);
6476
6477 PA_MRC_FINPLAN.g_calling_module := NULL;
6478 END IF;
6479
6480 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6481 RAISE g_mrc_exception;
6482 END IF;
6483 */
6484
6485 --Calling copy_attachments api
6486 --Copy all the source version attachments to target version
6487
6488 IF P_PA_DEBUG_MODE = 'Y' THEN
6489 pa_debug.g_err_stage := 'Calling Copy_Attachments api';
6490 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6491 END IF;
6492
6493 /* BUG FIX 2955827
6494 * copy_attachments is already done in PA_FP_COPY_FROM_PKG.Copy_Budget_Version
6495 FND_ATTACHED_DOCUMENTS2_PKG.Copy_Attachments(
6496 x_from_entity_name => 'PA_BUDGET_VERSIONS'
6497 ,x_from_pk1_value => l_source_version_id
6498 ,x_from_pk2_value => NULL
6499 ,x_from_pk3_value => NULL
6500 ,x_from_pk4_value => NULL
6501 ,x_from_pk5_value => NULL
6502 ,x_to_entity_name => 'PA_BUDGET_VERSIONS'
6503 ,x_to_pk1_value => l_target_version_id
6504 ,x_to_pk2_value => NULL
6505 ,x_to_pk3_value => NULL
6506 ,x_to_pk4_value => NULL
6507 ,x_to_pk5_value => NULL
6508 ,x_created_by => FND_GLOBAL.USER_ID
6509 ,x_last_update_login => FND_GLOBAL.LOGIN_ID
6510 ,x_program_application_id => FND_GLOBAL.PROG_APPL_ID()
6511 ,x_program_id => NULL
6512 ,x_request_id => NULL
6513 ,x_automatically_added_flag => NULL);
6514 END OF BUG FIX 2955827 */
6515
6516 --IPM Architechture Enhancement Bug 4865563 - Start
6517
6518 PA_FP_GEN_AMOUNT_UTILS.GET_PLAN_VERSION_DTLS
6519 (P_BUDGET_VERSION_ID => l_target_version_id,
6520 X_FP_COLS_REC => l_fp_cols_rec,
6521 X_RETURN_STATUS => l_return_status,
6522 X_MSG_COUNT => l_msg_count,
6523 X_MSG_DATA => l_msg_data);
6524
6525 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6526 IF P_PA_debug_mode = 'Y' THEN
6527 pa_debug.g_err_stage:= 'Error in PA_FP_GEN_AMOUNT_UTILS.GET_PLAN_VERSION_DETAILS';
6528 pa_debug.write(g_module_name,pa_debug.g_err_stage,l_debug_level5);
6529 END IF;
6530 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6531 END IF;
6532
6533 --Calling populate_display_qty for populating display_quantity in pa_budget_lines
6534 PA_BUDGET_LINES_UTILS.populate_display_qty
6535 (p_budget_version_id => l_target_version_id,
6536 p_context => 'FINANCIAL',
6537 p_use_temp_table_flag => 'N',
6538 x_return_status => l_return_status);
6539
6540 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6541 IF P_PA_debug_mode = 'Y' THEN
6542 pa_debug.g_err_stage:= 'Error in PA_BUDGET_LINES_UTILS.populate_display_qty';
6543 pa_debug.write(g_module_name,pa_debug.g_err_stage,l_debug_level5);
6544 END IF;
6545 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6546 END IF;
6547
6548 /*This piece of code calls maintain_data api with p_version_level_flag => 'N' i.e temp table mode for copying
6549 overrides from the source version and with p_rollup_flag => 'Y' for rolling up the amounts in the target
6550 version */
6551
6552 DELETE pa_resource_asgn_curr_tmp;
6553
6554 /* Populating temp table with target resource_assignment_id along with txn_curr_code and
6555 override rates from the source version of pa_resource_asgnc_curr */
6556 /*Inserting into temp table */
6557 INSERT INTO pa_resource_asgn_curr_tmp
6558 (RESOURCE_ASSIGNMENT_ID,
6559 TXN_CURRENCY_CODE,
6560 txn_raw_cost_rate_override,
6561 txn_burden_cost_rate_override,
6562 txn_bill_rate_override)
6563 SELECT
6564 pra.resource_assignment_id,
6565 rac.txn_currency_code,
6566 rac.txn_raw_cost_rate_override,
6567 rac.txn_burden_cost_rate_override,
6568 rac.txn_bill_rate_override
6569 FROM
6570 pa_resource_asgn_curr rac,
6571 pa_resource_assignments pra
6572 WHERE
6573 pra.budget_version_id = l_target_version_id and
6574 rac.budget_version_id = l_source_version_id and
6575 pra.parent_assignment_id = rac.resource_assignment_id;
6576
6577 /*Calling the maintain_data api for the 2nd time to do the rollup from
6578 pa_budget_lines. Note: This keeps the override rates copied in the
6579 previous call, intact */
6580 pa_res_asg_currency_pub.maintain_data
6581 (p_fp_cols_rec => l_fp_cols_rec,
6582 p_calling_module => 'COPY_PLAN',
6583 p_rollup_flag => 'Y', --rolling up
6584 p_version_level_flag => 'N', --temp table mode
6585 x_return_status => l_return_status,
6586 x_msg_data => l_msg_count,
6587 x_msg_count => l_msg_data);
6588
6589 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6590 IF P_PA_debug_mode = 'Y' THEN
6591 pa_debug.g_err_stage:= 'Error in PA_RES_ASG_CURRENCY_PUB.MAINTAIN_DATA while doing the rollup';
6592 pa_debug.write(g_module_name,pa_debug.g_err_stage,l_debug_level5);
6593 END IF;
6594 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6595 END IF;
6596
6597
6598 --IPM Architechture Enhancement Bug 4865563 - End
6599
6600 -- Rollup the budget version
6601 IF P_PA_DEBUG_MODE = 'Y' THEN
6602 pa_debug.g_err_stage := 'Calling Rollup_budget_version api';
6603 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6604 END IF;
6605
6606
6607 PA_FP_ROLLUP_PKG.ROLLUP_BUDGET_VERSION(
6608 p_budget_version_id => l_target_version_id
6609 ,p_entire_version => 'Y'
6610 ,x_return_status => l_return_status
6611 ,x_msg_count => l_msg_count
6612 ,x_msg_data => l_msg_data );
6613
6614 /* FP M - Reporting lines integration */
6615 l_budget_version_ids.delete;
6616 l_budget_version_ids := SYSTEM.pa_num_tbl_type(l_target_version_id);
6617
6618 IF P_PA_DEBUG_MODE = 'Y' THEN
6619 pa_debug.write('Copy_Finplans_From_Project','Calling PJI_FM_XBS_ACCUM_MAINT.PLAN_CREATE ' ,5);
6620 pa_debug.write('Copy_Finplans_From_Project','p_fp_version_ids count '|| l_budget_version_ids.count(),5);
6621 END IF;
6622
6623 /* We are sure that there is only one record. But just looping the std way */
6624 FOR I in l_budget_version_ids.first..l_budget_version_ids.last LOOP
6625 IF P_PA_DEBUG_MODE = 'Y' THEN
6626 pa_debug.write('Copy_Finplans_From_Project',''|| l_budget_version_ids(i),5);
6627 END IF;
6628 END LOOP;
6629
6630 l_src_budget_version_id_tbl.delete;
6631 l_src_budget_version_id_tbl := SYSTEM.pa_num_tbl_type(l_source_version_id);
6632 -- This parameter will be used when the source project is not equal to the target project.
6633 --This will be passed as null in the MSP flow other wise it will be defaulted to 'P'.
6634 Declare
6635 l_copy_mode VARCHAR2(1);
6636 Begin
6637 IF p_copy_version_and_elements = 'Y' THEN
6638 l_copy_mode := 'P';
6639 END IF;
6640
6641 PJI_FM_XBS_ACCUM_MAINT.PLAN_CREATE (
6642 p_fp_version_ids => l_budget_version_ids,
6643 p_fp_src_version_ids => l_src_budget_version_id_tbl,
6644 p_copy_mode => l_copy_mode,
6645 x_return_status => l_return_status,
6646 x_msg_code => l_err_stack);
6647
6648 IF l_return_status <> FND_API.G_RET_STS_SUCCESS then
6649 PA_UTILS.ADD_MESSAGE(p_app_short_name => PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_PA,
6650 p_msg_name => l_err_stack);
6651
6652 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6653 END IF;
6654
6655 End;
6656
6657
6658 --If source plan version is baselined and if the source
6659 --project is a template submit and baseline the target
6660 --plan version also if it satisfies any of the two cases
6661 --case 1: Funding is available for target project
6662 --case 2: version type created is cost version
6663
6664 --Fetch current_flag of source plan version to check if
6665 --source version is baselined
6666
6667 IF P_PA_DEBUG_MODE = 'Y' THEN
6668 pa_debug.g_err_stage := 'Fetching source version details';
6669 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6670 END IF;
6671
6672 SELECT current_flag
6673 ,record_version_number
6674 INTO l_source_current_flag
6675 ,l_source_record_version_num
6676 FROM pa_budget_versions
6677 WHERE budget_version_id = l_source_version_id;
6678
6679 --Fetch target version properties for the api calls
6680
6681 IF P_PA_DEBUG_MODE = 'Y' THEN
6682 pa_debug.g_err_stage := 'Fetching target version details';
6683 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6684 END IF;
6685
6686 SELECT record_version_number
6687 ,version_type
6688 INTO l_target_record_version_num
6689 ,l_version_type
6690 FROM pa_budget_versions
6691 WHERE budget_version_id = l_target_version_id;
6692
6693 IF (l_source_template_flag = 'Y') AND
6694 (l_source_current_flag = 'Y' )
6695 THEN
6696
6697 IF (nvl(l_funding_exists_flag,'N') = 'Y') OR
6698 (l_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST)
6699 THEN
6700
6701 --submit and baseline the the plan version
6702
6703 IF P_PA_DEBUG_MODE = 'Y' THEN
6704 pa_debug.g_err_stage := 'Calling Set_Current_Working';
6705 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6706 END IF;
6707
6708 PA_FIN_PLAN_PUB.Set_Current_Working(
6709 p_project_id => p_target_project_id
6710 ,p_budget_version_id => l_target_version_id
6711 ,p_record_version_number => NULL --l_target_record_version_num
6712 ,p_orig_budget_version_id => l_target_version_id --as this is the initial creation
6713 ,p_orig_record_version_number => NULL
6714 ,x_return_status => l_return_status
6715 ,x_msg_count => l_msg_count
6716 ,x_msg_data => l_msg_data );
6717
6718 /* Bug# 2647047 - Raise if return status is not success */
6719 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6720 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6721 END IF;
6722
6723 IF P_PA_DEBUG_MODE = 'Y' THEN
6724 pa_debug.g_err_stage := 'Calling Submit_Current_Working';
6725 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6726 END IF;
6727
6728 --Bug 3964755. In copy project flow, the version need not be locked. Added the context parameter
6729 --to submit API to skip this check.
6730 PA_FIN_PLAN_PUB.Submit_Current_Working(
6731 p_calling_context => 'COPY_PROJECT'
6732 ,p_project_id => p_target_project_id
6733 ,p_budget_version_id => l_target_version_id
6734 ,p_record_version_number => NULL --l_target_record_version_num
6735 ,x_return_status => l_return_status
6736 ,x_msg_count => l_msg_count
6737 ,x_msg_data => l_msg_data );
6738
6739 /* Bug# 2647047 - Raise if return status is not success */
6740 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6741 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6742 END IF;
6743
6744 IF P_PA_DEBUG_MODE = 'Y' THEN
6745 pa_debug.g_err_stage := 'Calling Baseline';
6746 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6747 END IF;
6748
6749 -- Bug Fix: 4569365. Removed MRC code.
6750 -- PA_MRC_FINPLAN.G_CALLING_MODULE := PA_MRC_FINPLAN.G_COPY_PROJECTS; /* FPB2 */
6751
6752 PA_FIN_PLAN_PUB.Baseline(
6753 p_project_id => p_target_project_id
6754 ,p_budget_version_id => l_target_version_id
6755 ,p_record_version_number => NUll --l_target_record_version_num
6756 ,p_orig_budget_version_id => NULL --l_target_version_id Bug # 2680859
6757 ,p_orig_record_version_number => NULL
6758 ,x_fc_version_created_flag => l_fc_version_created_flag
6759 ,x_return_status => l_return_status
6760 ,x_msg_count => l_msg_count
6761 ,x_msg_data => l_msg_data );
6762
6763 -- Bug Fix: 4569365. Removed MRC code.
6764 -- PA_MRC_FINPLAN.G_CALLING_MODULE := NULL; /* MRC */
6765
6766 /* Bug# 2647047 - Raise if return status is not success */
6767 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6768 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6769 END IF;
6770
6771 END IF;
6772
6773 END IF; --ifs used for baselining
6774 END IF; -- if version can be copied
6775
6776 END IF; -- if version
6777
6778 END LOOP; -- l_proj_fp_options_id_tbl
6779
6780 END IF; --Bug :- 2570874
6781
6782 IF P_PA_DEBUG_MODE = 'Y' THEN
6783 pa_debug.g_err_stage := 'Exiting Copy_Finplans_From_Project';
6784 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6785 pa_debug.reset_err_stack;
6786 END IF;
6787 EXCEPTION
6788
6789 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
6790
6791 l_msg_count := FND_MSG_PUB.count_msg;
6792 IF l_msg_count = 1 THEN
6793 PA_INTERFACE_UTILS_PUB.get_messages
6794 (p_encoded => FND_API.G_TRUE
6795 ,p_msg_index => 1
6796 ,p_msg_count => l_msg_count
6797 ,p_msg_data => l_msg_data
6798 ,p_data => l_data
6799 ,p_msg_index_out => l_msg_index_out);
6800 x_msg_data := l_data;
6801 x_msg_count := l_msg_count;
6802 ELSE
6803 x_msg_count := l_msg_count;
6804 END IF;
6805
6806 IF P_PA_DEBUG_MODE = 'Y' THEN
6807 pa_debug.g_err_stage:='Invalid Arguments Passed';
6808 pa_debug.write( g_module_name,pa_debug.g_err_stage,5);
6809 pa_debug.reset_err_stack;
6810 END IF;
6811 x_return_status:= FND_API.G_RET_STS_ERROR;
6812 -- bug#2753123
6813 IF l_err_stage is NOT NULL THEN
6814 x_msg_data := l_err_stage ;
6815 END IF ;
6816 -- Bug Fix: 4569365. Removed MRC code.
6817
6818 -- bug 3163280 ROLLBACK TO COPY_PROJECT;
6819 -- PA_MRC_FINPLAN.G_CALLING_MODULE := Null;
6820 RETURN ;
6821
6822 WHEN Others THEN
6823
6824 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6825 x_msg_count := 1;
6826 x_msg_data := SQLERRM;
6827 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
6828 ,p_procedure_name => 'Copy_Finplans_From_Project');
6829
6830 IF P_PA_DEBUG_MODE = 'Y' THEN
6831 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
6832 pa_debug.write( g_module_name,pa_debug.g_err_stage,5);
6833 pa_debug.reset_err_stack;
6834 END IF;
6835 -- Bug Fix: 4569365. Removed MRC code.
6836
6837 -- bug 3163280 ROLLBACK TO COPY_PROJECT;
6838 -- PA_MRC_FINPLAN.G_CALLING_MODULE := Null;
6839 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6840
6841 END Copy_Finplans_From_Project;
6842
6843
6844 /*===================================================================
6845 This is a private procedure called from Copy_Finplans_From_Project.
6846 This api populates a plsql table with all the proj_fp_options_id of
6847 source project that need to be copied to target project.
6848 Bug 2981655- Included new parameter p_copy_versions. If Y, versions
6849 will also be copied apart from plan type and project options. If N,
6850 only project and plan type options would be copied.
6851 ==================================================================*/
6852 PROCEDURE Get_Fp_Options_To_Be_Copied(
6853 p_source_project_id IN NUMBER
6854 ,p_copy_versions IN VARCHAR2
6855 ,x_fp_options_ids_tbl OUT NOCOPY PROJ_FP_OPTIONS_ID_TBL_TYP
6856 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
6857 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
6858 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
6859 AS
6860
6861 l_return_status VARCHAR2(2000);
6862 l_msg_count NUMBER :=0;
6863 l_msg_data VARCHAR2(2000);
6864 l_data VARCHAR2(2000);
6865 l_msg_index_out NUMBER;
6866 l_debug_mode VARCHAR2(30);
6867
6868 l_index NUMBER;
6869 l_fin_plan_preference_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
6870 l_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
6871 l_fin_plan_version_id pa_proj_fp_options.fin_plan_version_id%TYPE;
6872 l_fin_plan_type_id pa_proj_fp_options.fin_plan_type_id%TYPE;
6873
6874 l_proj_fp_options_id_tbl PROJ_FP_OPTIONS_ID_TBL_TYP;
6875
6876 CURSOR cur_for_fp_options(c_level_code pa_proj_fp_options.fin_plan_option_level_code%TYPE) IS
6877 SELECT pfo.proj_fp_options_id
6878 ,pfo.fin_plan_type_id
6879 ,pfo.fin_plan_preference_code
6880 FROM pa_proj_fp_options pfo
6881 ,pa_fin_plan_types_b fin
6882 WHERE project_id = p_source_project_id
6883 AND fin_plan_option_level_code = c_level_code
6884 AND pfo.fin_plan_type_id = fin.fin_plan_type_id(+)
6885 AND nvl(fin.use_for_workplan_flag,'N')<>'Y';
6886
6887
6888 BEGIN
6889
6890 x_msg_count := 0;
6891 x_return_status := FND_API.G_RET_STS_SUCCESS;
6892
6893 IF p_pa_debug_mode = 'Y' THEN
6894 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Get_Fp_Options_To_Be_Copied');
6895 pa_debug.set_process('PLSQL','LOG',p_pa_debug_mode);
6896 END IF;
6897
6898 -- Check if source project id is NULL,if so throw an error message
6899
6900 IF P_PA_DEBUG_MODE = 'Y' THEN
6901 pa_debug.g_err_stage := 'Checking for valid parameters:';
6902 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6903 END IF;
6904
6905 IF (p_source_project_id IS NULL) OR
6906 (p_copy_versions IS NULL) THEN
6907
6908 IF P_PA_DEBUG_MODE = 'Y' THEN
6909 pa_debug.g_err_stage := 'Source_project='||p_source_project_id;
6910 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6911 pa_debug.g_err_stage := 'p_copy_versions='||p_copy_versions;
6912 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
6913 END IF;
6914 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
6915 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
6916 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6917
6918 END IF;
6919
6920 IF P_PA_DEBUG_MODE = 'Y' THEN
6921 pa_debug.g_err_stage := 'Parameter validation complete';
6922 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6923 END IF;
6924
6925 --Fetch and store project level fp option id in proj_fp_options_id_tbl.
6926
6927 IF P_PA_DEBUG_MODE = 'Y' THEN
6928 pa_debug.g_err_stage := 'Fetching project level fp option id';
6929 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6930 END IF;
6931
6932 OPEN cur_for_fp_options(PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PROJECT);
6933
6934 FETCH cur_for_fp_options INTO
6935 l_proj_fp_options_id_tbl(1)
6936 ,l_fin_plan_type_id
6937 ,l_fin_plan_preference_code;
6938
6939 CLOSE cur_for_fp_options;
6940
6941 --Open and fetch fp options ids of all the plan types attached to project
6942
6943 IF P_PA_DEBUG_MODE = 'Y' THEN
6944 pa_debug.g_err_stage := 'Opening cur_for_plan_type_fp_options';
6945 pa_debug.write(g_module_name,pa_debug.g_err_stage,3);
6946 END IF;
6947
6948 OPEN cur_for_fp_options(PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_TYPE);
6949 LOOP
6950
6951 l_fp_options_id := NULL;
6952 l_fin_plan_version_id := NULL;
6953
6954 FETCH cur_for_fp_options INTO
6955 l_proj_fp_options_id_tbl(nvl(l_proj_fp_options_id_tbl.last,0)+1)
6956 ,l_fin_plan_type_id
6957 ,l_fin_plan_preference_code;
6958
6959 EXIT WHEN cur_for_fp_options%NOTFOUND;
6960
6961 IF p_copy_versions = 'Y' THEN /* Bug 2981655 */
6962
6963 --For each plan type fetched copy the options id of baselined or
6964 --current working version.
6965
6966 IF P_PA_DEBUG_MODE = 'Y' THEN
6967 pa_debug.g_err_stage := 'Preference_code ='|| l_fin_plan_preference_code;
6968 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6969 END IF;
6970
6971 --For COST_AND REV_SEP plan type we have to copy both revenue and cost
6972 --versions.
6973
6974 IF l_fin_plan_preference_code = PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SEP THEN
6975
6976 IF P_PA_DEBUG_MODE = 'Y' THEN
6977 pa_debug.g_err_stage := 'Fetching baselined cost plan version';
6978 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6979 END IF;
6980
6981 PA_FIN_PLAN_UTILS.Get_Baselined_Version_Info(
6982 p_project_id => p_source_project_id
6983 ,p_fin_plan_type_id => l_fin_plan_type_id
6984 ,p_version_type => PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST
6985 ,x_fp_options_id => l_fp_options_id
6986 ,x_fin_plan_version_id => l_fin_plan_version_id
6987 ,x_return_status => l_return_status
6988 ,x_msg_count => l_msg_count
6989 ,x_msg_data => l_msg_data );
6990
6991 --IF there is no baselined version existing fetch the options
6992 --id current working version
6993
6994 IF (l_fp_options_id IS NULL) THEN
6995
6996 IF P_PA_DEBUG_MODE = 'Y' THEN
6997 pa_debug.g_err_stage := 'Baselined plan cost version does not exist';
6998 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
6999
7000 pa_debug.g_err_stage := 'Fetching current cost woking plan version if any';
7001 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7002 END IF;
7003
7004 PA_FIN_PLAN_UTILS.Get_Curr_Working_Version_Info(
7005 p_project_id => p_source_project_id
7006 ,p_fin_plan_type_id => l_fin_plan_type_id
7007 ,p_version_type => PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST
7008 ,x_fp_options_id => l_fp_options_id
7009 ,x_fin_plan_version_id => l_fin_plan_version_id
7010 ,x_return_status => l_return_status
7011 ,x_msg_count => l_msg_count
7012 ,x_msg_data => l_msg_data );
7013
7014 END IF;
7015
7016 --Insert the fetched option id of plan version if existing
7017
7018 IF (l_fp_options_id IS NOT NULL) THEN
7019 IF P_PA_DEBUG_MODE = 'Y' THEN
7020 pa_debug.g_err_stage := 'Storing option id of cost plan version fetched';
7021 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7022 END IF;
7023
7024 l_proj_fp_options_id_tbl(nvl(l_proj_fp_options_id_tbl.last,0)+1) := l_fp_options_id;
7025 ELSE
7026 IF P_PA_DEBUG_MODE = 'Y' THEN
7027 pa_debug.g_err_stage := 'Current working cost plan version does not exist for this plan type';
7028 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7029 END IF;
7030 END IF;
7031
7032 --Fetch revenue version id for the plan type
7033
7034 IF P_PA_DEBUG_MODE = 'Y' THEN
7035 pa_debug.g_err_stage := 'Fetching baselined revenue plan version';
7036 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7037 END IF;
7038
7039 PA_FIN_PLAN_UTILS.Get_Baselined_Version_Info(
7040 p_project_id => p_source_project_id
7041 ,p_fin_plan_type_id => l_fin_plan_type_id
7042 ,p_version_type => PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE
7043 ,x_fp_options_id => l_fp_options_id
7044 ,x_fin_plan_version_id => l_fin_plan_version_id
7045 ,x_return_status => l_return_status
7046 ,x_msg_count => l_msg_count
7047 ,x_msg_data => l_msg_data );
7048
7049 --IF there is no baselined version existing fetch the options
7050 --id current working version
7051
7052 IF (l_fp_options_id IS NULL) THEN
7053
7054 IF P_PA_DEBUG_MODE = 'Y' THEN
7055 pa_debug.g_err_stage := 'Baselined plan revenue version does not exist';
7056 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7057
7058 pa_debug.g_err_stage := 'Fetching current revenue woking plan version if any';
7059 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7060 END IF;
7061
7062 PA_FIN_PLAN_UTILS.Get_Curr_Working_Version_Info(
7063 p_project_id => p_source_project_id
7064 ,p_fin_plan_type_id => l_fin_plan_type_id
7065 ,p_version_type => PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE
7066 ,x_fp_options_id => l_fp_options_id
7067 ,x_fin_plan_version_id => l_fin_plan_version_id
7068 ,x_return_status => l_return_status
7069 ,x_msg_count => l_msg_count
7070 ,x_msg_data => l_msg_data );
7071
7072 END IF;
7073
7074 --Insert the fetched option id of plan version if existing
7075
7076 IF (l_fp_options_id IS NOT NULL) THEN
7077
7078 IF P_PA_DEBUG_MODE = 'Y' THEN
7079 pa_debug.g_err_stage := 'Storing option id of revenue plan version fetched';
7080 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7081 END IF;
7082
7083 l_proj_fp_options_id_tbl(nvl(l_proj_fp_options_id_tbl.last,0)+1) := l_fp_options_id;
7084
7085 ELSE
7086 IF P_PA_DEBUG_MODE = 'Y' THEN
7087 pa_debug.g_err_stage := 'Current working revenue plan version does not exist for this plan type';
7088 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7089 END IF;
7090 END IF;
7091
7092 ELSE
7093
7094 --Fetch baselined plan version id for the plan type
7095
7096 IF P_PA_DEBUG_MODE = 'Y' THEN
7097 pa_debug.g_err_stage := 'Fetching baselined plan version if any';
7098 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7099 END IF;
7100
7101 PA_FIN_PLAN_UTILS.Get_Baselined_Version_Info(
7102 p_project_id => p_source_project_id
7103 ,p_fin_plan_type_id => l_fin_plan_type_id
7104 ,p_version_type => NULL
7105 ,x_fp_options_id => l_fp_options_id
7106 ,x_fin_plan_version_id => l_fin_plan_version_id
7107 ,x_return_status => l_return_status
7108 ,x_msg_count => l_msg_count
7109 ,x_msg_data => l_msg_data );
7110
7111 --IF there is no baselined version existing fetch the options
7112 --id current working version
7113
7114 IF (l_fp_options_id IS NULL) THEN
7115
7116 IF P_PA_DEBUG_MODE = 'Y' THEN
7117 pa_debug.g_err_stage := 'Baselined plan version does not exist';
7118 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7119
7120 pa_debug.g_err_stage := 'Fetching current woking plan version if any';
7121 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7122 END IF;
7123
7124 PA_FIN_PLAN_UTILS.Get_Curr_Working_Version_Info(
7125 p_project_id => p_source_project_id
7126 ,p_fin_plan_type_id => l_fin_plan_type_id
7127 ,p_version_type => NULL
7128 ,x_fp_options_id => l_fp_options_id
7129 ,x_fin_plan_version_id => l_fin_plan_version_id
7130 ,x_return_status => l_return_status
7131 ,x_msg_count => l_msg_count
7132 ,x_msg_data => l_msg_data );
7133
7134 END IF;
7135
7136 --Insert the fetched option id of plan version if existing
7137
7138 IF (l_fp_options_id IS NOT NULL) THEN
7139
7140 IF P_PA_DEBUG_MODE = 'Y' THEN
7141 pa_debug.g_err_stage := 'Storing option id of plan version fetched';
7142 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7143 END IF;
7144
7145 l_proj_fp_options_id_tbl(nvl(l_proj_fp_options_id_tbl.last,0)+1) := l_fp_options_id;
7146
7147 ELSE
7148 IF P_PA_DEBUG_MODE = 'Y' THEN
7149 pa_debug.g_err_stage := 'Current working plan version does not exist for this plan type';
7150 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7151 END IF;
7152 END IF;
7153 END IF; --l_fin_plan_preference_code
7154
7155 END IF; /* p_copy_versions = 'Y' */
7156
7157 END LOOP;
7158 CLOSE cur_for_fp_options;
7159
7160 --Return the fp_options_id tbl;
7161
7162 x_fp_options_ids_tbl := l_proj_fp_options_id_tbl;
7163
7164 IF P_PA_DEBUG_MODE = 'Y' THEN
7165 pa_debug.g_err_stage := 'Exiting Get_Fp_Options_To_Be_Copied';
7166 pa_debug.write( g_module_name,pa_debug.g_err_stage,3);
7167 pa_debug.reset_err_stack;
7168 END IF;
7169
7170 EXCEPTION
7171
7172 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
7173 l_msg_count := FND_MSG_PUB.count_msg;
7174 IF l_msg_count = 1 THEN
7175 PA_INTERFACE_UTILS_PUB.get_messages
7176 (p_encoded => FND_API.G_TRUE
7177 ,p_msg_index => 1
7178 ,p_msg_count => l_msg_count
7179 ,p_msg_data => l_msg_data
7180 ,p_data => l_data
7181 ,p_msg_index_out => l_msg_index_out);
7182 x_msg_data := l_data;
7183 x_msg_count := l_msg_count;
7184 ELSE
7185 x_msg_count := l_msg_count;
7186 END IF;
7187
7188 IF P_PA_DEBUG_MODE = 'Y' THEN
7189 pa_debug.g_err_stage:='Invalid Arguments Passed';
7190 pa_debug.write( g_module_name,pa_debug.g_err_stage,5);
7191 pa_debug.reset_err_stack;
7192 END IF;
7193 x_return_status:= FND_API.G_RET_STS_ERROR;
7194
7195 RAISE;
7196
7197 WHEN Others THEN
7198
7199 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7200 x_msg_count := 1;
7201 x_msg_data := SQLERRM;
7202 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
7203 ,p_procedure_name => 'Get_Fp_Options_To_Be_Copied');
7204
7205 IF P_PA_DEBUG_MODE = 'Y' THEN
7206 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
7207 pa_debug.write( g_module_name,pa_debug.g_err_stage,5);
7208 pa_debug.reset_err_stack;
7209 END IF;
7210 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7211
7212 END Get_Fp_Options_To_Be_Copied;
7213
7214
7215 /* Bug# 2634726 -
7216 Private procedure (not available in specification) used by COPY_BUDGET_LINES
7217 (with shift days logic) to insert shifted periods data into pa_fp_cpy_period_tmp */
7218
7219 PROCEDURE populate_cpy_periods_tmp(p_budget_version_id PA_BUDGET_LINES.budget_version_id%type,
7220 p_period_type PA_PROJ_FP_OPTIONS.cost_time_phased_code%TYPE,
7221 p_shift_periods number) AS
7222 cursor bl_periods is
7223 SELECT distinct bl.period_name,bl.start_date
7224 FROM pa_budget_lines bl
7225 WHERE budget_version_id = p_budget_version_id;
7226
7227 l_err_code NUMBER;
7228 l_err_stage VARCHAR2(2000);
7229 l_err_stack VARCHAR2(2000);
7230 l_period_name PA_BUDGET_PERIODS_V.period_name%TYPE;
7231 l_start_date DATE;
7232 l_end_date DATE;
7233
7234 BEGIN
7235
7236 DELETE FROM pa_fp_cpy_periods_tmp;
7237
7238 FOR i IN bl_periods LOOP
7239
7240 l_period_name := NULL;
7241 l_start_date := NULL;
7242 l_end_date := NULL;
7243 l_err_code := NULL;
7244 l_err_stage := NULL;
7245 l_err_stack := NULL;
7246
7247 pa_budget_core.shift_periods(
7248 x_start_period_date => i.start_date,
7249 x_periods => p_shift_periods,
7250 x_period_name => l_period_name,
7251 x_period_type => p_period_type,
7252 x_start_date => l_start_date,
7253 x_end_date => l_end_date,
7254 x_err_code => l_err_code,
7255 x_err_stage => l_err_stage,
7256 x_err_stack => l_err_stack);
7257 IF l_err_code <> 0 THEN
7258 IF P_PA_DEBUG_MODE = 'Y' THEN
7259 pa_debug.g_err_stage := 'Exception raised by pa_budget_core.shift_periods...';
7260 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7261 END IF;
7262
7263 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
7264 p_msg_name => l_err_stage);
7265 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
7266 END IF;
7267
7268 INSERT INTO pa_fp_cpy_periods_tmp
7269 (PA_PERIOD_NAME
7270 ,GL_PERIOD_NAME
7271 ,PERIOD_NAME
7272 ,START_DATE
7273 ,END_DATE)
7274 VALUES
7275 (decode(p_period_type,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P,i.period_name,'-99')
7276 ,decode(p_period_type,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,i.period_name,'-99')
7277 ,l_period_name
7278 ,l_start_date
7279 ,l_end_date);
7280 END LOOP;
7281
7282 END populate_cpy_periods_tmp;
7283
7284 /*=========================================================================
7285 This api inserts budget lines for target using source budget lines. If
7286 the shift days are zero, this api will copy from source to target version
7287 without shifting any periods. If shift days are non-zero,then we shift
7288 periods according to the existing businees rules. project and projfunc
7289 currencies amounts copied as NULL and would be populated by
7290 convert_txn_currency api.
7291 This is an overloaded procedure as of now used during copying projects.
7292
7293 21-Sep-04 Raja Bug 3841942
7294 During copy project flow, for non-time phased budgets
7295 start and end date should be same as planning start and
7296 end date of the resource assignment
7297
7298 2) If shift days i/p is not sufficient enough to cause
7299 shift in periods changed the code to behave as if
7300 shift days is zero.
7301 =========================================================================*/
7302
7303 PROCEDURE Copy_Budget_Lines(
7304 p_source_project_id IN NUMBER
7305 ,p_target_project_id IN NUMBER
7306 ,p_source_plan_version_id IN NUMBER
7307 ,p_target_plan_version_id IN NUMBER
7308 ,p_shift_days IN NUMBER
7309 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
7310 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
7311 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
7312 AS
7313
7314 l_msg_count NUMBER :=0;
7315 l_data VARCHAR2(2000);
7316 l_msg_data VARCHAR2(2000);
7317 l_error_msg_code VARCHAR2(2000);
7318 l_msg_index_out NUMBER;
7319 l_return_status VARCHAR2(2000);
7320 l_debug_mode VARCHAR2(30);
7321
7322 l_shift_days NUMBER;
7323 l_target_time_phased_code pa_proj_fp_options.all_time_phased_code%TYPE;
7324 l_target_budget_entry_level pa_proj_fp_options.all_fin_plan_level_code%TYPE; /* bug2726011 */
7325 l_target_proj_start_date DATE; /*bug2726011*/
7326 l_target_proj_completion_date DATE; /*bug2726011*/
7327
7328 /* Bug# 2634726 */
7329
7330 l_start_date DATE;
7331 l_err_code NUMBER;
7332 l_err_stage VARCHAR2(2000);
7333 l_err_stack VARCHAR2(2000);
7334 l_periods NUMBER := 0;
7335
7336 /* Bug# 2634726 */
7337
7338 BEGIN
7339
7340 x_msg_count := 0;
7341 x_return_status := FND_API.G_RET_STS_SUCCESS;
7342 IF P_PA_DEBUG_MODE = 'Y' THEN
7343 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Budget_Lines');
7344 END IF;
7345 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
7346 l_debug_mode := NVL(l_debug_mode, 'Y');
7347 IF P_PA_DEBUG_MODE = 'Y' THEN
7348 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
7349 END IF;
7350 -- Checking for all valid input parametrs
7351
7352 IF P_PA_DEBUG_MODE = 'Y' THEN
7353 pa_debug.g_err_stage := 'Checking for valid parameters:';
7354 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7355 END IF;
7356
7357 IF (p_source_plan_version_id IS NULL) OR
7358 (p_target_plan_version_id IS NULL) OR
7359 (p_source_project_id IS NULL) OR
7360 (p_target_project_id IS NULL)
7361 THEN
7362
7363 IF P_PA_DEBUG_MODE = 'Y' THEN
7364 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
7365 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7366 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
7367 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7368 pa_debug.g_err_stage := 'Source_project='||p_source_project_id;
7369 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7370 pa_debug.g_err_stage := 'Target_project'||p_target_project_id;
7371 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7372 END IF;
7373
7374 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
7375 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
7376 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
7377
7378 END IF;
7379
7380 IF P_PA_DEBUG_MODE = 'Y' THEN
7381 pa_debug.g_err_stage := 'Parameter validation complete';
7382 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7383 END IF;
7384
7385 --Make shift_days zero if passed as null
7386
7387 l_shift_days := NVL(p_shift_days,0);
7388
7389 IF P_PA_DEBUG_MODE = 'Y' THEN
7390 pa_debug.g_err_stage:='Shift_days ='|| l_shift_days;
7391 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7392 END IF;
7393
7394 --Fetch the target versions time phased code
7395
7396 l_target_time_phased_code := PA_FIN_PLAN_UTILS.get_time_phased_code(p_target_plan_version_id);
7397 l_target_budget_entry_level := PA_FIN_PLAN_UTILS.get_fin_plan_level_code(p_target_plan_version_id); /*bug2726011*/
7398
7399 IF P_PA_DEBUG_MODE = 'Y' THEN
7400 pa_debug.g_err_stage:='Time Phased Code ='|| l_target_time_phased_code;
7401 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7402 pa_debug.g_err_stage:='Budget Entry Level ='|| l_target_budget_entry_level;
7403 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7404 pa_debug.g_err_stage:='Inserting into pa_budget_lines';
7405 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7406 END IF;
7407
7408 IF P_PA_DEBUG_MODE = 'Y' THEN
7409 pa_debug.g_err_stage := 'Selecting project start and completion dates';
7410 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7411 END IF;
7412
7413 SELECT start_date,
7414 completion_date
7415 INTO l_target_proj_start_date,
7416 l_target_proj_completion_date
7417 FROM pa_projects p
7418 WHERE p.project_id = p_target_project_id;
7419
7420 IF l_shift_days <> 0
7421 AND l_target_time_phased_code IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,
7422 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P)
7423 THEN
7424 BEGIN
7425
7426 IF P_PA_DEBUG_MODE = 'Y' THEN
7427 pa_debug.g_err_stage := 'Selecting project start date';
7428 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7429 END IF;
7430
7431 SELECT p.start_date
7432 INTO l_start_date
7433 FROM pa_projects p
7434 WHERE p.project_id = p_source_project_id;
7435
7436 IF l_start_date IS NULL THEN
7437
7438 IF P_PA_DEBUG_MODE = 'Y' THEN
7439 pa_debug.g_err_stage := 'Selecting task mininum start date';
7440 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7441 END IF;
7442
7443 SELECt min(t.start_date)
7444 INTO l_start_date
7445 FROM pa_tasks t
7446 WHERE t.project_id = p_source_project_id;
7447
7448 IF l_start_date is NULL THEN
7449
7450 IF P_PA_DEBUG_MODE = 'Y' THEN
7451 pa_debug.g_err_stage := 'Selecting budget lines minimum start date';
7452 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
7453 END IF;
7454
7455 SELECT min(bl.start_date)
7456 INTO l_start_Date
7457 FROM pa_budget_lines bl
7458 WHERE bl.budget_version_id = p_source_plan_version_id;
7459
7460 -- If l_start_date is null after the above select it implies
7461 -- there are no budget lines. So return immediately as nothing
7462 -- needs to be copied
7463 IF l_start_Date IS NULL THEN
7464 pa_debug.reset_err_stack;
7465 RETURN;
7466 END IF;
7467
7468 END IF; /* Mininum Task start date is null */
7469
7470 END IF; /* Minimum Project start date is null */
7471 EXCEPTION
7472 WHEN OTHERS THEN
7473 IF P_PA_DEBUG_MODE = 'Y' THEN
7474 pa_debug.g_err_stage := 'Error while fetching start date ' || sqlerrm;
7475 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7476 END IF;
7477 RAISE;
7478 END;
7479
7480 --Based on the shift_days check how much shift is required period wise
7481 pa_budget_core.get_periods(
7482 x_start_date1 => l_start_date,
7483 x_start_date2 => l_start_date + l_shift_days,
7484 x_period_type => l_target_time_phased_code,
7485 x_periods => l_periods,
7486 x_err_code => l_err_code,
7487 x_err_stage => l_err_stage,
7488 x_err_stack => l_err_stack);
7489 IF l_err_code <> 0 THEN
7490 IF P_PA_DEBUG_MODE = 'Y' THEN
7491 pa_debug.g_err_stage := 'Exception raised by pa_budget_core.get_periods...';
7492 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
7493 END IF;
7494
7495 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
7496 p_msg_name => l_err_stage);
7497 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
7498 END IF;
7499 END IF; /* IF l_shift_days <> 0 AND l_target_time_phased_code IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P) */
7500
7501 --If shift_days is zero or the timephasing is none.
7502
7503 IF (l_shift_days = 0) OR (l_periods = 0) OR
7504 (l_target_time_phased_code NOT IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,
7505 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P))
7506 THEN
7507 /* If the time phasing is none, stamp the resource assignments' planning
7508 start and end dates for budget line start and end dates
7509 */
7510 --Display_quantity is being set in copy_version and copy_finplans_from_project api as well
7511
7512 INSERT INTO PA_BUDGET_LINES(
7513 budget_line_id /* FPB2 */
7514 ,budget_version_id /* FPB2 */
7515 ,resource_assignment_id
7516 ,start_date
7517 ,last_update_date
7518 ,last_updated_by
7519 ,creation_date
7520 ,created_by
7521 ,last_update_login
7522 ,end_date
7523 ,period_name
7524 ,quantity
7525 ,display_quantity --IPM Arch Enhancement Bug 4865563.
7526 ,raw_cost
7527 ,burdened_cost
7528 ,revenue
7529 ,change_reason_code
7530 ,description
7531 ,attribute_category
7532 ,attribute1
7533 ,attribute2
7534 ,attribute3
7535 ,attribute4
7536 ,attribute5
7537 ,attribute6
7538 ,attribute7
7539 ,attribute8
7540 ,attribute9
7541 ,attribute10
7542 ,attribute11
7543 ,attribute12
7544 ,attribute13
7545 ,attribute14
7546 ,attribute15
7547 ,raw_cost_source
7548 ,burdened_cost_source
7549 ,quantity_source
7550 ,revenue_source
7551 ,pm_product_code
7552 ,pm_budget_line_reference
7553 ,cost_rejection_code
7554 ,revenue_rejection_code
7555 ,burden_rejection_code
7556 ,other_rejection_code
7557 ,code_combination_id
7558 ,ccid_gen_status_code
7559 ,ccid_gen_rej_message
7560 ,request_id
7561 ,borrowed_revenue
7562 ,tp_revenue_in
7563 ,tp_revenue_out
7564 ,revenue_adj
7565 ,lent_resource_cost
7566 ,tp_cost_in
7567 ,tp_cost_out
7568 ,cost_adj
7569 ,unassigned_time_cost
7570 ,utilization_percent
7571 ,utilization_hours
7572 ,utilization_adj
7573 ,capacity
7574 ,head_count
7575 ,head_count_adj
7576 ,projfunc_currency_code
7577 ,projfunc_cost_rate_type
7578 ,projfunc_cost_exchange_rate
7579 ,projfunc_cost_rate_date_type
7580 ,projfunc_cost_rate_date
7581 ,projfunc_rev_rate_type
7582 ,projfunc_rev_exchange_rate
7583 ,projfunc_rev_rate_date_type
7584 ,projfunc_rev_rate_date
7585 ,project_currency_code
7586 ,project_cost_rate_type
7587 ,project_cost_exchange_rate
7588 ,project_cost_rate_date_type
7589 ,project_cost_rate_date
7590 ,project_raw_cost
7591 ,project_burdened_cost
7592 ,project_rev_rate_type
7593 ,project_rev_exchange_rate
7594 ,project_rev_rate_date_type
7595 ,project_rev_rate_date
7596 ,project_revenue
7597 ,txn_raw_cost
7598 ,txn_burdened_cost
7599 ,txn_currency_code
7600 ,txn_revenue
7601 ,bucketing_period_code
7602 -- 3/28/2004 FP M phase II Copy Project Impact
7603 ,txn_standard_cost_rate
7604 ,txn_cost_rate_override
7605 ,cost_ind_compiled_set_id
7606 ,txn_standard_bill_rate
7607 ,txn_bill_rate_override
7608 ,txn_markup_percent
7609 ,txn_markup_percent_override
7610 ,txn_discount_percentage
7611 ,transfer_price_rate
7612 ,init_quantity
7613 ,init_quantity_source
7614 ,init_raw_cost
7615 ,init_burdened_cost
7616 ,init_revenue
7617 ,init_raw_cost_source
7618 ,init_burdened_cost_source
7619 ,init_revenue_source
7620 ,project_init_raw_cost
7621 ,project_init_burdened_cost
7622 ,project_init_revenue
7623 ,txn_init_raw_cost
7624 ,txn_init_burdened_cost
7625 ,txn_init_revenue
7626 ,burden_cost_rate
7627 ,burden_cost_rate_override
7628 ,pc_cur_conv_rejection_code
7629 ,pfc_cur_conv_rejection_code
7630
7631 )
7632 SELECT pa_budget_lines_s.nextval /* FPB2 */
7633 ,p_target_plan_version_id /* FPB2 */
7634 ,pra.resource_assignment_id
7635 ,DECODE(l_target_time_phased_code,
7636 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_N,nvl(l_target_proj_start_date , pbl.start_date + l_shift_days), --Bug 4739375,l_target_proj_start_date.--bug 3841942 l_target_proj_start_date,
7637 pbl.start_date ) -- start_date
7638 ,sysdate
7639 ,fnd_global.user_id
7640 ,sysdate
7641 ,fnd_global.user_id
7642 ,fnd_global.login_id
7643 -- Commented by skkoppul for bug 7238582 and replaced this with the decode statement below
7644 -- ,DECODE(l_target_time_phased_code,
7645 -- PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_N, nvl(l_target_proj_completion_date, pbl.end_date + l_shift_days), --Bug 4739375,l_target_proj_completion_date,--bug 3841942 l_target_proj_completion_date,
7646 -- pbl.end_date ) -- end_date
7647 -- Default end date with start date if start date > end date else leave end date as is
7648 ,DECODE(SIGN(DECODE(l_target_time_phased_code,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_N,
7649 nvl(l_target_proj_start_date, pbl.start_date + l_shift_days), pbl.start_date)
7650 -
7651 DECODE(l_target_time_phased_code,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_N,
7652 nvl(l_target_proj_completion_date, pbl.end_date + l_shift_days), pbl.end_date )),
7653 1,
7654 DECODE(l_target_time_phased_code,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_N,
7655 nvl(l_target_proj_start_date, pbl.start_date + l_shift_days), pbl.start_date),
7656 DECODE(l_target_time_phased_code,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_N,
7657 nvl(l_target_proj_completion_date, pbl.end_date + l_shift_days), pbl.end_date)) -- end_date
7658 ,pbl.period_name
7659 ,pbl.quantity
7660 ,pbl.display_quantity --IPM Arch Enhancement Bug 4865563.
7661 ,NULL --raw_cost
7662 ,NULL --burdened_cost
7663 ,NULL --revenue
7664 ,NULL --change_reason_code
7665 ,pbl.description
7666 ,pbl.attribute_category
7667 ,pbl.attribute1
7668 ,pbl.attribute2
7669 ,pbl.attribute3
7670 ,pbl.attribute4
7671 ,pbl.attribute5
7672 ,pbl.attribute6
7673 ,pbl.attribute7
7674 ,pbl.attribute8
7675 ,pbl.attribute9
7676 ,pbl.attribute10
7677 ,pbl.attribute11
7678 ,pbl.attribute12
7679 ,pbl.attribute13
7680 ,pbl.attribute14
7681 ,pbl.attribute15
7682 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --raw_cost_souce
7683 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --burdened_cost_source
7684 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --quantity_source
7685 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --revenue source
7686 ,NULL --pm_product_code
7687 ,NULL --pm_budget_line_reference
7688 ,cost_rejection_code
7689 ,revenue_rejection_code
7690 ,burden_rejection_code
7691 ,other_rejection_code
7692 ,code_combination_id
7693 ,ccid_gen_status_code
7694 ,ccid_gen_rej_message
7695 ,fnd_global.conc_request_id
7696 ,borrowed_revenue
7697 ,tp_revenue_in
7698 ,tp_revenue_out
7699 ,revenue_adj
7700 ,lent_resource_cost
7701 ,tp_cost_in
7702 ,tp_cost_out
7703 ,cost_adj
7704 ,unassigned_time_cost
7705 ,utilization_percent
7706 ,utilization_hours
7707 ,utilization_adj
7708 ,capacity
7709 ,head_count
7710 ,head_count_adj
7711 ,pbl.projfunc_currency_code
7712 ,pbl.projfunc_cost_rate_type
7713 ,pbl.projfunc_cost_exchange_rate
7714 ,pbl.projfunc_cost_rate_date_type
7715 ,pbl.projfunc_cost_rate_date
7716 ,pbl.projfunc_rev_rate_type
7717 ,pbl.projfunc_rev_exchange_rate
7718 ,pbl.projfunc_rev_rate_date_type
7719 ,pbl.projfunc_rev_rate_date
7720 ,pbl.project_currency_code
7721 ,pbl.project_cost_rate_type
7722 ,pbl.project_cost_exchange_rate
7723 ,pbl.project_cost_rate_date_type
7724 ,pbl.project_cost_rate_date
7725 ,NULL --project_raw_cost
7726 ,NULL --project_burdened_cost
7727 ,pbl.project_rev_rate_type
7728 ,pbl.project_rev_exchange_rate
7729 ,pbl.project_rev_rate_date_type
7730 ,pbl.project_rev_rate_date
7731 ,NULL --project_revenue
7732 ,txn_raw_cost
7733 ,txn_burdened_cost
7734 ,txn_currency_code
7735 ,txn_revenue
7736 ,NULL --bucketing_period_code
7737 -- 3/28/2004 FP M phase II Copy Project Impact
7738 ,NULL -- txn_standard_cost_rate
7739 ,nvl(txn_cost_rate_override,txn_standard_cost_rate) -- txn_cost_rate_override
7740 ,cost_ind_compiled_set_id
7741 ,NULL -- txn_standard_bill_rate
7742 ,nvl(txn_bill_rate_override,txn_standard_bill_rate) -- txn_bill_rate_override
7743 ,NULL -- txn_markup_percent
7744 ,nvl(txn_markup_percent_override,txn_markup_percent)-- txn_markup_percent_override
7745 ,txn_discount_percentage
7746 ,transfer_price_rate
7747 ,NULL -- init_quantity
7748 ,NULL -- init_quantity_source
7749 ,NULL -- init_raw_cost
7750 ,NULL -- init_burdened_cost
7751 ,NULL -- init_revenue
7752 ,NULL -- init_raw_cost_source
7753 ,NULL -- init_burdened_cost_source
7754 ,NULL -- init_revenue_source
7755 ,NULL -- project_init_raw_cost
7756 ,NULL -- project_init_burdened_cost
7757 ,NULL -- project_init_revenue
7758 ,NULL -- txn_init_raw_cost
7759 ,NULL -- txn_init_burdened_cost
7760 ,NULL -- txn_init_revenue
7761 ,NULL -- burden_cost_rate
7762 ,nvl(burden_cost_rate_override,burden_cost_rate) -- burden_cost_rate_override
7763 ,NULL -- pc_cur_conv_rejection_code
7764 ,NULL -- pfc_cur_conv_rejection_code
7765
7766 FROM PA_BUDGET_LINES pbl
7767 ,pa_resource_assignments pra
7768 WHERE pbl.resource_assignment_id = pra.parent_assignment_id
7769 AND pbl.budget_version_id = p_source_plan_version_id
7770 AND pra.budget_version_id=p_target_plan_version_id;
7771
7772
7773 /* Start of Code Fix for Bug:4739375.*/
7774
7775 IF (l_target_time_phased_code NOT IN(PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,
7776 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P)) THEN
7777 /*
7778 UPDATE pa_resource_assignments pra
7779 SET (pra.planning_start_date , pra.planning_end_date , pra.sp_fixed_date)
7780 = (SELECT least(pra.planning_start_date + l_shift_days,
7781 nvl(min(bl.start_date) , pra.planning_start_date + l_shift_days)),
7782 greatest(pra.planning_end_date + l_shift_days,
7783 nvl(max(bl.end_date) , pra.planning_end_date + l_shift_days)),
7784 greatest(least(pra.sp_fixed_date + l_shift_days , pra.planning_end_date + l_shift_days),
7785 pra.planning_start_date + l_shift_days)
7786 FROM pa_budget_lines bl
7787 WHERE bl.resource_assignment_id = pra.resource_assignment_id
7788 )
7789 WHERE pra.budget_version_id = p_target_plan_version_id;
7790 */
7791 /* Bug 5846751: Commented the above update and added a new update to derive the Resource Assignment's
7792 dates similar to that of the Budget Lines start and end dates in the above INSERT statement. */
7793 update pa_resource_assignments pra
7794 set (pra.planning_start_date, pra.planning_end_date,pra.sp_fixed_date)
7795 = ( select nvl(min(bl.start_date),nvl(l_target_proj_start_date, pra.planning_start_date + l_shift_days)),
7796 nvl(min(bl.end_date),nvl(l_target_proj_completion_date, pra.planning_end_date + l_shift_days)),
7797 decode(pra.sp_fixed_date,null,null,nvl(min(bl.start_date),nvl(l_target_proj_start_date, pra.sp_fixed_date + l_shift_days)))
7798 from pa_budget_lines bl
7799 where bl.resource_assignment_id = pra.resource_assignment_id
7800 )
7801 where pra.budget_version_id = p_target_plan_version_id;
7802
7803 END IF;
7804
7805 /*End of Code Fix for Bug:4739375*/
7806
7807
7808 ELSE
7809
7810 /* Start of code fix for bug# 2634726 */
7811
7812 -- Call a private api to populate pa_fp_cpy_periods_tmp table
7813 populate_cpy_periods_tmp(p_budget_version_id => p_source_plan_version_id,
7814 p_period_type => l_target_time_phased_code,
7815 p_shift_periods => l_periods);
7816
7817 -- Shift the pa_periods by l_periods
7818 -- Bug# 2634726- The two individual inserts which read pa_periods or gl_period_statuses based
7819 -- on the l_target_time_phased_code condition have been merged into one insert which reads
7820 -- pa_fp_cpy_periods_tmp
7821
7822 INSERT INTO PA_BUDGET_LINES(
7823 budget_line_id /* FPB2 */
7824 ,budget_version_id /* FPB2 */
7825 ,resource_assignment_id
7826 ,start_date
7827 ,last_update_date
7828 ,last_updated_by
7829 ,creation_date
7830 ,created_by
7831 ,last_update_login
7832 ,end_date
7833 ,period_name
7834 ,quantity
7835 ,display_quantity --IPM Arch Enhancement Bug 4865563
7836 ,raw_cost
7837 ,burdened_cost
7838 ,revenue
7839 ,change_reason_code
7840 ,description
7841 ,attribute_category
7842 ,attribute1
7843 ,attribute2
7844 ,attribute3
7845 ,attribute4
7846 ,attribute5
7847 ,attribute6
7848 ,attribute7
7849 ,attribute8
7850 ,attribute9
7851 ,attribute10
7852 ,attribute11
7853 ,attribute12
7854 ,attribute13
7855 ,attribute14
7856 ,attribute15
7857 ,raw_cost_source
7858 ,burdened_cost_source
7859 ,quantity_source
7860 ,revenue_source
7861 ,pm_product_code
7862 ,pm_budget_line_reference
7863 ,cost_rejection_code
7864 ,revenue_rejection_code
7865 ,burden_rejection_code
7866 ,other_rejection_code
7867 ,code_combination_id
7868 ,ccid_gen_status_code
7869 ,ccid_gen_rej_message
7870 ,request_id
7871 ,borrowed_revenue
7872 ,tp_revenue_in
7873 ,tp_revenue_out
7874 ,revenue_adj
7875 ,lent_resource_cost
7876 ,tp_cost_in
7877 ,tp_cost_out
7878 ,cost_adj
7879 ,unassigned_time_cost
7880 ,utilization_percent
7881 ,utilization_hours
7882 ,utilization_adj
7883 ,capacity
7884 ,head_count
7885 ,head_count_adj
7886 ,projfunc_currency_code
7887 ,projfunc_cost_rate_type
7888 ,projfunc_cost_exchange_rate
7889 ,projfunc_cost_rate_date_type
7890 ,projfunc_cost_rate_date
7891 ,projfunc_rev_rate_type
7892 ,projfunc_rev_exchange_rate
7893 ,projfunc_rev_rate_date_type
7894 ,projfunc_rev_rate_date
7895 ,project_currency_code
7896 ,project_cost_rate_type
7897 ,project_cost_exchange_rate
7898 ,project_cost_rate_date_type
7899 ,project_cost_rate_date
7900 ,project_raw_cost
7901 ,project_burdened_cost
7902 ,project_rev_rate_type
7903 ,project_rev_exchange_rate
7904 ,project_rev_rate_date_type
7905 ,project_rev_rate_date
7906 ,project_revenue
7907 ,txn_raw_cost
7908 ,txn_burdened_cost
7909 ,txn_currency_code
7910 ,txn_revenue
7911 ,bucketing_period_code
7912 -- 3/28/2004 FP M phase II Copy Project Impact
7913 ,txn_standard_cost_rate
7914 ,txn_cost_rate_override
7915 ,cost_ind_compiled_set_id
7916 ,txn_standard_bill_rate
7917 ,txn_bill_rate_override
7918 ,txn_markup_percent
7919 ,txn_markup_percent_override
7920 ,txn_discount_percentage
7921 ,transfer_price_rate
7922 ,init_quantity
7923 ,init_quantity_source
7924 ,init_raw_cost
7925 ,init_burdened_cost
7926 ,init_revenue
7927 ,init_raw_cost_source
7928 ,init_burdened_cost_source
7929 ,init_revenue_source
7930 ,project_init_raw_cost
7931 ,project_init_burdened_cost
7932 ,project_init_revenue
7933 ,txn_init_raw_cost
7934 ,txn_init_burdened_cost
7935 ,txn_init_revenue
7936 ,burden_cost_rate
7937 ,burden_cost_rate_override
7938 ,pc_cur_conv_rejection_code
7939 ,pfc_cur_conv_rejection_code
7940 )
7941 SELECT pa_budget_lines_s.nextval /* FPB2 */
7942 ,p_target_plan_version_id /* FPB2 */
7943 ,pra.resource_assignment_id
7944 ,pptmp.start_date
7945 ,sysdate
7946 ,fnd_global.user_id
7947 ,sysdate
7948 ,fnd_global.user_id
7949 ,fnd_global.login_id
7950 ,pptmp.end_date
7951 ,pptmp.period_name
7952 ,pbl.quantity
7953 ,pbl.display_quantity --IPM Arch Enhancement Bug 4865563
7954 ,NULL --raw_cost
7955 ,NULL --burdened_cost
7956 ,NULL --revenue
7957 ,NULL --change_reason_code
7958 ,pbl.description
7959 ,pbl.attribute_category
7960 ,pbl.attribute1
7961 ,pbl.attribute2
7962 ,pbl.attribute3
7963 ,pbl.attribute4
7964 ,pbl.attribute5
7965 ,pbl.attribute6
7966 ,pbl.attribute7
7967 ,pbl.attribute8
7968 ,pbl.attribute9
7969 ,pbl.attribute10
7970 ,pbl.attribute11
7971 ,pbl.attribute12
7972 ,pbl.attribute13
7973 ,pbl.attribute14
7974 ,pbl.attribute15
7975 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --raw_cost_souce
7976 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --burdened_cost_source
7977 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --quantity_source
7978 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_MANUAL_M --revenue source
7979 ,NULL --pm_product_code
7980 ,NULL --pm_budget_line_reference
7981 ,cost_rejection_code
7982 ,revenue_rejection_code
7983 ,burden_rejection_code
7984 ,other_rejection_code
7985 ,code_combination_id
7986 ,ccid_gen_status_code
7987 ,ccid_gen_rej_message
7988 ,fnd_global.conc_request_id
7989 ,borrowed_revenue
7990 ,tp_revenue_in
7991 ,tp_revenue_out
7992 ,revenue_adj
7993 ,lent_resource_cost
7994 ,tp_cost_in
7995 ,tp_cost_out
7996 ,cost_adj
7997 ,unassigned_time_cost
7998 ,utilization_percent
7999 ,utilization_hours
8000 ,utilization_adj
8001 ,capacity
8002 ,head_count
8003 ,head_count_adj
8004 ,pbl.projfunc_currency_code
8005 ,pbl.projfunc_cost_rate_type
8006 ,pbl.projfunc_cost_exchange_rate
8007 ,pbl.projfunc_cost_rate_date_type
8008 ,pbl.projfunc_cost_rate_date
8009 ,pbl.projfunc_rev_rate_type
8010 ,pbl.projfunc_rev_exchange_rate
8011 ,pbl.projfunc_rev_rate_date_type
8012 ,pbl.projfunc_rev_rate_date
8013 ,pbl.project_currency_code
8014 ,pbl.project_cost_rate_type
8015 ,pbl.project_cost_exchange_rate
8016 ,pbl.project_cost_rate_date_type
8017 ,pbl.project_cost_rate_date
8018 ,NULL --project_raw_cost
8019 ,NULL --project_burdened_cost
8020 ,pbl.project_rev_rate_type
8021 ,pbl.project_rev_exchange_rate
8022 ,pbl.project_rev_rate_date_type
8023 ,pbl.project_rev_rate_date
8024 ,NULL --project_revenue
8025 ,txn_raw_cost
8026 ,txn_burdened_cost
8027 ,txn_currency_code
8028 ,txn_revenue
8029 ,NULL --bucketing_period_code
8030 ,NULL -- txn_standard_cost_rate
8031 ,nvl(txn_cost_rate_override,txn_standard_cost_rate) -- txn_cost_rate_override
8032 ,cost_ind_compiled_set_id
8033 ,NULL -- txn_standard_bill_rate
8034 ,nvl(txn_bill_rate_override,txn_standard_bill_rate) -- txn_bill_rate_override
8035 ,NULL -- txn_markup_percent
8036 ,nvl(txn_markup_percent_override,txn_markup_percent)-- txn_markup_percent_override
8037 ,txn_discount_percentage
8038 ,transfer_price_rate
8039 ,NULL -- init_quantity
8040 ,NULL -- init_quantity_source
8041 ,NULL -- init_raw_cost
8042 ,NULL -- init_burdened_cost
8043 ,NULL -- init_revenue
8044 ,NULL -- init_raw_cost_source
8045 ,NULL -- init_burdened_cost_source
8046 ,NULL -- init_revenue_source
8047 ,NULL -- project_init_raw_cost
8048 ,NULL -- project_init_burdened_cost
8049 ,NULL -- project_init_revenue
8050 ,NULL -- txn_init_raw_cost
8051 ,NULL -- txn_init_burdened_cost
8052 ,NULL -- txn_init_revenue
8053 ,NULL -- burden_cost_rate
8054 ,nvl(burden_cost_rate_override,burden_cost_rate) -- burden_cost_rate_override
8055 ,NULL -- pc_cur_conv_rejection_code
8056 ,NULL -- pfc_cur_conv_rejection_code
8057 FROM PA_BUDGET_LINES pbl
8058 ,pa_resource_assignments pra
8059 ,PA_FP_CPY_PERIODS_TMP pptmp /* Bug# 2634726 */
8060 WHERE pra.parent_assignment_id = pbl.resource_assignment_id
8061 AND decode(l_target_time_phased_code,
8062 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P, pptmp.pa_period_name,
8063 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G, pptmp.gl_period_name) = pbl.period_name
8064 AND pbl.budget_version_id = p_source_plan_version_id
8065 AND pra.budget_version_id=p_target_plan_version_id;
8066
8067 /* End of code fix for bug# 2634726 */
8068
8069 -- Bug 3841942 this update is required to make sure that planning start/end dates
8070 -- encompass budget line start and end dates after the shift
8071 --Bug 4200168, The logic for deriving sp fixed date is transferred to this previous. Previously
8072 --it was there in copy resource assignments.
8073 update pa_resource_assignments pra
8074 set (pra.planning_start_date, pra.planning_end_date,pra.sp_fixed_date)
8075 = ( select least(pra.planning_start_date+l_shift_days,
8076 nvl(min(bl.start_date),pra.planning_start_date+l_shift_days)),
8077 greatest(pra.planning_end_date+l_shift_days,
8078 nvl(max(bl.end_date),pra.planning_end_date+l_shift_days)),
8079 greatest(least(pra.sp_fixed_date + l_shift_days, pra.planning_end_date+ l_shift_days),
8080 pra.planning_start_date+ l_shift_days)
8081 from pa_budget_lines bl
8082 where bl.resource_assignment_id = pra.resource_assignment_id
8083 )
8084 where pra.budget_version_id = p_target_plan_version_id;
8085
8086 END IF; --l_target_time_phased_code
8087
8088 IF P_PA_DEBUG_MODE = 'Y' THEN
8089 pa_debug.g_err_stage:='Exiting Copy_Budget_Lines';
8090 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
8091 pa_debug.reset_err_stack;
8092 END IF;
8093 EXCEPTION
8094
8095 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
8096 l_msg_count := FND_MSG_PUB.count_msg;
8097 IF l_msg_count = 1 THEN
8098 PA_INTERFACE_UTILS_PUB.get_messages
8099 (p_encoded => FND_API.G_TRUE
8100 ,p_msg_index => 1
8101 ,p_msg_count => l_msg_count
8102 ,p_msg_data => l_msg_data
8103 ,p_data => l_data
8104 ,p_msg_index_out => l_msg_index_out);
8105
8106 x_msg_data := l_data;
8107 x_msg_count := l_msg_count;
8108 ELSE
8109 x_msg_count := l_msg_count;
8110 END IF;
8111
8112 x_return_status := FND_API.G_RET_STS_ERROR;
8113 IF P_PA_DEBUG_MODE = 'Y' THEN
8114 pa_debug.g_err_stage:='Invalid arguments passed';
8115 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
8116 pa_debug.reset_err_stack;
8117 END IF;
8118 RAISE;
8119
8120 WHEN Others THEN
8121
8122 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8123 x_msg_count := 1;
8124 x_msg_data := SQLERRM;
8125 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
8126 ,p_procedure_name => 'COPY_BUDGET_LINES');
8127 IF P_PA_DEBUG_MODE = 'Y' THEN
8128 pa_debug.g_err_stage:='Unexpected error'||SQLERRM;
8129 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,6);
8130 pa_debug.reset_err_stack;
8131 END IF;
8132 RAISE;
8133
8134 END Copy_Budget_Lines;
8135
8136 /*==================================================================
8137 This api is called during copy_project for the creation of new
8138 period profiles for the target project. The api creates new current
8139 period profiles for the target project using the current period
8140 profiles of the source project.
8141 ===================================================================*/
8142
8143 PROCEDURE Copy_Current_Period_Profiles
8144 ( p_target_project_id IN pa_projects.project_id%TYPE
8145 ,p_source_project_id IN pa_projects.project_id%TYPE
8146 ,p_shift_days IN NUMBER
8147 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
8148 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
8149 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
8150 AS
8151
8152 l_msg_count NUMBER := 0;
8153 l_data VARCHAR2(2000);
8154 l_msg_data VARCHAR2(2000);
8155 l_msg_index_out NUMBER;
8156 l_return_status VARCHAR2(2000);
8157
8158 l_target_period_profile_id pa_budget_versions.period_profile_id%TYPE;
8159 l_source_period_profile_id pa_budget_versions.period_profile_id%TYPE;
8160 l_dummy NUMBER;
8161
8162 CURSOR current_period_profiles_cur IS
8163 SELECT period_profile_id
8164 FROM pa_proj_period_profiles pp
8165 WHERE pp.project_id = p_source_project_id
8166 AND pp.current_flag = 'Y';
8167
8168 BEGIN
8169
8170 x_msg_count := 0;
8171 x_return_status := FND_API.G_RET_STS_SUCCESS;
8172
8173 IF p_pa_debug_mode = 'Y' THEN
8174 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Current_Period_Profiles');
8175 pa_debug.set_process('PLSQL','LOG',p_pa_debug_mode);
8176 END IF;
8177
8178 -- Check for NOT NULL parameters
8179
8180 IF (p_source_project_id IS NULL) OR
8181 (p_target_project_id IS NULL) OR
8182 (p_shift_days IS NULL )
8183 THEN
8184 IF p_pa_debug_mode = 'Y' THEN
8185 pa_debug.g_err_stage := 'Source_project ='||p_source_project_id;
8186 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
8187 pa_debug.g_err_stage := 'Target_project ='||p_target_project_id;
8188 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
8189 pa_debug.g_err_stage := 'p_shift_days ='||p_shift_days;
8190 pa_debug.write(g_module_name,pa_debug.g_err_stage,5);
8191 END IF;
8192 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
8193 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
8194 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8195
8196 END IF;
8197
8198 -- For the copied budget versions, create a new period profile
8199 -- by shifting existing period profile
8200
8201 OPEN current_period_profiles_cur;
8202 LOOP
8203
8204 FETCH current_period_profiles_cur INTO l_source_period_profile_id;
8205 EXIT WHEN current_period_profiles_cur%NOTFOUND;
8206
8207 /* Bug 2987076 - Period profile would not be created if periods are not available for the shifted dates */
8208
8209 PA_FP_COPY_FROM_PKG.Get_Create_Shifted_PD_Profile (
8210 p_target_project_id => p_target_project_id
8211 ,p_source_period_profile_id => l_source_period_profile_id
8212 ,p_shift_days => p_shift_days
8213 ,x_target_period_profile_id => l_target_period_profile_id
8214 ,x_return_status => l_return_status
8215 ,x_msg_count => l_msg_count
8216 ,x_msg_data => l_msg_data );
8217
8218 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8219 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8220 END IF;
8221
8222 END LOOP;
8223 CLOSE current_period_profiles_cur;
8224
8225 IF p_pa_debug_mode = 'Y' THEN
8226 pa_debug.g_err_stage:= 'Exiting Copy_Current_Period_Profiles';
8227 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8228 pa_debug.reset_err_stack;
8229 END IF;
8230
8231 EXCEPTION
8232
8233 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
8234
8235 x_return_status := FND_API.G_RET_STS_ERROR;
8236 l_msg_count := FND_MSG_PUB.count_msg;
8237 IF l_msg_count = 1 THEN
8238 PA_INTERFACE_UTILS_PUB.get_messages
8239 (p_encoded => FND_API.G_TRUE
8240 ,p_msg_index => 1
8241 ,p_msg_count => l_msg_count
8242 ,p_msg_data => l_msg_data
8243 ,p_data => l_data
8244 ,p_msg_index_out => l_msg_index_out);
8245 x_msg_data := l_data;
8246 x_msg_count := l_msg_count;
8247 ELSE
8248 x_msg_count := l_msg_count;
8249 END IF;
8250 IF p_pa_debug_mode = 'Y' THEN
8251 pa_debug.reset_err_stack;
8252 END IF;
8253 RAISE;
8254
8255 WHEN others THEN
8256
8257 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8258 x_msg_count := 1;
8259 x_msg_data := SQLERRM;
8260 FND_MSG_PUB.add_exc_msg
8261 ( p_pkg_name => 'PA_FP_COPY_FROM_PKG'
8262 ,p_procedure_name => 'Copy_Current_Period_Profiles'
8263 ,p_error_text => sqlerrm);
8264 IF p_pa_debug_mode = 'Y' THEN
8265 pa_debug.g_err_stage:= 'Unexpected Error'||SQLERRM;
8266 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8267 pa_debug.reset_err_stack;
8268 END IF;
8269 RAISE;
8270
8271 END Copy_Current_Period_Profiles;
8272
8273 /*==============================================================================
8274 This api creates new period profile for the new project created during
8275 copy_project. The api does the following :
8276
8277 a -> source profile duration
8278 b -> shift_days
8279
8280 1) The source period profile is shifted by p_shift_days
8281 2) If the shifted period profile goes ahead of the target project end date then,
8282 2.1) the project end date is set as period profile end date
8283 2.2) the profile start date is fetched by moving 'a' periods back.
8284 2.3) if the profile start date goes beyond the target project start date ,
8285 we make the target project start date as period profile start date.
8286 ================================================================================*/
8287
8288 PROCEDURE Get_Create_Shifted_PD_Profile
8289 ( p_target_project_id IN pa_projects.project_id%TYPE
8290 ,p_source_period_profile_id IN pa_proj_period_profiles.period_profile_id%TYPE
8291 ,p_shift_days IN NUMBER
8292 ,x_target_period_profile_id OUT NOCOPY pa_proj_period_profiles.period_profile_id%TYPE --File.Sql.39 bug 4440895
8293 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
8294 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
8295 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
8296 AS
8297
8298 l_msg_count NUMBER := 0;
8299 l_data VARCHAR2(2000);
8300 l_msg_data VARCHAR2(2000);
8301 l_msg_index_out NUMBER;
8302 l_return_status VARCHAR2(2000);
8303 l_index NUMBER;
8304
8305 l_period_set_name gl_sets_of_books.period_set_name%TYPE;
8306 l_accounted_period_type gl_sets_of_books.accounted_period_type%TYPE;
8307 l_pa_period_type pa_implementations.pa_period_type%TYPE;
8308
8309 l_number_of_periods NUMBER;
8310 l_plan_start_date pa_periods.start_date%TYPE;
8311 l_plan_end_date pa_periods.end_date%TYPE;
8312
8313 l_start_period pa_periods.period_name%TYPE;
8314 l_start_period_start_date pa_periods.start_date%TYPE;
8315 l_start_period_end_date pa_periods.end_date%TYPE;
8316
8317 l_end_period pa_periods.period_name%TYPE;
8318 l_end_period_start_date pa_periods.start_date%TYPE;
8319 l_end_period_end_date pa_periods.end_date%TYPE;
8320
8321 l_target_proj_gl_start_period gl_periods.period_name%TYPE;
8322 l_target_proj_gl_end_period gl_periods.period_name%TYPE;
8323 l_target_proj_pa_start_period pa_periods.period_name%TYPE;
8324 l_target_proj_pa_end_period pa_periods.period_name%TYPE;
8325
8326 l_target_proj_start_period pa_periods.period_name%TYPE;
8327 l_target_proj_end_period pa_periods.period_name%TYPE;
8328
8329 l_dummy_flag VARCHAR2(1);
8330 l_dummy1 VARCHAR2(30);
8331 l_dummy2 VARCHAR2(30);
8332
8333 CURSOR source_profile_info_cur (c_period_profile_id pa_proj_period_profiles.period_profile_id%TYPE)
8334 IS
8335 SELECT number_of_periods
8336 ,plan_period_type
8337 ,period_profile_type
8338 ,period_name1 -- profile_start_period
8339 ,profile_end_period_name
8340 ,period1_start_date -- profile start date
8341 ,current_flag
8342 FROM pa_proj_period_profiles
8343 WHERE period_profile_id = c_period_profile_id ;
8344
8345 source_profile_info_rec source_profile_info_cur%ROWTYPE;
8346
8347 /* Bug# 2987076 */
8348 l_create_period_profile VARCHAR2(1) := 'Y';
8349 l_prj_start_date VARCHAR2(12);
8350 l_prj_end_date VARCHAR2(12);
8351 /* Bug# 2987076 */
8352
8353 BEGIN
8354
8355 x_msg_count := 0;
8356 x_return_status := FND_API.G_RET_STS_SUCCESS;
8357 IF P_PA_DEBUG_MODE = 'Y' THEN
8358 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Get_Create_Shifted_PD_Profile');
8359 pa_debug.set_process('PLSQL','LOG',p_pa_debug_mode);
8360 END IF;
8361 -- Check for NOT NULL parameters
8362
8363 IF (p_target_project_id IS NULL) OR
8364 (p_source_period_profile_id IS NULL) OR
8365 (p_shift_days IS NULL)
8366 THEN
8367 IF p_pa_debug_mode = 'Y' THEN
8368 pa_debug.g_err_stage:= 'p_target_project_id = '|| p_target_project_id;
8369 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8370 pa_debug.g_err_stage:= 'p_source_period_profile_id = '|| p_source_period_profile_id;
8371 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8372 pa_debug.g_err_stage:= 'p_shift_days = '|| p_shift_days;
8373 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8374 pa_debug.g_err_stage:= 'Invalid Arguments Passed';
8375 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8376 END IF;
8377 PA_UTILS.ADD_MESSAGE
8378 (p_app_short_name => 'PA',
8379 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
8380 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8381 END IF;
8382
8383 -- Check for the target project if a period profile has been already created
8384 -- for the passed source period profile
8385
8386 IF NVL(g_source_period_profile_tbl.last,0) > 0 then
8387 FOR i IN g_source_period_profile_tbl.first .. g_source_period_profile_tbl.last
8388 LOOP
8389 -- If found then return the target period profile to the calling program
8390
8391 IF g_source_period_profile_tbl(i) = p_source_period_profile_id
8392 THEN
8393 x_target_period_profile_id := g_target_period_profile_tbl(i);
8394 IF P_PA_DEBUG_MODE = 'Y' THEN
8395 pa_debug.reset_err_stack;
8396 END IF;
8397 RETURN;
8398 END IF;
8399 END LOOP;
8400 END IF;
8401
8402 -- If no corresponding target period profile has been already created,
8403 -- then create one.
8404
8405 -- Fetch the source period profile details
8406 IF p_pa_debug_mode = 'Y' THEN
8407 pa_debug.g_err_stage:= 'Opening source_profile_info_cur';
8408 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8409 END IF;
8410
8411 OPEN source_profile_info_cur(p_source_period_profile_id);
8412 FETCH source_profile_info_cur INTO source_profile_info_rec;
8413 CLOSE source_profile_info_cur;
8414
8415 BEGIN
8416 -- Fetching the details required to create period profile for the target project
8417
8418 SELECT b.period_set_name
8419 ,DECODE(source_profile_info_rec.plan_period_type,
8420 PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_PA ,pa_period_type,
8421 PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_GL ,accounted_period_type) --accounted_period_type
8422 ,DECODE(source_profile_info_rec.plan_period_type,
8423 PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_PA ,pa_period_type,
8424 PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_GL ,NULL) --pa_period_type
8425 INTO l_period_set_name
8426 ,l_accounted_period_type
8427 ,l_pa_period_type
8428 FROM pa_projects_all p
8429 -- MOAC changes
8430 -- replaced with pa_implementations_all table.
8431 --,pa_implementations a
8432 ,pa_implementations_all a
8433 ,gl_sets_of_books b
8434 WHERE p.project_id = p_target_project_id
8435 -- MOAC changes
8436 -- removed the nvl around the org_id.
8437 -- AND NVL(p.Org_Id,-99) = NVL(a.Org_Id,-99)
8438 AND p.Org_Id =a.Org_Id
8439 AND a.set_of_books_id = b.set_of_books_id;
8440 EXCEPTION
8441 WHEN OTHERS THEN
8442 IF p_pa_debug_mode = 'Y' THEN
8443 pa_debug.g_err_stage:= 'Unexp Error while fetching the accounted period type||SQLERRM';
8444 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8445 END IF;
8446 RAISE;
8447 END;
8448
8449
8450 -- Fetch the target project start and completion dates
8451 -- Fetch the GL/PA periods into which the target project start and completion dates fall.
8452 IF p_pa_debug_mode = 'Y' THEN
8453 pa_debug.g_err_stage:= 'Calling Pa_Prj_Period_Profile_Utils.Get_Prj_Defaults';
8454 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8455 END IF;
8456
8457 Pa_Prj_Period_Profile_Utils.Get_Prj_Defaults(
8458 p_project_id => p_target_project_id
8459 ,p_info_flag => NULL
8460 ,p_create_defaults => 'N'
8461 ,x_gl_start_period => l_target_proj_gl_start_period
8462 ,x_gl_end_period => l_target_proj_gl_end_period
8463 ,x_gl_start_Date => l_dummy1 -- varchar2
8464 ,x_pa_start_period => l_target_proj_pa_start_period
8465 ,x_pa_end_period => l_target_proj_pa_end_period
8466 ,x_pa_start_date => l_dummy2 -- varchar2
8467 ,x_plan_version_exists_flag => l_dummy_flag
8468 ,x_prj_start_date => l_prj_start_date
8469 ,x_prj_end_date => l_prj_end_date);
8470
8471 IF source_profile_info_rec.plan_period_type = 'PA' THEN
8472
8473 l_target_proj_start_period := l_target_proj_pa_start_period;
8474 l_target_proj_end_period := l_target_proj_pa_end_period;
8475
8476 ELSIF source_profile_info_rec.plan_period_type = 'GL' THEN
8477
8478 l_target_proj_start_period := l_target_proj_gl_start_period;
8479 l_target_proj_end_period := l_target_proj_gl_end_period;
8480
8481 END IF;
8482
8483 -- Shift the source period profile start date by p_shift_days input.
8484 IF p_pa_debug_mode = 'Y' THEN
8485 pa_debug.g_err_stage:= 'Shifting source period profile by shift days i/p';
8486 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8487 END IF;
8488
8489 BEGIN /* Bug 2987076 - If shifted period is not available then return without creating the period profile */
8490
8491 IF source_profile_info_rec.plan_period_type = 'PA' THEN
8492
8493 SELECT period_name
8494 ,start_date
8495 INTO l_start_period
8496 ,l_start_period_start_date
8497 FROM pa_periods
8498 WHERE TRUNC(source_profile_info_rec.period1_start_date + p_shift_days) BETWEEN start_date AND end_date;
8499
8500 ELSIF source_profile_info_rec.plan_period_type = 'GL' THEN
8501
8502 SELECT period_name
8503 ,start_date
8504 INTO l_start_period
8505 ,l_start_period_start_date
8506 FROM gl_period_statuses g
8507 ,pa_implementations i
8508 WHERE g.application_id = pa_period_process_pkg.application_id
8509 AND g.set_of_books_id = i.set_of_books_id
8510 AND g.adjustment_period_flag = 'N'
8511 AND TRUNC(source_profile_info_rec.period1_start_date + p_shift_days) BETWEEN start_date AND end_date;
8512
8513 END IF;
8514 EXCEPTION
8515 WHEN NO_DATA_FOUND THEN
8516
8517 IF p_pa_debug_mode = 'Y' THEN
8518 pa_debug.g_err_stage:= 'Periods not available in system for the shifted dates!!!!';
8519 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8520 pa_debug.g_err_stage:= 'Period profile is not created.....';
8521 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8522 END IF;
8523
8524 l_create_period_profile := 'N';
8525
8526 END;
8527
8528 IF l_create_period_profile = 'Y' THEN /* Bug 2987076 */
8529
8530 -- Fetch the target profile end period by shifting the fetching the target profile start period forward
8531 -- by the number of periods of the source period profile
8532 IF p_pa_debug_mode = 'Y' THEN
8533 pa_debug.g_err_stage:= 'Calling get_Shifted_period';
8534 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8535 END IF;
8536
8537 PA_FIN_PLAN_UTILS.Get_Shifted_Period (
8538 p_period_name => l_start_period
8539 ,p_plan_period_type => source_profile_info_rec.plan_period_type
8540 ,p_number_of_periods => (source_profile_info_rec.number_of_periods -1)
8541 ,x_shifted_period => l_end_period
8542 ,x_shifted_period_start_date => l_end_period_start_date
8543 ,x_shifted_period_end_date => l_end_period_end_date
8544 ,x_return_status => l_return_status
8545 ,x_msg_count => l_msg_count
8546 ,x_msg_data => l_msg_data );
8547
8548 IF p_pa_debug_mode = 'Y' THEN
8549 pa_debug.g_err_stage:= 'l_end_period_start_date ='||l_end_period_start_date;
8550 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8551 pa_debug.g_err_stage:= 'l_prj_end_date=' || l_prj_end_date;
8552 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8553 END IF;
8554
8555 IF (l_prj_end_date IS NOT NULL) AND
8556 (to_date(l_prj_end_date,'rrrr/mm/dd') < l_end_period_start_date)
8557 THEN
8558
8559 -- If the fetched end period has gone beyond the project completion date then
8560 -- set the target project end period as the target profile end period
8561
8562 l_end_period := l_target_proj_end_period;
8563
8564 -- Fetch the end date of the above period
8565
8566 PA_FIN_PLAN_UTILS.Get_Period_Details(
8567 p_period_name => l_end_period
8568 ,p_plan_period_type => source_profile_info_rec.plan_period_type
8569 ,x_start_date => l_end_period_start_date
8570 ,x_end_date => l_end_period_end_date
8571 ,x_return_status => l_return_status
8572 ,x_msg_count => l_msg_count
8573 ,x_msg_data => l_msg_data );
8574
8575 -- Fetch the start period of the target period profile by moving backward from the end period
8576 -- by the number of periods of the source period profile
8577
8578 PA_FIN_PLAN_UTILS.Get_Shifted_Period (
8579 p_period_name => l_end_period
8580 ,p_plan_period_type => source_profile_info_rec.plan_period_type
8581 ,p_number_of_periods => (-source_profile_info_rec.number_of_periods+1)
8582 ,x_shifted_period => l_start_period
8583 ,x_shifted_period_start_date => l_start_period_start_date
8584 ,x_shifted_period_end_date => l_start_period_end_date
8585 ,x_return_status => l_return_status
8586 ,x_msg_count => l_msg_count
8587 ,x_msg_data => l_msg_data );
8588
8589 -- check if the fetched start period has gone beyond the target project start date.
8590 -- if so make the target project start period as the profile start period
8591
8592 IF (l_start_period_end_date < to_date(l_prj_start_date,'rrrr/mm/dd'))
8593 THEN
8594 l_start_period := l_target_proj_start_period;
8595
8596 -- If the fetched start period doesn't fall in the project duration, then
8597 -- set the project start period as the period profile start period
8598
8599 Pa_Fin_Plan_Utils.Get_Period_Details(
8600 p_period_name => l_start_period
8601 ,p_plan_period_type => source_profile_info_rec.plan_period_type
8602 ,x_start_date => l_start_period_start_date
8603 ,x_end_date => l_start_period_end_date
8604 ,x_return_status => l_return_status
8605 ,x_msg_count => l_msg_count
8606 ,x_msg_data => l_msg_data );
8607 END IF;
8608 END IF;
8609
8610 -- Call Maintain_Prj_Period_Profile
8611
8612 IF p_pa_debug_mode = 'Y' THEN
8613 pa_debug.g_err_stage:= 'Calling Pa_Prj_Period_Profile_Utils.Maintain_Prj_Period_Profile';
8614 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8615 END IF;
8616
8617 Pa_Prj_Period_Profile_Utils.Maintain_Prj_Period_Profile(
8618 p_project_id => p_target_project_id
8619 ,p_period_profile_type => source_profile_info_rec.period_profile_type
8620 ,p_plan_period_type => source_profile_info_rec.plan_period_type
8621 ,p_period_set_name => l_period_set_name
8622 ,p_gl_period_type => l_accounted_period_type
8623 ,p_pa_period_type => l_pa_period_type
8624 ,p_start_date => l_start_period_start_date
8625 ,px_end_date => l_end_period_end_date
8626 ,px_period_profile_id => x_target_period_profile_id
8627 ,p_commit_flag => 'N'
8628 ,px_number_of_periods => l_number_of_periods
8629 ,x_plan_start_date => l_plan_start_date
8630 ,x_plan_end_date => l_plan_end_date
8631 ,x_return_status => l_return_status
8632 ,x_msg_count => l_msg_count
8633 ,x_msg_data => l_msg_data );
8634
8635 -- update the global pl/sqls with the source period profile and
8636 -- equivalent target period profile
8637
8638 l_index := NVL(g_source_period_profile_tbl.last,0)+1;
8639
8640 g_source_period_profile_tbl(l_index) := p_source_period_profile_id;
8641 g_target_period_profile_tbl(l_index) := x_target_period_profile_id;
8642
8643 END IF; /* l_create_period_profile = 'Y' */
8644
8645 IF p_pa_debug_mode = 'Y' THEN
8646 pa_debug.g_err_stage:= 'Exiting Get_Create_Shifted_PD_Profile';
8647 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL3);
8648 pa_debug.reset_err_stack;
8649 END IF;
8650 EXCEPTION
8651
8652 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
8653
8654 x_return_status := FND_API.G_RET_STS_ERROR;
8655 l_msg_count := FND_MSG_PUB.count_msg;
8656 IF l_msg_count = 1 THEN
8657 PA_INTERFACE_UTILS_PUB.get_messages
8658 (p_encoded => FND_API.G_TRUE
8659 ,p_msg_index => 1
8660 ,p_msg_count => l_msg_count
8661 ,p_msg_data => l_msg_data
8662 ,p_data => l_data
8663 ,p_msg_index_out => l_msg_index_out);
8664 x_msg_data := l_data;
8665 x_msg_count := l_msg_count;
8666 ELSE
8667 x_msg_count := l_msg_count;
8668 END IF;
8669 IF P_PA_DEBUG_MODE = 'Y' THEN
8670 pa_debug.reset_err_stack;
8671 END IF;
8672 RAISE;
8673
8674 WHEN others THEN
8675
8676 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8677 x_msg_count := 1;
8678 x_msg_data := SQLERRM;
8679 FND_MSG_PUB.add_exc_msg
8680 ( p_pkg_name => 'PA_FP_COPY_FROM_PKG'
8681 ,p_procedure_name => 'Get_Create_Shifted_PD_Profile'
8682 ,p_error_text => sqlerrm);
8683 IF p_pa_debug_mode = 'Y' THEN
8684 pa_debug.g_err_stage:= 'Unexpected Error'||SQLERRM;
8685 pa_debug.write(g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8686 pa_debug.reset_err_stack;
8687 END IF;
8688 RAISE;
8689 END Get_Create_Shifted_PD_Profile;
8690
8691
8692 /*============================================================================================================
8693 * This procedure should be called to copy a workplan version. Copies budget
8694 * versions, resource assignments and budget lines as required for the workplan
8695 * version. This is added for FP M (Bug 3354518)
8696
8697 * 04-Jun-04 Bug 3619687 Raja
8698 * When a working version is created from a published workplan version,
8699 * all the additional workplan settings data (plan settings, txn currencies
8700 * and rate schedules) should be inherited from workplan plan type.
8701
8702 * 24-Sep-2004 Bug 3847386 Raja
8703 * Added a new parameter p_copy_act_from_str_ids_tbl. The table would contain
8704 * from which version actuals should be copied for the target versions if they
8705 * need to be copied
8706
8707 ============================================================================================================*/
8708
8709 PROCEDURE copy_wp_budget_versions
8710 (
8711 p_source_project_id IN pa_proj_element_versions.project_id%TYPE
8712 ,p_target_project_id IN pa_proj_element_versions.element_version_id%TYPE
8713 ,p_src_sv_ids_tbl IN SYSTEM.pa_num_tbl_type
8714 ,p_target_sv_ids_tbl IN SYSTEM.pa_num_tbl_type
8715 ,p_copy_act_from_str_ids_tbl IN SYSTEM.pa_num_tbl_type -- bug 3847386
8716 ,p_copy_people_flag IN VARCHAR2
8717 ,p_copy_equip_flag IN VARCHAR2
8718 ,p_copy_mat_item_flag IN VARCHAR2
8719 ,p_copy_fin_elem_flag IN VARCHAR2
8720 ,p_copy_mode IN VARCHAR2 --bug 4277801
8721 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
8722 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
8723 ,x_msg_data OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
8724 ) AS
8725
8726 --Start of variables used for debugging
8727 l_return_status VARCHAR2(1);
8728 l_msg_count NUMBER := 0;
8729 l_msg_data VARCHAR2(2000);
8730 l_data VARCHAR2(2000);
8731 l_msg_index_out NUMBER;
8732 l_debug_mode VARCHAR2(30);
8733 l_debug_level3 CONSTANT NUMBER :=3;
8734 l_debug_level5 CONSTANT NUMBER :=5;
8735
8736 --End of variables used for debugging
8737 l_module_name VARCHAR2(200) := g_module_name || '.copy_wp_budget_versions';
8738 i NUMBER;
8739 l_src_budget_version_id pa_budget_versions.budget_version_id%TYPE;
8740 --l_src_resource_list_id pa_resource_lists_all_bg.resource_list_id%TYPE; //Commented out for Bug 4200168.
8741 --l_targ_resource_list_id pa_resource_lists_all_bg.resource_list_id%TYPE; //Commented out for Bug 4200168.
8742 l_adj_percentage NUMBER;
8743 l_copy_mode VARCHAR2(1) := p_copy_mode;
8744 l_shift_days NUMBER :=0;--SHOULD BE REMOVED LATER
8745 l_targ_budget_version_id pa_budget_versions.budget_version_id%TYPE;
8746 l_src_proj_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
8747 l_targ_proj_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
8748 l_wp_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE;
8749 l_targ_multi_curr_flag pa_proj_fp_options.plan_in_multi_curr_flag%TYPE;
8750 l_pji_rollup_required VARCHAR(1);
8751
8752 -- pjdvdsn1 compile issues, 03-FEB-2004, jwhite -------------------------
8753
8754 /*
8755 l_src_elem_version_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
8756 l_targ_elem_version_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
8757 */
8758
8759
8760 l_src_elem_version_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
8761 l_targ_elem_version_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
8762
8763 -- ----------------------------------------------------------------------
8764
8765 l_copy_external_flag VARCHAR2(1);
8766
8767 --This table will be used in the PJI API call
8768 l_budget_version_ids SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
8769 l_src_budget_version_id_tbl SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
8770
8771 --Cursor for getting the source and target element version ids. This will be used in calling the
8772 --Copy Planning Txn API
8773 CURSOR l_prep_plan_txn_csr(c_source_plan_version_id pa_budget_versions.budget_version_id%TYPE
8774 ,c_src_struct_ver_id pa_proj_element_versions.element_version_id%TYPE
8775 ,c_targ_struct_ver_id pa_proj_element_versions.element_version_id%TYPE)
8776 IS
8777 SELECT selv.element_version_id
8778 ,telv.element_version_id
8779 FROM pa_proj_element_versions telv
8780 ,pa_proj_element_versions selv
8781 ,pa_proj_elements spe
8782 ,pa_proj_elements tpe
8783 WHERE spe.project_id=p_source_project_id
8784 AND tpe.project_id=p_target_project_id
8785 AND spe.element_number=tpe.element_number
8786 AND tpe.object_type='PA_TASKS'
8787 AND spe.object_type='PA_TASKS'
8788 AND telv.proj_element_id = tpe.proj_element_id
8789 AND selv.proj_element_id =spe.proj_element_id
8790 AND selv.parent_structure_version_id=c_src_struct_ver_id
8791 AND telv.parent_structure_version_id=c_targ_struct_ver_id
8792 AND EXISTS (SELECT task_id
8793 FROM pa_resource_assignments pra
8794 WHERE pra.budget_version_id=c_source_plan_version_id
8795 AND pra.task_id=spe.proj_element_id);
8796
8797 BEGIN
8798 x_msg_count := 0;
8799 x_return_status := FND_API.G_RET_STS_SUCCESS;
8800 SAVEPOINT copy_wp_budget_versions;
8801
8802 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
8803 l_debug_mode := NVL(l_debug_mode, 'Y');
8804
8805 -- Set curr function
8806
8807 IF l_debug_mode = 'Y' THEN
8808 pa_debug.set_curr_function(
8809 p_function =>'pafpcpfb.copy_wp_budget_versions'
8810 ,p_debug_mode => l_debug_mode );
8811
8812 pa_debug.g_err_stage:='Validating input parameters';
8813 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
8814 END IF;
8815
8816
8817 -- Source and target sv id tables should have same number of records
8818 -- Bug 3847386 if copy actuals from structure table is passed it
8819 -- should have same number of records as target sv ids table
8820 IF (p_src_sv_ids_tbl.count<>p_target_sv_ids_tbl.count) OR
8821 (p_copy_act_from_str_ids_tbl IS NOT NULL
8822 AND p_src_sv_ids_tbl.count <> p_copy_act_from_str_ids_tbl.count)
8823 THEN
8824
8825 IF l_debug_mode = 'Y' THEN
8826 pa_debug.g_err_stage:='p_src_sv_ids_tbl.count is'|| p_src_sv_ids_tbl.count ;
8827 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8828
8829 pa_debug.g_err_stage:='p_target_sv_ids_tbl.count is'|| p_target_sv_ids_tbl.count ;
8830 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8831
8832 IF p_copy_act_from_str_ids_tbl IS NOT NULL THEN
8833 pa_debug.g_err_stage:='p_copy_act_from_str_ids_tbl.count is'
8834 || p_copy_act_from_str_ids_tbl.count ;
8835 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8836 END IF;
8837 END IF;
8838
8839 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
8840 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
8841
8842 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8843
8844 END IF;
8845
8846
8847 --If the tables are empty then return
8848 IF p_src_sv_ids_tbl.count=0 THEN
8849
8850 IF l_debug_mode = 'Y' THEN
8851 pa_debug.g_err_stage:='The input tables are empty' ;
8852 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8853 pa_debug.reset_curr_function;
8854 END IF;
8855 RETURN;
8856
8857 END IF;
8858
8859
8860 --Source and target project ids should never be null
8861 IF p_source_project_id IS NULL OR
8862 p_target_project_id IS NULL THEN
8863
8864 IF l_debug_mode = 'Y' THEN
8865 pa_debug.g_err_stage:='p_source_project_id is '||p_source_project_id;
8866 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8867
8868 pa_debug.g_err_stage:='p_target_project_id is '||p_target_project_id;
8869 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8870 END IF;
8871
8872 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
8873 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
8874
8875 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8876
8877 END IF;
8878
8879 --Derive the workplan fin plan type id
8880 pa_fp_planning_transaction_pub.add_wp_plan_type
8881 (p_src_project_id => p_source_project_id
8882 ,p_targ_project_id => p_target_project_id
8883 ,x_return_status => x_return_status
8884 ,x_msg_count => x_msg_count
8885 ,x_msg_data => x_msg_data );
8886
8887 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8888
8889 IF l_debug_mode = 'Y' THEN
8890 pa_debug.g_err_stage:='pa_fp_planning_transaction_pub.add_wp_plan_type returned error';
8891 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8892 END IF;
8893 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8894
8895 END IF;
8896
8897 BEGIN
8898 SELECT fin_plan_type_id
8899 INTO l_wp_plan_type_id
8900 FROM pa_fin_plan_types_b
8901 WHERE use_for_workplan_flag='Y';
8902 EXCEPTION
8903 WHEN NO_DATA_FOUND THEN
8904 IF l_debug_mode = 'Y' THEN
8905 pa_debug.g_err_stage:='Adding an error message as the wp plan type is not defined';
8906 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
8907 END IF;
8908 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
8909 p_msg_name => 'PA_FP_NO_WP_PLAN_TYPE');
8910 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8911 END;
8912
8913 IF l_debug_mode = 'Y' THEN
8914 pa_debug.g_err_stage:='About to loop thru the source version id tbl '||p_src_sv_ids_tbl.count;
8915 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
8916 END IF;
8917
8918 --Loop thru the source structure version ids table and process each structure version id
8919 FOR i IN p_src_sv_ids_tbl.first..p_src_sv_ids_tbl.last LOOP
8920
8921
8922 --Assign null to the variables that will be used as the out parameters while calling various APIs(bug 3437643)
8923 l_targ_budget_version_id :=NULL;
8924 l_targ_proj_fp_options_id :=NULL;
8925
8926 l_src_budget_version_id := PA_PLANNING_TRANSACTION_UTILS.Get_Wp_Budget_Version_Id(p_src_sv_ids_tbl(i));
8927
8928 IF p_source_project_id <> p_target_project_id THEN
8929
8930 --l_src_resource_list_id := pa_fin_plan_utils.get_resource_list_id(l_src_budget_version_id); //Commented out for bug 4200168.
8931 --l_targ_resource_list_id := l_src_resource_list_id;--RESOURCE FOUNDATION api TO GET THE TARGET RESOURCE LIST ID; //Commented out for bug 4200168.
8932 l_adj_percentage:= 0.9999;
8933 ELSE
8934
8935 --l_src_resource_list_id := pa_fin_plan_utils.get_resource_list_id(l_src_budget_version_id); //Commented out for bug 4200168.
8936 --l_targ_resource_list_id := l_src_resource_list_id; //Commented out for bug 4200168.
8937 l_adj_percentage:= 0;
8938 END IF;
8939
8940 --Bug 3841130. As told by sheenie copy external flag should always be N in copy_wp_budget_versions.
8941 l_copy_external_flag := 'N';
8942
8943 IF l_debug_mode = 'Y' THEN
8944 pa_debug.g_err_stage:='Calling copy budget version';
8945 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
8946 END IF;
8947
8948 --Call the method that copies the budget version
8949 pa_fp_copy_from_pkg.copy_budget_version
8950 ( p_source_project_id => p_source_project_id
8951 ,p_target_project_id => p_target_project_id
8952 ,p_source_version_id => l_src_budget_version_id
8953 ,p_copy_mode => 'W'
8954 ,p_adj_percentage => l_adj_percentage
8955 ,p_calling_module => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_WORKPLAN
8956 ,p_shift_days => l_shift_days
8957 ,px_target_version_id => l_targ_budget_version_id
8958 ,p_struct_elem_version_id => p_target_sv_ids_tbl(i)
8959 ,x_return_status => x_return_status
8960 ,x_msg_count => x_msg_count
8961 ,x_msg_data => x_msg_data);
8962
8963 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8964
8965 IF l_debug_mode = 'Y' THEN
8966 pa_debug.g_err_stage:='Copy Budget version returned error';
8967 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8968 END IF;
8969 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8970
8971 END IF;
8972 --Get the details required to call the Create FP Option API
8973 BEGIN
8974
8975 SELECT proj_fp_options_id
8976 INTO l_src_proj_fp_options_id
8977 FROM pa_proj_fp_options
8978 WHERE fin_plan_version_id=l_src_budget_version_id;
8979
8980 EXCEPTION
8981 WHEN NO_DATA_FOUND THEN
8982
8983 IF l_debug_mode = 'Y' THEN
8984 pa_debug.g_err_stage:='No data found in pa_proj_fp_options for fin_plan_version_id '
8985 ||l_src_budget_version_id;
8986 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
8987 END IF;
8988 RAISE;
8989
8990 END;
8991
8992 IF l_debug_mode = 'Y' THEN
8993 pa_debug.g_err_stage:='Create FP Option';
8994 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
8995 END IF;
8996
8997 --Call the method to create the FP Option
8998 PA_PROJ_FP_OPTIONS_PUB.Create_Fp_Option
8999 (
9000 px_target_proj_fp_option_id => l_targ_proj_fp_options_id
9001 ,p_source_proj_fp_option_id => l_src_proj_fp_options_id
9002 ,p_target_fp_option_level_code => PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_VERSION
9003 ,p_target_fp_preference_code => PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY
9004 ,p_target_fin_plan_version_id => l_targ_budget_version_id
9005 ,p_target_plan_type_id => l_wp_plan_type_id
9006 ,p_target_project_id => p_target_project_id
9007 ,x_return_status => x_return_status
9008 ,x_msg_count => x_msg_count
9009 ,x_msg_data => x_msg_data);
9010
9011 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9012
9013 IF l_debug_mode = 'Y' THEN
9014 pa_debug.g_err_stage:='Create_Fp_Option returned error';
9015 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9016 END IF;
9017 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9018
9019 END IF;
9020
9021 --Derive the multi currency flag so as to call the copy planning txn currencies
9022 SELECT plan_in_multi_curr_flag
9023 INTO l_targ_multi_curr_flag
9024 FROM pa_proj_fp_options
9025 WHERE proj_fp_options_id=l_targ_proj_fp_options_id;
9026
9027 IF l_debug_mode = 'Y' THEN
9028 pa_debug.g_err_stage:='Calling copy fp txn currencies';
9029 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
9030 END IF;
9031
9032 --Call the API to create the txn currencies
9033 PA_FP_TXN_CURRENCIES_PUB.Copy_Fp_Txn_Currencies(
9034 p_source_fp_option_id => l_src_proj_fp_options_id
9035 ,p_target_fp_option_id => l_targ_proj_fp_options_id
9036 ,p_target_fp_preference_code => NULL
9037 ,p_plan_in_multi_curr_flag => l_targ_multi_curr_flag
9038 ,x_return_status => x_return_status
9039 ,x_msg_count => x_msg_count
9040 ,x_msg_data => x_msg_data);
9041
9042 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9043
9044 IF l_debug_mode = 'Y' THEN
9045 pa_debug.g_err_stage:='Copy_Fp_Txn_Currencies returned error';
9046 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9047 END IF;
9048 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9049
9050 END IF;
9051
9052 --Call the PJI API to register the creation of plan version
9053
9054 -- FP M - Reporting lines integration. The create API is being called even before calling the copy
9055 --planning txn as the copy planning txn will take care of later calling the PJI plan update API for
9056 --the new budget lines created
9057 l_budget_version_ids.delete;
9058 l_budget_version_ids := SYSTEM.pa_num_tbl_type(l_targ_budget_version_id);
9059
9060 l_src_budget_version_id_tbl.delete;
9061 l_src_budget_version_id_tbl := SYSTEM.pa_num_tbl_type(l_src_budget_version_id);
9062
9063 IF l_debug_mode = 'Y' THEN
9064 pa_debug.write(l_module_name,'Calling PJI_FM_XBS_ACCUM_MAINT.PLAN_CREATE ' ,5);
9065 pa_debug.write(l_module_name,'p_fp_version_ids count '|| l_budget_version_ids.count(),5);
9066 END IF;
9067
9068 /* We are sure that there is only one record. But just looping the std way */
9069 FOR I in l_budget_version_ids.first..l_budget_version_ids.last LOOP
9070 pa_debug.write(l_module_name,''|| l_budget_version_ids(i),5);
9071 END LOOP;
9072 -- This parameter p_copy_mode will be used when the source project is not equal to the target project.
9073 --This will be passed as null in the MSP flow other wise it will be defaulted to 'P'.
9074 IF p_source_project_id <> p_target_project_id THEN
9075 PJI_FM_XBS_ACCUM_MAINT.PLAN_CREATE (
9076 p_fp_version_ids => l_budget_version_ids,
9077 p_fp_src_version_ids => l_src_budget_version_id_tbl,
9078 p_copy_mode => l_copy_mode,
9079 x_return_status => l_return_status,
9080 x_msg_code => l_msg_data);
9081 ELSE
9082 PJI_FM_XBS_ACCUM_MAINT.PLAN_CREATE (
9083 p_fp_version_ids => l_budget_version_ids,
9084 x_return_status => l_return_status,
9085 x_msg_code => l_msg_data);
9086 END IF;
9087
9088 IF l_return_status <> FND_API.G_RET_STS_SUCCESS then
9089 PA_UTILS.ADD_MESSAGE(p_app_short_name => PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_PA,
9090 p_msg_name => l_msg_data);
9091 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9092 END IF;
9093
9094
9095
9096 IF l_debug_mode = 'Y' THEN
9097 pa_debug.g_err_stage:='Bulk fetching the Ids for calling copy planning txn'||' '||p_src_sv_ids_tbl(i)||' '||p_target_sv_ids_tbl(i);
9098 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
9099 END IF;
9100
9101 OPEN l_prep_plan_txn_csr( l_src_budget_version_id
9102 ,p_src_sv_ids_tbl(i)
9103 ,p_target_sv_ids_tbl(i));
9104 FETCH l_prep_plan_txn_csr
9105 BULK COLLECT INTO
9106 l_src_elem_version_id_tbl
9107 ,l_targ_elem_version_id_tbl;
9108 CLOSE l_prep_plan_txn_csr;
9109
9110 IF l_debug_mode = 'Y' THEN
9111 pa_debug.g_err_stage:='Calling copy planning txns after uncommenting';
9112 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
9113 END IF;
9114
9115
9116
9117 --Calling the copy planning txn API
9118 pa_fp_planning_transaction_pub.copy_planning_transactions(
9119 p_context => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_WORKPLAN
9120 ,p_copy_external_flag => l_copy_external_flag
9121 ,p_src_project_id => p_source_project_id
9122 ,p_target_project_id => p_target_project_id
9123 ,p_src_budget_version_id => l_src_budget_version_id
9124 ,p_targ_budget_version_id => l_targ_budget_version_id
9125 ,p_src_version_id_tbl => l_src_elem_version_id_tbl
9126 ,p_targ_version_id_tbl => l_targ_elem_version_id_tbl
9127 ,p_copy_people_flag => p_copy_people_flag
9128 ,p_copy_equip_flag => p_copy_equip_flag
9129 ,p_copy_mat_item_flag => p_copy_mat_item_flag
9130 ,p_copy_fin_elem_flag => p_copy_fin_elem_flag
9131 ,p_pji_rollup_required => 'N'
9132 ,x_return_status => x_return_status
9133 ,x_msg_count => x_msg_count
9134 ,x_msg_data => x_msg_data);
9135
9136 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9137
9138 IF l_debug_mode = 'Y' THEN
9139 pa_debug.g_err_stage:='Copy_Fp_Txn_Currencies returned error';
9140 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9141 END IF;
9142 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9143
9144 END IF;
9145
9146 -- Bug 3619687
9147 -- When this api is called to create a working workplan structure version from
9148 -- a published version, all the data in 'Additional Workplan settings' pages
9149 -- should be synchronised with workplan plan type data
9150
9151 PA_FP_COPY_FROM_PKG.Update_Plan_Setup_For_WP_Copy(
9152 p_project_id => p_target_project_id
9153 ,p_wp_version_id => l_targ_budget_version_id
9154 ,x_return_status => x_return_status
9155 ,x_msg_count => x_msg_count
9156 ,x_msg_data => x_msg_data);
9157
9158 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9159
9160 IF l_debug_mode = 'Y' THEN
9161 pa_debug.g_err_stage:='Update_Plan_Setup_For_WP_Copy returned error';
9162 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9163 END IF;
9164 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9165 END IF;
9166
9167 -- If copy actuals from structure id is passed progress actuals should be copied
9168 -- for the target version
9169 IF p_copy_act_from_str_ids_tbl IS NOT NULL AND
9170 p_copy_act_from_str_ids_tbl.EXISTS(i) AND
9171 p_copy_act_from_str_ids_tbl(i) IS NOT NULL AND
9172 p_source_project_id = p_target_project_id
9173 THEN
9174 -- Added for bug 3850488.
9175 -- Copy the missing unplanned assignments.
9176 BEGIN
9177 PA_TASK_ASSIGNMENTS_PVT.Copy_Missing_Unplanned_Asgmts(
9178 p_project_id => p_target_project_id
9179 ,p_old_structure_version_id => p_copy_act_from_str_ids_tbl(i)
9180 ,p_new_structure_version_id => p_target_sv_ids_tbl(i)
9181 ,x_msg_count => x_msg_count
9182 ,x_msg_data => x_msg_data
9183 ,x_return_status => x_return_status
9184 );
9185 EXCEPTION
9186 WHEN OTHERS THEN
9187 IF l_debug_mode = 'Y' THEN
9188 pa_debug.g_err_stage:='PA_TASK_ASSIGNMENTS_PVT.Copy_Missing_Unplanned_Asgmts returned error';
9189 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9190 END IF;
9191 RAISE FND_API.G_EXC_ERROR;
9192 END;
9193 IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9194 RAISE FND_API.G_EXC_ERROR;
9195 END IF;
9196 -- End bug 3850488.
9197
9198 -- Call copy_actuals_for_workplan
9199 PA_PROGRESS_PVT.copy_actuals_for_workplan(
9200 p_project_id => p_target_project_id
9201 ,p_source_struct_ver_id => p_copy_act_from_str_ids_tbl(i)
9202 ,p_target_struct_ver_id => p_target_sv_ids_tbl(i)
9203 ,x_return_status => x_return_status
9204 ,x_msg_count => x_msg_count
9205 ,x_msg_data => x_msg_data);
9206
9207 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9208
9209 IF l_debug_mode = 'Y' THEN
9210 pa_debug.g_err_stage:='Update_Plan_Setup_For_WP_Copy returned error';
9211 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9212 END IF;
9213 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9214 END IF;
9215 END IF;
9216
9217 PA_PLANNING_TRANSACTION_UTILS.call_update_rep_lines_api
9218 ( p_source => 'PA_FP_RA_MAP_TMP'
9219 ,p_budget_version_id => l_targ_budget_version_id
9220 ,x_return_status => x_return_status
9221 ,x_msg_data => x_msg_data
9222 ,x_msg_count => x_msg_count);
9223
9224 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9225
9226 IF l_debug_mode = 'Y' THEN
9227 pa_debug.g_err_stage:='PA_PLANNING_TRANSACTION_UTILS.call_update_rep_lines_api returned error';
9228 pa_debug.write( l_module_name,pa_debug.g_err_stage,5);
9229 END IF;
9230 RAISE PA_FP_CONSTANTS_PKG.INVALID_ARG_EXC;
9231 END IF;
9232
9233
9234 END LOOP;
9235
9236 IF l_debug_mode = 'Y' THEN
9237 pa_debug.g_err_stage:='Exiting copy_wp_budget_versions';
9238 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
9239 -- reset curr function
9240 pa_debug.reset_curr_function;
9241 END IF;
9242 EXCEPTION
9243
9244 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
9245 l_msg_count := FND_MSG_PUB.count_msg;
9246 IF l_msg_count = 1 THEN
9247 PA_INTERFACE_UTILS_PUB.get_messages
9248 (p_encoded => FND_API.G_TRUE
9249 ,p_msg_index => 1
9250 ,p_msg_count => l_msg_count
9251 ,p_msg_data => l_msg_data
9252 ,p_data => l_data
9253 ,p_msg_index_out => l_msg_index_out);
9254
9255 x_msg_data := l_data;
9256 x_msg_count := l_msg_count;
9257 ELSE
9258 x_msg_count := l_msg_count;
9259 END IF;
9260 ROLLBACK TO copy_wp_budget_versions;
9261 x_return_status := FND_API.G_RET_STS_ERROR;
9262
9263 IF l_debug_mode = 'Y' THEN
9264 pa_debug.g_err_stage:='Invalid Arguments Passed Or called api raised an error';
9265 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9266 -- reset curr function
9267 pa_debug.reset_curr_function();
9268 END IF;
9269 RETURN;
9270 WHEN OTHERS THEN
9271 ROLLBACK TO copy_wp_budget_versions;
9272 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9273 x_msg_count := 1;
9274 x_msg_data := SQLERRM;
9275
9276 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'pa_fp_copy_from_pkg'
9277 ,p_procedure_name => 'copy_wp_budget_versions');
9278
9279 IF l_debug_mode = 'Y' THEN
9280 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
9281 pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
9282 -- reset curr function
9283 pa_debug.Reset_Curr_Function();
9284 END IF;
9285 RAISE;
9286
9287 END copy_wp_budget_versions;
9288
9289 /*=========================================================================
9290 3156057: FP.M changes:
9291 If source plan is mc enabled but not appr rev and the target is appr rev,
9292 then this api will be called to group the source budget lines by PFC for creating target budget lines
9293 Logic:
9294 1) Get all the distinct resource_assignment_id and start_date combination for the source plan version id
9295 2) Fetch all the source budget lines for the given resource_assignment_id and start_date combination, ordering
9296 by transaction currency code (filtering out the records which have some rejection code populated,
9297 and sum up the amounts and quantities.
9298 3) For the DFF attributes, change reason and description, copy the attributes if any of the source lines for the
9299 given resource_assignment_id and start_date combination has the transaction currency same as the project
9300 functional currency. If not, then copy the attributes from the first listed source line,
9301 ordering by transaction currency.
9302 4) This api is dependant on PA_FP_RA_MAP_TMP being populated before it is called and it populates
9303 PA_FP_BL_MAP_TMP on which the api COPY_MC_BUDGET_LINES_APPR_REV would be dependant.
9304 =========================================================================*/
9305
9306 --Bug 4290043. Added p_derv_rates_missing_amts_flag to indicate whether the missing amounts in the target version
9307 --should be derived or not after copy
9308 /* Bug 4865563 IPM Arch Enhancement. Display_quantity is being set in copy_version and copy_finplans_from_project apis using
9309 populate_display_qty api. */
9310
9311 PROCEDURE Copy_Budget_Lines_Appr_Rev(
9312 p_source_plan_version_id IN NUMBER
9313 ,p_target_plan_version_id IN NUMBER
9314 ,p_adj_percentage IN NUMBER
9315 ,p_derv_rates_missing_amts_flag IN VARCHAR2
9316 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
9317 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
9318 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
9319 AS
9320
9321 l_msg_count NUMBER :=0;
9322 l_data VARCHAR2(2000);
9323 l_msg_data VARCHAR2(2000);
9324 l_error_msg_code VARCHAR2(2000);
9325 l_msg_index_out NUMBER;
9326 l_return_status VARCHAR2(2000);
9327 l_debug_mode VARCHAR2(30);
9328
9329 l_revenue_flag pa_fin_plan_amount_sets.revenue_flag%type;
9330 l_cost_flag pa_fin_plan_amount_sets.raw_cost_flag%type;
9331 l_rate_based_flag pa_resource_assignments.rate_based_flag%type;
9332
9333
9334 l_adj_percentage NUMBER ;
9335
9336 l_quantity_tot NUMBER;
9337 l_raw_cost_tot NUMBER;
9338 l_burdened_cost_tot NUMBER;
9339 l_revenue_tot NUMBER;
9340 l_project_raw_cost_tot NUMBER;
9341 l_project_burdened_cost_tot NUMBER;
9342 l_project_revenue_tot NUMBER;
9343 l_ref NUMBER ;
9344 l_target_budget_line_id NUMBER;
9345 l_project_cost_exchange_rate NUMBER;
9346 l_proj_rev_ex_rate NUMBER;
9347 l_txn_cost_rate_override NUMBER;
9348 l_txn_bill_rate_override NUMBER;
9349 l_burden_cost_rate_override NUMBER;
9350
9351 /* Initialized plsql tables for bug 3709036 */
9352
9353 l_budget_line_idTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE() ;
9354 l_quantityTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE() ;
9355 l_raw_costTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE() ;
9356 l_burdened_costTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE() ;
9357 l_revenueTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE() ;
9358 l_change_reason_codeTab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
9359 l_descriptionTab SYSTEM.PA_VARCHAR2_2000_TBL_TYPE := SYSTEM.PA_VARCHAR2_2000_TBL_TYPE();
9360 l_attribute_categoryTab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
9361 l_attribute1Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9362 l_attribute2Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9363 l_attribute3Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9364 l_attribute4Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9365 l_attribute5Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9366 l_attribute6Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9367 l_attribute7Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9368 l_attribute8Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9369 l_attribute9Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9370 l_attribute10Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9371 l_attribute11Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9372 l_attribute12Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9373 l_attribute13Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9374 l_attribute14Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9375 l_attribute15Tab SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE();
9376 l_project_raw_costTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
9377 l_project_burdened_costTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
9378 l_project_revenueTab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
9379 l_txn_currency_codeTab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
9380 l_projfunc_currency_codeTab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
9381 l_project_currency_codeTab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
9382 l_end_dateTab SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE ();
9383 l_period_nameTab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
9384
9385 CURSOR Cur_group_source_budget_lines IS
9386 SELECT distinct pbl.resource_assignment_id resource_assignment_id, pbl.start_date start_date,pra.rate_based_flag
9387 FROM pa_budget_lines pbl, pa_resource_assignments pra
9388 WHERE pbl.budget_version_id = p_source_plan_version_id
9389 AND pra.resource_assignment_id = pbl.resource_assignment_id;
9390
9391 CURSOR Cur_source_budget_lines(p_resource_assignment_id IN NUMBER, p_start_date IN DATE
9392 ,p_rate_based_flag IN VARCHAR2 , p_cost_flag IN VARCHAR2 , p_revenue_flag IN VARCHAR2) IS
9393 SELECT
9394 budget_line_id
9395 ,nvl(DECODE(p_rate_based_flag,'N',DECODE(p_cost_flag,'Y',nvl(raw_cost,0),nvl(revenue,0)),quantity),0) quantity
9396 ,nvl(raw_cost,0)
9397 ,nvl(burdened_cost,0)
9398 ,nvl(revenue,0)
9399 ,change_reason_code
9400 ,description
9401 ,attribute_category
9402 ,attribute1
9403 ,attribute2
9404 ,attribute3
9405 ,attribute4
9406 ,attribute5
9407 ,attribute6
9408 ,attribute7
9409 ,attribute8
9410 ,attribute9
9411 ,attribute10
9412 ,attribute11
9413 ,attribute12
9414 ,attribute13
9415 ,attribute14
9416 ,attribute15
9417 ,nvl(project_raw_cost,0)
9418 ,nvl(project_burdened_cost,0)
9419 ,nvl(project_revenue,0)
9420 ,txn_currency_code
9421 ,projfunc_currency_code
9422 ,project_currency_code
9423 ,end_date
9424 ,period_name
9425 FROM pa_budget_lines
9426 WHERE resource_assignment_id = p_resource_assignment_id
9427 AND start_date = p_start_date
9428 AND cost_rejection_code is null
9429 AND burden_rejection_code is null
9430 AND revenue_rejection_code is null
9431 AND other_rejection_code is null
9432 AND pc_cur_conv_rejection_code is null
9433 AND pfc_cur_conv_rejection_code is null
9434 ORDER BY txn_currency_code;
9435
9436 /* PROCEDURE InitPLSQLTab IS
9437 BEGIN
9438 l_budget_line_idTab.delete;
9439 l_quantityTab.delete;
9440 l_raw_costTab.delete;
9441 l_burdened_costTab.delete;
9442 l_revenueTab.delete;
9443 l_change_reason_codeTab.delete;
9444 l_descriptionTab.delete;
9445 l_attribute_categoryTab.delete;
9446 l_attribute1Tab.delete;
9447 l_attribute2Tab.delete;
9448 l_attribute3Tab.delete;
9449 l_attribute4Tab.delete;
9450 l_attribute5Tab.delete;
9451 l_attribute6Tab.delete;
9452 l_attribute7Tab.delete;
9453 l_attribute8Tab.delete;
9454 l_attribute9Tab.delete;
9455 l_attribute10Tab.delete;
9456 l_attribute11Tab.delete;
9457 l_attribute12Tab.delete;
9458 l_attribute13Tab.delete;
9459 l_attribute14Tab.delete;
9460 l_attribute15Tab.delete;
9461 l_project_raw_costTab.delete;
9462 l_project_burdened_costTab.delete;
9463 l_project_revenueTab.delete;
9464 l_txn_currency_codeTab.delete;
9465 l_projfunc_currency_codeTab.delete;
9466 l_project_currency_codeTab.delete;
9467 l_end_dateTab.delete;
9468 l_period_nameTab.delete;
9469
9470 END InitPLSQLTab; ** bug 3709036 */
9471
9472 l_etc_start_date pa_budget_versions.etc_start_date%TYPE;
9473
9474 --Bug 4290043.
9475 l_targ_pref_code pa_proj_fp_options.fin_plan_preference_code%TYPE;
9476 l_source_version_type pa_budget_versions.version_type%TYPE;
9477 l_target_version_type pa_budget_versions.version_type%TYPE;
9478 l_src_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
9479
9480 BEGIN
9481
9482 x_msg_count := 0;
9483 x_return_status := FND_API.G_RET_STS_SUCCESS;
9484 IF P_PA_DEBUG_MODE = 'Y' THEN
9485 pa_debug.set_err_stack('PA_FP_COPY_FROM_PKG.Copy_Budget_Lines_Appr_Rev');
9486 END IF;
9487 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
9488 l_debug_mode := NVL(l_debug_mode, 'Y');
9489 IF P_PA_DEBUG_MODE = 'Y' THEN
9490 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
9491 END IF;
9492 -- Checking for all valid input parametrs
9493
9494 IF P_PA_DEBUG_MODE = 'Y' THEN
9495 pa_debug.g_err_stage := 'Checking for valid parameters:';
9496 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,3);
9497 END IF;
9498
9499 IF (p_source_plan_version_id IS NULL) OR
9500 (p_target_plan_version_id IS NULL)
9501 THEN
9502
9503 IF P_PA_DEBUG_MODE = 'Y' THEN
9504 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
9505 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,5);
9506 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
9507 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,5);
9508 END IF;
9509
9510 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
9511 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
9512 p_token1=>'PROCEDURENAME',
9513 p_value1=>'COPY_BUDGET_LINES_APPR_REV');
9514
9515 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9516
9517 END IF;
9518
9519 IF P_PA_DEBUG_MODE = 'Y' THEN
9520 pa_debug.g_err_stage := 'Parameter validation complete';
9521 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,3);
9522 END IF;
9523
9524 --make adj percentage zero if passed as null
9525
9526 l_adj_percentage := NVL(p_adj_percentage,0);
9527
9528 -- Fetching the flags of target version using fin_plan_prefernce_code
9529
9530
9531 IF P_PA_DEBUG_MODE = 'Y' THEN
9532 pa_debug.g_err_stage:='Fetching the raw_cost,burdened_cost and revenue flags of target_version';
9533 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,3);
9534 END IF;
9535
9536 SELECT DECODE(fin_plan_preference_code -- l_revenue_flag
9537 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY ,'Y'
9538 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME ,'Y','N')
9539 ,DECODE(fin_plan_preference_code -- l_cost_flag
9540 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME , 'Y','N')
9541 ,fin_plan_preference_code
9542 INTO l_revenue_flag
9543 ,l_cost_flag
9544 ,l_targ_pref_code
9545 FROM pa_proj_fp_options
9546 WHERE fin_plan_version_id=p_target_plan_version_id;
9547
9548 --Bug 3927244
9549 --Bug 4290043. Selected version type too
9550 SELECT etc_start_date,
9551 version_type
9552 INTO l_etc_start_date,
9553 l_target_version_type
9554 FROM pa_budget_versions
9555 WHERE budget_version_id=p_target_plan_version_id;
9556 --Bug 3927244
9557
9558 --Bug 4290043.
9559 SELECT pbv.version_type,
9560 fin.plan_class_code
9561 INTO l_source_version_type,
9562 l_src_plan_class_code
9563 FROM pa_budget_versions pbv,
9564 pa_fin_plan_types_b fin
9565 WHERE pbv.fin_plan_type_id=fin.fin_plan_type_id
9566 AND pbv.budget_version_id = p_source_plan_version_id;
9567
9568 DELETE FROM PA_FP_BL_MAP_TMP;
9569
9570 FOR rec_group_source_budget_lines IN cur_group_source_budget_lines LOOP
9571
9572 -- InitPLSQLTab; ** bug 3709036
9573
9574 l_ref := 1;
9575 l_quantity_tot := 0;
9576 l_raw_cost_tot := 0;
9577 l_burdened_cost_tot := 0;
9578 l_revenue_tot := 0;
9579 l_project_raw_cost_tot := 0;
9580 l_project_burdened_cost_tot := 0;
9581 l_project_revenue_tot := 0;
9582 l_rate_based_flag := rec_group_source_budget_lines.rate_based_flag;
9583
9584 SELECT pa_budget_lines_s.nextval
9585 INTO l_target_budget_line_id
9586 FROM dual;
9587
9588 Open Cur_source_budget_lines(rec_group_source_budget_lines.resource_assignment_id,
9589 rec_group_source_budget_lines.start_date,
9590 l_rate_based_flag,
9591 l_cost_flag,
9592 l_revenue_flag);
9593
9594 Fetch Cur_source_budget_lines bulk collect into
9595 l_budget_line_idTab
9596 ,l_quantityTab
9597 ,l_raw_costTab
9598 ,l_burdened_costTab
9599 ,l_revenueTab
9600 ,l_change_reason_codeTab
9601 ,l_descriptionTab
9602 ,l_attribute_categoryTab
9603 ,l_attribute1Tab
9604 ,l_attribute2Tab
9605 ,l_attribute3Tab
9606 ,l_attribute4Tab
9607 ,l_attribute5Tab
9608 ,l_attribute6Tab
9609 ,l_attribute7Tab
9610 ,l_attribute8Tab
9611 ,l_attribute9Tab
9612 ,l_attribute10Tab
9613 ,l_attribute11Tab
9614 ,l_attribute12Tab
9615 ,l_attribute13Tab
9616 ,l_attribute14Tab
9617 ,l_attribute15Tab
9618 ,l_project_raw_costTab
9619 ,l_project_burdened_costTab
9620 ,l_project_revenueTab
9621 ,l_txn_currency_codeTab
9622 ,l_projfunc_currency_codeTab
9623 ,l_project_currency_codeTab
9624 ,l_end_dateTab
9625 ,l_period_nameTab;
9626
9627 Close Cur_source_budget_lines; -- bug 3709036
9628
9629 IF l_budget_line_idTab.count > 0 THEN -- bug 3709036
9630
9631 FOR J in 1..l_budget_line_idTab.count LOOP ---{
9632
9633 l_quantity_tot := l_quantity_tot + l_quantityTab(j);
9634 l_raw_cost_tot := l_raw_cost_tot + l_raw_costTab(j);
9635 l_burdened_cost_tot := l_burdened_cost_tot + l_burdened_costTab(j);
9636 l_revenue_tot := l_revenue_tot + l_revenueTab(j);
9637 l_project_raw_cost_tot := l_project_raw_cost_tot + l_project_raw_costTab(j);
9638 l_project_burdened_cost_tot := l_project_burdened_cost_tot + l_project_burdened_costTab(j);
9639 l_project_revenue_tot := l_project_revenue_tot + l_project_revenueTab(j);
9640
9641 IF (l_txn_currency_codeTab(j) = l_projfunc_currency_codeTab(j)
9642 and ( l_change_reason_codeTab(j) IS NOT NULL
9643 OR l_descriptionTab(j) IS NOT NULL
9644 OR l_attribute_categoryTab(j) IS NOT NULL
9645 OR l_attribute1Tab(j) IS NOT NULL
9646 OR l_attribute2Tab(j) IS NOT NULL
9647 OR l_attribute3Tab(j) IS NOT NULL
9648 OR l_attribute4Tab(j) IS NOT NULL
9649 OR l_attribute5Tab(j) IS NOT NULL
9650 OR l_attribute6Tab(j) IS NOT NULL
9651 OR l_attribute7Tab(j) IS NOT NULL
9652 OR l_attribute8Tab(j) IS NOT NULL
9653 OR l_attribute9Tab(j) IS NOT NULL
9654 OR l_attribute10Tab(j) IS NOT NULL
9655 OR l_attribute11Tab(j) IS NOT NULL
9656 OR l_attribute12Tab(j) IS NOT NULL
9657 OR l_attribute13Tab(j) IS NOT NULL
9658 OR l_attribute14Tab(j) IS NOT NULL
9659 OR l_attribute15Tab(j) IS NOT NULL )) THEN
9660
9661 l_ref := j;
9662
9663 END IF;
9664
9665 INSERT INTO PA_FP_BL_MAP_TMP
9666 ( source_budget_line_id
9667 ,target_budget_line_id
9668 )
9669 VALUES (l_budget_line_idTab(j),
9670 l_target_budget_line_id
9671 );
9672
9673 END LOOP; ---}
9674
9675 IF l_raw_cost_tot = 0 THEN
9676 l_project_cost_exchange_rate := 1;
9677 ELSE
9678 l_project_cost_exchange_rate := l_project_raw_cost_tot/l_raw_cost_tot;
9679 END IF;
9680
9681 IF l_revenue_tot = 0 THEN
9682 l_proj_rev_ex_rate := 1;
9683 ELSE
9684 l_proj_rev_ex_rate := l_project_revenue_tot/l_revenue_tot;
9685 END IF;
9686
9687 IF l_quantity_tot = 0 THEN
9688 l_txn_cost_rate_override := null;
9689 l_txn_bill_rate_override := null;
9690 l_burden_cost_rate_override := null;
9691 ELSE
9692 l_txn_cost_rate_override := l_raw_cost_tot/l_quantity_tot;
9693 l_txn_bill_rate_override := l_revenue_tot/l_quantity_tot;
9694 l_burden_cost_rate_override := l_burdened_cost_tot/l_quantity_tot;
9695 END IF;
9696
9697 INSERT INTO PA_BUDGET_LINES(
9698 budget_line_id
9699 ,budget_version_id
9700 ,resource_assignment_id
9701 ,start_date
9702 ,last_update_date
9703 ,last_updated_by
9704 ,creation_date
9705 ,created_by
9706 ,last_update_login
9707 ,end_date
9708 ,period_name
9709 ,quantity
9710 ,raw_cost
9711 ,burdened_cost
9712 ,revenue
9713 ,change_reason_code
9714 ,description
9715 ,attribute_category
9716 ,attribute1
9717 ,attribute2
9718 ,attribute3
9719 ,attribute4
9720 ,attribute5
9721 ,attribute6
9722 ,attribute7
9723 ,attribute8
9724 ,attribute9
9725 ,attribute10
9726 ,attribute11
9727 ,attribute12
9728 ,attribute13
9729 ,attribute14
9730 ,attribute15
9731 ,raw_cost_source
9732 ,burdened_cost_source
9733 ,quantity_source
9734 ,revenue_source
9735 ,pm_product_code
9736 ,pm_budget_line_reference
9737 ,cost_rejection_code
9738 ,revenue_rejection_code
9739 ,burden_rejection_code
9740 ,other_rejection_code
9741 ,code_combination_id
9742 ,ccid_gen_status_code
9743 ,ccid_gen_rej_message
9744 ,request_id
9745 ,borrowed_revenue
9746 ,tp_revenue_in
9747 ,tp_revenue_out
9748 ,revenue_adj
9749 ,lent_resource_cost
9750 ,tp_cost_in
9751 ,tp_cost_out
9752 ,cost_adj
9753 ,unassigned_time_cost
9754 ,utilization_percent
9755 ,utilization_hours
9756 ,utilization_adj
9757 ,capacity
9758 ,head_count
9759 ,head_count_adj
9760 ,projfunc_currency_code
9761 ,projfunc_cost_rate_type
9762 ,projfunc_cost_exchange_rate
9763 ,projfunc_cost_rate_date_type
9764 ,projfunc_cost_rate_date
9765 ,projfunc_rev_rate_type
9766 ,projfunc_rev_exchange_rate
9767 ,projfunc_rev_rate_date_type
9768 ,projfunc_rev_rate_date
9769 ,project_currency_code
9770 ,project_cost_rate_type
9771 ,project_cost_exchange_rate
9772 ,project_cost_rate_date_type
9773 ,project_cost_rate_date
9774 ,project_raw_cost
9775 ,project_burdened_cost
9776 ,project_rev_rate_type
9777 ,project_rev_exchange_rate
9778 ,project_rev_rate_date_type
9779 ,project_rev_rate_date
9780 ,project_revenue
9781 ,txn_raw_cost
9782 ,txn_burdened_cost
9783 ,txn_currency_code
9784 ,txn_revenue
9785 ,bucketing_period_code
9786 ,transfer_price_rate
9787 ,init_quantity
9788 ,init_quantity_source
9789 ,init_raw_cost
9790 ,init_burdened_cost
9791 ,init_revenue
9792 ,init_raw_cost_source
9793 ,init_burdened_cost_source
9794 ,init_revenue_source
9795 ,project_init_raw_cost
9796 ,project_init_burdened_cost
9797 ,project_init_revenue
9798 ,txn_init_raw_cost
9799 ,txn_init_burdened_cost
9800 ,txn_init_revenue
9801 ,txn_markup_percent
9802 ,txn_markup_percent_override
9803 ,txn_discount_percentage
9804 ,txn_standard_bill_rate
9805 ,txn_standard_cost_rate
9806 ,txn_cost_rate_override
9807 ,burden_cost_rate
9808 ,txn_bill_rate_override
9809 ,burden_cost_rate_override
9810 ,cost_ind_compiled_set_id
9811 ,pc_cur_conv_rejection_code
9812 ,pfc_cur_conv_rejection_code
9813 )
9814 SELECT l_target_budget_line_id
9815 ,p_target_plan_version_id
9816 ,pra.resource_assignment_id
9817 ,rec_group_source_budget_lines.start_date
9818 ,sysdate -- last_update_date
9819 ,fnd_global.user_id -- last_updated_by
9820 ,sysdate -- creation_date
9821 ,fnd_global.user_id -- created_by
9822 ,fnd_global.login_id -- last_update_login
9823 ,l_end_dateTab(l_ref)
9824 ,l_period_nameTab(l_ref)
9825 ,l_quantity_tot
9826 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y', l_raw_cost_tot,NULL),NULL) -- raw_cost
9827 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y', l_burdened_cost_tot,NULL),NULL) -- burdened_cost
9828 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y', l_revenue_tot,NULL),NULL) -- revenue
9829 ,l_change_reason_codeTab(l_ref) -- change_reason_code
9830 ,l_descriptionTab(l_ref)-- description
9831 ,l_attribute_categoryTab(l_ref)
9832 ,l_attribute1Tab(l_ref)
9833 ,l_attribute2Tab(l_ref)
9834 ,l_attribute3Tab(l_ref)
9835 ,l_attribute4Tab(l_ref)
9836 ,l_attribute5Tab(l_ref)
9837 ,l_attribute6Tab(l_ref)
9838 ,l_attribute7Tab(l_ref)
9839 ,l_attribute8Tab(l_ref)
9840 ,l_attribute9Tab(l_ref)
9841 ,l_attribute10Tab(l_ref)
9842 ,l_attribute11Tab(l_ref)
9843 ,l_attribute12Tab(l_ref)
9844 ,l_attribute13Tab(l_ref)
9845 ,l_attribute14Tab(l_ref)
9846 ,l_attribute15Tab(l_ref)
9847 ,DECODE(l_cost_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --raw_cost_souce
9848 ,DECODE(l_cost_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --burdened_cost_source
9849 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P --quantity_source
9850 ,DECODE(l_revenue_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --revenue source
9851 ,null -- pm_product_code
9852 ,null
9853 ,null
9854 ,null
9855 ,null
9856 ,null
9857 ,null
9858 ,null
9859 ,null
9860 ,null
9861 ,null
9862 ,null
9863 ,null
9864 ,null
9865 ,null
9866 ,null
9867 ,null
9868 ,null
9869 ,null
9870 ,null
9871 ,null
9872 ,null
9873 ,null
9874 ,null
9875 ,null -- head_count_adj
9876 ,l_projfunc_currency_codeTab(l_ref)
9877 ,DECODE(l_cost_flag,'Y','User',NULL) -- projfunc_cost_rate_type
9878 ,DECODE(l_cost_flag,'Y',1,NULL) -- projfunc_cost_exchange_rate
9879 ,null -- projfunc_cost_rate_date_type
9880 ,null -- projfunc_cost_rate_date
9881 ,'User' -- projfunc_rev_rate_type
9882 ,1 -- projfunc_rev_exchange_rate
9883 ,null -- projfunc_rev_rate_date_type
9884 ,null -- projfunc_rev_rate_date
9885 ,l_project_currency_codeTab(l_ref)
9886 ,DECODE(l_cost_flag,'Y','User',NULL) -- project_cost_rate_type
9887 ,DECODE(l_cost_flag,'Y',l_project_cost_exchange_rate,NULL) -- project_cost_exchange_rate
9888 ,null -- project_cost_rate_date_type
9889 ,null -- project_cost_rate_date
9890 ,DECODE(l_adj_percentage,0,
9891 DECODE(l_cost_flag,'Y', l_project_raw_cost_tot,NULL),NULL) --project_raw_cost
9892 ,DECODE(l_adj_percentage,0,
9893 DECODE(l_cost_flag,'Y', l_project_burdened_cost_tot,NULL),NULL) -- project_burdened_cost
9894 ,'User' -- project_rev_rate_type
9895 ,l_proj_rev_ex_rate -- project_rev_exchange_rate
9896 ,null -- project_rev_rate_date_type
9897 ,null -- project_rev_rate_date
9898 ,DECODE(l_adj_percentage,0,
9899 DECODE(l_revenue_flag,'Y', l_project_revenue_tot,NULL),NULL) -- project_revenue
9900 ,DECODE(l_cost_flag,'Y',
9901 decode(GREATEST(rec_group_source_budget_lines.start_date,NVL(l_etc_start_date,rec_group_source_budget_lines.start_date)),rec_group_source_budget_lines.start_date
9902 ,l_raw_cost_tot*(1+l_adj_percentage),l_raw_cost_tot),NULL) -- txn_raw_cost
9903 ,DECODE(l_cost_flag,'Y',
9904 decode(GREATEST(rec_group_source_budget_lines.start_date,NVL(l_etc_start_date,rec_group_source_budget_lines.start_date)),rec_group_source_budget_lines.start_date
9905 ,l_burdened_cost_tot*(1+l_adj_percentage),l_burdened_cost_tot),NULL) -- txn_burdened_cost
9906 ,l_projfunc_currency_codeTab(l_ref) -- txn_currency_code
9907 ,DECODE(l_revenue_flag,'Y',
9908 decode(GREATEST(rec_group_source_budget_lines.start_date,NVL(l_etc_start_date,rec_group_source_budget_lines.start_date)),rec_group_source_budget_lines.start_date
9909 ,l_revenue_tot*(1+l_adj_percentage),l_revenue_tot),NULL) -- txn_revenue
9910 ,null -- bucketing_period_code
9911 ,null -- transfer_price_rate
9912 ,NULL --init_quantity
9913 ,NULL --init_quantity_source
9914 ,NULL --init_raw_cost
9915 ,NULL --init_burdened_cost
9916 ,NULL --init_revenue
9917 ,NULL --init_raw_cost_source
9918 ,NULL --init_burdened_cost_source
9919 ,NULL --init_revenue_source
9920 ,NULL --project_init_raw_cost
9921 ,NULL --project_init_burdened_cost
9922 ,NULL --project_init_revenue
9923 ,NULL --txn_init_raw_cost
9924 ,NULL --txn_init_burdened_cost
9925 ,NULL --txn_init_revenue
9926 ,null -- txn_markup_percent
9927 ,null -- txn_markup_percent_override
9928 ,null -- txn_discount_percentage
9929 ,null -- txn_standard_bill_rate
9930 ,null -- txn_standard_cost_rate
9931 ,DECODE(l_cost_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',l_txn_cost_rate_override,NULL),NULL) -- txn_cost_rate_override
9932 ,null -- burden_cost_rate
9933 ,DECODE(l_revenue_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',l_txn_bill_rate_override,NULL),NULL) -- txn_bill_rate_override
9934 ,DECODE(l_cost_flag,'Y',DECODE(p_derv_rates_missing_amts_flag,'N',l_burden_cost_rate_override,NULL),NULL) -- burden_cost_rate_override
9935 ,null -- cost_ind_compiled_set_id
9936 ,null -- pc_cur_conv_rejection_code
9937 ,null -- pfc_cur_conv_rejection_code
9938 FROM pa_resource_assignments pra
9939 WHERE rec_group_source_budget_lines.resource_assignment_id = pra.parent_assignment_id
9940 AND pra.budget_version_id=p_target_plan_version_id;
9941
9942 END IF; -- l_budget_line_idTab.count
9943
9944 END LOOP;
9945
9946 -- Bug 4035856 Call rounding api if l_adj_percentage is not zero
9947 IF l_adj_percentage <> 0 THEN
9948 PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts
9949 ( p_budget_version_id => p_target_plan_version_id
9950 ,p_calling_context => 'COPY_VERSION'
9951 ,x_return_status => l_return_status
9952 ,x_msg_count => l_msg_count
9953 ,x_msg_data => l_msg_data);
9954
9955 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9956 IF P_PA_debug_mode = 'Y' THEN
9957 pa_debug.g_err_stage:= 'Error in PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts';
9958 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,5);
9959 END IF;
9960 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9961 END IF;
9962 END IF;
9963
9964 --Bug 4290043. Call the API to correct the missing amounts in the target version in case it can have
9965 --missing amounts/rates
9966 IF p_derv_rates_missing_amts_flag = 'Y' OR
9967 l_adj_percentage <> 0 THEN
9968
9969
9970 derv_missing_amts_chk_neg_qty
9971 (p_budget_version_id => p_target_plan_version_id,
9972 p_targ_pref_code => l_targ_pref_code,
9973 p_source_version_type => l_source_version_type,
9974 p_target_version_type => l_target_version_type,
9975 p_src_plan_class_code => l_src_plan_class_code,
9976 p_derv_rates_missing_amts_flag => p_derv_rates_missing_amts_flag,
9977 p_adj_percentage => l_adj_percentage,
9978 x_return_status => l_return_status,
9979 x_msg_count => l_msg_count,
9980 x_msg_data => l_msg_data);
9981
9982 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9983 IF P_PA_debug_mode = 'Y' THEN
9984 pa_debug.g_err_stage:= 'Error in derv_missing_amts_chk_neg_qty';
9985 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,5);
9986 END IF;
9987 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
9988
9989 END IF;
9990
9991 END IF;--IF p_derv_rates_missing_amts_flag = 'Y' THEN
9992
9993 IF P_PA_DEBUG_MODE = 'Y' THEN
9994 pa_debug.g_err_stage:='Exiting Copy_Budget_Lines_Appr_Rev';
9995 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,3);
9996 pa_debug.reset_err_stack; -- bug:- 2815593
9997 END IF;
9998 EXCEPTION
9999
10000 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
10001 l_msg_count := FND_MSG_PUB.count_msg;
10002 IF l_msg_count = 1 THEN
10003 PA_INTERFACE_UTILS_PUB.get_messages
10004 (p_encoded => FND_API.G_TRUE
10005 ,p_msg_index => 1
10006 ,p_msg_count => l_msg_count
10007 ,p_msg_data => l_msg_data
10008 ,p_data => l_data
10009 ,p_msg_index_out => l_msg_index_out);
10010 x_msg_data := l_data;
10011 x_msg_count := l_msg_count;
10012 ELSE
10013 x_msg_count := l_msg_count;
10014 END IF;
10015 x_return_status := FND_API.G_RET_STS_ERROR;
10016
10017 IF P_PA_DEBUG_MODE = 'Y' THEN
10018 pa_debug.g_err_stage:='Invalid arguments passed';
10019 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,5);
10020 pa_debug.reset_err_stack;
10021 END IF;
10022 RAISE;
10023
10024 WHEN Others THEN
10025 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10026 x_msg_count := 1;
10027 x_msg_data := SQLERRM;
10028 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'PA_FP_COPY_FROM_PKG'
10029 ,p_procedure_name => 'COPY_BUDGET_LINES_APPR_REV');
10030
10031 IF P_PA_DEBUG_MODE = 'Y' THEN
10032 pa_debug.g_err_stage:='Unexpected error'||SQLERRM;
10033 pa_debug.write('Copy_Budget_Lines_Appr_Rev: ' || g_module_name,pa_debug.g_err_stage,6);
10034 pa_debug.reset_err_stack;
10035 END IF;
10036 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10037 END Copy_Budget_Lines_Appr_Rev;
10038
10039 /*=============================================================================
10040 Bug 3619687: PJ.M:B5:BF:DEV:TRACKING BUG FOR PLAN SETTINGS CHANGE REQUEST
10041 When a new workplan structure version is created from a published version, this
10042 api is called to synchronise all the additional workplan settings related data.
10043 This api is called from copy_wp_budget_versions api at the end of copying all
10044 the budgets related data from source published version.
10045 Synchronisation involves:
10046 1) pa_fp_txn_currencies
10047 2) rate schedules, generation options and plan settings data
10048 (pa_proj_fp_options)
10049
10050 Stating some of the business rules for clarity:
10051 i) If there is a published version, time phasing can not be changed
10052 ii) Planning resource list can change only if existing resource list is
10053 'None'. To handle this case, we would re-map the resource assignments
10054 data. Please note that in this case, only 'PEOPLE' resource class assignments
10055 would be present.
10056 iii) RBS can be different only if existing RBS is null.
10057
10058 Bug 3725414: In update to pa_proj_fp_options, rbs_version_id column is missing
10059
10060 Bug 4101153: Current Planning period should always get the value from the source version and
10061 not from the workplan plan type option. Removed the update to current planning period
10062
10063 Bug 4337221: dbora- Excluded the quantity and cost amount columns from the update
10064 statement on pa_budget_versions, so that the quantity and cost amount columns gets
10065 copied as it is from the source version retaining the version level rolled up figures.
10066 ==============================================================================*/
10067
10068 PROCEDURE Update_Plan_Setup_For_WP_Copy(
10069 p_project_id IN pa_projects_all.project_id%TYPE
10070 ,p_wp_version_id IN pa_budget_versions.fin_plan_type_id%TYPE
10071 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
10072 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
10073 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
10074 AS
10075
10076 --Start of variables used for debugging
10077
10078 l_return_status VARCHAR2(1);
10079 l_msg_count NUMBER := 0;
10080 l_msg_data VARCHAR2(2000);
10081 l_data VARCHAR2(2000);
10082 l_msg_index_out NUMBER;
10083 l_debug_mode VARCHAR2(30);
10084 l_error_msg_code VARCHAR2(30);
10085
10086
10087 --End of variables used for debugging
10088
10089 l_resource_list_change_flag VARCHAR2(1);
10090 l_rbs_version_change_flag VARCHAR2(1);
10091 l_people_res_class_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
10092 l_equip_res_class_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
10093 l_fin_res_class_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
10094 l_mat_res_class_rlm_id pa_resource_list_members.resource_list_member_id%TYPE;
10095
10096 l_txn_source_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
10097 l_res_list_member_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
10098 l_rbs_element_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
10099 l_txn_accum_header_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
10100
10101 l_budget_version_id_tbl SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
10102
10103 CURSOR parent_plan_type_cur IS
10104 SELECT pfo.proj_fp_options_id
10105 ,pfo.track_workplan_costs_flag
10106 ,pfo.plan_in_multi_curr_flag
10107 ,pfo.rbs_version_id
10108 ,pfo.margin_derived_from_code
10109 ,pfo.factor_by_code
10110 ,pfo.cost_resource_list_id
10111 ,pfo.select_cost_res_auto_flag
10112 ,pfo.cost_time_phased_code
10113 ,pfo.cost_period_mask_id
10114 ,pfo.projfunc_cost_rate_type
10115 ,pfo.projfunc_cost_rate_date_type
10116 ,pfo.projfunc_cost_rate_date
10117 ,pfo.project_cost_rate_type
10118 ,pfo.project_cost_rate_date_type
10119 ,pfo.project_cost_rate_date
10120 ,pfo.use_planning_rates_flag
10121 ,pfo.res_class_raw_cost_sch_id
10122 ,pfo.cost_emp_rate_sch_id
10123 ,pfo.cost_job_rate_sch_id
10124 ,pfo.cost_non_labor_res_rate_sch_id
10125 ,pfo.cost_res_class_rate_sch_id
10126 ,pfo.cost_burden_rate_sch_id
10127 FROM pa_proj_fp_options pfo
10128 ,pa_fin_plan_types_b fpt
10129 WHERE pfo.project_id = p_project_id
10130 AND pfo.fin_plan_type_id = fpt.fin_plan_type_id
10131 AND fpt.use_for_workplan_flag = 'Y'
10132 AND pfo.fin_plan_option_level_code = 'PLAN_TYPE';
10133
10134 parent_plan_type_rec parent_plan_type_cur%ROWTYPE;
10135
10136 CURSOR wp_version_options_cur IS
10137 SELECT pfo.proj_fp_options_id
10138 ,pfo.rbs_version_id
10139 ,pfo.cost_resource_list_id
10140 FROM pa_proj_fp_options pfo
10141 ,pa_budget_versions bv
10142 WHERE bv.budget_version_id = p_wp_version_id
10143 AND bv.project_id = pfo.project_id
10144 AND pfo.fin_plan_version_id = bv.budget_version_id;
10145
10146 wp_version_options_rec wp_version_options_cur%ROWTYPE;
10147
10148
10149 BEGIN
10150
10151 x_msg_count := 0;
10152 x_return_status := FND_API.G_RET_STS_SUCCESS;
10153
10154 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
10155 l_debug_mode := NVL(l_debug_mode, 'Y');
10156
10157 -- Set curr function
10158 IF l_debug_mode = 'Y' THEN
10159 pa_debug.set_curr_function(
10160 p_function =>'PA_FP_COPY_FROM_PKG.Update_Plan_Setup_For_WP_Copy'
10161 ,p_debug_mode => l_debug_mode );
10162
10163 -- Check for business rules violations
10164 pa_debug.g_err_stage:='Validating input parameters';
10165 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,3);
10166 END IF;
10167
10168 IF (p_project_id IS NULL) OR
10169 (p_wp_version_id IS NULL)
10170 THEN
10171
10172 IF l_debug_mode = 'Y' THEN
10173 pa_debug.g_err_stage:='p_project_id = '||p_project_id;
10174 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10175
10176 pa_debug.g_err_stage:='p_wp_version_id = '||p_wp_version_id;
10177 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10178 END IF;
10179
10180 PA_UTILS.ADD_MESSAGE( p_app_short_name => 'PA',
10181 p_msg_name => 'PA_FP_INV_PARAM_PASSED',
10182 p_token1 => 'PROCEDURENAME',
10183 p_value1 => 'PA_FP_COPY_FROM_PKG.Update_Plan_Setup_For_WP_Copy');
10184
10185 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10186
10187 END IF;
10188
10189 -- Fetch all the plan type values that could have changed
10190 OPEN parent_plan_type_cur;
10191 FETCH parent_plan_type_cur INTO parent_plan_type_rec;
10192 CLOSE parent_plan_type_cur;
10193
10194 -- Fetch options id for the workplan version
10195 OPEN wp_version_options_cur;
10196 FETCH wp_version_options_cur INTO wp_version_options_rec;
10197 CLOSE wp_version_options_cur;
10198
10199 -- Check if resource list has changed
10200 IF wp_version_options_rec.cost_resource_list_id <> parent_plan_type_rec.cost_resource_list_id
10201 THEN
10202 l_resource_list_change_flag := 'Y';
10203 ELSE
10204 l_resource_list_change_flag := 'N';
10205 END IF;
10206
10207 -- Check if rbs version has changed
10208 IF nvl(wp_version_options_rec.rbs_version_id,-99) <> nvl(parent_plan_type_rec.rbs_version_id,-99)
10209 THEN
10210 l_rbs_version_change_flag := 'Y';
10211 ELSE
10212 l_rbs_version_change_flag := 'N';
10213 END IF;
10214
10215 -- Update pa_budget_versions table data
10216 -- Note that period mask and planning period could have changed so this update
10217 -- is necessary even if resource list is not changed
10218
10219 UPDATE pa_budget_versions
10220 SET resource_list_id = parent_plan_type_rec.cost_resource_list_id
10221 ,period_mask_id = parent_plan_type_rec.cost_period_mask_id
10222 /* Bug 4337221: removed from the update
10223 ,raw_cost = 0
10224 ,burdened_cost = 0
10225 ,total_project_raw_cost = 0
10226 ,total_project_burdened_cost = 0
10227 ,labor_quantity = 0
10228 ,equipment_quantity = 0
10229 */
10230 ,last_update_date = SYSDATE
10231 ,last_updated_by = FND_GLOBAL.user_id
10232 ,last_update_login = FND_GLOBAL.login_id
10233 ,record_version_number = record_version_number + 1
10234 WHERE budget_version_id = p_wp_version_id;
10235
10236 -- Update pa_proj_fp_options entity
10237 UPDATE pa_proj_fp_options
10238 SET track_workplan_costs_flag = parent_plan_type_rec.track_workplan_costs_flag
10239 ,plan_in_multi_curr_flag = parent_plan_type_rec.plan_in_multi_curr_flag
10240 ,margin_derived_from_code = parent_plan_type_rec.margin_derived_from_code
10241 ,factor_by_code = parent_plan_type_rec.factor_by_code
10242 ,cost_resource_list_id = parent_plan_type_rec.cost_resource_list_id
10243 ,select_cost_res_auto_flag = parent_plan_type_rec.select_cost_res_auto_flag
10244 ,cost_time_phased_code = parent_plan_type_rec.cost_time_phased_code
10245 ,cost_period_mask_id = parent_plan_type_rec.cost_period_mask_id
10246 ,projfunc_cost_rate_type = parent_plan_type_rec.projfunc_cost_rate_type
10247 ,projfunc_cost_rate_date_type = parent_plan_type_rec.projfunc_cost_rate_date_type
10248 ,projfunc_cost_rate_date = parent_plan_type_rec.projfunc_cost_rate_date
10249 ,project_cost_rate_type = parent_plan_type_rec.project_cost_rate_type
10250 ,project_cost_rate_date_type = parent_plan_type_rec.project_cost_rate_date_type
10251 ,project_cost_rate_date = parent_plan_type_rec.project_cost_rate_date
10252 ,use_planning_rates_flag = parent_plan_type_rec.use_planning_rates_flag
10253 ,res_class_raw_cost_sch_id = parent_plan_type_rec.res_class_raw_cost_sch_id
10254 ,cost_emp_rate_sch_id = parent_plan_type_rec.cost_emp_rate_sch_id
10255 ,cost_job_rate_sch_id = parent_plan_type_rec.cost_job_rate_sch_id
10256 ,cost_non_labor_res_rate_sch_id = parent_plan_type_rec.cost_non_labor_res_rate_sch_id
10257 ,cost_res_class_rate_sch_id = parent_plan_type_rec.cost_res_class_rate_sch_id
10258 ,cost_burden_rate_sch_id = parent_plan_type_rec.cost_burden_rate_sch_id
10259 ,rbs_version_id = parent_plan_type_rec.rbs_version_id -- Bug 3725414
10260 ,record_version_number = record_version_number + 1
10261 ,last_update_date = SYSDATE
10262 ,last_updated_by = FND_GLOBAL.user_id
10263 ,last_update_login = FND_GLOBAL.login_id
10264 WHERE proj_fp_options_id = wp_version_options_rec.proj_fp_options_id;
10265
10266 -- Copy MC currencies from plan type
10267
10268 PA_FP_TXN_CURRENCIES_PUB.copy_fp_txn_currencies (
10269 p_source_fp_option_id => parent_plan_type_rec.proj_fp_options_id
10270 ,p_target_fp_option_id => wp_version_options_rec.proj_fp_options_id
10271 ,p_target_fp_preference_code => NULL
10272 ,p_plan_in_multi_curr_flag => parent_plan_type_rec.plan_in_multi_curr_flag
10273 ,x_return_status => x_return_status
10274 ,x_msg_count => x_msg_count
10275 ,x_msg_data => x_msg_data );
10276
10277 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10278 IF l_debug_mode = 'Y' THEN
10279 pa_debug.g_err_stage:='Called API PA_FP_TXN_CURRENCIES_PUB.copy_fp_txn_currencies
10280 api returned error';
10281 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10282 END IF;
10283 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10284 END IF;
10285
10286 -- If resource list has changed, resource assingments data should be re-mapped as per
10287 -- the new resource list
10288 IF l_resource_list_change_flag = 'Y' THEN
10289 PA_PLANNING_TRANSACTION_UTILS.Get_Res_Class_Rlm_Ids
10290 ( p_project_id => p_project_id
10291 ,p_resource_list_id => parent_plan_type_rec.cost_resource_list_id
10292 ,x_people_res_class_rlm_id => l_people_res_class_rlm_id
10293 ,x_equip_res_class_rlm_id => l_equip_res_class_rlm_id
10294 ,x_fin_res_class_rlm_id => l_fin_res_class_rlm_id
10295 ,x_mat_res_class_rlm_id => l_mat_res_class_rlm_id
10296 ,x_return_status => x_return_status
10297 ,x_msg_count => x_msg_count
10298 ,x_msg_data => x_msg_data);
10299
10300 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10301 IF l_debug_mode = 'Y' THEN
10302 pa_debug.g_err_stage:='Called API PA_PLANNING_TRANSACTION_UTILS.Get_Res_Class_Rlm_Ids
10303 api returned error';
10304 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10305 END IF;
10306 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10307 END IF;
10308
10309 -- Update all the task planning elements with new PEOPLE rlmid
10310 IF l_debug_mode = 'Y' THEN
10311 pa_debug.g_err_stage:='Updaing res assignments with new PEOPLE rlmid : '
10312 || l_people_res_class_rlm_id;
10313 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,3);
10314 END IF;
10315
10316 UPDATE pa_resource_assignments
10317 SET resource_list_member_id = l_people_res_class_rlm_id
10318 WHERE budget_version_id = p_wp_version_id
10319 AND resource_class_code = 'PEOPLE'
10320 AND resource_class_flag = 'Y';
10321 END IF;
10322
10323 -- If rbs version has changed, call pji_create for summarising the data
10324 IF l_rbs_version_change_flag = 'Y'
10325 THEN
10326 -- Call RBS mapping api for the entire version
10327 -- The api returns rbs element id, txn accum header id for each
10328 -- resource assignment id in the form of plsql tables
10329 PA_RLMI_RBS_MAP_PUB.Map_Rlmi_Rbs(
10330 p_budget_version_id => p_wp_version_id
10331 ,p_resource_list_id => parent_plan_type_rec.cost_resource_list_id
10332 ,p_rbs_version_id => parent_plan_type_rec.rbs_version_id
10333 ,p_calling_process => 'RBS_REFRESH'
10334 ,p_calling_context => 'PLSQL'
10335 ,p_process_code => 'RBS_MAP'
10336 ,p_calling_mode => 'BUDGET_VERSION'
10337 ,p_init_msg_list_flag => 'N'
10338 ,p_commit_flag => 'N'
10339 ,x_txn_source_id_tab => l_txn_source_id_tbl
10340 ,x_res_list_member_id_tab => l_res_list_member_id_tbl
10341 ,x_rbs_element_id_tab => l_rbs_element_id_tbl
10342 ,x_txn_accum_header_id_tab => l_txn_accum_header_id_tbl
10343 ,x_return_status => x_return_status
10344 ,x_msg_count => x_msg_count
10345 ,x_msg_data => x_msg_data);
10346
10347 -- Bug 3579153 Check return status
10348 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10349 IF l_debug_mode = 'Y' THEN
10350 pa_debug.g_err_stage:='Called API PA_PLANNING_TRANSACTION_UTILS.Map_Rlmi_Rbs api returned error';
10351 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10352 END IF;
10353 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10354 ELSE
10355 -- Check count of the required out tables to be the same
10356 IF l_txn_source_id_tbl.count <> l_rbs_element_id_tbl.count OR
10357 l_txn_source_id_tbl.count <> l_txn_accum_header_id_tbl.count
10358 THEN
10359 IF l_debug_mode = 'Y' THEN
10360 pa_debug.g_err_stage:='Called API PA_PLANNING_TRANSACTION_UTILS.Map_Rlmi_Rbs api
10361 returned out tables with different count';
10362 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10363 pa_debug.g_err_stage:='l_txn_source_id_tbl.count = ' || l_txn_source_id_tbl.count;
10364 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10365 pa_debug.g_err_stage:='l_rbs_element_id_tbl.count = ' || l_rbs_element_id_tbl.count;
10366 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10367 pa_debug.g_err_stage:=
10368 'l_txn_accum_header_id_tbl.count = ' || l_txn_accum_header_id_tbl.count;
10369 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10370 END IF;
10371 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
10372 END IF;
10373 END IF;
10374
10375 -- Check if out table has any records first
10376 IF nvl(l_txn_source_id_tbl.last,0) >= 1 THEN
10377
10378 -- Update resource assignments data for the version
10379 FORALL i IN l_txn_source_id_tbl.first .. l_txn_source_id_tbl.last
10380 UPDATE pa_resource_assignments
10381 SET rbs_element_id = l_rbs_element_id_tbl(i)
10382 ,txn_accum_header_id = l_txn_accum_header_id_tbl(i)
10383 ,record_version_number = record_version_number + 1
10384 ,last_update_date = SYSDATE
10385 ,last_updated_by = FND_GLOBAL.user_id
10386 ,last_update_login = FND_GLOBAL.login_id
10387 WHERE budget_version_id = p_wp_version_id
10388 AND resource_assignment_id = l_txn_source_id_tbl(i);
10389 END IF;
10390
10391 -- populating the l_budget_version_id_tbl with p_budget_version_id
10392 l_budget_version_id_tbl := SYSTEM.pa_num_tbl_type(p_wp_version_id);
10393
10394
10395 END IF;
10396
10397 IF l_debug_mode = 'Y' THEN
10398 pa_debug.g_err_stage:='Exiting Update_Plan_Setup_For_WP_Copy';
10399 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,3);
10400 -- reset curr function
10401 pa_debug.reset_curr_function();
10402 END IF;
10403
10404 EXCEPTION
10405
10406 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
10407 l_msg_count := FND_MSG_PUB.count_msg;
10408 IF l_msg_count = 1 THEN
10409 PA_INTERFACE_UTILS_PUB.get_messages
10410 (p_encoded => FND_API.G_TRUE
10411 ,p_msg_index => 1
10412 ,p_msg_count => l_msg_count
10413 ,p_msg_data => l_msg_data
10414 ,p_data => l_data
10415 ,p_msg_index_out => l_msg_index_out);
10416
10417 x_msg_data := l_data;
10418 x_msg_count := l_msg_count;
10419 ELSE
10420 x_msg_count := l_msg_count;
10421 END IF;
10422
10423 x_return_status := FND_API.G_RET_STS_ERROR;
10424
10425 IF l_debug_mode = 'Y' THEN
10426 pa_debug.g_err_stage:='Invalid Arguments Passed Or called api raised an error';
10427 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10428 -- reset curr function
10429 pa_debug.reset_curr_function();
10430 END IF;
10431 RETURN;
10432 WHEN Others THEN
10433 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10434 x_msg_count := 1;
10435 x_msg_data := SQLERRM;
10436
10437 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'PA_FP_COPY_FROM_PKG'
10438 ,p_procedure_name => 'Update_Plan_Setup_For_WP_Copy');
10439
10440 IF l_debug_mode = 'Y' THEN
10441 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
10442 pa_debug.write('Update_Plan_Setup_For_WP_Copy: ' || g_module_name,pa_debug.g_err_stage,5);
10443 -- reset curr function
10444 pa_debug.Reset_Curr_Function();
10445 END IF;
10446
10447 RAISE;
10448 END Update_Plan_Setup_For_WP_Copy;
10449
10450 END pa_fp_copy_from_pkg;