DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_BUDGET_PVT

Source


1 package body PA_BUDGET_PVT as
2 --$Header: PAPMBUVB.pls 120.32.12010000.5 2008/12/05 12:10:43 vbkumar ship $
3 --package constants to be used in error messages
4 G_PKG_NAME          CONSTANT VARCHAR2(30)   := 'PA_BUDGET_PVT';
5 
6 --package constants to be used during updates
7 G_USER_ID         CONSTANT NUMBER := FND_GLOBAL.user_id;
8 G_LOGIN_ID        CONSTANT NUMBER := FND_GLOBAL.login_id;
9 
10 -- Bug Fix: 4569365. Removed MRC code.
11 -- g_mrc_exception         EXCEPTION; /* FPB2 */
12 
13 g_module_name   VARCHAR2(100) := 'pa.plsql.PA_BUDGET_PVT';
14 
15 -- Cursor to get the budget amount code of the budget type passed
16 CURSOR  l_budget_amount_code_csr
17        (c_budget_type_code    VARCHAR2 )
18 IS
19 SELECT  budget_amount_code
20 FROM    pa_budget_types
21 WHERE   budget_type_code = c_budget_type_code;
22 
23 -- Cursor to validate the change reason code
24 CURSOR l_budget_change_reason_csr ( c_change_reason_code VARCHAR2 )
25 IS
26 SELECT 'x'
27 FROM   pa_lookups
28 WHERE  lookup_type = 'BUDGET CHANGE REASON'
29 AND    lookup_code = c_change_reason_code;
30 
31 --Bug 2871603: Added the following PLSQL table to remove build dependency.
32 TYPE l_txn_currency_code_tbl_typ IS TABLE OF
33                 pa_budget_lines.TXN_CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER ;
34 
35 --This record type will contain key and a value. A pl/sql tbl of this record type can be declared and it can be
36 --used for different purposes. One such case is : if its required to get the wbs level for a task id at many
37 --places in the code then instead of firing a select each time we can fetch it and store in this record. The key
38 --will be the task id and the value will be top task id.
39 --Created for bug 3678314
40 TYPE key_value_rec IS RECORD
41 (key                          NUMBER
42 ,value                        VARCHAR2(30));
43 
44 TYPE key_value_rec_tbl_type IS TABLE OF key_value_rec
45       INDEX BY BINARY_INTEGER;
46 
47 -- This procedure accepts the rate types at the plan version level and plan type level
48 -- FALSE is returned if the rate type at plan type is not User and the rate type at
49 -- plan version is user.TRUE is returned otherwise
50 -- Created        19-FEB-03          sgoteti
51 --
52 PROCEDURE valid_rate_type
53 ( p_pt_project_cost_rate_type   IN      pa_proj_fp_options.project_cost_rate_type%TYPE
54  ,p_pt_project_rev_rate_type    IN      pa_proj_fp_options.project_rev_rate_type%TYPE
55  ,p_pt_projfunc_cost_rate_type  IN      pa_proj_fp_options.projfunc_cost_rate_type%TYPE
56  ,p_pt_projfunc_rev_rate_type   IN      pa_proj_fp_options.projfunc_rev_rate_type%TYPE
57  ,p_pv_project_cost_rate_type   IN      pa_proj_fp_options.project_cost_rate_type%TYPE
58  ,p_pv_project_rev_rate_type    IN      pa_proj_fp_options.project_rev_rate_type%TYPE
59  ,p_pv_projfunc_cost_rate_type  IN      pa_proj_fp_options.projfunc_cost_rate_type%TYPE
60  ,p_pv_projfunc_rev_rate_type   IN      pa_proj_fp_options.projfunc_rev_rate_type%TYPE
61  ,x_is_rate_type_valid          OUT     NOCOPY BOOLEAN --File.Sql.39 bug 4440895
62  ,x_return_status               OUT     NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
63  ,x_msg_count                   OUT     NOCOPY NUMBER --File.Sql.39 bug 4440895
64  ,x_msg_data                    OUT     NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
65 )
66 IS
67 
68       l_debug_mode                     VARCHAR2(1);
69       l_module_name                    VARCHAR2(80);
70       l_debug_level3          CONSTANT NUMBER := 3;
71 BEGIN
72 
73       x_msg_count :=0;
74       x_return_status := FND_API.G_RET_STS_SUCCESS;
75       l_debug_mode  := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
76       l_module_name := 'valid_rate_type: ' || g_module_name;
77 
78       IF l_debug_mode = 'Y' THEN
79         pa_debug.set_curr_function( p_function   => 'valid_rate_type',
80                                     p_debug_mode => l_debug_mode );
81       END IF;
82 
83       x_is_rate_type_valid := TRUE;
84 
85       IF (nvl(p_pv_project_cost_rate_type,'-99') = PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER AND
86           nvl(p_pt_project_cost_rate_type,'-99') <> PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER ) THEN
87 
88             x_is_rate_type_valid := FALSE;
89 
90       END IF;
91 
92       IF (nvl(p_pv_project_rev_rate_type,'-99') = PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER AND
93           nvl(p_pt_project_rev_rate_type,'-99') <> PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER ) THEN
94 
95             x_is_rate_type_valid := FALSE;
96 
97       END IF;
98 
99       IF (nvl(p_pv_projfunc_cost_rate_type,'-99') = PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER AND
100           nvl(p_pt_projfunc_cost_rate_type,'-99') <> PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER ) THEN
101 
102             x_is_rate_type_valid := FALSE;
103 
104       END IF;
105 
106       IF (nvl(p_pv_projfunc_rev_rate_type,'-99') = PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER AND
107           nvl(p_pt_projfunc_rev_rate_type,'-99') <> PA_FP_CONSTANTS_PKG.G_RATE_TYPE_USER ) THEN
108 
109             x_is_rate_type_valid := FALSE;
110 
111       END IF;
112 
113       IF(l_debug_mode='Y') THEN
114 
115             pa_debug.g_err_stage := 'Leaving valid_rate_type';
116             pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
117             pa_debug.reset_curr_function;
118       END IF;
119 EXCEPTION
120 
121       WHEN OTHERS THEN
122             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
123             x_msg_count     := 1;
124             x_msg_data      := SQLERRM;
125 
126             FND_MSG_PUB.add_exc_msg
127             ( p_pkg_name       => 'PA_BUDGET_PUB'
128             ,p_procedure_name  => 'VALID_RATE_TYPE'
129             ,p_error_text      => sqlerrm);
130 
131             IF l_debug_mode = 'Y' THEN
132                   pa_debug.G_Err_Stack := SQLERRM;
133                   pa_debug.write( l_module_name,pa_debug.G_Err_Stack,4);
134                   pa_debug.reset_curr_function;
135  	    END IF;
136             RAISE;
137 
138 
139 END valid_rate_type;
140 
141 
142 
143 -- This API is created as part of FinPlan Development. All header level validations are moved
144 -- from create_draft_budget API to this API. This API handles validations of versions in new
145 -- as well as old models.
146 
147 -- Created        19-FEB-03          sgoteti
148 
149 PROCEDURE Validate_Header_Info
150 ( p_api_version_number            IN        NUMBER
151  ,p_budget_version_name           IN        VARCHAR2       /* Introduced for bug 3133930*/
152  ,p_init_msg_list                 IN        VARCHAR2
153  ,px_pa_project_id                IN  OUT   NOCOPY pa_projects_all.project_id%TYPE --File.Sql.39 bug 4440895
154  ,p_pm_project_reference          IN        pa_projects_all.pm_project_reference%TYPE
155  ,p_pm_product_code               IN        pa_projects_all.pm_product_code%TYPE
156  ,p_budget_type_code              IN        pa_budget_types.budget_type_code%TYPE
157  ,p_entry_method_code             IN        pa_budget_entry_methods.budget_entry_method_code%TYPE
158  ,px_resource_list_name           IN  OUT   NOCOPY pa_resource_lists_tl.name%TYPE --File.Sql.39 bug 4440895
159  ,px_resource_list_id             IN  OUT   NOCOPY pa_resource_lists_all_bg.resource_list_id%TYPE --File.Sql.39 bug 4440895
160  ,px_fin_plan_type_id             IN  OUT   NOCOPY pa_fin_plan_types_b.fin_plan_type_id%TYPE --File.Sql.39 bug 4440895
161  ,px_fin_plan_type_name           IN  OUT   NOCOPY pa_fin_plan_types_tl.name%TYPE --File.Sql.39 bug 4440895
162  ,px_version_type                 IN  OUT   NOCOPY pa_budget_versions.version_type%TYPE --File.Sql.39 bug 4440895
163  ,px_fin_plan_level_code          IN  OUT   NOCOPY pa_proj_fp_options.cost_fin_plan_level_code%TYPE --File.Sql.39 bug 4440895
164  ,px_time_phased_code             IN  OUT   NOCOPY pa_proj_fp_options.cost_time_phased_code%TYPE --File.Sql.39 bug 4440895
165  ,px_plan_in_multi_curr_flag      IN  OUT   NOCOPY pa_proj_fp_options.plan_in_multi_curr_flag%TYPE --File.Sql.39 bug 4440895
166  ,px_projfunc_cost_rate_type      IN  OUT   NOCOPY pa_proj_fp_options.projfunc_cost_rate_type%TYPE --File.Sql.39 bug 4440895
167  ,px_projfunc_cost_rate_date_typ  IN  OUT   NOCOPY pa_proj_fp_options.projfunc_cost_rate_date_type%TYPE --File.Sql.39 bug 4440895
168  ,px_projfunc_cost_rate_date      IN  OUT   NOCOPY pa_proj_fp_options.projfunc_cost_rate_date%TYPE --File.Sql.39 bug 4440895
169  ,px_projfunc_rev_rate_type       IN  OUT   NOCOPY pa_proj_fp_options.projfunc_rev_rate_type%TYPE --File.Sql.39 bug 4440895
170  ,px_projfunc_rev_rate_date_typ   IN  OUT   NOCOPY pa_proj_fp_options.projfunc_rev_rate_date_type%TYPE --File.Sql.39 bug 4440895
171  ,px_projfunc_rev_rate_date       IN  OUT   NOCOPY pa_proj_fp_options.projfunc_rev_rate_date%TYPE --File.Sql.39 bug 4440895
172  ,px_project_cost_rate_type       IN  OUT   NOCOPY pa_proj_fp_options.project_cost_rate_type%TYPE --File.Sql.39 bug 4440895
173  ,px_project_cost_rate_date_typ   IN  OUT   NOCOPY pa_proj_fp_options.project_cost_rate_date_type%TYPE --File.Sql.39 bug 4440895
174  ,px_project_cost_rate_date       IN  OUT   NOCOPY pa_proj_fp_options.project_cost_rate_date%TYPE --File.Sql.39 bug 4440895
175  ,px_project_rev_rate_type        IN  OUT   NOCOPY pa_proj_fp_options.project_rev_rate_type%TYPE --File.Sql.39 bug 4440895
176  ,px_project_rev_rate_date_typ    IN  OUT   NOCOPY pa_proj_fp_options.project_rev_rate_date_type%TYPE --File.Sql.39 bug 4440895
177  ,px_project_rev_rate_date        IN  OUT   NOCOPY pa_proj_fp_options.project_rev_rate_date%TYPE --File.Sql.39 bug 4440895
178  ,px_raw_cost_flag                IN  OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
179  ,px_burdened_cost_flag           IN  OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
180  ,px_revenue_flag                 IN  OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
181  ,px_cost_qty_flag                IN  OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
182  ,px_revenue_qty_flag             IN  OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
183  ,px_all_qty_flag                 IN  OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
184  ,p_create_new_curr_working_flag  IN        VARCHAR2
185  ,p_replace_current_working_flag  IN        VARCHAR2
186  ,p_change_reason_code            IN        pa_budget_versions.change_reason_code%TYPE
187  ,p_calling_module                IN        VARCHAR2
188  ,p_using_resource_lists_flag     IN        VARCHAR2
189  ,x_budget_amount_code            OUT       NOCOPY pa_budget_types.budget_amount_code%TYPE --Added for bug 4224464. --File.Sql.39 bug 4440895
190  ,x_msg_count                     OUT       NOCOPY NUMBER --File.Sql.39 bug 4440895
191  ,x_msg_data                      OUT       NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
192  ,x_return_status                 OUT       NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
193 ) IS
194 
195       -- Cursor to get the cost and revenue budget entry flags from the project type
196       CURSOR  l_cost_rev_budget_entry_csr
197             (c_project_id pa_projects.project_id%type)
198       IS
199       SELECT ppt.allow_cost_budget_entry_flag
200             ,ppt.allow_rev_budget_entry_flag
201       FROM   pa_project_types ppt
202             ,pa_projects_all ppa
203       WHERE  ppa.project_id = c_project_id
204       AND    ppa.project_type = ppt.project_type;
205 
206       -- Cursor to get the details of the budget entry method passed
207       CURSOR  l_budget_entry_method_csr
208              (c_budget_entry_method_code pa_budget_entry_methods.budget_entry_method_code%type )
209       IS
210       SELECT *
211       FROM   pa_budget_entry_methods
212       WHERE  budget_entry_method_code = c_budget_entry_method_code
213       AND    trunc(sysdate) BETWEEN trunc(start_date_active) and trunc(nvl(end_date_active,sysdate));
214 
215       l_budget_entry_method_rec        pa_budget_entry_methods%rowtype;
216 
217 
218       l_budget_amount_code             pa_budget_types.budget_amount_code%TYPE;
219 
220       -- Cursor to get the plan type details of the version being created. Created as part
221       -- of changes due to fin plan in AMG
222       CURSOR  l_proj_fp_options_csr
223             ( c_project_id       pa_projects.project_id%TYPE
224              ,c_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE)
225       IS
226       SELECT fin_plan_preference_code
227             ,nvl(plan_in_multi_curr_flag,'N') plan_in_multi_curr_flag
228             ,approved_rev_plan_type_flag
229             ,projfunc_cost_rate_type
230             ,projfunc_cost_rate_date_type
231             ,projfunc_cost_rate_date
232             ,projfunc_rev_rate_type
233             ,projfunc_rev_rate_date_type
234             ,projfunc_rev_rate_date
235             ,project_cost_rate_type
236             ,project_cost_rate_date_type
237             ,project_cost_rate_date
238             ,project_rev_rate_type
239             ,project_rev_rate_date_type
240             ,project_rev_rate_date
241       FROM   pa_proj_fp_options
242       WHERE  project_id=c_project_id
243       AND    fin_plan_type_id=c_fin_plan_type_id
244       AND    fin_plan_version_id IS NULL
245       AND    fin_plan_option_level_code= PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_TYPE;
246 
247       l_proj_fp_options_rec           l_proj_fp_options_csr%ROWTYPE;
248 
249       -- Cursot to get the segment 1 of the project. Added baseline funding flag as part
250       -- changes due to finplan in AMG
251       CURSOR l_amg_project_csr
252             (c_project_id pa_projects_all.project_id%TYPE)
253       IS
254       SELECT segment1
255             ,baseline_funding_flag
256       FROM   pa_projects_all
257       WHERE  project_id=c_project_id;
258 
259       l_amg_project_rec               l_amg_project_csr%ROWTYPE;
260 
261       -- Cursor to get the planning level ,resource list and time phasing from the plan type
262       -- Added as part of changes due to finplan in AMG
263       CURSOR l_plan_type_settings_csr
264             ( c_project_id pa_projects.project_id%TYPE
265              ,c_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE
266              ,c_version_type VARCHAR2)
267 
268       IS
269       SELECT decode(c_version_type,
270                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST, cost_fin_plan_level_code,
271                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE, revenue_fin_plan_level_code,
272                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL, all_fin_plan_level_code) fin_plan_level_code
273             ,decode(c_version_type,
274                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST, cost_resource_list_id,
275                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE, revenue_resource_list_id,
276                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL, all_resource_list_id)  resource_list_id
277             ,decode(c_version_type,
278                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST, cost_time_phased_code,
279                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE, revenue_time_phased_code,
280                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL, all_time_phased_code)  time_phased_code
281       FROM   pa_proj_fp_options
282       WHERE  project_id=c_project_id
283       AND    fin_plan_type_id=c_fin_plan_type_id
284       AND    fin_plan_version_id IS NULL
285       AND    fin_plan_option_level_code= PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_TYPE;
286 
287       l_plan_type_settings_rec        l_plan_type_settings_csr%ROWTYPE;
288 
289 
290 
291  -- Cursor to get the existing version details of the budget type code passed
292 
293       CURSOR l_budget_version_csr
294             ( c_project_id NUMBER
295              ,c_budget_type_code VARCHAR2  )
296       IS
297       SELECT budget_version_id
298             ,budget_status_code
299       FROM   pa_budget_versions
300       WHERE  project_id = c_project_id
301       AND    budget_type_code = c_budget_type_code
302       AND    budget_status_code IN ('W','S')
303       AND    ci_id IS NULL;         -- Bug # 3507156 --Added an extra clause ci_id IS NULL
304 
305       -- Cursor to get the details of the current working version in finplan model. Added
306       -- as part of changes due to finplan in AMG
307       CURSOR l_finplan_CW_ver_csr
308            ( c_project_id NUMBER
309             ,c_fin_plan_type_id VARCHAR2
310             ,c_version_type VARCHAR2)
311       IS
312       SELECT budget_version_id
313             ,budget_status_code
314             ,record_version_number
315             ,plan_processing_code
316       FROM   pa_budget_versions
317       WHERE  project_id = c_project_id
318       AND    fin_plan_type_id = c_fin_plan_type_id
319       AND    current_working_flag='Y'
320       AND    version_type = c_version_type
321       AND    budget_status_code IN ('W','S')
322       AND    ci_id IS NULL;         -- Bug # 3507156 --Added an extra clause ci_id IS NULL
323 
324 
325       l_finplan_CW_ver_rec       l_finplan_CW_ver_csr%ROWTYPE;
326 
327       -- Cursor to know whether a version exists for plan type created by upgrading the budget type
328       -- which is given as input. Crated as part of changes due to finplan in AMG
329       CURSOR  is_budget_type_upgraded_csr
330             ( c_budget_type_code pa_budget_types.budget_type_code%TYPE
331              ,c_project_id       pa_projects_all.project_id%TYPE)
332       IS
333       SELECT  'X'
334       FROM    pa_fin_plan_types_b fin ,pa_proj_fp_options pfo
335       WHERE   pfo.project_id=c_project_id
336       AND     pfo.fin_plan_option_level_code=PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_TYPE   --AMG UT2
337       AND     pfo.fin_plan_type_id = fin.fin_plan_type_id
338       AND     fin.migrated_frm_bdgt_typ_code =  c_budget_type_code;
339 
340       l_budget_type_upgraded_rec       is_budget_type_upgraded_csr%ROWTYPE;
341 
342       -- Cursor to lock the version
343       CURSOR l_lock_old_budget_csr( c_budget_version_id NUMBER )
344       IS
345       SELECT 'x'
346       FROM   pa_budget_versions bv
347             ,pa_resource_assignments ra
348             ,pa_budget_lines bl
349       WHERE  bv.budget_version_id = c_budget_version_id
350       AND    bv.budget_version_id = ra.budget_version_id (+)
351       AND    ra.resource_assignment_id = bl.resource_assignment_id (+)
352       AND    bv.ci_id IS NULL          -- Bug # 3507156 --Added an extra clause ci_id IS NULL
353 
354       FOR UPDATE OF bv.budget_version_id,ra.budget_version_id,bl.resource_assignment_id NOWAIT;
355 
356       -- Cursor used in validating the product code
357       Cursor p_product_code_csr (c_pm_product_code IN VARCHAR2)
358       Is
359       Select 'X'
360       from   pa_lookups
361       where  lookup_type='PM_PRODUCT_CODE'
362       and    lookup_code = c_pm_product_code;
363 
364 
365       l_msg_count                      NUMBER := 0;
366       l_data                           VARCHAR2(2000);
367       l_msg_data                       VARCHAR2(2000);
368       l_msg_index_out                  NUMBER;
369       l_debug_mode                     VARCHAR2(1);
370       l_function_allowed               VARCHAR2(1);
371       l_resp_id                        NUMBER := 0;
372       l_user_id                        NUMBER := 0;
373       l_module_name                    VARCHAR2(80);
374 
375      -- <Patchset M:B and F impact changes : AMG:> -- Bug # 3507156
376      -- Added the variable l_editable_flag for call to procedure pa_fin_plan_utils.Check_if_plan_type_editable
377 
378       l_editable_flag                  VARCHAR2(1);
379 
380       l_copy_conv_attr                 boolean;
381       l_conv_attrs_to_be_validated     VARCHAR2(10);
382       l_old_budget_version_id          pa_budget_versions.budget_version_id%TYPE;
383       l_budget_status_code             pa_budget_versions.budget_status_code%TYPE;
384       l_approved_fin_plan_type_id      pa_fin_plan_types_b.fin_plan_type_id%TYPE;
385 
386       l_allow_cost_budget_entry_flag   pa_project_types_all.allow_cost_budget_entry_flag%TYPE;
387       l_allow_rev_budget_entry_flag    pa_project_types_all.allow_rev_budget_entry_flag%TYPE;
388 
389       -- Budget Integration Variables --------------------------
390       l_fck_req_flag                   VARCHAR2(1) := NULL;
391       l_bdgt_intg_flag                 VARCHAR2(1) := NULL;
392       l_bdgt_ver_id                    NUMBER := NULL;
393       l_encum_type_id                  NUMBER := NULL;
394       l_balance_type                   VARCHAR2(1) := NULL;
395 
396       -- --------------------------------------------------------
397       l_uncategorized_list_id          pa_resource_lists_all_bg.resource_list_id%TYPE;
398       l_uncategorized_resid            pa_resource_list_members.resource_id%TYPE;
399       l_err_code                       NUMBER;
400       l_err_stage                      VARCHAR2(120);
401       l_err_stack                      VARCHAR2(630);
402       l_track_as_labor_flag            pa_resource_list_members.track_as_labor_flag%TYPE;
403       l_period_type                    VARCHAR2(2);
404       l_period_profile_id              pa_proj_period_profiles.period_profile_id%TYPE;
405       l_start_period                   pa_proj_period_profiles.period_name1%TYPE;
406       l_end_period                     pa_proj_period_profiles.profile_end_period_name%TYPE;
407       l_security_ret_code              VARCHAR2(1);
408       l_dummy                          VARCHAR2(1);
409       l_debug_level2                   CONSTANT NUMBER := 2;
410       l_debug_level3                   CONSTANT NUMBER := 3;
411       l_debug_level4                   CONSTANT NUMBER := 4;
412       l_debug_level5                   CONSTANT NUMBER := 5;
413       l_pm_product_code                VARCHAR2(2) :='Z';
414 
415       -- Following variable will be set when atleast one error
416       -- is reported while validating the input parameters
417       -- passed by the user
418       l_any_error_occurred_flag        VARCHAR2(1) :='N';
419 
420       l_multi_currency_billing_flag    pa_projects_all.multi_currency_billing_flag%TYPE;
421       l_project_currency_code          pa_projects_all.project_currency_code%TYPE      ;
422       l_projfunc_currency_code         pa_projects_all.projfunc_currency_code%TYPE     ;
423       l_project_cost_rate_type         pa_projects_all.project_rate_type%TYPE          ;
424       l_projfunc_cost_rate_type        pa_projects_all.projfunc_cost_rate_type%TYPE    ;
425       l_project_bil_rate_type          pa_projects_all.project_bil_rate_type%TYPE      ;
426       l_projfunc_bil_rate_type         pa_projects_all.projfunc_bil_rate_type%TYPE     ;
427       l_uncategorized_rlmid            pa_resource_list_members.resource_list_member_id%TYPE;
428       l_is_rate_type_valid             BOOLEAN;
429       l_planning_level_lookup          CONSTANT VARCHAR2(30) := 'BUDGET ENTRY LEVEL';
430       l_time_phasing_lookup            CONSTANT VARCHAR2(30) := 'BUDGET TIME PHASED TYPE';
431       l_validate_mc_attributes         VARCHAR2(1);
432       l_project_cost_exchange_rate     pa_budget_lines.project_cost_exchange_rate%TYPE;
433       l_projfunc_cost_exchange_rate    pa_budget_lines.projfunc_cost_exchange_rate%TYPE;
434       l_project_rev_exchange_rate      pa_budget_lines.project_rev_exchange_rate%TYPE;
435       l_projfunc_rev_exchange_rate     pa_budget_lines.projfunc_rev_exchange_rate%TYPE;
436       l_fin_plan_type_name             pa_fin_plan_types_tl.name%TYPE;
437       l_context_info                   pa_fin_plan_types_tl.name%TYPE;
438 
439       l_called_from_agr_pub            VARCHAR2(1) := NULL;  -- Bug 3099706
440 
441       --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
442       --Added extra parameters
443       l_autobaseline_flag              VARCHAR2(1) := NULL;
444       l_workplan_flag                  VARCHAR2(1) := NULL;
445       l_exists                         VARCHAR2(1) := NULL;
446 
447       -- for bug 3954329
448       l_res_list_migration_code        pa_resource_list_members.migration_code%TYPE  := FND_API.G_MISS_CHAR;
449       l_targ_request_id                pa_budget_versions.request_id%TYPE;
450       px_pa_project_id_in              pa_projects_all.project_id%TYPE;
451       px_resource_list_id_in           pa_resource_lists_all_bg.resource_list_id%TYPE;
452       px_fin_plan_type_id_in           pa_fin_plan_types_b.fin_plan_type_id%TYPE;
453 
454 BEGIN
455 
456       --dbms_output.put_line('In validate header info');
457       x_msg_count :=0;
458       x_return_status := FND_API.G_RET_STS_SUCCESS;
459       l_debug_mode  := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
460       l_module_name := 'validate_header_info: ' || g_module_name;
461 
462 	  IF l_debug_mode = 'Y' THEN
463         	pa_debug.set_curr_function( p_function   => 'validate_header_info',
464                                     p_debug_mode => l_debug_mode );
465                 pa_debug.g_err_stage:= 'Validating input parameters';
466                 pa_debug.write(l_module_name,pa_debug.g_err_stage,
467                                                 l_debug_level3);
468           END IF;
469       --dbms_output.put_line('About to validate budget type code and fin plan type id');
470 
471       -- Initialize the message table if requested.Moved this above as the messages will be added from
472       -- this point.
473       IF FND_API.TO_BOOLEAN( p_init_msg_list )
474       THEN
475 
476         FND_MSG_PUB.initialize;
477 
478       END IF;
479 
480 
481 
482       -- Both Budget Type Code and Fin Plan Type Id should not be null
483       IF ((p_budget_type_code IS NULL  OR
484            p_budget_type_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR )  AND
485           (px_fin_plan_type_name IS NULL) AND
486           (px_fin_plan_type_id IS NULL) )THEN
487 
488             PA_UTILS.ADD_MESSAGE
489                   (p_app_short_name => 'PA',
490                   p_msg_name        => 'PA_BUDGET_FP_BOTH_MISSING');
491 
492             IF l_debug_mode = 'Y' THEN
493                   pa_debug.g_err_stage:= 'Fin Plan type info and budget type info are missing';
494                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
495             END IF;
496 
497             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
498 
499       END IF;
500 
501       -- Both Budget Type Code and Fin Plan Type Id should not be not null
502 
503       IF ((p_budget_type_code IS NOT NULL AND
504           p_budget_type_code <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR)  AND
505         ((px_fin_plan_type_name IS NOT NULL) OR
506          (px_fin_plan_type_id IS NOT NULL))) THEN
507 
508             PA_UTILS.ADD_MESSAGE
509                   (p_app_short_name => 'PA',
510                   p_msg_name        => 'PA_BUDGET_FP_BOTH_NOT_NULL');
511 
512             IF l_debug_mode = 'Y' THEN
513                   pa_debug.g_err_stage:= 'Fin Plan type info and budget type info both are provided';
514                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
515             END IF;
516 
517             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
518 
519       END IF;
520 
521        --dbms_output.put_line('After validating budget and finplan ids');
522 
523       --product_code is mandatory
524       IF p_pm_product_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
525          OR p_pm_product_code IS NULL
526       THEN
527               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
528               THEN
529                     pa_interface_utils_pub.map_new_amg_msg
530                     ( p_old_message_code => 'PA_PRODUCT_CODE_IS_MISSING'
531                      ,p_msg_attribute    => 'CHANGE'
532                      ,p_resize_flag      => 'N'
533                      ,p_msg_context      => 'GENERAL'
534                      ,p_attribute1       => ''
535                      ,p_attribute2       => ''
536                      ,p_attribute3       => ''
537                      ,p_attribute4       => ''
538                      ,p_attribute5       => '');
539                       --dbms_output.put_line('MSG count in the stack ' || FND_MSG_PUB.count_msg);
540                       --dbms_output.put_line('added msg to stack');
541                       --dbms_output.put_line('MSG count in the stack 2 ' || FND_MSG_PUB.count_msg);
542                     IF l_debug_mode = 'Y' THEN
543                           pa_debug.g_err_stage:= 'PM Product code is missing';
544                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
545                     END IF;
546 
547               END IF;
548               x_return_status := FND_API.G_RET_STS_ERROR;
549               l_any_error_occurred_flag := 'Y';
550 
551 
552                --dbms_output.put_line('pm product code is null or miss');
553 
554 
555               -- RAISE FND_API.G_EXC_ERROR;
556       ELSE
557 
558             -- added for bug no :2413400
559             OPEN p_product_code_csr (p_pm_product_code);
560             FETCH p_product_code_csr INTO l_pm_product_code;
561             CLOSE p_product_code_csr;
562             IF l_pm_product_code <> 'X'
563             THEN
564                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
565                   THEN
566                       pa_interface_utils_pub.map_new_amg_msg
567                       ( p_old_message_code => 'PA_PRODUCT_CODE_IS_INVALID'
568                        ,p_msg_attribute    => 'CHANGE'
569                        ,p_resize_flag      => 'N'
570                        ,p_msg_context      => 'GENERAL'
571                        ,p_attribute1       => ''
572                        ,p_attribute2       => ''
573                        ,p_attribute3       => ''
574                        ,p_attribute4       => ''
575                        ,p_attribute5       => '');
576                   END IF;
577                   IF l_debug_mode = 'Y' THEN
578                         pa_debug.g_err_stage:= 'PM Product code is invalid';
579                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
580                   END IF;
581 
582                   x_return_status             := FND_API.G_RET_STS_ERROR;
583                   l_any_error_occurred_flag := 'Y';
584             -- RAISE FND_API.G_EXC_ERROR;
585             END IF;
586 
587              --dbms_output.put_line('pm product code is not valid '||l_pm_product_code);
588       END IF;-- p_pm_product_code IS NULL
589 
590       l_resp_id := FND_GLOBAL.Resp_id;
591       l_user_id := FND_GLOBAL.User_id;
592 
593       --  l_module_name := p_pm_product_code||'.'||'PA_PM_CREATE_DRAFT_BUDGET';
594 
595       /* Replaced the security checks with a call to single api
596 
597       -- As part of enforcing project security, which would determine
598       -- whether the user has the necessary privileges to update the project
599       -- If a user does not have privileges to update the project, then
600       -- cannot create a budget
601       -- need to call the pa_security package
602 
603       pa_security.initialize (X_user_id        => l_user_id,
604                             X_calling_module => l_module_name);
605       */
606 
607       -- Actions performed using the APIs would be subject to
608       -- function security. If the responsibility does not allow
609       -- such functions to be executed, the API should not proceed further
610       -- since the user does not have access to such functions
611 
612 
613 
614       /*
615       PA_PM_FUNCTION_SECURITY_PUB.check_function_security
616       (p_api_version_number => p_api_version_number,
617        p_responsibility_id  => l_resp_id,
618        p_function_name      => 'PA_PM_CREATE_DRAFT_BUDGET',
619        p_msg_count          => l_msg_count,
620        p_msg_data           => l_msg_data,
621        p_return_status      => x_return_status,
622        p_function_allowed   => l_function_allowed );
623 
624       IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR
625       THEN
626             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
627       ELSIF x_return_status = FND_API.G_RET_STS_ERROR
628       THEN
629             RAISE FND_API.G_EXC_ERROR;
630       END IF;
631 
632       IF l_function_allowed = 'N' THEN
633             pa_interface_utils_pub.map_new_amg_msg
634             ( p_old_message_code => 'PA_FUNCTION_SECURITY_ENFORCED'
635             ,p_msg_attribute    => 'CHANGE'
636             ,p_resize_flag      => 'Y'
637             ,p_msg_context      => 'GENERAL'
638             ,p_attribute1       => ''
639             ,p_attribute2       => ''
640             ,p_attribute3       => ''
641             ,p_attribute4       => ''
642             ,p_attribute5       => '');
643             x_return_status := FND_API.G_RET_STS_ERROR;
644             --  RAISE FND_API.G_EXC_ERROR;
645       END IF;
646       */
647 
648       -- CHECK FOR MANDATORY FIELDS and CONVERT VALUES to ID's
649       -- convert pm_project_reference to id
650 
651 	  px_pa_project_id_in := px_pa_project_id;
652 
653       Pa_project_pvt.Convert_pm_projref_to_id (
654          p_pm_project_reference  => p_pm_project_reference,
655          p_pa_project_id         => px_pa_project_id_in,
656          p_out_project_id        => px_pa_project_id,
657          p_return_status         => x_return_status );
658 
659        --dbms_output.put_line('x_return_status is  '|| x_return_status);
660       IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
661       THEN
662              --dbms_output.put_line('unexpected error while deriving project id '|| px_pa_project_id);
663              --dbms_output.put_line('expected error while deriving l project id '||px_pa_project_id );
664             IF l_debug_mode = 'Y' THEN
665                   pa_debug.g_err_stage:= 'Unexpected error while deriving project id';
666                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
667             END IF;
668             RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
669 
670       ELSIF x_return_status = FND_API.G_RET_STS_ERROR
671       THEN
672              --dbms_output.put_line('expected error while deriving px project id '||px_pa_project_id );
673              --dbms_output.put_line('expected error while deriving l project id '||px_pa_project_id );
674             IF l_debug_mode = 'Y' THEN
675                   pa_debug.g_err_stage:= 'Error while deriving project id';
676                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
677             END IF;
678 
679             --RAISE  FND_API.G_EXC_ERROR;    --AMG UT2
680             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
681 
682       END IF;
683 
684       PA_INTERFACE_UTILS_PUB.G_PROJECT_ID := px_pa_project_id;
685 
686       -- Now verify whether project security allows the user to update
687       -- the project
688       -- If a user does not have privileges to update the project, then
689       -- cannot create a budget
690 
691       /*   dbms_output.put_line('Before project security'); */
692 
693       /*
694       IF pa_security.allow_query (x_project_id => px_pa_project_id ) = 'N' THEN
695 
696             -- The user does not have query privileges on this project
697             -- Hence, cannot create a draft budget.Raise error
698 
699             pa_interface_utils_pub.map_new_amg_msg
700             ( p_old_message_code => 'PA_PROJECT_SECURITY_ENFORCED'
701             ,p_msg_attribute    => 'CHANGE'
702             ,p_resize_flag      => 'Y'
703             ,p_msg_context      => 'GENERAL'
704             ,p_attribute1       => ''
705             ,p_attribute2       => ''
706             ,p_attribute3       => ''
707             ,p_attribute4       => ''
708             ,p_attribute5       => '');
709             x_return_status := FND_API.G_RET_STS_ERROR;
710             --        RAISE FND_API.G_EXC_ERROR;
711       ELSE
712             -- If the user has query privileges, then check whether
713             -- update privileges are also available
714             IF pa_security.allow_update (x_project_id => px_pa_project_id ) = 'N' THEN
715 
716                   -- The user does not have update privileges on this project
717                   -- Hence , raise error
718 
719                   pa_interface_utils_pub.map_new_amg_msg
720                   ( p_old_message_code => 'PA_PROJECT_SECURITY_ENFORCED'
721                    ,p_msg_attribute    => 'CHANGE'
722                    ,p_resize_flag      => 'Y'
723                    ,p_msg_context      => 'GENERAL'
724                    ,p_attribute1       => ''
725                    ,p_attribute2       => ''
726                    ,p_attribute3       => ''
727                    ,p_attribute4       => ''
728                    ,p_attribute5       => '');
729                   x_return_status := FND_API.G_RET_STS_ERROR;
730                   --            RAISE FND_API.G_EXC_ERROR;
731             END IF;
732       END IF;
733       */
734 
735 
736       -- Get the segment 1 of the project so that it can be used in the
737       -- later part of the code
738       OPEN l_amg_project_csr( px_pa_project_id );
739       FETCH l_amg_project_csr INTO l_amg_project_rec;
740       CLOSE l_amg_project_csr;
741 
742       -- Get the cost and rev budget entry flags so that they can be
743       -- used in budget and finplan models
744       OPEN  l_cost_rev_budget_entry_csr(px_pa_project_id);
745       FETCH l_cost_rev_budget_entry_csr
746       INTO  l_allow_cost_budget_entry_flag,
747             l_allow_rev_budget_entry_flag  ;
748       CLOSE l_cost_rev_budget_entry_csr;
749 
750        --dbms_output.put_line('Starting the budget type validations');
751 
752       -- Do the validations required for the budget model
753       IF (p_budget_type_code IS NOT NULL AND
754           p_budget_type_code <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
755 
756              --dbms_output.put_line('About to call the security api');
757             --Check for the security
758             PA_PM_FUNCTION_SECURITY_PUB.CHECK_BUDGET_SECURITY (
759                                                p_api_version_number => p_api_version_number
760                                               ,p_project_id         => px_pa_project_id
761                                               ,p_calling_context    => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_BUDGET
762                                               ,p_function_name      => p_calling_module
763                                               ,p_version_type       => null
764                                               ,x_return_status      => x_return_status
765                                               ,x_ret_code           => l_security_ret_code );
766 
767             -- the above API adds the error message to stack. Hence the message is not added here.
768             -- Also, as security check is important further validations are not done in case this
769             -- validation fails.
770             IF (x_return_status<>FND_API.G_RET_STS_SUCCESS OR
771                 l_security_ret_code = 'N') THEN
772                    --dbms_output.put_line('Security api failed l_security_ret_code '||l_security_ret_code);
773                   IF l_debug_mode = 'Y' THEN
774                         pa_debug.g_err_stage:= 'Security API Failed';
775                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
776                   END IF;
777 
778                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
779             END IF;
780 
781              --dbms_output.put_line('About to validate the budget type');
782             -- Get the budget amount code. Check whether the project type allows the
783             -- creation of plan versions with obtained budget amounT code.
784             OPEN  l_budget_amount_code_csr( p_budget_type_code );
785             FETCH l_budget_amount_code_csr
786             INTO  l_budget_amount_code;       --will be used later on during validation of Budget lines.
787 
788             x_budget_amount_code := l_budget_amount_code; -- Added for bug 4224464
789 
790             IF l_budget_amount_code_csr%NOTFOUND
791             THEN
792                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
793                   THEN
794                         pa_interface_utils_pub.map_new_amg_msg
795                          ( p_old_message_code => 'PA_BUDGET_TYPE_IS_INVALID'
796                           ,p_msg_attribute    => 'CHANGE'
797                           ,p_resize_flag      => 'N'
798                           ,p_msg_context      => 'BUDG'
799                           ,p_attribute1       => l_amg_project_rec.segment1
800                           ,p_attribute2       => ''
801                           ,p_attribute3       => p_budget_type_code
802                           ,p_attribute4       => ''
803                           ,p_attribute5       => '');
804 
805                           IF l_debug_mode = 'Y' THEN
806                                 pa_debug.g_err_stage:= 'Budget type is invalid';
807                                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
808                           END IF;
809 
810                   END IF;
811                   x_return_status := FND_API.G_RET_STS_ERROR;
812                   l_any_error_occurred_flag := 'Y';
813 
814                   CLOSE l_budget_amount_code_csr;
815                   -- RAISE FND_API.G_EXC_ERROR;
816 
817             ELSE
818 
819                   CLOSE l_budget_amount_code_csr;
820 
821 
822                   IF l_budget_amount_code = PA_FP_CONSTANTS_PKG.G_BUDGET_AMOUNT_CODE_C THEN
823 
824                         IF NVL(l_allow_cost_budget_entry_flag,'N') = 'N' THEN
825                               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
826                               THEN
827                                     PA_UTILS.ADD_MESSAGE
828                                           (p_app_short_name => 'PA',
829                                            p_msg_name       => 'PA_COST_BUDGET_NOT_ALLOWED',
830                                            p_token1         => 'PROJECT',
831                                            p_value1         =>  l_amg_project_rec.segment1,
832                                            p_token2         => 'BUDGET_TYPE',
833                                            p_value2         =>  p_budget_type_code );
834                                     IF l_debug_mode = 'Y' THEN
835                                           pa_debug.g_err_stage:= 'Creation of cost version is not allowed';
836                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
837                                     END IF;
838                               END IF;
839                               x_return_status := FND_API.G_RET_STS_ERROR;
840                               l_any_error_occurred_flag := 'Y';
841 
842                           -- RAISE FND_API.G_EXC_ERROR;
843                         END IF;
844 
845                   ELSIF l_budget_amount_code = PA_FP_CONSTANTS_PKG.G_BUDGET_AMOUNT_CODE_R THEN
846 
847                         IF NVL(l_allow_rev_budget_entry_flag,'N') = 'N' THEN
848                               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
849                               THEN
850                                     PA_UTILS.ADD_MESSAGE
851                                           (p_app_short_name => 'PA',
852                                            p_msg_name       => 'PA_REV_BUDGET_NOT_ALLOWED',
853                                            p_token1         => 'PROJECT',
854                                            p_value1         =>  l_amg_project_rec.segment1,
855                                            p_token2         => 'BUDGET_TYPE',
856                                            p_value2         =>  p_budget_type_code );
857                                     IF l_debug_mode = 'Y' THEN
858                                           pa_debug.g_err_stage:= 'Creation of rev version is not allowed';
859                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
860                                     END IF;
861                               END IF;
862                               x_return_status := FND_API.G_RET_STS_ERROR;
863                               l_any_error_occurred_flag := 'Y';
864 
865                         -- RAISE FND_API.G_EXC_ERROR;
866                         END IF;
867 
868                   END IF; --End of l_budget_amount_code = PA_FP_CONSTANTS_PKG.G_BUDGET_AMOUNT_CODE_C
869 
870             END IF; --End of l_budget_amount_code_csr%NOTFOUND
871 
872             --Added this for bug#4460139
873              --Verify that the budget is not of type FORECASTING_BUDGET_TYPE
874              IF p_budget_type_code='FORECASTING_BUDGET_TYPE' THEN
875                    IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
876                    THEN
877                          PA_UTILS.add_message
878                          (p_app_short_name => 'PA',
879                           p_msg_name       => 'PA_FP_CANT_EDIT_FCST_BUD_TYPE');
880                    END IF;
881                    IF l_debug_mode = 'Y' THEN
882                          pa_debug.g_err_stage := 'Budget of type FORECASTING_BUDGET_TYPE' ;
883                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
884                    END IF;
885                    x_return_status := FND_API.G_RET_STS_ERROR;
886                    RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
887              END IF;
888 
889             -- Budget Integration Validation ---------------------------------------
890 
891              --dbms_output.put_line('About to call get_bdget_ctrl_options');
892 
893             PA_BUDGET_FUND_PKG.get_budget_ctrl_options (p_project_Id => px_pa_project_id
894                             , p_budget_type_code => p_budget_type_code
895                             , p_calling_mode     => 'BUDGET'
896                             , x_fck_req_flag     => l_fck_req_flag
897                             , x_bdgt_intg_flag   => l_bdgt_intg_flag
898                             , x_bdgt_ver_id      => l_bdgt_ver_id
899                             , x_encum_type_id    => l_encum_type_id
900                             , x_balance_type     => l_balance_type
901                             , x_return_status    => x_return_status
902                             , x_msg_data         => x_msg_data
903                             , x_msg_count        => x_msg_count
904                             );
905 
906             -- calling api above adds the error message to stack hence not adding the error message here.
907             IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
908             THEN
909 
910                   IF l_debug_mode = 'Y' THEN
911                         pa_debug.g_err_stage:= 'get_budget_ctrl_options returned unexp error';
912                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
913                   END IF;
914 
915                   RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
916 
917             ELSIF x_return_status = FND_API.G_RET_STS_ERROR
918             THEN
919                   -- RAISE  FND_API.G_EXC_ERROR;
920                   IF l_debug_mode = 'Y' THEN
921                         pa_debug.g_err_stage:= 'get_budget_ctrl_options returned  error';
922                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
923                   END IF;
924 
925                   l_any_error_occurred_flag := 'Y';
926             END IF;
927 
928             IF (nvl(l_fck_req_flag,'N') = 'Y')
929             THEN
930                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
931                   THEN
932                       pa_interface_utils_pub.map_new_amg_msg
933                       ( p_old_message_code => 'PA_BC_BGT_TYPE_IS_BAD_AMG'
934                        ,p_msg_attribute    => 'CHANGE'
935                        ,p_resize_flag      => 'N'
936                        ,p_msg_context      => 'BUDG'
937                        ,p_attribute1       => l_amg_project_rec.segment1
938                        ,p_attribute2       => ''
939                        ,p_attribute3       => p_budget_type_code
940                        ,p_attribute4       => ''
941                        ,p_attribute5       => '');
942                   END IF;
943                   x_return_status := FND_API.G_RET_STS_ERROR;
944                   l_any_error_occurred_flag := 'Y';
945 
946                   -- RAISE FND_API.G_EXC_ERROR;
947             END IF;
948 
949             -- ----------------------------------------------------------------------
950 
951             -- entry method code is mandatory
952 
953             IF p_entry_method_code IS NULL
954                OR p_entry_method_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
955             THEN
956 
957                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
958                   THEN
959                         pa_interface_utils_pub.map_new_amg_msg
960                         ( p_old_message_code => 'PA_ENTRY_METHOD_IS_MISSING'
961                         ,p_msg_attribute    => 'CHANGE'
962                         ,p_resize_flag      => 'N'
963                         ,p_msg_context      => 'BUDG'
964                         ,p_attribute1       => l_amg_project_rec.segment1
965                         ,p_attribute2       => ''
966                         ,p_attribute3       => p_budget_type_code
967                         ,p_attribute4       => ''
968                         ,p_attribute5       => '');
969 
970                         IF l_debug_mode = 'Y' THEN
971                               pa_debug.g_err_stage:= 'Budget entry method is missing';
972                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
973                         END IF;
974                   END IF;
975                   x_return_status := FND_API.G_RET_STS_ERROR;
976                   l_any_error_occurred_flag := 'Y';
977 
978                   -- RAISE FND_API.G_EXC_ERROR;
979             ELSE -- entry method is not null
980 
981                   -- check validity of this budget entry method code, and store associated fields in record
982 
983                   OPEN l_budget_entry_method_csr(p_entry_method_code);
984                   FETCH l_budget_entry_method_csr INTO l_budget_entry_method_rec;
985 
986                   IF   l_budget_entry_method_csr%NOTFOUND
987                   THEN
988 
989                         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
990                         THEN
991                                 pa_interface_utils_pub.map_new_amg_msg
992                                ( p_old_message_code => 'PA_ENTRY_METHOD_IS_INVALID'
993                                 ,p_msg_attribute    => 'CHANGE'
994                                 ,p_resize_flag      => 'N'
995                                 ,p_msg_context      => 'BUDG'
996                                 ,p_attribute1       => l_amg_project_rec.segment1
997                                 ,p_attribute2       => ''
998                                 ,p_attribute3       => p_budget_type_code
999                                 ,p_attribute4       => ''
1000                                 ,p_attribute5       => '');
1001                                 IF l_debug_mode = 'Y' THEN
1002                                        pa_debug.g_err_stage:= 'Budget entry method is invlaid';
1003                                        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1004                                 END IF;
1005                         END IF;
1006                         x_return_status := FND_API.G_RET_STS_ERROR;
1007                         l_any_error_occurred_flag := 'Y';
1008 
1009                         CLOSE l_budget_entry_method_csr;
1010                         --  RAISE FND_API.G_EXC_ERROR;
1011 
1012                   ELSE
1013 
1014                         CLOSE l_budget_entry_method_csr;
1015 
1016                         IF l_budget_entry_method_rec.categorization_code = 'N' THEN
1017 
1018                               pa_get_resource.Get_Uncateg_Resource_Info
1019                                       (p_resource_list_id          => l_uncategorized_list_id,
1020                                        p_resource_list_member_id   => l_uncategorized_rlmid,
1021                                        p_resource_id               => l_uncategorized_resid,
1022                                        p_track_as_labor_flag       => l_track_as_labor_flag,
1023                                        p_err_code                  => l_err_code,
1024                                        p_err_stage                 => l_err_stage,
1025                                        p_err_stack                 => l_err_stack );
1026 
1027                               IF l_err_code <> 0 THEN
1028                                     IF NOT pa_project_pvt.check_valid_message(l_err_stage) THEN
1029                                           pa_interface_utils_pub.map_new_amg_msg
1030                                           ( p_old_message_code => 'PA_NO_UNCATEGORIZED_LIST'
1031                                           ,p_msg_attribute    => 'CHANGE'
1032                                           ,p_resize_flag      => 'N'
1033                                           ,p_msg_context      => 'BUDG'
1034                                           ,p_attribute1       => l_amg_project_rec.segment1
1035                                           ,p_attribute2       => ''
1036                                           ,p_attribute3       => p_budget_type_code
1037                                           ,p_attribute4       => ''
1038                                           ,p_attribute5       => '');
1039 
1040                                           IF l_debug_mode = 'Y' THEN
1041                                                  pa_debug.g_err_stage:= 'Uncategorized res list  is missing';
1042                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1043                                           END IF;
1044                                     ELSE
1045                                           pa_interface_utils_pub.map_new_amg_msg
1046                                           ( p_old_message_code => l_err_stage
1047                                           ,p_msg_attribute    => 'CHANGE'
1048                                           ,p_resize_flag      => 'N'
1049                                           ,p_msg_context      => 'BUDG'
1050                                           ,p_attribute1       => l_amg_project_rec.segment1
1051                                           ,p_attribute2       => ''
1052                                           ,p_attribute3       => p_budget_type_code
1053                                           ,p_attribute4       => ''
1054                                           ,p_attribute5       => '');
1055                                           IF l_debug_mode = 'Y' THEN
1056                                                  pa_debug.g_err_stage:= 'Unexp error while deriving uncat res list';
1057                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1058                                           END IF;
1059                                     END IF;
1060 
1061                               ELSE
1062 
1063                                     px_resource_list_id := l_uncategorized_list_id;
1064 
1065                               --  RAISE  FND_API.G_EXC_ERROR;
1066                               END IF; -- IF l_err_code <> 0 THEN
1067 
1068 
1069                         ELSIF l_budget_entry_method_rec.categorization_code = 'R' THEN
1070                               IF  (px_resource_list_name <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
1071                                AND px_resource_list_name IS NOT NULL)
1072                                 OR (px_resource_list_id <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
1073                                AND px_resource_list_id IS NOT NULL) THEN
1074                                     -- convert resource_list_name to resource_list_id
1075 									px_resource_list_id_in := px_resource_list_id;
1076                                     pa_resource_pub.Convert_List_name_to_id
1077                                     ( p_resource_list_name    =>  px_resource_list_name,
1078                                       p_resource_list_id      =>  px_resource_list_id_in,
1079                                       p_out_resource_list_id  =>  px_resource_list_id,
1080                                       p_return_status         =>  x_return_status );
1081 
1082                                     IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR THEN
1083                                           x_return_status := x_return_status;
1084                                            --dbms_output.put_line('Unexp error as Resource list id not derived properly');
1085                                           IF l_debug_mode = 'Y' THEN
1086                                                  pa_debug.g_err_stage:= 'Unexp error while deriving  res list';
1087                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1088                                           END IF;
1089 
1090                                           RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
1091 
1092                                     ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
1093                                           x_return_status := x_return_status;
1094                                           --                            RAISE  FND_API.G_EXC_ERROR;
1095                                           PA_UTILS.ADD_MESSAGE
1096                                                 (p_app_short_name => 'PA',
1097                                                  p_msg_name       => 'PA_FP_INVALID_RESOURCE_LIST',
1098                                                  p_token1         => 'PROJECT',
1099                                                  p_value1         =>  l_amg_project_rec.segment1);
1100                                            x_return_status := FND_API.G_RET_STS_ERROR;
1101                                             --dbms_output.put_line('exp error as Resource list id not derived properly');
1102                                            l_any_error_occurred_flag := 'Y';
1103                                            IF l_debug_mode = 'Y' THEN
1104                                                  pa_debug.g_err_stage:= 'error while deriving uncat res list';
1105                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1106                                            END IF;
1107 
1108                                     END IF;
1109 
1110                                     /* changes for bug 3954329: following check included */
1111                                     BEGIN
1112                                           SELECT migration_code
1113                                           INTO   l_res_list_migration_code
1114                                           FROM   pa_resource_lists_all_bg
1115                                           WHERE  resource_list_id = px_resource_list_id;
1116                                     EXCEPTION
1117                                           WHEN NO_DATA_FOUND THEN
1118                                                 x_return_status := FND_API.G_RET_STS_ERROR;
1119                                                 PA_UTILS.ADD_MESSAGE
1120                                                   (p_app_short_name => 'PA',
1121                                                    p_msg_name       => 'PA_FP_INVALID_RESOURCE_LIST',
1122                                                    p_token1         => 'PROJECT',
1123                                                    p_value1         =>  l_amg_project_rec.segment1);
1124                                                 x_return_status := FND_API.G_RET_STS_ERROR;
1125 
1126                                                l_any_error_occurred_flag := 'Y';
1127                                                IF l_debug_mode = 'Y' THEN
1128                                                    pa_debug.g_err_stage:= 'error while deriving uncat res list';
1129                                                    pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1130                                                END IF;
1131                                     END;
1132                                     IF l_res_list_migration_code = 'N' THEN
1133                                           x_return_status := FND_API.G_RET_STS_ERROR;
1134                                           l_any_error_occurred_flag := 'Y';
1135                                           PA_UTILS.ADD_MESSAGE
1136                                                (p_app_short_name => 'PA',
1137                                                 p_msg_name       => 'PA_FP_NEW_RES_LIST_OLD_MODEL');
1138                                           IF l_debug_mode = 'Y' THEN
1139                                                  pa_debug.g_err_stage:= 'res list is new in old budget model';
1140                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1141                                           END IF;
1142                                     END IF;
1143                                     /* bug 3954329 ends */
1144                               ELSE -- There is no valid resource list id
1145                                     x_return_status := FND_API.G_RET_STS_ERROR;     --AMG UT2
1146                                     l_any_error_occurred_flag := 'Y';
1147 
1148                                     IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
1149                                           pa_interface_utils_pub.map_new_amg_msg
1150                                           ( p_old_message_code => 'PA_RESOURCE_LIST_IS_MISSING'
1151                                           ,p_msg_attribute    => 'CHANGE'
1152                                           ,p_resize_flag      => 'Y'
1153                                           ,p_msg_context      => 'BUDG'
1154                                           ,p_attribute1       => l_amg_project_rec.segment1
1155                                           ,p_attribute2       => ''
1156                                           ,p_attribute3       => p_budget_type_code
1157                                           ,p_attribute4       => ''
1158                                           ,p_attribute5       => '');
1159                                     END IF;
1160                                     IF l_debug_mode = 'Y' THEN
1161                                            pa_debug.g_err_stage:= 'res list is missing';
1162                                            pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1163                                     END IF;
1164 
1165                                     --  RAISE FND_API.G_EXC_ERROR;
1166                               END IF;
1167                         END IF ; -- If l_budget_entry_method_rec.categorization_code = 'N
1168                   END IF;--l_budget_entry_method_csr%NOTFOUND
1169             END IF;--p_entry_method_code IS NULL
1170 
1171             -- If autobaselining is enabled for the project and If the budget type code is 'AR' then the
1172             -- version can not be created thru AMG
1173 
1174             l_called_from_agr_pub := PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB; -- Bug # 3099706
1175 
1176             IF (nvl(PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB,'N') = 'Y') THEN
1177                     PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB := 'N'; -- reset the value bug 3099706
1178             END IF;
1179 
1180             IF ( (NVL(l_amg_project_rec.baseline_funding_flag,'N')='Y')
1181             AND (p_budget_type_code = PA_FP_CONSTANTS_PKG.G_BUDGET_TYPE_CODE_AR)
1182             AND (NVL(l_called_from_agr_pub,'N') = 'N')) THEN -- Bug 3099706
1183 
1184 -- Added the param p_called_from_baseline to skip the autobaseline validation if
1185 -- the create_draft_budget API is called to create a draft budget while creating
1186 -- a baselined budget. If this API is called to create a draft version directly,
1187 -- this check should be done. In this case, the param p_called_from_baseline
1188 -- is defaulted to 'N' (for bug # 3099706)
1189 
1190                   IF l_debug_mode = 'Y' THEN
1191                         pa_debug.g_err_stage := 'Auto base line error' ;
1192                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1193                   END IF;
1194 
1195                   PA_UTILS.ADD_MESSAGE
1196                         (p_app_short_name => 'PA',
1197                          p_msg_name       => 'PA_FP_AUTO_BASELINE_ENABLED',
1198                          p_token1         => 'PROJECT',
1199                          p_value1         =>  l_amg_project_rec.segment1);
1200                   x_return_status := FND_API.G_RET_STS_ERROR;
1201                   l_any_error_occurred_flag := 'Y';
1202 
1203                   --RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1204                    --dbms_output.put_line('Autobaseline error');
1205 
1206             END IF;
1207 
1208             -- A version can not be created for a budget type that is already
1209             -- upgraded.
1210             OPEN is_budget_type_upgraded_csr( p_budget_type_code
1211                                              ,px_pa_project_id);
1212             FETCH is_budget_type_upgraded_csr INTO l_budget_type_upgraded_rec;
1213             IF (is_budget_type_upgraded_csr%FOUND) THEN
1214 
1215                   CLOSE is_budget_type_upgraded_csr;
1216 
1217                   PA_UTILS.ADD_MESSAGE
1218                         (p_app_short_name => 'PA',
1219                           p_msg_name      => 'PA_FP_BUDGET_TYPE_UPGRADED');
1220 
1221                   x_return_status := FND_API.G_RET_STS_ERROR;
1222                   l_any_error_occurred_flag := 'Y';
1223                    --dbms_output.put_line('Budget type upgraded error');
1224                   IF l_debug_mode = 'Y' THEN
1225                          pa_debug.g_err_stage:= 'Budget type is already upgraded';
1226                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1227                   END IF;
1228 
1229 
1230             ELSE
1231 
1232                   CLOSE is_budget_type_upgraded_csr;
1233 
1234             END IF;
1235 
1236             -- If an Approved Cost plan version exists for the project in new model then a budget version
1237             -- for budget type 'AC' can not be created for that project.
1238             IF (p_budget_type_code = PA_FP_CONSTANTS_PKG.G_BUDGET_TYPE_CODE_AC) THEN
1239 
1240                   -- Call the utility function that gives the id of the approved cost plan type, if exists,
1241                   -- that is added to the project
1242                   pa_fin_plan_utils.Get_Appr_Cost_Plan_Type_Info(
1243                      p_project_id     =>  px_pa_project_id
1244                     ,x_plan_type_id   =>  l_approved_fin_plan_type_id
1245                     ,x_return_status  =>  x_return_status
1246                     ,x_msg_count      =>  x_msg_count
1247                     ,x_msg_data       =>  x_msg_data);
1248 
1249                   -- Throw the error if the above API is not successfully executed
1250                   IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1251 
1252                         IF l_debug_mode = 'Y' THEN
1253                          pa_debug.g_err_stage := 'Get_Appr_Cost_Plan_Type_Info API returned error' ;
1254                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
1255                         END IF;
1256                         RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1257 
1258                   -- The Get_Appr_Cost_Plan_Type_Info api got executed successfully.Approved cost version
1259                   --  is already added to the project
1260                   ELSIF (l_approved_fin_plan_type_id IS NOT NULL)  THEN
1261 
1262                         IF l_debug_mode = 'Y' THEN
1263                          pa_debug.g_err_stage := 'Approved cost plan version is already added ' ;
1264                          pa_debug.write(l_module_name,pa_debug.g_err_stage, l_debug_level3);
1265                         END IF;
1266 
1267                         PA_UTILS.ADD_MESSAGE
1268                                (p_app_short_name => 'PA',
1269                                  p_msg_name      => 'PA_FP_AC_PLAN_TYPE_EXISTS');
1270 
1271                         x_return_status := FND_API.G_RET_STS_ERROR;
1272                         l_any_error_occurred_flag := 'Y';
1273 
1274                   END IF; --IF x_return_status <> FND_API.G_RET_STS_SUCCESS
1275 
1276             END IF; --IF (p_budget_type_code = PA_FP_CONSTANTS_PKG.G_BUDGET_TYPE_CODE_AC)
1277 
1278             -- If an Approved Revenue plan version exists for the project in new model then a budget
1279             -- version of budget   type 'AR' can not be created for that project.
1280             IF (p_budget_type_code = PA_FP_CONSTANTS_PKG.G_BUDGET_TYPE_CODE_AR) THEN
1281 
1282                   -- Call the utility function that gives the id of the approved revenue plan type, if exists,
1283                   -- that is added to the project
1284                   pa_fin_plan_utils.Get_Appr_Rev_Plan_Type_Info(
1285                      p_project_id     => px_pa_project_id
1286                     ,x_plan_type_id  =>  l_approved_fin_plan_type_id
1287                     ,x_return_status =>  x_return_status
1288                     ,x_msg_count     =>  x_msg_count
1289                     ,x_msg_data      =>  x_msg_data) ;
1290 
1291                   -- Throw the error if the above API is not successfully executed
1292                   IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1293 
1294                         IF l_debug_mode = 'Y' THEN
1295                          pa_debug.g_err_stage := 'Get_Appr_Cost_Plan_Type_Info API returned error' ;
1296                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
1297                         END IF;
1298                         RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1299 
1300                   -- The Get_Appr_Cost_Plan_Type_Info api got executed successfully.Approved cost version
1301                   -- is already added to the project
1302                   ELSIF(  l_approved_fin_plan_type_id IS NOT NULL)  THEN
1303 
1304                       IF l_debug_mode = 'Y' THEN
1305                          pa_debug.g_err_stage := 'Approved Revenue plan version is already added ' ;
1306                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1307                       END IF;
1308 
1309                       PA_UTILS.ADD_MESSAGE
1310                                (p_app_short_name => 'PA',
1311                                  p_msg_name      => 'PA_FP_AR_PLAN_TYPE_EXISTS');
1312                       x_return_status := FND_API.G_RET_STS_ERROR;
1313                       l_any_error_occurred_flag := 'Y';
1314 
1315                   END IF;
1316             END IF;
1317 
1318 
1319             -- Get the ID of the old draft budget and then
1320             -- Lock the old draft budget and it budget lines (if it exists)
1321             -- because it will be deleted by create_draft.
1322             OPEN l_budget_version_csr( px_pa_project_id, p_budget_type_code );
1323             FETCH l_budget_version_csr INTO l_old_budget_version_id, l_budget_status_code;
1324             CLOSE l_budget_version_csr;
1325 
1326             --if working bugdet is submitted no new working budget can be created
1327             IF l_budget_status_code = 'S'
1328             THEN
1329                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1330                   THEN
1331                      pa_interface_utils_pub.map_new_amg_msg
1332                     ( p_old_message_code => 'PA_BUDGET_IS_SUBMITTED'
1333                      ,p_msg_attribute    => 'CHANGE'
1334                      ,p_resize_flag      => 'N'
1335                      ,p_msg_context      => 'BUDG'
1336                      ,p_attribute1       => l_amg_project_rec.segment1
1337                      ,p_attribute2       => ''
1338                      ,p_attribute3       => p_budget_type_code
1339                      ,p_attribute4       => ''
1340                      ,p_attribute5       => '');
1341                   END IF;
1342                   x_return_status := FND_API.G_RET_STS_ERROR;
1343                   l_any_error_occurred_flag := 'Y';
1344                  --RAISE FND_API.G_EXC_ERROR;
1345 
1346             END IF;--l_budget_status_code = 'S'
1347 
1348 
1349       -- Validations for fin plan model
1350       ELSE
1351 	        px_fin_plan_type_id_in := px_fin_plan_type_id;
1352             PA_FIN_PLAN_PVT.convert_plan_type_name_to_id
1353                                            ( p_fin_plan_type_id    => px_fin_plan_type_id_in
1354                                             ,p_fin_plan_type_name  => px_fin_plan_type_name
1355                                             ,x_fin_plan_type_id    => px_fin_plan_type_id
1356                                             ,x_return_status       => x_return_status
1357                                             ,x_msg_count           => x_msg_count
1358                                             ,x_msg_data            => x_msg_data);
1359              --dbms_output.put_line('After the getting plan id');
1360 
1361             -- Throw the error if the above API is not successfully executed
1362             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1363 
1364                   IF l_debug_mode = 'Y' THEN
1365                         pa_debug.g_err_stage := 'Can not get the value of Fin Plan Type Id' ;
1366                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
1367                   END IF;
1368 
1369 
1370                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1371 
1372             END IF;
1373 
1374             -- Get the  plan type level settings
1375 
1376             OPEN  l_proj_fp_options_csr(px_pa_project_id,px_fin_plan_type_id);
1377             FETCH l_proj_fp_options_csr
1378             INTO  l_proj_fp_options_rec;
1379 
1380             --Bug # 3507156 : Patchset M: B and F impact changes : AMG
1381             --Added the parameter use_for_workplan_flag.We need to check this flag as workplan versions
1382             --cannot be created using AMG interface.Error handling also done.
1383 
1384             -- Get the name of the plan type
1385             SELECT name,use_for_workplan_flag
1386             INTO   l_fin_plan_type_name,l_workplan_flag
1387             FROM   pa_fin_plan_types_vl
1388             WHERE  fin_plan_type_id =  px_fin_plan_type_id;
1389 
1390             IF  l_workplan_flag = 'Y' THEN
1391 
1392                   IF l_debug_mode = 'Y' THEN
1393                         pa_debug.g_err_stage := 'WorkPlan Versions cannot be created using this AMG interface' ;
1394                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
1395                   END IF;
1396 
1397                   PA_UTILS.ADD_MESSAGE
1398                            (p_app_short_name => 'PA',
1399                             p_msg_name       => 'PA_FP_WP_BV_CR_NO_ALLOWED');
1400 
1401             --Bug # 3507156 : Patchset M: B and F impact changes : AMG
1402                   x_return_status := FND_API.G_RET_STS_ERROR;
1403                   l_any_error_occurred_flag := 'Y';
1404 
1405             END IF;
1406 
1407             -- Throw an error if the plan type is not attached to the project
1408             IF  l_proj_fp_options_csr%NOTFOUND THEN
1409 
1410                   IF l_debug_mode = 'Y' THEN
1411                         pa_debug.g_err_stage := 'Plan type options does not exist' ;
1412                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
1413                   END IF;
1414 
1415                   PA_UTILS.ADD_MESSAGE
1416                            (p_app_short_name => 'PA',
1417                             p_msg_name       => 'PA_FP_NO_PLAN_TYPE_OPTION',
1418                             p_token1         => 'PROJECT',
1419                             p_value1         =>  l_amg_project_rec.segment1,
1420                             p_token2         => 'PLAN_TYPE',
1421                             p_value2         =>  l_fin_plan_type_name);
1422 
1423 
1424                   CLOSE l_proj_fp_options_csr;
1425 
1426                   IF l_debug_mode = 'Y' THEN
1427                          pa_debug.g_err_stage:= 'Plan type is not yet added to the project';
1428                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1429                   END IF;
1430 
1431                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1432 
1433             ELSE
1434 
1435                   CLOSE l_proj_fp_options_csr;
1436 
1437             END IF;
1438 
1439             -- If autobaselining is enabled for the project and If the budget type code is 'AR' then the
1440             -- version can not be created thru AMG
1441 
1442              l_called_from_agr_pub := PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB; -- Bug # 3099706
1443 
1444             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1445             --PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB should be reset to N even in case of errors.
1446 
1447             IF (nvl(PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB,'N') = 'Y') THEN
1448                  PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB := 'N'; -- reset the value bug 3099706
1449             END IF;
1450 
1451             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1452             -- To check whether finplan is auto baselined by calling the api.
1453 
1454             l_autobaseline_flag := pa_fp_control_items_utils.IsFpAutoBaselineEnabled(px_pa_project_id);
1455 
1456             --dbms_output.put_line('About to get ver type');
1457 
1458             -- Derive the version type. An error will be thrown by this api if preference code is
1459             -- COST_AND_REV_SEP and version type is not passed
1460             pa_fin_plan_utils.get_version_type
1461                  ( p_project_id        => px_pa_project_id
1462                   ,p_fin_plan_type_id  => px_fin_plan_type_id
1463                   ,px_version_type     => px_version_type
1464                   ,x_return_status     => x_return_status
1465                   ,x_msg_count         => x_msg_count
1466                   ,x_msg_data          => x_msg_data);
1467 
1468             IF x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1469 
1470                   IF l_debug_mode = 'Y' THEN
1471                         pa_debug.g_err_stage := 'Faied in get_Version_type' ;
1472                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
1473                   END IF;
1474                                --dbms_output.put_line('Exc in getting ver type');
1475 
1476                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1477 
1478             END IF;
1479 
1480       IF l_autobaseline_flag = 'N' THEN
1481 
1482             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1483             --If validate_header_info is called for create_budget_context call pa_fin_plan_utils.allow_edit_after_baseline_flag.
1484 
1485             pa_fin_plan_utils.Check_if_plan_type_editable (
1486                      P_project_id         => px_pa_project_id
1487                     ,P_fin_plan_type_id   => px_fin_plan_type_id
1488                     ,P_version_type       => px_version_type
1489                     ,X_editable_flag      => l_editable_flag
1490                     ,X_return_status      => x_return_status
1491                     ,X_msg_count          => x_msg_count
1492                     ,X_msg_data           => x_msg_data);
1493 
1494             -- Throw the error if the above API is not successfully executed
1495 
1496             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1497 
1498                             IF l_debug_mode = 'Y' THEN
1499                                   pa_debug.g_err_stage := 'Can not check if plan type is editable' ;
1500                                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1501                             END IF;
1502 
1503                                  RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1504             END IF;
1505 
1506             --<Patchset M: B and F impact changes : AMG:> -- Bug # 3507156
1507             --If it returns N, then raise PA_FP_PLAN_TYPE_NON_EDITABLE.
1508 
1509             IF l_editable_flag = 'N'  THEN
1510 
1511                   IF l_debug_mode = 'Y' THEN
1512                         pa_debug.g_err_stage := 'Plan type is not editable' ;
1513                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1514                   END IF;
1515 
1516                   PA_UTILS.ADD_MESSAGE
1517                            (p_app_short_name => 'PA',
1518                             p_msg_name       => 'PA_FP_PLAN_TYPE_NON_EDITABLE',
1519                             p_token1         => 'PROJECT',
1520                             p_value1         =>  l_amg_project_rec.segment1,
1521                             p_token2         => 'PLAN_TYPE',
1522                             p_value2         =>  l_fin_plan_type_name);
1523 
1524             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1525             --Setting the error statuses if plan type is not editable.
1526 
1527             x_return_status := FND_API.G_RET_STS_ERROR;
1528             l_any_error_occurred_flag := 'Y';
1529 
1530             END IF;
1531       END IF;
1532 
1533             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1534             -- Commented out as it is redundant over here.
1535 /*
1536             IF (nvl(PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB,'N') = 'Y') THEN
1537                PA_FP_CONSTANTS_PKG.G_CALLED_FROM_AGREEMENT_PUB := 'N'; -- reset the value bug 3099706
1538             END IF;
1539 */
1540 
1541 
1542             IF ( (NVL(l_amg_project_rec.baseline_funding_flag,'N')='Y')
1543             AND (p_budget_type_code = PA_FP_CONSTANTS_PKG.G_BUDGET_TYPE_CODE_AR)
1544             AND (NVL(l_called_from_agr_pub,'N') = 'N')) THEN -- Bug 3099706
1545 
1546 
1547 -- Added the param p_called_from_baseline to skip the autobaseline validation if
1548 -- the create_draft_budget API is called to create a draft budget while creating
1549 -- a baselined budget. If this API is called to create a draft version directly,
1550 -- this check should be done. In this case, the param p_called_from_baseline
1551 -- is defaulted to 'N' (for bug # 3099706)
1552 
1553                  IF l_debug_mode = 'Y' THEN
1554                        pa_debug.g_err_stage := 'Auto base line error' ;
1555                        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1556                  END IF;
1557 
1558             PA_UTILS.ADD_MESSAGE
1559                   (p_app_short_name => 'PA',
1560                    p_msg_name       => 'PA_FP_AUTO_BASELINE_ENABLED',
1561                    p_token1         => 'PROJECT',
1562                    p_value1         =>  l_amg_project_rec.segment1);
1563 
1564             x_return_status := FND_API.G_RET_STS_ERROR;
1565             l_any_error_occurred_flag := 'Y';
1566 
1567             --RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1568              --dbms_output.put_line('Autobaseline error');
1569 
1570             END IF;
1571 
1572             PA_PM_FUNCTION_SECURITY_PUB.CHECK_BUDGET_SECURITY (
1573                                          p_api_version_number => p_api_version_number
1574                                         ,p_project_id         => px_pa_project_id
1575                                         ,p_fin_plan_type_id   => px_fin_plan_type_id /* Bug 3139924 */
1576                                         ,p_calling_context    => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN
1577                                         ,p_function_name      => p_calling_module
1578                                         ,p_version_type       => px_version_type
1579                                         ,x_return_status      => x_return_status
1580                                         ,x_ret_code           => l_security_ret_code );
1581 
1582             IF (x_return_status <>FND_API.G_RET_STS_SUCCESS OR
1583                 l_security_ret_code='N') THEN
1584                  --dbms_output.put_line('Exc in security');
1585                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1586             END IF;
1587 
1588 
1589             /* Bug 3133930- Version name validation is included */
1590 
1591             IF p_budget_version_name IS NULL OR
1592                p_budget_version_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
1593                   PA_UTILS.ADD_MESSAGE(
1594                            p_app_short_name => 'PA'
1595                            ,p_msg_name   => 'PA_VERSION_NAME_IS_MISSING');
1596                RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1597             END IF;
1598 
1599              --dbms_output.put_line('DONE with sec');
1600        	-- Added the check to skip the autobaseline validation if
1601         -- the create_draft_budget API is called to create a draft budget while creating
1602         -- a baselined budget. --4738996
1603             -- Auto Baseline check. If auto baselining is enabled for the project the user can not
1604             -- create an approved revenue plan version thru AMG
1605             IF ((NVL(l_amg_project_rec.baseline_funding_flag,'N')='Y')
1606                AND (px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE)
1607                AND (l_proj_fp_options_rec.approved_rev_plan_type_flag = 'Y')
1608 	       AND (NVL(l_called_from_agr_pub,'N') = 'N')) THEN -- Added for bug 4738996
1609 
1610                   IF l_debug_mode = 'Y' THEN
1611                         pa_debug.g_err_stage := 'Auto base line error' ;
1612                         pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
1613                   END IF;
1614 
1615                   PA_UTILS.ADD_MESSAGE
1616                            (p_app_short_name => 'PA',
1617                              p_msg_name      => 'PA_FP_AUTO_BASELINE_ENABLED',
1618                              p_token1        => 'PROJECT',
1619                              p_value1        =>  l_amg_project_rec.segment1);
1620 
1621                   x_return_status := FND_API.G_RET_STS_ERROR;
1622                   l_any_error_occurred_flag := 'Y';
1623                  --RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1624 
1625             END IF;
1626 
1627             -- Validate planning level, resource list id and time phasing if they are passed. If they
1628             -- are not passed, default them from the plan type options.
1629             -- Get the plan type level settings so that they can be used in the defaulting
1630             OPEN l_plan_type_settings_csr( px_pa_project_id
1631                                       ,px_fin_plan_type_id
1632                                       ,px_version_type);
1633             FETCH l_plan_type_settings_csr
1634             INTO  l_plan_type_settings_rec;
1635 
1636             IF (l_plan_type_settings_csr%NOTFOUND) THEN --This condition should never be true
1637 
1638                   IF l_debug_mode = 'Y' THEN
1639                         pa_debug.g_err_stage := 'l_plan_type_settings_csr returned 0 rows' ;
1640                         pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
1641                   END IF;
1642                   CLOSE l_plan_type_settings_csr;
1643                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1644 
1645             ELSE
1646 
1647                   CLOSE l_plan_type_settings_csr;
1648 
1649             END IF;
1650 
1651 
1652 
1653             -- Get the planning level
1654             IF ( px_fin_plan_level_code IS NULL) THEN
1655 
1656                   IF l_debug_mode = 'Y' THEN
1657                         pa_debug.g_err_stage := 'Defaulting planning level from the plan type' ;
1658                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1659                   END IF;
1660 
1661                   px_fin_plan_level_code :=  l_plan_type_settings_rec.fin_plan_level_code;
1662 
1663             ELSE -- validate the passed planning level
1664 
1665             -- Use the utility function that returns the meaning given the lookup type and code
1666             -- to validate the planning level given by the user
1667 
1668             -- <Patchset M : B andF impact changes : AMG:> -- Bug # 3507156
1669             -- Added a check to filter out budgets where fin_plan_level_code = 'M'
1670 
1671                  IF ((pa_fin_plan_utils.get_lookup_value(l_planning_level_lookup ,px_fin_plan_level_code) IS NULL)
1672                  OR (px_fin_plan_level_code = 'M'))
1673                   THEN
1674                         IF l_debug_mode = 'Y' THEN
1675                               pa_debug.g_err_stage := 'Planning level passed is '|| px_fin_plan_level_code ;
1676                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1677                         END IF;
1678 
1679                         PA_UTILS.ADD_MESSAGE
1680                            (p_app_short_name => 'PA',
1681                             p_msg_name       => 'PA_FP_INVALID_PLANNING_LEVEL',
1682                             p_token1         => 'PROJECT',
1683                             p_value1         =>  l_amg_project_rec.segment1,
1684                             p_token2         => 'PLAN_TYPE',
1685                             p_value2         =>  l_fin_plan_type_name);
1686 
1687                         x_return_status := FND_API.G_RET_STS_ERROR;
1688                         l_any_error_occurred_flag := 'Y';
1689 
1690                  END IF;
1691 
1692 
1693             END IF;--IF ( px_fin_plan_level_code IS NULL) THEN
1694 
1695             -- Get the resource list
1696                IF p_using_resource_lists_flag = 'N' THEN
1697                               pa_get_resource.Get_Uncateg_Resource_Info
1698                                       (p_resource_list_id          => l_uncategorized_list_id,
1699                                        p_resource_list_member_id   => l_uncategorized_rlmid,
1700                                        p_resource_id               => l_uncategorized_resid,
1701                                        p_track_as_labor_flag       => l_track_as_labor_flag,
1702                                        p_err_code                  => l_err_code,
1703                                        p_err_stage                 => l_err_stage,
1704                                        p_err_stack                 => l_err_stack );
1705 
1706                               IF l_err_code <> 0 THEN
1707                                     IF NOT pa_project_pvt.check_valid_message(l_err_stage) THEN
1708                                           pa_interface_utils_pub.map_new_amg_msg
1709                                           ( p_old_message_code => 'PA_NO_UNCATEGORIZED_LIST'
1710                                           ,p_msg_attribute    => 'CHANGE'
1711                                           ,p_resize_flag      => 'N'
1712                                           ,p_msg_context      => 'BUDG'
1713                                           ,p_attribute1       => l_amg_project_rec.segment1
1714                                           ,p_attribute2       => ''
1715                                           ,p_attribute3       => p_budget_type_code
1716                                           ,p_attribute4       => ''
1717                                           ,p_attribute5       => '');
1718 
1719                                           IF l_debug_mode = 'Y' THEN
1720                                                  pa_debug.g_err_stage:= 'Uncategorized res list  is missing';
1721                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1722                                           END IF;
1723                                     ELSE
1724                                           pa_interface_utils_pub.map_new_amg_msg
1725                                           ( p_old_message_code => l_err_stage
1726                                           ,p_msg_attribute    => 'CHANGE'
1727                                           ,p_resize_flag      => 'N'
1728                                           ,p_msg_context      => 'BUDG'
1729                                           ,p_attribute1       => l_amg_project_rec.segment1
1730                                           ,p_attribute2       => ''
1731                                           ,p_attribute3       => p_budget_type_code
1732                                           ,p_attribute4       => ''
1733                                           ,p_attribute5       => '');
1734                                           IF l_debug_mode = 'Y' THEN
1735                                                  pa_debug.g_err_stage:= 'Unexp error while deriving uncat res list';
1736                                                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1737                                           END IF;
1738                                     END IF;
1739 
1740                               ELSE
1741 
1742                                     px_resource_list_id := l_uncategorized_list_id;
1743 
1744                               --  RAISE  FND_API.G_EXC_ERROR;
1745                               END IF; -- IF l_err_code <> 0 THEN
1746                ELSE
1747                   IF( px_resource_list_name IS NULL OR
1748                       px_resource_list_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR )AND
1749                      (px_resource_list_id IS NULL OR
1750                       px_resource_list_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM) THEN
1751 
1752                         IF l_debug_mode = 'Y' THEN
1753                               pa_debug.g_err_stage := 'Defaulting Resource List Id from the plan type' ;
1754                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1755                         END IF;
1756 
1757                         px_resource_list_id := l_plan_type_settings_rec.resource_list_id;
1758                   ELSE
1759 
1760                      -- convert resource_list_name to resource_list_id
1761 					 px_resource_list_id_in := px_resource_list_id;
1762                      pa_resource_pub.Convert_List_name_to_id
1763                          ( p_resource_list_name    =>  px_resource_list_name,
1764                            p_resource_list_id      =>  px_resource_list_id_in,
1765                            p_out_resource_list_id  =>  px_resource_list_id,
1766                            p_return_status         =>  x_return_status );
1767 
1768                      IF x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
1769 
1770                            PA_UTILS.ADD_MESSAGE
1771                              (p_app_short_name => 'PA',
1772                               p_msg_name       => 'PA_FP_INVALID_RESOURCE_LIST',
1773                               p_token1         => 'PROJECT',
1774                               p_value1         =>  l_amg_project_rec.segment1);
1775 
1776                            IF l_debug_mode = 'Y' THEN
1777                                   pa_debug.g_err_stage:= 'Resource list passed is invalid';
1778                                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1779                            END IF;
1780 
1781 
1782                            x_return_status := FND_API.G_RET_STS_ERROR;
1783                            l_any_error_occurred_flag := 'Y';
1784 
1785                      END IF;
1786 
1787                      /* changes for bug 3954329: following check included */
1788                      BEGIN
1789                            SELECT migration_code
1790                            INTO   l_res_list_migration_code
1791                            FROM   pa_resource_lists_all_bg
1792                            WHERE  resource_list_id = px_resource_list_id;
1793                      EXCEPTION
1794                            WHEN NO_DATA_FOUND THEN
1795                                  x_return_status := FND_API.G_RET_STS_ERROR;
1796                                  PA_UTILS.ADD_MESSAGE
1797                                    (p_app_short_name => 'PA',
1798                                     p_msg_name       => 'PA_FP_INVALID_RESOURCE_LIST',
1799                                     p_token1         => 'PROJECT',
1800                                     p_value1         =>  l_amg_project_rec.segment1);
1801                                  x_return_status := FND_API.G_RET_STS_ERROR;
1802 
1803                                 l_any_error_occurred_flag := 'Y';
1804                                 IF l_debug_mode = 'Y' THEN
1805                                     pa_debug.g_err_stage:= 'error while deriving uncat res list';
1806                                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1807                                 END IF;
1808                      END;
1809                      IF l_res_list_migration_code IS NULL THEN
1810                            x_return_status := FND_API.G_RET_STS_ERROR;
1811                            l_any_error_occurred_flag := 'Y';
1812                            PA_UTILS.ADD_MESSAGE
1813                                 (p_app_short_name => 'PA',
1814                                  p_msg_name       => 'PA_FP_OLD_RES_LIST_NEW_MODEL');
1815                            IF l_debug_mode = 'Y' THEN
1816                                   pa_debug.g_err_stage:= 'res list is OLD in NEW budget model';
1817                                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1818                            END IF;
1819                      END IF;
1820                      /* bug 3954329 ends */
1821                   END IF;
1822                END IF;
1823 
1824             -- Get the Time Phasing
1825             IF ( px_time_phased_code IS NULL) THEN
1826 
1827                   IF l_debug_mode = 'Y' THEN
1828                         pa_debug.g_err_stage := 'Defaulting Time Phasing from the plan type' ;
1829                         pa_debug.write( l_module_name,pa_debug.g_err_stage, l_debug_level3);
1830                   END IF;
1831 
1832                   px_time_phased_code :=  l_plan_type_settings_rec.time_phased_code;
1833 
1834             ELSE -- validate the passed time phased code
1835 
1836             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1837             --Added the extra condition to check for time phasing as 'R'(Date Range) as date range time phasing is not supported in FP M.
1838 
1839                   IF  ((pa_fin_plan_utils.get_lookup_value( l_time_phasing_lookup,px_time_phased_code) IS NULL) OR (px_time_phased_code = 'R'))
1840                   THEN
1841 
1842                         IF l_debug_mode = 'Y' THEN
1843                               pa_debug.g_err_stage := 'Time Phased Code passed is '|| px_time_phased_code ;
1844                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1845                         END IF;
1846 
1847                         PA_UTILS.ADD_MESSAGE
1848                            (p_app_short_name => 'PA',
1849                             p_msg_name       => 'PA_FP_INVALID_TIME_PHASING',
1850                             p_token1         => 'PROJECT',
1851                             p_value1         =>  l_amg_project_rec.segment1,
1852                             p_token2         => 'PLAN_TYPE',
1853                             p_value2         =>  l_fin_plan_type_name);
1854 
1855                         x_return_status := FND_API.G_RET_STS_ERROR;
1856                         l_any_error_occurred_flag := 'Y';
1857 
1858 
1859             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1860             -- Call to Pa_Prj_Period_Profile_Utils.Get_Curr_Period_Profile_Info has become obsolete as per the FP M
1861             -- model so this condition has been commented out.
1862             --Comment START.
1863 /*
1864                   -- The time phasing passed is valid. Time phasing can not be 'PA' or 'GL' if the
1865                   -- period profile is not defined for the project.
1866                   ELSE
1867                         IF px_time_phased_code IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P,
1868                                                 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G) THEN
1869                               -- If the time phasing is either PA or GL check whether a period profile for that project
1870                               -- exists or not
1871                               IF px_time_phased_code = PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P THEN
1872                                     l_period_type := PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_PA;
1873                               ELSE
1874                                     l_period_type := PA_FP_CONSTANTS_PKG.G_PERIOD_TYPE_GL;
1875                               END IF;
1876 
1877                               Pa_Prj_Period_Profile_Utils.Get_Curr_Period_Profile_Info
1878                                    ( p_project_id          => px_pa_project_id,
1879                                      p_period_type         => l_period_type,
1880                                      p_period_profile_type => PA_FP_CONSTANTS_PKG.G_PD_PROFILE_FIN_PLANNING,
1881                                      x_period_profile_id   => l_period_profile_id,
1882                                      x_start_period        => l_start_period,
1883                                      x_end_period          => l_end_period,
1884                                      x_return_status       => x_return_status,
1885                                      x_msg_count           => x_msg_count,
1886                                      x_msg_data            => x_msg_data );
1887 
1888                               IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
1889 
1890                                     IF l_debug_mode = 'Y' THEN
1891                                           pa_debug.g_err_stage:= 'get current period profile gave error' ||px_pa_project_id;
1892                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1893 
1894                                     END IF;
1895                                     RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1896 
1897                               END IF;
1898 
1899                               IF(l_period_profile_id IS NULL) THEN
1900 
1901                                     PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
1902                                                          p_msg_name       => 'PA_FP_NO_PERIOD_PROFILE');
1903                                     x_return_status := FND_API.G_RET_STS_ERROR;
1904                                     l_any_error_occurred_flag := 'Y';
1905                                     IF l_debug_mode = 'Y' THEN
1906                                           pa_debug.g_err_stage:= 'Project does not have a period profile';
1907                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1908 
1909                                     END IF;
1910 
1911                               END IF;
1912                         END IF; --IF px_time_phased_code IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P,
1913 */
1914 
1915             --<Patchset M: B and F impact changes : AMG:>-- Bug # 3507156
1916             -- Replaced the call to Pa_Prj_Period_Profile_Utils.Get_Curr_Period_Profile_Info
1917             -- by a check for existence of record in pa_period_masks_b
1918 
1919                   ELSIF px_time_phased_code IN (PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_P,
1920                                                 PA_FP_CONSTANTS_PKG.G_TIME_PHASED_CODE_G) THEN
1921                        BEGIN
1922                        SELECT 'Y'
1923                        INTO l_exists
1924                        FROM dual
1925                        WHERE exists(SELECT 'X' FROM pa_period_masks_b WHERE trunc(sysdate) between  EFFECTIVE_START_DATE
1926                        AND nvl( EFFECTIVE_END_DATE,sysdate)
1927                        AND TIME_PHASE_CODE = px_time_phased_code);                  -- Bug # 3507156
1928 
1929                        EXCEPTION
1930                        WHEN no_data_found THEN
1931                        l_exists := 'N' ;  /* No record exists in pa_period_masks_b */
1932                        l_any_error_occurred_flag := 'Y';
1933 
1934                                    PA_UTILS.ADD_MESSAGE
1935                                         (p_app_short_name => 'PA',
1936                                          p_msg_name       => 'PA_FP_NO_PERIOD_MASK');
1937 
1938                        x_return_status := FND_API.G_RET_STS_ERROR;
1939                        END;
1940                   END IF; -- IF pa_fin_plan_utils.get_lookup_value
1941 
1942             END IF; -- IF(px_time_phased_code IS NULL) THEN
1943                                            --dbms_output.put_line('About to start mc');
1944 
1945             -- Multi currency flag validation.
1946 
1947             -- Depending on px_version_type initialise l_conv_attrs_to_be_validated
1948             IF (px_version_type <> PA_FP_CONSTANTS_PKG.G_VERSION_TYPE_ALL) THEN
1949                  l_conv_attrs_to_be_validated := px_version_type;
1950             ELSE
1951                  l_conv_attrs_to_be_validated := PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_BOTH;
1952             END IF;
1953 
1954 
1955             -- Get the project and project functional currencies.
1956             pa_fin_plan_utils.Get_Project_Curr_Attributes
1957             (  p_project_id                    => px_pa_project_id
1958               ,x_multi_currency_billing_flag   => l_multi_currency_billing_flag
1959               ,x_project_currency_code         => l_project_currency_code
1960               ,x_projfunc_currency_code        => l_projfunc_currency_code
1961               ,x_project_cost_rate_type        => l_project_cost_rate_type
1962               ,x_projfunc_cost_rate_type       => l_projfunc_cost_rate_type
1963               ,x_project_bil_rate_type         => l_project_bil_rate_type
1964               ,x_projfunc_bil_rate_type        => l_projfunc_bil_rate_type
1965               ,x_return_status                 => x_return_status
1966               ,x_msg_count                     => x_msg_count
1967               ,x_msg_data                      => x_msg_data);
1968 
1969             IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
1970 
1971                   IF l_debug_mode = 'Y' THEN
1972                         pa_debug.g_err_stage:= 'pa_fin_plan_utils.Get_Project_Curr_Attributes errored out for project' ||px_pa_project_id;
1973                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1974 
1975                   END IF;
1976                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
1977 
1978             END IF;
1979 
1980 
1981             -- Validate the MC flag.
1982             l_validate_mc_attributes := 'Y';
1983             IF (px_plan_in_multi_curr_flag IS NULL)   THEN
1984 
1985                   IF l_debug_mode = 'Y' THEN
1986                         pa_debug.g_err_stage := 'Defaulting MC from plan type' ;
1987                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
1988                   END IF;
1989 
1990                   px_plan_in_multi_curr_flag :=  l_proj_fp_options_rec.plan_in_multi_curr_flag ;
1991 
1992                   IF px_plan_in_multi_curr_flag = 'N' THEN
1993                         l_validate_mc_attributes := 'N';
1994 
1995                         px_projfunc_cost_rate_type := NULL;
1996                         px_projfunc_cost_rate_date_typ := NULL;
1997                         px_projfunc_cost_rate_date := NULL;
1998                         px_projfunc_rev_rate_type  := NULL;
1999                         px_projfunc_rev_rate_date_typ := NULL;
2000                         px_projfunc_rev_rate_date := NULL;
2001                         px_project_cost_rate_type := NULL;
2002                         px_project_cost_rate_date_typ := NULL;
2003                         px_project_cost_rate_date := NULL;
2004                         px_project_rev_rate_type  := NULL;
2005                         px_project_rev_rate_date_typ := NULL;
2006                         px_project_rev_rate_date  := NULL;
2007 
2008                   END IF;
2009 
2010             END IF;
2011 
2012             IF px_plan_in_multi_curr_flag = 'Y' THEN
2013                   -- if plan type does not allow MC then it is also not allowed at the version level.
2014                   IF  l_proj_fp_options_rec.plan_in_multi_curr_flag = 'N' THEN
2015 
2016                         IF l_debug_mode = 'Y' THEN
2017                               pa_debug.g_err_stage := 'mc is not enabled at plan type level';
2018                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2019                         END IF;
2020 
2021                         PA_UTILS.ADD_MESSAGE
2022                            (p_app_short_name => 'PA',
2023                             p_msg_name       => 'PA_FP_MC_MISMATCH',
2024                             p_token1         => 'PROJECT',
2025                             p_value1         =>  l_amg_project_rec.segment1,
2026                             p_token2         => 'PLAN_TYPE',
2027                             p_value2         =>  l_fin_plan_type_name);
2028 
2029                         x_return_status := FND_API.G_RET_STS_ERROR;
2030                         l_any_error_occurred_flag := 'Y';
2031                         l_validate_mc_attributes := 'N';
2032 
2033                   END IF;
2034 
2035                   --  when plan type is approved revenue and PC = PFC then its not allowed
2036                   --  to enable MC for revenue versions
2037                   IF l_proj_fp_options_rec.approved_rev_plan_type_flag = 'Y' AND
2038                      l_project_currency_code = l_projfunc_currency_code AND
2039                      px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE THEN
2040 
2041                         IF l_debug_mode = 'Y' THEN
2042                               pa_debug.g_err_stage := 'mc is wrongly enabled at version level';
2043                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2044                         END IF;
2045 
2046                         PA_UTILS.ADD_MESSAGE
2047                               (p_app_short_name => 'PA',
2048                                 p_msg_name      => 'PA_FP_INVALID_AR_AT_PROJ_TEMP');
2049                         x_return_status := FND_API.G_RET_STS_ERROR;
2050                         l_any_error_occurred_flag := 'Y';
2051 
2052                         l_validate_mc_attributes := 'N';
2053 
2054                   END IF;
2055 
2056             ELSIF px_plan_in_multi_curr_flag = 'N' THEN
2057 
2058                   l_validate_mc_attributes := 'N';
2059                   IF (l_project_currency_code <> l_projfunc_currency_code) THEN
2060                   --24-APR-03. Changes made for post_fpk by Xin Liu
2061             /*
2062                         IF l_debug_mode = 'Y' THEN
2063                               pa_debug.g_err_stage := 'mc should be enabled at version level since PC <> PFC';
2064                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2065                         END IF;
2066 
2067                         l_copy_conv_attr :=FALSE;
2068 
2069                         PA_UTILS.ADD_MESSAGE
2070                            (p_app_short_name => 'PA',
2071                             p_msg_name       => 'PA_FP_MC_DISABLED_AT_VER',
2072                             p_token1         => 'PROJECT',
2073                             p_value1         =>  l_amg_project_rec.segment1,
2074                             p_token2         => 'PLAN_TYPE',
2075                             p_value2         =>  l_fin_plan_type_name);
2076 
2077 
2078                         x_return_status := FND_API.G_RET_STS_ERROR;
2079                         l_any_error_occurred_flag := 'Y';
2080             */
2081                   l_validate_mc_attributes := 'Y';
2082                   px_plan_in_multi_curr_flag := 'Y';
2083                   --Done with changes
2084 
2085 
2086                   ELSE
2087 
2088                         px_projfunc_cost_rate_type := NULL;
2089                         px_projfunc_cost_rate_date_typ := NULL;
2090                         px_projfunc_cost_rate_date := NULL;
2091                         px_projfunc_rev_rate_type  := NULL;
2092                         px_projfunc_rev_rate_date_typ := NULL;
2093                         px_projfunc_rev_rate_date := NULL;
2094                         px_project_cost_rate_type := NULL;
2095                         px_project_cost_rate_date_typ := NULL;
2096                         px_project_cost_rate_date := NULL;
2097                         px_project_rev_rate_type  := NULL;
2098                         px_project_rev_rate_date_typ := NULL;
2099                         px_project_rev_rate_date  := NULL;
2100 
2101                   END IF;--IF (l_project_currency_code <> l_projfunc_currency_code) THEN
2102 
2103             ELSE--Invalid value for MC flagg
2104 
2105                   IF l_debug_mode = 'Y' THEN
2106                         pa_debug.g_err_stage := 'Value of mc flag is' ||px_plan_in_multi_curr_flag;
2107                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2108                   END IF;
2109 
2110                   PA_UTILS.ADD_MESSAGE
2111                      (p_app_short_name => 'PA',
2112                       p_msg_name       => 'PA_FP_INVALID_VAL_FOR_MC',
2113                       p_token1         => 'PROJECT',
2114                       p_value1         =>  l_amg_project_rec.segment1,
2115                       p_token2         => 'PLAN_TYPE',
2116                       p_value2         =>  l_fin_plan_type_name);
2117 
2118                   x_return_status := FND_API.G_RET_STS_ERROR;
2119                   l_any_error_occurred_flag := 'Y';
2120                   l_validate_mc_attributes := 'N';
2121 
2122 
2123             END IF; -- IF ( px_plan_in_multi_curr_flag = 'Y') THEN
2124 
2125             IF l_validate_mc_attributes = 'Y' THEN
2126 
2127                   IF (px_project_cost_rate_type        IS NULL     AND
2128                       px_project_cost_rate_date_typ    IS NULL     AND
2129                       px_project_cost_rate_date        IS NULL     AND
2130                       px_projfunc_cost_rate_type       IS NULL     AND
2131                       px_projfunc_cost_rate_date_typ   IS NULL     AND
2132                       px_projfunc_cost_rate_date       IS NULL     AND
2133                       px_project_rev_rate_type         IS NULL     AND
2134                       px_project_rev_rate_date_typ     IS NULL     AND
2135                       px_project_rev_rate_date         IS NULL     AND
2136                       px_projfunc_rev_rate_type        IS NULL     AND
2137                       px_projfunc_rev_rate_date_typ    IS NULL     AND
2138                       px_projfunc_rev_rate_date        IS NULL     ) THEN
2139 
2140                         IF l_debug_mode = 'Y' THEN
2141                             pa_debug.g_err_stage := 'Deriving the conversion attrs from plan type';
2142                             pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2143                         END IF;
2144 
2145                         px_projfunc_cost_rate_type    := l_proj_fp_options_rec.projfunc_cost_rate_type;
2146                         px_projfunc_cost_rate_date_typ:= l_proj_fp_options_rec.projfunc_cost_rate_date_type;
2147                         px_projfunc_cost_rate_date    := l_proj_fp_options_rec.projfunc_cost_rate_date;
2148                         px_projfunc_rev_rate_type     := l_proj_fp_options_rec.projfunc_rev_rate_type;
2149                         px_projfunc_rev_rate_date_typ := l_proj_fp_options_rec.projfunc_rev_rate_date_type;
2150                         px_projfunc_rev_rate_date     := l_proj_fp_options_rec.projfunc_rev_rate_date;
2151                         px_project_cost_rate_type     := l_proj_fp_options_rec.project_cost_rate_type;
2152                         px_project_cost_rate_date_typ := l_proj_fp_options_rec.project_cost_rate_date_type;
2153                         px_project_cost_rate_date     := l_proj_fp_options_rec.project_cost_rate_date;
2154                         px_project_rev_rate_type      := l_proj_fp_options_rec.project_rev_rate_type;
2155                         px_project_rev_rate_date_typ  := l_proj_fp_options_rec.project_rev_rate_date_type;
2156                         px_project_rev_rate_date      := l_proj_fp_options_rec.project_rev_rate_date;
2157 
2158                   -- Conversion attributes are passed. Validate them
2159                   ELSE
2160 
2161                         -- Null out the cost attributes for revenue version and vice versa              AMG UT2
2162                         IF l_conv_attrs_to_be_validated = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST THEN
2163 
2164                               px_project_rev_rate_type      :=NULL;
2165                               px_project_rev_rate_date_typ  :=NULL;
2166                               px_project_rev_rate_date      :=NULL;
2167 
2168                               px_projfunc_rev_rate_type     :=NULL;
2169                               px_projfunc_rev_rate_date_typ :=NULL;
2170                               px_projfunc_rev_rate_date     :=NULL;
2171 
2172                         ELSIF l_conv_attrs_to_be_validated = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE THEN
2173 
2174                               px_project_cost_rate_type      :=NULL;
2175                               px_project_cost_rate_date_typ  :=NULL;
2176                               px_project_cost_rate_date      :=NULL;
2177 
2178                               px_projfunc_cost_rate_type     :=NULL;
2179                               px_projfunc_cost_rate_date_typ :=NULL;
2180                               px_projfunc_cost_rate_date     :=NULL;
2181 
2182                         END IF;
2183 
2184                         -- If the rate type is not user at plan type and the rate type provided
2185                         -- is User then throw an error since the rates at the option level can not
2186                         -- be obtained
2187 
2188                         pa_budget_pvt.valid_rate_type
2189                               (p_pt_project_cost_rate_type => l_proj_fp_options_rec.project_cost_rate_type,
2190                                p_pt_project_rev_rate_type  => l_proj_fp_options_rec.project_rev_rate_type,
2191                                p_pt_projfunc_cost_rate_type=> l_proj_fp_options_rec.projfunc_cost_rate_type,
2192                                p_pt_projfunc_rev_rate_type => l_proj_fp_options_rec.projfunc_rev_rate_type,
2193                                p_pv_project_cost_rate_type => px_project_cost_rate_type,
2194                                p_pv_project_rev_rate_type  => px_project_rev_rate_type,
2195                                p_pv_projfunc_cost_rate_type=> px_projfunc_cost_rate_type,
2196                                p_pv_projfunc_rev_rate_type => px_projfunc_rev_rate_type,
2197                                x_is_rate_type_valid        => l_is_rate_type_valid,
2198                                x_return_status             => x_return_status,
2199                                x_msg_count                 => x_msg_count,
2200                                x_msg_data                  => x_msg_data);
2201 
2202                         IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2203 
2204                               IF l_debug_mode = 'Y' THEN
2205                                           pa_debug.g_err_stage:= 'valid_rate_type returned error';
2206                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2207                               END IF;
2208 
2209                               RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2210 
2211                         END IF;
2212 
2213                         IF NOT l_is_rate_type_valid THEN
2214 
2215                               IF l_debug_mode = 'Y' THEN
2216                                     pa_debug.g_err_stage := 'mc is wrongly enabled at version level';
2217                                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2218                               END IF;
2219 
2220                               PA_UTILS.ADD_MESSAGE
2221                               (p_app_short_name => 'PA',
2222                                p_msg_name       => 'PA_FP_RATE_TYPE_NOT_USER_AT_PT',
2223                                p_token1         => 'PROJECT',
2224                                p_value1         =>  l_amg_project_rec.segment1,
2225                                p_token2         => 'PLAN_TYPE',
2226                                p_value2         =>  l_fin_plan_type_name);
2227 
2228                               x_return_status := FND_API.G_RET_STS_ERROR;
2229                               l_any_error_occurred_flag := 'Y';
2230 
2231                         ELSE
2232                                --dbms_output.put_line('The value of l_conv_attrs_to_be_validated is ' ||l_conv_attrs_to_be_validated);
2233 
2234                               pa_fin_plan_utils.validate_currency_attributes
2235                               (px_project_cost_rate_type      =>px_project_cost_rate_type
2236                               ,px_project_cost_rate_date_typ  =>px_project_cost_rate_date_typ
2237                               ,px_project_cost_rate_date      =>px_project_cost_rate_date
2238                               ,px_project_cost_exchange_rate  =>l_project_cost_exchange_rate
2239                               ,px_projfunc_cost_rate_type     =>px_projfunc_cost_rate_type
2240                               ,px_projfunc_cost_rate_date_typ =>px_projfunc_cost_rate_date_typ
2241                               ,px_projfunc_cost_rate_date     =>px_projfunc_cost_rate_date
2242                               ,px_projfunc_cost_exchange_rate =>l_projfunc_cost_exchange_rate
2243                               ,px_project_rev_rate_type       =>px_project_rev_rate_type
2244                               ,px_project_rev_rate_date_typ   =>px_project_rev_rate_date_typ
2245                               ,px_project_rev_rate_date       =>px_project_rev_rate_date
2246                               ,px_project_rev_exchange_rate   =>l_project_rev_exchange_rate
2247                               ,px_projfunc_rev_rate_type      =>px_projfunc_rev_rate_type
2248                               ,px_projfunc_rev_rate_date_typ  =>px_projfunc_rev_rate_date_typ
2249                               ,px_projfunc_rev_rate_date      =>px_projfunc_rev_rate_date
2250                               ,px_projfunc_rev_exchange_rate  =>l_projfunc_rev_exchange_rate
2251                               ,p_project_currency_code        =>l_project_currency_code
2252                               ,p_projfunc_currency_code       =>l_projfunc_currency_code
2253                               ,p_context                      =>PA_FP_CONSTANTS_PKG.G_AMG_API_HEADER
2254                               ,p_attrs_to_be_validated        =>l_conv_attrs_to_be_validated
2255                               ,x_return_status                =>x_return_status
2256                               ,x_msg_count                    =>x_msg_count
2257                               ,x_msg_data                     =>x_msg_data);
2258 
2259                               IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2260                                     x_return_status:=FND_API.G_RET_STS_ERROR;
2261 
2262                                     IF l_debug_mode = 'Y' THEN
2263                                           pa_debug.g_err_stage:= 'Validate currency attributes returned error';
2264                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2265                                     END IF;
2266                                     l_any_error_occurred_flag := 'Y';
2267                               END IF;
2268                         END IF;
2269 
2270                   END IF;-- For If where all the conv attrs are checked for NULL
2271             END IF;--l_validate_mc_attributes = 'Y'
2272 
2273  -- Added for Bug#5510196 START
2274 
2275                      px_revenue_flag := nvl(px_revenue_flag,'N');
2276                      px_revenue_qty_flag := nvl(px_revenue_qty_flag,'N');
2277 
2278                      px_raw_cost_flag:= nvl(px_raw_cost_flag,'N');
2279                      px_burdened_cost_flag := nvl(px_burdened_cost_flag,'N');
2280                      px_cost_qty_flag := nvl(px_cost_qty_flag,'N');
2281                      px_all_qty_flag := nvl(px_all_qty_flag,'N');
2282 
2283    -- Addeed for Bug#5510196 END
2284 
2285 
2286             --  Validate amount and quantity flags
2287             IF( px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST) THEN
2288 
2289                   px_raw_cost_flag:= nvl(px_raw_cost_flag,'N');
2290                   px_burdened_cost_flag := nvl(px_burdened_cost_flag,'N');
2291                   px_cost_qty_flag := nvl(px_cost_qty_flag,'N');
2292 
2293                   IF( px_raw_cost_flag     NOT IN ('Y','N')) OR
2294                     ( px_burdened_cost_flag NOT IN ('Y','N')) OR
2295                     ( px_cost_qty_flag     NOT IN ('Y','N')) THEN
2296 
2297                         PA_UTILS.ADD_MESSAGE
2298                              (p_app_short_name => 'PA',
2299                               p_msg_name       => 'PA_FP_INVALID_AMT_FLAGS',
2300                               p_token1         => 'PROJECT',
2301                               p_value1         =>  l_amg_project_rec.segment1,
2302                               p_token2         => 'PLAN_TYPE',
2303                               p_value2         =>  l_fin_plan_type_name);
2304                         x_return_status := FND_API.G_RET_STS_ERROR;
2305                         l_any_error_occurred_flag := 'Y';
2306                         IF l_debug_mode = 'Y' THEN
2307                               pa_debug.g_err_stage:= 'Invalid values for amount flags ';
2308                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2309                         END IF;
2310                   END IF;
2311 
2312 
2313                   IF( px_raw_cost_flag     = 'N') AND
2314                     ( px_burdened_cost_flag = 'N') AND
2315                     ( px_cost_qty_flag     = 'N') THEN
2316 
2317                         PA_UTILS.ADD_MESSAGE
2318                              (p_app_short_name => 'PA',
2319                               p_msg_name       => 'PA_FP_NO_PLAN_AMT_CHECKED');
2320                         x_return_status := FND_API.G_RET_STS_ERROR;
2321                         l_any_error_occurred_flag := 'Y';
2322                         IF l_debug_mode = 'Y' THEN
2323                               pa_debug.g_err_stage:= 'None of the amount flags are Y ';
2324                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2325                         END IF;
2326                   END IF;
2327 
2328             ELSIF( px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE ) THEN
2329 
2330                   px_revenue_flag := nvl(px_revenue_flag,'N');
2331                   px_revenue_qty_flag := nvl(px_revenue_qty_flag,'N');
2332 
2333                   IF( px_revenue_flag     NOT IN ('Y','N')) OR
2334                     ( px_revenue_qty_flag NOT IN ('Y','N')) THEN
2335 
2336                         PA_UTILS.ADD_MESSAGE
2337                              (p_app_short_name => 'PA',
2338                               p_msg_name       => 'PA_FP_INVALID_AMT_FLAGS',
2339                               p_token1         => 'PROJECT',
2340                               p_value1         =>  l_amg_project_rec.segment1,
2341                               p_token2         => 'PLAN_TYPE',
2342                               p_value2         =>  l_fin_plan_type_name);
2343                         x_return_status := FND_API.G_RET_STS_ERROR;
2344                         l_any_error_occurred_flag := 'Y';
2345                         IF l_debug_mode = 'Y' THEN
2346                               pa_debug.g_err_stage:= 'Invalid value for the amount flags ';
2347                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2348                         END IF;
2349 
2350                   END IF;
2351 
2352 
2353                   IF( px_revenue_flag     ='N') AND
2354                     ( px_revenue_qty_flag ='N') THEN
2355 
2356                         PA_UTILS.ADD_MESSAGE
2357                              (p_app_short_name => 'PA',
2358                               p_msg_name       => 'PA_FP_NO_PLAN_AMT_CHECKED');
2359                         x_return_status := FND_API.G_RET_STS_ERROR;
2360                         l_any_error_occurred_flag := 'Y';
2361                         IF l_debug_mode = 'Y' THEN
2362                               pa_debug.g_err_stage:= 'None of the amount flags are Y ';
2363                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2364                         END IF;
2365 
2366                   END IF;
2367 
2368             ELSIF( px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL ) THEN
2369 
2370                   px_raw_cost_flag:= nvl(px_raw_cost_flag,'N');
2371                   px_burdened_cost_flag := nvl(px_burdened_cost_flag,'N');
2372                   px_revenue_flag := nvl(px_revenue_flag,'N');
2373                   px_all_qty_flag := nvl(px_all_qty_flag,'N');
2374 
2375                   IF( px_raw_cost_flag      NOT IN ('Y','N')) OR
2376                     ( px_burdened_cost_flag NOT IN ('Y','N')) OR
2377                     ( px_revenue_flag       NOT IN ('Y','N')) OR
2378                     ( px_all_qty_flag       NOT IN ('Y','N')) THEN
2379 
2380                         PA_UTILS.ADD_MESSAGE
2381                              (p_app_short_name => 'PA',
2382                               p_msg_name       => 'PA_FP_INVALID_AMT_FLAGS',
2383                               p_token1         => 'PROJECT',
2384                               p_value1         =>  l_amg_project_rec.segment1,
2385                               p_token2         => 'PLAN_TYPE',
2386                               p_value2         =>  l_fin_plan_type_name);
2387                         x_return_status := FND_API.G_RET_STS_ERROR;
2388                         l_any_error_occurred_flag := 'Y';
2389                         IF l_debug_mode = 'Y' THEN
2390                               pa_debug.g_err_stage:= 'Invalid value for the amount flags ';
2391                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2392                         END IF;
2393 
2394                   END IF;
2395 
2396 		  IF( px_raw_cost_flag     ='N') AND
2397                     ( px_burdened_cost_flag='N') AND
2398                     ( px_revenue_flag      ='N') AND
2399                     ( px_cost_qty_flag     = 'N') AND			--Fix for 7172129
2400                     ( px_revenue_qty_flag ='N') AND
2401                     ( px_all_qty_flag      ='N') THEN
2402 
2403 			PA_UTILS.ADD_MESSAGE
2404                         (p_app_short_name => 'PA',
2405                         p_msg_name       => 'PA_FP_NO_PLAN_AMT_CHECKED');
2406                         x_return_status := FND_API.G_RET_STS_ERROR;
2407                         l_any_error_occurred_flag := 'Y';
2408                         IF l_debug_mode = 'Y' THEN
2409                               pa_debug.g_err_stage:= 'None of the amount flags are Y ';
2410                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2411                         END IF;
2412 
2413                   END IF;
2414 
2415             END IF; -- Validate amount and quantity flags
2416 
2417             -- Check create_new_working_flag and replace_current_working_flag
2418             IF ( p_create_new_curr_working_flag IS NULL  OR
2419                  p_replace_current_working_flag IS NULL OR
2420                  p_create_new_curr_working_flag NOT IN ('Y','N') OR
2421                  p_replace_current_working_flag NOT IN ('Y','N')) THEN
2422 
2423                   PA_UTILS.ADD_MESSAGE
2424                            (p_app_short_name => 'PA',
2425                             p_msg_name       => 'PA_FP_CR_REP_FLAGS_INVALID',
2426                             p_token1         => 'PROJECT',
2427                             p_value1         =>  l_amg_project_rec.segment1,
2428                             p_token2         => 'PLAN_TYPE',
2429                             p_value2         =>  l_fin_plan_type_name);
2430 
2431                   x_return_status := FND_API.G_RET_STS_ERROR;
2432                   l_any_error_occurred_flag := 'Y';
2433                   IF l_debug_mode = 'Y' THEN
2434                         pa_debug.g_err_stage:= 'Create replace CW version flags are invalid ';
2435                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2436                   END IF;
2437 
2438 
2439             --Create and Replace flags have valid values
2440             ELSE
2441 
2442                   IF (p_replace_current_working_flag = 'Y' OR
2443                        p_create_new_curr_working_flag = 'Y')  THEN
2444 
2445                         -- Get the status of the current working version. If the status is submitted then
2446                         -- it can not be updated/deleted
2447                         OPEN  l_finplan_CW_ver_csr(px_pa_project_id,px_fin_plan_type_id,px_version_type);
2448                         FETCH l_finplan_CW_ver_csr
2449                         INTO  l_finplan_CW_ver_rec;
2450 
2451                         IF( l_finplan_CW_ver_csr%NOTFOUND) THEN
2452 
2453                               IF l_debug_mode = 'Y' THEN
2454                                     pa_debug.g_err_stage := 'A working version does not exist for the project '||px_pa_project_id;
2455                                     pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2456                               END IF;
2457                               CLOSE l_finplan_CW_ver_csr;
2458 
2459                         ELSE
2460 
2461                               CLOSE l_finplan_CW_ver_csr;
2462 
2463                               IF l_debug_mode = 'Y' THEN
2464                                     pa_debug.g_err_stage := 'One of the create  replace flags is Y';
2465                                     pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level3);
2466                               END IF;
2467 
2468                               IF nvl(l_finplan_CW_ver_rec.budget_status_code,'X') = 'S' THEN
2469                                     IF l_debug_mode = 'Y' THEN
2470                                           pa_debug.g_err_stage := 'Version exists in submitted status';
2471                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2472                                     END IF;
2473 
2474                                     pa_interface_utils_pub.map_new_amg_msg
2475                                       ( p_old_message_code => 'PA_BUDGET_IS_SUBMITTED'
2476                                        ,p_msg_attribute    => 'CHANGE'
2477                                        ,p_resize_flag      => 'N'
2478                                        ,p_msg_context      => 'BUDG'
2479                                        ,p_attribute1       => l_amg_project_rec.segment1
2480                                        ,p_attribute2       => ''
2481                                        ,p_attribute3       => l_fin_plan_type_name
2482                                        ,p_attribute4       => ''
2483                                        ,p_attribute5       => '');
2484                                     x_return_status := FND_API.G_RET_STS_ERROR;
2485                                     l_any_error_occurred_flag := 'Y';
2486 
2487                               IF l_finplan_CW_ver_rec.plan_processing_code IN ('XLUE','XLUP') THEN
2488 
2489                                   pa_fin_plan_utils.return_and_vldt_plan_prc_code
2490                                  (p_plan_processing_code    =>   l_finplan_CW_ver_rec.plan_processing_code
2491                                   ,x_final_plan_prc_code    =>   l_finplan_CW_ver_rec.plan_processing_code
2492                                   ,x_targ_request_id        =>   l_targ_request_id
2493                                   ,x_return_status          =>   x_return_status
2494                                   ,x_msg_count              =>   x_msg_count
2495                                   ,x_msg_data               =>   x_msg_data);
2496 
2497                                   IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2498                                         x_return_status:=FND_API.G_RET_STS_ERROR;
2499 
2500                                         IF l_debug_mode = 'Y' THEN
2501                                               pa_debug.g_err_stage:= 'pa_fin_plan_utils.return_and_vldt_plan_prc_code returned error';
2502                                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2503                                         END IF;
2504                                         l_any_error_occurred_flag := 'Y';
2505                                   END IF;
2506 
2507                               END IF;
2508 
2509                               END IF; -- if budget version is in submitted status.
2510 
2511                         END IF;--IF( l_finplan_CW_ver_csr%NOTFOUND) THEN
2512 
2513                   END IF;--IF ((p_replace_current_working_flag <> 'N' OR
2514 
2515             END IF;  -- p_create_new_curr_working_flag IS NULL  OR
2516 
2517       END IF; -- END OF CHECKS FOR FINPLAN MODEL
2518 
2519       -- check validity of the budget change reason code, passing NULL is OK
2520 
2521       IF (p_change_reason_code IS NOT NULL AND
2522           p_change_reason_code  <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
2523 
2524             --dbms_output.put_line('In head p_change_reason_code is '||p_change_reason_code);
2525             OPEN l_budget_change_reason_csr( p_change_reason_code );
2526             FETCH l_budget_change_reason_csr INTO l_dummy;
2527             IF (p_budget_type_code IS NULL  OR
2528                  p_budget_type_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR ) THEN
2529 
2530                   l_context_info := l_fin_plan_type_name;
2531 
2532             ELSE
2533 
2534                   l_context_info := p_budget_type_code;
2535 
2536             END IF;
2537             IF l_budget_change_reason_csr%NOTFOUND THEN
2538                   CLOSE l_budget_change_reason_csr;
2539 
2540                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2541                   THEN
2542                         pa_interface_utils_pub.map_new_amg_msg
2543                         ( p_old_message_code => 'PA_CHANGE_REASON_INVALID'
2544                         ,p_msg_attribute    => 'CHANGE'
2545                         ,p_resize_flag      => 'N'
2546                         ,p_msg_context      => 'BUDG'
2547                         ,p_attribute1       => l_amg_project_rec.segment1
2548                         ,p_attribute2       => ''
2549                         ,p_attribute3       => l_context_info
2550                         ,p_attribute4       => ''
2551                         ,p_attribute5       => '');
2552                         IF l_debug_mode = 'Y' THEN
2553                               pa_debug.g_err_stage:= 'Invalid Change Reason code ';
2554                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2555                         END IF;
2556                   END IF;
2557                   x_return_status := FND_API.G_RET_STS_ERROR;
2558                   l_any_error_occurred_flag := 'Y';
2559 
2560                   --RAISE FND_API.G_EXC_ERROR;
2561 
2562             ELSE
2563 
2564                   CLOSE l_budget_change_reason_csr;
2565             END IF;
2566 
2567 
2568 
2569       END IF;--IF (p_change_reason_code IS NOT NULL AND
2570                                --dbms_output.put_line('Leaving val header info');
2571       IF(l_debug_mode='Y') THEN
2572             pa_debug.g_err_stage := 'Leaving validate_header_info';
2573             pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2574       END IF;
2575 
2576       -- Stop further processing if any errors are reported
2577        --dbms_output.put_line('MSG count in the stack ' || FND_MSG_PUB.count_msg);
2578       IF(l_any_error_occurred_flag='Y') THEN
2579             IF(l_debug_mode='Y') THEN
2580                   pa_debug.g_err_stage := 'About to display all the messages';
2581                   pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
2582             END IF;
2583              x_return_status := FND_API.G_RET_STS_ERROR;
2584             l_any_error_occurred_flag := 'Y';
2585             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2586       END IF;
2587 
2588 	  IF l_debug_mode = 'Y' THEN
2589 	      pa_debug.reset_curr_function;
2590 	  END IF;
2591 EXCEPTION
2592 
2593       WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
2594             IF x_return_status IS NULL OR
2595                x_return_status =  FND_API.G_RET_STS_SUCCESS THEN
2596                   x_return_status := FND_API.G_RET_STS_ERROR;
2597             END IF;
2598 
2599             l_msg_count := FND_MSG_PUB.count_msg;
2600              --dbms_output.put_line('MSG count in the stack ' || l_msg_count);
2601 
2602             IF l_msg_count = 1 AND x_msg_data IS NULL THEN
2603                   PA_INTERFACE_UTILS_PUB.get_messages
2604                        (p_encoded        => FND_API.G_TRUE,
2605                         p_msg_index      => 1,
2606                         p_msg_count      => l_msg_count,
2607                         p_msg_data       => l_msg_data,
2608                         p_data           => l_data,
2609                         p_msg_index_out  => l_msg_index_out);
2610 
2611                   x_msg_data  := l_data;
2612                   x_msg_count := l_msg_count;
2613             ELSE
2614                   x_msg_count := l_msg_count;
2615             END IF;
2616              --dbms_output.put_line('MSG count in the stack ' || l_msg_count);
2617 
2618         IF l_debug_mode = 'Y' THEN
2619             pa_debug.reset_curr_function;
2620 	END IF;
2621             RETURN;
2622 
2623       WHEN OTHERS THEN
2624             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2625             x_msg_count     := 1;
2626             x_msg_data      := SQLERRM;
2627 
2628             FND_MSG_PUB.add_exc_msg
2629             ( p_pkg_name       => 'PA_BUDGET_PVT'
2630             ,p_procedure_name  => 'VALIDATE_HEADER_INFO'
2631             ,p_error_text      => sqlerrm);
2632 
2633 	    IF l_debug_mode = 'Y' THEN
2634                   pa_debug.G_Err_Stack := SQLERRM;
2635                   pa_debug.write( l_module_name,pa_debug.G_Err_Stack,4);
2636                   pa_debug.reset_curr_function;
2637             END IF;
2638             RAISE;
2639 
2640 END VALIDATE_HEADER_INFO;
2641 
2642 
2643 --###This API is an overloaded version of an already existing procedure. It is
2644 --created as part of FP.M Changes for FP AMG Apis. All header level validations
2645 --required for PA_BUDGET_PUB.add_budget_line have been added to this API.
2646 --This API handles validations for budget versions in new as well as old models.
2647 
2648 -- 26-APR-2005  Ritesh Shukla   Created.
2649 -- 01-Jun-2005  Ritesh Shukla   Bug 4224464: Commented out the budgetary control check
2650 --                              in this API as per the discussions between PM and Dev.
2651 --                              At present this API is being called from following APIs:
2652 --                              PA_BUDGET_PBU.add_budget_line
2653 --                              PA_BUDGET_PBU.update_budget_line
2654 --                              PA_BUDGET_PBU.delete_budget_line
2655 --                              PA_BUDGET_PBU.update_budget
2656 --                              These APIs do not require the budgetary control check.
2657 --                              If in future this API is called from any API that
2658 --                              requires the budgetary control check then this code may
2659 --                              be uncommented and following design suggested by
2660 --                              Jeff White (PM) may be used. "Add a IN-paramter,
2661 --                              say p_budgetary_control_flag (Y to enforece edit,
2662 --                              N to disable edit) Default 'N'.
2663 --
2664 -- 27-SEP-2005 jwhite           -Bug 4588279
2665 --                               For overloaded procedure Validate_Header_Info,
2666 --                               1) Renabled the budgetary control api call.
2667 --                               2) Rewrote logic to populate a package global for budget LINE validation
2668 --                                  by pa_budget_check_pvt.GET_VALID_PERIOD_DATES_PVT procedure.
2669 --
2670 --                               Note:
2671 --                               1)   For the PA_BUDGET_PBU.delete_budget_line, this procedure is NOT impacted
2672 --                                    by these code changes. Also, it is OK to delete budget lines for
2673 --                                    budgetary control project/budget-types.
2674 -- 21-Oct-2008 rthumma          -Bug 7498493
2675 --                               Added a variable px_pa_project_id_tmp to prevent the error
2676 --                               PA_PROJECT_REF_AND_ID_MISSING
2677 --
2678 --
2679 
2680 
2681 
2682 
2683 PROCEDURE Validate_Header_Info
2684 ( p_api_version_number            IN            NUMBER
2685  ,p_api_name                      IN            VARCHAR2
2686  ,p_init_msg_list                 IN            VARCHAR2
2687  ,px_pa_project_id                IN OUT NOCOPY NUMBER
2688  ,p_pm_project_reference          IN            VARCHAR2
2689  ,p_pm_product_code               IN            VARCHAR2
2690  ,px_budget_type_code             IN OUT NOCOPY VARCHAR2
2691  ,px_fin_plan_type_id             IN OUT NOCOPY NUMBER
2692  ,px_fin_plan_type_name           IN OUT NOCOPY VARCHAR2
2693  ,px_version_type                 IN OUT NOCOPY VARCHAR2
2694  ,p_budget_version_number         IN            NUMBER
2695  ,p_change_reason_code            IN            VARCHAR2
2696  ,p_function_name                 IN            VARCHAR2
2697  ,x_budget_entry_method_code      OUT    NOCOPY VARCHAR2
2698  ,x_resource_list_id              OUT    NOCOPY NUMBER
2699  ,x_budget_version_id             OUT    NOCOPY NUMBER
2700  ,x_fin_plan_level_code           OUT    NOCOPY VARCHAR2
2701  ,x_time_phased_code              OUT    NOCOPY VARCHAR2
2702  ,x_plan_in_multi_curr_flag       OUT    NOCOPY VARCHAR2
2703  ,x_budget_amount_code            OUT    NOCOPY VARCHAR2
2704  ,x_categorization_code           OUT    NOCOPY VARCHAR2
2705  ,x_project_number                OUT    NOCOPY VARCHAR2
2706  /* Plan Amount Entry flags introduced by bug 6408139 */
2707  ,px_raw_cost_flag                IN OUT NOCOPY   VARCHAR2
2708  ,px_burdened_cost_flag           IN OUT NOCOPY   VARCHAR2
2709  ,px_revenue_flag                 IN OUT NOCOPY   VARCHAR2
2710  ,px_cost_qty_flag                IN OUT NOCOPY   VARCHAR2
2711  ,px_revenue_qty_flag             IN OUT NOCOPY   VARCHAR2
2712  ,px_all_qty_flag                 IN OUT NOCOPY   VARCHAR2
2713  ,px_bill_rate_flag               IN OUT NOCOPY   VARCHAR2
2714  ,px_cost_rate_flag               IN OUT NOCOPY   VARCHAR2
2715  ,px_burden_rate_flag             IN OUT NOCOPY   VARCHAR2
2716  /* Plan Amount Entry flags introduced by bug 6408139 */
2717  ,x_msg_count                     OUT    NOCOPY NUMBER
2718  ,x_msg_data                      OUT    NOCOPY VARCHAR2
2719  ,x_return_status                 OUT    NOCOPY VARCHAR2)
2720 
2721 IS
2722 
2723       --This cursor is used to check if a fin_plan_type_id is
2724       --used to store workplan data
2725       CURSOR l_use_for_wp_csr
2726       ( p_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE)
2727       IS
2728       SELECT 1
2729       FROM pa_fin_plan_types_b
2730       WHERE fin_plan_type_id = p_fin_plan_type_id
2731       AND   use_for_workplan_flag = 'Y';
2732 
2733       --Cursor to get the details of the budget entry method passed
2734       CURSOR  l_budget_entry_method_csr
2735              (c_budget_entry_method_code pa_budget_entry_methods.budget_entry_method_code%type )
2736       IS
2737       SELECT entry_level_code
2738             ,categorization_code
2739             ,time_phased_type_code
2740       FROM   pa_budget_entry_methods
2741       WHERE  budget_entry_method_code = c_budget_entry_method_code
2742       AND    trunc(sysdate) BETWEEN trunc(start_date_active) and trunc(nvl(end_date_active,sysdate));
2743 
2744       --Cursor to get the plan type details of the version being created.
2745       CURSOR  l_proj_fp_options_csr
2746             ( c_project_id          pa_projects.project_id%TYPE
2747              ,c_fin_plan_type_id    pa_fin_plan_types_b.fin_plan_type_id%TYPE
2748              ,c_version_type        pa_budget_versions.version_type%TYPE
2749              ,c_fin_plan_version_id pa_budget_versions.budget_version_id%TYPE)
2750       IS
2751       SELECT nvl(plan_in_multi_curr_flag,'N') multi_curr_flag
2752             ,decode(c_version_type,
2753                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST, cost_fin_plan_level_code,
2754                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE, revenue_fin_plan_level_code,
2755                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL, all_fin_plan_level_code) fin_plan_level_code
2756             ,decode(c_version_type,
2757                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST, cost_resource_list_id,
2758                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE, revenue_resource_list_id,
2759                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL, all_resource_list_id)  resource_list_id
2760             ,decode(c_version_type,
2761                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST, cost_time_phased_code,
2762                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE, revenue_time_phased_code,
2763                    PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL, all_time_phased_code)  time_phased_code
2764       FROM   pa_proj_fp_options
2765       WHERE  project_id=c_project_id
2766       AND    fin_plan_type_id=c_fin_plan_type_id
2767       AND    fin_plan_version_id = c_fin_plan_version_id;
2768 
2769 
2770       -- Cursor to get the segment 1 of the project.
2771       CURSOR l_amg_project_csr
2772             (c_project_id pa_projects_all.project_id%TYPE)
2773       IS
2774       SELECT segment1
2775       FROM   pa_projects_all
2776       WHERE  project_id=c_project_id;
2777 
2778       -- Cursor used in validating the product code
2779       Cursor p_product_code_csr (c_pm_product_code IN VARCHAR2)
2780       Is
2781       Select 'X'
2782       from   pa_lookups
2783       where  lookup_type='PM_PRODUCT_CODE'
2784       and    lookup_code = c_pm_product_code;
2785 
2786       -- needed to get the related budget_version, entry_method and resource_list
2787       CURSOR  l_budget_version_csr
2788               ( c_project_id          NUMBER
2789               , c_budget_type_code    VARCHAR2 )
2790       IS
2791       SELECT budget_version_id
2792       ,      budget_entry_method_code
2793       ,      resource_list_id
2794       FROM   pa_budget_versions
2795       WHERE  project_id        = c_project_id
2796       AND    budget_type_code  = c_budget_type_code
2797       AND    budget_status_code    = 'W'
2798       AND    ci_id IS NULL;
2799 
2800       --Cursor to get FinPlan ver id for a FinPlan version
2801       CURSOR l_finplan_version_id_csr
2802              (c_project_id        NUMBER
2803              ,c_fin_plan_type_id  NUMBER
2804              ,c_version_type      VARCHAR2
2805              ,c_version_number    NUMBER )
2806       IS
2807       SELECT budget_version_id
2808       FROM   pa_budget_versions
2809       WHERE  project_id=c_project_id
2810       AND    fin_plan_type_id=c_fin_plan_type_id
2811       AND    version_type=c_version_type
2812       AND    version_number=c_version_number
2813       AND    budget_status_code='W'
2814       AND    ci_id is null;
2815 
2816       l_data                           VARCHAR2(2000);
2817       l_msg_index_out                  NUMBER;
2818       l_debug_mode                     VARCHAR2(1);
2819       l_module_name                    VARCHAR2(80);
2820 
2821       l_security_ret_code              VARCHAR2(1);
2822       l_dummy                          NUMBER;
2823       l_dummy1                         VARCHAR2(1); -- Bug 5359585;
2824       l_debug_level2                   CONSTANT NUMBER := 2;
2825       l_debug_level3                   CONSTANT NUMBER := 3;
2826       l_debug_level4                   CONSTANT NUMBER := 4;
2827       l_debug_level5                   CONSTANT NUMBER := 5;
2828       l_pm_product_code                VARCHAR2(2) :='Z';
2829       l_result                         VARCHAR2(30);
2830       l_locked_by_persion_id           pa_budget_versions.locked_by_person_id%TYPE;
2831       l_val_err_code                   VARCHAR2(30);
2832 
2833       -- Following variable will be set when atleast one error
2834       -- is reported while validating the input parameters
2835       -- passed by the user
2836       l_any_error_occurred_flag        VARCHAR2(1) :='N';
2837 
2838       l_context_info                   pa_fin_plan_types_tl.name%TYPE;
2839       l_plan_processing_code           pa_budget_versions.plan_processing_code%TYPE;
2840 
2841       --Local variables needed for calling Funds Check API
2842       l_fck_req_flag                   VARCHAR2(1) := NULL;
2843       l_bdgt_intg_flag                 VARCHAR2(1) := NULL;
2844       l_bdgt_ver_id                    NUMBER      := NULL;
2845       l_encum_type_id                  NUMBER      := NULL;
2846 
2847       l_balance_type                   VARCHAR2(1) := NULL;
2848 
2849       l_targ_request_id                pa_budget_versions.request_id%TYPE;
2850       /*Variables added for bug 6408139*/
2851       l_amount_set_id       pa_proj_fp_options.all_amount_set_id%TYPE;
2852       lx_raw_cost_flag                  VARCHAR2(1) ;
2853       lx_burdened_cost_flag             VARCHAR2(1);
2854       lx_revenue_flag                   VARCHAR2(1);
2855       lx_cost_qty_flag                  VARCHAR2(1);
2856       lx_revenue_qty_flag               VARCHAR2(1);
2857       lx_all_qty_flag                   VARCHAR2(1);
2858       lx_bill_rate_flag                 VARCHAR2(1);
2859       lx_cost_rate_flag                 VARCHAR2(1);
2860       lx_burden_rate_flag               VARCHAR2(1);
2861       px_pa_project_id_tmp NUMBER := NULL;    /* Bug 7498493 */
2862 
2863 BEGIN
2864 
2865 
2866       x_msg_count :=0;
2867       x_return_status := FND_API.G_RET_STS_SUCCESS;
2868       l_debug_mode  := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
2869       l_module_name := g_module_name || 'validate_header_info: ';
2870 
2871       IF l_debug_mode = 'Y' THEN
2872             pa_debug.set_curr_function( p_function   => 'validate_header_info',
2873                                         p_debug_mode => l_debug_mode );
2874       END IF;
2875 
2876       -- Initialize the message table if requested.
2877       IF FND_API.TO_BOOLEAN( p_init_msg_list )
2878       THEN
2879         FND_MSG_PUB.initialize;
2880       END IF;
2881 
2882       IF l_debug_mode = 'Y' THEN
2883               pa_debug.g_err_stage:= 'Validating input parameters';
2884               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
2885       END IF;
2886 
2887 
2888       --Standard call to check for call compatibility.
2889       --We do not perform the call compatibility check if p_api_name
2890       --is null. Internal APIs should pass this parameter as null.
2891       IF p_api_name IS NOT NULL THEN
2892             IF NOT FND_API.compatible_api_call ( PA_BUDGET_PUB.g_api_version_number,
2893                                                  p_api_version_number    ,
2894                                                  p_api_name              ,
2895                                                  PA_BUDGET_PUB.G_PKG_NAME )
2896             THEN
2897                   RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2898             END IF;
2899       END IF;
2900 
2901       --Convert following IN parameters from G_PA_MISS_XXX to null
2902 
2903       IF px_pa_project_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
2904             px_pa_project_id := NULL;
2905       END IF;
2906 
2907       IF px_budget_type_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
2908             px_budget_type_code := NULL;
2909       END IF;
2910 
2911       IF px_fin_plan_type_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
2912             px_fin_plan_type_id := NULL;
2913       END IF;
2914 
2915       IF px_fin_plan_type_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
2916             px_fin_plan_type_name := NULL;
2917       END IF;
2918 
2919       IF px_version_type = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
2920             px_version_type := NULL;
2921       END IF;
2922 
2923       -- Both Budget Type Code and Fin Plan Type Id should not be null
2924       IF (px_budget_type_code IS NULL  AND  px_fin_plan_type_name IS NULL  AND
2925           px_fin_plan_type_id IS NULL)  THEN
2926 
2927             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2928                  PA_UTILS.ADD_MESSAGE
2929                        (p_app_short_name => 'PA',
2930                         p_msg_name       => 'PA_BUDGET_FP_BOTH_MISSING');
2931             END IF;
2932 
2933             IF l_debug_mode = 'Y' THEN
2934                   pa_debug.g_err_stage:= 'Fin Plan type info and budget type info are missing';
2935                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
2936             END IF;
2937 
2938             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2939 
2940       END IF;
2941 
2942       -- Both Budget Type Code and Fin Plan Type Id should not be not null
2943 
2944       IF ((px_budget_type_code IS NOT NULL)  AND
2945           (px_fin_plan_type_name IS NOT NULL  OR  px_fin_plan_type_id IS NOT NULL)) THEN
2946 
2947             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2948                  PA_UTILS.ADD_MESSAGE
2949                        (p_app_short_name => 'PA',
2950                         p_msg_name       => 'PA_BUDGET_FP_BOTH_NOT_NULL');
2951             END IF;
2952 
2953             IF l_debug_mode = 'Y' THEN
2954                   pa_debug.g_err_stage:= 'Fin Plan type info and budget type info both are provided';
2955                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
2956             END IF;
2957 
2958             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2959 
2960       END IF;
2961 
2962       --product_code is mandatory
2963       IF p_pm_product_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
2964       OR p_pm_product_code IS NULL
2965       THEN
2966               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2967               THEN
2968                     PA_INTERFACE_UTILS_PUB.map_new_amg_msg
2969                     ( p_old_message_code => 'PA_PRODUCT_CODE_IS_MISSING'
2970                      ,p_msg_attribute    => 'CHANGE'
2971                      ,p_resize_flag      => 'N'
2972                      ,p_msg_context      => 'GENERAL'
2973                      ,p_attribute1       => ''
2974                      ,p_attribute2       => ''
2975                      ,p_attribute3       => ''
2976                      ,p_attribute4       => ''
2977                      ,p_attribute5       => '');
2978               END IF;
2979               IF l_debug_mode = 'Y' THEN
2980                     pa_debug.g_err_stage:= 'PM Product code is missing';
2981                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
2982               END IF;
2983 
2984               x_return_status := FND_API.G_RET_STS_ERROR;
2985               RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
2986 
2987       ELSE --p_pm_product_code is not null
2988 
2989             OPEN p_product_code_csr (p_pm_product_code);
2990             FETCH p_product_code_csr INTO l_pm_product_code;
2991             CLOSE p_product_code_csr;
2992             IF l_pm_product_code <> 'X'
2993             THEN
2994                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2995                   THEN
2996                       pa_interface_utils_pub.map_new_amg_msg
2997                       ( p_old_message_code => 'PA_PRODUCT_CODE_IS_INVALID'
2998                        ,p_msg_attribute    => 'CHANGE'
2999                        ,p_resize_flag      => 'N'
3000                        ,p_msg_context      => 'GENERAL'
3001                        ,p_attribute1       => ''
3002                        ,p_attribute2       => ''
3003                        ,p_attribute3       => ''
3004                        ,p_attribute4       => ''
3005                        ,p_attribute5       => '');
3006                   END IF;
3007                   IF l_debug_mode = 'Y' THEN
3008                         pa_debug.g_err_stage:= 'PM Product code is invalid';
3009                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3010                   END IF;
3011 
3012                   x_return_status             := FND_API.G_RET_STS_ERROR;
3013                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3014             END IF;
3015       END IF;-- p_pm_product_code IS NULL
3016 
3017 
3018       -- convert pm_project_reference to id
3019       Pa_project_pvt.Convert_pm_projref_to_id (
3020          p_pm_project_reference  => p_pm_project_reference,
3021          p_pa_project_id         => px_pa_project_id,
3022          p_out_project_id        => px_pa_project_id_tmp,      /* Bug 7498493 */
3023          p_return_status         => x_return_status );
3024 
3025         IF px_pa_project_id_tmp IS NOT NULL then        /* Bug 7498493 */
3026           px_pa_project_id := px_pa_project_id_tmp;
3027         END IF;
3028 
3029       IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
3030       THEN
3031             IF l_debug_mode = 'Y' THEN
3032                   pa_debug.g_err_stage:= 'Unexpected error while deriving project id';
3033                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3034             END IF;
3035             RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
3036 
3037       ELSIF x_return_status = FND_API.G_RET_STS_ERROR
3038       THEN
3039             IF l_debug_mode = 'Y' THEN
3040                   pa_debug.g_err_stage:= 'Error while deriving project id';
3041                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3042             END IF;
3043 
3044             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3045 
3046       END IF;
3047 
3048       PA_INTERFACE_UTILS_PUB.G_PROJECT_ID := px_pa_project_id;
3049 
3050       -- Get the segment 1 of the project so that it can be used in the
3051       -- later part of the code
3052       OPEN l_amg_project_csr( px_pa_project_id );
3053       FETCH l_amg_project_csr INTO x_project_number;
3054       CLOSE l_amg_project_csr;
3055 
3056 
3057       -- Bug 4588279, 27-SEP-05, jwhite -----------------------------------------
3058       -- Initialize for Budget LINE Conditional Validation
3059 
3060       -- Storing -99 here is essential for proper Budget LINE conditional validation
3061       -- for both the budget_type and FP models.
3062 
3063             PA_BUDGET_PUB.G_Latest_Encumbrance_Year := -99;
3064 
3065 
3066       -- End Bug 4588279, 27-SEP-05, jwhite -----------------------------------------
3067 
3068 
3069 
3070 
3071       -- Do the validations required for the BUDGET_TYPE_CODE budget model
3072       IF (px_budget_type_code IS NOT NULL)  THEN
3073 
3074 
3075             --Check for the security
3076             PA_PM_FUNCTION_SECURITY_PUB.CHECK_BUDGET_SECURITY (
3077                                                p_api_version_number => p_api_version_number
3078                                               ,p_project_id         => px_pa_project_id
3079                                               ,p_calling_context    => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_BUDGET
3080                                               ,p_function_name      => p_function_name
3081                                               ,p_version_type       => null
3082                                               ,x_return_status      => x_return_status
3083                                               ,x_ret_code           => l_security_ret_code );
3084 
3085             -- the above API adds the error message to stack. Hence the message is not added here.
3086             -- Also, as security check is important further validations are not done in case this
3087             -- validation fails.
3088             IF (x_return_status<>FND_API.G_RET_STS_SUCCESS OR
3089                 l_security_ret_code = 'N') THEN
3090 
3091                   IF l_debug_mode = 'Y' THEN
3092                         pa_debug.g_err_stage:= 'Security API Failed';
3093                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3094                   END IF;
3095 
3096                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3097             END IF;
3098 
3099             --Verify Budget Type and get the budget amount code.
3100             OPEN  l_budget_amount_code_csr( px_budget_type_code );
3101             FETCH l_budget_amount_code_csr
3102             INTO  x_budget_amount_code;
3103 
3104             IF l_budget_amount_code_csr%NOTFOUND
3105             THEN
3106                   CLOSE l_budget_amount_code_csr;
3107                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3108                   THEN
3109                         pa_interface_utils_pub.map_new_amg_msg
3110                          ( p_old_message_code => 'PA_BUDGET_TYPE_IS_INVALID'
3111                           ,p_msg_attribute    => 'CHANGE'
3112                           ,p_resize_flag      => 'N'
3113                           ,p_msg_context      => 'BUDG'
3114                           ,p_attribute1       => x_project_number
3115                           ,p_attribute2       => ''
3116                           ,p_attribute3       => px_budget_type_code
3117                           ,p_attribute4       => ''
3118                           ,p_attribute5       => '');
3119                   END IF;
3120                   x_return_status := FND_API.G_RET_STS_ERROR;
3121 
3122                   IF l_debug_mode = 'Y' THEN
3123                         pa_debug.g_err_stage:= 'Budget type is invalid';
3124                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3125                   END IF;
3126 
3127                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3128             ELSE
3129                   CLOSE l_budget_amount_code_csr;
3130             END IF; --End of l_budget_amount_code_csr%NOTFOUND
3131 
3132 
3133             --Verify that the budget is not of type FORECASTING_BUDGET_TYPE
3134             IF px_budget_type_code='FORECASTING_BUDGET_TYPE' THEN
3135                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3136                   THEN
3137                         PA_UTILS.add_message
3138                         (p_app_short_name => 'PA',
3139                          p_msg_name       => 'PA_FP_CANT_EDIT_FCST_BUD_TYPE');
3140                   END IF;
3141                   IF l_debug_mode = 'Y' THEN
3142                         pa_debug.g_err_stage := 'Budget of type FORECASTING_BUDGET_TYPE' ;
3143                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3144                   END IF;
3145                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3146             END IF;
3147 
3148             -- Budgetary Control Check
3149             -- Bug 4588279, 27-SEP-05, jwhite -----------------------------------------
3150 
3151             -- If project/budget-type enabled for budgetary control, then a package spec
3152             -- global is used for budget LINE validation by the lower-level
3153             -- pa_budget_check_pvt.GET_VALID_PERIOD_DATES_PVT procedure.
3154 
3155 
3156 
3157             --Check if budgetary control is enabled for the given project and
3158             --budget type code.
3159             PA_BUDGET_FUND_PKG.get_budget_ctrl_options
3160                             ( p_project_Id       => px_pa_project_id
3161                             , p_budget_type_code => px_budget_type_code
3162                             , p_calling_mode     => 'BUDGET'
3163                             , x_fck_req_flag     => l_fck_req_flag
3164                             , x_bdgt_intg_flag   => l_bdgt_intg_flag
3165                             , x_bdgt_ver_id      => l_bdgt_ver_id
3166                             , x_encum_type_id    => l_encum_type_id
3167                             , x_balance_type     => l_balance_type
3168                             , x_return_status    => x_return_status
3169                             , x_msg_data         => x_msg_data
3170                             , x_msg_count        => x_msg_count
3171                             );
3172 
3173             -- calling api above adds the error message to stack hence not adding the error message here.
3174             IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
3175             THEN
3176                   IF l_debug_mode = 'Y' THEN
3177                         pa_debug.g_err_stage:= 'get_budget_ctrl_options returned unexp error';
3178                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3179                   END IF;
3180                   RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
3181 
3182             ELSIF x_return_status = FND_API.G_RET_STS_ERROR
3183             THEN
3184                   IF l_debug_mode = 'Y' THEN
3185                         pa_debug.g_err_stage:= 'get_budget_ctrl_options returned  error';
3186                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3187                   END IF;
3188                   l_any_error_occurred_flag := 'Y';
3189             END IF;
3190 
3191 
3192             --If funds check is required then this budget cannot be inserted or updated thru AMG interface
3193               --FOR PERIOD_YEARS THAT FALL AFTER THE LATEST ENCUMBRANCE YEAR.
3194               --Deletes are OK.
3195 
3196 
3197             IF (nvl(l_fck_req_flag,'N') = 'Y')
3198             THEN
3199 
3200                  --RE-Populate global for subsequent conditional budget LINE validation
3201                  --  Storing a value other than -99 is essential to conditional LINE validation
3202 
3203                  PA_BUDGET_PVT.Get_Latest_BC_Year
3204                      ( p_pa_project_id            => px_pa_project_id
3205                        ,x_latest_encumbrance_year => PA_BUDGET_PUB.G_Latest_Encumbrance_Year
3206                        ,x_return_status           => x_return_status
3207                        ,x_msg_count               => x_msg_count
3208                        ,x_msg_data                => x_msg_data
3209                       );
3210 
3211 
3212                  -- calling api above adds the error message to stack hence not adding the error message here.
3213                  IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
3214                  THEN
3215                    IF l_debug_mode = 'Y' THEN
3216                         pa_debug.g_err_stage:= 'Get_Latest_BC_Year returned unexp error';
3217                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3218                    END IF;
3219                    RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
3220                  ELSIF x_return_status = FND_API.G_RET_STS_ERROR
3221                  THEN
3222                    IF l_debug_mode = 'Y' THEN
3223                         pa_debug.g_err_stage:= 'Get_Latest_BC_Year returned  error';
3224                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3225                    END IF;
3226                    l_any_error_occurred_flag := 'Y';
3227                  END IF;
3228 
3229 
3230               /* Since PA.M, this rule no longer applies for bugetary control
3231                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3232                   THEN
3233                       pa_interface_utils_pub.map_new_amg_msg
3234                       ( p_old_message_code => 'PA_BC_BGT_TYPE_IS_BAD_AMG'
3235                        ,p_msg_attribute    => 'CHANGE'
3236                        ,p_resize_flag      => 'N'
3237                        ,p_msg_context      => 'BUDG'
3238                        ,p_attribute1       => x_project_number
3239                        ,p_attribute2       => ''
3240                        ,p_attribute3       => px_budget_type_code
3241                        ,p_attribute4       => ''
3242                        ,p_attribute5       => '');
3243 
3244                       x_return_status := FND_API.G_RET_STS_ERROR;
3245                       l_any_error_occurred_flag := 'Y';
3246                   END IF;
3247                */
3248 
3249             END IF; --(nvl(l_fck_req_flag,'N') = 'Y')
3250 
3251 
3252             -- Bug 4588279, 27-SEP-05, jwhite -----------------------------------------
3253 
3254 
3255             --Get the budget_version_id, budget_entry_method_code and resource_list_id
3256             --from table pa_budget_version
3257             OPEN l_budget_version_csr( px_pa_project_id
3258                                      , px_budget_type_code );
3259             FETCH l_budget_version_csr
3260             INTO  x_budget_version_id
3261             ,     x_budget_entry_method_code
3262             ,     x_resource_list_id;
3263 
3264             IF l_budget_version_csr%NOTFOUND
3265             THEN
3266                  IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3267                  THEN
3268                          pa_interface_utils_pub.map_new_amg_msg
3269                           ( p_old_message_code => 'PA_NO_BUDGET_VERSION'
3270                            ,p_msg_attribute    => 'CHANGE'
3271                            ,p_resize_flag      => 'N'
3272                            ,p_msg_context      => 'BUDG'
3273                            ,p_attribute1       => x_project_number
3274                            ,p_attribute2       => ''
3275                            ,p_attribute3       => px_budget_type_code
3276                            ,p_attribute4       => ''
3277                            ,p_attribute5       => '');
3278                  END IF;
3279 
3280                  CLOSE l_budget_version_csr;
3281                  RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3282 
3283             END IF;--l_budget_version_csr%NOTFOUND
3284 
3285             CLOSE l_budget_version_csr;
3286 
3287             --entry method code is mandatory
3288             IF x_budget_entry_method_code IS NULL
3289             OR x_budget_entry_method_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
3290             THEN
3291 
3292                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3293                   THEN
3294                         pa_interface_utils_pub.map_new_amg_msg
3295                         (p_old_message_code => 'PA_ENTRY_METHOD_IS_MISSING'
3296                         ,p_msg_attribute    => 'CHANGE'
3297                         ,p_resize_flag      => 'N'
3298                         ,p_msg_context      => 'BUDG'
3299                         ,p_attribute1       => x_project_number
3300                         ,p_attribute2       => ''
3301                         ,p_attribute3       => px_budget_type_code
3302                         ,p_attribute4       => ''
3303                         ,p_attribute5       => '');
3304                   END IF;
3305 
3306                   x_return_status := FND_API.G_RET_STS_ERROR;
3307                   l_any_error_occurred_flag := 'Y';
3308                   IF l_debug_mode = 'Y' THEN
3309                         pa_debug.g_err_stage:= 'Budget entry method is missing';
3310                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3311                   END IF;
3312 
3313             ELSE -- entry method is not null
3314 
3315                   -- check validity of this budget entry method code, and store associated fields in record
3316                   OPEN l_budget_entry_method_csr(x_budget_entry_method_code);
3317                   FETCH l_budget_entry_method_csr INTO x_fin_plan_level_code
3318                                                       ,x_categorization_code
3319                                                       ,x_time_phased_code;
3320 
3321                   IF  l_budget_entry_method_csr%NOTFOUND
3322                   THEN
3323                         CLOSE l_budget_entry_method_csr;
3324                         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3325                         THEN
3326                                 pa_interface_utils_pub.map_new_amg_msg
3327                                ( p_old_message_code => 'PA_ENTRY_METHOD_IS_INVALID'
3328                                 ,p_msg_attribute    => 'CHANGE'
3329                                 ,p_resize_flag      => 'N'
3330                                 ,p_msg_context      => 'BUDG'
3331                                 ,p_attribute1       => x_project_number
3332                                 ,p_attribute2       => ''
3333                                 ,p_attribute3       => px_budget_type_code
3334                                 ,p_attribute4       => ''
3335                                 ,p_attribute5       => '');
3336                         END IF;
3337                         x_return_status := FND_API.G_RET_STS_ERROR;
3338                         l_any_error_occurred_flag := 'Y';
3339                         IF l_debug_mode = 'Y' THEN
3340                              pa_debug.g_err_stage:= 'Budget entry method is invalid';
3341                              pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3342                         END IF;
3343                   ELSE
3344                         CLOSE l_budget_entry_method_csr;
3345                   END IF;--l_budget_entry_method_csr%NOTFOUND
3346 
3347             END IF;--x_budget_entry_method_code IS NULL
3348 
3349 
3350       ELSE -- Validations for fin plan model
3351 
3352             PA_FIN_PLAN_PVT.convert_plan_type_name_to_id
3353                                            ( p_fin_plan_type_id    => px_fin_plan_type_id
3354                                             ,p_fin_plan_type_name  => px_fin_plan_type_name
3355                                             ,x_fin_plan_type_id    => px_fin_plan_type_id
3356                                             ,x_return_status       => x_return_status
3357                                             ,x_msg_count           => x_msg_count
3358                                             ,x_msg_data            => x_msg_data);
3359 
3360             -- Throw the error if the above API is not successfully executed
3361             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3362                   IF l_debug_mode = 'Y' THEN
3363                         pa_debug.g_err_stage := 'Cannot get the value of Fin Plan Type Id' ;
3364                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3365                   END IF;
3366                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3367             END IF;
3368 
3369             --We need to check use_for_workplan_flag as workplan versions
3370             --cannot be edited using this AMG interface.
3371             --reset the value of l_dummy
3372             l_dummy := 0;
3373             OPEN l_use_for_wp_csr( px_fin_plan_type_id );
3374             FETCH l_use_for_wp_csr INTO l_dummy;
3375             CLOSE l_use_for_wp_csr;
3376 
3377             IF l_dummy = 1
3378             THEN
3379                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3380                   THEN
3381                         PA_UTILS.add_message
3382                         (p_app_short_name => 'PA',
3383                          p_msg_name       => 'PA_FP_CANT_EDIT_WP_DATA');
3384                   END IF;
3385                   IF l_debug_mode = 'Y' THEN
3386                         pa_debug.g_err_stage := 'Fin Plan Type Id is used for WP' ;
3387                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3388                   END IF;
3389 
3390                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3391 
3392             END IF;
3393 
3394 
3395 
3396             -- Derive the version type. An error will be thrown by this api if preference code is
3397             -- COST_AND_REV_SEP and version type is not passed
3398             pa_fin_plan_utils.get_version_type
3399                  ( p_project_id        => px_pa_project_id
3400                   ,p_fin_plan_type_id  => px_fin_plan_type_id
3401                   ,px_version_type     => px_version_type
3402                   ,x_return_status     => x_return_status
3403                   ,x_msg_count         => x_msg_count
3404                   ,x_msg_data          => x_msg_data);
3405 
3406             IF x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
3407                   IF l_debug_mode = 'Y' THEN
3408                         pa_debug.g_err_stage := 'Failed in get_Version_type' ;
3409                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3410                   END IF;
3411                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3412             END IF;
3413 
3414             --if the budget version belongs to an org forecasting project then throw an error
3415             IF px_version_type = 'ORG_FORECAST' THEN
3416                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3417                   THEN
3418                         PA_UTILS.add_message
3419                         (p_app_short_name => 'PA',
3420                          p_msg_name       => 'PA_FP_ORG_FCST_PLAN_TYPE');
3421                   END IF;
3422                   IF l_debug_mode = 'Y' THEN
3423                         pa_debug.g_err_stage := 'Org_Forecast plan type has been passed' ;
3424                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3425                   END IF;
3426 
3427                   x_return_status    := FND_API.G_RET_STS_ERROR;
3428                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3429             END IF; --org_forecast
3430 
3431             --Check function security
3432             PA_PM_FUNCTION_SECURITY_PUB.CHECK_BUDGET_SECURITY (
3433                                          p_api_version_number => p_api_version_number
3434                                         ,p_project_id         => px_pa_project_id
3435                                         ,p_fin_plan_type_id   => px_fin_plan_type_id
3436                                         ,p_calling_context    => PA_FP_CONSTANTS_PKG.G_CALLING_MODULE_FIN_PLAN
3437                                         ,p_function_name      => p_function_name
3438                                         ,p_version_type       => px_version_type
3439                                         ,x_return_status      => x_return_status
3440                                         ,x_ret_code           => l_security_ret_code );
3441 
3442             IF (x_return_status <>FND_API.G_RET_STS_SUCCESS OR
3443                 l_security_ret_code='N') THEN
3444                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3445             END IF;
3446 
3447             --Derive the fin plan version id based on the unique combination of
3448             --project id, fin plan type id, version type and version number
3449             IF   p_budget_version_number IS NOT NULL
3450             AND  p_budget_Version_number <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
3451             THEN
3452 
3453                   OPEN l_finplan_version_id_csr( px_pa_project_id
3454                                                 ,px_fin_plan_type_id
3455                                                 ,px_version_type
3456                                                 ,p_budget_version_number);
3457                   FETCH l_finplan_version_id_csr INTO x_budget_version_id;
3458                   CLOSE l_finplan_version_id_csr;
3459 
3460             ELSE --p_budget_version_number IS NULL
3461 
3462                   -- Fetch the current working version for the project, finplan type and verion type
3463                   PA_FIN_PLAN_UTILS.Get_Curr_Working_Version_Info(
3464                       p_project_id           =>   px_pa_project_id
3465                      ,p_fin_plan_type_id     =>   px_fin_plan_type_id
3466                      ,p_version_type         =>   px_version_type
3467                      ,x_fp_options_id        =>   l_dummy
3468                      ,x_fin_plan_version_id  =>   x_budget_version_id
3469                      ,x_return_status        =>   x_return_status
3470                      ,x_msg_count            =>   x_msg_count
3471                      ,x_msg_data             =>   x_msg_data );
3472 
3473                   IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3474                         IF l_debug_mode = 'Y' THEN
3475                               pa_debug.g_err_stage := 'Get_Curr_Working_Version_Info api Failed ' ;
3476                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3477                         END IF;
3478                         RAISE FND_API.G_EXC_ERROR;
3479                   END IF;
3480 
3481             END IF; --p_budget_version_number IS NOT NULL
3482 
3483             --If budget version id can't be found throw appropriate error message
3484             IF x_budget_version_id IS NULL OR x_budget_version_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
3485             THEN
3486                   --Throw appropriate error message
3487                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3488                        PA_UTILS.ADD_MESSAGE
3489                                  (p_app_short_name => 'PA',
3490                                   p_msg_name       => 'PA_FP_NO_WORKING_VERSION',
3491                                   p_token1         => 'PROJECT',
3492                                   p_value1         =>  x_project_number,
3493                                   p_token2         => 'PLAN_TYPE',
3494                                   p_value2         =>  px_fin_plan_type_name,
3495                                   p_token3         => 'VERSION_NUMBER',
3496                                   p_value3         =>  p_budget_Version_number );
3497                   END IF;
3498 
3499                   IF l_debug_mode = 'Y' THEN
3500                      pa_debug.g_err_stage := 'Budget Version does not exist' ;
3501                      pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3502                   END IF;
3503                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3504 
3505             END IF;--x_budget_version_id IS NULL
3506 
3507             --Calling PA_FIN_PLAN_UTILS.validate_editable_bv API to check
3508             --if the budget version is locked by another user/process
3509             --or Edit after initial baseline setup is true and baseline
3510             --versions exist.
3511 
3512             pa_fin_plan_utils.validate_editable_bv
3513                        (p_budget_version_id   => x_budget_version_id,
3514                         p_user_id             => FND_GLOBAL.user_id,
3515                         p_context             => PA_FP_CONSTANTS_PKG.G_AMG_API,
3516                         x_locked_by_person_id => l_locked_by_persion_id,
3517                         x_err_code            => l_val_err_code,
3518                         x_return_status       => x_return_status,
3519                         x_msg_count           => x_msg_count,
3520                         x_msg_data            => x_msg_data);
3521 
3522             IF x_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
3523                  IF l_debug_mode = 'Y' THEN
3524                        pa_debug.g_err_stage := 'This budget version can not be edited';
3525                        pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3526                  END IF;
3527                  RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3528             END IF;
3529 
3530             -- Get the plan type level settings so that they can be passed as out parameters
3531             OPEN l_proj_fp_options_csr( px_pa_project_id
3532                                       , px_fin_plan_type_id
3533                                       , px_version_type
3534                                       , x_budget_version_id);
3535             FETCH l_proj_fp_options_csr
3536             INTO  x_plan_in_multi_curr_flag
3537                   ,x_fin_plan_level_code
3538                   ,x_resource_list_id
3539                   ,x_time_phased_code;
3540 
3541             --Control will never really enter this IF block since this check is
3542             --already made inside pa_fin_plan_utils.get_version_type before
3543             --control reaches here
3544             IF (l_proj_fp_options_csr%NOTFOUND) THEN
3545                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3546                        PA_UTILS.ADD_MESSAGE
3547                                 (p_app_short_name => 'PA',
3548                                  p_msg_name       => 'PA_FP_NO_PLAN_TYPE_OPTION',
3549                                  p_token1         => 'PROJECT',
3550                                  p_value1         =>  x_project_number,
3551                                  p_token2         => 'PLAN_TYPE',
3552                                  p_value2         =>  px_fin_plan_type_name);
3553                   END IF;
3554                   CLOSE l_proj_fp_options_csr;
3555                   IF l_debug_mode = 'Y' THEN
3556                          pa_debug.g_err_stage:= 'Plan type is not yet added to the project';
3557                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3558                   END IF;
3559                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3560             ELSE
3561                   CLOSE l_proj_fp_options_csr;
3562             END IF;--(l_proj_fp_options_csr%NOTFOUND)
3563 
3564 
3565       END IF; -- END OF CHECKS FOR FINPLAN MODEL
3566 
3567 
3568       -- check validity of the budget change reason code, passing NULL is OK
3569       IF (p_change_reason_code IS NOT NULL AND
3570           p_change_reason_code  <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR)
3571       THEN
3572             OPEN l_budget_change_reason_csr( p_change_reason_code );
3573             FETCH l_budget_change_reason_csr INTO l_dummy1;
3574 
3575             IF px_budget_type_code IS NULL  THEN
3576                   l_context_info := px_fin_plan_type_name;
3577             ELSE
3578                   l_context_info := px_budget_type_code;
3579             END IF;
3580 
3581             IF l_budget_change_reason_csr%NOTFOUND THEN
3582                   CLOSE l_budget_change_reason_csr;
3583 
3584                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3585                   THEN
3586                         pa_interface_utils_pub.map_new_amg_msg
3587                         ( p_old_message_code => 'PA_CHANGE_REASON_INVALID'
3588                         ,p_msg_attribute    => 'CHANGE'
3589                         ,p_resize_flag      => 'N'
3590                         ,p_msg_context      => 'BUDG'
3591                         ,p_attribute1       => x_project_number
3592                         ,p_attribute2       => ''
3593                         ,p_attribute3       => l_context_info
3594                         ,p_attribute4       => ''
3595                         ,p_attribute5       => '');
3596                   END IF;
3597                   x_return_status := FND_API.G_RET_STS_ERROR;
3598                   l_any_error_occurred_flag := 'Y';
3599                   IF l_debug_mode = 'Y' THEN
3600                         pa_debug.g_err_stage:= 'Invalid Change Reason code ';
3601                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3602                   END IF;
3603 
3604             ELSE
3605                   CLOSE l_budget_change_reason_csr;
3606             END IF;
3607       END IF;--p_change_reason_code IS NOT NULL
3608 
3609 
3610       -- Call the api that performs the autobaseline checks
3611       PA_FIN_PLAN_UTILS.PERFORM_AUTOBASLINE_CHECKS (
3612          p_budget_version_id  =>   x_budget_version_id
3613         ,x_result             =>   l_result
3614         ,x_return_status      =>   x_return_status
3615         ,x_msg_count          =>   x_msg_count
3616         ,x_msg_data           =>   x_msg_data       );
3617 
3618       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3619             IF(l_debug_mode='Y') THEN
3620                   pa_debug.g_err_stage := 'Auto baseline API falied';
3621                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3622             END IF;
3623             RAISE FND_API.G_EXC_ERROR;
3624       END IF;
3625 
3626       IF l_result = 'F' THEN
3627             IF(l_debug_mode='Y') THEN
3628                   pa_debug.g_err_stage := 'Auto baselining enabled for the project';
3629                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3630             END IF;
3631 
3632             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
3633                  PA_UTILS.ADD_MESSAGE(
3634                          p_app_short_name  => 'PA'
3635                         ,p_msg_name        => 'PA_FP_AB_AR_VER_NON_EDITABLE'
3636                         ,p_token1          => 'PROJECT'
3637                         ,p_value1          => x_project_number);
3638             END IF;
3639 
3640             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3641       END IF;
3642 
3643       --Check if the Budget version has any processing errors.
3644       PA_FIN_PLAN_UTILS.return_and_vldt_plan_prc_code
3645           (p_add_msg_to_stack      => 'Y'
3646           ,p_calling_context       => 'BUDGET'
3647           ,p_budget_version_id     => x_budget_version_id
3648           ,x_final_plan_prc_code   => l_plan_processing_code
3649           ,x_targ_request_id       => l_targ_request_id
3650           ,x_return_status         => x_return_status
3651           ,x_msg_count             => x_msg_count
3652           ,x_msg_data              => x_msg_data);
3653 
3654       IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3655             IF(l_debug_mode='Y') THEN
3656                   pa_debug.g_err_stage := 'return_and_vldt_plan_prc_code API falied';
3657                   pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3658             END IF;
3659             RAISE FND_API.G_EXC_ERROR;
3660       END IF;
3661 
3662 /* Plan Amount Entry flags validations start : bug 6408139 */
3663   IF px_budget_type_code IS NULL THEN -- for plan versions only, we are checking the flags
3664 
3665       px_raw_cost_flag         :=  NVL (px_raw_cost_flag,'N');
3666       px_burdened_cost_flag    :=  NVL (px_burdened_cost_flag,'N');
3667       px_revenue_flag          :=  NVL (px_revenue_flag,'N');
3668       px_cost_qty_flag         :=  NVL (px_cost_qty_flag,'N');
3669       px_revenue_qty_flag      :=  NVL (px_revenue_qty_flag,'N');
3670       px_all_qty_flag          :=  NVL (px_all_qty_flag,'N');
3671       px_bill_rate_flag        :=  NVL (px_bill_rate_flag,'N');
3672       px_cost_rate_flag        :=  NVL (px_cost_rate_flag,'N');
3673       px_burden_rate_flag      :=  NVL (px_burden_rate_flag,'N');
3674 
3675       /* Skip the validations if all are passed as G_PA_MISS_CHAR */
3676       IF (( px_raw_cost_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3677           ( px_burdened_cost_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3678       ( px_revenue_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3679       ( px_cost_qty_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3680       ( px_revenue_qty_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3681       ( px_all_qty_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3682       ( px_bill_rate_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3683       ( px_cost_rate_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) OR
3684       ( px_burden_rate_flag <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) ) THEN
3685 
3686           /*Get the existing plan amount entry flags for the plan version*/
3687       l_amount_set_id := PA_FIN_PLAN_UTILS.get_amount_set_id(x_budget_version_id);
3688 
3689       PA_FIN_PLAN_UTILS.GET_PLAN_AMOUNT_FLAGS(
3690                       P_AMOUNT_SET_ID      => l_amount_set_id
3691                      ,X_RAW_COST_FLAG      => lx_raw_cost_flag
3692                      ,X_BURDENED_FLAG      => lx_burdened_cost_flag
3693                      ,X_REVENUE_FLAG       => lx_revenue_flag
3694                      ,X_COST_QUANTITY_FLAG => lx_cost_qty_flag
3695                      ,X_REV_QUANTITY_FLAG  => lx_revenue_qty_flag
3696                      ,X_ALL_QUANTITY_FLAG  => lx_all_qty_flag
3697                      ,X_BILL_RATE_FLAG     => lx_bill_rate_flag
3698                      ,X_COST_RATE_FLAG     => lx_cost_rate_flag
3699                      ,X_BURDEN_RATE_FLAG   => lx_burden_rate_flag
3700                      ,x_message_count      => x_msg_count
3701                      ,x_return_status      => x_return_status
3702                      ,x_message_data       => x_msg_data) ;
3703 
3704                     IF x_return_status <> FND_API.G_RET_STS_SUCCESS
3705                     THEN
3706                          -- RAISE  FND_API.G_EXC_ERROR;
3707                          RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3708                     END IF;
3709 
3710           IF ( px_raw_cost_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3711             px_raw_cost_flag := lx_raw_cost_flag;
3712           END IF ;
3713 
3714           IF ( px_burdened_cost_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3715            px_burdened_cost_flag := lx_burdened_cost_flag;
3716           END IF ;
3717 
3718       IF ( px_revenue_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3719            px_revenue_flag := lx_revenue_flag;
3720           END IF ;
3721 
3722       IF ( px_cost_qty_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3723            px_cost_qty_flag := lx_cost_qty_flag;
3724           END IF ;
3725 
3726       IF ( px_revenue_qty_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3727            px_revenue_qty_flag := lx_revenue_qty_flag;
3728           END IF ;
3729 
3730       IF ( px_all_qty_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3731            px_all_qty_flag := lx_all_qty_flag;
3732           END IF ;
3733 
3734       IF ( px_bill_rate_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3735             px_bill_rate_flag :=  lx_bill_rate_flag;
3736           END IF ;
3737 
3738       IF ( px_cost_rate_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3739             px_cost_rate_flag := lx_cost_rate_flag;
3740           END IF ;
3741 
3742       IF ( px_burden_rate_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR) THEN
3743             px_burden_rate_flag := lx_burden_rate_flag;
3744           END IF ;
3745 
3746 
3747         IF( px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST) THEN
3748 
3749                   IF( px_raw_cost_flag     NOT IN ('Y','N')) OR
3750                     ( px_burdened_cost_flag NOT IN ('Y','N')) OR
3751                     ( px_cost_qty_flag     NOT IN ('Y','N')) OR
3752             ( px_bill_rate_flag <> 'N' ) OR
3753             ( px_cost_rate_flag    NOT IN ('Y','N')) OR
3754             ( px_burden_rate_flag  NOT IN ('Y','N')) THEN
3755 
3756             PA_UTILS.ADD_MESSAGE
3757                              (p_app_short_name => 'PA',
3758                               p_msg_name       => 'PA_FP_INVALID_AMT_FLAGS',
3759                               p_token1         => 'PROJECT',
3760                               p_value1         =>  x_project_number,
3761                               p_token2         => 'PLAN_TYPE',
3762                               p_value2         =>  px_fin_plan_type_name);
3763                         x_return_status := FND_API.G_RET_STS_ERROR;
3764                         l_any_error_occurred_flag := 'Y';
3765 
3766                         IF l_debug_mode = 'Y' THEN
3767                               pa_debug.g_err_stage:= 'Invalid values for amount flags ';
3768                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3769                         END IF;
3770                   END IF;
3771 
3772 
3773                   IF( px_raw_cost_flag     = 'N') AND
3774                     ( px_burdened_cost_flag = 'N') AND
3775                     ( px_cost_qty_flag     = 'N') THEN
3776 
3777                         PA_UTILS.ADD_MESSAGE
3778                              (p_app_short_name => 'PA',
3779                               p_msg_name       => 'PA_FP_NO_PLAN_AMT_CHECKED');
3780                         x_return_status := FND_API.G_RET_STS_ERROR;
3781                         l_any_error_occurred_flag := 'Y';
3782                         IF l_debug_mode = 'Y' THEN
3783                               pa_debug.g_err_stage:= 'None of the amount flags are Y ';
3784                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
3785                         END IF;
3786                   END IF;
3787 
3788             ELSIF( px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE ) THEN
3789 
3790                   IF( px_revenue_flag     NOT IN ('Y','N')) OR
3791                     ( px_revenue_qty_flag NOT IN ('Y','N')) OR
3792             ( px_bill_rate_flag   NOT IN ('Y','N')) OR
3793             ( px_cost_rate_flag   <> 'N') OR
3794             ( px_burden_rate_flag <> 'N')THEN
3795 
3796                         PA_UTILS.ADD_MESSAGE
3797                              (p_app_short_name => 'PA',
3798                               p_msg_name       => 'PA_FP_INVALID_AMT_FLAGS',
3799                               p_token1         => 'PROJECT',
3800                               p_value1         =>  x_project_number,
3801                               p_token2         => 'PLAN_TYPE',
3802                               p_value2         =>  px_fin_plan_type_name);
3803                         x_return_status := FND_API.G_RET_STS_ERROR;
3804                         l_any_error_occurred_flag := 'Y';
3805                         IF l_debug_mode = 'Y' THEN
3806                               pa_debug.g_err_stage:= 'Invalid value for the amount flags ';
3807                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3808                         END IF;
3809 
3810                   END IF;
3811 
3812 
3813                   IF( px_revenue_flag     ='N') AND
3814                     ( px_revenue_qty_flag ='N') THEN
3815 
3816                         PA_UTILS.ADD_MESSAGE
3817                              (p_app_short_name => 'PA',
3818                               p_msg_name       => 'PA_FP_NO_PLAN_AMT_CHECKED');
3819                         x_return_status := FND_API.G_RET_STS_ERROR;
3820                         l_any_error_occurred_flag := 'Y';
3821                         IF l_debug_mode = 'Y' THEN
3822                               pa_debug.g_err_stage:= 'None of the amount flags are Y ';
3823                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3824                         END IF;
3825 
3826                   END IF;
3827 
3828             ELSIF( px_version_type = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_ALL ) THEN
3829 
3830                   IF( px_raw_cost_flag      NOT IN ('Y','N')) OR
3831                     ( px_burdened_cost_flag NOT IN ('Y','N')) OR
3832                     ( px_revenue_flag       NOT IN ('Y','N')) OR
3833                     ( px_all_qty_flag       NOT IN ('Y','N')) OR
3834             ( px_bill_rate_flag     NOT IN ('Y','N')) OR
3835             ( px_cost_rate_flag     NOT IN ('Y','N')) OR
3836             ( px_burden_rate_flag   NOT IN ('Y','N')) THEN
3837 
3838                         PA_UTILS.ADD_MESSAGE
3839                              (p_app_short_name => 'PA',
3840                               p_msg_name       => 'PA_FP_INVALID_AMT_FLAGS',
3841                               p_token1         => 'PROJECT',
3842                               p_value1         =>  x_project_number,
3843                               p_token2         => 'PLAN_TYPE',
3844                               p_value2         =>  px_fin_plan_type_name);
3845                         x_return_status := FND_API.G_RET_STS_ERROR;
3846                         l_any_error_occurred_flag := 'Y';
3847                         IF l_debug_mode = 'Y' THEN
3848                               pa_debug.g_err_stage:= 'Invalid value for the amount flags ';
3849                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3850                         END IF;
3851 
3852                   END IF;
3853 
3854                  IF( px_raw_cost_flag     ='N') AND
3855                     ( px_burdened_cost_flag='N') AND
3856                     ( px_revenue_flag      ='N') AND
3857                     ( px_cost_qty_flag     = 'N') AND			--Fix for 7172129
3858                     ( px_revenue_qty_flag ='N') AND
3859                     ( px_all_qty_flag      ='N') THEN
3860 
3861                         PA_UTILS.ADD_MESSAGE
3862                         (p_app_short_name => 'PA',
3863                         p_msg_name       => 'PA_FP_NO_PLAN_AMT_CHECKED');
3864                         x_return_status := FND_API.G_RET_STS_ERROR;
3865                         l_any_error_occurred_flag := 'Y';
3866                         IF l_debug_mode = 'Y' THEN
3867                               pa_debug.g_err_stage:= 'None of the amount flags are Y ';
3868                               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3869                         END IF;
3870 
3871                   END IF;
3872 
3873             END IF; -- px_version_type checks
3874 
3875       END IF ; -- G_PA_MISS_CHAR condition
3876 
3877   END IF ; --IF px_budget_type_code IS NULL
3878 
3879 /* Plan Amount Entry flags validations end : bug 6408139*/
3880 
3881       -- Stop further processing if any errors are reported
3882       IF(l_any_error_occurred_flag='Y') THEN
3883             IF(l_debug_mode='Y') THEN
3884                   pa_debug.g_err_stage := 'About to display all the messages';
3885                   pa_debug.write( l_module_name,pa_debug.g_err_stage,l_debug_level5);
3886             END IF;
3887             x_return_status := FND_API.G_RET_STS_ERROR;
3888             l_any_error_occurred_flag := 'Y';
3889             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
3890       END IF;
3891 
3892       IF(l_debug_mode='Y') THEN
3893             pa_debug.g_err_stage := 'Leaving validate_header_info';
3894             pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
3895       END IF;
3896 
3897       IF l_debug_mode = 'Y' THEN
3898             pa_debug.reset_curr_function;
3899       END IF;
3900 
3901 EXCEPTION
3902 
3903       WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
3904       IF x_return_status IS NULL
3905       OR x_return_status =  FND_API.G_RET_STS_SUCCESS THEN
3906             x_return_status := FND_API.G_RET_STS_ERROR;
3907       END IF;
3908 
3909       x_msg_count := FND_MSG_PUB.count_msg;
3910 
3911       IF x_msg_count = 1 AND x_msg_data IS NULL THEN
3912             PA_INTERFACE_UTILS_PUB.get_messages
3913                  (p_encoded        => FND_API.G_TRUE,
3914                   p_msg_index      => 1,
3915                   p_msg_count      => x_msg_count,
3916                   p_msg_data       => x_msg_data,
3917                   p_data           => l_data,
3918                   p_msg_index_out  => l_msg_index_out);
3919             x_msg_count := l_msg_index_out;
3920             x_msg_data  := l_data;
3921       END IF;
3922 
3923       IF l_debug_mode = 'Y' THEN
3924             pa_debug.reset_curr_function;
3925       END IF;
3926 
3927       RETURN;
3928 
3929       WHEN FND_API.G_EXC_ERROR
3930       THEN
3931 
3932       x_return_status := FND_API.G_RET_STS_ERROR;
3933 
3934       FND_MSG_PUB.count_and_get
3935       (   p_count     =>  x_msg_count ,
3936           p_data      =>  x_msg_data  );
3937 
3938       IF ( l_debug_mode = 'Y' ) THEN
3939             pa_debug.reset_curr_function;
3940       END IF;
3941 
3942       WHEN FND_API.G_EXC_UNEXPECTED_ERROR
3943       THEN
3944 
3945       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3946 
3947       FND_MSG_PUB.count_and_get
3948       (   p_count     =>  x_msg_count ,
3949           p_data      =>  x_msg_data  );
3950 
3951       IF ( l_debug_mode = 'Y' ) THEN
3952             pa_debug.reset_curr_function;
3953       END IF;
3954 
3955       WHEN OTHERS THEN
3956       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3957       x_msg_count     := 1;
3958       x_msg_data      := SQLERRM;
3959 
3960       FND_MSG_PUB.add_exc_msg
3961       ( p_pkg_name       => 'PA_BUDGET_PVT'
3962       ,p_procedure_name  => 'VALIDATE_HEADER_INFO'
3963       ,p_error_text      => sqlerrm);
3964 
3965       IF l_debug_mode = 'Y' THEN
3966             pa_debug.G_Err_Stack := SQLERRM;
3967             pa_debug.reset_curr_function;
3968       END IF;
3969       RAISE;
3970 
3971 END Validate_Header_Info;
3972 
3973 
3974 ----------------------------------------------------------------------------------------
3975 --Name:               insert_budget_line
3976 --Type:               Procedure
3977 --Description:        This procedure can be used to insert a budgetline for
3978 --                    an existing WORKING budget. Used by create_draft_budget
3979 --                and add_budget_line.
3980 --
3981 --Called subprograms:
3982 --                pa_budget_utils.create_line
3983 --
3984 --
3985 --
3986 --History:
3987 --    18-NOV-1996        L. de Werker    Created
3988 --
3989 --    11-Feb-2002        Srikanth        Modified as part of the changes for AMG in finplan model
3990 --    10-AUG-2003        bvarnasi        Bug 3062294 : rectified many bugs. See bug for more details.
3991 --    22-OCT-2003        Rajagopal       bug 2998221 : Included call to validate_budget_lines api
3992 --                                       for validations. l_budget_lines_in_tbl is a in/out plsql table
3993 --                                       which stamps task_id derived from task_reference etc. So, use
3994 --                                       values from l_budget_lines_in_tbl while calling create_line api
3995 --    29-APR-2005        rishukla        Bug 4224464: FP M Changes: Added parameter p_change_reason_code
3996 --                                       to insert_budget_line API.
3997 
3998 PROCEDURE insert_budget_line
3999 ( p_return_status             OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4000  ,p_pa_project_id             IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4001  ,p_budget_type_code          IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4002  ,p_pa_task_id                IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4003  ,p_pm_task_reference         IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4004  ,p_resource_alias            IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4005  ,p_member_id                 IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4006  ,p_budget_start_date         IN    DATE              := PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE
4007  ,p_budget_end_date           IN    DATE              := PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE
4008  ,p_period_name               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4009  ,p_description               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4010  ,p_raw_cost                  IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4011  ,p_burdened_cost             IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4012  ,p_revenue                   IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4013  ,p_quantity                  IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4014  ,p_pm_product_code           IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4015  ,p_pm_budget_line_reference  IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4016  ,p_attribute_category        IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4017  ,p_attribute1                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4018  ,p_attribute2                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4019  ,p_attribute3                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4020  ,p_attribute4                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4021  ,p_attribute5                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4022  ,p_attribute6                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4023  ,p_attribute7                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4024  ,p_attribute8                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4025  ,p_attribute9                IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4026  ,p_attribute10               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4027  ,p_attribute11               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4028  ,p_attribute12               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4029  ,p_attribute13               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4030  ,p_attribute14               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4031  ,p_attribute15               IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4032  ,p_resource_list_id          IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4033  ,p_time_phased_type_code     IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4034  ,p_entry_level_code          IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4035  ,p_budget_amount_code        IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4036  ,p_budget_entry_method_code  IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4037  ,p_categorization_code       IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4038  ,p_budget_version_id         IN    NUMBER            := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4039  ,p_change_reason_code        IN    VARCHAR2          := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR )--Bug 4224464
4040 
4041 IS
4042 
4043    l_return_status                        VARCHAR2(1);
4044    l_api_name                 CONSTANT    VARCHAR2(30)            := 'insert_budget_line';
4045    l_resource_assignment_id               NUMBER;
4046    l_unit_of_measure                      VARCHAR2(30);
4047    l_track_as_labor_flag                  VARCHAR2(1);
4048    l_attribute_category                   VARCHAR2(30);
4049    l_attribute1                           VARCHAR2(150);
4050    l_attribute2                           VARCHAR2(150);
4051    l_attribute3                           VARCHAR2(150);
4052    l_attribute4                           VARCHAR2(150);
4053    l_attribute5                           VARCHAR2(150);
4054    l_attribute6                           VARCHAR2(150);
4055    l_attribute7                           VARCHAR2(150);
4056    l_attribute8                           VARCHAR2(150);
4057    l_attribute9                           VARCHAR2(150);
4058    l_attribute10                          VARCHAR2(150);
4059    l_attribute11                          VARCHAR2(150);
4060    l_attribute12                          VARCHAR2(150);
4061    l_attribute13                          VARCHAR2(150);
4062    l_attribute14                          VARCHAR2(150);
4063    l_attribute15                          VARCHAR2(150);
4064    l_err_code                             NUMBER;
4065    l_err_stage                            VARCHAR2(120);
4066    l_err_stack                            VARCHAR2(630);
4067    l_amg_segment1                         VARCHAR2(25);
4068    l_amg_task_number                      VARCHAR2(50);
4069    l_quantity                             NUMBER;
4070    l_raw_cost                             NUMBER;
4071    l_burdened_cost                        NUMBER;
4072    l_revenue                              NUMBER;
4073 --  Following local variables added as part of bug 3062294
4074    l_pa_task_id                           pa_resource_assignments.task_id%TYPE;
4075    l_pm_task_ref                          pa_tasks.pm_task_reference%TYPE;
4076    l_resource_alias                       pa_resource_list_members.alias%TYPE; -- bug 3711693
4077    l_rlm_id                               pa_resource_list_members.resource_list_member_id%TYPE;
4078    l_budget_start_date                    pa_budget_lines.start_date%TYPE;
4079    l_budget_end_date                      pa_budget_lines.start_date%TYPE;
4080    l_period_name                          pa_budget_lines.period_name%TYPE;
4081    l_description                          pa_budget_lines.description%TYPE;
4082    l_pm_budget_line_reference             pa_budget_lines.pm_budget_line_reference%TYPE;
4083    l_change_reason_code                   pa_budget_lines.change_reason_code%TYPE;
4084 
4085    l_budget_lines_in_tbl                  PA_BUDGET_PUB.G_BUDGET_LINES_IN_TBL%TYPE; /* bug 2998221 */
4086    l_budget_lines_out_tbl                 PA_BUDGET_PUB.G_BUDGET_LINES_OUT_TBL%TYPE;
4087    i                                      NUMBER;
4088    l_msg_data                             VARCHAR2(2000);
4089    l_msg_count                            NUMBER;
4090    l_debug_mode                           VARCHAR2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
4091    l_module_name                          VARCHAR2(80) := 'add_budget_line: ' || g_module_name;
4092 --   l_fp_type_id                           pa_budget_versions.fin_plan_type_id%TYPE; --3569883
4093 --   l_old_model                            VARCHAR2(1):=null; --3569883
4094 
4095    -- added for bug Bug 3986129: FP.M Web ADI Dev changes
4096    l_mfc_cost_type_id_tbl                SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
4097    l_etc_method_code_tbl                 SYSTEM.pa_varchar2_30_tbl_type := SYSTEM.pa_varchar2_30_tbl_type();
4098    l_spread_curve_id_tbl                 SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
4099 
4100    l_version_info_rec                    pa_fp_gen_amount_utils.fp_cols;
4101    l_pm_product_code                     VARCHAR2(30);
4102    l_task_id                             NUMBER;
4103 
4104       --needed to get the field values associated to a AMG message
4105 
4106       CURSOR   l_amg_project_csr
4107       (p_pa_project_id pa_projects.project_id%type)
4108       IS
4109       SELECT   segment1
4110       FROM     pa_projects p
4111       WHERE p.project_id = p_pa_project_id;
4112 
4113       --needed to get the unit_of_measure and track_as_labor_flag for this resource_list_member
4114       --and check for valid resource_list / member combination
4115 
4116       CURSOR l_resource_csr
4117             (c_resource_list_member_id NUMBER
4118             ,c_resource_list_id        NUMBER)
4119       IS
4120       SELECT pr.unit_of_measure
4121             ,prlm.track_as_labor_flag
4122       FROM   pa_resources pr
4123             ,pa_resource_lists prl
4124             ,pa_resource_list_members prlm
4125       WHERE  prl.resource_list_id = c_resource_list_id
4126       AND    pr.resource_id = prlm.resource_id
4127       AND    prl.resource_list_id = prlm.resource_list_id
4128       AND    prlm.resource_list_member_id = c_resource_list_member_id;
4129 
4130 BEGIN
4131       --Standard begin of API savepoint
4132 
4133       SAVEPOINT insert_budget_line_pvt;
4134 
4135       --Set API return status to success
4136 
4137       p_return_status := FND_API.G_RET_STS_SUCCESS;
4138 
4139       --get unit_of_measure and track_as_labor_flag associated to
4140       --the resource member and check whether this is a valid member for this list
4141       OPEN l_resource_csr( p_member_id
4142                           ,p_resource_list_id     );
4143       FETCH l_resource_csr INTO l_unit_of_measure, l_track_as_labor_flag;
4144       IF l_resource_csr%NOTFOUND
4145       THEN
4146             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4147             THEN
4148                   pa_interface_utils_pub.map_new_amg_msg
4149                   ( p_old_message_code => 'PA_LIST_MEMBER_INVALID'
4150                   ,p_msg_attribute    => 'CHANGE'
4151                   ,p_resize_flag      => 'N'
4152                   ,p_msg_context      => 'BUDG'
4153                   ,p_attribute1       => l_amg_segment1
4154                   ,p_attribute2       => l_amg_task_number
4155                   ,p_attribute3       => p_budget_type_code
4156                   ,p_attribute4       => ''
4157                   ,p_attribute5       => to_char(p_budget_start_date));
4158             END IF;
4159 
4160             CLOSE l_resource_csr;
4161             p_return_status := FND_API.G_RET_STS_ERROR;
4162             RAISE FND_API.G_EXC_ERROR;
4163 
4164       ELSE
4165             CLOSE l_resource_csr;
4166 
4167       END IF;
4168 
4169       /*****************************
4170        Bug 3218822 - PM_PRODUCT_CODE could be Null. We need valid it if it is NOT NULL.
4171          This will be done in validate_budget_lines.
4172 
4173       -- bug 3062294
4174       --product_code is mandatory : this validation was missing altogether
4175       IF p_pm_product_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4176          OR p_pm_product_code IS NULL
4177       THEN
4178               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4179               THEN
4180                     pa_interface_utils_pub.map_new_amg_msg
4181                     ( p_old_message_code => 'PA_PRODUCT_CODE_IS_MISSING'
4182                      ,p_msg_attribute    => 'CHANGE'
4183                      ,p_resize_flag      => 'N'
4184                      ,p_msg_context      => 'GENERAL'
4185                      ,p_attribute1       => ''
4186                      ,p_attribute2       => ''
4187                      ,p_attribute3       => ''
4188                      ,p_attribute4       => ''
4189                      ,p_attribute5       => '');
4190                       dbms_output.put_line('MSG count in the stack ' || FND_MSG_PUB.count_msg);
4191                       dbms_output.put_line('added msg to stack');
4192                       dbms_output.put_line('MSG count in the stack 2 ' || FND_MSG_PUB.count_msg);
4193               END IF;
4194               p_return_status := FND_API.G_RET_STS_ERROR;
4195         END IF;
4196       -- bug 3062294
4197 
4198       Bug 3218822 - PM_PRODUCT_CODE could be Null. We need valid it if it is NOT NULL
4199       *****************************/
4200 
4201       --Get the segment1 of the project so that it can be used later
4202       OPEN l_amg_project_csr(p_pa_project_id);
4203       FETCH l_amg_project_csr INTO l_amg_segment1;
4204       CLOSE l_amg_project_csr;
4205 
4206       --Get the task number
4207 
4208         --Fixed for bug 5060391
4209             IF (p_pa_task_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM) THEN
4210                 l_task_id := NULL;
4211             ELSE
4212                 l_task_id  := p_pa_task_id;
4213             END IF;
4214             l_amg_task_number := pa_interface_utils_pub.get_task_number_amg
4215                                       ( p_task_number=> ''
4216                                        ,p_task_reference => p_pm_task_reference
4217                                        ,p_task_id => l_task_id);
4218 
4219       --When descriptive flex fields are not passed set them to NULL
4220       IF p_attribute_category = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4221       THEN
4222             l_attribute_category := NULL;
4223       ELSE
4224             l_attribute_category := p_attribute_category;
4225       END IF;
4226 
4227       IF p_attribute1 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4228       THEN
4229             l_attribute1 := NULL;
4230       ELSE
4231             l_attribute1 := p_attribute1;
4232       END IF;
4233 
4234       IF p_attribute2 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4235       THEN
4236             l_attribute2 := NULL;
4237       ELSE
4238             l_attribute2 := p_attribute2;
4239       END IF;
4240 
4241       IF p_attribute3 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4242       THEN
4243             l_attribute3 := NULL;
4244       ELSE
4245             l_attribute3 := p_attribute3;
4246       END IF;
4247 
4248       IF p_attribute4 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4249       THEN
4250             l_attribute4 := NULL;
4251       ELSE
4252             l_attribute4 := p_attribute4;
4253       END IF;
4254 
4255       IF p_attribute5 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4256       THEN
4257             l_attribute5 := NULL;
4258       ELSE
4259             l_attribute5 := p_attribute5;
4260       END IF;
4261 
4262       IF p_attribute6 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4263       THEN
4264             l_attribute6 := NULL;
4265       ELSE
4266             l_attribute6 := p_attribute6;
4267       END IF;
4268 
4269       IF p_attribute7 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4270       THEN
4271             l_attribute7 := NULL;
4272       ELSE
4273             l_attribute7 := p_attribute7;
4274       END IF;
4275 
4276       IF p_attribute8 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4277       THEN
4278             l_attribute8 := NULL;
4279       ELSE
4280             l_attribute8 := p_attribute8;
4281       END IF;
4282 
4283       IF p_attribute9 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4284       THEN
4285             l_attribute9 := NULL;
4286       ELSE
4287             l_attribute9 := p_attribute9;
4288       END IF;
4289 
4290       IF p_attribute10 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4291       THEN
4292             l_attribute10 := NULL;
4293       ELSE
4294             l_attribute10 := p_attribute10;
4295       END IF;
4296 
4297       IF p_attribute11 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4298       THEN
4299             l_attribute11 := NULL;
4300       ELSE
4301             l_attribute11 := p_attribute11;
4302       END IF;
4303 
4304       IF p_attribute12 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4305       THEN
4306             l_attribute12 := NULL;
4307       ELSE
4308             l_attribute12 := p_attribute12;
4309       END IF;
4310 
4311       IF p_attribute13 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4312       THEN
4313             l_attribute13 := NULL;
4314       ELSE
4315             l_attribute13 := p_attribute13;
4316       END IF;
4317 
4318       IF p_attribute14 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4319       THEN
4320             l_attribute14:= NULL;
4321       ELSE
4322             l_attribute14:= p_attribute14;
4323       END IF;
4324 
4325       IF p_attribute15 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4326       THEN
4327             l_attribute15 := NULL;
4328       ELSE
4329             l_attribute15 := p_attribute15;
4330       END IF;
4331 
4332 
4333       --Remove big numbers in case parameters were not passed, default to NULL; Assign Valid
4334       --Values to local variables.
4335 
4336       IF p_quantity = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4337       THEN
4338             l_quantity := null;
4339       ELSE
4340             l_quantity := p_quantity;
4341       END IF;
4342 
4343       IF p_raw_cost = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4344       THEN
4345             l_raw_cost := null;
4346       ELSE
4347             l_raw_cost := p_raw_cost;
4348       END IF;
4349 
4350       IF p_burdened_cost = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4351       THEN
4352             l_burdened_cost := null;
4353       ELSE
4354             l_burdened_cost := p_burdened_cost;
4355       END IF;
4356 
4357       IF p_revenue = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4358       THEN
4359             l_revenue := null;
4360       ELSE
4361             l_revenue := p_revenue;
4362       END IF;
4363       -- extending this null assignment to all other parameters passed as part
4364       -- of p_budget_lines_rec (as defined in pa_budget_pub)
4365       -- Added for bug 3062294 :
4366 
4367       IF p_pa_task_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4368       THEN
4369             l_pa_task_id := null;
4370       ELSE
4371             l_pa_task_id := p_pa_task_id;
4372       END IF;
4373 
4374       IF p_pm_task_reference = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4375       THEN
4376             l_pm_task_ref := null;
4377       ELSE
4378             l_pm_task_ref := p_pm_task_reference;
4379       END IF;
4380 
4381       IF p_resource_alias = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4382       THEN
4383             l_resource_alias := null;
4384       ELSE
4385             l_resource_alias := p_resource_alias;
4386       END IF;
4387 
4388       IF p_member_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
4389       THEN
4390             l_rlm_id := null;
4391       ELSE
4392             l_rlm_id := p_member_id;
4393       END IF;
4394 
4395       IF p_budget_start_date = PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE
4396       THEN
4397             l_budget_start_date := null;
4398       ELSE
4399             l_budget_start_date := p_budget_start_date;
4400       END IF;
4401 
4402       IF p_budget_end_date = PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE
4403       THEN
4404             l_budget_end_date := null;
4405       ELSE
4406             l_budget_end_date := p_budget_end_date;
4407       END IF;
4408 
4409       IF p_period_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4410       THEN
4411             l_period_name := null;
4412       ELSE
4413             l_period_name := p_period_name;
4414       END IF;
4415 
4416       IF p_description  = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4417       THEN
4418             l_description := null;
4419       ELSE
4420             l_description := p_description;
4421       END IF;
4422 
4423       IF p_pm_budget_line_reference  = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4424       THEN
4425             l_pm_budget_line_reference := null;
4426       ELSE
4427             l_pm_budget_line_reference := p_pm_budget_line_reference;
4428       END IF;
4429 
4430       --Bug 4224464
4431       IF p_change_reason_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4432       THEN
4433             l_change_reason_code := NULL;
4434       ELSE
4435             l_change_reason_code := p_change_reason_code;
4436       END IF;
4437 
4438       IF p_pm_product_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
4439       THEN
4440             l_pm_product_code := NULL;
4441       ELSE
4442             l_pm_product_code := p_pm_product_code;
4443       END IF;
4444 
4445       IF (l_quantity IS NULL AND l_raw_cost IS NULL AND l_burdened_cost IS NULL AND p_budget_amount_code = 'C')
4446       OR (l_quantity IS NULL AND l_revenue IS NULL  AND p_budget_amount_code = 'R')
4447       THEN
4448             NULL;  --we don't insert budget lines with all zero's
4449 
4450       ELSE
4451 
4452             /**** Validation checks introduced for the bug 2998221 starts here   ****/
4453 
4454             -- Initialize l_budget_lines_tbl with the budget line details
4455             -- The table would contain only one record
4456 
4457             i :=  1;
4458 
4459             l_budget_lines_in_tbl(i).pa_task_id                    :=      l_pa_task_id;
4460             l_budget_lines_in_tbl(i).pm_task_reference             :=      l_pm_task_ref;
4461             l_budget_lines_in_tbl(i).resource_alias                :=      l_resource_alias;
4462             l_budget_lines_in_tbl(i).resource_list_member_id       :=      l_rlm_id;
4463             l_budget_lines_in_tbl(i).budget_start_date             :=      l_budget_start_date ;
4464             l_budget_lines_in_tbl(i).budget_end_date               :=      l_budget_end_date ;
4465             l_budget_lines_in_tbl(i).period_name                   :=      l_period_name;
4466             l_budget_lines_in_tbl(i).description                   :=      l_description ;
4467             l_budget_lines_in_tbl(i).raw_cost                      :=      l_raw_cost;
4468             l_budget_lines_in_tbl(i).burdened_cost                 :=      l_burdened_cost;
4469             l_budget_lines_in_tbl(i).revenue                       :=      l_revenue;
4470             l_budget_lines_in_tbl(i).quantity                      :=      l_quantity;
4471             l_budget_lines_in_tbl(i).pm_product_code               :=      l_pm_product_code;
4472             l_budget_lines_in_tbl(i).pm_budget_line_reference      :=      l_pm_budget_line_reference;
4473             l_budget_lines_in_tbl(i).attribute_category            :=      l_attribute_category ;
4474             l_budget_lines_in_tbl(i).attribute1                    :=      l_attribute1 ;
4475             l_budget_lines_in_tbl(i).attribute2                    :=      l_attribute2 ;
4476             l_budget_lines_in_tbl(i).attribute3                    :=      l_attribute3 ;
4477             l_budget_lines_in_tbl(i).attribute4                    :=      l_attribute4 ;
4478             l_budget_lines_in_tbl(i).attribute5                    :=      l_attribute5 ;
4479             l_budget_lines_in_tbl(i).attribute6                    :=      l_attribute6 ;
4480             l_budget_lines_in_tbl(i).attribute7                    :=      l_attribute7 ;
4481             l_budget_lines_in_tbl(i).attribute8                    :=      l_attribute8 ;
4482             l_budget_lines_in_tbl(i).attribute9                    :=      l_attribute9 ;
4483             l_budget_lines_in_tbl(i).attribute10                   :=      l_attribute10;
4484             l_budget_lines_in_tbl(i).attribute11                   :=      l_attribute11;
4485             l_budget_lines_in_tbl(i).attribute12                   :=      l_attribute12;
4486             l_budget_lines_in_tbl(i).attribute13                   :=      l_attribute13;
4487             l_budget_lines_in_tbl(i).attribute14                   :=      l_attribute14;
4488             l_budget_lines_in_tbl(i).attribute15                   :=      l_attribute15;
4489             l_budget_lines_in_tbl(i).txn_currency_code             :=      null;
4490             l_budget_lines_in_tbl(i).projfunc_cost_rate_type       :=      null;
4491             l_budget_lines_in_tbl(i).projfunc_cost_rate_date_type  :=      null;
4492             l_budget_lines_in_tbl(i).projfunc_cost_rate_date       :=      null;
4493             l_budget_lines_in_tbl(i).projfunc_cost_exchange_rate   :=      null;
4494             l_budget_lines_in_tbl(i).projfunc_rev_rate_type        :=      null;
4495             l_budget_lines_in_tbl(i).projfunc_rev_rate_date_type   :=      null;
4496             l_budget_lines_in_tbl(i).projfunc_rev_rate_date        :=      null;
4497             l_budget_lines_in_tbl(i).projfunc_rev_exchange_rate    :=      null;
4498             l_budget_lines_in_tbl(i).project_cost_rate_type        :=      null;
4499             l_budget_lines_in_tbl(i).project_cost_rate_date_type   :=      null;
4500             l_budget_lines_in_tbl(i).project_cost_rate_date        :=      null;
4501             l_budget_lines_in_tbl(i).project_cost_exchange_rate    :=      null;
4502             l_budget_lines_in_tbl(i).project_rev_rate_type         :=      null;
4503             l_budget_lines_in_tbl(i).project_rev_rate_date_type    :=      null;
4504             l_budget_lines_in_tbl(i).project_rev_rate_date         :=      null;
4505             l_budget_lines_in_tbl(i).project_rev_exchange_rate     :=      null;
4506             l_budget_lines_in_tbl(i).change_reason_code            :=      l_change_reason_code;--Bug 4224464
4507 
4508 --3569883 start
4509 --    select fin_plan_type_id
4510 --      into l_fp_type_id
4511 --          from pa_budget_versions
4512 --         where budget_version_id = p_budget_version_id;
4513 --
4514 --      select DECODE(l_fp_type_id, null, 'Y','N') into l_old_model from dual;
4515 ----3569883 end
4516 
4517             --Bug 4224464: FP.M Changes for Validate_Budget_Lines
4518             --Send the budget version id to validate_budget_lines API for
4519             --actuals on FORECAST check
4520             IF p_budget_version_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
4521                   l_version_info_rec.x_budget_version_id := null;
4522             ELSE
4523                   l_version_info_rec.x_budget_version_id := p_budget_version_id;
4524             END IF;
4525 
4526             -- Call validate_budget_lines api
4527             pa_budget_pvt.Validate_Budget_Lines
4528                     ( p_pa_project_id               => p_pa_project_id
4529                      ,p_budget_type_code            => p_budget_type_code
4530                      ,p_fin_plan_type_id            => NULL
4531                      ,p_version_type                => NULL
4532                      ,p_resource_list_id            => p_resource_list_id
4533                      ,p_time_phased_code            => p_time_phased_type_code
4534                      ,p_budget_entry_method_code    => p_budget_entry_method_code
4535                      ,p_entry_level_code            => p_entry_level_code
4536                      ,p_allow_qty_flag              => NULL
4537                      ,p_allow_raw_cost_flag         => NULL
4538                      ,p_allow_burdened_cost_flag    => NULL
4539                      ,p_allow_revenue_flag          => NULL
4540                      ,p_multi_currency_flag         => NULL
4541                      ,p_project_cost_rate_type      => NULL
4542                      ,p_project_cost_rate_date_typ  => NULL
4543                      ,p_project_cost_rate_date      => NULL
4544                      ,p_project_cost_exchange_rate  => NULL
4545                      ,p_projfunc_cost_rate_type     => NULL
4546                      ,p_projfunc_cost_rate_date_typ => NULL
4547                      ,p_projfunc_cost_rate_date     => NULL
4548                      ,p_projfunc_cost_exchange_rate => NULL
4549                      ,p_project_rev_rate_type       => NULL
4550                      ,p_project_rev_rate_date_typ   => NULL
4551                      ,p_project_rev_rate_date       => NULL
4552                      ,p_project_rev_exchange_rate   => NULL
4553                      ,p_projfunc_rev_rate_type      => NULL
4554                      ,p_projfunc_rev_rate_date_typ  => NULL
4555                      ,p_projfunc_rev_rate_date      => NULL
4556                      ,p_projfunc_rev_exchange_rate  => NULL
4557                      ,p_version_info_rec            => l_version_info_rec
4558                      ,px_budget_lines_in            => l_budget_lines_in_tbl
4559                      ,x_budget_lines_out            => l_budget_lines_out_tbl
4560 --                     ,x_old_model                   => l_old_model --3569883
4561                      ,x_mfc_cost_type_id_tbl        => l_mfc_cost_type_id_tbl
4562                      ,x_etc_method_code_tbl         => l_etc_method_code_tbl
4563                      ,x_spread_curve_id_tbl         => l_spread_curve_id_tbl
4564                      ,x_msg_count                   => l_msg_count
4565                      ,x_msg_data                    => l_msg_data
4566                      ,x_return_status               => l_return_status);
4567 
4568             IF(l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
4569                    RAISE  FND_API.G_EXC_ERROR;
4570             END IF;
4571 
4572             IF l_debug_mode = 'Y' THEN
4573                   pa_debug.g_err_stage := 'Validate Budget Lines got executed successfully';
4574                   pa_debug.write(l_module_name,pa_debug.g_err_stage,3);
4575             END IF;
4576 
4577             /**** Validation checks introduced for the bug 2998221 starts here   ****/
4578 
4579            --create budget line
4580 --      dbms_output.put_line('before create_line revenue = '|| l_revenue || ' raw cost '||l_raw_cost || 'l_burdened_cost '||l_burdened_cost||' l_quantity  ' || l_quantity);
4581 
4582             pa_budget_utils.create_line
4583                   (x_budget_version_id          => p_budget_version_id
4584                   ,x_project_id                 => p_pa_project_id
4585                   ,x_task_id                    => l_budget_lines_in_tbl(i).pa_task_id --bug 2998221  l_pa_task_id
4586                   ,x_resource_list_member_id    => l_budget_lines_in_tbl(i).resource_list_member_id --bug 2998221 l_rlm_id
4587                   ,x_description                => l_description
4588                   ,x_start_date                 => l_budget_lines_in_tbl(i).budget_start_date --bug 2998221 l_budget_start_date
4589                   ,x_end_date                   => l_budget_lines_in_tbl(i).budget_end_date   --bug 2998221 l_budget_end_date
4590                   ,x_period_name                => l_budget_lines_in_tbl(i).period_name       --bug 2998221 l_period_name
4591                   ,x_quantity                   => l_quantity
4592                   ,x_unit_of_measure            => l_unit_of_measure
4593                   ,x_track_as_labor_flag        => l_track_as_labor_flag
4594                   ,x_raw_cost                   => l_raw_cost
4595                   ,x_burdened_cost              => l_burdened_cost
4596                   ,x_revenue                    => l_revenue
4597                   ,x_change_reason_code         => l_change_reason_code --Bug 4224464
4598                   ,x_attribute_category         => l_attribute_category
4599                   ,x_attribute1                 => l_attribute1
4600                   ,x_attribute2                 => l_attribute2
4601                   ,x_attribute3                 => l_attribute3
4602                   ,x_attribute4                 => l_attribute4
4603                   ,x_attribute5                 => l_attribute5
4604                   ,x_attribute6                 => l_attribute6
4605                   ,x_attribute7                 => l_attribute7
4606                   ,x_attribute8                 => l_attribute8
4607                   ,x_attribute9                 => l_attribute9
4608                   ,x_attribute10                => l_attribute10
4609                   ,x_attribute11                => l_attribute11
4610                   ,x_attribute12                => l_attribute12
4611                   ,x_attribute13                => l_attribute13
4612                   ,x_attribute14                => l_attribute14
4613                   ,x_attribute15                => l_attribute15
4614                   -- Bug Fix: 4569365. Removed MRC code.
4615                   -- ,x_mrc_flag                   => 'Y' /* FPB2: MRC */
4616                   ,x_resource_assignment_id     => l_resource_assignment_id
4617                   ,x_err_code                   => l_err_code
4618                   ,x_err_stage                  => l_err_stage
4619                   ,x_err_stack                  => l_err_stack
4620                   ,x_pm_product_code            => l_pm_product_code
4621                   ,x_pm_budget_line_reference   =>  l_budget_lines_in_tbl(i).pm_budget_line_reference  --bug 2998221 l_pm_budget_line_reference
4622                   ,x_quantity_source            => 'I'
4623                   ,x_raw_cost_source            => 'I'
4624                   ,x_burdened_cost_source       => 'I'
4625                   ,x_revenue_source             => 'I' );
4626 
4627       --dbms_output.put_line('After create_line');
4628       --dbms_output.put_line('Error code: '||l_err_code);
4629       --dbms_output.put_line('Error Stage: '||l_err_stage);
4630       --dbms_output.put_line('Error Stack: '||l_err_stack);
4631 
4632             IF l_err_code > 0
4633             then
4634 
4635                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4636                   THEN
4637 
4638                         IF NOT pa_project_pvt.check_valid_message(l_err_stage)
4639                         THEN
4640                               pa_interface_utils_pub.map_new_amg_msg
4641                               ( p_old_message_code => 'PA_CREATE_LINE_FAILED'
4642                               ,p_msg_attribute    => 'CHANGE'
4643                               ,p_resize_flag      => 'N'
4644                               ,p_msg_context      => 'BUDG'
4645                               ,p_attribute1       => l_amg_segment1
4646                               ,p_attribute2       => l_amg_task_number
4647                               ,p_attribute3       => p_budget_type_code
4648                               ,p_attribute4       => ''
4649                               ,p_attribute5       => to_char(p_budget_start_date));
4650                         ELSE
4651                               pa_interface_utils_pub.map_new_amg_msg
4652                               ( p_old_message_code => l_err_stage
4653                               ,p_msg_attribute    => 'CHANGE'
4654                               ,p_resize_flag      => 'N'
4655                               ,p_msg_context      => 'BUDG'
4656                               ,p_attribute1       => l_amg_segment1
4657                               ,p_attribute2       => l_amg_task_number
4658                               ,p_attribute3       => p_budget_type_code
4659                               ,p_attribute4       => ''
4660                               ,p_attribute5       => to_char(p_budget_start_date));
4661                         END IF;
4662 
4663                   END IF;
4664 
4665                   RAISE FND_API.G_EXC_ERROR;
4666 
4667             ELSIF l_err_code < 0
4668             THEN
4669 
4670                   IF l_err_code = -1   --special handling of duplicate line error
4671                   THEN
4672                         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4673                         THEN
4674                               pa_interface_utils_pub.map_new_amg_msg
4675                               ( p_old_message_code => 'PA_BUDGET_LINE_ALREADY_EXISTS'
4676                               ,p_msg_attribute    => 'CHANGE'
4677                               ,p_resize_flag      => 'Y'
4678                               ,p_msg_context      => 'BUDG'
4679                               ,p_attribute1       => l_amg_segment1
4680                               ,p_attribute2       => l_amg_task_number
4681                               ,p_attribute3       => p_budget_type_code
4682                               ,p_attribute4       => ''
4683                               ,p_attribute5       => to_char(p_budget_start_date));
4684                         END IF;
4685                         RAISE FND_API.G_EXC_ERROR;
4686                   ELSE
4687 
4688                         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4689                         THEN
4690 
4691                               FND_MSG_PUB.add_exc_msg
4692                               (  p_pkg_name           => 'PA_BUDGET_UTILS'
4693                               ,  p_procedure_name     => 'CREATE_LINE'
4694                               ,  p_error_text         => 'ORA-'||LPAD(substr(l_err_code,2),5,'0') );
4695 
4696                         END IF;
4697                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4698                   END IF;
4699 
4700             END IF;
4701    END IF;  --all zero's
4702 
4703 EXCEPTION
4704 
4705       WHEN FND_API.G_EXC_ERROR
4706       THEN
4707 
4708             ROLLBACK TO insert_budget_line_pvt;
4709 
4710             p_return_status := FND_API.G_RET_STS_ERROR;
4711 
4712       WHEN FND_API.G_EXC_UNEXPECTED_ERROR
4713       THEN
4714 
4715             ROLLBACK TO insert_budget_line_pvt;
4716 
4717             p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4718 
4719       WHEN OTHERS THEN
4720 
4721             ROLLBACK TO insert_budget_line_pvt;
4722 
4723             p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4724 
4725             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4726             THEN
4727                   FND_MSG_PUB.add_exc_msg
4728                   (  p_pkg_name           => G_PKG_NAME
4729                   ,  p_procedure_name     => l_api_name );
4730 
4731             END IF;
4732 
4733 END insert_budget_line;
4734 
4735 
4736 ----------------------------------------------------------------------------------------
4737 --Name:               update_budget_line_sql
4738 --Type:               Procedure
4739 --Description:        This procedure is be build a update statement for a budgetline.
4740 --
4741 --
4742 --Called subprograms: PA_BUDGET_PVT.check_entry_method_flags
4743 --
4744 --
4745 --
4746 --
4747 --History:
4748 --    19-NOV-1996   L. de Werker    Created
4749 --
4750 --    04-FEB-2003   gjain           Bug 2756050: Modified the code which generates
4751 --                                  the dynamic sql to append additional quotes before
4752 --                                  and after the numeric columns like raw_cost,
4753 --                                  burdened_cost,revenue,quantity
4754 --    10-MAY-2005   Ritesh Shukla   Bug 4224464- This procedure has been modified extensively
4755 --                                  during FP.M changes for AMG. If you do not want to update
4756 --                                  a parameter then either do not pass it or pass its value
4757 --                                  as NULL, and if you want to null out a parameter then
4758 --                                  pass it as FND_API.G_MISS_XXX
4759 --    13-MAY-2005   Ritesh Shukla   Bug 4224464-Removed parameter p_budget_amount_code from
4760 --                                  procedure update_budget_line_sql since it has become redundant.
4761 
4762 PROCEDURE update_budget_line_sql
4763 ( p_return_status             OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
4764  ,p_budget_entry_method_code  IN    VARCHAR2
4765  ,p_resource_assignment_id    IN    NUMBER
4766  ,p_start_date                IN    DATE
4767  ,p_time_phased_type_code     IN    VARCHAR2
4768  ,p_description               IN    VARCHAR2
4769  ,p_quantity                  IN    NUMBER
4770  ,p_raw_cost                  IN    NUMBER
4771  ,p_burdened_cost             IN    NUMBER
4772  ,p_revenue                   IN    NUMBER
4773  ,p_change_reason_code        IN    VARCHAR2
4774  ,p_attribute_category        IN    VARCHAR2
4775  ,p_attribute1                IN    VARCHAR2
4776  ,p_attribute2                IN    VARCHAR2
4777  ,p_attribute3                IN    VARCHAR2
4778  ,p_attribute4                IN    VARCHAR2
4779  ,p_attribute5                IN    VARCHAR2
4780  ,p_attribute6                IN    VARCHAR2
4781  ,p_attribute7                IN    VARCHAR2
4782  ,p_attribute8                IN    VARCHAR2
4783  ,p_attribute9                IN    VARCHAR2
4784  ,p_attribute10               IN    VARCHAR2
4785  ,p_attribute11               IN    VARCHAR2
4786  ,p_attribute12               IN    VARCHAR2
4787  ,p_attribute13               IN    VARCHAR2
4788  ,p_attribute14               IN    VARCHAR2
4789  ,p_attribute15               IN    VARCHAR2
4790 )
4791 
4792 IS
4793 
4794    --needed to get the current data of a budget line
4795 
4796    CURSOR l_budget_line_csr
4797         (p_resource_assigment_id NUMBER
4798         ,p_budget_start_date     DATE )
4799    IS
4800    SELECT pa_budget_lines.*, rowid
4801    FROM   pa_budget_lines
4802    WHERE  resource_assignment_id = p_resource_assigment_id
4803    AND    start_date = p_budget_start_date;
4804 
4805 --cursor added as part of fix for Bug#1406799 to check the burdened_cost_flag
4806 
4807   CURSOR l_budget_entry_method_csr
4808 (p_budget_entry_method_code pa_budget_entry_methods.budget_entry_method_code%type)
4809   IS
4810   SELECT burdened_cost_flag
4811   FROM pa_budget_entry_methods
4812   WHERE budget_entry_method_code = p_budget_entry_method_code
4813   AND    trunc(sysdate)
4814   BETWEEN trunc(start_date_active) and trunc(nvl(end_date_active,sysdate));
4815 
4816 
4817    l_return_status                        VARCHAR2(1);
4818    l_api_name                 CONSTANT    VARCHAR2(30)            := 'update_budget_line_sql';
4819    l_budget_line_rec                      l_budget_line_csr%rowtype;
4820 
4821  --used by dynamic SQL
4822    l_statement                            VARCHAR2(2000);
4823    l_update_yes_flag                      VARCHAR2(1) := 'N';
4824    l_rows                           NUMBER;
4825    l_cursor_id                            NUMBER;
4826 -- added as part of fix for Bug#1406799 to check for burdened_cost_flag
4827    l_burdened_cost_flag                         VARCHAR2(1) := 'Y';
4828 
4829    /* FPB2: MRC */
4830    l_budget_line_id                            PA_BUDGET_LINES.BUDGET_LINE_ID%type;
4831    l_budget_version_id                         PA_BUDGET_LINES.BUDGET_VERSION_ID%type;
4832    l_txn_currency_code                         PA_BUDGET_LINES.TXN_CURRENCY_CODE%type;
4833    l_msg_count          NUMBER := 0;
4834    l_msg_data           VARCHAR2(2000);
4835 
4836 
4837 BEGIN
4838 
4839     --  Standard begin of API savepoint
4840 
4841     SAVEPOINT update_budget_line_sql_pvt;
4842 
4843     --  Set API return status to success
4844 
4845     p_return_status := FND_API.G_RET_STS_SUCCESS;
4846 
4847     --get the current values for this budget line
4848 
4849     OPEN l_budget_line_csr( p_resource_assignment_id, p_start_date );
4850     FETCH l_budget_line_csr INTO l_budget_line_rec;
4851     CLOSE l_budget_line_csr;
4852 
4853 --dbms_output.put_line('Building the dynamic SQL statement');
4854 
4855     --building the dynamic SQL statement
4856     -- Changes made by Xin Liu for using of SQL BIND VARIABLE 12-MAY-2003
4857 
4858     l_statement := ' UPDATE PA_BUDGET_LINES SET ';
4859 
4860 --dbms_output.put_line('p_description             : '||p_description);
4861 --dbms_output.put_line('l_budget_line_rec.description: '||l_budget_line_rec.description);
4862 
4863     IF  p_description IS NOT NULL
4864     AND p_description <> nvl(l_budget_line_rec.description,FND_API.G_MISS_CHAR)
4865     THEN
4866             l_statement := l_statement ||
4867                            ' DESCRIPTION = :xDescription'||',';
4868             l_update_yes_flag := 'Y';
4869     END IF;
4870 
4871 --dbms_output.put_line('New Raw cost: '||nvl(to_char(p_raw_cost),'NULL'));
4872 --dbms_output.put_line('Old Raw cost: '||nvl(to_char(l_budget_line_rec.raw_cost),'NULL'));
4873 
4874     IF p_raw_cost IS NOT NULL
4875     AND p_raw_cost <> nvl(l_budget_line_rec.raw_cost,FND_API.G_MISS_NUM)
4876     THEN
4877             l_statement := l_statement ||
4878                            ' RAW_COST = :xRawCost'||',';
4879 
4880             l_update_yes_flag := 'Y';
4881     END IF;
4882 
4883     -- code added as part of fix for Bug#1406799. To check for burdened_cost_flag.
4884     OPEN l_budget_entry_method_csr( p_budget_entry_method_code );
4885     FETCH l_budget_entry_method_csr INTO l_burdened_cost_flag;
4886     CLOSE l_budget_entry_method_csr;
4887 
4888     IF l_burdened_cost_flag = 'N'  -- added for burden_distributed_cost ='N'
4889     THEN
4890 /* Bug 2864086 - Added this check for p_raw_cost before updating burdened cost with the p_raw_cost */
4891 
4892           IF p_raw_cost IS NOT NULL
4893           AND p_raw_cost <> nvl(l_budget_line_rec.burdened_cost,FND_API.G_MISS_NUM)
4894           THEN
4895                 l_statement := l_statement ||
4896                                ' BURDENED_COST = :xRawCostForB'||',';
4897 
4898                 l_update_yes_flag := 'Y';
4899          END If;
4900     ELSE
4901 
4902         IF p_burdened_cost IS NOT NULL
4903         AND p_burdened_cost <> nvl(l_budget_line_rec.burdened_cost,FND_API.G_MISS_NUM)
4904         THEN
4905                 l_statement := l_statement ||
4906                                ' BURDENED_COST = :xBurdenedCost'||',';
4907 
4908                 l_update_yes_flag := 'Y';
4909         END IF;
4910     END IF;--l_burdened_cost_flag = 'N'
4911 
4912     IF p_revenue IS NOT NULL
4913     AND p_revenue <> nvl(l_budget_line_rec.revenue,FND_API.G_MISS_NUM)
4914     THEN
4915             l_statement := l_statement ||
4916                            ' REVENUE = :xRevenue'||',';
4917 
4918             l_update_yes_flag := 'Y';
4919     END IF;
4920 
4921     IF p_quantity IS NOT NULL
4922     AND p_quantity <> nvl(l_budget_line_rec.quantity,FND_API.G_MISS_NUM)
4923     THEN
4924             l_statement := l_statement ||
4925                            ' QUANTITY = :xQuantity'||',';
4926 
4927             l_update_yes_flag := 'Y';
4928     END IF;
4929 
4930     IF  p_change_reason_code IS NOT NULL
4931     AND p_change_reason_code <> nvl(l_budget_line_rec.change_reason_code,FND_API.G_MISS_CHAR)
4932     THEN
4933             l_statement := l_statement ||
4934                            ' CHANGE_REASON_CODE = :xChangeReasonCode'||',';
4935             l_update_yes_flag := 'Y';
4936     END IF;
4937 
4938     IF  p_attribute_category IS NOT NULL
4939     AND p_attribute_category <> nvl(l_budget_line_rec.attribute_category,FND_API.G_MISS_CHAR)
4940     THEN
4941             l_statement := l_statement ||
4942                            ' ATTRIBUTE_CATEGORY = :xAttributeCategory'||',';
4943             l_update_yes_flag := 'Y';
4944     END IF;
4945 
4946     IF  p_attribute1 IS NOT NULL
4947     AND p_attribute1 <> nvl(l_budget_line_rec.attribute1,FND_API.G_MISS_CHAR)
4948     THEN
4949             l_statement := l_statement ||
4950                            ' ATTRIBUTE1 = :xAttribute1'||',';
4951             l_update_yes_flag := 'Y';
4952     END IF;
4953 
4954     IF  p_attribute2 IS NOT NULL
4955     AND p_attribute2 <> nvl(l_budget_line_rec.attribute2,FND_API.G_MISS_CHAR)
4956     THEN
4957             l_statement := l_statement ||
4958                            ' ATTRIBUTE2 = :xAttribute2'||',';
4959             l_update_yes_flag := 'Y';
4960     END IF;
4961 
4962     IF  p_attribute3 IS NOT NULL
4963     AND p_attribute3 <> nvl(l_budget_line_rec.attribute3,FND_API.G_MISS_CHAR)
4964     THEN
4965             l_statement := l_statement ||
4966                            ' ATTRIBUTE3 = :xAttribute3'||',';
4967             l_update_yes_flag := 'Y';
4968     END IF;
4969 
4970     IF  p_attribute4 IS NOT NULL
4971     AND p_attribute4 <> nvl(l_budget_line_rec.attribute4,FND_API.G_MISS_CHAR)
4972     THEN
4973             l_statement := l_statement ||
4974                            ' ATTRIBUTE4 = :xAttribute4'||',';
4975             l_update_yes_flag := 'Y';
4976     END IF;
4977 
4978     IF  p_attribute5 IS NOT NULL
4979     AND p_attribute5 <> nvl(l_budget_line_rec.attribute5,FND_API.G_MISS_CHAR)
4980     THEN
4981             l_statement := l_statement ||
4982                            ' ATTRIBUTE5 = :xAttribute5'||',';
4983             l_update_yes_flag := 'Y';
4984     END IF;
4985 
4986     IF  p_attribute6 IS NOT NULL
4987     AND p_attribute6 <> nvl(l_budget_line_rec.attribute6,FND_API.G_MISS_CHAR)
4988     THEN
4989             l_statement := l_statement ||
4990                            ' ATTRIBUTE6 = :xAttribute6'||',';
4991             l_update_yes_flag := 'Y';
4992     END IF;
4993 
4994     IF  p_attribute7 IS NOT NULL
4995     AND p_attribute7 <> nvl(l_budget_line_rec.attribute7,FND_API.G_MISS_CHAR)
4996     THEN
4997             l_statement := l_statement ||
4998                            ' ATTRIBUTE7 = :xAttribute7'||',';
4999             l_update_yes_flag := 'Y';
5000     END IF;
5001 
5002     IF  p_attribute8 IS NOT NULL
5003     AND p_attribute8 <> nvl(l_budget_line_rec.attribute8,FND_API.G_MISS_CHAR)
5004     THEN
5005             l_statement := l_statement ||
5006                            ' ATTRIBUTE8 = :xAttribute8'||',';
5007             l_update_yes_flag := 'Y';
5008     END IF;
5009 
5010     IF  p_attribute9 IS NOT NULL
5011     AND p_attribute9 <> nvl(l_budget_line_rec.attribute9,FND_API.G_MISS_CHAR)
5012     THEN
5013             l_statement := l_statement ||
5014                            ' ATTRIBUTE9 = :xAttribute9'||',';
5015             l_update_yes_flag := 'Y';
5016     END IF;
5017 
5018     IF  p_attribute10 IS NOT NULL
5019     AND p_attribute10 <> nvl(l_budget_line_rec.attribute10,FND_API.G_MISS_CHAR)
5020     THEN
5021             l_statement := l_statement ||
5022                            ' ATTRIBUTE10 = :xAttribute10'||',';
5023             l_update_yes_flag := 'Y';
5024     END IF;
5025 
5026     IF  p_attribute11 IS NOT NULL
5027     AND p_attribute11 <> nvl(l_budget_line_rec.attribute11,FND_API.G_MISS_CHAR)
5028     THEN
5029             l_statement := l_statement ||
5030                            ' ATTRIBUTE11 = :xAttribute11'||',';
5031             l_update_yes_flag := 'Y';
5032     END IF;
5033 
5034     IF  p_attribute12 IS NOT NULL
5035     AND p_attribute12 <> nvl(l_budget_line_rec.attribute12,FND_API.G_MISS_CHAR)
5036     THEN
5037             l_statement := l_statement ||
5038                            ' ATTRIBUTE12 = :xAttribute12'||',';
5039             l_update_yes_flag := 'Y';
5040     END IF;
5041 
5042     IF  p_attribute13 IS NOT NULL
5043     AND p_attribute13 <> nvl(l_budget_line_rec.attribute13,FND_API.G_MISS_CHAR)
5044     THEN
5045             l_statement := l_statement ||
5046                            ' ATTRIBUTE13 = :xAttribute13'||',';
5047             l_update_yes_flag := 'Y';
5048     END IF;
5049 
5050     IF  p_attribute14 IS NOT NULL
5051     AND p_attribute14 <> nvl(l_budget_line_rec.attribute14,FND_API.G_MISS_CHAR)
5052     THEN
5053             l_statement := l_statement ||
5054                            ' ATTRIBUTE14 = :xAttribute14'||',';
5055             l_update_yes_flag := 'Y';
5056     END IF;
5057 
5058     IF  p_attribute15 IS NOT NULL
5059     AND p_attribute15 <> nvl(l_budget_line_rec.attribute15,FND_API.G_MISS_CHAR)
5060     THEN
5061             l_statement := l_statement ||
5062                            ' ATTRIBUTE15 = :xAttribute15'||',';
5063             l_update_yes_flag := 'Y';
5064     END IF;
5065 
5066 
5067     /* FPB2: MRC
5068            - This code is used only in the old model
5069            - Txn_currency_code will always be the projfunc_currency_code
5070            - Adding txn_currency_code in update for more clarity to indicate the update will
5071              always update just one record. We get the budget_line_id of the updated record
5072              and pass to mrc api */
5073 
5074     BEGIN
5075       SELECT projfunc_currency_code
5076       INTO   l_txn_currency_code
5077       FROM   pa_projects_all a, pa_budget_versions b, pa_resource_Assignments c
5078       WHERE  a.project_id = b.project_id
5079       AND    b.budget_version_id = c.budget_version_id
5080       AND    c.resource_assignment_id = p_resource_assignment_id
5081       AND    b.ci_id IS NULL;    -- <Patchset M:B and F impact changes : AMG:> -- Added an extra clause b.ci_id IS NULL --Bug # 3507156
5082 
5083     EXCEPTION
5084        WHEN OTHERS THEN
5085           /* May the resource assignment id passed is not correct ! */
5086          l_txn_currency_code := null;
5087     END;
5088 
5089     IF l_update_yes_flag = 'Y'
5090     THEN
5091         l_statement := l_statement ||
5092                        ' LAST_UPDATE_DATE = :xLastUpdateDate'||',';
5093 
5094         l_statement := l_statement ||
5095                        ' LAST_UPDATED_BY = '||G_USER_ID||',';
5096 
5097         l_statement := l_statement ||
5098                        ' LAST_UPDATE_LOGIN = '||G_LOGIN_ID||',';
5099 
5100         l_statement := SUBSTR(l_statement,1,LENGTH(l_statement)-1);
5101 
5102         l_statement := l_statement ||
5103           ' WHERE RESOURCE_ASSIGNMENT_ID  = '||TO_CHAR(p_resource_assignment_id) ||
5104           ' AND START_DATE = :xStartDate' ||
5105           ' AND TXN_CURRENCY_CODE = ' || '''' || l_txn_currency_code || ''''; /* FPB2: MRC */
5106 
5107 --dbms_output.put_line('Opening the cursor');
5108 --dbms_output.put_line(to_char(length(l_statement)));
5109 --dbms_output.put_line('Statement: '||substr(l_statement,1,100));
5110 --dbms_output.put_line('Statement: '||substr(l_statement,101,100));
5111 --dbms_output.put_line('Statement: '||substr(l_statement,201,100));
5112 
5113         l_cursor_id := DBMS_SQL.open_cursor;
5114         DBMS_SQL.parse(l_cursor_id, l_statement, DBMS_SQL.native);
5115 
5116         IF  p_description IS NOT NULL
5117           AND p_description <> nvl(l_budget_line_rec.description,FND_API.G_MISS_CHAR)
5118         THEN
5119               IF p_description = FND_API.G_MISS_CHAR THEN
5120                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xDescription', TO_CHAR(NULL));
5121               ELSE
5122                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xDescription', p_description);
5123               END IF;
5124         END IF;
5125 
5126         IF p_raw_cost IS NOT NULL
5127            AND p_raw_cost <> nvl(l_budget_line_rec.raw_cost,FND_API.G_MISS_NUM)
5128         THEN
5129               IF p_raw_cost = FND_API.G_MISS_NUM THEN
5130                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xRawCost', TO_NUMBER(NULL));
5131               ELSE
5132                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xRawCost', p_raw_cost);
5133               END IF;
5134         END IF;
5135 
5136         IF l_burdened_cost_flag = 'N'  -- added for burden_distributed_cost ='N'
5137         THEN
5138 
5139           IF p_raw_cost IS NOT NULL
5140           AND p_raw_cost <> nvl(l_budget_line_rec.burdened_cost,FND_API.G_MISS_NUM)
5141           THEN
5142               IF p_raw_cost = FND_API.G_MISS_NUM THEN
5143                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xRawCostForB', TO_NUMBER(NULL));
5144               ELSE
5145                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xRawCostForB', p_raw_cost);
5146               END IF;
5147           END IF;
5148 
5149         ELSE
5150 
5151          IF p_burdened_cost IS NOT NULL
5152           AND p_burdened_cost <> nvl(l_budget_line_rec.burdened_cost,FND_API.G_MISS_NUM)
5153          THEN
5154               IF p_burdened_cost = FND_API.G_MISS_NUM THEN
5155                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xBurdenedCost', TO_NUMBER(NULL));
5156               ELSE
5157                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xBurdenedCost', p_burdened_cost);
5158               END IF;
5159          END IF;
5160 
5161         END IF;--l_burdened_cost_flag = 'N'
5162 
5163         IF p_revenue IS NOT NULL
5164          AND p_revenue <> nvl(l_budget_line_rec.revenue,FND_API.G_MISS_NUM)
5165         THEN
5166               IF p_revenue = FND_API.G_MISS_NUM THEN
5167                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xRevenue',TO_NUMBER(NULL));
5168               ELSE
5169                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xRevenue',p_revenue);
5170               END IF;
5171         END IF;
5172 
5173         IF p_quantity IS NOT NULL
5174          AND p_quantity <> nvl(l_budget_line_rec.quantity,FND_API.G_MISS_NUM)
5175         THEN
5176               IF p_quantity = FND_API.G_MISS_NUM THEN
5177                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xQuantity',TO_NUMBER(NULL));
5178               ELSE
5179                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xQuantity',p_quantity);
5180               END IF;
5181         END IF;
5182 
5183         IF  p_change_reason_code IS NOT NULL
5184         AND p_change_reason_code <> nvl(l_budget_line_rec.change_reason_code,FND_API.G_MISS_CHAR)
5185         THEN
5186               IF p_change_reason_code = FND_API.G_MISS_CHAR THEN
5187                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xChangeReasonCode', TO_CHAR(NULL));
5188               ELSE
5189                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xChangeReasonCode', p_change_reason_code);
5190               END IF;
5191         END IF;
5192 
5193         IF  p_attribute_category IS NOT NULL
5194         AND p_attribute_category <> nvl(l_budget_line_rec.attribute_category,FND_API.G_MISS_CHAR)
5195         THEN
5196               IF p_attribute_category = FND_API.G_MISS_CHAR THEN
5197                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttributeCategory', TO_CHAR(NULL));
5198               ELSE
5199                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttributeCategory', p_attribute_category);
5200               END IF;
5201         END IF;
5202 
5203         IF  p_attribute1 IS NOT NULL
5204         AND p_attribute1 <> nvl(l_budget_line_rec.attribute1,FND_API.G_MISS_CHAR)
5205         THEN
5206               IF p_attribute1 = FND_API.G_MISS_CHAR THEN
5207                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute1', TO_CHAR(NULL));
5208               ELSE
5209                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute1', p_attribute1);
5210               END IF;
5211         END IF;
5212 
5213         IF  p_attribute2 IS NOT NULL
5214         AND p_attribute2 <> nvl(l_budget_line_rec.attribute2,FND_API.G_MISS_CHAR)
5215         THEN
5216               IF p_attribute2 = FND_API.G_MISS_CHAR THEN
5217                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute2', TO_CHAR(NULL));
5218               ELSE
5219                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute2', p_attribute2);
5220               END IF;
5221         END IF;
5222 
5223         IF  p_attribute3 IS NOT NULL
5224         AND p_attribute3 <> nvl(l_budget_line_rec.attribute3,FND_API.G_MISS_CHAR)
5225         THEN
5226               IF p_attribute3 = FND_API.G_MISS_CHAR THEN
5227                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute3', TO_CHAR(NULL));
5228               ELSE
5229                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute3', p_attribute3);
5230               END IF;
5231         END IF;
5232 
5233         IF  p_attribute4 IS NOT NULL
5234         AND p_attribute4 <> nvl(l_budget_line_rec.attribute4,FND_API.G_MISS_CHAR)
5235         THEN
5236               IF p_attribute4 = FND_API.G_MISS_CHAR THEN
5237                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute4', TO_CHAR(NULL));
5238               ELSE
5239                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute4', p_attribute4);
5240               END IF;
5241         END IF;
5242 
5243         IF  p_attribute5 IS NOT NULL
5244         AND p_attribute5 <> nvl(l_budget_line_rec.attribute5,FND_API.G_MISS_CHAR)
5245         THEN
5246               IF p_attribute5 = FND_API.G_MISS_CHAR THEN
5247                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute5', TO_CHAR(NULL));
5248               ELSE
5249                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute5', p_attribute5);
5250               END IF;
5251         END IF;
5252 
5253         IF  p_attribute6 IS NOT NULL
5254         AND p_attribute6 <> nvl(l_budget_line_rec.attribute6,FND_API.G_MISS_CHAR)
5255         THEN
5256               IF p_attribute6 = FND_API.G_MISS_CHAR THEN
5257                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute6', TO_CHAR(NULL));
5258               ELSE
5259                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute6', p_attribute6);
5260               END IF;
5261         END IF;
5262 
5263         IF  p_attribute7 IS NOT NULL
5264         AND p_attribute7 <> nvl(l_budget_line_rec.attribute7,FND_API.G_MISS_CHAR)
5265         THEN
5266               IF p_attribute7 = FND_API.G_MISS_CHAR THEN
5267                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute7', TO_CHAR(NULL));
5268               ELSE
5269                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute7', p_attribute7);
5270               END IF;
5271         END IF;
5272 
5273         IF  p_attribute8 IS NOT NULL
5274         AND p_attribute8 <> nvl(l_budget_line_rec.attribute8,FND_API.G_MISS_CHAR)
5275         THEN
5276               IF p_attribute8 = FND_API.G_MISS_CHAR THEN
5277                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute8', TO_CHAR(NULL));
5278               ELSE
5279                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute8', p_attribute8);
5280               END IF;
5281         END IF;
5282 
5283         IF  p_attribute9 IS NOT NULL
5284         AND p_attribute9 <> nvl(l_budget_line_rec.attribute9,FND_API.G_MISS_CHAR)
5285         THEN
5286               IF p_attribute9 = FND_API.G_MISS_CHAR THEN
5287                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute9', TO_CHAR(NULL));
5288               ELSE
5289                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute9', p_attribute9);
5290               END IF;
5291         END IF;
5292 
5293         IF  p_attribute10 IS NOT NULL
5294         AND p_attribute10 <> nvl(l_budget_line_rec.attribute10,FND_API.G_MISS_CHAR)
5295         THEN
5296               IF p_attribute10 = FND_API.G_MISS_CHAR THEN
5297                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute10', TO_CHAR(NULL));
5298               ELSE
5299                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute10', p_attribute10);
5300               END IF;
5301         END IF;
5302 
5303         IF  p_attribute11 IS NOT NULL
5304         AND p_attribute11 <> nvl(l_budget_line_rec.attribute11,FND_API.G_MISS_CHAR)
5305         THEN
5306               IF p_attribute11 = FND_API.G_MISS_CHAR THEN
5307                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute11', TO_CHAR(NULL));
5308               ELSE
5309                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute11', p_attribute11);
5310               END IF;
5311         END IF;
5312 
5313         IF  p_attribute12 IS NOT NULL
5314         AND p_attribute12 <> nvl(l_budget_line_rec.attribute12,FND_API.G_MISS_CHAR)
5315         THEN
5316               IF p_attribute12 = FND_API.G_MISS_CHAR THEN
5317                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute12', TO_CHAR(NULL));
5318               ELSE
5319                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute12', p_attribute12);
5320               END IF;
5321         END IF;
5322 
5323         IF  p_attribute13 IS NOT NULL
5324         AND p_attribute13 <> nvl(l_budget_line_rec.attribute13,FND_API.G_MISS_CHAR)
5325         THEN
5326               IF p_attribute13 = FND_API.G_MISS_CHAR THEN
5327                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute13', TO_CHAR(NULL));
5328               ELSE
5329                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute13', p_attribute13);
5330               END IF;
5331         END IF;
5332 
5333         IF  p_attribute14 IS NOT NULL
5334         AND p_attribute14 <> nvl(l_budget_line_rec.attribute14,FND_API.G_MISS_CHAR)
5335         THEN
5336               IF p_attribute14 = FND_API.G_MISS_CHAR THEN
5337                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute14', TO_CHAR(NULL));
5338               ELSE
5339                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute14', p_attribute14);
5340               END IF;
5341         END IF;
5342 
5343         IF  p_attribute15 IS NOT NULL
5344         AND p_attribute15 <> nvl(l_budget_line_rec.attribute15,FND_API.G_MISS_CHAR)
5345         THEN
5346               IF p_attribute15 = FND_API.G_MISS_CHAR THEN
5347                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute15', TO_CHAR(NULL));
5348               ELSE
5349                   DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xAttribute15', p_attribute15);
5350               END IF;
5351         END IF;
5352 
5353         --Dates should always be bound instead of concatenating them as strings to
5354         --avoid conversion problems.
5355         DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xLastUpdateDate', SYSDATE);
5356         DBMS_SQL.BIND_VARIABLE(l_cursor_id, ':xStartDate', p_start_date);
5357 
5358 
5359         l_rows   := DBMS_SQL.execute(l_cursor_id);
5360 
5361 --dbms_output.put_line('# rows processed: '||l_rows);
5362 
5363         IF DBMS_SQL.is_open (l_cursor_id)
5364         THEN
5365             DBMS_SQL.close_cursor (l_cursor_id);
5366         END IF;
5367 
5368             /* FPB2: MRC */
5369         BEGIN
5370              SELECT budget_line_id, budget_version_id --Bug 4224464
5371              INTO   l_budget_line_id, l_budget_version_id
5372              FROM   pa_budget_lines
5373              WHERE  resource_assignment_id = p_resource_assignment_id
5374              AND    start_date = p_start_date
5375              AND    txn_currency_code = l_txn_currency_code;
5376         EXCEPTION
5377              WHEN no_data_found THEN
5378                 l_budget_line_id := null; /* No budget line was updated */
5379         END;
5380         -- Bug Fix: 4569365. Removed MRC code.
5381 
5382         /* FPB2: Proceed with MRC only if a budget line was update */
5383         --Bug 4224464: changed IF condition to determine whether update has happened or not
5384         /*
5385          IF nvl(l_rows,0) > 0 THEN
5386 
5387              IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS IS NULL THEN
5388                     PA_MRC_FINPLAN.CHECK_MRC_INSTALL
5389                               (x_return_status      => l_return_status,
5390                                x_msg_count          => l_msg_count,
5391                                x_msg_data           => l_msg_data);
5392              END IF;
5393 
5394              IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS AND
5395                 PA_MRC_FINPLAN.G_FINPLAN_MRC_OPTION_CODE = 'A' THEN
5396                   PA_MRC_FINPLAN.MAINTAIN_ONE_MC_BUDGET_LINE
5397                              (p_budget_line_id => l_budget_line_id,
5398                               p_budget_version_id => l_budget_version_id,
5399                               p_action         => PA_MRC_FINPLAN.G_ACTION_UPDATE,
5400                               x_return_status  => l_return_status,
5401                               x_msg_count      => l_msg_count,
5402                               x_msg_data       => l_msg_data);
5403              END IF;
5404 
5405              IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5406                RAISE g_mrc_exception;
5407              END IF;
5408 
5409          END IF;--nvl(l_rows,0) > 0
5410          */
5411          --need to check for zero or null values in the case of a PA or GL phased budget
5412          --if so budget line needs to be deleted.
5413 
5414 --dbms_output.put_line('raw cost: '||NVL(to_char(l_budget_line_rec.raw_cost),'NULL'));
5415 --dbms_output.put_line('burdened cost: '||NVL(to_char(l_budget_line_rec.burdened_cost),'NULL'));
5416 --dbms_output.put_line('revenue: '||NVL(to_char(l_budget_line_rec.revenue),'NULL'));
5417 --dbms_output.put_line('quantity: '||NVL(to_char(l_budget_line_rec.quantity),'NULL'));
5418 
5419          IF p_time_phased_type_code IN ('G','P')
5420          THEN
5421 
5422             OPEN l_budget_line_csr( p_resource_assignment_id
5423                                  ,p_start_date  );
5424 
5425             FETCH l_budget_line_csr INTO l_budget_line_rec;
5426             CLOSE l_budget_line_csr;
5427 
5428 --dbms_output.put_line('raw cost: '||NVL(to_char(l_budget_line_rec.raw_cost),'NULL'));
5429 --dbms_output.put_line('burdened cost: '||NVL(to_char(l_budget_line_rec.burdened_cost),'NULL'));
5430 --dbms_output.put_line('revenue: '||NVL(to_char(l_budget_line_rec.revenue),'NULL'));
5431 --dbms_output.put_line('quantity: '||NVL(to_char(l_budget_line_rec.quantity),'NULL'));
5432 
5433             IF  NVL(l_budget_line_rec.raw_cost,0) = 0
5434             AND NVL(l_budget_line_rec.burdened_cost,0) = 0
5435             AND NVL(l_budget_line_rec.revenue,0) = 0
5436             AND NVL(l_budget_line_rec.quantity,0) = 0
5437             THEN
5438 
5439                   BEGIN
5440 --dbms_output.put_line('About to delete the budget line because of zero values');
5441                   PA_BUDGET_LINES_V_PKG.delete_row
5442                         ( x_rowid => l_budget_line_rec.rowid );
5443                           -- Bug Fix: 4569365. Removed MRC code.
5444 						  -- ,x_mrc_flag => 'Y'); /* FPB2: MRC */
5445 
5446                          -- Bug Fix: 4569365. Removed MRC code.
5447                         /* FPB2: MRC */
5448                         /*
5449                         IF nvl(l_rows,0) > 0 THEN--Calling MRC APIs only if a budget line was updated
5450 
5451                            IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS IS NULL THEN
5452                                   PA_MRC_FINPLAN.CHECK_MRC_INSTALL
5453                                             (x_return_status      => l_return_status,
5454                                              x_msg_count          => l_msg_count,
5455                                              x_msg_data           => l_msg_data);
5456                            END IF;
5457 
5458                            IF PA_MRC_FINPLAN.G_MRC_ENABLED_FOR_BUDGETS AND
5459                               PA_MRC_FINPLAN.G_FINPLAN_MRC_OPTION_CODE = 'A' THEN
5460                                 PA_MRC_FINPLAN.MAINTAIN_ONE_MC_BUDGET_LINE
5461                                            (p_budget_line_id => l_budget_line_rec.budget_line_id,
5462                                             p_budget_version_id => l_budget_line_rec.budget_version_id,
5463                                             p_action         => PA_MRC_FINPLAN.G_ACTION_DELETE,
5464                                             x_return_status  => l_return_status,
5465                                             x_msg_count      => l_msg_count,
5466                                             x_msg_data       => l_msg_data);
5467                            END IF;
5468 
5469                            IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5470                              RAISE g_mrc_exception;
5471                            END IF;
5472                         END IF; --nvl(l_rows,0) > 0
5473                         */
5474                   --this exception part is here because this procedure doesn't handle the exceptions itself.
5475                   EXCEPTION
5476                   WHEN OTHERS
5477                   THEN
5478 
5479                         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5480                         THEN
5481                               FND_MSG_PUB.add_exc_msg
5482                               (  p_pkg_name           => 'PA_BUDGET_LINES_V_PKG'
5483                               ,  p_procedure_name     => 'DELETE_ROW'
5484                               ,  p_error_text         => SQLCODE              );
5485                         END IF;
5486                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5487                   END;
5488 
5489             END IF;
5490          END IF;  --time phased by PA or GL period
5491     END IF;--l_update_yes_flag = 'Y'
5492 
5493 EXCEPTION
5494 
5495       WHEN FND_API.G_EXC_ERROR
5496       THEN
5497 
5498       ROLLBACK TO update_budget_line_sql_pvt;
5499 
5500       p_return_status := FND_API.G_RET_STS_ERROR;
5501 
5502       WHEN FND_API.G_EXC_UNEXPECTED_ERROR
5503       THEN
5504 
5505       ROLLBACK TO update_budget_line_sql_pvt;
5506 
5507       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5508 
5509       WHEN OTHERS THEN
5510 
5511       ROLLBACK TO update_budget_line_sql_pvt;
5512 
5513       p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5514 
5515       IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5516       THEN
5517             FND_MSG_PUB.add_exc_msg
5518             (  p_pkg_name           => G_PKG_NAME
5519             ,  p_procedure_name     => l_api_name );
5520 
5521       END IF;
5522 
5523 
5524 END update_budget_line_sql;
5525 
5526 
5527 ----------------------------------------------------------------------------------------
5528 --Name:               get_valid_period_dates
5529 --Type:               Procedure
5530 --Description:        This procedure can be used to get the valid begin and end date
5531 --                for a budget line
5532 --
5533 --
5534 --Called subprograms:
5535 --
5536 --
5537 --
5538 --History:
5539 --   10-OCT-1996         L. de Werker    Created
5540 --   17-OCT-1996         L. de Werker    Parameter p_period_name_out added, to enable the translation
5541 --                                       of begin and end date to a period name.
5542 --   09-Nov-2004         dbora           Bug 3986129: FP.M Web ADI Dev changes
5543 --                                       Modified to take care of the spec changes
5544 --                                       of pa_budget_check_pvt.get_valid_period_dates_Pvt
5545 
5546 PROCEDURE get_valid_period_dates
5547 ( p_return_status             OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5548  ,p_project_id                IN    NUMBER
5549  ,p_task_id                   IN    NUMBER
5550  ,p_time_phased_type_code     IN    VARCHAR2
5551  ,p_entry_level_code          IN    VARCHAR2
5552  ,p_period_name_in            IN    VARCHAR2
5553  ,p_budget_start_date_in      IN    DATE
5554  ,p_budget_end_date_in        IN    DATE
5555  ,p_period_name_out           OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5556  ,p_budget_start_date_out     OUT   NOCOPY DATE --File.Sql.39 bug 4440895
5557  ,p_budget_end_date_out       OUT   NOCOPY DATE --File.Sql.39 bug 4440895
5558 
5559 -- Bug 3986129: FP.M Web ADI Dev changes
5560  ,p_context                IN   VARCHAR2
5561  ,p_calling_model_context     IN   VARCHAR2
5562  ,x_error_code             OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5563  )
5564 IS
5565 
5566 BEGIN
5567 
5568 pa_budget_check_pvt.get_valid_period_dates_Pvt
5569 (p_return_status                    => p_return_status
5570 ,p_project_id                       => p_project_id
5571 ,p_task_id                          => p_task_id
5572 ,p_time_phased_type_code            => p_time_phased_type_code
5573 ,p_entry_level_code                 => p_entry_level_code
5574 ,p_period_name_in                   => p_period_name_in
5575 ,p_budget_start_date_in             => p_budget_start_date_in
5576 ,p_budget_end_date_in               => p_budget_end_date_in
5577 ,p_period_name_out                  => p_period_name_out
5578 ,p_budget_start_date_out            => p_budget_start_date_out
5579 ,p_budget_end_date_out              => p_budget_end_date_out
5580 
5581 -- Bug 3986129: FP.M Web ADI Dev changes
5582  ,p_context                         => p_context
5583  ,p_calling_model_context           => p_calling_model_context
5584  ,x_error_code                      => x_error_code);
5585 
5586 END get_valid_period_dates;
5587 
5588 
5589 ----------------------------------------------------------------------------------------
5590 --Name:               check_entry_method_flags
5591 --Type:               Procedure
5592 --Description:        This procedure can be used to check whether it is allowed to pass
5593 --                cost quantity, raw_cost, burdened_cost, revenue and revenue quantity.
5594 --
5595 --
5596 --Called subprograms:
5597 --
5598 --
5599 --
5600 --History:
5601 --    15-OCT-1996        L. de Werker    Created
5602 --    08-Nov-2004        dbora           Bug 3986129: FP.M Web ADI Dev changes
5603 --                                       Modified to take care of the spec changes
5604 --                                       of pa_budget_check_pvt.check_entry_method_flags_pvt
5605 
5606 PROCEDURE check_entry_method_flags
5607 ( p_return_status             OUT   NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5608  ,p_budget_amount_code        IN    VARCHAR2
5609  ,p_budget_entry_method_code  IN    VARCHAR2
5610  ,p_quantity                  IN    NUMBER
5611  ,p_raw_cost                  IN    NUMBER
5612  ,p_burdened_cost             IN    NUMBER
5613  ,p_revenue                   IN    NUMBER
5614  ,p_version_type              IN    VARCHAR2
5615  ,p_allow_qty_flag            IN    VARCHAR2
5616  ,p_allow_raw_cost_flag       IN    VARCHAR2
5617  ,p_allow_burdened_cost_flag  IN    VARCHAR2
5618  ,p_allow_revenue_flag        IN    VARCHAR2
5619 
5620 -- Bug 3986129: FP.M Web ADI Dev changes, new parameters
5621  ,p_context                   IN  VARCHAR2
5622  ,p_raw_cost_rate             IN  NUMBER
5623  ,p_burdened_cost_rate        IN  NUMBER
5624  ,p_bill_rate                 IN  NUMBER
5625  ,p_allow_raw_cost_rate_flag  IN  VARCHAR2
5626  ,p_allow_burd_cost_rate_flag IN  VARCHAR2
5627  ,p_allow_bill_rate_flag      IN  VARCHAR2
5628  ,x_webadi_error_code         OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5629 )
5630 IS
5631 
5632 BEGIN
5633 
5634       pa_budget_check_pvt.check_entry_method_flags_pvt
5635       (p_return_status                => p_return_status
5636       ,p_budget_amount_code           => p_budget_amount_code
5637       ,p_budget_entry_method_code     => p_budget_entry_method_code
5638       ,p_quantity                     => p_quantity
5639       ,p_raw_cost                     => p_raw_cost
5640       ,p_burdened_cost                => p_burdened_cost
5641       ,p_revenue                      => p_revenue
5642       ,p_version_type                 => p_version_type
5643       ,p_allow_qty_flag               => p_allow_qty_flag
5644       ,p_allow_raw_cost_flag          => p_allow_raw_cost_flag
5645       ,p_allow_burdened_cost_flag     => p_allow_burdened_cost_flag
5646       ,p_allow_revenue_flag           => p_allow_revenue_flag
5647 
5648       --Bug 3986129: FP.M Web ADI Dev changes
5649       ,p_context                      => p_context
5650       ,p_raw_cost_rate                => p_raw_cost_rate
5651       ,p_burdened_cost_rate           => p_burdened_cost_rate
5652       ,p_bill_rate                    => p_bill_rate
5653       ,p_allow_raw_cost_rate_flag     => p_allow_raw_cost_rate_flag
5654       ,p_allow_burd_cost_rate_flag    => p_allow_burd_cost_rate_flag
5655       ,p_allow_bill_rate_flag         => p_allow_bill_rate_flag
5656       ,x_webadi_error_code            => x_webadi_error_code);
5657 
5658 
5659 END check_entry_method_flags;
5660 
5661 
5662 --This procedure is created as part of FinPlan Development. All the validations
5663 --are shifted from insert_budget_line to this procedure. This procedure handles the
5664 --validations for both budget and finplan models
5665 
5666 -- sgoteti         14-Feb-03      Created
5667 -- rravipat        24-Jun-04      Bug 3717093  Commented out the validation put
5668 --                                included by hari on 11th may. The api is called
5669 --                                with the same context for both old budgets model
5670 --                                versions and nee budgets model versions.
5671 -- rishukla        09-May-05      Bug 4224464: FP M Changes - Added validation for
5672 --                                actual amounts on Forecast lines.
5673 -- sgoteti         11-May-05      Added p_run_id parameter. This parameter will be used in web ADI flow only
5674 PROCEDURE Validate_Budget_Lines
5675 ( p_calling_context                 IN     VARCHAR2 DEFAULT 'BUDGET_LINE_LEVEL_VALIDATION'
5676  ,p_run_id                          IN     pa_fp_webadi_upload_inf.run_id%TYPE
5677  ,p_pa_project_id                   IN     pa_projects_all.project_id%TYPE
5678  ,p_budget_type_code                IN     pa_budget_types.budget_type_code%TYPE
5679  ,p_fin_plan_type_id                IN     pa_fin_plan_types_b.fin_plan_type_id%TYPE
5680  ,p_version_type                    IN     pa_budget_versions.version_type%TYPE
5681  ,p_resource_list_id                IN     pa_resource_lists_all_bg.resource_list_id%TYPE
5682  ,p_time_phased_code                IN     pa_proj_fp_options.cost_time_phased_code%TYPE
5683  ,p_budget_entry_method_code        IN     pa_budget_entry_methods.budget_entry_method_code%TYPE
5684  ,p_entry_level_code                IN     pa_proj_fp_options.cost_fin_plan_level_code%TYPE
5685  ,p_allow_qty_flag                  IN     VARCHAR2
5686  ,p_allow_raw_cost_flag             IN     VARCHAR2
5687  ,p_allow_burdened_cost_flag        IN     VARCHAR2
5688  ,p_allow_revenue_flag              IN     VARCHAR2
5689  ,p_multi_currency_flag             IN     pa_proj_fp_options.plan_in_multi_curr_flag%TYPE
5690  ,p_project_cost_rate_type          IN     pa_proj_fp_options.project_cost_rate_type%TYPE
5691  ,p_project_cost_rate_date_typ      IN     pa_proj_fp_options.project_cost_rate_date_type%TYPE
5692  ,p_project_cost_rate_date          IN     pa_proj_fp_options.project_cost_rate_date%TYPE
5693  ,p_project_cost_exchange_rate      IN     pa_budget_lines.project_cost_exchange_rate%TYPE
5694  ,p_projfunc_cost_rate_type         IN     pa_proj_fp_options.projfunc_cost_rate_type%TYPE
5695  ,p_projfunc_cost_rate_date_typ     IN     pa_proj_fp_options.projfunc_cost_rate_date_type%TYPE
5696  ,p_projfunc_cost_rate_date         IN     pa_proj_fp_options.projfunc_cost_rate_date%TYPE
5697  ,p_projfunc_cost_exchange_rate     IN     pa_budget_lines.projfunc_cost_exchange_rate%TYPE
5698  ,p_project_rev_rate_type           IN     pa_proj_fp_options.project_rev_rate_type%TYPE
5699  ,p_project_rev_rate_date_typ       IN     pa_proj_fp_options.project_rev_rate_date_type%TYPE
5700  ,p_project_rev_rate_date           IN     pa_proj_fp_options.project_rev_rate_date%TYPE
5701  ,p_project_rev_exchange_rate       IN     pa_budget_lines.project_rev_exchange_rate%TYPE
5702  ,p_projfunc_rev_rate_type          IN     pa_proj_fp_options.projfunc_rev_rate_type%TYPE
5703  ,p_projfunc_rev_rate_date_typ      IN     pa_proj_fp_options.projfunc_rev_rate_date_type%TYPE
5704  ,p_projfunc_rev_rate_date          IN     pa_proj_fp_options.projfunc_rev_rate_date%TYPE
5705  ,p_projfunc_rev_exchange_rate      IN     pa_budget_lines.project_rev_exchange_rate%TYPE
5706 
5707   /* Bug 3986129: FP.M Web ADI Dev changes: New parameters added */
5708  ,p_version_info_rec                IN     pa_fp_gen_amount_utils.fp_cols
5709  ,p_allow_raw_cost_rate_flag        IN     VARCHAR2
5710  ,p_allow_burd_cost_rate_flag       IN     VARCHAR2
5711  ,p_allow_bill_rate_flag            IN     VARCHAR2
5712  ,p_raw_cost_rate_tbl               IN     SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type()
5713  ,p_burd_cost_rate_tbl              IN     SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type()
5714  ,p_bill_rate_tbl                   IN     SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type()
5715  ,p_uom_tbl                         IN     SYSTEM.pa_varchar2_80_tbl_type := SYSTEM.pa_varchar2_80_tbl_type()
5716  ,p_planning_start_date_tbl         IN     SYSTEM.pa_date_tbl_type := SYSTEM.pa_date_tbl_type()
5717  ,p_planning_end_date_tbl           IN     SYSTEM.pa_date_tbl_type := SYSTEM.pa_date_tbl_type()
5718  ,p_delete_flag_tbl                 IN     SYSTEM.pa_varchar2_1_tbl_type := SYSTEM.pa_varchar2_1_tbl_type()
5719  ,p_mfc_cost_type_tbl               IN     SYSTEM.PA_VARCHAR2_15_TBL_TYPE  := SYSTEM.PA_VARCHAR2_15_TBL_TYPE()
5720  ,p_spread_curve_name_tbl           IN     SYSTEM.PA_VARCHAR2_240_TBL_TYPE := SYSTEM.PA_VARCHAR2_240_TBL_TYPE()
5721  ,p_sp_fixed_date_tbl               IN     SYSTEM.PA_DATE_TBL_TYPE         := SYSTEM.PA_DATE_TBL_TYPE()
5722  ,p_etc_method_name_tbl             IN     SYSTEM.PA_VARCHAR2_80_TBL_TYPE  := SYSTEM.PA_VARCHAR2_80_TBL_TYPE()
5723  ,p_spread_curve_id_tbl             IN     SYSTEM.PA_NUM_TBL_TYPE          := SYSTEM.PA_NUM_TBL_TYPE()
5724  ,p_amount_type_tbl                 IN     SYSTEM.PA_VARCHAR2_30_TBL_TYPE  := SYSTEM.PA_VARCHAR2_30_TBL_TYPE()
5725  /* Bug 3986129: end*/
5726 
5727  ,px_budget_lines_in                IN OUT NOCOPY PA_BUDGET_PUB.G_BUDGET_LINES_IN_TBL%TYPE --File.Sql.39 bug 4440895
5728  /* Bug 3133930- a new output variable is introduced to return the error status */
5729  ,x_budget_lines_out                OUT    NOCOPY PA_BUDGET_PUB.G_BUDGET_LINES_OUT_TBL%TYPE --File.Sql.39 bug 4440895
5730 /* Bug 3986129: FP.M Web ADI Dev changes: New parameters added */
5731  ,x_mfc_cost_type_id_tbl            OUT    NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
5732  ,x_etc_method_code_tbl             OUT    NOCOPY SYSTEM.pa_varchar2_30_tbl_type --File.Sql.39 bug 4440895
5733  ,x_spread_curve_id_tbl             OUT    NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
5734  ,x_msg_count                       OUT    NOCOPY NUMBER --File.Sql.39 bug 4440895
5735  ,x_msg_data                        OUT    NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5736  ,x_return_status                   OUT    NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
5737 )
5738 IS
5739 
5740       --Declare a pl/sql table for storing the txn currencies of the plan type
5741 
5742       --l_valid_txn_currencies_tbl  pa_fp_webadi_pkg.l_txn_currency_code_tbl_typ;    Bug 2871603
5743       --Bug 2871603 - Created a package pvt defn for l_txn_currency_code_tbl_typ and using it.
5744       l_valid_txn_currencies_tbl  l_txn_currency_code_tbl_typ;
5745 
5746       --following table will contain the top task planning levels.
5747       l_top_tasks_tbl             key_value_rec_tbl_type;
5748       l_temp                      NUMBER;
5749 
5750 
5751       --This cursor is used to fetch the txn currencies of the plan type
5752       CURSOR l_plan_type_txn_curr_csr
5753              ( c_proj_fp_options_id  pa_fp_txn_currencies.proj_fp_options_id%TYPE
5754               ,c_project_id       pa_fp_txn_currencies.project_id%TYPE)
5755       IS
5756       SELECT txn_currency_code
5757       FROM   pa_fp_txn_currencies ptxn
5758             ,pa_projects_all p
5759       WHERE  p.project_id=c_project_id
5760       AND    ptxn.project_id = p.project_id
5761       AND    ptxn.txn_currency_code NOT IN (p.project_currency_code, p.projfunc_currency_code)
5762       AND    ptxn.proj_fp_options_id  = c_proj_fp_options_id;  --made changes to the sql for bug 4886319 (performance)
5763 
5764 
5765       -- this cursor is used to fetch the txn currencies of the plan version for web adi context
5766       CURSOR l_plan_ver_txn_curr_csr
5767              ( c_fin_plan_type_id      pa_fp_txn_currencies.fin_plan_type_id%TYPE
5768               ,c_project_id            pa_fp_txn_currencies.project_id%TYPE
5769               ,c_fin_plan_version_id   pa_fp_txn_currencies.fin_plan_version_id%TYPE)
5770       IS
5771       SELECT txn_currency_code
5772       FROM   pa_fp_txn_currencies ptxn
5773             ,pa_projects_all p
5774       WHERE  p.project_id = c_project_id
5775       AND    ptxn.project_id = p.project_id
5776       AND    ptxn.fin_plan_type_id = c_fin_plan_type_id
5777       AND    ptxn.txn_currency_code NOT IN (p.project_currency_code, p.projfunc_currency_code)
5778       AND    ptxn.fin_plan_version_id = c_fin_plan_version_id;
5779 
5780       --cursor to get the unit_of_measure and track_as_labor_flag for this resource_list_member
5781       --and check for valid resource_list / member combination
5782       CURSOR l_resource_csr
5783             (c_resource_list_member_id NUMBER
5784             ,c_resource_list_id        NUMBER)
5785       IS
5786       SELECT pr.unit_of_measure
5787             ,prlm.track_as_labor_flag
5788             ,prlm.migration_code
5789       FROM   pa_resources pr
5790             ,pa_resource_lists prl
5791             ,pa_resource_list_members prlm
5792       WHERE  prl.resource_list_id = c_resource_list_id
5793       AND    pr.resource_id = prlm.resource_id
5794       AND    prl.resource_list_id = prlm.resource_list_id
5795       AND    prlm.resource_list_member_id = c_resource_list_member_id;
5796 
5797       --cursor to get the unit_of_measure for FINPLAN Model - 3801891
5798       CURSOR l_resource_csr_fp
5799             (c_resource_list_member_id NUMBER)
5800       IS
5801       SELECT prlm.unit_of_measure,
5802              prlm.migration_code
5803       FROM   pa_resource_list_members prlm
5804       WHERE  prlm.resource_list_member_id = c_resource_list_member_id;
5805 
5806       --cursor to get the field values associated to a AMG message
5807       CURSOR l_amg_project_csr
5808              (c_pa_project_id pa_projects.project_id%type)
5809       IS
5810       SELECT segment1
5811       FROM   pa_projects p
5812       WHERE  p.project_id = c_pa_project_id;
5813 
5814       l_amg_project_rec     l_amg_project_csr%ROWTYPE;
5815 
5816       CURSOR l_amg_task_csr
5817             (c_pa_task_id pa_tasks.task_id%type)
5818       IS
5819       SELECT task_number
5820       FROM   pa_tasks p
5821       WHERE  p.task_id = c_pa_task_id;
5822 
5823       --This cursor is used to get the approved rev plan type flag of the plan type
5824       --Added as part of the changes for fin plan model in FP L
5825       CURSOR l_approved_revenue_flag_csr
5826                                         ( c_fin_plan_type_id pa_fin_plan_types_b.fin_plan_type_id%TYPE
5827                                          ,c_project_id pa_projects_all.project_id%TYPE)
5828       IS
5829       SELECT approved_rev_plan_type_flag,
5830              proj_fp_options_id
5831       FROM   pa_proj_fp_options
5832       WHERE  project_id=c_project_id
5833       AND    fin_plan_type_id=c_fin_plan_type_id
5834       AND    fin_plan_option_level_code=PA_FP_CONSTANTS_PKG.G_OPTION_LEVEL_PLAN_TYPE;
5835 
5836       /* Bug 4224464: FP M Changes Start */
5837       --Cursor to derive plan_class_code and etc_start_date for a budget version
5838       CURSOR budget_version_info_cur (c_budget_version_id IN NUMBER)
5839       IS
5840       SELECT  pt.plan_class_code
5841              ,bv.etc_start_date
5842       FROM    pa_budget_versions bv,
5843               pa_fin_plan_types_b pt
5844       WHERE   bv.budget_version_id = c_budget_version_id
5845       AND     pt.fin_plan_type_id = bv.fin_plan_type_id;
5846 
5847       l_plan_class_code                   pa_fin_plan_types_b.plan_class_code%TYPE;
5848       l_etc_start_date                    pa_budget_versions.etc_start_date%TYPE;
5849       /* Bug 4224464: FP M Changes End */
5850 
5851       l_app_rev_plan_type_flag            pa_proj_fp_options.approved_rev_plan_type_flag%TYPE;
5852 
5853       l_msg_count                         NUMBER := 0;
5854       l_data                              VARCHAR2(2000);
5855       l_msg_data                          VARCHAR2(2000);
5856       l_msg_index_out                     NUMBER;
5857       l_debug_mode                        VARCHAR2(1);
5858 
5859       l_debug_level2             CONSTANT NUMBER := 2;
5860       l_debug_level3             CONSTANT NUMBER := 3;
5861       l_debug_level4             CONSTANT NUMBER := 4;
5862       l_debug_level5             CONSTANT NUMBER := 5;
5863 
5864       l_return_status                     VARCHAR2(1);
5865       l_return_status_task                NUMBER;
5866       l_unit_of_measure                   VARCHAR2(30);
5867       l_track_as_labor_flag               VARCHAR2(1);
5868       l_err_code                          NUMBER;
5869       l_err_stage                         VARCHAR2(120);
5870       l_err_stack                         VARCHAR2(630);
5871       l_amg_segment1                      VARCHAR2(25);
5872       l_amg_task_number                   VARCHAR2(50);
5873       l_amg_top_task_number               VARCHAR2(50);
5874       l_any_error_occurred_flag           VARCHAR2(1) :='N';
5875       l_budget_lines_tbl_index            NUMBER;
5876       l_budget_amount_code                pa_budget_types.budget_amount_code%TYPE;
5877       l_txn_tbl_index                     NUMBER;
5878       i                                   NUMBER;
5879       l_valid_txn_curr                    BOOLEAN;
5880       l_txn_curr_code                     pa_fp_txn_currencies.txn_currency_code%TYPE;
5881       l_parent_member_id                  pa_resource_list_members.parent_member_id%TYPE;
5882       l_conv_attrs_to_be_validated        VARCHAR2(10);
5883       l_module_name                       VARCHAR2(80);
5884       l_top_task_id                       pa_tasks.top_task_id%TYPE;
5885       l_dummy                             VARCHAR2(1);
5886       l_txn_currency_code                 pa_fp_txn_currencies.txn_currency_code%TYPE;
5887       l_multi_currency_billing_flag       pa_projects_all.multi_currency_billing_flag%TYPE;
5888       l_project_currency_code             pa_projects_all.project_currency_code%TYPE      ;
5889       l_projfunc_currency_code            pa_projects_all.projfunc_currency_code%TYPE     ;
5890       l_project_cost_rate_type            pa_projects_all.project_rate_type%TYPE          ;
5891       l_projfunc_cost_rate_type           pa_projects_all.projfunc_cost_rate_type%TYPE    ;
5892       l_project_bil_rate_type             pa_projects_all.project_bil_rate_type%TYPE      ;
5893       l_projfunc_bil_rate_type            pa_projects_all.projfunc_bil_rate_type%TYPE     ;
5894       l_top_task_planning_level           pa_fp_elements.top_task_planning_level%TYPE;
5895       l_res_planning_level                pa_fp_elements.resource_planning_level%TYPE;
5896       l_uncategorized_res_list_id         pa_resource_list_members.resource_list_id%TYPE;
5897       l_uncategorized_rlmid               pa_resource_list_members.resource_list_member_id%TYPE;
5898       l_uncategorized_resid               pa_resource_list_members.resource_id%TYPE;
5899       l_res_group_name                    pa_resource_list_members.alias%TYPE;
5900       l_valid_rlmid                       VARCHAR2(1);
5901       l_fin_plan_type_name                pa_fin_plan_types_tl.name%TYPE;
5902       l_resource_type_code                pa_resource_list_members.resource_type_code%TYPE;
5903       l_context_info                      pa_fin_plan_types_tl.name%TYPE;
5904       l_pm_product_code                   pa_budget_lines.pm_product_code%TYPE;
5905 
5906       -- Cursor used in validating the product code
5907       Cursor p_product_code_csr (c_pm_product_code IN VARCHAR2)
5908       Is
5909       Select 'X'
5910       from   pa_lookups
5911       where  lookup_type='PM_PRODUCT_CODE'
5912       and    lookup_code = c_pm_product_code;
5913 
5914       -- Bug 3986129: FP.M Web ADI Dev changes
5915       l_spread_curve_id                   pa_spread_curves_b.spread_curve_id%TYPE;
5916       l_valid_spread_curve                VARCHAR2(1) := 'Y';
5917       l_etc_method_code                   pa_lookups.lookup_code%TYPE;
5918       l_valid_etc_method                  VARCHAR2(1) := 'Y';
5919       l_mfc_cost_type_id                  CST_COST_TYPES_V.cost_type_id%TYPE;
5920       l_valid_mfc_cost_type                VARCHAR2(1) := 'Y';
5921 
5922       l_webadi_sp_fix_date                DATE;
5923       l_webadi_err_code_tbl               SYSTEM.pa_varchar2_30_tbl_type := SYSTEM.pa_varchar2_30_tbl_type();
5924       l_new_error_code                    pa_lookups.lookup_code%TYPE;
5925       l_webadi_err_task_id_tbl            SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
5926       l_webadi_err_rlm_id_tbl             SYSTEM.pa_num_tbl_type := SYSTEM.pa_num_tbl_type();
5927       l_webadi_err_txn_curr_tbl           SYSTEM.pa_varchar2_30_tbl_type := SYSTEM.pa_varchar2_30_tbl_type();
5928       l_webadi_err_amt_type_tbl           SYSTEM.pa_varchar2_30_tbl_type := SYSTEM.pa_varchar2_30_tbl_type();
5929       l_webadi_err_prd_flag               VARCHAR2(1) := 'N';
5930       l_webadi_cont_proc_flag             VARCHAR2(1):= 'Y';
5931 
5932       TYPE web_adi_err_code_lookup IS TABLE OF VARCHAR2(30) INDEX BY VARCHAR2(30);
5933       l_wa_error_code_lookup              web_adi_err_code_lookup;
5934 
5935       -- for bug 3954329
5936       l_rlm_migration_code             pa_resource_lists_all_bg.migration_code%TYPE;
5937 
5938       l_wa_project_cost_rate_typ               pa_proj_fp_options.project_cost_rate_type%TYPE;
5939       l_wa_project_cost_rate_dt_typ            pa_proj_fp_options.project_cost_rate_date_type%TYPE;
5940       l_wa_project_cost_rate_date              pa_proj_fp_options.project_cost_rate_date%TYPE;
5941       l_wa_project_cost_exc_rate               pa_budget_lines.project_cost_exchange_rate%TYPE;
5942       l_wa_projfunc_cost_rate_typ              pa_proj_fp_options.projfunc_cost_rate_type%TYPE;
5943       l_wa_projfunc_cost_rate_dt_typ           pa_proj_fp_options.projfunc_cost_rate_date_type%TYPE;
5944       l_wa_projfunc_cost_rate_date             pa_proj_fp_options.projfunc_cost_rate_date%TYPE;
5945       l_wa_projfunc_cost_exc_rate              pa_budget_lines.projfunc_cost_exchange_rate%TYPE;
5946       l_wa_project_rev_rate_typ                pa_proj_fp_options.project_rev_rate_type%TYPE;
5947       l_wa_project_rev_rate_dt_typ             pa_proj_fp_options.project_rev_rate_date_type%TYPE;
5948       l_wa_project_rev_rate_date               pa_proj_fp_options.project_rev_rate_date%TYPE;
5949       l_wa_project_rev_exc_rate                pa_budget_lines.project_rev_exchange_rate%TYPE;
5950       l_wa_projfunc_rev_rate_typ               pa_proj_fp_options.projfunc_rev_rate_type%TYPE;
5951       l_wa_projfunc_rev_rate_dt_typ            pa_proj_fp_options.projfunc_rev_rate_date_type%TYPE;
5952       l_wa_projfunc_rev_rate_date              pa_proj_fp_options.projfunc_rev_rate_date%TYPE;
5953       l_wa_projfunc_rev_exc_rate               pa_budget_lines.project_rev_exchange_rate%TYPE;
5954       l_wa_val_conv_attr_flag                  VARCHAR2(1);
5955       l_calling_model_context   VARCHAR(30);
5956 
5957 
5958      -- Added for the bug 4414062
5959       l_period_time_phased_code  VARCHAR(1);
5960       l_period_plan_start_date   DATE;
5961       l_period_plan_end_date     DATE;
5962 
5963       -- bug 4462614: add the following cursor to be executed for Web ADI flow
5964       -- to check if the budget lines passed belongs to a CI version
5965       CURSOR check_and_return_ci_version (c_budget_version_id     pa_budget_versions.budget_version_id%TYPE)
5966       IS
5967       SELECT pbv.ci_id,
5968              agr.agreement_currency_code
5969       FROM   pa_budget_versions pbv,
5970              pa_agreements_all agr
5971       WHERE  pbv.budget_version_id = c_budget_version_id
5972       AND    pbv.agreement_id = agr.agreement_id;
5973 
5974       l_webadi_agr_curr_code           pa_agreements_all.agreement_currency_code%TYPE;
5975       l_webadi_ci_id                   pa_budget_versions.ci_id%TYPE;
5976 
5977       l_period_start_date    DATE;
5978       l_period_end_date      DATE;
5979       l_plan_start_date      pa_resource_assignments.planning_start_date%type;
5980       l_plan_end_date        pa_resource_assignments.planning_end_date%type;
5981 
5982       TYPE varchr_32_index_date_tbl_typ   IS TABLE OF DATE INDEX BY VARCHAR2(32);
5983       TYPE varchr_32_index_varchr_tbl_typ IS TABLE OF VARCHAR2(100) INDEX BY VARCHAR2(32);
5984 
5985       l_plan_start_date_tbl                varchr_32_index_date_tbl_typ;
5986       l_plan_end_date_tbl                  varchr_32_index_date_tbl_typ;
5987       l_task_name_tbl                      varchr_32_index_varchr_tbl_typ;
5988       l_resource_alias_tbl                 varchr_32_index_varchr_tbl_typ;
5989       l_distinct_taskid_rlmid_index        VARCHAR2(32);  --Index to store task id and rlm id comnination.
5990       l_resource_alias                     pa_resource_list_members.alias%type;
5991 
5992       TYPE varchr_120_index_num_tbl_typ IS TABLE OF NUMBER(15) INDEX BY VARCHAR2(120);
5993       l_distinct_rlmid_idx        VARCHAR2(120);  --Index to store rlm id and resource alias
5994       l_rlm_id_tbl                         varchr_120_index_num_tbl_typ;
5995 
5996       TYPE varchr_30_index_num_tbl_typ IS TABLE OF NUMBER(15) INDEX BY VARCHAR2(30);
5997       l_distinct_tskid_idx        VARCHAR2(30);  --Index to store task id and task name
5998       l_tsk_id_tbl                varchr_30_index_num_tbl_typ;
5999 
6000       --Added thses date tables for bug#4488926.
6001       TYPE date_tbl_type IS TABLE OF DATE INDEX BY VARCHAR2(20);
6002       l_period_start_date_tbl         date_tbl_type;
6003       l_period_end_date_tbl           date_tbl_type;
6004       l_period_plan_start_date_tbl    date_tbl_type;
6005       l_period_plan_end_date_tbl      date_tbl_type;
6006       l_proj_fp_options_id             pa_proj_fp_options.proj_fp_options_id%TYPE;
6007 
6008      l_fixed_date_sp_id             number;
6009      l_resource_assignment_id       number;
6010      l_planning_start_date          date;
6011      l_planning_end_date            date;
6012      l_sp_fixed_date                date;
6013      l_invalid_plandates_flag       varchar2(1);
6014      l_invalid_resassgn_flag        varchar2(1);
6015      l_project_number               varchar2(25);
6016      l_raid_hash_table              res_assign_tbl_type1;
6017 
6018 
6019 
6020 BEGIN
6021       x_msg_count :=0;
6022       x_return_status := FND_API.G_RET_STS_SUCCESS;
6023       l_debug_mode  := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
6024       l_module_name := 'Validate_Budget_Lines: ' || g_module_name;
6025 
6026 	  IF l_debug_mode = 'Y' THEN
6027 	      pa_debug.set_curr_function( p_function   => 'Validate_Budget_Lines',
6028                                   p_debug_mode => l_debug_mode );
6029 
6030       --dbms_output.put_line('----- Entering into validate_budget_lines-------');
6031               pa_debug.g_err_stage:= 'Validating input parameters';
6032               pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6033       END IF;
6034 
6035  /* Bug 3717093 This api is called both for new and old budgets model versions
6036       -- hari 11th may
6037       IF ( p_calling_context = 'BUDGET_LINE_LEVEL_VALIDATION' AND p_budget_type_code IS NULL )
6038       THEN
6039                   PA_UTILS.ADD_MESSAGE
6040                       (p_app_short_name => 'PA',
6041                        p_msg_name     => 'PA_FP_INV_PARAM_PASSED');
6042                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6043       END IF;
6044       Bug 3717093 */
6045 
6046       /*============================================================+
6047        | Bug 3717093 : Replaced the above check with the following. |
6048        +============================================================*/
6049       IF ( p_calling_context in('RES_ASSGNMT_LEVEL_VALIDATION','UPDATE_PLANNING_ELEMENT_ATTR') AND p_budget_type_code IS NOT NULL )
6050       THEN
6051                   PA_UTILS.ADD_MESSAGE
6052                       (p_app_short_name => 'PA',
6053                        p_msg_name     => 'PA_FP_INV_PARAM_PASSED');
6054                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6055       END IF;
6056 
6057       IF(p_fin_plan_type_id IS NULL) AND (p_budget_type_code IS NOT NULL) THEN
6058 
6059             IF(p_pa_project_id             IS NULL OR
6060                p_resource_list_id          IS NULL OR
6061                p_budget_entry_method_code  IS NULL OR
6062                p_entry_level_code          IS NULL ) THEN
6063 
6064                   IF l_debug_mode = 'Y' THEN
6065 
6066                         pa_debug.g_err_stage:= 'p_pa_project_id is ' || p_pa_project_id;
6067                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6068 
6069                         pa_debug.g_err_stage:= 'p_budget_type_code is ' || p_budget_type_code;
6070                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6071 
6072                         pa_debug.g_err_stage:= 'p_resource_list_id is ' || p_resource_list_id;
6073                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6074 
6075                         pa_debug.g_err_stage:= 'p_budget_entry_method_code is ' ||
6076                                                                               p_budget_entry_method_code;
6077                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6078 
6079                         pa_debug.g_err_stage:= 'p_entry_level_code is ' || p_entry_level_code;
6080                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6081 
6082                   END IF;
6083 
6084                   PA_UTILS.ADD_MESSAGE
6085                       (p_app_short_name => 'PA',
6086                        p_msg_name     => 'PA_FP_INV_PARAM_PASSED');
6087                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6088 
6089             END IF;
6090       END IF;
6091 
6092       --<Patchset M: B and F impact changes : AMG:> -- Bug # 3507156
6093       --Added a check to error out budget lines with time phased code as 'R'(Date Range) and p_entry_level_code as 'M'
6094       -- as it is not supported in FP M model.
6095 
6096       IF(p_fin_plan_type_id IS NOT NULL) AND (p_budget_type_code IS NULL) THEN
6097 
6098             IF(p_pa_project_id             IS NULL OR
6099                p_version_type              IS NULL OR
6100                p_resource_list_id          IS NULL OR
6101                p_time_phased_code          IS NULL OR
6102                p_entry_level_code          IS NULL OR
6103                p_multi_currency_flag       IS NULL OR
6104                p_time_phased_code          = 'R'   OR
6105                p_entry_level_code          = 'M')THEN
6106 
6107                   IF l_debug_mode = 'Y' THEN
6108                         pa_debug.g_err_stage:= 'p_pa_project_id is ' || p_pa_project_id;
6109                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6110 
6111                         pa_debug.g_err_stage:= 'p_fin_plan_type_id is ' || p_fin_plan_type_id;
6112                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6113 
6114                         pa_debug.g_err_stage:= 'p_version_type is ' || p_version_type;
6115                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6116 
6117                         pa_debug.g_err_stage:= 'p_resource_list_id is ' || p_resource_list_id;
6118                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6119 
6120                         pa_debug.g_err_stage:= 'p_time_phased_code is ' || p_time_phased_code;
6121                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6122 
6123                         pa_debug.g_err_stage:= 'p_entry_level_code is ' || p_entry_level_code;
6124                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6125 
6126                         pa_debug.g_err_stage:= 'p_multi_currency_flag is ' || p_multi_currency_flag;
6127                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6128 
6129                   END IF;
6130                   PA_UTILS.ADD_MESSAGE
6131                       (p_app_short_name => 'PA',
6132                        p_msg_name     => 'PA_FP_INV_PARAM_PASSED');
6133                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6134 
6135             END IF;
6136       END IF;
6137 
6138       -- Bug 3986129: FP.M Web ADI Dev changes:
6139       IF p_calling_context = 'WEBADI' THEN
6140              IF p_version_info_rec.x_plan_in_multi_curr_flag IS NULL THEN
6141                   IF l_debug_mode = 'Y' THEN
6142                       pa_debug.g_err_stage:= 'For Web ADI context the version info rec is null';
6143                       pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6144                   END IF;
6145                   PA_UTILS.ADD_MESSAGE
6146                       (p_app_short_name => 'PA',
6147                        p_msg_name       => 'PA_FP_INV_PARAM_PASSED',
6148                        p_token1         => 'PROCEDURENAME',
6149                        p_value1         => l_module_name);
6150                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6151              END IF;
6152              IF px_budget_lines_in.COUNT <> p_raw_cost_rate_tbl.COUNT OR
6153                 px_budget_lines_in.COUNT <> p_burd_cost_rate_tbl.COUNT OR
6154                 px_budget_lines_in.COUNT <> p_bill_rate_tbl.COUNT OR
6155                 px_budget_lines_in.COUNT <> p_uom_tbl.COUNT OR
6156                 px_budget_lines_in.COUNT <> p_planning_start_date_tbl.COUNT OR
6157                 px_budget_lines_in.COUNT <> p_planning_end_date_tbl.COUNT OR
6158                 px_budget_lines_in.COUNT <> p_delete_flag_tbl.COUNT OR
6159                 px_budget_lines_in.COUNT <> p_mfc_cost_type_tbl.COUNT OR
6160                 px_budget_lines_in.COUNT <> p_spread_curve_name_tbl.COUNT OR
6161                 px_budget_lines_in.COUNT <> p_sp_fixed_date_tbl.COUNT OR
6162                 px_budget_lines_in.COUNT <> p_etc_method_name_tbl.COUNT THEN
6163                      IF l_debug_mode = 'Y' THEN
6164                          pa_debug.g_err_stage:= 'For Web ADI context the input tables are not equal';
6165                          pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6166                      END IF;
6167                      PA_UTILS.ADD_MESSAGE
6168                          (p_app_short_name => 'PA',
6169                           p_msg_name       => 'PA_FP_INV_PARAM_PASSED',
6170                           p_token1         => 'PROCEDURENAME',
6171                           p_value1         => l_module_name);
6172                      RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6173              END IF;
6174 
6175              -- initializing the out table type parameters
6176              x_mfc_cost_type_id_tbl := SYSTEM.pa_num_tbl_type();
6177              x_etc_method_code_tbl  := SYSTEM.pa_varchar2_30_tbl_type();
6178              x_spread_curve_id_tbl  := SYSTEM.pa_num_tbl_type();
6179 
6180              -- initializing the web adi error code lookup table:
6181              -- this is required to get the validation failure context, so that appropriate lookup code
6182              -- for web adi context can be used to stamp the interface table corresponding the error
6183              -- code returned from the currency conversion validating api.
6184              l_wa_error_code_lookup ('PA_FP_INVALID_RATE_TYPE')      := 'PA_FP_WA_INV_RATE_TYPE';
6185              l_wa_error_code_lookup ('PA_FP_INVALID_RATE_DATE_TYPE') := 'PA_FP_WA_INV_RATE_DATE_TYPE';
6186              l_wa_error_code_lookup ('PA_FP_INVALID_RATE_DATE')      := 'PA_FP_WA_INV_RATE_DATE';
6187              l_wa_error_code_lookup ('PA_FP_USER_EXCH_RATE_REQ')     := 'PA_FP_WA_USER_EXCH_RATE_REQ';
6188              l_wa_error_code_lookup ('PA_FP_RATE_TYPE_REQ')          := 'PA_FP_WA_INV_RATE_TYPE';
6189 
6190       END IF;
6191 
6192 
6193        IF p_calling_context = 'UPDATE_PLANNING_ELEMENT_ATTR' THEN
6194                IF px_budget_lines_in.COUNT <> p_uom_tbl.COUNT OR
6195                        px_budget_lines_in.COUNT <> p_planning_start_date_tbl.COUNT OR
6196                        px_budget_lines_in.COUNT <> p_planning_end_date_tbl.COUNT OR
6197                        px_budget_lines_in.COUNT <> p_mfc_cost_type_tbl.COUNT OR
6198                        px_budget_lines_in.COUNT <> p_spread_curve_name_tbl.COUNT OR
6199                        px_budget_lines_in.COUNT <> p_sp_fixed_date_tbl.COUNT OR
6200                        px_budget_lines_in.COUNT <> p_etc_method_name_tbl.COUNT THEN
6201                             IF l_debug_mode = 'Y' THEN
6202                                 pa_debug.g_err_stage:= 'For UPDATE_PLANNING_ELEMENT_ATTR context the input tables are not equal';
6203                                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6204                             END IF;
6205                             PA_UTILS.ADD_MESSAGE
6206                                 (p_app_short_name => 'PA',
6207                                  p_msg_name       => 'PA_FP_INV_PARAM_PASSED',
6208                                  p_token1         => 'PROCEDURENAME',
6209                                  p_value1         => l_module_name);
6210                             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6211                END IF;
6212 
6213             -- initializing the out table type parameters
6214             x_mfc_cost_type_id_tbl := SYSTEM.pa_num_tbl_type();
6215             x_etc_method_code_tbl  := SYSTEM.pa_varchar2_30_tbl_type();
6216             x_spread_curve_id_tbl  := SYSTEM.pa_num_tbl_type();
6217 
6218             Select spread_curve_id
6219             into l_fixed_date_sp_id
6220             from pa_spread_curves_b
6221             where spread_curve_code = 'FIXED_DATE';
6222 
6223             select segment1
6224             into l_project_number
6225             from pa_projects_all
6226             where project_id=p_pa_project_id;
6227 
6228        END IF;  -- Bug 5509192
6229 
6230       --Set API return status to success
6231       x_return_status := FND_API.G_RET_STS_SUCCESS;
6232 
6233       -- Get segment1 for AMG messages
6234       OPEN  l_amg_project_csr( p_pa_project_id );
6235       FETCH l_amg_project_csr INTO l_amg_project_rec;
6236       CLOSE l_amg_project_csr;
6237 
6238       --AMG UT2. Moved this piece of code from if plan_type_id <> null to here.
6239       --Get the uncategorized resource list info.If the resource is uncategorized
6240       --resource list member id should be set to uncategorized resource list member id
6241       pa_get_resource.Get_Uncateg_Resource_Info
6242             (p_resource_list_id         => l_uncategorized_res_list_id,
6243             p_resource_list_member_id   => l_uncategorized_rlmid,
6244             p_resource_id               => l_uncategorized_resid,
6245             p_track_as_labor_flag       => l_track_as_labor_flag,
6246             p_err_code                  => l_err_code,
6247             p_err_stage                 => l_err_stage,
6248             p_err_stack                 => l_err_stack );
6249 
6250       IF l_err_code <> 0 THEN
6251             IF NOT pa_project_pvt.check_valid_message(l_err_stage) THEN
6252                   pa_interface_utils_pub.map_new_amg_msg
6253                   ( p_old_message_code => 'PA_NO_UNCATEGORIZED_LIST'
6254                   ,p_msg_attribute    => 'CHANGE'
6255                   ,p_resize_flag      => 'N'
6256                   ,p_msg_context      => 'BUDG'
6257                   ,p_attribute1       => l_amg_project_rec.segment1
6258                   ,p_attribute2       => ''
6259                   ,p_attribute3       => p_budget_type_code
6260                   ,p_attribute4       => ''
6261                   ,p_attribute5       => '');
6262             ELSE
6263                   pa_interface_utils_pub.map_new_amg_msg
6264                   ( p_old_message_code => l_err_stage
6265                   ,p_msg_attribute    => 'CHANGE'
6266                   ,p_resize_flag      => 'N'
6267                   ,p_msg_context      => 'BUDG'
6268                   ,p_attribute1       => l_amg_project_rec.segment1
6269                   ,p_attribute2       => ''
6270                   ,p_attribute3       => p_budget_type_code
6271                   ,p_attribute4       => ''
6272                   ,p_attribute5       => '');
6273             END IF;
6274 
6275             IF l_debug_mode = 'Y' THEN
6276                  pa_debug.g_err_stage:= 'Could not obtain uncategorized resource list info';
6277                  pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level5);
6278             END IF;
6279             RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;   --AMG UT2
6280       END IF; -- IF l_err_code <> 0 THEN
6281 
6282 
6283       -- Get the budget amount code so that it can be used later
6284       IF (p_budget_type_code IS NOT  NULL) THEN
6285 
6286             /*Get the budget amount code. Check whether the project type allows the
6287               creation of plan versions with obtained budget amounT code.
6288             */
6289             OPEN  l_budget_amount_code_csr( p_budget_type_code );
6290             FETCH l_budget_amount_code_csr
6291             INTO  l_budget_amount_code;       --will be used later on during validation of Budget lines.
6292             CLOSE l_budget_amount_code_csr;
6293       END IF;
6294 
6295 
6296       --Get the approved revenue plan type flag and txn currencies for the plan type so that the
6297       --txn currencies for the plan version can be validated later.
6298       IF(p_fin_plan_type_id IS NOT NULL) THEN
6299             OPEN l_approved_revenue_flag_csr( p_fin_plan_type_id
6300                                              ,p_pa_project_id);
6301             FETCH l_approved_revenue_flag_csr INTO l_app_rev_plan_type_flag , l_proj_fp_options_id; --for bug 4886319
6302             CLOSE l_approved_revenue_flag_csr;
6303 
6304            --Bug 4290310. Changed the if condition to read the txn currency for budget version level when the
6305            --budget version id is passed.
6306             IF (p_calling_context = 'WEBADI' OR p_version_info_rec.x_budget_version_id is not null) THEN
6307                 OPEN   l_plan_ver_txn_curr_csr( p_fin_plan_type_id
6308                                                ,p_pa_project_id
6309                                                ,p_version_info_rec.x_budget_version_id);
6310                 FETCH l_plan_ver_txn_curr_csr BULK COLLECT
6311                 INTO  l_valid_txn_currencies_tbl;
6312 
6313                 CLOSE l_plan_ver_txn_curr_csr;
6314             ELSE
6315                 OPEN   l_plan_type_txn_curr_csr( l_proj_fp_options_id
6316                                                  ,p_pa_project_id);
6317                 FETCH l_plan_type_txn_curr_csr BULK COLLECT
6318                 INTO  l_valid_txn_currencies_tbl;
6319 
6320                 CLOSE l_plan_type_txn_curr_csr;
6321             END IF;
6322 
6323             --Get the project and project functional currencies so that they can be used later
6324             pa_fin_plan_utils.Get_Project_Curr_Attributes
6325             (  p_project_id                    => p_pa_project_id
6326               ,x_multi_currency_billing_flag   => l_multi_currency_billing_flag
6327               ,x_project_currency_code         => l_project_currency_code
6328               ,x_projfunc_currency_code        => l_projfunc_currency_code
6329               ,x_project_cost_rate_type        => l_project_cost_rate_type
6330               ,x_projfunc_cost_rate_type       => l_projfunc_cost_rate_type
6331               ,x_project_bil_rate_type         => l_project_bil_rate_type
6332               ,x_projfunc_bil_rate_type        => l_projfunc_bil_rate_type
6333               ,x_return_status                 => x_return_status
6334               ,x_msg_count                     => x_msg_count
6335               ,x_msg_data                      => x_msg_data);
6336 
6337             IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
6338 
6339                   IF l_debug_mode = 'Y' THEN
6340                         pa_debug.g_err_stage:= 'pa_fin_plan_utils.Get_Project_Curr_Attributes errored out for project' ||p_pa_project_id;
6341                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6342 
6343                   END IF;
6344                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6345 
6346             END IF;
6347 
6348             -- Get the plan type name
6349            SELECT name
6350             INTO   l_fin_plan_type_name
6351             FROM   pa_fin_plan_types_vl
6352             WHERE  fin_plan_type_id =  p_fin_plan_type_id;
6353 
6354 
6355       -- bug 4462614: added the following check for CI version for webadi context
6356       IF (p_calling_context = 'WEBADI' AND
6357          Nvl(l_app_rev_plan_type_flag, 'N') = 'Y') THEN
6358              -- open the cursor to get the ci_id and agr_curr_code
6359              OPEN check_and_return_ci_version(p_version_info_rec.x_budget_version_id);
6360              FETCH check_and_return_ci_version
6361              INTO  l_webadi_ci_id,
6362                    l_webadi_agr_curr_code;
6363              CLOSE check_and_return_ci_version;
6364       END IF;
6365 
6366       END IF;  --IF(p_fin_plan_type_id IS NOT NULL) THEN
6367 
6368      --Bug 4488926.Deriving the l_period_time_phased_code only once  for passed budget version id.
6369      l_period_time_phased_code := p_time_phased_code; --Use the i/p parameter to get this value.
6370     --if p_time_phased_code was passed as null we try to derive the time phase code.
6371      IF(l_period_time_phased_code is null)
6372      THEN
6373         l_period_time_phased_code :=  PA_FIN_PLAN_UTILS.Get_Time_Phased_code(p_version_info_rec.x_budget_version_id);
6374      END IF;
6375 
6376 
6377       IF px_budget_lines_in.exists(px_budget_lines_in.first) THEN
6378             --Loop thru the pl/sql table and validate each budget line
6379             FOR i IN px_budget_lines_in.first..px_budget_lines_in.last LOOP
6380                   /* Bug 3133930 */
6381                   x_budget_lines_out(i).return_status     := FND_API.G_RET_STS_SUCCESS;
6382                   --Initialise all the global variables to null
6383                   pa_budget_pvt.g_Task_number    := NULL;
6384                   pa_budget_pvt.g_start_date     := NULL;
6385                   pa_budget_pvt.g_resource_alias := NULL;
6386 
6387 
6388                   /* Bug 3218822 - PM_PRODUCT_CODE could be Null. We need valid it if it is NOT NULL */
6389 
6390                   IF px_budget_lines_in(i).pm_product_code <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
6391                      OR px_budget_lines_in(i).pm_product_code IS NOT NULL
6392                   THEN
6393 
6394                         /* Validating as done in bug# 2413400 */
6395                         OPEN p_product_code_csr (px_budget_lines_in(i).pm_product_code);
6396                         FETCH p_product_code_csr INTO l_pm_product_code;
6397                         CLOSE p_product_code_csr;
6398                         IF l_pm_product_code <> 'X'
6399                         THEN
6400                               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6401                               THEN
6402                                   pa_interface_utils_pub.map_new_amg_msg
6403                                   ( p_old_message_code => 'PA_PRODUCT_CODE_IS_INVALID'
6404                                    ,p_msg_attribute    => 'CHANGE'
6405                                    ,p_resize_flag      => 'N'
6406                                    ,p_msg_context      => 'GENERAL'
6407                                    ,p_attribute1       => ''
6408                                    ,p_attribute2       => ''
6409                                    ,p_attribute3       => ''
6410                                    ,p_attribute4       => ''
6411                                    ,p_attribute5       => '');
6412                               END IF;
6413                               IF l_debug_mode = 'Y' THEN
6414                                     pa_debug.g_err_stage:= 'PM Product code is invalid';
6415                                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6416                               END IF;
6417                               x_return_status             := FND_API.G_RET_STS_ERROR;
6418                               x_budget_lines_out(i).return_status := FND_API.G_RET_STS_ERROR;
6419                               l_any_error_occurred_flag:='Y';
6420                         END IF;
6421 
6422                   END IF;
6423 
6424                   /* End of bug fix for Bug 3218822 */
6425 
6426                   -- checking if for project level planning, tasks ids are passed as 0 or not for web adi context
6427                   IF p_calling_context = 'WEBADI' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
6428                         IF p_entry_level_code = 'P' THEN
6429                               IF px_budget_lines_in(i).pa_task_id <> 0 THEN
6430                                      l_webadi_err_code_tbl.extend(1);
6431                                      l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_TASK_IS_NOT_PROJECT';
6432                                      l_webadi_err_task_id_tbl.extend(1);
6433                                      l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
6434                                      l_webadi_err_rlm_id_tbl.extend(1);
6435                                      l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
6436                                      l_webadi_err_txn_curr_tbl.extend(1);
6437                                      l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
6438                                      l_webadi_err_amt_type_tbl.extend(1);
6439                                      l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
6440                               END IF;
6441                         END IF;
6442                   END IF; -- p_context = WEBADI
6443                   -- convert pm_task_reference to pa_task_id
6444                   -- if both task id and reference are NULL or not passed, we will assume that budgetting is
6445                   -- done at the project level and that requires l_task_id to be '0'
6446                   -- if budgeting at the project level,then ignore all tasks
6447                   IF p_entry_level_code = 'P' THEN
6448                       px_budget_lines_in(i).pa_task_id := 0;
6449 
6450                   ELSIF p_entry_level_code in ('T','L','M') THEN
6451                         --Added a null check in the if below for the bug#4479835. The API pa_project_pvt.Convert_pm_taskref_to_id
6452                         --should be called to derive the pa_task_id if pa_task_id is null
6453                         IF (px_budget_lines_in(i).pa_task_id is null OR px_budget_lines_in(i).pa_task_id <> 0) THEN
6454 
6455                             --Selecting the index if it will be based on pa_task_id or pm_ask_reference. This index is decided on the
6456                             --basis of whther this (pa_project_pvt.Convert_pm_taskref_to_id ) API call would honour the
6457                             --pa_task_id or pm_task_reference. The rule is pa_task_id is honoured if both are passed to the API
6458                             --otherwise whichever value is passed that value is honoured by the API.
6459                             --Also note while preparing the index we are prepending 'TSKID' or 'TSKREF' before the actual values.
6460                             --The index would always be in this format.
6461                              IF(px_budget_lines_in(i).pa_task_id <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM AND
6462                              px_budget_lines_in(i).pa_task_id is not null)
6463                              THEN
6464                              --Prepending the word 'TSKID' before the pa_task_id value while preparing the index.
6465                              l_distinct_tskid_idx := 'TSKID' || px_budget_lines_in(i).pa_task_id;
6466                              ELSIF( px_budget_lines_in(i).pm_task_reference <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR AND
6467                              px_budget_lines_in(i).pm_task_reference is not null)
6468                              THEN
6469                              --Prepending the word 'TSKREF' before the pm_task_reference value while preparing the index.
6470                              l_distinct_tskid_idx := 'TSKREF' || px_budget_lines_in(i).pm_task_reference;
6471                              END IF;
6472 
6473                            --l_tsk_id_tbl table would be used to cache the pa_task_id for the pa_task_id/pm_task_reference passed.
6474                            -- This table would store the value for pa_task_id everytime a new task_id or pm_task_reference is passed.
6475                            --The table is indexed by index 'l_distinct_tskid_idx' which could be either pm_task_reference or
6476                            --pa_task_id.
6477                            --Check in the table if the value is already present for this index(which is one of
6478                            --pa_task_id/pm_task_reference). If present then read the task_id from the table for this index
6479                            --else call the api.
6480                             IF( NOT(l_tsk_id_tbl.exists(l_distinct_tskid_idx) ) )
6481                             THEN
6482                                         pa_project_pvt.Convert_pm_taskref_to_id
6483                                                       ( p_pa_project_id       => p_pa_project_id,
6484                                                         p_pa_task_id          => px_budget_lines_in(i).pa_task_id,
6485                                                         p_pm_task_reference   => px_budget_lines_in(i).pm_task_reference,
6486                                                         p_out_task_id         => px_budget_lines_in(i).pa_task_id,
6487                                                         p_return_status       => x_return_status );
6488 
6489                                     IF l_debug_mode = 'Y' THEN
6490                                           pa_debug.g_err_stage:= 'Converted Task Id is ' || px_budget_lines_in(i).pa_task_id;
6491                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
6492                                     END IF;
6493 
6494                                     IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR THEN
6495                                           /*  Bug 3133930- set the return status to the new output variable */
6496                                           x_budget_lines_out(i).return_status := x_return_status;
6497 
6498                                           RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
6499                                     ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
6500                                           -- exception is raised here because we cannot go ahead and do further validations
6501                                           -- as other validations depend upon task id to be correct.
6502                                           --RAISE  FND_API.G_EXC_ERROR; AMG UT2
6503                                           x_budget_lines_out(i).return_status := x_return_status;
6504                                           RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
6505                                     --Changed the elsif below for bug#4488926.
6506                                     ELSIF (px_budget_lines_in(i).pa_task_id IS NOT NULL) THEN /*if the API above executes successfully
6507                                                                                               then pa_task_id would never be null*/
6508                                           --If the API completes successfully then store the task_id in the l_tsk_id_tbl at the location
6509                                           --indexed by l_distinct_tskid_idx.
6510                                           l_tsk_id_tbl(l_distinct_tskid_idx) := px_budget_lines_in(i).pa_task_id;
6511                                           --Also if the index was based on task_reference then we derive task_id for this, but next time
6512                                           --possibly task_id could be passed which has been derived from this task_reference. So we
6513                                           --should store this derived task_id also in the table.
6514                                           --More importantly this task_id should be stored at the location indexed by
6515                                           --'TSKID' || px_budget_lines_in(i).pa_task_id. Here prepending the TSKID and the value
6516                                           --px_budget_lines_in(i).pa_task_id was derived in the above API call as o/p parameter.
6517                                           IF(l_distinct_tskid_idx = 'TSKREF' || px_budget_lines_in(i).pm_task_reference)
6518                                           THEN
6519                                               IF(l_tsk_id_tbl.exists('TSKID' || px_budget_lines_in(i).pa_task_id))
6520                                               THEN
6521                                                   --If the task_id derived from this task_reference is already present then dont store
6522                                                   --it again.
6523                                                    null;
6524                                                ELSE
6525                                                   --Derived task_id should be stored at the location indexed by
6526                                                   --'TSKID' || px_budget_lines_in(i).pa_task_id. Here prepending the TSKID and the value
6527                                                   --px_budget_lines_in(i).pa_task_id was derived in the above API call as o/p parameter.
6528                                                   --Storing this value would ensure that next time if this task_id is passed we dont
6529                                                   --call the API.
6530                                                    l_tsk_id_tbl('TSKID' || px_budget_lines_in(i).pa_task_id) :=
6531                                                                                                       px_budget_lines_in(i).pa_task_id;
6532                                                END IF;
6533                                           END IF;
6534                                     END IF;
6535                             ELSE --IF( NOT(l_tsk_id_tbl.exists(l_distinct_tskid_idx) ) )
6536                                  --If the value is already there in the table for this index(task_id/task_ref) then read it from table
6537                                  --for this index.
6538                                 px_budget_lines_in(i).pa_task_id := l_tsk_id_tbl(l_distinct_tskid_idx) ;
6539                             END IF;--IF( NOT(l_tsk_id_tbl.exists(l_distinct_tskid_idx) ) )
6540 
6541                         END IF;
6542                   END IF;
6543 
6544 
6545                   -- get the task number. This task number is required as input to map_new_amg_msg API.
6546 
6547                   IF px_budget_lines_in(i).pa_task_id <> 0 THEN
6548 
6549                       l_amg_task_number := pa_interface_utils_pub.get_task_number_amg
6550                                                                           ( p_task_number=> ''
6551                                                                            ,p_task_reference => px_budget_lines_in(i).pm_task_reference
6552                                                                            ,p_task_id => px_budget_lines_in(i).pa_task_id);
6553                       /* Bug 3124283: Added substr below */
6554                       pa_budget_pvt.g_task_number := substrb(l_amg_task_number,1,25);
6555                   ELSE
6556                       pa_budget_pvt.g_task_number := substrb(l_amg_project_rec.segment1,1,25); --Added for the bug 4421602.
6557                   END IF;
6558 
6559   -- <Patchset M:B and F impact changes : AMG:> -- Bug # 3507156
6560   -- Added a check for old model(p_budget_type_code) or new model(p_fin_plan_type_id) as the processing
6561   -- of the parameter p_entry_level_code is different for both.
6562 
6563   IF(p_budget_type_code IS NOT NULL) THEN  --Budget Model
6564 
6565                   IF p_entry_level_code = 'T' THEN -- then check whether it is top task
6566                              IF px_budget_lines_in(i).pa_task_id <> pa_task_utils.get_top_task_id( px_budget_lines_in(i).pa_task_id ) THEN
6567                                         IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6568                                               pa_interface_utils_pub.map_new_amg_msg
6569                                                                     ( p_old_message_code => 'PA_TASK_IS_NOT_TOP'
6570                                                                      ,p_msg_attribute    => 'CHANGE'
6571                                                                      ,p_resize_flag      => 'N'
6572                                                                      ,p_msg_context      => 'TASK'
6573                                                                      ,p_attribute1       => l_amg_project_rec.segment1
6574                                                                      ,p_attribute2       => l_amg_task_number
6575                                                                      ,p_attribute3       => ''
6576                                                                      ,p_attribute4       => ''
6577                                                                      ,p_attribute5       => '');
6578                                         END IF;
6579                                    -- RAISE FND_API.G_EXC_ERROR;
6580                                    x_return_status :=  FND_API.G_RET_STS_ERROR;
6581                                    /*  Bug 3133930- set the return status to the new output variable */
6582                                    x_budget_lines_out(i).return_status := FND_API.G_RET_STS_ERROR;
6583 
6584                                    l_any_error_occurred_flag:='Y';
6585                              END IF;
6586                   ELSIF p_entry_level_code = 'L' -- then check whether it is lowest task
6587                   THEN
6588                         pa_tasks_pkg.verify_lowest_level_task( l_return_status_task,
6589                                                                px_budget_lines_in(i).pa_task_id);
6590                         IF l_return_status_task <> 0 THEN
6591                               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6592                               THEN
6593                                     pa_interface_utils_pub.map_new_amg_msg
6594                                     ( p_old_message_code => 'PA_TASK_IS_NOT_LOWEST'
6595                                     ,p_msg_attribute    => 'CHANGE'
6596                                     ,p_resize_flag      => 'N'
6597                                     ,p_msg_context      => 'TASK'
6598                                     ,p_attribute1       => l_amg_project_rec.segment1
6599                                     ,p_attribute2       => l_amg_task_number
6600                                     ,p_attribute3       => ''
6601                                     ,p_attribute4       => ''
6602                                     ,p_attribute5       => '');
6603                               END IF;
6604                               --RAISE FND_API.G_EXC_ERROR;
6605                               x_return_status :=  FND_API.G_RET_STS_ERROR;
6606                               /*  Bug 3133930- set the return status to the new output variable */
6607                               x_budget_lines_out(i).return_status := x_return_status;
6608 
6609                               l_any_error_occurred_flag:='Y';
6610                         END IF;
6611 
6612                   ELSIF p_entry_level_code = 'M' -- then check whether it is a top or
6613                                                  -- lowest level tasks
6614                   THEN
6615                         --Added check to prevent the user from entering the amounts for both
6616                         --top task and one of its sub tasks.
6617                         l_top_task_id := pa_task_utils.get_top_task_id( px_budget_lines_in(i).pa_task_id );
6618 
6619                         l_top_task_planning_level := NULL;
6620 
6621                         IF px_budget_lines_in(i).pa_task_id =  nvl(l_top_task_id,-99) THEN
6622 
6623                               l_top_task_planning_level := PA_FP_CONSTANTS_PKG.G_TASK_PLAN_LEVEL_TOP;
6624 
6625                         ELSE
6626                               pa_tasks_pkg.verify_lowest_level_task( l_return_status_task
6627                                                                    , px_budget_lines_in(i).pa_task_id);
6628                                    IF l_return_status_task <> 0 THEN
6629                                               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6630                                               THEN
6631                                                     pa_interface_utils_pub.map_new_amg_msg
6632                                                     ( p_old_message_code => 'PA_TASK_IS_NOT_TOP_OR_LOWEST'
6633                                                     ,p_msg_attribute    => 'CHANGE'
6634                                                     ,p_resize_flag      => 'Y'
6635                                                     ,p_msg_context      => 'TASK'
6636                                                     ,p_attribute1       => l_amg_project_rec.segment1
6637                                                     ,p_attribute2       => l_amg_task_number
6638                                                     ,p_attribute3       => ''
6639                                                     ,p_attribute4       => ''
6640                                                     ,p_attribute5       => '');
6641                                               END IF;
6642                                          --RAISE FND_API.G_EXC_ERROR;
6643                                          x_return_status :=  FND_API.G_RET_STS_ERROR;
6644                                          /*  Bug 3133930- set the return status to the new output variable */
6645                                          x_budget_lines_out(i).return_status := x_return_status;
6646 
6647                                          l_any_error_occurred_flag:='Y';
6648                                    ELSE--The task passed is a lowest task
6649                                          l_top_task_planning_level := PA_FP_CONSTANTS_PKG.G_TASK_PLAN_LEVEL_LOWEST;
6650                                    END IF;
6651 
6652 
6653                         END IF;--iF px_budget_lines_in(i).pa_task_id =  nvl(l_top_task_id,-99) THEN
6654 
6655                   -- Check the planning level only if the task entered is valid.
6656                         IF l_top_task_planning_level IS NOT NULL THEN
6657 
6658                               --See whether the planning level is already cached in l_top_tasks_tbl. If it is
6659                               --cached then that can be used. For bug 3678314
6660                               l_temp:=NULL;
6661                               FOR kk IN 1..l_top_tasks_tbl.COUNT LOOP
6662 
6663                                   IF l_top_tasks_tbl(kk).key=l_top_task_id THEN
6664                                       l_temp:=kk;
6665                                       EXIT;
6666                                   END IF;
6667 
6668                               END LOOP;
6669 
6670                               IF (l_temp IS NOT NULL) THEN
6671                                     IF l_top_task_planning_level <> l_top_tasks_tbl(l_temp).value THEN
6672 
6673                                           l_amg_top_task_number := pa_interface_utils_pub.get_task_number_amg
6674                                                                       ( p_task_number=> ''
6675                                                                        ,p_task_reference => NULL
6676                                                                        ,p_task_id => l_top_task_id);
6677 
6678 
6679                                           PA_UTILS.ADD_MESSAGE
6680                                             ( p_app_short_name => 'PA',
6681                                               p_msg_name       => 'PA_FP_AMTS_FOR_BOTH_TOP_LOWEST',
6682                                               p_token1         => 'PROJECT',
6683                                               p_value1         =>  l_amg_project_rec.segment1,
6684                                               p_token2         => 'TASK',
6685                                               p_value2         =>  l_amg_top_task_number);
6686 
6687 
6688                                           x_return_status := FND_API.G_RET_STS_ERROR;
6689                                           /*  Bug 3133930- set the return status to the new output variable */
6690                                           x_budget_lines_out(i).return_status := x_return_status;
6691 
6692                                           l_any_error_occurred_flag := 'Y';
6693                                     END IF;
6694                               ELSE
6695                                     --Cache the values derived so that they can be used again. Bug 3678314
6696                                     l_temp := l_top_tasks_tbl.COUNT + 1;
6697                                     l_top_tasks_tbl(l_temp).key := l_top_task_id;
6698                                     l_top_tasks_tbl(l_temp).value := l_top_task_planning_level;
6699 
6700                               END IF;
6701                         END IF;
6702 
6703                   END IF;     -- IF p_entry_level_code = T THEN
6704 
6705  ELSIF (p_fin_plan_type_id IS NOT NULL) THEN  --FinPlan Model
6706  -- <Patchset M:B and F impact changes : AMG:> -- Bug # 3507156
6707  -- If Planning level is Top, then only top task or project level planning is allowed.
6708 
6709                IF p_entry_level_code = 'T' THEN -- then check whether it is a task at top level or project level
6710                           IF  (px_budget_lines_in(i).pa_task_id <> 0)
6711                           AND (px_budget_lines_in(i).pa_task_id <> pa_task_utils.get_top_task_id( px_budget_lines_in(i).pa_task_id )) THEN
6712                                     IF p_calling_context = 'WEBADI' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
6713                                           l_webadi_err_code_tbl.extend(1);
6714                                           l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_TASK_IS_NOT_TOP';
6715                                           l_webadi_err_task_id_tbl.extend(1);
6716                                           l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
6717                                           l_webadi_err_rlm_id_tbl.extend(1);
6718                                           l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
6719                                           l_webadi_err_txn_curr_tbl.extend(1);
6720                                           l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
6721                                           l_webadi_err_amt_type_tbl.extend(1);
6722                                           l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
6723                                     ELSE
6724                                        IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
6725                                           pa_interface_utils_pub.map_new_amg_msg
6726                                                       ( p_old_message_code => 'PA_TASK_IS_NOT_TOP'
6727                                                        ,p_msg_attribute    => 'CHANGE'
6728                                                        ,p_resize_flag      => 'N'
6729                                                        ,p_msg_context      => 'TASK'
6730                                                        ,p_attribute1       => l_amg_project_rec.segment1
6731                                                        ,p_attribute2       => l_amg_task_number
6732                                                        ,p_attribute3       => ''
6733                                                        ,p_attribute4       => ''
6734                                                        ,p_attribute5       => '');
6735                                        END IF;
6736                                          -- RAISE FND_API.G_EXC_ERROR;
6737                                          x_return_status :=  FND_API.G_RET_STS_ERROR;
6738                                          /*  Bug 3133930- set the return status to the new output variable */
6739                                          x_budget_lines_out(i).return_status := FND_API.G_RET_STS_ERROR;
6740                                     END IF;
6741                                    l_any_error_occurred_flag:='Y';
6742                           END IF;
6743 
6744  -- <Patchset M:B and F impact changes : AMG:> --Bug # 3507156
6745  --If Planning level is lowest, then no validations - any task can be planned
6746  --As there is already a check for p_entry_level_code = 'M' we do not need to check it again.
6747 
6748                END IF; -- if p_entry_level_code = 'T'
6749 
6750  END IF ; -- If fin_plan_type_id is NOT NULL
6751 
6752 
6753                   -- check the validity of the period_name,budget_start_date and
6754                   -- budget_end_date for budget lines and return values of budget_start_date
6755                   -- and budget_end_date for given period_name
6756            -- hari 11th may
6757               IF ( p_calling_context  not in ('RES_ASSGNMT_LEVEL_VALIDATION','UPDATE_PLANNING_ELEMENT_ATTR') )
6758               THEN
6759                       IF p_calling_context = 'WEBADI' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
6760                           -- checking if the planning start date/end date has been explcitely nulled ou
6761                           IF p_planning_start_date_tbl(i) = FND_API.G_MISS_DATE OR
6762                              p_planning_end_date_tbl(i) = FND_API.G_MISS_DATE THEN
6763                                   l_webadi_err_code_tbl.extend(1);
6764                                   l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_PLAN_DATES_NULLED_OUT';
6765                                   l_webadi_err_task_id_tbl.extend(1);
6766                                   l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
6767                                   l_webadi_err_rlm_id_tbl.extend(1);
6768                                   l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
6769                                   l_webadi_err_txn_curr_tbl.extend(1);
6770                                   l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
6771                                   l_webadi_err_amt_type_tbl.extend(1);
6772                                   l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
6773                                   l_any_error_occurred_flag:='Y';
6774                           END IF;
6775 
6776                           -- before calling get_valid_periods_dates validating the followings
6777                           IF (px_budget_lines_in(i).budget_start_date IS NOT NULL OR
6778                               px_budget_lines_in(i).budget_start_date <> FND_API.G_MISS_DATE) AND
6779                              (px_budget_lines_in(i).budget_end_date IS NOT NULL OR
6780                               px_budget_lines_in(i).budget_end_date <> FND_API.G_MISS_DATE) THEN
6781 
6782                                   -- checking if the budget line start date/ end date falls between
6783                                   -- the planning start date/ end date
6784                                   -- Added for the bug 4414062
6785 
6786                                   --After the  derivation of l_period_time_phased_code, if l_period_time_phased_code = N
6787                                   --then it means its a non periodic finplan case
6788                                   IF ( l_period_time_phased_code <> 'N')
6789                                   THEN
6790                                         ---Added this code for bug#4488926. Caching the values of l_period_plan_start_date and
6791                                         --l_period_plan_end_date
6792                                         IF ( NOT(l_period_plan_start_date_tbl.exists(to_char(p_planning_start_date_tbl(i)))
6793                                              AND l_period_plan_end_date_tbl.exists(to_char(p_planning_end_date_tbl(i)))))
6794                                         THEN
6795                                         --For periodic case get the start and end dates.
6796                                             l_period_plan_start_date := PA_FIN_PLAN_UTILS.get_period_start_date(p_planning_start_date_tbl(i),l_period_time_phased_code);
6797                                             l_period_plan_end_date :=  PA_FIN_PLAN_UTILS.get_period_end_date (p_planning_end_date_tbl(i) , l_period_time_phased_code);
6798                                             l_period_plan_start_date_tbl(to_char(p_planning_start_date_tbl(i))) := l_period_plan_start_date;
6799                                             l_period_plan_end_date_tbl(to_char(p_planning_end_date_tbl(i))) := l_period_plan_end_date;
6800                                         ELSE
6801                                             l_period_plan_start_date := l_period_plan_start_date_tbl(to_char(p_planning_start_date_tbl(i)));
6802                                             l_period_plan_end_date := l_period_plan_end_date_tbl(to_char(p_planning_end_date_tbl(i)));
6803                                         END IF;
6804                                   ELSE
6805                                   --Its a non periodic case.
6806                                      l_period_plan_start_date := p_planning_start_date_tbl(i);
6807                                      l_period_plan_end_date   := p_planning_end_date_tbl(i);
6808                                   END IF;
6809 
6810 
6811 
6812 
6813                                   IF px_budget_lines_in(i).budget_start_date < l_period_plan_start_date OR
6814                                      px_budget_lines_in(i).budget_end_date > l_period_plan_end_date THEN
6815                                           -- throwing error
6816                                           l_webadi_err_code_tbl.extend(1);
6817                                           l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_BL_OUT_OF_PLAN_RANGE';
6818                                           l_webadi_err_task_id_tbl.extend(1);
6819                                           l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
6820                                           l_webadi_err_rlm_id_tbl.extend(1);
6821                                           l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
6822                                           l_webadi_err_txn_curr_tbl.extend(1);
6823                                           l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
6824                                           l_webadi_err_amt_type_tbl.extend(1);
6825                                           l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
6826                                           l_any_error_occurred_flag:='Y';
6827                                   END IF;
6828                           END IF;
6829 
6830                                 IF p_budget_type_code IS NOT NULL THEN
6831                                        l_calling_model_context := 'BUDGETSMODEL';
6832                                  ELSIF p_fin_plan_type_id IS NOT NULL THEN
6833                                        l_calling_model_context := 'FINPLANMODEL';
6834                                 END IF;
6835 
6836                                get_valid_period_dates
6837                                              ( p_project_id              => p_pa_project_id
6838                                               ,p_task_id                 => px_budget_lines_in(i).pa_task_id
6839                                               ,p_time_phased_type_code   => p_time_phased_code
6840                                               ,p_entry_level_code        => p_entry_level_code
6841                                               ,p_period_name_in          => px_budget_lines_in(i).period_name
6842                                               ,p_budget_start_date_in    => px_budget_lines_in(i).budget_start_date
6843                                               ,p_budget_end_date_in      => px_budget_lines_in(i).budget_end_date
6844                                               ,p_period_name_out         => px_budget_lines_in(i).period_name
6845                                               ,p_budget_start_date_out   => px_budget_lines_in(i).budget_start_date
6846                                               ,p_budget_end_date_out     => px_budget_lines_in(i).budget_end_date
6847                                               ,p_calling_model_context   => l_calling_model_context
6848                                               ,p_context                 => 'WEBADI'
6849                                               ,p_return_status           => x_return_status
6850                                               ,x_error_code              => l_new_error_code);
6851 
6852                                               IF x_return_status = FND_API.G_RET_STS_ERROR THEN
6853                                                    -- populationg the error tbl variables to call process_errors at the end
6854                                                    l_webadi_err_code_tbl.extend(1);
6855                                                    l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) :=    l_new_error_code;
6856                                                    l_webadi_err_task_id_tbl.extend(1);
6857                                                    l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
6858                                                    l_webadi_err_rlm_id_tbl.extend(1);
6859                                                    l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
6860                                                    l_webadi_err_txn_curr_tbl.extend(1);
6861                                                    l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
6862                                                    l_webadi_err_amt_type_tbl.extend(1);
6863                                                    l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
6864                                               END IF;
6865                       ELSE -- p_context <> 'WEBADI'
6866 
6867                                 IF p_budget_type_code IS NOT NULL THEN
6868                                        l_calling_model_context := 'BUDGETSMODEL';
6869                                  ELSIF p_fin_plan_type_id IS NOT NULL THEN
6870                                        l_calling_model_context := 'FINPLANMODEL';
6871                                 END IF;
6872 
6873                                   IF (l_calling_model_context = 'BUDGETSMODEL') or (NOT(p_time_phased_code = 'N' AND  -- Bug no 5846942
6874                                    (px_budget_lines_in(i).budget_start_date IS NULL
6875                                     OR px_budget_lines_in(i).budget_start_date  = FND_API.G_MISS_DATE )
6876                                    AND (px_budget_lines_in(i).budget_end_date IS NULL
6877                                     OR px_budget_lines_in(i).budget_end_date  = FND_API.G_MISS_DATE )) )THEN
6878 
6879                                get_valid_period_dates
6880                                              ( p_project_id              => p_pa_project_id
6881                                               ,p_task_id                 => px_budget_lines_in(i).pa_task_id
6882                                               ,p_time_phased_type_code   => p_time_phased_code
6883                                               ,p_entry_level_code        => p_entry_level_code
6884                                               ,p_period_name_in          => px_budget_lines_in(i).period_name
6885                                               ,p_budget_start_date_in    => px_budget_lines_in(i).budget_start_date
6886                                               ,p_budget_end_date_in      => px_budget_lines_in(i).budget_end_date
6887                                               ,p_period_name_out         => px_budget_lines_in(i).period_name
6888                                               ,p_budget_start_date_out   => px_budget_lines_in(i).budget_start_date
6889                                               ,p_budget_end_date_out     => px_budget_lines_in(i).budget_end_date
6890                                               ,p_return_status           => x_return_status
6891                                               ,p_calling_model_context   => l_calling_model_context
6892                                               ,x_error_code              => l_new_error_code);
6893                                   END IF;
6894                       END IF;  -- Bug 3986129
6895 
6896                   pa_budget_pvt.g_start_date := px_budget_lines_in(i).budget_start_date;
6897                   IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6898                        -- RAISE  FND_API.G_EXC_ERROR;
6899                        -- as the API get_valid_period_dates adds the error msg to the stack hence we
6900                        -- do not need to add the error msg in this API.
6901                         /*  Bug 3133930- set the return status to the new output variable */
6902                         x_budget_lines_out(i).return_status := x_return_status;
6903                        l_any_error_occurred_flag:='Y';
6904                   END IF;
6905               END IF; --p_calling_context <> 'RES_ASSGNMT_LEVEL_VALIDATION','UPDATE_PLANNING_ELEMENT_ATTR'
6906 
6907               IF p_calling_context <> 'UPDATE_PLANNING_ELEMENT_ATTR' then -- Bug 5509192
6908                   --every budget line need to be checked for it's amount values.
6909                   IF p_fin_plan_type_id IS NULL THEN
6910                   --Budget Model.Do not pass version type and amount flags
6911 
6912                         pa_budget_pvt.check_entry_method_flags
6913                                    ( p_budget_amount_code        => l_budget_amount_code
6914                                     ,p_budget_entry_method_code  => p_budget_entry_method_code
6915                                     ,p_quantity                  => px_budget_lines_in(i).quantity
6916                                     ,p_raw_cost                  => px_budget_lines_in(i).raw_cost
6917                                     ,p_burdened_cost             => px_budget_lines_in(i).burdened_cost
6918                                     ,p_revenue                   => px_budget_lines_in(i).revenue
6919                                     ,p_return_status             => x_return_status
6920 
6921                                     -- Bug 3986129: FP.M Web ADI Dev changes
6922                                     ,x_webadi_error_code         => l_new_error_code);
6923 
6924                   ELSE
6925                   --Finplan model.Pass version type and other amount flags
6926                         IF p_calling_context = 'WEBADI' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
6927                                pa_budget_pvt.check_entry_method_flags
6928                                    ( p_budget_amount_code        => NULL
6929                                     ,p_budget_entry_method_code  => p_budget_entry_method_code
6930                                     ,p_quantity                  => px_budget_lines_in(i).quantity
6931                                     ,p_raw_cost                  => px_budget_lines_in(i).raw_cost
6932                                     ,p_burdened_cost             => px_budget_lines_in(i).burdened_cost
6933                                     ,p_revenue                   => px_budget_lines_in(i).revenue
6934                                     ,p_return_status             => x_return_status
6935                                     ,p_version_type              => p_version_type
6936                                     ,p_allow_qty_flag            => p_allow_qty_flag
6937                                     ,p_allow_raw_cost_flag       => p_allow_raw_cost_flag
6938                                     ,p_allow_burdened_cost_flag  => p_allow_burdened_cost_flag
6939                                     ,p_allow_revenue_flag        => p_allow_revenue_flag
6940                                     ,p_context                   => 'WEBADI'
6941                                     ,p_raw_cost_rate             => p_raw_cost_rate_tbl(i)
6942                                     ,p_burdened_cost_rate        => p_burd_cost_rate_tbl(i)
6943                                     ,p_bill_rate                 => p_bill_rate_tbl(i)
6944                                     ,p_allow_raw_cost_rate_flag  => p_allow_raw_cost_rate_flag
6945                                     ,p_allow_burd_cost_rate_flag => p_allow_burd_cost_rate_flag
6946                                     ,p_allow_bill_rate_flag      => p_allow_bill_rate_flag
6947                                     ,x_webadi_error_code         => l_new_error_code);
6948 
6949                                     IF x_return_status = FND_API.G_RET_STS_ERROR THEN
6950                                         l_webadi_err_code_tbl.extend(1);
6951                                         l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := l_new_error_code;
6952                                         l_webadi_err_task_id_tbl.extend(1);
6953                                         l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
6954                                         l_webadi_err_rlm_id_tbl.extend(1);
6955                                         l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
6956                                         l_webadi_err_txn_curr_tbl.extend(1);
6957                                         l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
6958                                         l_webadi_err_amt_type_tbl.extend(1);
6959                                         l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
6960                                     END IF;
6961                         ELSE  -- p_calling_context <> 'WEBADI'
6962                                     pa_budget_pvt.check_entry_method_flags
6963                                    ( p_budget_amount_code        => NULL
6964                                     ,p_budget_entry_method_code  => p_budget_entry_method_code
6965                                     ,p_quantity                  => px_budget_lines_in(i).quantity
6966                                     ,p_raw_cost                  => px_budget_lines_in(i).raw_cost
6967                                     ,p_burdened_cost             => px_budget_lines_in(i).burdened_cost
6968                                     ,p_revenue                   => px_budget_lines_in(i).revenue
6969                                     ,p_return_status             => x_return_status
6970                                     ,p_version_type              => p_version_type
6971                                     ,p_allow_qty_flag            => p_allow_qty_flag
6972                                     ,p_allow_raw_cost_flag       => p_allow_raw_cost_flag
6973                                     ,p_allow_burdened_cost_flag  => p_allow_burdened_cost_flag
6974                                     ,p_allow_revenue_flag        => p_allow_revenue_flag
6975                                     ,x_webadi_error_code         => l_new_error_code);
6976                         END IF;  -- Bug 3986129
6977                   END IF;
6978                        IF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
6979                        THEN
6980                              /*  Bug 3133930- set the return status to the new output variable */
6981                              x_budget_lines_out(i).return_status := x_return_status;
6982 
6983                              RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
6984 
6985                        ELSIF x_return_status = FND_API.G_RET_STS_ERROR
6986                        THEN
6987                              --RAISE  FND_API.G_EXC_ERROR;
6988                              -- as the called api adds msg to stack hence no need to add err msg here.
6989 
6990                              /*  Bug 3133930- set the return status to the new output variable */
6991                              x_budget_lines_out(i).return_status := x_return_status;
6992 
6993                              l_any_error_occurred_flag:='Y';
6994                        END IF;
6995               END IF; --p_clalling_context <> 'UPDATE_PLANNING_ELEMENT_ATTR' Bug 5509192
6996 
6997                   l_res_planning_level := NULL;
6998 
6999                   --Manipulation of resource alias should be done only when the resource list passed
7000                   --is not uncategorized
7001                   IF (nvl(l_uncategorized_res_list_id,-99) = p_resource_list_id) THEN
7002 
7003                         px_budget_lines_in(i).resource_list_member_id :=l_uncategorized_rlmid;
7004                         px_budget_lines_in(i).resource_alias := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR;
7005 
7006                         IF p_calling_context = 'UPDATE_PLANNING_ELEMENT_ATTR' then
7007                                    l_valid_rlmid := 'Y';
7008                         END IF ;
7009 
7010 
7011                   ELSE -- not uncategorized RL
7012                         -- convert resource alias to (resource) member id
7013                         -- if resource alias is (passed and not NULL)
7014                         -- and resource member is (passed and not NULL)
7015                         -- then we convert the alias to the id
7016                         -- else we default to the uncategorized resource member
7017 
7018                         IF (px_budget_lines_in(i).resource_alias <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
7019                            AND px_budget_lines_in(i).resource_alias IS NOT NULL)
7020                             OR (px_budget_lines_in(i).resource_list_member_id <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM
7021                            AND px_budget_lines_in(i).resource_list_member_id IS NOT NULL)
7022                         THEN
7023 
7024                             --Selecting the index if it will be based on rlm_id or resource_alias. This index is decided on the
7025                             --basis of whther this (pa_resource_pub.Convert_alias_to_id ) API call would honour the
7026                             --rlm_id or resource_alias. The rule is rlm_id is honoured if both are passed to the API
7027                             --otherwise whichever value is passed that value is honoured by the API.
7028                             --Also note while preparing the index we are prepending 'RLMID' or 'RALIAS' before the actual values.
7029                             --The index would always be in this format.
7030 
7031                             --Also didnt included the null check in below if's to decide the index because it has already been
7032                             --taken care of in the last if before this. See above. We wont reach here if any one of rlm_id or
7033                             --resource_alias is null
7034                              IF(px_budget_lines_in(i).resource_list_member_id <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM )
7035                              THEN
7036                              --Prepending the word 'RLMID' before the rlm_id value while preparing the index.
7037                              l_distinct_rlmid_idx := 'RLMID' || px_budget_lines_in(i).resource_list_member_id;
7038                              ELSIF( px_budget_lines_in(i).resource_alias <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR)
7039                              THEN
7040                              --Prepending the word 'RALIAS' before the reasource_alias value while preparing the index.
7041                              l_distinct_rlmid_idx := 'RALIAS' || px_budget_lines_in(i).resource_alias;
7042                              END IF;
7043 
7044                            --l_rlm_id_tbl table would be used to cache the rlm_id for the rlm_id/resource_alias passed.
7045                            -- This table would store the value for rlm_id everytime a new rlm_id or resource_alias is passed.
7046                            --The table is indexed by index 'l_distinct_rlmid_idx' which could be either resource_alias or
7047                            --rlm_id.
7048                            --Check in the table if the value is already present for this index(which is one of
7049                            --rlm_id/resource_alias). If present then read the rlm_id from the table for this index
7050                            --else call the api.
7051                              IF( NOT(l_rlm_id_tbl.exists(l_distinct_rlmid_idx) ) )
7052                              THEN
7053                                       pa_resource_pub.Convert_alias_to_id
7054                                                     ( p_project_id                  => p_pa_project_id
7055                                                      ,p_resource_list_id            => p_resource_list_id
7056                                                      ,p_alias                       => px_budget_lines_in(i).resource_alias
7057                                                      ,p_resource_list_member_id     => px_budget_lines_in(i).resource_list_member_id
7058                                                      ,p_out_resource_list_member_id => px_budget_lines_in(i).resource_list_member_id
7059                                                      ,p_return_status               => x_return_status   );
7060 
7061                                       --dbms_output.put_line('----- p_out_resource_list_member_id: -----' || p_out_resource_list_member_id);
7062                                       IF x_return_status = FND_API.G_RET_STS_SUCCESS
7063                                       THEN
7064                                           -- Initialise valid rlmid variable to Y
7065                                           l_valid_rlmid := 'Y';
7066                                           IF((p_budget_type_code IS NOT NULL) AND
7067                                              (p_budget_type_code <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR)) THEN -- Old Bugdets Model -- Bug 3801891
7068                                             --get unit_of_measure and track_as_labor_flag associated to
7069                                             --the resource member and check whether this is a valid member for this list
7070                                             OPEN l_resource_csr( px_budget_lines_in(i).resource_list_member_id
7071                                                                 ,p_resource_list_id     );
7072                                             FETCH l_resource_csr INTO l_unit_of_measure, l_track_as_labor_flag, l_rlm_migration_code;
7073                                             IF l_resource_csr%NOTFOUND THEN
7074                                                   l_context_info := p_budget_type_code;
7075                                                   IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
7076                                                   THEN
7077                                                       pa_interface_utils_pub.map_new_amg_msg
7078                                                       ( p_old_message_code => 'PA_LIST_MEMBER_INVALID'
7079                                                       ,p_msg_attribute    => 'CHANGE'
7080                                                       ,p_resize_flag      => 'N'
7081                                                       ,p_msg_context      => 'BUDG'
7082                                                       ,p_attribute1       => l_amg_project_rec.segment1
7083                                                       ,p_attribute2       => l_amg_task_number
7084                                                       ,p_attribute3       => l_context_info
7085                                                       ,p_attribute4       => ''
7086                                                       ,p_attribute5       => to_char(px_budget_lines_in(i).budget_start_date));
7087                                                   END IF;
7088                                                   x_return_status := FND_API.G_RET_STS_ERROR;
7089                                                   /*  Bug 3133930- set the return status to the new output variable */
7090                                                   x_budget_lines_out(i).return_status := x_return_status;
7091                                                   CLOSE l_resource_csr;
7092 
7093                                                   l_any_error_occurred_flag:='Y';
7094                                                   l_valid_rlmid := 'N';
7095                                                   --RAISE FND_API.G_EXC_ERROR;
7096                                             ELSE
7097                                                   CLOSE l_resource_csr;
7098                                             END IF;
7099 
7100                                             /* bug 3954329: included the following check */
7101                                             IF l_rlm_migration_code = 'N' THEN
7102                                                   l_any_error_occurred_flag:='Y';
7103                                                   l_valid_rlmid := 'N';
7104                                                   x_return_status := FND_API.G_RET_STS_ERROR;
7105                                                   x_budget_lines_out(i).return_status := x_return_status;
7106                                                   PA_UTILS.ADD_MESSAGE
7107                                                               ( p_app_short_name => 'PA',
7108                                                                 p_msg_name       => 'PA_FP_OLD_MOD_NEW_RLM_PASSED');
7109                                             END IF;
7110                                             /* bug 3954329 end */
7111 
7112                                           ELSE -- New Bugdets Model -- Bug 3801891
7113                                             OPEN l_resource_csr_fp(px_budget_lines_in(i).resource_list_member_id);
7114                                             FETCH l_resource_csr_fp INTO l_unit_of_measure, l_rlm_migration_code;
7115                                             IF l_resource_csr_fp%NOTFOUND THEN
7116                                                   l_context_info := l_fin_plan_type_name;
7117                                                     IF p_calling_context = 'WEBADI' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
7118                                                            l_webadi_err_code_tbl.extend(1);
7119                                                            l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_LIST_MEMBER_INVALID';
7120                                                            l_webadi_err_task_id_tbl.extend(1);
7121                                                            l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7122                                                            l_webadi_err_rlm_id_tbl.extend(1);
7123                                                            l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7124                                                            l_webadi_err_txn_curr_tbl.extend(1);
7125                                                            l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7126                                                            l_webadi_err_amt_type_tbl.extend(1);
7127                                                            l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7128                                                     ELSE
7129                                                        IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7130                                                           pa_interface_utils_pub.map_new_amg_msg
7131                                                           ( p_old_message_code => 'PA_LIST_MEMBER_INVALID'
7132                                                            ,p_msg_attribute    => 'CHANGE'
7133                                                            ,p_resize_flag      => 'N'
7134                                                            ,p_msg_context      => 'BUDG'
7135                                                            ,p_attribute1       => l_amg_project_rec.segment1
7136                                                            ,p_attribute2       => l_amg_task_number
7137                                                            ,p_attribute3       => l_context_info
7138                                                            ,p_attribute4       => ''
7139                                                            ,p_attribute5       => to_char(px_budget_lines_in(i).budget_start_date));
7140                                                        END IF;
7141                                                           x_return_status := FND_API.G_RET_STS_ERROR;
7142                                                           x_budget_lines_out(i).return_status := x_return_status;
7143                                                     END IF;
7144                                                   CLOSE l_resource_csr_fp;
7145 
7146                                                   l_any_error_occurred_flag:='Y';
7147                                                   l_valid_rlmid := 'N';
7148                                             ELSE
7149                                                   CLOSE l_resource_csr_fp;
7150                                             END IF;
7151                                             /* bug 3954329: included the following check */
7152                                             IF l_rlm_migration_code IS NULL THEN
7153                                                   IF p_calling_context = 'WEBADI' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
7154                                                          l_webadi_err_code_tbl.extend(1);
7155                                                          l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_OLD_RLM_PASSED';
7156                                                          l_webadi_err_task_id_tbl.extend(1);
7157                                                          l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7158                                                          l_webadi_err_rlm_id_tbl.extend(1);
7159                                                          l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7160                                                          l_webadi_err_txn_curr_tbl.extend(1);
7161                                                          l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7162                                                          l_webadi_err_amt_type_tbl.extend(1);
7163                                                          l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7164                                                   ELSE
7165                                                         x_return_status := FND_API.G_RET_STS_ERROR;
7166                                                         x_budget_lines_out(i).return_status := x_return_status;
7167                                                         PA_UTILS.ADD_MESSAGE
7168                                                                     ( p_app_short_name => 'PA',
7169                                                                       p_msg_name       => 'PA_FP_NEW_MOD_OLD_RLM_PASSED');
7170                                                   END IF;
7171 
7172                                                   l_any_error_occurred_flag:='Y';
7173                                                   l_valid_rlmid := 'N';
7174                                             END IF;
7175                                             /* bug 3954329 end */
7176 
7177                                           END IF; -- Bug 3801891
7178 
7179                                           IF((p_budget_type_code IS NOT NULL) AND
7180                                              (p_budget_type_code <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR)) THEN -- 4504585 For old budget model only
7181 
7182                                                 IF l_valid_rlmid='Y' THEN
7183 
7184                                                       SELECT parent_member_id
7185                                                             ,resource_type_code
7186                                                             ,alias
7187                                                       INTO   l_parent_member_id
7188                                                             ,l_resource_type_code
7189                                                             ,pa_budget_pvt.g_resource_alias
7190                                                       FROM   pa_resource_list_members
7191                                                       WHERE  resource_list_member_id = px_budget_lines_in(i).resource_list_member_id;
7192 
7193                                                       IF l_resource_type_code = 'UNCLASSIFIED' THEN
7194 
7195                                                             l_any_error_occurred_flag:='Y';
7196                                                             l_valid_rlmid := 'N';
7197                                                             x_return_status := FND_API.G_RET_STS_ERROR;
7198                                                             /*  Bug 3133930- set the return status to the new output variable */
7199                                                             x_budget_lines_out(i).return_status := x_return_status;
7200 
7201                                                             PA_UTILS.ADD_MESSAGE
7202                                                                         ( p_app_short_name => 'PA',
7203                                                                           p_msg_name       => 'PA_FP_AMT_FOR_UNCLASSIFIED_RES',
7204                                                                           p_token1         => 'PROJECT',
7205                                                                           p_value1         =>  l_amg_project_rec.segment1,
7206                                                                           p_token2         => 'TASK',
7207                                                                           p_value2         => l_amg_task_number);
7208                                                             l_valid_rlmid:='N';
7209 
7210                                                       ELSE
7211 
7212                                                             IF l_parent_member_id IS NULL THEN
7213                                                                   l_res_planning_level := PA_FP_CONSTANTS_PKG.G_RESOURCE_PLANNING_LEVEL_G;
7214                                                             ELSE
7215                                                                   l_res_planning_level := PA_FP_CONSTANTS_PKG.G_RESOURCE_PLANNING_LEVEL_R;
7216                                                             END IF;
7217 
7218                                                       END IF;
7219                                                 END IF;
7220                                           END IF;
7221                                             --Changed the if below for bug#4488926.
7222                                             IF (l_valid_rlmid = 'Y') THEN /*l_valid_rlmid equal to Y would ensure that no error
7223                                             occurred after  the API call pa_resource_pub.Convert_alias_to_id made above till this
7224                                             point in code*/
7225                                           --If the API completes and above validations completes successfully then store the rlm_id in the
7226                                           --l_rlm_id_tbl at the location indexed by l_distinct_rlmid_idx.
7227                                                l_rlm_id_tbl(l_distinct_rlmid_idx) := px_budget_lines_in(i).resource_list_member_id;
7228                                           --Also if the index was based on resource_alias then we derive rlm_id for this, but next time
7229                                           --possibly rlm_id could be passed which has been derived from this resource_alias. So we
7230                                           --should store this derived rlm_id also in the table.
7231                                           --More importantly this rlm_id should be stored at the location indexed by
7232                                           --'RLMID' || px_budget_lines_in(i).rlm_id. Here prepending the RLMID and the value
7233                                           --px_budget_lines_in(i).resource_list_member_id was derived in the above API call as o/p
7234                                           --parameter.
7235                                               IF(l_distinct_rlmid_idx = 'RALIAS' || px_budget_lines_in(i).resource_alias)
7236                                               THEN
7237                                                   IF(l_rlm_id_tbl.exists('RLMID' || px_budget_lines_in(i).resource_list_member_id))
7238                                                   THEN
7239                                                       --If the rlm_id derived from this resource_alias is already present then dont
7240                                                       --store it again.
7241                                                        null;
7242                                                   ELSE
7243                                                       --Derived rlm_id should be stored at the location indexed by
7244                                                       --'RLMID' || px_budget_lines_in(i).resource_list_member_id Here prepending the
7245                                                       --RLMID and the value px_budget_lines_in(i).resource_list_member_id was derived in
7246                                                       --the above API call as o/p parameter.
7247                                                       --Storing this value would ensure that next time if this rlm_id is passed we dont
7248                                                       --call the API.
7249                                                        l_rlm_id_tbl('RLMID' || px_budget_lines_in(i).resource_list_member_id) :=
7250                                                                                          px_budget_lines_in(i).resource_list_member_id;
7251                                                   END IF;
7252                                               END IF;
7253                                             END IF; --x_return_status = FND_API.G_RET_STS_SUCCESS THEN
7254 
7255                                       ELSIF x_return_status =  FND_API.G_RET_STS_UNEXP_ERROR
7256                                       THEN
7257                                             /*  Bug 3133930- set the return status to the new output variable */
7258                                             x_budget_lines_out(i).return_status := x_return_status;
7259                                             RAISE  FND_API.G_EXC_UNEXPECTED_ERROR;
7260 
7261                                       ELSIF x_return_status = FND_API.G_RET_STS_ERROR
7262                                       THEN
7263                                             /*  Bug 3133930- set the return status to the new output variable */
7264                                             x_budget_lines_out(i).return_status := x_return_status;
7265                                             --RAISE  FND_API.G_EXC_ERROR;
7266                                             -- error message is added by the called API. Hence no error msg need to be added here.
7267                                             l_any_error_occurred_flag:='Y';
7268                                       END IF;
7269                               ELSE --IF( NOT(l_rlm_id_tbl.exists(l_distinct_rlmid_idx) ) )
7270                              --If the value is already there in the table for this index(task_id/task_ref) then read it from table
7271                                 --for this index.
7272                                 px_budget_lines_in(i).resource_list_member_id := l_rlm_id_tbl(l_distinct_rlmid_idx) ;
7273                               END IF; --IF( NOT(l_rlm_id_tbl.exists(l_distinct_rlmid_idx) ) )
7274 
7275                         ELSE
7276                               IF (p_budget_type_code IS NULL  OR
7277                                    p_budget_type_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR ) THEN
7278                                     l_context_info := l_fin_plan_type_name;
7279                               ELSE
7280                                     l_context_info := p_budget_type_code;
7281                               END IF;
7282 
7283                               IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7284                                     pa_interface_utils_pub.map_new_amg_msg
7285                                    ( p_old_message_code => 'PA_RESOURCE_IS_MISSING'
7286                                    ,p_msg_attribute    => 'CHANGE'
7287                                    ,p_resize_flag      => 'N'
7288                                    ,p_msg_context      => 'BUDG'
7289                                    ,p_attribute1       => l_amg_project_rec.segment1
7290                                    ,p_attribute2       => l_amg_task_number
7291                                    ,p_attribute3       => l_context_info
7292                                    ,p_attribute4       => ''
7293                                    ,p_attribute5       => to_char(px_budget_lines_in(i).budget_start_date));
7294                                    --RAISE FND_API.G_EXC_ERROR;
7295                                END IF;
7296                               x_return_status := FND_API.G_RET_STS_ERROR;
7297                               /*  Bug 3133930- set the return status to the new output variable */
7298                               x_budget_lines_out(i).return_status := x_return_status;
7299                               l_any_error_occurred_flag:='Y';
7300                         END IF;
7301 
7302                   END IF;--IF (nvl(l_uncategorized_res_list_id,-99) = p_resource_list_id) THEN
7303 
7304                   IF p_calling_context= 'UPDATE_PLANNING_ELEMENT_ATTR' then
7305                          IF l_valid_rlmid ='Y' then
7306                                    SELECT  ALIAS
7307                                    INTO   px_budget_lines_in(i).resource_alias
7308                                    FROM   pa_resource_list_members
7309                                    WHERE  resource_list_member_id = px_budget_lines_in(i).resource_list_member_id;
7310                          END IF;
7311                           -- DBMS_OUTPUT.PUT_LINE('resource alias '||i||' '||px_budget_lines_in(i).resource_alias);
7312                   END IF;
7313 
7314 
7315                   -- Bug 3986129: FP.M Web ADI Dev changes
7316                    IF p_calling_context = 'WEBADI' or
7317                    (p_calling_context='UPDATE_PLANNING_ELEMENT_ATTR' and l_valid_rlmid ='Y') THEN --Bug 5509192
7318 
7319                        -- validating resource level attributes
7320                        IF p_uom_tbl(i) IS NOT NULL AND
7321                           p_uom_tbl(i) = FND_API.G_MISS_CHAR THEN
7322                               -- UOM has been nulled out
7323                               l_webadi_err_code_tbl.extend(1);
7324                               l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_UOM_NULLED_OUT';
7325                               l_webadi_err_task_id_tbl.extend(1);
7326                               l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7327                               l_webadi_err_rlm_id_tbl.extend(1);
7328                               l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7329                               l_webadi_err_txn_curr_tbl.extend(1);
7330                               l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7331                               l_webadi_err_amt_type_tbl.extend(1);
7332                               l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7333                               l_any_error_occurred_flag := 'Y';
7334                        ELSIF p_uom_tbl(i) IS NOT NULL AND
7335                              p_uom_tbl(i) <> FND_API.G_MISS_CHAR THEN
7336                              -- value for UOM has been passed
7337                              -- calling an api to validate the UOM passed
7338                              PA_BUDGET_CHECK_PVT.validate_uom_passed
7339                                  (p_res_list_mem_id  => px_budget_lines_in(i).resource_list_member_id,
7340                                   p_uom_passed       => p_uom_tbl(i),
7341                                   x_error_code       => l_new_error_code,
7342                                   x_return_status    => x_return_status,
7343                                   x_msg_data         => x_msg_data,
7344                                   x_msg_count        => x_msg_count);
7345 
7346                                   IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
7347                                       IF l_new_error_code IS NOT NULL THEN
7348                                             l_webadi_err_code_tbl.extend(1);
7349                                             l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := l_new_error_code;
7350                                             l_webadi_err_task_id_tbl.extend(1);
7351                                             l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7352                                             l_webadi_err_rlm_id_tbl.extend(1);
7353                                             l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7354                                             l_webadi_err_txn_curr_tbl.extend(1);
7355                                             l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7356                                             l_webadi_err_amt_type_tbl.extend(1);
7357                                             l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7358                                             l_any_error_occurred_flag := 'Y';
7359                                       END IF;
7360                                   ELSE
7361                                       RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
7362                                   END IF;
7363                        END IF; -- uom validation
7364 
7365                      --etc method validation starts
7366                       l_valid_etc_method:='Y';
7367                       l_etc_method_code :=null;
7368 
7369                        IF p_etc_method_name_tbl(i) IS NOT NULL AND
7370                          (p_calling_context = 'UPDATE_PLANNING_ELEMENT_ATTR' or
7371                           p_etc_method_name_tbl(i) <> FND_API.G_MISS_CHAR) THEN
7372                               BEGIN
7373                                     SELECT lookup_code
7374                                     INTO   l_etc_method_code
7375                                     FROM   pa_lookups
7376                                     WHERE  lookup_type = 'PA_FP_ETC_METHOD'
7377                                     AND    meaning = p_etc_method_name_tbl(i);
7378                               EXCEPTION
7379                                     WHEN NO_DATA_FOUND THEN
7380                                            l_valid_etc_method := 'N';
7381                               END;
7382 
7383                               IF l_valid_etc_method = 'N' THEN
7384                               -- throwing error
7385                                  IF p_calling_context = 'UPDATE_PLANNING_ELEMENT_ATTR' then
7386                                        IF px_budget_lines_in(i).pa_task_id <> 0 then
7387                                                PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7388                                                p_msg_name       => 'INVALID_ETC_METHOD_AMG',
7389                                                p_token1         => 'PROJECT_OR_TASK_NUMBER',
7390                                                p_value1         => l_amg_task_number,
7391                                                p_token2         => 'RESOURCE',
7392                                                p_value2         => px_budget_lines_in(i).resource_alias);
7393                                        ELSE
7394                                                PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7395                                                p_msg_name       => 'INVALID_ETC_METHOD_AMG',
7396                                                p_token1         => 'PROJECT_OR_TASK_NUMBER',
7397                                                p_value1         => l_project_number,
7398                                                p_token2         => 'RESOURCE',
7399                                                p_value2         => px_budget_lines_in(i).resource_alias);
7400                                        END IF;
7401                                        l_any_error_occurred_flag := 'Y';
7402                                  ELSE
7403                                     l_webadi_err_code_tbl.extend(1);
7404                                     l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_INV_ETC_PASSED';
7405                                     l_webadi_err_task_id_tbl.extend(1);
7406                                     l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7407                                     l_webadi_err_rlm_id_tbl.extend(1);
7408                                     l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7409                                     l_webadi_err_txn_curr_tbl.extend(1);
7410                                     l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7411                                     l_webadi_err_amt_type_tbl.extend(1);
7412                                     l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7413                                     l_any_error_occurred_flag := 'Y';
7414                                  END IF;
7415                               ELSE
7416                                     x_etc_method_code_tbl.EXTEND(1);
7417                                     x_etc_method_code_tbl(x_etc_method_code_tbl.COUNT) := l_etc_method_code;
7418                               END IF;
7419                        ELSIF p_etc_method_name_tbl(i) IS NULL THEN
7420                               -- this need not be validated as the column is hidden
7421                               x_etc_method_code_tbl.EXTEND(1);
7422                               x_etc_method_code_tbl(x_etc_method_code_tbl.COUNT) := null;
7423                        END IF; -- etc validation
7424 
7425 
7426 
7427                        IF p_mfc_cost_type_tbl(i) IS NOT NULL AND
7428                           p_mfc_cost_type_tbl(i) <> FND_API.G_MISS_CHAR THEN
7429                               BEGIN
7430                                     SELECT cost_type_id
7431                                     INTO   l_mfc_cost_type_id
7432                                     FROM   CST_COST_TYPES_V
7433                                     WHERE  multi_org_flag = 1
7434                                     AND    cost_type = p_mfc_cost_type_tbl(i);
7435                               EXCEPTION
7436                                     WHEN NO_DATA_FOUND THEN
7437                                            l_valid_mfc_cost_type := 'N';
7438                               END;
7439 
7440                               IF l_valid_mfc_cost_type = 'N' THEN
7441                               -- throwing error
7442                                     l_webadi_err_code_tbl.extend(1);
7443                                     l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_INV_MFC_PASSED';
7444                                     l_webadi_err_task_id_tbl.extend(1);
7445                                     l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7446                                     l_webadi_err_rlm_id_tbl.extend(1);
7447                                     l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7448                                     l_webadi_err_txn_curr_tbl.extend(1);
7449                                     l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7450                                     l_webadi_err_amt_type_tbl.extend(1);
7451                                     l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7452                                     l_any_error_occurred_flag := 'Y';
7453                               ELSE
7454                                     x_mfc_cost_type_id_tbl.EXTEND(1);
7455                                     x_mfc_cost_type_id_tbl(x_mfc_cost_type_id_tbl.COUNT) := l_mfc_cost_type_id;
7456                               END IF;
7457                        ELSIF p_mfc_cost_type_tbl(i) IS NULL THEN
7458                               -- this need not be validated as the column is hidden
7459                               x_mfc_cost_type_id_tbl.EXTEND(1);
7460                               x_mfc_cost_type_id_tbl(x_mfc_cost_type_id_tbl.COUNT) := null;
7461                        END IF; -- MFC validation\
7462 
7463                        l_valid_spread_curve := 'Y';
7464                        l_spread_curve_id    :=null;
7465 
7466                        -- validating spread curve
7467                        IF p_calling_context='WEBADI' and p_spread_curve_id_tbl.EXISTS(i) AND
7468                           (p_spread_curve_id_tbl(i) IS NULL  OR p_spread_curve_id_tbl(i) <> FND_API.G_MISS_NUM) THEN
7469                               x_spread_curve_id_tbl.EXTEND(1);
7470                               x_spread_curve_id_tbl(x_spread_curve_id_tbl.COUNT) := p_spread_curve_id_tbl(i);
7471                        ELSE
7472                               IF p_spread_curve_name_tbl(i) IS NOT NULL AND
7473                                  p_spread_curve_name_tbl(i) = FND_API.G_MISS_CHAR AND
7474                                  p_calling_context <> 'UPDATE_PLANNING_ELEMENT_ATTR' THEN
7475 
7476                                     l_webadi_err_code_tbl.extend(1);
7477                                     l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_SC_NULLED_OUT';
7478                                     l_webadi_err_task_id_tbl.extend(1);
7479                                     l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7480                                     l_webadi_err_rlm_id_tbl.extend(1);
7481                                     l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7482                                     l_webadi_err_txn_curr_tbl.extend(1);
7483                                     l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7484                                     l_webadi_err_amt_type_tbl.extend(1);
7485                                     l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7486                                     l_any_error_occurred_flag := 'Y';
7487                               ELSIF p_spread_curve_name_tbl(i) IS NOT NULL AND
7488                                     (p_calling_context = 'UPDATE_PLANNING_ELEMENT_ATTR' or
7489                                       p_spread_curve_name_tbl(i) <> FND_API.G_MISS_CHAR) THEN
7490 
7491                                     BEGIN
7492                                           SELECT spread_curve_id
7493                                           INTO   l_spread_curve_id
7494                                           FROM   pa_spread_curves_vl
7495                                           WHERE  name = p_spread_curve_name_tbl(i);
7496                                     EXCEPTION
7497                                           WHEN NO_DATA_FOUND THEN
7498                                                 l_valid_spread_curve := 'N';
7499                                     END;
7500                                     IF l_valid_spread_curve = 'N' THEN
7501                                     -- throwing error
7502                                        IF p_calling_context = 'UPDATE_PLANNING_ELEMENT_ATTR' then
7503                                                IF px_budget_lines_in(i).pa_task_id <> 0 then
7504                                                        PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7505                                                        p_msg_name       => 'INVALID_SPREAD_CURVE_AMG',
7506                                                        p_token1         => 'PROJECT_OR_TASK_NUMBER',
7507                                                        p_value1         => l_amg_task_number,
7508                                                        p_token2         => 'RESOURCE',
7509                                                        p_value2         => px_budget_lines_in(i).resource_alias);
7510                                                 ELSE
7511                                                        PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7512                                                        p_msg_name       => 'INVALID_SPREAD_CURVE_AMG',
7513                                                        p_token1         => 'PROJECT_OR_TASK_NUMBER',
7514                                                        p_value1         => l_project_number,
7515                                                        p_token2         => 'RESOURCE',
7516                                                        p_value2         => px_budget_lines_in(i).resource_alias);
7517                                                END IF;
7518 
7519                                                l_any_error_occurred_flag := 'Y';
7520                                        ELSE
7521 
7522                                           l_webadi_err_code_tbl.extend(1);
7523                                           l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_INV_SC_PASSED';
7524                                           l_webadi_err_task_id_tbl.extend(1);
7525                                           l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7526                                           l_webadi_err_rlm_id_tbl.extend(1);
7527                                           l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7528                                           l_webadi_err_txn_curr_tbl.extend(1);
7529                                           l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7530                                           l_webadi_err_amt_type_tbl.extend(1);
7531                                           l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7532                                           l_any_error_occurred_flag := 'Y';
7533                                        END IF;
7534                                     ELSE
7535                                           x_spread_curve_id_tbl.EXTEND(1);
7536                                           x_spread_curve_id_tbl(x_spread_curve_id_tbl.COUNT) := l_spread_curve_id;
7537                                     END IF;
7538                               ELSIF p_spread_curve_name_tbl(i) IS NULL then
7539                                           x_spread_curve_id_tbl.EXTEND(1);
7540                                           x_spread_curve_id_tbl(x_spread_curve_id_tbl.COUNT) := null;
7541                               END IF;
7542                        END IF; -- spread curve validation ends
7543 
7544                       if p_calling_context ='UPDATE_PLANNING_ELEMENT_ATTR' then
7545                                    l_invalid_resassgn_flag :='N';
7546                                    l_resource_assignment_id:=null;
7547                                    l_planning_start_date   :=null;
7548                                    l_planning_end_date     :=null;
7549                                    l_sp_fixed_date         :=null;
7550                                    begin
7551                                            SELECT resource_assignment_id,planning_start_date,
7552                                            planning_end_date,nvl(l_spread_curve_id,spread_curve_id),sp_fixed_date
7553                                            INTO l_resource_assignment_id,l_planning_start_date,
7554                                            l_planning_end_date,l_spread_curve_id,l_sp_fixed_date
7555                                            FROM pa_resource_assignments
7556                                            WHERE  budget_version_id=p_version_info_rec.x_budget_version_id
7557                                            AND task_id=px_budget_lines_in(i).pa_task_id
7558                                            AND resource_list_member_id=px_budget_lines_in(i).resource_list_member_id
7559                                            AND project_id=p_pa_project_id
7560                                            AND PROJECT_ASSIGNMENT_ID =-1;
7561                                    exception when no_data_found then
7562                                            if px_budget_lines_in(i).pa_task_id <> 0 then
7563                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7564                                                            p_msg_name       => 'RES_ASSGN_DOESNT_EXIST_AMG',
7565                                                            p_token1         => 'PROJECT_OR_TASK_NUMBER',
7566                                                            p_value1         => l_amg_task_number,
7567                                                            p_token2         => 'RESOURCE',
7568                                                            p_value2         => px_budget_lines_in(i).resource_alias);
7569                                            else
7570                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7571                                                            p_msg_name       => 'RES_ASSGN_DOESNT_EXIST_AMG',
7572                                                            p_token1         => 'PROJECT_OR_TASK_NUMBER',
7573                                                            p_value1         => l_project_number,
7574                                                            p_token2         => 'RESOURCE',
7575                                                            p_value2         => px_budget_lines_in(i).resource_alias);
7576                                            end if;
7577                                            l_any_error_occurred_flag := 'Y';
7578                                            l_invalid_resassgn_flag:='Y';
7579                                    end;
7580 
7581                                    G_res_assign_tbl(i).resource_assignment_id:=l_resource_assignment_id;
7582 
7583                                    if l_invalid_resassgn_flag <> 'Y' then
7584                                            if l_raid_hash_table.exists('RA'||l_resource_assignment_id) then
7585                                                    if px_budget_lines_in(i).pa_task_id <> 0 then
7586                                                            PA_UTILS.ADD_MESSAGE
7587                                                                   (p_app_short_name => 'PA',
7588                                                                    p_msg_name       => 'PA_ATTR_DUP_SRCH_ERR',
7589                                                                    p_token1         => 'ATTR_NAME',
7590                                                                    p_value1         => 'Task '||l_amg_task_number||' Resource '||px_budget_lines_in(i).resource_alias
7591 
7592                                                                    );
7593                                                    else
7594                                                            PA_UTILS.ADD_MESSAGE
7595                                                                    (p_app_short_name => 'PA',
7596                                                                     p_msg_name       => 'PA_ATTR_DUP_SRCH_ERR',
7597                                                                     p_token1         => 'ATTR_NAME',
7598                                                                     p_value1         => 'Project '||l_project_number||' Resource '||px_budget_lines_in(i).resource_alias
7599 
7600                                                                     );
7601                                                    end if;
7602                                                    l_any_error_occurred_flag := 'Y';
7603                                            else
7604                                                    l_raid_hash_table('RA'||l_resource_assignment_id).resource_assignment_id:=l_resource_assignment_id;
7605                                            end if;
7606                                    end if;
7607 
7608                                    l_invalid_plandates_flag :='N';
7609 
7610                                    if p_planning_start_date_tbl(i) = FND_API.G_MISS_DATE or
7611                                       p_planning_end_date_tbl(i) = FND_API.G_MISS_DATE   then
7612                                            if px_budget_lines_in(i).pa_task_id <> 0 then
7613                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7614                                                    p_msg_name       => 'INVALID_PLANNING_DATES_AMG',
7615                                                    p_token1         => 'PROJECT_OR_TASK_NUMBER',
7616                                                    p_value1         => l_amg_task_number,
7617                                                    p_token2         => 'RESOURCE',
7618                                                    p_value2         => px_budget_lines_in(i).resource_alias);
7619                                            else
7620                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7621                                                    p_msg_name       => 'INVALID_PLANNING_DATES_AMG',
7622                                                    p_token1         => 'PROJECT_OR_TASK_NUMBER',
7623                                                    p_value1         => l_project_number,
7624                                                    p_token2         => 'RESOURCE',
7625                                                    p_value2         => px_budget_lines_in(i).resource_alias);
7626                                            end if;
7627                                            l_any_error_occurred_flag := 'Y';
7628                                            l_invalid_plandates_flag  := 'Y';
7629 
7630                                     end if;
7631 
7632                                    if (l_invalid_plandates_flag  <> 'Y' and
7633                                        ((p_planning_start_date_tbl(i) is null and
7634                                            p_planning_end_date_tbl(i) is not null) or
7635                                         (p_planning_start_date_tbl(i) is not null and
7636                                            p_planning_end_date_tbl(i) is null) or
7637                                          (nvl(p_planning_end_date_tbl(i),FND_API.G_MISS_DATE) <
7638                                            nvl(p_planning_start_date_tbl(i),FND_API.G_MISS_DATE)))) then
7639 
7640                                            if px_budget_lines_in(i).pa_task_id <> 0 then
7641                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7642                                                    p_msg_name       => 'INVALID_PLANNING_DATES_AMG',
7643                                                    p_token1         => 'PROJECT_OR_TASK_NUMBER',
7644                                                    p_value1         => l_amg_task_number,
7645                                                    p_token2         => 'RESOURCE',
7646                                                    p_value2         => px_budget_lines_in(i).resource_alias);
7647                                            else
7648                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7649                                                    p_msg_name       => 'INVALID_PLANNING_DATES_AMG',
7650                                                    p_token1         => 'PROJECT_OR_TASK_NUMBER',
7651                                                    p_value1         => l_project_number,
7652                                                    p_token2         => 'RESOURCE',
7653                                                    p_value2         => px_budget_lines_in(i).resource_alias);
7654                                            end if;
7655                                            l_any_error_occurred_flag := 'Y';
7656                                            l_invalid_plandates_flag  := 'Y';
7657 
7658                                    end if;
7659 
7660                                    IF l_spread_curve_id = l_fixed_date_sp_id THEN
7661                                            if (l_sp_fixed_date is null and (p_sp_fixed_date_tbl(i) is null or p_sp_fixed_date_tbl(i)= FND_API.G_MISS_DATE )) or
7662                                            (l_sp_fixed_date is not null and p_sp_fixed_date_tbl(i)= FND_API.G_MISS_DATE)
7663                                            then
7664                                                            PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7665                                                            p_msg_name       => 'PA_FP_SP_FIXED_DATE_NULL');
7666                                                            l_any_error_occurred_flag := 'Y';
7667                                                            l_invalid_plandates_flag  := 'Y';
7668                                            end if;
7669 
7670                                            if l_invalid_plandates_flag <> 'Y' then
7671                                                    if ((nvl(p_sp_fixed_date_tbl(i),l_sp_fixed_date) <
7672                                                            nvl(p_planning_start_date_tbl(i),l_planning_start_date)) or
7673                                                            (nvl(p_sp_fixed_date_tbl(i),l_sp_fixed_date) >
7674                                                            nvl(p_planning_end_date_tbl(i),l_planning_end_date))) then
7675 
7676                                                            if px_budget_lines_in(i).pa_task_id <> 0 then
7677                                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7678                                                                            p_msg_name       => 'INVALID_FIXED_DATE_AMG',
7679                                                                            p_token1         => 'PROJECT_OR_TASK_NUMBER',
7680                                                                            p_value1         => l_amg_task_number,
7681                                                                            p_token2         => 'RESOURCE',
7682                                                                            p_value2         => px_budget_lines_in(i).resource_alias);
7683                                                            else
7684                                                                    PA_UTILS.ADD_MESSAGE(p_app_short_name => 'PA',
7685                                                                            p_msg_name       => 'INVALID_FIXED_DATE_AMG',
7686                                                                            p_token1         => 'PROJECT_OR_TASK_NUMBER',
7687                                                                            p_value1         => l_project_number,
7688                                                                            p_token2         => 'RESOURCE',
7689                                                                            p_value2         => px_budget_lines_in(i).resource_alias);
7690                                                     end if;
7691                                                    l_any_error_occurred_flag := 'Y';
7692 
7693                                            end if;
7694 
7695                                    end if;
7696 
7697 
7698 
7699                            END IF;
7700                           end if; -- end of newly introduced checks for UPDATE_PLANNING_ELEMENT_ATTR
7701                    END IF;  -- Bug 3986129: FP.M Web ADI ,UPDATE_PLANNING_ELEMENT_ATTR
7702 
7703            -- hari 11th may
7704               IF ( p_calling_context NOT IN( 'RES_ASSGNMT_LEVEL_VALIDATION','WEBADI','UPDATE_PLANNING_ELEMENT_ATTR') OR --Bug 5509192
7705                   (p_calling_context = 'WEBADI' AND ((NOT (p_delete_flag_tbl.exists(i))) OR
7706                                                           Nvl(p_delete_flag_tbl(i), 'N') <> 'Y')))
7707               THEN
7708                     --Validate the change reason code. This validation is added for Fin plan model in FP L
7709                    IF (px_budget_lines_in(i).change_reason_code IS NOT NULL AND
7710                        ((p_calling_context = 'WEBADI' AND px_budget_lines_in(i).change_reason_code  <> FND_API.G_MISS_CHAR) OR
7711                         (p_calling_context <> 'WEBADI' AND px_budget_lines_in(i).change_reason_code  <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR))) THEN
7712 
7713                           OPEN l_budget_change_reason_csr( px_budget_lines_in(i).change_reason_code );
7714                           FETCH l_budget_change_reason_csr INTO l_dummy;
7715                           IF l_budget_change_reason_csr%NOTFOUND THEN
7716                               CLOSE l_budget_change_reason_csr;
7717 
7718                               IF p_calling_context <> 'WEBADI' THEN
7719                                          IF (p_budget_type_code IS NULL  OR
7720                                              p_budget_type_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR ) THEN
7721 
7722                                                l_context_info := l_fin_plan_type_name;
7723                                                /*  Bug 3133930- set the return status to the new output variable */
7724                                                x_budget_lines_out(i).return_status := x_return_status;
7725                                          ELSE
7726 
7727                                                 l_context_info := p_budget_type_code;
7728                                          END IF;
7729                                          IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
7730                                              PA_UTILS.add_message
7731                                              (p_app_short_name => 'PA',
7732                                               p_msg_name       => 'PA_CHANGE_REASON_INVALID_AMG',
7733                                               p_token1         => 'PROJECT',
7734                                               p_value1         =>  l_amg_project_rec.segment1,
7735                                               p_token2         => 'TASK',
7736                                               p_value2         => l_amg_task_number,
7737                                               p_token3         => 'BUDGET_TYPE',
7738                                               p_value3         => l_context_info ,
7739                                               p_token4         => 'START_DATE',
7740                                               p_value4         => to_char(px_budget_lines_in(i).budget_start_date));
7741                                           END IF;
7742                                     x_return_status := FND_API.G_RET_STS_ERROR;
7743                                     /*  Bug 3133930- set the return status to the new output variable */
7744                                     x_budget_lines_out(i).return_status := x_return_status;
7745                                     --RAISE FND_API.G_EXC_ERROR;
7746                               ELSE --p_calling_context <> 'WEBADI' THEN
7747                                     -- populate the error code specific to webadi context
7748                                     l_webadi_err_code_tbl.extend(1);
7749                                     l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_INV_RESN_CODE_PASSED';
7750                                     l_webadi_err_task_id_tbl.extend(1);
7751                                     l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7752                                     l_webadi_err_rlm_id_tbl.extend(1);
7753                                     l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7754                                     l_webadi_err_txn_curr_tbl.extend(1);
7755                                     l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7756                                     l_webadi_err_amt_type_tbl.extend(1);
7757                                     l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7758                               END IF;  -- calling context WEBADI
7759 
7760 
7761                               l_any_error_occurred_flag:='Y';
7762                           ELSE
7763                               CLOSE l_budget_change_reason_csr;
7764                           END IF;
7765                    END IF;--IF (px_budget_lines_in(i).change_reason_code IS NOT NULL AND
7766                 END IF; --p_calling_context <> 'RES_ASSGNMT_LEVEL_VALIDATION','UPDATE_PLANNING_ELEMENT_ATTR'
7767 
7768                  IF p_fin_plan_type_id IS NOT NULL and p_calling_context <> 'UPDATE_PLANNING_ELEMENT_ATTR' THEN -- Bug 5509192
7769 
7770                       --Bug#4457546:Added code to throw an error when amounts are entered for a period which
7771                       --does not fall within the planning start/end dates of resource assignment
7772                       --This API validate_budget_lines is being called from the following API's
7773                       --CREATE_DRAFT_BUDGET  (PACKAGE PA_BUDGET_PUB)
7774                       --ADD_BUDGET_LINE      (PACKAGE PA_BUDGET_PUB)
7775                       --UPDATE_BUDGET        (PACKAGE PA_BUDGET_PUB)
7776                       --UPDATE_BUDGET_LINE   (PACKAGE PA_BUDGET_PUB)
7777                       --CREATE_DRAFT_FINPLAN (PACKAGE PA_BUDGET_PUB)
7778                       --INSERT_BUDGET_LINE   (PACKAGE PA_BUDGET_PVT)
7779                       -- Of all the above places the below if condition would only be satisfied by ADD_BUDGET_LINE, UPDATE_BUDGET,
7780                       --UPDATE_BUDGET_LINE for finplan model only which is what is required here. This validation should only be done
7781                       --only from these calling places and only for finplan model.
7782 
7783                       IF ( p_calling_context = 'BUDGET_LINE_LEVEL_VALIDATION' and p_version_info_rec.x_budget_version_id is not null)
7784                       THEN
7785 
7786                         --Prepare the index in this form for each budget line.
7787                          l_distinct_taskid_rlmid_index := 'T'||px_budget_lines_in(i).pa_task_id||'R'||px_budget_lines_in(i).resource_list_member_id;
7788 
7789                           --Checking if the values are already present in the tables(l_plan_start_date_tbl, l_plan_end_date_tbl,
7790                           --l_task_name_tbl, l_resource_alias_tbl) for the index which we just prepared above. If the values are persent
7791                           --in these tables then done fire the below select
7792                          IF ( NOT(l_plan_start_date_tbl.exists(l_distinct_taskid_rlmid_index)
7793                              AND l_plan_end_date_tbl.exists(l_distinct_taskid_rlmid_index)
7794                              AND l_resource_alias_tbl.exists(l_distinct_taskid_rlmid_index) ) )
7795                          THEN
7796                              --Fire this select only if the values are not present in the above tables for any of the four values
7797                              --that we are reading in the below query.
7798                               BEGIN
7799                               -- We have to handle the no_data_found exception for this select because this select could be fired for
7800                               -- caselike from add_budget_line, the budget_line is being added for first time so there wont be any
7801                               --record in pa_resource_assignments when line is added for first time.
7802                                  SELECT pra.planning_start_date,
7803                                         pra.planning_end_date,
7804                                         prlm.alias
7805                                  INTO l_plan_start_date,
7806                                       l_plan_end_date,
7807                                       l_resource_alias
7808                                  FROM pa_resource_assignments pra,
7809                                       pa_resource_list_members prlm
7810                                  WHERE pra.budget_version_id = p_version_info_rec.x_budget_version_id
7811                                  AND   pra.resource_list_member_id = px_budget_lines_in(i).resource_list_member_id
7812                                  AND   pra.task_id = px_budget_lines_in(i).pa_task_id
7813                                  AND   prlm.resource_list_member_id = pra.resource_list_member_id;
7814                               EXCEPTION
7815                                   WHEN NO_DATA_FOUND THEN
7816                                      l_plan_start_date := null;
7817                                      l_plan_end_date := null;
7818                                      l_resource_alias := null;
7819                               END;
7820 
7821                                     --Store the values just read in the tables for caching purpose
7822                                     l_plan_start_date_tbl(l_distinct_taskid_rlmid_index) := l_plan_start_date;
7823                                     l_plan_end_date_tbl(l_distinct_taskid_rlmid_index) := l_plan_end_date;
7824                                     l_resource_alias_tbl(l_distinct_taskid_rlmid_index) := l_resource_alias;
7825 
7826                          ELSE
7827                                  --The tables already contain the values so read the values from the tables.
7828                                  l_plan_start_date   := l_plan_start_date_tbl(l_distinct_taskid_rlmid_index);
7829                                  l_plan_end_date     := l_plan_end_date_tbl(l_distinct_taskid_rlmid_index);
7830                                  l_resource_alias    := l_resource_alias_tbl(l_distinct_taskid_rlmid_index);
7831                          END IF;
7832 
7833                           --Added this if condition below for the bug#4479835
7834                           --We should do these validations only when the above query returned a record.
7835                           IF (l_plan_start_date is not null)
7836                           THEN
7837                                   IF (px_budget_lines_in(i).budget_start_date IS NOT NULL AND
7838                                       px_budget_lines_in(i).budget_start_date <> FND_API.G_MISS_DATE) AND
7839                                      (px_budget_lines_in(i).budget_end_date IS NOT NULL AND
7840                                       px_budget_lines_in(i).budget_end_date <> FND_API.G_MISS_DATE) THEN
7841 
7842                                           -- checking if the budget line start date/ end date falls between
7843                                           -- the planning start date/ end date
7844 
7845                                           --After the above  of l_period_time_phased_code, if l_period_time_phased_code = N
7846                                           --then it means its a non periodic finplan case
7847                                           IF ( l_period_time_phased_code <> 'N')
7848                                           THEN
7849                                               ---Added this code for bug#4488926. Caching the values of l_period_start_date and
7850                                               --l_period_end_date
7851                                               IF ( NOT(l_period_start_date_tbl.exists(to_char(l_plan_start_date))
7852                                                    AND l_period_end_date_tbl.exists(to_char(l_plan_end_date))))
7853                                                    THEN
7854                                                   --For periodic case get the start and end dates.
7855                                                   l_period_start_date := PA_FIN_PLAN_UTILS.get_period_start_date(l_plan_start_date,l_period_time_phased_code);
7856                                                   l_period_end_date :=  PA_FIN_PLAN_UTILS.get_period_end_date (l_plan_end_date , l_period_time_phased_code);
7857                                                   l_period_start_date_tbl(to_char(l_plan_start_date)) := l_period_start_date;
7858                                                   l_period_end_date_tbl(to_char(l_plan_end_date)) := l_period_end_date;
7859                                               ELSE
7860                                                   l_period_start_date := l_period_start_date_tbl(to_char(l_plan_start_date));
7861                                                   l_period_end_date := l_period_end_date_tbl(to_char(l_plan_end_date));
7862                                               END IF;
7863                                           ELSE
7864                                           --Its a non periodic case.
7865                                                   l_period_start_date := l_plan_start_date;
7866                                                   l_period_end_date :=  l_plan_end_date;
7867                                           END IF;
7868 
7869                                           IF (px_budget_lines_in(i).budget_start_date < l_period_start_date OR
7870                                              px_budget_lines_in(i).budget_end_date > l_period_end_date)
7871                                           THEN
7872                                               x_return_status := FND_API.G_RET_STS_ERROR;
7873                                               x_budget_lines_out(i).return_status := x_return_status;
7874                                               PA_UTILS.add_message
7875                                               (p_app_short_name => 'PA',
7876                                                p_msg_name       => 'PA_FP_START_END_DATE_NOT_VALID',
7877                                                p_token1         => 'TASK',
7878                                                p_value1         => l_amg_task_number,
7879                                                p_token2         => 'RESOURCE',
7880                                                p_value2         => l_resource_alias,
7881                                                p_token3         => 'CURRENCY',
7882                                                p_value3         => px_budget_lines_in(i).txn_currency_code,
7883                                                p_token4         => 'START_DATE',
7884                                                p_value4         => to_char(px_budget_lines_in(i).budget_start_date) );
7885                                            l_any_error_occurred_flag:='Y';
7886                                           END IF;
7887                                     ELSIF ( p_time_phased_code = 'N' and
7888                                            (px_budget_lines_in(i).budget_start_date IS NULL
7889                                             OR px_budget_lines_in(i).budget_start_date  = FND_API.G_MISS_DATE )
7890                                            AND (px_budget_lines_in(i).budget_end_date IS NULL
7891                                             OR px_budget_lines_in(i).budget_end_date  = FND_API.G_MISS_DATE ) )THEN
7892 
7893                                            px_budget_lines_in(i).budget_start_date := l_plan_start_date;
7894                                            px_budget_lines_in(i).budget_end_date :=   l_period_end_date;
7895 
7896                                   END IF; --px_budget_lines_in(i).budget_start_date IS NOT NULL AND
7897                           END IF; --IF (l_plan_start_date is not null)
7898                       END IF;-- p_calling_context='BUDGET_LINE_LEVEL_VALIDATION' and p_version_info_rec.x_budget_version_id is not null
7899 
7900 
7901                         --Validate the txn currency code provided by the user. The follwing checks are made.
7902                         --1.If the version is an approved revenue version then the txn curr code should be PFC.
7903                         --else If the version is MC enabled then txn curr code should be among the txn
7904                         --currencies provided at the plan type level option
7905                         --else if the version is not MC enabled then the txn curr code should be PC
7906 
7907 
7908                         -- check for approved rev plan type flag is made here because in case plan type is at
7909                         -- cost and revenue separately then version can have currencies other than PFC.
7910                         l_valid_txn_curr := FALSE;
7911                         IF(l_app_rev_plan_type_flag = 'Y' AND
7912                            p_version_type <> PA_FP_CONSTANTS_PKG.G_VERSION_TYPE_COST) THEN
7913 
7914                               --Bug 4382980:Issue#19 - Currency Defaulting when txn_currency_code
7915                               --is null done as suggested by Venkatesh Jayeraman
7916                               IF (px_budget_lines_in(i).txn_currency_code IS NULL ) THEN
7917                                    -- bug 4462614: added the following check for webadi context
7918                                    IF p_calling_context = 'WEBADI' THEN
7919                                          IF l_webadi_ci_id IS NULL THEN
7920                                              px_budget_lines_in(i).txn_currency_code:=l_projfunc_currency_code;
7921                                          ELSE
7922                                              px_budget_lines_in(i).txn_currency_code:=l_webadi_agr_curr_code;
7923                                          END IF;
7924                                    ELSE
7925                                          px_budget_lines_in(i).txn_currency_code:=l_projfunc_currency_code;
7926                                    END IF;
7927 
7928                               END IF; -- if currency passed is null
7929 
7930                               IF l_debug_mode = 'Y' THEN
7931                                     pa_debug.g_err_stage:= 'Plan Version is approved for revenue';
7932                                     pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
7933                               END IF;
7934 
7935                               IF l_webadi_ci_id IS NULL THEN
7936                                     -- non ci version for both web adi and other contexts
7937                                     IF(nvl(px_budget_lines_in(i).txn_currency_code,'-99') <>
7938                                                             l_projfunc_currency_code) THEN
7939                                           IF p_calling_context <> 'WEBADI' THEN
7940                                                 PA_UTILS.ADD_MESSAGE
7941                                                   ( p_app_short_name => 'PA',
7942                                                     p_msg_name       => 'PA_FP_TXN_NOT_PFC_FOR_APP_REV',
7943                                                     p_token1         => 'PROJECT',
7944                                                     p_value1         =>  l_amg_project_rec.segment1,
7945                                                     p_token2         => 'PLAN_TYPE',
7946                                                     p_value2         =>  l_fin_plan_type_name,
7947                                                     p_token3         => 'CURRENCY',
7948                                                     p_value3         =>  px_budget_lines_in(i).txn_currency_code);
7949 
7950 
7951                                                 x_return_status := FND_API.G_RET_STS_ERROR;
7952                                                 /*  Bug 3133930- set the return status to the new output variable */
7953                                                 x_budget_lines_out(i).return_status := x_return_status;
7954 
7955                                           ELSE
7956                                                 -- populate the error code specific to webadi context
7957                                                 l_webadi_err_code_tbl.extend(1);
7958                                                 l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_TXN_CURR_NOT_PFC_AR';
7959                                                 l_webadi_err_task_id_tbl.extend(1);
7960                                                 l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7961                                                 l_webadi_err_rlm_id_tbl.extend(1);
7962                                                 l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7963                                                 l_webadi_err_txn_curr_tbl.extend(1);
7964                                                 l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7965                                                 l_webadi_err_amt_type_tbl.extend(1);
7966                                                 l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7967                                           END IF;  -- p_calling_context <> WEBADI
7968 
7969                                           l_any_error_occurred_flag:='Y';
7970                                     ELSE
7971                                         l_valid_txn_curr := TRUE;
7972                                     END IF;
7973                               ELSE  -- bug 4462614:
7974                                     -- ci versions, webadi context only.
7975                                     IF(nvl(px_budget_lines_in(i).txn_currency_code,'-99') <>
7976                                                             l_webadi_agr_curr_code) THEN
7977                                         -- txn curr code passed is not agreement currency
7978                                         l_webadi_err_code_tbl.extend(1);
7979                                         l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_TXN_CURR_NOT_AGR_CUR';
7980                                         l_webadi_err_task_id_tbl.extend(1);
7981                                         l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
7982                                         l_webadi_err_rlm_id_tbl.extend(1);
7983                                         l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
7984                                         l_webadi_err_txn_curr_tbl.extend(1);
7985                                         l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
7986                                         l_webadi_err_amt_type_tbl.extend(1);
7987                                         l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
7988 
7989                                         l_any_error_occurred_flag:='Y';
7990                                     ELSE
7991                                         l_valid_txn_curr := TRUE;
7992                                     END IF;
7993                               END IF; -- l_ci_id null
7994 
7995                         -- Version is not approved for revenue. The txn curr must be available in fp txn curr table
7996                         ELSE
7997 
7998                               --Bug 4382980:Issue#19 - Currency Defaulting when txn_currency_code
7999                               --is null done as suggested by Venkatesh Jayeraman
8000                               IF (px_budget_lines_in(i).txn_currency_code IS NULL
8001                               AND p_multi_currency_flag='N')
8002                               THEN
8003 
8004                                     px_budget_lines_in(i).txn_currency_code:=l_project_currency_code;
8005 
8006                               END IF; -- if currency passed is null
8007 
8008                               IF( nvl(px_budget_lines_in(i).txn_currency_code,'-99') <>
8009                                                       l_project_currency_code
8010                                  AND nvl(px_budget_lines_in(i).txn_currency_code,'-99') <>
8011                                                       l_projfunc_currency_code ) THEN
8012 
8013                                   IF(p_multi_currency_flag = 'Y') THEN --Added for bug 4290310.
8014                                         IF l_valid_txn_currencies_tbl.exists(l_valid_txn_currencies_tbl.first) THEN
8015 
8016                                               FOR l_txn_tbl_index in l_valid_txn_currencies_tbl.first..l_valid_txn_currencies_tbl.last LOOP
8017 
8018                                                     IF( nvl(px_budget_lines_in(i).txn_currency_code,'-99')= l_valid_txn_currencies_tbl(l_txn_tbl_index)) THEN
8019 
8020                                                           l_valid_txn_curr := TRUE;
8021 
8022                                                           EXIT;
8023 
8024                                                     END IF;
8025 
8026                                               END LOOP;
8027 
8028                                         END IF;
8029                                   ELSE
8030                                          l_valid_txn_curr := FALSE;
8031                                   END IF;
8032                               ELSE --The Txn curr code is either PC or PFC
8033 
8034                                   l_valid_txn_curr := TRUE;
8035 
8036                               END IF;--IF(l_app_rev_plan_type_flag = 'Y') THEN
8037 
8038                               --The txn currency code passed is not valid
8039                               IF NOT l_valid_txn_curr THEN
8040                                     IF p_calling_context <> 'WEBADI' THEN
8041                                           --Add a message to the stack since the txn curr code is not valid
8042                                           PA_UTILS.ADD_MESSAGE
8043                                             ( p_app_short_name => 'PA',
8044                                               p_msg_name       => 'PA_FP_TXN_NOT_ADDED_FOR_PT',
8045                                               p_token1         => 'PROJECT',
8046                                               p_value1         =>  l_amg_project_rec.segment1,
8047                                               p_token2         => 'PLAN_TYPE',
8048                                               p_value2         =>  l_fin_plan_type_name,
8049                                               p_token3         => 'CURRENCY',
8050                                               p_value3         =>  px_budget_lines_in(i).txn_currency_code);
8051 
8052                                           x_return_status := FND_API.G_RET_STS_ERROR;
8053                                           /*  Bug 3133930- set the return status to the new output variable */
8054                                           x_budget_lines_out(i).return_status := x_return_status;
8055 
8056                                           IF l_debug_mode = 'Y' THEN
8057                                                 pa_debug.g_err_stage:= 'Txn Curreny Code Entered is '|| l_txn_curr_code ;
8058                                                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8059                                           END IF;
8060                                     ELSE
8061                                           -- populate the error code specific to webadi context
8062                                           l_webadi_err_code_tbl.extend(1);
8063                                           l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := 'PA_FP_WA_TXN_CURR_NOT_AVL_PT';
8064                                           l_webadi_err_task_id_tbl.extend(1);
8065                                           l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
8066                                           l_webadi_err_rlm_id_tbl.extend(1);
8067                                           l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
8068                                           l_webadi_err_txn_curr_tbl.extend(1);
8069                                           l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
8070                                           l_webadi_err_amt_type_tbl.extend(1);
8071                                           l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
8072 
8073                                     END IF;  -- WEBADI context
8074 
8075                                     l_any_error_occurred_flag:='Y';
8076                               END IF;
8077 
8078                         END IF;
8079 
8080                         -- deriving the value of a flag to continue the following processing
8081                         l_webadi_cont_proc_flag:='Y';
8082                         IF p_calling_context = 'WEBADI' THEN
8083                              IF (p_delete_flag_tbl.exists(i) AND
8084                                  Nvl(p_delete_flag_tbl(i), 'N') = 'Y')THEN
8085                                      l_webadi_cont_proc_flag := 'N';
8086                              END IF;
8087                         END IF;
8088                         -- validation of curr attributes is done only if the currency passed is a valid currency.
8089                         IF l_valid_txn_curr THEN
8090                               IF l_webadi_cont_proc_flag = 'Y' THEN  -- Bug 3986129: FP.M Web ADI Dev changes
8091                                    l_wa_val_conv_attr_flag := 'Y';
8092                                    --TXN Currency is valid . validate the currency attributes
8093                                    IF   (px_budget_lines_in(i).project_cost_rate_type        IS NULL     AND
8094                                          px_budget_lines_in(i).project_cost_rate_date_type   IS NULL     AND
8095                                          px_budget_lines_in(i).project_cost_rate_date        IS NULL     AND
8096                                          px_budget_lines_in(i).projfunc_cost_rate_type       IS NULL     AND
8097                                          px_budget_lines_in(i).projfunc_cost_rate_date_type  IS NULL     AND
8098                                          px_budget_lines_in(i).projfunc_cost_rate_date       IS NULL     AND
8099                                          px_budget_lines_in(i).project_rev_rate_type         IS NULL     AND
8100                                          px_budget_lines_in(i).project_rev_rate_date_type    IS NULL     AND
8101                                          px_budget_lines_in(i).project_rev_rate_date         IS NULL     AND
8102                                          px_budget_lines_in(i).projfunc_rev_rate_type        IS NULL     AND
8103                                          px_budget_lines_in(i).projfunc_rev_rate_date_type   IS NULL     AND
8104                                          px_budget_lines_in(i).projfunc_rev_rate_date        IS NULL     ) THEN
8105 
8106                                       IF l_debug_mode = 'Y' THEN
8107                                           pa_debug.g_err_stage := 'Deriving the conversion attrs from plan Version option';
8108                                           pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8109                                       END IF;
8110 
8111                                       -- Bug 3986129: FP.M Web ADI Dev changes: included the following check
8112                                       IF p_calling_context <> 'WEBADI' THEN
8113                                           px_budget_lines_in(i).project_cost_rate_type      := p_project_cost_rate_type      ;
8114                                           px_budget_lines_in(i).project_cost_rate_date_type := p_project_cost_rate_date_typ  ;
8115                                           px_budget_lines_in(i).project_cost_rate_date      := p_project_cost_rate_date      ;
8116                                           px_budget_lines_in(i).projfunc_cost_rate_type     := p_projfunc_cost_rate_type     ;
8117                                           px_budget_lines_in(i).projfunc_cost_rate_date_type:= p_projfunc_cost_rate_date_typ ;
8118                                           px_budget_lines_in(i).projfunc_cost_rate_date     := p_projfunc_cost_rate_date     ;
8119                                           px_budget_lines_in(i).project_rev_rate_type       := p_project_rev_rate_type       ;
8120                                           px_budget_lines_in(i).project_rev_rate_date_type  := p_project_rev_rate_date_typ   ;
8121                                           px_budget_lines_in(i).project_rev_rate_date       := p_project_rev_rate_date       ;
8122                                           px_budget_lines_in(i).projfunc_rev_rate_type      := p_projfunc_rev_rate_type      ;
8123                                           px_budget_lines_in(i).projfunc_rev_rate_date_type := p_projfunc_rev_rate_date_typ  ;
8124                                           px_budget_lines_in(i).projfunc_rev_rate_date      := p_projfunc_rev_rate_date      ;
8125                                       END IF;
8126 
8127                                       l_wa_val_conv_attr_flag := 'N';
8128 
8129                                    -- Conversion attributes are passed. Validate them
8130                                    ELSE
8131                                       -- Depending on p_version_type initialise l_conv_attrs_to_be_validated
8132                                       IF (p_version_type <> PA_FP_CONSTANTS_PKG.G_VERSION_TYPE_ALL) THEN
8133                                              l_conv_attrs_to_be_validated := p_version_type;
8134                                       ELSE
8135                                              l_conv_attrs_to_be_validated := PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_BOTH;
8136                                       END IF;
8137 
8138                                       -- Null out the cost attributes for revenue version and vice versa
8139                                       IF l_conv_attrs_to_be_validated = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_COST THEN
8140 
8141                                           px_budget_lines_in(i).project_rev_rate_type       :=NULL;
8142                                           px_budget_lines_in(i).project_rev_rate_date_type  :=NULL;
8143                                           px_budget_lines_in(i).project_rev_rate_date       :=NULL;
8144                                           px_budget_lines_in(i).project_rev_exchange_rate   :=NULL;
8145 
8146                                           px_budget_lines_in(i).projfunc_rev_rate_type      :=NULL;
8147                                           px_budget_lines_in(i).projfunc_rev_rate_date_type :=NULL;
8148                                           px_budget_lines_in(i).projfunc_rev_rate_date      :=NULL;
8149                                           px_budget_lines_in(i).projfunc_rev_exchange_rate  :=NULL;
8150 
8151                                       ELSIF l_conv_attrs_to_be_validated = PA_FP_CONSTANTS_PKG.G_ELEMENT_TYPE_REVENUE THEN
8152 
8153                                           px_budget_lines_in(i).project_cost_rate_type        :=NULL;
8154                                           px_budget_lines_in(i).project_cost_rate_date_type   :=NULL;
8155                                           px_budget_lines_in(i).project_cost_rate_date        :=NULL;
8156                                           px_budget_lines_in(i).project_cost_exchange_rate    :=NULL;
8157 
8158                                           px_budget_lines_in(i).projfunc_cost_rate_type      :=NULL;
8159                                           px_budget_lines_in(i).projfunc_cost_rate_date_type :=NULL;
8160                                           px_budget_lines_in(i).projfunc_cost_rate_date      :=NULL;
8161                                           px_budget_lines_in(i).projfunc_cost_exchange_rate  :=NULL;
8162 
8163                                       END IF;
8164 
8165                                       -- Bug 3986129: FP.M Web ADI Dev changes: included the following check
8166                                          IF p_calling_context = 'WEBADI' AND
8167                                             l_wa_val_conv_attr_flag='Y'  THEN
8168 
8169                                               IF px_budget_lines_in(i).project_cost_rate_type = FND_API.G_MISS_CHAR THEN
8170                                                      l_wa_project_cost_rate_typ := NULL;
8171                                               ELSE
8172                                                      l_wa_project_cost_rate_typ := px_budget_lines_in(i).project_cost_rate_type;
8173                                               END IF;
8174                                               IF px_budget_lines_in(i).project_cost_rate_date_type = FND_API.G_MISS_CHAR THEN
8175                                                      l_wa_project_cost_rate_dt_typ := NULL;
8176                                               ELSE
8177                                                      l_wa_project_cost_rate_dt_typ := px_budget_lines_in(i).project_cost_rate_date_type;
8178                                               END IF;
8179                                               IF px_budget_lines_in(i).project_cost_rate_date = FND_API.G_MISS_DATE THEN
8180                                                      l_wa_project_cost_rate_date := NULL;
8181                                               ELSE
8182                                                      l_wa_project_cost_rate_date := px_budget_lines_in(i).project_cost_rate_date;
8183                                               END IF;
8184                                               IF px_budget_lines_in(i).project_cost_exchange_rate = FND_API.G_MISS_NUM THEN
8185                                                      l_wa_project_cost_exc_rate := NULL;
8186                                               ELSE
8187                                                      l_wa_project_cost_exc_rate := px_budget_lines_in(i).project_cost_exchange_rate;
8188                                               END IF;
8189                                               IF px_budget_lines_in(i).projfunc_cost_rate_type = FND_API.G_MISS_CHAR THEN
8190                                                      l_wa_projfunc_cost_rate_typ := NULL;
8191                                               ELSE
8192                                                      l_wa_projfunc_cost_rate_typ := px_budget_lines_in(i).projfunc_cost_rate_type;
8193                                               END IF;
8194                                               IF px_budget_lines_in(i).projfunc_cost_rate_date_type = FND_API.G_MISS_CHAR THEN
8195                                                      l_wa_projfunc_cost_rate_dt_typ := NULL;
8196                                               ELSE
8197                                                      l_wa_projfunc_cost_rate_dt_typ := px_budget_lines_in(i).projfunc_cost_rate_date_type;
8198                                               END IF;
8199                                               IF px_budget_lines_in(i).projfunc_cost_rate_date = FND_API.G_MISS_DATE THEN
8200                                                      l_wa_projfunc_cost_rate_date := NULL;
8201                                               ELSE
8202                                                      l_wa_projfunc_cost_rate_date := px_budget_lines_in(i).projfunc_cost_rate_date;
8203                                               END IF;
8204                                               IF px_budget_lines_in(i).projfunc_cost_exchange_rate = FND_API.G_MISS_NUM THEN
8205                                                      l_wa_projfunc_cost_exc_rate := NULL;
8206                                               ELSE
8207                                                      l_wa_projfunc_cost_exc_rate := px_budget_lines_in(i).projfunc_cost_exchange_rate;
8208                                               END IF;
8209                                               IF px_budget_lines_in(i).project_rev_rate_type = FND_API.G_MISS_CHAR THEN
8210                                                      l_wa_project_rev_rate_typ := NULL;
8211                                               ELSE
8212                                                      l_wa_project_rev_rate_typ := px_budget_lines_in(i).project_rev_rate_type;
8213                                               END IF;
8214                                               IF px_budget_lines_in(i).project_rev_rate_date_type = FND_API.G_MISS_CHAR THEN
8215                                                      l_wa_project_rev_rate_dt_typ := NULL;
8216                                               ELSE
8217                                                      l_wa_project_rev_rate_dt_typ := px_budget_lines_in(i).project_rev_rate_date_type;
8218                                               END IF;
8219                                               IF px_budget_lines_in(i).project_rev_rate_date = FND_API.G_MISS_DATE THEN
8220                                                      l_wa_project_rev_rate_date := NULL;
8221                                               ELSE
8222                                                      l_wa_project_rev_rate_date := px_budget_lines_in(i).project_rev_rate_date;
8223                                               END IF;
8224                                               IF px_budget_lines_in(i).project_rev_exchange_rate = FND_API.G_MISS_NUM THEN
8225                                                      l_wa_project_rev_exc_rate := NULL;
8226                                               ELSE
8227                                                      l_wa_project_rev_exc_rate := px_budget_lines_in(i).project_rev_exchange_rate;
8228                                               END IF;
8229                                               IF px_budget_lines_in(i).projfunc_rev_rate_type = FND_API.G_MISS_CHAR THEN
8230                                                      l_wa_projfunc_rev_rate_typ := NULL;
8231                                               ELSE
8232                                                      l_wa_projfunc_rev_rate_typ := px_budget_lines_in(i).projfunc_rev_rate_type;
8233                                               END IF;
8234                                               IF px_budget_lines_in(i).projfunc_rev_rate_date_type = FND_API.G_MISS_CHAR THEN
8235                                                      l_wa_projfunc_rev_rate_dt_typ := NULL;
8236                                               ELSE
8237                                                      l_wa_projfunc_rev_rate_dt_typ := px_budget_lines_in(i).projfunc_rev_rate_date_type;
8238                                               END IF;
8239                                               IF px_budget_lines_in(i).projfunc_rev_rate_date = FND_API.G_MISS_DATE THEN
8240                                                      l_wa_projfunc_rev_rate_date := NULL;
8241                                               ELSE
8242                                                      l_wa_projfunc_rev_rate_date := px_budget_lines_in(i).projfunc_rev_rate_date;
8243                                               END IF;
8244                                               IF px_budget_lines_in(i).projfunc_rev_exchange_rate = FND_API.G_MISS_NUM THEN
8245                                                      l_wa_projfunc_rev_exc_rate := NULL;
8246                                               ELSE
8247                                                      l_wa_projfunc_rev_exc_rate := px_budget_lines_in(i).projfunc_rev_exchange_rate;
8248                                               END IF;
8249                                          END IF; -- p_context = WEBADI
8250 
8251                                       --Validate the conversion attributes passed
8252                                       IF p_calling_context = 'WEBADI' AND
8253                                          l_wa_val_conv_attr_flag='Y' THEN
8254                                             pa_fin_plan_utils.validate_currency_attributes
8255                                             ( px_project_cost_rate_type      => l_wa_project_cost_rate_typ
8256                                              ,px_project_cost_rate_date_typ  => l_wa_project_cost_rate_dt_typ
8257                                              ,px_project_cost_rate_date      => l_wa_project_cost_rate_date
8258                                              ,px_project_cost_exchange_rate  => l_wa_project_cost_exc_rate
8259                                              ,px_projfunc_cost_rate_type     => l_wa_projfunc_cost_rate_typ
8260                                              ,px_projfunc_cost_rate_date_typ => l_wa_projfunc_cost_rate_dt_typ
8261                                              ,px_projfunc_cost_rate_date     => l_wa_projfunc_cost_rate_date
8262                                              ,px_projfunc_cost_exchange_rate => l_wa_projfunc_cost_exc_rate
8263                                              ,px_project_rev_rate_type       => l_wa_project_rev_rate_typ
8264                                              ,px_project_rev_rate_date_typ   => l_wa_project_rev_rate_dt_typ
8265                                              ,px_project_rev_rate_date       => l_wa_project_rev_rate_date
8266                                              ,px_project_rev_exchange_rate   => l_wa_project_rev_exc_rate
8267                                              ,px_projfunc_rev_rate_type      => l_wa_projfunc_rev_rate_typ
8268                                              ,px_projfunc_rev_rate_date_typ  => l_wa_projfunc_rev_rate_dt_typ
8269                                              ,px_projfunc_rev_rate_date      => l_wa_projfunc_rev_rate_date
8270                                              ,px_projfunc_rev_exchange_rate  => l_wa_projfunc_rev_exc_rate
8271                                              ,p_project_currency_code        => l_project_currency_code
8272                                              ,p_projfunc_currency_code       => l_projfunc_currency_code
8273                                              ,p_context                      => PA_FP_CONSTANTS_PKG.G_WEBADI
8274                                              ,p_attrs_to_be_validated        => l_conv_attrs_to_be_validated
8275                                              ,x_return_status                => x_return_status
8276                                              ,x_msg_count                    => x_msg_count
8277                                              ,x_msg_data                     => x_msg_data);
8278                                       ELSE
8279                                             pa_fin_plan_utils.validate_currency_attributes
8280                                             ( px_project_cost_rate_type      =>px_budget_lines_in(i).project_cost_rate_type
8281                                              ,px_project_cost_rate_date_typ  =>px_budget_lines_in(i).project_cost_rate_date_type
8282                                              ,px_project_cost_rate_date      =>px_budget_lines_in(i).project_cost_rate_date
8283                                              ,px_project_cost_exchange_rate  =>px_budget_lines_in(i).project_cost_exchange_rate
8284                                              ,px_projfunc_cost_rate_type     =>px_budget_lines_in(i).projfunc_cost_rate_type
8285                                              ,px_projfunc_cost_rate_date_typ =>px_budget_lines_in(i).projfunc_cost_rate_date_type
8286                                              ,px_projfunc_cost_rate_date     =>px_budget_lines_in(i).projfunc_cost_rate_date
8287                                              ,px_projfunc_cost_exchange_rate =>px_budget_lines_in(i).projfunc_cost_exchange_rate
8288                                              ,px_project_rev_rate_type       =>px_budget_lines_in(i).project_rev_rate_type
8289                                              ,px_project_rev_rate_date_typ   =>px_budget_lines_in(i).project_rev_rate_date_type
8290                                              ,px_project_rev_rate_date       =>px_budget_lines_in(i).project_rev_rate_date
8291                                              ,px_project_rev_exchange_rate   =>px_budget_lines_in(i).project_rev_exchange_rate
8292                                              ,px_projfunc_rev_rate_type      =>px_budget_lines_in(i).projfunc_rev_rate_type
8293                                              ,px_projfunc_rev_rate_date_typ  =>px_budget_lines_in(i).projfunc_rev_rate_date_type
8294                                              ,px_projfunc_rev_rate_date      =>px_budget_lines_in(i).projfunc_rev_rate_date
8295                                              ,px_projfunc_rev_exchange_rate  =>px_budget_lines_in(i).projfunc_rev_exchange_rate
8296                                              ,p_project_currency_code        =>l_project_currency_code
8297                                              ,p_projfunc_currency_code       =>l_projfunc_currency_code
8298                                              ,p_context                      =>PA_FP_CONSTANTS_PKG.G_AMG_API_DETAIL
8299                                              ,p_attrs_to_be_validated        =>l_conv_attrs_to_be_validated
8300                                              ,x_return_status                =>x_return_status
8301                                              ,x_msg_count                    =>x_msg_count
8302                                              ,x_msg_data                     =>x_msg_data);
8303                                       END IF;
8304                                           IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8305                                              IF p_calling_context <> 'WEBADI' THEN
8306                                                    /*  Bug 3133930- set the return status to the new output variable */
8307                                                    x_budget_lines_out(i).return_status := x_return_status;
8308 
8309                                              ELSIF l_wa_val_conv_attr_flag='Y' THEN
8310                                                    l_webadi_err_code_tbl.extend(1);
8311                                                    l_webadi_err_code_tbl(l_webadi_err_code_tbl.COUNT) := l_wa_error_code_lookup(PA_FIN_PLAN_UTILS.g_first_error_code);
8312                                                    l_webadi_err_task_id_tbl.extend(1);
8313                                                    l_webadi_err_task_id_tbl(l_webadi_err_task_id_tbl.COUNT) := px_budget_lines_in(i).pa_task_id;
8314                                                    l_webadi_err_rlm_id_tbl.extend(1);
8315                                                    l_webadi_err_rlm_id_tbl(l_webadi_err_rlm_id_tbl.COUNT) := px_budget_lines_in(i).resource_list_member_id;
8316                                                    l_webadi_err_txn_curr_tbl.extend(1);
8317                                                    l_webadi_err_txn_curr_tbl(l_webadi_err_txn_curr_tbl.COUNT) := px_budget_lines_in(i).txn_currency_code;
8318                                                    l_webadi_err_amt_type_tbl.extend(1);
8319                                                    l_webadi_err_amt_type_tbl(l_webadi_err_amt_type_tbl.COUNT) := p_amount_type_tbl(i);
8320                                              END IF;
8321 
8322                                              l_any_error_occurred_flag:='Y';
8323                                           ELSIF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8324                                              IF p_calling_context = 'WEBADI' THEN --Bug 4382980
8325                                                  -- copying back the validated attribute in the rac type
8326                                                  px_budget_lines_in(i).project_cost_rate_type := l_wa_project_cost_rate_typ;
8327                                                  px_budget_lines_in(i).project_cost_rate_date_type := l_wa_project_cost_rate_dt_typ;
8328                                                  px_budget_lines_in(i).project_cost_rate_date := l_wa_project_cost_rate_date;
8329                                                  px_budget_lines_in(i).project_cost_exchange_rate := l_wa_project_cost_exc_rate;
8330                                                  px_budget_lines_in(i).projfunc_cost_rate_type := l_wa_projfunc_cost_rate_typ;
8331                                                  px_budget_lines_in(i).projfunc_cost_rate_date_type := l_wa_projfunc_cost_rate_dt_typ;
8332                                                  px_budget_lines_in(i).projfunc_cost_rate_date := l_wa_projfunc_cost_rate_date;
8333                                                  px_budget_lines_in(i).projfunc_cost_exchange_rate := l_wa_projfunc_cost_exc_rate;
8334                                                  px_budget_lines_in(i).project_rev_rate_type := l_wa_project_rev_rate_typ;
8335                                                  px_budget_lines_in(i).project_rev_rate_date_type := l_wa_project_rev_rate_dt_typ;
8336                                                  px_budget_lines_in(i).project_rev_rate_date := l_wa_project_rev_rate_date;
8337                                                  px_budget_lines_in(i).project_rev_exchange_rate := l_wa_project_rev_exc_rate;
8338                                                  px_budget_lines_in(i).projfunc_rev_rate_type := l_wa_projfunc_rev_rate_typ;
8339                                                  px_budget_lines_in(i).projfunc_rev_rate_date_type := l_wa_projfunc_rev_rate_dt_typ;
8340                                                  px_budget_lines_in(i).projfunc_rev_rate_date := l_wa_projfunc_rev_rate_date;
8341                                                  px_budget_lines_in(i).projfunc_rev_exchange_rate := l_wa_projfunc_rev_exc_rate;
8342                                              END IF;
8343                                           END IF; -- return_status
8344                                    END IF;--IF all parameters are null
8345                               END IF; -- cont_proc_flag
8346                         END IF; -- IF l_valid_txn_curr THEN
8347 
8348                         /* Bug 4224464: FP M Changes Start */
8349                         --Check if Actuals have been entered for the FORECAST Line. We perform this
8350                         --check only when p_version_info_rec.x_budget_version_id has been passed.
8351                         IF p_calling_context <> 'WEBADI' THEN
8352                               IF (p_version_info_rec.x_budget_version_id IS NOT NULL)
8353                               THEN
8354                                     OPEN budget_version_info_cur(p_version_info_rec.x_budget_version_id);
8355                                     FETCH budget_version_info_cur
8356                                     INTO  l_plan_class_code
8357                                          ,l_etc_start_date;
8358 
8359                                     IF budget_version_info_cur%NOTFOUND
8360                                     THEN
8361                                          l_any_error_occurred_flag := 'Y';
8362                                          IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
8363                                          THEN
8364                                                PA_UTILS.add_message
8365                                                (p_app_short_name => 'PA'
8366                                                ,p_msg_name       => 'PA_FP_NO_WORKING_VERSION'
8367                                                ,p_token1         => 'PROJECT'
8368                                                ,p_value1         => l_amg_project_rec.segment1
8369                                                ,p_token2         => 'PLAN_TYPE'
8370                                                ,p_value2         => l_fin_plan_type_name
8371                                                ,p_token3         => 'VERSION_NUMBER'
8372                                                ,p_value3         => '' );
8373                                          END IF;
8374 
8375                                          IF l_debug_mode = 'Y' THEN
8376                                                pa_debug.g_err_stage := 'Passed Budget Version Id is invalid';
8377                                                pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8378                                          END IF;
8379 
8380                                     END IF; --budget_version_info_cur%NOTFOUND
8381 
8382                                     CLOSE budget_version_info_cur;
8383 
8384                                     IF (l_plan_class_code IS NOT NULL AND
8385                                         l_plan_class_code = 'FORECAST' AND
8386                                         l_etc_start_date IS NOT NULL AND
8387                                         l_etc_start_date > px_budget_lines_in(i).budget_start_date AND
8388                                         p_time_phased_code IS NOT NULL AND
8389                                         p_time_phased_code <> 'N')
8390                                     THEN
8391                                           l_any_error_occurred_flag := 'Y';
8392                                           IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR)
8393                                           THEN
8394                                                 PA_UTILS.add_message
8395                                                 (p_app_short_name => 'PA'
8396                                                 ,p_msg_name       => 'PA_FP_FCST_ACTUALS_AMG'
8397                                                 ,p_token1         => 'PROJECT'
8398                                                 ,p_value1         => l_amg_project_rec.segment1
8399                                                 ,p_token2         => 'PLAN_TYPE'
8400                                                 ,p_value2         => l_fin_plan_type_name
8401                                                 ,p_token3         => 'TASK'
8402                                                 ,p_value3         => l_amg_task_number
8403                                                 ,p_token4         => 'CURRENCY'
8404                                                 ,p_value4         => px_budget_lines_in(i).txn_currency_code
8405                                                 ,p_token5         => 'START_DATE'
8406                                                 ,p_value5         => to_char(px_budget_lines_in(i).budget_start_date) );
8407                                           END IF;
8408 
8409                                           IF l_debug_mode = 'Y' THEN
8410                                                 pa_debug.g_err_stage := 'Forecast Line has actuals and hence cannot be edited';
8411                                                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8412                                           END IF;
8413 
8414                                     END IF;--end of actuals-on-FORECAST check
8415 
8416                               END IF; --budget_version_id IS NOT NULL
8417                         END IF; -- p_calling_context
8418                         /* Bug 4224464: FP M Changes End */
8419 
8420                   END IF; -- IF p_fin_plan_type_id IS NOT NULL THEN
8421 
8422             END LOOP; -- ;For Loop
8423 
8424       END IF;--Check for the existence of budget lines
8425 
8426       -- Bug 3986129: FP.M Web ADI Dev changes
8427       IF p_calling_context = 'WEBADI' THEN
8428             IF l_webadi_err_code_tbl.COUNT > 0 THEN
8429                   -- call an api to populate the error code in the excel sheet
8430                   pa_fp_webadi_pkg.process_errors
8431                         ( p_run_id          => p_run_id,
8432                           p_error_code_tbl  => l_webadi_err_code_tbl,
8433                           p_task_id_tbl     => l_webadi_err_task_id_tbl,
8434                           p_rlm_id_tbl      => l_webadi_err_rlm_id_tbl,
8435                           p_txn_curr_tbl    => l_webadi_err_txn_curr_tbl,
8436                           p_amount_type_tbl => l_webadi_err_amt_type_tbl,
8437                           x_return_status   => x_return_status,
8438                           x_msg_data        => x_msg_data,
8439                           x_msg_count       => x_msg_count);
8440 
8441                        IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8442                              IF l_debug_mode = 'Y' THEN
8443                                 pa_debug.g_err_stage := 'Call to process_errors returned with error';
8444                                 pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8445                              END IF;
8446 
8447                              RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8448                        END IF;
8449             END IF;  -- error tbl count > 0
8450       END IF; -- Bug 3986129
8451 
8452       --Raise an error if any errors are reported till this poing
8453       IF l_any_error_occurred_flag = 'Y' THEN
8454             IF p_calling_context <> 'WEBADI' THEN
8455                   IF l_debug_mode = 'Y' THEN
8456                         pa_debug.g_err_stage := 'Reporting the errors occured while validating budget lines';
8457                         pa_debug.write(l_module_name,pa_debug.g_err_stage,l_debug_level3);
8458                   END IF;
8459 
8460                   RAISE PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc;
8461             END IF; -- non webadi context
8462       END IF;
8463 
8464       -- Null out the global variables.
8465       pa_budget_pvt.g_Task_number    := NULL;
8466       pa_budget_pvt.g_start_date     := NULL;
8467       pa_budget_pvt.g_resource_alias := NULL;
8468 
8469 
8470       IF l_debug_mode = 'Y' THEN
8471           pa_debug.g_err_stage:= 'Exiting Validate Budget Lines';
8472           pa_debug.write(g_module_name,pa_debug.g_err_stage,
8473                                    l_debug_level3);
8474           pa_debug.reset_curr_function;
8475       END IF;
8476 EXCEPTION
8477       WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
8478 
8479             IF  x_return_status IS NULL OR
8480                 x_return_status = FND_API.G_RET_STS_SUCCESS THEN
8481                 x_return_status := FND_API.G_RET_STS_ERROR;
8482 
8483             END IF;
8484 
8485             l_msg_count := FND_MSG_PUB.count_msg;
8486 
8487             IF l_msg_count = 1 and x_msg_data IS NULL THEN
8488                 PA_INTERFACE_UTILS_PUB.get_messages
8489                     (p_encoded        => FND_API.G_TRUE
8490                     ,p_msg_index      => 1
8491                     ,p_msg_count      => l_msg_count
8492                     ,p_msg_data       => l_msg_data
8493                     ,p_data           => l_data
8494                     ,p_msg_index_out  => l_msg_index_out);
8495                 x_msg_data := l_data;
8496                 x_msg_count := l_msg_count;
8497             ELSE
8498                 x_msg_count := l_msg_count;
8499             END IF;
8500 	  IF l_debug_mode = 'Y' THEN
8501               pa_debug.reset_curr_function;
8502 	  END IF;
8503             RETURN;
8504 
8505       WHEN OTHERS THEN
8506 
8507             x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8508 
8509             IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
8510 
8511             THEN
8512                   FND_MSG_PUB.add_exc_msg
8513                   (  p_pkg_name           => G_PKG_NAME
8514                   ,  p_procedure_name     => 'Validate_Budget_Lines' );
8515 
8516             END IF;
8517 	  IF l_debug_mode = 'Y' THEN
8518             pa_debug.reset_curr_function;
8519 	  END IF;
8520 END validate_budget_lines;
8521 
8522 
8523 
8524 PROCEDURE GET_FIN_PLAN_LINES_STATUS
8525           (p_calling_context                 IN                VARCHAR2 DEFAULT NULL
8526           ,p_fin_plan_version_id               IN             pa_budget_versions.budget_version_id%TYPE
8527           ,p_budget_lines_in                 IN             PA_BUDGET_PUB.budget_line_in_tbl_type
8528           ,x_fp_lines_retn_status_tab     OUT NOCOPY     PA_BUDGET_PUB.budget_line_out_tbl_type
8529           ,x_return_status                      OUT NOCOPY     VARCHAR2
8530           ,x_msg_count                          OUT NOCOPY     NUMBER
8531           ,x_msg_data                           OUT NOCOPY     VARCHAR2)
8532 
8533 IS
8534 
8535 l_cost_rejection_data_tab           PA_PLSQL_DATATYPES.Char2000TabTyp;
8536 l_burden_rejection_data_tab         PA_PLSQL_DATATYPES.Char2000TabTyp;
8537 l_revenue_rejection_data_tab       PA_PLSQL_DATATYPES.Char2000TabTyp;
8538 l_pc_conv_rejection_data_tab       PA_PLSQL_DATATYPES.Char2000TabTyp;
8539 l_pfc_conv_rejection_data_tab      PA_PLSQL_DATATYPES.Char2000TabTyp;
8540 l_other_rejection_data_tab          PA_PLSQL_DATATYPES.Char2000TabTyp;
8541 l_return_status                    VARCHAR2(1);
8542 l_fin_plan_line_id_tab             PA_PLSQL_DATATYPES.IDTABTYP;
8543 l_fp_lines_retn_status_tab          PA_BUDGET_PUB.budget_line_out_tbl_type;
8544 l_debug_mode                        VARCHAR2(1);
8545 l_module_name                       VARCHAR2(80);
8546 l_tmp_return_status                VARCHAR2(1);
8547 I                                  NUMBER;
8548 l_count                            NUMBER;
8549 l_time_phased_code                pa_proj_fp_options.all_time_phased_code%TYPE;      -- Added for BUG 6847497
8550 l_uncategorized_flag              pa_resource_lists_all_bg.uncategorized_flag%TYPE;  -- Added for BUG 6847497
8551 
8552 CURSOR get_primary_key_csr IS
8553 SELECT ra.task_id,
8554      ra.resource_list_member_id,
8555      bl.txn_currency_code,
8556      bl.start_date,
8557      DECODE(bl.cost_rejection_code,NULL,
8558           DECODE(bl.revenue_rejection_code,NULL,
8559                DECODE(bl.burden_rejection_code,NULL,
8560                     DECODE(bl.other_rejection_code,NULL,
8561                          DECODE(bl.pfc_cur_conv_rejection_code,NULL,
8562                               DECODE(bl.pc_cur_conv_rejection_code,NULL,NULL,'E')
8563                                    ,'E'),'E'),'E'),'E'),'E') return_status
8564 FROM pa_resource_assignments ra , pa_budget_lines bl
8565 where ra.budget_version_id = p_fin_plan_version_id
8566 and ra.resource_assignment_id = bl.resource_assignment_id;
8567 
8568 BEGIN
8569 
8570 x_msg_count := 0;
8571 x_return_status := FND_API.G_RET_STS_SUCCESS;
8572 l_debug_mode  := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
8573 l_module_name :=  'PA_BUDGET_PVT.GET_FIN_PLAN_LINES_STATUS ';
8574 
8575           IF l_debug_mode = 'Y' THEN
8576               pa_debug.set_curr_function( p_function   => l_module_name,
8577                                           p_debug_mode => l_debug_mode );
8578           END IF;
8579 
8580 
8581 PA_FIN_PLAN_UTILS2.Get_AMG_BdgtLineRejctions
8582                 (p_budget_version_id              =>   p_fin_plan_version_id
8583                 ,x_budget_line_id_tab             =>   l_fin_plan_line_id_tab
8584                 ,x_cost_rejection_data_tab        =>   l_cost_rejection_data_tab
8585                 ,x_burden_rejection_data_tab      =>   l_burden_rejection_data_tab
8586                 ,x_revenue_rejection_data_tab     =>   l_revenue_rejection_data_tab
8587                 ,x_pc_conv_rejection_data_tab     =>   l_pc_conv_rejection_data_tab
8588                 ,x_pfc_conv_rejection_data_tab    =>   l_pfc_conv_rejection_data_tab
8589                 ,x_other_rejection_data_tab       =>   l_other_rejection_data_tab
8590                 ,x_return_status                  =>   l_return_status ) ;
8591 
8592 IF l_return_status ='U' THEN
8593 
8594      IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
8595 
8596              FND_MSG_PUB.add_exc_msg
8597                  (  p_pkg_name       => 'PA_BUDGET_PVT'
8598                    ,p_procedure_name => 'GET_FIN_PLAN_LINES_STATUS' );
8599 
8600      END IF;
8601 
8602       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8603 
8604 END IF;
8605 
8606 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
8607 
8608      IF nvl(l_fin_plan_line_id_tab.LAST,0) > 0 THEN                 /* Bug # 3588604 */
8609 
8610                FOR I in l_fin_plan_line_id_tab.FIRST .. l_fin_plan_line_id_tab.LAST LOOP
8611 
8612                          IF L_cost_rejection_data_tab(I) IS NOT NULL THEN
8613 
8614                                 pa_utils.Add_Message( p_app_short_name  => 'PA'
8615                                                      ,p_msg_name     =>l_cost_rejection_data_tab(i));
8616 
8617                          END IF;
8618 
8619                          IF l_burden_rejection_data_tab(I) IS NOT NULL THEN
8620 
8621                                 pa_utils.Add_Message( p_app_short_name  => 'PA'
8622                                                      ,p_msg_name     =>l_burden_rejection_data_tab(i));
8623 
8624                          END IF;
8625                          IF l_revenue_rejection_data_tab(I) IS NOT NULL THEN
8626 
8627                                 pa_utils.Add_Message( p_app_short_name  => 'PA'
8628                                                      ,p_msg_name     =>l_revenue_rejection_data_tab(i));
8629 
8630                          END IF;
8631                          IF l_pc_conv_rejection_data_tab(I) IS NOT NULL THEN
8632 
8633                                 pa_utils.Add_Message( p_app_short_name  => 'PA'
8634                                                      ,p_msg_name     =>l_pc_conv_rejection_data_tab(i));
8635 
8636                          END IF;
8637                          IF l_pfc_conv_rejection_data_tab(I) IS NOT NULL THEN
8638 
8639                                 pa_utils.Add_Message( p_app_short_name  => 'PA'
8640                                                      ,p_msg_name     =>l_pfc_conv_rejection_data_tab(i));
8641 
8642                          END IF;
8643 
8644                          IF l_other_rejection_data_tab(I) IS NOT NULL THEN
8645                                 pa_utils.Add_Message( p_app_short_name  => 'PA'
8646                                                      ,p_msg_name     => l_other_rejection_data_tab(i));
8647 
8648                          END IF;
8649 
8650                END LOOP;
8651 
8652      END IF;   --IF nvl(l_fin_plan_line_id_tab.LAST,0) > 0
8653 
8654 END IF;
8655 
8656   BEGIN /* Added for bug 7611462 */
8657 
8658 	 SELECT nvl(cost_time_phased_code,NVL(revenue_time_phased_code,all_time_phased_code)),     -- Added for BUG 6847497
8659  	        prl.uncategorized_flag
8660  	 INTO   l_time_phased_code, l_uncategorized_flag
8661  	 FROM   pa_proj_fp_options , pa_resource_lists_all_bg prl
8662  	 WHERE  fin_plan_version_id=p_fin_plan_version_id
8663  	 AND    nvl(cost_resource_list_id,nvl(revenue_resource_list_id,all_resource_list_id))=
8664  	        prl.resource_list_id;
8665 
8666 	/* Added below logic for bug 7611462 */
8667    EXCEPTION
8668      WHEN NO_DATA_FOUND THEN
8669 	    l_time_phased_code := NULL;
8670 		l_uncategorized_flag := NULL;
8671    END;/* Ends added for bug 7611462 */
8672 
8673 /*===========================================================================+
8674  | The amg api pa_budgets_pub.CREATE_DRAFT_FINPLAN need to know if           |
8675  | any of budget lines in the budget version had any rejections.             |
8676  | And that's all it need to know. x_return_status is being reused for this. |
8677  +===========================================================================*/
8678 IF ( p_calling_context = 'CREATE_DRAFT_FINPLAN')
8679 THEN
8680           IF ( NVL(l_fin_plan_line_id_tab.LAST,0) > 0 )
8681           THEN
8682                        x_return_status := 'R';
8683           END IF;
8684 
8685 END IF; --p_calling_context <> 'CREATE_DRAFT_FINPLAN'
8686 
8687 /*=========================================================================+
8688  | pa_budgets_pub.CREATE_DRAFT_FINPLAN is AMG api. When this api is called |
8689  | from CREATE_DRAFT_FINPLAN, p_budget_lines_in is not passed in.          |
8690  | Rejections at the budget line level need not be returned back. Hence    |
8691  | the following code not executed for when it is calling from the AMG api.|
8692  +=========================================================================*/
8693 IF ( NVL(p_calling_context,'-99') <> 'CREATE_DRAFT_FINPLAN')
8694 THEN
8695 FOR l_primary_key_tab IN get_primary_key_csr LOOP
8696 
8697           l_count := 0;
8698 
8699           IF nvl(p_budget_lines_in.LAST,0) > 0 THEN                      /* Bug # 3588604 */
8700 
8701                FOR k in p_budget_lines_in.FIRST .. p_budget_lines_in.LAST LOOP
8702                /* Added null handing for l_time_phased_code for bug 7611462 */
8703                      IF ( p_budget_lines_in(k).pa_task_id = l_primary_key_tab.task_id) AND    -- Modified for BUG 6847497
8704                        (((NVL(l_uncategorized_flag,'N')<>'Y') AND (p_budget_lines_in(k).resource_list_member_id = l_primary_key_tab.resource_list_member_id)) OR l_uncategorized_flag = 'Y') AND
8705                        (((nvl(l_time_phased_code, 'Y') <> 'N') AND (nvl(p_budget_lines_in(k).budget_start_date, l_primary_key_tab.start_date) = l_primary_key_tab.start_date)) OR l_time_phased_code = 'N') AND
8706                        (nvl(p_budget_lines_in(k).txn_currency_code,l_primary_key_tab.txn_currency_code) = l_primary_key_tab.txn_currency_code) THEN
8707 
8708                     l_count := 1;
8709                     l_fp_lines_retn_status_tab(k).return_status := l_primary_key_tab.return_status;
8710 
8711                     END IF;
8712 
8713                EXIT WHEN (l_count = 1);
8714 
8715                END LOOP;
8716 
8717           END IF ;                  --IF nvl(p_budget_lines_in.LAST,0) > 0
8718 
8719 
8720 IF (l_count = 0) THEN
8721     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8722 END IF;
8723 
8724 END LOOP;
8725 
8726 x_fp_lines_retn_status_tab := l_fp_lines_retn_status_tab ;
8727 END IF; -- p_calling_context <> 'CREATE_DRAFT_FINPLAN'
8728 
8729 EXCEPTION
8730 
8731 WHEN PA_FP_CONSTANTS_PKG.Invalid_Arg_Exc THEN
8732 
8733            x_return_status := FND_API.G_RET_STS_ERROR;
8734   	IF l_debug_mode = 'Y' THEN
8735                 pa_debug.g_err_stage:= 'Invalid Arguments Passed';
8736                 pa_debug.write('GET_FIN_PLAN_LINES_STATUS: ' || g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8737                 pa_debug.reset_err_stack;
8738 	END IF;
8739            RETURN;
8740 
8741 WHEN OTHERS THEN
8742 
8743           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8744           x_msg_count     := 1;
8745           x_msg_data      := SQLERRM;
8746 
8747           FND_MSG_PUB.add_exc_msg( p_pkg_name        => 'pa_budget_pvt'
8748                                   ,p_procedure_name  => 'GET_FIN_PLAN_LINES_STATUS');
8749 
8750 	     IF l_debug_mode = 'Y' THEN
8751                pa_debug.g_err_stage:= 'Unexpected Error'||SQLERRM;
8752                pa_debug.write('GET_FIN_PLAN_LINES_STATUS: ' || g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8753                pa_debug.reset_err_stack;
8754 	     END IF;
8755           FND_MSG_PUB.Count_And_Get (p_count     =>  x_msg_count
8756                                     ,p_data      =>  x_msg_data  );
8757           RAISE;
8758 
8759 
8760 END GET_FIN_PLAN_LINES_STATUS;
8761 
8762 
8763 -- Function             : Is_bc_enabled_for_budget
8764 -- Purpose              : This functions returns true if a record exists in
8765 --                        PA_BC_BALANCES table for the given budget version id
8766 -- Parameters           : Budget Version Id.
8767 --
8768 
8769 FUNCTION Is_bc_enabled_for_budget
8770 ( p_budget_version_id   IN    NUMBER )
8771 RETURN BOOLEAN
8772 IS
8773 
8774       CURSOR bc_enabled_for_budg_ver_csr
8775       IS
8776       SELECT 'Y'
8777       FROM pa_bc_balances
8778       WHERE budget_version_id = p_budget_version_id;
8779 
8780 l_return_value    VARCHAR2(2) := 'N';
8781 
8782 BEGIN
8783 
8784       OPEN bc_enabled_for_budg_ver_csr;
8785       FETCH bc_enabled_for_budg_ver_csr into l_return_value;
8786       CLOSE bc_enabled_for_budg_ver_csr;
8787 
8788       IF ( l_return_value = 'Y' ) THEN
8789             RETURN true;
8790       ELSE
8791             RETURN false;
8792       END IF;
8793 
8794 END Is_bc_enabled_for_budget;
8795 
8796 
8797 
8798 
8799 --Name:               Get_Latest_BC_Year
8800 --Type:               Procedure
8801 --Description:        For budgetary control projects, this procedure fetches the
8802 --                    latest encumbrance year for the project's set-of-books.
8803 --
8804 --
8805 --
8806 --History:
8807 --   27-SEP-2005    jwhite    Created per bug 4588279
8808 
8809 
8810   PROCEDURE Get_Latest_BC_Year
8811           ( p_pa_project_id                IN      pa_projects_all.project_id%TYPE
8812             ,x_latest_encumbrance_year     OUT     NOCOPY gl_ledgers.Latest_Encumbrance_Year%TYPE
8813             ,x_return_status               OUT     NOCOPY VARCHAR2
8814             ,x_msg_count                   OUT     NOCOPY NUMBER
8815             ,x_msg_data                    OUT     NOCOPY VARCHAR2
8816               )
8817 
8818   IS
8819 
8820          l_debug_mode                      VARCHAR2(1)  := NULL;
8821          l_module_name                     VARCHAR2(80) :=NULL;
8822 
8823   BEGIN
8824 
8825          x_msg_count := 0;
8826          x_return_status := FND_API.G_RET_STS_SUCCESS;
8827 
8828          l_debug_mode  := NVL(FND_PROFILE.value('PA_DEBUG_MODE'),'N');
8829          l_module_name :=  'PA_BUDGET_PVT.GET_FIN_PLAN_LINES_STATUS ';
8830 
8831          IF l_debug_mode = 'Y' THEN
8832             pa_debug.set_curr_function( p_function   => l_module_name,
8833                                           p_debug_mode => l_debug_mode );
8834          END IF;
8835 
8836 
8837 
8838          SELECT l.Latest_Encumbrance_Year
8839          INTO   x_latest_encumbrance_year
8840          FROM   GL_ledgers l
8841                 , pa_implementations_all i
8842                 , pa_projects_all p
8843          WHERE  l.LEDGER_ID = i.set_of_books_id
8844          AND        i.org_id = p.org_id
8845          AND        p.project_id  = p_pa_project_id;
8846 
8847 
8848 
8849   EXCEPTION
8850 
8851   WHEN OTHERS THEN
8852 
8853           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
8854           x_msg_count     := 1;
8855           x_msg_data      := SQLERRM;
8856 
8857           FND_MSG_PUB.add_exc_msg( p_pkg_name        => 'pa_budget_pvt'
8858                                   ,p_procedure_name  => 'GET_LATEST_BC_YEAR');
8859 	  IF l_debug_mode = 'Y' THEN
8860              pa_debug.g_err_stage:= 'Unexpected Error'||SQLERRM;
8861              pa_debug.write('GET_LATEST_BC_YEAR: ' || g_module_name,pa_debug.g_err_stage,PA_FP_CONSTANTS_PKG.G_DEBUG_LEVEL5);
8862              pa_debug.reset_err_stack;
8863 	  END IF;
8864           FND_MSG_PUB.Count_And_Get (p_count     =>  x_msg_count
8865                                     ,p_data      =>  x_msg_data  );
8866           RAISE;
8867 
8868 
8869   END Get_Latest_BC_Year;
8870 
8871 
8872 
8873 
8874 
8875 
8876 end PA_BUDGET_PVT;