DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_BUDGET_CORE

Source


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