[Home] [Help]
PACKAGE BODY: APPS.PA_FP_ORG_FCST_GEN_PUB
Source
1 PACKAGE BODY pa_fp_org_fcst_gen_pub as
2 /* $Header: PAFPORGB.pls 120.3.12010000.2 2008/08/25 10:49:13 bifernan ship $ */
3 /**
4 -- Start of Comments
5 -- Package name : PA_FP_ORG_FCST_GEN_PUB
6 -- Purpose :
7 -- History :
8 -- 27-SEP-2002 sdebroy FPB2: Changes made due to addition of
9 -- budget_line_id into pa_budget_lines
10 -- table .
11 -- 26-NOV-02 ssarma FPB4: Added txn_currency_code to
12 -- all inserts into budget_lines.
13 -- The value will be that of PFC.
14 -- This is done b'coz txn_currency_code
15 -- is a new not null column from
16 -- patchset K.
17 -- 10-JAN-03 ssarma FPB7: Fix for 2744924. Look for seeded
18 -- row for amount sets.
19 -- 12-FEB-03 vejayara Bug 2796261-Source_Txn_currency_code in
20 -- pa_fin_plan_lines_tmp was not populated.
21 -- Now it is populated.
22 -- 02-JUN-03 msoundra replaced the call to
23 -- API pa_fp_org_fcst_utils.get_utilization_details
24 -- with pa_pji_util_pkg.get_utilization_dtls to get the numbers from
25 -- PJI data model if PJI is installed.
26 -- 21-AUG-03 dbora Bug 3106741 Performance related changes
27 -- 25-AUG-08 bifernan Bug 7309811 Use byte equivalent versions of
28 -- substr and length functions
29 -- NOTE :
30 -- End of Comments
31 REM | 03-OCT-2005 Riyengar MRC Elimination Changes:
32 **/
33
34 P_PA_DEBUG_MODE varchar2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
35 g_module_name VARCHAR2(100):= 'pa.plsql.pa_fp_org_fcst_gen_pub';
36 g_plsql_max_array_size NUMBER := 200;
37
38 FUNCTION budget_version_in_error
39 ( p_budget_version_id IN pa_budget_versions.budget_version_id%TYPE
40 ) RETURN NUMBER IS
41
42 BEGIN
43
44 UPDATE pa_budget_versions
45 SET plan_processing_code = 'E'
46 WHERE budget_version_id = p_budget_version_id;
47
48 COMMIT;
49
50 RETURN(1);
51
52 EXCEPTION
53 WHEN OTHERS THEN
54 FND_MSG_PUB.add_exc_msg(
55 p_pkg_name => 'PA_FP_ORG_FCST_GEN_PUB.budget_version_in_error'
56 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
57
58 IF P_PA_DEBUG_MODE = 'Y' THEN
59 pa_debug.write_file('budget_version_in_error: ' || SQLERRM);
60 END IF;
61 pa_debug.reset_err_stack;
62 RETURN(-1);
63 RAISE;
64 END budget_version_in_error;
65
66 FUNCTION get_amttype_id
67 ( p_amt_typ_code IN pa_amount_types_b.amount_type_code%TYPE
68 := NULL
69 ) RETURN NUMBER IS
70 l_amount_type_id pa_amount_types_b.amount_type_id%TYPE;
71 l_amt_code pa_fp_org_fcst_gen_pub.char240_data_type_table;
72 l_amt_id pa_fp_org_fcst_gen_pub.number_data_type_table;
73
74 l_debug_mode VARCHAR2(30);
75
76 CURSOR get_amt_det IS
77 SELECT atb.amount_type_id
78 ,atb.amount_type_code
79 FROM pa_amount_types_b atb
80 WHERE atb.amount_type_class = 'R';
81
82 l_stage number := 0;
83
84 BEGIN
85 IF P_PA_DEBUG_MODE = 'Y' THEN
86 pa_debug.init_err_stack('PA_FP_ORG_FCST_GEN_PUB.get_amttype_id');
87 END IF;
88
89 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
90 l_debug_mode := NVL(l_debug_mode, 'Y');
91
92 IF P_PA_DEBUG_MODE = 'Y' THEN
93 pa_debug.set_process('get_amttype_id: ' || 'PLSQL','LOG',l_debug_mode);
94 END IF;
95
96 l_amount_type_id := -99;
97
98 IF l_amt_code.last IS NULL THEN
99 OPEN get_amt_det;
100 LOOP
101 FETCH get_amt_det into l_amt_id(nvl(l_amt_id.last+1,1))
102 ,l_amt_code(nvl(l_amt_code.last+1,1));
103 EXIT WHEN get_amt_det%NOTFOUND;
104 END LOOP;
105 END IF;
106
107 IF l_amt_code.last IS NOT NULL THEN
108 FOR i in l_amt_id.first..l_amt_id.last LOOP
109 IF l_amt_code(i) = p_amt_typ_code THEN
110 l_amount_type_id := l_amt_id(i);
111 END IF;
112 END LOOP;
113 END IF;
114 IF l_amount_type_id = -99 THEN
115 pa_debug.g_err_stage := 'p_amt_typ_code ['||p_amt_typ_code ||']';
116 IF P_PA_DEBUG_MODE = 'Y' THEN
117 pa_debug.write_file('get_amttype_id: ' || pa_debug.g_err_stage);
118 END IF;
119 END IF;
120 pa_debug.reset_err_stack;
121 RETURN(l_amount_type_id);
122
123 EXCEPTION
124 WHEN OTHERS THEN
125 FND_MSG_PUB.add_exc_msg(
126 p_pkg_name => 'PA_FP_ORG_FCST_GEN_PUB.get_amttype_id'
127 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
128
129 IF P_PA_DEBUG_MODE = 'Y' THEN
130 pa_debug.write_file('get_amttype_id: ' || SQLERRM);
131 END IF;
132 pa_debug.reset_err_stack;
133 RAISE;
134 END get_amttype_id;
135
136 PROCEDURE gen_org_fcst
137 ( errbuff OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
138 ,retcode OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
139 ,p_selection_criteria IN VARCHAR2
140 := NULL
141 ,p_is_org IN VARCHAR2
142 := NULL
143 ,p_organization_id IN hr_organization_units.organization_id%TYPE
144 := NULL
145 ,p_is_start_org IN VARCHAR2
146 := NULL
147 ,p_starting_organization_id IN hr_organization_units.organization_id%TYPE
148 := NULL
149 ,p_budget_version_id IN pa_budget_versions.budget_version_id%TYPE
150 := NULL)
151 IS
152
153 /* Local Variables */
154
155 /* Error handling local variables */
156 l_msg_count number := 0;
157 l_data VARCHAR2(2000);
158 l_msg_data VARCHAR2(2000);
159 l_err_code VARCHAR2(2000);
160 l_msg_index_out NUMBER(20);
161 l_return_status VARCHAR2(2000);
162 l_budget_version_in_error NUMBER(5) := 0;
163
164 l_row_id ROWID;
165
166 l_err_stage varchar2(240);
167 l_err_stack varchar2(240);
168 l_debug_mode varchar2(30) := 'Y';
169 l_bg_org varchar2(25);
170
171 l_records_affected number(20);
172 l_fe_ctr number(20);
173 l_fe_new_seq number(20);
174 l_fl_ctr number(20);
175 l_fl_new_seq number(20);
176 l_string_length number(20);
177 l_stage number := 100;
178 l_budget_ctr number;
179 l_active_organization number;
180 l_request_id number;
181
182 l_fcst_start_date date;
183 l_fcst_end_date date;
184 l_ppp_start_date date;
185 l_ppp_end_date date;
186
187 l_project_action_allowed varchar2(1);
188
189 l_proj_fp_options_id pa_proj_fp_options.proj_fp_options_id%TYPE;
190 l_time_phased_code pa_proj_fp_options.all_time_phased_code%TYPE;
191 l_fin_plan_amount_set_id pa_fin_plan_amount_sets.fin_plan_amount_set_id%TYPE;
192 l_budget_version_id pa_budget_versions.budget_version_id%TYPE;
193 l_period_profile_id pa_budget_versions.period_profile_id%TYPE;
194 l_resource_list_id pa_budget_versions.resource_list_id%TYPE;
195 l_bv_rec_ver_num pa_budget_versions.record_version_number%TYPE;
196 l_bv_version_number pa_budget_versions.version_number%TYPE;
197 l_bv_version_name pa_budget_versions.version_name%TYPE;
198 l_pfi_txn_project_id pa_budget_versions.project_id%TYPE;
199 l_fin_plan_type_id pa_budget_versions.fin_plan_type_id%TYPE;
200 l_current_working_flag pa_budget_versions.current_working_flag%TYPE;
201 l_org_fcst_period_type pa_forecasting_options_all.org_fcst_period_type%TYPE;
202 l_org_proj_template_id pa_forecasting_options_all.org_fcst_project_template_id%TYPE;
203 l_number_of_periods pa_forecasting_options_all.number_of_periods%TYPE;
204 l_weighted_or_full_code pa_forecasting_options_all.weighted_or_full_code%TYPE;
205 l_org_id pa_implementations_all.org_id%TYPE;
206 l_pfi_project_org_id pa_implementations_all.org_id%TYPE;
207 l_pfi_exp_org_id pa_implementations_all.org_id%TYPE;
208 l_pa_period_type pa_implementations_all.pa_period_type%TYPE;
209 l_period_set_name pa_implementations_all.period_set_name%TYPE;
210 l_org_structure_version_id pa_implementations_all.org_structure_version_id%TYPE;
211 l_task_organization_id hr_organization_units.organization_id%TYPE;
212 l_organization_id hr_organization_units.organization_id%TYPE;
213 l_business_group_id hr_organization_units.business_group_id%TYPE;
214 l_org_name hr_organization_units.name%TYPE;
215 l_org_location_id hr_organization_units.location_id%TYPE;
216 l_pfi_organization_id hr_organization_units.organization_id%TYPE;
217 l_pfi_project_organization_id hr_organization_units.organization_id%TYPE;
218 l_pfi_exp_organization_id hr_organization_units.organization_id%TYPE;
219 l_project_id pa_projects_all.project_id%TYPE;
220 l_project_name pa_projects_all.name%TYPE;
221 l_project_number pa_projects_all.segment1%TYPE;
222 l_new_project_number pa_projects_all.segment1%TYPE;
223 l_org_projfunc_currency_code pa_projects_all.projfunc_currency_code%TYPE;
224 l_own_task_id pa_tasks.task_id%TYPE;
225 l_prob_percent pa_probability_members.probability_percentage%TYPE;
226 l_period_profile_type pa_proj_period_profiles.period_profile_type%TYPE;
227 l_pfi_assignment_id pa_forecast_items.assignment_id%TYPE;
228 l_pfi_resource_id pa_forecast_items.resource_id%TYPE;
229 l_own_resource_assignment_id pa_resource_assignments.resource_assignment_id%TYPE;
230 l_proj_resource_assignment_id pa_resource_assignments.resource_assignment_id%TYPE;
231 l_resource_list_member_id pa_resource_assignments.resource_list_member_id%TYPE;
232 l_prv_forecast_element_id pa_org_fcst_elements.forecast_element_id%TYPE;
233 l_utl_hours pa_budget_lines.utilization_hours%TYPE;
234 l_utl_capacity pa_budget_lines.capacity%TYPE;
235 l_set_of_books_id gl_sets_of_books.set_of_books_id%TYPE;
236 l_act_period_type gl_periods.period_type%TYPE;
237
238
239 CURSOR fl_lines_task IS
240 SELECT
241 fl.budget_version_id /* FPB2: budget_version_id */
242 ,l_own_resource_assignment_id
243 ,fl.period_name
244 ,fl.start_date
245 ,fl.end_date
246 ,nvl(sum(fl.quantity),0)
247 ,nvl(sum(fl.raw_cost),0)
248 ,nvl(sum(fl.burdened_cost),0)
249 ,nvl(sum(fl.revenue),0)
250 ,nvl(sum(fl.borrowed_revenue),0)
251 ,nvl(sum(fl.tp_revenue_in),0)
252 ,nvl(sum(fl.tp_revenue_out),0)
253 ,nvl(sum(fl.lent_resource_cost),0)
254 ,nvl(sum(fl.tp_cost_in),0)
255 ,nvl(sum(fl.tp_cost_out),0)
256 ,nvl(sum(fl.unassigned_time_cost),0)
257 FROM pa_org_forecast_lines fl
258 WHERE fl.budget_version_id = l_budget_version_id
259 AND fl.project_id = l_project_id
260 AND fl.task_id = l_own_task_id
261 GROUP BY fl.period_name
262 ,fl.start_date
263 ,fl.end_date
264 ,fl.budget_version_id; /* FPB2 */
265
266 /* Bug 3106741 for performance improvement budget_version_id join has been added */
267
268 CURSOR bl_lines_project IS
269 SELECT
270 bl.budget_version_id /* FPB2: budget_version_id */
271 ,l_proj_resource_assignment_id
272 ,bl.period_name
273 ,bl.start_date
274 ,bl.end_date
275 ,nvl(sum(bl.quantity),0)
276 ,nvl(sum(bl.raw_cost),0)
277 ,nvl(sum(bl.burdened_cost),0)
278 ,nvl(sum(bl.revenue),0)
279 ,nvl(sum(bl.borrowed_revenue),0)
280 ,nvl(sum(bl.tp_revenue_in),0)
281 ,nvl(sum(bl.tp_revenue_out),0)
282 ,nvl(sum(bl.lent_resource_cost),0)
283 ,nvl(sum(bl.tp_cost_in),0)
284 ,nvl(sum(bl.tp_cost_out),0)
285 ,nvl(sum(bl.unassigned_time_cost),0)
286 ,nvl(sum(bl.utilization_percent),0)
287 ,nvl(sum(bl.utilization_hours),0)
288 ,nvl(sum(bl.capacity),0)
289 ,nvl(sum(bl.head_count),0)
290 FROM pa_budget_lines bl
291 ,pa_resource_assignments ra
292 WHERE bl.resource_assignment_id = ra.resource_assignment_id
293 AND bl.budget_version_id = ra.budget_version_id
294 AND ra.budget_version_id = l_budget_version_id
295 AND ra.task_id <> 0
296 AND bl.budget_version_id = l_budget_version_id /* bug 3106741 */
297 GROUP BY bl.period_name
298 ,bl.start_date
299 ,bl.end_date
300 ,bl.budget_version_id; /* FPB2 */
301
302 /* Only one can be passed at any given time -- that is if p_organization_id
303 is passed then p_starting_organization_id will be null and vice-a-versa
304 One of them is mandatory from the form, that is both cannot be passed as
305 null. p_budget_version_id will only be passed from the OA pages */
306
307 CURSOR org_hierarchy is
308 SELECT child_organization_id
309 FROM pa_org_hierarchy_denorm
310 WHERE pa_org_use_type = 'REPORTING'
311 and parent_organization_id = p_starting_organization_id
312 and org_id = l_org_id
313 and org_hierarchy_version_id = l_org_structure_version_id
314 order by
315 parent_level DESC
316 ,child_level DESC
317 ,child_organization_id;
318
319 /*
320 SELECT se.organization_id_child org_id
321 FROM per_org_structure_elements se
322 WHERE se.org_structure_version_id = l_org_structure_version_id
323 CONNECT BY PRIOR se.organization_id_child = se.organization_id_parent
324 AND se.org_structure_version_id = l_org_structure_version_id
325 START WITH se.organization_id_parent = p_starting_organization_id
326 AND se.org_structure_version_id = l_org_structure_version_id
327 UNION
328 SELECT p_starting_organization_id FROM DUAL;
329 */
330
331 CURSOR specific_org_only is
332 SELECT hou.organization_id
333 ,houtl.name
334 ,hou.business_group_id
335 ,hou.location_id
336 FROM hr_all_organization_units hou,
337 hr_all_organization_units_tl houtl
338 WHERE hou.organization_id = p_organization_id
339 AND houtl.organization_id = hou.organization_id
340 AND houtl.language = USERENV('LANG');
341
342 CURSOR sub_orgs IS
343 SELECT pa.child_organization_id
344 FROM pa_org_hierarchy_denorm pa
345 WHERE pa.pa_org_use_type = 'REPORTING'
346 AND pa.parent_level-pa.child_level < 1
347 AND nvl(pa.org_id,-99) = l_org_id
348 AND pa.org_hierarchy_version_id = l_org_structure_version_id
349 AND pa.parent_organization_id = l_organization_id
350 ORDER BY parent_level desc,
351 parent_organization_id,
352 child_level desc,
353 child_organization_id;
354
355 CURSOR sub_tasks IS
356 SELECT carrying_out_organization_id,
357 task_id
358 FROM pa_tasks
359 WHERE project_id = l_project_id;
360
361 /* Transfer Price Logic as part of Select statement:
362
363 Org Context TP Amount Type CC In CC Out Rev In Rev Out
364 ----------- ---------------- ----- ------ ------ -------
365 Provider COST_TRANSFER 0 Y 0 0
366 Provider REVENUE_TRANSFER 0 0 Y 0
367 Receiver COST_TRANSFER Y 0 0 0
368 Receiver REVENUE_TRANSFER 0 0 0 Y
369 */
370
371 CURSOR forecast_items IS
372 SELECT
373 l_organization_id,
374 pfi.project_organization_id,
375 pfi.project_org_id,
376 pfi.expenditure_organization_id,
377 pfi.expenditure_org_id,
378 pfi.project_id txn_project_id,
379 nvl(pfi.assignment_id,-1),
380 nvl(pfi.resource_id,-1),
381 gp.period_name,
382 gp.start_date,
383 gp.end_date,
384 nvl(sum(pfi.item_quantity),0),
385 DECODE(pfi.forecast_item_type,'U',0,
386 DECODE(pfi.expenditure_organization_id,pfi.project_organization_id,
387 DECODE(pfi.expenditure_organization_id,l_organization_id,
388 DECODE(pfi.expenditure_org_id,l_org_id,
389 NVL(SUM(pfi.expfunc_raw_cost),0),0),0),0)) raw_cost,
390 DECODE(pfi.forecast_item_type,'U',0,
391 DECODE(pfi.expenditure_organization_id, pfi.project_organization_id,
392 DECODE(pfi.expenditure_organization_id,l_organization_id,
393 DECODE(pfi.expenditure_org_id,l_org_id,
394 NVL(SUM(pfi.expfunc_burdened_cost),0),0),0),0)) burdened_cost,
395 DECODE(pfi.forecast_item_type,'U',0,
396 DECODE(pfi.expenditure_organization_id,pfi.project_organization_id,
397 DECODE(pfi.expenditure_org_id,l_org_id,0,
398 DECODE(pfi.expenditure_organization_id,l_organization_id,
399 NVL(SUM(pfi.expfunc_burdened_cost),0),0)),
400 DECODE(pfi.expenditure_organization_id,l_organization_id,
401 DECODE(pfi.expenditure_org_id,l_org_id,
402 NVL(SUM(pfi.expfunc_burdened_cost),0),0),0))) lent_resource_cost,
403 DECODE(pfi.forecast_item_type,'U',
404 DECODE(pfi.expenditure_organization_id,l_organization_id,
405 DECODE(pfi.expenditure_org_id,l_org_id,
406 NVL(SUM(pfi.expfunc_burdened_cost),0),0),0),0) unassigned_time_cost,
407 DECODE(pfi.project_organization_id,l_organization_id,
408 DECODE(pfi.project_org_id,l_org_id,
409 DECODE(pfi.tp_amount_type,'COST_TRANSFER',
410 NVL(SUM(pfi.projfunc_transfer_price),0),0),0),0) tp_cost_in,
411 DECODE(pfi.expenditure_organization_id,l_organization_id,
412 DECODE(pfi.expenditure_org_id,l_org_id,
413 DECODE(pfi.tp_amount_type,'COST_TRANSFER',
414 NVL(SUM(pfi.expfunc_transfer_price),0),0),0),0) tp_cost_out,
415 DECODE(pfi.project_organization_id,pfi.expenditure_organization_id,
416 DECODE(pfi.project_organization_id,l_organization_id,
417 DECODE(pfi.project_org_id,l_org_id,
418 NVL(SUM(pfi.projfunc_revenue),0),0),0),0) revenue,
419 DECODE(pfi.project_organization_id,pfi.expenditure_organization_id,
420 DECODE(pfi.project_org_id,l_org_id,0,
421 DECODE(pfi.project_organization_id,l_organization_id,
422 NVL(SUM(pfi.projfunc_revenue),0),0)),
423 DECODE(pfi.project_organization_id,l_organization_id,
424 DECODE(pfi.project_org_id,l_org_id,
425 NVL(SUM(pfi.projfunc_revenue),0),0),0)) borrowed_revenue,
426 DECODE(pfi.expenditure_organization_id,l_organization_id,
427 DECODE(pfi.expenditure_org_id,l_org_id,
428 DECODE(pfi.tp_amount_type,'REVENUE_TRANSFER',
429 NVL(SUM(pfi.expfunc_transfer_price),0),0),0),0) tp_rev_in,
430 DECODE(pfi.project_organization_id,l_organization_id,
431 DECODE(pfi.project_org_id,l_org_id,
432 DECODE(pfi.tp_amount_type,'REVENUE_TRANSFER',
433 NVL(sum(pfi.projfunc_transfer_price),0),0),0),0) tp_rev_out
434 FROM pa_forecast_items pfi,
435 gl_date_period_map dpm,
436 gl_periods gp
437 WHERE pfi.project_organization_id = l_organization_id
438 and nvl(pfi.project_org_id,-99) = l_org_id
439 AND pfi.forecast_item_type in ('A','R','U')
440 AND pfi.delete_flag = 'N'
441 AND pfi.error_flag = 'N'
442 AND pfi.item_date BETWEEN l_fcst_start_date
443 AND l_fcst_end_date
444 AND pfi.forecast_amt_calc_flag||'' = 'Y'
445 AND dpm.period_set_name = l_period_set_name
446 AND dpm.period_type = l_act_period_type
447 AND pfi.item_date = dpm.accounting_date
448 AND dpm.period_set_name = gp.period_set_name
449 AND dpm.period_type = gp.period_type
450 AND dpm.period_name = gp.period_name
451 AND gp.adjustment_period_flag = 'N'
452 GROUP BY pfi.project_organization_id,
453 pfi.project_org_id,
454 pfi.expenditure_organization_id,
455 pfi.expenditure_org_id,
456 pfi.project_id,
457 nvl(pfi.assignment_id,-1),
458 nvl(pfi.resource_id,-1),
459 pfi.tp_amount_type,
460 pfi.forecast_item_type,
461 gp.start_date,
462 gp.end_date,
463 gp.period_name
464 UNION ALL -- bug 3106741 changed union to uinon all for performance benefit
465 SELECT
466 l_organization_id,
467 pfi.project_organization_id,
468 pfi.project_org_id,
469 pfi.expenditure_organization_id,
470 pfi.expenditure_org_id,
471 pfi.project_id txn_project_id,
472 nvl(pfi.assignment_id,-1),
473 nvl(pfi.resource_id,-1),
474 gp.period_name,
475 gp.start_date,
476 gp.end_date,
477 nvl(sum(pfi.item_quantity),0),
478 DECODE(pfi.forecast_item_type,'U',0,
479 DECODE(pfi.expenditure_organization_id,pfi.project_organization_id,
480 DECODE(pfi.expenditure_organization_id,l_organization_id,
481 DECODE(pfi.expenditure_org_id,l_org_id,
482 NVL(SUM(pfi.expfunc_raw_cost),0),0),0),0)) raw_cost,
483 DECODE(pfi.forecast_item_type,'U',0,
484 DECODE(pfi.expenditure_organization_id, pfi.project_organization_id,
485 DECODE(pfi.expenditure_organization_id,l_organization_id,
486 DECODE(pfi.expenditure_org_id,l_org_id,
487 NVL(SUM(pfi.expfunc_burdened_cost),0),0),0),0)) burdened_cost,
488 DECODE(pfi.forecast_item_type,'U',0,
489 DECODE(pfi.expenditure_organization_id,pfi.project_organization_id,
490 DECODE(pfi.expenditure_org_id,l_org_id,0,
491 DECODE(pfi.expenditure_organization_id,l_organization_id,
492 NVL(SUM(pfi.expfunc_burdened_cost),0),0)),
493 DECODE(pfi.expenditure_organization_id,l_organization_id,
494 DECODE(pfi.expenditure_org_id,l_org_id,
495 NVL(SUM(pfi.expfunc_burdened_cost),0),0),0))) lent_resource_cost,
496 DECODE(pfi.forecast_item_type,'U',
497 DECODE(pfi.expenditure_organization_id,l_organization_id,
498 DECODE(pfi.expenditure_org_id,l_org_id,
499 NVL(SUM(pfi.expfunc_burdened_cost),0),0),0),0) unassigned_time_cost,
500 DECODE(pfi.project_organization_id,l_organization_id,
501 DECODE(pfi.project_org_id,l_org_id,
502 DECODE(pfi.tp_amount_type,'COST_TRANSFER',
503 NVL(SUM(pfi.projfunc_transfer_price),0),0),0),0) tp_cost_in,
504 DECODE(pfi.expenditure_organization_id,l_organization_id,
505 DECODE(pfi.expenditure_org_id,l_org_id,
506 DECODE(pfi.tp_amount_type,'COST_TRANSFER',
507 NVL(SUM(pfi.expfunc_transfer_price),0),0),0),0) tp_cost_out,
508 DECODE(pfi.project_organization_id,pfi.expenditure_organization_id,
509 DECODE(pfi.project_organization_id,l_organization_id,
510 DECODE(pfi.project_org_id,l_org_id,
511 NVL(SUM(pfi.projfunc_revenue),0),0),0),0) revenue,
512 DECODE(pfi.project_organization_id,pfi.expenditure_organization_id,
513 DECODE(pfi.project_org_id,l_org_id,0,
514 DECODE(pfi.project_organization_id,l_organization_id,
515 NVL(SUM(pfi.projfunc_revenue),0),0)),
516 DECODE(pfi.project_organization_id,l_organization_id,
517 DECODE(pfi.project_org_id,l_org_id,
518 NVL(SUM(pfi.projfunc_revenue),0),0),0)) borrowed_revenue,
519 DECODE(pfi.expenditure_organization_id,l_organization_id,
520 DECODE(pfi.expenditure_org_id,l_org_id,
521 DECODE(pfi.tp_amount_type,'REVENUE_TRANSFER',
522 NVL(SUM(pfi.expfunc_transfer_price),0),0),0),0) tp_rev_in,
523 DECODE(pfi.project_organization_id,l_organization_id,
524 DECODE(pfi.project_org_id,l_org_id,
525 DECODE(pfi.tp_amount_type,'REVENUE_TRANSFER',
526 NVL(sum(pfi.projfunc_transfer_price),0),0),0),0) tp_rev_out
527 FROM pa_forecast_items pfi,
528 gl_date_period_map dpm,
529 gl_periods gp
530 WHERE pfi.expenditure_organization_id = l_organization_id
531 and nvl(pfi.expenditure_org_id,-99) = l_org_id
532 AND pfi.forecast_item_type in ('A','R','U')
533 AND pfi.delete_flag = 'N'
534 AND pfi.error_flag = 'N'
535 AND pfi.item_date BETWEEN l_fcst_start_date
536 AND l_fcst_end_date
537 AND pfi.forecast_amt_calc_flag||'' = 'Y'
538 AND dpm.period_set_name = l_period_set_name
539 AND dpm.period_type = l_act_period_type
540 AND pfi.item_date = dpm.accounting_date
541 AND dpm.period_set_name = gp.period_set_name
542 AND dpm.period_type = gp.period_type
543 AND dpm.period_name = gp.period_name
544 AND gp.adjustment_period_flag = 'N'
545 GROUP BY pfi.project_organization_id,
546 pfi.project_org_id,
547 pfi.expenditure_organization_id,
548 pfi.expenditure_org_id,
549 pfi.project_id,
550 nvl(pfi.assignment_id,-1),
551 nvl(pfi.resource_id,-1),
552 pfi.tp_amount_type,
553 pfi.forecast_item_type,
554 gp.start_date,
555 gp.end_date,
556 gp.period_name
557 ORDER BY 1,6,7,8,10,11,2,3,4,5;
558
559 /* Record Definitions */
560 amt_rec pa_plan_matrix.amount_type_tabtyp;
561 budget_lines_rec budget_lines_record_table_type;
562
563 /* PLSQL Table Declarations */
564
565 /* Forecast Item PL/SQL tables */
566 l_fi_organization_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
567 l_fi_proj_organization_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
568 l_fi_proj_orgid_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
569 l_fi_exp_organization_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
570 l_fi_exp_orgid_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
571 l_fi_txn_project_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
572 l_fi_assignment_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
573 l_fi_resource_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
574
575 l_fi_period_name_tab pa_fp_org_fcst_gen_pub.char240_data_type_table;
576 l_fi_start_date_tab pa_fp_org_fcst_gen_pub.date_data_type_table;
577 l_fi_end_date_tab pa_fp_org_fcst_gen_pub.date_data_type_table;
578 l_fi_item_quantity_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
579 l_fi_raw_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
580 l_fi_burdened_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
581 l_fi_tp_cost_in_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
582 l_fi_tp_cost_out_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
583 l_fi_revenue_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
584 l_fi_tp_rev_in_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
585 l_fi_tp_rev_out_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
586 l_fi_borrowed_revenue_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
587 l_fi_lent_resource_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
588 l_fi_unassigned_time_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
589
590 /* Forecast Element PL/SQL Tables */
591 l_fe_forecast_element_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
592 l_fe_organization_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
593 l_fe_org_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
594 l_fe_budget_version_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
595 l_fe_project_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
596 l_fe_task_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
597 l_fe_pvdr_rcvr_code_tab pa_fp_org_fcst_gen_pub.char240_data_type_table;
598 l_fe_other_organization_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
599 l_fe_other_org_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
600 l_fe_txn_project_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
601 l_fe_assignment_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
602 l_fe_resource_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
603
604 /* Forecast Lines PL/SQL Tables */
605 l_fl_forecast_line_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
606 l_fl_forecast_element_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
607 l_fl_budget_version_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
608 l_fl_project_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
609 l_fl_task_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
610 l_fl_period_name_tab pa_fp_org_fcst_gen_pub.char240_data_type_table;
611 l_fl_start_date_tab pa_fp_org_fcst_gen_pub.date_data_type_table;
612 l_fl_end_date_tab pa_fp_org_fcst_gen_pub.date_data_type_table;
613 l_fl_quantity_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
614 l_fl_raw_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
615 l_fl_burdened_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
616 l_fl_tp_cost_in_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
617 l_fl_tp_cost_out_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
618 l_fl_revenue_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
619 l_fl_tp_rev_in_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
620 l_fl_tp_rev_out_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
621 l_fl_borrowed_revenue_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
622 l_fl_lent_resource_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
623 l_fl_unassigned_time_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
624
625 /* Budget Lines PL/SQL Tables */
626 l_bl_budget_version_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table; /* FPB2: budget_version_id */
627
628 l_bl_res_asg_id_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
629 l_bl_start_date_tab pa_fp_org_fcst_gen_pub.date_data_type_table;
630 l_bl_end_date_tab pa_fp_org_fcst_gen_pub.date_data_type_table;
631 l_bl_period_name_tab pa_fp_org_fcst_gen_pub.char240_data_type_table;
632 l_bl_quantity_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
633 l_bl_raw_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
634 l_bl_burdened_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
635 l_bl_revenue_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
636 l_bl_borrowed_revenue_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
637 l_bl_tp_revenue_in_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
638 l_bl_tp_revenue_out_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
639 l_bl_lent_resource_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
640 l_bl_tp_cost_in_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
641 l_bl_tp_cost_out_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
642 l_bl_unassigned_time_cost_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
643 l_bl_utilization_percent_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
644 l_bl_utilization_hours_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
645 l_bl_capacity_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
646 l_bl_head_count_tab pa_fp_org_fcst_gen_pub.number_data_type_table;
647
648 BEGIN
649
650 IF P_PA_DEBUG_MODE = 'Y' THEN
651 pa_debug.init_err_stack('PA_FP_ORG_FCST_GEN_PUB.gen_org_fcst');
652 END IF;
653
654 --fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
655 l_debug_mode := NVL(l_debug_mode, 'Y');
656
657 IF P_PA_DEBUG_MODE = 'Y' THEN
658 pa_debug.set_process('gen_org_fcst: ' || 'PLSQL','LOG',l_debug_mode);
659 END IF;
660
661 l_stage := 100;
662 -- hr_utility.trace(to_char(l_stage));
663
664 -- get information from pa_forecast_options_all
665 pa_fp_org_fcst_utils.get_forecast_option_details
666 ( x_fcst_period_type => l_org_fcst_period_type
667 ,x_period_set_name => l_period_set_name
668 ,x_act_period_type => l_act_period_type
669 ,x_org_projfunc_currency_code => l_org_projfunc_currency_code
670 ,x_number_of_periods => l_number_of_periods
671 ,x_weighted_or_full_code => l_weighted_or_full_code
672 ,x_org_proj_template_id => l_org_proj_template_id
673 ,x_org_structure_version_id => l_org_structure_version_id
674 ,x_fcst_start_date => l_fcst_start_date
675 ,x_fcst_end_date => l_fcst_end_date
676 ,x_org_id => l_org_id
677 ,x_return_status => l_return_status
678 ,x_err_code => l_err_code);
679
680 pa_debug.g_err_stage := l_stage||': Forecast Options Data: ';
681 IF P_PA_DEBUG_MODE = 'Y' THEN
682 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
683 END IF;
684 pa_debug.g_err_stage := 'l_org_fcst_period_type ['||l_org_fcst_period_type||']';
685 IF P_PA_DEBUG_MODE = 'Y' THEN
686 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
687 END IF;
688 pa_debug.g_err_stage := 'l_period_set_name ['||l_period_set_name||']';
689 IF P_PA_DEBUG_MODE = 'Y' THEN
690 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
691 END IF;
692 pa_debug.g_err_stage := 'l_act_period_type ['||l_act_period_type||']';
693 IF P_PA_DEBUG_MODE = 'Y' THEN
694 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
695 END IF;
696 pa_debug.g_err_stage := 'l_org_projfunc_currency_code ['||l_org_projfunc_currency_code||']';
697 IF P_PA_DEBUG_MODE = 'Y' THEN
698 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
699 END IF;
700 pa_debug.g_err_stage := 'l_number_of_periods ['||l_number_of_periods||']';
701 IF P_PA_DEBUG_MODE = 'Y' THEN
702 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
703 END IF;
704 pa_debug.g_err_stage := 'l_weighted_or_full_code ['||l_weighted_or_full_code||']';
705 IF P_PA_DEBUG_MODE = 'Y' THEN
706 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
707 END IF;
708 pa_debug.g_err_stage := 'l_org_proj_template_id ['||l_org_proj_template_id||']';
709 IF P_PA_DEBUG_MODE = 'Y' THEN
710 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
711 END IF;
712 pa_debug.g_err_stage := 'l_org_structure_version_id ['||l_org_structure_version_id||']';
713 IF P_PA_DEBUG_MODE = 'Y' THEN
714 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
715 END IF;
716 pa_debug.g_err_stage := 'l_fcst_start_date ['||l_fcst_start_date||']';
717 IF P_PA_DEBUG_MODE = 'Y' THEN
718 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
719 END IF;
720 pa_debug.g_err_stage := 'l_fcst_end_date ['||l_fcst_end_date||']';
721 IF P_PA_DEBUG_MODE = 'Y' THEN
722 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
723 END IF;
724 pa_debug.g_err_stage := 'l_org_id ['||l_org_id||']';
725 IF P_PA_DEBUG_MODE = 'Y' THEN
726 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
727 END IF;
728
729 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
730 THEN
731 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
732 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
733 ': Error occured while Getting forecast Options Det [' ||
734 l_err_code|| ']';
735 IF P_PA_DEBUG_MODE = 'Y' THEN
736 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
737 END IF;
738 retcode := FND_API.G_RET_STS_ERROR;
739 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
740 p_msg_name => 'PA_FP_FCST_OPTION_ERR');
741 END IF;
742 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
743 END IF;
744
745
746 /* Get resource list information */
747 BEGIN
748 l_stage := 200;
749 pa_debug.g_err_stage := l_stage||': Get resource list information';
750 IF P_PA_DEBUG_MODE = 'Y' THEN
751 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
752 END IF;
753 -- hr_utility.trace(to_char(l_stage));
754
755 l_resource_list_id := FND_PROFILE.VALUE('PA_FORECAST_RESOURCE_LIST');
756
757 SELECT rlm.resource_list_member_id
758 INTO l_resource_list_member_id
759 FROM pa_resource_list_members rlm
760 WHERE rlm.resource_list_id = l_resource_list_id
761 AND rlm.resource_type_code = 'UNCATEGORIZED';
762 EXCEPTION
763 WHEN OTHERS THEN
764 -- hr_utility.trace(to_char(l_stage)||'-'||SQLERRM);
765 pa_debug.g_err_stage := TO_CHAR(l_stage)||'-'||SQLERRM;
766 IF P_PA_DEBUG_MODE = 'Y' THEN
767 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
768 END IF;
769 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
770 END;
771
772 BEGIN
773 l_stage := 300;
774 pa_debug.g_err_stage := l_stage||': Get Time Phased Code';
775 IF P_PA_DEBUG_MODE = 'Y' THEN
776 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
777 END IF;
778 -- hr_utility.trace(to_char(l_stage));
779
780 SELECT substr(l_org_fcst_period_type,1,1)
781 INTO l_time_phased_code
782 FROM sys.dual;
783
784 l_stage := 400;
785 pa_debug.g_err_stage := l_stage||': Get Plan Type Id';
786 IF P_PA_DEBUG_MODE = 'Y' THEN
787 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
788 END IF;
789 -- hr_utility.trace(to_char(l_stage));
790
791 SELECT fin_plan_type_id
792 INTO l_fin_plan_type_id
793 FROM pa_fin_plan_types_b
794 WHERE fin_plan_type_code = 'ORG_FORECAST';
795
796 l_stage := 500;
797 pa_debug.g_err_stage := l_stage||': Get Amount Set Id';
798 IF P_PA_DEBUG_MODE = 'Y' THEN
799 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
800 END IF;
801 -- hr_utility.trace(to_char(l_stage));
802
803 SELECT fin_plan_amount_set_id
804 INTO l_fin_plan_amount_set_id
805 FROM pa_fin_plan_amount_sets
806 WHERE amount_set_type_code = 'ALL'
807 AND fin_plan_amount_set_id = 1; /* Fix for 2744924. */
808
809 l_stage := 600;
810 pa_debug.g_err_stage := l_stage||': Derive BV Name';
811 IF P_PA_DEBUG_MODE = 'Y' THEN
812 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
813 END IF;
814 -- hr_utility.trace(to_char(l_stage));
815
816 SELECT meaning
817 INTO l_bv_version_name
818 FROM pa_lookups
819 WHERE lookup_type = 'TRANSLATION'
820 AND lookup_code = 'AUTO_GEN_PLAN_VERSION';
821
822 EXCEPTION
823 WHEN OTHERS THEN
824 -- hr_utility.trace(to_char(l_stage)||'-'||SQLERRM);
825 pa_debug.g_err_stage := TO_CHAR(l_stage)||'-'||SQLERRM;
826 IF P_PA_DEBUG_MODE = 'Y' THEN
827 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
828 END IF;
829 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
830 END;
831
832 BEGIN
833 IF p_budget_version_id IS NULL THEN
834 l_stage := 700;
835 pa_debug.g_err_stage := l_stage||': BudgetVersionId is NULL';
836 IF P_PA_DEBUG_MODE = 'Y' THEN
837 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
838 END IF;
839 -- hr_utility.trace(to_char(l_stage));
840 IF p_starting_organization_id IS NULL THEN
841 l_stage := 800;
842 pa_debug.g_err_stage := l_stage||': Start Org is NULL';
843 IF P_PA_DEBUG_MODE = 'Y' THEN
844 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
845 END IF;
846 -- hr_utility.trace(to_char(l_stage));
847 OPEN specific_org_only;
848 ELSE
849 l_stage := 900;
850 pa_debug.g_err_stage := l_stage||': Start Org is Not NULL';
851 IF P_PA_DEBUG_MODE = 'Y' THEN
852 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
853 END IF;
854 -- hr_utility.trace(to_char(l_stage));
855 OPEN org_hierarchy;
856 END IF;
857 END IF;
858
859 EXCEPTION
860 WHEN OTHERS THEN
861 -- hr_utility.trace(to_char(l_stage)||'-'||SQLERRM);
862 pa_debug.g_err_stage := TO_CHAR(l_stage)||'-'||SQLERRM;
863 IF P_PA_DEBUG_MODE = 'Y' THEN
864 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
865 END IF;
866 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
867 END;
868
869 l_budget_ctr := 0; /* This is required to let the loop run
870 only once if budget version id is passed*/
871 LOOP
872 BEGIN
873 IF l_budget_ctr = 1 THEN
874 IF P_PA_DEBUG_MODE = 'Y' THEN
875 pa_debug.write_file('gen_org_fcst: ' || 'Exiting as Budget Version Process has failed');
876 END IF;
877 EXIT;
878 END IF;
879 savepoint org_project;
880 IF p_budget_version_id IS NULL THEN
881 l_stage := 1000;
882 -- hr_utility.trace(to_char(l_stage));
883 IF p_starting_organization_id IS NULL THEN
884 l_stage := 1100;
885 pa_debug.g_err_stage := l_stage||': Fetching from specific_org_only';
886 IF P_PA_DEBUG_MODE = 'Y' THEN
887 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
888 END IF;
889 -- hr_utility.trace(to_char(l_stage));
890 FETCH specific_org_only
891 INTO l_organization_id
892 ,l_org_name
893 ,l_business_group_id
894 ,l_org_location_id;
895
896 IF specific_org_only%NOTFOUND THEN
897 pa_debug.g_err_stage := l_stage||': Exiting from specific_org_only FETCH';
898 IF P_PA_DEBUG_MODE = 'Y' THEN
899 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
900 END IF;
901 EXIT;
902 END IF;
903 l_stage := 1200;
904 -- hr_utility.trace(to_char(l_stage));
905
906 IF l_org_location_id IS NULL THEN
907 l_stage := 1300;
908 -- hr_utility.trace(to_char(l_stage));
909 pa_debug.g_err_stage := l_stage||': Organization Id ['
910 ||l_organization_id||
911 '] has no location';
912 IF P_PA_DEBUG_MODE = 'Y' THEN
913 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
914 END IF;
915 rollback to org_project;
916 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
917 END IF;
918
919 l_stage := 1400;
920
921 BEGIN
922 SELECT 1
923 INTO l_active_organization
924 FROM pa_organizations_project_v
925 WHERE organization_id = l_organization_id
926 AND active_flag = 'Y'
927 AND TRUNC(SYSDATE) BETWEEN TRUNC(date_from)
928 AND NVL(date_to, TRUNC(SYSDATE));
929 EXCEPTION WHEN NO_DATA_FOUND THEN
930 -- hr_utility.trace(to_char(l_stage)||'-'||SQLERRM);
931 pa_debug.g_err_stage := l_stage||': Organization Id ['
932 ||l_organization_id||
933 '] is Not Active';
934 IF P_PA_DEBUG_MODE = 'Y' THEN
935 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
936 END IF;
937 rollback to org_project;
938 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
939 END;
940 ELSE
941 l_stage := 1500;
942 pa_debug.g_err_stage := l_stage||': Fetching from org_hierarchy';
943 IF P_PA_DEBUG_MODE = 'Y' THEN
944 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
945 END IF;
946 -- hr_utility.trace(to_char(l_stage));
947 FETCH org_hierarchy
948 INTO l_organization_id;
949 IF org_hierarchy%NOTFOUND THEN
950 pa_debug.g_err_stage := l_stage||': Exiting from org_hierarchy FETCH';
951 IF P_PA_DEBUG_MODE = 'Y' THEN
952 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
953 END IF;
954 EXIT;
955 END IF;
956 l_stage := 1600;
957 -- hr_utility.trace(to_char(l_stage));
958
959 BEGIN
960 SELECT 1
961 INTO l_active_organization
962 FROM pa_organizations_project_v
963 WHERE organization_id = l_organization_id
964 AND active_flag = 'Y'
965 AND TRUNC(SYSDATE) BETWEEN TRUNC(date_from)
966 AND NVL(date_to, TRUNC(SYSDATE));
967 EXCEPTION WHEN NO_DATA_FOUND THEN
968 -- hr_utility.trace(to_char(l_stage)||'-'||SQLERRM);
969 pa_debug.g_err_stage := l_stage||': Organization Id ['
970 ||l_organization_id||
971 '] is Not Active';
972 IF P_PA_DEBUG_MODE = 'Y' THEN
973 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
974 END IF;
975 rollback to org_project;
976 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
977 END;
978
979 l_stage := 1700;
980 -- hr_utility.trace(to_char(l_stage));
981
982 SELECT hou.name
983 ,hou.business_group_id
984 ,hou.location_id
985 INTO l_org_name
986 ,l_business_group_id
987 ,l_org_location_id
988 FROM hr_all_organization_units hou
989 WHERE hou.organization_id = l_organization_id;
990
991 IF l_org_location_id IS NULL THEN
992 pa_debug.g_err_stage := l_stage||': Organization Id ['
993 ||l_organization_id||
994 '] has no location';
995 IF P_PA_DEBUG_MODE = 'Y' THEN
996 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
997 END IF;
998 rollback to org_project;
999 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1000 END IF;
1001 END IF;
1002
1003 SELECT '-'||decode(substr(to_char(l_org_id),1,1),'-',
1004 substr(to_char(l_org_id),2),to_char(l_org_id))||
1005 '-'||to_char(l_business_group_id)
1006 INTO l_bg_org
1007 FROM sys.dual;
1008
1009 l_stage := 1800;
1010 -- hr_utility.trace(to_char(l_stage));
1011
1012 -- Bug 7309811 - Use byte equivalent versions of substr and length functions
1013 SELECT substrb(l_org_name,1,(30 - lengthb(l_bg_org)))||l_bg_org
1014 ,substrb(l_org_name,1,(25 - lengthb(l_bg_org)))||l_bg_org
1015 INTO l_project_name
1016 ,l_project_number
1017 FROM DUAL;
1018
1019 -- hr_utility.trace(to_char(l_stage));
1020 pa_debug.g_err_stage := l_stage||': Project Name is '||l_project_name;
1021 IF P_PA_DEBUG_MODE = 'Y' THEN
1022 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1023 END IF;
1024
1025 l_stage := 1900;
1026 pa_debug.g_err_stage := l_stage||': Get Org Project Info';
1027 IF P_PA_DEBUG_MODE = 'Y' THEN
1028 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1029 END IF;
1030 /* Get Project information if the project exists else create the
1031 project by copying the template as per forecasting options
1032 and then get the project info */
1033
1034 pa_fp_org_fcst_utils.get_org_project_info
1035 ( p_organization_id => l_organization_id
1036 ,x_org_project_id => l_project_id
1037 ,x_return_status => l_return_status
1038 ,x_err_code => l_err_code);
1039
1040 IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
1041 THEN
1042 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1043 ': Error occured while Getting Project Info [' ||
1044 l_err_code|| ']';
1045 IF P_PA_DEBUG_MODE = 'Y' THEN
1046 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1047 END IF;
1048 pa_debug.g_err_stage := l_stage||': Organization Id = '||TO_CHAR(l_organization_id);
1049 IF P_PA_DEBUG_MODE = 'Y' THEN
1050 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1051 END IF;
1052 rollback to org_project;
1053 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1054 END IF;
1055 l_stage := 2000;
1056 -- hr_utility.trace(to_char(l_stage));
1057 pa_debug.g_err_stage := l_stage||': Org Project ID is ['||l_project_id||']';
1058 IF P_PA_DEBUG_MODE = 'Y' THEN
1059 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1060 END IF;
1061
1062 IF l_project_id > 0 THEN
1063
1064 l_stage := 2100;
1065 -- hr_utility.trace(to_char(l_stage));
1066 pa_debug.g_err_stage := l_stage||': Get Org Task Info';
1067 IF P_PA_DEBUG_MODE = 'Y' THEN
1068 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1069 END IF;
1070
1071 pa_fp_org_fcst_utils.get_org_task_info
1072 ( p_project_id => l_project_id
1073 ,x_organization_id => l_task_organization_id
1074 ,x_org_task_id => l_own_task_id
1075 ,x_return_status => l_return_status
1076 ,x_err_code => l_err_code);
1077
1078 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1079 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1080 ': Error getting Own Task';
1081 IF P_PA_DEBUG_MODE = 'Y' THEN
1082 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1083 END IF;
1084 /*
1085 pa_debug.g_err_stage :=
1086 'l_project_id ['||l_project_id ||
1087 '] l_organization_id ['||l_organization_id ||
1088 '] l_org_id ['||l_org_id ||
1089 ']';
1090 IF P_PA_DEBUG_MODE = 'Y' THEN
1091 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1092 END IF;
1093 */
1094 rollback to org_project;
1095 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1096 END IF;
1097 l_stage := 2200;
1098 -- hr_utility.trace('2200: Own Task Id = '||to_char(l_own_task_id));
1099 pa_debug.g_err_stage := l_stage||': Own Task Id = '||l_own_task_id;
1100 IF P_PA_DEBUG_MODE = 'Y' THEN
1101 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1102 END IF;
1103
1104 IF l_own_task_id < 0 THEN
1105 l_stage := 2300;
1106 -- hr_utility.trace(to_char(l_stage));
1107 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1108 ': Own Task Not Found';
1109 IF P_PA_DEBUG_MODE = 'Y' THEN
1110 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1111 END IF;
1112 /*
1113 pa_debug.g_err_stage :=
1114 'l_project_id ['||l_project_id ||
1115 '] l_organization_id ['||l_organization_id ||
1116 '] l_org_id ['||l_org_id ||
1117 ']';
1118 IF P_PA_DEBUG_MODE = 'Y' THEN
1119 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1120 END IF;
1121 */
1122 PA_UTILS.ADD_MESSAGE( p_app_short_name => 'PA'
1123 ,p_msg_name => 'PA_FP_OWN_TASK_NOT_FOUND');
1124 rollback to org_project;
1125 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1126 END IF;
1127
1128 IF l_task_organization_id <> l_organization_id THEN
1129 l_stage := 2400;
1130 -- hr_utility.trace(to_char(l_stage));
1131 UPDATE pa_tasks
1132 SET carrying_out_organization_id = l_organization_id
1133 WHERE project_id = l_project_id
1134 AND task_id = l_own_task_id;
1135 END IF;
1136 END IF;
1137
1138 IF l_project_id < 0 THEN /* Organization Project not found */
1139 l_stage := 2500;
1140 -- hr_utility.trace(to_char(l_stage));
1141 pa_debug.g_err_stage := l_stage||': Create New Org Project for '||TO_CHAR(l_organization_id);
1142 IF P_PA_DEBUG_MODE = 'Y' THEN
1143 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1144 END IF;
1145
1146 l_err_code := NULL;
1147 l_err_stage := NULL;
1148 l_err_stack := NULL;
1149
1150 pa_project_core1.copy_project
1151 ( x_orig_project_id => l_org_proj_template_id
1152 , x_project_name => l_project_name
1153 , x_project_number => l_project_number
1154 , x_description => NULL
1155 , x_project_type => NULL
1156 , x_project_status_code => NULL
1157 , x_distribution_rule => NULL
1158 , x_public_sector_flag => 'N'
1159 , x_organization_id => l_organization_id
1160 , x_start_date => TRUNC(sysdate)
1161 , x_completion_date => NULL
1162 , x_probability_member_id => NULL
1163 , x_project_value => NULL
1164 , x_expected_approval_date => NULL
1165 , x_agreement_currency => NULL
1166 , x_agreement_amount => NULL
1167 , x_agreement_org_id => NULL
1168 , x_copy_task_flag => 'Y'
1169 , x_copy_budget_flag => 'N'
1170 , x_use_override_flag => 'N'
1171 , x_copy_assignment_flag => 'N'
1172 , x_template_flag => 'N'
1173 , x_project_id => l_project_id
1174 , x_err_code => l_err_code
1175 , x_err_stage => l_err_stage
1176 , x_err_stack => l_err_stack
1177 , x_new_project_number => l_new_project_number
1178 , x_team_template_id => NULL
1179 , x_country_code => NULL
1180 , x_region => NULL
1181 , x_city => NULL
1182 , x_opp_value_currency_code => NULL
1183 , x_org_project_copy_flag => 'Y');
1184
1185 IF l_err_code > 0 THEN
1186 pa_debug.g_err_stage := l_stage||': Error Creating Project [' || l_err_code || ']';
1187 IF P_PA_DEBUG_MODE = 'Y' THEN
1188 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1189 END IF;
1190 pa_debug.g_err_stage := l_stage||': [' || l_err_stage|| ']';
1191 IF P_PA_DEBUG_MODE = 'Y' THEN
1192 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1193 END IF;
1194 pa_debug.g_err_stage := l_stage||': [' || l_err_stack|| ']';
1195 IF P_PA_DEBUG_MODE = 'Y' THEN
1196 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1197 END IF;
1198 pa_debug.g_err_stage := l_stage||': l_org_proj_template_id ['||l_org_proj_template_id || ']';
1199 IF P_PA_DEBUG_MODE = 'Y' THEN
1200 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1201 END IF;
1202 pa_debug.g_err_stage := l_stage||': l_project_name ['||l_project_name || ']';
1203 IF P_PA_DEBUG_MODE = 'Y' THEN
1204 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1205 END IF;
1206 pa_debug.g_err_stage := l_stage||': l_project_number ['||l_project_number || ']';
1207 IF P_PA_DEBUG_MODE = 'Y' THEN
1208 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1209 END IF;
1210 pa_debug.g_err_stage := l_stage||': l_organization_id ['||l_organization_id || ']';
1211 IF P_PA_DEBUG_MODE = 'Y' THEN
1212 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1213 END IF;
1214 pa_debug.g_err_stage := l_stage||': l_org_id ['||l_org_id || ']';
1215 IF P_PA_DEBUG_MODE = 'Y' THEN
1216 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1217 END IF;
1218 rollback to org_project;
1219 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1220 END IF;
1221
1222 l_stage := 2600;
1223 -- hr_utility.trace(to_char(l_stage));
1224 pa_debug.g_err_stage := l_stage||': Get Org Task Info';
1225 IF P_PA_DEBUG_MODE = 'Y' THEN
1226 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1227 END IF;
1228 pa_fp_org_fcst_utils.get_org_task_info
1229 ( p_project_id => l_project_id
1230 ,x_organization_id => l_task_organization_id
1231 ,x_org_task_id => l_own_task_id
1232 ,x_return_status => l_return_status
1233 ,x_err_code => l_err_code);
1234
1235 -- hr_utility.trace('Own Task Id = '||to_char(l_own_task_id));
1236
1237 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1238 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1239 ': Error getting Own Task';
1240 IF P_PA_DEBUG_MODE = 'Y' THEN
1241 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1242 END IF;
1243 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1244 IF P_PA_DEBUG_MODE = 'Y' THEN
1245 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1246 END IF;
1247 pa_debug.g_err_stage := 'l_organization_id ['||l_organization_id || ']';
1248 IF P_PA_DEBUG_MODE = 'Y' THEN
1249 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1250 END IF;
1251 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1252 IF P_PA_DEBUG_MODE = 'Y' THEN
1253 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1254 END IF;
1255 rollback to org_project;
1256 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1257 END IF;
1258
1259 IF l_own_task_id < 0 THEN
1260 l_stage := 2700;
1261 -- hr_utility.trace(to_char(l_stage));
1262 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Own Task Not Found';
1263 IF P_PA_DEBUG_MODE = 'Y' THEN
1264 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1265 END IF;
1266 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1267 IF P_PA_DEBUG_MODE = 'Y' THEN
1268 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1269 END IF;
1270 pa_debug.g_err_stage := 'l_organization_id ['||l_organization_id || ']';
1271 IF P_PA_DEBUG_MODE = 'Y' THEN
1272 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1273 END IF;
1274 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1275 IF P_PA_DEBUG_MODE = 'Y' THEN
1276 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1277 END IF;
1278 PA_UTILS.ADD_MESSAGE( p_app_short_name => 'PA'
1279 ,p_msg_name => 'PA_FP_OWN_TASK_NOT_FOUND');
1280 rollback to org_project;
1281 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1282 END IF;
1283
1284 IF l_task_organization_id <> l_organization_id THEN
1285 l_stage := 2800;
1286 -- hr_utility.trace(to_char(l_stage));
1287 UPDATE pa_tasks
1288 SET carrying_out_organization_id = l_organization_id
1289 WHERE project_id = l_project_id
1290 AND task_id = l_own_task_id;
1291 END IF;
1292
1293 l_stage := 2900;
1294 -- hr_utility.trace(to_char(l_stage));
1295 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Create Proj Fin Plan Options at Project Level';
1296 IF P_PA_DEBUG_MODE = 'Y' THEN
1297 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1298 END IF;
1299
1300 -- Create Proj Fin Plan Options at Project Level
1301 l_proj_fp_options_id := NULL;
1302 pa_proj_fp_options_pkg.Insert_Row
1303 ( px_proj_fp_options_id => l_proj_fp_options_id
1304 ,p_project_id => l_project_id
1305 ,p_fin_plan_option_level_code => 'PROJECT'
1306 ,p_fin_plan_type_id => NULL
1307 ,p_fin_plan_start_date => NULL
1308 ,p_fin_plan_end_date => NULL
1309 ,p_fin_plan_preference_code => 'COST_AND_REV_SAME'
1310 ,p_cost_amount_set_id => NULL
1311 ,p_revenue_amount_set_id => NULL
1312 ,p_all_amount_set_id => 1
1313 ,p_cost_fin_plan_level_code => NULL
1314 ,p_cost_time_phased_code => NULL
1315 ,p_cost_resource_list_id => NULL
1316 ,p_revenue_fin_plan_level_code => NULL
1317 ,p_revenue_time_phased_code => NULL
1318 ,p_revenue_resource_list_id => NULL
1319 ,p_all_fin_plan_level_code => 'L'
1320 ,p_all_time_phased_code => l_time_phased_code
1321 ,p_all_resource_list_id => l_resource_list_id
1322 ,p_report_labor_hrs_from_code => 'COST'
1323 ,p_fin_plan_version_id => NULL
1324 ,x_row_id => l_row_id
1325 ,x_return_status => l_return_status);
1326
1327 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1328 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1329 ': Error creating Proj FP Options';
1330 IF P_PA_DEBUG_MODE = 'Y' THEN
1331 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1332 END IF;
1333 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1334 IF P_PA_DEBUG_MODE = 'Y' THEN
1335 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1336 END IF;
1337 pa_debug.g_err_stage := 'l_fin_plan_type_id ['||l_fin_plan_type_id || ']';
1338 IF P_PA_DEBUG_MODE = 'Y' THEN
1339 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1340 END IF;
1341 pa_debug.g_err_stage := 'option_level_code ['||'PROJECT' || ']';
1342 IF P_PA_DEBUG_MODE = 'Y' THEN
1343 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1344 END IF;
1345 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1346 IF P_PA_DEBUG_MODE = 'Y' THEN
1347 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1348 END IF;
1349 rollback to org_project;
1350 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1351 END IF;
1352
1353 l_stage := 3000;
1354 -- hr_utility.trace(to_char(l_stage));
1355 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Create Proj FP Options at Plan Type Level';
1356 IF P_PA_DEBUG_MODE = 'Y' THEN
1357 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1358 END IF;
1359
1360 -- Create Proj Fin Plan Options at Plan Type Level
1361 l_proj_fp_options_id := NULL;
1362 pa_proj_fp_options_pkg.Insert_Row
1363 ( px_proj_fp_options_id => l_proj_fp_options_id
1364 ,p_project_id => l_project_id
1365 ,p_fin_plan_option_level_code => 'PLAN_TYPE'
1366 ,p_fin_plan_type_id => l_fin_plan_type_id
1367 ,p_fin_plan_start_date => NULL
1368 ,p_fin_plan_end_date => NULL
1369 ,p_fin_plan_preference_code => 'COST_AND_REV_SAME'
1370 ,p_cost_amount_set_id => NULL
1371 ,p_revenue_amount_set_id => NULL
1372 ,p_all_amount_set_id => 1
1373 ,p_cost_fin_plan_level_code => NULL
1374 ,p_cost_time_phased_code => NULL
1375 ,p_cost_resource_list_id => NULL
1376 ,p_revenue_fin_plan_level_code => NULL
1377 ,p_revenue_time_phased_code => NULL
1378 ,p_revenue_resource_list_id => NULL
1379 ,p_all_fin_plan_level_code => 'L'
1380 ,p_all_time_phased_code => l_time_phased_code
1381 ,p_all_resource_list_id => l_resource_list_id
1382 ,p_report_labor_hrs_from_code => 'COST'
1383 ,p_fin_plan_version_id => NULL
1384 ,x_row_id => l_row_id
1385 ,x_return_status => l_return_status);
1386
1387 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1388 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1389 ': Error creating Plan FP Options';
1390 IF P_PA_DEBUG_MODE = 'Y' THEN
1391 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1392 END IF;
1393 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1394 IF P_PA_DEBUG_MODE = 'Y' THEN
1395 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1396 END IF;
1397 pa_debug.g_err_stage := 'l_fin_plan_type_id ['||l_fin_plan_type_id || ']';
1398 IF P_PA_DEBUG_MODE = 'Y' THEN
1399 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1400 END IF;
1401 pa_debug.g_err_stage := 'option_level_code ['||'PROJECT' || ']';
1402 IF P_PA_DEBUG_MODE = 'Y' THEN
1403 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1404 END IF;
1405 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1406 IF P_PA_DEBUG_MODE = 'Y' THEN
1407 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1408 END IF;
1409 rollback to org_project;
1410 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1411 END IF;
1412
1413 l_stage := 3100;
1414 -- hr_utility.trace(to_char(l_stage));
1415
1416 END IF; /* End of Organization Project Creation */
1417
1418 l_stage := 3200;
1419 -- hr_utility.trace(to_char(l_stage));
1420 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Check Existence of Period Profile for the following data: ';
1421 IF P_PA_DEBUG_MODE = 'Y' THEN
1422 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1423 END IF;
1424
1425
1426 -- Get Period Profile Information if exists
1427 pa_debug.g_err_stage := l_stage||': l_project_id ['||l_project_id ||']';
1428 IF P_PA_DEBUG_MODE = 'Y' THEN
1429 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1430 END IF;
1431 pa_debug.g_err_stage := l_stage||': period_profile_type ['||'FINANCIAL_PLANNING' ||']';
1432 IF P_PA_DEBUG_MODE = 'Y' THEN
1433 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1434 END IF;
1435 pa_debug.g_err_stage := l_stage||': l_org_fcst_period_type ['||l_org_fcst_period_type||']';
1436 IF P_PA_DEBUG_MODE = 'Y' THEN
1437 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1438 END IF;
1439 pa_debug.g_err_stage := l_stage||': l_period_set_name ['||l_period_set_name ||']';
1440 IF P_PA_DEBUG_MODE = 'Y' THEN
1441 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1442 END IF;
1443 pa_debug.g_err_stage := l_stage||': l_act_period_type ['||l_act_period_type ||']';
1444 IF P_PA_DEBUG_MODE = 'Y' THEN
1445 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1446 END IF;
1447 pa_debug.g_err_stage := l_stage||': l_fcst_start_date ['||l_fcst_start_date ||']';
1448 IF P_PA_DEBUG_MODE = 'Y' THEN
1449 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1450 END IF;
1451 pa_debug.g_err_stage := l_stage||': l_number_of_periods ['||l_number_of_periods ||']';
1452 IF P_PA_DEBUG_MODE = 'Y' THEN
1453 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1454 END IF;
1455
1456
1457 pa_fp_org_fcst_utils.get_period_profile
1458 ( p_project_id => l_project_id
1459 ,p_period_profile_type => 'FINANCIAL_PLANNING'
1460 ,p_plan_period_type => l_org_fcst_period_type
1461 ,p_period_set_name => l_period_set_name
1462 ,p_act_period_type => l_act_period_type
1463 ,p_start_date => l_fcst_start_date
1464 ,p_number_of_periods => l_number_of_periods
1465 ,x_period_profile_id => l_period_profile_id
1466 ,x_return_status => l_return_status
1467 ,x_err_code => l_err_code);
1468
1469 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1470 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1471 ': Error in get_period_profile ';
1472 IF P_PA_DEBUG_MODE = 'Y' THEN
1473 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1474 END IF;
1475 rollback to org_project;
1476 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1477 END IF;
1478
1479 l_stage := 3300;
1480 -- hr_utility.trace(to_char(l_stage));
1481
1482 IF l_period_profile_id < 0 THEN
1483 l_period_profile_id := NULL;
1484 l_stage := 3400;
1485 -- hr_utility.trace(to_char(l_stage));
1486 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Creating Period Profile';
1487 IF P_PA_DEBUG_MODE = 'Y' THEN
1488 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1489 END IF;
1490
1491 IF l_org_fcst_period_type = 'PA' THEN
1492 /* Denorm pkg requires this */
1493 -- hr_utility.trace(to_char(l_stage));
1494 l_pa_period_type := l_act_period_type;
1495 END IF;
1496
1497 -- Create Period Profile
1498 Pa_Prj_Period_Profile_Utils.maintain_prj_period_profile
1499 ( p_project_id => l_project_id
1500 ,p_period_profile_type => 'FINANCIAL_PLANNING'
1501 ,p_plan_period_type => l_org_fcst_period_type
1502 ,p_period_set_name => l_period_set_name
1503 ,p_gl_period_type => l_act_period_type
1504 ,p_pa_period_type => l_pa_period_type
1505 ,p_start_date => l_fcst_start_date
1506 ,px_end_date => l_fcst_end_date
1507 ,px_period_profile_id => l_period_profile_id
1508 ,p_commit_flag => 'N'
1509 ,px_number_of_periods => l_number_of_periods
1510 ,x_plan_start_date => l_ppp_start_date
1511 ,x_plan_end_date => l_ppp_end_date
1512 ,x_return_status => l_return_status
1513 ,x_msg_count => l_msg_count
1514 ,x_msg_data => errbuff );
1515
1516 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1517 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1518 ': Error creating period profile';
1519 IF P_PA_DEBUG_MODE = 'Y' THEN
1520 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1521 END IF;
1522 rollback to org_project;
1523 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1524 END IF;
1525 END IF;
1526
1527 l_stage := 3500;
1528 -- hr_utility.trace(to_char(l_stage));
1529 pa_debug.g_err_stage := l_stage||': Period Profile Id ['||l_period_profile_id||']';
1530 IF P_PA_DEBUG_MODE = 'Y' THEN
1531 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1532 END IF;
1533
1534 SELECT nvl(max(bv.version_number),0) + 1,
1535 DECODE(nvl(max(bv.version_number),0) + 1,1,'Y','N')
1536 INTO l_bv_version_number
1537 ,l_current_working_flag
1538 FROM pa_budget_versions bv
1539 WHERE bv.project_id = l_project_id
1540 AND bv.fin_plan_type_id = l_fin_plan_type_id
1541 AND bv.budget_status_code in ('W','S');
1542
1543 l_stage := 3600;
1544 -- hr_utility.trace(to_char(l_stage));
1545 pa_debug.g_err_stage := l_stage||': BV Number ['||l_bv_version_number ||']';
1546 IF P_PA_DEBUG_MODE = 'Y' THEN
1547 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1548 END IF;
1549 pa_debug.g_err_stage := l_stage||': Current Working Flag ['||l_current_working_flag||']';
1550 IF P_PA_DEBUG_MODE = 'Y' THEN
1551 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1552 END IF;
1553
1554 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Create Budget Version';
1555 IF P_PA_DEBUG_MODE = 'Y' THEN
1556 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1557 END IF;
1558
1559 -- Create Budget Version
1560 l_budget_version_id := NULL;
1561 pa_fp_budget_versions_pkg.Insert_Row
1562 ( px_budget_version_id => l_budget_version_id
1563 ,p_project_id => l_project_id
1564 ,p_budget_type_code => NULL
1565 ,p_version_number => l_bv_version_number
1566 ,p_budget_status_code => 'W'
1567 ,p_current_flag => 'N'
1568 ,p_original_flag => 'N'
1569 ,p_current_original_flag => 'N'
1570 ,p_resource_accumulated_flag => 'N'
1571 ,p_resource_list_id => l_resource_list_id
1572 ,p_version_name => l_bv_version_name
1573 ,p_plan_run_date => sysdate
1574 ,p_plan_processing_code => 'S'
1575 ,p_period_profile_id => l_period_profile_id
1576 ,p_fin_plan_type_id => l_fin_plan_type_id
1577 ,p_current_working_flag => l_current_working_flag
1578 ,p_version_type => 'ORG_FORECAST'
1579 ,x_row_id => l_row_id
1580 ,x_return_status => l_return_status);
1581
1582 l_stage := 3700;
1583 -- hr_utility.trace(to_char(l_stage));
1584 pa_debug.g_err_stage := l_stage||': Budget Version Id ['||l_budget_version_id ||']';
1585 IF P_PA_DEBUG_MODE = 'Y' THEN
1586 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1587 END IF;
1588 pa_debug.g_err_stage := l_stage||': Resource List Id ['||l_resource_list_id||']';
1589 IF P_PA_DEBUG_MODE = 'Y' THEN
1590 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1591 END IF;
1592
1593 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1594 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1595 ': Error creating Budget version';
1596 IF P_PA_DEBUG_MODE = 'Y' THEN
1597 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1598 END IF;
1599 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1600 IF P_PA_DEBUG_MODE = 'Y' THEN
1601 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1602 END IF;
1603 pa_debug.g_err_stage := 'l_bv_version_number ['||l_bv_version_number || ']';
1604 IF P_PA_DEBUG_MODE = 'Y' THEN
1605 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1606 END IF;
1607 pa_debug.g_err_stage := 'l_resource_list_id ['||l_resource_list_id || ']';
1608 IF P_PA_DEBUG_MODE = 'Y' THEN
1609 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1610 END IF;
1611 pa_debug.g_err_stage := 'l_period_profile_id ['||l_period_profile_id || ']';
1612 IF P_PA_DEBUG_MODE = 'Y' THEN
1613 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1614 END IF;
1615 pa_debug.g_err_stage := 'l_fin_plan_type_id ['||l_fin_plan_type_id || ']';
1616 IF P_PA_DEBUG_MODE = 'Y' THEN
1617 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1618 END IF;
1619 pa_debug.g_err_stage := 'l_current_working_flag ['||l_current_working_flag || ']';
1620 IF P_PA_DEBUG_MODE = 'Y' THEN
1621 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1622 END IF;
1623 pa_debug.g_err_stage := 'version_type ['||'ORG_FORECAST' || ']';
1624 IF P_PA_DEBUG_MODE = 'Y' THEN
1625 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1626 END IF;
1627 rollback to org_project;
1628 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1629 END IF;
1630
1631 l_stage := 3750;
1632 -- hr_utility.trace(to_char(l_stage));
1633 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Create Proj Fin Plan Options at Plan Version Level';
1634 IF P_PA_DEBUG_MODE = 'Y' THEN
1635 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1636 END IF;
1637
1638 -- Create Proj Fin Plan Options at Plan Version Level
1639 l_proj_fp_options_id := NULL;
1640 pa_proj_fp_options_pkg.Insert_Row
1641 ( px_proj_fp_options_id => l_proj_fp_options_id
1642 ,p_project_id => l_project_id
1643 ,p_fin_plan_option_level_code => 'PLAN_VERSION'
1644 ,p_fin_plan_type_id => l_fin_plan_type_id
1645 ,p_fin_plan_start_date => l_fcst_start_date
1646 ,p_fin_plan_end_date => l_fcst_end_date
1647 ,p_fin_plan_preference_code => 'COST_AND_REV_SAME'
1648 ,p_cost_amount_set_id => NULL
1649 ,p_revenue_amount_set_id => NULL
1650 ,p_all_amount_set_id => 1
1651 ,p_cost_fin_plan_level_code => NULL
1652 ,p_cost_time_phased_code => NULL
1653 ,p_cost_resource_list_id => NULL
1654 ,p_revenue_fin_plan_level_code => NULL
1655 ,p_revenue_time_phased_code => NULL
1656 ,p_revenue_resource_list_id => NULL
1657 ,p_all_fin_plan_level_code => 'L'
1658 ,p_all_time_phased_code => l_time_phased_code
1659 ,p_all_resource_list_id => l_resource_list_id
1660 ,p_report_labor_hrs_from_code => 'COST'
1661 ,p_fin_plan_version_id => l_budget_version_id
1662 ,x_row_id => l_row_id
1663 ,x_return_status => l_return_status);
1664
1665 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1666 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1667 ': Error creating Budget Version FP Options';
1668 IF P_PA_DEBUG_MODE = 'Y' THEN
1669 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1670 END IF;
1671 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1672 IF P_PA_DEBUG_MODE = 'Y' THEN
1673 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1674 END IF;
1675 pa_debug.g_err_stage := 'l_fin_plan_type_id ['||l_fin_plan_type_id || ']';
1676 IF P_PA_DEBUG_MODE = 'Y' THEN
1677 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1678 END IF;
1679 pa_debug.g_err_stage := 'option_level_code ['||'PROJECT' || ']';
1680 IF P_PA_DEBUG_MODE = 'Y' THEN
1681 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1682 END IF;
1683 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1684 IF P_PA_DEBUG_MODE = 'Y' THEN
1685 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1686 END IF;
1687 rollback to org_project;
1688 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1689 END IF;
1690 ELSE /* Budget version passed */
1691 l_budget_ctr := 1;
1692 l_stage := 3800;
1693 -- hr_utility.trace(to_char(l_stage));
1694 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Get BudgetVersion Details';
1695 IF P_PA_DEBUG_MODE = 'Y' THEN
1696 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1697 END IF;
1698
1699 SELECT bv.budget_version_id,
1700 bv.project_id,
1701 bv.record_version_number,
1702 bv.period_profile_id,
1703 pa.carrying_out_organization_id,
1704 pa.projfunc_currency_code
1705 INTO l_budget_version_id,
1706 l_project_id,
1707 l_bv_rec_ver_num,
1708 l_period_profile_id,
1709 l_organization_id,
1710 l_org_projfunc_currency_code
1711 FROM pa_budget_versions bv,
1712 pa_projects pa
1713 WHERE bv.budget_version_id = p_budget_version_id
1714 AND pa.project_id = bv.project_id;
1715
1716 l_stage := 3900;
1717 -- hr_utility.trace(to_char(l_stage));
1718
1719 IF l_project_id > 0 THEN
1720
1721 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Get Org Task Info';
1722 IF P_PA_DEBUG_MODE = 'Y' THEN
1723 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1724 END IF;
1725
1726 pa_fp_org_fcst_utils.get_org_task_info
1727 ( p_project_id => l_project_id
1728 ,x_organization_id => l_task_organization_id
1729 ,x_org_task_id => l_own_task_id
1730 ,x_return_status => l_return_status
1731 ,x_err_code => l_err_code);
1732
1733 -- hr_utility.trace('Own Task Id = '||to_char(l_own_task_id));
1734
1735 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1736 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1737 ': Error getting Own Task';
1738 IF P_PA_DEBUG_MODE = 'Y' THEN
1739 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1740 END IF;
1741 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1742 IF P_PA_DEBUG_MODE = 'Y' THEN
1743 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1744 END IF;
1745 pa_debug.g_err_stage := 'l_organization_id ['||l_organization_id || ']';
1746 IF P_PA_DEBUG_MODE = 'Y' THEN
1747 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1748 END IF;
1749 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1750 IF P_PA_DEBUG_MODE = 'Y' THEN
1751 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1752 END IF;
1753 rollback to org_project;
1754 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1755 END IF;
1756
1757 IF l_own_task_id < 0 THEN
1758 l_stage := 4000;
1759 -- hr_utility.trace(to_char(l_stage));
1760 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1761 ': Own Task Not Found';
1762 IF P_PA_DEBUG_MODE = 'Y' THEN
1763 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1764 END IF;
1765 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
1766 IF P_PA_DEBUG_MODE = 'Y' THEN
1767 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1768 END IF;
1769 pa_debug.g_err_stage := 'l_organization_id ['||l_organization_id || ']';
1770 IF P_PA_DEBUG_MODE = 'Y' THEN
1771 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1772 END IF;
1773 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
1774 IF P_PA_DEBUG_MODE = 'Y' THEN
1775 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1776 END IF;
1777 PA_UTILS.ADD_MESSAGE( p_app_short_name => 'PA'
1778 ,p_msg_name => 'PA_FP_OWN_TASK_NOT_FOUND');
1779 rollback to org_project;
1780 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1781 END IF;
1782
1783 IF l_task_organization_id <> l_organization_id THEN
1784 l_stage := 4100;
1785 -- hr_utility.trace(to_char(l_stage));
1786 UPDATE pa_tasks
1787 SET carrying_out_organization_id = l_organization_id
1788 WHERE project_id = l_project_id
1789 AND task_id = l_own_task_id;
1790 END IF;
1791 END IF;
1792
1793 l_stage := 4200;
1794 -- hr_utility.trace(to_char(l_stage));
1795 pa_debug.g_err_stage := l_stage||': Org Projfunc Currency Code ['||l_org_projfunc_currency_code||']';
1796 IF P_PA_DEBUG_MODE = 'Y' THEN
1797 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1798 END IF;
1799
1800 pa_prj_period_profile_utils.get_prj_period_profile_dtls
1801 ( p_period_profile_id => l_period_profile_id
1802 ,x_period_profile_type => l_period_profile_type
1803 ,x_plan_period_type => l_org_fcst_period_type
1804 ,x_period_set_name => l_period_set_name
1805 ,x_gl_period_type => l_act_period_type
1806 ,x_plan_start_date => l_fcst_start_date
1807 ,x_plan_end_date => l_fcst_end_date
1808 ,x_number_of_periods => l_number_of_periods
1809 ,x_return_status => l_return_status
1810 --,x_msg_count => x_msg_count
1811 ,x_msg_data => errbuff );
1812
1813 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1814 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
1815 ': Error getting period profile info';
1816 IF P_PA_DEBUG_MODE = 'Y' THEN
1817 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1818 END IF;
1819 pa_debug.g_err_stage :=
1820 'l_period_profile_id ['||l_period_profile_id || ']';
1821 IF P_PA_DEBUG_MODE = 'Y' THEN
1822 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1823 END IF;
1824 rollback to org_project;
1825 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1826 END IF;
1827
1828 /* DELETE existing data for budget version */
1829
1830 l_stage := 4300;
1831 -- hr_utility.trace(to_char(l_stage));
1832 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Deleting Existing Data';
1833 IF P_PA_DEBUG_MODE = 'Y' THEN
1834 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1835 END IF;
1836
1837 pa_fin_plan_pub.Delete_Version_Helper
1838 (p_budget_version_id => p_budget_version_id,
1839 x_return_status => l_return_status,
1840 x_msg_count => l_msg_count,
1841 x_msg_data => l_msg_data);
1842
1843 IF l_return_status <> FND_API.G_RET_STS_SUCCESS then
1844 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
1845 END IF;
1846 l_stage := 4900;
1847 -- hr_utility.trace(to_char(l_stage));
1848 UPDATE pa_budget_versions
1849 SET
1850 version_name = DECODE(version_name,null,l_bv_version_name
1851 ||'-'||to_char(l_budget_version_id),
1852 version_name)
1853 ,last_update_date = sysdate
1854 ,last_updated_by = fnd_global.user_id
1855 ,last_update_login = fnd_global.login_id
1856 ,revenue = 0
1857 ,raw_cost = 0
1858 ,burdened_cost = 0
1859 ,labor_quantity = 0
1860 ,total_borrowed_revenue = 0
1861 ,total_tp_revenue_in = 0
1862 ,total_tp_revenue_out = 0
1863 ,total_lent_resource_cost = 0
1864 ,total_tp_cost_in = 0
1865 ,total_tp_cost_out = 0
1866 ,total_unassigned_time_cost = 0
1867 ,total_utilization_percent = 0
1868 ,total_utilization_hours = 0
1869 ,total_capacity = 0
1870 ,total_head_count = 0
1871 ,total_revenue_adj = 0
1872 ,total_cost_adj = 0
1873 ,total_utilization_adj = 0
1874 ,total_head_count_adj = 0
1875 WHERE budget_version_id = p_budget_version_id;
1876
1877 l_stage := 5000;
1878 -- hr_utility.trace(to_char(l_stage));
1879 COMMIT;
1880 END IF; /* Budget Version Check */
1881
1882 l_stage := 5100;
1883 -- hr_utility.trace(to_char(l_stage));
1884 IF l_org_fcst_period_type = 'PA' THEN /* Denorm pkg requires this */
1885 l_stage := 5200;
1886 -- hr_utility.trace(to_char(l_stage));
1887 l_pa_period_type := l_act_period_type;
1888 END IF;
1889
1890 /* Now we have the Organization Project and all the task for own
1891 and sub-tasks and period profile, budget version and plan
1892 options in place */
1893
1894 /* The program flow from here is as follows:
1895 - Create Forecast Elements
1896 - Create Forecast Lines
1897 - Create Proj Denorm for forecast lines
1898 - Create Resource Assignments
1899 - Create Budget Lines
1900 - Update Resource Assignments
1901 - Update Budget Versions
1902 - Create Proj Denorm for budget lines
1903 */
1904 l_stage := 5300;
1905 -- hr_utility.trace(to_char(l_stage));
1906 pa_debug.g_err_stage := TO_CHAR(l_stage) ||': Populate amt_rec for Forecast Lines Denorm';
1907 IF P_PA_DEBUG_MODE = 'Y' THEN
1908 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
1909 END IF;
1910 /* Populate amt_rec for Forecast Lines Denorm */
1911 amt_rec.delete;
1912
1913 amt_rec(1).amount_type_code := 'QUANTITY';
1914 amt_rec(1).amount_subtype_code := 'QUANTITY';
1915 amt_rec(1).amount_type_id := get_amttype_id(p_amt_typ_code => 'QUANTITY');
1916 amt_rec(1).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'QUANTITY');
1917
1918 amt_rec(2).amount_type_code := 'COST';
1919 amt_rec(2).amount_subtype_code := 'OWN_PROJECT_COST';
1920 amt_rec(2).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
1921 amt_rec(2).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'OWN_PROJECT_COST');
1922
1923 amt_rec(3).amount_type_code := 'COST';
1924 amt_rec(3).amount_subtype_code := 'TP_COST_IN';
1925 amt_rec(3).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
1926 amt_rec(3).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_COST_IN');
1927
1928 amt_rec(4).amount_type_code := 'COST';
1929 amt_rec(4).amount_subtype_code := 'TP_COST_OUT';
1930 amt_rec(4).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
1931 amt_rec(4).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_COST_OUT');
1932
1933 amt_rec(5).amount_type_code := 'COST';
1934 amt_rec(5).amount_subtype_code := 'LENT_RESOURCE_COST';
1935 amt_rec(5).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
1936 amt_rec(5).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'LENT_RESOURCE_COST');
1937
1938 amt_rec(6).amount_type_code := 'COST';
1939 amt_rec(6).amount_subtype_code := 'UNASSIGNED_TIME_COST';
1940 amt_rec(6).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
1941 amt_rec(6).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'UNASSIGNED_TIME_COST');
1942
1943 amt_rec(7).amount_type_code := 'REVENUE';
1944 amt_rec(7).amount_subtype_code := 'OWN_REVENUE';
1945 amt_rec(7).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
1946 amt_rec(7).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'OWN_REVENUE');
1947
1948 amt_rec(8).amount_type_code := 'REVENUE';
1949 amt_rec(8).amount_subtype_code := 'BORROWED_REVENUE';
1950 amt_rec(8).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
1951 amt_rec(8).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'BORROWED_REVENUE');
1952
1953 amt_rec(9).amount_type_code := 'REVENUE';
1954 amt_rec(9).amount_subtype_code := 'TP_REVENUE_IN';
1955 amt_rec(9).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
1956 amt_rec(9).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_REVENUE_IN');
1957
1958 amt_rec(10).amount_type_code := 'REVENUE';
1959 amt_rec(10).amount_subtype_code := 'TP_REVENUE_OUT';
1960 amt_rec(10).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
1961 amt_rec(10).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_REVENUE_OUT');
1962
1963 /* DELETE FROM ALL plsql tables */
1964
1965 /* For forecast items */
1966 l_fi_organization_id_tab.delete;
1967 l_fi_proj_organization_tab.delete;
1968 l_fi_proj_orgid_tab.delete;
1969 l_fi_exp_organization_id_tab.delete;
1970 l_fi_exp_orgid_tab.delete;
1971 l_fi_txn_project_id_tab.delete;
1972 l_fi_assignment_id_tab.delete;
1973 l_fi_resource_id_tab.delete;
1974 l_fi_period_name_tab.delete;
1975 l_fi_start_date_tab.delete;
1976 l_fi_end_date_tab.delete;
1977 l_fi_item_quantity_tab.delete;
1978 l_fi_raw_cost_tab.delete;
1979 l_fi_burdened_cost_tab.delete;
1980 l_fi_tp_cost_in_tab.delete;
1981 l_fi_tp_cost_out_tab.delete;
1982 l_fi_revenue_tab.delete;
1983 l_fi_tp_rev_in_tab.delete;
1984 l_fi_tp_rev_out_tab.delete;
1985 l_fi_borrowed_revenue_tab.delete;
1986 l_fi_lent_resource_cost_tab.delete;
1987 l_fi_unassigned_time_cost_tab.delete;
1988
1989 /* Forecast Element PL/SQL Tables */
1990 l_fe_forecast_element_id_tab.delete;
1991 l_fe_organization_id_tab.delete;
1992 l_fe_org_id_tab.delete;
1993 l_fe_budget_version_id_tab.delete;
1994 l_fe_project_id_tab.delete;
1995 l_fe_task_id_tab.delete;
1996 l_fe_pvdr_rcvr_code_tab.delete;
1997 l_fe_other_organization_id_tab.delete;
1998 l_fe_other_org_id_tab.delete;
1999 l_fe_txn_project_id_tab.delete;
2000 l_fe_assignment_id_tab.delete;
2001 l_fe_resource_id_tab.delete;
2002
2003 /* Forecast Lines PL/SQL Tables */
2004 l_fl_forecast_line_id_tab.delete;
2005 l_fl_forecast_element_id_tab.delete;
2006 l_fl_budget_version_id_tab.delete;
2007 l_fl_project_id_tab.delete;
2008 l_fl_task_id_tab.delete;
2009 l_fl_period_name_tab.delete;
2010 l_fl_start_date_tab.delete;
2011 l_fl_end_date_tab.delete;
2012 l_fl_quantity_tab.delete;
2013 l_fl_raw_cost_tab.delete;
2014 l_fl_burdened_cost_tab.delete;
2015 l_fl_tp_cost_in_tab.delete;
2016 l_fl_tp_cost_out_tab.delete;
2017 l_fl_revenue_tab.delete;
2018 l_fl_tp_rev_in_tab.delete;
2019 l_fl_tp_rev_out_tab.delete;
2020 l_fl_borrowed_revenue_tab.delete;
2021 l_fl_lent_resource_cost_tab.delete;
2022 l_fl_unassigned_time_cost_tab.delete;
2023
2024 /* Budget Lines PL/SQL Tables */
2025
2026 l_bl_res_asg_id_tab.delete;
2027 l_bl_budget_version_id_tab.delete; /* FPB2 */
2028 l_bl_start_date_tab.delete;
2029 l_bl_end_date_tab.delete;
2030 l_bl_period_name_tab.delete;
2031 l_bl_quantity_tab.delete;
2032 l_bl_raw_cost_tab.delete;
2033 l_bl_burdened_cost_tab.delete;
2034 l_bl_revenue_tab.delete;
2035 l_bl_borrowed_revenue_tab.delete;
2036 l_bl_tp_revenue_in_tab.delete;
2037 l_bl_tp_revenue_out_tab.delete;
2038 l_bl_lent_resource_cost_tab.delete;
2039 l_bl_tp_cost_in_tab.delete;
2040 l_bl_tp_cost_out_tab.delete;
2041 l_bl_unassigned_time_cost_tab.delete;
2042 l_bl_utilization_percent_tab.delete;
2043 l_bl_utilization_hours_tab.delete;
2044 l_bl_capacity_tab.delete;
2045 l_bl_head_count_tab.delete;
2046
2047 l_pfi_organization_id := null;
2048 l_pfi_project_organization_id := null;
2049 l_pfi_project_org_id := null;
2050 l_pfi_exp_organization_id := null;
2051 l_pfi_exp_org_id := null;
2052 l_pfi_txn_project_id := null;
2053 l_pfi_assignment_id := null;
2054 l_pfi_resource_id := null;
2055 l_prv_forecast_element_id := null;
2056
2057 IF NOT forecast_items%ISOPEN THEN
2058 OPEN forecast_items;
2059 ELSE
2060 CLOSE forecast_items;
2061 OPEN forecast_items;
2062 END IF;
2063 l_stage := 5400;
2064 -- hr_utility.trace(to_char(l_stage));
2065 LOOP
2066 l_fi_organization_id_tab.delete;
2067 l_fi_proj_organization_tab.delete;
2068 l_fi_proj_orgid_tab.delete;
2069 l_fi_exp_organization_id_tab.delete;
2070 l_fi_exp_orgid_tab.delete;
2071 l_fi_txn_project_id_tab.delete;
2072 l_fi_assignment_id_tab.delete;
2073 l_fi_resource_id_tab.delete;
2074 l_fi_period_name_tab.delete;
2075 l_fi_start_date_tab.delete;
2076 l_fi_end_date_tab.delete;
2077 l_fi_item_quantity_tab.delete;
2078 l_fi_raw_cost_tab.delete;
2079 l_fi_burdened_cost_tab.delete;
2080 l_fi_tp_cost_in_tab.delete;
2081 l_fi_tp_cost_out_tab.delete;
2082 l_fi_revenue_tab.delete;
2083 l_fi_tp_rev_in_tab.delete;
2084 l_fi_tp_rev_out_tab.delete;
2085 l_fi_borrowed_revenue_tab.delete;
2086 l_fi_lent_resource_cost_tab.delete;
2087 l_fi_unassigned_time_cost_tab.delete;
2088
2089 FETCH forecast_items BULK COLLECT INTO
2090 l_fi_organization_id_tab,
2091 l_fi_proj_organization_tab,
2092 l_fi_proj_orgid_tab,
2093 l_fi_exp_organization_id_tab,
2094 l_fi_exp_orgid_tab,
2095 l_fi_txn_project_id_tab,
2096 l_fi_assignment_id_tab,
2097 l_fi_resource_id_tab,
2098 l_fi_period_name_tab,
2099 l_fi_start_date_tab,
2100 l_fi_end_date_tab,
2101 l_fi_item_quantity_tab,
2102 l_fi_raw_cost_tab,
2103 l_fi_burdened_cost_tab,
2104 l_fi_lent_resource_cost_tab,
2105 l_fi_unassigned_time_cost_tab,
2106 l_fi_tp_cost_in_tab,
2107 l_fi_tp_cost_out_tab,
2108 l_fi_revenue_tab,
2109 l_fi_borrowed_revenue_tab,
2110 l_fi_tp_rev_in_tab,
2111 l_fi_tp_rev_out_tab LIMIT 200;
2112
2113 IF NVL(l_fi_organization_id_tab.count,0) =0 THEN
2114 l_stage := 4200;
2115 -- hr_utility.trace(to_char(l_stage));
2116 pa_debug.g_err_stage := l_stage||': Exiting fi loop no rows to process';
2117 IF P_PA_DEBUG_MODE = 'Y' THEN
2118 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2119 END IF;
2120 EXIT WHEN NVL(l_fi_organization_id_tab.count,0) =0;
2121 END IF;
2122
2123
2124 l_stage := 5500;
2125 -- hr_utility.trace(to_char(l_stage));
2126 -- hr_utility.trace('Row fetched : '||to_char(l_fi_organization_id_tab.count));
2127
2128 /* Transfer Price Logic as part of Select statement:
2129
2130 Org Context TP Amount Type CC In CC Out Rev In Rev Out
2131 ----------- -------------- ----- ------ ------ -------
2132 Provider COST 0 Y 0 0
2133 Provider REVENUE 0 0 Y 0
2134 Receiver COST Y 0 0 0
2135 Receiver REVENUE 0 0 0 Y
2136 */
2137
2138 FOR i in l_fi_organization_id_tab.first..l_fi_organization_id_tab.last LOOP
2139 BEGIN
2140 -- hr_utility.trace('Orgn id=> '||to_char(l_fi_organization_id_tab(i)));
2141 -- hr_utility.trace('Proj Orgn=> '||to_char(l_fi_proj_organization_tab(i)));
2142 -- hr_utility.trace('Proj Orgid=> '||to_char(l_fi_proj_orgid_tab(i)));
2143 -- hr_utility.trace('Exp Orgn=> '||to_char(l_fi_exp_organization_id_tab(i)));
2144 -- hr_utility.trace('Exp Orgid=> '||to_char(l_fi_exp_orgid_tab(i)));
2145 -- hr_utility.trace('Txn Proj=> '||to_char(l_fi_txn_project_id_tab(i)));
2146 -- hr_utility.trace('Asg Id=> '||to_char(l_fi_assignment_id_tab(i)));
2147 -- hr_utility.trace('Res Id=> '||to_char(l_fi_resource_id_tab(i)));
2148 -- hr_utility.trace('Period=> '||l_fi_period_name_tab(i));
2149 -- hr_utility.trace('Start Dt=> '||l_fi_start_date_tab(i));
2150 -- hr_utility.trace('End Dt=> '||l_fi_end_date_tab(i));
2151 -- hr_utility.trace('prv txn Id => '||to_char(l_pfi_txn_project_id));
2152 -- hr_utility.trace('Weighted_full => '||l_weighted_or_full_code);
2153 -- hr_utility.trace('End Dt=> '||l_fi_end_date_tab(i));
2154
2155 IF (l_pfi_txn_project_id IS NULL OR
2156 l_pfi_txn_project_id <> l_fi_txn_project_id_tab(i)) THEN
2157 l_stage := 5510;
2158 -- hr_utility.trace(to_char(l_stage));
2159 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2160 ': Getting Project Action Allowed';
2161 IF P_PA_DEBUG_MODE = 'Y' THEN
2162 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2163 END IF;
2164 pa_debug.g_err_stage := 'l_project_id ['||l_fi_txn_project_id_tab(i)|| ']';
2165 IF P_PA_DEBUG_MODE = 'Y' THEN
2166 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2167 END IF;
2168
2169 l_project_action_allowed := pa_project_utils.check_project_action_allowed
2170 ( x_project_id => l_fi_txn_project_id_tab(i)
2171 ,x_action_code => 'PROJ_ORG_FORECASTING');
2172 END IF;
2173
2174 IF l_project_action_allowed = 'N' THEN
2175 l_stage := 5520;
2176 -- hr_utility.trace(to_char(l_stage));
2177 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2178 ': Project Action Not Allowed -- Skipping : '
2179 ||l_fi_txn_project_id_tab(i);
2180
2181 IF P_PA_DEBUG_MODE = 'Y' THEN
2182 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2183 END IF;
2184 l_pfi_txn_project_id := l_fi_txn_project_id_tab(i);
2185
2186 RAISE pa_fp_org_fcst_gen_pub.proj_action_reloop;
2187 END IF;
2188
2189
2190 IF (l_pfi_txn_project_id IS NULL OR
2191 l_pfi_txn_project_id <> l_fi_txn_project_id_tab(i)) THEN
2192 IF l_weighted_or_full_code = 'W' THEN
2193 pa_fp_org_fcst_utils.get_probability_percent
2194 ( p_project_id => l_fi_txn_project_id_tab(i)
2195 ,x_prob_percent => l_prob_percent
2196 ,x_return_status => l_return_status
2197 ,x_err_code => l_err_code);
2198 l_stage := 5600;
2199 -- hr_utility.trace(to_char(l_stage));
2200 -- hr_utility.trace('Probability => '||to_char(l_prob_percent));
2201
2202 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2203 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2204 ': Error getting probability percent';
2205 IF P_PA_DEBUG_MODE = 'Y' THEN
2206 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2207 END IF;
2208 pa_debug.g_err_stage := 'l_project_id ['||l_project_id|| ']';
2209 IF P_PA_DEBUG_MODE = 'Y' THEN
2210 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2211 END IF;
2212 rollback to org_project;
2213 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
2214 END IF;
2215 ELSE
2216 l_prob_percent := 100;
2217 END IF;
2218 END IF;
2219
2220 IF (( l_pfi_organization_id IS NULL) /* First Iteration */ OR
2221 ( l_pfi_organization_id <>
2222 l_fi_organization_id_tab(i) OR
2223 l_pfi_project_organization_id <>
2224 l_fi_proj_organization_tab(i) OR
2225 l_pfi_project_org_id <>
2226 l_fi_proj_orgid_tab(i) OR
2227 l_pfi_exp_organization_id <>
2228 l_fi_exp_organization_id_tab(i) OR
2229 l_pfi_exp_org_id <>
2230 l_fi_exp_orgid_tab(i) OR
2231 l_pfi_txn_project_id <>
2232 l_fi_txn_project_id_tab(i) OR
2233 l_pfi_assignment_id <>
2234 l_fi_assignment_id_tab(i) OR
2235 l_pfi_resource_id <>
2236 l_fi_resource_id_tab(i))) THEN
2237
2238 l_stage := 5700;
2239 -- hr_utility.trace(to_char(l_stage));
2240
2241 l_fe_ctr := nvl(l_fe_forecast_element_id_tab.last+1,1);
2242 l_stage := 5800;
2243 -- hr_utility.trace(to_char(l_stage));
2244
2245 SELECT pa_org_fcst_elements_s.NEXTVAL
2246 INTO l_fe_new_seq
2247 FROM dual;
2248
2249 l_stage := 5900;
2250 -- hr_utility.trace(to_char(l_stage));
2251 l_fe_forecast_element_id_tab(l_fe_ctr) := l_fe_new_seq;
2252 l_fe_organization_id_tab(l_fe_ctr) := l_fi_organization_id_tab(i);
2253 l_fe_budget_version_id_tab(l_fe_ctr) := l_budget_version_id;
2254 l_fe_project_id_tab(l_fe_ctr) := l_project_id;
2255 l_fe_task_id_tab(l_fe_ctr) := l_own_task_id;
2256
2257 IF l_fi_exp_organization_id_tab(i) =
2258 l_fi_organization_id_tab(i) THEN
2259 l_stage := 6000;
2260 -- hr_utility.trace(to_char(l_stage));
2261 l_fe_pvdr_rcvr_code_tab(l_fe_ctr) := 'P';
2262 l_fe_other_organization_id_tab(l_fe_ctr)
2263 := l_fi_proj_organization_tab(i);
2264 l_fe_other_org_id_tab(l_fe_ctr)
2265 := l_fi_proj_orgid_tab(i);
2266 l_fe_org_id_tab(l_fe_ctr)
2267 := l_fi_exp_orgid_tab(i);
2268 ELSE
2269 l_stage := 6100;
2270 -- hr_utility.trace(to_char(l_stage));
2271 l_fe_pvdr_rcvr_code_tab(l_fe_ctr) := 'R';
2272 l_fe_other_organization_id_tab(l_fe_ctr)
2273 := l_fi_exp_organization_id_tab(i);
2274 l_fe_other_org_id_tab(l_fe_ctr)
2275 := l_fi_exp_orgid_tab(i);
2276 l_fe_org_id_tab(l_fe_ctr)
2277 := l_fi_proj_orgid_tab(i);
2278 END IF;
2279 l_stage := 6200;
2280 -- hr_utility.trace(to_char(l_stage));
2281 l_fe_txn_project_id_tab(l_fe_ctr) := l_fi_txn_project_id_tab(i);
2282 l_fe_assignment_id_tab(l_fe_ctr) := l_fi_assignment_id_tab(i);
2283 l_fe_resource_id_tab(l_fe_ctr) := l_fi_resource_id_tab(i);
2284
2285 l_fl_ctr := nvl(l_fl_forecast_line_id_tab.last+1,1);
2286 l_stage := 6300;
2287 -- hr_utility.trace(to_char(l_stage));
2288 SELECT pa_org_forecast_lines_s.NEXTVAL
2289 INTO l_fl_new_seq
2290 FROM DUAL;
2291
2292 l_stage := 6400;
2293 -- hr_utility.trace(to_char(l_stage));
2294
2295 -- hr_utility.trace('FECounter=> '||l_fe_ctr);
2296 -- hr_utility.trace('FE ID => '||to_char(l_fe_forecast_element_id_tab(l_fe_ctr)));
2297 -- hr_utility.trace('Org Id => '||to_char(l_fe_organization_id_tab(l_fe_ctr)));
2298 -- hr_utility.trace('BV Id => '||to_char(l_fe_budget_version_id_tab(l_fe_ctr)));
2299 -- hr_utility.trace('Proj Id => '||to_char(l_fe_project_id_tab(l_fe_ctr)));
2300 -- hr_utility.trace('Task Id => '||to_char(l_fe_task_id_tab(l_fe_ctr)));
2301 -- hr_utility.trace('PR => '||l_fe_pvdr_rcvr_code_tab(l_fe_ctr));
2302 -- hr_utility.trace('OOrg => '||to_char(l_fe_other_organization_id_tab(l_fe_ctr)));
2303 -- hr_utility.trace('Txn Proj => '||to_char(l_fe_txn_project_id_tab(l_fe_ctr)));
2304 -- hr_utility.trace('Asg Id => '||to_char(l_fe_assignment_id_tab(l_fe_ctr)));
2305 -- hr_utility.trace('ResId => '||to_char(l_fe_resource_id_tab(l_fe_ctr)));
2306
2307 l_fl_forecast_line_id_tab(l_fl_ctr) := l_fl_new_seq;
2308 l_fl_forecast_element_id_tab(l_fl_ctr) := l_fe_new_seq;
2309 l_fl_budget_version_id_tab(l_fl_ctr) := l_budget_version_id;
2310 l_fl_project_id_tab(l_fl_ctr) := l_project_id;
2311 l_fl_task_id_tab(l_fl_ctr) := l_own_task_id;
2312 l_fl_period_name_tab(l_fl_ctr) := l_fi_period_name_tab(i);
2313 l_fl_start_date_tab(l_fl_ctr) := l_fi_start_date_tab(i);
2314 l_fl_end_date_tab(l_fl_ctr) := l_fi_end_date_tab(i);
2315 l_fl_quantity_tab(l_fl_ctr) := l_fi_item_quantity_tab(i);
2316 l_fl_raw_cost_tab(l_fl_ctr) := (l_fi_raw_cost_tab(i)
2317 *l_prob_percent)/ 100;
2318 l_fl_burdened_cost_tab(l_fl_ctr) := (l_fi_burdened_cost_tab(i)
2319 *l_prob_percent)/ 100;
2320 l_fl_tp_cost_in_tab(l_fl_ctr) := (l_fi_tp_cost_in_tab(i)
2321 *l_prob_percent)/ 100;
2322 l_fl_tp_cost_out_tab(l_fl_ctr) := (l_fi_tp_cost_out_tab(i)
2323 *l_prob_percent)/ 100;
2324 l_fl_revenue_tab(l_fl_ctr) := (l_fi_revenue_tab(i)*l_prob_percent)/
2325 100;
2326 l_fl_tp_rev_in_tab(l_fl_ctr) := (l_fi_tp_rev_in_tab(i)
2327 *l_prob_percent)/ 100;
2328 l_fl_tp_rev_out_tab(l_fl_ctr) := (l_fi_tp_rev_out_tab(i)
2329 *l_prob_percent)/ 100;
2330 l_fl_borrowed_revenue_tab(l_fl_ctr) := (l_fi_borrowed_revenue_tab(i)
2331 *l_prob_percent)/ 100;
2332 l_fl_lent_resource_cost_tab(l_fl_ctr)
2333 := (l_fi_lent_resource_cost_tab(i)
2334 *l_prob_percent)/ 100;
2335 l_fl_unassigned_time_cost_tab(l_fl_ctr)
2336 := (l_fi_unassigned_time_cost_tab(i)
2337 *l_prob_percent)/ 100;
2338
2339 l_stage := 6500;
2340 -- hr_utility.trace(to_char(l_stage));
2341 -- hr_utility.trace('FLCounter=> '||l_fl_ctr);
2342 -- hr_utility.trace('FLId => '||to_char(l_fl_forecast_line_id_tab(l_fl_ctr)));
2343 -- hr_utility.trace('FEId => '||to_char(l_fl_forecast_element_id_tab(l_fl_ctr)));
2344 -- hr_utility.trace('BVId => '||to_char(l_fl_budget_version_id_tab(l_fl_ctr)));
2345 -- hr_utility.trace('ProjId => '||to_char(l_fl_project_id_tab(l_fl_ctr)));
2346 -- hr_utility.trace('TaskId => '||to_char(l_fl_task_id_tab(l_fl_ctr)));
2347 -- hr_utility.trace('Period => '||l_fl_period_name_tab(l_fl_ctr));
2348 -- hr_utility.trace('StartDt => '||l_fl_start_date_tab(l_fl_ctr));
2349 -- hr_utility.trace('EndDt => '||l_fl_end_date_tab(l_fl_ctr));
2350 -- hr_utility.trace('Qty => '||to_char(l_fl_quantity_tab(l_fl_ctr)));
2351 -- hr_utility.trace('Raw => '||to_char(l_fl_raw_cost_tab(l_fl_ctr)));
2352 -- hr_utility.trace('BurCost => '||to_char(l_fl_burdened_cost_tab(l_fl_ctr)));
2353 -- hr_utility.trace('CostIn => '||to_char(l_fl_tp_cost_in_tab(l_fl_ctr)));
2354 -- hr_utility.trace('CostOut => '||to_char(l_fl_tp_cost_out_tab(l_fl_ctr)));
2355 -- hr_utility.trace('Rev => '||to_char(l_fl_revenue_tab(l_fl_ctr)));
2356 -- hr_utility.trace('RevIn => '||to_char(l_fl_tp_rev_in_tab(l_fl_ctr)));
2357 -- hr_utility.trace('RevOut => '||to_char(l_fl_tp_rev_out_tab(l_fl_ctr)));
2358 -- hr_utility.trace('BorRev => '||to_char(l_fl_borrowed_revenue_tab(l_fl_ctr)));
2359 -- hr_utility.trace('LentCost => '||to_char(l_fl_lent_resource_cost_tab(l_fl_ctr)));
2360 -- hr_utility.trace('TimeCost => '||to_char(l_fl_unassigned_time_cost_tab(l_fl_ctr)));
2361 ELSE
2362
2363 l_stage := 6600;
2364 -- hr_utility.trace(to_char(l_stage));
2365 l_fl_ctr := nvl(l_fl_forecast_line_id_tab.last+1,1);
2366 SELECT pa_org_forecast_lines_s.NEXTVAL
2367 INTO l_fl_new_seq
2368 FROM DUAL;
2369 l_stage := 6700;
2370 -- hr_utility.trace(to_char(l_stage));
2371
2372 l_fl_forecast_line_id_tab(l_fl_ctr) := l_fl_new_seq;
2373 l_fl_forecast_element_id_tab(l_fl_ctr) := l_fe_new_seq;
2374 l_fl_budget_version_id_tab(l_fl_ctr) := l_budget_version_id;
2375 l_fl_project_id_tab(l_fl_ctr) := l_project_id;
2376 l_fl_task_id_tab(l_fl_ctr) := l_own_task_id;
2377 l_fl_period_name_tab(l_fl_ctr) := l_fi_period_name_tab(i);
2378 l_fl_start_date_tab(l_fl_ctr) := l_fi_start_date_tab(i);
2379 l_fl_end_date_tab(l_fl_ctr) := l_fi_end_date_tab(i);
2380 l_fl_quantity_tab(l_fl_ctr) := l_fi_item_quantity_tab(i);
2381 l_fl_raw_cost_tab(l_fl_ctr) := (l_fi_raw_cost_tab(i)
2382 *l_prob_percent)/ 100;
2383 l_fl_burdened_cost_tab(l_fl_ctr) := (l_fi_burdened_cost_tab(i)
2384 *l_prob_percent)/ 100;
2385 l_fl_tp_cost_in_tab(l_fl_ctr) := (l_fi_tp_cost_in_tab(i)
2386 *l_prob_percent)/ 100;
2387 l_fl_tp_cost_out_tab(l_fl_ctr) := (l_fi_tp_cost_out_tab(i)
2388 *l_prob_percent)/ 100;
2389 l_fl_revenue_tab(l_fl_ctr) := (l_fi_revenue_tab(i)*l_prob_percent)/
2390 100;
2391 l_fl_tp_rev_in_tab(l_fl_ctr) := (l_fi_tp_rev_in_tab(i)
2392 *l_prob_percent)/ 100;
2393 l_fl_tp_rev_out_tab(l_fl_ctr) := (l_fi_tp_rev_out_tab(i)
2394 *l_prob_percent)/ 100;
2395 l_fl_borrowed_revenue_tab(l_fl_ctr) := (l_fi_borrowed_revenue_tab(i)
2396 *l_prob_percent)/ 100;
2397 l_fl_lent_resource_cost_tab(l_fl_ctr)
2398 := (l_fi_lent_resource_cost_tab(i)
2399 *l_prob_percent)/ 100;
2400 l_fl_unassigned_time_cost_tab(l_fl_ctr)
2401 := (l_fi_unassigned_time_cost_tab(i)
2402 *l_prob_percent)/ 100;
2403
2404 l_stage := 6800;
2405 -- hr_utility.trace(to_char(l_stage));
2406 -- hr_utility.trace('FLCounter=> '||l_fl_ctr);
2407 -- hr_utility.trace('FLId => '||to_char(l_fl_forecast_line_id_tab(l_fl_ctr)));
2408 -- hr_utility.trace('FEId => '||to_char(l_fl_forecast_element_id_tab(l_fl_ctr)));
2409 -- hr_utility.trace('BVId => '||to_char(l_fl_budget_version_id_tab(l_fl_ctr)));
2410 -- hr_utility.trace('ProjId => '||to_char(l_fl_project_id_tab(l_fl_ctr)));
2411 -- hr_utility.trace('TaskId => '||to_char(l_fl_task_id_tab(l_fl_ctr)));
2412 -- hr_utility.trace('Period => '||l_fl_period_name_tab(l_fl_ctr));
2413 -- hr_utility.trace('StartDt => '||l_fl_start_date_tab(l_fl_ctr));
2414 -- hr_utility.trace('EndDt => '||l_fl_end_date_tab(l_fl_ctr));
2415 -- hr_utility.trace('Qty => '||to_char(l_fl_quantity_tab(l_fl_ctr)));
2416 -- hr_utility.trace('Raw => '||to_char(l_fl_raw_cost_tab(l_fl_ctr)));
2417 -- hr_utility.trace('BurCost => '||to_char(l_fl_burdened_cost_tab(l_fl_ctr)));
2418 -- hr_utility.trace('CostIn => '||to_char(l_fl_tp_cost_in_tab(l_fl_ctr)));
2419 -- hr_utility.trace('CostOut => '||to_char(l_fl_tp_cost_out_tab(l_fl_ctr)));
2420 -- hr_utility.trace('Rev => '||to_char(l_fl_revenue_tab(l_fl_ctr)));
2421 -- hr_utility.trace('RevIn => '||to_char(l_fl_tp_rev_in_tab(l_fl_ctr)));
2422 -- hr_utility.trace('RevOut => '||to_char(l_fl_tp_rev_out_tab(l_fl_ctr)));
2423 -- hr_utility.trace('BorRev => '||to_char(l_fl_borrowed_revenue_tab(l_fl_ctr)));
2424 -- hr_utility.trace('LentCost => '||to_char(l_fl_lent_resource_cost_tab(l_fl_ctr)));
2425 -- hr_utility.trace('TimeCost => '||to_char(l_fl_unassigned_time_cost_tab(l_fl_ctr)));
2426 END IF;
2427
2428 l_stage := 6900;
2429 -- hr_utility.trace(to_char(l_stage));
2430
2431 l_pfi_organization_id := l_fi_organization_id_tab(i);
2432 l_pfi_project_organization_id :=
2433 l_fi_proj_organization_tab(i);
2434 l_pfi_project_org_id :=
2435 l_fi_proj_orgid_tab(i);
2436 l_pfi_exp_organization_id :=
2437 l_fi_exp_organization_id_tab(i);
2438 l_pfi_exp_org_id :=
2439 l_fi_exp_orgid_tab(i);
2440 l_pfi_txn_project_id := l_fi_txn_project_id_tab(i);
2441 l_pfi_assignment_id := l_fi_assignment_id_tab(i);
2442 l_pfi_resource_id := l_fi_resource_id_tab(i);
2443
2444 l_stage := 7000;
2445 -- hr_utility.trace(to_char(l_stage));
2446
2447 EXCEPTION
2448 WHEN pa_fp_org_fcst_gen_pub.proj_action_reloop THEN
2449 -- hr_utility.trace('UserDefined Txn Project Skipping - '||to_char(l_stage)||'-'||SQLERRM);
2450 pa_debug.g_err_stage := l_stage||': UserDefined Txn Project Skipping - '||'['||SQLERRM||']';
2451 IF P_PA_DEBUG_MODE = 'Y' THEN
2452 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2453 END IF;
2454 NULL;
2455 END;
2456 END LOOP; -- l_fi_organization_id_tab
2457
2458
2459 l_stage := 7100;
2460 -- hr_utility.trace(to_char(l_stage));
2461
2462 /* Bulk Insert into Forecast Elements */
2463 pa_debug.g_err_stage := l_stage||': fe_count = ['||l_fe_forecast_element_id_tab.count||']';
2464 IF P_PA_DEBUG_MODE = 'Y' THEN
2465 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2466 END IF;
2467
2468 IF l_fe_forecast_element_id_tab.count > 0 THEN
2469 l_stage := 7200;
2470 -- hr_utility.trace(to_char(l_stage));
2471
2472
2473 FORALL i in l_fe_forecast_element_id_tab.first..l_fe_forecast_element_id_tab.last
2474 INSERT INTO pa_org_fcst_elements
2475 ( forecast_element_id
2476 ,organization_id
2477 ,org_id
2478 ,budget_version_id
2479 ,project_id
2480 ,task_id
2481 ,provider_receiver_code
2482 ,other_organization_id
2483 ,other_org_id
2484 ,txn_project_id
2485 ,assignment_id
2486 ,resource_id
2487 ,record_version_number
2488 ,creation_date
2489 ,created_by
2490 ,last_update_login
2491 ,last_updated_by
2492 ,last_update_date
2493 ) VALUES (
2494 l_fe_forecast_element_id_tab(i)
2495 ,l_fe_organization_id_tab(i)
2496 ,l_fe_org_id_tab(i)
2497 ,l_fe_budget_version_id_tab(i)
2498 ,l_fe_project_id_tab(i)
2499 ,l_fe_task_id_tab(i)
2500 ,l_fe_pvdr_rcvr_code_tab(i)
2501 ,l_fe_other_organization_id_tab(i)
2502 ,l_fe_other_org_id_tab(i)
2503 ,l_fe_txn_project_id_tab(i)
2504 ,l_fe_assignment_id_tab(i)
2505 ,l_fe_resource_id_tab(i)
2506 ,1
2507 ,sysdate
2508 ,fnd_global.user_id
2509 ,fnd_global.login_id
2510 ,fnd_global.user_id
2511 ,sysdate);
2512
2513 l_records_affected := SQL%ROWCOUNT;
2514
2515 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2516 ': After Inserting Forecast Elements' ;
2517 IF P_PA_DEBUG_MODE = 'Y' THEN
2518 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2519 END IF;
2520
2521 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2522 ': Inserted [' || TO_CHAR(l_records_affected) ||
2523 '] Forecast Elements.';
2524 IF P_PA_DEBUG_MODE = 'Y' THEN
2525 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2526 END IF;
2527 l_stage := 7300;
2528 -- hr_utility.trace(to_char(l_stage));
2529 END IF;
2530
2531 /* Bulk Insert into Forecast Lines */
2532 l_stage := 7400;
2533 -- hr_utility.trace(to_char(l_stage));
2534
2535 pa_debug.g_err_stage := l_stage||': fl_count = ['||l_fl_forecast_line_id_tab.count||']';
2536 IF P_PA_DEBUG_MODE = 'Y' THEN
2537 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2538 END IF;
2539
2540 IF l_fl_forecast_line_id_tab.count > 0 THEN
2541 FORALL j in l_fl_forecast_line_id_tab.first..l_fl_forecast_line_id_tab.last
2542 INSERT INTO pa_org_forecast_lines
2543 ( forecast_line_id
2544 ,forecast_element_id
2545 ,budget_version_id
2546 ,project_id
2547 ,task_id
2548 ,period_name
2549 ,start_date
2550 ,end_date
2551 ,quantity
2552 ,raw_cost
2553 ,burdened_cost
2554 ,tp_cost_in
2555 ,tp_cost_out
2556 ,revenue
2557 ,tp_revenue_in
2558 ,tp_revenue_out
2559 ,borrowed_revenue
2560 ,lent_resource_cost
2561 ,unassigned_time_cost
2562 ,record_version_number
2563 ,creation_date
2564 ,created_by
2565 ,last_update_login
2566 ,last_updated_by
2567 ,last_update_date
2568 ) VALUES (
2569 l_fl_forecast_line_id_tab(j)
2570 ,l_fl_forecast_element_id_tab(j)
2571 ,l_fl_budget_version_id_tab(j)
2572 ,l_fl_project_id_tab(j)
2573 ,l_fl_task_id_tab(j)
2574 ,l_fl_period_name_tab(j)
2575 ,l_fl_start_date_tab(j)
2576 ,l_fl_end_date_tab(j)
2577 ,l_fl_quantity_tab(j)
2578 ,l_fl_raw_cost_tab(j)
2579 ,l_fl_burdened_cost_tab(j)
2580 ,l_fl_tp_cost_in_tab(j)
2581 ,l_fl_tp_cost_out_tab(j)
2582 ,l_fl_revenue_tab(j)
2583 ,l_fl_tp_rev_in_tab(j)
2584 ,l_fl_tp_rev_out_tab(j)
2585 ,l_fl_borrowed_revenue_tab(j)
2586 ,l_fl_lent_resource_cost_tab(j)
2587 ,l_fl_unassigned_time_cost_tab(j)
2588 ,1
2589 ,sysdate
2590 ,fnd_global.user_id
2591 ,fnd_global.login_id
2592 ,fnd_global.user_id
2593 ,sysdate);
2594
2595 l_records_affected := SQL%ROWCOUNT;
2596
2597 l_stage := 7500;
2598 -- hr_utility.trace(to_char(l_stage));
2599 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2600 ': After Inserting Forecast Lines' ;
2601 IF P_PA_DEBUG_MODE = 'Y' THEN
2602 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2603 END IF;
2604
2605 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2606 ': Inserted [' || TO_CHAR(l_records_affected) ||
2607 '] Forecast Lines.';
2608 IF P_PA_DEBUG_MODE = 'Y' THEN
2609 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2610 END IF;
2611
2612 END IF;
2613
2614 l_stage := 7600;
2615 -- hr_utility.trace(to_char(l_stage));
2616
2617 DELETE FROM pa_fin_plan_lines_tmp;
2618
2619 l_stage := 7700;
2620 -- hr_utility.trace(to_char(l_stage));
2621
2622 pa_debug.g_err_stage := l_stage||': fl_count = ['
2623 ||l_fl_forecast_line_id_tab.count||']';
2624 IF P_PA_DEBUG_MODE = 'Y' THEN
2625 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2626 END IF;
2627
2628 IF l_fl_forecast_line_id_tab.count > 0 THEN
2629 FORALL j in l_fl_forecast_line_id_tab.first..l_fl_forecast_line_id_tab.last
2630 INSERT INTO pa_fin_plan_lines_tmp
2631 ( resource_assignment_id
2632 ,object_id
2633 ,object_type_code
2634 ,period_name
2635 ,start_date
2636 ,end_date
2637 ,currency_type
2638 ,currency_code
2639 ,source_txn_currency_code /* Bug 2796261 */
2640 ,quantity
2641 ,raw_cost
2642 ,burdened_cost
2643 ,tp_cost_in
2644 ,tp_cost_out
2645 ,lent_resource_cost
2646 ,unassigned_time_cost
2647 ,cost_adj
2648 ,revenue
2649 ,borrowed_revenue
2650 ,tp_revenue_in
2651 ,tp_revenue_out
2652 ,revenue_adj
2653 ,utilization_percent
2654 ,utilization_adj
2655 ,utilization_hours
2656 ,capacity
2657 ,head_count
2658 ,head_count_adj
2659 ,margin
2660 ,margin_percentage)
2661 SELECT
2662 -1
2663 ,l_fl_forecast_element_id_tab(j)
2664 ,'FCST_ELEMENTS'
2665 ,l_fl_period_name_tab(j)
2666 ,l_fl_start_date_tab(j)
2667 ,l_fl_end_date_tab(j)
2668 ,'PROJ_FUNCTIONAL'
2669 ,l_org_projfunc_currency_code
2670 ,l_org_projfunc_currency_code /* 2796261 */
2671 ,l_fl_quantity_tab(j)
2672 ,l_fl_raw_cost_tab(j)
2673 ,l_fl_burdened_cost_tab(j)
2674 ,l_fl_tp_cost_in_tab(j)
2675 ,l_fl_tp_cost_out_tab(j)
2676 ,l_fl_lent_resource_cost_tab(j)
2677 ,l_fl_unassigned_time_cost_tab(j)
2678 ,0
2679 ,l_fl_revenue_tab(j)
2680 ,l_fl_borrowed_revenue_tab(j)
2681 ,l_fl_tp_rev_in_tab(j)
2682 ,l_fl_tp_rev_out_tab(j)
2683 ,0
2684 ,0
2685 ,0
2686 ,0
2687 ,0
2688 ,0
2689 ,0
2690 ,DECODE(SIGN(
2691 l_fl_revenue_tab(j)+
2692 l_fl_borrowed_revenue_tab(j)+
2693 l_fl_tp_rev_in_tab(j)-
2694 l_fl_tp_rev_out_tab(j)),0,0,-1,0,
2695 (l_fl_revenue_tab(j)+
2696 l_fl_borrowed_revenue_tab(j)+
2697 l_fl_tp_rev_in_tab(j)-
2698 l_fl_tp_rev_out_tab(j)) -
2699 (l_fl_burdened_cost_tab(j)+
2700 l_fl_lent_resource_cost_tab(j)+
2701 l_fl_unassigned_time_cost_tab(j)+
2702 l_fl_tp_cost_in_tab(j)-
2703 l_fl_tp_cost_out_tab(j)))
2704 ,DECODE(SIGN(
2705 l_fl_revenue_tab(j)+
2706 l_fl_borrowed_revenue_tab(j)+
2707 l_fl_tp_rev_in_tab(j)-
2708 l_fl_tp_rev_out_tab(j)),0,0,-1,0,
2709 ((l_fl_revenue_tab(j)+
2710 l_fl_borrowed_revenue_tab(j)+
2711 l_fl_tp_rev_in_tab(j)-
2712 l_fl_tp_rev_out_tab(j)) -
2713 (l_fl_burdened_cost_tab(j)+
2714 l_fl_lent_resource_cost_tab(j)+
2715 l_fl_unassigned_time_cost_tab(j)+
2716 l_fl_tp_cost_in_tab(j)-
2717 l_fl_tp_cost_out_tab(j)))/
2718 (l_fl_revenue_tab(j)+
2719 l_fl_borrowed_revenue_tab(j)+
2720 l_fl_tp_rev_in_tab(j)-
2721 l_fl_tp_rev_out_tab(j)) * 100)
2722 FROM DUAL;
2723
2724 l_stage := 7800;
2725 -- hr_utility.trace(to_char(l_stage));
2726 l_records_affected := SQL%ROWCOUNT;
2727
2728 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2729 ': After Inserting Fin Plan Lines Tmp' ;
2730 IF P_PA_DEBUG_MODE = 'Y' THEN
2731 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2732 END IF;
2733
2734 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2735 ': Inserted [' || TO_CHAR(l_records_affected) ||
2736 '] Fin Plan Lines Tmp.';
2737 IF P_PA_DEBUG_MODE = 'Y' THEN
2738 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2739 END IF;
2740
2741 /* Populate Project Periods Denorm for Forecast Lines */
2742
2743 l_stage := 7900;
2744 -- hr_utility.trace(to_char(l_stage));
2745 Pa_Plan_Matrix.Maintain_Plan_Matrix
2746 ( p_amount_type_tab => amt_rec
2747 ,p_period_profile_id => l_period_profile_id
2748 ,p_prior_period_flag => 'N'
2749 ,p_commit_Flag => 'N'
2750 ,p_budget_version_id => l_budget_version_id
2751 ,p_project_id => l_project_id
2752 ,p_debug_mode => l_debug_mode
2753 ,p_add_msg_in_stack => 'Y'
2754 ,x_return_status => l_return_status
2755 ,x_msg_count => l_msg_count
2756 ,x_msg_data => errbuff );
2757
2758 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2759 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2760 ': Error creating Period Denorm';
2761 IF P_PA_DEBUG_MODE = 'Y' THEN
2762 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2763 END IF;
2764 pa_debug.g_err_stage := 'l_period_profile_id ['||l_period_profile_id || ']';
2765 IF P_PA_DEBUG_MODE = 'Y' THEN
2766 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2767 END IF;
2768 pa_debug.g_err_stage := 'l_budget_version_id ['||l_budget_version_id || ']';
2769 IF P_PA_DEBUG_MODE = 'Y' THEN
2770 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2771 END IF;
2772 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
2773 IF P_PA_DEBUG_MODE = 'Y' THEN
2774 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2775 END IF;
2776 rollback to org_project;
2777 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
2778 END IF;
2779
2780 END IF;
2781
2782 l_stage := 8000;
2783 -- hr_utility.trace(to_char(l_stage));
2784
2785 /* For forecast items */
2786 l_fi_organization_id_tab.delete;
2787 l_fi_proj_organization_tab.delete;
2788 l_fi_proj_orgid_tab.delete;
2789 l_fi_exp_organization_id_tab.delete;
2790 l_fi_exp_orgid_tab.delete;
2791 l_fi_txn_project_id_tab.delete;
2792 l_fi_assignment_id_tab.delete;
2793 l_fi_resource_id_tab.delete;
2794 l_fi_period_name_tab.delete;
2795 l_fi_start_date_tab.delete;
2796 l_fi_end_date_tab.delete;
2797 l_fi_item_quantity_tab.delete;
2798 l_fi_raw_cost_tab.delete;
2799 l_fi_burdened_cost_tab.delete;
2800 l_fi_tp_cost_in_tab.delete;
2801 l_fi_tp_cost_out_tab.delete;
2802 l_fi_revenue_tab.delete;
2803 l_fi_tp_rev_in_tab.delete;
2804 l_fi_tp_rev_out_tab.delete;
2805 l_fi_borrowed_revenue_tab.delete;
2806 l_fi_lent_resource_cost_tab.delete;
2807 l_fi_unassigned_time_cost_tab.delete;
2808
2809 /* Forecast Element PL/SQL Tables */
2810 l_fe_forecast_element_id_tab.delete;
2811 l_fe_organization_id_tab.delete;
2812 l_fe_org_id_tab.delete;
2813 l_fe_budget_version_id_tab.delete;
2814 l_fe_project_id_tab.delete;
2815 l_fe_task_id_tab.delete;
2816 l_fe_pvdr_rcvr_code_tab.delete;
2817 l_fe_other_organization_id_tab.delete;
2818 l_fe_other_org_id_tab.delete;
2819 l_fe_txn_project_id_tab.delete;
2820 l_fe_assignment_id_tab.delete;
2821 l_fe_resource_id_tab.delete;
2822
2823 /* Forecast Lines PL/SQL Tables */
2824 l_fl_forecast_line_id_tab.delete;
2825 l_fl_forecast_element_id_tab.delete;
2826 l_fl_budget_version_id_tab.delete;
2827 l_fl_project_id_tab.delete;
2828 l_fl_task_id_tab.delete;
2829 l_fl_period_name_tab.delete;
2830 l_fl_start_date_tab.delete;
2831 l_fl_end_date_tab.delete;
2832 l_fl_quantity_tab.delete;
2833 l_fl_raw_cost_tab.delete;
2834 l_fl_burdened_cost_tab.delete;
2835 l_fl_tp_cost_in_tab.delete;
2836 l_fl_tp_cost_out_tab.delete;
2837 l_fl_revenue_tab.delete;
2838 l_fl_tp_rev_in_tab.delete;
2839 l_fl_tp_rev_out_tab.delete;
2840 l_fl_borrowed_revenue_tab.delete;
2841 l_fl_lent_resource_cost_tab.delete;
2842 l_fl_unassigned_time_cost_tab.delete;
2843
2844 END LOOP; /* BULK FETCH OF FORECAST ITEMS */
2845 CLOSE forecast_items;
2846
2847 l_stage := 8100;
2848 -- hr_utility.trace(to_char(l_stage));
2849 pa_debug.g_err_stage := l_stage||': Populate amt_rec for Budget Lines Denorm';
2850 IF P_PA_DEBUG_MODE = 'Y' THEN
2851 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2852 END IF;
2853 /* Populate amt_rec for Budget Lines Denorm */
2854 amt_rec.delete;
2855
2856 amt_rec(1).amount_type_code := 'QUANTITY';
2857 amt_rec(1).amount_subtype_code := 'QUANTITY';
2858 amt_rec(1).amount_type_id := get_amttype_id(p_amt_typ_code => 'QUANTITY');
2859 amt_rec(1).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'QUANTITY');
2860
2861 amt_rec(2).amount_type_code := 'COST';
2862 amt_rec(2).amount_subtype_code := 'OWN_PROJECT_COST';
2863 amt_rec(2).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
2864 amt_rec(2).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'OWN_PROJECT_COST');
2865
2866 amt_rec(3).amount_type_code := 'COST';
2867 amt_rec(3).amount_subtype_code := 'TP_COST_IN';
2868 amt_rec(3).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
2869 amt_rec(3).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_COST_IN');
2870
2871 amt_rec(4).amount_type_code := 'COST';
2872 amt_rec(4).amount_subtype_code := 'TP_COST_OUT';
2873 amt_rec(4).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
2874 amt_rec(4).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_COST_OUT');
2875
2876 amt_rec(5).amount_type_code := 'COST';
2877 amt_rec(5).amount_subtype_code := 'LENT_RESOURCE_COST';
2878 amt_rec(5).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
2879 amt_rec(5).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'LENT_RESOURCE_COST');
2880
2881 amt_rec(6).amount_type_code := 'COST';
2882 amt_rec(6).amount_subtype_code := 'UNASSIGNED_TIME_COST';
2883 amt_rec(6).amount_type_id := get_amttype_id(p_amt_typ_code => 'COST');
2884 amt_rec(6).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'UNASSIGNED_TIME_COST');
2885
2886 amt_rec(7).amount_type_code := 'REVENUE';
2887 amt_rec(7).amount_subtype_code := 'OWN_REVENUE';
2888 amt_rec(7).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
2889 amt_rec(7).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'OWN_REVENUE');
2890
2891 amt_rec(8).amount_type_code := 'REVENUE';
2892 amt_rec(8).amount_subtype_code := 'BORROWED_REVENUE';
2893 amt_rec(8).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
2894 amt_rec(8).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'BORROWED_REVENUE');
2895
2896 amt_rec(9).amount_type_code := 'REVENUE';
2897 amt_rec(9).amount_subtype_code := 'TP_REVENUE_IN';
2898 amt_rec(9).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
2899 amt_rec(9).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_REVENUE_IN');
2900
2901 amt_rec(10).amount_type_code := 'REVENUE';
2902 amt_rec(10).amount_subtype_code := 'TP_REVENUE_OUT';
2903 amt_rec(10).amount_type_id := get_amttype_id(p_amt_typ_code => 'REVENUE');
2904 amt_rec(10).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'TP_REVENUE_OUT');
2905
2906 amt_rec(11).amount_type_code := 'MARGIN';
2907 amt_rec(11).amount_subtype_code := 'MARGIN';
2908 amt_rec(11).amount_type_id := get_amttype_id(p_amt_typ_code => 'MARGIN');
2909 amt_rec(11).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'MARGIN');
2910
2911 amt_rec(12).amount_type_code := 'MARGIN_PERCENT';
2912 amt_rec(12).amount_subtype_code := 'MARGIN_PERCENT';
2913 amt_rec(12).amount_type_id := get_amttype_id(p_amt_typ_code => 'MARGIN_PERCENT');
2914 amt_rec(12).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'MARGIN_PERCENT');
2915
2916 amt_rec(13).amount_type_code := 'UTILIZATION';
2917 amt_rec(13).amount_subtype_code := 'UTILIZATION_PERCENT';
2918 amt_rec(13).amount_type_id := get_amttype_id(p_amt_typ_code => 'UTILIZATION');
2919 amt_rec(13).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'UTILIZATION_PERCENT');
2920
2921 /*
2922 amt_rec(14).amount_type_code := 'UTILIZATION';
2923 amt_rec(14).amount_subtype_code := 'UTILIZATION_HOURS';
2924 amt_rec(14).amount_type_id := get_amttype_id(p_amt_typ_code => 'UTILIZATION');
2925 amt_rec(14).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'UTILIZATION_HOURS');
2926
2927 amt_rec(15).amount_type_code := 'UTILIZATION';
2928 amt_rec(15).amount_subtype_code := 'CAPACITY';
2929 amt_rec(15).amount_type_id := get_amttype_id(p_amt_typ_code => 'UTILIZATION');
2930 amt_rec(15).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'CAPACITY');
2931 */
2932
2933 amt_rec(14).amount_type_code := 'HEADCOUNT';
2934 amt_rec(14).amount_subtype_code := 'BEGIN_HEADCOUNT';
2935 amt_rec(14).amount_type_id := get_amttype_id(p_amt_typ_code => 'HEADCOUNT');
2936 amt_rec(14).amount_subtype_id := get_amttype_id(p_amt_typ_code => 'BEGIN_HEADCOUNT');
2937
2938 l_stage := 8200;
2939 -- hr_utility.trace(to_char(l_stage));
2940 pa_debug.g_err_stage := l_stage||': Create Resource Assignments for Own Task';
2941 IF P_PA_DEBUG_MODE = 'Y' THEN
2942 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2943 END IF;
2944 /* Create Resource Assignments for Own Task */
2945
2946 l_own_resource_assignment_id := NULL;
2947
2948 pa_fp_resource_assignments_pkg.Insert_Row
2949 ( px_resource_assignment_id => l_own_resource_assignment_id
2950 ,p_budget_version_id => l_budget_version_id
2951 ,p_project_id => l_project_id
2952 ,p_task_id => l_own_task_id
2953 ,p_resource_list_member_id => l_resource_list_member_id
2954 ,p_unit_of_measure => 'HOURS'
2955 ,p_track_as_labor_flag => 'Y'
2956 ,p_standard_bill_rate => Null
2957 ,p_average_bill_rate => Null
2958 ,p_average_cost_rate => Null
2959 ,p_project_assignment_id => -1
2960 ,p_plan_error_code => Null
2961 ,p_total_plan_revenue => 0
2962 ,p_total_plan_raw_cost => 0
2963 ,p_total_plan_burdened_cost => 0
2964 ,p_total_plan_quantity => 0
2965 ,p_average_discount_percentage => Null
2966 ,p_total_borrowed_revenue => 0
2967 ,p_total_tp_revenue_in => 0
2968 ,p_total_tp_revenue_out => 0
2969 ,p_total_revenue_adj => 0
2970 ,p_total_lent_resource_cost => 0
2971 ,p_total_tp_cost_in => 0
2972 ,p_total_tp_cost_out => 0
2973 ,p_total_cost_adj => 0
2974 ,p_total_unassigned_time_cost => 0
2975 ,p_total_utilization_percent => 0
2976 ,p_total_utilization_hours => 0
2977 ,p_total_utilization_adj => 0
2978 ,p_total_capacity => 0
2979 ,p_total_head_count => 0
2980 ,p_total_head_count_adj => 0
2981 ,p_resource_assignment_type => 'OWN'
2982 ,x_row_id => l_row_id
2983 ,x_return_status => l_return_status );
2984
2985 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2986 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
2987 ': Error creating Resource Assignment';
2988 IF P_PA_DEBUG_MODE = 'Y' THEN
2989 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2990 END IF;
2991 pa_debug.g_err_stage := 'l_budget_version_id ['||l_budget_version_id || ']';
2992 IF P_PA_DEBUG_MODE = 'Y' THEN
2993 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2994 END IF;
2995 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
2996 IF P_PA_DEBUG_MODE = 'Y' THEN
2997 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
2998 END IF;
2999 pa_debug.g_err_stage := 'l_own_task_id ['||l_own_task_id || ']';
3000 IF P_PA_DEBUG_MODE = 'Y' THEN
3001 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3002 END IF;
3003 pa_debug.g_err_stage := 'l_resource_list_member_id['||l_resource_list_member_id|| ']';
3004 IF P_PA_DEBUG_MODE = 'Y' THEN
3005 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3006 END IF;
3007 rollback to org_project;
3008 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
3009 END IF;
3010
3011 l_stage := 8300;
3012 -- hr_utility.trace(to_char(l_stage));
3013
3014 l_bl_budget_version_id_tab.delete; /* FPB2: budget_version_id */
3015 l_bl_res_asg_id_tab.delete;
3016 l_bl_start_date_tab.delete;
3017 l_bl_end_date_tab.delete;
3018 l_bl_period_name_tab.delete;
3019 l_bl_quantity_tab.delete;
3020 l_bl_raw_cost_tab.delete;
3021 l_bl_burdened_cost_tab.delete;
3022 l_bl_revenue_tab.delete;
3023 l_bl_borrowed_revenue_tab.delete;
3024 l_bl_tp_revenue_in_tab.delete;
3025 l_bl_tp_revenue_out_tab.delete;
3026 l_bl_lent_resource_cost_tab.delete;
3027 l_bl_tp_cost_in_tab.delete;
3028 l_bl_tp_cost_out_tab.delete;
3029 l_bl_unassigned_time_cost_tab.delete;
3030 l_bl_utilization_percent_tab.delete;
3031 l_bl_utilization_hours_tab.delete;
3032 l_bl_capacity_tab.delete;
3033 l_bl_head_count_tab.delete;
3034
3035 IF NOT fl_lines_task%ISOPEN THEN
3036 OPEN fl_lines_task;
3037 ELSE
3038 CLOSE fl_lines_task;
3039 OPEN fl_lines_task;
3040 END IF;
3041
3042 l_stage := 8400;
3043 -- hr_utility.trace(to_char(l_stage));
3044
3045 FETCH fl_lines_task BULK COLLECT INTO
3046 l_bl_budget_version_id_tab /* FPB2: budget_version_id */
3047 ,l_bl_res_asg_id_tab
3048 ,l_bl_period_name_tab
3049 ,l_bl_start_date_tab
3050 ,l_bl_end_date_tab
3051 ,l_bl_quantity_tab
3052 ,l_bl_raw_cost_tab
3053 ,l_bl_burdened_cost_tab
3054 ,l_bl_revenue_tab
3055 ,l_bl_borrowed_revenue_tab
3056 ,l_bl_tp_revenue_in_tab
3057 ,l_bl_tp_revenue_out_tab
3058 ,l_bl_lent_resource_cost_tab
3059 ,l_bl_tp_cost_in_tab
3060 ,l_bl_tp_cost_out_tab
3061 ,l_bl_unassigned_time_cost_tab;
3062
3063
3064 l_stage := 8500;
3065 -- hr_utility.trace(to_char(l_stage));
3066
3067 IF NVL(l_bl_res_asg_id_tab.count,0) =0 THEN
3068 l_stage := 8600;
3069 -- hr_utility.trace(to_char(l_stage));
3070 pa_debug.g_err_stage := l_stage||': Exiting fl_lines_task loop no rows to process';
3071 IF P_PA_DEBUG_MODE = 'Y' THEN
3072 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3073 END IF;
3074 ELSE
3075
3076 FOR i in l_bl_res_asg_id_tab.first..l_bl_res_asg_id_tab.last LOOP
3077 l_stage := 8700;
3078 -- hr_utility.trace(to_char(l_stage));
3079
3080 /* API call changed from pa_fp_org_fcst_utils.get_utilization_details
3081 to pa_pji_util_pkg.get_utilization_dtls to get the Utilization
3082 numbers from PJI data model if PJI is installed. */
3083
3084 pa_pji_util_pkg.get_utilization_dtls
3085 ( p_org_id => l_org_id
3086 ,p_organization_id => l_organization_id
3087 ,p_period_type => l_org_fcst_period_type
3088 ,p_period_set_name => l_period_set_name
3089 ,p_period_name => l_bl_period_name_tab(i)
3090 ,x_utl_hours => l_bl_utilization_hours_tab(i)
3091 ,x_utl_capacity => l_bl_capacity_tab(i)
3092 ,x_utl_percent => l_bl_utilization_percent_tab(i)
3093 ,x_return_status => l_return_status
3094 ,x_err_code => l_err_code);
3095
3096 -- hr_utility.trace(l_err_code);
3097
3098 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3099 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3100 ':Error getting utilization details'||'-'||l_err_code;
3101 IF P_PA_DEBUG_MODE = 'Y' THEN
3102 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3103 END IF;
3104 pa_debug.g_err_stage := 'l_org_id ['||l_org_id || ']';
3105 IF P_PA_DEBUG_MODE = 'Y' THEN
3106 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3107 END IF;
3108 pa_debug.g_err_stage := 'l_organization_id ['||l_organization_id || ']';
3109 IF P_PA_DEBUG_MODE = 'Y' THEN
3110 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3111 END IF;
3112 pa_debug.g_err_stage := 'l_org_fcst_period_type ['||l_org_fcst_period_type || ']';
3113 IF P_PA_DEBUG_MODE = 'Y' THEN
3114 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3115 END IF;
3116 pa_debug.g_err_stage := 'l_period_set_name ['||l_period_set_name || ']';
3117 IF P_PA_DEBUG_MODE = 'Y' THEN
3118 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3119 END IF;
3120 pa_debug.g_err_stage := 'l_bl_period_name_tab ['||l_bl_period_name_tab(i) || ']';
3121 IF P_PA_DEBUG_MODE = 'Y' THEN
3122 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3123 END IF;
3124 rollback to org_project;
3125 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
3126 END IF;
3127
3128 l_stage := 8800;
3129 -- hr_utility.trace(to_char(l_stage));
3130
3131 pa_fp_org_fcst_utils.get_headcount
3132 ( p_organization_id => l_organization_id
3133 ,p_effective_date => l_bl_start_date_tab(i)
3134 ,x_headcount => l_bl_head_count_tab(i)
3135 ,x_return_status => l_return_status
3136 ,x_err_code => l_err_code);
3137
3138 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3139 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3140 ':Error getting Head Count';
3141 IF P_PA_DEBUG_MODE = 'Y' THEN
3142 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3143 END IF;
3144 pa_debug.g_err_stage :=
3145 'l_organization_id ['||l_organization_id ||
3146 '] l_bl_start_date_tab ['||l_bl_start_date_tab(i) ||
3147 ']';
3148 IF P_PA_DEBUG_MODE = 'Y' THEN
3149 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3150 END IF;
3151 rollback to org_project;
3152 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
3153 END IF;
3154 l_stage := 8900;
3155 -- hr_utility.trace(to_char(l_stage));
3156 END LOOP;
3157 CLOSE fl_lines_task;
3158
3159 l_stage := 9000;
3160 -- hr_utility.trace(to_char(l_stage));
3161 pa_debug.g_err_stage := l_stage||': Create Budget Lines for Own Task';
3162 IF P_PA_DEBUG_MODE = 'Y' THEN
3163 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3164 END IF;
3165
3166 /* Bulk insert into Budget Lines for Own Numbers Phase I */
3167 IF l_bl_res_asg_id_tab.count > 0 THEN
3168 FORALL i in l_bl_res_asg_id_tab.first..l_bl_res_asg_id_tab.last
3169 INSERT INTO pa_budget_lines
3170 ( budget_line_id /* FPB2 */
3171 ,budget_version_id /* FPB2 */
3172 ,txn_currency_code /* FPB4 */
3173 ,resource_assignment_id
3174 ,period_name
3175 ,start_date
3176 ,end_date
3177 ,quantity
3178 ,raw_cost
3179 ,burdened_cost
3180 ,lent_resource_cost
3181 ,unassigned_time_cost
3182 ,tp_cost_in
3183 ,tp_cost_out
3184 ,revenue
3185 ,borrowed_revenue
3186 ,tp_revenue_in
3187 ,tp_revenue_out
3188 ,quantity_source
3189 ,raw_cost_source
3190 ,burdened_cost_source
3191 ,revenue_source
3192 ,utilization_percent
3193 ,utilization_hours
3194 ,capacity
3195 ,head_count
3196 ,creation_date
3197 ,created_by
3198 ,last_update_login
3199 ,last_updated_by
3200 ,last_update_date
3201 ) VALUES (
3202 pa_budget_lines_s.nextval /* FPB2 */
3203 ,l_bl_budget_version_id_tab(i) /* FPB2 */
3204 ,l_org_projfunc_currency_code /* FPB4 */
3205 ,l_bl_res_asg_id_tab(i)
3206 ,l_bl_period_name_tab(i)
3207 ,l_bl_start_date_tab(i)
3208 ,l_bl_end_date_tab(i)
3209 ,l_bl_quantity_tab(i)
3210 ,l_bl_raw_cost_tab(i)
3211 ,l_bl_burdened_cost_tab(i)
3212 ,l_bl_lent_resource_cost_tab(i)
3213 ,l_bl_unassigned_time_cost_tab(i)
3214 ,l_bl_tp_cost_in_tab(i)
3215 ,l_bl_tp_cost_out_tab(i)
3216 ,l_bl_revenue_tab(i)
3217 ,l_bl_borrowed_revenue_tab(i)
3218 ,l_bl_tp_revenue_in_tab(i)
3219 ,l_bl_tp_revenue_out_tab(i)
3220 ,'C'
3221 ,'C'
3222 ,'C'
3223 ,'C'
3224 ,l_bl_utilization_percent_tab(i)
3225 ,l_bl_utilization_hours_tab(i)
3226 ,l_bl_capacity_tab(i)
3227 ,l_bl_head_count_tab(i)
3228 ,sysdate
3229 ,fnd_global.user_id
3230 ,fnd_global.login_id
3231 ,fnd_global.user_id
3232 ,sysdate);
3233
3234 END IF;
3235 l_stage := 9100;
3236 -- hr_utility.trace(to_char(l_stage));
3237
3238 /* Need to update Own Level Resource Assignment
3239 from budget Lines */
3240
3241 SELECT nvl(sum(bl.quantity),0)
3242 ,nvl(sum(bl.raw_cost),0)
3243 ,nvl(sum(bl.burdened_cost),0)
3244 ,nvl(sum(bl.lent_resource_cost),0)
3245 ,nvl(sum(bl.unassigned_time_cost),0)
3246 ,nvl(sum(bl.tp_cost_in),0)
3247 ,nvl(sum(bl.tp_cost_out),0)
3248 ,nvl(sum(bl.revenue),0)
3249 ,nvl(sum(bl.borrowed_revenue),0)
3250 ,nvl(sum(bl.tp_revenue_in),0)
3251 ,nvl(sum(bl.tp_revenue_out),0)
3252 ,nvl(round(avg(bl.utilization_percent)),0)
3253 ,nvl(sum(bl.utilization_hours),0)
3254 ,nvl(sum(bl.capacity),0)
3255 ,nvl(round(avg(bl.head_count)),0)
3256 INTO budget_lines_rec(1).quantity
3257 ,budget_lines_rec(1).raw_cost
3258 ,budget_lines_rec(1).burdened_cost
3259 ,budget_lines_rec(1).lent_resource_cost
3260 ,budget_lines_rec(1).unassigned_time_cost
3261 ,budget_lines_rec(1).tp_cost_in
3262 ,budget_lines_rec(1).tp_cost_out
3263 ,budget_lines_rec(1).revenue
3264 ,budget_lines_rec(1).borrowed_revenue
3265 ,budget_lines_rec(1).tp_revenue_in
3266 ,budget_lines_rec(1).tp_revenue_out
3267 ,budget_lines_rec(1).utilization_percent
3268 ,budget_lines_rec(1).utilization_hours
3269 ,budget_lines_rec(1).capacity
3270 ,budget_lines_rec(1).head_count
3271 FROM pa_budget_lines bl
3272 WHERE bl.resource_assignment_id = l_own_resource_assignment_id;
3273
3274 l_stage := 9200;
3275 -- hr_utility.trace(to_char(l_stage));
3276
3277 IF budget_lines_rec.COUNT = 1 THEN
3278 l_stage := 9300;
3279 -- hr_utility.trace(to_char(l_stage));
3280 pa_debug.g_err_stage := l_stage||': Update Resource Assignments for Own Task';
3281 IF P_PA_DEBUG_MODE = 'Y' THEN
3282 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3283 END IF;
3284
3285 UPDATE pa_resource_assignments
3286 SET
3287 last_update_date = sysdate
3288 ,last_updated_by = fnd_global.user_id
3289 ,last_update_login = fnd_global.login_id
3290 ,total_plan_revenue = budget_lines_rec(1).revenue
3291 ,total_plan_raw_cost = budget_lines_rec(1).raw_cost
3292 ,total_plan_burdened_cost = budget_lines_rec(1).burdened_cost
3293 ,total_plan_quantity = budget_lines_rec(1).quantity
3294 ,total_borrowed_revenue = budget_lines_rec(1).borrowed_revenue
3295 ,total_tp_revenue_in = budget_lines_rec(1).tp_revenue_in
3296 ,total_tp_revenue_out = budget_lines_rec(1).tp_revenue_out
3297 ,total_lent_resource_cost = budget_lines_rec(1).lent_resource_cost
3298 ,total_tp_cost_in = budget_lines_rec(1).tp_cost_in
3299 ,total_tp_cost_out = budget_lines_rec(1).tp_cost_out
3300 ,total_unassigned_time_cost = budget_lines_rec(1).unassigned_time_cost
3301 ,total_utilization_percent = budget_lines_rec(1).utilization_percent
3302 ,total_utilization_hours = budget_lines_rec(1).utilization_hours
3303 ,total_capacity = budget_lines_rec(1).capacity
3304 ,total_head_count = budget_lines_rec(1).head_count
3305 WHERE resource_assignment_id = l_own_resource_assignment_id;
3306
3307 l_stage := 9400;
3308 -- hr_utility.trace(to_char(l_stage));
3309 END IF;
3310 l_stage := 9500;
3311 -- hr_utility.trace(to_char(l_stage));
3312
3313 budget_lines_rec.DELETE;
3314 DELETE FROM pa_fin_plan_lines_tmp;
3315
3316 l_stage := 9600;
3317 -- hr_utility.trace(to_char(l_stage));
3318
3319 FORALL i in l_bl_res_asg_id_tab.first..l_bl_res_asg_id_tab.last
3320 INSERT INTO pa_fin_plan_lines_tmp
3321 ( resource_assignment_id
3322 ,object_id
3323 ,object_type_code
3324 ,period_name
3325 ,start_date
3326 ,end_date
3327 ,currency_type
3328 ,currency_code
3329 ,source_txn_currency_code /* Bug 2796261 */
3330 ,quantity
3331 ,raw_cost
3332 ,burdened_cost
3333 ,tp_cost_in
3334 ,tp_cost_out
3335 ,lent_resource_cost
3336 ,unassigned_time_cost
3337 ,cost_adj
3338 ,revenue
3339 ,borrowed_revenue
3340 ,tp_revenue_in
3341 ,tp_revenue_out
3342 ,revenue_adj
3343 ,utilization_percent
3344 ,utilization_adj
3345 ,utilization_hours
3346 ,capacity
3347 ,head_count
3348 ,head_count_adj
3349 ,margin
3350 ,margin_percentage)
3351 SELECT
3352 l_bl_res_asg_id_tab(i)
3353 ,l_bl_res_asg_id_tab(i)
3354 ,'RES_ASSIGNMENT'
3355 ,l_bl_period_name_tab(i)
3356 ,l_bl_start_date_tab(i)
3357 ,l_bl_end_date_tab(i)
3358 ,'PROJ_FUNCTIONAL'
3359 ,l_org_projfunc_currency_code
3360 ,l_org_projfunc_currency_code /* 2796261 */
3361 ,l_bl_quantity_tab(i)
3362 ,l_bl_raw_cost_tab(i)
3363 ,l_bl_burdened_cost_tab(i)
3364 ,l_bl_tp_cost_in_tab(i)
3365 ,l_bl_tp_cost_out_tab(i)
3366 ,l_bl_lent_resource_cost_tab(i)
3367 ,l_bl_unassigned_time_cost_tab(i)
3368 ,0
3369 ,l_bl_revenue_tab(i)
3370 ,l_bl_borrowed_revenue_tab(i)
3371 ,l_bl_tp_revenue_in_tab(i)
3372 ,l_bl_tp_revenue_out_tab(i)
3373 ,0
3374 ,l_bl_utilization_percent_tab(i)
3375 ,0
3376 ,l_bl_utilization_hours_tab(i)
3377 ,l_bl_capacity_tab(i)
3378 ,l_bl_head_count_tab(i)
3379 ,0
3380 ,DECODE(SIGN(
3381 l_bl_revenue_tab(i)+
3382 l_bl_borrowed_revenue_tab(i)+
3383 l_bl_tp_revenue_in_tab(i)-
3384 l_bl_tp_revenue_out_tab(i)),0,0,-1,0,
3385 (l_bl_revenue_tab(i)+
3386 l_bl_borrowed_revenue_tab(i)+
3387 l_bl_tp_revenue_in_tab(i)-
3388 l_bl_tp_revenue_out_tab(i)) -
3389 (l_bl_burdened_cost_tab(i)+
3390 l_bl_lent_resource_cost_tab(i)+
3391 l_bl_unassigned_time_cost_tab(i)+
3392 l_bl_tp_cost_in_tab(i)-
3393 l_bl_tp_cost_out_tab(i)))
3394 ,DECODE(SIGN(
3395 l_bl_revenue_tab(i)+
3396 l_bl_borrowed_revenue_tab(i)+
3397 l_bl_tp_revenue_in_tab(i)-
3398 l_bl_tp_revenue_out_tab(i)),0,0,-1,0,
3399 ((l_bl_revenue_tab(i)+
3400 l_bl_borrowed_revenue_tab(i)+
3401 l_bl_tp_revenue_in_tab(i)-
3402 l_bl_tp_revenue_out_tab(i)) -
3403 (l_bl_burdened_cost_tab(i)+
3404 l_bl_lent_resource_cost_tab(i)+
3405 l_bl_unassigned_time_cost_tab(i)+
3406 l_bl_tp_cost_in_tab(i)-
3407 l_bl_tp_cost_out_tab(i)))/
3408 (l_bl_revenue_tab(i)+
3409 l_bl_borrowed_revenue_tab(i)+
3410 l_bl_tp_revenue_in_tab(i)-
3411 l_bl_tp_revenue_out_tab(i)) * 100)
3412 FROM DUAL;
3413
3414 l_stage := 9700;
3415 -- hr_utility.trace(to_char(l_stage));
3416 l_records_affected := SQL%ROWCOUNT;
3417
3418 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3419 ': After Inserting Fin Plan Lines Tmp' ;
3420 IF P_PA_DEBUG_MODE = 'Y' THEN
3421 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3422 END IF;
3423
3424 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3425 ': Inserted [' || TO_CHAR(l_records_affected) ||
3426 '] Fin Plan Lines Tmp.';
3427 IF P_PA_DEBUG_MODE = 'Y' THEN
3428 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3429 END IF;
3430
3431 /* Populate Project Periods Denorm for Budget Lines */
3432
3433 l_stage := 9800;
3434 -- hr_utility.trace(to_char(l_stage));
3435 pa_debug.g_err_stage := l_stage||': Populate Project Periods Denorm for Budget Lines';
3436 IF P_PA_DEBUG_MODE = 'Y' THEN
3437 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3438 END IF;
3439 Pa_Plan_Matrix.Maintain_Plan_Matrix
3440 ( p_amount_type_tab => amt_rec
3441 ,p_period_profile_id => l_period_profile_id
3442 ,p_prior_period_flag => 'N'
3443 ,p_commit_Flag => 'N'
3444 ,p_budget_version_id => l_budget_version_id
3445 ,p_project_id => l_project_id
3446 ,p_debug_mode => l_debug_mode
3447 ,p_add_msg_in_stack => 'Y'
3448 ,x_return_status => l_return_status
3449 ,x_msg_count => l_msg_count
3450 ,x_msg_data => errbuff );
3451
3452 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3453 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3454 ':Error creating Period Denorm';
3455 IF P_PA_DEBUG_MODE = 'Y' THEN
3456 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3457 END IF;
3458 pa_debug.g_err_stage := 'l_period_profile_id ['||l_period_profile_id || ']';
3459 IF P_PA_DEBUG_MODE = 'Y' THEN
3460 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3461 END IF;
3462 pa_debug.g_err_stage := 'l_budget_version_id ['||l_budget_version_id || ']';
3463 IF P_PA_DEBUG_MODE = 'Y' THEN
3464 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3465 END IF;
3466 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
3467 IF P_PA_DEBUG_MODE = 'Y' THEN
3468 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3469 END IF;
3470 rollback to org_project;
3471 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
3472 END IF;
3473 END IF; /* l_bl_res_asg_id_tab.count <> 0 */
3474
3475 l_stage := 9900;
3476 -- hr_utility.trace(to_char(l_stage));
3477 pa_debug.g_err_stage := l_stage||': Create Resource Assignments for Project Task';
3478 IF P_PA_DEBUG_MODE = 'Y' THEN
3479 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3480 END IF;
3481
3482 /* Now one pass for Project level numbers */
3483 /* Create Resource assignment with task_id = 0 */
3484
3485 l_proj_resource_assignment_id := NULL;
3486
3487 pa_fp_resource_assignments_pkg.Insert_Row
3488 ( px_resource_assignment_id => l_proj_resource_assignment_id
3489 ,p_budget_version_id => l_budget_version_id
3490 ,p_project_id => l_project_id
3491 ,p_task_id => 0
3492 ,p_resource_list_member_id => l_resource_list_member_id
3493 ,p_unit_of_measure => 'HOURS'
3494 ,p_track_as_labor_flag => 'Y'
3495 ,p_standard_bill_rate => Null
3496 ,p_average_bill_rate => Null
3497 ,p_average_cost_rate => Null
3498 ,p_project_assignment_id => -1
3499 ,p_plan_error_code => Null
3500 ,p_total_plan_revenue => 0
3501 ,p_total_plan_raw_cost => 0
3502 ,p_total_plan_burdened_cost => 0
3503 ,p_total_plan_quantity => 0
3504 ,p_average_discount_percentage => Null
3505 ,p_total_borrowed_revenue => 0
3506 ,p_total_tp_revenue_in => 0
3507 ,p_total_tp_revenue_out => 0
3508 ,p_total_revenue_adj => 0
3509 ,p_total_lent_resource_cost => 0
3510 ,p_total_tp_cost_in => 0
3511 ,p_total_tp_cost_out => 0
3512 ,p_total_cost_adj => 0
3513 ,p_total_unassigned_time_cost => 0
3514 ,p_total_utilization_percent => 0
3515 ,p_total_utilization_hours => 0
3516 ,p_total_utilization_adj => 0
3517 ,p_total_capacity => 0
3518 ,p_total_head_count => 0
3519 ,p_total_head_count_adj => 0
3520 ,p_resource_assignment_type => 'PROJECT'
3521 ,x_row_id => l_row_id
3522 ,x_return_status => l_return_status );
3523
3524 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3525 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3526 ': Error creating Proj Resource Assignment';
3527 IF P_PA_DEBUG_MODE = 'Y' THEN
3528 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3529 END IF;
3530 pa_debug.g_err_stage := 'l_budget_version_id ['||l_budget_version_id || ']';
3531 IF P_PA_DEBUG_MODE = 'Y' THEN
3532 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3533 END IF;
3534 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
3535 IF P_PA_DEBUG_MODE = 'Y' THEN
3536 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3537 END IF;
3538 pa_debug.g_err_stage := 'l_resource_list_member_id['||l_resource_list_member_id|| ']';
3539 IF P_PA_DEBUG_MODE = 'Y' THEN
3540 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3541 END IF;
3542 rollback to org_project;
3543 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
3544 END IF;
3545
3546 l_stage := 10000;
3547 -- hr_utility.trace(to_char(l_stage));
3548
3549 /* Budget Lines for Project Level Task */
3550
3551 IF NOT bl_lines_project%ISOPEN THEN
3552 OPEN bl_lines_project;
3553 ELSE
3554 CLOSE bl_lines_project;
3555 OPEN bl_lines_project;
3556 END IF;
3557
3558 l_stage := 10100;
3559 -- hr_utility.trace(to_char(l_stage));
3560
3561 l_bl_budget_version_id_tab.delete; /* FPB2: budget_version_id */
3562 l_bl_res_asg_id_tab.delete;
3563 l_bl_start_date_tab.delete;
3564 l_bl_end_date_tab.delete;
3565 l_bl_period_name_tab.delete;
3566 l_bl_quantity_tab.delete;
3567 l_bl_raw_cost_tab.delete;
3568 l_bl_burdened_cost_tab.delete;
3569 l_bl_revenue_tab.delete;
3570 l_bl_borrowed_revenue_tab.delete;
3571 l_bl_tp_revenue_in_tab.delete;
3572 l_bl_tp_revenue_out_tab.delete;
3573 l_bl_lent_resource_cost_tab.delete;
3574 l_bl_tp_cost_in_tab.delete;
3575 l_bl_tp_cost_out_tab.delete;
3576 l_bl_unassigned_time_cost_tab.delete;
3577 l_bl_utilization_percent_tab.delete;
3578 l_bl_utilization_hours_tab.delete;
3579 l_bl_capacity_tab.delete;
3580 l_bl_head_count_tab.delete;
3581
3582 FETCH bl_lines_project BULK COLLECT INTO
3583 l_bl_budget_version_id_tab /* FPB2: budget_version_id */
3584 ,l_bl_res_asg_id_tab
3585 ,l_bl_period_name_tab
3586 ,l_bl_start_date_tab
3587 ,l_bl_end_date_tab
3588 ,l_bl_quantity_tab
3589 ,l_bl_raw_cost_tab
3590 ,l_bl_burdened_cost_tab
3591 ,l_bl_revenue_tab
3592 ,l_bl_borrowed_revenue_tab
3593 ,l_bl_tp_revenue_in_tab
3594 ,l_bl_tp_revenue_out_tab
3595 ,l_bl_lent_resource_cost_tab
3596 ,l_bl_tp_cost_in_tab
3597 ,l_bl_tp_cost_out_tab
3598 ,l_bl_unassigned_time_cost_tab
3599 ,l_bl_utilization_percent_tab
3600 ,l_bl_utilization_hours_tab
3601 ,l_bl_capacity_tab
3602 ,l_bl_head_count_tab;
3603
3604 l_stage := 10200;
3605 -- hr_utility.trace(to_char(l_stage));
3606 IF NVL(l_bl_res_asg_id_tab.count,0) =0 THEN
3607 l_stage := 10300;
3608 -- hr_utility.trace(to_char(l_stage));
3609 ELSE
3610 /* Bulk insert into Budget Lines for Project Numbers */
3611 pa_debug.g_err_stage := l_stage||': Create Budget Lines for Project Level Task';
3612 IF P_PA_DEBUG_MODE = 'Y' THEN
3613 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3614 END IF;
3615 FORALL i in l_bl_res_asg_id_tab.first..l_bl_res_asg_id_tab.last
3616 INSERT INTO pa_budget_lines
3617 ( budget_line_id /* FPB2 budget_line_id */
3618 ,budget_version_id /* FPB2 */
3619 ,txn_currency_code /* FPB4 */
3620 ,resource_assignment_id
3621 ,period_name
3622 ,start_date
3623 ,end_date
3624 ,quantity
3625 ,raw_cost
3626 ,burdened_cost
3627 ,lent_resource_cost
3628 ,unassigned_time_cost
3629 ,tp_cost_in
3630 ,tp_cost_out
3631 ,revenue
3632 ,borrowed_revenue
3633 ,tp_revenue_in
3634 ,tp_revenue_out
3635 ,quantity_source
3636 ,raw_cost_source
3637 ,burdened_cost_source
3638 ,revenue_source
3639 ,utilization_percent
3640 ,utilization_hours
3641 ,capacity
3642 ,head_count
3643 ,creation_date
3644 ,created_by
3645 ,last_update_login
3646 ,last_updated_by
3647 ,last_update_date
3648 ) VALUES (
3649 pa_budget_lines_s.nextval /* FPB2: budget_line_id */
3650 ,l_bl_budget_version_id_tab(i) /* FPB2: budget_version_id */
3651 ,l_org_projfunc_currency_code /* FPB4 */
3652 ,l_bl_res_asg_id_tab(i)
3653 ,l_bl_period_name_tab(i)
3654 ,l_bl_start_date_tab(i)
3655 ,l_bl_end_date_tab(i)
3656 ,l_bl_quantity_tab(i)
3657 ,l_bl_raw_cost_tab(i)
3658 ,l_bl_burdened_cost_tab(i)
3659 ,l_bl_lent_resource_cost_tab(i)
3660 ,l_bl_unassigned_time_cost_tab(i)
3661 ,l_bl_tp_cost_in_tab(i)
3662 ,l_bl_tp_cost_out_tab(i)
3663 ,l_bl_revenue_tab(i)
3664 ,l_bl_borrowed_revenue_tab(i)
3665 ,l_bl_tp_revenue_in_tab(i)
3666 ,l_bl_tp_revenue_out_tab(i)
3667 ,'C'
3668 ,'C'
3669 ,'C'
3670 ,'C'
3671 ,l_bl_utilization_percent_tab(i)
3672 ,l_bl_utilization_hours_tab(i)
3673 ,l_bl_capacity_tab(i)
3674 ,l_bl_head_count_tab(i)
3675 ,sysdate
3676 ,fnd_global.user_id
3677 ,fnd_global.login_id
3678 ,fnd_global.user_id
3679 ,sysdate);
3680
3681 l_stage := 10400;
3682 -- hr_utility.trace(to_char(l_stage));
3683
3684 /* Need to update Project Level Resource Assignment
3685 from budget Lines */
3686
3687 SELECT nvl(sum(bl.quantity),0)
3688 ,nvl(sum(bl.raw_cost),0)
3689 ,nvl(sum(bl.burdened_cost),0)
3690 ,nvl(sum(bl.lent_resource_cost),0)
3691 ,nvl(sum(bl.unassigned_time_cost),0)
3692 ,nvl(sum(bl.tp_cost_in),0)
3693 ,nvl(sum(bl.tp_cost_out),0)
3694 ,nvl(sum(bl.revenue),0)
3695 ,nvl(sum(bl.borrowed_revenue),0)
3696 ,nvl(sum(bl.tp_revenue_in),0)
3697 ,nvl(sum(bl.tp_revenue_out),0)
3698 ,nvl(round(avg(bl.utilization_percent)),0)
3699 ,nvl(sum(bl.utilization_hours),0)
3700 ,nvl(sum(bl.capacity),0)
3701 ,nvl(round(avg(bl.head_count)),0)
3702 INTO budget_lines_rec(1).quantity
3703 ,budget_lines_rec(1).raw_cost
3704 ,budget_lines_rec(1).burdened_cost
3705 ,budget_lines_rec(1).lent_resource_cost
3706 ,budget_lines_rec(1).unassigned_time_cost
3707 ,budget_lines_rec(1).tp_cost_in
3708 ,budget_lines_rec(1).tp_cost_out
3709 ,budget_lines_rec(1).revenue
3710 ,budget_lines_rec(1).borrowed_revenue
3711 ,budget_lines_rec(1).tp_revenue_in
3712 ,budget_lines_rec(1).tp_revenue_out
3713 ,budget_lines_rec(1).utilization_percent
3714 ,budget_lines_rec(1).utilization_hours
3715 ,budget_lines_rec(1).capacity
3716 ,budget_lines_rec(1).head_count
3717 FROM pa_budget_lines bl
3718 WHERE bl.resource_assignment_id = l_proj_resource_assignment_id;
3719
3720 l_stage := 10500;
3721 -- hr_utility.trace(to_char(l_stage));
3722
3723 IF budget_lines_rec.COUNT = 1 THEN
3724 l_stage := 10600;
3725 -- hr_utility.trace(to_char(l_stage));
3726 pa_debug.g_err_stage := l_stage||': Update Resource Assignments for Project Task';
3727 IF P_PA_DEBUG_MODE = 'Y' THEN
3728 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3729 END IF;
3730 UPDATE pa_resource_assignments
3731 SET
3732 last_update_date = sysdate
3733 ,last_updated_by = fnd_global.user_id
3734 ,last_update_login = fnd_global.login_id
3735 ,total_plan_revenue = budget_lines_rec(1).revenue
3736 ,total_plan_raw_cost = budget_lines_rec(1).raw_cost
3737 ,total_plan_burdened_cost = budget_lines_rec(1).burdened_cost
3738 ,total_plan_quantity = budget_lines_rec(1).quantity
3739 ,total_borrowed_revenue = budget_lines_rec(1).borrowed_revenue
3740 ,total_tp_revenue_in = budget_lines_rec(1).tp_revenue_in
3741 ,total_tp_revenue_out = budget_lines_rec(1).tp_revenue_out
3742 ,total_lent_resource_cost = budget_lines_rec(1).lent_resource_cost
3743 ,total_tp_cost_in = budget_lines_rec(1).tp_cost_in
3744 ,total_tp_cost_out = budget_lines_rec(1).tp_cost_out
3745 ,total_unassigned_time_cost = budget_lines_rec(1).unassigned_time_cost
3746 ,total_utilization_percent = budget_lines_rec(1).utilization_percent
3747 ,total_utilization_hours = budget_lines_rec(1).utilization_hours
3748 ,total_capacity = budget_lines_rec(1).capacity
3749 ,total_head_count = budget_lines_rec(1).head_count
3750 WHERE resource_assignment_id = l_proj_resource_assignment_id;
3751
3752 l_stage := 10700;
3753 -- hr_utility.trace(to_char(l_stage));
3754 END IF;
3755
3756 IF budget_lines_rec.COUNT = 1 THEN
3757 l_stage := 10800;
3758 -- hr_utility.trace(to_char(l_stage));
3759 pa_debug.g_err_stage := l_stage||': Update Budget Version for Project Level Numbers';
3760 IF P_PA_DEBUG_MODE = 'Y' THEN
3761 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3762 END IF;
3763
3764 UPDATE pa_budget_versions
3765 SET
3766 record_version_number = record_version_number+1
3767 ,version_name = DECODE(version_name,null,l_bv_version_name
3768 ||'-'||to_char(l_budget_version_id),
3769 version_name)
3770 ,last_update_date = sysdate
3771 ,last_updated_by = fnd_global.user_id
3772 ,last_update_login = fnd_global.login_id
3773 ,revenue = budget_lines_rec(1).revenue
3774 ,raw_cost = budget_lines_rec(1).raw_cost
3775 ,burdened_cost = budget_lines_rec(1).burdened_cost
3776 ,labor_quantity = budget_lines_rec(1).quantity
3777 ,total_borrowed_revenue = budget_lines_rec(1).borrowed_revenue
3778 ,total_tp_revenue_in = budget_lines_rec(1).tp_revenue_in
3779 ,total_tp_revenue_out = budget_lines_rec(1).tp_revenue_out
3780 ,total_lent_resource_cost = budget_lines_rec(1).lent_resource_cost
3781 ,total_tp_cost_in = budget_lines_rec(1).tp_cost_in
3782 ,total_tp_cost_out = budget_lines_rec(1).tp_cost_out
3783 ,total_unassigned_time_cost = budget_lines_rec(1).unassigned_time_cost
3784 ,total_utilization_percent = budget_lines_rec(1).utilization_percent
3785 ,total_utilization_hours = budget_lines_rec(1).utilization_hours
3786 ,total_capacity = budget_lines_rec(1).capacity
3787 ,total_head_count = budget_lines_rec(1).head_count
3788 ,plan_processing_code = 'G'
3789 WHERE budget_version_id = l_budget_version_id;
3790
3791 l_stage := 10900;
3792 -- hr_utility.trace(to_char(l_stage));
3793 END IF;
3794
3795 l_stage := 11000;
3796 -- hr_utility.trace(to_char(l_stage));
3797 budget_lines_rec.DELETE;
3798
3799 DELETE FROM pa_fin_plan_lines_tmp;
3800
3801 l_stage := 11100;
3802 -- hr_utility.trace(to_char(l_stage));
3803
3804 FORALL i in l_bl_res_asg_id_tab.first..l_bl_res_asg_id_tab.last
3805 INSERT INTO pa_fin_plan_lines_tmp
3806 ( resource_assignment_id
3807 ,object_id
3808 ,object_type_code
3809 ,period_name
3810 ,start_date
3811 ,end_date
3812 ,currency_type
3813 ,currency_code
3814 ,source_txn_currency_code /* Bug 2796261 */
3815 ,quantity
3816 ,raw_cost
3817 ,burdened_cost
3818 ,tp_cost_in
3819 ,tp_cost_out
3820 ,lent_resource_cost
3821 ,unassigned_time_cost
3822 ,cost_adj
3823 ,revenue
3824 ,borrowed_revenue
3825 ,tp_revenue_in
3826 ,tp_revenue_out
3827 ,revenue_adj
3828 ,utilization_percent
3829 ,utilization_adj
3830 ,utilization_hours
3831 ,capacity
3832 ,head_count
3833 ,head_count_adj
3834 ,margin
3835 ,margin_percentage)
3836 SELECT
3837 l_bl_res_asg_id_tab(i)
3838 ,l_bl_res_asg_id_tab(i)
3839 ,'RES_ASSIGNMENT'
3840 ,l_bl_period_name_tab(i)
3841 ,l_bl_start_date_tab(i)
3842 ,l_bl_end_date_tab(i)
3843 ,'PROJ_FUNCTIONAL'
3844 ,l_org_projfunc_currency_code
3845 ,l_org_projfunc_currency_code /* 2796261 */
3846 ,l_bl_quantity_tab(i)
3847 ,l_bl_raw_cost_tab(i)
3848 ,l_bl_burdened_cost_tab(i)
3849 ,l_bl_tp_cost_in_tab(i)
3850 ,l_bl_tp_cost_out_tab(i)
3851 ,l_bl_lent_resource_cost_tab(i)
3852 ,l_bl_unassigned_time_cost_tab(i)
3853 ,0
3854 ,l_bl_revenue_tab(i)
3855 ,l_bl_borrowed_revenue_tab(i)
3856 ,l_bl_tp_revenue_in_tab(i)
3857 ,l_bl_tp_revenue_out_tab(i)
3858 ,0
3859 ,l_bl_utilization_percent_tab(i)
3860 ,0
3861 ,l_bl_utilization_hours_tab(i)
3862 ,l_bl_capacity_tab(i)
3863 ,l_bl_head_count_tab(i)
3864 ,0
3865 ,DECODE(SIGN(
3866 l_bl_revenue_tab(i)+
3867 l_bl_borrowed_revenue_tab(i)+
3868 l_bl_tp_revenue_in_tab(i)-
3869 l_bl_tp_revenue_out_tab(i)),0,0,-1,0,
3870 (l_bl_revenue_tab(i)+
3871 l_bl_borrowed_revenue_tab(i)+
3872 l_bl_tp_revenue_in_tab(i)-
3873 l_bl_tp_revenue_out_tab(i)) -
3874 (l_bl_burdened_cost_tab(i)+
3875 l_bl_lent_resource_cost_tab(i)+
3876 l_bl_unassigned_time_cost_tab(i)+
3877 l_bl_tp_cost_in_tab(i)-
3878 l_bl_tp_cost_out_tab(i)))
3879 ,DECODE(SIGN(
3880 l_bl_revenue_tab(i)+
3881 l_bl_borrowed_revenue_tab(i)+
3882 l_bl_tp_revenue_in_tab(i)-
3883 l_bl_tp_revenue_out_tab(i)),0,0,-1,0,
3884 ((l_bl_revenue_tab(i)+
3885 l_bl_borrowed_revenue_tab(i)+
3886 l_bl_tp_revenue_in_tab(i)-
3887 l_bl_tp_revenue_out_tab(i)) -
3888 (l_bl_burdened_cost_tab(i)+
3889 l_bl_lent_resource_cost_tab(i)+
3890 l_bl_unassigned_time_cost_tab(i)+
3891 l_bl_tp_cost_in_tab(i)-
3892 l_bl_tp_cost_out_tab(i)))/
3893 (l_bl_revenue_tab(i)+
3894 l_bl_borrowed_revenue_tab(i)+
3895 l_bl_tp_revenue_in_tab(i)-
3896 l_bl_tp_revenue_out_tab(i)) * 100)
3897 FROM DUAL;
3898
3899 l_stage := 11200;
3900 -- hr_utility.trace(to_char(l_stage));
3901
3902 l_records_affected := SQL%ROWCOUNT;
3903
3904 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3905 ': After Inserting Fin Plan Lines Tmp' ;
3906 IF P_PA_DEBUG_MODE = 'Y' THEN
3907 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3908 END IF;
3909
3910 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3911 ': Inserted [' || TO_CHAR(l_records_affected) ||
3912 '] Fin Plan Lines Tmp.';
3913 IF P_PA_DEBUG_MODE = 'Y' THEN
3914 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3915 END IF;
3916
3917 l_stage := 11300;
3918 -- hr_utility.trace(to_char(l_stage));
3919
3920 /* Populate Project Periods Denorm for budget lines for Project */
3921 Pa_Plan_Matrix.Maintain_Plan_Matrix
3922 ( p_amount_type_tab => amt_rec
3923 ,p_period_profile_id => l_period_profile_id
3924 ,p_prior_period_flag => 'N'
3925 ,p_commit_Flag => 'N'
3926 ,x_return_status => l_return_status
3927 ,x_msg_count => l_msg_count
3928 ,x_msg_data => errbuff
3929 ,p_budget_version_id => l_budget_version_id
3930 ,p_project_id => l_project_id);
3931
3932 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3933 pa_debug.g_err_stage := TO_CHAR(l_stage) ||
3934 ':Error creating Period Denorm';
3935 IF P_PA_DEBUG_MODE = 'Y' THEN
3936 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3937 END IF;
3938 pa_debug.g_err_stage :=
3939 'l_period_profile_id ['||l_period_profile_id ||
3940 '] l_budget_version_id ['||l_budget_version_id ||
3941 '] l_project_id ['||l_project_id ||
3942 ']';
3943 IF P_PA_DEBUG_MODE = 'Y' THEN
3944 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3945 END IF;
3946 rollback to org_project;
3947 RAISE pa_fp_org_fcst_gen_pub.error_reloop;
3948 END IF;
3949 END IF;
3950 l_stage := 11400;
3951 -- hr_utility.trace(to_char(l_stage));
3952
3953 IF p_budget_version_id IS NOT NULL THEN
3954 l_stage := 11500;
3955 -- hr_utility.trace(to_char(l_stage));
3956 pa_debug.g_err_stage := l_stage||': Process Complete for budget version -- EXITING';
3957 IF P_PA_DEBUG_MODE = 'Y' THEN
3958 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3959 END IF;
3960 COMMIT;
3961 EXIT; -- need to force exit when generating for a budget version.
3962 END IF;
3963 l_stage := 11600;
3964 -- hr_utility.trace(to_char(l_stage));
3965 EXCEPTION
3966 WHEN pa_fp_org_fcst_gen_pub.error_reloop THEN
3967 -- hr_utility.trace('UserDefined Skipping - '||to_char(l_stage)||'-'||SQLERRM);
3968 pa_debug.g_err_stage := l_stage||': UserDefined Skipping - '||'['||SQLERRM||']';
3969 IF P_PA_DEBUG_MODE = 'Y' THEN
3970 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3971 END IF;
3972 rollback to org_project;
3973 IF l_budget_version_id > 0 THEN
3974 l_budget_version_in_error := budget_version_in_error(l_budget_version_id);
3975 pa_debug.g_err_stage := l_stage||': Budget Version has errored - '
3976 ||'['||l_budget_version_id||']';
3977 IF P_PA_DEBUG_MODE = 'Y' THEN
3978 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3979 END IF;
3980 END IF;
3981 WHEN OTHERS THEN
3982 -- hr_utility.trace('UnExpected Skipping - '||to_char(l_stage)||'-'||SQLERRM);
3983 pa_debug.g_err_stage := l_stage||': UnExpected Skipping - '||'['||SQLERRM||']';
3984 IF P_PA_DEBUG_MODE = 'Y' THEN
3985 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3986 END IF;
3987 pa_debug.g_err_stage := 'l_organization_id ['||l_organization_id || ']';
3988 IF P_PA_DEBUG_MODE = 'Y' THEN
3989 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3990 END IF;
3991 pa_debug.g_err_stage := 'l_budget_version_id ['||l_budget_version_id || ']';
3992 IF P_PA_DEBUG_MODE = 'Y' THEN
3993 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3994 END IF;
3995 pa_debug.g_err_stage := 'l_project_id ['||l_project_id || ']';
3996 IF P_PA_DEBUG_MODE = 'Y' THEN
3997 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
3998 END IF;
3999 pa_debug.g_err_stage := 'l_period_profile_id ['||l_period_profile_id || ']';
4000 IF P_PA_DEBUG_MODE = 'Y' THEN
4001 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4002 END IF;
4003 rollback to org_project;
4004 IF l_budget_version_id > 0 THEN
4005 l_budget_version_in_error := budget_version_in_error(l_budget_version_id);
4006 pa_debug.g_err_stage := l_stage||': Budget Version has errored - '
4007 ||'['||l_budget_version_id||']';
4008 IF P_PA_DEBUG_MODE = 'Y' THEN
4009 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4010 END IF;
4011 END IF;
4012 END;
4013 COMMIT;
4014 END LOOP; /* Org Loop */
4015
4016 IF p_budget_version_id IS NULL THEN
4017 l_stage := 11700;
4018 -- hr_utility.trace(to_char(l_stage));
4019 IF p_starting_organization_id IS NULL THEN
4020 CLOSE specific_org_only;
4021 l_stage := 11800;
4022 -- hr_utility.trace(to_char(l_stage));
4023
4024 -- R12 MOAC 4447573
4025 If P_PA_DEBUG_MODE = 'Y' THEN
4026 PA_DEBUG.Log_Message(p_message => 'Calling FND_REQUEST.set_org_id{'||l_org_id||'}');
4027 End If;
4028 FND_REQUEST.set_org_id(l_org_id);
4029 -- end of R12 MOAC 4447573
4030
4031 l_request_id := FND_REQUEST.submit_request
4032 (application => 'PA',
4033 program => 'PAFPEXRP',
4034 description => 'PRC: List Organization Forecast Exceptions',
4035 start_time => NULL,
4036 sub_request => false,
4037 argument1 => l_org_id, -- P_ORG_ID
4038 argument2 => '02', -- P_SELECT_CRITERIA
4039 argument3 => NULL, -- P_PROJECT_FLAG
4040 argument4 => NULL, -- P_PROJECT_ID
4041 argument5 => NULL, -- P_ASSIGNMENT_ID
4042 argument6 => 1, -- P_ORGANIZATION_FLAG
4043 argument7 => l_organization_id, -- P_ORGANIZATION_ID
4044 argument8 => NULL, -- P_START_ORGANIZATION_FLAG
4045 argument9 => NULL); -- P_START_ORGANIZATION_ID
4046 IF l_request_id = 0 then
4047 l_return_status := FND_API.G_RET_STS_ERROR;
4048 IF P_PA_DEBUG_MODE = 'Y' THEN
4049 pa_debug.write_file('gen_org_fcst: ' || 'Report not successful [PAFPEXRP] l_request_id=0; ERROR');
4050 END IF;
4051 ELSE
4052 pa_debug.g_err_stage := 'Exception Report Request Id is '||TO_CHAR(l_request_id);
4053 IF P_PA_DEBUG_MODE = 'Y' THEN
4054 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4055 END IF;
4056 END IF;
4057 ELSE
4058 CLOSE org_hierarchy;
4059 l_stage := 11900;
4060 -- hr_utility.trace(to_char(l_stage));
4061
4062 -- R12 MOAC 4447573
4063 If P_PA_DEBUG_MODE = 'Y' THEN
4064 PA_DEBUG.Log_Message(p_message => 'Calling FND_REQUEST.set_org_id{'||l_org_id||'}');
4065 End If;
4066 FND_REQUEST.set_org_id(l_org_id);
4067 -- end of R12 MOAC 4447573
4068
4069 l_request_id := FND_REQUEST.submit_request
4070 (application => 'PA',
4071 program => 'PAFPEXRP',
4072 description => 'PRC: List Organization Forecast Exceptions',
4073 start_time => NULL,
4074 sub_request => false,
4075 argument1 => l_org_id, -- P_ORG_ID
4076 argument2 => '03', -- P_SELECT_CRITERIA
4077 argument3 => NULL, -- P_PROJECT_FLAG
4078 argument4 => NULL, -- P_PROJECT_ID
4079 argument5 => NULL, -- P_ASSIGNMENT_ID
4080 argument6 => NULL, -- P_ORGANIZATION_FLAG
4081 argument7 => NULL, -- P_ORGANIZATION_ID
4082 argument8 => 1, -- P_START_ORGANIZATION_FLAG
4083 argument9 => p_starting_organization_id); -- P_START_ORGANIZATION_ID
4084 IF l_request_id = 0 then
4085 l_return_status := FND_API.G_RET_STS_ERROR;
4086 IF P_PA_DEBUG_MODE = 'Y' THEN
4087 pa_debug.write_file('gen_org_fcst: ' || 'Report not successful [PAFPEXRP] l_request_id=0; ERROR');
4088 END IF;
4089 ELSE
4090 pa_debug.g_err_stage := 'Exception Report Request Id is '||TO_CHAR(l_request_id);
4091 IF P_PA_DEBUG_MODE = 'Y' THEN
4092 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4093 END IF;
4094 END IF;
4095 END IF;
4096 ELSE
4097 l_stage := 12000;
4098 -- hr_utility.trace(to_char(l_stage));
4099
4100 -- R12 MOAC 4447573
4101 If P_PA_DEBUG_MODE = 'Y' THEN
4102 PA_DEBUG.Log_Message(p_message => 'Calling FND_REQUEST.set_org_id{'||l_org_id||'}');
4103 End If;
4104 FND_REQUEST.set_org_id(l_org_id);
4105 -- end of R12 MOAC 4447573
4106
4107 l_request_id := FND_REQUEST.submit_request
4108 (application => 'PA',
4109 program => 'PAFPEXRP',
4110 description => 'PRC: List Organization Forecast Exceptions',
4111 start_time => NULL,
4112 sub_request => false,
4113 argument1 => l_org_id, -- P_ORG_ID
4114 argument2 => '02', -- P_SELECT_CRITERIA
4115 argument3 => NULL, -- P_PROJECT_FLAG
4116 argument4 => NULL, -- P_PROJECT_ID
4117 argument5 => NULL, -- P_ASSIGNMENT_ID
4118 argument6 => 1, -- P_ORGANIZATION_FLAG
4119 argument7 => l_organization_id, -- P_ORGANIZATION_ID
4120 argument8 => NULL, -- P_START_ORGANIZATION_FLAG
4121 argument9 => NULL); -- P_START_ORGANIZATION_ID
4122
4123 IF l_request_id = 0 then
4124 l_return_status := FND_API.G_RET_STS_ERROR;
4125 IF P_PA_DEBUG_MODE = 'Y' THEN
4126 pa_debug.write_file('gen_org_fcst: ' || 'Report not successful [PAFPEXRP] l_request_id=0; ERROR');
4127 END IF;
4128 ELSE
4129 pa_debug.g_err_stage := 'Exception Report Request Id is '||TO_CHAR(l_request_id);
4130 IF P_PA_DEBUG_MODE = 'Y' THEN
4131 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4132 END IF;
4133 END IF;
4134
4135
4136 END IF; -- p_budget_version_id IS NULL
4137
4138 pa_debug.g_err_stage := TO_CHAR(l_stage)||': End of Generation Process';
4139 IF P_PA_DEBUG_MODE = 'Y' THEN
4140 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4141 END IF;
4142 pa_debug.reset_err_stack;
4143
4144 EXCEPTION
4145 WHEN OTHERS THEN
4146 FND_MSG_PUB.add_exc_msg
4147 ( p_pkg_name => 'PA_FP_ORG_FCST_GEN_PKG.gen_org_fcst'
4148 ,p_procedure_name => PA_DEBUG.G_Err_Stack);
4149
4150 retcode := FND_API.G_RET_STS_UNEXP_ERROR;
4151 errbuff := TO_CHAR(l_stage)||'['||SQLERRM||']';
4152
4153 -- hr_utility.trace(to_char(l_stage)||'-'||SQLERRM);
4154 pa_debug.g_err_stage := TO_CHAR(l_stage)||'['||SQLERRM||']';
4155 IF P_PA_DEBUG_MODE = 'Y' THEN
4156 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4157 END IF;
4158 IF l_budget_version_id > 0 THEN
4159 l_budget_version_in_error := budget_version_in_error(l_budget_version_id);
4160 pa_debug.g_err_stage := l_stage||': Budget Version has errored - '
4161 ||'['||l_budget_version_id||']';
4162 IF P_PA_DEBUG_MODE = 'Y' THEN
4163 pa_debug.write_file('gen_org_fcst: ' || pa_debug.g_err_stage);
4164 END IF;
4165 END IF;
4166 pa_debug.reset_err_stack;
4167 RAISE;
4168 END gen_org_fcst;
4169
4170
4171 /*************************************************************************
4172 sgoteti 03/03/2005.This API was previously in PAFPCPFB.pls, Copied it here as this will be used
4173 only in Org Forecasting Context. The code is copied without any change from the version
4174 115.196 of PAFPCPFB.pls
4175 **************************************************************************/
4176 PROCEDURE create_res_task_maps(
4177 p_source_project_id IN NUMBER
4178 ,p_target_project_id IN NUMBER
4179 ,p_source_plan_version_id IN NUMBER
4180 ,p_adj_percentage IN NUMBER
4181 ,p_copy_mode IN VARCHAR2 /* Bug 2920954 */
4182 ,p_calling_module IN VARCHAR2 /* Bug 2920954 */
4183 ,p_shift_days IN NUMBER -- 3/28/2004 FP M Dev Phase II Effort
4184 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4185 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
4186 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
4187
4188 AS
4189
4190 l_msg_count NUMBER := 0;
4191 l_data VARCHAR2(2000);
4192 l_msg_data VARCHAR2(2000);
4193 l_error_msg_code VARCHAR2(2000);
4194 l_msg_index_out NUMBER;
4195 l_return_status VARCHAR2(2000);
4196 l_debug_mode VARCHAR2(30);
4197 l_adj_percentage NUMBER;
4198 l_shift_days NUMBER;
4199
4200 l_periods NUMBER := 0;
4201 l_start_date DATE;
4202 l_err_code NUMBER;
4203 l_err_stage VARCHAR2(2000);
4204 l_err_stack VARCHAR2(2000);
4205
4206 TYPE ra_map_tmp_tbl1_type IS TABLE OF
4207 pa_fp_ra_map_tmp.source_res_assignment_id%TYPE
4208 INDEX BY BINARY_INTEGER;
4209
4210 TYPE ra_map_tmp_tbl2_type IS TABLE OF
4211 pa_fp_ra_map_tmp.target_res_assignment_id%TYPE
4212 INDEX BY BINARY_INTEGER;
4213
4214 TYPE ra_map_tmp_tbl3_type IS TABLE OF
4215 pa_fp_ra_map_tmp.resource_assignment_id%TYPE
4216 INDEX BY BINARY_INTEGER;
4217
4218 TYPE ra_map_tmp_tbl4_type IS TABLE OF
4219 pa_fp_ra_map_tmp.source_task_id%TYPE
4220 INDEX BY BINARY_INTEGER;
4221
4222 TYPE ra_map_tmp_tbl5_type IS TABLE OF
4223 pa_fp_ra_map_tmp.target_task_id%TYPE
4224 INDEX BY BINARY_INTEGER;
4225
4226 --Added the following table types for bug 3354518
4227
4228 TYPE ra_map_tmp_tbl6_type IS TABLE OF
4229 pa_fp_ra_map_tmp.system_reference1%TYPE
4230 INDEX BY BINARY_INTEGER;
4231
4232 TYPE ra_map_tmp_tbl7_type IS TABLE OF
4233 pa_fp_ra_map_tmp.system_reference2%TYPE
4234 INDEX BY BINARY_INTEGER;
4235
4236 TYPE ra_map_tmp_tbl8_type IS TABLE OF
4237 pa_fp_ra_map_tmp.system_reference3%TYPE
4238 INDEX BY BINARY_INTEGER;
4239
4240 TYPE ra_map_tmp_tbl9_type IS TABLE OF
4241 pa_fp_ra_map_tmp.planning_start_date%TYPE
4242 INDEX BY BINARY_INTEGER;
4243
4244 TYPE ra_map_tmp_tbl10_type IS TABLE OF
4245 pa_fp_ra_map_tmp.planning_end_date%TYPE
4246 INDEX BY BINARY_INTEGER;
4247
4248 TYPE ra_map_tmp_tbl11_type IS TABLE OF
4249 pa_fp_ra_map_tmp.schedule_start_date%TYPE
4250 INDEX BY BINARY_INTEGER;
4251
4252 TYPE ra_map_tmp_tbl12_type IS TABLE OF
4253 pa_fp_ra_map_tmp.schedule_end_date%TYPE
4254 INDEX BY BINARY_INTEGER;
4255
4256 -- Declared for bug 3615617
4257 TYPE ra_map_tmp_tbl13_type IS TABLE OF
4258 pa_fp_ra_map_tmp.system_reference4%TYPE
4259 INDEX BY BINARY_INTEGER;
4260
4261 l_ra_map_tmp_tbl1 ra_map_tmp_tbl1_type;
4262 l_ra_map_tmp_tbl2 ra_map_tmp_tbl2_type;
4263 l_ra_map_tmp_tbl3 ra_map_tmp_tbl3_type;
4264 l_ra_map_tmp_tbl4 ra_map_tmp_tbl4_type;
4265 l_ra_map_tmp_tbl5 ra_map_tmp_tbl5_type;
4266
4267 --Declared the following pl/sql tbls for bug 3354518
4268 l_ra_map_tmp_tbl6 ra_map_tmp_tbl6_type;
4269 l_ra_map_tmp_tbl7 ra_map_tmp_tbl7_type;
4270 l_ra_map_tmp_tbl8 ra_map_tmp_tbl8_type;
4271 l_ra_map_tmp_tbl9 ra_map_tmp_tbl9_type;
4272 l_ra_map_tmp_tbl10 ra_map_tmp_tbl10_type;
4273 l_ra_map_tmp_tbl11 ra_map_tmp_tbl11_type;
4274 l_ra_map_tmp_tbl12 ra_map_tmp_tbl12_type;
4275 -- Declared for bug 3615617
4276 l_ra_map_tmp_tbl13 ra_map_tmp_tbl13_type;
4277
4278 l_source_project_id pa_projects.project_id%TYPE;
4279 l_target_project_id pa_projects.project_id%TYPE;
4280 l_source_plan_level_code pa_proj_fp_options.all_fin_plan_level_code%TYPE ;
4281 l_target_struct_version_id pa_proj_element_versions.element_version_id%TYPE;
4282 l_source_struct_version_id pa_proj_element_versions.element_version_id%TYPE;
4283 l_target_time_phased_code pa_proj_fp_options.all_time_phased_code%TYPE; -- bug 3841942
4284
4285
4286 -- cursor same_projects_cur is going to be used when the source and target projects are same
4287
4288 CURSOR same_projects_cur IS
4289 SELECT resource_assignment_id
4290 ,pa_resource_assignments_s.nextval
4291 ,parent_assignment_id
4292 ,task_id
4293 ,task_id
4294 --Start of Changes for bug 3354518
4295 ,NULL
4296 ,NULL
4297 ,project_assignment_id
4298 ,planning_start_date
4299 ,planning_end_date
4300 ,schedule_start_date
4301 ,schedule_end_date
4302 --End of Changes for bug 3354518
4303 ,resource_list_member_id -- bug 3615617 TARGET_RLM_ID
4304 FROM pa_resource_assignments
4305 WHERE budget_version_id = p_source_plan_version_id;
4306
4307
4308 /* Bug 2920954 - This cursor is used for FINPLAN when copy mode is B.
4309 In this case, we copy only the ras with amounts. Since this cursor
4310 is used only for baselie case, we dont have to check adj percentage
4311 during copying. In pa_resource_assignments, the amount columns
4312 would be Null if no budget lines "ever" existed. */
4313
4314 /* 06-Jul-2004 Bug 3729657 Raja FP M Dev changes
4315 Resource assignments with no amounts also should be copied
4316 */
4317
4318 CURSOR baseline_budgt_res_cur IS
4319 SELECT pra.resource_assignment_id
4320 ,pa_resource_assignments_s.NEXTVAL
4321 ,pra.parent_assignment_id
4322 ,pra.task_id
4323 ,pra.task_id
4324 --Start of Changes for bug 3354518
4325 ,NULL
4326 ,NULL
4327 ,pra.project_assignment_id
4328 ,pra.planning_start_date
4329 ,pra.planning_end_date
4330 ,pra.schedule_start_date
4331 ,pra.schedule_end_date
4332 --End of Changes for bug 3354518
4333 ,resource_list_member_id -- bug 3615617 TARGET_RLM_ID
4334 FROM pa_resource_assignments pra
4335 WHERE pra.budget_version_id = p_source_plan_version_id;
4336 /*** Bug 3729657
4337 AND (pra.total_plan_quantity IS NOT NULL
4338 OR pra.total_plan_raw_cost IS NOT NULL
4339 OR pra.total_plan_burdened_cost IS NOT NULL
4340 OR pra.total_plan_revenue IS NOT NULL);
4341 ***/
4342 -- cursor diferent_projects_cur is going to be used when the source and target projects are different
4343 -- Reference to pa_tasks is changed to pa_struct_task_wbs_v (bug 3354518)
4344
4345 CURSOR different_projects_task_cur IS
4346 SELECT pra.resource_assignment_id -- SOURCE_RES_ASSIGNMENT_ID
4347 ,pa_resource_assignments_s.nextval -- TARGET_RES_ASSIGNMENT_ID
4348 ,pra.parent_assignment_id -- PARENT_ASSIGNMENT_ID
4349 ,pra.task_id -- SOURCE_TASK_ID
4350 ,target_tasks.task_id -- TARGET_TASK_ID
4351 ,NULL -- SOURCE ELEMENT_VERSION_ID
4352 ,NULL -- TARGET ELEMENT_VERSION_ID
4353 ,-1 -- PROJECT_ASSIGNMENT_ID
4354 ,pra.planning_start_date + l_shift_days -- PLANNING_START_DATE
4355 ,pra.planning_end_date + l_shift_days -- PLANNING_END_DATE
4356 /* It is assumed that this api and this cursor would not be called for TA/WP flow!
4357 So, the schedule dates are stamped as planning start dates itself */
4358 ,pra.planning_start_date + l_shift_days -- SCHEDULE_START_DATE
4359 ,pra.planning_end_date + l_shift_days -- SCHEDULE_END_DATE
4360 ,target_rlm.resource_list_member_id -- bug 3615617 TARGET_RLM_ID
4361 FROM pa_resource_assignments pra
4362 ,pa_tasks source_tasks
4363 ,pa_tasks target_tasks
4364 ,pa_resource_list_members source_rlm -- bug 3615617
4365 ,pa_resource_list_members target_rlm -- bug 3615617
4366 WHERE pra.budget_version_id = p_source_plan_version_id
4367 AND pra.project_id = p_source_project_id --bug#2708524
4368 AND source_tasks.task_id = pra.task_id
4369 AND source_tasks.task_number = target_tasks.task_number
4370 AND target_tasks.project_id = l_target_project_id
4371 AND source_rlm.resource_list_member_id = pra.resource_list_member_id -- bug 3615617
4372 AND target_rlm.resource_list_id = source_rlm.resource_list_id -- bug 3615617
4373 AND target_rlm.alias = source_rlm.alias -- bug 3615617
4374 AND target_rlm.object_type = source_rlm.object_type -- bug 3615617
4375 AND target_rlm.object_id = Decode(target_rlm.object_type, -- bug 3615617
4376 'RESOURCE_LIST', target_rlm.resource_list_id,
4377 'PROJECT', l_target_project_id)
4378 AND pra.task_id <> 0; -- bug 3615617 this is redundant but put for clarity
4379
4380
4381 --bug#2684748
4382 --This cursor is added to resolve the issue of resource
4383 --assignments being not populated when planning level
4384 --is PROJECT and source and target project id is different.
4385
4386 CURSOR proj_plan_lev_diff_proj_cur IS
4387 SELECT resource_assignment_id -- SOURCE_RES_ASSIGNMENT_ID
4388 ,pa_resource_assignments_s.nextval -- TARGET_RES_ASSIGNMENT_ID
4389 ,NULL -- PARENT_ASSIGNMENT_ID
4390 ,0 -- SOURCE_TASK_ID
4391 ,0 -- TARGET_TASK_ID
4392 --Start of Changes for bug 3354518
4393 ,NULL -- SOURCE ELEMENT_VERSION_ID
4394 ,NULL -- TARGET ELEMENT_VERSION_ID
4395 ,-1 -- PROJECT_ASSIGNMENT_ID
4396 ,planning_start_date + l_shift_days -- PLANNING_START_DATE
4397 ,planning_end_date + l_shift_days -- PLANNING_END_DATE
4398 /* It is assumed that this api and this cursor would not be called for TA/WP flow!
4399 So, the schedule dates are stamped as planning start dates itself */
4400 ,planning_start_date + l_shift_days -- SCHEDULE_START_DATE
4401 ,planning_end_date + l_shift_days -- SCHEDULE_END_DATE
4402 --End of Changes for bug 3354518
4403 ,target_rlm.resource_list_member_id -- bug 3615617 TARGET_RLM_ID
4404 FROM pa_resource_assignments pra
4405 ,pa_resource_list_members source_rlm -- bug 3615617
4406 ,pa_resource_list_members target_rlm -- bug 3615617
4407 WHERE pra.budget_version_id = p_source_plan_version_id
4408 AND pra.task_id = 0
4409 AND source_rlm.resource_list_member_id = pra.resource_list_member_id -- bug 3615617
4410 AND target_rlm.resource_list_id = source_rlm.resource_list_id -- bug 3615617
4411 AND target_rlm.alias = source_rlm.alias -- bug 3615617
4412 AND target_rlm.object_type = source_rlm.object_type -- bug 3615617
4413 AND target_rlm.object_id = Decode(target_rlm.object_type, -- bug 3615617
4414 'RESOURCE_LIST', target_rlm.resource_list_id,
4415 'PROJECT', l_target_project_id) ;
4416 BEGIN
4417
4418 x_msg_count := 0;
4419 x_return_status := FND_API.G_RET_STS_SUCCESS;
4420 pa_debug.set_err_stack('pa_fp_org_fcst_gen_pub.Create_Res_Task_Maps');
4421 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
4422 l_debug_mode := NVL(l_debug_mode, 'Y');
4423 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
4424
4425 -- Check for business rules violations
4426
4427 IF P_PA_DEBUG_MODE = 'Y' THEN
4428 pa_debug.g_err_stage:='Validating input parameters';
4429 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4430 END IF;
4431
4432 -- Check for null source_plan__version_id
4433
4434 IF (p_source_plan_version_id IS NULL) THEN
4435
4436 IF P_PA_DEBUG_MODE = 'Y' THEN
4437 pa_debug.g_err_stage:='Source fin plan version id'||p_source_plan_version_id;
4438 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,5);
4439 END IF;
4440
4441 PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
4442 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
4443 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4444 END IF;
4445
4446 IF P_PA_DEBUG_MODE = 'Y' THEN
4447 pa_debug.g_err_stage:='Parameter validation complete';
4448 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4449 END IF;
4450
4451 -- If adjustment percentage is null make it zero.
4452 -- Similarly, if shift days is null make it zero
4453
4454 l_adj_percentage := NVL(p_adj_percentage,0);
4455 l_shift_days := NVL(p_shift_days,0);
4456
4457 IF P_PA_DEBUG_MODE = 'Y' THEN
4458 pa_debug.g_err_stage:='Source fin plan version id'||p_source_plan_version_id;
4459 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4460
4461 pa_debug.g_err_stage:='Adj_percentage = '||l_adj_percentage;
4462 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4463 END IF;
4464
4465 --Fetch source project id
4466
4467 IF P_PA_DEBUG_MODE = 'Y' THEN
4468 pa_debug.g_err_stage:='Fetching source project id ';
4469 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4470 END IF;
4471
4472 SELECT project_id
4473 INTO l_source_project_id
4474 FROM pa_budget_versions
4475 WHERE budget_version_id = p_source_plan_version_id;
4476
4477 --IF target project id isn't passed, copy source projecct to target project
4478
4479 l_target_project_id := NVL(p_target_project_id,l_source_project_id);
4480
4481 IF P_PA_DEBUG_MODE = 'Y' THEN
4482 pa_debug.g_err_stage:='Source_project_id = '||l_source_project_id;
4483 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4484
4485 pa_debug.g_err_stage:='Target_project_id = '||l_target_project_id;
4486 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4487 END IF;
4488
4489
4490 -- Remove the old records, if any,from pa_fp_ra_map_tmp
4491
4492 DELETE FROM pa_fp_ra_map_tmp;
4493
4494 --Using bulk insert logic here
4495
4496 IF (l_source_project_id = l_target_project_id) THEN
4497
4498 /* Included conditional opening of cursor for bug# 2920954 */
4499
4500 IF p_calling_module = PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN AND
4501 p_copy_mode = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED THEN
4502
4503 IF P_PA_DEBUG_MODE = 'Y' THEN
4504 pa_debug.g_err_stage:='opening baseline_budgt_res_cur';
4505 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4506 END IF;
4507
4508 OPEN baseline_budgt_res_cur;
4509
4510 ELSE
4511
4512 IF P_PA_DEBUG_MODE = 'Y' THEN
4513 pa_debug.g_err_stage:='opening same_projects_cur';
4514 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4515 END IF;
4516
4517 OPEN same_projects_cur;
4518
4519 END IF;
4520
4521 /* Bug 3067254 The fetch statement should be inside the loop to avoid infinite loop*/
4522 LOOP
4523
4524 --Doing the bulk fetch
4525
4526 IF p_calling_module = PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN AND
4527 p_copy_mode = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED THEN
4528
4529 IF P_PA_DEBUG_MODE = 'Y' THEN
4530 pa_debug.g_err_stage:='fetching from cursor baseline_budgt_res_cur';
4531 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4532 END IF;
4533
4534 FETCH baseline_budgt_res_cur BULK COLLECT INTO
4535 l_ra_map_tmp_tbl1
4536 ,l_ra_map_tmp_tbl2
4537 ,l_ra_map_tmp_tbl3
4538 ,l_ra_map_tmp_tbl4
4539 ,l_ra_map_tmp_tbl5
4540 --Added for bug 3354518
4541 ,l_ra_map_tmp_tbl6
4542 ,l_ra_map_tmp_tbl7
4543 ,l_ra_map_tmp_tbl8
4544 ,l_ra_map_tmp_tbl9
4545 ,l_ra_map_tmp_tbl10
4546 ,l_ra_map_tmp_tbl11
4547 ,l_ra_map_tmp_tbl12
4548 --Added for bug 3615617
4549 ,l_ra_map_tmp_tbl13
4550 LIMIT g_plsql_max_array_size;
4551
4552 ELSE
4553
4554 IF P_PA_DEBUG_MODE = 'Y' THEN
4555 pa_debug.g_err_stage:='fetching from same_projects_cur';
4556 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4557 END IF;
4558
4559 FETCH same_projects_cur BULK COLLECT INTO
4560 l_ra_map_tmp_tbl1
4561 ,l_ra_map_tmp_tbl2
4562 ,l_ra_map_tmp_tbl3
4563 ,l_ra_map_tmp_tbl4
4564 ,l_ra_map_tmp_tbl5
4565 --Added for bug 3354518
4566 ,l_ra_map_tmp_tbl6
4567 ,l_ra_map_tmp_tbl7
4568 ,l_ra_map_tmp_tbl8
4569 ,l_ra_map_tmp_tbl9
4570 ,l_ra_map_tmp_tbl10
4571 ,l_ra_map_tmp_tbl11
4572 ,l_ra_map_tmp_tbl12
4573 --Added for bug 3615617
4574 ,l_ra_map_tmp_tbl13
4575 LIMIT g_plsql_max_array_size;
4576
4577 END IF;
4578
4579 /* Bug 3067254 LOOP */
4580
4581 IF NVL(l_ra_map_tmp_tbl1.last,0) >= 1 THEN
4582
4583 --Only if something is fetched
4584
4585 FORALL i in l_ra_map_tmp_tbl1.first..l_ra_map_tmp_tbl1.last
4586
4587 INSERT INTO pa_fp_ra_map_tmp
4588 (source_res_assignment_id
4589 ,target_res_assignment_id
4590 ,resource_assignment_id --parent of source res_assignment_id
4591 ,source_task_id
4592 ,target_task_id
4593 --Added for bug 3354518
4594 ,system_reference1
4595 ,system_reference2
4596 ,system_reference3
4597 ,planning_start_date
4598 ,planning_end_date
4599 ,schedule_start_date
4600 ,schedule_end_date
4601 ,system_reference4) -- Bug 3615617
4602 VALUES ( l_ra_map_tmp_tbl1(i)
4603 ,l_ra_map_tmp_tbl2(i)
4604 ,l_ra_map_tmp_tbl3(i)
4605 ,l_ra_map_tmp_tbl4(i)
4606 ,l_ra_map_tmp_tbl5(i)
4607 --Added for bug 3354518
4608 ,l_ra_map_tmp_tbl6(i)
4609 ,l_ra_map_tmp_tbl7(i)
4610 ,l_ra_map_tmp_tbl8(i)
4611 ,l_ra_map_tmp_tbl9(i)
4612 ,l_ra_map_tmp_tbl10(i)
4613 ,l_ra_map_tmp_tbl11(i)
4614 ,l_ra_map_tmp_tbl12(i)
4615 ,l_ra_map_tmp_tbl13(i)); -- Bug 3615617
4616
4617 END IF;
4618
4619 --exit loop if the recent fetch size is less than 200
4620
4621 EXIT WHEN NVL(l_ra_map_tmp_tbl1.last,0)<g_plsql_max_array_size;
4622
4623 END LOOP;
4624
4625
4626 IF p_calling_module = PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN AND
4627 p_copy_mode = PA_FP_CONSTANTS_PKG.G_BUDGET_STATUS_BASELINED THEN
4628
4629 CLOSE baseline_budgt_res_cur;
4630
4631 IF P_PA_DEBUG_MODE = 'Y' THEN
4632 pa_debug.g_err_stage:='cursor baseline_budgt_res_cur is closed';
4633 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4634 END IF;
4635
4636 ELSE
4637
4638 CLOSE same_projects_cur;
4639
4640 IF P_PA_DEBUG_MODE = 'Y' THEN
4641 pa_debug.g_err_stage:='cursor same_projects_cur is closed';
4642 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4643 END IF;
4644
4645 END IF;
4646
4647 ELSE -- if projects are different
4648
4649 -- bug 3841942 for periodic time phased versions check if the shift days i/p
4650 -- is large enough to cause a shift in the periodic data
4651
4652 l_target_time_phased_code :=
4653 PA_FIN_PLAN_UTILS.get_time_phased_code(p_source_plan_version_id);
4654
4655 IF l_shift_days <> 0
4656 AND l_target_time_phased_code IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,
4657 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P)
4658 THEN
4659 BEGIN
4660
4661 IF P_PA_DEBUG_MODE = 'Y' THEN
4662 pa_debug.g_err_stage := 'Selecting project start date';
4663 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4664 END IF;
4665
4666 SELECT p.start_date
4667 INTO l_start_date
4668 FROM pa_projects p
4669 WHERE p.project_id = l_source_project_id;
4670
4671 IF l_start_date IS NULL THEN
4672
4673 IF P_PA_DEBUG_MODE = 'Y' THEN
4674 pa_debug.g_err_stage := 'Selecting task mininum start date';
4675 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4676 END IF;
4677
4678 SELECt min(t.start_date)
4679 INTO l_start_date
4680 FROM pa_tasks t
4681 WHERE t.project_id = l_source_project_id;
4682
4683 IF l_start_date is NULL THEN
4684
4685 IF P_PA_DEBUG_MODE = 'Y' THEN
4686 pa_debug.g_err_stage := 'Selecting budget lines minimum start date';
4687 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4688 END IF;
4689
4690 SELECT min(bl.start_date)
4691 INTO l_start_Date
4692 FROM pa_budget_lines bl
4693 WHERE bl.budget_version_id = p_source_plan_version_id;
4694
4695 END IF; /* Mininum Task start date is null */
4696
4697 END IF; /* Minimum Project start date is null */
4698 EXCEPTION
4699 WHEN OTHERS THEN
4700 IF P_PA_DEBUG_MODE = 'Y' THEN
4701 pa_debug.g_err_stage := 'Error while fetching start date ' || sqlerrm;
4702 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,5);
4703 END IF;
4704 RAISE;
4705 END;
4706
4707 -- If l_start_date is null then that implies there are no budget lines
4708 IF l_start_date IS NOT NULL THEN
4709 -- Based on the shift_days check how much shift is required period wise
4710 pa_budget_core.get_periods(
4711 x_start_date1 => l_start_date,
4712 x_start_date2 => l_start_date + l_shift_days,
4713 x_period_type => l_target_time_phased_code,
4714 x_periods => l_periods,
4715 x_err_code => l_err_code,
4716 x_err_stage => l_err_stage,
4717 x_err_stack => l_err_stack);
4718 IF l_err_code <> 0 THEN
4719 IF P_PA_DEBUG_MODE = 'Y' THEN
4720 pa_debug.g_err_stage := 'Exception raised by pa_budget_core.get_periods...';
4721 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,5);
4722 END IF;
4723
4724 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
4725 p_msg_name => l_err_stage);
4726 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
4727 END IF;
4728
4729 -- If l_periods is 0 then budget line data does not require a shift so no
4730 -- shift is required in the planning start and end dates as well
4731 IF l_periods = 0 THEN
4732 l_shift_days := 0;
4733 END IF;
4734 END IF;
4735 END IF; -- IF l_shift_days <> 0 AND l_target_time_phased_code IN ('G','P')
4736
4737 IF P_PA_DEBUG_MODE = 'Y' THEN
4738 pa_debug.g_err_stage:='opening different_projects_task_cur ';
4739 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4740 END IF;
4741
4742 OPEN proj_plan_lev_diff_proj_cur ;
4743 LOOP
4744 --Doing the bulk fetch
4745 FETCH proj_plan_lev_diff_proj_cur BULK COLLECT INTO
4746 l_ra_map_tmp_tbl1
4747 ,l_ra_map_tmp_tbl2
4748 ,l_ra_map_tmp_tbl3
4749 ,l_ra_map_tmp_tbl4
4750 ,l_ra_map_tmp_tbl5
4751 --Added for bug 3354518
4752 ,l_ra_map_tmp_tbl6
4753 ,l_ra_map_tmp_tbl7
4754 ,l_ra_map_tmp_tbl8
4755 ,l_ra_map_tmp_tbl9
4756 ,l_ra_map_tmp_tbl10
4757 ,l_ra_map_tmp_tbl11
4758 ,l_ra_map_tmp_tbl12
4759 --Added for bug 3615617
4760 ,l_ra_map_tmp_tbl13
4761 LIMIT g_plsql_max_array_size;
4762
4763 IF NVL(l_ra_map_tmp_tbl1.last,0) >= 1 THEN
4764
4765 /* only if something is fetched */
4766
4767 FORALL i IN l_ra_map_tmp_tbl1.first..l_ra_map_tmp_tbl1.last
4768
4769 INSERT INTO pa_fp_ra_map_tmp
4770 (source_res_assignment_id
4771 ,target_res_assignment_id
4772 ,resource_assignment_id --parent of source res_assignment_id
4773 ,source_task_id
4774 ,target_task_id
4775 --Added for bug 3354518
4776 ,system_reference1
4777 ,system_reference2
4778 ,system_reference3
4779 ,planning_start_date
4780 ,planning_end_date
4781 ,schedule_start_date
4782 ,schedule_end_date
4783 -- Added for bug 3615617
4784 ,system_reference4
4785 )
4786 VALUES (l_ra_map_tmp_tbl1(i)
4787 ,l_ra_map_tmp_tbl2(i)
4788 ,l_ra_map_tmp_tbl3(i)
4789 ,l_ra_map_tmp_tbl4(i)
4790 ,l_ra_map_tmp_tbl5(i)
4791 --Added for bug 3354518
4792 ,l_ra_map_tmp_tbl6(i)
4793 ,l_ra_map_tmp_tbl7(i)
4794 ,l_ra_map_tmp_tbl8(i)
4795 ,l_ra_map_tmp_tbl9(i)
4796 ,l_ra_map_tmp_tbl10(i)
4797 ,l_ra_map_tmp_tbl11(i)
4798 ,l_ra_map_tmp_tbl12(i)
4799 -- Added for bug 3615617
4800 ,l_ra_map_tmp_tbl13(i));
4801 END IF;
4802
4803 --Exit loop if the recent fetch size is less than 200
4804
4805 EXIT WHEN NVL(l_ra_map_tmp_tbl1.last,0) < g_plsql_max_array_size;
4806 END LOOP;
4807 CLOSE proj_plan_lev_diff_proj_cur ;
4808
4809 -- If planning level is not project, task level resource assignments also should be copied
4810 l_source_plan_level_code := PA_FIN_PLAN_UTILS.Get_Fin_Plan_Level_Code(p_source_plan_version_id);
4811
4812 IF l_source_plan_level_code <> 'P' THEN
4813 OPEN different_projects_task_cur;
4814 LOOP
4815 --Doing the bulk fetch
4816 FETCH different_projects_task_cur BULK COLLECT INTO
4817 l_ra_map_tmp_tbl1
4818 ,l_ra_map_tmp_tbl2
4819 ,l_ra_map_tmp_tbl3
4820 ,l_ra_map_tmp_tbl4
4821 ,l_ra_map_tmp_tbl5
4822 --Added for bug 3354518
4823 ,l_ra_map_tmp_tbl6
4824 ,l_ra_map_tmp_tbl7
4825 ,l_ra_map_tmp_tbl8
4826 ,l_ra_map_tmp_tbl9
4827 ,l_ra_map_tmp_tbl10
4828 ,l_ra_map_tmp_tbl11
4829 ,l_ra_map_tmp_tbl12
4830 --Added for bug 3615617
4831 ,l_ra_map_tmp_tbl13
4832 LIMIT g_plsql_max_array_size;
4833
4834 IF NVL(l_ra_map_tmp_tbl1.last,0) >= 1 THEN
4835
4836 /* only if something is fetched */
4837
4838 FORALL i IN l_ra_map_tmp_tbl1.first..l_ra_map_tmp_tbl1.last
4839
4840 INSERT INTO pa_fp_ra_map_tmp
4841 (source_res_assignment_id
4842 ,target_res_assignment_id
4843 ,resource_assignment_id --parent of source res_assignment_id
4844 ,source_task_id
4845 ,target_task_id
4846 --Added for bug 3354518
4847 ,system_reference1
4848 ,system_reference2
4849 ,system_reference3
4850 ,planning_start_date
4851 ,planning_end_date
4852 ,schedule_start_date
4853 ,schedule_end_date
4854 -- Added for bug 3615617
4855 ,system_reference4
4856 )
4857 VALUES (l_ra_map_tmp_tbl1(i)
4858 ,l_ra_map_tmp_tbl2(i)
4859 ,l_ra_map_tmp_tbl3(i)
4860 ,l_ra_map_tmp_tbl4(i)
4861 ,l_ra_map_tmp_tbl5(i)
4862 --Added for bug 3354518
4863 ,l_ra_map_tmp_tbl6(i)
4864 ,l_ra_map_tmp_tbl7(i)
4865 ,l_ra_map_tmp_tbl8(i)
4866 ,l_ra_map_tmp_tbl9(i)
4867 ,l_ra_map_tmp_tbl10(i)
4868 ,l_ra_map_tmp_tbl11(i)
4869 ,l_ra_map_tmp_tbl12(i)
4870 -- Added for bug 3615617
4871 ,l_ra_map_tmp_tbl13(i));
4872 END IF;
4873
4874 --Exit loop if the recent fetch size is less than 200
4875
4876 EXIT WHEN NVL(l_ra_map_tmp_tbl1.last,0) < g_plsql_max_array_size;
4877 END LOOP;
4878 CLOSE different_projects_task_cur ;
4879 IF P_PA_DEBUG_MODE = 'Y' THEN
4880 pa_debug.g_err_stage:='cursor different_projects_task_cur is closed';
4881 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4882 END IF;
4883 END IF; -- task level planning
4884 END IF; -- same/different projects
4885
4886 IF P_PA_DEBUG_MODE = 'Y' THEN
4887 pa_debug.g_err_stage:='Exiting Create_Res_Task_Maps';
4888 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,3);
4889 END IF;
4890
4891 pa_debug.reset_err_stack;
4892
4893 EXCEPTION
4894
4895 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
4896 l_msg_count := FND_MSG_PUB.count_msg;
4897 IF l_msg_count = 1 THEN
4898 PA_INTERFACE_UTILS_PUB.get_messages
4899 (p_encoded => FND_API.G_TRUE
4900 ,p_msg_index => 1
4901 ,p_msg_count => l_msg_count
4902 ,p_msg_data => l_msg_data
4903 ,p_data => l_data
4904 ,p_msg_index_out => l_msg_index_out);
4905 x_msg_data := l_data;
4906 x_msg_count := l_msg_count;
4907 ELSE
4908 x_msg_count := l_msg_count;
4909 END IF;
4910 x_return_status := FND_API.G_RET_STS_ERROR;
4911 IF P_PA_DEBUG_MODE = 'Y' THEN
4912 pa_debug.g_err_stage:='Invalid Arguments Passed';
4913 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,5);
4914 END IF;
4915 pa_debug.reset_err_stack;
4916 RAISE;
4917
4918 WHEN Others THEN
4919 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4920 x_msg_count := 1;
4921 x_msg_data := SQLERRM;
4922 FND_MSG_PUB.add_exc_msg( p_pkg_name => 'pa_fp_org_fcst_gen_pub'
4923 ,p_procedure_name => 'CREATE_RES_TASK_MAPS');
4924 IF P_PA_DEBUG_MODE = 'Y' THEN
4925 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
4926 pa_debug.write('create_res_task_maps: ' || g_module_name,pa_debug.g_err_stage,5);
4927 END IF;
4928 pa_debug.reset_err_stack;
4929 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4930
4931 END CREATE_RES_TASK_MAPS;
4932
4933
4934 /*************************************************************************
4935 sgoteti 03/03/2005.This API was previously in PAFPCPFB.pls, Copied it here as this will be used
4936 only in Org Forecasting Context. (Note: copy_resource_assignments in latest PAFPCPFB.pls will not
4937 go thru pa_fp_ra_map_tmp). The code is copied without any change from the version 115.196 of
4938 PAFPCPFB.pls to reduce the impact. The parameter p_rbs_map_diff_flag can be considered as an
4939 obsolete parameter in org forecasting flow.
4940 **************************************************************************/
4941
4942 PROCEDURE Copy_Resource_Assignments(
4943 p_source_plan_version_id IN NUMBER
4944 ,p_target_plan_version_id IN NUMBER
4945 ,p_adj_percentage IN NUMBER
4946 ,p_rbs_map_diff_flag IN VARCHAR2 DEFAULT 'N'
4947 ,p_calling_context IN VARCHAR2 DEFAULT NULL -- Bug 4065314
4948 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4949 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
4950 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
4951 AS
4952 l_msg_count NUMBER :=0;
4953 l_data VARCHAR2(2000);
4954 l_msg_data VARCHAR2(2000);
4955 l_error_msg_code VARCHAR2(2000);
4956 l_msg_index_out NUMBER;
4957 l_return_status VARCHAR2(2000);
4958 l_debug_mode VARCHAR2(30);
4959
4960 l_adj_percentage NUMBER ;
4961 l_target_project_id pa_projects.project_id%TYPE;
4962 l_cost_flag pa_fin_plan_amount_sets.raw_cost_flag%TYPE;
4963 l_revenue_flag pa_fin_plan_amount_sets.revenue_flag%TYPE;
4964
4965 l_tmp NUMBER;
4966
4967
4968 BEGIN
4969
4970 x_msg_count := 0;
4971 x_return_status := FND_API.G_RET_STS_SUCCESS;
4972 pa_debug.set_err_stack('pa_fp_org_fcst_gen_pub.Copy_Resource_Assignments');
4973 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
4974 l_debug_mode := NVL(l_debug_mode, 'Y');
4975 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
4976
4977 /*
4978 * Check if source_verion_id, target_version_id are NULL, if so throw
4979 * an error message
4980 */
4981
4982 IF P_PA_DEBUG_MODE = 'Y' THEN
4983 pa_debug.g_err_stage := 'Checking for valid parameters:';
4984 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
4985 END IF;
4986
4987 IF (p_source_plan_version_id IS NULL) OR
4988 (p_target_plan_version_id IS NULL)
4989 THEN
4990
4991 IF P_PA_DEBUG_MODE = 'Y' THEN
4992 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
4993 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
4994
4995 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
4996 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
4997 END IF;
4998
4999 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
5000 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
5001 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5002 END IF;
5003
5004 IF P_PA_DEBUG_MODE = 'Y' THEN
5005 pa_debug.g_err_stage := 'Parameter validation complete';
5006 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5007 END IF;
5008
5009 --If adj_percentage is zero make it null
5010
5011 l_adj_percentage := NVL(p_adj_percentage,0);
5012
5013 --Fetching the flags of target version using fin_plan_prefernce_code
5014
5015 IF P_PA_DEBUG_MODE = 'Y' THEN
5016 pa_debug.g_err_stage:='Fetching the raw_cost,burdened_cost and revenue flags of target_version';
5017 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5018 END IF;
5019
5020 SELECT DECODE(fin_plan_preference_code
5021 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY ,'Y'
5022 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME , 'Y','N') --cost_flag
5023 ,DECODE(fin_plan_preference_code
5024 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY ,'Y'
5025 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME ,'Y','N')--revenue_flag
5026 ,project_id
5027 INTO l_cost_flag
5028 ,l_revenue_flag
5029 ,l_target_project_id
5030 FROM pa_proj_fp_options
5031 WHERE fin_plan_version_id=p_target_plan_version_id;
5032 /*
5033 IF P_PA_DEBUG_MODE = 'Y' THEN
5034 pa_debug.g_err_stage:='l_cost_flag ='||l_cost_flag;
5035 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5036 pa_debug.g_err_stage:='l_revenue_flag ='||l_revenue_flag;
5037 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5038 pa_debug.g_err_stage:='l_target_project_id ='||l_target_project_id;
5039 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5040 END IF;
5041 */
5042 --Inserting records into pa_resource_assignments using pa_fp_ra_map_tmp
5043
5044 IF P_PA_DEBUG_MODE = 'Y' THEN
5045 pa_debug.g_err_stage:='Copying the source version records as target version records';
5046 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5047 END IF;
5048
5049 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
5050
5051 --Bug 3974569. Need not have pa_rbs_plans_out_tmp in the FROM clause if the parameter is N
5052 IF P_PA_DEBUG_MODE = 'Y' THEN
5053 pa_debug.g_err_stage:='p_rbs_map_diff_flag '||p_rbs_map_diff_flag;
5054 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5055 END IF;
5056
5057 IF p_rbs_map_diff_flag ='N' THEN
5058
5059 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
5060 resource_assignment_id
5061 ,budget_version_id
5062 ,project_id
5063 ,task_id
5064 ,resource_list_member_id
5065 ,last_update_date
5066 ,last_updated_by
5067 ,creation_date
5068 ,created_by
5069 ,last_update_login
5070 ,unit_of_measure
5071 ,track_as_labor_flag
5072 ,total_plan_revenue
5073 ,total_plan_raw_cost
5074 ,total_plan_burdened_cost
5075 ,total_plan_quantity
5076 ,resource_assignment_type
5077 ,total_project_raw_cost
5078 ,total_project_burdened_cost
5079 ,total_project_revenue
5080 ,standard_bill_rate
5081 ,average_bill_rate
5082 ,average_cost_rate
5083 ,project_assignment_id
5084 ,plan_error_code
5085 ,average_discount_percentage
5086 ,total_borrowed_revenue
5087 ,total_revenue_adj
5088 ,total_lent_resource_cost
5089 ,total_cost_adj
5090 ,total_unassigned_time_cost
5091 ,total_utilization_percent
5092 ,total_utilization_hours
5093 ,total_utilization_adj
5094 ,total_capacity
5095 ,total_head_count
5096 ,total_head_count_adj
5097 ,total_tp_revenue_in
5098 ,total_tp_revenue_out
5099 ,total_tp_cost_in
5100 ,total_tp_cost_out
5101 ,parent_assignment_id
5102 ,wbs_element_version_id
5103 ,rbs_element_id
5104 ,planning_start_date
5105 ,planning_end_date
5106 ,schedule_start_date
5107 ,schedule_end_date
5108 ,spread_curve_id
5109 ,etc_method_code
5110 ,res_type_code
5111 ,attribute_category
5112 ,attribute1
5113 ,attribute2
5114 ,attribute3
5115 ,attribute4
5116 ,attribute5
5117 ,attribute6
5118 ,attribute7
5119 ,attribute8
5120 ,attribute9
5121 ,attribute10
5122 ,attribute11
5123 ,attribute12
5124 ,attribute13
5125 ,attribute14
5126 ,attribute15
5127 ,attribute16
5128 ,attribute17
5129 ,attribute18
5130 ,attribute19
5131 ,attribute20
5132 ,attribute21
5133 ,attribute22
5134 ,attribute23
5135 ,attribute24
5136 ,attribute25
5137 ,attribute26
5138 ,attribute27
5139 ,attribute28
5140 ,attribute29
5141 ,attribute30
5142 ,fc_res_type_code
5143 ,resource_class_code
5144 ,organization_id
5145 ,job_id
5146 ,person_id
5147 ,expenditure_type
5148 ,expenditure_category
5149 ,revenue_category_code
5150 ,event_type
5151 ,supplier_id
5152 ,non_labor_resource
5153 ,bom_resource_id
5154 ,inventory_item_id
5155 ,item_category_id
5156 ,record_version_number
5157 ,transaction_source_code
5158 ,mfc_cost_type_id
5159 ,procure_resource_flag
5160 ,assignment_description
5161 ,incurred_by_res_flag
5162 ,rate_job_id
5163 ,rate_expenditure_type
5164 ,ta_display_flag
5165 ,sp_fixed_date
5166 ,person_type_code
5167 ,rate_based_flag
5168 ,use_task_schedule_flag
5169 ,rate_exp_func_curr_code
5170 ,rate_expenditure_org_id
5171 ,incur_by_res_class_code
5172 ,incur_by_role_id
5173 ,project_role_id
5174 ,resource_class_flag
5175 ,named_role
5176 ,txn_accum_header_id
5177 ,scheduled_delay --For Bug 3948128
5178 )
5179 SELECT /*+ ORDERED USE_NL(PFRMT,PRA) INDEX(PRA PA_RESOURCE_ASSIGNMENTS_U1)*/ pfrmt.target_res_assignment_id --Bug 2814165
5180 ,p_target_plan_version_id
5181 ,l_target_project_id
5182 ,pfrmt.target_task_id
5183 ,pfrmt.system_reference4 -- Bug 3615617 resource_list_member_id
5184 ,sysdate
5185 ,fnd_global.user_id
5186 ,sysdate
5187 ,fnd_global.user_id
5188 ,fnd_global.login_id
5189 ,pra.unit_of_measure
5190 ,pra.track_as_labor_flag
5191 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
5192 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
5193 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
5194 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
5195 ,pra.resource_assignment_type
5196 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
5197 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
5198 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
5199 ,standard_bill_rate
5200 ,average_bill_rate
5201 ,average_cost_rate
5202 ,pfrmt.system_reference3 -- Project assignment id of the target (Bug 3354518)
5203 ,plan_error_code
5204 ,average_discount_percentage
5205 ,total_borrowed_revenue
5206 ,total_revenue_adj
5207 ,total_lent_resource_cost
5208 ,total_cost_adj
5209 ,total_unassigned_time_cost
5210 ,total_utilization_percent
5211 ,total_utilization_hours
5212 ,total_utilization_adj
5213 ,total_capacity
5214 ,total_head_count
5215 ,total_head_count_adj
5216 ,total_tp_revenue_in
5217 ,total_tp_revenue_out
5218 ,total_tp_cost_in
5219 ,total_tp_cost_out
5220 ,pfrmt.parent_assignment_id
5221 ,pfrmt.system_reference2 -- element version id of the target. (Bug 3354518)
5222 ,pra.rbs_element_id
5223 ,pfrmt.planning_start_date -- Planning start date of the target (Bug 3354518)
5224 ,pfrmt.planning_end_date -- Planning end date of the target (Bug 3354518)
5225 ,pfrmt.schedule_start_date
5226 ,pfrmt.schedule_end_date
5227 ,pra.spread_curve_id
5228 ,pra.etc_method_code
5229 ,pra.res_type_code
5230 ,pra.attribute_category
5231 ,pra.attribute1
5232 ,pra.attribute2
5233 ,pra.attribute3
5234 ,pra.attribute4
5235 ,pra.attribute5
5236 ,pra.attribute6
5237 ,pra.attribute7
5238 ,pra.attribute8
5239 ,pra.attribute9
5240 ,pra.attribute10
5241 ,pra.attribute11
5242 ,pra.attribute12
5243 ,pra.attribute13
5244 ,pra.attribute14
5245 ,pra.attribute15
5246 ,pra.attribute16
5247 ,pra.attribute17
5248 ,pra.attribute18
5249 ,pra.attribute19
5250 ,pra.attribute20
5251 ,pra.attribute21
5252 ,pra.attribute22
5253 ,pra.attribute23
5254 ,pra.attribute24
5255 ,pra.attribute25
5256 ,pra.attribute26
5257 ,pra.attribute27
5258 ,pra.attribute28
5259 ,pra.attribute29
5260 ,pra.attribute30
5261 ,pra.fc_res_type_code
5262 ,pra.resource_class_code
5263 ,pra.organization_id
5264 ,pra.job_id
5265 ,pra.person_id
5266 ,pra.expenditure_type
5267 ,pra.expenditure_category
5268 ,pra.revenue_category_code
5269 ,pra.event_type
5270 ,pra.supplier_id
5271 ,pra.non_labor_resource
5272 ,pra.bom_resource_id
5273 ,pra.inventory_item_id
5274 ,pra.item_category_id
5275 ,1 -- should be 1 in the target version being created
5276 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
5277 ,pra.mfc_cost_type_id
5278 ,pra.procure_resource_flag
5279 ,pra.assignment_description
5280 ,pra.incurred_by_res_flag
5281 ,pra.rate_job_id
5282 ,pra.rate_expenditure_type
5283 ,pra.ta_display_flag
5284 -- Bug 3820625 sp_fixed_date should also move as per planning_start_date
5285 -- Least and greatest are used to make sure that sp_fixed_date is with in planning start and end dates
5286 ,greatest(least(pra.sp_fixed_date + (pfrmt.planning_start_date - pra.planning_start_date),
5287 pfrmt.planning_end_date),
5288 pfrmt.planning_start_date)
5289 ,pra.person_type_code
5290 ,pra.rate_based_flag
5291 ,pra.use_task_schedule_flag
5292 ,pra.rate_exp_func_curr_code
5293 ,pra.rate_expenditure_org_id
5294 ,pra.incur_by_res_class_code
5295 ,pra.incur_by_role_id
5296 ,pra.project_role_id
5297 ,pra.resource_class_flag
5298 ,pra.named_role
5299 ,pra.txn_accum_header_id
5300 ,scheduled_delay --For Bug 3948128
5301 FROM PA_FP_RA_MAP_TMP pfrmt --Bug 2814165
5302 ,PA_RESOURCE_ASSIGNMENTS pra
5303 WHERE pra.resource_assignment_id = pfrmt.source_res_assignment_id
5304 AND pra.budget_version_id = p_source_plan_version_id ;
5305
5306 --For Bug 3974569. Take rbs_element_id and txn_accum_header_id from pa_rbs_plans_out_tmp
5307 ELSIF p_rbs_map_diff_flag ='Y' THEN --IF p_rbs_map_diff_flag ='N' THEN
5308
5309 IF P_PA_DEBUG_MODE = 'Y' THEN
5310
5311 SELECT COUNT(*)
5312 INTO l_tmp
5313 FROM PA_FP_RA_MAP_TMP;
5314
5315 pa_debug.g_err_stage:='PA_FP_RA_MAP_TMP count '||l_tmp;
5316 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5317
5318 SELECT COUNT(*)
5319 INTO l_tmp
5320 FROM pa_rbs_plans_out_tmp;
5321
5322 pa_debug.g_err_stage:='pa_rbs_plans_out_tmp count '||l_tmp;
5323 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5324
5325 END IF;
5326
5327 INSERT INTO PA_RESOURCE_ASSIGNMENTS(
5328 resource_assignment_id
5329 ,budget_version_id
5330 ,project_id
5331 ,task_id
5332 ,resource_list_member_id
5333 ,last_update_date
5334 ,last_updated_by
5335 ,creation_date
5336 ,created_by
5337 ,last_update_login
5338 ,unit_of_measure
5339 ,track_as_labor_flag
5340 ,total_plan_revenue
5341 ,total_plan_raw_cost
5342 ,total_plan_burdened_cost
5343 ,total_plan_quantity
5344 ,resource_assignment_type
5345 ,total_project_raw_cost
5346 ,total_project_burdened_cost
5347 ,total_project_revenue
5348 ,standard_bill_rate
5349 ,average_bill_rate
5350 ,average_cost_rate
5351 ,project_assignment_id
5352 ,plan_error_code
5353 ,average_discount_percentage
5354 ,total_borrowed_revenue
5355 ,total_revenue_adj
5356 ,total_lent_resource_cost
5357 ,total_cost_adj
5358 ,total_unassigned_time_cost
5359 ,total_utilization_percent
5360 ,total_utilization_hours
5361 ,total_utilization_adj
5362 ,total_capacity
5363 ,total_head_count
5364 ,total_head_count_adj
5365 ,total_tp_revenue_in
5366 ,total_tp_revenue_out
5367 ,total_tp_cost_in
5368 ,total_tp_cost_out
5369 ,parent_assignment_id
5370 ,wbs_element_version_id
5371 ,rbs_element_id
5372 ,planning_start_date
5373 ,planning_end_date
5374 ,schedule_start_date
5375 ,schedule_end_date
5376 ,spread_curve_id
5377 ,etc_method_code
5378 ,res_type_code
5379 ,attribute_category
5380 ,attribute1
5381 ,attribute2
5382 ,attribute3
5383 ,attribute4
5384 ,attribute5
5385 ,attribute6
5386 ,attribute7
5387 ,attribute8
5388 ,attribute9
5389 ,attribute10
5390 ,attribute11
5391 ,attribute12
5392 ,attribute13
5393 ,attribute14
5394 ,attribute15
5395 ,attribute16
5396 ,attribute17
5397 ,attribute18
5398 ,attribute19
5399 ,attribute20
5400 ,attribute21
5401 ,attribute22
5402 ,attribute23
5403 ,attribute24
5404 ,attribute25
5405 ,attribute26
5406 ,attribute27
5407 ,attribute28
5408 ,attribute29
5409 ,attribute30
5410 ,fc_res_type_code
5411 ,resource_class_code
5412 ,organization_id
5413 ,job_id
5414 ,person_id
5415 ,expenditure_type
5416 ,expenditure_category
5417 ,revenue_category_code
5418 ,event_type
5419 ,supplier_id
5420 ,non_labor_resource
5421 ,bom_resource_id
5422 ,inventory_item_id
5423 ,item_category_id
5424 ,record_version_number
5425 ,transaction_source_code
5426 ,mfc_cost_type_id
5427 ,procure_resource_flag
5428 ,assignment_description
5429 ,incurred_by_res_flag
5430 ,rate_job_id
5431 ,rate_expenditure_type
5432 ,ta_display_flag
5433 ,sp_fixed_date
5434 ,person_type_code
5435 ,rate_based_flag
5436 ,use_task_schedule_flag
5437 ,rate_exp_func_curr_code
5438 ,rate_expenditure_org_id
5439 ,incur_by_res_class_code
5440 ,incur_by_role_id
5441 ,project_role_id
5442 ,resource_class_flag
5443 ,named_role
5444 ,txn_accum_header_id
5445 ,scheduled_delay --For Bug 3948128
5446 )
5447 SELECT /*+ ORDERED USE_NL(PFRMT,PRA,RMAP) INDEX(PRA PA_RESOURCE_ASSIGNMENTS_U1)*/ pfrmt.target_res_assignment_id --Bug 2814165
5448 ,p_target_plan_version_id
5449 ,l_target_project_id
5450 ,pfrmt.target_task_id
5451 ,pfrmt.system_reference4 -- Bug 3615617 resource_list_member_id
5452 ,sysdate
5453 ,fnd_global.user_id
5454 ,sysdate
5455 ,fnd_global.user_id
5456 ,fnd_global.login_id
5457 ,pra.unit_of_measure
5458 ,pra.track_as_labor_flag
5459 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_plan_revenue,NULL),NULL)
5460 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_raw_cost,NULL),NULL)
5461 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_plan_burdened_cost,NULL),NULL)
5462 ,DECODE(l_adj_percentage,0,total_plan_quantity,NULL)
5463 ,pra.resource_assignment_type
5464 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_raw_cost,NULL),NULL)
5465 ,DECODE(l_adj_percentage,0,DECODE(l_cost_flag,'Y',total_project_burdened_cost,NULL),NULL)
5466 ,DECODE(l_adj_percentage,0,DECODE(l_revenue_flag,'Y',total_project_revenue,NULL),NULL)
5467 ,standard_bill_rate
5468 ,average_bill_rate
5469 ,average_cost_rate
5470 ,pfrmt.system_reference3 -- Project assignment id of the target (Bug 3354518)
5471 ,plan_error_code
5472 ,average_discount_percentage
5473 ,total_borrowed_revenue
5474 ,total_revenue_adj
5475 ,total_lent_resource_cost
5476 ,total_cost_adj
5477 ,total_unassigned_time_cost
5478 ,total_utilization_percent
5479 ,total_utilization_hours
5480 ,total_utilization_adj
5481 ,total_capacity
5482 ,total_head_count
5483 ,total_head_count_adj
5484 ,total_tp_revenue_in
5485 ,total_tp_revenue_out
5486 ,total_tp_cost_in
5487 ,total_tp_cost_out
5488 ,pfrmt.parent_assignment_id
5489 ,pfrmt.system_reference2 -- element version id of the target. (Bug 3354518)
5490 ,rmap.rbs_element_id
5491 ,pfrmt.planning_start_date -- Planning start date of the target (Bug 3354518)
5492 ,pfrmt.planning_end_date -- Planning end date of the target (Bug 3354518)
5493 ,pfrmt.schedule_start_date
5494 ,pfrmt.schedule_end_date
5495 ,pra.spread_curve_id
5496 ,pra.etc_method_code
5497 ,pra.res_type_code
5498 ,pra.attribute_category
5499 ,pra.attribute1
5500 ,pra.attribute2
5501 ,pra.attribute3
5502 ,pra.attribute4
5503 ,pra.attribute5
5504 ,pra.attribute6
5505 ,pra.attribute7
5506 ,pra.attribute8
5507 ,pra.attribute9
5508 ,pra.attribute10
5509 ,pra.attribute11
5510 ,pra.attribute12
5511 ,pra.attribute13
5512 ,pra.attribute14
5513 ,pra.attribute15
5514 ,pra.attribute16
5515 ,pra.attribute17
5516 ,pra.attribute18
5517 ,pra.attribute19
5518 ,pra.attribute20
5519 ,pra.attribute21
5520 ,pra.attribute22
5521 ,pra.attribute23
5522 ,pra.attribute24
5523 ,pra.attribute25
5524 ,pra.attribute26
5525 ,pra.attribute27
5526 ,pra.attribute28
5527 ,pra.attribute29
5528 ,pra.attribute30
5529 ,pra.fc_res_type_code
5530 ,pra.resource_class_code
5531 ,pra.organization_id
5532 ,pra.job_id
5533 ,pra.person_id
5534 ,pra.expenditure_type
5535 ,pra.expenditure_category
5536 ,pra.revenue_category_code
5537 ,pra.event_type
5538 ,pra.supplier_id
5539 ,pra.non_labor_resource
5540 ,pra.bom_resource_id
5541 ,pra.inventory_item_id
5542 ,pra.item_category_id
5543 ,1 -- should be 1 in the target version being created
5544 ,decode(p_calling_context, 'CREATE_VERSION', NULL, pra.transaction_source_code)
5545 ,pra.mfc_cost_type_id
5546 ,pra.procure_resource_flag
5547 ,pra.assignment_description
5548 ,pra.incurred_by_res_flag
5549 ,pra.rate_job_id
5550 ,pra.rate_expenditure_type
5551 ,pra.ta_display_flag
5552 -- Bug 3820625 sp_fixed_date should also move as per planning_start_date
5553 -- Least and greatest are used to make sure that sp_fixed_date is with in planning start and end dates
5554 ,greatest(least(pra.sp_fixed_date + (pfrmt.planning_start_date - pra.planning_start_date),
5555 pfrmt.planning_end_date),
5556 pfrmt.planning_start_date)
5557 ,pra.person_type_code
5558 ,pra.rate_based_flag
5559 ,pra.use_task_schedule_flag
5560 ,pra.rate_exp_func_curr_code
5561 ,pra.rate_expenditure_org_id
5562 ,pra.incur_by_res_class_code
5563 ,pra.incur_by_role_id
5564 ,pra.project_role_id
5565 ,pra.resource_class_flag
5566 ,pra.named_role
5567 ,rmap.txn_accum_header_id
5568 ,scheduled_delay --For Bug 3948128
5569 FROM PA_FP_RA_MAP_TMP pfrmt --Bug 2814165
5570 ,PA_RESOURCE_ASSIGNMENTS pra
5571 ,pa_rbs_plans_out_tmp rmap
5572 WHERE pra.resource_assignment_id = pfrmt.source_res_assignment_id
5573 AND pra.budget_version_id = p_source_plan_version_id
5574 AND rmap.source_id = pra.resource_assignment_id;
5575
5576
5577 END IF;--IF p_rbs_map_diff_flag ='N' THEN
5578
5579 l_tmp := SQL%ROWCOUNT;
5580 IF P_PA_DEBUG_MODE = 'Y' THEN
5581 pa_debug.g_err_stage:='No. of records inserted into PRA '||l_tmp;
5582 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5583 END IF;
5584
5585 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
5586 IF P_PA_DEBUG_MODE = 'Y' THEN
5587 pa_debug.g_err_stage:='Exiting Copy_Resource_Assignments';
5588 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,3);
5589 END IF;
5590 pa_debug.reset_err_stack; -- bug:- 2815593
5591 EXCEPTION
5592
5593 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
5594 l_msg_count := FND_MSG_PUB.count_msg;
5595 IF l_msg_count = 1 THEN
5596 PA_INTERFACE_UTILS_PUB.get_messages
5597 (p_encoded => FND_API.G_TRUE
5598 ,p_msg_index => 1
5599 ,p_msg_count => l_msg_count
5600 ,p_msg_data => l_msg_data
5601 ,p_data => l_data
5602 ,p_msg_index_out => l_msg_index_out);
5603 x_msg_data := l_data;
5604 x_msg_count := l_msg_count;
5605 ELSE
5606 x_msg_count := l_msg_count;
5607 END IF;
5608 x_return_status := FND_API.G_RET_STS_ERROR;
5609
5610 IF P_PA_DEBUG_MODE = 'Y' THEN
5611 pa_debug.g_err_stage:='Invalid Arguments Passed';
5612 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
5613 END IF;
5614 pa_debug.reset_err_stack;
5615 RAISE;
5616
5617 WHEN Others THEN
5618 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5619 x_msg_count := 1;
5620 x_msg_data := SQLERRM;
5621 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'pa_fp_org_fcst_gen_pub'
5622 ,p_procedure_name => 'COPY_RESOURCE_ASSIGNMENTS');
5623
5624 IF P_PA_DEBUG_MODE = 'Y' THEN
5625 pa_debug.g_err_stage:='Unexpected Error'||SQLERRM;
5626 pa_debug.write('Copy_Resource_Assignments: ' || g_module_name,pa_debug.g_err_stage,5);
5627 END IF;
5628 pa_debug.reset_err_stack;
5629 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5630
5631 END Copy_Resource_Assignments;
5632
5633 /*===================================================================
5634 sgoteti 03/03/2005.This API was previously in PAFPCPFB.pls, Copied it here as this will be used
5635 only in Org Forecasting Context. (Note: Copy_Budget_Lines in latest PAFPCPFB.pls will not
5636 go thru pa_fp_ra_map_tmp). The code is copied without any change from the version 115.196 of P
5637 PAFPCPFB.pls to reduce the impact.
5638 ===================================================================*/
5639
5640 PROCEDURE Copy_Budget_Lines(
5641 p_source_plan_version_id IN NUMBER
5642 ,p_target_plan_version_id IN NUMBER
5643 ,p_adj_percentage IN NUMBER
5644 ,x_return_status OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5645 ,x_msg_count OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
5646 ,x_msg_data OUT NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
5647 AS
5648
5649 l_msg_count NUMBER :=0;
5650 l_data VARCHAR2(2000);
5651 l_msg_data VARCHAR2(2000);
5652 l_error_msg_code VARCHAR2(2000);
5653 l_msg_index_out NUMBER;
5654 l_return_status VARCHAR2(2000);
5655 l_debug_mode VARCHAR2(30);
5656
5657 l_source_period_profile_id pa_budget_versions.period_profile_id%TYPE;
5658 l_target_period_profile_id pa_budget_versions.period_profile_id%TYPE;
5659
5660 l_revenue_flag pa_fin_plan_amount_sets.revenue_flag%type;
5661 l_cost_flag pa_fin_plan_amount_sets.raw_cost_flag%type;
5662
5663 l_adj_percentage NUMBER ;
5664 l_period_profiles_same_flag VARCHAR2(1);
5665
5666 -- Bug 3927244
5667 l_copy_actuals_flag VARCHAR2(1) := 'Y';
5668 l_src_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
5669 l_trg_plan_class_code pa_fin_plan_types_b.plan_class_code%TYPE;
5670 l_wp_version_flag pa_budget_versions.wp_version_flag%TYPE;
5671
5672 l_etc_start_date pa_budget_versions.etc_start_date%TYPE;
5673
5674 CURSOR get_plan_class_code_csr(c_budget_version_id pa_budget_versions.budget_version_id%TYPE) IS
5675 SELECT pfb.plan_class_code,nvl(pbv.wp_version_flag,'N'),etc_start_date
5676 FROM pa_fin_plan_types_b pfb,
5677 pa_budget_versions pbv
5678 WHERE pbv.budget_version_id = c_budget_version_id
5679 AND pbv.fin_plan_type_id = pfb.fin_plan_type_id;
5680 -- Bug 3927244
5681
5682 BEGIN
5683
5684 x_msg_count := 0;
5685 x_return_status := FND_API.G_RET_STS_SUCCESS;
5686 pa_debug.set_err_stack('pa_fp_org_fcst_gen_pub.Copy_Budget_Lines');
5687 fnd_profile.get('PA_DEBUG_MODE',l_debug_mode);
5688 l_debug_mode := NVL(l_debug_mode, 'Y');
5689 pa_debug.set_process('PLSQL','LOG',l_debug_mode);
5690
5691 -- Checking for all valid input parametrs
5692
5693 IF P_PA_DEBUG_MODE = 'Y' THEN
5694 pa_debug.g_err_stage := 'Checking for valid parameters:';
5695 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5696 END IF;
5697
5698 IF (p_source_plan_version_id IS NULL) OR
5699 (p_target_plan_version_id IS NULL)
5700 THEN
5701
5702 IF P_PA_DEBUG_MODE = 'Y' THEN
5703 pa_debug.g_err_stage := 'Source_plan='||p_source_plan_version_id;
5704 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5705 pa_debug.g_err_stage := 'Target_plan'||p_target_plan_version_id;
5706 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
5707 END IF;
5708
5709 PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
5710 p_msg_name => 'PA_FP_INV_PARAM_PASSED');
5711
5712 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
5713
5714 END IF;
5715
5716 IF P_PA_DEBUG_MODE = 'Y' THEN
5717 pa_debug.g_err_stage := 'Parameter validation complete';
5718 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5719 END IF;
5720 /*
5721 pa_debug.g_err_stage:='Source fin plan version id'||p_source_plan_version_id;
5722 IF P_PA_DEBUG_MODE = 'Y' THEN
5723 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5724 END IF;
5725 pa_debug.g_err_stage:='Target fin plan version id'||p_target_plan_version_id;
5726 IF P_PA_DEBUG_MODE = 'Y' THEN
5727 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5728 END IF;
5729 */
5730 --make adj percentage zero if passed as null
5731
5732 l_adj_percentage := NVL(p_adj_percentage,0);
5733 /*
5734 pa_debug.g_err_stage:='Adj_percentage'||l_adj_percentage;
5735 IF P_PA_DEBUG_MODE = 'Y' THEN
5736 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5737 END IF;
5738 */
5739 -- Fetching the flags of target version using fin_plan_prefernce_code
5740
5741
5742 IF P_PA_DEBUG_MODE = 'Y' THEN
5743 pa_debug.g_err_stage:='Fetching the raw_cost,burdened_cost and revenue flags of target_version';
5744 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5745 END IF;
5746
5747 SELECT DECODE(fin_plan_preference_code -- l_revenue_flag
5748 ,PA_FP_CONSTANTS_PKG.G_PREF_REVENUE_ONLY ,'Y'
5749 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME ,'Y','N')
5750 ,DECODE(fin_plan_preference_code -- l_cost_flag
5751 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_ONLY ,'Y'
5752 ,PA_FP_CONSTANTS_PKG.G_PREF_COST_AND_REV_SAME , 'Y','N')
5753 INTO l_revenue_flag
5754 ,l_cost_flag
5755 FROM pa_proj_fp_options
5756 WHERE fin_plan_version_id=p_target_plan_version_id;
5757 /*
5758 pa_debug.g_err_stage:='l_revenue_flag ='||l_revenue_flag;
5759 IF P_PA_DEBUG_MODE = 'Y' THEN
5760 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5761 END IF;
5762 pa_debug.g_err_stage:='l_cost_flag ='||l_cost_flag;
5763 IF P_PA_DEBUG_MODE = 'Y' THEN
5764 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5765 END IF;
5766 */
5767 -- Checking if source and target version period profiles match
5768
5769 /* FPB2: REVIEW */
5770
5771 /** MRC Elimination changes: PA_MRC_FINPLAN.populate_bl_map_tmp */
5772 PA_FIN_PLAN_UTILS2.populate_bl_map_tmp
5773 (p_source_fin_plan_version_id => p_source_plan_version_id,
5774 x_return_status => x_return_status,
5775 x_msg_count => x_msg_count,
5776 x_msg_data => x_msg_data);
5777
5778 IF P_PA_DEBUG_MODE = 'Y' THEN
5779 pa_debug.g_err_stage:='Inserting budget_lines';
5780 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
5781 END IF;
5782
5783 -- Bug 3927244: Actuals need to be copied from forecast to forecast within the same project for FINPLAN versions
5784
5785 OPEN get_plan_class_code_csr(p_source_plan_version_id);
5786 FETCH get_plan_class_code_csr
5787 INTO l_src_plan_class_code,l_wp_version_flag,l_etc_start_date;
5788 CLOSE get_plan_class_code_csr;
5789
5790 OPEN get_plan_class_code_csr(p_target_plan_version_id);
5791 FETCH get_plan_class_code_csr
5792 INTO l_trg_plan_class_code,l_wp_version_flag,l_etc_start_date;
5793 CLOSE get_plan_class_code_csr;
5794
5795 IF l_wp_version_flag='Y' OR l_src_plan_class_code <> PA_FP_CONSTANTS_PKG.G_PLAN_CLASS_FORECAST OR
5796 l_trg_plan_class_code <> PA_FP_CONSTANTS_PKG.G_PLAN_CLASS_FORECAST THEN
5797 l_copy_actuals_flag := 'N';
5798 END IF;
5799
5800 -- End: Bug 3927244
5801
5802 -- Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
5803 --Bug 4052403. For non rate-based transactions quantity should be same as raw cost if the version type is COST/ALL or
5804 --it should be revenue if the version type is REVENUE. This business rule will be taken care by the API
5805 --PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts which is called after this INSERT. Note that this has to be done only
5806 --when adjustment% is not null since the amounts in the source will be altered only when the user enters some adj %
5807 --Bug 4188225. PC/PFC buckets will be copied unconditionally (Removed the condition that checks for l_adj_percentage
5808 --being greater than 0 in order to copy)
5809 INSERT INTO PA_BUDGET_LINES(
5810 budget_line_id /* FPB2 */
5811 ,budget_version_id /* FPB2 */
5812 ,resource_assignment_id
5813 ,start_date
5814 ,last_update_date
5815 ,last_updated_by
5816 ,creation_date
5817 ,created_by
5818 ,last_update_login
5819 ,end_date
5820 ,period_name
5821 ,quantity
5822 ,raw_cost
5823 ,burdened_cost
5824 ,revenue
5825 ,change_reason_code
5826 ,description
5827 ,attribute_category
5828 ,attribute1
5829 ,attribute2
5830 ,attribute3
5831 ,attribute4
5832 ,attribute5
5833 ,attribute6
5834 ,attribute7
5835 ,attribute8
5836 ,attribute9
5837 ,attribute10
5838 ,attribute11
5839 ,attribute12
5840 ,attribute13
5841 ,attribute14
5842 ,attribute15
5843 ,raw_cost_source
5844 ,burdened_cost_source
5845 ,quantity_source
5846 ,revenue_source
5847 ,pm_product_code
5848 ,pm_budget_line_reference
5849 ,cost_rejection_code
5850 ,revenue_rejection_code
5851 ,burden_rejection_code
5852 ,other_rejection_code
5853 ,code_combination_id
5854 ,ccid_gen_status_code
5855 ,ccid_gen_rej_message
5856 ,request_id
5857 ,borrowed_revenue
5858 ,tp_revenue_in
5859 ,tp_revenue_out
5860 ,revenue_adj
5861 ,lent_resource_cost
5862 ,tp_cost_in
5863 ,tp_cost_out
5864 ,cost_adj
5865 ,unassigned_time_cost
5866 ,utilization_percent
5867 ,utilization_hours
5868 ,utilization_adj
5869 ,capacity
5870 ,head_count
5871 ,head_count_adj
5872 ,projfunc_currency_code
5873 ,projfunc_cost_rate_type
5874 ,projfunc_cost_exchange_rate
5875 ,projfunc_cost_rate_date_type
5876 ,projfunc_cost_rate_date
5877 ,projfunc_rev_rate_type
5878 ,projfunc_rev_exchange_rate
5879 ,projfunc_rev_rate_date_type
5880 ,projfunc_rev_rate_date
5881 ,project_currency_code
5882 ,project_cost_rate_type
5883 ,project_cost_exchange_rate
5884 ,project_cost_rate_date_type
5885 ,project_cost_rate_date
5886 ,project_raw_cost
5887 ,project_burdened_cost
5888 ,project_rev_rate_type
5889 ,project_rev_exchange_rate
5890 ,project_rev_rate_date_type
5891 ,project_rev_rate_date
5892 ,project_revenue
5893 ,txn_raw_cost
5894 ,txn_burdened_cost
5895 ,txn_currency_code
5896 ,txn_revenue
5897 ,bucketing_period_code
5898 ,transfer_price_rate
5899 ,init_quantity
5900 ,init_quantity_source
5901 ,init_raw_cost
5902 ,init_burdened_cost
5903 ,init_revenue
5904 ,init_raw_cost_source
5905 ,init_burdened_cost_source
5906 ,init_revenue_source
5907 ,project_init_raw_cost
5908 ,project_init_burdened_cost
5909 ,project_init_revenue
5910 ,txn_init_raw_cost
5911 ,txn_init_burdened_cost
5912 ,txn_init_revenue
5913 ,txn_markup_percent
5914 ,txn_markup_percent_override
5915 ,txn_discount_percentage
5916 ,txn_standard_bill_rate
5917 ,txn_standard_cost_rate
5918 ,txn_cost_rate_override
5919 ,burden_cost_rate
5920 ,txn_bill_rate_override
5921 ,burden_cost_rate_override
5922 ,cost_ind_compiled_set_id
5923 ,pc_cur_conv_rejection_code
5924 ,pfc_cur_conv_rejection_code
5925 )
5926 SELECT bmt.target_budget_line_id /* FPB2 */
5927 ,p_target_plan_version_id /* FPB2 */
5928 ,pfrmt.target_res_assignment_id
5929 ,pbl.start_date
5930 ,sysdate
5931 ,fnd_global.user_id
5932 ,sysdate
5933 ,fnd_global.user_id
5934 ,fnd_global.login_id
5935 ,pbl.end_date
5936 ,pbl.period_name
5937 ,pbl.quantity
5938 ,DECODE(l_cost_flag,'Y', raw_cost,NULL)
5939 ,DECODE(l_cost_flag,'Y', burdened_cost,NULL)
5940 ,DECODE(l_revenue_flag,'Y', revenue,NULL)
5941 ,pbl.change_reason_code
5942 ,description
5943 ,attribute_category
5944 ,attribute1
5945 ,attribute2
5946 ,attribute3
5947 ,attribute4
5948 ,attribute5
5949 ,attribute6
5950 ,attribute7
5951 ,attribute8
5952 ,attribute9
5953 ,attribute10
5954 ,attribute11
5955 ,attribute12
5956 ,attribute13
5957 ,attribute14
5958 ,attribute15
5959 ,DECODE(l_cost_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --raw_cost_souce
5960 ,DECODE(l_cost_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --burdened_cost_source
5961 ,PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P --quantity_source
5962 ,DECODE(l_revenue_flag,'Y',PA_FP_CONSTANTS_PKG.G_AMOUNT_SOURCE_COPY_P,NULL) --revenue source
5963 ,pm_product_code
5964 ,pm_budget_line_reference
5965 ,DECODE(l_cost_flag, 'Y',cost_rejection_code, NULL)
5966 ,DECODE(l_revenue_flag, 'Y',revenue_rejection_code, NULL)
5967 ,DECODE(l_cost_flag,'Y',burden_rejection_code, NULL)
5968 ,other_rejection_code
5969 ,code_combination_id
5970 ,ccid_gen_status_code
5971 ,ccid_gen_rej_message
5972 ,fnd_global.conc_request_id
5973 ,borrowed_revenue
5974 ,tp_revenue_in
5975 ,tp_revenue_out
5976 ,revenue_adj
5977 ,lent_resource_cost
5978 ,tp_cost_in
5979 ,tp_cost_out
5980 ,cost_adj
5981 ,unassigned_time_cost
5982 ,utilization_percent
5983 ,utilization_hours
5984 ,utilization_adj
5985 ,capacity
5986 ,head_count
5987 ,head_count_adj
5988 ,projfunc_currency_code
5989 ,DECODE(l_cost_flag,'Y',projfunc_cost_rate_type,NULL)
5990 ,DECODE(l_cost_flag,'Y',projfunc_cost_exchange_rate,NULL)
5991 ,DECODE(l_cost_flag,'Y',projfunc_cost_rate_date_type,NULL)
5992 ,DECODE(l_cost_flag,'Y',projfunc_cost_rate_date,NULL)
5993 ,DECODE(l_revenue_flag,'Y',projfunc_rev_rate_type,NULL)
5994 ,DECODE(l_revenue_flag,'Y',projfunc_rev_exchange_rate,NULL)
5995 ,DECODE(l_revenue_flag,'Y',projfunc_rev_rate_date_type,NULL)
5996 ,DECODE(l_revenue_flag,'Y',projfunc_rev_rate_date,NULL)
5997 ,project_currency_code
5998 ,DECODE(l_cost_flag,'Y',project_cost_rate_type,NULL)
5999 ,DECODE(l_cost_flag,'Y',project_cost_exchange_rate,NULL)
6000 ,DECODE(l_cost_flag,'Y',project_cost_rate_date_type,NULL)
6001 ,DECODE(l_cost_flag,'Y',project_cost_rate_date,NULL)
6002 ,DECODE(l_cost_flag,'Y', project_raw_cost,NULL)
6003 ,DECODE(l_cost_flag,'Y', project_burdened_cost,NULL)
6004 ,DECODE(l_revenue_flag,'Y',project_rev_rate_type,NULL)
6005 ,DECODE(l_revenue_flag,'Y',project_rev_exchange_rate,NULL)
6006 ,DECODE(l_revenue_flag,'Y',project_rev_rate_date_type,NULL)
6007 ,DECODE(l_revenue_flag,'Y',project_rev_rate_date,NULL)
6008 ,DECODE(l_revenue_flag,'Y', project_revenue,NULL)
6009 ,DECODE(l_cost_flag,'Y',
6010 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)
6011 ,DECODE(l_cost_flag,'Y',
6012 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)
6013 ,txn_currency_code
6014 ,DECODE(l_revenue_flag,'Y',
6015 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)
6016 ,DECODE(l_period_profiles_same_flag,'Y',bucketing_period_code,NULL)
6017 ,transfer_price_rate
6018 ,decode(l_copy_actuals_flag,'N',NULL,pbl.init_quantity) --init_quantity
6019 ,decode(l_copy_actuals_flag,'N',NULL,pbl.init_quantity_source) --init_quantity_source
6020 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.init_raw_cost),NULL) --init_raw_cost
6021 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.init_burdened_cost),NULL) --init_burdened_cost
6022 ,DECODE(l_revenue_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.init_revenue),NULL) --init_revenue
6023 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.init_raw_cost_source),NULL) --init_raw_cost_source
6024 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.init_burdened_cost_source),NULL) --init_burdened_cost_source
6025 ,DECODE(l_revenue_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.init_revenue_source),NULL) --init_revenue_source
6026 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.project_init_raw_cost),NULL) --project_init_raw_cost
6027 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.project_init_burdened_cost),NULL) --project_init_burdened_cost
6028 ,DECODE(l_revenue_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.project_init_revenue),NULL) --project_init_revenue
6029 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.txn_init_raw_cost),NULL) --txn_init_raw_cost
6030 ,DECODE(l_cost_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.txn_init_burdened_cost),NULL) --txn_init_burdened_cost
6031 ,DECODE(l_revenue_flag,'Y',decode(l_copy_actuals_flag,'N',NULL,pbl.txn_init_revenue),NULL) --txn_init_revenue
6032 ,txn_markup_percent
6033 ,txn_markup_percent_override
6034 ,txn_discount_percentage
6035 ,Decode(l_revenue_flag,'Y',txn_standard_bill_rate,null) --txn_standard_bill_rate
6036 ,Decode(l_cost_flag,'Y',txn_standard_cost_rate,null) --txn_standard_cost_rate
6037 ,Decode(l_cost_flag,'Y',txn_cost_rate_override,null) --txn_cost_rate_override
6038 ,Decode(l_cost_flag,'Y',burden_cost_rate,null) --burden_cost_rate
6039 ,Decode(l_revenue_flag,'Y',txn_bill_rate_override,null) --txn_bill_rate_override
6040 ,Decode(l_cost_flag,'Y',burden_cost_rate_override,null) --burden_cost_rate_override
6041 ,cost_ind_compiled_set_id
6042 ,Decode(l_adj_percentage,0,pc_cur_conv_rejection_code,null)
6043 ,Decode(l_adj_percentage,0,pfc_cur_conv_rejection_code,null)
6044 FROM PA_BUDGET_LINES pbl
6045 ,PA_FP_RA_MAP_TMP pfrmt
6046 ,pa_fp_bl_map_tmp bmt /* FPB2 */
6047 WHERE pbl.resource_assignment_id = pfrmt.source_res_assignment_id
6048 AND bmt.source_budget_line_id = pbl.budget_line_id /* FPB2 */
6049 AND pbl.budget_version_id = p_source_plan_version_id;
6050
6051 -- End, Bug 3362316, 08-JAN-2003: Added New FP.M Columns --------------------------
6052
6053 -- Bug 4035856 Call rounding api if l_adj_percentage is not zero
6054 IF l_adj_percentage <> 0 THEN
6055 PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts
6056 ( p_budget_version_id => p_target_plan_version_id
6057 ,p_calling_context => 'COPY_VERSION'
6058 ,x_return_status => l_return_status
6059 ,x_msg_count => l_msg_count
6060 ,x_msg_data => l_msg_data);
6061
6062 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6063 IF P_PA_debug_mode = 'Y' THEN
6064 pa_debug.g_err_stage:= 'Error in PA_FP_MULTI_CURRENCY_PKG.Round_Budget_Line_Amounts';
6065 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
6066 END IF;
6067 RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6068 END IF;
6069 END IF;
6070
6071 IF P_PA_DEBUG_MODE = 'Y' THEN
6072 pa_debug.g_err_stage:='Exiting Copy_Budget_Lines';
6073 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,3);
6074 END IF;
6075 pa_debug.reset_err_stack; -- bug:- 2815593
6076 EXCEPTION
6077
6078 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
6079 l_msg_count := FND_MSG_PUB.count_msg;
6080 IF l_msg_count = 1 THEN
6081 PA_INTERFACE_UTILS_PUB.get_messages
6082 (p_encoded => FND_API.G_TRUE
6083 ,p_msg_index => 1
6084 ,p_msg_count => l_msg_count
6085 ,p_msg_data => l_msg_data
6086 ,p_data => l_data
6087 ,p_msg_index_out => l_msg_index_out);
6088 x_msg_data := l_data;
6089 x_msg_count := l_msg_count;
6090 ELSE
6091 x_msg_count := l_msg_count;
6092 END IF;
6093 x_return_status := FND_API.G_RET_STS_ERROR;
6094
6095 IF P_PA_DEBUG_MODE = 'Y' THEN
6096 pa_debug.g_err_stage:='Invalid arguments passed';
6097 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,5);
6098 END IF;
6099 pa_debug.reset_err_stack;
6100 RAISE;
6101
6102 WHEN Others THEN
6103 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6104 x_msg_count := 1;
6105 x_msg_data := SQLERRM;
6106 FND_MSG_PUB.add_exc_msg( p_pkg_name=> 'pa_fp_org_fcst_gen_pub'
6107 ,p_procedure_name => 'COPY_BUDGET_LINES');
6108
6109 IF P_PA_DEBUG_MODE = 'Y' THEN
6110 pa_debug.g_err_stage:='Unexpected error'||SQLERRM;
6111 pa_debug.write('Copy_Budget_Lines: ' || g_module_name,pa_debug.g_err_stage,6);
6112 END IF;
6113 pa_debug.reset_err_stack;
6114 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6115 END Copy_Budget_Lines;
6116
6117
6118 END pa_fp_org_fcst_gen_pub;