DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_BUDGET_CORE

Source


1 PACKAGE BODY pa_budget_core AS
2 -- $Header: PAXBUBCB.pls 120.23.12020000.3 2012/12/07 10:40:41 tvala ship $
3 
4   -- Bug Fix: 4569365. Removed MRC code.
5   -- g_mrc_exception EXCEPTION;
6   p_pa_debug_mode       Varchar2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
7   g_module_name varchar2(100) := 'pa_budget_core';
8 
9   PROCEDURE PRINT_MSG(P_MSG  VARCHAR2) is
10   BEGIN
11         --dbms_output.put_line(P_MSG);
12         IF P_PA_DEBUG_MODE = 'Y' Then
13             pa_debug.g_err_stage := substr('LOG:'||p_msg,1,240);
14             PA_DEBUG.write
15                 (x_Module       => g_module_name
16                 ,x_Msg          => pa_debug.g_err_stage
17                 ,x_Log_Level    => 3);
18         END IF;
19         Return;
20   END PRINT_MSG;
21 
22   procedure shift_periods(x_start_period_date in date,
23                           x_periods      in  number,
24                           x_period_name  in out NOCOPY varchar2, --File.Sql.39 bug 4440895
25                           x_period_type  in varchar2,
26                           x_start_date   in out NOCOPY date, --File.Sql.39 bug 4440895
27                           x_end_date     in out NOCOPY date, --File.Sql.39 bug 4440895
28                           x_err_code     in out NOCOPY number, --File.Sql.39 bug 4440895
29                           x_err_stage    in out NOCOPY varchar2, --File.Sql.39 bug 4440895
30                           x_err_stack    in out NOCOPY varchar2) --File.Sql.39 bug 4440895
31   is
32   cursor c is
33   select period_name, start_date , end_date
34   from PA_periods
35   where   start_date > x_start_period_date
36   order by  start_date ;
37 
38   cursor c1 is
39   select period_name, start_date , end_date
40   from PA_periods
41   where     start_date < x_start_period_date
42   order by  start_date  desc;
43 
44 cursor c2 is
45   select period_name, start_date , end_date
46   from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
47   where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
48   AND P.APPLICATION_ID = pa_period_process_pkg.application_id
49   AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
50   and   start_date > x_start_period_date
51   order by start_date ;
52 
53 
54   cursor c3 is
55   select period_name, start_date , end_date
56   from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
57   where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
58   AND P.APPLICATION_ID = pa_period_process_pkg.application_id
59   AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
60   and   start_date < x_start_period_date
61   order by start_date  desc;
62 
63 
64 
65 
66   old_stack                     varchar2(630);
67   number_period   number(10);
68 
69   begin
70     x_err_code := 0;
71     old_stack := x_err_stack;
72     x_err_stack := x_err_stack || '->shift_periods';
73 
74     if x_periods > 0 then
75 
76         IF  NVL(x_period_type ,'X') = 'P' THEN
77 
78           select count(*)
79           into   number_period
80           from pa_periods
81           where start_date > x_start_period_date;
82 
83         ELSIF  NVL(x_period_type ,'X') = 'G' THEN
84 
85           select count(*)
86           into   number_period
87           from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
91           AND   start_date > x_start_period_date;
88           where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
89           AND P.APPLICATION_ID = pa_period_process_pkg.application_id
90           AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
92         END IF ;
93 
94     -- Bug 12760225 Bug#11867498: Removed the error properly for the fix of bug#7556248
95       if number_period < abs(x_periods) then
96 
97           -- x_err_code := 20;  -- Removed error being thrown for Bug 7556248
98           -- x_err_stage := 'PA_BU_INVALID_NEW_PERIOD';
99           return;
100       end if;
101 
102         IF NVL(x_period_type,'X') = 'P' THEN
103           open c;
104           for i in 1..abs(x_periods)
105           loop
106           fetch c into x_period_name, x_start_date, x_end_date;
107           exit when c%notfound;
108           end loop;
109           close c;
110         ELSIF NVL(x_period_type,'X') = 'G' THEN
111           open c2;
112           for i in 1..abs(x_periods)
113           loop
114           fetch c2 into x_period_name, x_start_date, x_end_date;
115           exit when c2%notfound;
116           end loop;
117           close c2;
118         END IF;
119 
120     elsif x_periods < 0 then
121 
122         IF  NVL(x_period_type ,'X') = 'P' THEN
123 
124           select count(*)
125           into   number_period
126           from pa_periods
127           where   start_date < x_start_period_date;
128         ELSIF  NVL(x_period_type ,'X') = 'G' THEN
129           select count(*)
130           into   number_period
131           from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
132           where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
133           AND P.APPLICATION_ID = pa_period_process_pkg.application_id
134           AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
135           AND start_date < x_start_period_date;
136         END IF ;
137 
138       --Bug 12760225 Bug#11867498: Removed the error properly for the fix of bug#7556248
139       if number_period < abs(x_periods) then
140 
141           -- x_err_code := 20;  -- Removed error being thrown for Bug 7556248
142           -- x_err_stage := 'PA_BU_INVALID_NEW_PERIOD';
143           return;
144       end if;
145 
146         IF NVL(x_period_type,'X') = 'P' THEN
147           open c1;
148           for i in 1..abs(x_periods)
149           loop
150           fetch c1 into x_period_name, x_start_date, x_end_date;
151           exit when c1%notfound;
152           end loop;
153           close c1;
154         ELSIF  NVL(x_period_type ,'X') = 'G' THEN
155           open c3;
156           for i in 1..abs(x_periods)
157           loop
158           fetch c3 into x_period_name, x_start_date, x_end_date;
159           exit when c3%notfound;
160           end loop;
161           close c3;
162         END IF;
163 
164     end if;
165 
166     x_err_stack := old_stack;
167 
168  exception
169    when NO_DATA_FOUND then
170       x_err_code := 20;
171       x_err_stage := 'PA_BU_INVALID_NEW_PERIOD';
172       return;
173    when others then
174       x_err_code := SQLCODE;
175       return;
176  end;
177 
178  procedure get_periods(x_start_date1 in date,
179                        x_start_date2 in date,
180                        x_period_type  in varchar2,
181                        x_periods   in out  NOCOPY number, --File.Sql.39 bug 4440895
182                        x_err_code          in out NOCOPY number, --File.Sql.39 bug 4440895
183                        x_err_stage         in out NOCOPY varchar2, --File.Sql.39 bug 4440895
184                        x_err_stack         in out NOCOPY varchar2) --File.Sql.39 bug 4440895
185  is
186  x_period_start_date1 date;
187  x_period_start_date2 date;
188  cursor c is
189  select count(1) -1
190  from pa_periods
191  where  start_date between least(x_period_start_date1,x_period_start_date2) and greatest(x_period_start_date1,x_period_start_date2);
192 
193  cursor c1 is
194  select count(1) -1
195  from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
196  where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
197  AND P.APPLICATION_ID = pa_period_process_pkg.application_id
198  AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
199  and   start_date between least(x_period_start_date1,x_period_start_date2) and greatest(x_period_start_date1,x_period_start_date2);
200 
201 
202 
203 
204  old_stack                      varchar2(630);
205  begin
206    x_err_code := 0;
207    old_stack := x_err_stack;
208    x_err_stack := x_err_stack || '->get_periods';
209 
210     IF  NVL(x_period_type ,'X') = 'P' THEN
211        select start_date
212        into   x_period_start_date1
213        from pa_periods
214        where  x_start_date1 between start_date and end_date;
215     ELSIF  NVL(x_period_type ,'X') = 'G' THEN
216        select start_date
217        into   x_period_start_date1
218        from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
219        where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
220        AND P.APPLICATION_ID = pa_period_process_pkg.application_id
221        AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
222        AND  x_start_date1 between start_date and end_date;
223 
224     END IF;
225 
226 
227     IF  NVL(x_period_type ,'X') = 'P' THEN
228 
229        select start_date
230        into   x_period_start_date2
231        from pa_periods
232        where  x_start_date2 between start_date and end_date;
233 
234     ELSIF  NVL(x_period_type ,'X') = 'G' THEN
235 
236 
237        select start_date
241        AND P.APPLICATION_ID = pa_period_process_pkg.application_id
238        into   x_period_start_date2
239        from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
240        where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
242        AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
243        AND  x_start_date2 between start_date and end_date;
244 
245     END IF;
246 
247 
248 
249     IF NVL(x_period_type ,'X') = 'P' THEN
250 
251        open c;
252        fetch c into x_periods;
253        close c;
254     ELSIF NVL(x_period_type ,'X') = 'G' THEN
255        open c1;
256        fetch c1 into x_periods;
257        close c1;
258     END IF;
259 
260 
261    if x_start_date1 > x_start_date2 then
262      x_periods := -1* x_periods;
263    end if;
264 
265    x_err_stack := old_stack;
266  exception
267    when NO_DATA_FOUND then
268       x_err_code := 20;
269       x_err_stage := 'PA_BU_INVALID_NEW_PERIOD';
270       return;
271    when others then
272       x_err_code := SQLCODE;
273       return;
274  end;
275 
276 -- ===================================================
277 --
278 -- History
279 --
280 --      12-AUG-97       jwhite  Updated to latest specifications the baseline
281 --                              procedure for workflow implementation.
282 --
283 --      10-SEP-97       Rkrishna Added default value for x_verify_budget_rules
284 --                               in baseline procedure
285 --
286 --      10-SEP-97       jwhite  As per latest specs, supplemented modifications
287 --                              made by chk for call to Verify_Budget_Rules
288 --                              (added two new OUT-parameters, changed
289 --                               error handling code); added new code
290 --                              for update_funding calls.
291 --
292 --      12-AUG-02       jwhite  For the new FP model, made minor modifications
293 --                              so the package would compile and new FP queries
294 --                              would fire successfully. Otherwise, this procedure
295 --                              does NOT support the FP Model.
296 --
297 --                              Modifications:
298 --                              1) Modified pa_budget_versions-INSERT to populate the
299 --                                 new FP approved_cost/rev_plan_type columns.
300 --
301 -- NOTE:
302 --
303 --           !!! This Baseline Procedure does NOT support the FP Model !!!
304 --
305 --               This procedure only creates r11.5.7 budgets. You cannot use
306 --               this procedure to create FP plans.
307 --
308 --
309 
310   procedure baseline (x_draft_version_id  in     number,
311                       x_mark_as_original  in     varchar2,
312                       x_verify_budget_rules in   varchar2 default 'Y',
313                       x_err_code          in out NOCOPY number, --File.Sql.39 bug 4440895
314                       x_err_stage         in out NOCOPY varchar2, --File.Sql.39 bug 4440895
315                       x_err_stack         in out NOCOPY varchar2) --File.Sql.39 bug 4440895
316 
317   IS
318     -- Standard who
319     x_created_by                number(15);
320     x_last_update_login         number(15);
321 
322     x_project_id                number(15);
323     x_budget_type_code          varchar2(30);
324     max_version                 number(15);
325     x_dest_version_id           number(15);
326     x_entry_level_code          varchar2(30);
327     x_project_type_class_code   varchar2(30);
328     dummy                       number;
329     budget_total                number default 0;
330     old_stack                   varchar2(630);
331     x_resource_list_assgmt_id   number;
332     x_resource_list_id          number;
333     x_baselined_version_id      number;
334     x_funding_level             varchar2(2) default NULL;
335     x_time_phased_type_code     varchar2(30);
336 
337     l_warnings_only_flag        VARCHAR2(1)     := 'Y';
338     l_err_msg_count     NUMBER  := 0;
339     v_project_start_date        date;
340     v_project_completion_date   date;
341     v_emp_id                    number;
342     v_baselined_by_person_id    number;
343     l_workflow_is_used          VARCHAR2(1);
344     x_pm_product_code           VARCHAR2(100);
345 
346     x_msg_count          NUMBER := 0;
347     x_msg_data           VARCHAR2(2000);
348     x_return_status      VARCHAR2(2000);
349 
350 BEGIN
351 
352 	print_msg('PA_BUDGET_CORE.BASELINE- Inside');
353 
354      x_err_code := 0;
355      old_stack := x_err_stack;
356      x_err_stack := x_err_stack || '->baseline';
357 
358      x_created_by := FND_GLOBAL.USER_ID;
359     --x_created_by := ( to_number(fnd_profile.value('USER_ID')));
360      x_last_update_login := FND_GLOBAL.LOGIN_ID;
361 
362 -- This call is repeated in  PA_BUDGET_UTILS.Verify_Budget_Rules
363 -- as the APIs call that procedure. Using v_emp_id eliminates join
364 -- to fnd_user while inserting record in pa_budget_versions
365 
366      v_emp_id := PA_UTILS.GetEmpIdFromUser(x_created_by );
367 
368      if v_emp_id IS NULL then
369         x_err_code := 10;
370         x_err_stage := 'PA_ALL_WARN_NO_EMPL_REC';
371         return;
372      end if;
373 
374 
375      savepoint before_baseline;
376 
377      x_err_stage := 'get draft budget info <' || to_char(x_draft_version_id)
378                     || '>';
382 /* Modified the following query for the bug 6320792 */
379 	print_msg(x_err_stage);
380 
381 
383     select v.project_id, v.budget_type_code, v.resource_list_id,
384             t.project_type_class_code,time_phased_type_code,
385             entry_level_code,v.pm_product_code
386      into   x_project_id, x_budget_type_code, x_resource_list_id,
387             x_project_type_class_code,x_time_phased_type_code,
388             x_entry_level_code, x_pm_product_code
389      from   pa_project_types_all t,
390             pa_projects_all p,
391             pa_budget_versions v,
392             pa_budget_entry_methods b
393      where  v.budget_version_id = x_draft_version_id
394      and    v.project_id = p.project_id
395      and    b.budget_entry_method_code = v.budget_entry_method_code
396      and    p.project_type = t.project_type
397      and    nvl(p.org_id, -99) = nvl(t.org_id, -99);
398 
399 
400 /***** Code added for bug 2162949 */
401      --Check whether workflow is being used for this project budget
402         x_err_stage := 'Calling PA_CLIENT_EXTN_BUDGET_WF.Budget_Wf_Is_Used';
403         print_msg(x_err_stage);
404      PA_CLIENT_EXTN_BUDGET_WF.Budget_Wf_Is_Used
405                 ( p_draft_version_id            =>      x_draft_version_id
406                 , p_project_id                  =>      x_project_id
407                 , p_budget_type_code            =>      x_budget_type_code
408                 , p_pm_product_code             =>      x_pm_product_code
409                 , p_result                      =>      l_workflow_is_used
410                 , p_err_code                    =>      x_err_code
411                 , p_err_stage                   =>      x_err_stage
412                 , p_err_stack                   =>      x_err_stack
413                 );
414 	print_msg('End of Budget_Wf_Is_Used:['||l_workflow_is_used||']');
415 
416      If l_workflow_is_used =  'T' Then
417         v_emp_id := pa_utils.GetEmpIdFromUser(pa_budget_wf.g_baselined_by_user_id);
418     end if;
419 
420 /*Code fix ends for bug 2162949 */
421 -- -------------------------------------------------------------------------------------
422 -- During R11 development, this section was
423 -- rewritten to call verify_budget_rules, etc.
424 --
425 -- Need to check if call is for verification purpose only
426 -- (chk 09/04/97)
427 --
428 
429      IF ( x_verify_budget_rules = 'Y' )
430      THEN
431 	x_err_stage := 'Calling PA_BUDGET_UTILS.Verify_Budget_Rules';
432         print_msg(x_err_stage);
433        PA_BUDGET_UTILS.Verify_Budget_Rules
434          (p_draft_version_id            =>      x_draft_version_id
435         , p_mark_as_original    =>      x_mark_as_original
436         , p_event                       =>      'BASELINE'
437         , p_project_id          =>      x_project_id
438         , p_budget_type_code    =>      x_budget_type_code
439         , p_resource_list_id            =>      x_resource_list_id
440         , p_project_type_class_code     =>      x_project_type_class_code
441         , p_created_by          =>      x_created_by
442         , p_calling_module              =>      'PAXBUBCB'
443         , p_warnings_only_flag  =>      l_warnings_only_flag
444         , p_err_msg_count               =>      l_err_msg_count
445         , p_err_code                    =>      x_err_code
446         , p_err_stage           =>      x_err_stage
447         , p_err_stack           =>      x_err_stack
448           );
449 	 print_msg('end of Verify_Budget_Rules :errCode['||x_err_code||']ErrStage['||x_err_stage||']');
450 
451          IF (l_err_msg_count > 0 )
452          THEN
453         IF (l_warnings_only_flag = 'N') THEN
454                 RETURN;
455         END IF;
456          END IF;
457     END IF;  -- x_verify_budget_rules = 'Y'
458 
459 
460        -- Updates for Selected Revenue and Cost Budgets
461 
462     IF (    (x_budget_type_code = 'AR')
463          AND (x_project_type_class_code = 'CONTRACT'))
464      THEN
465 
466         -- call pa_billing_core.update_funding to update funding tables if
467         -- necessary.
468         -- check project funding level flag properly
469 	x_err_stage := 'Calling pa_billing_core.check_funding_level for AR budget';
470         print_msg(x_err_stage);
471         pa_billing_core.check_funding_level(
472                             x_project_id,
473                             x_funding_level,
474                             x_err_code,
475                             x_err_stage,
476                             x_err_stack);
477 	print_msg('End of check_funding_level:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
478         if (x_err_code <> 0) then
479            return;
480         end if;
481 
482 	x_err_stage := 'Calling pa_billing_core.update_funding';
483         print_msg(x_err_stage);
484         pa_billing_core.update_funding(
485                 x_project_id,
486                 x_funding_level,        -- Funding level
487                 x_err_code,
488                 x_err_stage,
489                 x_err_stack);
490 	print_msg('End of update_funding:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
491                 if (x_err_code <> 0) then
492                 rollback to before_baseline;
493                         RETURN;
494                 end if;
495 
496            ELSIF (    (x_budget_type_code = 'AC')
497            AND (x_project_type_class_code <> 'CONTRACT'))
498             THEN
499 
500         -- call pa_billing_core.update_funding to update funding tables if
501         -- necessary.
502 	x_err_stage := 'Calling pa_billing_core.update_funding for AC budget';
503         print_msg(x_err_stage);
507                 x_err_code,
504         pa_billing_core.update_funding(
505                 x_project_id,
506                 x_funding_level,        -- Funding level
508                 x_err_stage,
509                         x_err_stack);
510 	print_msg('End of update_funding:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
511 
512          if ( x_err_code <> 0) then
513                 rollback to before_baseline;
514                         return;
515                 end if;
516 
517     END IF;  -- of AR revenue budget
518 
519 -- End R11 rewrite
520 -- ----------------------------------------------------------------------------------
521 
522 
523     	x_err_stage := 'Calling pa_budget_utils.get_baselined_version_id';
524         print_msg(x_err_stage);
525       pa_budget_utils.get_baselined_version_id(
526                                   x_project_id        => x_project_id,
527                                   x_budget_type_code  => x_budget_type_code,
528                                   x_budget_version_id => x_baselined_version_id,
529                                   x_err_code          => x_err_code,
530                                   x_err_stage         => x_err_stage,
531                                   x_err_stack         => x_err_stack
532                                   );
533 	print_msg('End of get_baselined_version_id:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
534 
535 
536      if (x_err_code < 0) then
537          rollback to before_baseline;
538          return;
539 
540      elsif (x_err_code > 0) then
541 
542         -- baseline budget does not exist
543 
544         x_err_stage := 'create resource list assignment <'
545                        || to_char(x_project_id) || '><'
546                        || to_char(x_resource_list_id) || '>';
547 	print_msg(x_err_stage);
548 
549         -- create resource list assignment if necessary
550         pa_res_list_assignments.create_rl_assgmt(x_project_id,
551                          x_resource_list_id,
552                          x_resource_list_assgmt_id,
553                          x_err_code,
554                          x_err_stage,
555                          x_err_stack);
556 	print_msg('End of create_rl_assgmt:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
557 
558         -- if oracle or application error, return
559         if (x_err_code <> 0) then
560         rollback    to before_baseline;
561            return;
562         end if;
563 
564         x_err_stage := 'create resource list usage <'
565                        || to_char(x_project_id) || '><'
566                        || to_char(x_resource_list_assgmt_id) || '><'
567                        || x_budget_type_code || '>';
568 	print_msg(x_err_stage);
569 
570         -- create resource list usage if necessary
571         pa_res_list_assignments.create_rl_uses(x_project_id,
572                          x_resource_list_assgmt_id,
573                          x_budget_type_code,
574                          x_err_code,
575                          x_err_stage,
576                          x_err_stack);
577 	print_msg('End of create_rl_uses:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
578 
579         -- if oracle or application error, return.
580 
581         if (x_err_code <> 0) then
582         rollback    to before_baseline;
583            return;
584         end if;
585 
586      end if;
587 
588      x_err_stage := 'update current version <' || to_char(x_project_id) || '><'
589                     || x_budget_type_code || '>';
590 	print_msg(x_err_stage);
591 
592      if (x_mark_as_original = 'Y') then
593 
594           -- reset current budget version to non-current
595           update pa_budget_versions
596           set    original_flag = 'Y',
597                  current_original_flag = 'N',
598                  last_update_date = SYSDATE,
599                  last_updated_by = x_created_by,
600                  last_update_login = x_last_update_login
601           where  project_id = x_project_id
602           and    budget_type_code = x_budget_type_code
603           and    current_original_flag = 'Y'
604 	   and    budget_status_code = 'B'; -- added for bug 9950839
605 
606      end if;
607 
608      update pa_budget_versions
609      set    current_flag = 'N',
610             last_update_date = SYSDATE,
611             last_updated_by = x_created_by,
612             last_update_login = x_last_update_login
613      where  project_id = x_project_id
614      and    budget_type_code = x_budget_type_code
615      and    current_flag = 'Y';
616 
617 
618      -- get the maximun number of existing versions
619      x_err_stage := 'get maximum baseline number <' || to_char(x_project_id)
620                     || '><' || x_budget_type_code || '>';
621 	print_msg(x_err_stage);
622 
623      select nvl(max(version_number), 0)
624      into   max_version
625      from   pa_budget_versions
626      where  project_id = x_project_id
627      and    budget_type_code = x_budget_type_code
628      and    budget_status_code = 'B';
629 
630      -- get the dest version id
631      select pa_budget_versions_s.nextval
632      into   x_dest_version_id
633      from   sys.dual;
634 
635      -- populate pa_budget_versions
636      x_err_stage := 'create baselined version <' || to_char(x_dest_version_id)
640 
637                     || '><' || to_char(max_version)
638                     || '><' || to_char(x_created_by) || '>';
639 	print_msg(x_err_stage);
641      insert into pa_budget_versions(
642             budget_version_id,
643             project_id,
644             budget_type_code,
645             version_number,
646             budget_status_code,
647             last_update_date,
648             last_updated_by,
649             creation_date,
650             created_by,
651             last_update_login,
652             current_flag,
653             original_flag,
654             current_original_flag,
655             resource_accumulated_flag,
656             resource_list_id,
657             version_name,
658             budget_entry_method_code,
659             baselined_by_person_id,
660             baselined_date,
661             change_reason_code,
662             labor_quantity,
663             labor_unit_of_measure,
664             raw_cost,
665             burdened_cost,
666             revenue,
667             description,
668             attribute_category,
669             attribute1,
670             attribute2,
671             attribute3,
672             attribute4,
673             attribute5,
674             attribute6,
675             attribute7,
676             attribute8,
677             attribute9,
678             attribute10,
679             attribute11,
680             attribute12,
681             attribute13,
682             attribute14,
683             attribute15,
684             first_budget_period,
685             pm_product_code,
686             pm_budget_reference,
687             wf_status_code,
688             approved_cost_plan_type_flag,
689             approved_rev_plan_type_flag
690         )
691          select
692             x_dest_version_id,
693             v.project_id,
694             v.budget_type_code,
695             max_version + 1,
696             'B',
697             SYSDATE,
698             x_created_by,
699             SYSDATE,
700             x_created_by,
701             x_last_update_login,
702             'Y',
703             'N',
704             x_mark_as_original,
705             'N',
706             v.resource_list_id,
707             v.version_name,
708             v.budget_entry_method_code,
709             v_emp_id,
710             SYSDATE,
711             v.change_reason_code,
712             (v.labor_quantity),
713             v.labor_unit_of_measure,
714 --          pa_currency.round_currency_amt(v.raw_cost),
715 --          pa_currency.round_currency_amt(v.burdened_cost),
716 --          pa_currency.round_currency_amt(v.revenue),
717             v.raw_cost,
718             v.burdened_cost,
719             v.revenue,
720             v.description,
721             v.attribute_category,
722             v.attribute1,
723             v.attribute2,
724             v.attribute3,
725             v.attribute4,
726             v.attribute5,
727             v.attribute6,
728             v.attribute7,
729             v.attribute8,
730             v.attribute9,
731             v.attribute10,
732             v.attribute11,
733             v.attribute12,
734             v.attribute13,
735             v.attribute14,
736             v.attribute15,
737             first_budget_period,
738             pm_product_code,
739             pm_budget_reference,
740             NULL,
741             decode(v.budget_type_code,'AC','Y','N'),
742             decode(v.budget_type_code,'AR','Y','N')
743          from   pa_budget_versions v
744          where  budget_version_id = x_draft_version_id;
745 
746      x_err_stage := 'create budget lines <' || to_char(x_draft_version_id)
747                     || '><' || to_char(x_dest_version_id)
748                     || '>';
749 	print_msg(x_err_stage);
750 
751 /* FPB2: MRC - sep 2002
752 
753    Fix 876456 copy_lines is a generic procedure that copies budget lines
754    and resource assignments from a source project's budget to a destination
755    project's budget
756    This procedure has been replaced with a procedure copy_draft_lines defined
757    in pa_budget_core1 which copies budget lines and resource assignments  from
758    the draft budget of a project to the baselined version of the same project
759 
760      pa_budget_core.copy_lines(x_draft_version_id,
761                                1,
762                                5,
763                                0,
764                                x_dest_version_id,
765                                x_err_code,
766                                x_err_stage,
767                                x_err_stack,
768                                'Y');
769 */
770 
771 	x_err_stage:= 'Calling pa_budget_core1.copy_draft_lines';
772         print_msg(x_err_stage);
773      pa_budget_core1.copy_draft_lines(x_src_version_id        => x_draft_version_id,
774                                       x_time_phased_type_code => x_time_phased_type_code,
775                                       x_entry_level_code      => x_entry_level_code,
776                                       x_dest_version_id       => x_dest_version_id,
777                                       x_err_code              => x_err_code,
778                                       x_err_stage             => x_err_stage,
779                                       x_err_stack             => x_err_stack,
780                                       x_pm_flag               => 'Y');
784      if (x_err_code <> 0) then
781 	print_msg('End of copy_draft_lines:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
782 
783 
785         rollback to before_baseline;
786         return;
787      end if;
788 
789     -- Fix for Bug #561420 - If the effective dates on Project/Tasks
790     -- has changed for Non Time phased budgets, then update the
791     -- start and end dates on the budget lines.
792 
793    -- gp_msg('TIME:'||x_time_phased_type_code||':ENTRY:'||x_entry_level_code);
794     if (x_time_phased_type_code = 'N')
795        and (x_entry_level_code = 'P') then -- Project Level
796 --
797 	x_err_stage:= 'Non-Time Phase: Project Level update';
798         print_msg(x_err_stage);
799 	-- Added nvl in the below select query for the bug 11891595
800       select start_date,nvl(completion_date,PA_BUDGET_CHECK_PVT.Get_project_end_date)	-- Changed for the bug 13344742
801       into v_project_start_date,
802            v_project_completion_date
803       from pa_projects_all
804       where project_id = x_project_id;
805 
806       if (v_project_start_date is null ) or (v_project_completion_date
807           is null) then
808           x_err_code := 20;
809           x_err_stage :='PA_BU_NO_PROJ_END_DATE';
810          return;
811       end if;
812 
813       update pa_budget_lines
814       set start_date= v_project_start_date,
815           end_date = v_project_completion_date
816       where resource_assignment_id in
817           (select resource_assignment_id
818            from pa_resource_assignments
819            where budget_version_id = x_dest_version_id)
820       and ((start_date <> v_project_start_date) OR (end_date <> v_project_completion_date));
821 
822 -- fix 876456: Added check that rows should be updated only if the project start or end
823 -- dates are different from the budget start and end dates
824 
825     elsif (x_time_phased_type_code = 'N') then -- Task Level
826 	x_err_stage:= 'Non-Time Phase: Task Level update';
827         print_msg(x_err_stage);
828       select start_date,completion_date
829       into v_project_start_date,
830            v_project_completion_date
831       from pa_projects_all
832       where project_id = x_project_id;
833 
834       for bl_rec in (select start_date,
835                             completion_date ,
836                             resource_assignment_id
837                      from pa_tasks t ,pa_resource_assignments r
838                      where t.task_id = r.task_id
839                      and  r.budget_version_id = x_dest_version_id) loop
840           bl_rec.start_date := nvl(bl_rec.start_date,v_project_start_date);
841           bl_rec.completion_date := nvl(bl_rec.completion_date
842                                        ,v_project_completion_date);
843 
844 -- fix 876456: Added check that rows should be updated only if the task start or end
845 -- dates are different from the budget start and end dates
846 
847           IF (bl_rec.start_date is null) or (bl_rec.completion_date is null)
848             THEN
849             x_err_code := 20;
850             x_err_stage :='PA_BU_NO_TASK_PROJ_DATE';
851             exit;
852           ELSE
853              UPDATE pa_budget_lines
854                SET start_date = bl_rec.start_date,
855                    end_date   = bl_rec.completion_date
856              WHERE resource_assignment_id = bl_rec.resource_assignment_id
857                AND ((start_date <> bl_rec.start_date) or (end_date <> bl_rec.completion_date));
858 
859           END IF;
860 
861       end loop;
862 
863       if x_err_code <> 0 then
864         return;
865       end if;
866 
867 --
868     end if;
869 
870       /* Bug fix:5246812: When this API raises unexpected error, the baseline process
871         * shows ORA-01400: cannot insert NULL into (PA."PA_WF_PROCESSES.ENTITY_KEY2)
872         * error. so execute this api in a begin , end block and set the error status
873         */
874         BEGIN
875                 -- Copy attachments for every draft budget copied
876                 x_err_stage:= 'Calling fnd_attached_documents2_pkg.copy_attachments';
877                 print_msg(x_err_stage);
878                 fnd_attached_documents2_pkg.copy_attachments('PA_BUDGET_VERSIONS',
879                                                    x_draft_version_id,
880                                                    null,null,null,null,
881                                                    'PA_BUDGET_VERSIONS',
882                                                    x_dest_version_id,
883                                                    null,null,null,null,
884                                                    FND_GLOBAL.USER_ID,
885                                                    FND_GLOBAL.LOGIN_ID,
886                                                    275, null, null) ;
887                 print_msg('End of copy_attachments');
888                 -- End copying attachments
889         EXCEPTION
890                 WHEN OTHERS THEN
891                         print_msg('Errored in fnd_attached_documents2_pkg: ERRMSG:['||sqlcode||sqlerrm);
892                         x_err_code := SQLCODE;
893                         x_err_stack := substr(SQLERRM,630);
894                         rollback to before_baseline;
895                         RETURN;
896                         NULL;
897         END;
898 
899       	x_err_stage:= 'Calling PA_BUDGET_UTILS.summerize_project_totals';
900         print_msg(x_err_stage);
901      	PA_BUDGET_UTILS.summerize_project_totals(x_dest_version_id,
902                                              x_err_code,
903                                              x_err_stage,
907      if (x_err_code <> 0) then
904                                              x_err_stack);
905 	print_msg('End of summerize_project_totals:errCode['||x_err_code||']ErrStage['||x_err_stage||']');
906 
908         rollback to before_baseline;
909         return;
910      end if;
911 
912      x_err_stack := old_stack;
913 	x_err_stage:= 'End of baseline';
914         print_msg(x_err_stage);
915 
916   exception
917       when others then
918 	print_msg('ErrStage:'||x_err_stage||']ErrCode['||SQLCODE||']');
919          x_err_code := SQLCODE;
920          rollback to before_baseline;
921          return;
922   end baseline;
923 
924 -----------------------------------------------------------------------------
925 -- History
926 -- 26-Dec-2006 kchaitan created
927 -- Following api will copy a non integrated budget version to destination
928 -- gl integrated budget without overriding the closed gl period budget lines
929 -- in destination and without copying the closed gl period budget lines in
930 -- source.
931 -----------------------------------------------------------------------------
932 
933 procedure copy_without_delete (p_src_version_id      in     number,
934                                p_amount_change_pct   in     number,
935                                p_rounding_precision  in     number,
936                                p_dest_project_id     in     number,
937                                p_dest_budget_type_code    in     varchar2,
938                                x_err_code            in out NOCOPY number,   -- added NOCOPY to pass GSCC errors for bug 5838587
939                                x_err_stage           in out NOCOPY varchar2, -- added NOCOPY to pass GSCC errors for bug 5838587
940                                x_err_stack           in out NOCOPY varchar2) -- added NOCOPY to pass GSCC errors for bug 5838587
941   is
942      old_stack varchar2(630);
943 
944      l_created_by  number;
945      l_last_update_login number;
946 
947      l_dest_version_id number;
948      l_baselined_version_id number;
949      l_baselined_resource_list_id number;
950 
951      l_src_resource_list_id number;
952      l_dest_resource_list_id number;
953      l_draft_exists boolean;
954      l_cls_prds_exists varchar2(1);
955      l_src_time_phased_type_code varchar2(30);
956      l_dest_time_phased_type_code varchar2(30);
957      l_src_entry_level_code varchar2(30);
958      l_dest_entry_level_code varchar2(30);
959 
960      l_version_is_baselined varchar2(1);
961 
962      x_return_status      VARCHAR2(2000);
963      x_msg_count          NUMBER        := 0;
964      x_msg_data           VARCHAR2(2000);
965 
966   begin
967 
968      x_err_code := 0;
969      old_stack := x_err_stack;
970      x_err_stack := x_err_stack || '->copy_without_delete';
971 
972      l_created_by := FND_GLOBAL.USER_ID;
973      l_last_update_login := FND_GLOBAL.LOGIN_ID;
974 
975      savepoint before_copy1;
976 
977 
978      x_err_stage := 'Getting Budget Entry Method Parameters for Source <'||  to_char(p_src_version_id);
979      select m.time_phased_type_code,
980             m.entry_level_code,
981             v.resource_list_id
982      into   l_src_time_phased_type_code,
983             l_src_entry_level_code,
984             l_src_resource_list_id
985      from   pa_budget_entry_methods m,
986             pa_budget_versions v
987      where  v.budget_version_id = p_src_version_id
988      and    v.budget_entry_method_code = m.budget_entry_method_code;
989 
990      x_err_stage := 'getting baselined budget <' ||  to_char(p_dest_project_id)
991                     || '><' ||  p_dest_budget_type_code || '>' ;
992 
993      pa_budget_utils.get_baselined_version_id(
994                                   x_project_id        => p_dest_project_id,
995                                   x_budget_type_code  => p_dest_budget_type_code,
996                                   x_budget_version_id => l_baselined_version_id,
997                                   x_err_code          => x_err_code,
998                                   x_err_stage         => x_err_stage,
999                                   x_err_stack         => x_err_stack
1000                                   );
1001 
1002      if (x_err_code = 0) then
1003         -- baseliend budget exists, verify if resource lists are the same
1004         -- resource list used in accumulation
1005         select resource_list_id
1006         into   l_baselined_resource_list_id
1007         from   pa_budget_versions
1008         where  budget_version_id = l_baselined_version_id;
1009 
1010         if (l_src_resource_list_id <> l_baselined_resource_list_id) then
1011             x_err_code := 10;
1012             x_err_stage := 'PA_BU_BASE_RES_LIST_EXISTS';
1013             rollback to before_copy1;
1014             return;
1015         end if;
1016 
1017         l_version_is_baselined := 'Y';
1018      elsif (x_err_code < 0) then
1019         x_err_stage := 'Unexpected error while trying to get baselined budget version id';
1020         rollback to before_copy1;
1021         return;
1022      end if;
1023 
1024 
1025      x_err_stage := 'getting old draft budget <' ||  to_char(p_dest_project_id)
1026                     || '><' ||  p_dest_budget_type_code || '>' ;
1027 
1028      -- check if destination draft budget exists
1029      pa_budget_utils.get_draft_version_id(
1030                                   x_project_id        => p_dest_project_id,
1031                                   x_budget_type_code  => p_dest_budget_type_code,
1032                                   x_budget_version_id => l_dest_version_id,
1033                                   x_err_code          => x_err_code,
1034                                   x_err_stage         => x_err_stage,
1035                                   x_err_stack         => x_err_stack
1036                                   );
1037 
1038 
1039      if (x_err_code = 0) then
1040         -- draft budget exists, update it
1041          x_err_stage := 'draft budget exists <' ||  to_char(l_dest_version_id)||'>';
1042         l_draft_exists := TRUE;
1043      elsif (x_err_code < 0) then
1044         x_err_stage := 'Unexpected error while trying to get draft budget version id';
1045         rollback to before_copy1;
1046         return;
1047      else
1048         --insert into pa_budget_versions
1049         select pa_budget_versions_s.nextval
1050         into   l_dest_version_id
1051         from   sys.dual;
1052 
1053         insert into pa_budget_versions(
1054             budget_version_id,
1055             project_id,
1056             budget_type_code,
1057             version_number,
1058             budget_status_code,
1059             last_update_date,
1060             last_updated_by,
1061             creation_date,
1062             created_by,
1063             last_update_login,
1064             current_flag,
1065             original_flag,
1066             current_original_flag,
1067             resource_accumulated_flag,
1068             resource_list_id,
1069             version_name,
1070             budget_entry_method_code,
1071             baselined_by_person_id,
1072             baselined_date,
1073             change_reason_code,
1074             labor_quantity,
1075             labor_unit_of_measure,
1076             raw_cost,
1077             burdened_cost,
1078             revenue,
1079             description,
1080             attribute_category,
1081             attribute1,
1082             attribute2,
1083             attribute3,
1084             attribute4,
1085             attribute5,
1086             attribute6,
1087             attribute7,
1088             attribute8,
1089             attribute9,
1090             attribute10,
1091             attribute11,
1092             attribute12,
1093             attribute13,
1094             attribute14,
1095             attribute15,
1096             first_budget_period,
1097             wf_status_code,
1098             approved_cost_plan_type_flag,
1099             approved_rev_plan_type_flag
1100                 )
1101          select
1102             l_dest_version_id,
1103             p_dest_project_id,
1104             p_dest_budget_type_code,
1105             1,
1106             'W',
1107             SYSDATE,
1108             l_created_by,
1109             SYSDATE,
1110             l_created_by,
1111             l_last_update_login,
1112             'N',
1113             'N',
1114             'N',
1115             'N',
1116             v.resource_list_id,
1117             v.version_name,
1118             v.budget_entry_method_code,
1119             NULL,
1120             NULL,
1121             v.change_reason_code,
1122             NULL,
1123             NULL,
1124             NULL,
1125             NULL,
1126             NULL,
1127             v.description,
1128             v.attribute_category,
1129             v.attribute1,
1130             v.attribute2,
1131             v.attribute3,
1132             v.attribute4,
1133             v.attribute5,
1134             v.attribute6,
1135             v.attribute7,
1136             v.attribute8,
1137             v.attribute9,
1138             v.attribute10,
1139             v.attribute11,
1140             v.attribute12,
1141             v.attribute13,
1142             v.attribute14,
1143             v.attribute15,
1144             v.first_budget_period,
1145             NULL,
1146             decode(p_dest_budget_type_code,'AC','Y','N'), /* Bug 5076424 */
1147             decode(p_dest_budget_type_code,'AR','Y','N')  /* Bug 5076424 */
1148          from   pa_budget_versions v
1149          where  v.budget_version_id = p_src_version_id;
1150 
1151          l_draft_exists := FALSE;
1152          x_err_stage := 'Created new draft version '||to_char(p_src_version_id);
1153      end if;
1154 
1155      if l_draft_exists then
1156 
1157             begin
1158                 l_cls_prds_exists := 'N';
1159                 SELECT 'Y' into l_cls_prds_exists
1160                 FROM   pa_budget_lines l
1161                 , gl_period_statuses s
1162                 , pa_implementations i
1163                 , pa_budget_versions v
1164                 where s.application_id = pa_period_process_pkg.application_id
1165                 and   i.set_of_books_id = s.set_of_books_id
1166                 and   l.budget_version_id=v.budget_version_id
1167                 and   s.closing_status in ('C','P')
1168                 and   l.period_name = s.period_name
1169                 and   v.budget_version_id = l_dest_version_id
1170                 and   rownum < 2;
1171             exception when no_data_found then
1172                 l_cls_prds_exists := 'N';
1173             end;
1174 
1175             if l_cls_prds_exists = 'Y' then
1176                  x_err_stage := 'Budget lines in closed periods exists. About to perform validations';
1177                  select m.time_phased_type_code,
1178                         m.entry_level_code,
1179                         v.resource_list_id
1180                  into   l_dest_time_phased_type_code,
1181                         l_dest_entry_level_code,
1182                         l_dest_resource_list_id
1183                  from   pa_budget_entry_methods m,
1184                         pa_budget_versions v
1185                  where  v.budget_version_id = l_dest_version_id
1186                  and    v.budget_entry_method_code = m.budget_entry_method_code;
1187 
1188                  if (l_src_resource_list_id <> l_dest_resource_list_id)
1189                     or (l_src_entry_level_code <> l_dest_entry_level_code)
1190                     or (l_src_time_phased_type_code <> l_dest_time_phased_type_code) then
1191                      x_err_code := 20;
1192                      x_err_stage := 'PA_BUDG_PARAM_MISMATCH';
1193                      --x_err_stage := 'Mismatch in entry level or resource list or time phase';
1194                      rollback to before_copy1;
1195                      return;
1196                  end if;
1197             end if;
1198      end if;
1199 
1200      if l_draft_exists then
1201         x_err_stage := 'Updating the existing budget version';
1202         update pa_budget_versions
1203         set (version_number,
1204             budget_status_code,
1205             last_update_date,
1206             last_updated_by,
1207             last_update_login,
1208             current_flag,
1209             original_flag,
1210             current_original_flag,
1211             resource_accumulated_flag,
1212             resource_list_id,
1213             version_name,
1214             budget_entry_method_code,
1215             baselined_by_person_id,
1216             baselined_date,
1217             change_reason_code,
1218             labor_quantity,
1219             labor_unit_of_measure,
1220             raw_cost,
1221             burdened_cost,
1222             revenue,
1223             description,
1224             attribute_category,
1225             attribute1,
1226             attribute2,
1227             attribute3,
1228             attribute4,
1229             attribute5,
1230             attribute6,
1231             attribute7,
1232             attribute8,
1233             attribute9,
1234             attribute10,
1235             attribute11,
1236             attribute12,
1237             attribute13,
1238             attribute14,
1239             attribute15,
1240             first_budget_period,
1241             wf_status_code,
1242             approved_cost_plan_type_flag,
1243             approved_rev_plan_type_flag
1244              )=(
1245                 select
1246                     1,
1247                     'W',
1248                     SYSDATE,
1249                     l_created_by,
1250                     l_last_update_login,
1251                     'N',
1252                     'N',
1253                     'N',
1254                     'N',
1255                     v.resource_list_id,
1256                     v.version_name,
1257                     v.budget_entry_method_code,
1258                     NULL,
1259                     NULL,
1260                     v.change_reason_code,
1261                     NULL,
1262                     NULL,
1263                     NULL,
1264                     NULL,
1265                     NULL,
1266                     v.description,
1267                     v.attribute_category,
1268                     v.attribute1,
1269                     v.attribute2,
1270                     v.attribute3,
1271                     v.attribute4,
1272                     v.attribute5,
1273                     v.attribute6,
1274                     v.attribute7,
1275                     v.attribute8,
1276                     v.attribute9,
1277                     v.attribute10,
1278                     v.attribute11,
1279                     v.attribute12,
1283                     v.first_budget_period,
1280                     v.attribute13,
1281                     v.attribute14,
1282                     v.attribute15,
1284                     NULL,
1285                     decode(p_dest_budget_type_code,'AC','Y','N'),
1286                     decode(p_dest_budget_type_code,'AR','Y','N')
1287                 from   pa_budget_versions v
1288                 where  v.budget_version_id = p_src_version_id
1289              )
1290         where budget_version_id = l_dest_version_id;
1291 
1292         fnd_attached_documents2_pkg.delete_attachments('PA_BUDGET_VERSIONS',
1293                                                      l_dest_version_id,
1294                                                      null, null, null, null,
1295                                                      'Y') ;
1296         end if;
1297 
1298      --copy resource assignments
1299     if l_draft_exists then
1300          x_err_stage := 'About to delete budget lines in closed gl periods in dest';
1301          delete from pa_budget_lines
1302          where budget_version_id=l_dest_version_id
1303          and period_name not in (select s.period_name
1304                              from gl_period_statuses s
1305                                 , pa_implementations i
1306                              where s.application_id = pa_period_process_pkg.application_id
1307                              and   i.set_of_books_id = s.set_of_books_id
1308                              and   s.closing_status in ('C','P'));
1309     end if;
1310 
1311     x_err_stage := 'About to create new resource assignments in dest';
1312     INSERT INTO pa_resource_assignments
1313                    (resource_assignment_id,
1314                     budget_version_id,
1315                     project_id,
1316                     task_id,
1317                     resource_list_member_id,
1318                     last_update_date,
1319                     last_updated_by,
1320                     creation_date,
1321                     created_by,
1322                     last_update_login,
1323                     unit_of_measure,
1324                     track_as_labor_flag,
1325                     project_assignment_id,
1326                     RESOURCE_ASSIGNMENT_TYPE
1327                    )
1328            SELECT  pa_resource_assignments_s.nextval,
1329                    l_dest_version_id,
1330                    sa.project_id,
1331                    sa.task_id,
1332                    sa.resource_list_member_id,
1333                    SYSDATE,
1334                    l_created_by,
1335                    SYSDATE,
1336                    l_created_by,
1337                    l_last_update_login,
1338                    sa.unit_of_measure,
1339                    sa.track_as_labor_flag,
1340                    -1,
1341                    sa.RESOURCE_ASSIGNMENT_TYPE
1342             FROM
1343                    pa_resource_assignments sa,
1344                    pa_resource_assignments da
1345            WHERE   sa.budget_version_id = p_src_version_id
1346            AND     da.budget_version_id(+) = l_dest_version_id
1347            AND sa.project_assignment_id=-1
1348            AND da.project_assignment_id(+)=-1
1349            AND sa.project_id=p_dest_project_id
1350            AND da.project_id(+)=p_dest_project_id
1351            AND sa.task_id=da.task_id(+)
1352            AND sa.resource_list_member_id=da.resource_list_member_id(+)
1353            AND da.resource_assignment_id IS NULL;
1354      x_err_stage := 'About to insert budget lines to dest';
1355      INSERT INTO pa_budget_lines
1356              (budget_line_id,
1357               budget_version_id,
1358               resource_assignment_id,
1359               start_date,
1360               last_update_date,
1361               last_updated_by,
1362               creation_date,
1363               created_by,
1364               last_update_login,
1365               end_date,
1366               period_name,
1367               quantity,
1368               raw_cost,
1369               burdened_cost,
1370               revenue,
1371               change_reason_code,
1372               description,
1373               attribute_category,
1374               attribute1,
1375               attribute2,
1376               attribute3,
1377               attribute4,
1378               attribute5,
1379               attribute6,
1380               attribute7,
1381               attribute8,
1382               attribute9,
1383               attribute10,
1384               attribute11,
1385               attribute12,
1386               attribute13,
1387               attribute14,
1388               attribute15,
1389               pm_product_code,
1390               pm_budget_line_reference,
1391               raw_cost_source,
1392               burdened_cost_source,
1393               quantity_source,
1394               revenue_source,
1395               projfunc_currency_code,
1396               project_currency_code,
1397               txn_currency_code
1398               )
1399            select
1400                  pa_budget_lines_s.nextval,
1401                  l_dest_version_id,
1402                  dra.resource_assignment_id,
1403                  pbl.start_date,
1404                  sysdate,
1405                  l_created_by,
1406                  sysdate,
1407                  l_created_by,
1408                  l_last_update_login,
1409                  pbl.end_date,
1410                  pbl.period_name,
1411                  pbl.quantity,
1412                  round(pbl.raw_cost * p_amount_change_pct, p_rounding_precision),
1413                  round(pbl.burdened_cost * p_amount_change_pct, p_rounding_precision),
1417                  pbl.attribute_category,
1414                  round(pbl.revenue * p_amount_change_pct, p_rounding_precision),
1415                  pbl.change_reason_code,
1416                  pbl.description,
1418                  pbl.attribute1,
1419                  pbl.attribute2,
1420                  pbl.attribute3,
1421                  pbl.attribute4,
1422                  pbl.attribute5,
1423                  pbl.attribute6,
1424                  pbl.attribute7,
1425                  pbl.attribute8,
1426                  pbl.attribute9,
1427                  pbl.attribute10,
1428                  pbl.attribute11,
1429                  pbl.attribute12,
1430                  pbl.attribute13,
1431                  pbl.attribute14,
1432                  pbl.attribute15,
1433                  pbl.pm_product_code,
1434                  pbl.pm_budget_line_reference,
1435                  'B',
1436                  'B',
1437                  'B',
1438                  'B',
1439                  pbl.projfunc_currency_code,
1440                  pbl.project_currency_code,
1441                  pbl.txn_currency_code
1442            from pa_budget_lines pbl,
1443                 pa_resource_assignments sra,
1444                 pa_resource_assignments dra
1445            where dra.budget_version_id = l_dest_version_id
1446            and   sra.budget_version_id = p_src_version_id
1447            and pbl.budget_version_id = p_src_version_id
1448            and sra.resource_assignment_id=pbl.resource_assignment_id
1449            and sra.resource_list_member_id=dra.resource_list_member_id
1450            and sra.task_id=dra.task_id
1451            and pbl.period_name not in (select s.period_name
1452                                         from gl_period_statuses s
1453                                       , pa_implementations_all i
1454                                         where s.application_id = pa_period_process_pkg.application_id
1455                                         and   i.set_of_books_id = s.set_of_books_id
1456                                         and   s.closing_status in ('C','P'));
1457            x_err_stage := 'About to delete unused resource assignments from dest';
1458            delete from pa_resource_assignments
1459            where budget_version_id = l_dest_version_id
1460            and resource_assignment_id not in
1461                 (select distinct resource_assignment_id
1462                  from pa_budget_lines
1463                  where budget_version_id = l_dest_version_id);
1464     x_err_stage := 'About to begin mrc processing';
1465 
1466 -- Commented below  MRC code for Bug  5838587
1467    /*
1468     BEGIN
1469 
1470             IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS IS NULL THEN
1471                  PA_MRC_FINPLAN.CHECK_MRC_INSTALL
1472                                    (x_return_status      => x_return_status,
1473                                     x_msg_count          => x_msg_count,
1474                                     x_msg_data           => x_msg_data);
1475             END IF;
1476                -- Bug 2676494
1477 
1478             IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS THEN
1479                IF PA_MRC_FINPLAN.G_FINPLAN_MRC_OPTION_CODE = 'A' THEN
1480                   PA_MRC_FINPLAN.COPY_MC_BUDGET_LINES
1481                                    (p_source_fin_plan_version_id => p_src_version_id,
1482                                     p_target_fin_plan_version_id => l_dest_version_id,
1483                                     x_return_status              => x_return_status,
1484                                     x_msg_count                  => x_msg_count,
1485                                     x_msg_data                   => x_msg_data);
1486                ELSIF  (PA_MRC_FINPLAN.G_FINPLAN_MRC_OPTION_CODE = 'B' AND l_version_is_baselined = 'Y') THEN
1487                     PA_MRC_FINPLAN.MAINTAIN_ALL_MC_BUDGET_LINES
1488                                (p_fin_plan_version_id => l_dest_version_id, -- Target version should be passed
1489                                 p_entire_version      => 'Y',
1490                                 x_return_status       => x_return_status,
1491                                 x_msg_count           => x_msg_count,
1492                                 x_msg_data            => x_msg_data);
1493                -- Bug 2676494
1494               END IF;
1495 
1496             END IF;
1497 
1498             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1499               RAISE g_mrc_exception;
1500             END IF;
1501 
1502          END;
1503 */
1504      -- Copy attachments for every draft budget copied
1505 
1506      fnd_attached_documents2_pkg.copy_attachments('PA_BUDGET_VERSIONS',
1507                                                    p_src_version_id,
1508                                                    null,null,null,null,
1509                                                    'PA_BUDGET_VERSIONS',
1510                                                    l_dest_version_id,
1511                                                    null,null,null,null,
1512                                                    FND_GLOBAL.USER_ID,
1513                                                    FND_GLOBAL.LOGIN_ID,
1514                                                    275, null, null) ;
1515 
1516      -- End copying attachments
1517 
1518      PA_BUDGET_UTILS.summerize_project_totals(l_dest_version_id,
1519                                              x_err_code,
1520                                              x_err_stage,
1521                                              x_err_stack);
1522 
1523      if (x_err_code <> 0) then
1524         rollback to before_copy1;
1525         return;
1526      end if;
1527 
1528      x_err_stack := old_stack;
1529 exception
1530       when others then
1531          rollback to before_copy1;
1535 
1532          x_err_code := SQLCODE;
1533          return;
1534   end copy_without_delete;
1536 -----------------------------------------------------------------------------
1537 -- History
1538 --
1539 --
1540 --      12-AUG-02       jwhite  For the new FP model, made minor modifications
1541 --                              so the package would compile and new FP queries
1542 --                              would fire successfully. Otherwise, this procedure
1543 --                              does NOT support the FP Model.
1544 --
1545 --                              Modifications:
1546 --                              1) Modified pa_budget_versions-INSERT to populate the
1547 --                                 new FP approved_cost/rev_plan_type columns.
1548 --
1549 -- NOTE:
1550 --
1551 --           !!! This Copy Procedure does NOT support the FP Model !!!
1552 --
1553 --               This procedure only creates r11.5.7 budgets. You cannot use
1554 --               this procedure to create FP plans.
1555 --
1556 
1557   procedure copy (x_src_version_id      in     number,
1558                   x_amount_change_pct   in     number,
1559                   x_rounding_precision  in     number,
1560                   x_shift_days          in     number,
1561                   x_dest_project_id     in     number,
1562                   x_dest_budget_type_code    in     varchar2,
1563                   x_err_code            in out NOCOPY number, --File.Sql.39 bug 4440895
1564                   x_err_stage           in out NOCOPY varchar2, --File.Sql.39 bug 4440895
1565                   x_err_stack           in out NOCOPY varchar2) --File.Sql.39 bug 4440895
1566   is
1567      old_stack varchar2(630);
1568      x_dest_version_id number;
1569      x_created_by  number;
1570      x_last_update_login number;
1571      x_baselined_version_id number;
1572      x_baselined_resource_list_id number;
1573      x_src_resource_list_id number;
1574      x_resource_list_assgmt_id number;
1575      x_baselined_exists boolean;
1576      x_first_budget_period   varchar2(30);
1577      x_time_phased_type_code varchar2(30);
1578      x_entry_level_code varchar2(30);
1579      x_fbp_start_date   date;
1580      x_periods   number;
1581      x_start_date date;
1582      x_end_date   date;
1583 
1584   begin
1585 
1586      x_err_code := 0;
1587      old_stack := x_err_stack;
1588      x_err_stack := x_err_stack || '->copy';
1589 
1590      x_created_by := FND_GLOBAL.USER_ID;
1591      x_last_update_login := FND_GLOBAL.LOGIN_ID;
1592 
1593      x_err_stage := 'get project start date <'
1594                     ||  to_char(x_src_version_id) || '>';
1595 
1596      select start_date
1597      into g_project_start_date
1598      from pa_projects_all a,pa_budget_versions b /*Modified for 6320792 */
1599      where b.budget_version_id = x_src_version_id
1600      and   a.project_id = b.project_id;
1601 
1602      savepoint before_copy;
1603 
1604      x_err_stage := 'get source resource list id <'
1605                     ||  to_char(x_src_version_id) || '>';
1606 
1607      select resource_list_id,first_budget_period
1608      into   x_src_resource_list_id, x_first_budget_period
1609      from   pa_budget_versions
1610      where  budget_version_id = x_src_version_id;
1611 
1612      x_err_stage := 'get baselined budget <' ||  to_char(x_dest_project_id)
1613                     || '><' ||  x_dest_budget_type_code || '>' ;
1614 
1615 
1616 
1617      pa_budget_utils.get_baselined_version_id(
1618                                   x_project_id        => x_dest_project_id,
1619                                   x_budget_type_code  => x_dest_budget_type_code,
1620                                   x_budget_version_id => x_baselined_version_id,
1621                                   x_err_code          => x_err_code,
1622                                   x_err_stage         => x_err_stage,
1623                                   x_err_stack         => x_err_stack
1624                                   );
1625 
1626      if (x_err_code > 0) then
1627          x_baselined_exists := FALSE;
1628 
1629      elsif (x_err_code = 0) then
1630         -- baseliend budget exists, verify if resource lists are the same
1631         -- resource list used in accumulation
1632 
1633         select resource_list_id
1634         into   x_baselined_resource_list_id
1635         from   pa_budget_versions
1636         where  budget_version_id = x_baselined_version_id;
1637 
1638         if (x_src_resource_list_id <> x_baselined_resource_list_id) then
1639             x_err_code := 10;
1640             x_err_stage := 'PA_BU_BASE_RES_LIST_EXISTS';
1641             rollback to before_copy;
1642             return;
1643         end if;
1644 
1645         x_baselined_exists := TRUE;
1646 
1647      else
1648         -- x_err_code < 0
1649         rollback to before_copy;
1650         return;
1651      end if;
1652 
1653      x_err_stage := 'delete old draft budget <' ||  to_char(x_dest_project_id)
1654                     || '><' ||  x_dest_budget_type_code || '>' ;
1655 
1656      -- check if destination draft budget exists
1657 
1658      pa_budget_utils.get_draft_version_id(
1659                                   x_project_id        => x_dest_project_id,
1660                                   x_budget_type_code  => x_dest_budget_type_code,
1661                                   x_budget_version_id => x_dest_version_id,
1662                                   x_err_code          => x_err_code,
1663                                   x_err_stage         => x_err_stage,
1664                                   x_err_stack         => x_err_stack
1665                                   );
1666 
1667 
1671                                     x_err_code,
1668      if (x_err_code = 0) then
1669         -- draft budget exists, delete it
1670         PA_BUDGET_UTILS.delete_draft(x_dest_version_id,
1672                                     x_err_stage,
1673                                     x_err_stack);
1674      end if;
1675 
1676      if (x_err_code < 0) then
1677         rollback to before_copy;
1678         return;
1679      end if;
1680 
1681 /* Only check at baseline
1682      if (x_baselined_exists = FALSE) then
1683 
1684         -- create resource list assignment if necessary
1685         x_err_stage := 'create resource list assignment <'
1686                        || to_char(x_dest_project_id) || '><'
1687                        || to_char(x_src_resource_list_id) || '>';
1688 
1689         pa_res_list_assignments.create_rl_assgmt(x_dest_project_id,
1690                          x_src_resource_list_id,
1691                          x_resource_list_assgmt_id,
1692                          x_err_code,
1693                          x_err_stage,
1694                          x_err_stack);
1695 
1696         -- if oracle or application error, return
1697         if (x_err_code <> 0) then
1698               rollback to before_copy;
1699            return;
1700         end if;
1701 
1702         x_err_stage := 'create resource list usage <'
1703                        || to_char(x_dest_project_id) || '><'
1704                        || to_char(x_resource_list_assgmt_id) || '><'
1705                        || x_dest_budget_type_code || '>';
1706 
1707         -- create resource list usage if necessary
1708         pa_res_list_assignments.create_rl_uses(x_dest_project_id,
1709                          x_resource_list_assgmt_id,
1710                          x_dest_budget_type_code,
1711                          x_err_code,
1712                          x_err_stage,
1713                          x_err_stack);
1714 
1715         -- if oracle or application error, return.
1716 
1717         if (x_err_code <> 0) then
1718            rollback to before_copy;
1719            return;
1720         end if;
1721 
1722      end if;
1723 */
1724 
1725 
1726 
1727     x_err_stage := 'Getting Budget Entry Method Parameters <'||  to_char(x_src_version_id);
1728     select m.time_phased_type_code,
1729            m.entry_level_code
1730     into   x_time_phased_type_code,
1731            x_entry_level_code
1732     from   pa_budget_entry_methods m,
1733            pa_budget_versions v
1734     where  v.budget_version_id = x_src_version_id
1735     and    v.budget_entry_method_code = m.budget_entry_method_code;
1736 
1737 -- Shifting the First Budget Period
1738     if ( (nvl(x_shift_days,0) <> 0) and (x_first_budget_period is not null) and (
1739        x_time_phased_type_code not in ('R','N') )  ) then
1740 
1741         x_err_stage := 'Getting First Budget Period Start Date <'||  to_char(x_src_version_id);
1742 
1743         IF  NVL(x_time_phased_type_code ,'X') = 'P' THEN
1744           select start_date
1745           into x_fbp_start_date
1746           from pa_periods
1747           where  period_name = x_first_budget_period;
1748         ELSIF  NVL(x_time_phased_type_code ,'X') = 'G' THEN
1749           select start_date
1750           into x_fbp_start_date
1751           from GL_PERIOD_STATUSES P, PA_IMPLEMENTATIONS I
1752           where I.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
1753           AND P.APPLICATION_ID = pa_period_process_pkg.application_id
1754           AND P.ADJUSTMENT_PERIOD_FLAG = 'N'
1755           AND  period_name = x_first_budget_period;
1756         END IF ;
1757 
1758 
1759         x_err_stage := 'Getting no of periods by which first budget period needs to be shifted<'||  to_char(x_src_version_id);
1760         get_periods(nvl(g_project_start_date,x_fbp_start_date),
1761                   nvl(g_project_start_date, x_fbp_start_date)+ x_shift_days,
1762                   x_time_phased_type_code  ,
1763                   x_periods  ,
1764                   x_err_code ,
1765                   x_err_stage,
1766                   x_err_stack );
1767 
1768         if (x_err_code <> 0) then
1769           rollback to before_copy;
1770           return;
1771         end if;
1772 
1773 
1774 
1775         x_err_stage := 'Shifting first budget period <'||  to_char(x_src_version_id);
1776         shift_periods(x_fbp_start_date,
1777                       x_periods ,
1778                       x_first_budget_period ,
1779                       x_time_phased_type_code,
1780                       x_start_date ,
1781                       x_end_date,
1782                       x_err_code,
1783                       x_err_stage ,
1784                       x_err_stack );
1785 
1786          if (x_err_code <> 0) then
1787            rollback to before_copy;
1788            return;
1789          end if;
1790 
1791       end if;
1792 
1793 
1794      x_err_stage := 'create budget version <' ||  to_char(x_dest_project_id)
1795                     || '><' ||  x_dest_budget_type_code || '>' ;
1796 
1797      select pa_budget_versions_s.nextval
1798      into   x_dest_version_id
1799      from   sys.dual;
1800      insert into pa_budget_versions(
1801             budget_version_id,
1802             project_id,
1803             budget_type_code,
1804             version_number,
1805             budget_status_code,
1806             last_update_date,
1807             last_updated_by,
1808             creation_date,
1809             created_by,
1810             last_update_login,
1811             current_flag,
1812             original_flag,
1816             version_name,
1813             current_original_flag,
1814             resource_accumulated_flag,
1815             resource_list_id,
1817             budget_entry_method_code,
1818             baselined_by_person_id,
1819             baselined_date,
1820             change_reason_code,
1821             labor_quantity,
1822             labor_unit_of_measure,
1823             raw_cost,
1824             burdened_cost,
1825             revenue,
1826             description,
1827             attribute_category,
1828             attribute1,
1829             attribute2,
1830             attribute3,
1831             attribute4,
1832             attribute5,
1833             attribute6,
1834             attribute7,
1835             attribute8,
1836             attribute9,
1837             attribute10,
1838             attribute11,
1839             attribute12,
1840             attribute13,
1841             attribute14,
1842             attribute15,
1843             first_budget_period,
1844                 wf_status_code,
1845            approved_cost_plan_type_flag,
1846             approved_rev_plan_type_flag
1847                 )
1848          select
1849             x_dest_version_id,
1850             x_dest_project_id,
1851             x_dest_budget_type_code,
1852             1,
1853             'W',
1854             SYSDATE,
1855             x_created_by,
1856             SYSDATE,
1857             x_created_by,
1858             x_last_update_login,
1859             'N',
1860             'N',
1861             'N',
1862             'N',
1863             v.resource_list_id,
1864             v.version_name,
1865             v.budget_entry_method_code,
1866             NULL,
1867             NULL,
1868             v.change_reason_code,
1869             NULL,
1870             NULL,
1871             NULL,
1872             NULL,
1873             NULL,
1874             v.description,
1875             v.attribute_category,
1876             v.attribute1,
1877             v.attribute2,
1878             v.attribute3,
1879             v.attribute4,
1880             v.attribute5,
1881             v.attribute6,
1882             v.attribute7,
1883             v.attribute8,
1884             v.attribute9,
1885             v.attribute10,
1886             v.attribute11,
1887             v.attribute12,
1888             v.attribute13,
1889             v.attribute14,
1890             v.attribute15,
1891             x_first_budget_period,
1892             NULL,
1893             decode(x_dest_budget_type_code, 'AC', 'Y', 'N'), --Bug 5081715.
1894             decode(x_dest_budget_type_code, 'AR', 'Y', 'N')  --Bug 5081715.
1895          from   pa_budget_versions v
1896          where  v.budget_version_id = x_src_version_id;
1897 
1898      pa_budget_core.copy_lines(x_src_version_id,
1899                                x_amount_change_pct,
1900                                x_rounding_precision,
1901                                x_shift_days,
1902                                x_dest_version_id,
1903                                x_err_code,
1904                                x_err_stage,
1905                                x_err_stack);
1906 
1907      if (x_err_code <> 0) then
1908         rollback to before_copy;
1909         return;
1910      end if;
1911 
1912      -- Copy attachments for every draft budget copied
1913 
1914      fnd_attached_documents2_pkg.copy_attachments('PA_BUDGET_VERSIONS',
1915                                                    x_src_version_id,
1916                                                    null,null,null,null,
1917                                                    'PA_BUDGET_VERSIONS',
1918                                                    x_dest_version_id,
1919                                                    null,null,null,null,
1920                                                    FND_GLOBAL.USER_ID,
1921                                                    FND_GLOBAL.LOGIN_ID,
1922                                                    275, null, null) ;
1923 
1924      -- End copying attachments
1925 
1926      PA_BUDGET_UTILS.summerize_project_totals(x_dest_version_id,
1927                                              x_err_code,
1928                                              x_err_stage,
1929                                              x_err_stack);
1930 
1931      if (x_err_code <> 0) then
1932         rollback to before_copy;
1933         return;
1934      end if;
1935 
1936      x_err_stack := old_stack;
1937 
1938   exception
1939       when others then
1940          rollback to before_copy;
1941          x_err_code := SQLCODE;
1942          return;
1943   end copy;
1944 
1945 -----------------------------------------------------------------------------
1946 
1947   procedure verify (x_budget_version_id   in     number,
1948                     x_err_code            in out NOCOPY number, --File.Sql.39 bug 4440895
1949                     x_err_stage           in out NOCOPY varchar2, --File.Sql.39 bug 4440895
1950                     x_err_stack           in out NOCOPY varchar2) --File.Sql.39 bug 4440895
1951   is
1952   begin
1953      null;
1954   exception
1955       when others then
1956          x_err_code := SQLCODE;
1957   end verify;
1958 
1959 
1960 -----------------------------------------------------------------------------
1961 
1962 -- Name:   copy_lines
1963 --
1967 --                                    for insert into pa_resource_assignments:
1964 -- History
1965 --         27-JUN-2002  jwhite        Bug 1877119
1966 --                                    For the Copy_Lines procedure, add new column
1968 --                                    project_assignment_id, default -1.
1969 --
1970 --                                  - MOdified to support the new FP model:
1971 --                                    a. added NVL(a.RESOURCE_ASSIGNMENT_TYPE,'USER_ENTERED') = 'USER_ENTERED'
1972 --                                       to the budget_line loop.
1973 --                                    b. added three new columns to budget line inserts:
1974 --                                       1.     projfunc_currency_code
1975 --                                       2.     project_currency_code
1976 --                                       3.     txn_currency_code
1977 --
1978 --
1979 --
1980 
1981 --         23-feb-2006  prachand      Bug 4914055: Copy Project failing in copy_lines due to performance issues
1982 --                                    Replace the insert statement into pa_budget_lines with a bulk insert.
1983 
1984   procedure copy_lines (x_src_version_id      in     number,
1985                         x_amount_change_pct   in     number,
1986                         x_rounding_precision  in     number,
1987                         x_shift_days          in     number,
1988                         x_dest_version_id     in     number,
1989                         x_err_code            in out    NOCOPY number, --File.Sql.39 bug 4440895
1990                         x_err_stage           in out NOCOPY varchar2, --File.Sql.39 bug 4440895
1991                         x_err_stack           in out NOCOPY varchar2, --File.Sql.39 bug 4440895
1992                         x_pm_flag             in varchar2 default 'N')
1993   is
1994     -- Standard who
1995     x_created_by                 NUMBER(15);
1996     x_last_update_login          NUMBER(15);
1997 
1998     old_stack  varchar2(630);
1999     x_start_date date;
2000     x_end_date date;
2001     x_period_name varchar2(30);
2002     amount_change_pct number;
2003     rounding_precision number;
2004     x_time_phased_type_code varchar2(30);
2005     x_entry_level_code varchar2(30);
2006     x_task_start_date date;
2007     x_periods   number;
2008 
2009     x_return_status      VARCHAR2(2000);
2010     x_msg_count          NUMBER        := 0;
2011     x_msg_data           VARCHAR2(2000);
2012 
2013     l_version_is_baselined VARCHAR2(1);
2014 
2015      -- bug 4914055: added the followings:
2016      l_budget_line_id_tbl                            SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2017      l_budget_version_id_tbl                         SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2018      l_resource_assignment_id_tbl                    SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2019      l_start_date_tbl                                SYSTEM.PA_DATE_TBL_TYPE           := SYSTEM.PA_DATE_TBL_TYPE();
2020      l_last_update_date_tbl                          SYSTEM.PA_DATE_TBL_TYPE           := SYSTEM.PA_DATE_TBL_TYPE();
2021      l_last_updated_by_tbl                           SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2022      l_creation_date_tbl                             SYSTEM.PA_DATE_TBL_TYPE           := SYSTEM.PA_DATE_TBL_TYPE();
2023      l_created_by_tbl                                SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2024      l_last_update_login_tbl                         SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2025      l_end_date_tbl                                  SYSTEM.PA_DATE_TBL_TYPE           := SYSTEM.PA_DATE_TBL_TYPE();
2026      l_period_name_tbl                               SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
2027      l_quantity_tbl                                  SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2028      l_raw_cost_tbl                                  SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2029      l_burdened_cost_tbl                             SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2030      l_revenue_tbl                                   SYSTEM.pa_num_tbl_type:=SYSTEM.pa_num_tbl_type();
2031      l_change_reason_code_tbl                        SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
2032      l_description_tbl                               SYSTEM.pa_varchar2_2000_tbl_type:=SYSTEM.pa_varchar2_2000_tbl_type();
2033      l_attribute_category_tbl                        SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
2034      l_attribute1_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2035      l_attribute2_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2036      l_attribute3_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2037      l_attribute4_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2038      l_attribute5_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2039      l_attribute6_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2040      l_attribute7_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2041      l_attribute8_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2042      l_attribute9_tbl                                SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2043      l_attribute10_tbl                               SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2044      l_attribute11_tbl                               SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2048      l_attribute15_tbl                               SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2045      l_attribute12_tbl                               SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2046      l_attribute13_tbl                               SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2047      l_attribute14_tbl                               SYSTEM.pa_varchar2_150_tbl_type:=SYSTEM.pa_varchar2_150_tbl_type();
2049      l_pm_product_code_tbl                           SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
2050      l_pm_budget_line_reference_tbl                  SYSTEM.pa_varchar2_30_tbl_type:=SYSTEM.pa_varchar2_30_tbl_type();
2051      l_raw_cost_source_tbl                           SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2052      l_burdened_cost_source_tbl                      SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2053      l_quantity_source_tbl                           SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2054      l_revenue_source_tbl                            SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2055      l_projfunc_currency_code_tbl                    SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2056      l_project_currency_code_tbl                     SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2057      l_txn_currency_code_tbl                         SYSTEM.pa_varchar2_15_tbl_type:=SYSTEM.pa_varchar2_15_tbl_type();
2058 
2059 
2060      TYPE period_info_tab IS TABLE OF NUMBER INDEX BY VARCHAR2(60);
2061 
2062      l_period_info_tbl     period_info_tab;
2063 
2064      l_project_id              pa_projects_all.project_id%TYPE;
2065      l_min_start_date          DATE;
2066 
2067      -- end bug 4914055
2068 
2069   begin
2070 
2071      x_err_code := 0;
2072      old_stack := x_err_stack;
2073      x_err_stack := x_err_stack || '->copy_lines';
2074 
2075      x_created_by := FND_GLOBAL.USER_ID;
2076      x_last_update_login := FND_GLOBAL.LOGIN_ID;
2077 
2078      begin
2079        select 'Y'
2080        into   l_version_is_baselined
2081        from   pa_budget_versions
2082        where  budget_status_code = 'B'
2083        and    budget_version_id = x_dest_version_id;
2084      exception
2085        when no_data_found then
2086          l_version_is_baselined := 'N';
2087      end;
2088 
2089      if (x_amount_change_pct is not null) then
2090          amount_change_pct := x_amount_change_pct;
2091      else
2092          amount_change_pct := 1;
2093      end if;
2094 
2095      if (x_rounding_precision is not null) then
2096          rounding_precision := x_rounding_precision;
2097      else
2098          rounding_precision := 5;
2099      end if;
2100 
2101      x_err_stage := 'get time phased type <' ||  to_char(x_src_version_id)
2102                     || '>' ;
2103      SELECT m.time_phased_type_code,
2104                  m.entry_level_code
2105      INTO   x_time_phased_type_code,
2106               x_entry_level_code
2107      FROM   pa_budget_entry_methods m,
2108               pa_budget_versions v
2109      WHERE  v.budget_version_id = x_src_version_id
2110      AND    v.budget_entry_method_code = m.budget_entry_method_code;
2111 
2112      x_err_stage := 'copy resource assignment <' ||  to_char(x_src_version_id)
2113                     || '>' ;
2114 
2115      IF (x_entry_level_code <> 'P') THEN
2116 
2117         INSERT INTO pa_resource_assignments
2118                    (resource_assignment_id,
2119                     budget_version_id,
2120                     project_id,
2121                     task_id,
2122                     resource_list_member_id,
2123                     last_update_date,
2124                     last_updated_by,
2125                     creation_date,
2126                     created_by,
2127                     last_update_login,
2128                     unit_of_measure,
2129                     track_as_labor_flag,
2130                     project_assignment_id,
2131                     RESOURCE_ASSIGNMENT_TYPE
2132                    )
2133            SELECT  pa_resource_assignments_s.nextval,
2134                    x_dest_version_id,
2135                    dt.project_id,
2136                    dt.task_id,
2137                    sa.resource_list_member_id,
2138                    SYSDATE,
2139                    x_created_by,
2140                    SYSDATE,
2141                    x_created_by,
2142                    x_last_update_login,
2143                    sa.unit_of_measure,
2144                    sa.track_as_labor_flag,
2145                    -1,
2146                    sa.RESOURCE_ASSIGNMENT_TYPE
2147             FROM
2148                    pa_resource_assignments sa,
2149                    pa_tasks st,
2150                    pa_tasks dt,
2151                    pa_budget_versions dv
2152            WHERE   sa.budget_version_id = x_src_version_id
2153            AND     sa.project_id = st.project_id
2154            AND     sa.task_id = st.task_id
2155            AND     st.task_number = dt.task_number
2156            AND     dt.project_id = dv.project_id
2157            AND     dv.budget_version_id = x_dest_version_id
2158            AND     NVL(sa.RESOURCE_ASSIGNMENT_TYPE,'USER_ENTERED') = 'USER_ENTERED';
2159 
2160      ELSE
2161 
2162         INSERT INTO pa_resource_assignments
2163                    (resource_assignment_id,
2164                     budget_version_id,
2165                     project_id,
2166                     task_id,
2167                     resource_list_member_id,
2168                     last_update_date,
2169                     last_updated_by,
2170                     creation_date,
2174                     track_as_labor_flag,
2171                     created_by,
2172                     last_update_login,
2173                     unit_of_measure,
2175                     project_assignment_id,
2176                     RESOURCE_ASSIGNMENT_TYPE
2177                    )
2178            SELECT  pa_resource_assignments_s.nextval,
2179                    x_dest_version_id,
2180                    dv.project_id,
2181                    0,
2182                    sa.resource_list_member_id,
2183                    SYSDATE,
2184                    x_created_by,
2185                    SYSDATE,
2186                    x_created_by,
2187                    x_last_update_login,
2188                    sa.unit_of_measure,
2189                    sa.track_as_labor_flag,
2190                    -1,
2191                    sa.RESOURCE_ASSIGNMENT_TYPE
2192            FROM
2193                   pa_resource_assignments sa,
2194                   pa_budget_versions dv
2195            WHERE  sa.budget_version_id = x_src_version_id
2196            AND    sa.task_id = 0
2197            AND    dv.budget_version_id = x_dest_version_id
2198            AND    NVL(sa.RESOURCE_ASSIGNMENT_TYPE,'USER_ENTERED') = 'USER_ENTERED';
2199 
2200      END IF;
2201         -- Bug Fix: 4569365. Removed MRC code.
2202         /* FPB2: MRC */
2203         x_err_stage := 'calling populate_bl_map_tmp <' ||to_char(x_src_version_id)
2204                     || '>' ;
2205 
2206         /** MRC Elimination Changes: PA_MRC_FINPLAN.populate_bl_map_tmp **/
2207         PA_FIN_PLAN_UTILS2.populate_bl_map_tmp
2208 		(p_source_fin_plan_version_id  => x_src_version_id,
2209                                                     x_return_status      => x_return_status,
2210                                                     x_msg_count          => x_msg_count,
2211                                                     x_msg_data           => x_msg_data);
2212 
2213 
2214      -- bug 4914055: we are mimicing the logic used in finplan model to derive the number of periods
2215      -- to be shifted due to performance reason.
2216 
2217      select project_id
2218      into   l_project_id
2219      from   pa_budget_versions
2220      where  budget_version_id = x_src_version_id;
2221 
2222      DELETE FROM pa_fp_cpy_periods_tmp;
2223 
2224      if (nvl(x_shift_days,0) <> 0) then
2225           if (   (x_time_phased_type_code = 'G')
2226               or (x_time_phased_type_code = 'P')) then
2227                SELECT p.start_date
2228                INTO   l_min_start_date
2229                FROM   pa_projects_all p /*Modified for bug 6320792 */
2230                WHERE  p.project_id = l_project_id;
2231 
2232                IF l_min_start_date IS NULL THEN
2233                     SELECt min(t.start_date)
2234                     INTO   l_min_start_date
2235                     FROM   pa_tasks t
2236                     WHERE  t.project_id = l_project_id;
2237 
2238                     IF l_min_start_date is NULL THEN
2239 
2240                          SELECT min(bl.start_date)
2241                          INTO   l_min_start_Date
2242                          FROM   pa_budget_lines bl
2243                          WHERE  bl.budget_version_id = x_src_version_id;
2244 
2245                          -- If l_start_date is null after the above select it implies
2246                          -- there are no budget lines. So return immediately as nothing
2247                          -- needs to be copied
2248                          IF l_min_start_Date IS NULL THEN
2249                             RETURN;
2250                          END IF;
2251                     END IF;  /* Mininum Task start date is null */
2252                END IF; /* Minimum Project start date is null */
2253 
2254                --Based on the shift_days check how much shift is required period wise
2255                pa_budget_core.get_periods(
2256                              x_start_date1 => l_min_start_date,
2257                              x_start_date2 => l_min_start_date + x_shift_days,
2258                              x_period_type => x_time_phased_type_code,
2259                              x_periods     => x_periods,
2260                              x_err_code    => x_err_code,
2261                              x_err_stage   => x_err_stage,
2262                              x_err_stack   => x_err_stack);
2263                IF x_err_code <> 0 THEN
2264                     PA_UTILS.ADD_MESSAGE(p_app_short_name=> 'PA',
2265                                          p_msg_name      => x_err_stage);
2266                     RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2267                END IF;
2268           end if; -- g/p time phase
2269      end if; -- shift days non zero
2270 
2271         for budget_line_row in
2272           (select l.resource_assignment_id, l.start_date, l.end_date,a.task_id, l.period_name
2273            from   pa_budget_lines l,
2274                   pa_resource_assignments a
2275            where  a.budget_version_id = x_src_version_id
2276                 and    a.resource_assignment_id = l.resource_assignment_id
2277            and    NVL(a.RESOURCE_ASSIGNMENT_TYPE,'USER_ENTERED') = 'USER_ENTERED'
2278           ) loop
2279 
2280             x_period_name := NULL;
2281             x_start_date := NULL;
2282             x_end_date := NULL;
2283 
2284 -- Shifting Periods for Budget Lines
2285      if (nvl(x_shift_days,0) <> 0) then
2286               if (   (x_time_phased_type_code = 'R')
2287                        or (x_time_phased_type_code = 'N')) then
2288                  -- time-phased by date range or non-time-phased
2289              x_start_date :=  budget_line_row.start_date + x_shift_days;
2290              x_end_date :=  budget_line_row.end_date + x_shift_days;
2291         else
2295             /*
2292 
2293                  -- Bug 4772773: commenting the following for perf reason to pass only a single number of
2294                  -- periods to be passed to be shifted same for all the lines.
2296                 if (x_entry_level_code <> 'P') then
2297               x_err_stage := 'Getting Task Start Date <'|| to_char(x_src_version_id);
2298               select start_date
2299               into x_task_start_date
2300               from pa_tasks
2301               where task_id =  budget_line_row.task_id;
2302            end if;
2303 
2304                 x_err_stage := 'Getting no of periods by which line budget period needs to be shifted<'||
2305                                 to_char(x_src_version_id);
2306                 get_periods(nvl(x_task_start_date, nvl(g_project_start_date, budget_line_row.start_date) ),
2307                           nvl(x_task_start_date, nvl(g_project_start_date, budget_line_row.start_date) )
2308                                + x_shift_days,
2309                           x_time_phased_type_code  ,
2310                           x_periods  ,
2311                           x_err_code ,
2312                           x_err_stage,
2313                           x_err_stack );
2314 
2315                   if (x_err_code <> 0) then
2316                    return;
2317              end if;
2318               */
2319               if (x_periods <> 0) then --Bug 5151476
2320                 x_err_stage := 'Shifting line budget period <'||  to_char(x_src_version_id);
2321                 shift_periods(budget_line_row.start_date,
2322                               x_periods ,
2323                               x_period_name ,
2324                               x_time_phased_type_code,
2325                               x_start_date ,
2326                               x_end_date,
2327                               x_err_code,
2328                               x_err_stage,
2329                               x_err_stack );
2330 
2331                  if (x_err_code <> 0) then
2332                    return;
2333                  end if;
2334                    /* Bug 4772773: Populating a temp table with the new shifted period name, start date and end date */
2335                        IF (NOT (l_period_info_tbl.EXISTS(x_period_name)) AND x_period_name IS NOT NULL) THEN  -- Fix for bug 12760225
2336                            INSERT INTO pa_fp_cpy_periods_tmp
2337                                    (PA_PERIOD_NAME
2338                                    ,GL_PERIOD_NAME
2339                                    ,PERIOD_NAME
2340                                    ,START_DATE
2341                                    ,END_DATE)
2342                            VALUES
2343                                    (decode(x_time_phased_type_code,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P,budget_line_row.period_name,'-99')
2344                                    ,decode(x_time_phased_type_code,PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G,budget_line_row.period_name,'-99')
2345                                    ,x_period_name
2346                                    ,x_start_date
2347                                    ,x_end_date);
2348                            l_period_info_tbl(x_period_name ) := budget_line_row.resource_assignment_id;
2349                        END IF;
2350                 end if;
2351                end if;
2352              end if;
2353      end loop; -- bug 4772773: moved up here.
2354 
2355 -- bug 4772773: Commented out the following code block for performance reasons.
2356 /*
2357             if (x_entry_level_code <> 'P') then
2358 
2359          INSERT INTO pa_budget_lines
2360                (budget_line_id,           /* FPB2
2361                 budget_version_id,        /* FPB2
2362                 resource_assignment_id,
2363                 start_date,
2364                 last_update_date,
2365                 last_updated_by,
2366                 creation_date,
2367                 created_by,
2368                 last_update_login,
2369                 end_date,
2370                 period_name,
2371                 quantity,
2372                 raw_cost,
2373                 burdened_cost,
2374                 revenue,
2375                 change_reason_code,
2376                 description,
2377                 attribute_category,
2378                 attribute1,
2379                 attribute2,
2380                 attribute3,
2381                 attribute4,
2382                 attribute5,
2383                 attribute6,
2384                 attribute7,
2385                 attribute8,
2386                 attribute9,
2387                 attribute10,
2388                 attribute11,
2389                 attribute12,
2390                 attribute13,
2391                 attribute14,
2392                 attribute15,
2393                 pm_product_code,
2394                 pm_budget_line_reference,
2395                 raw_cost_source,
2396                 burdened_cost_source,
2397                 quantity_source,
2398                 revenue_source,
2399                 projfunc_currency_code,
2400                 project_currency_code,
2401                 txn_currency_code
2402                 )
2403               select
2404                 bmt.target_budget_line_id,       /* FPB2
2405                 x_dest_version_id,               /* FPB2
2406                 da.resource_assignment_id,
2407                 decode(x_start_date, NULL, l.start_date, x_start_date),
2408                 SYSDATE,
2409                 x_created_by,
2410                 SYSDATE,
2411                 x_created_by,
2412                 x_last_update_login,
2413                 decode(x_end_date, NULL, l.end_date, x_end_date),
2414                 decode(x_period_name, NULL, l.period_name, x_period_name),
2415                 l.quantity,
2416                 round(l.raw_cost * amount_change_pct, rounding_precision),
2417                 round(l.burdened_cost * amount_change_pct, rounding_precision),
2418                 round(l.revenue * amount_change_pct, rounding_precision),
2419                 l.change_reason_code,
2420                 l.description,
2421                 l.attribute_category,
2422                 l.attribute1,
2423                 l.attribute2,
2424                 l.attribute3,
2425                 l.attribute4,
2426                 l.attribute5,
2427                 l.attribute6,
2428                 l.attribute7,
2429                 l.attribute8,
2430                 l.attribute9,
2431                 l.attribute10,
2432                 l.attribute11,
2433                 l.attribute12,
2434                 l.attribute13,
2435                 l.attribute14,
2436                 l.attribute15,
2437                 decode(x_pm_flag,'Y',l.pm_product_code,NULL),
2438                 decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
2439                 'B',
2440                 'B',
2441                 'B',
2442                 'B',
2443                 l.projfunc_currency_code,
2444                 l.project_currency_code,
2445                 l.txn_currency_code
2446          from   pa_budget_lines l,
2447                 pa_resource_assignments sa,
2448                 pa_tasks st,
2449                 pa_tasks dt,
2450                 pa_resource_assignments da,
2451                 pa_fp_bl_map_tmp bmt            /* FPB2
2452          where  l.resource_assignment_id =
2453                 budget_line_row.resource_assignment_id
2454          and    l.start_date = budget_line_row.start_date
2455          and    l.resource_assignment_id = sa.resource_assignment_id
2456          and    sa.budget_version_id = x_src_version_id
2457          and    sa.task_id = st.task_id
2458          and    sa.project_id = st.project_id
2459          and    sa.resource_list_member_id = da.resource_list_member_id
2460          and    st.task_number = dt.task_number
2461          and    dt.task_id = da.task_id
2462          and    dt.project_id = da.project_id
2463          and    da.budget_version_id = x_dest_version_id
2464          and    l.budget_line_id = bmt.source_budget_line_id      /* FPB2
2465         ;
2466 
2467           else
2468 
2469              insert into pa_budget_lines
2470                (budget_line_id,           /* FPB2
2471                 budget_version_id,        /* FPB2
2472                 resource_assignment_id,
2473                 start_date,
2474                 last_update_date,
2475                 last_updated_by,
2476                 creation_date,
2477                 created_by,
2478                 last_update_login,
2479                 end_date,
2480                 period_name,
2481                 quantity,
2482                 raw_cost,
2483                 burdened_cost,
2484                 revenue,
2485                 change_reason_code,
2486                 description,
2487                 attribute_category,
2488                 attribute1,
2489                 attribute2,
2490                 attribute3,
2491                 attribute4,
2492                 attribute5,
2493                 attribute6,
2494                 attribute7,
2495                 attribute8,
2496                 attribute9,
2497                 attribute10,
2498                 attribute11,
2499                 attribute12,
2500                 attribute13,
2501                 attribute14,
2502                 attribute15,
2503                 pm_product_code,
2504                 pm_budget_line_reference,
2505                 raw_cost_source,
2506                 burdened_cost_source,
2507                 quantity_source,
2508                 revenue_source,
2509                 projfunc_currency_code,
2510                 project_currency_code,
2511                 txn_currency_code
2512                 )
2513               select
2514                bmt.target_budget_line_id,       /* FPB2
2515                x_dest_version_id,               /* FPB2
2516                da.resource_assignment_id,
2517                decode(x_start_date, NULL, l.start_date, x_start_date),
2518                SYSDATE,
2519                x_created_by,
2520                SYSDATE,
2521                x_created_by,
2522                x_last_update_login,
2523                decode(x_end_date, NULL, l.end_date, x_end_date),
2524                decode(x_period_name, NULL, l.period_name, x_period_name),
2525                l.quantity,
2526                round(l.raw_cost * amount_change_pct, rounding_precision),
2527                round(l.burdened_cost * amount_change_pct, rounding_precision),
2528                round(l.revenue * amount_change_pct, rounding_precision),
2529                l.change_reason_code,
2530                l.description,
2531                l.attribute_category,
2532                l.attribute1,
2533                l.attribute2,
2534                l.attribute3,
2535                l.attribute4,
2536                l.attribute5,
2537                l.attribute6,
2538                l.attribute7,
2539                l.attribute8,
2540                l.attribute9,
2541                l.attribute10,
2542                l.attribute11,
2543                l.attribute12,
2544                l.attribute13,
2545                l.attribute14,
2546                l.attribute15,
2547                decode(x_pm_flag,'Y',l.pm_product_code,NULL),
2548                decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
2549                'B',
2550                'B',
2551                'B',
2552                'B',
2553                l.projfunc_currency_code,
2554                l.project_currency_code,
2555                l.txn_currency_code
2556          from  pa_budget_lines l,
2557                pa_resource_assignments sa,
2558                pa_resource_assignments da,
2559                pa_fp_bl_map_tmp bmt            /* FPB2
2560          where l.resource_assignment_id =
2561                budget_line_row.resource_assignment_id
2562          and   l.start_date = budget_line_row.start_date
2563          and   l.resource_assignment_id = sa.resource_assignment_id
2564          and   sa.budget_version_id = x_src_version_id
2565          and   sa.task_id = 0
2566          and   sa.resource_list_member_id = da.resource_list_member_id
2567          and   da.task_id = 0
2568          and   da.budget_version_id = x_dest_version_id
2569          and   l.budget_line_id = bmt.source_budget_line_id      /* FPB2
2570          ;
2571 
2572         end if; */
2573 
2574       -- bug 4772773: Splitted the above select and insert as following
2575       -- individual processing block due to performance reason so that
2576       -- we can make use of bulk processing logic wherever possible and required.
2577       --Bug 5151476
2578       if Nvl(x_shift_days, 0) = 0 OR (nvl(x_periods,0)=0 AND
2579 (x_time_phased_type_code='P' OR x_time_phased_type_code='G')) then
2580         if (x_entry_level_code <> 'P') then
2581                 select
2582                     bmt.target_budget_line_id,       /* FPB2 */
2583                     x_dest_version_id,               /* FPB2 */
2584                     da.resource_assignment_id,
2585                     l.start_date,
2586                     SYSDATE,
2587                     x_created_by,
2588                     SYSDATE,
2589                     x_created_by,
2590                     x_last_update_login,
2591                     l.end_date,
2592                     l.period_name,
2593                     l.quantity,
2594                     round(l.raw_cost * amount_change_pct, rounding_precision),
2595                     round(l.burdened_cost * amount_change_pct, rounding_precision),
2596                     round(l.revenue * amount_change_pct, rounding_precision),
2597                     l.change_reason_code,
2598                     l.description,
2599                     l.attribute_category,
2600                     l.attribute1,
2601                     l.attribute2,
2602                     l.attribute3,
2603                     l.attribute4,
2604                     l.attribute5,
2605                     l.attribute6,
2606                     l.attribute7,
2607                     l.attribute8,
2608                     l.attribute9,
2609                     l.attribute10,
2610                     l.attribute11,
2611                     l.attribute12,
2612                     l.attribute13,
2613                     l.attribute14,
2614                     l.attribute15,
2615                     decode(x_pm_flag,'Y',l.pm_product_code,NULL),
2616                     decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
2617                     'B',
2618                     'B',
2619                     'B',
2620                     'B',
2621                     l.projfunc_currency_code,
2622                     l.project_currency_code,
2623                     l.txn_currency_code
2624                 bulk collect into
2625                     l_budget_line_id_tbl,
2626                     l_budget_version_id_tbl,
2627                     l_resource_assignment_id_tbl,
2628                     l_start_date_tbl,
2629                     l_last_update_date_tbl,
2630                     l_last_updated_by_tbl,
2631                     l_creation_date_tbl,
2632                     l_created_by_tbl,
2633                     l_last_update_login_tbl,
2634                     l_end_date_tbl,
2635                     l_period_name_tbl,
2636                     l_quantity_tbl,
2637                     l_raw_cost_tbl,
2638                     l_burdened_cost_tbl,
2639                     l_revenue_tbl,
2640                     l_change_reason_code_tbl,
2641                     l_description_tbl,
2642                     l_attribute_category_tbl,
2643                     l_attribute1_tbl,
2644                     l_attribute2_tbl,
2645                     l_attribute3_tbl,
2646                     l_attribute4_tbl,
2647                     l_attribute5_tbl,
2648                     l_attribute6_tbl,
2649                     l_attribute7_tbl,
2650                     l_attribute8_tbl,
2651                     l_attribute9_tbl,
2652                     l_attribute10_tbl,
2653                     l_attribute11_tbl,
2654                     l_attribute12_tbl,
2655                     l_attribute13_tbl,
2656                     l_attribute14_tbl,
2657                     l_attribute15_tbl,
2658                     l_pm_product_code_tbl,
2659                     l_pm_budget_line_reference_tbl,
2660                     l_raw_cost_source_tbl,
2661                     l_burdened_cost_source_tbl,
2662                     l_quantity_source_tbl,
2663                     l_revenue_source_tbl,
2664                     l_projfunc_currency_code_tbl,
2665                     l_project_currency_code_tbl,
2666                     l_txn_currency_code_tbl
2667              from   pa_budget_lines l,
2668                     pa_resource_assignments sa,
2669                     pa_tasks st,
2670                     pa_tasks dt,
2671                     pa_resource_assignments da,
2672                     pa_fp_bl_map_tmp bmt            /* FPB2 */
2673              where  l.budget_version_id = x_src_version_id
2674              and    l.resource_assignment_id = sa.resource_assignment_id
2675              and    sa.budget_version_id = x_src_version_id
2676              and    sa.task_id = st.task_id
2677              and    sa.project_id = st.project_id
2678              and    sa.resource_list_member_id = da.resource_list_member_id
2679              and    st.task_number = dt.task_number
2680              and    dt.task_id = da.task_id
2681              and    dt.project_id = da.project_id
2682              and    da.budget_version_id = x_dest_version_id
2683              and    l.budget_line_id = bmt.source_budget_line_id; /* FPB2 */
2684 
2685         else -- project level planning
2686                 select
2687                    bmt.target_budget_line_id,       /* FPB2 */
2688                    x_dest_version_id,               /* FPB2 */
2689                    da.resource_assignment_id,
2690                    l.start_date,
2691                    SYSDATE,
2692                    x_created_by,
2693                    SYSDATE,
2694                    x_created_by,
2695                    x_last_update_login,
2696                    l.end_date,
2697                    l.period_name,
2698                    l.quantity,
2699                    round(l.raw_cost * amount_change_pct, rounding_precision),
2700                    round(l.burdened_cost * amount_change_pct, rounding_precision),
2701                    round(l.revenue * amount_change_pct, rounding_precision),
2702                    l.change_reason_code,
2703                    l.description,
2704                    l.attribute_category,
2705                    l.attribute1,
2706                    l.attribute2,
2707                    l.attribute3,
2708                    l.attribute4,
2709                    l.attribute5,
2710                    l.attribute6,
2711                    l.attribute7,
2712                    l.attribute8,
2713                    l.attribute9,
2714                    l.attribute10,
2715                    l.attribute11,
2716                    l.attribute12,
2717                    l.attribute13,
2718                    l.attribute14,
2719                    l.attribute15,
2720                    decode(x_pm_flag,'Y',l.pm_product_code,NULL),
2721                    decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
2722                    'B',
2723                    'B',
2724                    'B',
2725                    'B',
2726                    l.projfunc_currency_code,
2727                    l.project_currency_code,
2728                    l.txn_currency_code
2729                 bulk collect into
2730                     l_budget_line_id_tbl,
2731                     l_budget_version_id_tbl,
2732                     l_resource_assignment_id_tbl,
2733                     l_start_date_tbl,
2734                     l_last_update_date_tbl,
2735                     l_last_updated_by_tbl,
2736                     l_creation_date_tbl,
2737                     l_created_by_tbl,
2738                     l_last_update_login_tbl,
2739                     l_end_date_tbl,
2740                     l_period_name_tbl,
2741                     l_quantity_tbl,
2742                     l_raw_cost_tbl,
2743                     l_burdened_cost_tbl,
2744                     l_revenue_tbl,
2745                     l_change_reason_code_tbl,
2746                     l_description_tbl,
2747                     l_attribute_category_tbl,
2748                     l_attribute1_tbl,
2749                     l_attribute2_tbl,
2750                     l_attribute3_tbl,
2751                     l_attribute4_tbl,
2752                     l_attribute5_tbl,
2753                     l_attribute6_tbl,
2754                     l_attribute7_tbl,
2755                     l_attribute8_tbl,
2756                     l_attribute9_tbl,
2757                     l_attribute10_tbl,
2758                     l_attribute11_tbl,
2759                     l_attribute12_tbl,
2760                     l_attribute13_tbl,
2761                     l_attribute14_tbl,
2762                     l_attribute15_tbl,
2763                     l_pm_product_code_tbl,
2764                     l_pm_budget_line_reference_tbl,
2765                     l_raw_cost_source_tbl,
2766                     l_burdened_cost_source_tbl,
2767                     l_quantity_source_tbl,
2768                     l_revenue_source_tbl,
2769                     l_projfunc_currency_code_tbl,
2770                     l_project_currency_code_tbl,
2771                     l_txn_currency_code_tbl
2772              from  pa_budget_lines l,
2773                    pa_resource_assignments sa,
2774                    pa_resource_assignments da,
2775                    pa_fp_bl_map_tmp bmt            /* FPB2 */
2776              where l.budget_version_id = x_src_version_id
2777              and   l.resource_assignment_id = sa.resource_assignment_id
2778              and   sa.budget_version_id = x_src_version_id
2779              and   sa.task_id = 0
2780              and   sa.resource_list_member_id = da.resource_list_member_id
2781              and   da.task_id = 0
2782              and   da.budget_version_id = x_dest_version_id
2783              and   l.budget_line_id = bmt.source_budget_line_id; /* FPB2 */
2784         end if;
2785       else -- shift date non zero
2786           if x_time_phased_type_code not in ('N', 'R') then
2787               if (x_entry_level_code <> 'P') then
2788                       select
2789                           bmt.target_budget_line_id,       /* FPB2 */
2790                           x_dest_version_id,               /* FPB2 */
2791                           da.resource_assignment_id,
2792                           pptmp.start_date,
2793                           SYSDATE,
2794                           x_created_by,
2795                           SYSDATE,
2796                           x_created_by,
2797                           x_last_update_login,
2798                           pptmp.end_date,
2799                           pptmp.period_name,
2800                           l.quantity,
2801                           round(l.raw_cost * amount_change_pct, rounding_precision),
2802                           round(l.burdened_cost * amount_change_pct, rounding_precision),
2803                           round(l.revenue * amount_change_pct, rounding_precision),
2804                           l.change_reason_code,
2805                           l.description,
2806                           l.attribute_category,
2807                           l.attribute1,
2808                           l.attribute2,
2809                           l.attribute3,
2810                           l.attribute4,
2811                           l.attribute5,
2812                           l.attribute6,
2813                           l.attribute7,
2814                           l.attribute8,
2815                           l.attribute9,
2816                           l.attribute10,
2817                           l.attribute11,
2818                           l.attribute12,
2819                           l.attribute13,
2820                           l.attribute14,
2821                           l.attribute15,
2822                           decode(x_pm_flag,'Y',l.pm_product_code,NULL),
2823                           decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
2824                           'B',
2825                           'B',
2826                           'B',
2827                           'B',
2828                           l.projfunc_currency_code,
2829                           l.project_currency_code,
2830                           l.txn_currency_code
2831                       bulk collect into
2832                           l_budget_line_id_tbl,
2833                           l_budget_version_id_tbl,
2834                           l_resource_assignment_id_tbl,
2835                           l_start_date_tbl,
2836                           l_last_update_date_tbl,
2837                           l_last_updated_by_tbl,
2838                           l_creation_date_tbl,
2839                           l_created_by_tbl,
2840                           l_last_update_login_tbl,
2841                           l_end_date_tbl,
2842                           l_period_name_tbl,
2843                           l_quantity_tbl,
2844                           l_raw_cost_tbl,
2845                           l_burdened_cost_tbl,
2846                           l_revenue_tbl,
2847                           l_change_reason_code_tbl,
2848                           l_description_tbl,
2849                           l_attribute_category_tbl,
2850                           l_attribute1_tbl,
2851                           l_attribute2_tbl,
2852                           l_attribute3_tbl,
2853                           l_attribute4_tbl,
2854                           l_attribute5_tbl,
2855                           l_attribute6_tbl,
2856                           l_attribute7_tbl,
2857                           l_attribute8_tbl,
2858                           l_attribute9_tbl,
2859                           l_attribute10_tbl,
2860                           l_attribute11_tbl,
2861                           l_attribute12_tbl,
2862                           l_attribute13_tbl,
2863                           l_attribute14_tbl,
2864                           l_attribute15_tbl,
2865                           l_pm_product_code_tbl,
2866                           l_pm_budget_line_reference_tbl,
2867                           l_raw_cost_source_tbl,
2868                           l_burdened_cost_source_tbl,
2869                           l_quantity_source_tbl,
2870                           l_revenue_source_tbl,
2871                           l_projfunc_currency_code_tbl,
2872                           l_project_currency_code_tbl,
2873                           l_txn_currency_code_tbl
2874                    from   pa_budget_lines l,
2875                           pa_resource_assignments sa,
2876                           pa_tasks st,
2877                           pa_tasks dt,
2878                           pa_resource_assignments da,
2879                           pa_fp_bl_map_tmp bmt,            /* FPB2 */
2880                           PA_FP_CPY_PERIODS_TMP pptmp
2881                    where  l.budget_version_id = x_src_version_id
2882                    and    l.resource_assignment_id = sa.resource_assignment_id
2883                    and    decode(x_time_phased_type_code,
2884                                  PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P, pptmp.pa_period_name,
2885                                  PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G, pptmp.gl_period_name) = l.period_name
2886                    and    sa.budget_version_id = x_src_version_id
2887                    and    sa.task_id = st.task_id
2888                    and    sa.project_id = st.project_id
2889                    and    sa.resource_list_member_id = da.resource_list_member_id
2890                    and    st.task_number = dt.task_number
2891                    and    dt.task_id = da.task_id
2892                    and    dt.project_id = da.project_id
2893                    and    da.budget_version_id = x_dest_version_id
2894                    and    l.budget_line_id = bmt.source_budget_line_id; /* FPB2 */
2895                 else -- project level planning
2896 
2897                       select
2898                          bmt.target_budget_line_id,       /* FPB2 */
2899                          x_dest_version_id,               /* FPB2 */
2900                          da.resource_assignment_id,
2901                          pptmp.start_date,
2902                          SYSDATE,
2903                          x_created_by,
2904                          SYSDATE,
2905                          x_created_by,
2906                          x_last_update_login,
2907                          pptmp.end_date,
2908                          pptmp.period_name,
2909                          l.quantity,
2910                          round(l.raw_cost * amount_change_pct, rounding_precision),
2911                          round(l.burdened_cost * amount_change_pct, rounding_precision),
2912                          round(l.revenue * amount_change_pct, rounding_precision),
2913                          l.change_reason_code,
2914                          l.description,
2915                          l.attribute_category,
2916                          l.attribute1,
2917                          l.attribute2,
2918                          l.attribute3,
2919                          l.attribute4,
2920                          l.attribute5,
2921                          l.attribute6,
2922                          l.attribute7,
2923                          l.attribute8,
2924                          l.attribute9,
2925                          l.attribute10,
2926                          l.attribute11,
2927                          l.attribute12,
2928                          l.attribute13,
2929                          l.attribute14,
2930                          l.attribute15,
2931                          decode(x_pm_flag,'Y',l.pm_product_code,NULL),
2932                          decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
2933                          'B',
2934                          'B',
2935                          'B',
2936                          'B',
2937                          l.projfunc_currency_code,
2938                          l.project_currency_code,
2939                          l.txn_currency_code
2940                       bulk collect into
2941                           l_budget_line_id_tbl,
2942                           l_budget_version_id_tbl,
2943                           l_resource_assignment_id_tbl,
2944                           l_start_date_tbl,
2945                           l_last_update_date_tbl,
2946                           l_last_updated_by_tbl,
2947                           l_creation_date_tbl,
2948                           l_created_by_tbl,
2949                           l_last_update_login_tbl,
2950                           l_end_date_tbl,
2951                           l_period_name_tbl,
2952                           l_quantity_tbl,
2953                           l_raw_cost_tbl,
2954                           l_burdened_cost_tbl,
2955                           l_revenue_tbl,
2956                           l_change_reason_code_tbl,
2957                           l_description_tbl,
2958                           l_attribute_category_tbl,
2959                           l_attribute1_tbl,
2960                           l_attribute2_tbl,
2961                           l_attribute3_tbl,
2962                           l_attribute4_tbl,
2963                           l_attribute5_tbl,
2964                           l_attribute6_tbl,
2965                           l_attribute7_tbl,
2966                           l_attribute8_tbl,
2967                           l_attribute9_tbl,
2968                           l_attribute10_tbl,
2969                           l_attribute11_tbl,
2970                           l_attribute12_tbl,
2971                           l_attribute13_tbl,
2972                           l_attribute14_tbl,
2973                           l_attribute15_tbl,
2974                           l_pm_product_code_tbl,
2975                           l_pm_budget_line_reference_tbl,
2976                           l_raw_cost_source_tbl,
2977                           l_burdened_cost_source_tbl,
2978                           l_quantity_source_tbl,
2979                           l_revenue_source_tbl,
2980                           l_projfunc_currency_code_tbl,
2981                           l_project_currency_code_tbl,
2982                           l_txn_currency_code_tbl
2983                    from  pa_budget_lines l,
2984                          pa_resource_assignments sa,
2985                          pa_resource_assignments da,
2986                          pa_fp_bl_map_tmp bmt,            /* FPB2 */
2987                          PA_FP_CPY_PERIODS_TMP pptmp
2988                    where l.budget_version_id = x_src_version_id
2989                    and   l.resource_assignment_id = sa.resource_assignment_id
2990                    and   decode(x_time_phased_type_code,
2991                                 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P, pptmp.pa_period_name,
2992                                 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G, pptmp.gl_period_name) = l.period_name
2993                    and   sa.budget_version_id = x_src_version_id
2994                    and   sa.task_id = 0
2995                    and   sa.resource_list_member_id = da.resource_list_member_id
2996                    and   da.task_id = 0
2997                    and   da.budget_version_id = x_dest_version_id
2998                    and   l.budget_line_id = bmt.source_budget_line_id; /* FPB2 */
2999             end if;
3000 
3001           else -- non time phased
3002             if (x_entry_level_code <> 'P') then
3003                   select
3004                       bmt.target_budget_line_id,       /* FPB2 */
3005                       x_dest_version_id,               /* FPB2 */
3006                       da.resource_assignment_id,
3007                       (l.start_date + Nvl(x_shift_days, 0)),
3008                       SYSDATE,
3009                       x_created_by,
3010                       SYSDATE,
3011                       x_created_by,
3012                       x_last_update_login,
3013                       (l.end_date + Nvl(x_shift_days, 0)),
3014                       l.period_name, -- would be null
3015                       l.quantity,
3016                       round(l.raw_cost * amount_change_pct, rounding_precision),
3017                       round(l.burdened_cost * amount_change_pct, rounding_precision),
3018                       round(l.revenue * amount_change_pct, rounding_precision),
3019                       l.change_reason_code,
3020                       l.description,
3021                       l.attribute_category,
3022                       l.attribute1,
3023                       l.attribute2,
3024                       l.attribute3,
3025                       l.attribute4,
3026                       l.attribute5,
3027                       l.attribute6,
3028                       l.attribute7,
3029                       l.attribute8,
3030                       l.attribute9,
3031                       l.attribute10,
3032                       l.attribute11,
3033                       l.attribute12,
3034                       l.attribute13,
3035                       l.attribute14,
3036                       l.attribute15,
3037                       decode(x_pm_flag,'Y',l.pm_product_code,NULL),
3038                       decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
3039                       'B',
3040                       'B',
3041                       'B',
3042                       'B',
3043                       l.projfunc_currency_code,
3044                       l.project_currency_code,
3045                       l.txn_currency_code
3046                   bulk collect into
3047                       l_budget_line_id_tbl,
3048                       l_budget_version_id_tbl,
3049                       l_resource_assignment_id_tbl,
3050                       l_start_date_tbl,
3051                       l_last_update_date_tbl,
3052                       l_last_updated_by_tbl,
3053                       l_creation_date_tbl,
3054                       l_created_by_tbl,
3055                       l_last_update_login_tbl,
3056                       l_end_date_tbl,
3057                       l_period_name_tbl,
3058                       l_quantity_tbl,
3059                       l_raw_cost_tbl,
3060                       l_burdened_cost_tbl,
3061                       l_revenue_tbl,
3062                       l_change_reason_code_tbl,
3063                       l_description_tbl,
3064                       l_attribute_category_tbl,
3065                       l_attribute1_tbl,
3066                       l_attribute2_tbl,
3067                       l_attribute3_tbl,
3068                       l_attribute4_tbl,
3069                       l_attribute5_tbl,
3070                       l_attribute6_tbl,
3071                       l_attribute7_tbl,
3072                       l_attribute8_tbl,
3073                       l_attribute9_tbl,
3074                       l_attribute10_tbl,
3075                       l_attribute11_tbl,
3076                       l_attribute12_tbl,
3077                       l_attribute13_tbl,
3078                       l_attribute14_tbl,
3079                       l_attribute15_tbl,
3080                       l_pm_product_code_tbl,
3081                       l_pm_budget_line_reference_tbl,
3082                       l_raw_cost_source_tbl,
3083                       l_burdened_cost_source_tbl,
3084                       l_quantity_source_tbl,
3085                       l_revenue_source_tbl,
3086                       l_projfunc_currency_code_tbl,
3087                       l_project_currency_code_tbl,
3088                       l_txn_currency_code_tbl
3089                from   pa_budget_lines l,
3090                       pa_resource_assignments sa,
3091                       pa_tasks st,
3092                       pa_tasks dt,
3093                       pa_resource_assignments da,
3094                       pa_fp_bl_map_tmp bmt            /* FPB2 */
3095                where  l.budget_version_id = x_src_version_id
3096                and    l.resource_assignment_id = sa.resource_assignment_id
3097                and    sa.budget_version_id = x_src_version_id
3098                and    sa.task_id = st.task_id
3099                and    sa.project_id = st.project_id
3100                and    sa.resource_list_member_id = da.resource_list_member_id
3101                and    st.task_number = dt.task_number
3102                and    dt.task_id = da.task_id
3103                and    dt.project_id = da.project_id
3104                and    da.budget_version_id = x_dest_version_id
3105                and    l.budget_line_id = bmt.source_budget_line_id; /* FPB2 */
3106 
3107            else -- project level planning
3108 
3109                   select
3110                      bmt.target_budget_line_id,       /* FPB2 */
3111                      x_dest_version_id,               /* FPB2 */
3112                      da.resource_assignment_id,
3113                      (l.start_date + Nvl(x_shift_days, 0)),
3114                      SYSDATE,
3115                      x_created_by,
3116                      SYSDATE,
3117                      x_created_by,
3118                      x_last_update_login,
3119                      (l.end_date + Nvl(x_shift_days, 0)),
3120                      l.period_name, -- would be null
3121                      l.quantity,
3122                      round(l.raw_cost * amount_change_pct, rounding_precision),
3123                      round(l.burdened_cost * amount_change_pct, rounding_precision),
3124                      round(l.revenue * amount_change_pct, rounding_precision),
3125                      l.change_reason_code,
3126                      l.description,
3127                      l.attribute_category,
3128                      l.attribute1,
3129                      l.attribute2,
3130                      l.attribute3,
3131                      l.attribute4,
3132                      l.attribute5,
3133                      l.attribute6,
3134                      l.attribute7,
3135                      l.attribute8,
3136                      l.attribute9,
3137                      l.attribute10,
3138                      l.attribute11,
3139                      l.attribute12,
3140                      l.attribute13,
3141                      l.attribute14,
3142                      l.attribute15,
3143                      decode(x_pm_flag,'Y',l.pm_product_code,NULL),
3144                      decode(x_pm_flag,'Y',l.pm_budget_line_reference,NULL),
3145                      'B',
3146                      'B',
3147                      'B',
3148                      'B',
3149                      l.projfunc_currency_code,
3150                      l.project_currency_code,
3151                      l.txn_currency_code
3152                   bulk collect into
3153                       l_budget_line_id_tbl,
3154                       l_budget_version_id_tbl,
3155                       l_resource_assignment_id_tbl,
3156                       l_start_date_tbl,
3157                       l_last_update_date_tbl,
3158                       l_last_updated_by_tbl,
3159                       l_creation_date_tbl,
3160                       l_created_by_tbl,
3161                       l_last_update_login_tbl,
3162                       l_end_date_tbl,
3163                       l_period_name_tbl,
3164                       l_quantity_tbl,
3165                       l_raw_cost_tbl,
3166                       l_burdened_cost_tbl,
3167                       l_revenue_tbl,
3168                       l_change_reason_code_tbl,
3169                       l_description_tbl,
3170                       l_attribute_category_tbl,
3171                       l_attribute1_tbl,
3172                       l_attribute2_tbl,
3173                       l_attribute3_tbl,
3174                       l_attribute4_tbl,
3175                       l_attribute5_tbl,
3176                       l_attribute6_tbl,
3177                       l_attribute7_tbl,
3178                       l_attribute8_tbl,
3179                       l_attribute9_tbl,
3180                       l_attribute10_tbl,
3181                       l_attribute11_tbl,
3182                       l_attribute12_tbl,
3183                       l_attribute13_tbl,
3184                       l_attribute14_tbl,
3185                       l_attribute15_tbl,
3186                       l_pm_product_code_tbl,
3187                       l_pm_budget_line_reference_tbl,
3188                       l_raw_cost_source_tbl,
3189                       l_burdened_cost_source_tbl,
3190                       l_quantity_source_tbl,
3191                       l_revenue_source_tbl,
3192                       l_projfunc_currency_code_tbl,
3193                       l_project_currency_code_tbl,
3194                       l_txn_currency_code_tbl
3195                from  pa_budget_lines l,
3196                      pa_resource_assignments sa,
3197                      pa_resource_assignments da,
3198                      pa_fp_bl_map_tmp bmt            /* FPB2 */
3199                where l.budget_version_id = x_src_version_id
3200                and   l.resource_assignment_id = sa.resource_assignment_id
3201                and   sa.budget_version_id = x_src_version_id
3202                and   sa.task_id = 0
3203                and   sa.resource_list_member_id = da.resource_list_member_id
3204                and   da.task_id = 0
3205                and   da.budget_version_id = x_dest_version_id
3206                and   l.budget_line_id = bmt.source_budget_line_id; /* FPB2 */
3207 
3208             end if; -- project level
3209           end if; -- time phase R, N
3210       end if; -- shift date 0
3211 
3212       -- inserting bulk into pa_budget_lines bug 4772773
3213       FORALL i IN l_budget_line_id_tbl.FIRST .. l_budget_line_id_tbl.LAST
3214 
3215         INSERT INTO pa_budget_lines
3216              (budget_line_id,           /* FPB2 */
3217               budget_version_id,        /* FPB2 */
3218               resource_assignment_id,
3219               start_date,
3220               last_update_date,
3221               last_updated_by,
3222               creation_date,
3223               created_by,
3224               last_update_login,
3225               end_date,
3226               period_name,
3227               quantity,
3228               raw_cost,
3229               burdened_cost,
3230               revenue,
3231               change_reason_code,
3232               description,
3233               attribute_category,
3234               attribute1,
3235               attribute2,
3236               attribute3,
3237               attribute4,
3238               attribute5,
3239               attribute6,
3240               attribute7,
3241               attribute8,
3242               attribute9,
3243               attribute10,
3244               attribute11,
3245               attribute12,
3246               attribute13,
3247               attribute14,
3248               attribute15,
3249               pm_product_code,
3250               pm_budget_line_reference,
3251               raw_cost_source,
3252               burdened_cost_source,
3253               quantity_source,
3254               revenue_source,
3255               projfunc_currency_code,
3256               project_currency_code,
3257               txn_currency_code
3258               )
3259         VALUES
3260              (l_budget_line_id_tbl(i),
3261               l_budget_version_id_tbl(i),
3262               l_resource_assignment_id_tbl(i),
3263               l_start_date_tbl(i),
3264               l_last_update_date_tbl(i),
3265               l_last_updated_by_tbl(i),
3266               l_creation_date_tbl(i),
3267               l_created_by_tbl(i),
3268               l_last_update_login_tbl(i),
3269               l_end_date_tbl(i),
3270               l_period_name_tbl(i),
3271               l_quantity_tbl(i),
3272               l_raw_cost_tbl(i),
3273               l_burdened_cost_tbl(i),
3274               l_revenue_tbl(i),
3275               l_change_reason_code_tbl(i),
3276               l_description_tbl(i),
3277               l_attribute_category_tbl(i),
3278               l_attribute1_tbl(i),
3279               l_attribute2_tbl(i),
3280               l_attribute3_tbl(i),
3281               l_attribute4_tbl(i),
3282               l_attribute5_tbl(i),
3283               l_attribute6_tbl(i),
3284               l_attribute7_tbl(i),
3285               l_attribute8_tbl(i),
3286               l_attribute9_tbl(i),
3287               l_attribute10_tbl(i),
3288               l_attribute11_tbl(i),
3289               l_attribute12_tbl(i),
3290               l_attribute13_tbl(i),
3291               l_attribute14_tbl(i),
3292               l_attribute15_tbl(i),
3293               l_pm_product_code_tbl(i),
3294               l_pm_budget_line_reference_tbl(i),
3295               l_raw_cost_source_tbl(i),
3296               l_burdened_cost_source_tbl(i),
3297               l_quantity_source_tbl(i),
3298               l_revenue_source_tbl(i),
3299               l_projfunc_currency_code_tbl(i),
3300               l_project_currency_code_tbl(i),
3301               l_txn_currency_code_tbl(i));
3302 
3303 
3304               l_budget_line_id_tbl.DELETE;
3305               l_budget_version_id_tbl.DELETE;
3306               l_resource_assignment_id_tbl.DELETE;
3307               l_start_date_tbl.DELETE;
3308               l_last_update_date_tbl.DELETE;
3309               l_last_updated_by_tbl.DELETE;
3310               l_creation_date_tbl.DELETE;
3311               l_created_by_tbl.DELETE;
3312               l_last_update_login_tbl.DELETE;
3313               l_end_date_tbl.DELETE;
3314               l_period_name_tbl.DELETE;
3315               l_quantity_tbl.DELETE;
3316               l_raw_cost_tbl.DELETE;
3317               l_burdened_cost_tbl.DELETE;
3318               l_revenue_tbl.DELETE;
3319               l_change_reason_code_tbl.DELETE;
3320               l_description_tbl.DELETE;
3321               l_attribute_category_tbl.DELETE;
3322               l_attribute1_tbl.DELETE;
3323               l_attribute2_tbl.DELETE;
3324               l_attribute3_tbl.DELETE;
3325               l_attribute4_tbl.DELETE;
3326               l_attribute5_tbl.DELETE;
3327               l_attribute6_tbl.DELETE;
3328               l_attribute7_tbl.DELETE;
3329               l_attribute8_tbl.DELETE;
3330               l_attribute9_tbl.DELETE;
3331               l_attribute10_tbl.DELETE;
3332               l_attribute11_tbl.DELETE;
3333               l_attribute12_tbl.DELETE;
3334               l_attribute13_tbl.DELETE;
3335               l_attribute14_tbl.DELETE;
3336               l_attribute15_tbl.DELETE;
3337               l_pm_product_code_tbl.DELETE;
3338               l_pm_budget_line_reference_tbl.DELETE;
3339               l_raw_cost_source_tbl.DELETE;
3340               l_burdened_cost_source_tbl.DELETE;
3341               l_quantity_source_tbl.DELETE;
3342               l_revenue_source_tbl.DELETE;
3343               l_projfunc_currency_code_tbl.DELETE;
3344               l_project_currency_code_tbl.DELETE;
3345               l_txn_currency_code_tbl.DELETE;
3346         -- bug 4772773: ends
3347 
3348          -- Bug Fix: 4569365. Removed MRC code.
3349          /* FPB2 */
3350          /*
3351          BEGIN
3352 
3353             IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS IS NULL THEN
3354                  PA_MRC_FINPLAN.CHECK_MRC_INSTALL
3355                                    (x_return_status      => x_return_status,
3356                                     x_msg_count          => x_msg_count,
3357                                     x_msg_data           => x_msg_data);
3358             END IF;
3359                -- Bug 2676494
3360 
3361             IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS THEN
3362                IF PA_MRC_FINPLAN.G_FINPLAN_MRC_OPTION_CODE = 'A' THEN
3363                   PA_MRC_FINPLAN.COPY_MC_BUDGET_LINES
3364                                    (p_source_fin_plan_version_id => x_src_version_id,
3365                                     p_target_fin_plan_version_id => x_dest_version_id,
3366                                     x_return_status              => x_return_status,
3367                                     x_msg_count                  => x_msg_count,
3368                                     x_msg_data                   => x_msg_data);
3369                ELSIF  (PA_MRC_FINPLAN.G_FINPLAN_MRC_OPTION_CODE = 'B' AND l_version_is_baselined = 'Y') THEN
3370                     PA_MRC_FINPLAN.MAINTAIN_ALL_MC_BUDGET_LINES
3371                                (p_fin_plan_version_id => x_dest_version_id, -- Target version should be passed
3372                                 p_entire_version      => 'Y',
3373                                 x_return_status       => x_return_status,
3374                                 x_msg_count           => x_msg_count,
3375                                 x_msg_data            => x_msg_data);
3376                -- Bug 2676494
3377               END IF;
3378 
3379          END IF;
3380 
3381             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3382               RAISE g_mrc_exception;
3383             END IF;
3384 
3385          END;
3386          */
3387 
3388 
3389   exception
3390       when others then
3391          x_err_code := SQLCODE;
3392          return;
3393   end copy_lines;
3394 
3395 
3396 END pa_budget_core;