DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_RES_MANAGEMENT_AMG_PUB

Source


1 PACKAGE BODY PA_RES_MANAGEMENT_AMG_PUB AS
2 /* $Header: PAPMRSPB.pls 120.3.12010000.3 2008/12/11 22:20:49 snizam ship $ */
3 
4 G_PA_MISS_NUM   CONSTANT   NUMBER := PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM;
5 G_PA_MISS_DATE  CONSTANT   DATE   := PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE;
6 G_PA_MISS_CHAR  CONSTANT   VARCHAR2(3) := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR;
7 
8 /*---Bug 6511907 PJR Date Validation Enhancement ----- Start---*/
9 
10 FUNCTION GET_PROJECT_START_DATE(l_prj_id NUMBER)
11 RETURN DATE
12 IS
13 
14 l_start_dt DATE;
15 
16 BEGIN
17 
18 SELECT start_date
19 INTO l_start_dt
20 FROM pa_projects_all
21 WHERE project_id = l_prj_id;
22 
23 RETURN l_start_dt;
24 
25 EXCEPTION
26  WHEN NO_DATA_FOUND THEN
27         RETURN NULL;
28  WHEN OTHERS THEN
29         RETURN NULL;
30 END;
31 
32 FUNCTION GET_PROJECT_COMPLETION_DATE(l_prj_id NUMBER)
33 RETURN DATE
34 IS
35 
36 l_compl_dt DATE;
37 
38 BEGIN
39 
40 SELECT completion_date
41 INTO l_compl_dt
42 FROM pa_projects_all
43 WHERE project_id = l_prj_id;
44 
45 RETURN l_compl_dt;
46 
47 EXCEPTION
48  WHEN NO_DATA_FOUND THEN
49         RETURN NULL;
50  WHEN OTHERS THEN
51         RETURN NULL;
52 END;
53 
54 /*---Bug 6511907 PJR Date Validation Enhancement ----- End---*/
55 
56 FUNCTION IS_VALID_APPROVER(l_approver_id NUMBER,l_resource_id NUMBER,l_start_date DATE)
57 RETURN VARCHAR2
58 IS
59 
60 l_dummy VARCHAR2(1) := 'N';
61 
62 BEGIN
63 
64 BEGIN
65 SELECT 'Y' into l_dummy
66   FROM dual
67  WHERE l_approver_id in
68 (SELECT pa_resource_utils.get_hr_manager_id(res_denorm.resource_id,l_start_date) approver_id
69  from pa_resources_denorm res_denorm
70  WHERE  l_start_date between resource_effective_start_date
71         and resource_effective_end_date
72   START WITH resource_id = l_resource_id
73   CONNECT BY
74           prior pa_resource_utils.get_hr_manager_id(res_denorm.resource_id,l_start_date)= person_id
75           and pa_resource_utils.get_hr_manager_id(res_denorm.resource_id,l_start_date) <> prior person_id
76          and l_start_date between prior resource_effective_start_date and prior resource_effective_end_date
77           and  l_start_date between resource_effective_start_date and resource_effective_end_date
78   UNION
79   SELECT per.person_id  approver_id
80    from pa_resources_denorm res_denorm,
81         fnd_grants       fg,
82         fnd_objects      fob,
83         per_all_people_f per,
84         wf_roles wfr,
85         (select pa_security_pvt.get_menu_id('PA_PRM_RES_PRMRY_CONTACT') menu_id
86         from dual) prmry_contact_menu
87    where   fob.obj_name              = 'ORGANIZATION'
88    and     res_denorm.resource_id    = l_resource_id
89    and     l_start_date between res_denorm.resource_effective_start_date and res_denorm.resource_effective_end_date
90    and     fg.instance_pk1_value     = to_char(res_denorm.resource_organization_id)
91    and     fg.instance_type          = 'INSTANCE'
92    and     fg.object_id              = fob.object_id
93    and     fg.grantee_type           = 'USER'
94    AND     fg.grantee_key    = wfr.name
95    AND     wfr.orig_system    = 'HZ_PARTY'
96    AND     per.party_id      = wfr.orig_system_id
97    and     sysdate between per.effective_start_date and per.effective_end_date
98    and     fg.menu_id                = prmry_contact_menu.menu_id
99    and     trunc(SYSDATE) between trunc(fg.start_date) and     trunc(NVL(fg.end_date, SYSDATE+1))
100 UNION
101    select per.person_id  approver_id
102    from pa_resources_denorm res_denorm,
103         fnd_grants          fg,
104         fnd_objects         fob,
105         wf_roles            wfr,
106         per_people_f        per,
107         (select pa_security_pvt.get_menu_id('PA_PRM_RES_AUTH') menu_id
108          from dual) res_auth_menu
109    where   fob.obj_name              = 'ORGANIZATION'
110    and     res_denorm.resource_id    = l_resource_id
111    and     fg.instance_pk1_value     = to_char(res_denorm.resource_organization_id)
112    and     l_start_date between res_denorm.resource_effective_start_date and res_denorm.resource_effective_end_date
113    and     fg.instance_type          = 'INSTANCE'
114    and     fg.object_id              = fob.object_id
115    and     fg.grantee_type           = 'USER'
116    and     fg.menu_id = res_auth_menu.menu_id
117    and     trunc(SYSDATE) between trunc(fg.start_date)
118                           and     trunc(NVL(fg.end_date, SYSDATE+1))
119    AND   fg.grantee_key    = wfr.name
120    AND   wfr.orig_system    = 'HZ_PARTY'
121    AND   per.party_id      = wfr.orig_system_id
122    and   sysdate between per.effective_start_date and per.effective_end_date
123    and     per.person_id <> res_denorm.manager_id
124    and     per.person_id not in
125           (
126              select per2.person_Id
127              from
128                 fnd_grants       fg2,
129                 fnd_objects      fob2,
130                 wf_roles         wfr2,
131                 (select pa_security_pvt.get_menu_id('PA_PRM_RES_PRMRY_CONTACT') menu_id
132                 from dual) prmry_contact_menu,
133                 per_people_f     per2
134              where   fob.obj_name               = 'ORGANIZATION'
135              and     fg2.instance_pk1_value     = to_char(res_denorm.resource_organization_id)
136              and     fg2.instance_type          = 'INSTANCE'
137              and     fg2.object_id              = fob2.object_id
138              and     fg2.grantee_type           = 'USER'
139              and     fg2.menu_id = prmry_contact_menu.menu_id
140              and     trunc(SYSDATE) between trunc(fg2.start_date)
141                                     and     trunc(NVL(fg2.end_date, SYSDATE+1))
142              AND   fg2.grantee_key    = wfr2.name
143              AND   wfr2.orig_system    = 'HZ_PARTY'
144              AND   per2.party_id      = wfr2.orig_system_id
145              and   sysdate between per2.effective_start_date
146                                and per2.effective_end_date
147           )
148 ) ;
149 EXCEPTION
150 WHEN NO_DATA_FOUND THEN
151         l_dummy := 'N';
152 WHEN OTHERS THEN
153         l_dummy := 'N';
154         RAISE ;
155 END;
156 
157 return l_dummy;
158 END IS_VALID_APPROVER;
159 
160 -- Start of comments
161 --	API name 	: VALIDATE_FLEX_FIELD
162 --	Type		: Private
163 --	Pre-reqs	: None.
164 --	Function	: This is a private API to validate Flex Field segments.
165 --	Usage		: This API will be called from AMG.
166 --	Parameters	:
167 --	IN/INOUT	:	p_desc_flex_name	IN  VARCHAR2
168 --					Name of the descriptive flex field.
169 --				p_attribute_category		IN  VARCHAR2
170 --					Context value of the flex field.
171 --				px_attribute1 .. 15     	IN  VARCHAR2
172 --					Attribute values.
173 --	OUT		:
174 --				x_return_status		OUT VARCHAR2
175 --					Indicates the return status of the API.
176 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
177 --				x_msg_count		OUT NUMBER
178 --					Indicates the number of error messages in the message stack
179 --				x_msg_data		OUT VARCHAR2
180 --					Indicates the error message text if only one error exists
181 --	History		:
182 --                              01-Mar-2006 - amksingh  - Created
183 -- End of comments
184 PROCEDURE VALIDATE_FLEX_FIELD(
185   p_desc_flex_name              IN              VARCHAR2 := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
186 , p_attribute_category          IN              VARCHAR2 := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR
187 , px_attribute1                 IN OUT  NOCOPY  VARCHAR2
188 , px_attribute2                 IN OUT  NOCOPY  VARCHAR2
189 , px_attribute3                 IN OUT  NOCOPY  VARCHAR2
190 , px_attribute4                 IN OUT  NOCOPY  VARCHAR2
191 , px_attribute5                 IN OUT  NOCOPY  VARCHAR2
192 , px_attribute6                 IN OUT  NOCOPY  VARCHAR2
193 , px_attribute7                 IN OUT  NOCOPY  VARCHAR2
194 , px_attribute8                 IN OUT  NOCOPY  VARCHAR2
195 , px_attribute9                 IN OUT  NOCOPY  VARCHAR2
196 , px_attribute10                IN OUT  NOCOPY  VARCHAR2
197 , px_attribute11                IN OUT  NOCOPY  VARCHAR2
198 , px_attribute12                IN OUT  NOCOPY  VARCHAR2
199 , px_attribute13                IN OUT  NOCOPY  VARCHAR2
200 , px_attribute14                IN OUT  NOCOPY  VARCHAR2
201 , px_attribute15                IN OUT  NOCOPY  VARCHAR2
202 , x_return_status	        OUT	NOCOPY	VARCHAR2
203 , x_msg_count			OUT	NOCOPY	NUMBER
204 , x_msg_data			OUT	NOCOPY	VARCHAR2
205 )
206 IS
207 TYPE seg_col_name       IS TABLE OF VARCHAR2(150)
208 INDEX BY BINARY_INTEGER;
209 
210 l_segment_column_name   seg_col_name;
211 l_attribute             seg_col_name;
212 BEGIN
213         -- This API will return only those segment values which are enabled as part of
214         -- Global Data Elements context and the passed context.
215         x_return_status := FND_API.G_RET_STS_SUCCESS;
216 
217         -- I don't think we need to do null check here
218         -- If we do this check, then if some sgements are mandatory
219         -- the error will not come
220         --IF p_attribute_category IS NULL AND px_attribute1 IS NULL AND px_attribute2 IS NULL
221         --AND px_attribute3 IS NULl AND px_attribute4 IS NULL AND px_attribute5 IS NULL
222         --AND px_attribute6 IS NULL AND px_attribute7 IS NULL AND px_attribute8 IS NULL
223         --AND px_attribute9 IS NULL AND px_attribute10 IS NULL AND px_attribute11 IS NULL
224         --AND px_attribute12 IS NULL AND px_attribute13 IS NULL AND px_attribute14 IS NULL
225         --AND px_attribute15 IS NULL
226         --THEN
227         --        return;
228         --END IF;
229 
230         -- DEFINE ID COLUMNS
231         fnd_flex_descval.set_context_value(p_attribute_category);
232         fnd_flex_descval.set_column_value('ATTRIBUTE1', px_attribute1);
233         fnd_flex_descval.set_column_value('ATTRIBUTE2', px_attribute2);
234         fnd_flex_descval.set_column_value('ATTRIBUTE3', px_attribute3);
235         fnd_flex_descval.set_column_value('ATTRIBUTE4', px_attribute4);
236         fnd_flex_descval.set_column_value('ATTRIBUTE5', px_attribute5);
237         fnd_flex_descval.set_column_value('ATTRIBUTE6', px_attribute6);
238         fnd_flex_descval.set_column_value('ATTRIBUTE7', px_attribute7);
239         fnd_flex_descval.set_column_value('ATTRIBUTE8', px_attribute8);
240         fnd_flex_descval.set_column_value('ATTRIBUTE9', px_attribute9);
241         fnd_flex_descval.set_column_value('ATTRIBUTE10', px_attribute10);
242         fnd_flex_descval.set_column_value('ATTRIBUTE11', px_attribute11);
243         fnd_flex_descval.set_column_value('ATTRIBUTE12', px_attribute12);
244         fnd_flex_descval.set_column_value('ATTRIBUTE13', px_attribute13);
245         fnd_flex_descval.set_column_value('ATTRIBUTE14', px_attribute14);
246         fnd_flex_descval.set_column_value('ATTRIBUTE15', px_attribute15);
247         px_attribute1 := null;
248         px_attribute2 := null;
249         px_attribute3 := null;
250         px_attribute4 := null;
251         px_attribute5 := null;
252         px_attribute6 := null;
253         px_attribute7 := null;
254         px_attribute8 := null;
255         px_attribute9 := null;
256         px_attribute10 := null;
257         px_attribute11 := null;
258         px_attribute12 := null;
259         px_attribute13 := null;
260         px_attribute14 := null;
261         px_attribute15 := null;
262         -- VALIDATE
263         IF (fnd_flex_descval.validate_desccols( 'PA',p_desc_flex_name,'D', sysdate)) then
264                 x_msg_data := 'VALID: ' || fnd_flex_descval.concatenated_ids;
265                 x_return_status := 'S';
266                 FOR j IN 1 ..15 LOOP --Bug 7240954
267                         l_segment_column_name(j) := ltrim(rtrim(FND_FLEX_DESCVAL.segment_column_name(j)));
268                         l_attribute(j)           := ltrim(rtrim(FND_FLEX_DESCVAL.segment_id(j)));
269 
270                         IF l_segment_column_name(j) = 'ATTRIBUTE1' Then
271                                 px_attribute1 := l_attribute(j);
272                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE2' Then
273                                 px_attribute2 := l_attribute(j);
274                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE3' Then
275                                 px_attribute3 := l_attribute(j);
276                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE4' Then
277                                 px_attribute4 := l_attribute(j);
278                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE5' Then
279                                 px_attribute5 := l_attribute(j);
280                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE6' Then
281                                 px_attribute6 := l_attribute(j);
282                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE7' Then
283                                 px_attribute7 := l_attribute(j);
284                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE8' Then
285                                 px_attribute8 := l_attribute(j);
286                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE9' Then
287                                 px_attribute9 := l_attribute(j);
288                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE10' Then
289                                 px_attribute10 := l_attribute(j);
290                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE11' Then
291                                 px_attribute11 := l_attribute(j);
292                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE12' Then
293                                 px_attribute12 := l_attribute(j);
294                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE13' Then
295                                 px_attribute13 := l_attribute(j);
296                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE14' Then
297                                 px_attribute14 := l_attribute(j);
298                         ELSIF l_segment_column_name(j) = 'ATTRIBUTE15' Then
299                                 px_attribute15 := l_attribute(j);
300                         END IF;
301                 END LOOP;
302         ELSE
303                 x_msg_data := 'INVALID: ' || fnd_flex_descval.error_message;
304                 x_return_status := 'E';
305         END IF;
306 EXCEPTION
307 WHEN OTHERS THEN
308         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
309         x_msg_data      := SQLERRM;
310 
311         FND_MSG_PUB.add_exc_msg
312         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
313         , p_procedure_name      => 'VALIDATE_FLEX_FIELD'
314         , p_error_text          => x_msg_data);
315 
316         x_msg_count     := FND_MSG_PUB.count_msg;
317 
318         RAISE;
319 END VALIDATE_FLEX_FIELD;
320 
321 -- Start of comments
322 --	API name 	: CREATE_REQUIREMENTS
323 --	Type		: Public
324 --	Pre-reqs	: None.
325 --	Function	: This is a public API to create one or more requirements for one or more projects.
326 --	Usage		: This API will be called from AMG.
327 --	Parameters	:
328 --	IN		:	p_api_version_number	IN  NUMBER			Required
329 --					To be compliant with Applications API coding standards.
330 --				p_init_msg_list		IN  VARCHAR2
331 --					Identifier to initialize the error message stack.
332 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
333 --				p_commit		IN  VARCHAR2
334 --					Identifier to commit the transaction.
335 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
336 --				p_requirement_in_tbl	IN  REQUIREMENT_IN_TBL_TYPE	Required
337 --					Table of requirement records. Please see the REQUIREMENT_IN_TBL_TYPE datatype table.
338 --	OUT		:
339 --				x_requirement_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
340 --					Table to store requirement_ids created by the API.
341 --					Reference: pa_project_assignments.assignment_id
342 --				x_return_status		OUT VARCHAR2
343 --					Indicates the return status of the API.
344 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
345 --				x_msg_count		OUT NUMBER
346 --					Indicates the number of error messages in the message stack
347 --				x_msg_data		OUT VARCHAR2
348 --					Indicates the error message text if only one error exists
349 --	History		:
350 --                              01-Mar-2006 - amksingh  - Created
351 -- End of comments
352 PROCEDURE CREATE_REQUIREMENTS
353 (
354   p_api_version_number		IN		NUMBER   := 1.0
355 , p_init_msg_list		IN		VARCHAR2 := FND_API.G_TRUE
356 , p_commit			IN		VARCHAR2 := FND_API.G_FALSE
357 , p_requirement_in_tbl		IN		REQUIREMENT_IN_TBL_TYPE
358 , x_requirement_id_tbl		OUT	NOCOPY	SYSTEM.PA_NUM_TBL_TYPE
359 , x_return_status		OUT	NOCOPY	VARCHAR2
360 , x_msg_count			OUT	NOCOPY	NUMBER
361 , x_msg_data			OUT	NOCOPY	VARCHAR2
362 )
363 IS
364 l_calling_application           VARCHAR2(10)            := 'PLSQL';
365 l_calling_module                VARCHAR2(10)            := 'AMG';
366 l_check_id_flag                 VARCHAR2(1)             := 'Y';
367 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
368 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
369 l_log_level                     NUMBER                  := 3;
370 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.CREATE_REQUIREMENTS';
371 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
372 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
373 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
374 l_msg_count                     NUMBER;
375 l_msg_data                      VARCHAR2(2000);
376 l_msg_index_out                 NUMBER;
377 l_data                          VARCHAR2(2000);
378 l_debug_mode                    VARCHAR2(1);
379 
380 i                               NUMBER;
381 l_new_assignment_id_tbl         SYSTEM.PA_NUM_TBL_TYPE  := SYSTEM.PA_NUM_TBL_TYPE();
382 l_new_assignment_id             NUMBER;
383 l_assignment_number             NUMBER;
384 l_assignment_row_id             ROWID;
385 l_resource_id                   NUMBER;
386 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
387 l_error_flag                    VARCHAR2(1)             := 'N';
388 l_error_flag_local              VARCHAR2(1)             := 'N';
389 l_req_rec		        REQUIREMENT_IN_REC_TYPE;
390 l_asgn_creation_mode		VARCHAR2(10)	        := 'FULL';
391 l_assignment_type		VARCHAR2(30)	        := 'OPEN_ASSIGNMENT';
392 l_multiple_status_flag		VARCHAR2(1)	        := 'N';
393 l_dummy_code                    VARCHAR2(30);
394 l_loop_msg_count                NUMBER                  :=0;
395 l_start_msg_count               NUMBER                  :=0;
396 l_end_msg_count                 NUMBER                  :=0;
397 l_missing_params                VARCHAR2(1000);
398 l_privilege                     VARCHAR2(30);
399 l_object_name                   VARCHAR2(30);
400 l_object_key                    NUMBER;
401 l_error_message_code            VARCHAR2(30);
402 l_ret_code                      VARCHAR2(1);
403 
404 
405 CURSOR c_get_valid_calendar_types(c_code VARCHAR2) IS
406 SELECT lookup_code
407 FROM pa_lookups
408 WHERE lookup_type = 'CHANGE_CALENDAR_TYPE_CODE'
409 AND lookup_code = c_code
410 AND lookup_code <> 'RESOURCE';
411 
412 CURSOR c_get_project_dtls(c_project_id NUMBER) IS
413 SELECT role_list_id, multi_currency_billing_flag, calendar_id, work_type_id, location_id
414 FROM pa_projects_all
415 WHERE project_id = c_project_id;
416 
417 CURSOR c_get_team_templ_dtls(c_team_templ_id NUMBER) IS
418 SELECT role_list_id, calendar_id, work_type_id
419 FROM pa_team_templates
420 WHERE team_template_id = c_team_templ_id;
421 
422 CURSOR c_get_role_dtls(c_role_id NUMBER) IS
423 SELECT meaning, default_min_job_level, default_max_job_level, default_job_id
424 FROM   pa_project_role_types_vl
425 WHERE  project_role_id = c_role_id ;
426 
427 CURSOR get_bill_rate_override_flags(c_project_id NUMBER) IS
428 SELECT impl.rate_discount_reason_flag ,impl.br_override_flag, impl.br_discount_override_flag
429 FROM pa_implementations_all impl
430     , pa_projects_all proj
431 WHERE proj.org_id=impl.org_id		-- Removed nvl condition from org_id : Post review changes for Bug 5130421
432 AND proj.project_id = c_project_id ;
433 
434 CURSOR c_get_lookup_exists(c_lookup_type VARCHAR2, c_lookup_code VARCHAR2) IS
435 SELECT 'Y'
436 FROM dual
437 WHERE EXISTS
438 (SELECT 'XYZ' FROM pa_lookups WHERE lookup_type = c_lookup_type AND lookup_code = c_lookup_code);
439 
440 
441 CURSOR c_get_location(c_location_id NUMBER) IS
442 SELECT country_code, region, city
443 FROM pa_locations
444 WHERE location_id = c_location_id;
445 
446 CURSOR c_derive_country_code(c_country_name IN VARCHAR2) IS
447 SELECT country_code
448 FROM pa_country_v
449 WHERE name = c_country_name;
450 
451 CURSOR c_derive_country_name(c_country_code IN VARCHAR2) IS
452 SELECT name
453 FROM pa_country_v
454 WHERE  country_code  = c_country_code;
455 
456 
457 -- This cursor is for future extension when we support creation of team role from planning resource
458 CURSOR c_get_planning_res_info(c_resource_list_member_id NUMBER, c_budget_version_id NUMBER, c_project_id NUMBER) IS
459 SELECT
460   ra.resource_list_member_id
461 , firstrow.person_id
462 , rlm.resource_id
463 , PA_RESOURCE_UTILS.get_person_name_no_date(firstrow.person_id)
464 , ra.project_id
465 , ra.budget_version_id
466 , decode (ra.role_count, 1, firstrow.named_role, null) named_role
467 , decode (ra.role_count, 1, firstrow.project_role_id, null) project_role_id
468 , decode (ra.role_count, 1, ro.meaning, null) project_role
469 , ra.min_date task_assign_start_date
470 , ra.max_date task_assign_end_date
471 , firstrow.resource_assignment_id
472 , firstrow.res_type_code
473 FROM pa_resource_assignments firstrow
474 , pa_resource_list_members rlm
475 , pa_proj_roles_v ro
476 , (SELECT project_id , budget_version_id , resource_list_member_id , count(1) role_count , max(max_id) max_id
477      , min(min_date) min_date , max(max_date) max_date
478    FROM (SELECT project_id , budget_version_id , resource_list_member_id , project_role_id
479            , max(resource_assignment_id) max_id , min(SCHEDULE_START_DATE) min_date , max(SCHEDULE_END_DATE) max_date
480          FROM pa_resource_assignments
481          WHERE ta_display_flag = 'Y' and nvl(PROJECT_ASSIGNMENT_ID, -1) = -1
482          AND resource_class_code = 'PEOPLE'
483          GROUP BY project_id, budget_version_id, resource_list_member_id, project_role_id
484          ) res_roles
485     GROUP BY project_id, budget_version_id, resource_list_member_id
486    ) ra
487 WHERE ra.resource_list_member_id = rlm.resource_list_member_id
488 AND firstrow.resource_assignment_id = ra.max_id
489 AND firstrow.project_role_id = ro.project_role_id (+)
490 AND ra.budget_version_id = c_budget_version_id
491 AND ra.resource_list_member_id = c_resource_list_member_id
492 AND ra.project_id = c_project_id
493 AND firstrow.person_id IS NULL;
494 -- If the value from this cusror is returned, then passed resource list member id is valid
495 -- Pass this resource list member id, budget version id to internal API
496 -- Pass calendar type as PROJECT and calendar_id as of project
497 -- Pass sum_tasks_flag as N
498 
499 -- In case of assignments, user can choose calendar type between PROJECT or RESOURCE
500 -- Pass this resource list member id, budget version id to internal API
501 -- Pass sum_tasks_flag as Y if calendar is RESOURCE
502 -- pass person_id, resource_id
503 
504 -- Added for Bug 5202329
505 CURSOR c_get_exp_organization_id(c_business_group_id NUMBER, c_exp_organization_name VARCHAR) IS
506 SELECT organization_id
507 FROM hr_organization_units
508 WHERE business_group_id = c_business_group_id
509 AND name = c_exp_organization_name;
510 
511 
512 l_role_list_id                  NUMBER;
513 l_multi_currency_billing_flag   VARCHAR2(1);
514 l_calendar_id                   NUMBER;
515 l_work_type_id                  NUMBER;
516 l_location_id                   NUMBER;
517 l_role_name                     VARCHAR2(80);
518 l_min_job_level                 NUMBER;
519 l_max_job_level                 NUMBER;
520 l_fcst_job_id                   NUMBER;
521 l_valid_flag                    VARCHAR2(1);
522 l_tp_amount_type_desc_tmp       VARCHAR2(80);
523 l_rate_discount_reason_flag     VARCHAR2(1);
524 l_br_override_flag              VARCHAR2(1);
525 l_br_discount_override_flag     VARCHAR2(1);
526 l_project_id_tmp                NUMBER;
527 l_project_role_id_tmp		NUMBER;
528 l_search_country_code_tmp	VARCHAR2(2);
529 l_srch_exp_org_str_ver_id_tmp	NUMBER;
530 l_search_exp_start_org_id_tmp	NUMBER;
531 l_expenditure_org_id_tmp	NUMBER;
532 l_exp_organization_id_tmp       NUMBER;
533 l_fcst_job_group_id_tmp         NUMBER;
534 l_fcst_job_id_tmp               NUMBER;
535 l_tp_currency_override_tmp      VARCHAR2(30);
536 l_valid_country                 VARCHAR2(1);
537 l_dummy_country_code            VARCHAR2(2);
538 l_dummy_state		        VARCHAR2(240);
539 l_dummy_city		        VARCHAR2(80);
540 l_out_location_id	        NUMBER;
541 l_bill_currency_override_tmp    VARCHAR2(30); -- 5144288, 5144369
542 l_business_group_id             NUMBER;       -- Added for Bug 5202329
543 
544 BEGIN
545 
546         --Flows which are supported by this API
547         ---------------------------------------
548         --1. Create project requirements
549         --        1.1 Setting basic information(staffing priority, staffing owner, subteams, location etc..)
550         --        1.2 Setting schedule information(dates, status, calendar etc..)
551         --        1.3 Setting competencies defaulted by team role
552         --        1.4 Setting advertisement rule
553         --        1.5 Setting candidate search(search organization, weightages etc..) information
554         --        1.6 Setting financial information(expendtiture organization, bill rate etc..)
555         --        1.7 Setting forecast infomation(job, job group, expenditure type etc..)
556         --2. Create team template requirments
557         --        2.1 Setting basic information(staffing priority, staffing owner, subteams, location etc..)
558         --        2.2 Setting schedule information(dates, status, calendar etc..)
559         --        2.3 Setting competencies defaulted by team role
560         --
561         --Flows which are not supported by this API
562         -------------------------------------------
563         --1. Create team role for given planning resource
564         --2. Adding candidates while creating requirements
565         --3. Adding new competencies(other than defaulted by role) while creating requirement
566 
567 
568         -- Mandatory Parameters
569         -----------------------
570         --1. Either project_role_id or project_role_name should be passed.
571         --2. Either team_template_id or one of project_id, project_name, project_number should be passed.
572         --3. Both start_date and end_date should be passed.
573         --4. Either status_code or status_name should be specified.
574 
575 
576         x_return_status := FND_API.G_RET_STS_SUCCESS;
577         x_requirement_id_tbl:= SYSTEM.pa_num_tbl_type();
578 
579         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
580 
581         IF l_debug_mode = 'Y' THEN
582                 PA_DEBUG.set_curr_function(p_function => 'CREATE_REQUIREMENTS', p_debug_mode => l_debug_mode);
583         END IF;
584 
585         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
586                 FND_MSG_PUB.initialize;
587         END IF;
588 
589         IF p_commit = FND_API.G_TRUE THEN
590                 savepoint CREATE_REQUIREMENTS_SP;
591         END IF;
592 
593         IF l_debug_mode = 'Y' THEN
594                 pa_debug.write(l_module, 'Start of create_requirements', l_log_level);
595         END IF;
596 
597         IF l_debug_mode = 'Y' THEN
598                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
599                 i := p_requirement_in_tbl.first;
600                 WHILE i IS NOT NULL LOOP
601                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').requirement_id'||p_requirement_in_tbl(i).requirement_id, l_log_level);
602                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').requirement_name'||p_requirement_in_tbl(i).requirement_name, l_log_level);
603                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').team_template_id'||p_requirement_in_tbl(i).team_template_id, l_log_level);
604                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').number_of_requirements'||p_requirement_in_tbl(i).number_of_requirements, l_log_level);
605                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_role_id'||p_requirement_in_tbl(i).project_role_id, l_log_level);
606                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_role_name'||p_requirement_in_tbl(i).project_role_name, l_log_level);
607                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_id'||p_requirement_in_tbl(i).project_id, l_log_level);
608                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_name'||p_requirement_in_tbl(i).project_name, l_log_level);
609                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_number'||p_requirement_in_tbl(i).project_number, l_log_level);
610                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').staffing_owner_person_id'||p_requirement_in_tbl(i).staffing_owner_person_id, l_log_level);
611                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').staffing_priority_code'||p_requirement_in_tbl(i).staffing_priority_code, l_log_level);
612                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').staffing_priority_name'||p_requirement_in_tbl(i).staffing_priority_name, l_log_level);
613                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_subteam_id'||p_requirement_in_tbl(i).project_subteam_id, l_log_level);
614                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_subteam_name'||p_requirement_in_tbl(i).project_subteam_name, l_log_level);
615                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_id'||p_requirement_in_tbl(i).location_id, l_log_level);
616                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_country_code'||p_requirement_in_tbl(i).location_country_code, l_log_level);
617                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_country_name'||p_requirement_in_tbl(i).location_country_name, l_log_level);
618                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_region'||p_requirement_in_tbl(i).location_region, l_log_level);
619                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_city'||p_requirement_in_tbl(i).location_city, l_log_level);
620                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').min_resource_job_level'||p_requirement_in_tbl(i).min_resource_job_level, l_log_level);
621                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').max_resource_job_level'||p_requirement_in_tbl(i).max_resource_job_level, l_log_level);
622                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').description'||p_requirement_in_tbl(i).description, l_log_level);
623                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').additional_information'||p_requirement_in_tbl(i).additional_information, l_log_level);
624                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').start_date'||p_requirement_in_tbl(i).start_date, l_log_level);
625                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').end_date'||p_requirement_in_tbl(i).end_date, l_log_level);
626                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').status_code'||p_requirement_in_tbl(i).status_code, l_log_level);
627                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').status_name'||p_requirement_in_tbl(i).status_name, l_log_level);
628                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').calendar_type'||p_requirement_in_tbl(i).calendar_type, l_log_level);
629                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').calendar_id'||p_requirement_in_tbl(i).calendar_id, l_log_level);
630                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').calendar_name'||p_requirement_in_tbl(i).calendar_name, l_log_level);
631                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').start_adv_action_set_flag'||p_requirement_in_tbl(i).start_adv_action_set_flag, l_log_level);
632                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').adv_action_set_id'||p_requirement_in_tbl(i).adv_action_set_id, l_log_level);
633                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').adv_action_set_name'||p_requirement_in_tbl(i).adv_action_set_name, l_log_level);
634                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').comp_match_weighting'||p_requirement_in_tbl(i).comp_match_weighting, l_log_level);
635                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').avail_match_weighting'||p_requirement_in_tbl(i).avail_match_weighting, l_log_level);
636                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').job_level_match_weighting'||p_requirement_in_tbl(i).job_level_match_weighting, l_log_level);
637                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').enable_auto_cand_nom_flag'||p_requirement_in_tbl(i).enable_auto_cand_nom_flag, l_log_level);
638                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_min_availability'||p_requirement_in_tbl(i).search_min_availability, l_log_level);
639                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_org_str_ver_id'||p_requirement_in_tbl(i).search_exp_org_str_ver_id, l_log_level);
640                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_org_hier_name'||p_requirement_in_tbl(i).search_exp_org_hier_name, l_log_level);
641                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_start_org_id'||p_requirement_in_tbl(i).search_exp_start_org_id, l_log_level);
642                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_start_org_name'||p_requirement_in_tbl(i).search_exp_start_org_name, l_log_level);
643                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_country_code'||p_requirement_in_tbl(i).search_country_code, l_log_level);
644                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_country_name'||p_requirement_in_tbl(i).search_country_name, l_log_level);
645                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_min_candidate_score'||p_requirement_in_tbl(i).search_min_candidate_score, l_log_level);
646                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_org_id'||p_requirement_in_tbl(i).expenditure_org_id, l_log_level);
647                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_org_name'||p_requirement_in_tbl(i).expenditure_org_name, l_log_level);
648                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_organization_id'||p_requirement_in_tbl(i).expenditure_organization_id, l_log_level);
649                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_organization_name'||p_requirement_in_tbl(i).expenditure_organization_name, l_log_level);
650                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_type_class'||p_requirement_in_tbl(i).expenditure_type_class, l_log_level);
651                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_type'||p_requirement_in_tbl(i).expenditure_type, l_log_level);
652                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_group_id'||p_requirement_in_tbl(i).fcst_job_group_id, l_log_level);
653                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_group_name'||p_requirement_in_tbl(i).fcst_job_group_name, l_log_level);
654                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_id'||p_requirement_in_tbl(i).fcst_job_id, l_log_level);
655                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_name'||p_requirement_in_tbl(i).fcst_job_name, l_log_level);
656                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').work_type_id'||p_requirement_in_tbl(i).work_type_id, l_log_level);
657                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').work_type_name'||p_requirement_in_tbl(i).work_type_name, l_log_level);
658                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').bill_rate_option'||p_requirement_in_tbl(i).bill_rate_option, l_log_level);
659                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').bill_rate_override'||p_requirement_in_tbl(i).bill_rate_override, l_log_level);
660                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').bill_rate_curr_override'||p_requirement_in_tbl(i).bill_rate_curr_override, l_log_level);
661                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').markup_percent_override'||p_requirement_in_tbl(i).markup_percent_override, l_log_level);
662                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').discount_percentage'||p_requirement_in_tbl(i).discount_percentage, l_log_level);
663                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').rate_disc_reason_code'||p_requirement_in_tbl(i).rate_disc_reason_code, l_log_level);
664                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_rate_option'||p_requirement_in_tbl(i).tp_rate_option, l_log_level);
665                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_rate_override'||p_requirement_in_tbl(i).tp_rate_override, l_log_level);
666                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_currency_override'||p_requirement_in_tbl(i).tp_currency_override, l_log_level);
667                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_calc_base_code_override'||p_requirement_in_tbl(i).tp_calc_base_code_override, l_log_level);
668                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_percent_applied_override'||p_requirement_in_tbl(i).tp_percent_applied_override, l_log_level);
669                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').extension_possible'||p_requirement_in_tbl(i).extension_possible, l_log_level);
670                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expense_owner'||p_requirement_in_tbl(i).expense_owner, l_log_level);
671                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expense_limit'||p_requirement_in_tbl(i).expense_limit, l_log_level);
672                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').orig_system_code'||p_requirement_in_tbl(i).orig_system_code, l_log_level);
673                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').orig_system_reference'||p_requirement_in_tbl(i).orig_system_reference, l_log_level);
674                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').record_version_number'||p_requirement_in_tbl(i).record_version_number, l_log_level);
675                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute_category'||p_requirement_in_tbl(i).attribute_category, l_log_level);
676                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute1'||p_requirement_in_tbl(i).attribute1, l_log_level);
677                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute2'||p_requirement_in_tbl(i).attribute2, l_log_level);
678                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute3'||p_requirement_in_tbl(i).attribute3, l_log_level);
679                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute4'||p_requirement_in_tbl(i).attribute4, l_log_level);
680                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute5'||p_requirement_in_tbl(i).attribute5, l_log_level);
681                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute6'||p_requirement_in_tbl(i).attribute6, l_log_level);
682                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute7'||p_requirement_in_tbl(i).attribute7, l_log_level);
683                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute8'||p_requirement_in_tbl(i).attribute8, l_log_level);
684                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute9'||p_requirement_in_tbl(i).attribute9, l_log_level);
685                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute10'||p_requirement_in_tbl(i).attribute10, l_log_level);
686                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute11'||p_requirement_in_tbl(i).attribute11, l_log_level);
687                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute12'||p_requirement_in_tbl(i).attribute12, l_log_level);
688                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute13'||p_requirement_in_tbl(i).attribute13, l_log_level);
689                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute14'||p_requirement_in_tbl(i).attribute14, l_log_level);
690                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute15'||p_requirement_in_tbl(i).attribute15, l_log_level);
691                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
692                         i := p_requirement_in_tbl.next(i);
693                 END LOOP;
694         END IF;
695 
696         PA_STARTUP.INITIALIZE(
697                   p_calling_application                 => l_calling_application
698                 , p_calling_module                      => l_calling_module
699                 , p_check_id_flag                       => l_check_id_flag
700                 , p_check_role_security_flag            => l_check_role_security_flag
701                 , p_check_resource_security_flag        => l_check_resource_security_flag
702                 , p_debug_level                         => l_log_level
703                 );
704 
705         IF l_debug_mode = 'Y' THEN
706                 pa_debug.write(l_module, 'After call of pa_startup.initialize', l_log_level);
707         END IF;
708 
709         -- Page does not check PRM licensing, but keeping this code so in future if required, can be used
710         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
711         --IF l_prm_license_flag <> 'Y' THEN
712         --        null;
713         --END IF;
714 
715         i := p_requirement_in_tbl.first;
716 
717         WHILE i IS NOT NULL LOOP
718                 l_error_flag_local := 'N';
719                 l_missing_params := null;
720                 l_req_rec := null;
721                 l_valid_country := 'Y';
722 
723                 l_start_msg_count := FND_MSG_PUB.count_msg;
724 
725                 l_req_rec := p_requirement_in_tbl(i);
726 
727                 -- Blank Out Parameters if not passed.
728                 IF l_debug_mode = 'Y' THEN
729                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
730                         pa_debug.write(l_module, '-----------------------------', l_log_level);
731                         pa_debug.write(l_module, 'NullOut parameters which are not required.', l_log_level);
732                 END IF;
733 
734                         /*--Bug 6511907 PJR Date Validation Enhancement ----- Start--*/
735                         /*-- Validating Resource Req Start and End Date against
736                              Project Start and Completion dates --*/
737 
738                         Declare
739                           l_validate           VARCHAR2(10);
740                           l_start_date_status  VARCHAR2(10);
741                           l_end_date_status    VARCHAR2(10);
742                           l_start_date         DATE;
743                           l_end_date           DATE;
744                         Begin
745                          If l_req_rec.start_date is not null or l_req_rec.end_date is not null then
746                            l_start_date := l_req_rec.start_date;
747                            l_end_date   := l_req_rec.end_date;
748                            PA_PROJECT_DATES_UTILS.Validate_Resource_Dates
749                                        (l_req_rec.project_id, l_start_date, l_end_date,
750                                         l_validate, l_start_date_status, l_end_date_status);
751 
752                            If l_validate = 'Y' and l_start_date_status = 'I' Then
753 
754                               pa_utils.add_message
755                                ( p_app_short_name  => 'PA'
756                                 ,p_msg_name	       => 'PA_PJR_DATE_START_ERROR'
757                                 ,p_token1          => 'PROJ_TXN_START_DATE'
758 				,p_value1          =>  GET_PROJECT_START_DATE(l_req_rec.project_id)
759                                 ,p_token2          => ''
760                                 ,p_value2          => ''
761                                 ,p_token3          => ''
762                                 ,p_value3          => ''
763                                );
764 
765                               RAISE  FND_API.G_EXC_ERROR;
766                            End If;
767 
768                            If l_validate = 'Y' and l_end_date_status = 'I' Then
769 
770                               pa_utils.add_message
771                                ( p_app_short_name  => 'PA'
772                                 ,p_msg_name	    => 'PA_PJR_DATE_FINISH_ERROR'
773                                 ,p_token1          => 'PROJ_TXN_END_DATE'
774 				,p_value1          => GET_PROJECT_COMPLETION_DATE(l_req_rec.project_id)
775                                 ,p_token2          => ''
776                                 ,p_value2          => ''
777                                 ,p_token3          => ''
778                                 ,p_value3          => ''
779                                );
780 
781                               RAISE  FND_API.G_EXC_ERROR;
782                            End If;
783                          End If;
784                         End;
785 
786                         /*--Bug 6511907 PJR Date Validation Enhancement ----- End--*/
787                 IF l_req_rec.requirement_id = G_PA_MISS_NUM THEN
788                         l_req_rec.requirement_id := null;
789                 END IF;
790 
791                 IF l_req_rec.requirement_name = G_PA_MISS_CHAR THEN
792                         l_req_rec.requirement_name := null;
793                 END IF;
794 
795                 IF l_req_rec.team_template_id = G_PA_MISS_NUM THEN
796                         l_req_rec.team_template_id := null;
797                 END IF;
798 
799                 IF l_req_rec.number_of_requirements = G_PA_MISS_NUM THEN
800                         l_req_rec.number_of_requirements := 1;
801                 END IF;
802 
803                 IF l_req_rec.project_role_id = G_PA_MISS_NUM THEN
804                         l_req_rec.project_role_id := null;
805                 END IF;
806 
807                 IF l_req_rec.project_role_name = G_PA_MISS_CHAR THEN
808                         l_req_rec.project_role_name := null;
809                 END IF;
810 
811                 IF l_req_rec.project_id = G_PA_MISS_NUM THEN
812                         l_req_rec.project_id := null;
813                 END IF;
814 
815                 IF l_req_rec.project_name = G_PA_MISS_CHAR THEN
816                         l_req_rec.project_name := null;
817                 END IF;
818 
819                 IF l_req_rec.project_number = G_PA_MISS_CHAR THEN
820                         l_req_rec.project_number := null;
821                 END IF;
822 
823                 -- Some fields like Staffing Owner will be defaulted further in internal APIs
824                 -- But user may like to pass them explicitely as null
825                 -- So in that case we need to distinguish MISS NUM with null
826                 -- But there is a problem that pa_inerface_utils_pub.g_pa_miss_num
827                 -- is diffrent than fnd_api.g_miss_num. PJR internal code uses
828                 -- fnd_api.g_miss_num, so it throws the error.
829                 -- For this reason, we need to convert the G_PA_MISS_NUM/CHAR to FND_API.G_MISS_NUM/CHAR
830                 -- before sending it to internal APIs
831 
832                 IF l_req_rec.staffing_owner_person_id = G_PA_MISS_NUM THEN
833                         -- We can not make null here
834                         -- Because underlying API treat null as override and does not
835                         -- default value.
836                         l_req_rec.staffing_owner_person_id := FND_API.G_MISS_NUM;
837                 END IF;
838 
839                 IF l_req_rec.staffing_priority_code = G_PA_MISS_CHAR THEN
840                         l_req_rec.staffing_priority_code := null;
841                 END IF;
842 
843                 IF l_req_rec.staffing_priority_name = G_PA_MISS_CHAR THEN
844                         l_req_rec.staffing_priority_name := null;
845                 END IF;
846 
847                 IF l_req_rec.project_subteam_id = G_PA_MISS_NUM THEN
848                         l_req_rec.project_subteam_id := null;
849                 END IF;
850 
851                 IF l_req_rec.project_subteam_name = G_PA_MISS_CHAR THEN
852                         l_req_rec.project_subteam_name := null;
853                 END IF;
854 
855                 -- Location will be default to project location for project requirements
856                 -- But user may like to pass them explicitely as null
857                 -- So in that case we need to distinguish MISS CHAR with null
858                 IF l_req_rec.location_id = G_PA_MISS_NUM THEN
859                         l_req_rec.location_id := FND_API.G_MISS_NUM;
860                 END IF;
861 
862                 IF l_req_rec.location_country_code = G_PA_MISS_CHAR THEN
863                         l_req_rec.location_country_code := FND_API.G_MISS_CHAR;
864                 END IF;
865 
866                 IF l_req_rec.location_country_name = G_PA_MISS_CHAR THEN
867                         l_req_rec.location_country_name := FND_API.G_MISS_CHAR;
868                 END IF;
869 
870                 IF l_req_rec.location_region = G_PA_MISS_CHAR THEN
871                         l_req_rec.location_region := FND_API.G_MISS_CHAR;
872                 END IF;
873 
874                 IF l_req_rec.location_city = G_PA_MISS_CHAR THEN
875                         l_req_rec.location_city := FND_API.G_MISS_CHAR;
876                 END IF;
877 
878 
879                 IF l_req_rec.min_resource_job_level = G_PA_MISS_NUM THEN
880                         l_req_rec.min_resource_job_level := null;
881                 END IF;
882 
883                 IF l_req_rec.max_resource_job_level = G_PA_MISS_NUM THEN
884                         l_req_rec.max_resource_job_level := null;
885                 END IF;
886 
887                 IF l_req_rec.description = G_PA_MISS_CHAR THEN
888                         l_req_rec.description := null;
889                 END IF;
890 
891                 IF l_req_rec.additional_information = G_PA_MISS_CHAR THEN
892                         l_req_rec.additional_information := null;
893                 END IF;
894 
895                 IF l_req_rec.start_date = G_PA_MISS_DATE THEN
896                         l_req_rec.start_date := null;
897                 END IF;
898 
899                 IF l_req_rec.end_date = G_PA_MISS_DATE THEN
900                         l_req_rec.end_date := null;
901                 END IF;
902 
903                 IF l_req_rec.status_code = G_PA_MISS_CHAR THEN
904                         l_req_rec.status_code := null;
905                 END IF;
906 
907                 IF l_req_rec.status_name = G_PA_MISS_CHAR THEN
908                         l_req_rec.status_name := null;
909                 END IF;
910 
911                 IF l_req_rec.calendar_type = G_PA_MISS_CHAR THEN
912                         l_req_rec.calendar_type := 'PROJECT';
913                 END IF;
914 
915                 IF l_req_rec.calendar_id = G_PA_MISS_NUM THEN
916                         l_req_rec.calendar_id := null;
917                 END IF;
918 
919                 IF l_req_rec.calendar_name = G_PA_MISS_CHAR THEN
920                         l_req_rec.calendar_name := null;
921                 END IF;
922 
923                 IF l_req_rec.start_adv_action_set_flag = G_PA_MISS_CHAR THEN
924                         l_req_rec.start_adv_action_set_flag := null;
925                 END IF;
926 
927                 IF l_req_rec.adv_action_set_id = G_PA_MISS_NUM THEN
928                         l_req_rec.adv_action_set_id := null;
929                 END IF;
930 
931                 IF l_req_rec.adv_action_set_name = G_PA_MISS_CHAR THEN
932                         l_req_rec.adv_action_set_name := null;
933                 END IF;
934 
935                 IF l_req_rec.comp_match_weighting = G_PA_MISS_NUM THEN
936                         l_req_rec.comp_match_weighting := null;
937                 END IF;
938 
939                 IF l_req_rec.avail_match_weighting = G_PA_MISS_NUM THEN
940                         l_req_rec.avail_match_weighting := null;
941                 END IF;
942 
943                 IF l_req_rec.job_level_match_weighting = G_PA_MISS_NUM THEN
944                         l_req_rec.job_level_match_weighting := null;
945                 END IF;
946 
947                 IF l_req_rec.enable_auto_cand_nom_flag = G_PA_MISS_CHAR THEN
948                         l_req_rec.enable_auto_cand_nom_flag := null;
949                 END IF;
950 
951                 IF l_req_rec.search_min_availability = G_PA_MISS_NUM THEN
952                         l_req_rec.search_min_availability := null;
953                 END IF;
954 
955                 IF l_req_rec.search_exp_org_str_ver_id = G_PA_MISS_NUM THEN
956                         l_req_rec.search_exp_org_str_ver_id := null;
957                 END IF;
958 
959                 IF l_req_rec.search_exp_org_hier_name = G_PA_MISS_CHAR THEN
960                         l_req_rec.search_exp_org_hier_name := null;
961                 END IF;
962 
963                 IF l_req_rec.search_exp_start_org_id = G_PA_MISS_NUM THEN
964                         l_req_rec.search_exp_start_org_id := null;
965                 END IF;
966 
967                 IF l_req_rec.search_exp_start_org_name = G_PA_MISS_CHAR THEN
968                         l_req_rec.search_exp_start_org_name := null;
969                 END IF;
970 
971                 -- Search country code, name can be made as null, so we need to distinguish
972                 -- miss char with null
973                 IF l_req_rec.search_country_code = G_PA_MISS_CHAR THEN
974                         l_req_rec.search_country_code := FND_API.G_MISS_CHAR;
975                 END IF;
976 
977                 IF l_req_rec.search_country_name = G_PA_MISS_CHAR THEN
978                         l_req_rec.search_country_name := FND_API.G_MISS_CHAR;
979                 END IF;
980 
981                 IF l_req_rec.search_min_candidate_score = G_PA_MISS_NUM THEN
982                         l_req_rec.search_min_candidate_score := null;
983                 END IF;
984 
985                 IF l_req_rec.expenditure_org_id = G_PA_MISS_NUM THEN
986                         l_req_rec.expenditure_org_id := null;
987                 END IF;
988 
989                 IF l_req_rec.expenditure_org_name = G_PA_MISS_CHAR THEN
990                         l_req_rec.expenditure_org_name := null;
991                 END IF;
992 
993                 IF l_req_rec.expenditure_organization_id = G_PA_MISS_NUM THEN
994                         l_req_rec.expenditure_organization_id := null;
995                 END IF;
996 
997                 IF l_req_rec.expenditure_organization_name = G_PA_MISS_CHAR THEN
998                         l_req_rec.expenditure_organization_name := null;
999                 END IF;
1000 
1001                 IF l_req_rec.expenditure_type_class = G_PA_MISS_CHAR THEN
1002                         l_req_rec.expenditure_type_class := null;
1003                 END IF;
1004 
1005                 IF l_req_rec.expenditure_type = G_PA_MISS_CHAR THEN
1006                         l_req_rec.expenditure_type := null;
1007                 END IF;
1008 
1009                 -- Job Group and ID can be null, so we need to distinguish b/w null and miss chars
1010                 IF l_req_rec.fcst_job_group_id = G_PA_MISS_NUM THEN
1011                         l_req_rec.fcst_job_group_id := FND_API.G_MISS_NUM;
1012                 END IF;
1013 
1014                 IF l_req_rec.fcst_job_group_name = G_PA_MISS_CHAR THEN
1015                         l_req_rec.fcst_job_group_name := FND_API.G_MISS_CHAR;
1016                 END IF;
1017 
1018                 IF l_req_rec.fcst_job_id = G_PA_MISS_NUM THEN
1019                         l_req_rec.fcst_job_id := FND_API.G_MISS_NUM;
1020                 END IF;
1021 
1022                 IF l_req_rec.fcst_job_name = G_PA_MISS_CHAR THEN
1023                         l_req_rec.fcst_job_name := FND_API.G_MISS_CHAR;
1024                 END IF;
1025 
1026                 IF l_req_rec.work_type_id = G_PA_MISS_NUM THEN
1027                         l_req_rec.work_type_id := null;
1028                 END IF;
1029 
1030                 IF l_req_rec.work_type_name = G_PA_MISS_CHAR THEN
1031                         l_req_rec.work_type_name := null;
1032                 END IF;
1033 
1034                 IF l_req_rec.bill_rate_option = G_PA_MISS_CHAR THEN
1035                         l_req_rec.bill_rate_option := 'NONE';
1036                 END IF;
1037 
1038                 IF l_req_rec.bill_rate_override = G_PA_MISS_NUM THEN
1039                         l_req_rec.bill_rate_override := null;
1040                 END IF;
1041 
1042                 IF l_req_rec.bill_rate_curr_override = G_PA_MISS_CHAR THEN
1043                         l_req_rec.bill_rate_curr_override := null;
1044                 END IF;
1045 
1046                 IF l_req_rec.markup_percent_override = G_PA_MISS_NUM THEN
1047                         l_req_rec.markup_percent_override := null;
1048                 END IF;
1049 
1050                 IF l_req_rec.discount_percentage = G_PA_MISS_NUM THEN
1051                         l_req_rec.discount_percentage := null;
1052                 END IF;
1053 
1054                 IF l_req_rec.rate_disc_reason_code = G_PA_MISS_CHAR THEN
1055                         l_req_rec.rate_disc_reason_code := null;
1056                 END IF;
1057 
1058                 IF l_req_rec.tp_rate_option = G_PA_MISS_CHAR THEN
1059                         l_req_rec.tp_rate_option := 'NONE';
1060                 END IF;
1061 
1062                 IF l_req_rec.tp_rate_override = G_PA_MISS_NUM THEN
1063                         l_req_rec.tp_rate_override := null;
1064                 END IF;
1065 
1066                 IF l_req_rec.tp_currency_override = G_PA_MISS_CHAR THEN
1067                         l_req_rec.tp_currency_override := null;
1068                 END IF;
1069 
1070                 IF l_req_rec.tp_calc_base_code_override = G_PA_MISS_CHAR THEN
1071                         l_req_rec.tp_calc_base_code_override := null;
1072                 END IF;
1073 
1074                 IF l_req_rec.tp_percent_applied_override = G_PA_MISS_NUM THEN
1075                         l_req_rec.tp_percent_applied_override := null;
1076                 END IF;
1077 
1078                 IF l_req_rec.extension_possible = G_PA_MISS_CHAR THEN
1079                         l_req_rec.extension_possible := null;
1080                 END IF;
1081 
1082                 IF l_req_rec.expense_owner = G_PA_MISS_CHAR THEN
1083                         l_req_rec.expense_owner := null;
1084                 END IF;
1085 
1086                 IF l_req_rec.expense_limit = G_PA_MISS_NUM THEN
1087                         l_req_rec.expense_limit := null;
1088                 END IF;
1089 
1090                 IF l_req_rec.orig_system_code = G_PA_MISS_CHAR THEN
1091                         l_req_rec.orig_system_code := null;
1092                 END IF;
1093 
1094                 IF l_req_rec.orig_system_reference = G_PA_MISS_CHAR THEN
1095                         l_req_rec.orig_system_reference := null;
1096                 END IF;
1097 
1098                 IF l_req_rec.record_version_number = G_PA_MISS_NUM THEN
1099                         l_req_rec.record_version_number := 1;
1100                 END IF;
1101 
1102                 IF l_req_rec.attribute_category = G_PA_MISS_CHAR THEN
1103                         l_req_rec.attribute_category := null;
1104                 END IF;
1105 
1106                 IF l_req_rec.attribute1 = G_PA_MISS_CHAR THEN
1107                         l_req_rec.attribute1 := null;
1108                 END IF;
1109 
1110                 IF l_req_rec.attribute2 = G_PA_MISS_CHAR THEN
1111                         l_req_rec.attribute2 := null;
1112                 END IF;
1113 
1114                 IF l_req_rec.attribute3 = G_PA_MISS_CHAR THEN
1115                         l_req_rec.attribute3 := null;
1116                 END IF;
1117 
1118                 IF l_req_rec.attribute4 = G_PA_MISS_CHAR THEN
1119                         l_req_rec.attribute4 := null;
1120                 END IF;
1121 
1122                 IF l_req_rec.attribute5 = G_PA_MISS_CHAR THEN
1123                         l_req_rec.attribute5 := null;
1124                 END IF;
1125 
1126                 IF l_req_rec.attribute6 = G_PA_MISS_CHAR THEN
1127                         l_req_rec.attribute6 := null;
1128                 END IF;
1129 
1130                 IF l_req_rec.attribute7 = G_PA_MISS_CHAR THEN
1131                         l_req_rec.attribute7 := null;
1132                 END IF;
1133 
1134                 IF l_req_rec.attribute8 = G_PA_MISS_CHAR THEN
1135                         l_req_rec.attribute8 := null;
1136                 END IF;
1137 
1138                 IF l_req_rec.attribute9 = G_PA_MISS_CHAR THEN
1139                         l_req_rec.attribute9 := null;
1140                 END IF;
1141 
1142                 IF l_req_rec.attribute10 = G_PA_MISS_CHAR THEN
1143                         l_req_rec.attribute10 := null;
1144                 END IF;
1145 
1146                 IF l_req_rec.attribute11 = G_PA_MISS_CHAR THEN
1147                         l_req_rec.attribute11 := null;
1148                 END IF;
1149 
1150                 IF l_req_rec.attribute12 = G_PA_MISS_CHAR THEN
1151                         l_req_rec.attribute12 := null;
1152                 END IF;
1153 
1154                 IF l_req_rec.attribute13 = G_PA_MISS_CHAR THEN
1155                         l_req_rec.attribute13 := null;
1156                 END IF;
1157 
1158                 IF l_req_rec.attribute14 = G_PA_MISS_CHAR THEN
1159                         l_req_rec.attribute14 := null;
1160                 END IF;
1161 
1162                 IF l_req_rec.attribute15 = G_PA_MISS_CHAR THEN
1163                         l_req_rec.attribute15 := null;
1164                 END IF;
1165 
1166 
1167                 -- Mandatory Parameters Check
1168                 -----------------------------
1169 
1170                 IF l_debug_mode = 'Y' THEN
1171                         pa_debug.write(l_module, 'Mandatory parameter validation starts', l_log_level);
1172                 END IF;
1173 
1174                 IF l_req_rec.number_of_requirements IS NULL THEN
1175                         l_missing_params := l_missing_params||', NUMBER_OF_REQUIREMENTS';
1176                 END IF;
1177 
1178                 IF l_req_rec.project_role_id IS NULL AND l_req_rec.project_role_name IS NULL THEN
1179                         l_missing_params := l_missing_params||', PROJECT_ROLE_ID, PROJECT_ROLE_NAME';
1180                 END IF;
1181 
1182                 IF (l_req_rec.team_template_id IS NULL AND l_req_rec.project_id IS NULL
1183                         AND l_req_rec.project_name IS NULL AND l_req_rec.project_number IS NULL
1184                      )
1185                     OR
1186                     (l_req_rec.team_template_id IS NOT NULL AND
1187                         (l_req_rec.project_id IS NOT NULL OR l_req_rec.project_name IS NOT NULL
1188                                 OR l_req_rec.project_number IS NOT NULL
1189                         )
1190                      )
1191                 THEN
1192                         -- Note that here we are supporting only Project Requirment and Team Template Requirment Flow.
1193                         -- We are not supporting  apply team template flow in which team template id and project id
1194                         -- both are present.
1195                         l_missing_params := l_missing_params||', TEAM_TEMPLATE_ID, PROJECT_ID, PROJECT_NAME, PROJECT_NUMBER';
1196                 END IF;
1197 
1198                 IF l_req_rec.start_date IS NULL OR l_req_rec.end_date IS NULL THEN
1199                         l_missing_params := l_missing_params||', START_DATE, END_DATE';
1200                 END IF;
1201 
1202                 -- Requirment status is not mandatory, if not passed we default it to 101 (Open)
1203                 --IF l_req_rec.status_code IS NULL AND l_req_rec.status_name IS NULL THEN
1204                 --        l_missing_params := l_missing_params||', STATUS_CODE, STATUS_NAME';
1205                 --END IF;
1206                 IF l_req_rec.status_code IS NULL AND l_req_rec.status_name IS NULL THEN
1207                        l_req_rec.status_code := 101;
1208                 END IF;
1209 
1210                 IF l_req_rec.location_id IS NULL OR l_req_rec.location_id = FND_API.G_MISS_NUM THEN
1211                         -- If either city or state (or) both are passed ,then country is
1212                         -- mandatory
1213                         IF (l_req_rec.location_country_code IS NULL AND l_req_rec.location_country_name IS NULL)
1214                            OR (l_req_rec.location_country_code =  FND_API.G_MISS_CHAR AND l_req_rec.location_country_name = FND_API.G_MISS_CHAR)
1215                         THEN
1216                                 IF (l_req_rec.location_region <> FND_API.G_MISS_CHAR AND l_req_rec.location_region IS NOT NULL)
1217                                     OR (l_req_rec.location_city <> FND_API.G_MISS_CHAR AND l_req_rec.location_city IS NOT NULL)
1218                                 THEN
1219                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE, LOCATION_COUNTRY_NAME';
1220                                         l_valid_country := 'N';
1221                                 END IF;
1222                         ELSIF l_req_rec.location_country_code IS NOT NULL AND l_req_rec.location_country_code <> FND_API.G_MISS_CHAR
1223                         THEN
1224                                 OPEN c_derive_country_name(l_req_rec.location_country_code);
1225                                 FETCH c_derive_country_name INTO l_req_rec.location_country_name;
1226                                 IF c_derive_country_name%NOTFOUND THEN
1227                                         -- Invalid Country code passed.
1228                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE';
1229                                         l_valid_country := 'N';
1230                                 ELSE
1231                                         l_valid_country := 'Y';
1232                                 END IF;
1233                                 CLOSE c_derive_country_name;
1234                         ELSIF l_req_rec.location_country_name IS NOT NULL AND l_req_rec.location_country_name <> FND_API.G_MISS_CHAR
1235                         THEN
1236                               OPEN c_derive_country_code(l_req_rec.location_country_name);
1237                               FETCH c_derive_country_code INTO l_req_rec.location_country_code;
1238                               IF c_derive_country_code%NOTFOUND THEN
1239                                         -- Invalid Country Name passed.
1240                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_NAME';
1241                                         l_valid_country := 'N';
1242                                ELSE
1243                                         l_valid_country := 'Y';
1244                               END IF;
1245                               CLOSE c_derive_country_code;
1246                         END IF;
1247 
1248                         -- If the country is valid,then proceed with the state and city validations
1249                         IF l_valid_country = 'Y' AND l_req_rec.location_country_code IS NOT NULL
1250                         AND l_req_rec.location_country_code <> FND_API.G_MISS_CHAR
1251                         THEN
1252 
1253                                 l_dummy_country_code := l_req_rec.location_country_code;
1254                                 IF l_req_rec.location_region IS NULL OR l_req_rec.location_region = FND_API.G_MISS_CHAR THEN
1255                                         l_dummy_state := null;
1256                                 ELSE
1257                                         l_dummy_state := l_req_rec.location_region;
1258                                 END IF;
1259 
1260                                 IF l_req_rec.location_city IS NULL OR l_req_rec.location_city = FND_API.G_MISS_CHAR THEN
1261                                         l_dummy_city := null;
1262                                 ELSE
1263                                         l_dummy_city := l_req_rec.location_city;
1264                                 END IF;
1265 
1266                                 PA_LOCATION_UTILS.CHECK_LOCATION_EXISTS
1267                                 (
1268                                          p_country_code         => l_dummy_country_code
1269                                         ,p_city		        => l_dummy_city
1270                                         ,p_region	        => l_dummy_state
1271                                         ,x_location_id	        => l_out_location_id
1272                                         ,x_return_status        => l_return_status
1273                                 );
1274 
1275                                 IF l_out_location_id IS NULL THEN
1276                                         PA_UTILS.ADD_MESSAGE('PA','PA_AMG_RES_INV_CRC_COMB');
1277                                         l_error_flag_local := 'Y'; -- 5148975
1278                                 ELSE
1279                                         l_req_rec.location_id := l_out_location_id;
1280                                 END IF;
1281                         END IF;
1282                 ELSE
1283                         -- if location id is passed, then it will override the city, region, country code
1284                         OPEN c_get_location(l_req_rec.location_id);
1285                         FETCH c_get_location INTO l_req_rec.location_country_code, l_req_rec.location_region, l_req_rec.location_city;
1286 
1287                         IF c_get_location%NOTFOUND THEN
1288                                 l_missing_params := l_missing_params||', LOCATION_ID';
1289                         END IF;
1290                         CLOSE c_get_location;
1291                 END IF; -- l_req_rec.location_id IS NULL OR l_req_rec.location_id = FND_API.G_MISS_NUM
1292 
1293 
1294                 IF l_req_rec.team_template_id IS NULL THEN
1295                         -- Project Requirement Flow
1296 
1297                         IF l_req_rec.calendar_type IS NULL OR (l_req_rec.calendar_type NOT IN('PROJECT','OTHER')) THEN
1298                                 l_missing_params := l_missing_params||', CALENDAR_TYPE';
1299                         ELSE
1300                                 IF l_req_rec.calendar_type = 'OTHER' AND l_req_rec.calendar_id IS NULL
1301                                         AND l_req_rec.calendar_name IS NULL
1302                                 THEN
1303                                         l_missing_params := l_missing_params||', CALENDAR_ID, CALENDAR_NAME';
1304                                 END IF;
1305                         END IF;
1306 
1307                         -- 5148545 : Added check for search org hier and start org name
1308                         IF l_req_rec.search_exp_org_str_ver_id IS NULL AND l_req_rec.search_exp_org_hier_name IS NULL
1309                         AND (l_req_rec.search_exp_start_org_id IS NOT NULL OR l_req_rec.search_exp_start_org_name IS NOT NULL) THEN
1310                                 l_missing_params := l_missing_params||', SEARCH_EXP_ORG_STR_VER_ID, SEARCH_EXP_ORG_HIER_NAME';
1311                         END IF;
1312 
1313                         IF l_req_rec.search_exp_start_org_id IS NULL AND l_req_rec.search_exp_start_org_name IS NULL
1314                         AND (l_req_rec.search_exp_org_str_ver_id IS NOT NULL OR l_req_rec.search_exp_org_hier_name IS NOT NULL) THEN
1315                                 l_missing_params := l_missing_params||', SEARCH_EXP_START_ORG_ID, SEARCH_EXP_START_ORG_NAME';
1316                         END IF;
1317 
1318 
1319                         IF l_req_rec.bill_rate_option IS NULL OR l_req_rec.bill_rate_option NOT IN('RATE','MARKUP','DISCOUNT','NONE') THEN
1320                                 l_missing_params := l_missing_params||', BILL_RATE_OPTION';
1321                         ELSE
1322                                 IF l_req_rec.bill_rate_option = 'NONE' THEN
1323                                         l_req_rec.bill_rate_override := null;
1324                                         l_req_rec.bill_rate_curr_override := null;
1325                                         l_req_rec.markup_percent_override := null;
1326                                         l_req_rec.discount_percentage := null;
1327                                         l_req_rec.rate_disc_reason_code := null;
1328                                 ELSIF l_req_rec.bill_rate_option = 'RATE' THEN
1329                                         l_req_rec.markup_percent_override := null;
1330                                         l_req_rec.discount_percentage := null;
1331                                         IF l_req_rec.bill_rate_override IS NULL THEN
1332                                                 l_missing_params := l_missing_params||', BILL_RATE_OVERRIDE';
1333                                         END IF;
1334                                 ELSIF l_req_rec.bill_rate_option = 'MARKUP' THEN
1335                                         l_req_rec.bill_rate_override := null;
1336                                         l_req_rec.bill_rate_curr_override := null;
1337                                         l_req_rec.discount_percentage := null;
1338                                         IF l_req_rec.markup_percent_override IS NULL THEN
1339                                                 l_missing_params := l_missing_params||', MARKUP_PERCENT_OVERRIDE';
1340                                         END IF;
1341                                 ELSIF l_req_rec.bill_rate_option = 'DISCOUNT' THEN
1342                                         l_req_rec.bill_rate_override := null;
1343                                         l_req_rec.bill_rate_curr_override := null;
1344                                         l_req_rec.markup_percent_override := null;
1345                                         IF l_req_rec.discount_percentage IS NULL THEN
1346                                                 l_missing_params := l_missing_params||', DISCOUNT_PERCENTAGE';
1347                                         END IF;
1348                                 END IF;
1349                         END IF;
1350 
1351                         IF l_req_rec.expenditure_type_class IS NULL AND l_req_rec.expenditure_type IS NOT NULL THEN
1352                                 -- Expenditue type is specified then class must also be there
1353                                 l_missing_params := l_missing_params||', EXPENDITURE_TYPE_CLASS';
1354                         ELSIF l_req_rec.expenditure_type_class IS NOT NULL AND l_req_rec.expenditure_type IS NULL THEN
1355                                 l_missing_params := l_missing_params||', EXPENDITURE_TYPE';
1356                         END IF;
1357 
1358                         IF l_req_rec.tp_rate_option IS NULL OR l_req_rec.tp_rate_option NOT IN('RATE','BASIS','NONE') THEN
1359                                 l_missing_params := l_missing_params||', TP_RATE_OPTION';
1360                         ELSE
1361                                 IF l_req_rec.tp_rate_option = 'NONE' THEN
1362                                         l_req_rec.tp_rate_override := null;
1363                                         l_req_rec.tp_currency_override := null;
1364                                         l_req_rec.tp_calc_base_code_override := null;
1365                                         l_req_rec.tp_percent_applied_override := null;
1366                                 ELSIF l_req_rec.tp_rate_option = 'RATE' THEN
1367                                         l_req_rec.tp_calc_base_code_override := null;
1368                                         l_req_rec.tp_percent_applied_override := null;
1369                                         IF l_req_rec.tp_rate_override IS NULL OR l_req_rec.tp_currency_override IS NULL THEN
1370                                                 l_missing_params := l_missing_params||', TP_RATE_OVERRIDE, TP_CURRENCY_OVERRIDE';
1371                                         END IF;
1372                                 ELSIF l_req_rec.tp_rate_option = 'BASIS' THEN
1373                                         l_req_rec.tp_rate_override := null;
1374                                         l_req_rec.tp_currency_override := null;
1375                                         IF l_req_rec.tp_calc_base_code_override IS NULL OR l_req_rec.tp_percent_applied_override IS NULL THEN
1376                                                 l_missing_params := l_missing_params||', TP_CALC_BASE_CODE_OVERRIDE, TP_PERCENT_APPLIED_OVERRIDE';
1377                                         END IF;
1378                                 END IF;
1379                         END IF;
1380 
1381                         IF l_req_rec.extension_possible IS NOT NULL AND l_req_rec.extension_possible NOT IN ('Y','N') THEN
1382                                 l_missing_params := l_missing_params||', EXTENSION_POSSIBLE';
1383                         END IF;
1384                 END IF; -- l_req_rec.team_template_id IS NULL THEN
1385 
1386                 IF l_debug_mode = 'Y' THEN
1387                         pa_debug.write(l_module, 'Mandatory parameter validation over. List of Missing Parameters='||l_missing_params, l_log_level);
1388                 END IF;
1389 
1390                 IF l_missing_params IS NOT NULL THEN
1391                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
1392                                                 'INVALID_PARAMS', l_missing_params);
1393                         l_error_flag_local := 'Y';
1394                 END IF;
1395 
1396                 -- NullOut parameters which are not required in team template flow
1397                 IF l_req_rec.team_template_id IS NOT NULL THEN
1398                         -- Team Template flow
1399                         l_req_rec.extension_possible := null;
1400                         --5152025 : Mistakenly work_type_id and work_type_name was getting nulled out
1401                         --l_req_rec.work_type_id := null;
1402                         --l_req_rec.work_type_name := null;
1403                         l_req_rec.bill_rate_override := null;
1404                         l_req_rec.bill_rate_curr_override := null;
1405                         l_req_rec.markup_percent_override := null;
1406                         l_req_rec.discount_percentage := null;
1407                         l_req_rec.rate_disc_reason_code := null;
1408                         l_req_rec.tp_rate_override := null;
1409                         l_req_rec.tp_currency_override := null;
1410                         l_req_rec.tp_calc_base_code_override := null;
1411                         l_req_rec.tp_percent_applied_override := null;
1412                         l_req_rec.expense_owner := null;
1413                         l_req_rec.expense_limit := null;
1414                         l_req_rec.fcst_job_id := null;
1415                         l_req_rec.fcst_job_group_id := null;
1416                         l_req_rec.expenditure_org_id := null;
1417                         l_req_rec.expenditure_organization_id := null;
1418                         l_req_rec.expenditure_type_class := null;
1419                         l_req_rec.expenditure_type := null;
1420                         l_req_rec.fcst_job_group_name := null;
1421                         l_req_rec.fcst_job_name := null;
1422                         l_req_rec.expenditure_org_name := null;
1423                         l_req_rec.expenditure_organization_name := null;
1424                         l_req_rec.start_adv_action_set_flag := null;
1425                         l_req_rec.adv_action_set_id := null;
1426                         l_req_rec.adv_action_set_name := null;
1427                 END IF; -- l_req_rec.team_template_id IS NOT NULL THEN
1428 
1429 
1430                 -- Project Name, Number to ID Conversion
1431                 -- Though it is done by pa_assignmnts_pub.create_assignment
1432                 -- But we require to get project_id so that we can defualt
1433                 -- values from the project and check security on project
1434                 -- Also project name to id conversion does not happen by internal APIs
1435                 IF l_debug_mode = 'Y' THEN
1436                         pa_debug.write(l_module, 'Deriving ProjectId', l_log_level);
1437                 END IF;
1438 
1439                 IF l_error_flag_local <> 'Y' AND l_req_rec.team_template_id IS NULL THEN
1440                         l_project_id_tmp := l_req_rec.project_id;
1441                         IF l_req_rec.project_number IS NOT NULL THEN
1442                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1443                                 l_error_message_code := null;
1444 
1445                                 PA_PROJECT_UTILS2.CHECK_PROJECT_NUMBER_OR_ID(
1446                                          p_project_id           => l_project_id_tmp
1447                                         ,p_project_number       => l_req_rec.project_number
1448                                         ,p_check_id_flag        => PA_STARTUP.g_check_id_flag
1449                                         ,x_project_id           => l_req_rec.project_id
1450                                         ,x_return_status        => l_return_status
1451                                         ,x_error_message_code   => l_error_message_code );
1452 
1453                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1454                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1455                                         l_error_flag_local := 'Y';
1456                                 END IF;
1457                         END IF;
1458                         IF l_req_rec.project_name IS NOT NULL THEN
1459                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1460                                 l_error_message_code := null;
1461 
1462                                 PA_TASKS_MAINT_UTILS.CHECK_PROJECT_NAME_OR_ID(
1463                                          p_project_id           => l_project_id_tmp
1464                                         ,p_project_name         => l_req_rec.project_name
1465                                         ,p_check_id_flag        => PA_STARTUP.g_check_id_flag
1466                                         ,x_project_id           => l_req_rec.project_id
1467                                         ,x_return_status        => l_return_status
1468                                         ,x_error_msg_code       => l_error_message_code );
1469 
1470                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1471                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1472                                         l_error_flag_local := 'Y';
1473                                 END IF;
1474                         END IF;
1475                 END IF; -- l_error_flag_local <> 'Y' AND l_req_rec.team_template_id IS NULL
1476 
1477                 IF l_debug_mode = 'Y' THEN
1478                         pa_debug.write(l_module, 'ProjectId='||l_req_rec.project_id, l_log_level);
1479                         pa_debug.write(l_module, 'TeamTemplateId='||l_req_rec.team_template_id, l_log_level);
1480                         pa_debug.write(l_module, 'l_error_flag_local='||l_error_flag_local, l_log_level);
1481                 END IF;
1482 
1483                 IF l_error_flag_local <> 'Y' AND l_req_rec.team_template_id IS NULL THEN
1484                         -- Project Requirement Flow
1485                         l_role_list_id := null;
1486                         l_multi_currency_billing_flag := null;
1487                         l_calendar_id := null;
1488                         l_work_type_id := null;
1489                         l_location_id := null;
1490 
1491                         OPEN c_get_project_dtls(l_req_rec.project_id);
1492                         FETCH c_get_project_dtls INTO l_role_list_id, l_multi_currency_billing_flag, l_calendar_id
1493                                 , l_work_type_id, l_location_id;
1494                         CLOSE c_get_project_dtls;
1495 
1496                         IF l_req_rec.bill_rate_option = 'RATE' AND  nvl(l_multi_currency_billing_flag,'N') <> 'Y'
1497                         THEN
1498                                 l_req_rec.bill_rate_curr_override := null;
1499                         END IF;
1500                 ELSIF l_error_flag_local <> 'Y' AND l_req_rec.team_template_id IS NOT NULL THEN
1501                         -- Team Template Flow
1502                         l_role_list_id := null;
1503                         l_multi_currency_billing_flag := null;
1504                         l_calendar_id := null;
1505                         l_work_type_id := null;
1506                         OPEN c_get_team_templ_dtls(l_req_rec.team_template_id);
1507                         FETCH c_get_team_templ_dtls INTO l_role_list_id, l_calendar_id, l_work_type_id;
1508                         CLOSE c_get_team_templ_dtls;
1509                 END IF;
1510 
1511                 IF l_debug_mode = 'Y' THEN
1512                         pa_debug.write(l_module, 'Defaults Value from Project or Team Template Flow', l_log_level);
1513                         pa_debug.write(l_module, 'l_role_list_id='||l_role_list_id, l_log_level);
1514                         pa_debug.write(l_module, 'l_multi_currency_billing_flag='||l_multi_currency_billing_flag, l_log_level);
1515                         pa_debug.write(l_module, 'l_calendar_id='||l_calendar_id, l_log_level);
1516                         pa_debug.write(l_module, 'l_work_type_id='||l_work_type_id, l_log_level);
1517                         pa_debug.write(l_module, 'l_location_id='||l_location_id, l_log_level);
1518                 END IF;
1519 
1520 
1521                 -- Default calendar, location, work type, requirement name, min max res job level
1522                 IF l_error_flag_local <> 'Y' THEN
1523                         IF l_debug_mode = 'Y' THEN
1524                                 pa_debug.write(l_module, 'Default values of calendar, work type, location from project or team template', l_log_level);
1525                         END IF;
1526 
1527                         -- For OTHER type of calendar there is alredy check done above in code
1528                         -- For PROJECT type ignore the user value and take the project value
1529                         IF l_req_rec.calendar_type = 'PROJECT' THEN
1530                                 l_req_rec.calendar_id := l_calendar_id;
1531                         END IF;
1532 
1533                         IF l_req_rec.work_type_id IS NULL AND l_req_rec.work_type_name IS NULL
1534                         THEN
1535                                 l_req_rec.work_type_id := l_work_type_id;
1536                         END IF;
1537 
1538                         IF l_req_rec.project_id IS NOT NULL AND l_req_rec.location_id = FND_API.G_MISS_NUM
1539                                 AND l_req_rec.location_country_code = FND_API.G_MISS_CHAR
1540                                 AND l_req_rec.location_country_name = FND_API.G_MISS_CHAR
1541                                 AND l_req_rec.location_region = FND_API.G_MISS_CHAR
1542                                 AND l_req_rec.location_city = FND_API.G_MISS_CHAR
1543                         THEN
1544                                 l_req_rec.location_id := l_location_id;
1545                         END IF;
1546 
1547                         -- Role Validation
1548                         -- Though it is done by pa_assignmnts_pub.create_assignment
1549                         -- But we require to get role_id so that we can defualt
1550                         -- values from the role
1551                         -- Defaulting is required
1552 
1553                         IF l_debug_mode = 'Y' THEN
1554                                 pa_debug.write(l_module, 'Validating Role against Role List and doing Role Name to ID conversion', l_log_level);
1555                         END IF;
1556 
1557                         l_return_status := FND_API.G_RET_STS_SUCCESS;
1558                         l_error_message_code := null;
1559                         l_project_role_id_tmp := l_req_rec.project_role_id;
1560 
1561                         PA_ROLE_UTILS.Check_Role_RoleList (
1562                                 p_role_id               => l_project_role_id_tmp
1563                                 ,p_role_name            => l_req_rec.project_role_name
1564                                 ,p_role_list_id         => l_role_list_id
1565                                 ,p_role_list_name       => NULL
1566                                 ,p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag
1567                                 ,x_role_id              => l_req_rec.project_role_id
1568                                 ,x_role_list_id         => l_role_list_id
1569                                 ,x_return_status        => l_return_status
1570                                 ,x_error_message_code   => l_error_message_code );
1571 
1572                         IF l_debug_mode = 'Y' THEN
1573                                 pa_debug.write(l_module, 'After role validation Role id='||l_req_rec.project_role_id, l_log_level);
1574                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1575                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1576                         END IF;
1577 
1578                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1579                                 PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1580                                 l_error_flag_local := 'Y';
1581                         END IF;
1582 
1583                         IF l_debug_mode = 'Y' THEN
1584                                 pa_debug.write(l_module, 'Defaulting RequirmentName, Min Job Level, Max Job Level from Role ', l_log_level);
1585                         END IF;
1586 
1587                         l_role_name := null;
1588                         l_min_job_level := null;
1589                         l_max_job_level := null;
1590                         l_fcst_job_id := null;
1591 
1592                         OPEN c_get_role_dtls(l_req_rec.project_role_id);
1593                         FETCH c_get_role_dtls INTO l_role_name, l_min_job_level, l_max_job_level, l_fcst_job_id;
1594                         CLOSE c_get_role_dtls;
1595 
1596                         IF l_req_rec.requirement_name IS NULL THEN
1597                                 l_req_rec.requirement_name := l_role_name;
1598                         END IF;
1599                         IF l_req_rec.min_resource_job_level IS NULL THEN
1600                                 l_req_rec.min_resource_job_level := l_min_job_level;
1601                         END IF;
1602                         IF l_req_rec.max_resource_job_level IS NULL THEN
1603                                 l_req_rec.max_resource_job_level := l_max_job_level;
1604                         END IF;
1605 
1606                         IF l_debug_mode = 'Y' THEN
1607                                 pa_debug.write(l_module, 'l_role_name='||l_role_name, l_log_level);
1608                                 pa_debug.write(l_module, 'l_min_job_level='||l_min_job_level, l_log_level);
1609                                 pa_debug.write(l_module, 'l_max_job_level='||l_max_job_level, l_log_level);
1610                         END IF;
1611                 END IF; -- l_error_flag_local <> 'Y' THEN
1612 
1613                 -- All validations are not required as some validation is done in underlying code
1614                 -- Here, we are doing only those validations which are not done internally.
1615                 -- NOTE : In update flow, all these validations are done and it is taken from there
1616                 --        Ideally in create flow also, underlying code should do these validations
1617                 --        But we are doing here to avoid more code changes in existing code.
1618 
1619                 IF l_error_flag_local <> 'Y' AND l_req_rec.project_id IS NOT NULL THEN
1620                         -- Project Requirement Flow
1621 
1622                         -- Search Info Validation
1623                         -------------------------
1624 
1625 
1626                         -- 5147921 : In create requirment flow, weightages were not checked between 0 and 100
1627                         -- They are checked by internal API in update flow but not in create flow.
1628                         -- Hence added checks here
1629 
1630                         IF (l_req_rec.comp_match_weighting IS NOT NULL AND (l_req_rec.comp_match_weighting < 0 OR l_req_rec.comp_match_weighting > 100))
1631                         OR (l_req_rec.avail_match_weighting IS NOT NULL AND (l_req_rec.avail_match_weighting < 0 OR l_req_rec.avail_match_weighting > 100))
1632                         OR (l_req_rec.job_level_match_weighting IS NOT NULL AND (l_req_rec.job_level_match_weighting < 0 OR l_req_rec.job_level_match_weighting > 100))
1633                         THEN
1634                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_MATCH_WEIGHTING');
1635                                 l_error_flag_local := 'Y';
1636                         END IF;
1637 
1638                         IF l_req_rec.search_min_availability IS NOT NULL AND (l_req_rec.search_min_availability < 0 OR l_req_rec.search_min_availability > 100)
1639                         THEN
1640                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_MIN_AVAIL_INVALID');
1641                                 l_error_flag_local := 'Y';
1642                         END IF;
1643 
1644                         IF l_req_rec.search_min_candidate_score IS NOT NULL AND (l_req_rec.search_min_candidate_score < 0 OR l_req_rec.search_min_candidate_score > 100 )
1645                         THEN
1646                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_MIN_CAN_SCORE_INVALID');
1647                                 l_error_flag_local := 'Y';
1648                         END IF;
1649 
1650                         IF (l_req_rec.search_country_code IS NOT NULL AND l_req_rec.search_country_code <> FND_API.G_MISS_CHAR)
1651                                 OR (l_req_rec.search_country_name IS NOT NULL AND l_req_rec.search_country_name <> FND_API.G_MISS_CHAR)
1652                         THEN
1653                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1654                                 l_error_message_code := null;
1655                                 l_search_country_code_tmp := l_req_rec.search_country_code;
1656 
1657                                 IF l_debug_mode = 'Y' THEN
1658                                         pa_debug.write(l_module, 'Validating Search Country Code and Name to Code Conversion', l_log_level);
1659                                 END IF;
1660 
1661                                 PA_LOCATION_UTILS.CHECK_COUNTRY_NAME_OR_CODE
1662                                         (p_country_code         => l_search_country_code_tmp,
1663                                         p_country_name          => l_req_rec.search_country_name,
1664                                         p_check_id_flag         => PA_STARTUP.G_Check_ID_Flag,
1665                                         x_country_code          => l_req_rec.search_country_code,
1666                                         x_return_status         => l_return_status,
1667                                         x_error_message_code    => l_error_message_code);
1668 
1669                                 IF l_debug_mode = 'Y' THEN
1670                                         pa_debug.write(l_module, 'After Search Country Code Validation l_req_rec.search_country_code='||l_req_rec.search_country_code, l_log_level);
1671                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1672                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1673                                 END IF;
1674 
1675                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1676                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1677                                         l_error_flag_local := 'Y';
1678                                 END IF;
1679                         END IF;   -- l_req_rec.search_country_code IS NOT NULL
1680 
1681                         IF l_req_rec.search_exp_org_hier_name IS NOT NULL OR l_req_rec.search_exp_org_str_ver_id IS NOT NULL THEN
1682                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1683                                 l_error_message_code := null;
1684                                 l_srch_exp_org_str_ver_id_tmp := l_req_rec.search_exp_org_str_ver_id;
1685 
1686                                 IF l_debug_mode = 'Y' THEN
1687                                         pa_debug.write(l_module, 'Validating Search Organization Hierarchy and Name to ID Conversion', l_log_level);
1688                                 END IF;
1689 
1690                                 PA_HR_ORG_UTILS.CHECK_ORGHIERNAME_OR_ID
1691                                         (p_org_hierarchy_version_id     => l_srch_exp_org_str_ver_id_tmp,
1692                                         p_org_hierarchy_name            => l_req_rec.search_exp_org_hier_name,
1693                                         p_check_id_flag                 => PA_STARTUP.G_Check_ID_Flag,
1694                                         x_org_hierarchy_version_id      => l_req_rec.search_exp_org_str_ver_id,
1695                                         x_return_status                 => l_return_status,
1696                                         x_error_msg_code                => l_error_message_code);
1697 
1698                                 IF l_debug_mode = 'Y' THEN
1699                                         pa_debug.write(l_module, 'After Search Organization Hierarchy Validation l_req_rec.search_exp_org_str_ver_id='||l_req_rec.search_exp_org_str_ver_id, l_log_level);
1700                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1701                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1702                                 END IF;
1703 
1704 
1705                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1706                                         -- PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1707 					PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_SRCH_ORG_HIER_NA');      -- Changed for Bug 5148154
1708                                         l_error_flag_local := 'Y';
1709                                 ELSE
1710                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
1711                                         l_error_message_code := null;
1712 
1713                                         IF l_debug_mode = 'Y' THEN
1714                                                 pa_debug.write(l_module, 'Validating Search Organization Hierarchy Type', l_log_level);
1715                                         END IF;
1716 
1717                                         PA_ORG_UTILS.CHECK_ORGHIERARCHY_TYPE(
1718                                                 p_org_structure_version_id      => l_req_rec.search_exp_org_str_ver_id,
1719                                                 p_org_structure_type            => 'EXPENDITURES',
1720                                                 x_return_status                 => l_return_status,
1721                                                 x_error_message_code            => l_error_message_code);
1722 
1723                                         IF l_debug_mode = 'Y' THEN
1724                                                 pa_debug.write(l_module, 'After Search Organization Hierarchy Type Validation', l_log_level);
1725                                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1726                                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1727                                         END IF;
1728 
1729                                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1730                                                 PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1731                                                 l_error_flag_local := 'Y';
1732                                         END IF;
1733                                 END IF;
1734                         END IF; -- l_req_rec.search_exp_org_hier_name IS NOT NULL
1735 
1736                         IF l_req_rec.search_exp_start_org_name IS NOT NULL OR l_req_rec.search_exp_start_org_id IS NOT NULL THEN
1737                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1738                                 l_error_message_code := null;
1739                                 l_search_exp_start_org_id_tmp := l_req_rec.search_exp_start_org_id;
1740 
1741                                 IF l_debug_mode = 'Y' THEN
1742                                         pa_debug.write(l_module, 'Validating Search Organization and Name to ID Conversion', l_log_level);
1743                                 END IF;
1744 
1745                                 PA_HR_ORG_UTILS.CHECK_ORGNAME_OR_ID
1746                                         (p_organization_id      => l_search_exp_start_org_id_tmp,
1747                                         p_organization_name     => l_req_rec.search_exp_start_org_name,
1748                                         p_check_id_flag         => PA_STARTUP.G_Check_ID_Flag,
1749                                         x_organization_id       => l_req_rec.search_exp_start_org_id,
1750                                         x_return_status         => l_return_status,
1751                                         x_error_msg_code        => l_error_message_code);
1752 
1753                                 IF l_debug_mode = 'Y' THEN
1754                                         pa_debug.write(l_module, 'After Search Organization Name Validation', l_log_level);
1755                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1756                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1757                                 END IF;
1758 
1759                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1760                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1761                                         l_error_flag_local := 'Y';
1762                                 ELSE
1763                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
1764                                         l_error_message_code := null;
1765 
1766                                         IF l_debug_mode = 'Y' THEN
1767                                                 pa_debug.write(l_module, 'Validating Search Organization Type', l_log_level);
1768                                         END IF;
1769 
1770                                         PA_ORG_UTILS.CHECK_ORG_TYPE(
1771                                                 p_organization_id       => l_req_rec.search_exp_start_org_id,
1772                                                 p_org_structure_type    => 'EXPENDITURES',
1773                                                 x_return_status         => l_return_status,
1774                                                 x_error_message_code    => l_error_message_code);
1775 
1776                                         IF l_debug_mode = 'Y' THEN
1777                                                 pa_debug.write(l_module, 'After Search Organization Type Validation', l_log_level);
1778                                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1779                                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1780                                         END IF;
1781 
1782                                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1783                                                 PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1784                                                 l_error_flag_local := 'Y';
1785                                         END IF;
1786                                 END IF;
1787                         END IF; -- l_req_rec.search_exp_start_org_name IS NOT NULL
1788 
1789                         IF l_req_rec.search_exp_org_str_ver_id IS NOT NULL AND l_req_rec.search_exp_start_org_id IS NOT NULL THEN
1790                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1791                                 l_error_message_code := null;
1792 
1793                                 IF l_debug_mode = 'Y' THEN
1794                                         pa_debug.write(l_module, 'Validating Search Organization wrt Search Org Hierarchy', l_log_level);
1795                                 END IF;
1796 
1797                                 PA_ORG_UTILS.CHECK_ORG_IN_ORGHIERARCHY(
1798                                 p_organization_id               => l_req_rec.search_exp_start_org_id,
1799                                 p_org_structure_version_id      => l_req_rec.search_exp_org_str_ver_id,
1800                                 p_org_structure_type            => 'EXPENDITURES',
1801                                 x_return_status                 => l_return_status,
1802                                 x_error_message_code            => l_error_message_code);
1803 
1804                                 IF l_debug_mode = 'Y' THEN
1805                                         pa_debug.write(l_module, 'After Search wrt Search Org Hierarchy Validation', l_log_level);
1806                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1807                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1808                                 END IF;
1809 
1810                                 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1811                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1812                                         l_error_flag_local := 'Y';
1813                                 END IF;
1814                         END IF;
1815 
1816                         -- Financial Information Validation
1817                         -----------------------------------
1818 
1819                         IF l_req_rec.expenditure_org_id IS NOT NULL OR l_req_rec.expenditure_org_name IS NOT NULL THEN
1820                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1821                                 l_error_message_code := null;
1822                                 l_expenditure_org_id_tmp := l_req_rec.expenditure_org_id;
1823 
1824                                 IF l_debug_mode = 'Y' THEN
1825                                         pa_debug.write(l_module, 'Validating Expenditure OU and Name to ID conversion', l_log_level);
1826                                 END IF;
1827 
1828                                 PA_HR_ORG_UTILS.CHECK_ORGNAME_OR_ID
1829                                         (p_organization_id      => l_expenditure_org_id_tmp,
1830                                         p_organization_name     => l_req_rec.expenditure_org_name,
1831                                         p_check_id_flag         => PA_STARTUP.G_Check_ID_Flag,
1832                                         x_organization_id       => l_req_rec.expenditure_org_id,
1833                                         x_return_status         => l_return_status,
1834                                         x_error_msg_code        => l_error_message_code );
1835 
1836                                 IF l_debug_mode = 'Y' THEN
1837                                         pa_debug.write(l_module, 'After Expenditure OU Validation l_req_rec.expenditure_org_id='||l_req_rec.expenditure_org_id, l_log_level);
1838                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1839                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1840                                 END IF;
1841 
1842                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1843                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_EXP_OU_INVALID');
1844                                         l_error_flag_local := 'Y';
1845                                 ELSE
1846                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
1847                                         l_error_message_code := null;
1848 
1849                                         IF l_debug_mode = 'Y' THEN
1850                                                 pa_debug.write(l_module, 'Validating OU to be used in PA Implementation', l_log_level);
1851                                         END IF;
1852 
1853                                         PA_HR_UPDATE_API.CHECK_EXP_OU
1854                                                 (p_org_id             => l_req_rec.expenditure_org_id
1855                                                 ,x_return_status      => l_return_status
1856                                                 ,x_error_message_code => l_error_message_code ) ;
1857 
1858                                         IF l_debug_mode = 'Y' THEN
1859                                                 pa_debug.write(l_module, 'After Expenditure OU to be used in PA Implementation Validation', l_log_level);
1860                                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1861                                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1862                                         END IF;
1863 
1864                                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1865                                                 PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1866                                                 l_error_flag_local := 'Y';
1867 					-- Start 1: Changed for Bug 5202329
1868                                         ELSE
1869                                                 SELECT business_group_id
1870                                                 INTO l_business_group_id
1871                                                 FROM hr_organization_units
1872                                                 WHERE organization_id = l_req_rec.expenditure_org_id;
1873                                         END IF;
1874 					-- End 1: Changed for Bug 5202329
1875                                 END IF;
1876                         END IF; -- l_req_rec.expenditure_org_id IS NOT NULL
1877 
1878 			-- l_error_flag_local <> 'Y' for Bug 5202329
1879                         IF l_error_flag_local <> 'Y' AND (l_req_rec.expenditure_organization_id IS NOT NULL
1880 			   OR l_req_rec.expenditure_organization_name IS NOT NULL) THEN
1881                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1882                                 l_error_message_code := null;
1883                                 l_exp_organization_id_tmp := l_req_rec.expenditure_organization_id;
1884 
1885                                 IF l_debug_mode = 'Y' THEN
1886                                         pa_debug.write(l_module, 'Validating Expenditure Organization and Name to ID conversion', l_log_level);
1887                                 END IF;
1888 
1889                                 PA_HR_ORG_UTILS.CHECK_ORGNAME_OR_ID
1890                                         (p_organization_id      => l_exp_organization_id_tmp,
1891                                         p_organization_name     => l_req_rec.expenditure_organization_name,
1892                                         p_check_id_flag         => PA_STARTUP.G_Check_ID_Flag,
1893                                         x_organization_id       => l_req_rec.expenditure_organization_id,
1894                                         x_return_status         => l_return_status,
1895                                         x_error_msg_code        => l_error_message_code );
1896 
1897                                 IF l_debug_mode = 'Y' THEN
1898                                         pa_debug.write(l_module, 'After Expenditure Organization Validation', l_log_level);
1899                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1900                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1901                                 END IF;
1902 
1903 				-- Start 2: Changes for Bug 5202329
1904                                 IF l_error_message_code = 'PA_ORG_NOT_UNIQUE' AND l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1905                                         OPEN c_get_exp_organization_id(l_business_group_id, l_req_rec.expenditure_organization_name);
1906                                         FETCH c_get_exp_organization_id INTO l_req_rec.expenditure_organization_id;
1907                                         IF c_get_exp_organization_id%NOTFOUND IS NULL THEN
1908                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_EXP_ORG_INVALID');
1909                                                 l_error_flag_local := 'Y';
1910                                         END IF;
1911                                         CLOSE c_get_exp_organization_id;
1912                                 END IF;
1913                                 IF l_error_message_code <> 'PA_ORG_NOT_UNIQUE' AND l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1914                                 -- IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1915 				-- End 2: Changes for Bug 5202329
1916                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_EXP_ORG_INVALID');
1917                                         l_error_flag_local := 'Y';
1918                                 ELSE
1919                                         l_valid_flag := null;
1920 
1921                                         IF l_debug_mode = 'Y' THEN
1922                                                 pa_debug.write(l_module, 'Validating Expenditure Organization to be used in PA', l_log_level);
1923                                         END IF;
1924 
1925                                         l_valid_flag := PA_UTILS2.CHECKEXPORG
1926                                                 (x_org_id       => l_req_rec.expenditure_organization_id,
1927                                                 x_txn_date      => l_req_rec.start_date);
1928 
1929                                         IF l_debug_mode = 'Y' THEN
1930                                                 pa_debug.write(l_module, 'After Expenditure Organization to be used in PA Implementation Validation', l_log_level);
1931                                                 pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
1932                                         END IF;
1933 
1934                                         IF l_valid_flag <> 'Y' THEN
1935                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_EXP_ORG');
1936                                                 l_error_flag_local := 'Y';
1937                                         END IF;
1938                                 END IF;
1939                         END IF; --  l_req_rec.expenditure_organization_id IS NOT NULL
1940 
1941                         -- Forecast Info Validations
1942                         -----------------------------
1943 
1944                         IF (l_req_rec.fcst_job_group_name IS NOT NULL  AND l_req_rec.fcst_job_group_name <> FND_API.G_MISS_CHAR)
1945                                 OR (l_req_rec.fcst_job_group_id IS NOT NULL AND l_req_rec.fcst_job_group_id <> FND_API.G_MISS_NUM)
1946                         THEN
1947                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1948                                 l_error_message_code := null;
1949                                 l_fcst_job_group_id_tmp := l_req_rec.fcst_job_group_id;
1950 
1951                                 IF l_debug_mode = 'Y' THEN
1952                                         pa_debug.write(l_module, 'Validating Job Group and Name to ID conversion', l_log_level);
1953                                 END IF;
1954 
1955                                 PA_JOB_UTILS.CHECK_JOB_GROUPNAME_OR_ID(
1956                                         p_job_group_id          => l_fcst_job_group_id_tmp
1957                                         ,p_job_group_name       => l_req_rec.fcst_job_group_name
1958                                         ,p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag
1959                                         ,x_job_group_id         => l_req_rec.fcst_job_group_id
1960                                         ,x_return_status        => l_return_status
1961                                         ,x_error_message_code   => l_error_message_code );
1962 
1963                                 IF l_debug_mode = 'Y' THEN
1964                                         pa_debug.write(l_module, 'After Job Group Validation l_req_rec.fcst_job_group_id='||l_req_rec.fcst_job_group_id, l_log_level);
1965                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1966                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1967                                 END IF;
1968 
1969                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1970                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
1971                                         l_error_flag_local := 'Y';
1972                                 END IF;
1973                         END IF;
1974 
1975                         IF (l_req_rec.fcst_job_name IS NOT NULL AND l_req_rec.fcst_job_name <> FND_API.G_MISS_CHAR)
1976                                 OR (l_req_rec.fcst_job_id IS NOT NULL  AND l_req_rec.fcst_job_id <> FND_API.G_MISS_NUM)
1977                         THEN
1978                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
1979                                 l_error_message_code := null;
1980                                 l_fcst_job_id_tmp := l_req_rec.fcst_job_id;
1981 
1982                                 IF l_debug_mode = 'Y' THEN
1983                                         pa_debug.write(l_module, 'Validating Job and Name to ID conversion', l_log_level);
1984                                 END IF;
1985 
1986                                 PA_JOB_UTILS.CHECK_JOBNAME_OR_ID (
1987                                         p_job_id                => l_fcst_job_id_tmp
1988                                         ,p_job_name		=> l_req_rec.fcst_job_name
1989                                         ,p_job_group_id         => l_req_rec.fcst_job_group_id -- 5144999
1990                                         ,p_check_id_flag	=> PA_STARTUP.G_Check_ID_Flag
1991                                         ,x_job_id		=> l_req_rec.fcst_job_id
1992                                         ,x_return_status	=> l_return_status
1993                                         ,x_error_message_code	=> l_error_message_code);
1994 
1995                                 IF l_debug_mode = 'Y' THEN
1996                                         pa_debug.write(l_module, 'After Job Validation l_req_rec.fcst_job_id='||l_req_rec.fcst_job_id, l_log_level);
1997                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
1998                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
1999                                 END IF;
2000 
2001                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2002                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
2003                                         l_error_flag_local := 'Y';
2004                                 END IF;
2005                         END IF;
2006 
2007                         IF l_req_rec.fcst_job_id IS NOT NULL AND l_req_rec.fcst_job_id <> FND_API.G_MISS_NUM
2008                         AND l_req_rec.fcst_job_group_id IS NOT NULL  AND l_req_rec.fcst_job_group_id <> FND_API.G_MISS_NUM
2009                         THEN
2010                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
2011                                 l_error_message_code := null;
2012 
2013                                 IF l_debug_mode = 'Y' THEN
2014                                         pa_debug.write(l_module, 'Validating Job wrt Job Group', l_log_level);
2015                                 END IF;
2016 
2017                                 PA_JOB_UTILS.VALIDATE_JOB_RELATIONSHIP (
2018                                         p_job_id                => l_req_rec.fcst_job_id
2019                                         ,p_job_group_id         => l_req_rec.fcst_job_group_id
2020                                         ,x_return_status        => l_return_status
2021                                         ,x_error_message_code   => l_error_message_code);
2022 
2023                                 IF l_debug_mode = 'Y' THEN
2024                                         pa_debug.write(l_module, 'After Job wrt Job Group Validation', l_log_level);
2025                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
2026                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
2027                                 END IF;
2028 
2029                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2030                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
2031                                         l_error_flag_local := 'Y';
2032                                 END IF;
2033                         END IF;
2034 
2035 
2036                         -- Bill Rate Options Validation
2037                         -------------------------------
2038 
2039                         IF l_req_rec.bill_rate_option <> 'NONE' THEN
2040                                 l_rate_discount_reason_flag := 'N';
2041                                 l_br_override_flag := 'N';
2042                                 l_br_discount_override_flag := 'N';
2043 
2044                                 OPEN get_bill_rate_override_flags(l_req_rec.project_id);
2045                                 FETCH get_bill_rate_override_flags INTO  l_rate_discount_reason_flag, l_br_override_flag, l_br_discount_override_flag;
2046                                 CLOSE get_bill_rate_override_flags;
2047 
2048                                 IF l_debug_mode = 'Y' THEN
2049                                         pa_debug.write(l_module, 'Validating Bill Rate Options', l_log_level);
2050                                         pa_debug.write(l_module, 'l_rate_discount_reason_flag='||l_rate_discount_reason_flag, l_log_level);
2051                                         pa_debug.write(l_module, 'l_br_override_flag='||l_br_override_flag, l_log_level);
2052                                         pa_debug.write(l_module, 'l_br_discount_override_flag='||l_br_discount_override_flag, l_log_level);
2053                                 END IF;
2054 
2055                                 IF l_req_rec.bill_rate_option = 'RATE' THEN
2056                                         IF l_br_override_flag <> 'Y' OR l_req_rec.bill_rate_override <= 0 THEN /* OR l_req_rec.bill_rate_override > 100 - Removed for Bug 5703021*/
2057                                                 IF l_br_override_flag <> 'Y' THEN
2058                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
2059                                                         l_error_flag_local := 'Y';
2060                                                 ELSE
2061                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_BILL_RATE_OVRD');
2062                                                         l_error_flag_local := 'Y';
2063                                                 END IF;
2064                                         END IF;
2065 
2066                                         -- 5144288, 5144369 : Added bill rate currency check below
2067                                         -- Begin
2068                                         IF nvl(l_multi_currency_billing_flag,'N') = 'Y' AND l_br_override_flag = 'Y' THEN
2069 
2070                                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
2071                                                 l_error_message_code := null;
2072                                                 l_bill_currency_override_tmp := l_req_rec.bill_rate_curr_override;
2073 
2074                                                 IF l_debug_mode = 'Y' THEN
2075                                                         pa_debug.write(l_module, 'Validating Bill Rate Currency', l_log_level);
2076                                                 END IF;
2077 
2078                                                 PA_PROJECTS_MAINT_UTILS.CHECK_CURRENCY_NAME_OR_CODE(
2079                                                         p_agreement_currency       => l_bill_currency_override_tmp
2080                                                         ,p_agreement_currency_name  => null
2081                                                         ,p_check_id_flag            => 'Y'
2082                                                         ,x_agreement_currency       => l_req_rec.bill_rate_curr_override
2083                                                         ,x_return_status            => l_return_status
2084                                                         ,x_error_msg_code           => l_error_message_code);
2085 
2086                                                 IF l_debug_mode = 'Y' THEN
2087                                                         pa_debug.write(l_module, 'After Bill Rate Currency Validation', l_log_level);
2088                                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
2089                                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
2090                                                 END IF;
2091 
2092                                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2093                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_CISI_CURRENCY_NULL');
2094                                                         l_error_flag_local := 'Y';
2095                                                 END IF;
2096                                         END IF;
2097                                         -- 5144288, 5144369 : End
2098                                 ELSIF l_req_rec.bill_rate_option = 'MARKUP' THEN
2099 					-- 5144675 Changed l_req_rec.markup_percent_override <= 0 to < 0
2100                                         IF l_br_override_flag <> 'Y' OR l_req_rec.markup_percent_override < 0
2101 					   OR l_req_rec.markup_percent_override > 100 THEN
2102                                                 IF l_br_override_flag <> 'Y' THEN
2103                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
2104                                                         l_error_flag_local := 'Y';
2105                                                 ELSE
2106                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_MARKUP_PERCENT');
2107                                                         l_error_flag_local := 'Y';
2108                                                 END IF;
2109                                         END IF;
2110                                 ELSIF l_req_rec.bill_rate_option = 'DISCOUNT' THEN
2111 					-- 5144675 Changed l_req_rec.discount_percentage <=0 to < 0
2112                                         IF l_br_discount_override_flag <> 'Y' OR l_req_rec.discount_percentage < 0
2113 					   OR l_req_rec.discount_percentage > 100 THEN
2114                                                 IF l_br_override_flag <> 'Y' THEN
2115                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_OVRD_NA');
2116                                                         l_error_flag_local := 'Y';
2117                                                 ELSE
2118                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_DISCOUNT_PERCENT');
2119                                                         l_error_flag_local := 'Y';
2120                                                 END IF;
2121                                         END IF;
2122                                 END IF;
2123                                 IF l_req_rec.rate_disc_reason_code IS NULL THEN
2124                                         IF (l_rate_discount_reason_flag ='Y' AND (l_br_override_flag ='Y' OR l_br_discount_override_flag='Y') AND
2125                                                 (l_req_rec.bill_rate_override IS NOT NULL OR l_req_rec.markup_percent_override IS NOT NULL OR l_req_rec.discount_percentage IS NOT NULL)
2126                                            )
2127                                         THEN
2128                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_RATE_DISC_REASON_REQUIRED');
2129                                                 l_error_flag_local := 'Y';
2130                                         END IF;
2131                                 ELSE
2132                                         l_valid_flag := 'N';
2133                                         OPEN c_get_lookup_exists('RATE AND DISCOUNT REASON', l_req_rec.rate_disc_reason_code);
2134                                         FETCH c_get_lookup_exists INTO l_valid_flag;
2135                                         CLOSE c_get_lookup_exists;
2136                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
2137                                                 -- This is a new message, define it
2138                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_RSN_INVALID');
2139                                                 l_error_flag_local := 'Y';
2140                                         END IF;
2141                                 END IF;
2142 
2143                                 IF l_debug_mode = 'Y' THEN
2144                                         pa_debug.write(l_module, 'After Validating Bill Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
2145                                 END IF;
2146                         END IF; -- l_req_rec.bill_rate_option <> 'NONE'
2147 
2148                         -- Transfer Price Rate Options Validation
2149                         -----------------------------------------
2150 
2151                         IF l_req_rec.tp_rate_option <> 'NONE' THEN
2152 
2153                                 IF l_debug_mode = 'Y' THEN
2154                                         pa_debug.write(l_module, 'Validating Transfer Price Rate Options', l_log_level);
2155                                 END IF;
2156 
2157                                 IF l_req_rec.tp_rate_option = 'RATE' THEN
2158 					-- 5144675 Changed l_req_rec.tp_rate_override <= 0 to  < 0
2159                                         IF l_req_rec.tp_rate_override < 0 OR l_req_rec.tp_rate_override > 100 THEN
2160                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_TP_RATE_OVRD');
2161                                                 l_error_flag_local := 'Y';
2162                                         END IF;
2163 
2164                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
2165                                         l_error_message_code := null;
2166                                         l_tp_currency_override_tmp := l_req_rec.tp_currency_override;
2167 
2168                                         IF l_debug_mode = 'Y' THEN
2169                                                 pa_debug.write(l_module, 'Validating Transfer Price Rate Currency', l_log_level);
2170                                         END IF;
2171 
2172                                         PA_PROJECTS_MAINT_UTILS.CHECK_CURRENCY_NAME_OR_CODE(
2173                                                 p_agreement_currency       => l_tp_currency_override_tmp
2174                                                 ,p_agreement_currency_name  => null
2175                                                 ,p_check_id_flag            => 'Y'
2176                                                 ,x_agreement_currency       => l_req_rec.tp_currency_override
2177                                                 ,x_return_status            => l_return_status
2178                                                 ,x_error_msg_code           => l_error_message_code);
2179 
2180                                         IF l_debug_mode = 'Y' THEN
2181                                                 pa_debug.write(l_module, 'After Transfer Price Rate Currency Validation', l_log_level);
2182                                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
2183                                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
2184                                         END IF;
2185 
2186                                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2187                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_CURR_NOT_VALID');
2188                                                 l_error_flag_local := 'Y';
2189                                         END IF;
2190                                 ELSIF l_req_rec.tp_rate_option = 'BASIS' THEN
2191 					-- 5144675 Changed l_req_rec.tp_percent_applied_override <=0 to < 0
2192                                         IF l_req_rec.tp_percent_applied_override < 0 OR l_req_rec.tp_percent_applied_override > 100  THEN
2193                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_APPLY_BASIS_PERCENT');
2194                                                 l_error_flag_local := 'Y';
2195                                         END IF;
2196                                         l_valid_flag := 'N';
2197                                         IF l_debug_mode = 'Y' THEN
2198                                                 pa_debug.write(l_module, 'Validating Transfer Price Rate Basis', l_log_level);
2199                                         END IF;
2200 
2201                                         OPEN c_get_lookup_exists('CC_MARKUP_BASE_CODE', l_req_rec.tp_calc_base_code_override);
2202                                         FETCH c_get_lookup_exists INTO l_valid_flag;
2203                                         CLOSE c_get_lookup_exists;
2204 
2205                                         IF l_debug_mode = 'Y' THEN
2206                                                 pa_debug.write(l_module, 'After Transfer Price Rate Basis Validation', l_log_level);
2207                                                 pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
2208                                         END IF;
2209 
2210                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
2211                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_TP_BASIS_INVALID');
2212                                                 l_error_flag_local := 'Y';
2213                                         END IF;
2214                                 END IF;
2215 
2216                                 IF l_debug_mode = 'Y' THEN
2217                                         pa_debug.write(l_module, 'After Validating Transfer Price Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
2218                                 END IF;
2219                         END IF; -- l_req_rec.tp_rate_option <> 'NONE'
2220 
2221                         -- Res Loan Agreement Validations
2222                         ---------------------------------
2223 
2224                         IF l_req_rec.expense_owner IS NOT NULL THEN
2225                                 l_valid_flag := 'N';
2226 
2227                                 IF l_debug_mode = 'Y' THEN
2228                                         pa_debug.write(l_module, 'Validating Expense Owner Option', l_log_level);
2229                                 END IF;
2230 
2231                                 OPEN c_get_lookup_exists('EXPENSE_OWNER_TYPE', l_req_rec.expense_owner);
2232                                 FETCH c_get_lookup_exists INTO l_valid_flag;
2233                                 CLOSE c_get_lookup_exists;
2234 
2235                                 IF l_debug_mode = 'Y' THEN
2236                                         pa_debug.write(l_module, 'After Expense Owner Option Validation', l_log_level);
2237                                         pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
2238                                 END IF;
2239 
2240                                 IF nvl(l_valid_flag,'N') <> 'Y' THEN
2241                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_EXP_OWNER_INVALID');
2242                                         l_error_flag_local := 'Y';
2243                                 END IF;
2244                         END IF;
2245                 END IF; -- l_error_flag_local <> 'Y' AND l_req_rec.project_id IS NOT NULL
2246 
2247                 IF l_debug_mode = 'Y' THEN
2248                         pa_debug.write(l_module, 'After all validations l_error_flag_local='||l_error_flag_local, l_log_level);
2249                 END IF;
2250 
2251                 -- Flex field Validation
2252                 ------------------------
2253 
2254                 IF l_error_flag_local <> 'Y' THEN
2255                         l_return_status := FND_API.G_RET_STS_SUCCESS;
2256 
2257                         VALIDATE_FLEX_FIELD(
2258                                   p_desc_flex_name         => 'PA_TEAM_ROLE_DESC_FLEX'
2259                                 , p_attribute_category     => l_req_rec.attribute_category
2260                                 , px_attribute1            => l_req_rec.attribute1
2261                                 , px_attribute2            => l_req_rec.attribute2
2262                                 , px_attribute3            => l_req_rec.attribute3
2263                                 , px_attribute4            => l_req_rec.attribute4
2264                                 , px_attribute5            => l_req_rec.attribute5
2265                                 , px_attribute6            => l_req_rec.attribute6
2266                                 , px_attribute7            => l_req_rec.attribute7
2267                                 , px_attribute8            => l_req_rec.attribute8
2268                                 , px_attribute9            => l_req_rec.attribute9
2269                                 , px_attribute10           => l_req_rec.attribute10
2270                                 , px_attribute11           => l_req_rec.attribute11
2271                                 , px_attribute12           => l_req_rec.attribute12
2272                                 , px_attribute13           => l_req_rec.attribute13
2273                                 , px_attribute14           => l_req_rec.attribute14
2274                                 , px_attribute15           => l_req_rec.attribute15
2275                                 , x_return_status          => l_return_status
2276                                 , x_msg_count		   => l_msg_count
2277                                 , x_msg_data		   => l_msg_data
2278                          );
2279 
2280                         IF l_debug_mode = 'Y' THEN
2281                                 pa_debug.write(l_module, 'After Flex Field Validation l_return_status='||l_return_status, l_log_level);
2282                                 pa_debug.write(l_module, 'After Flex Field Validation l_msg_data='||l_msg_data, l_log_level);
2283                         END IF;
2284 
2285 
2286                         IF l_return_status <>  FND_API.G_RET_STS_SUCCESS  THEN
2287                                 -- This message does not have toekn defined, still it is ok to pass token as the value
2288                                 -- returned by flex APIs because token are appended as it is
2289                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_DFF_VALIDATION_FAILED',
2290                                                       'ERROR_MESSAGE', l_msg_data );
2291                                 l_error_flag_local := 'Y';
2292                         END IF;
2293                 END IF; -- l_error_flag_local <> 'Y'
2294 
2295                 -- Security Check
2296                 -----------------
2297 
2298                 IF l_error_flag_local <> 'Y' THEN
2299 
2300                         IF l_debug_mode = 'Y' THEN
2301                                 pa_debug.write(l_module, 'Checking Security for Record#'||i, l_log_level);
2302                         END IF;
2303 
2304                         IF l_req_rec.team_template_id IS NOT NULL THEN
2305                                 l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
2306                                 l_object_name := null;
2307                                 l_object_key := null;
2308                         ELSIF l_req_rec.project_id IS NOT NULL THEN
2309                                 l_privilege := 'PA_ASN_CR_AND_DL';
2310                                 l_object_name := 'PA_PROJECTS';
2311                                 l_object_key := null;
2312                         ELSE
2313                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
2314                                 raise FND_API.G_EXC_ERROR;
2315                         END IF;
2316 
2317                         IF l_debug_mode = 'Y' THEN
2318                                 pa_debug.write(l_module, 'l_privilege='||l_privilege, l_log_level);
2319                                 pa_debug.write(l_module, 'l_object_name='||l_object_name, l_log_level);
2320                                 pa_debug.write(l_module, 'l_object_key='||l_object_key, l_log_level);
2321                         END IF;
2322 
2323                         l_return_status := FND_API.G_RET_STS_SUCCESS;
2324                         l_ret_code := 'T';
2325 
2326                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
2327                                   x_ret_code       => l_ret_code
2328                                 , x_return_status  => l_return_status
2329                                 , x_msg_count      => l_msg_count
2330                                 , x_msg_data       => l_msg_data
2331                                 , p_init_msg_list   => 'F'
2332                                 , p_privilege      => l_privilege
2333                                 , p_object_name    => l_object_name
2334                                 , p_object_key     => l_object_key);
2335 
2336                         IF l_debug_mode = 'Y' THEN
2337                                 pa_debug.write(l_module, 'After Security Check l_ret_code='||l_ret_code, l_log_level);
2338                         END IF;
2339 
2340 
2341                         IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2342                                 -- This message does not have token defined, but intentionally putting token
2343                                 -- bcoz we still want to show the privielge name which is missing
2344                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_CR_DL'
2345                                                       ,'MISSING_PRIVILEGE', l_privilege);
2346                                 l_error_flag_local := 'Y';
2347                         END IF;
2348                 END IF;
2349 
2350                 -- Call Core Actual API
2351                 -----------------------
2352 
2353                 IF l_error_flag_local <> 'Y' THEN
2354                         l_return_status := FND_API.G_RET_STS_SUCCESS;
2355 
2356                         IF l_debug_mode = 'Y' THEN
2357                                 pa_debug.write(l_module, 'Calling pa_assignments_pub.execute_create_assignment for Record#'||i, l_log_level);
2358                         END IF;
2359 
2360                         l_new_assignment_id_tbl := null;
2361                         l_new_assignment_id := null;
2362                         l_assignment_number := null;
2363                         l_assignment_row_id := null;
2364                         l_resource_id := null;
2365 
2366                         PA_ASSIGNMENTS_PUB.EXECUTE_CREATE_ASSIGNMENT
2367                         (
2368                                   p_api_version                 => p_api_version_number
2369                                 , p_init_msg_list               => l_init_msg_list
2370                                 , p_commit                      => l_commit
2371                                 , p_validate_only               => l_validate_only
2372                                 , p_asgn_creation_mode		=> l_asgn_creation_mode
2373                                 , p_assignment_name		=> l_req_rec.requirement_name
2374                                 , p_assignment_type		=> l_assignment_type
2375                                 , p_assignment_template_id      => l_req_rec.team_template_id
2376 --                                , p_source_assignment_id        => l_req_rec.source_requirement_id
2377                                 , p_number_of_requirements      => l_req_rec.number_of_requirements
2378                                 , p_project_role_id             => l_req_rec.project_role_id
2379                                 , p_project_role_name           => l_req_rec.project_role_name
2380                                 , p_project_id                  => l_req_rec.project_id
2381                                 , p_project_name                => l_req_rec.project_name
2382                                 , p_project_number              => l_req_rec.project_number
2383                 --                , p_resource_id                 =>
2384                 --                , p_project_party_id            =>
2385                 --                , p_resource_name               =>
2386                 --                , p_resource_source_id          => null
2387                                 , p_staffing_owner_person_id    => l_req_rec.staffing_owner_person_id
2388                 --                , p_staffing_owner_name         =>
2389                                 , p_staffing_priority_code      => l_req_rec.staffing_priority_code
2390                                 , p_staffing_priority_name      => l_req_rec.staffing_priority_name
2391                                 , p_project_subteam_id          => l_req_rec.project_subteam_id
2392                                 , p_project_subteam_name        => l_req_rec.project_subteam_name
2393                                 , p_location_id                 => l_req_rec.location_id
2394                                 , p_location_city               => l_req_rec.location_city
2395                                 , p_location_region             => l_req_rec.location_region
2396                                 , p_location_country_name       => l_req_rec.location_country_name
2397                                 , p_location_country_code       => l_req_rec.location_country_code
2398                                 , p_min_resource_job_level      => l_req_rec.min_resource_job_level
2399                                 , p_max_resource_job_level	=> l_req_rec.max_resource_job_level
2400                                 , p_description                 => l_req_rec.description
2401                                 , p_additional_information      => l_req_rec.additional_information
2402                                 , p_start_date                  => l_req_rec.start_date
2403                                 , p_end_date                    => l_req_rec.end_date
2404                                 , p_status_code                 => l_req_rec.status_code
2405                                 , p_project_status_name         => l_req_rec.status_name
2406                 --		, p_multiple_status_flag        => l_multiple_status_flag
2407                 --                , p_assignment_effort           =>
2408                 --                , p_resource_list_member_id   =>
2409                 --                , p_budget_version_id		=>
2410                 --                , p_sum_tasks_flag            =>
2411                                 , p_calendar_type               => l_req_rec.calendar_type
2412                                 , p_calendar_id	                => l_req_rec.calendar_id
2413                                 , p_calendar_name               => l_req_rec.calendar_name
2414                                 , p_start_adv_action_set_flag   => l_req_rec.start_adv_action_set_flag
2415                                 , p_adv_action_set_id           => l_req_rec.adv_action_set_id
2416                                 , p_adv_action_set_name         => l_req_rec.adv_action_set_name
2417                                 -- As of now internal code does not support setting the candidate search options
2418                                 -- at create time. It can only be updated.
2419                                 , p_comp_match_weighting        => l_req_rec.comp_match_weighting
2420                                 , p_avail_match_weighting       => l_req_rec.avail_match_weighting
2421                                 , p_job_level_match_weighting   => l_req_rec.job_level_match_weighting
2422                                 , p_enable_auto_cand_nom_flag   => l_req_rec.enable_auto_cand_nom_flag
2423                                 , p_search_min_availability     => l_req_rec.search_min_availability
2424                                 , p_search_exp_org_struct_ver_id => l_req_rec.search_exp_org_str_ver_id
2425                                 , p_search_exp_start_org_id     => l_req_rec.search_exp_start_org_id
2426                                 , p_search_country_code         => l_req_rec.search_country_code
2427                                 , p_search_min_candidate_score  => l_req_rec.search_min_candidate_score
2428                                 , p_expenditure_org_id          => l_req_rec.expenditure_org_id
2429                                 , p_expenditure_org_name        => l_req_rec.expenditure_org_name
2430                                 , p_expenditure_organization_id => l_req_rec.expenditure_organization_id
2431                                 , p_exp_organization_name       => l_req_rec.expenditure_organization_name
2432                                 , p_expenditure_type_class      => l_req_rec.expenditure_type_class
2433                                 , p_expenditure_type            => l_req_rec.expenditure_type
2434                                 , p_fcst_job_group_id           => l_req_rec.fcst_job_group_id
2435                                 , p_fcst_job_group_name         => l_req_rec.fcst_job_group_name
2436                                 , p_fcst_job_id                 => l_req_rec.fcst_job_id
2437                                 , p_fcst_job_name               => l_req_rec.fcst_job_name
2438 --                                , p_fcst_tp_amount_type         => l_req_rec.fcst_tp_amount_type
2439                                 , p_work_type_id                => l_req_rec.work_type_id
2440                                 , p_work_type_name              => l_req_rec.work_type_name
2441                                 , p_bill_rate_override          => l_req_rec.bill_rate_override
2442                                 , p_bill_rate_curr_override     => l_req_rec.bill_rate_curr_override
2443                                 , p_markup_percent_override     => l_req_rec.markup_percent_override
2444                                 , p_discount_percentage         => l_req_rec.discount_percentage
2445                                 , p_rate_disc_reason_code       => l_req_rec.rate_disc_reason_code
2446                                 , p_tp_rate_override            => l_req_rec.tp_rate_override
2447                                 , p_tp_currency_override        => l_req_rec.tp_currency_override
2448                                 , p_tp_calc_base_code_override  => l_req_rec.tp_calc_base_code_override
2449                                 , p_tp_percent_applied_override => l_req_rec.tp_percent_applied_override
2450                                 , p_extension_possible          => l_req_rec.extension_possible
2451                                 , p_expense_owner               => l_req_rec.expense_owner
2452                                 , p_expense_limit               => l_req_rec.expense_limit
2453                 --                , p_revenue_currency_code     =>
2454                 --                , p_revenue_bill_rate           =>
2455                 --                , p_markup_percent              =>
2456                 --                , p_resource_calendar_percent   =>
2457                                 , p_attribute_category          => l_req_rec.attribute_category
2458                                 , p_attribute1                  => l_req_rec.attribute1
2459                                 , p_attribute2                  => l_req_rec.attribute2
2460                                 , p_attribute3                  => l_req_rec.attribute3
2461                                 , p_attribute4                  => l_req_rec.attribute4
2462                                 , p_attribute5                  => l_req_rec.attribute5
2463                                 , p_attribute6                  => l_req_rec.attribute6
2464                                 , p_attribute7                  => l_req_rec.attribute7
2465                                 , p_attribute8                  => l_req_rec.attribute8
2466                                 , p_attribute9                  => l_req_rec.attribute9
2467                                 , p_attribute10                 => l_req_rec.attribute10
2468                                 , p_attribute11                 => l_req_rec.attribute11
2469                                 , p_attribute12                 => l_req_rec.attribute12
2470                                 , p_attribute13                 => l_req_rec.attribute13
2471                                 , p_attribute14                 => l_req_rec.attribute14
2472                                 , p_attribute15                 => l_req_rec.attribute15
2473                                 , x_new_assignment_id_tbl       => l_new_assignment_id_tbl
2474                                 , x_new_assignment_id           => l_new_assignment_id
2475                                 , x_assignment_number           => l_assignment_number
2476                                 , x_assignment_row_id           => l_assignment_row_id
2477                                 , x_resource_id                 => l_resource_id
2478                                 , x_return_status               => l_return_status
2479                                 , x_msg_count                   => l_msg_count
2480                                 , x_msg_data                    => l_msg_data
2481                         );
2482 
2483                         IF l_debug_mode = 'Y' THEN
2484                                 pa_debug.write(l_module, 'After call pa_assignments_pub.execute_create_assignment l_return_status='||l_return_status, l_log_level);
2485                         END IF;
2486 
2487                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2488                                 l_error_flag_local := 'Y';
2489                                 -- Still we populating out tables so that if calling env tries
2490                                 -- to get all ids even after error has occured
2491                                 x_requirement_id_tbl.extend(1);
2492                                 x_requirement_id_tbl(x_requirement_id_tbl.count):= -1;
2493                         ELSE
2494                                 IF l_debug_mode = 'Y' THEN
2495                                         pa_debug.write(l_module, 'Updating Original System Code and Reference', l_log_level);
2496                                         pa_debug.write(l_module, 'l_new_assignment_id_tbl.count'||l_new_assignment_id_tbl.count, l_log_level);
2497                                 END IF;
2498 
2499                                 IF l_new_assignment_id_tbl.count > 0 THEN
2500                                         FOR j in l_new_assignment_id_tbl.FIRST..l_new_assignment_id_tbl.LAST LOOP
2501                                                 IF l_new_assignment_id_tbl.exists(j) THEN
2502                                                         x_requirement_id_tbl.extend(1);
2503                                                         x_requirement_id_tbl(x_requirement_id_tbl.count):= l_new_assignment_id_tbl(j);
2504                                                         IF (l_req_rec.orig_system_code IS NOT NULL OR l_req_rec.orig_system_reference IS NOT NULL) THEN
2505                                                                 UPDATE PA_PROJECT_ASSIGNMENTS
2506                                                                 SET orig_system_code = l_req_rec.orig_system_code
2507                                                                 , orig_system_reference = l_req_rec.orig_system_reference
2508                                                                 WHERE assignment_id = l_new_assignment_id_tbl(j);
2509                                                         END IF;
2510                                                 END IF;
2511                                         END LOOP;
2512                                 END IF;
2513                                 IF l_debug_mode = 'Y' THEN
2514                                         pa_debug.write(l_module, 'After Updating Original System Code and Reference', l_log_level);
2515                                 END IF;
2516                         END IF;
2517 		ELSE
2518 			-- Still we populating out tables so that if calling env tries
2519 			-- to get all ids even after error has occured
2520 			x_requirement_id_tbl.extend(1);
2521 			x_requirement_id_tbl(x_requirement_id_tbl.count):= -1;
2522                 END IF;
2523 
2524                 l_end_msg_count := FND_MSG_PUB.count_msg;
2525                 IF l_debug_mode = 'Y' THEN
2526                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
2527                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
2528                 END IF;
2529                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
2530 
2531                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
2532                         l_error_flag := 'Y';
2533 
2534                         IF l_debug_mode = 'Y' THEN
2535                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
2536                         END IF;
2537 
2538                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
2539                                 -- Always get from first location in stack i.e. l_start_msg_count+1
2540                                 -- Because stack moves down after delete
2541                                 FND_MSG_PUB.get (
2542                                         p_msg_index      => l_start_msg_count+1,
2543                                         p_encoded        => FND_API.G_FALSE,
2544                                         p_data           => l_data,
2545                                         p_msg_index_out  => l_msg_index_out );
2546 
2547                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
2548                                 -- Because stack moves down after delete
2549                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
2550 
2551                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
2552                                                 'RECORD_NO', i,
2553                                                 'MESSAGE', l_data);
2554                         END LOOP;
2555                         IF l_debug_mode = 'Y' THEN
2556                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
2557                         END IF;
2558                 END IF;
2559                 i := p_requirement_in_tbl.next(i);
2560         END LOOP;
2561 
2562         IF l_debug_mode = 'Y' THEN
2563                 pa_debug.write(l_module, 'All records are done', l_log_level);
2564                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
2565                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
2566         END IF;
2567 
2568         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
2569                 RAISE FND_API.G_EXC_ERROR;
2570         END IF;
2571 
2572         IF l_debug_mode = 'Y' THEN
2573                 PA_DEBUG.reset_curr_function;
2574         END IF;
2575 
2576         IF p_commit = FND_API.G_TRUE THEN
2577                 commit;
2578         END IF;
2579 
2580 
2581 EXCEPTION
2582 WHEN FND_API.G_EXC_ERROR THEN
2583         x_return_status := FND_API.G_RET_STS_ERROR;
2584         l_msg_count := FND_MSG_PUB.count_msg;
2585 
2586         IF p_commit = FND_API.G_TRUE THEN
2587                 ROLLBACK TO CREATE_REQUIREMENTS_SP;
2588         END IF;
2589 
2590         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
2591                 PA_INTERFACE_UTILS_PUB.get_messages
2592                 ( p_encoded        => FND_API.G_FALSE
2593                 , p_msg_index      => 1
2594                 , p_msg_count      => l_msg_count
2595                 , p_msg_data       => l_msg_data
2596                 , p_data           => l_data
2597                 , p_msg_index_out  => l_msg_index_out);
2598 
2599                 x_msg_data := l_data;
2600                 x_msg_count := l_msg_count;
2601         ELSE
2602                 x_msg_count := l_msg_count;
2603         END IF;
2604 
2605         IF l_debug_mode = 'Y' THEN
2606                 Pa_Debug.reset_curr_function;
2607         END IF;
2608 
2609 WHEN OTHERS THEN
2610 
2611         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2612         x_msg_data      := SQLERRM;
2613 
2614         IF p_commit = FND_API.G_TRUE THEN
2615                 ROLLBACK TO CREATE_REQUIREMENTS_SP;
2616         END IF;
2617 
2618         FND_MSG_PUB.add_exc_msg
2619         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
2620         , p_procedure_name      => 'CREATE_REQUIREMENTS'
2621         , p_error_text          => x_msg_data);
2622 
2623         x_msg_count     := FND_MSG_PUB.count_msg;
2624 
2625         IF l_debug_mode = 'Y' THEN
2626                 PA_DEBUG.reset_curr_function;
2627         END IF;
2628         RAISE;
2629 END CREATE_REQUIREMENTS;
2630 
2631 -- Start of comments
2632 --	API name 	: UPDATE_REQUIREMENTS
2633 --	Type		: Public
2634 --	Pre-reqs	: None.
2635 --	Function	: This is a public API to update one or more requirements for one or more projects
2636 --	Usage		: This API will be called from AMG.
2637 --	Parameters	:
2638 --	IN		:	p_commit		IN  VARCHAR2
2639 --					Identifier to commit the transaction.
2640 --					Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
2641 --				p_init_msg_list		IN  VARCHAR2
2642 --					Identifier to initialize the error message stack.
2643 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
2644 --				p_api_version_number	IN  NUMBER			Required
2645 --					To be compliant with Applications API coding standards.
2646 --				p_requirement_in_tbl	IN  REQUIREMENT_IN_TBL_TYPE	Required
2647 --					Table of requirement records. Please see the REQUIREMENT_IN_TBL_TYPE datatype table.
2648 --	OUT		:
2649 --				x_return_status		OUT VARCHAR2
2650 --					Indicates the return status of the API.
2651 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
2652 --				x_msg_count		OUT NUMBER
2653 --					Indicates the number of error messages in the message stack
2654 --				x_msg_data		OUT VARCHAR2
2655 --					Indicates the error message text if only one error exists
2656 --	History		:
2657 --                              01-Mar-2006 - amksingh  - Created
2658 -- End of comments
2659 PROCEDURE UPDATE_REQUIREMENTS
2660 (
2661   p_api_version_number		IN		NUMBER   := 1.0
2662 , p_init_msg_list		IN		VARCHAR2 := FND_API.G_TRUE
2663 , p_commit			IN		VARCHAR2 := FND_API.G_FALSE
2664 , p_requirement_in_tbl		IN		REQUIREMENT_IN_TBL_TYPE
2665 , x_return_status		OUT	NOCOPY	VARCHAR2
2666 , x_msg_count			OUT	NOCOPY	NUMBER
2667 , x_msg_data			OUT	NOCOPY	VARCHAR2
2668 )
2669 IS
2670 l_calling_application           VARCHAR2(10)            := 'PLSQL';
2671 l_calling_module                VARCHAR2(10)            := 'AMG';
2672 l_check_id_flag                 VARCHAR2(1)             := 'Y';
2673 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
2674 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
2675 l_log_level                     NUMBER                  := 3;
2676 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.UPDATE_REQUIREMENTS';
2677 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
2678 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
2679 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
2680 l_msg_count                     NUMBER;
2681 l_msg_data                      VARCHAR2(2000);
2682 l_msg_index_out                 NUMBER;
2683 l_data                          VARCHAR2(2000);
2684 l_debug_mode                    VARCHAR2(1);
2685 
2686 i                               NUMBER;
2687 l_new_assignment_id_tbl         SYSTEM.PA_NUM_TBL_TYPE  := SYSTEM.PA_NUM_TBL_TYPE();
2688 l_new_assignment_id             NUMBER;
2689 l_assignment_number             NUMBER;
2690 l_assignment_row_id             ROWID;
2691 l_resource_id                   NUMBER;
2692 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
2693 l_error_flag                    VARCHAR2(1)             := 'N';
2694 l_error_flag_local              VARCHAR2(1)             := 'N';
2695 l_req_rec		        REQUIREMENT_IN_REC_TYPE;
2696 l_asgn_update_mode		VARCHAR2(10)	        := 'FULL';
2697 l_assignment_type		VARCHAR2(30)	        := 'OPEN_ASSIGNMENT';
2698 l_multiple_status_flag		VARCHAR2(1)	        := 'N';
2699 l_loop_msg_count                NUMBER                  :=0;
2700 l_start_msg_count               NUMBER                  :=0;
2701 l_end_msg_count                 NUMBER                  :=0;
2702 l_missing_params                VARCHAR2(1000);
2703 l_privilege                     VARCHAR2(30);
2704 l_object_name                   VARCHAR2(30);
2705 l_object_key                    NUMBER;
2706 l_error_message_code            VARCHAR2(30);
2707 l_ret_code                      VARCHAR2(1);
2708 
2709 
2710 CURSOR get_bill_rate_override_flags(c_project_id NUMBER) IS
2711 SELECT impl.rate_discount_reason_flag ,impl.br_override_flag, impl.br_discount_override_flag
2712 FROM pa_implementations_all impl
2713     , pa_projects_all proj
2714 WHERE proj.org_id=impl.org_id  -- Removed nvl condition from org_id : Post review changes for Bug 5130421
2715 AND proj.project_id = c_project_id ;
2716 
2717 CURSOR c_get_lookup_exists(c_lookup_type VARCHAR2, c_lookup_code VARCHAR2) IS
2718 SELECT 'Y'
2719 FROM dual
2720 WHERE EXISTS
2721 (SELECT 'XYZ' FROM pa_lookups WHERE lookup_type = c_lookup_type AND lookup_code = c_lookup_code);
2722 
2723 CURSOR c_get_subteam_party_id(c_requirement_id NUMBER) IS
2724 SELECT project_subteam_party_id, project_subteam_id
2725 FROM pa_project_subteam_parties
2726 WHERE object_id = c_requirement_id
2727 AND object_type = 'PA_PROJECT_ASSIGNMENTS'
2728 AND primary_subteam_flag = 'Y';
2729 
2730 CURSOR c_get_requirement_details(c_requirement_id NUMBER) IS
2731 SELECT *
2732 FROM pa_project_assignments
2733 WHERE assignment_type = 'OPEN_ASSIGNMENT'
2734 AND assignment_id = c_requirement_id;
2735 
2736 CURSOR c_get_system_status_code(c_status_code VARCHAR2, c_status_type VARCHAR2) IS
2737 SELECT project_system_status_code
2738 FROM pa_project_statuses
2739 WHERE status_type = c_status_type
2740 AND project_status_code = c_status_code;
2741 
2742 CURSOR c_get_location(c_location_id NUMBER) IS
2743 SELECT country_code, region, city
2744 FROM pa_locations
2745 WHERE location_id = c_location_id;
2746 
2747 CURSOR c_derive_country_code(c_country_name IN VARCHAR2) IS
2748 SELECT country_code
2749 FROM pa_country_v
2750 WHERE name = c_country_name;
2751 
2752 CURSOR c_derive_country_name(c_country_code IN VARCHAR2) IS
2753 SELECT name
2754 FROM pa_country_v
2755 WHERE  country_code  = c_country_code;
2756 
2757 -- 5144288, 5144369 : Added c_get_mcb_flag
2758 CURSOR c_get_mcb_flag(c_project_id NUMBER) IS
2759 SELECT multi_currency_billing_flag
2760 FROM pa_projects_all
2761 WHERE project_id = c_project_id;
2762 
2763 
2764 l_req_dtls_csr                  c_get_requirement_details%ROWTYPE;
2765 l_valid_flag                    VARCHAR2(1);
2766 l_rate_discount_reason_flag     VARCHAR2(1);
2767 l_br_override_flag              VARCHAR2(1);
2768 l_br_discount_override_flag     VARCHAR2(1);
2769 l_project_subteam_party_id      NUMBER;
2770 l_project_subteam_id            NUMBER;
2771 l_system_status_code            VARCHAR2(30);
2772 l_basic_info_changed            VARCHAR2(1);
2773 l_candidate_info_changed        VARCHAR2(1);
2774 l_fin_info_changed              VARCHAR2(1);
2775 l_fin_bill_rate_info_changed    VARCHAR2(1);
2776 l_fin_tp_rate_info_changed      VARCHAR2(1);
2777 l_valid_country                 VARCHAR2(1);
2778 l_dummy_country_code            VARCHAR2(2);
2779 l_dummy_state		        VARCHAR2(240);
2780 l_dummy_city		        VARCHAR2(80);
2781 l_out_location_id	        NUMBER;
2782 l_multi_currency_billing_flag   VARCHAR2(1); -- 5144288, 5144369
2783 l_bill_currency_override_tmp    VARCHAR2(30); -- 5144288, 5144369
2784 
2785 BEGIN
2786 
2787         --Flows which are supported by this API
2788         ---------------------------------------
2789         --1. Update project requirements
2790         --        1.1 Updating basic information(staffing priority, staffing owner, subteams, location etc..)
2791         --        1.2 Updating candidate search(search organization, weightages etc..) information
2792         --        1.3 Updating financial information(expendtiture organization, bill rate etc..)
2793         --        1.4 Updating forecast infomation(job, job group, expenditure type etc..)
2794         --2. Create team template requirments
2795         --        2.1 Updating basic information(staffing priority, staffing owner, subteams, location etc..)
2796         --
2797         --Flows which are not supported by this API
2798         -------------------------------------------
2799         --1. Update team role for given planning resource
2800         --2. Adding candidates while updating requirements
2801         --3. Adding/Updating competencies
2802         --4. Updating schedule information(dates, status, calendar etc..)
2803         --5. Updating advertisement rule
2804 
2805         -- Mandatory Parameters
2806         -----------------------
2807         --1. Requirement_id should be passed.
2808 
2809         x_return_status := FND_API.G_RET_STS_SUCCESS;
2810 
2811         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
2812 
2813         IF l_debug_mode = 'Y' THEN
2814                 PA_DEBUG.set_curr_function(p_function => 'UPDATE_REQUIREMENTS', p_debug_mode => l_debug_mode);
2815         END IF;
2816 
2817         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
2818                 FND_MSG_PUB.initialize;
2819         END IF;
2820 
2821         IF p_commit = FND_API.G_TRUE THEN
2822                 savepoint UPDATE_REQUIREMENTS_SP;
2823         END IF;
2824 
2825         IF l_debug_mode = 'Y' THEN
2826                 pa_debug.write(l_module, 'Start of update_requirements', l_log_level);
2827         END IF;
2828 
2829         IF l_debug_mode = 'Y' THEN
2830                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
2831                 i := p_requirement_in_tbl.first;
2832                 WHILE i IS NOT NULL LOOP
2833                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').requirement_id'||p_requirement_in_tbl(i).requirement_id, l_log_level);
2834                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').requirement_name'||p_requirement_in_tbl(i).requirement_name, l_log_level);
2835                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').team_template_id'||p_requirement_in_tbl(i).team_template_id, l_log_level);
2836                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').number_of_requirements'||p_requirement_in_tbl(i).number_of_requirements, l_log_level);
2837                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_role_id'||p_requirement_in_tbl(i).project_role_id, l_log_level);
2838                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_role_name'||p_requirement_in_tbl(i).project_role_name, l_log_level);
2839                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_id'||p_requirement_in_tbl(i).project_id, l_log_level);
2840                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_name'||p_requirement_in_tbl(i).project_name, l_log_level);
2841                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_number'||p_requirement_in_tbl(i).project_number, l_log_level);
2842                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').staffing_owner_person_id'||p_requirement_in_tbl(i).staffing_owner_person_id, l_log_level);
2843                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').staffing_priority_code'||p_requirement_in_tbl(i).staffing_priority_code, l_log_level);
2844                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').staffing_priority_name'||p_requirement_in_tbl(i).staffing_priority_name, l_log_level);
2845                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_subteam_id'||p_requirement_in_tbl(i).project_subteam_id, l_log_level);
2846                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').project_subteam_name'||p_requirement_in_tbl(i).project_subteam_name, l_log_level);
2847                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_id'||p_requirement_in_tbl(i).location_id, l_log_level);
2848                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_country_code'||p_requirement_in_tbl(i).location_country_code, l_log_level);
2849                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_country_name'||p_requirement_in_tbl(i).location_country_name, l_log_level);
2850                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_region'||p_requirement_in_tbl(i).location_region, l_log_level);
2851                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').location_city'||p_requirement_in_tbl(i).location_city, l_log_level);
2852                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').min_resource_job_level'||p_requirement_in_tbl(i).min_resource_job_level, l_log_level);
2853                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').max_resource_job_level'||p_requirement_in_tbl(i).max_resource_job_level, l_log_level);
2854                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').description'||p_requirement_in_tbl(i).description, l_log_level);
2855                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').additional_information'||p_requirement_in_tbl(i).additional_information, l_log_level);
2856                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').start_date'||p_requirement_in_tbl(i).start_date, l_log_level);
2857                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').end_date'||p_requirement_in_tbl(i).end_date, l_log_level);
2858                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').status_code'||p_requirement_in_tbl(i).status_code, l_log_level);
2859                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').status_name'||p_requirement_in_tbl(i).status_name, l_log_level);
2860                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').calendar_type'||p_requirement_in_tbl(i).calendar_type, l_log_level);
2861                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').calendar_id'||p_requirement_in_tbl(i).calendar_id, l_log_level);
2862                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').calendar_name'||p_requirement_in_tbl(i).calendar_name, l_log_level);
2863                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').start_adv_action_set_flag'||p_requirement_in_tbl(i).start_adv_action_set_flag, l_log_level);
2864                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').adv_action_set_id'||p_requirement_in_tbl(i).adv_action_set_id, l_log_level);
2865                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').adv_action_set_name'||p_requirement_in_tbl(i).adv_action_set_name, l_log_level);
2866                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').comp_match_weighting'||p_requirement_in_tbl(i).comp_match_weighting, l_log_level);
2867                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').avail_match_weighting'||p_requirement_in_tbl(i).avail_match_weighting, l_log_level);
2868                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').job_level_match_weighting'||p_requirement_in_tbl(i).job_level_match_weighting, l_log_level);
2869                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').enable_auto_cand_nom_flag'||p_requirement_in_tbl(i).enable_auto_cand_nom_flag, l_log_level);
2870                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_min_availability'||p_requirement_in_tbl(i).search_min_availability, l_log_level);
2871                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_org_str_ver_id'||p_requirement_in_tbl(i).search_exp_org_str_ver_id, l_log_level);
2872                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_org_hier_name'||p_requirement_in_tbl(i).search_exp_org_hier_name, l_log_level);
2873                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_start_org_id'||p_requirement_in_tbl(i).search_exp_start_org_id, l_log_level);
2874                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_exp_start_org_name'||p_requirement_in_tbl(i).search_exp_start_org_name, l_log_level);
2875                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_country_code'||p_requirement_in_tbl(i).search_country_code, l_log_level);
2876                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_country_name'||p_requirement_in_tbl(i).search_country_name, l_log_level);
2877                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').search_min_candidate_score'||p_requirement_in_tbl(i).search_min_candidate_score, l_log_level);
2878                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_org_id'||p_requirement_in_tbl(i).expenditure_org_id, l_log_level);
2879                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_org_name'||p_requirement_in_tbl(i).expenditure_org_name, l_log_level);
2880                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_organization_id'||p_requirement_in_tbl(i).expenditure_organization_id, l_log_level);
2881                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_organization_name'||p_requirement_in_tbl(i).expenditure_organization_name, l_log_level);
2882                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_type_class'||p_requirement_in_tbl(i).expenditure_type_class, l_log_level);
2883                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expenditure_type'||p_requirement_in_tbl(i).expenditure_type, l_log_level);
2884                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_group_id'||p_requirement_in_tbl(i).fcst_job_group_id, l_log_level);
2885                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_group_name'||p_requirement_in_tbl(i).fcst_job_group_name, l_log_level);
2886                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_id'||p_requirement_in_tbl(i).fcst_job_id, l_log_level);
2887                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').fcst_job_name'||p_requirement_in_tbl(i).fcst_job_name, l_log_level);
2888                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').work_type_id'||p_requirement_in_tbl(i).work_type_id, l_log_level);
2889                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').work_type_name'||p_requirement_in_tbl(i).work_type_name, l_log_level);
2890                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').bill_rate_option'||p_requirement_in_tbl(i).bill_rate_option, l_log_level);
2891                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').bill_rate_override'||p_requirement_in_tbl(i).bill_rate_override, l_log_level);
2892                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').bill_rate_curr_override'||p_requirement_in_tbl(i).bill_rate_curr_override, l_log_level);
2893                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').markup_percent_override'||p_requirement_in_tbl(i).markup_percent_override, l_log_level);
2894                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').discount_percentage'||p_requirement_in_tbl(i).discount_percentage, l_log_level);
2895                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').rate_disc_reason_code'||p_requirement_in_tbl(i).rate_disc_reason_code, l_log_level);
2896                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_rate_option'||p_requirement_in_tbl(i).tp_rate_option, l_log_level);
2897                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_rate_override'||p_requirement_in_tbl(i).tp_rate_override, l_log_level);
2898                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_currency_override'||p_requirement_in_tbl(i).tp_currency_override, l_log_level);
2899                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_calc_base_code_override'||p_requirement_in_tbl(i).tp_calc_base_code_override, l_log_level);
2900                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').tp_percent_applied_override'||p_requirement_in_tbl(i).tp_percent_applied_override, l_log_level);
2901                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').extension_possible'||p_requirement_in_tbl(i).extension_possible, l_log_level);
2902                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expense_owner'||p_requirement_in_tbl(i).expense_owner, l_log_level);
2903                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').expense_limit'||p_requirement_in_tbl(i).expense_limit, l_log_level);
2904                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').orig_system_code'||p_requirement_in_tbl(i).orig_system_code, l_log_level);
2905                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').orig_system_reference'||p_requirement_in_tbl(i).orig_system_reference, l_log_level);
2906                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').record_version_number'||p_requirement_in_tbl(i).record_version_number, l_log_level);
2907                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute_category'||p_requirement_in_tbl(i).attribute_category, l_log_level);
2908                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute1'||p_requirement_in_tbl(i).attribute1, l_log_level);
2909                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute2'||p_requirement_in_tbl(i).attribute2, l_log_level);
2910                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute3'||p_requirement_in_tbl(i).attribute3, l_log_level);
2911                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute4'||p_requirement_in_tbl(i).attribute4, l_log_level);
2912                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute5'||p_requirement_in_tbl(i).attribute5, l_log_level);
2913                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute6'||p_requirement_in_tbl(i).attribute6, l_log_level);
2914                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute7'||p_requirement_in_tbl(i).attribute7, l_log_level);
2915                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute8'||p_requirement_in_tbl(i).attribute8, l_log_level);
2916                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute9'||p_requirement_in_tbl(i).attribute9, l_log_level);
2917                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute10'||p_requirement_in_tbl(i).attribute10, l_log_level);
2918                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute11'||p_requirement_in_tbl(i).attribute11, l_log_level);
2919                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute12'||p_requirement_in_tbl(i).attribute12, l_log_level);
2920                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute13'||p_requirement_in_tbl(i).attribute13, l_log_level);
2921                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute14'||p_requirement_in_tbl(i).attribute14, l_log_level);
2922                         pa_debug.write(l_module, 'p_requirement_in_tbl('||i||').attribute15'||p_requirement_in_tbl(i).attribute15, l_log_level);
2923                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
2924                         i := p_requirement_in_tbl.next(i);
2925                 END LOOP;
2926         END IF;
2927 
2928         PA_STARTUP.INITIALIZE(
2929                   p_calling_application                 => l_calling_application
2930                 , p_calling_module                      => l_calling_module
2931                 , p_check_id_flag                       => l_check_id_flag
2932                 , p_check_role_security_flag            => l_check_role_security_flag
2933                 , p_check_resource_security_flag        => l_check_resource_security_flag
2934                 , p_debug_level                         => l_log_level
2935                 );
2936 
2937         IF l_debug_mode = 'Y' THEN
2938                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
2939         END IF;
2940 
2941         -- Page does not check PRM licensing, but keeping this code so in future if required, can be used
2942         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
2943         --IF l_prm_license_flag <> 'Y' THEN
2944         --        null;
2945         --END IF;
2946 
2947 
2948         i := p_requirement_in_tbl.first;
2949 
2950         WHILE i IS NOT NULL LOOP
2951                 l_error_flag_local := 'N';
2952                 l_missing_params := null;
2953                 l_req_rec := null;
2954                 l_valid_country := 'Y';
2955                 l_basic_info_changed := 'N';
2956                 l_candidate_info_changed := 'N';
2957                 l_fin_info_changed := 'N';
2958                 l_fin_bill_rate_info_changed := 'N';
2959                 l_fin_tp_rate_info_changed := 'N';
2960 
2961                 l_start_msg_count := FND_MSG_PUB.count_msg;
2962 
2963                 l_req_rec := p_requirement_in_tbl(i);
2964 
2965                 -- Mandatory Parameters Check
2966                 ------------------------------
2967 
2968                 IF l_debug_mode = 'Y' THEN
2969                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
2970                         pa_debug.write(l_module, '-----------------------------', l_log_level);
2971                         pa_debug.write(l_module, 'Validate requirement_id.', l_log_level);
2972                 END IF;
2973 
2974                         /*--Bug 6511907 PJR Date Validation Enhancement ----- Start--*/
2975                         /*-- Validating Resource Req Start and End Date against
2976                              Project Start and Completion dates --*/
2977 
2978                         Declare
2979                           l_validate           VARCHAR2(10);
2980                           l_start_date_status  VARCHAR2(10);
2981                           l_end_date_status    VARCHAR2(10);
2982                           l_start_date         DATE;
2983                           l_end_date           DATE;
2984                         Begin
2985                          If l_req_rec.start_date is not null or l_req_rec.end_date is not null then
2986                            l_start_date := l_req_rec.start_date;
2987                            l_end_date   := l_req_rec.end_date;
2988                            PA_PROJECT_DATES_UTILS.Validate_Resource_Dates
2989                                        (l_req_rec.project_id, l_start_date, l_end_date,
2990                                                    l_validate, l_start_date_status, l_end_date_status);
2991 
2992                            If l_validate = 'Y' and l_start_date_status = 'I' Then
2993 
2994                               pa_utils.add_message
2995                                ( p_app_short_name  => 'PA'
2996                                 ,p_msg_name	       => 'PA_PJR_DATE_START_ERROR'
2997                                 ,p_token1          => 'PROJ_TXN_START_DATE'
2998                                 ,p_value1          => GET_PROJECT_START_DATE(l_req_rec.project_id)
2999                                 ,p_token2          => ''
3000                                 ,p_value2          => ''
3001                                 ,p_token3          => ''
3002                                 ,p_value3          => ''
3003                                );
3004 
3005                               RAISE  FND_API.G_EXC_ERROR;
3006                            End If;
3007 
3008                            If l_validate = 'Y' and l_end_date_status = 'I' Then
3009 
3010                               pa_utils.add_message
3011                                ( p_app_short_name  => 'PA'
3012                                 ,p_msg_name	    => 'PA_PJR_DATE_FINISH_ERROR'
3013                                 ,p_token1          => 'PROJ_TXN_END_DATE'
3014                                 ,p_value1          => GET_PROJECT_COMPLETION_DATE(l_req_rec.project_id)
3015                                 ,p_token2          => ''
3016                                 ,p_value2          => ''
3017                                 ,p_token3          => ''
3018                                 ,p_value3          => ''
3019                                );
3020 
3021                               RAISE  FND_API.G_EXC_ERROR;
3022                            End If;
3023                          End If;
3024                         End;
3025 
3026                         /*--Bug 6511907 PJR Date Validation Enhancement ----- End--*/
3027                 l_req_dtls_csr := null;
3028                 OPEN c_get_requirement_details(l_req_rec.requirement_id);
3029                 FETCH c_get_requirement_details INTO l_req_dtls_csr;
3030 
3031                 IF c_get_requirement_details%NOTFOUND THEN
3032                         l_missing_params := l_missing_params||', REQUIREMENT_ID';
3033                 ELSE
3034                         l_system_status_code := null;
3035                         OPEN c_get_system_status_code(l_req_dtls_csr.status_code, 'OPEN_ASGMT');
3036                         FETCH c_get_system_status_code INTO l_system_status_code;
3037                         CLOSE c_get_system_status_code;
3038 
3039                         IF l_system_status_code IN ('OPEN_ASGMT_FILLED','OPEN_ASGMT_CANCEL') THEN
3040                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
3041                                 l_error_flag_local := 'Y';
3042                         END IF;
3043 
3044                         IF nvl(l_req_dtls_csr.mass_wf_in_progress_flag, 'N') = 'Y' THEN
3045                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_ASSIGNMENT_WF');
3046                                 l_error_flag_local := 'Y';
3047                         END IF;
3048                 END IF;
3049 
3050                 CLOSE c_get_requirement_details;
3051 
3052                 IF l_req_rec.work_type_id IS NULL AND l_req_rec.work_type_name IS NULL THEN
3053                         l_missing_params := l_missing_params||', WORK_TYPE_ID, WORK_TYPE_NAME';
3054                 END IF;
3055 
3056                 IF l_req_rec.min_resource_job_level IS NULL THEN
3057                         l_missing_params := l_missing_params||', MIN_RESOURCE_JOB_LEVEL';
3058                 END IF;
3059 
3060                 IF l_req_rec.max_resource_job_level IS NULL THEN
3061                         l_missing_params := l_missing_params||', MAX_RESOURCE_JOB_LEVEL';
3062                 END IF;
3063 
3064                 IF l_req_rec.location_id IS NULL OR l_req_rec.location_id = G_PA_MISS_NUM THEN
3065                         -- If either city or state (or) both are passed ,then country is
3066                         -- mandatory
3067                         IF (l_req_rec.location_country_code IS NULL AND l_req_rec.location_country_name IS NULL)
3068                            OR (l_req_rec.location_country_code =  G_PA_MISS_CHAR AND l_req_rec.location_country_name = G_PA_MISS_CHAR)
3069                         THEN
3070                                 IF (l_req_rec.location_region <> G_PA_MISS_CHAR AND l_req_rec.location_region IS NOT NULL)
3071                                     OR (l_req_rec.location_city <> G_PA_MISS_CHAR AND l_req_rec.location_city IS NOT NULL)
3072                                 THEN
3073                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE, LOCATION_COUNTRY_NAME';
3074                                         l_valid_country := 'N';
3075                                 END IF;
3076                         ELSIF l_req_rec.location_country_code IS NOT NULL AND l_req_rec.location_country_code <> G_PA_MISS_CHAR
3077                         THEN
3078                                 OPEN c_derive_country_name(l_req_rec.location_country_code);
3079                                 FETCH c_derive_country_name INTO l_req_rec.location_country_name;
3080                                 IF c_derive_country_name%NOTFOUND THEN
3081                                         -- Invalid Country code passed.
3082                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE';
3083                                         l_valid_country := 'N';
3084                                 ELSE
3085                                         l_valid_country := 'Y';
3086                                 END IF;
3087                                 CLOSE c_derive_country_name;
3088                         ELSIF l_req_rec.location_country_name IS NOT NULL AND l_req_rec.location_country_name <> G_PA_MISS_CHAR
3089                         THEN
3090                               OPEN c_derive_country_code(l_req_rec.location_country_name);
3091                               FETCH c_derive_country_code INTO l_req_rec.location_country_code;
3092                               IF c_derive_country_code%NOTFOUND THEN
3093                                         -- Invalid Country Name passed.
3094                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_NAME';
3095                                         l_valid_country := 'N';
3096                                ELSE
3097                                         l_valid_country := 'Y';
3098                               END IF;
3099                               CLOSE c_derive_country_code;
3100                         END IF;
3101 
3102                         -- If the country is valid,then proceed with the state and city validations
3103                         IF l_valid_country = 'Y' AND l_req_rec.location_country_code IS NOT NULL
3104                         AND l_req_rec.location_country_code <> G_PA_MISS_CHAR
3105                         THEN
3106 
3107                                 IF l_req_rec.location_id = G_PA_MISS_NUM THEN
3108                                         OPEN c_get_location(l_req_dtls_csr.location_id);
3109                                         FETCH c_get_location INTO l_dummy_country_code, l_dummy_state, l_dummy_city;
3110                                         CLOSE c_get_location;
3111                                 END IF;
3112 
3113                                 l_dummy_country_code := l_req_rec.location_country_code;
3114 
3115                                 IF l_req_rec.location_region IS NULL THEN
3116                                         l_dummy_state := null;
3117                                 ELSIF l_req_rec.location_region = G_PA_MISS_CHAR THEN
3118                                         l_dummy_state := l_dummy_state;
3119                                 ELSE
3120                                         l_dummy_state := l_req_rec.location_region;
3121                                 END IF;
3122 
3123                                 IF l_req_rec.location_city IS NULL THEN
3124                                         l_dummy_city := null;
3125                                 ELSIF l_req_rec.location_city = G_PA_MISS_CHAR THEN
3126                                         l_dummy_city := l_dummy_city;
3127                                 ELSE
3128                                         l_dummy_city := l_req_rec.location_city;
3129                                 END IF;
3130 
3131                                 PA_LOCATION_UTILS.CHECK_LOCATION_EXISTS
3132                                 (
3133                                          p_country_code         => l_dummy_country_code
3134                                         ,p_city		        => l_dummy_city
3135                                         ,p_region	        => l_dummy_state
3136                                         ,x_location_id	        => l_out_location_id
3137                                         ,x_return_status        => l_return_status
3138                                 );
3139 
3140                                 IF l_out_location_id IS NULL THEN
3141                                         PA_UTILS.ADD_MESSAGE('PA','PA_AMG_RES_INV_CRC_COMB');
3142                                         l_error_flag_local := 'Y'; -- 5148975
3143                                 ELSE
3144                                         l_req_rec.location_id := l_out_location_id;
3145                                 END IF;
3146                         END IF;
3147                 ELSE
3148                         -- if location id is passed, then it will override the city, region, country code
3149                         OPEN c_get_location(l_req_rec.location_id);
3150                         FETCH c_get_location INTO l_req_rec.location_country_code, l_req_rec.location_region, l_req_rec.location_city;
3151 
3152                         IF c_get_location%NOTFOUND THEN
3153                                 l_missing_params := l_missing_params||', LOCATION_ID';
3154                         END IF;
3155                         CLOSE c_get_location;
3156                 END IF; -- l_req_rec.location_id IS NULL OR l_req_rec.location_id = FND_API.G_MISS_NUM
3157 
3158 
3159 
3160                 -- For start date, and end dates, status, calendar uses cant update from this flow
3161                 --IF l_req_rec.start_date IS NULL THEN
3162                 --        l_missing_params := l_missing_params||', START_DATE';
3163                 --END IF;
3164 
3165                 --IF l_req_rec.end_date IS NULL THEN
3166                 --        l_missing_params := l_missing_params||', END_DATE';
3167                 --END IF;
3168 
3169                 --IF l_req_rec.status_code IS NULL AND l_req_rec.status_name IS NULL THEN
3170                 --        l_missing_params := l_missing_params||', STATUS_CODE, STATUS_NAME';
3171                 --END IF;
3172 
3173                 --IF l_req_rec.calendar_id IS NULL AND l_req_rec.calendar_name IS NULL THEN
3174                 --        l_missing_params := l_missing_params||', CALENDAR_ID, CALENDAR_NAME';
3175                 --END IF;
3176 
3177                 IF nvl(l_req_dtls_csr.template_flag, 'N') = 'N' AND l_req_dtls_csr.project_id IS NOT NULL THEN
3178                         -- Project Requirement Flow
3179 
3180                         -- These checks are NULL checks, which means user is passing them explicitely as NULL
3181                         -- If user does not pass anything, then it will be G_PA_MISS_XXX
3182 
3183                         IF l_req_rec.comp_match_weighting IS NULL THEN
3184                                 l_missing_params := l_missing_params||', COMP_MATCH_WEIGHTING';
3185                         END IF;
3186 
3187                         IF l_req_rec.avail_match_weighting IS NULL THEN
3188                                 l_missing_params := l_missing_params||', AVAIL_MATCH_WEIGHTING';
3189                         END IF;
3190 
3191                         IF l_req_rec.job_level_match_weighting IS NULL THEN
3192                                 l_missing_params := l_missing_params||', JOB_LEVEL_MATCH_WEIGHTING';
3193                         END IF;
3194 
3195                         -- Let enable_auto_cand_nom_flag be null, If null then we shd take it as N
3196                         --IF l_req_rec.enable_auto_cand_nom_flag IS NULL THEN
3197                         --        l_missing_params := l_missing_params||', ENABLE_AUTO_CAND_NOM_FLAG';
3198                         --END IF;
3199 
3200                         IF l_req_rec.search_min_availability IS NULL THEN
3201                                 l_missing_params := l_missing_params||', SEARCH_MIN_AVAILABILITY';
3202                         END IF;
3203 
3204                         IF l_req_rec.search_exp_org_str_ver_id IS NULL AND l_req_rec.search_exp_org_hier_name IS NULL THEN
3205                                 l_missing_params := l_missing_params||', SEARCH_EXP_ORG_STR_VER_ID, SEARCH_EXP_ORG_HIER_NAME';
3206                         END IF;
3207 
3208                         IF l_req_rec.search_exp_start_org_id IS NULL AND l_req_rec.search_exp_start_org_name IS NULL THEN
3209                                 l_missing_params := l_missing_params||', SEARCH_EXP_START_ORG_ID, SEARCH_EXP_START_ORG_NAME';
3210                         END IF;
3211 
3212                         IF l_req_rec.search_min_candidate_score IS NULL THEN
3213                                 l_missing_params := l_missing_params||', SEARCH_MIN_CANDIDATE_SCORE';
3214                         END IF;
3215 
3216                         IF l_req_rec.expenditure_org_id IS NULL AND l_req_rec.expenditure_org_name IS NULL THEN
3217                                 l_missing_params := l_missing_params||', EXPENDITURE_ORG_ID, EXPENDITURE_ORG_NAME';
3218                         END IF;
3219 
3220                         IF l_req_rec.expenditure_organization_id IS NULL AND l_req_rec.expenditure_organization_name IS NULL THEN
3221                                 l_missing_params := l_missing_params||', EXPENDITURE_ORGANIZATION_ID, EXPENDITURE_ORGANIZATION_NAME';
3222                         END IF;
3223 
3224                         IF l_req_rec.expenditure_type_class IS NULL THEN
3225                                 l_missing_params := l_missing_params||', EXPENDITURE_TYPE_CLASS';
3226                         END IF;
3227 
3228                         IF l_req_rec.expenditure_type IS NULL THEN
3229                                 l_missing_params := l_missing_params||', EXPENDITURE_TYPE';
3230                         END IF;
3231 
3232                         IF l_req_rec.bill_rate_option IS NULL THEN
3233                                 l_missing_params := l_missing_params||', BILL_RATE_OPTION';
3234                         ELSIF l_req_rec.bill_rate_option <> G_PA_MISS_CHAR AND l_req_rec.bill_rate_option NOT IN('RATE','MARKUP','DISCOUNT','NONE') THEN
3235                                 l_missing_params := l_missing_params||', BILL_RATE_OPTION';
3236                         ELSIF l_req_rec.bill_rate_option = 'NONE' THEN
3237                                 l_req_rec.bill_rate_override := null;
3238                                 l_req_rec.bill_rate_curr_override := null;
3239                                 l_req_rec.markup_percent_override := null;
3240                                 l_req_rec.discount_percentage := null;
3241                                 l_req_rec.rate_disc_reason_code := null;
3242                         ELSIF l_req_rec.bill_rate_option = 'RATE' THEN
3243                                 l_req_rec.markup_percent_override := null;
3244                                 l_req_rec.discount_percentage := null;
3245                                 IF (l_req_rec.bill_rate_override IS NULL OR l_req_rec.bill_rate_override = G_PA_MISS_NUM)
3246                                 AND l_req_dtls_csr.bill_rate_override IS NULL
3247                                 THEN
3248                                         l_missing_params := l_missing_params||', BILL_RATE_OVERRIDE';
3249                                 END IF;
3250                         ELSIF l_req_rec.bill_rate_option = 'MARKUP' THEN
3251                                 l_req_rec.bill_rate_override := null;
3252                                 l_req_rec.bill_rate_curr_override := null;
3253                                 l_req_rec.discount_percentage := null;
3254                                 IF (l_req_rec.markup_percent_override IS NULL OR l_req_rec.markup_percent_override = G_PA_MISS_NUM)
3255                                 AND l_req_dtls_csr.markup_percent_override IS NULL
3256                                 THEN
3257                                         l_missing_params := l_missing_params||', MARKUP_PERCENT_OVERRIDE';
3258                                 END IF;
3259                         ELSIF l_req_rec.bill_rate_option = 'DISCOUNT' THEN
3260                                 l_req_rec.bill_rate_override := null;
3261                                 l_req_rec.bill_rate_curr_override := null;
3262                                 l_req_rec.markup_percent_override := null;
3263                                 IF (l_req_rec.discount_percentage IS NULL OR l_req_rec.discount_percentage = G_PA_MISS_NUM)
3264                                 AND l_req_dtls_csr.discount_percentage IS NULL
3265                                 THEN
3266                                         l_missing_params := l_missing_params||', DISCOUNT_PERCENTAGE';
3267                                 END IF;
3268                         END IF;
3269 
3270 
3271                         IF l_req_rec.tp_rate_option IS NULL THEN
3272                                 l_missing_params := l_missing_params||', TP_RATE_OPTION';
3273                         ELSIF l_req_rec.tp_rate_option <> G_PA_MISS_CHAR AND l_req_rec.tp_rate_option NOT IN('RATE','BASIS','NONE')
3274                         THEN
3275                                 l_missing_params := l_missing_params||', TP_RATE_OPTION';
3276                         ELSIF l_req_rec.tp_rate_option = 'NONE' THEN
3277                                 l_req_rec.tp_rate_override := null;
3278                                 l_req_rec.tp_currency_override := null;
3279                                 l_req_rec.tp_calc_base_code_override := null;
3280                                 l_req_rec.tp_percent_applied_override := null;
3281                         ELSIF l_req_rec.tp_rate_option = 'RATE' THEN
3282                                 l_req_rec.tp_calc_base_code_override := null;
3283                                 l_req_rec.tp_percent_applied_override := null;
3284                                 IF (((l_req_rec.tp_rate_override IS NULL OR l_req_rec.tp_rate_override = G_PA_MISS_NUM)
3285                                         AND l_req_dtls_csr.tp_rate_override IS NULL)
3286                                     OR
3287                                      ((l_req_rec.tp_currency_override IS NULL OR l_req_rec.tp_currency_override = G_PA_MISS_CHAR)
3288                                         AND l_req_dtls_csr.tp_currency_override IS NULL)
3289                                     )
3290                                 THEN
3291                                         l_missing_params := l_missing_params||', TP_RATE_OVERRIDE, TP_CURRENCY_OVERRIDE';
3292                                 END IF;
3293                         ELSIF l_req_rec.tp_rate_option = 'BASIS' THEN
3294                                 l_req_rec.tp_rate_override := null;
3295                                 l_req_rec.tp_currency_override := null;
3296                                 IF (((l_req_rec.tp_calc_base_code_override IS NULL OR l_req_rec.tp_calc_base_code_override = G_PA_MISS_CHAR)
3297                                         AND l_req_dtls_csr.tp_calc_base_code_override IS NULL)
3298                                     OR
3299                                      ((l_req_rec.tp_percent_applied_override IS NULL OR l_req_rec.tp_percent_applied_override = G_PA_MISS_NUM)
3300                                         AND l_req_dtls_csr.tp_percent_applied_override IS NULL)
3301                                     )
3302                                 THEN
3303                                         l_missing_params := l_missing_params||', TP_CALC_BASE_CODE_OVERRIDE, TP_PERCENT_APPLIED_OVERRIDE';
3304                                 END IF;
3305                         END IF;
3306 
3307                         IF l_req_rec.extension_possible <>  G_PA_MISS_CHAR AND l_req_rec.extension_possible NOT IN ('Y','N') THEN
3308                                 l_missing_params := l_missing_params||', EXTENSION_POSSIBLE';
3309                         END IF;
3310                 END IF; -- nvl(l_req_dtls_csr.team_template_flag, 'N')
3311 
3312                 IF l_debug_mode = 'Y' THEN
3313                         pa_debug.write(l_module, 'Mandatory parameter validation over. List of Missing Parameters='||l_missing_params, l_log_level);
3314                 END IF;
3315 
3316                 IF l_missing_params IS NOT NULL THEN
3317                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
3318                                                 'INVALID_PARAMS', l_missing_params);
3319                         l_error_flag_local := 'Y';
3320                 END IF;
3321 
3322                 -- Retrieve values from data base if Parameters are not passed.
3323                 ---------------------------------------------------------------
3324 
3325 
3326                 IF l_debug_mode = 'Y' THEN
3327                         pa_debug.write(l_module, 'Take values from database for those parameters which are not passed.', l_log_level);
3328                 END IF;
3329 
3330                 IF l_req_rec.requirement_name = G_PA_MISS_CHAR THEN
3331                         l_req_rec.requirement_name := l_req_dtls_csr.assignment_name;
3332                 END IF;
3333 
3334 
3335                 -- These parameters are Not used for Update Flow:
3336 
3337                 -- Internal API requires to pass FND_API miss nums instead of null
3338                 -- if we pass null, they treat it as update and raise error
3339                 l_req_rec.team_template_id := l_req_dtls_csr.assignment_template_id;
3340 
3341                 l_req_rec.number_of_requirements := FND_API.G_MISS_NUM;
3342 
3343                 l_req_rec.project_role_id := FND_API.G_MISS_NUM;
3344 
3345                 l_req_rec.project_role_name := FND_API.G_MISS_CHAR;
3346 
3347                 l_req_rec.project_id := l_req_dtls_csr.project_id;
3348 
3349                 l_req_rec.project_name := FND_API.G_MISS_CHAR;
3350 
3351                 l_req_rec.project_number := FND_API.G_MISS_CHAR;
3352 
3353                 IF l_req_rec.staffing_owner_person_id = G_PA_MISS_NUM THEN
3354                         l_req_rec.staffing_owner_person_id := l_req_dtls_csr.staffing_owner_person_id;
3355                 END IF;
3356 
3357                 IF l_req_rec.staffing_priority_code = G_PA_MISS_CHAR THEN
3358                         l_req_rec.staffing_priority_code := l_req_dtls_csr.staffing_priority_code;
3359                 END IF;
3360 
3361                 IF l_req_rec.staffing_priority_name = G_PA_MISS_CHAR THEN
3362                         l_req_rec.staffing_priority_name := null;
3363                 END IF;
3364 
3365                 l_project_subteam_party_id := null;
3366 
3367                 OPEN c_get_subteam_party_id(l_req_rec.requirement_id);
3368                 FETCH c_get_subteam_party_id INTO l_project_subteam_party_id, l_project_subteam_id;
3369                 CLOSE c_get_subteam_party_id;
3370 
3371                 IF l_req_rec.project_subteam_id = G_PA_MISS_NUM THEN
3372                         -- The reason we need to check name here, because
3373                         -- If name is passed and id is not. In this case, id
3374                         -- will default to previous id and new name will be lost
3375                         IF l_req_rec.project_subteam_name = G_PA_MISS_CHAR THEN
3376                                 l_req_rec.project_subteam_id := l_project_subteam_id;
3377                         ELSIF l_req_rec.project_subteam_name IS NULL THEN
3378                                 l_req_rec.project_subteam_id := null;
3379                         ELSE
3380                                 l_req_rec.project_subteam_id := null;
3381                         END IF;
3382                 END IF;
3383 
3384                 IF l_req_rec.project_subteam_name = G_PA_MISS_CHAR THEN
3385                         l_req_rec.project_subteam_name := null;
3386                 END IF;
3387 
3388 
3389                 IF l_req_rec.location_id = G_PA_MISS_NUM THEN
3390                         l_req_rec.location_id := l_req_dtls_csr.location_id;
3391                 END IF;
3392 
3393                 IF l_req_rec.location_country_code = G_PA_MISS_CHAR THEN
3394                         l_req_rec.location_country_code := null;
3395                 END IF;
3396 
3397                 IF l_req_rec.location_country_name = G_PA_MISS_CHAR THEN
3398                         l_req_rec.location_country_name := null;
3399                 END IF;
3400 
3401                 IF l_req_rec.location_region = G_PA_MISS_CHAR THEN
3402                         l_req_rec.location_region := null;
3403                 END IF;
3404 
3405                 IF l_req_rec.location_city = G_PA_MISS_CHAR THEN
3406                         l_req_rec.location_city := null;
3407                 END IF;
3408 
3409                 IF l_req_rec.min_resource_job_level = G_PA_MISS_NUM THEN
3410                         l_req_rec.min_resource_job_level := l_req_dtls_csr.min_resource_job_level;
3411                 END IF;
3412 
3413                 IF l_req_rec.max_resource_job_level = G_PA_MISS_NUM THEN
3414                         l_req_rec.max_resource_job_level := l_req_dtls_csr.max_resource_job_level;
3415                 END IF;
3416 
3417                 IF l_req_rec.description = G_PA_MISS_CHAR THEN
3418                         l_req_rec.description := l_req_dtls_csr.description;
3419                 END IF;
3420 
3421                 IF l_req_rec.additional_information = G_PA_MISS_CHAR THEN
3422                         l_req_rec.additional_information := l_req_dtls_csr.additional_information;
3423                 END IF;
3424 
3425                 -- These parameters are not For Update flow
3426                 l_req_rec.start_date := l_req_dtls_csr.start_date;
3427                 l_req_rec.end_date := l_req_dtls_csr.end_date;
3428                 l_req_rec.status_code := l_req_dtls_csr.status_code;
3429                 l_req_rec.status_name := null;
3430                 l_req_rec.calendar_type := null;
3431                 l_req_rec.calendar_id := l_req_dtls_csr.calendar_id;
3432                 l_req_rec.calendar_name := null;
3433                 l_req_rec.start_adv_action_set_flag := null;
3434                 l_req_rec.adv_action_set_id := null;
3435                 l_req_rec.adv_action_set_name := null;
3436 
3437 
3438                 IF l_req_rec.comp_match_weighting = G_PA_MISS_NUM THEN
3439                         l_req_rec.comp_match_weighting := l_req_dtls_csr.competence_match_weighting;
3440                 END IF;
3441 
3442                 IF l_req_rec.avail_match_weighting = G_PA_MISS_NUM THEN
3443                         l_req_rec.avail_match_weighting := l_req_dtls_csr.availability_match_weighting;
3444                 END IF;
3445 
3446                 IF l_req_rec.job_level_match_weighting = G_PA_MISS_NUM THEN
3447                         l_req_rec.job_level_match_weighting := l_req_dtls_csr.job_level_match_weighting;
3448                 END IF;
3449 
3450                 IF l_req_rec.enable_auto_cand_nom_flag = G_PA_MISS_CHAR THEN
3451                         l_req_rec.enable_auto_cand_nom_flag := l_req_dtls_csr.enable_auto_cand_nom_flag;
3452                 END IF;
3453 
3454                 -- Treat null as N for flags
3455                 IF l_req_rec.enable_auto_cand_nom_flag IS NULL THEN
3456                         l_req_rec.enable_auto_cand_nom_flag := 'N';
3457                 END IF;
3458 
3459                 IF l_req_rec.search_min_availability = G_PA_MISS_NUM THEN
3460                         l_req_rec.search_min_availability := l_req_dtls_csr.search_min_availability;
3461                 END IF;
3462 
3463                 IF l_req_rec.search_exp_org_str_ver_id = G_PA_MISS_NUM THEN
3464                         IF l_req_rec.search_exp_org_hier_name = G_PA_MISS_CHAR THEN
3465                                 l_req_rec.search_exp_org_str_ver_id := l_req_dtls_csr.search_exp_org_struct_ver_id;
3466                         ELSIF l_req_rec.search_exp_org_hier_name IS NULL THEN
3467                                 l_req_rec.search_exp_org_str_ver_id := null;
3468                         ELSE
3469                                 l_req_rec.search_exp_org_str_ver_id := null;
3470                         END IF;
3471                 END IF;
3472 
3473                 IF l_req_rec.search_exp_org_hier_name = G_PA_MISS_CHAR THEN
3474                         l_req_rec.search_exp_org_hier_name := null;
3475                 END IF;
3476 
3477                 IF l_req_rec.search_exp_start_org_id = G_PA_MISS_NUM THEN
3478                         IF l_req_rec.search_exp_start_org_name = G_PA_MISS_CHAR THEN
3479                                 l_req_rec.search_exp_start_org_id := l_req_dtls_csr.search_exp_start_org_id;
3480                         ELSIF l_req_rec.search_exp_start_org_name IS NULL THEN
3481                                 l_req_rec.search_exp_start_org_id := null;
3482                         ELSE
3483                                 l_req_rec.search_exp_start_org_id := null;
3484                         END IF;
3485                 END IF;
3486 
3487                 IF l_req_rec.search_exp_start_org_name = G_PA_MISS_CHAR THEN
3488                         l_req_rec.search_exp_start_org_name := null;
3489                 END IF;
3490 
3491                 IF l_req_rec.search_country_code = G_PA_MISS_CHAR THEN
3492                         IF l_req_rec.search_country_name = G_PA_MISS_CHAR THEN
3493                                 l_req_rec.search_country_code := l_req_dtls_csr.search_country_code;
3494                         ELSIF l_req_rec.search_country_name IS NULL THEN
3495                                 l_req_rec.search_country_code := null;
3496                         ELSE
3497                                 l_req_rec.search_country_code := null;
3498                         END IF;
3499                 END IF;
3500 
3501                 IF l_req_rec.search_country_name = G_PA_MISS_CHAR THEN
3502                         l_req_rec.search_country_name := null;
3503                 END IF;
3504 
3505                 IF l_req_rec.search_min_candidate_score = G_PA_MISS_NUM THEN
3506                         l_req_rec.search_min_candidate_score := l_req_dtls_csr.search_min_candidate_score;
3507                 END IF;
3508 
3509                 IF l_req_rec.expenditure_org_id = G_PA_MISS_NUM THEN
3510                         IF l_req_rec.expenditure_org_name = G_PA_MISS_CHAR THEN
3511                                 l_req_rec.expenditure_org_id := l_req_dtls_csr.expenditure_org_id;
3512                         ELSIF l_req_rec.expenditure_org_name IS NULL THEN
3513                                 l_req_rec.expenditure_org_id := null;
3514                         ELSE
3515                                 l_req_rec.expenditure_org_id := null;
3516                         END IF;
3517                 END IF;
3518 
3519                 IF l_req_rec.expenditure_org_name = G_PA_MISS_CHAR THEN
3520                         l_req_rec.expenditure_org_name := null;
3521                 END IF;
3522 
3523                 IF l_req_rec.expenditure_organization_id = G_PA_MISS_NUM THEN
3524                         IF l_req_rec.expenditure_organization_name = G_PA_MISS_CHAR THEN
3525                                 l_req_rec.expenditure_organization_id := l_req_dtls_csr.expenditure_organization_id;
3526                         ELSIF l_req_rec.expenditure_organization_name IS NULL THEN
3527                                 l_req_rec.expenditure_organization_id := null;
3528                         ELSE
3529                                 l_req_rec.expenditure_organization_id := null;
3530                         END IF;
3531                 END IF;
3532 
3533                 IF l_req_rec.expenditure_organization_name = G_PA_MISS_CHAR THEN
3534                         l_req_rec.expenditure_organization_name := null;
3535                 END IF;
3536 
3537                 IF l_req_rec.expenditure_type_class = G_PA_MISS_CHAR THEN
3538                         l_req_rec.expenditure_type_class := l_req_dtls_csr.expenditure_type_class;
3539                 END IF;
3540 
3541                 IF l_req_rec.expenditure_type = G_PA_MISS_CHAR THEN
3542                         l_req_rec.expenditure_type := l_req_dtls_csr.expenditure_type;
3543                 END IF;
3544 
3545 
3546                 IF l_req_rec.fcst_job_group_id = G_PA_MISS_NUM THEN
3547                         IF l_req_rec.fcst_job_group_name = G_PA_MISS_CHAR THEN
3548                                 l_req_rec.fcst_job_group_id := l_req_dtls_csr.fcst_job_group_id;
3549                         ELSIF l_req_rec.fcst_job_group_name IS NULL THEN
3550                                 l_req_rec.fcst_job_group_id := null;
3551                         ELSE
3552                                 l_req_rec.fcst_job_group_id := null;
3553                         END IF;
3554                 END IF;
3555 
3556                 IF l_req_rec.fcst_job_group_name = G_PA_MISS_CHAR THEN
3557                         l_req_rec.fcst_job_group_name := null;
3558                 END IF;
3559 
3560                 IF l_req_rec.fcst_job_id = G_PA_MISS_NUM THEN
3561                         IF l_req_rec.fcst_job_name = G_PA_MISS_CHAR THEN
3562                                 l_req_rec.fcst_job_id := l_req_dtls_csr.fcst_job_id;
3563                         ELSIF l_req_rec.fcst_job_name IS NULL THEN
3564                                 l_req_rec.fcst_job_id := null;
3565                         ELSE
3566                                 l_req_rec.fcst_job_id := null;
3567                         END IF;
3568                 END IF;
3569 
3570                 IF l_req_rec.fcst_job_name = G_PA_MISS_CHAR THEN
3571                         l_req_rec.fcst_job_name := null;
3572                 END IF;
3573 
3574                 IF l_req_rec.work_type_id = G_PA_MISS_NUM THEN
3575                         IF l_req_rec.work_type_name = G_PA_MISS_CHAR THEN
3576                                 l_req_rec.work_type_id := l_req_dtls_csr.work_type_id;
3577                         ELSIF l_req_rec.work_type_name IS NULL THEN
3578                                 l_req_rec.work_type_id := null;
3579                         ELSE
3580                                 l_req_rec.work_type_id := null;
3581                         END IF;
3582                 END IF;
3583 
3584                 IF l_req_rec.work_type_name = G_PA_MISS_CHAR THEN
3585                         l_req_rec.work_type_name := null;
3586                 END IF;
3587 
3588                 -- No need to default this
3589                 --  l_req_rec.bill_rate_option := 'NONE';
3590 
3591                 IF l_req_rec.bill_rate_override = G_PA_MISS_NUM THEN
3592                         l_req_rec.bill_rate_override := l_req_dtls_csr.bill_rate_override;
3593                 END IF;
3594 
3595                 IF l_req_rec.bill_rate_curr_override = G_PA_MISS_CHAR THEN
3596                         l_req_rec.bill_rate_curr_override := l_req_dtls_csr.bill_rate_curr_override;
3597                 END IF;
3598 
3599                 IF l_req_rec.markup_percent_override = G_PA_MISS_NUM THEN
3600                         l_req_rec.markup_percent_override := l_req_dtls_csr.markup_percent_override;
3601                 END IF;
3602 
3603                 IF l_req_rec.discount_percentage = G_PA_MISS_NUM THEN
3604                         l_req_rec.discount_percentage := l_req_dtls_csr.discount_percentage;
3605                 END IF;
3606 
3607                 IF l_req_rec.rate_disc_reason_code = G_PA_MISS_CHAR THEN
3608                         l_req_rec.rate_disc_reason_code := l_req_dtls_csr.rate_disc_reason_code;
3609                 END IF;
3610 
3611                 -- No need to default this
3612                 -- l_req_rec.tp_rate_option := 'NONE';
3613 
3614                 IF l_req_rec.tp_rate_override = G_PA_MISS_NUM THEN
3615                         l_req_rec.tp_rate_override := l_req_dtls_csr.tp_rate_override;
3616                 END IF;
3617 
3618                 IF l_req_rec.tp_currency_override = G_PA_MISS_CHAR THEN
3619                         l_req_rec.tp_currency_override := l_req_dtls_csr.tp_currency_override;
3620                 END IF;
3621 
3622                 IF l_req_rec.tp_calc_base_code_override = G_PA_MISS_CHAR THEN
3623                         l_req_rec.tp_calc_base_code_override := l_req_dtls_csr.tp_calc_base_code_override;
3624                 END IF;
3625 
3626                 IF l_req_rec.tp_percent_applied_override = G_PA_MISS_NUM THEN
3627                         l_req_rec.tp_percent_applied_override := l_req_dtls_csr.tp_percent_applied_override;
3628                 END IF;
3629 
3630                 IF l_req_rec.extension_possible = G_PA_MISS_CHAR THEN
3631                         l_req_rec.extension_possible := l_req_dtls_csr.extension_possible;
3632                 END IF;
3633 
3634                 IF l_req_rec.expense_owner = G_PA_MISS_CHAR THEN
3635                         l_req_rec.expense_owner := l_req_dtls_csr.expense_owner;
3636                 END IF;
3637 
3638                 IF l_req_rec.expense_limit = G_PA_MISS_NUM THEN
3639                         l_req_rec.expense_limit := l_req_dtls_csr.expense_limit;
3640                 END IF;
3641 
3642                 IF l_req_rec.orig_system_code = G_PA_MISS_CHAR THEN
3643                         l_req_rec.orig_system_code := l_req_dtls_csr.orig_system_code;
3644                 END IF;
3645 
3646                 IF l_req_rec.orig_system_reference = G_PA_MISS_CHAR THEN
3647                         l_req_rec.orig_system_reference := l_req_dtls_csr.orig_system_reference;
3648                 END IF;
3649 
3650                 IF l_req_rec.record_version_number = G_PA_MISS_NUM THEN
3651                         l_req_rec.record_version_number := l_req_dtls_csr.record_version_number;
3652                 END IF;
3653 
3654                 IF l_req_rec.attribute_category = G_PA_MISS_CHAR THEN
3655                         l_req_rec.attribute_category := l_req_dtls_csr.attribute_category;
3656                 END IF;
3657 
3658                 IF l_req_rec.attribute1 = G_PA_MISS_CHAR THEN
3659                         l_req_rec.attribute1 := l_req_dtls_csr.attribute1;
3660                 END IF;
3661 
3662                 IF l_req_rec.attribute2 = G_PA_MISS_CHAR THEN
3663                         l_req_rec.attribute2 := l_req_dtls_csr.attribute2;
3664                 END IF;
3665 
3666                 IF l_req_rec.attribute3 = G_PA_MISS_CHAR THEN
3667                         l_req_rec.attribute3 := l_req_dtls_csr.attribute3;
3668                 END IF;
3669 
3670                 IF l_req_rec.attribute4 = G_PA_MISS_CHAR THEN
3671                         l_req_rec.attribute4 := l_req_dtls_csr.attribute4;
3672                 END IF;
3673 
3674                 IF l_req_rec.attribute5 = G_PA_MISS_CHAR THEN
3675                         l_req_rec.attribute5 := l_req_dtls_csr.attribute5;
3676                 END IF;
3677 
3678                 IF l_req_rec.attribute6 = G_PA_MISS_CHAR THEN
3679                         l_req_rec.attribute6 := l_req_dtls_csr.attribute6;
3680                 END IF;
3681 
3682                 IF l_req_rec.attribute7 = G_PA_MISS_CHAR THEN
3683                         l_req_rec.attribute7 := l_req_dtls_csr.attribute7;
3684                 END IF;
3685 
3686                 IF l_req_rec.attribute8 = G_PA_MISS_CHAR THEN
3687                         l_req_rec.attribute8 := l_req_dtls_csr.attribute8;
3688                 END IF;
3689 
3690                 IF l_req_rec.attribute9 = G_PA_MISS_CHAR THEN
3691                         l_req_rec.attribute9 := l_req_dtls_csr.attribute9;
3692                 END IF;
3693 
3694                 IF l_req_rec.attribute10 = G_PA_MISS_CHAR THEN
3695                         l_req_rec.attribute10 := l_req_dtls_csr.attribute10;
3696                 END IF;
3697 
3698                 IF l_req_rec.attribute11 = G_PA_MISS_CHAR THEN
3699                         l_req_rec.attribute11 := l_req_dtls_csr.attribute11;
3700                 END IF;
3701 
3702                 IF l_req_rec.attribute12 = G_PA_MISS_CHAR THEN
3703                         l_req_rec.attribute12 := l_req_dtls_csr.attribute12;
3704                 END IF;
3705 
3706                 IF l_req_rec.attribute13 = G_PA_MISS_CHAR THEN
3707                         l_req_rec.attribute13 := l_req_dtls_csr.attribute13;
3708                 END IF;
3709 
3710                 IF l_req_rec.attribute14 = G_PA_MISS_CHAR THEN
3711                         l_req_rec.attribute14 := l_req_dtls_csr.attribute14;
3712                 END IF;
3713 
3714                 IF l_req_rec.attribute15 = G_PA_MISS_CHAR THEN
3715                         l_req_rec.attribute15 := l_req_dtls_csr.attribute15;
3716                 END IF;
3717 
3718 
3719                 IF l_debug_mode = 'Y' THEN
3720                         pa_debug.write(l_module, 'Got the values from database.', l_log_level);
3721                         pa_debug.write(l_module, 'DB value of ProjectId='||l_req_dtls_csr.project_id, l_log_level);
3722                         pa_debug.write(l_module, 'DB value of TeamTemplateId='||l_req_dtls_csr.assignment_template_id, l_log_level);
3723                         pa_debug.write(l_module, 'DB value of TeamTemplateFlag='||l_req_dtls_csr.template_flag, l_log_level);
3724                         pa_debug.write(l_module, 'l_error_flag_local='||l_error_flag_local, l_log_level);
3725                 END IF;
3726 
3727 
3728                 -- All validations are not required as some validation is done in underlying code
3729                 -- Here, we are doing only those validations which are not done internally.
3730 
3731                 IF l_error_flag_local <> 'Y' AND nvl(l_req_dtls_csr.template_flag,'N') = 'N' THEN
3732                         -- Project Requirement Flow
3733 
3734 
3735                         -- Bill Rate Options Validation
3736                         -------------------------------
3737 
3738                         IF l_req_rec.bill_rate_option <> 'NONE' THEN
3739                                 l_rate_discount_reason_flag := 'N';
3740                                 l_br_override_flag := 'N';
3741                                 l_br_discount_override_flag := 'N';
3742 
3743                                 OPEN get_bill_rate_override_flags(l_req_rec.project_id);
3744                                 FETCH get_bill_rate_override_flags INTO  l_rate_discount_reason_flag, l_br_override_flag, l_br_discount_override_flag;
3745                                 CLOSE get_bill_rate_override_flags;
3746 
3747                                 IF l_debug_mode = 'Y' THEN
3748                                         pa_debug.write(l_module, 'Validating Bill Rate Options', l_log_level);
3749                                         pa_debug.write(l_module, 'l_rate_discount_reason_flag='||l_rate_discount_reason_flag, l_log_level);
3750                                         pa_debug.write(l_module, 'l_br_override_flag='||l_br_override_flag, l_log_level);
3751                                         pa_debug.write(l_module, 'l_br_discount_override_flag='||l_br_discount_override_flag, l_log_level);
3752                                 END IF;
3753 
3754                                 IF l_req_rec.bill_rate_option = 'RATE' THEN
3755 
3756                                         IF l_br_override_flag <> 'Y' OR l_req_rec.bill_rate_override <= 0 THEN /* OR l_req_rec.bill_rate_override > 100 - Removed for Bug 5703021*/
3757                                                 IF l_br_override_flag <> 'Y' THEN
3758                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
3759                                                         l_error_flag_local := 'Y';
3760                                                 ELSE
3761                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_BILL_RATE_OVRD');
3762                                                         l_error_flag_local := 'Y';
3763                                                 END IF;
3764                                         END IF;
3765 
3766                                         -- 5144288, 5144369 : Begin
3767                                         l_multi_currency_billing_flag := null;
3768                                         OPEN c_get_mcb_flag(l_req_rec.project_id);
3769                                         FETCH c_get_mcb_flag INTO l_multi_currency_billing_flag;
3770                                         CLOSE c_get_mcb_flag;
3771 
3772                                         IF nvl(l_multi_currency_billing_flag,'N') = 'Y' AND l_br_override_flag = 'Y' THEN
3773                                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
3774                                                 l_error_message_code := null;
3775                                                 l_bill_currency_override_tmp := l_req_rec.bill_rate_curr_override;
3776 
3777                                                 IF l_debug_mode = 'Y' THEN
3778                                                         pa_debug.write(l_module, 'Validating Bill Rate Currency', l_log_level);
3779                                                 END IF;
3780 
3781                                                 PA_PROJECTS_MAINT_UTILS.CHECK_CURRENCY_NAME_OR_CODE(
3782                                                         p_agreement_currency       => l_bill_currency_override_tmp
3783                                                         ,p_agreement_currency_name  => null
3784                                                         ,p_check_id_flag            => 'Y'
3785                                                         ,x_agreement_currency       => l_req_rec.bill_rate_curr_override
3786                                                         ,x_return_status            => l_return_status
3787                                                         ,x_error_msg_code           => l_error_message_code);
3788 
3789                                                 IF l_debug_mode = 'Y' THEN
3790                                                         pa_debug.write(l_module, 'After Bill Rate Currency Validation', l_log_level);
3791                                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
3792                                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
3793                                                 END IF;
3794 
3795                                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3796                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_CISI_CURRENCY_NULL');
3797                                                         l_error_flag_local := 'Y';
3798                                                 END IF;
3799                                         END IF;
3800                                         -- 5144288, 5144369 : End
3801                                 ELSIF l_req_rec.bill_rate_option = 'MARKUP' THEN
3802 					-- 5144675 Changed l_req_rec.markup_percent_override <= 0 to < 0
3803                                         IF l_br_override_flag <> 'Y' OR l_req_rec.markup_percent_override < 0
3804 					   OR l_req_rec.markup_percent_override > 100 THEN
3805                                                 IF l_br_override_flag <> 'Y' THEN
3806                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
3807                                                         l_error_flag_local := 'Y';
3808                                                 ELSE
3809                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_MARKUP_PERCENT');
3810                                                         l_error_flag_local := 'Y';
3811                                                 END IF;
3812                                         END IF;
3813                                 ELSIF l_req_rec.bill_rate_option = 'DISCOUNT' THEN
3814 					-- 5144675 Changed l_req_rec.discount_percentage <= 0 to < 0
3815                                         IF l_br_discount_override_flag <> 'Y' OR l_req_rec.discount_percentage < 0
3816 					    OR l_req_rec.discount_percentage > 100 THEN
3817                                                 IF l_br_discount_override_flag <> 'Y' THEN
3818                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_OVRD_NA');
3819                                                         l_error_flag_local := 'Y';
3820                                                 ELSE
3821                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_DISCOUNT_PERCENT');
3822                                                         l_error_flag_local := 'Y';
3823                                                 END IF;
3824                                         END IF;
3825                                 END IF;
3826 
3827                                 IF l_req_rec.rate_disc_reason_code IS NULL THEN
3828                                         IF (l_rate_discount_reason_flag ='Y' AND (l_br_override_flag ='Y' OR l_br_discount_override_flag='Y') AND
3829                                                 (l_req_rec.bill_rate_override IS NOT NULL OR l_req_rec.markup_percent_override IS NOT NULL OR l_req_rec.discount_percentage IS NOT NULL)
3830                                            )
3831                                         THEN
3832                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_RATE_DISC_REASON_REQUIRED');
3833                                                 l_error_flag_local := 'Y';
3834                                         END IF;
3835                                 ELSE
3836                                         l_valid_flag := 'N';
3837                                         OPEN c_get_lookup_exists('RATE AND DISCOUNT REASON', l_req_rec.rate_disc_reason_code);
3838                                         FETCH c_get_lookup_exists INTO l_valid_flag;
3839                                         CLOSE c_get_lookup_exists;
3840                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
3841                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_RSN_INVALID');
3842                                                 l_error_flag_local := 'Y';
3843                                         END IF;
3844                                 END IF;
3845 
3846                                 IF l_debug_mode = 'Y' THEN
3847                                         pa_debug.write(l_module, 'After Validating Bill Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
3848                                 END IF;
3849                         END IF; -- l_req_rec.bill_rate_option <> 'NONE'
3850 
3851                         -- Transfer Price Rate Options Validation
3852                         -----------------------------------------
3853 
3854                         IF l_req_rec.tp_rate_option <> 'NONE' THEN
3855 
3856                                 IF l_debug_mode = 'Y' THEN
3857                                         pa_debug.write(l_module, 'Validating Transfer Price Rate Options', l_log_level);
3858                                 END IF;
3859 
3860                                 IF l_req_rec.tp_rate_option = 'RATE' THEN
3861                                         null; -- This validation is done internally
3862                                 ELSIF l_req_rec.tp_rate_option = 'BASIS' THEN
3863                                         IF l_debug_mode = 'Y' THEN
3864                                                 pa_debug.write(l_module, 'Validating Transfer Price Rate Basis', l_log_level);
3865                                         END IF;
3866 
3867                                         OPEN c_get_lookup_exists('CC_MARKUP_BASE_CODE', l_req_rec.tp_calc_base_code_override);
3868                                         FETCH c_get_lookup_exists INTO l_valid_flag;
3869                                         CLOSE c_get_lookup_exists;
3870 
3871                                         IF l_debug_mode = 'Y' THEN
3872                                                 pa_debug.write(l_module, 'After Transfer Price Rate Basis Validation', l_log_level);
3873                                                 pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
3874                                         END IF;
3875 
3876                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
3877                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_TP_BASIS_INVALID');
3878                                                 l_error_flag_local := 'Y';
3879                                         END IF;
3880                                 END IF;
3881 
3882                                 IF l_debug_mode = 'Y' THEN
3883                                         pa_debug.write(l_module, 'After Validating Transfer Price Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
3884                                 END IF;
3885                         END IF; -- l_req_rec.tp_rate_option <> 'NONE'
3886 
3887                         -- Res Loan Agreement Validations
3888                         ---------------------------------
3889 
3890                         IF l_req_rec.expense_owner IS NOT NULL THEN
3891                                 l_valid_flag := 'N';
3892 
3893                                 IF l_debug_mode = 'Y' THEN
3894                                         pa_debug.write(l_module, 'Validating Expense Owner Option', l_log_level);
3895                                 END IF;
3896 
3897                                 OPEN c_get_lookup_exists('EXPENSE_OWNER_TYPE', l_req_rec.expense_owner);
3898                                 FETCH c_get_lookup_exists INTO l_valid_flag;
3899                                 CLOSE c_get_lookup_exists;
3900 
3901                                 IF l_debug_mode = 'Y' THEN
3902                                         pa_debug.write(l_module, 'After Expense Owner Option Validation', l_log_level);
3903                                         pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
3904                                 END IF;
3905 
3906                                 IF nvl(l_valid_flag,'N') <> 'Y' THEN
3907                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_EXP_OWNER_INVALID');
3908                                         l_error_flag_local := 'Y';
3909                                 END IF;
3910                         END IF;
3911                 END IF; -- l_error_flag_local <> 'Y' AND nvl(l_req_dtls_csr.template_flag,'N') = 'N'
3912 
3913                 IF l_debug_mode = 'Y' THEN
3914                         pa_debug.write(l_module, 'After all validations l_error_flag_local='||l_error_flag_local, l_log_level);
3915                 END IF;
3916 
3917                 -- Flex field Validation
3918                 ------------------------
3919 
3920                 IF l_error_flag_local <> 'Y' THEN
3921                         l_return_status := FND_API.G_RET_STS_SUCCESS;
3922 
3923                         VALIDATE_FLEX_FIELD(
3924                                   p_desc_flex_name         => 'PA_TEAM_ROLE_DESC_FLEX'
3925                                 , p_attribute_category     => l_req_rec.attribute_category
3926                                 , px_attribute1            => l_req_rec.attribute1
3927                                 , px_attribute2            => l_req_rec.attribute2
3928                                 , px_attribute3            => l_req_rec.attribute3
3929                                 , px_attribute4            => l_req_rec.attribute4
3930                                 , px_attribute5            => l_req_rec.attribute5
3931                                 , px_attribute6            => l_req_rec.attribute6
3932                                 , px_attribute7            => l_req_rec.attribute7
3933                                 , px_attribute8            => l_req_rec.attribute8
3934                                 , px_attribute9            => l_req_rec.attribute9
3935                                 , px_attribute10           => l_req_rec.attribute10
3936                                 , px_attribute11           => l_req_rec.attribute11
3937                                 , px_attribute12           => l_req_rec.attribute12
3938                                 , px_attribute13           => l_req_rec.attribute13
3939                                 , px_attribute14           => l_req_rec.attribute14
3940                                 , px_attribute15           => l_req_rec.attribute15
3941                                 , x_return_status          => l_return_status
3942                                 , x_msg_count		   => l_msg_count
3943                                 , x_msg_data		   => l_msg_data
3944                          );
3945 
3946                         IF l_debug_mode = 'Y' THEN
3947                                 pa_debug.write(l_module, 'After Flex Field Validation l_return_status='||l_return_status, l_log_level);
3948                                 pa_debug.write(l_module, 'After Flex Field Validation l_msg_data='||l_msg_data, l_log_level);
3949                         END IF;
3950 
3951 
3952                         IF l_return_status <>  FND_API.G_RET_STS_SUCCESS  THEN
3953                                 -- This message does not have toekn defined, still it is ok to pass token as the value
3954                                 -- returned by flex APIs because token are appended as it is
3955                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_DFF_VALIDATION_FAILED',
3956                                                       'MESSAGE', l_msg_data );
3957                                 l_error_flag_local := 'Y';
3958                         END IF;
3959                 END IF; -- l_error_flag_local <> 'Y'
3960 
3961                 -- Security Check
3962                 -----------------
3963                 -- The underlying API does security check of PA_ASN_BASIC_INFO_ED
3964                 -- , PA_CREATE_CANDIDATES, PA_ASN_FCST_INFO_ED
3965                 -- But still we need to do check here because there are some more checks required
3966                 -- Also the underlying API does not consider the MISS chars
3967 
3968                 IF l_error_flag_local <> 'Y' AND nvl(l_req_dtls_csr.template_flag,'N') = 'N' THEN
3969                         -- Project Requirement
3970 
3971                         IF nvl(l_req_rec.requirement_name, 'XYZ') <> nvl(l_req_dtls_csr.assignment_name, 'XYZ')
3972                         OR nvl(l_req_rec.min_resource_job_level, -1) <> nvl(l_req_dtls_csr.min_resource_job_level, -1)
3973                         OR nvl(l_req_rec.max_resource_job_level, -1) <> nvl(l_req_dtls_csr.max_resource_job_level, -1)
3974                         OR nvl(l_req_rec.staffing_priority_code, 'XYZ') <> nvl(l_req_dtls_csr.staffing_priority_code, 'XYZ')
3975                         OR nvl(l_req_rec.staffing_owner_person_id, -1) <> nvl(l_req_dtls_csr.staffing_owner_person_id, -1)
3976                         OR nvl(l_req_rec.description, 'XYZ') <> nvl(l_req_dtls_csr.description, 'XYZ')
3977                         OR nvl(l_req_rec.additional_information, 'XYZ') <> nvl(l_req_dtls_csr.additional_information, 'XYZ')
3978                         OR nvl(l_req_rec.project_subteam_id, -1) <> nvl(l_project_subteam_id, -1)
3979                         OR nvl(l_req_rec.location_id, -1) <> nvl(l_req_dtls_csr.location_id, -1)
3980                         THEN
3981                                 l_basic_info_changed := 'Y';
3982                         END IF;
3983 
3984                         IF nvl(l_req_rec.comp_match_weighting, -1) <> nvl(l_req_dtls_csr.competence_match_weighting, -1)
3985                         OR nvl(l_req_rec.avail_match_weighting, -1) <> nvl(l_req_dtls_csr.availability_match_weighting, -1)
3986                         OR nvl(l_req_rec.job_level_match_weighting, -1) <> nvl(l_req_dtls_csr.job_level_match_weighting, -1)
3987                         OR nvl(l_req_rec.enable_auto_cand_nom_flag, 'XYZ') <> nvl(l_req_dtls_csr.enable_auto_cand_nom_flag, 'XYZ')
3988                         OR nvl(l_req_rec.search_min_availability, -1) <> nvl(l_req_dtls_csr.search_min_availability, -1)
3989                         OR nvl(l_req_rec.search_exp_org_str_ver_id, -1) <> nvl(l_req_dtls_csr.search_exp_org_struct_ver_id, -1)
3990                         OR nvl(l_req_rec.search_exp_start_org_id, -1) <> nvl(l_req_dtls_csr.search_exp_start_org_id, -1)
3991                         OR nvl(l_req_rec.search_country_code, 'XYZ') <> nvl(l_req_dtls_csr.search_country_code, 'XYZ')
3992                         OR nvl(l_req_rec.search_min_candidate_score, -1) <> nvl(l_req_dtls_csr.search_min_candidate_score, -1)
3993                         THEN
3994                                 l_candidate_info_changed := 'Y';
3995                         END IF;
3996 
3997                         IF nvl(l_req_rec.extension_possible, 'XYZ') <> nvl(l_req_dtls_csr.extension_possible, 'XYZ')
3998                         OR nvl(l_req_rec.expense_owner, 'XYZ') <> nvl(l_req_dtls_csr.expense_owner, 'XYZ')
3999                         OR nvl(l_req_rec.expense_limit, -1) <> nvl(l_req_dtls_csr.expense_limit, -1)
4000                         OR nvl(l_req_rec.expenditure_org_id, -1) <> nvl(l_req_dtls_csr.expenditure_org_id, -1)
4001                         OR nvl(l_req_rec.expenditure_organization_id, -1) <> nvl(l_req_dtls_csr.expenditure_organization_id, -1)
4002                         OR nvl(l_req_rec.expenditure_type_class, 'XYZ') <> nvl(l_req_dtls_csr.expenditure_type_class, 'XYZ')
4003                         OR nvl(l_req_rec.fcst_job_group_id, -1) <> nvl(l_req_dtls_csr.fcst_job_group_id, -1)
4004                         OR nvl(l_req_rec.fcst_job_id, -1) <> nvl(l_req_dtls_csr.fcst_job_id, -1)
4005                         OR nvl(l_req_rec.work_type_id, -1) <> nvl(l_req_dtls_csr.work_type_id, -1)
4006                         THEN
4007                                 l_fin_info_changed := 'Y';
4008                         END IF;
4009 
4010                         IF nvl(l_req_rec.bill_rate_override, -1) <> nvl(l_req_dtls_csr.bill_rate_override, -1)
4011                         OR nvl(l_req_rec.bill_rate_curr_override, 'XYZ') <> nvl(l_req_dtls_csr.bill_rate_curr_override, 'XYZ')
4012                         OR nvl(l_req_rec.markup_percent_override, -1) <> nvl(l_req_dtls_csr.markup_percent_override, -1)
4013                         OR nvl(l_req_rec.discount_percentage, -1) <> nvl(l_req_dtls_csr.discount_percentage, -1)
4014                         OR nvl(l_req_rec.rate_disc_reason_code, 'XYZ') <> nvl(l_req_dtls_csr.rate_disc_reason_code, 'XYZ')
4015                         THEN
4016                                 l_fin_bill_rate_info_changed := 'Y';
4017                         END IF;
4018 
4019                         IF nvl(l_req_rec.tp_rate_override, -1) <> nvl(l_req_dtls_csr.tp_rate_override, -1)
4020                         OR nvl(l_req_rec.tp_currency_override, 'XYZ') <> nvl(l_req_dtls_csr.tp_currency_override, 'XYZ')
4021                         OR nvl(l_req_rec.tp_percent_applied_override, -1) <> nvl(l_req_dtls_csr.tp_percent_applied_override, -1)
4022                         OR nvl(l_req_rec.tp_calc_base_code_override, 'XYZ') <> nvl(l_req_dtls_csr.tp_calc_base_code_override, 'XYZ')
4023                         THEN
4024                                 l_fin_tp_rate_info_changed := 'Y';
4025                         END IF;
4026 
4027 
4028                         IF l_basic_info_changed = 'Y' THEN
4029 
4030                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
4031                                 l_ret_code := 'T';
4032                                 l_privilege := 'PA_ASN_BASIC_INFO_ED';
4033                                 l_object_name := 'PA_PROJECTS';
4034                                 l_object_key := l_req_rec.project_id;
4035 
4036                                 IF l_debug_mode = 'Y' THEN
4037                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_BASIC_INFO_ED', l_log_level);
4038                                 END IF ;
4039 
4040                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4041                                           x_ret_code       => l_ret_code
4042                                         , x_return_status  => l_return_status
4043                                         , x_msg_count      => l_msg_count
4044                                         , x_msg_data       => l_msg_data
4045                                         , p_privilege      => l_privilege
4046                                         , p_object_name    => l_object_name
4047                                         , p_object_key     => l_object_key
4048                                         , p_init_msg_list  => FND_API.G_FALSE);
4049 
4050                                 IF l_debug_mode = 'Y' THEN
4051                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_BASIC_INFO_ED l_ret_code '|| l_ret_code , l_log_level);
4052                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_BASIC_INFO_ED l_return_status '|| l_return_status , l_log_level);
4053                                 END IF ;
4054 
4055                                 IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4056 
4057                                         IF l_debug_mode = 'Y' THEN
4058                                                 pa_debug.write(l_module,'Checking Requirement Level Security for PA_ASN_BASIC_INFO_ED', l_log_level);
4059                                         END IF ;
4060 
4061                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4062                                         l_ret_code := 'T';
4063                                         l_privilege := 'PA_ASN_BASIC_INFO_ED';
4064                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
4065                                         l_object_key := l_req_rec.requirement_id;
4066 
4067                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4068                                                   x_ret_code       => l_ret_code
4069                                                 , x_return_status  => l_return_status
4070                                                 , x_msg_count      => l_msg_count
4071                                                 , x_msg_data       => l_msg_data
4072                                                 , p_privilege      => l_privilege
4073                                                 , p_object_name    => l_object_name
4074                                                 , p_object_key     => l_object_key
4075                                                 , p_init_msg_list  => FND_API.G_FALSE );
4076 
4077                                         IF l_debug_mode = 'Y' THEN
4078                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_BASIC_INFO_ED l_ret_code='||l_ret_code, l_log_level);
4079                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_BASIC_INFO_ED l_return_status='||l_return_status, l_log_level);
4080                                         END IF ;
4081                                 END IF;
4082 
4083                                 IF nvl(l_ret_code,'F') <> 'T' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4084                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_UPD_ASGN_BASIC_INFO'
4085                                                       ,'MISSING_PRIVILEGE', l_privilege);
4086                                         l_error_flag_local := 'Y';
4087                                 END IF;
4088 
4089                         END IF;-- l_basic_info_changed = 'Y'
4090 
4091                         IF l_candidate_info_changed = 'Y' THEN
4092 
4093                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
4094                                 l_ret_code := 'T';
4095                                 l_privilege := 'PA_CREATE_CANDIDATES';
4096                                 l_object_name := 'PA_PROJECTS';
4097                                 l_object_key := l_req_rec.project_id;
4098 
4099                                 IF l_debug_mode = 'Y' THEN
4100                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_CREATE_CANDIDATES', l_log_level);
4101                                 END IF ;
4102 
4103                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4104                                           x_ret_code       => l_ret_code
4105                                         , x_return_status  => l_return_status
4106                                         , x_msg_count      => l_msg_count
4107                                         , x_msg_data       => l_msg_data
4108                                         , p_privilege      => l_privilege
4109                                         , p_object_name    => l_object_name
4110                                         , p_object_key     => l_object_key
4111                                         , p_init_msg_list  => FND_API.G_FALSE);
4112 
4113                                 IF l_debug_mode = 'Y' THEN
4114                                         pa_debug.write(l_module, 'Project Level Security for PA_CREATE_CANDIDATES l_ret_code '|| l_ret_code , l_log_level);
4115                                         pa_debug.write(l_module, 'Project Level Security for PA_CREATE_CANDIDATES l_return_status '|| l_return_status , l_log_level);
4116                                 END IF ;
4117 
4118                                 IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4119 
4120                                         IF l_debug_mode = 'Y' THEN
4121                                                 pa_debug.write(l_module,'Checking Requirement Level Security for PA_CREATE_CANDIDATES', l_log_level);
4122                                         END IF ;
4123 
4124                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4125                                         l_ret_code := 'T';
4126                                         l_privilege := 'PA_CREATE_CANDIDATES';
4127                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
4128                                         l_object_key := l_req_rec.requirement_id;
4129 
4130                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4131                                                   x_ret_code       => l_ret_code
4132                                                 , x_return_status  => l_return_status
4133                                                 , x_msg_count      => l_msg_count
4134                                                 , x_msg_data       => l_msg_data
4135                                                 , p_privilege      => l_privilege
4136                                                 , p_object_name    => l_object_name
4137                                                 , p_object_key     => l_object_key
4138                                                 , p_init_msg_list  => FND_API.G_FALSE );
4139 
4140                                         IF l_debug_mode = 'Y' THEN
4141                                                 pa_debug.write(l_module,'Requirement Level Security for PA_CREATE_CANDIDATES l_ret_code='||l_ret_code, l_log_level);
4142                                                 pa_debug.write(l_module,'Requirement Level Security for PA_CREATE_CANDIDATES l_return_status='||l_return_status, l_log_level);
4143                                         END IF ;
4144                                 END IF;
4145 
4146                                 IF nvl(l_ret_code,'F') <> 'T' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4147                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_UPD_ASGN_CANDIDATE'
4148                                                       ,'MISSING_PRIVILEGE', l_privilege);
4149                                         l_error_flag_local := 'Y';
4150                                 END IF;
4151 
4152                         END IF;-- l_candidate_info_changed = 'Y'
4153 
4154                         IF l_fin_info_changed = 'Y' OR l_fin_bill_rate_info_changed = 'Y' OR l_fin_tp_rate_info_changed = 'Y' THEN
4155 
4156                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
4157                                 l_ret_code := 'T';
4158                                 l_privilege := 'PA_ASN_FCST_INFO_ED';
4159                                 l_object_name := 'PA_PROJECTS';
4160                                 l_object_key := l_req_rec.project_id;
4161 
4162                                 IF l_debug_mode = 'Y' THEN
4163                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_FCST_INFO_ED', l_log_level);
4164                                 END IF ;
4165 
4166                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4167                                           x_ret_code       => l_ret_code
4168                                         , x_return_status  => l_return_status
4169                                         , x_msg_count      => l_msg_count
4170                                         , x_msg_data       => l_msg_data
4171                                         , p_privilege      => l_privilege
4172                                         , p_object_name    => l_object_name
4173                                         , p_object_key     => l_object_key
4174                                         , p_init_msg_list  => FND_API.G_FALSE);
4175 
4176                                 IF l_debug_mode = 'Y' THEN
4177                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_ED l_ret_code '|| l_ret_code , l_log_level);
4178                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_ED l_return_status '|| l_return_status , l_log_level);
4179                                 END IF ;
4180 
4181                                 IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4182 
4183                                         IF l_debug_mode = 'Y' THEN
4184                                                 pa_debug.write(l_module,'Checking Requirement Level Security for PA_CREATE_CANDIDATES', l_log_level);
4185                                         END IF ;
4186 
4187                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4188                                         l_ret_code := 'T';
4189                                         l_privilege := 'PA_ASN_FCST_INFO_ED';
4190                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
4191                                         l_object_key := l_req_rec.requirement_id;
4192 
4193                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4194                                                   x_ret_code       => l_ret_code
4195                                                 , x_return_status  => l_return_status
4196                                                 , x_msg_count      => l_msg_count
4197                                                 , x_msg_data       => l_msg_data
4198                                                 , p_privilege      => l_privilege
4199                                                 , p_object_name    => l_object_name
4200                                                 , p_object_key     => l_object_key
4201                                                 , p_init_msg_list  => FND_API.G_FALSE );
4202 
4203                                         IF l_debug_mode = 'Y' THEN
4204                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_ED l_ret_code='||l_ret_code, l_log_level);
4205                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_ED l_return_status='||l_return_status, l_log_level);
4206                                         END IF ;
4207                                 END IF;
4208 
4209                                 IF nvl(l_ret_code,'F') <> 'T' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4210                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_UPD_ASGN_FIN_INFO'
4211                                                       ,'MISSING_PRIVILEGE', l_privilege);
4212                                         l_error_flag_local := 'Y';
4213                                 END IF;
4214 
4215                         END IF;-- l_fin_info_changed = 'Y' OR l_fin_bill_rate_info_changed = 'Y' OR l_fin_tp_rate_info_changed = 'Y'
4216 
4217 
4218                         IF l_fin_bill_rate_info_changed = 'Y' THEN
4219 
4220                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
4221                                 l_ret_code := 'T';
4222                                 l_privilege := 'PA_ASN_FCST_INFO_BILL_ED';
4223                                 l_object_name := 'PA_PROJECTS';
4224                                 l_object_key := l_req_rec.project_id;
4225 
4226                                 IF l_debug_mode = 'Y' THEN
4227                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_FCST_INFO_BILL_ED', l_log_level);
4228                                 END IF ;
4229 
4230                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4231                                           x_ret_code       => l_ret_code
4232                                         , x_return_status  => l_return_status
4233                                         , x_msg_count      => l_msg_count
4234                                         , x_msg_data       => l_msg_data
4235                                         , p_privilege      => l_privilege
4236                                         , p_object_name    => l_object_name
4237                                         , p_object_key     => l_object_key
4238                                         , p_init_msg_list  => FND_API.G_FALSE);
4239 
4240                                 IF l_debug_mode = 'Y' THEN
4241                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_BILL_ED l_ret_code '|| l_ret_code , l_log_level);
4242                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_BILL_ED l_return_status '|| l_return_status , l_log_level);
4243                                 END IF ;
4244 
4245                                 IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4246 
4247                                         IF l_debug_mode = 'Y' THEN
4248                                                 pa_debug.write(l_module,'Checking Requirement Level Security for PA_ASN_FCST_INFO_BILL_ED', l_log_level);
4249                                         END IF ;
4250 
4251                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4252                                         l_ret_code := 'T';
4253                                         l_privilege := 'PA_ASN_FCST_INFO_BILL_ED';
4254                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
4255                                         l_object_key := l_req_rec.requirement_id;
4256 
4257                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4258                                                   x_ret_code       => l_ret_code
4259                                                 , x_return_status  => l_return_status
4260                                                 , x_msg_count      => l_msg_count
4261                                                 , x_msg_data       => l_msg_data
4262                                                 , p_privilege      => l_privilege
4263                                                 , p_object_name    => l_object_name
4264                                                 , p_object_key     => l_object_key
4265                                                 , p_init_msg_list  => FND_API.G_FALSE );
4266 
4267                                         IF l_debug_mode = 'Y' THEN
4268                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_BILL_ED l_ret_code='||l_ret_code, l_log_level);
4269                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_BILL_ED l_return_status='||l_return_status, l_log_level);
4270                                         END IF ;
4271                                 END IF;
4272 
4273                                 IF nvl(l_ret_code,'F') <> 'T' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4274                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_UPD_ASGN_BR_INFO'
4275                                                       ,'MISSING_PRIVILEGE', l_privilege);
4276                                         l_error_flag_local := 'Y';
4277                                 END IF;
4278 
4279                         END IF;-- l_fin_bill_rate_info_changed = 'Y'
4280 
4281                         IF l_fin_tp_rate_info_changed = 'Y' THEN
4282 
4283                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
4284                                 l_ret_code := 'T';
4285                                 l_privilege := 'PA_ASN_FCST_INFO_TP_ED';
4286                                 l_object_name := 'PA_PROJECTS';
4287                                 l_object_key := l_req_rec.project_id;
4288 
4289                                 IF l_debug_mode = 'Y' THEN
4290                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_FCST_INFO_TP_ED', l_log_level);
4291                                 END IF ;
4292 
4293                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4294                                           x_ret_code       => l_ret_code
4295                                         , x_return_status  => l_return_status
4296                                         , x_msg_count      => l_msg_count
4297                                         , x_msg_data       => l_msg_data
4298                                         , p_privilege      => l_privilege
4299                                         , p_object_name    => l_object_name
4300                                         , p_object_key     => l_object_key
4301                                         , p_init_msg_list  => FND_API.G_FALSE);
4302 
4303                                 IF l_debug_mode = 'Y' THEN
4304                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_TP_ED l_ret_code '|| l_ret_code , l_log_level);
4305                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_TP_ED l_return_status '|| l_return_status , l_log_level);
4306                                 END IF ;
4307 
4308                                 IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4309 
4310                                         IF l_debug_mode = 'Y' THEN
4311                                                 pa_debug.write(l_module,'Checking Requirement Level Security for PA_ASN_FCST_INFO_TP_ED', l_log_level);
4312                                         END IF ;
4313 
4314                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4315                                         l_ret_code := 'T';
4316                                         l_privilege := 'PA_ASN_FCST_INFO_TP_ED';
4317                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
4318                                         l_object_key := l_req_rec.requirement_id;
4319 
4320                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4321                                                   x_ret_code       => l_ret_code
4322                                                 , x_return_status  => l_return_status
4323                                                 , x_msg_count      => l_msg_count
4324                                                 , x_msg_data       => l_msg_data
4325                                                 , p_privilege      => l_privilege
4326                                                 , p_object_name    => l_object_name
4327                                                 , p_object_key     => l_object_key
4328                                                 , p_init_msg_list  => FND_API.G_FALSE );
4329 
4330                                         IF l_debug_mode = 'Y' THEN
4331                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_TP_ED l_ret_code='||l_ret_code, l_log_level);
4332                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_TP_ED l_return_status='||l_return_status, l_log_level);
4333                                         END IF ;
4334                                 END IF;
4335 
4336                                 IF nvl(l_ret_code,'F') <> 'T' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4337                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_UPD_ASGN_TP_INFO'
4338                                                       ,'MISSING_PRIVILEGE', l_privilege);
4339                                         l_error_flag_local := 'Y';
4340                                 END IF;
4341                         END IF;-- l_fin_tp_rate_info_changed = 'Y'
4342                 ELSIF l_error_flag_local <> 'Y' AND nvl(l_req_dtls_csr.template_flag,'N') = 'Y' THEN
4343                         -- Template Requirement
4344                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4345                         l_ret_code := 'T';
4346                         l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
4347                         l_object_name := null;
4348                         l_object_key := null;
4349 
4350                         IF l_debug_mode = 'Y' THEN
4351                                 pa_debug.write(l_module,'Checking Team template security', l_log_level);
4352                         END IF ;
4353 
4354                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4355                                   x_ret_code       => l_ret_code
4356                                 , x_return_status  => l_return_status
4357                                 , x_msg_count      => l_msg_count
4358                                 , x_msg_data       => l_msg_data
4359                                 , p_privilege      => l_privilege
4360                                 , p_object_name    => l_object_name
4361                                 , p_object_key     => l_object_key
4362                                 , p_init_msg_list  => FND_API.G_FALSE );
4363 
4364                         IF l_debug_mode = 'Y' THEN
4365                                 pa_debug.write(l_module,'Team Template Security l_ret_code='||l_ret_code, l_log_level);
4366                                 pa_debug.write(l_module,'Team Template Security l_return_status='||l_return_status, l_log_level);
4367                         END IF ;
4368 
4369                         IF nvl(l_ret_code,'F') <> 'T' OR l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
4370                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_UPD'
4371                                                       ,'MISSING_PRIVILEGE', l_privilege);
4372                                 l_error_flag_local := 'Y';
4373                         END IF;
4374                 END IF; -- l_error_flag_local <> 'Y' AND nvl(l_req_dtls_csr.template_flag,'N') = 'N'
4375 
4376 
4377                 -- Call Core Actual API
4378                 -----------------------
4379 
4380                 IF l_error_flag_local <> 'Y' THEN
4381                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4382 
4383                         IF l_debug_mode = 'Y' THEN
4384                                 pa_debug.write(l_module, 'Calling PA_ASSIGNMENTS_PUB.EXECUTE_UPDATE_REQUIREMENT for Record#'||i, l_log_level);
4385                         END IF;
4386 
4387 
4388                         PA_ASSIGNMENTS_PUB.EXECUTE_UPDATE_REQUIREMENT
4389                         (
4390                                   p_api_version                 => p_api_version_number
4391                                 , p_init_msg_list               => l_init_msg_list
4392                                 , p_commit                      => l_commit
4393                                 , p_validate_only               => l_validate_only
4394                                 , p_asgn_update_mode		=> l_asgn_update_mode
4395                                 , p_assignment_id               => l_req_rec.requirement_id
4396                                 , p_assignment_name		=> l_req_rec.requirement_name
4397 --                                , p_assignment_number           =>
4398                                 , p_assignment_type		=> l_assignment_type
4399                                 , p_assignment_template_id      => l_req_rec.team_template_id
4400 --                                , p_source_assignment_id        => l_req_dtls_csr.source_assignment_id
4401 --                                , p_number_of_requirements      => l_req_rec.number_of_requirements
4402                                 , p_project_role_id             => l_req_rec.project_role_id
4403                                 , p_project_role_name           => l_req_rec.project_role_name
4404                                 , p_project_id                  => l_req_rec.project_id
4405 --                                , p_project_name                => l_req_rec.project_name
4406                                 , p_project_number              => l_req_rec.project_number
4407                 --                , p_resource_id                 =>
4408                 --                , p_project_party_id            =>
4409                 --                , p_resource_name               =>
4410                 --                , p_resource_source_id          => null
4411                                 , p_staffing_owner_person_id    => l_req_rec.staffing_owner_person_id
4412                 --                , p_staffing_owner_name         =>
4413                                 , p_staffing_priority_code      => l_req_rec.staffing_priority_code
4414                                 , p_staffing_priority_name      => l_req_rec.staffing_priority_name
4415                                 , p_project_subteam_id          => l_req_rec.project_subteam_id
4416                                 , p_project_subteam_name        => l_req_rec.project_subteam_name
4417                                 , p_project_subteam_party_id    => l_project_subteam_party_id
4418                                 , p_location_id                 => l_req_rec.location_id
4419                                 , p_location_city               => l_req_rec.location_city
4420                                 , p_location_region             => l_req_rec.location_region
4421                                 , p_location_country_name       => l_req_rec.location_country_name
4422                                 , p_location_country_code       => l_req_rec.location_country_code
4423                                 , p_min_resource_job_level      => l_req_rec.min_resource_job_level
4424                                 , p_max_resource_job_level	=> l_req_rec.max_resource_job_level
4425                                 , p_description                 => l_req_rec.description
4426                                 , p_additional_information      => l_req_rec.additional_information
4427                                 , p_start_date                  => l_req_rec.start_date
4428                                 , p_end_date                    => l_req_rec.end_date
4429                                 , p_status_code                 => l_req_rec.status_code
4430                                 , p_project_status_name         => l_req_rec.status_name
4431                 		, p_multiple_status_flag        => l_req_dtls_csr.multiple_status_flag
4432                 --                , p_assignment_effort           =>
4433 --                                , p_resource_list_member_id   => l_req_dtls_csr.resource_list_member_id
4434                 --                , p_budget_version_id		=>
4435                 --                , p_sum_tasks_flag            =>
4436 --                                , p_calendar_type               => l_req_rec.calendar_type
4437                                 , p_calendar_id	                => l_req_rec.calendar_id
4438                                 , p_calendar_name               => l_req_rec.calendar_name
4439 --                                , p_start_adv_action_set_flag   => l_req_rec.start_adv_action_set_flag
4440 --                                , p_adv_action_set_id           => l_req_rec.adv_action_set_id
4441 --                                , p_adv_action_set_name         => l_req_rec.adv_action_set_name
4442                                 -- As of now internal code does not support setting the candidate search options
4443                                 -- at create time. It can only be updated.
4444                                 , p_comp_match_weighting        => l_req_rec.comp_match_weighting
4445                                 , p_avail_match_weighting       => l_req_rec.avail_match_weighting
4446                                 , p_job_level_match_weighting   => l_req_rec.job_level_match_weighting
4447                                 , p_enable_auto_cand_nom_flag   => l_req_rec.enable_auto_cand_nom_flag
4448                                 , p_search_min_availability     => l_req_rec.search_min_availability
4449                                 , p_search_exp_org_struct_ver_id => l_req_rec.search_exp_org_str_ver_id
4450                                 , p_search_exp_org_hier_name    => l_req_rec.search_exp_org_hier_name
4451                                 , p_search_exp_start_org_id     => l_req_rec.search_exp_start_org_id
4452                                 , p_search_exp_start_org_name   => l_req_rec.search_exp_start_org_name
4453                                 , p_search_country_code         => l_req_rec.search_country_code
4454                                 , p_search_country_name         => l_req_rec.search_country_name
4455                                 , p_search_min_candidate_score  => l_req_rec.search_min_candidate_score
4456                                 , p_expenditure_org_id          => l_req_rec.expenditure_org_id
4457                                 , p_expenditure_org_name        => l_req_rec.expenditure_org_name
4458                                 , p_expenditure_organization_id => l_req_rec.expenditure_organization_id
4459                                 , p_exp_organization_name       => l_req_rec.expenditure_organization_name
4460                                 , p_expenditure_type_class      => l_req_rec.expenditure_type_class
4461                                 , p_expenditure_type            => l_req_rec.expenditure_type
4462                                 , p_fcst_job_group_id           => l_req_rec.fcst_job_group_id
4463                                 , p_fcst_job_group_name         => l_req_rec.fcst_job_group_name
4464                                 , p_fcst_job_id                 => l_req_rec.fcst_job_id
4465                                 , p_fcst_job_name               => l_req_rec.fcst_job_name
4466 --                                , p_fcst_tp_amount_type         => l_req_rec.fcst_tp_amount_type
4467                                 , p_work_type_id                => l_req_rec.work_type_id
4468                                 , p_work_type_name              => l_req_rec.work_type_name
4469                                 , p_bill_rate_override          => l_req_rec.bill_rate_override
4470                                 , p_bill_rate_curr_override     => l_req_rec.bill_rate_curr_override
4471                                 , p_markup_percent_override     => l_req_rec.markup_percent_override
4472                                 , p_discount_percentage         => l_req_rec.discount_percentage
4473                                 , p_rate_disc_reason_code       => l_req_rec.rate_disc_reason_code
4474                                 , p_tp_rate_override            => l_req_rec.tp_rate_override
4475                                 , p_tp_currency_override        => l_req_rec.tp_currency_override
4476                                 , p_tp_calc_base_code_override  => l_req_rec.tp_calc_base_code_override
4477                                 , p_tp_percent_applied_override => l_req_rec.tp_percent_applied_override
4478                                 , p_extension_possible          => l_req_rec.extension_possible
4479                                 , p_expense_owner               => l_req_rec.expense_owner
4480                                 , p_expense_limit               => l_req_rec.expense_limit
4481                                 , p_expense_limit_currency_code => l_req_dtls_csr.expense_limit_currency_code
4482                                 , p_revenue_currency_code       => l_req_dtls_csr.revenue_currency_code
4483                                 , p_revenue_bill_rate           => l_req_dtls_csr.revenue_bill_rate
4484                                 , p_markup_percent              => l_req_dtls_csr.markup_percent
4485                 --                , p_resource_calendar_percent   =>
4486                                 , p_record_version_number       => l_req_rec.record_version_number
4487                                 , p_attribute_category          => l_req_rec.attribute_category
4488                                 , p_attribute1                  => l_req_rec.attribute1
4489                                 , p_attribute2                  => l_req_rec.attribute2
4490                                 , p_attribute3                  => l_req_rec.attribute3
4491                                 , p_attribute4                  => l_req_rec.attribute4
4492                                 , p_attribute5                  => l_req_rec.attribute5
4493                                 , p_attribute6                  => l_req_rec.attribute6
4494                                 , p_attribute7                  => l_req_rec.attribute7
4495                                 , p_attribute8                  => l_req_rec.attribute8
4496                                 , p_attribute9                  => l_req_rec.attribute9
4497                                 , p_attribute10                 => l_req_rec.attribute10
4498                                 , p_attribute11                 => l_req_rec.attribute11
4499                                 , p_attribute12                 => l_req_rec.attribute12
4500                                 , p_attribute13                 => l_req_rec.attribute13
4501                                 , p_attribute14                 => l_req_rec.attribute14
4502                                 , p_attribute15                 => l_req_rec.attribute15
4503                                 , x_return_status               => l_return_status
4504                                 , x_msg_count                   => l_msg_count
4505                                 , x_msg_data                    => l_msg_data
4506                         );
4507 
4508                         IF l_debug_mode = 'Y' THEN
4509                                 pa_debug.write(l_module, 'After call PA_ASSIGNMENTS_PUB.EXECUTE_CREATE_ASSIGNMENT l_return_status='||l_return_status, l_log_level);
4510                         END IF;
4511 
4512                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4513                                 --l_error_flag := 'Y';
4514                                 l_error_flag_local := 'Y';
4515                         ELSE
4516                                 IF l_debug_mode = 'Y' THEN
4517                                         pa_debug.write(l_module, 'Updating Original System Code and Reference', l_log_level);
4518                                 END IF;
4519 
4520                                 IF l_req_rec.orig_system_code IS NOT NULL OR l_req_rec.orig_system_reference IS NOT NULL THEN
4521                                         UPDATE PA_PROJECT_ASSIGNMENTS
4522                                         SET orig_system_code = decode(l_req_rec.orig_system_code, null, orig_system_code, l_req_rec.orig_system_code)
4523                                         , orig_system_reference = decode(l_req_rec.orig_system_reference, null, orig_system_reference, l_req_rec.orig_system_reference)
4524                                         WHERE assignment_id = l_req_rec.requirement_id;
4525                                 END IF;
4526 
4527                                 IF l_debug_mode = 'Y' THEN
4528                                         pa_debug.write(l_module, 'After Updating Original System Code and Reference', l_log_level);
4529                                 END IF;
4530                         END IF;
4531                 END IF;
4532 
4533                 l_end_msg_count := FND_MSG_PUB.count_msg;
4534                 IF l_debug_mode = 'Y' THEN
4535                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
4536                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
4537                 END IF;
4538                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
4539 
4540                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
4541                         l_error_flag := 'Y';
4542 
4543                         IF l_debug_mode = 'Y' THEN
4544                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
4545                         END IF;
4546 
4547                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
4548                                 -- Always get from first location in stack i.e. l_start_msg_count+1
4549                                 -- Because stack moves down after delete
4550                                 FND_MSG_PUB.get (
4551                                         p_msg_index      => l_start_msg_count+1,
4552                                         p_encoded        => FND_API.G_FALSE,
4553                                         p_data           => l_data,
4554                                         p_msg_index_out  => l_msg_index_out );
4555 
4556                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
4557                                 -- Because stack moves down after delete
4558                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
4559 
4560                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
4561                                                 'RECORD_NO', i,
4562                                                 'MESSAGE', l_data);
4563                         END LOOP;
4564                         IF l_debug_mode = 'Y' THEN
4565                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
4566                         END IF;
4567                 END IF;
4568                 i := p_requirement_in_tbl.next(i);
4569         END LOOP;
4570 
4571         IF l_debug_mode = 'Y' THEN
4572                 pa_debug.write(l_module, 'All records are done', l_log_level);
4573                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
4574                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
4575         END IF;
4576 
4577         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
4578                 RAISE FND_API.G_EXC_ERROR;
4579         END IF;
4580 
4581         IF l_debug_mode = 'Y' THEN
4582                 PA_DEBUG.reset_curr_function;
4583         END IF;
4584 
4585         IF p_commit = FND_API.G_TRUE THEN
4586                 commit;
4587         END IF;
4588 
4589 
4590 EXCEPTION
4591 WHEN FND_API.G_EXC_ERROR THEN
4592         x_return_status := FND_API.G_RET_STS_ERROR;
4593         l_msg_count := FND_MSG_PUB.count_msg;
4594 
4595         IF p_commit = FND_API.G_TRUE THEN
4596                 ROLLBACK TO UPDATE_REQUIREMENTS_SP;
4597         END IF;
4598 
4599         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
4600                 PA_INTERFACE_UTILS_PUB.get_messages
4601                 ( p_encoded        => FND_API.G_FALSE
4602                 , p_msg_index      => 1
4603                 , p_msg_count      => l_msg_count
4604                 , p_msg_data       => l_msg_data
4605                 , p_data           => l_data
4606                 , p_msg_index_out  => l_msg_index_out);
4607 
4608                 x_msg_data := l_data;
4609                 x_msg_count := l_msg_count;
4610         ELSE
4611                 x_msg_count := l_msg_count;
4612         END IF;
4613 
4614         IF l_debug_mode = 'Y' THEN
4615                 Pa_Debug.reset_curr_function;
4616         END IF;
4617 
4618 WHEN OTHERS THEN
4619 
4620         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4621         x_msg_data      := SQLERRM;
4622 
4623         IF p_commit = FND_API.G_TRUE THEN
4624                 ROLLBACK TO UPDATE_REQUIREMENTS_SP;
4625         END IF;
4626 
4627         FND_MSG_PUB.add_exc_msg
4628         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
4629         , p_procedure_name      => 'UPDATE_REQUIREMENTS'
4630         , p_error_text          => x_msg_data);
4631 
4632         x_msg_count     := FND_MSG_PUB.count_msg;
4633 
4634         IF l_debug_mode = 'Y' THEN
4635                 PA_DEBUG.reset_curr_function;
4636         END IF;
4637         RAISE;
4638 END UPDATE_REQUIREMENTS;
4639 
4640 -- Start of comments
4641 --	API name 	: DELETE_REQUIREMENTS
4642 --	Type		: Public
4643 --	Pre-reqs	: None.
4644 --	Function	: This API is a public API to delete one or more requirements for one or more projects.
4645 --	Usage		: This API will be called from AMG.
4646 --	Parameters	:
4647 --	IN		:	p_commit		IN  VARCHAR2
4648 --					Identifier to commit the transaction.
4649 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
4650 --				p_init_msg_list		IN  VARCHAR2
4651 --					Identifier to initialize the error message stack.
4652 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
4653 --				p_api_version_number	IN  NUMBER			Required
4654 --					To be compliant with Applications API coding standards.
4655 --				p_requirement_in_tbl	IN  REQUIREMENT_IN_TBL_TYPE	Required
4656 --					Table of requirement records. Please see the REQUIREMENT_IN_TBL_TYPE datatype table.
4657 --	OUT		:
4658 --				x_return_status		OUT VARCHAR2
4659 --					Indicates the return status of the API.
4660 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
4661 --				x_msg_count		OUT NUMBER
4662 --					Indicates the number of error messages in the message stack
4663 --				x_msg_data		OUT VARCHAR2
4664 --					Indicates the error message text if only one error exists
4665 --	History		:
4666 --                              01-Mar-2006 - avaithia  - Created
4667 -- End of comments
4668 PROCEDURE DELETE_REQUIREMENTS
4669 (
4670   p_api_version_number		IN		NUMBER   := 1.0
4671 , p_init_msg_list		IN		VARCHAR2 := FND_API.G_TRUE
4672 , p_commit			IN		VARCHAR2 := FND_API.G_FALSE
4673 , p_requirement_in_tbl		IN		REQUIREMENT_IN_TBL_TYPE
4674 , x_return_status		OUT	NOCOPY	VARCHAR2
4675 , x_msg_count			OUT	NOCOPY	NUMBER
4676 , x_msg_data			OUT	NOCOPY	VARCHAR2
4677 )
4678 IS
4679 l_calling_application           VARCHAR2(10)            := 'PLSQL';
4680 l_calling_module                VARCHAR2(10)            := 'AMG';
4681 l_check_id_flag                 VARCHAR2(1)             := 'Y';
4682 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
4683 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
4684 
4685 l_log_level                     NUMBER                  := 3;
4686 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.DELETE_REQUIREMENTS';
4687 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
4688 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
4689 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
4690 
4691 l_msg_count                     NUMBER;
4692 l_msg_data                      VARCHAR2(2000);
4693 l_msg_index_out                 NUMBER;
4694 l_data                          VARCHAR2(2000);
4695 l_debug_mode                    VARCHAR2(1);
4696 
4697 i                               NUMBER;
4698 
4699 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
4700 l_error_flag                    VARCHAR2(1)             := 'N';
4701 l_error_flag_local              VARCHAR2(1)             := 'N';
4702 
4703 l_req_rec		        REQUIREMENT_IN_REC_TYPE;
4704 
4705 l_dummy_code                    VARCHAR2(30);
4706 l_loop_msg_count                NUMBER                  :=0;
4707 l_start_msg_count               NUMBER                  :=0;
4708 l_end_msg_count                 NUMBER                  :=0;
4709 
4710 l_missing_params                VARCHAR2(1000);
4711 l_privilege                     VARCHAR2(30);
4712 l_object_name                   VARCHAR2(30);
4713 l_object_key                    NUMBER;
4714 l_error_message_code            VARCHAR2(30);
4715 l_ret_code                      VARCHAR2(1);
4716 
4717 l_assignment_number             NUMBER;
4718 l_assignment_row_id             ROWID;
4719 l_assignment_type               VARCHAR2(30)            := 'OPEN_ASSIGNMENT';
4720 l_record_version_number	        NUMBER;
4721 l_assignment_id			NUMBER;
4722 l_project_id			NUMBER;
4723 l_team_template_id		NUMBER;
4724 l_status_code			VARCHAR2(30);
4725 l_system_status_code		VARCHAR2(30);
4726 
4727 CURSOR c_derive_values(p_requirement_id IN NUMBER) IS
4728 SELECT ROWID,project_id,record_version_number,ASSIGNMENT_TEMPLATE_ID,assignment_number,status_code
4729 FROM   pa_project_assignments
4730 WHERE  assignment_id = p_requirement_id
4731 AND  ASSIGNMENT_TYPE = l_assignment_type ;
4732 
4733 CURSOR c_get_system_status IS
4734 SELECT PROJECT_SYSTEM_STATUS_CODE
4735 FROM   pa_project_statuses
4736 WHERE  project_status_code = l_status_code
4737 AND  status_type  = 'OPEN_ASGMT';
4738 
4739 BEGIN
4740 
4741         --------------------------------------------------
4742         -- RESET OUT params
4743         --------------------------------------------------
4744         x_return_status := FND_API.G_RET_STS_SUCCESS;
4745 	x_msg_count := 0;
4746 	x_msg_data := NULL ;
4747 
4748         --------------------------------------------------
4749         -- Initialize Current Function and Msg Stack
4750         --------------------------------------------------
4751         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
4752 
4753         IF l_debug_mode = 'Y' THEN
4754                 PA_DEBUG.set_curr_function(p_function => 'DELETE_REQUIREMENTS', p_debug_mode => l_debug_mode);
4755         END IF;
4756 
4757         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
4758                 FND_MSG_PUB.initialize;
4759         END IF;
4760         --------------------------------------------------
4761         -- Create Savepoint
4762         --------------------------------------------------
4763         IF p_commit = FND_API.G_TRUE THEN
4764                 savepoint DELETE_REQUIREMENTS_SP;
4765         END IF;
4766 
4767         IF l_debug_mode = 'Y' THEN
4768                 pa_debug.write(l_module, 'Start of DELETE_REQUIREMENTS', l_log_level);
4769         END IF;
4770         --------------------------------------------------
4771         -- Start Initialize
4772         --------------------------------------------------
4773         PA_STARTUP.INITIALIZE(
4774                   p_calling_application => l_calling_application
4775                 , p_calling_module => l_calling_module
4776                 , p_check_id_flag => l_check_id_flag
4777                 , p_check_role_security_flag => l_check_role_security_flag
4778                 , p_check_resource_security_flag => l_check_resource_security_flag
4779                 , p_debug_level => l_log_level
4780                 );
4781 
4782         IF l_debug_mode = 'Y' THEN
4783                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
4784         END IF;
4785         --------------------------------------------------
4786         -- Defaulting Values and Mandatory param validations
4787         -- Security Check
4788         -- Core Logic
4789         --------------------------------------------------
4790         i := p_requirement_in_tbl.first;
4791 
4792         WHILE i is not NULL LOOP
4793                 l_error_flag_local := 'N';
4794                 l_missing_params := null;
4795                 l_req_rec := null;
4796 
4797                 l_start_msg_count := FND_MSG_PUB.count_msg;
4798 
4799                 l_req_rec := p_requirement_in_tbl(i);
4800 
4801                 -- Blank Out Parameters if not passed.
4802            	IF l_req_rec.requirement_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
4803 			l_req_rec.requirement_id := NULL  ;
4804 		END IF;
4805 
4806 		IF l_req_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
4807 			l_req_rec.record_version_number := NULL ;
4808 		END IF;
4809 
4810 		IF l_debug_mode = 'Y' THEN
4811                         pa_debug.write(l_module, 'Requirement_id is ' || l_req_rec.requirement_id,l_log_level);
4812 			pa_debug.write(l_module, 'Record Version Number is ' || l_req_rec.record_version_number, l_log_level);
4813                 END IF;
4814 
4815                 -- Mandatory Parameters Check
4816                 IF l_debug_mode = 'Y' THEN
4817                         pa_debug.write(l_module, 'Mandatory Parameter Validation Starts', l_log_level);
4818                 END IF;
4819 
4820 		IF l_req_rec.requirement_id IS NULL THEN
4821 			l_missing_params := l_missing_params||'REQUIREMENT_ID ' ;
4822 		END IF;
4823 
4824 
4825 		IF l_debug_mode = 'Y' THEN
4826                         pa_debug.write(l_module, 'Mandatory Parameter Validation Over. ',l_log_level);
4827 			pa_debug.write(l_module, 'The missing parameters are '||l_missing_params, l_log_level);
4828                 END IF;
4829 
4830                 IF l_missing_params IS NOT NULL THEN
4831                         l_error_flag_local := 'Y';
4832                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
4833                                                 'INVALID_PARAMS', l_missing_params);
4834                 END IF;
4835 
4836 		IF l_error_flag_local <> 'Y' THEN
4837 
4838                 	l_assignment_id := l_req_rec.requirement_id ;
4839                 	-- Derive the other values
4840                 	OPEN c_derive_values(l_assignment_id);
4841                 	FETCH c_derive_values INTO l_assignment_row_id ,l_project_id,l_record_version_number,l_team_template_id,l_assignment_number,l_status_code;
4842 			IF c_derive_values%NOTFOUND THEN
4843                                 l_missing_params := l_missing_params||'REQUIREMENT_ID ' ;
4844                                 l_error_flag_local := 'Y';
4845                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
4846                                                         'INVALID_PARAMS', l_missing_params);
4847 			END IF;
4848                		CLOSE c_derive_values;
4849 
4850 			IF l_error_flag_local <> 'Y' THEN
4851 
4852                         l_system_status_code := null;
4853                         OPEN c_get_system_status ;
4854 			FETCH c_get_system_status INTO l_system_status_code ;
4855 			CLOSE c_get_system_status;
4856 
4857 			--IF l_system_status_code IN ('OPEN_ASGMT_CANCEL','OPEN_ASGMT_FILLED') THEN --Bug 7638990
4858 			IF l_system_status_code IN ('OPEN_ASGMT_FILLED') THEN  --Bug 7638990
4859 				l_error_flag_local := 'Y' ;
4860                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
4861 			END IF;
4862 
4863                 	-- Security Check
4864                         IF l_debug_mode = 'Y' THEN
4865                                 pa_debug.write(l_module, 'Checking Security for record number '||i, l_log_level);
4866                         END IF;
4867 
4868                         IF l_project_id IS NOT NULL THEN
4869                                 l_privilege := 'PA_ASN_CR_AND_DL';
4870                                 l_object_name := 'PA_PROJECTS';
4871                                 l_object_key := l_project_id ;
4872 			ELSIF l_team_template_id IS NOT NULL THEN
4873                                 l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
4874                                 l_object_name := null;
4875                                 l_object_key := null;
4876 			ELSE -- This wont happen
4877 				PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
4878                                 raise FND_API.G_EXC_ERROR;
4879                         END IF;
4880 
4881                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4882                         l_ret_code := 'T';
4883 
4884                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
4885                                   x_ret_code       => l_ret_code
4886                                 , x_return_status  => l_return_status
4887                                 , x_msg_count      => l_msg_count
4888                                 , x_msg_data       => l_msg_data
4889                                 , p_privilege      => l_privilege
4890                                 , p_object_name    => l_object_name
4891                                 , p_object_key     => l_object_key
4892 				,p_init_msg_list   => FND_API.G_FALSE);
4893 
4894                         IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4895                                 -- This message does not have token defined, but intentionally putting token
4896                                 -- because we still want to show the privilege name which is missing
4897                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_CR_DL'
4898                                                       ,'MISSING_PRIVILEGE', l_privilege);
4899                                 l_error_flag_local := 'Y';
4900                         END IF;
4901 
4902 			END IF;
4903 	         END IF;
4904 
4905                 -- Call Actual API
4906                 IF l_error_flag_local <> 'Y' THEN
4907                         l_return_status := FND_API.G_RET_STS_SUCCESS;
4908 
4909                         IF l_debug_mode = 'Y' THEN
4910                                 pa_debug.write(l_module, 'Calling PA_ASSIGNMENTS_PUB.DELETE_ASSIGNMENT for record number'||i, l_log_level);
4911                         END IF;
4912 
4913 
4914 			PA_ASSIGNMENTS_PUB.Delete_Assignment
4915 			( p_assignment_row_id => l_assignment_row_id
4916  			, p_assignment_id     => l_assignment_id
4917  			, p_record_version_number  => l_record_version_number
4918 			, p_assignment_type        => l_assignment_type
4919  			, p_assignment_number      => l_assignment_number
4920  			, p_commit                 => l_commit
4921  			, p_validate_only          => l_validate_only
4922  			, x_return_status          => l_return_status
4923  			, x_msg_count              => l_msg_count
4924  			, x_msg_data               => l_msg_data
4925  			);
4926                         IF l_debug_mode = 'Y' THEN
4927                                 pa_debug.write(l_module, 'After call PA_ASSIGNMENTS_PUB.DELETE_ASSIGNMENT l_return_status='||l_return_status, l_log_level);
4928                         END IF;
4929 
4930                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4931                                 l_error_flag_local := 'Y';
4932                         END IF;
4933                 END IF;
4934 
4935                 l_end_msg_count := FND_MSG_PUB.count_msg;
4936                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
4937 
4938                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
4939                         l_error_flag := 'Y';
4940 
4941                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
4942                                 -- Always get from first location in stack i.e. l_start_msg_count+1
4943                                 -- Because stack moves down after delete
4944                                 FND_MSG_PUB.get (
4945                                         p_msg_index      => l_start_msg_count+1,
4946                                         p_encoded        => FND_API.G_FALSE,
4947                                         p_data           => l_data,
4948                                         p_msg_index_out  => l_msg_index_out );
4949 
4950                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
4951                                 -- Because stack moves down after delete
4952                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
4953 
4954                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
4955                                                 'RECORD_NO', i,
4956                                                 'MESSAGE', l_data);
4957                         END LOOP;
4958                 END IF;
4959                 i := p_requirement_in_tbl.next(i);
4960         END LOOP;
4961 
4962         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
4963                 RAISE FND_API.G_EXC_ERROR;
4964         END IF;
4965 
4966         IF l_debug_mode = 'Y' THEN
4967                 PA_DEBUG.reset_curr_function;
4968         END IF;
4969 
4970         IF p_commit = FND_API.G_TRUE THEN
4971                 commit;
4972         END IF;
4973 
4974 
4975 EXCEPTION
4976 WHEN FND_API.G_EXC_ERROR THEN
4977         x_return_status := FND_API.G_RET_STS_ERROR;
4978         l_msg_count := FND_MSG_PUB.count_msg;
4979 
4980         IF p_commit = FND_API.G_TRUE THEN
4981                 ROLLBACK TO DELETE_REQUIREMENTS_SP;
4982         END IF;
4983 
4984 	IF c_derive_values%ISOPEN THEN
4985 		CLOSE c_derive_values ;
4986 	END IF;
4987 
4988 	IF c_get_system_status%ISOPEN THEN
4989                 CLOSE c_get_system_status ;
4990 	END IF;
4991 
4992         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
4993                 PA_INTERFACE_UTILS_PUB.get_messages
4994                 ( p_encoded        => FND_API.G_FALSE
4995                 , p_msg_index      => 1
4996                 , p_msg_count      => l_msg_count
4997                 , p_msg_data       => l_msg_data
4998                 , p_data           => l_data
4999                 , p_msg_index_out  => l_msg_index_out);
5000 
5001                 x_msg_data := l_data;
5002                 x_msg_count := l_msg_count;
5003         ELSE
5004                 x_msg_count := l_msg_count;
5005         END IF;
5006 
5007         IF l_debug_mode = 'Y' THEN
5008                 Pa_Debug.reset_curr_function;
5009         END IF;
5010 
5011 WHEN OTHERS THEN
5012 
5013         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5014         x_msg_data      := SQLERRM;
5015 
5016         IF p_commit = FND_API.G_TRUE THEN
5017                 ROLLBACK TO DELETE_REQUIREMENTS_SP;
5018         END IF;
5019 
5020         IF c_derive_values%ISOPEN THEN
5021                 CLOSE c_derive_values ;
5022         END IF;
5023 
5024         IF c_get_system_status%ISOPEN THEN
5025                 CLOSE c_get_system_status ;
5026         END IF;
5027 
5028         FND_MSG_PUB.add_exc_msg
5029         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
5030         , p_procedure_name      => 'DELETE_REQUIREMENTS'
5031         , p_error_text          => x_msg_data);
5032 
5033         x_msg_count     := FND_MSG_PUB.count_msg;
5034 
5035         IF l_debug_mode = 'Y' THEN
5036                 PA_DEBUG.reset_curr_function;
5037         END IF;
5038         RAISE;
5039 END DELETE_REQUIREMENTS;
5040 
5041 -- Start of comments
5042 --	API name 	: STAFF_REQUIREMENTS
5043 --	Type		: Public
5044 --	Pre-reqs	: None.
5045 --	Function	: This is a public API to staff the requirements.
5046 --	Usage		: This API will be called from AMG.
5047 --	Parameters	:
5048 --	IN		:	p_commit		IN  VARCHAR2
5049 --					Identifier to commit the transaction.
5050 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
5051 --				p_init_msg_list		IN  VARCHAR2
5052 --					Identifier to initialize the error message stack.
5053 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
5054 --				p_api_version_number	IN  NUMBER			Required
5055 --					To be compliant with Applications API coding standards.
5056 --				p_staff_requirement_tbl	IN  STAFF_REQUIREMENT_TBL_TYPE	Required
5057 --					Table of staffing information for each requirement. Please see the datatype Staff_requirement_tbl_TYPE.
5058 --	OUT		:
5059 --				x_assignment_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
5060 --					Table to store the staffed assignment ids and newly created requirement_ids
5061 --				x_return_status		OUT VARCHAR2
5062 --					Indicates the return status of the API.
5063 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
5064 --				x_msg_count		OUT NUMBER
5065 --					Indicates the number of error messages in the message stack
5066 --				x_msg_data		OUT VARCHAR2
5067 --					Indicates the error message text if only one error exists
5068 --	History		:
5069 --                              01-Mar-2006 - avaithia  - Created
5070 -- End of comments
5071 PROCEDURE STAFF_REQUIREMENTS
5072 (
5073   p_api_version_number          IN              NUMBER   := 1.0
5074 , p_init_msg_list               IN              VARCHAR2 := FND_API.G_TRUE
5075 , p_commit                      IN              VARCHAR2 := FND_API.G_FALSE
5076 , P_STAFF_REQUIREMENT_TBL       IN              STAFF_REQUIREMENT_TBL_TYPE
5077 , X_ASSIGNMENT_ID_TBL           OUT     NOCOPY  SYSTEM.PA_NUM_TBL_TYPE
5078 , x_return_status               OUT     NOCOPY  VARCHAR2
5079 , x_msg_count                   OUT     NOCOPY  NUMBER
5080 , x_msg_data                    OUT     NOCOPY  VARCHAR2
5081 )
5082 IS
5083 l_calling_application           VARCHAR2(10)            := 'PLSQL';
5084 l_calling_module                VARCHAR2(10)            := 'AMG';
5085 l_check_id_flag                 VARCHAR2(1)             := 'Y';
5086 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
5087 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
5088 
5089 l_log_level                     NUMBER                  := 3;
5090 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.STAFF_REQUIREMENTS';
5091 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
5092 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
5093 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
5094 
5095 l_msg_count                     NUMBER;
5096 l_msg_data                      VARCHAR2(2000);
5097 l_msg_index_out                 NUMBER;
5098 l_data                          VARCHAR2(2000);
5099 l_debug_mode                    VARCHAR2(1);
5100 
5101 i                               NUMBER;
5102 
5103 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
5104 l_error_flag                    VARCHAR2(1)             := 'N';
5105 l_error_flag_local              VARCHAR2(1)             := 'N';
5106 
5107 l_loop_msg_count                NUMBER                  :=0;
5108 l_start_msg_count               NUMBER                  :=0;
5109 l_end_msg_count                 NUMBER                  :=0;
5110 l_before_api_msg_count		NUMBER                  :=0;
5111 l_after_api_msg_count		NUMBER			:=0;
5112 
5113 l_missing_params                VARCHAR2(1000);
5114 l_privilege                     VARCHAR2(30);
5115 l_object_name                   VARCHAR2(30);
5116 l_object_key                    NUMBER;
5117 l_error_message_code            VARCHAR2(30);
5118 l_ret_code                      VARCHAR2(1);
5119 
5120 l_staff_rec			STAFF_REQUIREMENT_REC_TYPE ;
5121 
5122 l_requirement_creation_mode     VARCHAR2(10);
5123 l_source_requirement_id         NUMBER;
5124 l_resource_id               	NUMBER;
5125 l_person_id                 	NUMBER;
5126 l_assignment_status_code        VARCHAR2(30);
5127 l_assignment_status_name    	VARCHAR2(80);
5128 l_unfilled_assign_status_code	VARCHAR2(30);
5129 l_unfilled_assign_status_name   VARCHAR2(80);
5130 l_remaining_candidate_code      VARCHAR2(30);
5131 l_change_reason_code            VARCHAR2(30);
5132 l_record_version_number		NUMBER;
5133 l_start_date			DATE;
5134 l_end_date			DATE;
5135 
5136 l_project_id 			NUMBER;
5137 l_team_template_id		NUMBER;
5138 l_status_code 			NUMBER;
5139 l_db_start_date			DATE;
5140 l_db_end_date			DATE;
5141 
5142 l_out_assignment_id		NUMBER;
5143 l_out_assignment_number		NUMBER;
5144 l_out_assignment_row_id		ROWID;
5145 l_out_resource_id		NUMBER;
5146 
5147 CURSOR c_derive_values(c_source_reqmt_id IN NUMBER) IS
5148 SELECT project_id,ASSIGNMENT_TEMPLATE_ID ,status_code,start_date,end_date
5149 FROM   pa_project_assignments
5150 WHERE  assignment_id = c_source_reqmt_id ;
5151 
5152 CURSOR c_valid_status_code IS
5153 SELECT project_status_name from pa_project_statuses
5154 where
5155 status_type = 'STAFFED_ASGMT'
5156 and   project_status_code = l_assignment_status_code
5157 and   trunc(SYSDATE) between start_date_active and nvl(end_date_active, trunc(SYSDATE))
5158 and   starting_status_flag = 'Y' and project_system_status_code <> 'STAFFED_ASGMT_CONF';
5159 
5160 CURSOR c_valid_unfilled_status_code IS
5161 SELECT project_status_name from pa_project_statuses
5162 where
5163 status_type = 'OPEN_ASGMT'
5164 and   project_status_code = l_unfilled_assign_status_code
5165 and   trunc(SYSDATE) between start_date_active and nvl(end_date_active, trunc(SYSDATE))
5166 and   starting_status_flag = 'Y' ;
5167 
5168 CURSOR c_valid_status_name IS
5169 SELECT project_status_code from pa_project_statuses
5170 where
5171 status_type = 'STAFFED_ASGMT'
5172 and   project_status_name = l_assignment_status_name
5173 and   trunc(SYSDATE) between start_date_active and nvl(end_date_active, trunc(SYSDATE))
5174 and   starting_status_flag = 'Y' and project_system_status_code <> 'STAFFED_ASGMT_CONF';
5175 
5176 CURSOR c_valid_unfilled_status_name IS
5177 SELECT project_status_code from pa_project_statuses
5178 where
5179 status_type = 'OPEN_ASGMT'
5180 and   project_status_name = l_unfilled_assign_status_name
5181 and   trunc(SYSDATE) between start_date_active and nvl(end_date_active, trunc(SYSDATE))
5182 and   starting_status_flag = 'Y' ;
5183 
5184 BEGIN
5185 
5186         --------------------------------------------------
5187         -- RESET OUT params
5188         --------------------------------------------------
5189         x_return_status := FND_API.G_RET_STS_SUCCESS;
5190         x_msg_count := 0;
5191         x_msg_data := NULL ;
5192 
5193 	X_ASSIGNMENT_ID_TBL := SYSTEM.PA_NUM_TBL_TYPE();
5194         --------------------------------------------------
5195         -- Initialize Current Function and Msg Stack
5196         --------------------------------------------------
5197         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
5198 
5199         IF l_debug_mode = 'Y' THEN
5200                 PA_DEBUG.set_curr_function(p_function => 'STAFF_REQUIREMENTS', p_debug_mode => l_debug_mode);
5201         END IF;
5202 
5203         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
5204                 FND_MSG_PUB.initialize;
5205         END IF;
5206         --------------------------------------------------
5207         -- Create Savepoint
5208         --------------------------------------------------
5209         IF p_commit = FND_API.G_TRUE THEN
5210                 savepoint STAFF_REQUIREMENTS_SP;
5211         END IF;
5212 
5213         IF l_debug_mode = 'Y' THEN
5214                 pa_debug.write(l_module, 'Start of STAFF_REQUIREMENTS', l_log_level);
5215         END IF;
5216         --------------------------------------------------
5217         -- Start Initialize
5218         --------------------------------------------------
5219         PA_STARTUP.INITIALIZE(
5220                   p_calling_application => l_calling_application
5221                 , p_calling_module => l_calling_module
5222                 , p_check_id_flag => l_check_id_flag
5223                 , p_check_role_security_flag => l_check_role_security_flag
5224                 , p_check_resource_security_flag => l_check_resource_security_flag
5225                 , p_debug_level => l_log_level
5226                 );
5227 
5228         IF l_debug_mode = 'Y' THEN
5229                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
5230         END IF;
5231         --------------------------------------------------
5232         -- Defaulting Values and Mandatory param validations
5233         -- Security Check
5234         -- Core Logic
5235         --------------------------------------------------
5236 	i := P_STAFF_REQUIREMENT_TBL.FIRST ;
5237 
5238         WHILE i is not NULL LOOP
5239                 l_error_flag_local := 'N';
5240                 l_missing_params := null;
5241 		l_staff_rec :=  NULL ;
5242                 l_start_msg_count := FND_MSG_PUB.count_msg;
5243 
5244 		l_staff_rec := P_STAFF_REQUIREMENT_TBL(i);
5245 
5246 		------------------------------------------------------------------------------------------
5247                 -- Blank Out Parameters if not passed.
5248 	        ------------------------------------------------------------------------------------------
5249 		-- Commented out as this param needs to be derived inside code
5250 		-- it should not be exposed to the user
5251 
5252 
5253 		IF l_staff_rec.source_requirement_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
5254 			l_staff_rec.source_requirement_id := NULL ;
5255                 END IF;
5256 
5257 	 	IF l_staff_rec.resource_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
5258                         l_staff_rec.resource_id := NULL ;
5259                 END IF;
5260 
5261 		IF l_staff_rec.person_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
5262                         l_staff_rec.person_id := NULL ;
5263                 END IF;
5264 
5265 		IF l_staff_rec.assignment_status_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
5266 			l_staff_rec.assignment_status_code := NULL ;
5267                 END IF;
5268 
5269 		IF l_staff_rec.assignment_status_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
5270                         l_staff_rec.assignment_status_name := NULL ;
5271                 END IF;
5272 
5273 		IF l_staff_rec.unfilled_assign_status_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
5274                         l_staff_rec.unfilled_assign_status_code := NULL ;
5275                 END IF;
5276 
5277 		IF l_staff_rec.unfilled_assign_status_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
5278                         l_staff_rec.unfilled_assign_status_name := NULL ;
5279                 END IF;
5280 
5281 		IF l_staff_rec.remaining_candidate_code  = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
5282                         l_staff_rec.remaining_candidate_code := NULL ;
5283                 END IF;
5284 
5285 		IF l_staff_rec.change_reason_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
5286                         l_staff_rec.change_reason_code := NULL ;
5287                 END IF;
5288 
5289                 IF l_staff_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
5290                         l_staff_rec.record_version_number := NULL ;
5291                 END IF;
5292 
5293 		IF l_staff_rec.start_date = PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE THEN
5294 			l_staff_rec.start_date := NULL ;
5295 		END IF;
5296 
5297 		IF l_staff_rec.end_Date = PA_INTERFACE_UTILS_PUB.G_PA_MISS_DATE THEN
5298                         l_staff_rec.end_Date := NULL ;
5299                 END IF;
5300 
5301                 IF l_debug_mode = 'Y' THEN
5302                         pa_debug.write(l_module,'Source Requirement ID ' || l_staff_rec.source_requirement_id,l_log_level);
5303 			pa_debug.write(l_module,'Record Version Number ' ||l_staff_rec.record_version_number,l_log_level);
5304 			pa_debug.write(l_module,'Resource id ' || l_staff_rec.resource_id,l_log_level);
5305                         pa_debug.write(l_module,'Person Id ' || l_staff_rec.person_id,l_log_level);
5306                         pa_debug.write(l_module,'Asgmt Status code ' ||l_staff_rec.assignment_status_code,l_log_level);
5307 			pa_debug.write(l_module,'Asgmt Status name ' ||l_staff_rec.assignment_status_name,l_log_level);
5308                         pa_debug.write(l_module,'Unfilled Asgmt Status code ' ||l_staff_rec.unfilled_assign_status_code,l_log_level);
5309                         pa_debug.write(l_module,'Unfilled Asgmt Status Name ' ||l_staff_rec.unfilled_assign_status_name,l_log_level);
5310 			pa_debug.write(l_module,'Remaining Candidate Code ' ||l_staff_rec.remaining_candidate_code,l_log_level);
5311 			pa_debug.write(l_module,'Change Reason Code ' ||l_staff_rec.change_reason_code,l_log_level);
5312 			pa_debug.write(l_module,'Start date ' || l_staff_rec.start_date,l_log_level);
5313                         pa_debug.write(l_module,'End date ' || l_staff_rec.end_Date,l_log_level);
5314 
5315 		END IF;
5316 
5317 		l_source_requirement_id := l_staff_rec.source_requirement_id;
5318 		l_record_version_number := l_staff_rec.record_version_number;
5319 		-- l_requirement_creation_mode := l_staff_rec.requirement_creation_mode;
5320 		l_resource_id := l_staff_rec.resource_id ;
5321 		l_person_id := l_staff_rec.person_id ;
5322 		l_assignment_status_code := l_staff_rec.assignment_status_code ;
5323 		l_assignment_status_name := l_staff_rec.assignment_status_name ;
5324 	 	l_unfilled_assign_status_code := l_staff_rec.unfilled_assign_status_code;
5325 		l_unfilled_assign_status_name := l_staff_rec.unfilled_assign_status_name ;
5326 		l_remaining_candidate_code := l_staff_rec.remaining_candidate_code;
5327 		l_change_reason_code := l_staff_rec.change_reason_code ;
5328 		l_start_date := l_staff_rec.start_date ;
5329 		l_end_date := l_staff_rec.end_Date;
5330 		------------------------------------------
5331 		-- Mandatory params check
5332 		------------------------------------------
5333 		IF l_source_requirement_id IS NULL THEN
5334 			l_missing_params := l_missing_params||'SOURCE_REQUIREMENT_ID' ;
5335                 END IF;
5336 
5337 		IF l_record_version_number IS NULL THEN
5338                         l_missing_params := l_missing_params||', RECORD_VERSION_NUMBER ';
5339 		END IF;
5340 
5341 		IF l_start_date IS NULL THEN
5342 			l_missing_params := l_missing_params||', START_DATE ';
5343 		END IF;
5344 
5345 		IF l_end_Date IS NULL THEN
5346 			l_missing_params := l_missing_params||', END_DATE ';
5347 		END IF;
5348 
5349 		IF l_resource_id IS NULL THEN
5350 			IF l_person_id IS NOT NULL THEN
5351 				l_resource_id := PA_RESOURCE_UTILS.GET_RESOURCE_ID(l_person_id);
5352 			ELSE -- if both are NULL
5353 				l_missing_params := l_missing_params||', RESOURCE_ID ';
5354 			END IF;
5355 		END IF;
5356 
5357 		IF l_person_id IS NULL THEN
5358 			IF l_resource_id IS NOT NULL THEN
5359 				l_person_id := PA_RESOURCE_UTILS.GET_PERSON_ID(l_resource_id);
5360 			ELSE -- if both are NULL
5361 				l_missing_params := l_missing_params||', PERSON_ID ';
5362 			END IF;
5363 		END IF;
5364 
5365 		IF l_assignment_status_code IS NULL THEN
5366 			IF l_assignment_status_name IS  NULL THEN
5367 				-- both NULL ,then add them .Any one is available,derive the other
5368 				l_missing_params := l_missing_params||', ASSIGNMENT_STATUS_CODE , ASSIGNMENT_STATUS_NAME';
5369 			END IF;
5370 		END IF;
5371 
5372 		IF l_missing_params IS NOT NULL THEN
5373                         l_error_flag_local := 'Y';
5374                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
5375                                                 'INVALID_PARAMS', l_missing_params);
5376                 	IF l_debug_mode = 'Y' THEN
5377 				pa_debug.write(l_module, 'The missing parameters are '||l_missing_params, l_log_level);
5378 			END IF;
5379 		END IF;
5380 
5381 		------------------------------------------------------------------------
5382 		-- 1) Derive Values and verify for valid values 2) Do Security Check
5383 		------------------------------------------------------------------------
5384 		IF l_error_flag_local <> 'Y' THEN
5385 			OPEN c_derive_values(l_source_requirement_id);
5386 			FETCH c_derive_values INTO l_project_id,l_team_template_id,l_status_code,l_db_start_date,l_db_end_date;
5387                         IF c_derive_values%NOTFOUND THEN
5388                                 l_error_flag_local := 'Y' ;
5389                                 l_missing_params := l_missing_params||'SOURCE_REQUIREMENT_ID' ;
5390                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
5391                                                 'INVALID_PARAMS', l_missing_params);
5392 			ELSE
5393 				-- If the requirement exists ,determine the mode and validate status values passed
5394 				-- Logic got from AssignResourceVORowImpl.java
5395 
5396 				-- 1) Creation Mode
5397 				IF l_start_date > l_db_start_date OR l_end_date < l_db_end_date THEN
5398 					l_requirement_creation_mode := 'PARTIAL';
5399 				ELSE
5400 					l_requirement_creation_mode := 'FULL';
5401 				END IF;
5402 
5403 				-- 2) Assignment Status Code Validation
5404 				IF l_assignment_status_code IS NOT NULL THEN
5405 					-- Anusha : Existing API just checks whether the status code name exists in
5406 					-- pa_project_statuses table
5407 
5408 					-- It does not check whether the status is a valid starting status and not
5409 					-- Confirmed etc.
5410 
5411 					-- Hence we need in explicitly here. In UI (SS) its controlled by poplist query.
5412 
5413 					-- Validate the passed status code
5414 					-- If its a valid code passed,it will auto populate status name
5415 					OPEN c_valid_status_code;
5416 					FETCH c_valid_status_code into l_assignment_status_name;
5417 
5418 					IF c_valid_status_code%NOTFOUND	THEN
5419 					-- Invalid status code has been passed.
5420 					l_error_flag_local := 'Y' ;
5421 					PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_ASG_STATUS',--New message
5422 					'SOURCE_REQUIREMENT_ID',l_source_requirement_id,'STATUS_CODE',l_assignment_status_code);
5423 					END IF;
5424 					CLOSE c_valid_status_code ;
5425 				ELSE -- if status code is NULL
5426 					-- Validate the passed status name
5427 					-- If its a valid name passed,it will auto populate status code
5428 					OPEN c_valid_status_name;
5429 					FETCH c_valid_status_name into l_assignment_status_code;
5430 
5431 					IF c_valid_status_name%NOTFOUND THEN
5432                                         -- Invalid status name has been passed .Here ,code is also nt passed
5433 					l_error_flag_local := 'Y' ;
5434                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_ASG_STATUS',
5435                                         'SOURCE_REQUIREMENT_ID',l_source_requirement_id,'STATUS_NAME',l_assignment_status_name);
5436 					END IF;
5437 					CLOSE c_valid_status_name ;
5438 				END IF;
5439 
5440 				-- 3) Validate the unfilled open assignment status value passed
5441 				IF l_unfilled_assign_status_code is not NULL THEN
5442 
5443 					-- Anusha : Existing API just checks whether the status code name exists in
5444                                         -- pa_project_statuses table
5445 
5446                                         -- It does not check whether the status is a valid starting status and
5447 					-- whether its a status specific to Open Requirements .
5448 					-- In SS ,this condition is controlled by Poplist query.So,here we need to
5449 					-- simulate the same
5450 
5451                                         -- Validate the passed status code
5452                                         -- If its a valid code passed,it will auto populate status name
5453 					OPEN c_valid_unfilled_status_code;
5454 					FETCH c_valid_unfilled_status_code into l_unfilled_assign_status_name ;
5455 
5456 					IF c_valid_unfilled_status_code%NOTFOUND THEN
5457                                         -- Invalid statuscode has been passed.
5458                                         l_error_flag_local := 'Y' ;
5459                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_UNFILL_INV_STATUS',--New message
5460                                         'SOURCE_REQUIREMENT_ID',l_source_requirement_id,'UNFILLED_STATUS_CODE',l_unfilled_assign_status_code);
5461 					END IF;
5462 					CLOSE c_valid_unfilled_status_code;
5463 				ELSE -- if unfilled status code is NULL
5464                                         -- Validate the passed unfilled status name
5465                                         -- If its a valid name passed,it will auto populate status code
5466                                         OPEN c_valid_unfilled_status_name;
5467 					FETCH c_valid_unfilled_status_name into l_unfilled_assign_status_code;
5468 					IF c_valid_unfilled_status_name%NOTFOUND THEN
5469                                         -- Invalid unfilled status name has been passed .Here ,code is also nt passed
5470                                         l_error_flag_local := 'Y' ;
5471                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_UNFILL_INV_STATUS',
5472 					'SOURCE_REQUIREMENT_ID',l_source_requirement_id,'UNFILLED_STATUS_NAME',l_unfilled_assign_status_name);
5473 					END IF;
5474 					CLOSE c_valid_unfilled_status_name;
5475 				END IF;
5476                         END IF;
5477                         CLOSE c_derive_values;
5478 		END IF;
5479 
5480 		IF l_error_flag_local <> 'Y' THEN
5481 			IF l_debug_mode = 'Y' THEN
5482                                 pa_debug.write(l_module, 'Checking Security for record number '||i, l_log_level);
5483                         END IF;
5484 
5485                         IF l_project_id IS NOT NULL THEN
5486                                 l_privilege := 'PA_ASN_CR_AND_DL';
5487                                 l_object_name := 'PA_PROJECTS';
5488                                 l_object_key := l_project_id ;
5489                         ELSIF l_team_template_id IS NOT NULL THEN
5490                                 l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
5491                                 l_object_name := null;
5492                                 l_object_key := null;
5493                         ELSE -- This wont happen though (using hard coded english for internal reference)
5494                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
5495                                 raise FND_API.G_EXC_ERROR;
5496                         END IF;
5497 
5498                         l_return_status := FND_API.G_RET_STS_SUCCESS;
5499                         l_ret_code := 'T';
5500 
5501 			PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
5502                          x_ret_code       => l_ret_code
5503                        , x_return_status  => l_return_status
5504                        , x_msg_count      => l_msg_count
5505                        , x_msg_data       => l_msg_data
5506                        , p_privilege      => l_privilege
5507                        , p_object_name    => l_object_name
5508                        , p_object_key     => l_object_key
5509                        ,p_init_msg_list   => FND_API.G_FALSE);
5510                                                                                                                                                   IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5511 
5512                             -- This message does not have token defined, but intentionally putting token
5513                             -- because we still want to show the privilege name which is missing
5514                                PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_STAFF'
5515                                                          ,'MISSING_PRIVILEGE', l_privilege);
5516                                l_error_flag_local := 'Y';
5517                        END IF;
5518  		END IF;
5519 
5520 		--------------------------------------------------------
5521 		-- Call Actual API
5522 		--------------------------------------------------------
5523 		IF l_error_flag_local <> 'Y' THEN
5524                         l_return_status := FND_API.G_RET_STS_SUCCESS;
5525                         l_msg_count:= 0;
5526                         l_msg_data := NULL ;
5527 
5528                         IF l_debug_mode = 'Y' THEN
5529                                 pa_debug.write(l_module, 'Calling PA_ASSIGNMENTS_PUB.Execute_Staff_Assign_From_Open for record number ' || i, l_log_level);
5530                         END IF;
5531 
5532 			l_before_api_msg_count := FND_MSG_PUB.count_msg;
5533 			PA_ASSIGNMENTS_PUB.Execute_Staff_Assign_From_Open
5534 			( p_asgn_creation_mode          => l_requirement_creation_mode
5535 			 ,p_record_version_number       => l_record_version_number
5536 			 ,p_multiple_status_flag	=> 'N'
5537 			 ,p_assignment_status_code      => l_assignment_status_code
5538 			 ,p_assignment_status_name      => l_assignment_status_name
5539 			 ,p_unfilled_assign_status_code => l_unfilled_assign_status_code
5540 			 ,p_unfilled_assign_status_name => l_unfilled_assign_status_name
5541 			 ,p_remaining_candidate_code    => l_remaining_candidate_code
5542 			 ,p_change_reason_code          => l_change_reason_code
5543 			 ,p_resource_id                 => l_resource_id
5544 			 ,p_source_assignment_id        => l_source_requirement_id
5545 			 ,p_start_date			=> l_start_date
5546 			 ,p_end_date			=> l_end_date
5547 			 ,p_init_msg_list               => l_init_msg_list
5548 			 ,p_commit                      => l_commit
5549 			 ,p_validate_only               => l_validate_only
5550 			 ,x_new_assignment_id           => l_out_assignment_id
5551 			 ,x_assignment_number           => l_out_assignment_number
5552 			 ,x_assignment_row_id           => l_out_assignment_row_id
5553 			 ,x_resource_id                 => l_out_resource_id
5554 			 ,x_return_status               => l_return_status
5555 			 ,x_msg_count                   => l_msg_count
5556 			 ,x_msg_data                    => l_msg_data
5557 			);
5558 
5559                         l_after_api_msg_count := FND_MSG_PUB.count_msg;
5560 			IF l_debug_mode = 'Y' THEN
5561 				pa_debug.write(l_module, 'After main API Call l_return_status ' || l_return_status,l_log_level);
5562 				pa_debug.write(l_module, 'l_msg_count is ' || l_msg_count ||' and l_msg_data is ' ||l_msg_data);
5563 			END IF;
5564 
5565 			---------------------------------------------------------------------------------------------
5566 			-- Populate OUT table appropriately
5567 			---------------------------------------------------------------------------------------------
5568 			IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5569 				l_error_flag_local := 'Y';
5570 				X_ASSIGNMENT_ID_TBL.EXTEND(1);
5571 				X_ASSIGNMENT_ID_TBL(X_ASSIGNMENT_ID_TBL.COUNT) := -1;
5572 			ELSE -- Success
5573 				IF (l_after_api_msg_count - l_before_api_msg_count) = 0 AND l_msg_data is NULL THEN
5574 					X_ASSIGNMENT_ID_TBL.EXTEND(1);
5575 					X_ASSIGNMENT_ID_TBL(X_ASSIGNMENT_ID_TBL.COUNT) := l_out_assignment_id ;
5576 				ELSE -- some message populated while executing the called API
5577 					l_error_flag_local := 'Y';
5578 					X_ASSIGNMENT_ID_TBL.EXTEND(1);
5579 					X_ASSIGNMENT_ID_TBL(X_ASSIGNMENT_ID_TBL.COUNT) := -1;
5580 				END IF;
5581 			END IF;
5582 
5583 			---------------------------------------------------------------------------------------------
5584 			l_end_msg_count := FND_MSG_PUB.count_msg;
5585 
5586 			l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
5587 
5588 			IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
5589 				l_error_flag := 'Y';
5590 
5591 				FOR j in l_start_msg_count+1..l_end_msg_count LOOP
5592 					-- Always get from first location in stack i.e. l_start_msg_count+1
5593 					-- Because stack moves down after delete
5594 					FND_MSG_PUB.get (
5595 					p_msg_index      => l_start_msg_count+1,
5596 					p_encoded        => FND_API.G_FALSE,
5597 					p_data           => l_data,
5598 					p_msg_index_out  => l_msg_index_out );
5599 
5600 				-- Always delete at first location in stack i.e. l_start_msg_count+1
5601 				-- Because stack moves down after delete
5602 				FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
5603 
5604 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
5605 					'RECORD_NO', i,'MESSAGE', l_data);
5606 				END LOOP;
5607 			END IF;
5608 			---------------------------------------------------------------------------------------------
5609 		END IF;
5610 		i := P_STAFF_REQUIREMENT_TBL.NEXT(i);
5611 	END LOOP;
5612 
5613         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
5614                 RAISE FND_API.G_EXC_ERROR;
5615         END IF;
5616 
5617         IF l_debug_mode = 'Y' THEN
5618                 PA_DEBUG.reset_curr_function;
5619         END IF;
5620 
5621         IF p_commit = FND_API.G_TRUE THEN
5622                 commit;
5623         END IF;
5624 
5625 EXCEPTION
5626 WHEN FND_API.G_EXC_ERROR THEN
5627         x_return_status := FND_API.G_RET_STS_ERROR;
5628         l_msg_count := FND_MSG_PUB.count_msg;
5629 
5630         IF p_commit = FND_API.G_TRUE THEN
5631                 ROLLBACK TO STAFF_REQUIREMENTS_SP;
5632         END IF;
5633 
5634         IF c_derive_values%ISOPEN THEN
5635                 CLOSE c_derive_values ;
5636         END IF;
5637 
5638 	IF c_valid_status_code%ISOPEN THEN
5639                 CLOSE c_valid_status_code ;
5640 	END IF;
5641 
5642 	IF c_valid_status_name%ISOPEN THEN
5643                 CLOSE c_valid_status_name;
5644 	END IF;
5645 
5646         IF c_valid_unfilled_status_code%ISOPEN THEN
5647                 CLOSE c_valid_unfilled_status_code ;
5648 	END IF;
5649 
5650 	IF c_valid_unfilled_status_name%ISOPEN THEN
5651                 CLOSE c_valid_unfilled_status_name ;
5652 	END IF;
5653 
5654         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
5655                 PA_INTERFACE_UTILS_PUB.get_messages
5656                 ( p_encoded        => FND_API.G_FALSE
5657                 , p_msg_index      => 1
5658                 , p_msg_count      => l_msg_count
5659                 , p_msg_data       => l_msg_data
5660                 , p_data           => l_data
5661                 , p_msg_index_out  => l_msg_index_out);
5662 
5663                 x_msg_data := l_data;
5664                 x_msg_count := l_msg_count;
5665         ELSE
5666                 x_msg_count := l_msg_count;
5667         END IF;
5668 
5669 
5670         IF l_debug_mode = 'Y' THEN
5671                 Pa_Debug.reset_curr_function;
5672         END IF;
5673 WHEN OTHERS THEN
5674 
5675         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5676         x_msg_data      := SUBSTRB(SQLERRM,1,240);
5677 
5678         IF p_commit = FND_API.G_TRUE THEN
5679                 ROLLBACK TO STAFF_REQUIREMENTS_SP;
5680         END IF;
5681 
5682         IF c_derive_values%ISOPEN THEN
5683                 CLOSE c_derive_values ;
5684         END IF;
5685 
5686         IF c_valid_status_code%ISOPEN THEN
5687                 CLOSE c_valid_status_code ;
5688         END IF;
5689 
5690         IF c_valid_status_name%ISOPEN THEN
5691                 CLOSE c_valid_status_name;
5692         END IF;
5693 
5694         IF c_valid_unfilled_status_code%ISOPEN THEN
5695                 CLOSE c_valid_unfilled_status_code ;
5696         END IF;
5697 
5698         IF c_valid_unfilled_status_name%ISOPEN THEN
5699                 CLOSE c_valid_unfilled_status_name ;
5700         END IF;
5701 
5702         FND_MSG_PUB.add_exc_msg
5703         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
5704         , p_procedure_name      => 'STAFF_REQUIREMENTS'
5705         , p_error_text          => x_msg_data);
5706 
5707         x_msg_count     := FND_MSG_PUB.count_msg;
5708 
5709         IF l_debug_mode = 'Y' THEN
5710                 PA_DEBUG.reset_curr_function;
5711         END IF;
5712         RAISE;
5713 
5714 END STAFF_REQUIREMENTS;
5715 
5716 -- Start of comments
5717 --	API name 	: COPY_TEAM_ROLES
5718 --	Type		: Public
5719 --	Pre-reqs	: None.
5720 --	Function	: This is a public API to copy team roles from project assignments or requirements.
5721 --	Usage		: This API will be called from AMG.
5722 --	Parameters	:
5723 --	IN		:	p_commit		IN  VARCHAR2
5724 --					Identifier to commit the transaction.
5725 --					Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
5726 --				p_init_msg_list		IN  VARCHAR2
5727 --					Identifier to initialize the error message stack.
5728 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
5729 --				p_api_version_number	IN  NUMBER			Required
5730 --					To be compliant with Applications API coding standards.
5731 --				p_req_asgn_id_tbl	IN  SYSTEM.PA_NUM_TBL_TYPE	Required
5732 --					Table of requirement or assignment ids.
5733 --					Reference: pa_project_assignments.assignment_id
5734 --	OUT		:
5735 --				x_req_asgn_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
5736 --					Table to store the created requirement or assignment ids
5737 --				x_return_status		OUT VARCHAR2
5738 --					Indicates the return status of the API.
5739 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
5740 --				x_msg_count		OUT NUMBER
5741 --					Indicates the number of error messages in the message stack
5742 --				x_msg_data		OUT VARCHAR2
5743 --					Indicates the error message text if only one error exists
5744 --	History		:
5745 --                              01-Mar-2006 - avaithia  - Created
5746 -- End of comments
5747 PROCEDURE COPY_TEAM_ROLES
5748 (
5749   p_api_version_number          IN              NUMBER   := 1.0
5750 , p_init_msg_list               IN              VARCHAR2 := FND_API.G_TRUE
5751 , p_commit                      IN              VARCHAR2 := FND_API.G_FALSE
5752 , p_req_asgn_id_tbl             IN              SYSTEM.PA_NUM_TBL_TYPE
5753 , x_req_asgn_id_tbl             OUT     NOCOPY  SYSTEM.PA_NUM_TBL_TYPE
5754 , x_return_status               OUT     NOCOPY  VARCHAR2
5755 , x_msg_count                   OUT     NOCOPY  NUMBER
5756 , x_msg_data                    OUT     NOCOPY  VARCHAR2
5757 )
5758 IS
5759 l_calling_application           VARCHAR2(10)            := 'PLSQL';
5760 l_calling_module                VARCHAR2(10)            := 'AMG';
5761 l_check_id_flag                 VARCHAR2(1)             := 'Y';
5762 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
5763 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
5764 
5765 l_log_level                     NUMBER                  := 3;
5766 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.COPY_TEAM_ROLES';
5767 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
5768 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
5769 
5770 l_msg_count                     NUMBER;
5771 l_msg_data                      VARCHAR2(2000);
5772 l_msg_index_out                 NUMBER;
5773 l_data                          VARCHAR2(2000);
5774 l_debug_mode                    VARCHAR2(1);
5775 
5776 i                               NUMBER;
5777 k				NUMBER;
5778 
5779 -- l_req_rec               REQUIREMENT_IN_REC_TYPE;
5780 l_req_rec			NUMBER ;
5781 
5782 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
5783 l_error_flag                    VARCHAR2(1)             := 'N';
5784 l_error_flag_local              VARCHAR2(1)             := 'N';
5785 
5786 l_loop_msg_count                NUMBER                  :=0;
5787 l_start_msg_count               NUMBER                  :=0;
5788 l_end_msg_count                 NUMBER                  :=0;
5789 
5790 l_missing_params                VARCHAR2(1000);
5791 l_privilege                     VARCHAR2(30);
5792 l_object_name                   VARCHAR2(30);
5793 l_object_key                    NUMBER;
5794 l_error_message_code            VARCHAR2(30);
5795 l_ret_code                      VARCHAR2(1);
5796 
5797 l_req_asgn_id			NUMBER;
5798 l_project_id			NUMBER;
5799 l_team_template_id		NUMBER;
5800 
5801 l_out_req_asgn_id		NUMBER;
5802 l_out_req_asgn_number	 	NUMBER;
5803 l_out_req_asgn_row_id 		ROWID;
5804 
5805 l_before_api_msg_count		NUMBER;
5806 l_after_api_msg_count		NUMBER;
5807 
5808 l_status_code			VARCHAR2(30);
5809 
5810 CURSOR c_derive_values(p_req_asgn_id IN NUMBER) IS
5811 SELECT project_id,ASSIGNMENT_TEMPLATE_ID,status_code
5812 FROM   pa_project_assignments
5813 WHERE  assignment_id = p_req_asgn_id ;
5814 
5815 CURSOR c_get_system_status IS
5816 SELECT PROJECT_SYSTEM_STATUS_CODE
5817 FROM   pa_project_statuses
5818 WHERE  project_status_code = l_status_code
5819   AND  status_type  in ('OPEN_ASGMT','STAFFED_ASGMT');
5820 
5821 l_system_status_code     	VARCHAR2(30);
5822 BEGIN
5823 
5824         --------------------------------------------------
5825         -- RESET OUT params
5826         --------------------------------------------------
5827         x_return_status := FND_API.G_RET_STS_SUCCESS;
5828         x_msg_count := 0;
5829         x_msg_data := NULL ;
5830 
5831 	X_REQ_ASGN_ID_TBL := SYSTEM.PA_NUM_TBL_TYPE();
5832         --------------------------------------------------
5833         -- Initialize Current Function and Msg Stack
5834         --------------------------------------------------
5835         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
5836 
5837         IF l_debug_mode = 'Y' THEN
5838                 PA_DEBUG.set_curr_function(p_function => 'COPY_TEAM_ROLES', p_debug_mode => l_debug_mode);
5839         END IF;
5840 
5841         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
5842                 FND_MSG_PUB.initialize;
5843         END IF;
5844         --------------------------------------------------
5845         -- Create Savepoint
5846         --------------------------------------------------
5847         IF p_commit = FND_API.G_TRUE THEN
5848                 savepoint COPY_TEAM_ROLES_SP;
5849         END IF;
5850 
5851         IF l_debug_mode = 'Y' THEN
5852                 pa_debug.write(l_module, 'Start of COPY_TEAM_ROLES', l_log_level);
5853         END IF;
5854         --------------------------------------------------
5855         -- Start Initialize
5856         --------------------------------------------------
5857         PA_STARTUP.INITIALIZE(
5858                   p_calling_application => l_calling_application
5859                 , p_calling_module => l_calling_module
5860                 , p_check_id_flag => l_check_id_flag
5861                 , p_check_role_security_flag => l_check_role_security_flag
5862                 , p_check_resource_security_flag => l_check_resource_security_flag
5863                 , p_debug_level => l_log_level
5864                 );
5865 
5866         IF l_debug_mode = 'Y' THEN
5867                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
5868         END IF;
5869         --------------------------------------------------
5870         -- Defaulting Values and Mandatory param validations
5871         -- Security Check
5872         -- Core Logic
5873         --------------------------------------------------
5874         i := p_req_asgn_id_tbl.first;
5875         WHILE i is not NULL LOOP
5876                 l_error_flag_local := 'N';
5877                 l_missing_params := null;
5878                 l_req_asgn_id := null;
5879 		l_req_rec := NULL ;
5880 
5881                 l_start_msg_count := FND_MSG_PUB.count_msg;
5882 
5883 		l_req_rec := p_req_asgn_id_tbl(i);
5884 
5885 		l_req_asgn_id := l_req_rec;
5886 
5887 		-- Blank Out Parameters if not passed.
5888 		IF l_req_asgn_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
5889                         l_req_asgn_id := NULL ;
5890 		END IF ;
5891 
5892                 -- Mandatory Parameters Check
5893                 IF l_debug_mode = 'Y' THEN
5894                         pa_debug.write(l_module, 'Mandatory Parameter Validation Starts', l_log_level);
5895                 END IF;
5896 
5897                 IF l_debug_mode = 'Y' THEN
5898                         pa_debug.write(l_module, 'The Passed id is : ' || l_req_asgn_id ,l_log_level);
5899 		END IF;
5900 
5901                 IF l_req_asgn_id is NULL THEN
5902 			l_missing_params := l_missing_params||'TEAM_ROLE_ID';
5903 		END IF;
5904 
5905 		IF l_debug_mode = 'Y' THEN
5906                         pa_debug.write(l_module, 'Mandatory Parameter Validation Over. ',l_log_level);
5907                         pa_debug.write(l_module, 'The missing parameters are '||l_missing_params, l_log_level);
5908                 END IF;
5909 
5910 		IF l_missing_params IS NOT NULL THEN
5911                         l_error_flag_local := 'Y';
5912                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
5913                                                 'INVALID_PARAMS', l_missing_params);
5914                 END IF;
5915 
5916 		IF l_error_flag_local <> 'Y' THEN
5917 			OPEN c_derive_values(l_req_asgn_id) ;
5918 			FETCH c_derive_values INTO l_project_id ,l_team_template_id,l_status_code ;
5919 			IF c_derive_values%NOTFOUND THEN
5920 
5921                                 l_error_flag_local := 'Y' ;
5922                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS'
5923 							,'TEAM_ROLE_ID',l_req_asgn_id); -- New message to say invalid team role
5924 			ELSE -- If team role exists
5925 				OPEN c_get_system_status ;
5926                         	FETCH c_get_system_status INTO l_system_status_code ;
5927                         	CLOSE c_get_system_status;
5928 
5929                         IF l_system_status_code IN ('OPEN_ASGMT_CANCEL','OPEN_ASGMT_FILLED','STAFFED_ASGMT_CANCEL') THEN
5930                                 l_error_flag_local := 'Y' ;
5931                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_CP_STATUS'); -- New message
5932                         END IF;
5933 
5934                         END IF;
5935                         CLOSE c_derive_values;
5936 
5937 			--------------------------------------------------------
5938                         -- Security Check
5939 			--------------------------------------------------------
5940 
5941 			IF l_error_flag_local <> 'Y' THEN
5942 
5943                         IF l_debug_mode = 'Y' THEN
5944                                 pa_debug.write(l_module, 'Checking Security for record number '||i, l_log_level);
5945                         END IF;
5946 
5947                         IF l_project_id IS NOT NULL THEN
5948                                 l_privilege := 'PA_ASN_CR_AND_DL';
5949                                 l_object_name := 'PA_PROJECTS';
5950                                 l_object_key := l_project_id ;
5951                         /* ELSIF l_team_template_id IS NOT NULL THEN
5952                                 -- Commented as Copy team role functionality is not available to team templates
5953 
5954                                 l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
5955                                 l_object_name := null;
5956                                 l_object_key := null;*/
5957                         ELSE -- This wont happen though (using hard coded english for internal reference)
5958                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
5959                                 raise FND_API.G_EXC_ERROR;
5960                         END IF;
5961 
5962                         l_return_status := FND_API.G_RET_STS_SUCCESS;
5963                         l_ret_code := 'T';
5964 
5965                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
5966                                   x_ret_code       => l_ret_code
5967                                 , x_return_status  => l_return_status
5968                                 , x_msg_count      => l_msg_count
5969                                 , x_msg_data       => l_msg_data
5970                                 , p_privilege      => l_privilege
5971                                 , p_object_name    => l_object_name
5972                                 , p_object_key     => l_object_key
5973 				,p_init_msg_list   => FND_API.G_FALSE);
5974 
5975                         IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5976                                 -- This message does not have token defined, but intentionally putting token
5977                                 -- because we still want to show the privilege name which is missing
5978                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_COPY_TM_RO'
5979                                                       ,'MISSING_PRIVILEGE', l_privilege);
5980                                 l_error_flag_local := 'Y';
5981                         END IF;
5982 
5983 			END IF;
5984 		END IF;
5985 
5986 		--------------------------------------------------------
5987                 -- Call Actual API
5988                 --------------------------------------------------------
5989 		IF l_error_flag_local <> 'Y' THEN
5990                         l_return_status := FND_API.G_RET_STS_SUCCESS;
5991 			l_msg_count:= 0;
5992 			l_msg_data := NULL ;
5993 
5994                         IF l_debug_mode = 'Y' THEN
5995                                 pa_debug.write(l_module, 'Calling PA_ASSIGNMENTS_PUB.COPY_TEAM_ROLES for record number'||i, l_log_level);
5996                         END IF;
5997 
5998 			l_before_api_msg_count := FND_MSG_PUB.count_msg;
5999 			PA_ASSIGNMENTS_PUB.Copy_Team_Role
6000                         (
6001                                 p_assignment_id => l_req_asgn_id,
6002                                 x_new_assignment_id => l_out_req_asgn_id ,
6003                                 x_assignment_number => l_out_req_asgn_number,
6004                                 x_assignment_row_id => l_out_req_asgn_row_id,
6005                                 x_return_status     => l_return_status,
6006                                 x_msg_count         => l_msg_count,
6007                                 x_msg_data          => l_msg_data
6008                         );
6009 			l_after_api_msg_count := FND_MSG_PUB.count_msg;
6010 
6011 			IF l_debug_mode = 'Y' THEN
6012                                 pa_debug.write(l_module, 'After call PA_ASSIGNMENTS_PUB.COPY_TEAM_ROLES l_return_status='||l_return_status, l_log_level);
6013                         END IF;
6014                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6015                                 l_error_flag_local := 'Y';
6016 				X_REQ_ASGN_ID_TBL.extend(1);
6017                                 X_REQ_ASGN_ID_TBL(X_REQ_ASGN_ID_TBL.COUNT) := -1;
6018 			ELSE -- Success
6019 				IF (l_after_api_msg_count - l_before_api_msg_count) = 0 AND l_msg_data is NULL THEN
6020 					X_REQ_ASGN_ID_TBL.extend(1);
6021 					X_REQ_ASGN_ID_TBL(X_REQ_ASGN_ID_TBL.COUNT) := l_out_req_asgn_id ;
6022 				ELSE -- some message populated while executing the called API
6023 					l_error_flag_local := 'Y';
6024 					X_REQ_ASGN_ID_TBL.extend(1);
6025 					X_REQ_ASGN_ID_TBL(X_REQ_ASGN_ID_TBL.COUNT) := -1 ; -- to indicate some wrong operation happened
6026 				END IF;
6027                         END IF;
6028                 END IF;
6029 
6030 		l_end_msg_count := FND_MSG_PUB.count_msg;
6031                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
6032 
6033                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
6034                         l_error_flag := 'Y';
6035 
6036 
6037                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
6038                                 -- Always get from first location in stack i.e. l_start_msg_count+1
6039                                 -- Because stack moves down after delete
6040 
6041                                 FND_MSG_PUB.get (
6042                                         p_msg_index      => l_start_msg_count+1,
6043                                         p_encoded        => FND_API.G_FALSE,
6044                                         p_data           => l_data,
6045                                         p_msg_index_out  => l_msg_index_out );
6046 
6047                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
6048                                 -- Because stack moves down after delete
6049                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
6050 
6051                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
6052                                                 'RECORD_NO', i,
6053                                                 'MESSAGE', l_data);
6054                         END LOOP;
6055                 END IF;
6056 
6057 	i := p_req_asgn_id_tbl.next(i);
6058 	END LOOP;
6059 
6060         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
6061                 RAISE FND_API.G_EXC_ERROR;
6062         END IF;
6063 
6064         IF l_debug_mode = 'Y' THEN
6065                 PA_DEBUG.reset_curr_function;
6066         END IF;
6067 
6068         IF p_commit = FND_API.G_TRUE THEN
6069                 commit;
6070         END IF;
6071 EXCEPTION
6072 WHEN FND_API.G_EXC_ERROR THEN
6073         x_return_status := FND_API.G_RET_STS_ERROR;
6074         l_msg_count := FND_MSG_PUB.count_msg;
6075 
6076         IF p_commit = FND_API.G_TRUE THEN
6077                 ROLLBACK TO COPY_TEAM_ROLES_SP;
6078         END IF;
6079 
6080         IF c_derive_values%ISOPEN THEN
6081                 CLOSE c_derive_values ;
6082         END IF;
6083 
6084 	IF c_get_system_status%ISOPEN THEN
6085 		CLOSE c_get_system_status ;
6086 	END IF;
6087 
6088         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
6089                 PA_INTERFACE_UTILS_PUB.get_messages
6090                 ( p_encoded        => FND_API.G_FALSE
6091                 , p_msg_index      => 1
6092                 , p_msg_count      => l_msg_count
6093                 , p_msg_data       => l_msg_data
6094                 , p_data           => l_data
6095                 , p_msg_index_out  => l_msg_index_out);
6096 
6097                 x_msg_data := l_data;
6098                 x_msg_count := l_msg_count;
6099         ELSE
6100                 x_msg_count := l_msg_count;
6101         END IF;
6102 
6103 
6104         IF l_debug_mode = 'Y' THEN
6105                 Pa_Debug.reset_curr_function;
6106         END IF;
6107 
6108 WHEN OTHERS THEN
6109 
6110         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6111         x_msg_data      := SUBSTRB(SQLERRM,1,240);
6112 
6113         IF p_commit = FND_API.G_TRUE THEN
6114                 ROLLBACK TO COPY_TEAM_ROLES_SP;
6115         END IF;
6116 
6117         IF c_derive_values%ISOPEN THEN
6118                 CLOSE c_derive_values ;
6119         END IF;
6120 
6121         IF c_get_system_status%ISOPEN THEN
6122                 CLOSE c_get_system_status ;
6123         END IF;
6124 
6125         FND_MSG_PUB.add_exc_msg
6126         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
6127         , p_procedure_name      => 'COPY_TEAM_ROLES'
6128         , p_error_text          => x_msg_data);
6129 
6130         x_msg_count     := FND_MSG_PUB.count_msg;
6131 
6132         IF l_debug_mode = 'Y' THEN
6133                 PA_DEBUG.reset_curr_function;
6134         END IF;
6135         RAISE;
6136 
6137 END COPY_TEAM_ROLES;
6138 
6139 -- Start of comments
6140 --	API name 	: CREATE_ASSIGNMENTS
6141 --	Type		: Public
6142 --	Pre-reqs	: None.
6143 --	Function	: This is a public API to create one or more assignments for one or more projects.
6144 --	Usage		: This API will be called from AMG.
6145 --	Parameters	:
6146 --	IN		:	p_commit		IN  VARCHAR2
6147 --					Identifier to commit the transaction.
6148 --					Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
6149 --				p_init_msg_list		IN  VARCHAR2
6150 --					Identifier to initialize the error message stack.
6151 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
6152 --				p_api_version_number	IN  NUMBER			Required
6153 --					To be compliant with Applications API coding standards.
6154 --				p_assignment_in_tbl	IN  ASSIGNMENT_IN_TBL_TYPE	Required
6155 --					Table of assignment records.
6156 --					Please see the ASSIGNMENT_IN_TBL_TYPE datatype table.
6157 --	OUT		:
6158 --				x_assignment_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
6159 --					Table to store assignment ids created by the API.
6160 --					Reference: pa_project_assignments.assignment_id
6161 --				x_return_status		OUT VARCHAR2
6162 --					Indicates the return status of the API.
6163 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
6164 --				x_msg_count		OUT NUMBER
6165 --					Indicates the number of error messages in the message stack
6166 --				x_msg_data		OUT VARCHAR2
6167 --					Indicates the error message text if only one error exists
6168 --	History		:
6169 --                              01-Mar-2006 - amksingh  - Created
6170 -- End of comments
6171 PROCEDURE CREATE_ASSIGNMENTS
6172 (
6173   p_api_version_number		IN		NUMBER   := 1.0
6174 , p_init_msg_list		IN		VARCHAR2 := FND_API.G_TRUE
6175 , p_commit			IN		VARCHAR2 := FND_API.G_FALSE
6176 , p_assignment_in_tbl		IN		ASSIGNMENT_IN_TBL_TYPE
6177 , x_assignment_id_tbl		OUT	NOCOPY	SYSTEM.PA_NUM_TBL_TYPE
6178 , x_return_status		OUT	NOCOPY	VARCHAR2
6179 , x_msg_count			OUT	NOCOPY	NUMBER
6180 , x_msg_data			OUT	NOCOPY	VARCHAR2
6181 )
6182 IS
6183 l_calling_application           VARCHAR2(10)            := 'PLSQL';
6184 l_calling_module                VARCHAR2(10)            := 'AMG';
6185 l_check_id_flag                 VARCHAR2(1)             := 'Y';
6186 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
6187 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
6188 l_log_level                     NUMBER                  := 3;
6189 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.CREATE_ASSIGNMENTS';
6190 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
6191 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
6192 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
6193 l_msg_count                     NUMBER;
6194 l_msg_data                      VARCHAR2(2000);
6195 l_msg_index_out                 NUMBER;
6196 l_data                          VARCHAR2(2000);
6197 l_debug_mode                    VARCHAR2(1);
6198 
6199 i                               NUMBER;
6200 l_new_assignment_id_tbl         SYSTEM.PA_NUM_TBL_TYPE  := SYSTEM.PA_NUM_TBL_TYPE();
6201 l_new_assignment_id             NUMBER;
6202 l_assignment_number             NUMBER;
6203 l_assignment_row_id             ROWID;
6204 l_resource_id                   NUMBER;
6205 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
6206 l_error_flag                    VARCHAR2(1)             := 'N';
6207 l_error_flag_local              VARCHAR2(1)             := 'N';
6208 l_asgn_rec		        ASSIGNMENT_IN_REC_TYPE;
6209 l_asgn_creation_mode		VARCHAR2(10)	        := 'FULL';
6210 --l_assignment_type		VARCHAR2(30)	        := 'OPEN_ASSIGNMENT';
6211 l_multiple_status_flag		VARCHAR2(1)	        := 'N';
6212 l_loop_msg_count                NUMBER                  :=0;
6213 l_start_msg_count               NUMBER                  :=0;
6214 l_end_msg_count                 NUMBER                  :=0;
6215 l_missing_params                VARCHAR2(1000);
6216 l_privilege                     VARCHAR2(30);
6217 l_object_name                   VARCHAR2(30);
6218 l_object_key                    NUMBER;
6219 l_error_message_code            VARCHAR2(30);
6220 l_ret_code                      VARCHAR2(1);
6221 
6222 
6223 CURSOR c_get_valid_calendar_types(c_code VARCHAR2) IS
6224 SELECT lookup_code
6225 FROM pa_lookups
6226 WHERE lookup_type = 'CHANGE_CALENDAR_TYPE_CODE'
6227 AND lookup_code = c_code
6228 AND lookup_code <> 'RESOURCE';
6229 
6230 CURSOR c_get_project_dtls(c_project_id NUMBER) IS
6231 SELECT role_list_id, multi_currency_billing_flag, calendar_id, work_type_id, location_id
6232 FROM pa_projects_all
6233 WHERE project_id = c_project_id;
6234 
6235 CURSOR c_get_team_templ_dtls(c_team_templ_id NUMBER) IS
6236 SELECT role_list_id, calendar_id, work_type_id
6237 FROM pa_team_templates
6238 WHERE team_template_id = c_team_templ_id;
6239 
6240 CURSOR c_get_role_dtls(c_role_id NUMBER) IS
6241 SELECT meaning
6242 FROM   pa_project_role_types_vl
6243 WHERE  project_role_id = c_role_id ;
6244 
6245 CURSOR get_bill_rate_override_flags(c_project_id NUMBER) IS
6246 SELECT impl.rate_discount_reason_flag ,impl.br_override_flag, impl.br_discount_override_flag
6247 FROM pa_implementations_all impl
6248     , pa_projects_all proj
6249 WHERE proj.org_id=impl.org_id   -- Removed nvl condition from org_id : Post review changes for Bug 5130421
6250 AND proj.project_id = c_project_id ;
6251 
6252 CURSOR c_get_lookup_exists(c_lookup_type VARCHAR2, c_lookup_code VARCHAR2) IS
6253 SELECT 'Y'
6254 FROM dual
6255 WHERE EXISTS
6256 (SELECT 'XYZ' FROM pa_lookups WHERE lookup_type = c_lookup_type AND lookup_code = c_lookup_code);
6257 
6258 CURSOR c_get_location(c_location_id NUMBER) IS
6259 SELECT country_code, region, city
6260 FROM pa_locations
6261 WHERE location_id = c_location_id;
6262 
6263 CURSOR c_derive_country_code(c_country_name IN VARCHAR2) IS
6264 SELECT country_code
6265 FROM pa_country_v
6266 WHERE name = c_country_name;
6267 
6268 CURSOR c_derive_country_name(c_country_code IN VARCHAR2) IS
6269 SELECT name
6270 FROM pa_country_v
6271 WHERE  country_code  = c_country_code;
6272 
6273 
6274 -- This cursor is for future extension when we support creation of team role from planning resource
6275 CURSOR c_get_planning_res_info(c_resource_list_member_id NUMBER, c_budget_version_id NUMBER, c_project_id NUMBER) IS
6276 SELECT
6277   ra.resource_list_member_id
6278 , firstrow.person_id
6279 , rlm.resource_id
6280 , PA_RESOURCE_UTILS.get_person_name_no_date(firstrow.person_id)
6281 , ra.project_id
6282 , ra.budget_version_id
6283 , decode (ra.role_count, 1, firstrow.named_role, null) named_role
6284 , decode (ra.role_count, 1, firstrow.project_role_id, null) project_role_id
6285 , decode (ra.role_count, 1, ro.meaning, null) project_role
6286 , ra.min_date task_assign_start_date
6287 , ra.max_date task_assign_end_date
6288 , firstrow.resource_assignment_id
6289 , firstrow.res_type_code
6290 FROM pa_resource_assignments firstrow
6291 , pa_resource_list_members rlm
6292 , pa_proj_roles_v ro
6293 , (SELECT project_id , budget_version_id , resource_list_member_id , count(1) role_count , max(max_id) max_id
6294      , min(min_date) min_date , max(max_date) max_date
6295    FROM (SELECT project_id , budget_version_id , resource_list_member_id , project_role_id
6296            , max(resource_assignment_id) max_id , min(SCHEDULE_START_DATE) min_date , max(SCHEDULE_END_DATE) max_date
6297          FROM pa_resource_assignments
6298          WHERE ta_display_flag = 'Y' and nvl(PROJECT_ASSIGNMENT_ID, -1) = -1
6299          AND resource_class_code = 'PEOPLE'
6300          GROUP BY project_id, budget_version_id, resource_list_member_id, project_role_id
6301          ) res_roles
6302     GROUP BY project_id, budget_version_id, resource_list_member_id
6303    ) ra
6304 WHERE ra.resource_list_member_id = rlm.resource_list_member_id
6305 AND firstrow.resource_assignment_id = ra.max_id
6306 AND firstrow.project_role_id = ro.project_role_id (+)
6307 AND ra.budget_version_id = c_budget_version_id
6308 AND ra.resource_list_member_id = c_resource_list_member_id
6309 AND ra.project_id = c_project_id
6310 AND firstrow.person_id IS NULL;
6311 -- If the value from this cusror is returned, then passed resource list member id is valid
6312 -- Pass this resource list member id, budget version id to internal API
6313 -- Pass calendar type as PROJECT and calendar_id as of project
6314 -- Pass sum_tasks_flag as N
6315 
6316 -- In case of assignments, user can choose calendar type between PROJECT or RESOURCE
6317 -- Pass this resource list member id, budget version id to internal API
6318 -- Pass sum_tasks_flag as Y if calendar is RESOURCE
6319 -- pass person_id, resource_id
6320 
6321 -- Bug 5175060
6322 CURSOR c_get_system_status_code(c_status_code VARCHAR2, c_status_type VARCHAR2) IS
6323 SELECT project_system_status_code,starting_status_flag
6324 FROM pa_project_statuses
6325 WHERE status_type = c_status_type
6326 AND project_status_code = c_status_code;
6327 
6328 CURSOR c_get_sys_code_from_name(c_status_name VARCHAR2, c_status_type VARCHAR2) IS
6329 SELECT project_system_status_code,starting_status_flag
6330 FROM pa_project_statuses
6331 WHERE status_type = c_status_type
6332 AND project_status_name = c_status_name;
6333 
6334 l_dummy_sys_code 		pa_project_statuses.project_system_status_code%TYPE;
6335 --End 5175060
6336 
6337 l_starting_status_flag		VARCHAR2(1);
6338 
6339 l_role_list_id                  NUMBER;
6340 l_multi_currency_billing_flag   VARCHAR2(1);
6341 l_calendar_id                   NUMBER;
6342 l_work_type_id                  NUMBER;
6343 l_location_id                   NUMBER;
6344 l_role_name                     VARCHAR2(80);
6345 l_valid_flag                    VARCHAR2(1);
6346 l_rate_discount_reason_flag     VARCHAR2(1);
6347 l_br_override_flag              VARCHAR2(1);
6348 l_br_discount_override_flag     VARCHAR2(1);
6349 l_project_id_tmp                NUMBER;
6350 l_project_role_id_tmp		NUMBER;
6351 l_tp_currency_override_tmp      VARCHAR2(30);
6352 l_my_person_id                  NUMBER;
6353 l_my_resource_id                NUMBER;
6354 l_my_resource_name              VARCHAR2(240);
6355 l_valid_country                 VARCHAR2(1);
6356 l_dummy_country_code            VARCHAR2(2);
6357 l_dummy_state		        VARCHAR2(240);
6358 l_dummy_city		        VARCHAR2(80);
6359 l_out_location_id	        NUMBER;
6360 l_bill_currency_override_tmp    VARCHAR2(30); -- 5144288, 5144369
6361 
6362 BEGIN
6363 
6364         --Flows which are supported by this API
6365         ---------------------------------------
6366         --1. Create project assignments
6367         --        1.1 Setting basic information(staffing priority, staffing owner, subteams, location etc..)
6368         --        1.2 Setting schedule information(dates, status, calendar etc..)
6369         --        1.3 Setting forecast infomation(expenditure type etc..)
6370         --
6371         --Flows which are not supported by this API
6372         -------------------------------------------
6373         --1. Create team role for given planning resource
6374 
6375         --Mandatory parameters
6376         -----------------------
6377         --1. assignment_type should be specified.
6378         --2. Either project_role_id or project_role_name should be passed.
6379         --3. Either of project_id, project_name, project_number should be passed.
6380         --4. resource_id should be passed.
6381         --5. Both start_date and end_date should be passed.
6382         --6. Either status_code or status_name should be specified.
6383 
6384 
6385         x_return_status := FND_API.G_RET_STS_SUCCESS;
6386         x_assignment_id_tbl:= SYSTEM.pa_num_tbl_type();
6387 
6388         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
6389 
6390         IF l_debug_mode = 'Y' THEN
6391                 PA_DEBUG.set_curr_function(p_function => 'CREATE_ASSIGNMENTS', p_debug_mode => l_debug_mode);
6392         END IF;
6393 
6394         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
6395                 FND_MSG_PUB.initialize;
6396         END IF;
6397 
6398         IF p_commit = FND_API.G_TRUE THEN
6399                 savepoint CREATE_ASSIGNMENTS_SP;
6400         END IF;
6401 
6402         IF l_debug_mode = 'Y' THEN
6403                 pa_debug.write(l_module, 'Start of create_assignments', l_log_level);
6404         END IF;
6405 
6406         IF l_debug_mode = 'Y' THEN
6407                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
6408                 i := p_assignment_in_tbl.first;
6409                 WHILE i IS NOT NULL LOOP
6410                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').assignment_id'||p_assignment_in_tbl(i).assignment_id, l_log_level);
6411                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').assignment_name'||p_assignment_in_tbl(i).assignment_name, l_log_level);
6412                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').assignment_type'||p_assignment_in_tbl(i).assignment_type, l_log_level);
6413                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_role_id'||p_assignment_in_tbl(i).project_role_id, l_log_level);
6414                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_role_name'||p_assignment_in_tbl(i).project_role_name, l_log_level);
6415                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_id'||p_assignment_in_tbl(i).project_id, l_log_level);
6416                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_name'||p_assignment_in_tbl(i).project_name, l_log_level);
6417                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_number'||p_assignment_in_tbl(i).project_number, l_log_level);
6418                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').resource_id'||p_assignment_in_tbl(i).resource_id, l_log_level);
6419                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').staffing_owner_person_id'||p_assignment_in_tbl(i).staffing_owner_person_id, l_log_level);
6420                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').staffing_priority_code'||p_assignment_in_tbl(i).staffing_priority_code, l_log_level);
6421                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').staffing_priority_name'||p_assignment_in_tbl(i).staffing_priority_name, l_log_level);
6422                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_subteam_id'||p_assignment_in_tbl(i).project_subteam_id, l_log_level);
6423                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_subteam_name'||p_assignment_in_tbl(i).project_subteam_name, l_log_level);
6424                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_id'||p_assignment_in_tbl(i).location_id, l_log_level);
6425                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_country_code'||p_assignment_in_tbl(i).location_country_code, l_log_level);
6426                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_country_name'||p_assignment_in_tbl(i).location_country_name, l_log_level);
6427                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_region'||p_assignment_in_tbl(i).location_region, l_log_level);
6428                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_city'||p_assignment_in_tbl(i).location_city, l_log_level);
6429                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').description'||p_assignment_in_tbl(i).description, l_log_level);
6430                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').additional_information'||p_assignment_in_tbl(i).additional_information, l_log_level);
6431                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').start_date'||p_assignment_in_tbl(i).start_date, l_log_level);
6432                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').end_date'||p_assignment_in_tbl(i).end_date, l_log_level);
6433                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').status_code'||p_assignment_in_tbl(i).status_code, l_log_level);
6434                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').status_name'||p_assignment_in_tbl(i).status_name, l_log_level);
6435                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').calendar_type'||p_assignment_in_tbl(i).calendar_type, l_log_level);
6436                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').calendar_id'||p_assignment_in_tbl(i).calendar_id, l_log_level);
6437                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').calendar_name'||p_assignment_in_tbl(i).calendar_name, l_log_level);
6438                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').resource_calendar_percent'||p_assignment_in_tbl(i).resource_calendar_percent, l_log_level);
6439                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expenditure_type_class'||p_assignment_in_tbl(i).expenditure_type_class, l_log_level);
6440                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expenditure_type'||p_assignment_in_tbl(i).expenditure_type, l_log_level);
6441                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').work_type_id'||p_assignment_in_tbl(i).work_type_id, l_log_level);
6442                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').work_type_name'||p_assignment_in_tbl(i).work_type_name, l_log_level);
6443                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').bill_rate_option'||p_assignment_in_tbl(i).bill_rate_option, l_log_level);
6444                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').bill_rate_override'||p_assignment_in_tbl(i).bill_rate_override, l_log_level);
6445                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').bill_rate_curr_override'||p_assignment_in_tbl(i).bill_rate_curr_override, l_log_level);
6446                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').markup_percent_override'||p_assignment_in_tbl(i).markup_percent_override, l_log_level);
6447                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').discount_percentage'||p_assignment_in_tbl(i).discount_percentage, l_log_level);
6448                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').rate_disc_reason_code'||p_assignment_in_tbl(i).rate_disc_reason_code, l_log_level);
6449                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_rate_option'||p_assignment_in_tbl(i).tp_rate_option, l_log_level);
6450                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_rate_override'||p_assignment_in_tbl(i).tp_rate_override, l_log_level);
6451                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_currency_override'||p_assignment_in_tbl(i).tp_currency_override, l_log_level);
6452                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_calc_base_code_override'||p_assignment_in_tbl(i).tp_calc_base_code_override, l_log_level);
6453                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_percent_applied_override'||p_assignment_in_tbl(i).tp_percent_applied_override, l_log_level);
6454                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').extension_possible'||p_assignment_in_tbl(i).extension_possible, l_log_level);
6455                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expense_owner'||p_assignment_in_tbl(i).expense_owner, l_log_level);
6456                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expense_limit'||p_assignment_in_tbl(i).expense_limit, l_log_level);
6457                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').orig_system_code'||p_assignment_in_tbl(i).orig_system_code, l_log_level);
6458                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').orig_system_reference'||p_assignment_in_tbl(i).orig_system_reference, l_log_level);
6459                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').record_version_number'||p_assignment_in_tbl(i).record_version_number, l_log_level);
6460 			pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').auto_approve ' || p_assignment_in_tbl(i).auto_approve, l_log_level);
6461                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute_category'||p_assignment_in_tbl(i).attribute_category, l_log_level);
6462                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute1'||p_assignment_in_tbl(i).attribute1, l_log_level);
6463                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute2'||p_assignment_in_tbl(i).attribute2, l_log_level);
6464                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute3'||p_assignment_in_tbl(i).attribute3, l_log_level);
6465                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute4'||p_assignment_in_tbl(i).attribute4, l_log_level);
6466                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute5'||p_assignment_in_tbl(i).attribute5, l_log_level);
6467                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute6'||p_assignment_in_tbl(i).attribute6, l_log_level);
6468                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute7'||p_assignment_in_tbl(i).attribute7, l_log_level);
6469                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute8'||p_assignment_in_tbl(i).attribute8, l_log_level);
6470                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute9'||p_assignment_in_tbl(i).attribute9, l_log_level);
6471                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute10'||p_assignment_in_tbl(i).attribute10, l_log_level);
6472                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute11'||p_assignment_in_tbl(i).attribute11, l_log_level);
6473                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute12'||p_assignment_in_tbl(i).attribute12, l_log_level);
6474                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute13'||p_assignment_in_tbl(i).attribute13, l_log_level);
6475                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute14'||p_assignment_in_tbl(i).attribute14, l_log_level);
6476                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute15'||p_assignment_in_tbl(i).attribute15, l_log_level);
6477                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
6478                         i := p_assignment_in_tbl.next(i);
6479                 END LOOP;
6480         END IF;
6481 
6482         PA_STARTUP.INITIALIZE(
6483                   p_calling_application                 => l_calling_application
6484                 , p_calling_module                      => l_calling_module
6485                 , p_check_id_flag                       => l_check_id_flag
6486                 , p_check_role_security_flag            => l_check_role_security_flag
6487                 , p_check_resource_security_flag        => l_check_resource_security_flag
6488                 , p_debug_level                         => l_log_level
6489                 );
6490 
6491         IF l_debug_mode = 'Y' THEN
6492                 pa_debug.write(l_module, 'After call of pa_startup.initialize', l_log_level);
6493         END IF;
6494 
6495         -- Page does not check PRM licensing, but keeping this code so in future if required, can be used
6496         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
6497         --IF l_prm_license_flag <> 'Y' THEN
6498         --        null;
6499         --END IF;
6500 
6501         i := p_assignment_in_tbl.first;
6502 
6503         WHILE i IS NOT NULL LOOP
6504                 l_error_flag_local := 'N';
6505                 l_missing_params := null;
6506                 l_asgn_rec := null;
6507                 l_valid_country := 'Y';
6508        		PA_STAFFED_ASSIGNMENT_PVT.G_AUTO_APPROVE := NULL ;
6509 
6510                 l_start_msg_count := FND_MSG_PUB.count_msg;
6511 
6512                 l_asgn_rec := p_assignment_in_tbl(i);
6513 
6514                 -- Blank Out Parameters if not passed.
6515                 IF l_debug_mode = 'Y' THEN
6516                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
6517                         pa_debug.write(l_module, '-----------------------------', l_log_level);
6518                         pa_debug.write(l_module, 'NullOut parameters which are not required.', l_log_level);
6519                 END IF;
6520 
6521                   /*--Bug 6511907 PJR Date Validation Enhancement ----- Start--*/
6522                         /*-- Validating Resource Req Start and End Date against
6523                              Project Start and Completion dates --*/
6524 
6525                         Declare
6526                           l_validate           VARCHAR2(10);
6527                           l_start_date_status  VARCHAR2(10);
6528                           l_end_date_status    VARCHAR2(10);
6529                           l_start_date         DATE;
6530                           l_end_date           DATE;
6531                         Begin
6532                          If l_asgn_rec.start_date is not null or l_asgn_rec.end_date is not null then
6533                            l_start_date := l_asgn_rec.start_date;
6534                            l_end_date   := l_asgn_rec.end_date;
6535                            PA_PROJECT_DATES_UTILS.Validate_Resource_Dates
6536                                        (l_asgn_rec.project_id, l_start_date, l_end_date,
6537                                                    l_validate, l_start_date_status, l_end_date_status);
6538 
6539                            If l_validate = 'Y' and l_start_date_status = 'I' Then
6540 
6541                               pa_utils.add_message
6542                                ( p_app_short_name  => 'PA'
6543                                 ,p_msg_name	       => 'PA_PJR_DATE_START_ERROR'
6544                                 ,p_token1          => 'PROJ_TXN_START_DATE'
6545                                 ,p_value1          => GET_PROJECT_START_DATE(l_asgn_rec.project_id)
6546                                 ,p_token2          => ''
6547                                 ,p_value2          => ''
6548                                 ,p_token3          => ''
6549                                 ,p_value3          => ''
6550                                );
6551 
6552                               RAISE  FND_API.G_EXC_ERROR;
6553                            End If;
6554 
6555                            If l_validate = 'Y' and l_end_date_status = 'I' Then
6556 
6557                               pa_utils.add_message
6558                                ( p_app_short_name  => 'PA'
6559                                 ,p_msg_name	    => 'PA_PJR_DATE_FINISH_ERROR'
6560                                 ,p_token1          => 'PROJ_TXN_END_DATE'
6561                                 ,p_value1          => GET_PROJECT_COMPLETION_DATE(l_asgn_rec.project_id)
6562                                 ,p_token2          => ''
6563                                 ,p_value2          => ''
6564                                 ,p_token3          => ''
6565                                 ,p_value3          => ''
6566                                );
6567 
6568                               RAISE  FND_API.G_EXC_ERROR;
6569                            End If;
6570                          End If;
6571                         End;
6572 
6573                         /*--Bug 6511907 PJR Date Validation Enhancement ----- End--*/
6574                 IF l_asgn_rec.assignment_id = G_PA_MISS_NUM THEN
6575                         l_asgn_rec.assignment_id := null;
6576                 END IF;
6577 
6578                 IF l_asgn_rec.assignment_name = G_PA_MISS_CHAR THEN
6579                         l_asgn_rec.assignment_name := null;
6580                 END IF;
6581 
6582                 IF l_asgn_rec.assignment_type = G_PA_MISS_CHAR THEN
6583                         l_asgn_rec.assignment_type := null;
6584                 END IF;
6585 
6586 
6587                 IF l_asgn_rec.project_role_id = G_PA_MISS_NUM THEN
6588                         l_asgn_rec.project_role_id := null;
6589                 END IF;
6590 
6591                 IF l_asgn_rec.project_role_name = G_PA_MISS_CHAR THEN
6592                         l_asgn_rec.project_role_name := null;
6593                 END IF;
6594 
6595                 IF l_asgn_rec.project_id = G_PA_MISS_NUM THEN
6596                         l_asgn_rec.project_id := null;
6597                 END IF;
6598 
6599                 IF l_asgn_rec.project_name = G_PA_MISS_CHAR THEN
6600                         l_asgn_rec.project_name := null;
6601                 END IF;
6602 
6603                 IF l_asgn_rec.project_number = G_PA_MISS_CHAR THEN
6604                         l_asgn_rec.project_number := null;
6605                 END IF;
6606 
6607                 IF l_asgn_rec.resource_id = G_PA_MISS_NUM THEN
6608                         l_asgn_rec.resource_id := null;
6609                 END IF;
6610 
6611 
6612                 -- Some fields like Staffing Owner will be defaulted further in internal APIs
6613                 -- But user may like to pass them explicitely as null
6614                 -- So in that case we need to distinguish MISS NUM with null
6615                 -- But there is a problem that pa_inerface_utils_pub.g_pa_miss_num
6616                 -- is diffrent than fnd_api.g_miss_num. PJR internal code uses
6617                 -- fnd_api.g_miss_num, so it throws the error.
6618                 -- For this reason, we need to convert the G_PA_MISS_NUM/CHAR to FND_API.G_MISS_NUM/CHAR
6619                 -- before sending it to internal APIs
6620 
6621                 IF l_asgn_rec.staffing_owner_person_id = G_PA_MISS_NUM THEN
6622                         -- We can not make null here
6623                         -- Because underlying API treat null as override and does not
6624                         -- default value.
6625                         l_asgn_rec.staffing_owner_person_id := FND_API.G_MISS_NUM;
6626                 END IF;
6627 
6628                 IF l_asgn_rec.staffing_priority_code = G_PA_MISS_CHAR THEN
6629                         l_asgn_rec.staffing_priority_code := null;
6630                 END IF;
6631 
6632                 IF l_asgn_rec.staffing_priority_name = G_PA_MISS_CHAR THEN
6633                         l_asgn_rec.staffing_priority_name := null;
6634                 END IF;
6635 
6636                 IF l_asgn_rec.project_subteam_id = G_PA_MISS_NUM THEN
6637                         l_asgn_rec.project_subteam_id := null;
6638                 END IF;
6639 
6640                 IF l_asgn_rec.project_subteam_name = G_PA_MISS_CHAR THEN
6641                         l_asgn_rec.project_subteam_name := null;
6642                 END IF;
6643 
6644                 -- Location will be default to project location for project requirments
6645                 -- But user may like to pass them explicitely as null
6646                 -- So in that case we need to distinguish MISS CHAR with null
6647                 IF l_asgn_rec.location_id = G_PA_MISS_NUM THEN
6648                         l_asgn_rec.location_id := FND_API.G_MISS_NUM;
6649                 END IF;
6650 
6651                 IF l_asgn_rec.location_country_code = G_PA_MISS_CHAR THEN
6652                         l_asgn_rec.location_country_code := FND_API.G_MISS_CHAR;
6653                 END IF;
6654 
6655                 IF l_asgn_rec.location_country_name = G_PA_MISS_CHAR THEN
6656                         l_asgn_rec.location_country_name := FND_API.G_MISS_CHAR;
6657                 END IF;
6658 
6659                 IF l_asgn_rec.location_region = G_PA_MISS_CHAR THEN
6660                         l_asgn_rec.location_region := FND_API.G_MISS_CHAR;
6661                 END IF;
6662 
6663                 IF l_asgn_rec.location_city = G_PA_MISS_CHAR THEN
6664                         l_asgn_rec.location_city := FND_API.G_MISS_CHAR;
6665                 END IF;
6666 
6667 
6668                 IF l_asgn_rec.description = G_PA_MISS_CHAR THEN
6669                         l_asgn_rec.description := null;
6670                 END IF;
6671 
6672                 IF l_asgn_rec.additional_information = G_PA_MISS_CHAR THEN
6673                         l_asgn_rec.additional_information := null;
6674                 END IF;
6675 
6676                 IF l_asgn_rec.start_date = G_PA_MISS_DATE THEN
6677                         l_asgn_rec.start_date := null;
6678                 END IF;
6679 
6680                 IF l_asgn_rec.end_date = G_PA_MISS_DATE THEN
6681                         l_asgn_rec.end_date := null;
6682                 END IF;
6683 
6684                 IF l_asgn_rec.status_code = G_PA_MISS_CHAR THEN
6685                         l_asgn_rec.status_code := null;
6686                 END IF;
6687 
6688                 IF l_asgn_rec.status_name = G_PA_MISS_CHAR THEN
6689                         l_asgn_rec.status_name := null;
6690                 END IF;
6691 
6692                 IF l_asgn_rec.calendar_type = G_PA_MISS_CHAR THEN
6693                         l_asgn_rec.calendar_type := 'PROJECT';
6694                 END IF;
6695 
6696                 IF l_asgn_rec.calendar_id = G_PA_MISS_NUM THEN
6697                         l_asgn_rec.calendar_id := null;
6698                 END IF;
6699 
6700                 IF l_asgn_rec.calendar_name = G_PA_MISS_CHAR THEN
6701                         l_asgn_rec.calendar_name := null;
6702                 END IF;
6703                 -- 5171889 : Changed = to <>
6704                 --IF l_asgn_rec.resource_calendar_percent = G_PA_MISS_NUM OR l_asgn_rec.calendar_type = 'RESOURCE' THEN
6705                 IF l_asgn_rec.resource_calendar_percent = G_PA_MISS_NUM OR l_asgn_rec.calendar_type <> 'RESOURCE' THEN
6706                         l_asgn_rec.resource_calendar_percent := null;
6707                 END IF;
6708 
6709                 IF l_asgn_rec.expenditure_type_class = G_PA_MISS_CHAR THEN
6710                         l_asgn_rec.expenditure_type_class := null;
6711                 END IF;
6712 
6713                 IF l_asgn_rec.expenditure_type = G_PA_MISS_CHAR THEN
6714                         l_asgn_rec.expenditure_type := null;
6715                 END IF;
6716 
6717                 IF l_asgn_rec.work_type_id = G_PA_MISS_NUM THEN
6718                         l_asgn_rec.work_type_id := null;
6719                 END IF;
6720 
6721                 IF l_asgn_rec.work_type_name = G_PA_MISS_CHAR THEN
6722                         l_asgn_rec.work_type_name := null;
6723                 END IF;
6724 
6725                 IF l_asgn_rec.bill_rate_option = G_PA_MISS_CHAR THEN
6726                         l_asgn_rec.bill_rate_option := 'NONE';
6727                 END IF;
6728 
6729                 IF l_asgn_rec.bill_rate_override = G_PA_MISS_NUM THEN
6730                         l_asgn_rec.bill_rate_override := null;
6731                 END IF;
6732 
6733                 IF l_asgn_rec.bill_rate_curr_override = G_PA_MISS_CHAR THEN
6734                         l_asgn_rec.bill_rate_curr_override := null;
6735                 END IF;
6736 
6737                 IF l_asgn_rec.markup_percent_override = G_PA_MISS_NUM THEN
6738                         l_asgn_rec.markup_percent_override := null;
6739                 END IF;
6740 
6741                 IF l_asgn_rec.discount_percentage = G_PA_MISS_NUM THEN
6742                         l_asgn_rec.discount_percentage := null;
6743                 END IF;
6744 
6745                 IF l_asgn_rec.rate_disc_reason_code = G_PA_MISS_CHAR THEN
6746                         l_asgn_rec.rate_disc_reason_code := null;
6747                 END IF;
6748 
6749                 IF l_asgn_rec.tp_rate_option = G_PA_MISS_CHAR THEN
6750                         l_asgn_rec.tp_rate_option := 'NONE';
6751                 END IF;
6752 
6753                 IF l_asgn_rec.tp_rate_override = G_PA_MISS_NUM THEN
6754                         l_asgn_rec.tp_rate_override := null;
6755                 END IF;
6756 
6757                 IF l_asgn_rec.tp_currency_override = G_PA_MISS_CHAR THEN
6758                         l_asgn_rec.tp_currency_override := null;
6759                 END IF;
6760 
6761                 IF l_asgn_rec.tp_calc_base_code_override = G_PA_MISS_CHAR THEN
6762                         l_asgn_rec.tp_calc_base_code_override := null;
6763                 END IF;
6764 
6765                 IF l_asgn_rec.tp_percent_applied_override = G_PA_MISS_NUM THEN
6766                         l_asgn_rec.tp_percent_applied_override := null;
6767                 END IF;
6768 
6769                 IF l_asgn_rec.extension_possible = G_PA_MISS_CHAR THEN
6770                         l_asgn_rec.extension_possible := null;
6771                 END IF;
6772 
6773                 IF l_asgn_rec.expense_owner = G_PA_MISS_CHAR THEN
6774                         l_asgn_rec.expense_owner := null;
6775                 END IF;
6776 
6777                 IF l_asgn_rec.expense_limit = G_PA_MISS_NUM THEN
6778                         l_asgn_rec.expense_limit := null;
6779                 END IF;
6780 
6781                 IF l_asgn_rec.orig_system_code = G_PA_MISS_CHAR THEN
6782                         l_asgn_rec.orig_system_code := null;
6783                 END IF;
6784 
6785                 IF l_asgn_rec.orig_system_reference = G_PA_MISS_CHAR THEN
6786                         l_asgn_rec.orig_system_reference := null;
6787                 END IF;
6788 
6789                 IF l_asgn_rec.record_version_number = G_PA_MISS_NUM THEN
6790                         l_asgn_rec.record_version_number := 1;
6791                 END IF;
6792 
6793 		IF l_asgn_rec.auto_approve = G_PA_MISS_CHAR THEN
6794                         l_asgn_rec.auto_approve := 'N'; -- If this param is not passed ,take as 'N'
6795 		END IF;
6796 
6797 		IF l_asgn_rec.auto_approve = 'Y' THEN
6798 			-- If Auto Approve is True,then pass the status as Confirmed
6799 			-- This is needed for the security check for resource authority
6800 			-- to be done in PA_STAFFED_ASSIGNMENT_PVT.Create_Staffed_Assignment API (internal)
6801 			-- One more reason is : Only Confirmed Assignments can be approved.
6802 
6803 			l_asgn_rec.status_code := '105';
6804 			l_asgn_rec.status_name := 'Confirmed';
6805 		END IF;
6806 
6807 		-- Set Global Variable for Auto Approve
6808 		PA_STAFFED_ASSIGNMENT_PVT.G_AUTO_APPROVE := l_asgn_rec.auto_approve ;
6809 
6810                 IF l_asgn_rec.attribute_category = G_PA_MISS_CHAR THEN
6811                         l_asgn_rec.attribute_category := null;
6812                 END IF;
6813 
6814                 IF l_asgn_rec.attribute1 = G_PA_MISS_CHAR THEN
6815                         l_asgn_rec.attribute1 := null;
6816                 END IF;
6817 
6818                 IF l_asgn_rec.attribute2 = G_PA_MISS_CHAR THEN
6819                         l_asgn_rec.attribute2 := null;
6820                 END IF;
6821 
6822                 IF l_asgn_rec.attribute3 = G_PA_MISS_CHAR THEN
6823                         l_asgn_rec.attribute3 := null;
6824                 END IF;
6825 
6826                 IF l_asgn_rec.attribute4 = G_PA_MISS_CHAR THEN
6827                         l_asgn_rec.attribute4 := null;
6828                 END IF;
6829 
6830                 IF l_asgn_rec.attribute5 = G_PA_MISS_CHAR THEN
6831                         l_asgn_rec.attribute5 := null;
6832                 END IF;
6833 
6834                 IF l_asgn_rec.attribute6 = G_PA_MISS_CHAR THEN
6835                         l_asgn_rec.attribute6 := null;
6836                 END IF;
6837 
6838                 IF l_asgn_rec.attribute7 = G_PA_MISS_CHAR THEN
6839                         l_asgn_rec.attribute7 := null;
6840                 END IF;
6841 
6842                 IF l_asgn_rec.attribute8 = G_PA_MISS_CHAR THEN
6843                         l_asgn_rec.attribute8 := null;
6844                 END IF;
6845 
6846                 IF l_asgn_rec.attribute9 = G_PA_MISS_CHAR THEN
6847                         l_asgn_rec.attribute9 := null;
6848                 END IF;
6849 
6850                 IF l_asgn_rec.attribute10 = G_PA_MISS_CHAR THEN
6851                         l_asgn_rec.attribute10 := null;
6852                 END IF;
6853 
6854                 IF l_asgn_rec.attribute11 = G_PA_MISS_CHAR THEN
6855                         l_asgn_rec.attribute11 := null;
6856                 END IF;
6857 
6858                 IF l_asgn_rec.attribute12 = G_PA_MISS_CHAR THEN
6859                         l_asgn_rec.attribute12 := null;
6860                 END IF;
6861 
6862                 IF l_asgn_rec.attribute13 = G_PA_MISS_CHAR THEN
6863                         l_asgn_rec.attribute13 := null;
6864                 END IF;
6865 
6866                 IF l_asgn_rec.attribute14 = G_PA_MISS_CHAR THEN
6867                         l_asgn_rec.attribute14 := null;
6868                 END IF;
6869 
6870                 IF l_asgn_rec.attribute15 = G_PA_MISS_CHAR THEN
6871                         l_asgn_rec.attribute15 := null;
6872                 END IF;
6873 
6874 
6875                 -- Mandatory Parameters Check
6876                 -----------------------------
6877 
6878                 IF l_debug_mode = 'Y' THEN
6879                         pa_debug.write(l_module, 'Mandatory parameter validation starts', l_log_level);
6880                 END IF;
6881 
6882                 IF l_asgn_rec.assignment_type IS NULL OR l_asgn_rec.assignment_type NOT IN ('STAFFED_ASSIGNMENT','STAFFED_ADMIN_ASSIGNMENT') THEN
6883                         l_missing_params := l_missing_params||', ASSIGNMENT_TYPE';
6884                 END IF;
6885 
6886                 IF l_asgn_rec.project_role_id IS NULL AND l_asgn_rec.project_role_name IS NULL THEN
6887                         l_missing_params := l_missing_params||', PROJECT_ROLE_ID, PROJECT_ROLE_NAME';
6888                 END IF;
6889 
6890                 IF l_asgn_rec.project_id IS NULL AND l_asgn_rec.project_name IS NULL AND l_asgn_rec.project_number IS NULL
6891                 THEN
6892                         l_missing_params := l_missing_params||', PROJECT_ID, PROJECT_NAME, PROJECT_NUMBER';
6893                 END IF;
6894 
6895                 IF l_asgn_rec.resource_id IS NULL THEN
6896                         l_missing_params := l_missing_params||', RESOURCE_ID';
6897                 END IF;
6898 
6899 
6900                 IF l_asgn_rec.start_date IS NULL OR l_asgn_rec.end_date IS NULL THEN
6901                         l_missing_params := l_missing_params||', START_DATE, END_DATE';
6902                 END IF;
6903 
6904                 -- Assignment status is not mandatory, if not passed we default it to 104 (Provisonal)
6905                 --IF l_asgn_rec.status_code IS NULL AND l_asgn_rec.status_name IS NULL THEN
6906                 --        l_missing_params := l_missing_params||', STATUS_CODE, STATUS_NAME';
6907                 --END IF;
6908                 IF l_asgn_rec.status_code IS NULL AND l_asgn_rec.status_name IS NULL  THEN
6909                        l_asgn_rec.status_code := 104;
6910                 END IF;
6911 
6912 		-- Bug 5175060 If Auto Approval is not there and Yet, Some other status other than
6913 		-- Provisional is passed by user , Throw error.
6914 
6915 		-- If Status code is passed,it always takes precedence over name
6916 
6917 		IF l_asgn_rec.auto_approve = 'N' THEN
6918 
6919 		IF l_asgn_rec.status_code IS NOT NULL THEN
6920 			OPEN c_get_system_status_code(l_asgn_rec.status_code,'STAFFED_ASGMT');
6921 			FETCH c_get_system_status_code INTO l_dummy_sys_code,l_starting_status_flag; -- 5210813
6922 			IF c_get_system_status_code%NOTFOUND THEN -- Not existent value passed
6923 				l_missing_params := l_missing_params||', STATUS_CODE';
6924 			ELSE
6925 				-- If it is confirmed or its not a starting status throw error - 5210813
6926 				IF l_dummy_sys_code = 'STAFFED_ASGMT_CONF' OR l_starting_status_flag ='N'  THEN
6927 					l_missing_params := l_missing_params||', STATUS_CODE';
6928 				END IF;
6929 			END IF;
6930 			CLOSE c_get_system_status_code;
6931 		ELSIF l_asgn_rec.status_name IS NOT NULL THEN
6932 			OPEN c_get_sys_code_from_name(l_asgn_rec.status_name,'STAFFED_ASGMT');
6933 			FETCH c_get_sys_code_from_name INTO l_dummy_sys_code,l_starting_status_flag; -- 5210813
6934                         IF c_get_sys_code_from_name%NOTFOUND THEN -- Not existent value passed
6935                                 l_missing_params := l_missing_params||', STATUS_NAME';
6936 			ELSE
6937                                 -- If it s confirmed or its not a starting status throw error
6938                                 IF l_dummy_sys_code = 'STAFFED_ASGMT_CONF' OR l_starting_status_flag ='N' THEN
6939                                         l_missing_params := l_missing_params||', STATUS_NAME';
6940                                 END IF;
6941                         END IF;
6942 			CLOSE c_get_sys_code_from_name;	-- Correct spelling mistake in cursor name 5200325
6943 		END IF;
6944 
6945 		END IF;
6946 		-- End 5175060
6947                 IF l_asgn_rec.location_id IS NULL OR l_asgn_rec.location_id = FND_API.G_MISS_NUM THEN
6948                         -- If either city or state (or) both are passed ,then country is
6949                         -- mandatory
6950                         IF (l_asgn_rec.location_country_code IS NULL AND l_asgn_rec.location_country_name IS NULL)
6951                            OR (l_asgn_rec.location_country_code =  FND_API.G_MISS_CHAR AND l_asgn_rec.location_country_name = FND_API.G_MISS_CHAR)
6952                         THEN
6953                                 IF (l_asgn_rec.location_region <> FND_API.G_MISS_CHAR AND l_asgn_rec.location_region IS NOT NULL)
6954                                     OR (l_asgn_rec.location_city <> FND_API.G_MISS_CHAR AND l_asgn_rec.location_city IS NOT NULL)
6955                                 THEN
6956                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE, LOCATION_COUNTRY_NAME';
6957                                         l_valid_country := 'N';
6958                                 END IF;
6959                         ELSIF l_asgn_rec.location_country_code IS NOT NULL AND l_asgn_rec.location_country_code <> FND_API.G_MISS_CHAR
6960                         THEN
6961                                 OPEN c_derive_country_name(l_asgn_rec.location_country_code);
6962                                 FETCH c_derive_country_name INTO l_asgn_rec.location_country_name;
6963                                 IF c_derive_country_name%NOTFOUND THEN
6964                                         -- Invalid Country code passed.
6965                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE';
6966                                         l_valid_country := 'N';
6967                                 ELSE
6968                                         l_valid_country := 'Y';
6969                                 END IF;
6970                                 CLOSE c_derive_country_name;
6971                         ELSIF l_asgn_rec.location_country_name IS NOT NULL AND l_asgn_rec.location_country_name <> FND_API.G_MISS_CHAR
6972                         THEN
6973                               OPEN c_derive_country_code(l_asgn_rec.location_country_name);
6974                               FETCH c_derive_country_code INTO l_asgn_rec.location_country_code;
6975                               IF c_derive_country_code%NOTFOUND THEN
6976                                         -- Invalid Country Name passed.
6977                                         l_missing_params := l_missing_params||', LOCATION_COUNTRY_NAME';
6978                                         l_valid_country := 'N';
6979                                ELSE
6980                                         l_valid_country := 'Y';
6981                               END IF;
6982                               CLOSE c_derive_country_code;
6983                         END IF;
6984 
6985                         -- If the country is valid,then proceed with the state and city validations
6986                         IF l_valid_country = 'Y' AND l_asgn_rec.location_country_code IS NOT NULL
6987                         AND l_asgn_rec.location_country_code <> FND_API.G_MISS_CHAR
6988                         THEN
6989 
6990                                 l_dummy_country_code := l_asgn_rec.location_country_code;
6991                                 IF l_asgn_rec.location_region IS NULL OR l_asgn_rec.location_region = FND_API.G_MISS_CHAR THEN
6992                                         l_dummy_state := null;
6993                                 ELSE
6994                                         l_dummy_state := l_asgn_rec.location_region;
6995                                 END IF;
6996 
6997                                 IF l_asgn_rec.location_city IS NULL OR l_asgn_rec.location_city = FND_API.G_MISS_CHAR THEN
6998                                         l_dummy_city := null;
6999                                 ELSE
7000                                         l_dummy_city := l_asgn_rec.location_city;
7001                                 END IF;
7002 
7003                                 PA_LOCATION_UTILS.CHECK_LOCATION_EXISTS
7004                                 (
7005                                          p_country_code         => l_dummy_country_code
7006                                         ,p_city		        => l_dummy_city
7007                                         ,p_region	        => l_dummy_state
7008                                         ,x_location_id	        => l_out_location_id
7009                                         ,x_return_status        => l_return_status
7010                                 );
7011 
7012                                 IF l_out_location_id IS NULL THEN
7013                                         PA_UTILS.ADD_MESSAGE('PA','PA_AMG_RES_INV_CRC_COMB');
7014                                         l_error_flag_local := 'Y'; -- 5148975
7015                                 ELSE
7016                                         l_asgn_rec.location_id := l_out_location_id;
7017                                 END IF;
7018                         END IF;
7019                 ELSE
7020                         -- if location id is passed, then it will override the city, region, country code
7021                         OPEN c_get_location(l_asgn_rec.location_id);
7022                         FETCH c_get_location INTO l_asgn_rec.location_country_code, l_asgn_rec.location_region, l_asgn_rec.location_city;
7023 
7024                         IF c_get_location%NOTFOUND THEN
7025                                 l_missing_params := l_missing_params||', LOCATION_ID';
7026                         END IF;
7027                         CLOSE c_get_location;
7028                 END IF; -- l_asgn_rec.location_id IS NULL OR l_asgn_rec.location_id = FND_API.G_MISS_NUM
7029 
7030 
7031                 IF l_asgn_rec.calendar_type IS NULL OR (l_asgn_rec.calendar_type NOT IN('PROJECT','OTHER', 'RESOURCE')) THEN
7032                         l_missing_params := l_missing_params||', CALENDAR_TYPE';
7033                 ELSE
7034                         IF l_asgn_rec.calendar_type = 'OTHER' AND l_asgn_rec.calendar_id IS NULL
7035                                 AND l_asgn_rec.calendar_name IS NULL
7036                         THEN
7037                                 l_missing_params := l_missing_params||', CALENDAR_ID, CALENDAR_NAME';
7038                         END IF;
7039                         IF l_asgn_rec.calendar_type = 'RESOURCE' AND l_asgn_rec.resource_calendar_percent IS NULL
7040                         THEN
7041                                 l_missing_params := l_missing_params||', RESOURCE_CALENDAR_PERCENT';
7042                         END IF;
7043                 END IF;
7044 
7045                 IF l_asgn_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
7046                         IF l_asgn_rec.bill_rate_option IS NULL OR l_asgn_rec.bill_rate_option NOT IN('RATE','MARKUP','DISCOUNT','NONE') THEN
7047                                 l_missing_params := l_missing_params||', BILL_RATE_OPTION';
7048                         ELSE
7049                                 IF l_asgn_rec.bill_rate_option = 'NONE' THEN
7050                                         l_asgn_rec.bill_rate_override := null;
7051                                         l_asgn_rec.bill_rate_curr_override := null;
7052                                         l_asgn_rec.markup_percent_override := null;
7053                                         l_asgn_rec.discount_percentage := null;
7054                                         l_asgn_rec.rate_disc_reason_code := null;
7055                                 ELSIF l_asgn_rec.bill_rate_option = 'RATE' THEN
7056                                         l_asgn_rec.markup_percent_override := null;
7057                                         l_asgn_rec.discount_percentage := null;
7058                                         IF l_asgn_rec.bill_rate_override IS NULL THEN
7059                                                 l_missing_params := l_missing_params||', BILL_RATE_OVERRIDE';
7060                                         END IF;
7061                                 ELSIF l_asgn_rec.bill_rate_option = 'MARKUP' THEN
7062                                         l_asgn_rec.bill_rate_override := null;
7063                                         l_asgn_rec.bill_rate_curr_override := null;
7064                                         l_asgn_rec.discount_percentage := null;
7065                                         IF l_asgn_rec.markup_percent_override IS NULL THEN
7066                                                 l_missing_params := l_missing_params||', MARKUP_PERCENT_OVERRIDE';
7067                                         END IF;
7068                                 ELSIF l_asgn_rec.bill_rate_option = 'DISCOUNT' THEN
7069                                         l_asgn_rec.bill_rate_override := null;
7070                                         l_asgn_rec.bill_rate_curr_override := null;
7071                                         l_asgn_rec.markup_percent_override := null;
7072                                         IF l_asgn_rec.discount_percentage IS NULL THEN
7073                                                 l_missing_params := l_missing_params||', DISCOUNT_PERCENTAGE';
7074                                         END IF;
7075                                 END IF;
7076                         END IF;
7077 
7078 
7079                         IF l_asgn_rec.tp_rate_option IS NULL OR l_asgn_rec.tp_rate_option NOT IN('RATE','BASIS','NONE') THEN
7080                                 l_missing_params := l_missing_params||', TP_RATE_OPTION';
7081                         ELSE
7082                                 IF l_asgn_rec.tp_rate_option = 'NONE' THEN
7083                                         l_asgn_rec.tp_rate_override := null;
7084                                         l_asgn_rec.tp_currency_override := null;
7085                                         l_asgn_rec.tp_calc_base_code_override := null;
7086                                         l_asgn_rec.tp_percent_applied_override := null;
7087                                 ELSIF l_asgn_rec.tp_rate_option = 'RATE' THEN
7088                                         l_asgn_rec.tp_calc_base_code_override := null;
7089                                         l_asgn_rec.tp_percent_applied_override := null;
7090                                         IF l_asgn_rec.tp_rate_override IS NULL OR l_asgn_rec.tp_currency_override IS NULL THEN
7091                                                 l_missing_params := l_missing_params||', TP_RATE_OVERRIDE, TP_CURRENCY_OVERRIDE';
7092                                         END IF;
7093                                 ELSIF l_asgn_rec.tp_rate_option = 'BASIS' THEN
7094                                         l_asgn_rec.tp_rate_override := null;
7095                                         l_asgn_rec.tp_currency_override := null;
7096                                         IF l_asgn_rec.tp_calc_base_code_override IS NULL OR l_asgn_rec.tp_percent_applied_override IS NULL THEN
7097                                                 l_missing_params := l_missing_params||', TP_CALC_BASE_CODE_OVERRIDE, TP_PERCENT_APPLIED_OVERRIDE';
7098                                         END IF;
7099                                 END IF;
7100                         END IF;
7101 
7102                         IF l_asgn_rec.extension_possible IS NOT NULL AND l_asgn_rec.extension_possible NOT IN ('Y','N') THEN
7103                                 l_missing_params := l_missing_params||', EXTENSION_POSSIBLE';
7104                         END IF;
7105                 END IF; -- l_asgn_rec.assignment_type = 'STAFFED_ASSIGNMENT'
7106 
7107 		IF l_asgn_rec.auto_approve NOT IN ('Y','N') THEN
7108 			l_missing_params := l_missing_params||', AUTO_APPROVE' ;
7109 		END IF;
7110 
7111                 IF l_debug_mode = 'Y' THEN
7112                         pa_debug.write(l_module, 'Mandatory parameter validation over. List of Missing Parameters='||l_missing_params, l_log_level);
7113                 END IF;
7114 
7115                 IF l_missing_params IS NOT NULL THEN
7116                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
7117                                                 'INVALID_PARAMS', l_missing_params);
7118                         l_error_flag_local := 'Y';
7119                 END IF;
7120 
7121                 -- Project Name, Number to ID Conversion
7122                 -- Though it is done by pa_assignmnts_pub.create_assignment
7123                 -- But we require to get project_id so that we can defualt
7124                 -- values from the project and check security on project
7125                 -- Also project name to id conversion does not happen by internal APIs
7126                 IF l_debug_mode = 'Y' THEN
7127                         pa_debug.write(l_module, 'Deriving ProjectId', l_log_level);
7128                 END IF;
7129 
7130                 IF l_error_flag_local <> 'Y' THEN
7131                         l_project_id_tmp := l_asgn_rec.project_id;
7132                         IF l_asgn_rec.project_number IS NOT NULL THEN
7133                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
7134                                 l_error_message_code := null;
7135 
7136                                 PA_PROJECT_UTILS2.CHECK_PROJECT_NUMBER_OR_ID(
7137                                          p_project_id           => l_project_id_tmp
7138                                         ,p_project_number       => l_asgn_rec.project_number
7139                                         ,p_check_id_flag        => PA_STARTUP.g_check_id_flag
7140                                         ,x_project_id           => l_asgn_rec.project_id
7141                                         ,x_return_status        => l_return_status
7142                                         ,x_error_message_code   => l_error_message_code );
7143 
7144                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7145                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
7146                                         l_error_flag_local := 'Y';
7147                                 END IF;
7148                         END IF;
7149                         IF l_asgn_rec.project_name IS NOT NULL THEN
7150                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
7151                                 l_error_message_code := null;
7152 
7153                                 PA_TASKS_MAINT_UTILS.CHECK_PROJECT_NAME_OR_ID(
7154                                          p_project_id           => l_project_id_tmp
7155                                         ,p_project_name         => l_asgn_rec.project_name
7156                                         ,p_check_id_flag        => PA_STARTUP.g_check_id_flag
7157                                         ,x_project_id           => l_asgn_rec.project_id
7158                                         ,x_return_status        => l_return_status
7159                                         ,x_error_msg_code       => l_error_message_code );
7160 
7161                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7162                                         PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
7163                                         l_error_flag_local := 'Y';
7164                                 END IF;
7165                         END IF;
7166                 END IF; -- l_error_flag_local <> 'Y' AND l_asgn_rec.team_template_id IS NULL
7167 
7168                 IF l_debug_mode = 'Y' THEN
7169                         pa_debug.write(l_module, 'ProjectId='||l_asgn_rec.project_id, l_log_level);
7170                         pa_debug.write(l_module, 'l_error_flag_local='||l_error_flag_local, l_log_level);
7171                 END IF;
7172 
7173                 IF l_error_flag_local <> 'Y' THEN
7174                         -- Project assignment Flow
7175                         l_role_list_id := null;
7176                         l_multi_currency_billing_flag := null;
7177                         l_calendar_id := null;
7178                         l_work_type_id := null;
7179                         l_location_id := null;
7180 
7181                         OPEN c_get_project_dtls(l_asgn_rec.project_id);
7182                         FETCH c_get_project_dtls INTO l_role_list_id, l_multi_currency_billing_flag, l_calendar_id
7183                                 , l_work_type_id, l_location_id;
7184                         CLOSE c_get_project_dtls;
7185 
7186                         IF l_asgn_rec.bill_rate_option = 'RATE' AND  nvl(l_multi_currency_billing_flag,'N') <> 'Y' THEN
7187                                 l_asgn_rec.bill_rate_curr_override := null;
7188                         END IF;
7189                 END IF;
7190 
7191                 IF l_debug_mode = 'Y' THEN
7192                         pa_debug.write(l_module, 'Defaults Value from Project', l_log_level);
7193                         pa_debug.write(l_module, 'l_role_list_id='||l_role_list_id, l_log_level);
7194                         pa_debug.write(l_module, 'l_multi_currency_billing_flag='||l_multi_currency_billing_flag, l_log_level);
7195                         pa_debug.write(l_module, 'l_calendar_id='||l_calendar_id, l_log_level);
7196                         pa_debug.write(l_module, 'l_work_type_id='||l_work_type_id, l_log_level);
7197                         pa_debug.write(l_module, 'l_location_id='||l_location_id, l_log_level);
7198                 END IF;
7199 
7200 
7201                 -- Default calendar, location, work type, assignment name
7202                 IF l_error_flag_local <> 'Y' THEN
7203                         IF l_debug_mode = 'Y' THEN
7204                                 pa_debug.write(l_module, 'Default values of calendar, work type, location from project or team template', l_log_level);
7205                         END IF;
7206 
7207                         -- For OTHER type of calendar there is alredy check done above in code
7208                         -- For PROJECT type ignore the user value and take the project value
7209                         IF l_asgn_rec.calendar_type = 'PROJECT' THEN
7210                                 l_asgn_rec.calendar_id := l_calendar_id;
7211                         END IF;
7212 
7213                         IF l_asgn_rec.work_type_id IS NULL AND l_asgn_rec.work_type_name IS NULL
7214                         THEN
7215                                 l_asgn_rec.work_type_id := l_work_type_id;
7216                         END IF;
7217 
7218                         IF l_asgn_rec.project_id IS NOT NULL AND l_asgn_rec.location_id = FND_API.G_MISS_NUM
7219                                 AND l_asgn_rec.location_country_code = FND_API.G_MISS_CHAR
7220                                 AND l_asgn_rec.location_country_name = FND_API.G_MISS_CHAR
7221                                 AND l_asgn_rec.location_region = FND_API.G_MISS_CHAR
7222                                 AND l_asgn_rec.location_city = FND_API.G_MISS_CHAR
7223                         THEN
7224                                 l_asgn_rec.location_id := l_location_id;
7225                         END IF;
7226 
7227                         -- Role Validation
7228                         -- Though it is done by pa_assignmnts_pub.create_assignment
7229                         -- But we require to get role_id so that we can defualt
7230                         -- values from the role
7231                         -- Defaulting is required
7232 
7233                         IF l_debug_mode = 'Y' THEN
7234                                 pa_debug.write(l_module, 'Validating Role against Role List and doing Role Name to ID conversion', l_log_level);
7235                         END IF;
7236 
7237                         l_return_status := FND_API.G_RET_STS_SUCCESS;
7238                         l_error_message_code := null;
7239                         l_project_role_id_tmp := l_asgn_rec.project_role_id;
7240 
7241                         PA_ROLE_UTILS.Check_Role_RoleList (
7242                                 p_role_id               => l_project_role_id_tmp
7243                                 ,p_role_name            => l_asgn_rec.project_role_name
7244                                 ,p_role_list_id         => l_role_list_id
7245                                 ,p_role_list_name       => NULL
7246                                 ,p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag
7247                                 ,x_role_id              => l_asgn_rec.project_role_id
7248                                 ,x_role_list_id         => l_role_list_id
7249                                 ,x_return_status        => l_return_status
7250                                 ,x_error_message_code   => l_error_message_code );
7251 
7252                         IF l_debug_mode = 'Y' THEN
7253                                 pa_debug.write(l_module, 'After role validation Role id='||l_asgn_rec.project_role_id, l_log_level);
7254                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
7255                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
7256                         END IF;
7257 
7258                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7259                                 PA_UTILS.ADD_MESSAGE('PA', l_error_message_code);
7260                                 l_error_flag_local := 'Y';
7261                         END IF;
7262 
7263                         IF l_debug_mode = 'Y' THEN
7264                                 pa_debug.write(l_module, 'Defaulting RequirmentName from Role ', l_log_level);
7265                         END IF;
7266 
7267                         l_role_name := null;
7268 
7269                         OPEN c_get_role_dtls(l_asgn_rec.project_role_id);
7270                         FETCH c_get_role_dtls INTO l_role_name;
7271                         CLOSE c_get_role_dtls;
7272 
7273                         IF l_asgn_rec.assignment_name IS NULL THEN
7274                                 l_asgn_rec.assignment_name := l_role_name;
7275                         END IF;
7276 
7277                         IF l_debug_mode = 'Y' THEN
7278                                 pa_debug.write(l_module, 'l_role_name='||l_role_name, l_log_level);
7279                         END IF;
7280                 END IF; -- l_error_flag_local <> 'Y' THEN
7281 
7282                 -- All validations are not required as some validation is done in underlying code
7283                 -- Here, we are doing only those validations which are not done internally.
7284                 -- NOTE : In update flow, all these validations are done and it is taken from there
7285                 --        Ideally in create flow also, underlying code should do these validations
7286                 --        But we are doing here to avoid more code changes in existing code.
7287 
7288                 IF l_error_flag_local <> 'Y' AND l_asgn_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
7289 
7290                         -- Bill Rate Options Validation
7291                         -------------------------------
7292 
7293                         IF l_asgn_rec.bill_rate_option <> 'NONE' THEN
7294                                 l_rate_discount_reason_flag := 'N';
7295                                 l_br_override_flag := 'N';
7296                                 l_br_discount_override_flag := 'N';
7297 
7298                                 OPEN get_bill_rate_override_flags(l_asgn_rec.project_id);
7299                                 FETCH get_bill_rate_override_flags INTO  l_rate_discount_reason_flag, l_br_override_flag, l_br_discount_override_flag;
7300                                 CLOSE get_bill_rate_override_flags;
7301 
7302                                 IF l_debug_mode = 'Y' THEN
7303                                         pa_debug.write(l_module, 'Validating Bill Rate Options', l_log_level);
7304                                         pa_debug.write(l_module, 'l_rate_discount_reason_flag='||l_rate_discount_reason_flag, l_log_level);
7305                                         pa_debug.write(l_module, 'l_br_override_flag='||l_br_override_flag, l_log_level);
7306                                         pa_debug.write(l_module, 'l_br_discount_override_flag='||l_br_discount_override_flag, l_log_level);
7307                                 END IF;
7308 
7309                                 IF l_asgn_rec.bill_rate_option = 'RATE' THEN
7310                                         IF l_br_override_flag <> 'Y' OR l_asgn_rec.bill_rate_override <= 0 THEN /* OR l_asgn_rec.bill_rate_override > 100  - Removed for Bug 5703021*/
7311                                                 IF l_br_override_flag <> 'Y' THEN
7312                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
7313                                                         l_error_flag_local := 'Y';
7314                                                 ELSE
7315                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_BILL_RATE_OVRD');
7316                                                         l_error_flag_local := 'Y';
7317                                                 END IF;
7318                                         END IF;
7319                                         -- 5144288, 5144369 : Added bill rate currency check below
7320                                         -- Begin
7321                                         IF nvl(l_multi_currency_billing_flag,'N') = 'Y' AND l_br_override_flag = 'Y' THEN
7322 
7323                                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
7324                                                 l_error_message_code := null;
7325                                                 l_bill_currency_override_tmp := l_asgn_rec.bill_rate_curr_override;
7326 
7327                                                 IF l_debug_mode = 'Y' THEN
7328                                                         pa_debug.write(l_module, 'Validating Bill Rate Currency', l_log_level);
7329                                                 END IF;
7330 
7331                                                 PA_PROJECTS_MAINT_UTILS.CHECK_CURRENCY_NAME_OR_CODE(
7332                                                         p_agreement_currency       => l_bill_currency_override_tmp
7333                                                         ,p_agreement_currency_name  => null
7334                                                         ,p_check_id_flag            => 'Y'
7335                                                         ,x_agreement_currency       => l_asgn_rec.bill_rate_curr_override
7336                                                         ,x_return_status            => l_return_status
7337                                                         ,x_error_msg_code           => l_error_message_code);
7338 
7339                                                 IF l_debug_mode = 'Y' THEN
7340                                                         pa_debug.write(l_module, 'After Bill Rate Currency Validation', l_log_level);
7341                                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
7342                                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
7343                                                 END IF;
7344 
7345                                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7346                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_CISI_CURRENCY_NULL');
7347                                                         l_error_flag_local := 'Y';
7348                                                 END IF;
7349                                         END IF;
7350                                         -- 5144288, 5144369 : End
7351                                 ELSIF l_asgn_rec.bill_rate_option = 'MARKUP' THEN
7352 					-- 5144675 Changed l_asgn_rec.markup_percent_override <=0 to < 0
7353                                         IF l_br_override_flag <> 'Y' OR l_asgn_rec.markup_percent_override < 0
7354 					   OR l_asgn_rec.markup_percent_override > 100 THEN
7355                                                 IF l_br_override_flag <> 'Y' THEN
7356                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
7357                                                         l_error_flag_local := 'Y';
7358                                                 ELSE
7359                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_MARKUP_PERCENT');
7360                                                         l_error_flag_local := 'Y';
7361                                                 END IF;
7362                                         END IF;
7363                                 ELSIF l_asgn_rec.bill_rate_option = 'DISCOUNT' THEN
7364 					-- 5144675 Changed l_asgn_rec.discount_percentage <= 0 to  < 0
7365                                         IF l_br_discount_override_flag <> 'Y' OR l_asgn_rec.discount_percentage < 0
7366 					   OR l_asgn_rec.discount_percentage > 100 THEN
7367                                                 IF l_br_discount_override_flag <> 'Y' THEN
7368                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_OVRD_NA');
7369                                                         l_error_flag_local := 'Y';
7370                                                 ELSE
7371                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_DISCOUNT_PERCENT');
7372                                                         l_error_flag_local := 'Y';
7373                                                 END IF;
7374                                         END IF;
7375                                 END IF;
7376                                 IF l_asgn_rec.rate_disc_reason_code IS NULL THEN
7377                                         IF (l_rate_discount_reason_flag ='Y' AND (l_br_override_flag ='Y' OR l_br_discount_override_flag='Y') AND
7378                                                 (l_asgn_rec.bill_rate_override IS NOT NULL OR l_asgn_rec.markup_percent_override IS NOT NULL OR l_asgn_rec.discount_percentage IS NOT NULL)
7379                                            )
7380                                         THEN
7381                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_RATE_DISC_REASON_REQUIRED');
7382                                                 l_error_flag_local := 'Y';
7383                                         END IF;
7384                                 ELSE
7385                                         l_valid_flag := 'N';
7386                                         OPEN c_get_lookup_exists('RATE AND DISCOUNT REASON', l_asgn_rec.rate_disc_reason_code);
7387                                         FETCH c_get_lookup_exists INTO l_valid_flag;
7388                                         CLOSE c_get_lookup_exists;
7389                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
7390                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_RSN_INVALID');
7391                                                 l_error_flag_local := 'Y';
7392                                         END IF;
7393                                 END IF;
7394 
7395                                 IF l_debug_mode = 'Y' THEN
7396                                         pa_debug.write(l_module, 'After Validating Bill Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
7397                                 END IF;
7398                         END IF; -- l_asgn_rec.bill_rate_option <> 'NONE'
7399 
7400                         -- Transfer Price Rate Options Validation
7401                         -----------------------------------------
7402 
7403                         IF l_asgn_rec.tp_rate_option <> 'NONE' THEN
7404 
7405                                 IF l_debug_mode = 'Y' THEN
7406                                         pa_debug.write(l_module, 'Validating Transfer Price Rate Options', l_log_level);
7407                                 END IF;
7408 
7409                                 IF l_asgn_rec.tp_rate_option = 'RATE' THEN
7410 					-- 5144675 Changed l_asgn_rec.tp_rate_override <= to < 0
7411                                         IF l_asgn_rec.tp_rate_override < 0 OR l_asgn_rec.tp_rate_override > 100 THEN
7412                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_TP_RATE_OVRD');
7413                                                 l_error_flag_local := 'Y';
7414                                         END IF;
7415 
7416                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
7417                                         l_error_message_code := null;
7418                                         l_tp_currency_override_tmp := l_asgn_rec.tp_currency_override;
7419 
7420                                         IF l_debug_mode = 'Y' THEN
7421                                                 pa_debug.write(l_module, 'Validating Transfer Price Rate Currency', l_log_level);
7422                                         END IF;
7423 
7424                                         PA_PROJECTS_MAINT_UTILS.CHECK_CURRENCY_NAME_OR_CODE(
7425                                                 p_agreement_currency       => l_tp_currency_override_tmp
7426                                                 ,p_agreement_currency_name  => null
7427                                                 ,p_check_id_flag            => 'Y'
7428                                                 ,x_agreement_currency       => l_asgn_rec.tp_currency_override
7429                                                 ,x_return_status            => l_return_status
7430                                                 ,x_error_msg_code           => l_error_message_code);
7431 
7432                                         IF l_debug_mode = 'Y' THEN
7433                                                 pa_debug.write(l_module, 'After Transfer Price Rate Currency Validation', l_log_level);
7434                                                 pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
7435                                                 pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
7436                                         END IF;
7437 
7438                                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7439                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_CURR_NOT_VALID');
7440                                                 l_error_flag_local := 'Y';
7441                                         END IF;
7442                                 ELSIF l_asgn_rec.tp_rate_option = 'BASIS' THEN
7443 					-- 5144675 Changed l_asgn_rec.tp_percent_applied_override <= to < 0
7444                                         IF l_asgn_rec.tp_percent_applied_override < 0 OR l_asgn_rec.tp_percent_applied_override > 100  THEN
7445                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_APPLY_BASIS_PERCENT');
7446                                                 l_error_flag_local := 'Y';
7447                                         END IF;
7448                                         l_valid_flag := 'N';
7449                                         IF l_debug_mode = 'Y' THEN
7450                                                 pa_debug.write(l_module, 'Validating Transfer Price Rate Basis', l_log_level);
7451                                         END IF;
7452 
7453                                         OPEN c_get_lookup_exists('CC_MARKUP_BASE_CODE', l_asgn_rec.tp_calc_base_code_override);
7454                                         FETCH c_get_lookup_exists INTO l_valid_flag;
7455                                         CLOSE c_get_lookup_exists;
7456 
7457                                         IF l_debug_mode = 'Y' THEN
7458                                                 pa_debug.write(l_module, 'After Transfer Price Rate Basis Validation', l_log_level);
7459                                                 pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
7460                                         END IF;
7461 
7462                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
7463                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_TP_BASIS_INVALID');
7464                                                 l_error_flag_local := 'Y';
7465                                         END IF;
7466                                 END IF;
7467 
7468                                 IF l_debug_mode = 'Y' THEN
7469                                         pa_debug.write(l_module, 'After Validating Transfer Price Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
7470                                 END IF;
7471                         END IF; -- l_asgn_rec.tp_rate_option <> 'NONE'
7472 
7473                         -- Res Loan Agreement Validations
7474                         ---------------------------------
7475 
7476                         IF l_asgn_rec.expense_owner IS NOT NULL THEN
7477                                 l_valid_flag := 'N';
7478 
7479                                 IF l_debug_mode = 'Y' THEN
7480                                         pa_debug.write(l_module, 'Validating Expense Owner Option', l_log_level);
7481                                 END IF;
7482 
7483                                 OPEN c_get_lookup_exists('EXPENSE_OWNER_TYPE', l_asgn_rec.expense_owner);
7484                                 FETCH c_get_lookup_exists INTO l_valid_flag;
7485                                 CLOSE c_get_lookup_exists;
7486 
7487                                 IF l_debug_mode = 'Y' THEN
7488                                         pa_debug.write(l_module, 'After Expense Owner Option Validation', l_log_level);
7489                                         pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
7490                                 END IF;
7491 
7492                                 IF nvl(l_valid_flag,'N') <> 'Y' THEN
7493                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_EXP_OWNER_INVALID');
7494                                         l_error_flag_local := 'Y';
7495                                 END IF;
7496                         END IF;
7497                 END IF; -- l_error_flag_local <> 'Y' AND l_asgn_rec.assignment_type = 'STAFFED_ASSIGNMENT'
7498 
7499                 IF l_debug_mode = 'Y' THEN
7500                         pa_debug.write(l_module, 'After all validations l_error_flag_local='||l_error_flag_local, l_log_level);
7501                 END IF;
7502 
7503                 -- Flex field Validation
7504                 ------------------------
7505 
7506                 IF l_error_flag_local <> 'Y' THEN
7507                         l_return_status := FND_API.G_RET_STS_SUCCESS;
7508 
7509                         VALIDATE_FLEX_FIELD(
7510                                   p_desc_flex_name         => 'PA_TEAM_ROLE_DESC_FLEX'
7511                                 , p_attribute_category     => l_asgn_rec.attribute_category
7512                                 , px_attribute1            => l_asgn_rec.attribute1
7513                                 , px_attribute2            => l_asgn_rec.attribute2
7514                                 , px_attribute3            => l_asgn_rec.attribute3
7515                                 , px_attribute4            => l_asgn_rec.attribute4
7516                                 , px_attribute5            => l_asgn_rec.attribute5
7517                                 , px_attribute6            => l_asgn_rec.attribute6
7518                                 , px_attribute7            => l_asgn_rec.attribute7
7519                                 , px_attribute8            => l_asgn_rec.attribute8
7520                                 , px_attribute9            => l_asgn_rec.attribute9
7521                                 , px_attribute10           => l_asgn_rec.attribute10
7522                                 , px_attribute11           => l_asgn_rec.attribute11
7523                                 , px_attribute12           => l_asgn_rec.attribute12
7524                                 , px_attribute13           => l_asgn_rec.attribute13
7525                                 , px_attribute14           => l_asgn_rec.attribute14
7526                                 , px_attribute15           => l_asgn_rec.attribute15
7527                                 , x_return_status          => l_return_status
7528                                 , x_msg_count		   => l_msg_count
7529                                 , x_msg_data		   => l_msg_data
7530                          );
7531 
7532                         IF l_debug_mode = 'Y' THEN
7533                                 pa_debug.write(l_module, 'After Flex Field Validation l_return_status='||l_return_status, l_log_level);
7534                                 pa_debug.write(l_module, 'After Flex Field Validation l_msg_data='||l_msg_data, l_log_level);
7535                         END IF;
7536 
7537 
7538                         IF l_return_status <>  FND_API.G_RET_STS_SUCCESS  THEN
7539                                 -- This message does not have toekn defined, still it is ok to pass token as the value
7540                                 -- returned by flex APIs because token are appended as it is
7541                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_DFF_VALIDATION_FAILED',
7542                                                       'MESSAGE', l_msg_data );
7543                                 l_error_flag_local := 'Y';
7544                         END IF;
7545                 END IF; -- l_error_flag_local <> 'Y'
7546 
7547                 -- Security Check
7548                 -----------------
7549 
7550                 IF l_error_flag_local <> 'Y' THEN
7551 
7552                         IF l_debug_mode = 'Y' THEN
7553                                 pa_debug.write(l_module, 'Checking Security for Record#'||i, l_log_level);
7554                         END IF;
7555 
7556 
7557                         IF l_asgn_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
7558                                 l_privilege := 'PA_ASN_CR_AND_DL';
7559                                 l_object_name := 'PA_PROJECTS';
7560                                 l_object_key := l_asgn_rec.project_id;
7561                         ELSIF l_asgn_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
7562                                 l_privilege := 'PA_ADM_ASN_CR_AND_DL';
7563                                 l_object_name := 'PA_PROJECTS';
7564                                 l_object_key := l_asgn_rec.project_id;
7565                         END IF;
7566 
7567                         IF l_debug_mode = 'Y' THEN
7568                                 pa_debug.write(l_module, 'l_privilege='||l_privilege, l_log_level);
7569                                 pa_debug.write(l_module, 'l_object_name='||l_object_name, l_log_level);
7570                                 pa_debug.write(l_module, 'l_object_key='||l_object_key, l_log_level);
7571                         END IF;
7572 
7573                         --If required this may be used to get
7574                         --l_my_person_id := null;
7575                         --l_my_resource_id := null;
7576                         --l_my_resource_name := null;
7577                         --PA_COMP_PROFILE_PUB.GET_USER_INFO(
7578                         --    p_user_id         => fnd_global.user_id
7579                         --  , x_Person_id       => l_my_person_id
7580                         --  , x_Resource_id     => l_my_resource_id
7581                         --  , x_resource_name   => l_my_resource_name);
7582                         --IF l_debug_mode = 'Y' THEN
7583                         --        pa_debug.write(l_module, 'Logged in user Person Id='||l_my_person_id, l_log_level);
7584                         --        pa_debug.write(l_module, 'Logged in user Resource Id='||l_my_resource_id, l_log_level);
7585                         --        pa_debug.write(l_module, 'Logged in user Resource Name='||l_my_resource_name, l_log_level);
7586                         --END IF;
7587 
7588 
7589                         l_return_status := FND_API.G_RET_STS_SUCCESS;
7590                         l_ret_code := 'T';
7591 
7592                         IF l_asgn_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
7593                                 IF l_debug_mode = 'Y' THEN
7594                                         pa_debug.write(l_module, 'Checking Resource Authority', l_log_level);
7595                                 END IF;
7596 
7597                                 PA_SECURITY_PVT.CHECK_CONFIRM_ASMT
7598                                         (p_project_id           => l_asgn_rec.project_id
7599                                         , p_resource_id         => l_asgn_rec.resource_id
7600                                         , p_resource_name       => null
7601                                         , p_privilege           => l_privilege
7602                                         , p_start_date          => l_asgn_rec.start_date
7603                                         , x_ret_code            => l_ret_code
7604                                         , x_return_status       => l_return_status
7605                                         , x_msg_count           => l_msg_count
7606                                         , x_msg_data            => l_msg_data
7607                                         );
7608 
7609                                 IF l_debug_mode = 'Y' THEN
7610                                         pa_debug.write(l_module, 'After Resource Authority Check l_ret_code='||l_ret_code, l_log_level);
7611                                 END IF;
7612                         ELSE
7613                                 IF l_debug_mode = 'Y' THEN
7614                                         pa_debug.write(l_module, 'Checking Project Security', l_log_level);
7615                                 END IF;
7616 
7617                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
7618                                           x_ret_code       => l_ret_code
7619                                         , x_return_status  => l_return_status
7620                                         , x_msg_count      => l_msg_count
7621                                         , x_msg_data       => l_msg_data
7622                                         , p_init_msg_list   => 'F'
7623                                         , p_privilege      => l_privilege
7624                                         , p_object_name    => l_object_name
7625                                         , p_object_key     => l_object_key);
7626 
7627                                 IF l_debug_mode = 'Y' THEN
7628                                         pa_debug.write(l_module, 'After Project Security Check l_ret_code='||l_ret_code, l_log_level);
7629                                 END IF;
7630                         END IF;
7631 
7632 
7633                         IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7634                                 -- This message does not have token defined, but intentionally putting token
7635                                 -- bcoz we still want to show the privielge name which is missing
7636                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_CR_DL'
7637                                                       ,'MISSING_PRIVILEGE', l_privilege);
7638                                 l_error_flag_local := 'Y';
7639                         END IF;
7640                 END IF;
7641 
7642                 -- Call Core Actual API
7643                 -----------------------
7644 
7645                 IF l_error_flag_local <> 'Y' THEN
7646                         l_return_status := FND_API.G_RET_STS_SUCCESS;
7647 
7648                         IF l_debug_mode = 'Y' THEN
7649                                 pa_debug.write(l_module, 'Calling pa_assignments_pub.execute_create_assignment for Record#'||i, l_log_level);
7650                         END IF;
7651 
7652                         l_new_assignment_id_tbl := null;
7653                         l_new_assignment_id := null;
7654                         l_assignment_number := null;
7655                         l_assignment_row_id := null;
7656                         l_resource_id := null;
7657 
7658                         PA_ASSIGNMENTS_PUB.EXECUTE_CREATE_ASSIGNMENT
7659                         (
7660                                   p_api_version                 => p_api_version_number
7661                                 , p_init_msg_list               => l_init_msg_list
7662                                 , p_commit                      => l_commit
7663                                 , p_validate_only               => l_validate_only
7664                                 , p_asgn_creation_mode		=> l_asgn_creation_mode
7665                                 , p_assignment_name		=> l_asgn_rec.assignment_name
7666                                 , p_assignment_type		=> l_asgn_rec.assignment_type
7667 --                                , p_assignment_template_id      => l_asgn_rec.team_template_id
7668 --                                , p_source_assignment_id        => l_asgn_rec.source_assignment_id
7669 --                                , p_number_of_assignments      => l_asgn_rec.number_of_assignments
7670                                 , p_project_role_id             => l_asgn_rec.project_role_id
7671                                 , p_project_role_name           => l_asgn_rec.project_role_name
7672                                 , p_project_id                  => l_asgn_rec.project_id
7673                                 , p_project_name                => l_asgn_rec.project_name
7674                                 , p_project_number              => l_asgn_rec.project_number
7675                                 , p_resource_id                 => l_asgn_rec.resource_id
7676                 --                , p_project_party_id            =>
7677                 --                , p_resource_name               =>
7678                 --                , p_resource_source_id          => null
7679                                 , p_staffing_owner_person_id    => l_asgn_rec.staffing_owner_person_id
7680                 --                , p_staffing_owner_name         =>
7681                                 , p_staffing_priority_code      => l_asgn_rec.staffing_priority_code
7682                                 , p_staffing_priority_name      => l_asgn_rec.staffing_priority_name
7683                                 , p_project_subteam_id          => l_asgn_rec.project_subteam_id
7684                                 , p_project_subteam_name        => l_asgn_rec.project_subteam_name
7685                                 , p_location_id                 => l_asgn_rec.location_id
7686                                 , p_location_city               => l_asgn_rec.location_city
7687                                 , p_location_region             => l_asgn_rec.location_region
7688                                 , p_location_country_name       => l_asgn_rec.location_country_name
7689                                 , p_location_country_code       => l_asgn_rec.location_country_code
7690 --                                , p_min_resource_job_level      => l_asgn_rec.min_resource_job_level
7691 --                                , p_max_resource_job_level	=> l_asgn_rec.max_resource_job_level
7692                                 , p_description                 => l_asgn_rec.description
7693                                 , p_additional_information      => l_asgn_rec.additional_information
7694                                 , p_start_date                  => l_asgn_rec.start_date
7695                                 , p_end_date                    => l_asgn_rec.end_date
7696                                 , p_status_code                 => l_asgn_rec.status_code
7697                                 , p_project_status_name         => l_asgn_rec.status_name
7698                 		, p_multiple_status_flag        => l_multiple_status_flag
7699                 --                , p_assignment_effort           =>
7700                 --                , p_resource_list_member_id   =>
7701                 --                , p_budget_version_id		=>
7702                 --                , p_sum_tasks_flag            =>
7703                                 , p_calendar_type               => l_asgn_rec.calendar_type
7704                                 , p_calendar_id	                => l_asgn_rec.calendar_id
7705                                 , p_calendar_name               => l_asgn_rec.calendar_name
7706                                 , p_resource_calendar_percent   => l_asgn_rec.resource_calendar_percent
7707 --                                , p_start_adv_action_set_flag   => l_asgn_rec.start_adv_action_set_flag
7708 --                                , p_adv_action_set_id           => l_asgn_rec.adv_action_set_id
7709 --                                , p_adv_action_set_name         => l_asgn_rec.adv_action_set_name
7710                                 -- As of now internal code does not support setting the candidate search options
7711                                 -- at create time. It can only be updated.
7712 --                                , p_comp_match_weighting        => l_asgn_rec.comp_match_weighting
7713 --                                , p_avail_match_weighting       => l_asgn_rec.avail_match_weighting
7714 --                                , p_job_level_match_weighting   => l_asgn_rec.job_level_match_weighting
7715 --                                , p_enable_auto_cand_nom_flag   => l_asgn_rec.enable_auto_cand_nom_flag
7716 --                                , p_search_min_availability     => l_asgn_rec.search_min_availability
7717 --                                , p_search_exp_org_struct_ver_id => l_asgn_rec.search_exp_org_str_ver_id
7718 --                                , p_search_exp_start_org_id     => l_asgn_rec.search_exp_start_org_id
7719 --                                , p_search_country_code         => l_asgn_rec.search_country_code
7720 --                                , p_search_min_candidate_score  => l_asgn_rec.search_min_candidate_score
7721 --                                , p_expenditure_org_id          => l_asgn_rec.expenditure_org_id
7722 --                                , p_expenditure_org_name        => l_asgn_rec.expenditure_org_name
7723 --                                , p_expenditure_organization_id => l_asgn_rec.expenditure_organization_id
7724 --                                , p_exp_organization_name       => l_asgn_rec.expenditure_organization_name
7725                                 , p_expenditure_type_class      => l_asgn_rec.expenditure_type_class
7726                                 , p_expenditure_type            => l_asgn_rec.expenditure_type
7727 --                                , p_fcst_job_group_id           => l_asgn_rec.fcst_job_group_id
7728 --                                , p_fcst_job_group_name         => l_asgn_rec.fcst_job_group_name
7729 --                                , p_fcst_job_id                 => l_asgn_rec.fcst_job_id
7730 --                                , p_fcst_job_name               => l_asgn_rec.fcst_job_name
7731 --                                , p_fcst_tp_amount_type         => l_asgn_rec.fcst_tp_amount_type
7732                                 , p_work_type_id                => l_asgn_rec.work_type_id
7733                                 , p_work_type_name              => l_asgn_rec.work_type_name
7734                                 , p_bill_rate_override          => l_asgn_rec.bill_rate_override
7735                                 , p_bill_rate_curr_override     => l_asgn_rec.bill_rate_curr_override
7736                                 , p_markup_percent_override     => l_asgn_rec.markup_percent_override
7737                                 , p_discount_percentage         => l_asgn_rec.discount_percentage
7738                                 , p_rate_disc_reason_code       => l_asgn_rec.rate_disc_reason_code
7739                                 , p_tp_rate_override            => l_asgn_rec.tp_rate_override
7740                                 , p_tp_currency_override        => l_asgn_rec.tp_currency_override
7741                                 , p_tp_calc_base_code_override  => l_asgn_rec.tp_calc_base_code_override
7742                                 , p_tp_percent_applied_override => l_asgn_rec.tp_percent_applied_override
7743                                 , p_extension_possible          => l_asgn_rec.extension_possible
7744                                 , p_expense_owner               => l_asgn_rec.expense_owner
7745                                 , p_expense_limit               => l_asgn_rec.expense_limit
7746                 --                , p_revenue_currency_code     =>
7747                 --                , p_revenue_bill_rate           =>
7748                 --                , p_markup_percent              =>
7749 
7750                                 , p_attribute_category          => l_asgn_rec.attribute_category
7751                                 , p_attribute1                  => l_asgn_rec.attribute1
7752                                 , p_attribute2                  => l_asgn_rec.attribute2
7753                                 , p_attribute3                  => l_asgn_rec.attribute3
7754                                 , p_attribute4                  => l_asgn_rec.attribute4
7755                                 , p_attribute5                  => l_asgn_rec.attribute5
7756                                 , p_attribute6                  => l_asgn_rec.attribute6
7757                                 , p_attribute7                  => l_asgn_rec.attribute7
7758                                 , p_attribute8                  => l_asgn_rec.attribute8
7759                                 , p_attribute9                  => l_asgn_rec.attribute9
7760                                 , p_attribute10                 => l_asgn_rec.attribute10
7761                                 , p_attribute11                 => l_asgn_rec.attribute11
7762                                 , p_attribute12                 => l_asgn_rec.attribute12
7763                                 , p_attribute13                 => l_asgn_rec.attribute13
7764                                 , p_attribute14                 => l_asgn_rec.attribute14
7765                                 , p_attribute15                 => l_asgn_rec.attribute15
7766                                 , x_new_assignment_id_tbl       => l_new_assignment_id_tbl
7767                                 , x_new_assignment_id           => l_new_assignment_id
7768                                 , x_assignment_number           => l_assignment_number
7769                                 , x_assignment_row_id           => l_assignment_row_id
7770                                 , x_resource_id                 => l_resource_id
7771                                 , x_return_status               => l_return_status
7772                                 , x_msg_count                   => l_msg_count
7773                                 , x_msg_data                    => l_msg_data
7774                         );
7775 
7776                         IF l_debug_mode = 'Y' THEN
7777                                 pa_debug.write(l_module, 'After call pa_assignments_pub.execute_create_assignment l_return_status='||l_return_status, l_log_level);
7778                         END IF;
7779 
7780                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7781                                 l_error_flag_local := 'Y';
7782                                 -- Still we populating out tables so that if calling env tries
7783                                 -- to get all ids even after error has occured
7784                                 x_assignment_id_tbl.extend(1);
7785                                 x_assignment_id_tbl(x_assignment_id_tbl.count):= -1;
7786                         ELSE
7787                                 IF l_debug_mode = 'Y' THEN
7788                                         pa_debug.write(l_module, 'Updating Original System Code and Reference', l_log_level);
7789                                         pa_debug.write(l_module, 'l_new_assignment_id_tbl.count'||l_new_assignment_id_tbl.count, l_log_level);
7790                                 END IF;
7791 
7792 
7793                                 IF l_new_assignment_id_tbl.count > 0 THEN
7794                                         FOR j in l_new_assignment_id_tbl.FIRST..l_new_assignment_id_tbl.LAST LOOP
7795                                                 IF l_new_assignment_id_tbl.exists(j) THEN
7796                                                         x_assignment_id_tbl.extend(1);
7797                                                         x_assignment_id_tbl(x_assignment_id_tbl.count):= l_new_assignment_id_tbl(j);
7798                                                         IF (l_asgn_rec.orig_system_code IS NOT NULL OR l_asgn_rec.orig_system_reference IS NOT NULL) THEN
7799                                                                 UPDATE PA_PROJECT_ASSIGNMENTS
7800                                                                 SET orig_system_code = l_asgn_rec.orig_system_code
7801                                                                 , orig_system_reference = l_asgn_rec.orig_system_reference
7802                                                                 WHERE assignment_id = l_new_assignment_id_tbl(j);
7803                                                         END IF;
7804                                                 END IF;
7805                                         END LOOP;
7806                                 END IF;
7807                                 IF l_debug_mode = 'Y' THEN
7808                                         pa_debug.write(l_module, 'After Updating Original System Code and Reference', l_log_level);
7809                                 END IF;
7810                         END IF;
7811                 END IF;
7812 
7813                 l_end_msg_count := FND_MSG_PUB.count_msg;
7814                 IF l_debug_mode = 'Y' THEN
7815                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
7816                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
7817                 END IF;
7818                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
7819 
7820                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
7821                         l_error_flag := 'Y';
7822 
7823                         IF l_debug_mode = 'Y' THEN
7824                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
7825                         END IF;
7826 
7827                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
7828                                 -- Always get from first location in stack i.e. l_start_msg_count+1
7829                                 -- Because stack moves down after delete
7830                                 FND_MSG_PUB.get (
7831                                         p_msg_index      => l_start_msg_count+1,
7832                                         p_encoded        => FND_API.G_FALSE,
7833                                         p_data           => l_data,
7834                                         p_msg_index_out  => l_msg_index_out );
7835 
7836                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
7837                                 -- Because stack moves down after delete
7838                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
7839 
7840                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
7841                                                 'RECORD_NO', i,
7842                                                 'MESSAGE', l_data);
7843                         END LOOP;
7844                         IF l_debug_mode = 'Y' THEN
7845                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
7846                         END IF;
7847                 END IF;
7848                 i := p_assignment_in_tbl.next(i);
7849         END LOOP;
7850 
7851         IF l_debug_mode = 'Y' THEN
7852                 pa_debug.write(l_module, 'All records are done', l_log_level);
7853                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
7854                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
7855         END IF;
7856 
7857         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
7858                 RAISE FND_API.G_EXC_ERROR;
7859         END IF;
7860 
7861         IF l_debug_mode = 'Y' THEN
7862                 PA_DEBUG.reset_curr_function;
7863         END IF;
7864 
7865         IF p_commit = FND_API.G_TRUE THEN
7866                 commit;
7867         END IF;
7868 
7869 
7870 EXCEPTION
7871 WHEN FND_API.G_EXC_ERROR THEN
7872         x_return_status := FND_API.G_RET_STS_ERROR;
7873         l_msg_count := FND_MSG_PUB.count_msg;
7874 
7875         IF p_commit = FND_API.G_TRUE THEN
7876                 ROLLBACK TO CREATE_ASSIGNMENTS_SP;
7877         END IF;
7878 
7879         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
7880                 PA_INTERFACE_UTILS_PUB.get_messages
7881                 ( p_encoded        => FND_API.G_FALSE
7882                 , p_msg_index      => 1
7883                 , p_msg_count      => l_msg_count
7884                 , p_msg_data       => l_msg_data
7885                 , p_data           => l_data
7886                 , p_msg_index_out  => l_msg_index_out);
7887 
7888                 x_msg_data := l_data;
7889                 x_msg_count := l_msg_count;
7890         ELSE
7891                 x_msg_count := l_msg_count;
7892         END IF;
7893 
7894         IF l_debug_mode = 'Y' THEN
7895                 Pa_Debug.reset_curr_function;
7896         END IF;
7897 
7898 WHEN OTHERS THEN
7899 
7900         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7901         x_msg_data      := SQLERRM;
7902 
7903         IF p_commit = FND_API.G_TRUE THEN
7904                 ROLLBACK TO CREATE_ASSIGNMENTS_SP;
7905         END IF;
7906 
7907         FND_MSG_PUB.add_exc_msg
7908         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
7909         , p_procedure_name      => 'CREATE_ASSIGNMENTS'
7910         , p_error_text          => x_msg_data);
7911 
7912         x_msg_count     := FND_MSG_PUB.count_msg;
7913 
7914         IF l_debug_mode = 'Y' THEN
7915                 PA_DEBUG.reset_curr_function;
7916         END IF;
7917         RAISE;
7918 END CREATE_ASSIGNMENTS;
7919 
7920 
7921 -- Start of comments
7922 --      API name        : UPDATE_ASSIGNMENTS
7923 --      Type            : Public
7924 --      Pre-reqs        : None.
7925 --      Function        : This is a public API to update one or more assignments for one or more projects.
7926 --      Usage           : This API will be called from AMG.
7927 --      Parameters      :
7928 --      IN              :       p_commit                IN  VARCHAR2
7929 --                                      Identifier to commit the transaction.
7930 --                                      Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
7931 --                              p_init_msg_list         IN  VARCHAR2
7932 --                                      Identifier to initialize the error message stack.
7933 --                                      Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
7934 --                              p_api_version_number    IN  NUMBER                      Required
7935 --                                      To be compliant with Applications API coding standards.
7936 --				p_assignment_in_tbl     IN  ASSIGNMENT_IN_TBL_TYPE	Required
7937 --					Table of assignment records. Please see the ASSIGNMENT_IN_TBL_TYPE datatype table
7938 --      OUT             :
7939 --                              x_return_status         OUT VARCHAR2
7940 --                                      Indicates the return status of the API.
7941 --                                      Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
7942 --                              x_msg_count             OUT NUMBER
7943 --                                      Indicates the number of error messages in the message stack
7944 --                              x_msg_data              OUT VARCHAR2
7945 --                                      Indicates the error message text if only one error exists
7946 --      History         :
7947 --
7948 --                              01-Mar-2006 - avaithia  - Created
7949 -- End of comments
7950 
7951 PROCEDURE UPDATE_ASSIGNMENTS
7952 (
7953   p_api_version_number          IN              NUMBER   := 1.0
7954 , p_init_msg_list               IN              VARCHAR2 := FND_API.G_TRUE
7955 , p_commit                      IN              VARCHAR2 := FND_API.G_FALSE
7956 , p_assignment_in_tbl           IN              ASSIGNMENT_IN_TBL_TYPE
7957 , x_return_status               OUT     NOCOPY  VARCHAR2
7958 , x_msg_count                   OUT     NOCOPY  NUMBER
7959 , x_msg_data                    OUT     NOCOPY  VARCHAR2
7960 )
7961 IS
7962 l_calling_application           VARCHAR2(10)            := 'PLSQL';
7963 l_calling_module                VARCHAR2(10)            := 'AMG';
7964 l_check_id_flag                 VARCHAR2(1)             := 'Y';
7965 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
7966 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
7967 
7968 l_log_level                     NUMBER                  := 3;
7969 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.UPDATE_ASSIGNMENTS';
7970 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
7971 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
7972 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
7973 l_asgn_update_mode              VARCHAR2(10)            := 'FULL'; -- This is just a dummy value
7974 l_multiple_status_flag          VARCHAR2(1)             := 'N';
7975 
7976 l_msg_count                     NUMBER;
7977 l_msg_data                      VARCHAR2(2000);
7978 l_msg_index_out                 NUMBER;
7979 l_data                          VARCHAR2(2000);
7980 l_debug_mode                    VARCHAR2(1);
7981 
7982 i                               NUMBER;
7983 l_asgn_rec			ASSIGNMENT_IN_REC_TYPE;
7984 
7985 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
7986 l_error_flag                    VARCHAR2(1)             := 'N';
7987 l_error_flag_local              VARCHAR2(1)             := 'N';
7988 
7989 l_loop_msg_count                NUMBER                  :=0;
7990 l_start_msg_count               NUMBER                  :=0;
7991 l_end_msg_count                 NUMBER                  :=0;
7992 
7993 l_missing_params                VARCHAR2(1000);
7994 l_privilege                     VARCHAR2(30);
7995 l_object_name                   VARCHAR2(30);
7996 l_object_key                    NUMBER;
7997 l_error_message_code            VARCHAR2(30);
7998 l_ret_code                      VARCHAR2(1);
7999 
8000 l_before_api_msg_count          NUMBER;
8001 l_after_api_msg_count           NUMBER;
8002 
8003 l_assignment_name		PA_PROJECT_ASSIGNMENTS.ASSIGNMENT_NAME%TYPE;
8004 l_assignment_id			PA_PROJECT_ASSIGNMENTS.ASSIGNMENT_ID%TYPE;
8005 l_record_version_number		PA_PROJECT_ASSIGNMENTS.RECORD_VERSION_NUMBER%TYPE;
8006 l_status_code			PA_PROJECT_ASSIGNMENTS.STATUS_CODE%TYPE;
8007 l_apprvl_status_code		PA_PROJECT_ASSIGNMENTS.APPRVL_STATUS_CODE%TYPE;
8008 l_apprvl_sys_status_code	PA_PROJECT_STATUSES.PROJECT_SYSTEM_STATUS_CODE%TYPE;
8009 l_mass_wf_in_progress_flag	PA_PROJECT_ASSIGNMENTS.MASS_WF_IN_PROGRESS_FLAG%TYPE ;
8010 
8011 CURSOR c_sys_status_code(l_in_status_code IN VARCHAR2  ) IS
8012 SELECT project_system_status_code
8013 FROM  pa_project_statuses
8014 WHERE project_status_code = l_in_status_code
8015 AND status_type= 'ASGMT_APPRVL';
8016 
8017 CURSOR c_asgn_db_values IS
8018 SELECT * from pa_project_assignments
8019 WHERE assignment_id = l_assignment_id
8020   AND assignment_type <> 'OPEN_ASSIGNMENT' ;
8021 
8022 CURSOR c_get_subteam_party_id(l_in_assignment_id IN NUMBER) IS
8023 SELECT project_subteam_party_id, project_subteam_id
8024 FROM pa_project_subteam_parties
8025 WHERE object_id = l_in_assignment_id
8026 AND object_type = 'PA_PROJECT_ASSIGNMENTS'
8027 AND primary_subteam_flag = 'Y';
8028 
8029 CURSOR get_bill_rate_override_flags(c_project_id NUMBER) IS
8030 SELECT impl.rate_discount_reason_flag ,impl.br_override_flag, impl.br_discount_override_flag
8031 FROM pa_implementations_all impl
8032     , pa_projects_all proj
8033 WHERE proj.org_id=impl.org_id   -- Removed nvl condition from org_id : Post review changes for Bug 5130421
8034 AND proj.project_id = c_project_id ;
8035 
8036 CURSOR c_get_lookup_exists(c_lookup_type VARCHAR2, c_lookup_code VARCHAR2) IS
8037 SELECT 'Y'
8038 FROM dual
8039 WHERE EXISTS
8040 (SELECT 'XYZ' FROM pa_lookups WHERE lookup_type = c_lookup_type AND lookup_code = c_lookup_code);
8041 
8042 CURSOR c_derive_country_code(c_country_name IN VARCHAR2) IS
8043 SELECT COUNTRY_CODE
8044 FROM PA_COUNTRY_V
8045 WHERE NAME = c_country_name;
8046 
8047 CURSOR c_derive_country_name(c_country_code IN VARCHAR2) IS
8048 SELECT NAME
8049 FROM PA_COUNTRY_V
8050 WHERE  COUNTRY_CODE  = c_country_code;
8051 
8052 -- 5144288, 5144369 : Added c_get_mcb_flag
8053 CURSOR c_get_mcb_flag(c_project_id NUMBER) IS
8054 SELECT multi_currency_billing_flag
8055 FROM pa_projects_all
8056 WHERE project_id = c_project_id;
8057 
8058 
8059 
8060 l_valid_country		        VARCHAR2(1):='N';
8061 l_dummy_country_code            VARCHAR2(2);
8062 l_dummy_state		        VARCHAR2(240);
8063 l_dummy_city		        VARCHAR2(80);
8064 l_out_location_id	        NUMBER;
8065 l_asgn_db_values_rec	        c_asgn_db_values%ROWTYPE;
8066 l_valid_assignment	        VARCHAR2(1) := 'N';
8067 l_project_subteam_party_id      NUMBER;
8068 l_project_subteam_id            NUMBER;
8069 l_valid_flag                    VARCHAR2(1);
8070 l_rate_discount_reason_flag     VARCHAR2(1);
8071 l_br_override_flag              VARCHAR2(1);
8072 l_br_discount_override_flag     VARCHAR2(1);
8073 l_basic_info_changed		VARCHAR2(1);
8074 l_fin_info_changed              VARCHAR2(1);
8075 l_fin_bill_rate_info_changed    VARCHAR2(1);
8076 l_fin_tp_rate_info_changed      VARCHAR2(1);
8077 
8078 l_multi_currency_billing_flag   VARCHAR2(1); -- 5144288, 5144369
8079 l_bill_currency_override_tmp    VARCHAR2(30); -- 5144288, 5144369
8080 
8081 
8082 
8083 BEGIN
8084 
8085         --------------------------------------------------
8086         -- RESET OUT params
8087         --------------------------------------------------
8088         x_return_status := FND_API.G_RET_STS_SUCCESS;
8089         x_msg_count := 0;
8090         x_msg_data := NULL ;
8091         --------------------------------------------------
8092         -- Initialize Current Function and Msg Stack
8093         --------------------------------------------------
8094         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
8095 
8096         IF l_debug_mode = 'Y' THEN
8097                 PA_DEBUG.set_curr_function(p_function => 'UPDATE_ASSIGNMENTS', p_debug_mode => l_debug_mode);
8098         END IF;
8099 
8100         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
8101                 FND_MSG_PUB.initialize;
8102         END IF;
8103         --------------------------------------------------
8104         -- Create Savepoint
8105         --------------------------------------------------
8106         IF p_commit = FND_API.G_TRUE THEN
8107                 savepoint UPDATE_ASSIGNMENTS_SP;
8108         END IF;
8109 
8110         IF l_debug_mode = 'Y' THEN
8111                 pa_debug.write(l_module, 'Start of UPDATE_ASSIGNMENTS', l_log_level);
8112         END IF;
8113         --------------------------------------------------
8114         -- Start Initialize
8115         --------------------------------------------------
8116         PA_STARTUP.INITIALIZE(
8117                   p_calling_application => l_calling_application
8118                 , p_calling_module => l_calling_module
8119                 , p_check_id_flag => l_check_id_flag
8120                 , p_check_role_security_flag => l_check_role_security_flag
8121                 , p_check_resource_security_flag => l_check_resource_security_flag
8122                 , p_debug_level => l_log_level
8123                 );
8124 
8125         IF l_debug_mode = 'Y' THEN
8126                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
8127         END IF;
8128         ----------------------------------------------------
8129         -- Mandatory param validations and Defaulting Values
8130         -- Security Check
8131         -- Core Logic
8132         ----------------------------------------------------
8133 	i := p_assignment_in_tbl.first ;
8134 
8135 	WHILE i IS NOT NULL LOOP
8136 
8137 		l_error_flag_local := 'N';
8138                 l_missing_params := null;
8139 		l_asgn_rec := NULL ;
8140 		l_basic_info_changed := 'N';
8141                 l_fin_info_changed := 'N';
8142                 l_fin_bill_rate_info_changed := 'N';
8143                 l_fin_tp_rate_info_changed := 'N';
8144 
8145 		l_start_msg_count := FND_MSG_PUB.count_msg;
8146 
8147 		l_asgn_rec := p_assignment_in_tbl(i);
8148 
8149          /*--Bug 6511907 PJR Date Validation Enhancement ----- Start--*/
8150          /*-- Validating Resource Req Start and End Date against
8151          Project Start and Completion dates --*/
8152 
8153          If l_asgn_rec.start_date is not null or l_asgn_rec.end_date is not null Then
8154                         Declare
8155                           l_validate           VARCHAR2(10);
8156                           l_start_date_status  VARCHAR2(10);
8157                           l_end_date_status    VARCHAR2(10);
8158                           l_start_date         DATE;
8159                           l_end_date           DATE;
8160                         Begin
8161                          If l_asgn_rec.start_date is not null or l_asgn_rec.end_date is not null then
8162                            l_start_date := l_asgn_rec.start_date;
8163                            l_end_date   := l_asgn_rec.end_date;
8164                            PA_PROJECT_DATES_UTILS.Validate_Resource_Dates
8165                                        (l_asgn_rec.project_id, l_start_date, l_end_date,
8166                                                    l_validate, l_start_date_status, l_end_date_status);
8167 
8168                            If l_validate = 'Y' and l_start_date_status = 'I' Then
8169 
8170                               pa_utils.add_message
8171                                ( p_app_short_name  => 'PA'
8172                                 ,p_msg_name	       => 'PA_PJR_DATE_START_ERROR'
8173                                 ,p_token1          => 'PROJ_TXN_START_DATE'
8174                                 ,p_value1          => GET_PROJECT_START_DATE(l_asgn_rec.project_id)
8175                                 ,p_token2          => ''
8176                                 ,p_value2          => ''
8177                                 ,p_token3          => ''
8178                                 ,p_value3          => ''
8179                                );
8180 
8181                               RAISE  FND_API.G_EXC_ERROR;
8182                            End If;
8183 
8184                            If l_validate = 'Y' and l_end_date_status = 'I' Then
8185 
8186                               pa_utils.add_message
8187                                ( p_app_short_name  => 'PA'
8188                                 ,p_msg_name	    => 'PA_PJR_DATE_FINISH_ERROR'
8189                                 ,p_token1          => 'PROJ_TXN_END_DATE'
8190                                 ,p_value1          => GET_PROJECT_COMPLETION_DATE(l_asgn_rec.project_id)
8191                                 ,p_token2          => ''
8192                                 ,p_value2          => ''
8193                                 ,p_token3          => ''
8194                                 ,p_value3          => ''
8195                                );
8196 
8197                               RAISE  FND_API.G_EXC_ERROR;
8198                            End If;
8199                          End If;
8200                         End;
8201 
8202          End if;
8203          /*--Bug 6511907 PJR Date Validation Enhancement ----- End--*/
8204 
8205 		-----------------------------------------------------------------------
8206 		-- Print all the IN params here
8207 		-----------------------------------------------------------------------
8208 
8209 		-----------------------------------------------------------------------
8210 		-- Mandatory Parameters Check and Valid Values Checks
8211 		-----------------------------------------------------------------------
8212 		l_asgn_db_values_rec := NULL ;
8213 
8214 		l_assignment_id := l_asgn_rec.assignment_id ;
8215 
8216 		OPEN c_asgn_db_values ;
8217 		FETCH c_asgn_db_values INTO l_asgn_db_values_rec ;
8218 
8219 		IF c_asgn_db_values%NOTFOUND THEN
8220 			l_missing_params := l_missing_params || 'ASSIGNMENT_ID';
8221 		ELSE
8222 			l_valid_assignment := 'Y';
8223 			-- Assignment ID exists
8224 			l_apprvl_sys_status_code := NULL ;
8225                         OPEN c_sys_status_code(l_asgn_db_values_rec.apprvl_status_code);
8226                         FETCH c_sys_status_code INTO l_apprvl_sys_status_code;
8227                         CLOSE c_sys_status_code ;
8228 
8229                         IF l_apprvl_sys_status_code in ('ASGMT_APPRVL_CANCELED','ASGMT_APPRVL_SUBMITTED') THEN
8230                                 l_error_flag_local := 'Y';
8231                                 PA_UTILS.ADD_MESSAGE('PA','PA_AMG_RES_INV_UP_ASG_STATUS') ;-- Need new msg
8232 				-- Discuss with Amit
8233                         END IF;
8234 
8235                         IF nvl(l_asgn_db_values_rec.mass_wf_in_progress_flag, 'N') = 'Y' THEN
8236                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_ASSIGNMENT_WF');
8237                                 l_error_flag_local := 'Y';
8238                         END IF;
8239 
8240 		END IF;
8241 		CLOSE c_asgn_db_values ;
8242 
8243                 IF l_asgn_rec.work_type_id IS NULL AND l_asgn_rec.work_type_name IS NULL THEN
8244                         l_missing_params := l_missing_params||', WORK_TYPE_ID, WORK_TYPE_NAME';
8245                 END IF;
8246 
8247 		IF l_valid_assignment = 'Y' THEN
8248 			IF l_asgn_db_values_rec.project_id IS NOT NULL THEN
8249 				-- Update Project Assignment Flow
8250 
8251 				-- Bug 5174557 : Assignment Type Change is not allowed.
8252 				IF l_asgn_rec.assignment_type IS NOT NULL AND
8253 				   l_asgn_rec.assignment_type <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8254 
8255 					IF l_asgn_rec.assignment_type <> l_asgn_db_values_rec.assignment_type THEN
8256 						l_missing_params := l_missing_params||', ASSIGNMENT_TYPE';
8257 					END IF;
8258                 		END IF;
8259 
8260 				IF l_asgn_rec.expenditure_type_class IS NULL THEN
8261 					l_missing_params := l_missing_params||', EXPENDITURE_TYPE_CLASS';
8262 				END IF;
8263 
8264 				IF l_asgn_rec.expenditure_type IS NULL THEN
8265                                         l_missing_params := l_missing_params||', EXPENDITURE_TYPE';
8266                                 END IF;
8267 
8268 				IF l_asgn_rec.bill_rate_option IS NULL THEN
8269                                 	l_missing_params := l_missing_params||', BILL_RATE_OPTION';
8270 				ELSIF  l_asgn_rec.bill_rate_option <> G_PA_MISS_CHAR
8271 				   AND l_asgn_rec.bill_rate_option NOT IN('RATE','MARKUP','DISCOUNT','NONE') THEN
8272                                 	l_missing_params := l_missing_params||', BILL_RATE_OPTION';
8273 				ELSIF l_asgn_rec.bill_rate_option = 'NONE' THEN
8274 					l_asgn_rec.bill_rate_override := null;
8275 					l_asgn_rec.bill_rate_curr_override := NULL ;
8276 					l_asgn_rec.markup_percent_override := NULL ;
8277 					l_asgn_rec.discount_percentage := NULL ;
8278 					l_asgn_rec.rate_disc_reason_code := NULL ;
8279 				ELSIF l_asgn_rec.bill_rate_option = 'RATE' THEN
8280 					l_asgn_rec.markup_percent_override := null;
8281                                 	l_asgn_rec.discount_percentage := null;
8282                                 	IF (l_asgn_rec.bill_rate_override IS NULL
8283 					    OR l_asgn_rec.bill_rate_override = G_PA_MISS_NUM)
8284 						AND l_asgn_db_values_rec.bill_rate_override IS NULL
8285                                 	THEN
8286                                        	     l_missing_params := l_missing_params||', BILL_RATE_OVERRIDE';
8287                                 	END IF;
8288 				ELSIF l_asgn_rec.bill_rate_option ='MARKUP' THEN
8289 					l_asgn_rec.bill_rate_override := null;
8290                                         l_asgn_rec.bill_rate_curr_override := NULL ;
8291 					l_asgn_rec.discount_percentage := null;
8292 					IF (l_asgn_rec.markup_percent_override IS NULL
8293 					    OR l_asgn_rec.markup_percent_override = G_PA_MISS_NUM)
8294 						AND l_asgn_db_values_rec.markup_percent_override IS NULL
8295 					THEN
8296 						l_missing_params := l_missing_params||', MARKUP_PERCENT_OVERRIDE';
8297 					END IF;
8298 				ELSIF l_asgn_rec.bill_rate_option = 'DISCOUNT' THEN
8299 					l_asgn_rec.bill_rate_override := null;
8300                                         l_asgn_rec.bill_rate_curr_override := NULL ;
8301 					l_asgn_rec.markup_percent_override := NULL ;
8302 					IF (l_asgn_rec.discount_percentage IS NULL
8303 					    OR l_asgn_rec.discount_percentage = G_PA_MISS_NUM)
8304                                                 AND l_asgn_db_values_rec.discount_percentage IS NULL
8305 					THEN
8306 						l_missing_params := l_missing_params||', DISCOUNT_PERCENTAGE';
8307 					END IF;
8308 				END IF;
8309 
8310 				IF l_asgn_rec.tp_rate_option  IS NULL THEN
8311                                 	l_missing_params := l_missing_params||', TP_RATE_OPTION';
8312                         	ELSIF l_asgn_rec.tp_rate_option <> G_PA_MISS_CHAR
8313 				   AND l_asgn_rec.tp_rate_option NOT IN('RATE','BASIS','NONE') THEN
8314 					l_missing_params := l_missing_params||', TP_RATE_OPTION';
8315                                 ELSIF l_asgn_rec.tp_rate_option = 'NONE' THEN
8316 					l_asgn_rec.tp_rate_override := null;
8317 					l_asgn_rec.tp_currency_override := NULL ;
8318 					l_asgn_rec.tp_calc_base_code_override := NULL ;
8319                                         l_asgn_rec.tp_percent_applied_override := NULL ;
8320 				ELSIF l_asgn_rec.tp_rate_option = 'RATE' THEN
8321 					l_asgn_rec.tp_calc_base_code_override := NULL ;
8322                                         l_asgn_rec.tp_percent_applied_override := NULL ;
8323 					IF ((l_asgn_rec.tp_rate_override IS NULL
8324 					     OR l_asgn_rec.tp_rate_override = G_PA_MISS_NUM
8325 					     )
8326 					    AND l_asgn_db_values_rec.tp_rate_override IS NULL
8327 					    )
8328 					    OR
8329 					   ((l_asgn_rec.tp_currency_override IS NULL
8330 					     OR l_asgn_rec.tp_currency_override = G_PA_MISS_CHAR
8331 					     )
8332                                              AND l_asgn_db_values_rec.tp_currency_override IS NULL
8333 					    )
8334 					THEN
8335 						l_missing_params := l_missing_params||', TP_RATE_OVERRIDE, TP_CURRENCY_OVERRIDE';
8336 					END IF;
8337 				ELSIF l_asgn_rec.tp_rate_option = 'BASIS' THEN
8338 					l_asgn_rec.tp_rate_override := null;
8339                                         l_asgn_rec.tp_currency_override := NULL ;
8340 					IF ((l_asgn_rec.tp_calc_base_code_override IS NULL
8341 					     OR l_asgn_rec.tp_calc_base_code_override = G_PA_MISS_CHAR
8342 					     )
8343 					    AND l_asgn_db_values_rec.tp_calc_base_code_override IS NULL
8344 					   )
8345 					    OR
8346 					   (( l_asgn_rec.tp_percent_applied_override IS NULL
8347 					      OR l_asgn_rec.tp_percent_applied_override = G_PA_MISS_NUM
8348 					     )
8349                                              AND l_asgn_db_values_rec.tp_percent_applied_override IS NULL
8350 					   )
8351 					THEN
8352 						l_missing_params := l_missing_params||', TP_CALC_BASE_CODE_OVERRIDE,TP_PERCENT_APPLIED_OVERRIDE' ;
8353 					END IF;
8354 				END IF;
8355 
8356 				IF l_asgn_rec.extension_possible <>  G_PA_MISS_CHAR
8357 				   AND l_asgn_rec.extension_possible NOT IN ('Y','N')
8358 				THEN
8359 					l_missing_params := l_missing_params||', EXTENSION_POSSIBLE';
8360 				END IF;
8361 
8362 				IF l_asgn_rec.expense_owner  <>  G_PA_MISS_CHAR
8363 				   AND l_asgn_rec.expense_owner NOT IN ('CLIENT','PROJECT_ORG','RESOURCE_ORG')
8364 				THEN
8365 					l_missing_params := l_missing_params||', EXPENSE_OWNER';
8366 				END IF;
8367 
8368 				-- If either city or state (or) both are passed ,then country is
8369 				-- mandatory
8370 				IF (l_asgn_rec.location_country_code IS NULL AND l_asgn_rec.location_country_name IS NULL)
8371 				   OR
8372 				   (l_asgn_rec.location_country_code =  G_PA_MISS_CHAR
8373 				       AND l_asgn_rec.location_country_code = G_PA_MISS_CHAR
8374 				       AND l_asgn_db_values_rec.location_id IS NULL)
8375 				THEN
8376 					IF (l_asgn_rec.location_region <> G_PA_MISS_CHAR AND
8377 					    l_asgn_rec.location_region IS NOT NULL)
8378 					    OR
8379 					   (l_asgn_rec.location_city <> G_PA_MISS_CHAR AND
8380 					    l_asgn_rec.location_city IS NOT NULL)
8381 					THEN
8382 						-- This means,User is NULLING OUT Country Field
8383 						-- But Passing State (or) City Values.
8384 						-- (OR)
8385 						-- In DB,No Country has been specified yet.
8386 						-- User is not passing Country Value
8387 						-- But user is trying to specify State or City
8388 						-- We should nt allow it
8389 						--PA_UTILS.ADD_MESSAGE('PA','PA_COUNTRY_INVALID');
8390 						l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE, LOCATION_COUNTRY_NAME';
8391 						l_valid_country := 'N';
8392 					END IF;
8393 				ELSIF l_asgn_rec.location_country_code IS NOT NULL
8394 				      AND l_asgn_rec.location_country_code <> G_PA_MISS_CHAR
8395 				THEN
8396 					OPEN c_derive_country_name(l_asgn_rec.location_country_code);
8397 					FETCH c_derive_country_name INTO l_asgn_rec.location_country_name;
8398 					IF c_derive_country_name%NOTFOUND THEN
8399 						-- Invalid Country code passed.
8400 						l_missing_params := l_missing_params||', LOCATION_COUNTRY_CODE';
8401 						l_valid_country := 'N';
8402 					ELSE
8403 						l_valid_country := 'Y';
8404 					END IF;
8405 					CLOSE c_derive_country_name;
8406 				ELSIF l_asgn_rec.location_country_name IS NOT NULL
8407 				      AND l_asgn_rec.location_country_name <> G_PA_MISS_CHAR
8408 				THEN
8409 				      OPEN c_derive_country_code(l_asgn_rec.location_country_name);
8410 				      FETCH c_derive_country_code INTO l_asgn_rec.location_country_code;
8411 				      IF c_derive_country_code%NOTFOUND THEN
8412 						-- Invalid Country Name passed.
8413 						l_missing_params := l_missing_params||', LOCATION_COUNTRY_NAME';
8414 						l_valid_country := 'N';
8415 					ELSE
8416 						l_valid_country := 'Y';
8417 				      END IF;
8418 				      CLOSE c_derive_country_code;
8419 				END IF;
8420 
8421 				-- If the country is valid,then proceed with the state and city validations
8422 				IF (l_valid_country = 'Y') -- This is for user passed values
8423 				   OR
8424 				   (l_asgn_rec.location_country_code = G_PA_MISS_CHAR -- This is for existing DB Value
8425 				    AND l_asgn_rec.location_country_name = G_PA_MISS_CHAR
8426 				    AND l_asgn_db_values_rec.location_id IS NOT NULL)
8427 				THEN
8428 					-- If Existing Location ID exists
8429 					-- Derive DB values for location details
8430 					IF (
8431 					     (l_asgn_rec.location_country_code = G_PA_MISS_CHAR
8432 					     AND  l_asgn_rec.location_country_name = G_PA_MISS_CHAR
8433 					     )
8434 					     OR (l_asgn_rec.location_region = G_PA_MISS_CHAR)
8435 					     OR (l_asgn_rec.location_city = G_PA_MISS_CHAR)
8436 					   )
8437 					   AND ( l_asgn_db_values_rec.location_id IS NOT NULL)
8438 					THEN
8439 						SELECT country_code,region,city
8440 						INTO l_dummy_country_code,l_dummy_state,l_dummy_city
8441 						FROM PA_LOCATIONS
8442 						WHERE location_id = l_asgn_db_values_rec.location_id;
8443 					END IF;
8444 
8445 					IF (l_asgn_rec.location_country_code <> G_PA_MISS_CHAR)
8446 					THEN
8447 						l_dummy_country_code := l_asgn_rec.location_country_code;
8448 					END IF;
8449 
8450 					IF (l_asgn_rec.location_region <> G_PA_MISS_CHAR)
8451 					THEN
8452 						l_dummy_state := l_asgn_rec.location_region;
8453 					END IF;
8454 
8455 					IF (l_asgn_rec.location_city <> G_PA_MISS_CHAR)
8456 					THEN
8457 						l_dummy_city := l_asgn_rec.location_city;
8458 					END IF;
8459 
8460 					-- ==== A ==== Added for 5174316 : Start
8461 					l_asgn_rec.location_country_code := l_dummy_country_code ;
8462 					l_asgn_rec.location_region := l_dummy_state ;
8463 					l_asgn_rec.location_city := l_dummy_city ;
8464 					-- ==== A ==== Added for 5174316 : End
8465 
8466 					-- If any of values ,not passed, DB Values will be taken
8467 					pa_location_utils.Check_Location_Exists
8468 					(
8469 						 p_country_code => l_dummy_country_code
8470 						,p_city		=> l_dummy_city
8471 						,p_region	=> l_dummy_state
8472 						,x_location_id	=> l_out_location_id
8473 						,x_return_status => l_return_status
8474 					);
8475 
8476 					IF l_out_location_id IS NULL THEN
8477 						PA_UTILS.ADD_MESSAGE('PA','PA_AMG_RES_INV_CRC_COMB'); -- New message to say ,Invalid comb
8478                                                 l_error_flag_local := 'Y'; -- 5148975
8479 					END IF;
8480 				END IF;
8481 				--
8482 			END IF; -- Project Flow
8483 		END IF; -- If it is a valid assignment
8484 
8485 		IF l_debug_mode = 'Y' THEN
8486                         pa_debug.write(l_module, 'Mandatory parameter validation over.List of Missing Parameters='||l_missing_params, l_log_level);
8487                 END IF;
8488 
8489                 IF l_missing_params IS NOT NULL THEN
8490                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
8491                                                 'INVALID_PARAMS', l_missing_params);
8492                         l_error_flag_local := 'Y';
8493                 END IF;
8494 
8495 		-- Take the db values,if param is not passed
8496 
8497 		IF l_debug_mode = 'Y' THEN
8498                         pa_debug.write(l_module, 'Take values from database for those parameters which are not passed.', l_log_level);
8499                 END IF;
8500 
8501 		IF l_asgn_rec.assignment_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8502 			l_asgn_rec.assignment_name := l_asgn_db_values_rec.assignment_name ;
8503                 END IF;
8504 
8505 		IF l_asgn_rec.assignment_type = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8506                         l_asgn_rec.assignment_type := l_asgn_db_values_rec.assignment_type ;
8507                 END IF;
8508 
8509 		-- These parameters are Not used for Update Flow:
8510                 -- Internal API requires to pass FND_API miss nums instead of null
8511                 -- if we pass null, they treat it as update and raise error
8512 
8513 		l_asgn_rec.project_role_id := FND_API.G_MISS_NUM;
8514 
8515 		l_asgn_rec.project_role_name := FND_API.G_MISS_CHAR;
8516 
8517 		l_asgn_rec.project_id := l_asgn_db_values_rec.project_id;
8518 
8519 		l_asgn_rec.project_name := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR ;
8520 
8521 		l_asgn_rec.project_number := PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR ;
8522 
8523 		-- Resource ID cant be changed once an assignment is done
8524 		-- Internal API expects it to be passed as Miss NUM
8525                 l_asgn_rec.resource_id := FND_API.G_MISS_NUM ;
8526 
8527 
8528 		IF l_asgn_rec.staffing_owner_person_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8529                         l_asgn_rec.staffing_owner_person_id := l_asgn_db_values_rec.staffing_owner_person_id ;
8530                 END IF;
8531 
8532 		IF l_asgn_rec.staffing_priority_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8533                         l_asgn_rec.staffing_priority_code := l_asgn_db_values_rec.staffing_priority_code ;
8534                 END IF;
8535 
8536 		IF l_asgn_rec.staffing_priority_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8537                         l_asgn_rec.staffing_priority_name := NULL ;
8538 		END IF;
8539 
8540 		l_project_subteam_party_id := null;
8541 
8542                 OPEN c_get_subteam_party_id( l_asgn_rec.assignment_id );
8543                 FETCH c_get_subteam_party_id INTO l_project_subteam_party_id, l_project_subteam_id;
8544                 CLOSE c_get_subteam_party_id;
8545 
8546                 IF l_asgn_rec.project_subteam_id = G_PA_MISS_NUM THEN
8547                         -- The reason we need to check name here, because
8548                         -- If name is passed and id is not. In this case, id
8549                         -- will default to previous id and new name will be lost
8550                         IF l_asgn_rec.project_subteam_name = G_PA_MISS_CHAR THEN
8551                                 l_asgn_rec.project_subteam_id := l_project_subteam_id;
8552                         ELSIF l_asgn_rec.project_subteam_name IS NULL THEN
8553                                 l_asgn_rec.project_subteam_id := null;
8554                         ELSE
8555                                 l_asgn_rec.project_subteam_id := null;
8556                         END IF;
8557                 END IF;
8558 
8559                 IF l_asgn_rec.project_subteam_name = G_PA_MISS_CHAR THEN
8560                         l_asgn_rec.project_subteam_name := null;
8561                 END IF;
8562 
8563 		--IF l_asgn_rec.project_subteam_id IS NULL AND  l_asgn_rec.project_subteam_name IS NULL
8564 		--THEN
8565 		--	l_project_subteam_party_id := NULL;
8566 		--END IF;
8567 
8568                 IF l_asgn_rec.location_id = G_PA_MISS_NUM THEN
8569                         l_asgn_rec.location_id := l_asgn_db_values_rec.location_id;
8570                 END IF;
8571 
8572 		/* Commented for Bug 5174316
8573 		   The following logic is wrong.If we dont pass these params ,
8574 		   it should not be NULLED OUT.
8575 		   The logic is already present in location tagged with ==== A ====
8576                 IF l_asgn_rec.location_country_code = G_PA_MISS_CHAR THEN
8577                         l_asgn_rec.location_country_code := null;
8578                 END IF;
8579 
8580                 IF l_asgn_rec.location_country_name = G_PA_MISS_CHAR THEN
8581                         l_asgn_rec.location_country_name := null;
8582                 END IF;
8583 
8584                 IF l_asgn_rec.location_region = G_PA_MISS_CHAR THEN
8585                         l_asgn_rec.location_region := null;
8586                 END IF;
8587 
8588                 IF l_asgn_rec.location_city = G_PA_MISS_CHAR THEN
8589                         l_asgn_rec.location_city := null;
8590                 END IF;
8591    		*/
8592 
8593 		IF l_asgn_rec.description = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8594                         l_asgn_rec.description := l_asgn_db_values_rec.description ;
8595 		ELSE
8596 			l_asgn_rec.description := SUBSTRB(l_asgn_rec.description,1,2000);
8597                 END IF;
8598 
8599 		IF l_asgn_rec.additional_information = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8600                         l_asgn_rec.additional_information := l_asgn_db_values_rec.additional_information ;
8601 		ELSE
8602 			l_asgn_rec.additional_information := SUBSTRB(l_asgn_rec.additional_information,1,2000) ;
8603                 END IF;
8604 
8605 	        -- These parameters are not For Update flow
8606 		l_asgn_rec.start_date := l_asgn_db_values_rec.start_date ;
8607 
8608 		l_asgn_rec.end_date := l_asgn_db_values_rec.end_date;
8609 
8610 		l_asgn_rec.status_code := l_asgn_db_values_rec.status_code;
8611 
8612 		l_asgn_rec.status_name := NULL ;
8613 
8614 		l_asgn_rec.calendar_type := NULL;
8615 
8616 		l_asgn_rec.calendar_id := l_asgn_db_values_rec.calendar_id;
8617 
8618 		l_asgn_rec.calendar_name  := NULL ;
8619 
8620 		IF l_asgn_rec.resource_calendar_percent = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8621                         l_asgn_rec.resource_calendar_percent  := l_asgn_db_values_rec.resource_calendar_percent ;
8622                 END IF;
8623 
8624 		IF l_asgn_rec.expenditure_type_class = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8625                         l_asgn_rec.expenditure_type_class := l_asgn_db_values_rec.expenditure_type_class ;
8626                 END IF;
8627 
8628 		IF l_asgn_rec.expenditure_type  = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8629                         l_asgn_rec.expenditure_type := l_asgn_db_values_rec.expenditure_type ;
8630                 END IF;
8631 
8632                 IF l_asgn_rec.work_type_id = G_PA_MISS_NUM THEN
8633                         IF l_asgn_rec.work_type_name = G_PA_MISS_CHAR THEN
8634                                 l_asgn_rec.work_type_id := l_asgn_db_values_rec.work_type_id;
8635                         ELSIF l_asgn_rec.work_type_name IS NULL THEN
8636                                 l_asgn_rec.work_type_id := null;
8637                         ELSE
8638                                 l_asgn_rec.work_type_id := null;
8639                         END IF;
8640                 END IF;
8641 
8642                 IF l_asgn_rec.work_type_name = G_PA_MISS_CHAR THEN
8643                         l_asgn_rec.work_type_name := null;
8644                 END IF;
8645 
8646 		IF l_asgn_rec.bill_rate_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8647                         l_asgn_rec.bill_rate_override := l_asgn_db_values_rec.bill_rate_override;
8648 		END IF;
8649 
8650 		IF l_asgn_rec.bill_rate_curr_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8651                         l_asgn_rec.bill_rate_curr_override := l_asgn_db_values_rec.bill_rate_curr_override;
8652                 END IF;
8653 
8654 		IF l_asgn_rec.markup_percent_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8655                         l_asgn_rec.markup_percent_override := l_asgn_db_values_rec.markup_percent_override;
8656                 END IF;
8657 
8658 		IF l_asgn_rec.discount_percentage = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8659                         l_asgn_rec.discount_percentage := l_asgn_db_values_rec.discount_percentage;
8660                 END IF;
8661 
8662 		IF l_asgn_rec.rate_disc_reason_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8663                         l_asgn_rec.rate_disc_reason_code := l_asgn_db_values_rec.rate_disc_reason_code;
8664                 END IF;
8665 
8666 		IF l_asgn_rec.tp_rate_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8667                         l_asgn_rec.tp_rate_override := l_asgn_db_values_rec.tp_rate_override;
8668                 END IF;
8669 
8670 		IF l_asgn_rec.tp_currency_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8671                         l_asgn_rec.tp_currency_override := l_asgn_db_values_rec.tp_currency_override;
8672                 END IF;
8673 
8674 		IF l_asgn_rec.tp_calc_base_code_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8675                         l_asgn_rec.tp_calc_base_code_override := l_asgn_db_values_rec.tp_calc_base_code_override;
8676                 END IF;
8677 
8678 		IF l_asgn_rec.tp_percent_applied_override = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8679                         l_asgn_rec.tp_percent_applied_override := l_asgn_db_values_rec.tp_percent_applied_override;
8680                 END IF;
8681 
8682 		IF l_asgn_rec.extension_possible = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8683                         l_asgn_rec.extension_possible := l_asgn_db_values_rec.extension_possible;
8684                 END IF;
8685 
8686 		IF l_asgn_rec.expense_owner = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8687                         l_asgn_rec.expense_owner := l_asgn_db_values_rec.expense_owner;
8688                 END IF;
8689 
8690 		IF l_asgn_rec.expense_limit = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8691                         l_asgn_rec.expense_limit := l_asgn_db_values_rec.expense_limit;
8692                 END IF;
8693 
8694 		IF l_asgn_rec.orig_system_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8695                         l_asgn_rec.orig_system_code := l_asgn_db_values_rec.orig_system_code;
8696                 END IF;
8697 
8698 		IF l_asgn_rec.orig_system_reference = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8699                         l_asgn_rec.orig_system_reference := l_asgn_db_values_rec.orig_system_reference;
8700                 END IF;
8701 
8702 		IF l_asgn_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
8703                         l_asgn_rec.record_version_number := l_asgn_db_values_rec.record_version_number;
8704                 END IF;
8705 
8706 		IF l_asgn_rec.attribute_category  = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8707                         l_asgn_rec.attribute_category := l_asgn_db_values_rec.attribute_category;
8708                 END IF;
8709 
8710 		IF l_asgn_rec.attribute1 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8711                         l_asgn_rec.attribute1 := l_asgn_db_values_rec.attribute1;
8712                 END IF;
8713 
8714 		IF l_asgn_rec.attribute2 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8715                         l_asgn_rec.attribute2 := l_asgn_db_values_rec.attribute2;
8716                 END IF;
8717 
8718 		IF l_asgn_rec.attribute3 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8719                         l_asgn_rec.attribute3 := l_asgn_db_values_rec.attribute3;
8720                 END IF;
8721 
8722 		IF l_asgn_rec.attribute4 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8723                         l_asgn_rec.attribute4 := l_asgn_db_values_rec.attribute4;
8724                 END IF;
8725 
8726                 IF l_asgn_rec.attribute5 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8727                         l_asgn_rec.attribute5 := l_asgn_db_values_rec.attribute5;
8728                 END IF;
8729 
8730                 IF l_asgn_rec.attribute6 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8731                         l_asgn_rec.attribute6 := l_asgn_db_values_rec.attribute6;
8732                 END IF;
8733 
8734                 IF l_asgn_rec.attribute7 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8735                         l_asgn_rec.attribute7 := l_asgn_db_values_rec.attribute7;
8736                 END IF;
8737 
8738                 IF l_asgn_rec.attribute8 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8739                         l_asgn_rec.attribute8 := l_asgn_db_values_rec.attribute8;
8740                 END IF;
8741 
8742                 IF l_asgn_rec.attribute9 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8743                         l_asgn_rec.attribute9 := l_asgn_db_values_rec.attribute9;
8744                 END IF;
8745 
8746 		IF l_asgn_rec.attribute10 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8747                         l_asgn_rec.attribute10 :=l_asgn_db_values_rec.attribute10;
8748                 END IF;
8749 
8750                 IF l_asgn_rec.attribute11 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8751                         l_asgn_rec.attribute11 := l_asgn_db_values_rec.attribute11;
8752                 END IF;
8753 
8754                 IF l_asgn_rec.attribute12 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8755                         l_asgn_rec.attribute12 :=l_asgn_db_values_rec.attribute12;
8756                 END IF;
8757 
8758                 IF l_asgn_rec.attribute13 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8759                         l_asgn_rec.attribute13 :=l_asgn_db_values_rec.attribute13;
8760                 END IF;
8761 
8762                 IF l_asgn_rec.attribute14 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8763                         l_asgn_rec.attribute14 := l_asgn_db_values_rec.attribute14;
8764                 END IF;
8765 
8766                 IF l_asgn_rec.attribute15 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
8767                         l_asgn_rec.attribute15 :=l_asgn_db_values_rec.attribute15;
8768                 END IF;
8769 
8770 
8771                 IF l_debug_mode = 'Y' THEN
8772                         pa_debug.write(l_module, 'After defaulting values ', l_log_level);
8773                         pa_debug.write(l_module, 'ProjectId is ' || l_asgn_db_values_rec.project_id, l_log_level);
8774                         pa_debug.write(l_module, 'DB Value of TeamTemplateFlag is ' ||l_asgn_db_values_rec.template_flag, l_log_level);
8775                         pa_debug.write(l_module, 'l_error_flag_local is '||l_error_flag_local, l_log_level);
8776                 END IF;
8777 
8778 		--------------------------------------------------------------------------------------------
8779 		-- Validation Of Param Values continues
8780 		--------------------------------------------------------------------------------------------
8781                 -- All validations are not required as some validation is done in underlying code
8782                 -- Here, we are doing only those validations which are not done internally.
8783 
8784                 IF l_error_flag_local <> 'Y' THEN
8785                         -- Project Assignment Flow
8786 
8787 			-------------------------------
8788 			-- Bill Rate Options Validation
8789                         -------------------------------
8790 
8791                         IF l_asgn_rec.bill_rate_option <> 'NONE' THEN
8792                                 l_rate_discount_reason_flag := 'N';
8793                                 l_br_override_flag := 'N';
8794                                 l_br_discount_override_flag := 'N';
8795 
8796                                 OPEN get_bill_rate_override_flags(l_asgn_rec.project_id);
8797                                 FETCH get_bill_rate_override_flags INTO  l_rate_discount_reason_flag, l_br_override_flag, l_br_discount_override_flag;
8798                                 CLOSE get_bill_rate_override_flags;
8799 
8800                                 IF l_debug_mode = 'Y' THEN
8801                                         pa_debug.write(l_module, 'Validating Bill Rate Options', l_log_level);
8802                                         pa_debug.write(l_module, 'l_rate_discount_reason_flag is '||l_rate_discount_reason_flag, l_log_level);
8803                                         pa_debug.write(l_module, 'l_br_override_flag is '||l_br_override_flag, l_log_level);
8804                                         pa_debug.write(l_module, 'l_br_discount_override_flag is '||l_br_discount_override_flag, l_log_level);
8805                                 END IF;
8806 
8807 				IF l_asgn_rec.bill_rate_option = 'RATE' THEN
8808                                         IF l_br_override_flag <> 'Y' OR l_asgn_rec.bill_rate_override <= 0 THEN /* OR l_asgn_rec.bill_rate_override > 100  - Removed for Bug 5703021*/
8809                                                 IF l_br_override_flag <> 'Y' THEN
8810                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
8811                                                         l_error_flag_local := 'Y';
8812                                                 ELSE
8813                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_BILL_RATE_OVRD');
8814                                                         l_error_flag_local := 'Y';
8815                                                 END IF;
8816                                         END IF;
8817                                         -- 5144288, 5144369 : Begin
8818                                         l_multi_currency_billing_flag := null;
8819                                         OPEN c_get_mcb_flag(l_asgn_rec.project_id);
8820                                         FETCH c_get_mcb_flag INTO l_multi_currency_billing_flag;
8821                                         CLOSE c_get_mcb_flag;
8822 
8823                                         IF nvl(l_multi_currency_billing_flag,'N') = 'Y' AND l_br_override_flag = 'Y' THEN
8824                                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
8825                                                 l_error_message_code := null;
8826                                                 l_bill_currency_override_tmp := l_asgn_rec.bill_rate_curr_override;
8827 
8828                                                 IF l_debug_mode = 'Y' THEN
8829                                                         pa_debug.write(l_module, 'Validating Bill Rate Currency', l_log_level);
8830                                                 END IF;
8831 
8832                                                 PA_PROJECTS_MAINT_UTILS.CHECK_CURRENCY_NAME_OR_CODE(
8833                                                         p_agreement_currency       => l_bill_currency_override_tmp
8834                                                         ,p_agreement_currency_name  => null
8835                                                         ,p_check_id_flag            => 'Y'
8836                                                         ,x_agreement_currency       => l_asgn_rec.bill_rate_curr_override
8837                                                         ,x_return_status            => l_return_status
8838                                                         ,x_error_msg_code           => l_error_message_code);
8839 
8840                                                 IF l_debug_mode = 'Y' THEN
8841                                                         pa_debug.write(l_module, 'After Bill Rate Currency Validation', l_log_level);
8842                                                         pa_debug.write(l_module, 'l_return_status='||l_return_status, l_log_level);
8843                                                         pa_debug.write(l_module, 'l_error_message_code='||l_error_message_code, l_log_level);
8844                                                 END IF;
8845 
8846                                                 IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
8847                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_CISI_CURRENCY_NULL');
8848                                                         l_error_flag_local := 'Y';
8849                                                 END IF;
8850                                         END IF;
8851                                         -- 5144288, 5144369 : End
8852                                 ELSIF l_asgn_rec.bill_rate_option = 'MARKUP' THEN
8853 					-- 5144675 Changed l_asgn_rec.markup_percent_override <=0 to  < 0
8854                                         IF l_br_override_flag <> 'Y' OR l_asgn_rec.markup_percent_override < 0
8855 					   OR l_asgn_rec.markup_percent_override > 100 THEN
8856                                                 IF l_br_override_flag <> 'Y' THEN
8857                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_BILL_RATE_OVRD_NA');
8858                                                         l_error_flag_local := 'Y';
8859                                                 ELSE
8860                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_MARKUP_PERCENT');
8861                                                         l_error_flag_local := 'Y';
8862                                                 END IF;
8863                                         END IF;
8864                                 ELSIF l_asgn_rec.bill_rate_option = 'DISCOUNT' THEN
8865 					-- 5144675 Changed l_asgn_rec.discount_percentage <= 0 to < 0
8866 					IF l_br_discount_override_flag <> 'Y' OR l_asgn_rec.discount_percentage < 0
8867 					   OR l_asgn_rec.discount_percentage > 100 THEN
8868                                                 IF l_br_discount_override_flag <> 'Y' THEN
8869                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_OVRD_NA');
8870                                                         l_error_flag_local := 'Y';
8871                                                 ELSE
8872                                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_DISCOUNT_PERCENT');
8873                                                         l_error_flag_local := 'Y';
8874                                                 END IF;
8875                                         END IF;
8876                                 END IF;
8877 
8878                                 IF l_asgn_rec.rate_disc_reason_code IS NULL THEN
8879                                         IF (l_rate_discount_reason_flag ='Y' AND (l_br_override_flag ='Y' OR l_br_discount_override_flag='Y') AND
8880                                                 (l_asgn_rec.bill_rate_override IS NOT NULL OR l_asgn_rec.markup_percent_override IS NOT NULL OR l_asgn_rec.discount_percentage IS NOT NULL)
8881                                            )
8882                                         THEN
8883                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_RATE_DISC_REASON_REQUIRED');
8884                                                 l_error_flag_local := 'Y';
8885                                         END IF;
8886                                 ELSE
8887 					l_valid_flag := 'N';
8888                                         OPEN c_get_lookup_exists('RATE AND DISCOUNT REASON', l_asgn_rec.rate_disc_reason_code);
8889                                         FETCH c_get_lookup_exists INTO l_valid_flag;
8890                                         CLOSE c_get_lookup_exists;
8891                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
8892                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_DISC_RSN_INVALID');
8893                                                 l_error_flag_local := 'Y';
8894                                         END IF;
8895                                 END IF;
8896 
8897                                 IF l_debug_mode = 'Y' THEN
8898                                         pa_debug.write(l_module, 'After Validating Bill Rate Options l_error_flag_local is '||l_error_flag_local, l_log_level);
8899                                 END IF;
8900                         END IF; -- l_asgn_rec.bill_rate_option <> 'NONE'
8901 
8902 			---------------------------------------------
8903 			-- Transfer Price Rate Options Validation
8904                         ---------------------------------------------
8905 
8906                         IF l_asgn_rec.tp_rate_option <> 'NONE' THEN
8907 
8908                                 IF l_debug_mode = 'Y' THEN
8909                                         pa_debug.write(l_module, 'Validating Transfer Price Rate Options', l_log_level);
8910                                 END IF;
8911 
8912                                 IF l_asgn_rec.tp_rate_option = 'RATE' THEN
8913                                         null; -- This validation is done internally
8914                                 ELSIF l_asgn_rec.tp_rate_option = 'BASIS' THEN
8915                                         IF l_debug_mode = 'Y' THEN
8916                                                 pa_debug.write(l_module, 'Validating Transfer Price Rate Basis', l_log_level);
8917                                         END IF;
8918 
8919                                         OPEN c_get_lookup_exists('CC_MARKUP_BASE_CODE', l_asgn_rec.tp_calc_base_code_override);
8920                                         FETCH c_get_lookup_exists INTO l_valid_flag;
8921                                         CLOSE c_get_lookup_exists;
8922 
8923                                         IF l_debug_mode = 'Y' THEN
8924                                                 pa_debug.write(l_module, 'After Transfer Price Rate Basis Validation', l_log_level);
8925                                                 pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
8926                                         END IF;
8927 
8928                                         IF nvl(l_valid_flag,'N') <> 'Y' THEN
8929                                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_TP_BASIS_INVALID');
8930                                                 l_error_flag_local := 'Y';
8931                                         END IF;
8932                                 END IF;
8933 
8934                                 IF l_debug_mode = 'Y' THEN
8935                                         pa_debug.write(l_module, 'After Validating Transfer Price Rate Options l_error_flag_local='||l_error_flag_local, l_log_level);
8936                                 END IF;
8937                         END IF; -- l_asgn_rec.tp_rate_option <> 'NONE'
8938 
8939 			---------------------------------------------
8940 			-- Res Loan Agreement Validations
8941 			---------------------------------------------
8942 			IF l_asgn_rec.expense_owner IS NOT NULL THEN
8943 				l_valid_flag := 'N';
8944 
8945                                 IF l_debug_mode = 'Y' THEN
8946                                         pa_debug.write(l_module, 'Validating Expense Owner Option', l_log_level);
8947                                 END IF;
8948 
8949                                 OPEN c_get_lookup_exists('EXPENSE_OWNER_TYPE', l_asgn_rec.expense_owner);
8950                                 FETCH c_get_lookup_exists INTO l_valid_flag;
8951                                 CLOSE c_get_lookup_exists;
8952 
8953                                 IF l_debug_mode = 'Y' THEN
8954                                         pa_debug.write(l_module, 'After Expense Owner Option Validation', l_log_level);
8955                                         pa_debug.write(l_module, 'l_valid_flag='||l_valid_flag, l_log_level);
8956                                 END IF;
8957 
8958                                 IF nvl(l_valid_flag,'N') <> 'Y' THEN
8959                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_EXP_OWNER_INVALID');
8960                                         l_error_flag_local := 'Y';
8961                                 END IF;
8962 			END IF;
8963 			IF l_debug_mode = 'Y' THEN
8964 	                        pa_debug.write(l_module, 'After all validations except flexfield l_error_flag_local='||l_error_flag_local, l_log_level);
8965 		        END IF;
8966 
8967 			-- Flex field Validation
8968 			------------------------
8969 
8970 			IF l_error_flag_local <> 'Y' THEN
8971 				l_return_status := FND_API.G_RET_STS_SUCCESS;
8972 
8973 				VALIDATE_FLEX_FIELD(
8974 					  p_desc_flex_name         => 'PA_TEAM_ROLE_DESC_FLEX'
8975 					, p_attribute_category     => l_asgn_rec.attribute_category
8976 					, px_attribute1            => l_asgn_rec.attribute1
8977 					, px_attribute2            => l_asgn_rec.attribute2
8978 					, px_attribute3            => l_asgn_rec.attribute3
8979 					, px_attribute4            => l_asgn_rec.attribute4
8980 					, px_attribute5            => l_asgn_rec.attribute5
8981 					, px_attribute6            => l_asgn_rec.attribute6
8982 					, px_attribute7            => l_asgn_rec.attribute7
8983 					, px_attribute8            => l_asgn_rec.attribute8
8984 					, px_attribute9            => l_asgn_rec.attribute9
8985 					, px_attribute10           => l_asgn_rec.attribute10
8986 					, px_attribute11           => l_asgn_rec.attribute11
8987 					, px_attribute12           => l_asgn_rec.attribute12
8988 					, px_attribute13           => l_asgn_rec.attribute13
8989 					, px_attribute14           => l_asgn_rec.attribute14
8990 					, px_attribute15           => l_asgn_rec.attribute15
8991 					, x_return_status          => l_return_status
8992 					, x_msg_count              => l_msg_count
8993 					, x_msg_data               => l_msg_data
8994 				 );
8995 
8996 				IF l_debug_mode = 'Y' THEN
8997 					pa_debug.write(l_module, 'After Flex Field Validation l_return_status='||l_return_status, l_log_level);
8998 					pa_debug.write(l_module, 'After Flex Field Validation l_msg_data='||l_msg_data, l_log_level);
8999 				END IF;
9000 
9001 				IF l_return_status <>  FND_API.G_RET_STS_SUCCESS  THEN
9002 					-- This message does not have toekn defined, still it is ok to pass token as the value
9003 					-- returned by flex APIs because token are appended as it is
9004 					PA_UTILS.ADD_MESSAGE('PA', 'PA_DFF_VALIDATION_FAILED',
9005 							      'MESSAGE', l_msg_data );
9006 					l_error_flag_local := 'Y';
9007 				END IF;
9008 			END IF;
9009 
9010 		END IF; -- End of Param Validations
9011 
9012 		-- Security Check
9013                 -----------------
9014                 -- The underlying API does security check of PA_ASN_BASIC_INFO_ED
9015                 -- , PA_CREATE_CANDIDATES, PA_ASN_FCST_INFO_ED
9016                 -- But still we need to do check here because there are some more checks required
9017                 -- Also the underlying API does not consider the MISS chars
9018 
9019 		----------- (1)
9020                 IF l_error_flag_local <> 'Y' AND nvl(l_asgn_db_values_rec.template_flag,'N') = 'N' THEN
9021                         -- Project Assignment
9022                         IF nvl(l_asgn_rec.assignment_name, 'XYZ') <> nvl(l_asgn_db_values_rec.assignment_name, 'XYZ')
9023                         OR nvl(l_asgn_rec.staffing_priority_code, 'XYZ') <> nvl(l_asgn_db_values_rec.staffing_priority_code, 'XYZ')
9024                         OR nvl(l_asgn_rec.staffing_owner_person_id, -1) <> nvl(l_asgn_db_values_rec.staffing_owner_person_id, -1)
9025                         OR nvl(l_asgn_rec.description, 'XYZ') <> nvl(l_asgn_db_values_rec.description, 'XYZ')
9026                         OR nvl(l_asgn_rec.additional_information, 'XYZ') <> nvl(l_asgn_db_values_rec.additional_information, 'XYZ')
9027                         OR nvl(l_asgn_rec.project_subteam_id, -1) <> nvl(l_project_subteam_id, -1)
9028                         OR nvl(l_asgn_rec.location_id, -1) <> nvl(l_asgn_db_values_rec.location_id, -1)
9029 			OR nvl(l_asgn_rec.attribute_category,'XX') <> nvl(l_asgn_db_values_rec.attribute_category,'XX')
9030 			OR nvl(l_asgn_rec.attribute1,'XX') <> nvl(l_asgn_db_values_rec.attribute1,'XX')
9031 			OR nvl(l_asgn_rec.attribute2,'XX') <> nvl(l_asgn_db_values_rec.attribute2,'XX')
9032 			OR nvl(l_asgn_rec.attribute3,'XX') <> nvl(l_asgn_db_values_rec.attribute3,'XX')
9033 			OR nvl(l_asgn_rec.attribute4,'XX') <> nvl(l_asgn_db_values_rec.attribute4,'XX')
9034 			OR nvl(l_asgn_rec.attribute5,'XX') <> nvl(l_asgn_db_values_rec.attribute5,'XX')
9035 			OR nvl(l_asgn_rec.attribute6,'XX') <> nvl(l_asgn_db_values_rec.attribute6,'XX')
9036 			OR nvl(l_asgn_rec.attribute7,'XX') <> nvl(l_asgn_db_values_rec.attribute7,'XX')
9037 			OR nvl(l_asgn_rec.attribute8,'XX') <> nvl(l_asgn_db_values_rec.attribute8,'XX')
9038 			OR nvl(l_asgn_rec.attribute9,'XX') <> nvl(l_asgn_db_values_rec.attribute9,'XX')
9039 			OR nvl(l_asgn_rec.attribute10,'XX') <> nvl(l_asgn_db_values_rec.attribute10,'XX')
9040 			OR nvl(l_asgn_rec.attribute11,'XX') <> nvl(l_asgn_db_values_rec.attribute11,'XX')
9041 			OR nvl(l_asgn_rec.attribute12,'XX') <> nvl(l_asgn_db_values_rec.attribute12,'XX')
9042 			OR nvl(l_asgn_rec.attribute13,'XX') <> nvl(l_asgn_db_values_rec.attribute13,'XX')
9043 			OR nvl(l_asgn_rec.attribute14,'XX') <> nvl(l_asgn_db_values_rec.attribute14,'XX')
9044 			OR nvl(l_asgn_rec.attribute15,'XX') <> nvl(l_asgn_db_values_rec.attribute15,'XX')
9045                         THEN
9046                                 l_basic_info_changed := 'Y';
9047                         END IF;
9048 
9049 
9050                         IF nvl(l_asgn_rec.extension_possible, 'XYZ') <> nvl(l_asgn_db_values_rec.extension_possible, 'XYZ')
9051                         OR nvl(l_asgn_rec.expense_owner, 'XYZ') <> nvl(l_asgn_db_values_rec.expense_owner, 'XYZ')
9052                         OR nvl(l_asgn_rec.expense_limit, -1) <> nvl(l_asgn_db_values_rec.expense_limit, -1)
9053                         OR nvl(l_asgn_rec.expenditure_type_class, 'XYZ') <> nvl(l_asgn_db_values_rec.expenditure_type_class, 'XYZ')
9054                         OR nvl(l_asgn_rec.expenditure_type, 'XYZ') <> nvl(l_asgn_db_values_rec.expenditure_type, 'XYZ')
9055                         OR nvl(l_asgn_rec.work_type_id, -1) <> nvl(l_asgn_db_values_rec.work_type_id, -1)
9056                         THEN
9057                                 l_fin_info_changed := 'Y';
9058                         END IF;
9059 
9060                         IF nvl(l_asgn_rec.bill_rate_override, -1) <> nvl(l_asgn_db_values_rec.bill_rate_override, -1)
9061                         OR nvl(l_asgn_rec.bill_rate_curr_override, 'XYZ') <> nvl(l_asgn_db_values_rec.bill_rate_curr_override, 'XYZ')
9062                         OR nvl(l_asgn_rec.markup_percent_override, -1) <> nvl(l_asgn_db_values_rec.markup_percent_override, -1)
9063                         OR nvl(l_asgn_rec.discount_percentage, -1) <> nvl(l_asgn_db_values_rec.discount_percentage, -1)
9064                         OR nvl(l_asgn_rec.rate_disc_reason_code, 'XYZ') <> nvl(l_asgn_db_values_rec.rate_disc_reason_code, 'XYZ')
9065                         THEN
9066                                 l_fin_bill_rate_info_changed := 'Y';
9067 			END IF;
9068 
9069 			IF nvl(l_asgn_rec.tp_rate_override, -1) <> nvl(l_asgn_db_values_rec.tp_rate_override, -1)
9070                         OR nvl(l_asgn_rec.tp_currency_override, 'XYZ') <> nvl(l_asgn_db_values_rec.tp_currency_override, 'XYZ')
9071                         OR nvl(l_asgn_rec.tp_percent_applied_override, -1) <> nvl(l_asgn_db_values_rec.tp_percent_applied_override, -1)
9072                         OR nvl(l_asgn_rec.tp_calc_base_code_override, 'XYZ') <> nvl(l_asgn_db_values_rec.tp_calc_base_code_override, 'XYZ')
9073                         THEN
9074                                 l_fin_tp_rate_info_changed := 'Y';
9075                         END IF;
9076 
9077                         IF l_basic_info_changed = 'Y' THEN
9078 
9079                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
9080                                 l_ret_code := 'T';
9081 
9082 				IF l_asgn_db_values_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
9083 
9084 					l_privilege := 'PA_ASN_BASIC_INFO_ED';
9085 				ELSIF l_asgn_db_values_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
9086 
9087 					l_privilege := 'PA_ADM_ASN_CR_AND_DL';
9088 				END IF;
9089 
9090                                 l_object_name := 'PA_PROJECTS';
9091                                 l_object_key := l_asgn_rec.project_id;
9092 
9093                                 IF l_debug_mode = 'Y' THEN
9094                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_BASIC_INFO_ED', l_log_level);
9095                                 END IF ;
9096 
9097 				l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9098                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9099                                           x_ret_code       => l_ret_code
9100                                         , x_return_status  => l_return_status
9101                                         , x_msg_count      => l_msg_count
9102                                         , x_msg_data       => l_msg_data
9103                                         , p_privilege      => l_privilege
9104                                         , p_object_name    => l_object_name
9105                                         , p_object_key     => l_object_key
9106                                         , p_init_msg_list  => FND_API.G_FALSE);
9107 				l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9108 
9109 				IF l_debug_mode = 'Y' THEN
9110                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_BASIC_INFO_ED l_ret_code '|| l_ret_code , l_log_level);
9111                                 END IF ;
9112 
9113 				IF nvl(l_ret_code, 'F') = 'F' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9114 					IF l_debug_mode = 'Y' THEN
9115                                                 pa_debug.write(l_module,'Checking Assignment Level Security for PA_ASN_BASIC_INFO_ED', l_log_level);
9116                                         END IF ;
9117 
9118                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9119                                         l_ret_code := 'T';
9120 
9121 					IF l_asgn_db_values_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
9122 
9123 						l_privilege := 'PA_ASN_BASIC_INFO_ED';
9124 					ELSIF l_asgn_db_values_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
9125 						l_privilege := 'PA_ADM_ASN_CR_AND_DL';
9126 					END IF;
9127 
9128                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
9129                                         l_object_key := l_asgn_rec.assignment_id;
9130 
9131 					l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9132  					PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9133                                                   x_ret_code       => l_ret_code
9134                                                 , x_return_status  => l_return_status
9135                                                 , x_msg_count      => l_msg_count
9136                                                 , x_msg_data       => l_msg_data
9137                                                 , p_privilege      => l_privilege
9138                                                 , p_object_name    => l_object_name
9139                                                 , p_object_key     => l_object_key
9140                                                 , p_init_msg_list  => FND_API.G_FALSE );
9141 					l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9142 
9143 					IF l_debug_mode = 'Y' THEN
9144                                                 pa_debug.write(l_module,'Assignment Level Security for PA_ASN_BASIC_INFO_ED l_ret_code='||l_ret_code, l_log_level);
9145                                         END IF ;
9146                                 END IF;
9147 
9148                                 IF nvl(l_ret_code,'F') <> 'T' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9149                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_UPD_ASGN_BASIC_INFO'
9150                                                       ,'MISSING_PRIVILEGE', l_privilege);
9151                                         l_error_flag_local := 'Y';
9152                                 END IF;
9153 			END IF; -- End If basic info changed
9154 
9155 			IF l_fin_info_changed = 'Y' OR l_fin_bill_rate_info_changed = 'Y' OR l_fin_tp_rate_info_changed = 'Y' THEN
9156 
9157                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
9158                                 l_ret_code := 'T';
9159 				IF l_asgn_db_values_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
9160 
9161 					l_privilege := 'PA_ASN_FCST_INFO_ED';
9162 				ELSIF l_asgn_db_values_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
9163 					l_privilege := 'PA_ADM_ASN_FCST_INFO_ED';
9164 				END IF;
9165 
9166                                 l_object_name := 'PA_PROJECTS';
9167                                 l_object_key := l_asgn_rec.project_id;
9168 
9169                                 IF l_debug_mode = 'Y' THEN
9170                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_FCST_INFO_ED', l_log_level);
9171                                 END IF ;
9172 
9173 				l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9174                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9175                                           x_ret_code       => l_ret_code
9176                                         , x_return_status  => l_return_status
9177                                         , x_msg_count      => l_msg_count
9178                                         , x_msg_data       => l_msg_data
9179                                         , p_privilege      => l_privilege
9180                                         , p_object_name    => l_object_name
9181                                         , p_object_key     => l_object_key
9182                                         , p_init_msg_list  => FND_API.G_FALSE);
9183 				l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9184 
9185                                 IF l_debug_mode = 'Y' THEN
9186                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_ED l_ret_code '|| l_ret_code , l_log_level);
9187                                 END IF ;
9188 
9189 				IF nvl(l_ret_code,'F') <> 'T' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9190                                         IF l_debug_mode = 'Y' THEN
9191                                                 pa_debug.write(l_module,'Checking Assignment Level Security for PA_CREATE_CANDIDATES', l_log_level);
9192                                         END IF ;
9193 
9194                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9195                                         l_ret_code := 'T';
9196 					IF l_asgn_db_values_rec.assignment_type = 'STAFFED_ASSIGNMENT' THEN
9197 
9198 						l_privilege := 'PA_ASN_FCST_INFO_ED';
9199 					ELSIF l_asgn_db_values_rec.assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
9200 						l_privilege := 'PA_ADM_ASN_FCST_INFO_ED';
9201 					END IF;
9202 
9203                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
9204                                         l_object_key := l_asgn_rec.assignment_id;
9205 
9206 					l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9207                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9208                                                   x_ret_code       => l_ret_code
9209                                                 , x_return_status  => l_return_status
9210                                                 , x_msg_count      => l_msg_count
9211                                                 , x_msg_data       => l_msg_data
9212                                                 , p_privilege      => l_privilege
9213                                                 , p_object_name    => l_object_name
9214                                                 , p_object_key     => l_object_key
9215                                                 , p_init_msg_list  => FND_API.G_FALSE );
9216 					l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9217 
9218 					IF l_debug_mode = 'Y' THEN
9219                                                 pa_debug.write(l_module,'Requirement Level Security for PA_ASN_FCST_INFO_ED l_ret_code='||l_ret_code, l_log_level);
9220                                         END IF ;
9221                                 END IF;
9222 
9223 				IF nvl(l_ret_code,'F') <> 'T' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9224                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_UPD_ASGN_FIN_INFO'
9225                                                       ,'MISSING_PRIVILEGE', l_privilege);
9226                                         l_error_flag_local := 'Y';
9227                                 END IF;
9228 
9229 			END IF; -- End If Financial Information changed
9230 
9231 			IF l_fin_bill_rate_info_changed = 'Y' THEN
9232 
9233                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
9234                                 l_ret_code := 'T';
9235                                 l_privilege := 'PA_ASN_FCST_INFO_BILL_ED';
9236                                 l_object_name := 'PA_PROJECTS';
9237                                 l_object_key := l_asgn_rec.project_id;
9238 
9239                                 IF l_debug_mode = 'Y' THEN
9240                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_FCST_INFO_BILL_ED', l_log_level);
9241                                 END IF ;
9242 
9243 				l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9244                                 PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9245                                           x_ret_code       => l_ret_code
9246                                         , x_return_status  => l_return_status
9247                                         , x_msg_count      => l_msg_count
9248                                         , x_msg_data       => l_msg_data
9249                                         , p_privilege      => l_privilege
9250                                         , p_object_name    => l_object_name
9251                                         , p_object_key     => l_object_key
9252                                         , p_init_msg_list  => FND_API.G_FALSE);
9253 				l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9254 
9255                                 IF l_debug_mode = 'Y' THEN
9256                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_BILL_ED l_ret_code '|| l_ret_code , l_log_level);
9257                                 END IF ;
9258 
9259                                 IF nvl(l_ret_code, 'F') = 'F' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9260 
9261                                         IF l_debug_mode = 'Y' THEN
9262                                                 pa_debug.write(l_module,'Checking Assignment Level Security for PA_ASN_FCST_INFO_BILL_ED', l_log_level);
9263                                         END IF ;
9264 
9265 					l_return_status := FND_API.G_RET_STS_SUCCESS;
9266                                         l_ret_code := 'T';
9267                                         l_privilege := 'PA_ASN_FCST_INFO_BILL_ED';
9268                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
9269                                         l_object_key :=  l_asgn_rec.assignment_id;
9270 
9271 					l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9272 					PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9273 						  x_ret_code       => l_ret_code
9274 						, x_return_status  => l_return_status
9275 						, x_msg_count      => l_msg_count
9276 						, x_msg_data       => l_msg_data
9277 						, p_privilege      => l_privilege
9278 						, p_object_name    => l_object_name
9279 						, p_object_key     => l_object_key
9280 						, p_init_msg_list  => FND_API.G_FALSE);
9281 					l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9282 
9283                                         IF l_debug_mode = 'Y' THEN
9284                                                 pa_debug.write(l_module,'Assignment Level Security for PA_ASN_FCST_INFO_BILL_ED l_ret_code='||l_ret_code, l_log_level);
9285                                         END IF ;
9286                                 END IF;
9287 
9288 				IF nvl(l_ret_code,'F') <> 'T' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9289                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_UPD_ASGN_BR_INFO'
9290                                                       ,'MISSING_PRIVILEGE', l_privilege);
9291                                         l_error_flag_local := 'Y';
9292                                 END IF;
9293 			END IF ; -- End If l_fin_bill_rate_info_changed
9294 
9295 			IF l_fin_tp_rate_info_changed = 'Y' THEN
9296 
9297                                 l_return_status := FND_API.G_RET_STS_SUCCESS;
9298                                 l_ret_code := 'T';
9299                                 l_privilege := 'PA_ASN_FCST_INFO_TP_ED';
9300                                 l_object_name := 'PA_PROJECTS';
9301                                 l_object_key := l_asgn_rec.project_id;
9302 
9303                                 IF l_debug_mode = 'Y' THEN
9304                                         pa_debug.write(l_module, 'Checking Project Level Security for PA_ASN_FCST_INFO_TP_ED', l_log_level);
9305                                 END IF ;
9306 
9307 				l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9308 				PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9309 					  x_ret_code       => l_ret_code
9310 					, x_return_status  => l_return_status
9311 					, x_msg_count      => l_msg_count
9312 					, x_msg_data       => l_msg_data
9313 					, p_privilege      => l_privilege
9314 					, p_object_name    => l_object_name
9315 					, p_object_key     => l_object_key
9316 					, p_init_msg_list  => FND_API.G_FALSE);
9317 				l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9318 
9319 				IF l_debug_mode = 'Y' THEN
9320                                         pa_debug.write(l_module, 'Project Level Security for PA_ASN_FCST_INFO_TP_ED l_ret_code '|| l_ret_code , l_log_level);
9321                                 END IF ;
9322 
9323                                 IF nvl(l_ret_code, 'F') = 'F' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9324 
9325                                         IF l_debug_mode = 'Y' THEN
9326                                                 pa_debug.write(l_module,'Checking Assignment Level Security for PA_ASN_FCST_INFO_TP_ED', l_log_level);
9327                                         END IF ;
9328 
9329                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9330                                         l_ret_code := 'T';
9331                                         l_privilege := 'PA_ASN_FCST_INFO_TP_ED';
9332                                         l_object_name := 'PA_PROJECT_ASSIGNMENTS';
9333                                         l_object_key := l_asgn_rec.assignment_id;
9334 
9335 					l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9336                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9337                                                   x_ret_code       => l_ret_code
9338                                                 , x_return_status  => l_return_status
9339                                                 , x_msg_count      => l_msg_count
9340                                                 , x_msg_data       => l_msg_data
9341                                                 , p_privilege      => l_privilege
9342                                                 , p_object_name    => l_object_name
9343                                                 , p_object_key     => l_object_key
9344                                                 , p_init_msg_list  => FND_API.G_FALSE );
9345 					l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9346 
9347 					IF l_debug_mode = 'Y' THEN
9348                                                 pa_debug.write(l_module,'Assignment Level Security for PA_ASN_FCST_INFO_TP_ED l_ret_code='||l_ret_code, l_log_level);
9349                                                 pa_debug.write(l_module,'Assignment Level Security for PA_ASN_FCST_INFO_TP_ED l_return_status='||l_return_status, l_log_level);
9350                                         END IF ;
9351                                 END IF;
9352 
9353                                 IF nvl(l_ret_code,'F') <> 'T' OR (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9354                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_UPD_ASGN_TP_INFO'
9355                                                       ,'MISSING_PRIVILEGE', l_privilege);
9356                                         l_error_flag_local := 'Y';
9357                                 END IF;
9358                         END IF;-- l_fin_tp_rate_info_changed = 'Y'
9359 
9360 		END IF; ----------- (1)
9361 
9362 		--------------------------------------------------------------------------------------
9363 		-- All Validations and Security checks are over at this point
9364 		-- Call Actual Core API
9365 		--------------------------------------------------------------------------------------
9366 		IF l_error_flag_local <> 'Y' THEN
9367                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9368 
9369                         IF l_debug_mode = 'Y' THEN
9370                                 pa_debug.write(l_module, 'Calling PA_ASSIGNMENTS_PUB.EXECUTE_UPDATE_ASSIGNMENT for Record No.'||i, l_log_level);
9371 			END IF;
9372 
9373 			l_before_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9374 
9375 			--Before calling API ,Make location_id as NULL
9376 			--If country code is made NULL
9377 
9378 			--This consistent with Update_Assignment API code in PARAPUBB.pls
9379 			IF (l_asgn_rec.location_country_code IS NULL
9380 			   AND l_asgn_rec.location_country_name IS NULL)
9381 			THEN
9382 				l_asgn_rec.location_id := NULL ;
9383 			END IF;
9384 
9385 			PA_ASSIGNMENTS_PUB.EXECUTE_UPDATE_ASSIGNMENT
9386 			(
9387 			  p_api_version                 => p_api_version_number
9388 			, p_init_msg_list               => l_init_msg_list
9389 			, p_commit                      => l_commit
9390 			, p_validate_only               => l_validate_only
9391 			, p_asgn_update_mode            => l_asgn_update_mode
9392 			, p_assignment_id 		=> l_asgn_rec.assignment_id
9393 			, p_record_version_number	=> l_asgn_rec.record_version_number
9394 			, p_assignment_name		=> l_asgn_rec.assignment_name
9395 			, p_assignment_type		=> l_asgn_rec.assignment_type
9396 			, p_multiple_status_flag	=> l_asgn_db_values_rec.multiple_status_flag
9397 			, p_project_status_name		=> l_asgn_rec.status_name
9398 			, p_status_code			=> l_asgn_rec.status_code
9399 			, p_start_date			=> l_asgn_rec.start_date
9400 			, p_end_date			=> l_asgn_rec.end_date
9401 			, p_staffing_priority_code	=> l_asgn_rec.staffing_priority_code
9402 			, p_project_id			=> l_asgn_rec.project_id
9403 --			, p_assignment_template_id	=> l_asgn_rec.assignment_template_id
9404 			, p_project_role_id		=> l_asgn_rec.project_role_id
9405 			, p_project_subteam_id		=> l_asgn_rec.project_subteam_id
9406 			, p_project_subteam_party_id    => l_project_subteam_party_id
9407 			, p_description			=> l_asgn_rec.description
9408 --			, p_assignment_effort		=> l_asgn_rec.assignment_effort
9409 			, p_extension_possible		=> l_asgn_rec.extension_possible
9410 --			, p_source_assignment_id	=> l_asgn_rec.source_assignment_id
9411 --			, p_min_resource_job_level	=> l_asgn_rec.min_resource_job_level
9412 --			, p_max_resource_job_level	=> l_asgn_rec.max_resource_job_level
9413 --			, p_assignment_number		=> l_asgn_rec.assignment_number --
9414 			, p_additional_information	=> l_asgn_rec.additional_information
9415 			, p_location_id			=> l_asgn_rec.location_id
9416 			, p_work_type_id                => l_asgn_rec.work_type_id
9417 --			 ,p_revenue_currency_code       => l_asgn_rec.revenue_currency_code
9418 --			 ,p_revenue_bill_rate           => l_asgn_rec.revenue_bill_rate
9419 --			 ,p_markup_percent              => l_asgn_rec.markup_percent
9420 			 ,p_expense_owner               => l_asgn_rec.expense_owner
9421 			 ,p_expense_limit               => l_asgn_rec.expense_limit
9422 --			 ,p_expense_limit_currency_code => l_asgn_rec.expense_limit_currency_code
9423 --			 ,p_fcst_tp_amount_type         => l_asgn_rec.fcst_tp_amount_type
9424 --			 ,p_fcst_job_id                 => l_asgn_rec.fcst_job_id
9425 --			 ,p_fcst_job_group_id           => l_asgn_rec.fcst_job_group_id
9426 --			 ,p_expenditure_org_id          => l_asgn_rec.expenditure_org_id
9427 --			 ,p_expenditure_organization_id => l_asgn_rec.expenditure_organization_id
9428 			 ,p_expenditure_type_class      => l_asgn_rec.expenditure_type_class
9429 			 ,p_expenditure_type            => l_asgn_rec.expenditure_type
9430 --			 ,p_project_number              =>
9431 --			 ,p_resource_name               =>
9432 --			 ,p_resource_source_id          =>
9433 			 ,p_resource_id                 => l_asgn_rec.resource_id
9434 			 ,p_project_subteam_name        => l_asgn_rec.project_subteam_name
9435 			 ,p_staffing_priority_name      => l_asgn_rec.staffing_priority_name
9436 --			 ,p_project_role_name           => l_asgn_rec.project_role_name
9437 			 ,p_location_city               => l_asgn_rec.location_city
9438 			 ,p_location_region             => l_asgn_rec.location_region
9439 --			 ,p_location_country_name       => l_asgn_rec.location_country_name
9440 			 ,p_location_country_code       => l_asgn_rec.location_country_code
9441 			 ,p_calendar_name               => l_asgn_rec.calendar_name
9442 			 ,p_calendar_id                 => l_asgn_rec.calendar_id
9443 			 ,p_work_type_name              => l_asgn_rec.work_type_name
9444 --			 ,p_fcst_job_name               =>
9445 --			 ,p_fcst_job_group_name
9446 --			 ,p_expenditure_org_name
9447 --			 ,p_exp_organization_name
9448 --			 ,p_comp_match_weighting
9449 --			 ,p_avail_match_weighting
9450 --			 ,p_job_level_match_weighting
9451 --			 ,p_search_min_availability
9452 --			 ,p_search_country_code
9453 --			 ,p_search_country_name
9454 --			 ,p_search_exp_org_struct_ver_id
9455 --			 ,p_search_exp_org_hier_name
9456 --			 ,p_search_exp_start_org_id
9457 --			 ,p_search_exp_start_org_name
9458 --			 ,p_search_min_candidate_score
9459 --			 ,p_enable_auto_cand_nom_flag
9460 			 ,p_bill_rate_override          => l_asgn_rec.bill_rate_override
9461 			 ,p_bill_rate_curr_override     => l_asgn_rec.bill_rate_curr_override
9462 			 ,p_markup_percent_override     => l_asgn_rec.markup_percent_override
9463 			 ,p_discount_percentage         => l_asgn_rec.discount_percentage
9464 			 ,p_rate_disc_reason_code       => l_asgn_rec.rate_disc_reason_code
9465 			 ,p_tp_rate_override            => l_asgn_rec.tp_rate_override
9466 			 ,p_tp_currency_override        => l_asgn_rec.tp_currency_override
9467 			 ,p_tp_calc_base_code_override  => l_asgn_rec.tp_calc_base_code_override
9468 			 ,p_tp_percent_applied_override => l_asgn_rec.tp_percent_applied_override
9469 			 ,p_staffing_owner_person_id    => l_asgn_rec.staffing_owner_person_id
9470 --			 ,p_staffing_owner_name         =>
9471 --			 ,p_resource_list_member_id
9472 			 ,p_attribute_category          => l_asgn_rec.attribute_category
9473 			 ,p_attribute1                  => l_asgn_rec.attribute1
9474 			 ,p_attribute2                  => l_asgn_rec.attribute2
9475 			 ,p_attribute3                  => l_asgn_rec.attribute3
9476 			 ,p_attribute4                  => l_asgn_rec.attribute4
9477 			 ,p_attribute5                  => l_asgn_rec.attribute5
9478 			 ,p_attribute6                  => l_asgn_rec.attribute6
9479 			 ,p_attribute7                  => l_asgn_rec.attribute7
9480 			 ,p_attribute8                  => l_asgn_rec.attribute8
9481 			 ,p_attribute9                  => l_asgn_rec.attribute9
9482 			 ,p_attribute10                 => l_asgn_rec.attribute10
9483 			 ,p_attribute11                 => l_asgn_rec.attribute11
9484 			 ,p_attribute12                 => l_asgn_rec.attribute12
9485 			 ,p_attribute13                 => l_asgn_rec.attribute13
9486 			 ,p_attribute14                 => l_asgn_rec.attribute14
9487 			 ,p_attribute15                 => l_asgn_rec.attribute15
9488 			 ,x_return_status               => l_return_status
9489 			 ,x_msg_count                   => l_msg_count
9490 			 ,x_msg_data                    => l_msg_data
9491 			);
9492 			l_after_api_msg_count :=  FND_MSG_PUB.COUNT_MSG;
9493 
9494 			IF l_debug_mode = 'Y' THEN
9495 				pa_debug.write(l_module, 'After call PA_ASSIGNMENTS_PUB.EXECUTE_UPDATE_ASSIGNMENT l_return_status='||l_return_status, l_log_level);
9496 			END IF;
9497 
9498 			IF (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
9499 				--l_error_flag := 'Y';
9500 				l_error_flag_local := 'Y';
9501 			ELSE
9502 				IF l_debug_mode = 'Y' THEN
9503 					pa_debug.write(l_module, 'Updating Original System Code and Reference', l_log_level);
9504 				END IF;
9505 
9506 				--IF l_asgn_rec.orig_system_code IS NOT NULL OR l_asgn_rec.orig_system_reference IS NOT NULL THEN
9507 				--	UPDATE PA_PROJECT_ASSIGNMENTS
9508 				--	SET orig_system_code = decode(l_asgn_rec.orig_system_code, null, orig_system_code, l_asgn_rec.orig_system_code)
9509 				--	, orig_system_reference = decode(l_asgn_rec.orig_system_reference, null, orig_system_reference, l_asgn_rec.orig_system_reference)
9510 				--	WHERE assignment_id = l_asgn_rec.assignment_id;
9511 				--END IF;
9512 
9513 				UPDATE PA_PROJECT_ASSIGNMENTS
9514 				SET	orig_system_code = l_asgn_rec.orig_system_code
9515 				,	orig_system_reference = l_asgn_rec.orig_system_reference
9516 				WHERE	assignment_id = l_asgn_rec.assignment_id;
9517 
9518 				IF l_debug_mode = 'Y' THEN
9519 					pa_debug.write(l_module, 'After Updating Original System Code and Reference', l_log_level);
9520 				END IF;
9521 			END IF;
9522 		END IF;
9523 
9524                 l_end_msg_count := FND_MSG_PUB.count_msg;
9525                 IF l_debug_mode = 'Y' THEN
9526                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
9527                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
9528                 END IF;
9529                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
9530 
9531                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
9532                         l_error_flag := 'Y';
9533 
9534                         IF l_debug_mode = 'Y' THEN
9535                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
9536                         END IF;
9537 
9538                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
9539                                 -- Always get from first location in stack i.e. l_start_msg_count+1
9540                                 -- Because stack moves down after delete
9541                                 FND_MSG_PUB.get (
9542                                         p_msg_index      => l_start_msg_count+1,
9543                                         p_encoded        => FND_API.G_FALSE,
9544                                         p_data           => l_data,
9545                                         p_msg_index_out  => l_msg_index_out );
9546 
9547                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
9548                                 -- Because stack moves down after delete
9549                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
9550 
9551                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
9552                                                 'RECORD_NO', i,
9553                                                 'MESSAGE', l_data);
9554                         END LOOP;
9555                         IF l_debug_mode = 'Y' THEN
9556                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
9557                         END IF;
9558                 END IF;
9559 
9560 	i := p_assignment_in_tbl.next(i);
9561 
9562 	END LOOP ;
9563 
9564         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
9565                 RAISE FND_API.G_EXC_ERROR;
9566         END IF;
9567 
9568         IF l_debug_mode = 'Y' THEN
9569                 PA_DEBUG.reset_curr_function;
9570         END IF;
9571 
9572         IF p_commit = FND_API.G_TRUE THEN
9573                 commit;
9574         END IF;
9575 EXCEPTION
9576 WHEN FND_API.G_EXC_ERROR THEN
9577         x_return_status := FND_API.G_RET_STS_ERROR;
9578         l_msg_count := FND_MSG_PUB.count_msg;
9579 
9580         IF p_commit = FND_API.G_TRUE THEN
9581                 ROLLBACK TO UPDATE_ASSIGNMENTS_SP;
9582 	END IF;
9583 
9584         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
9585                 PA_INTERFACE_UTILS_PUB.get_messages
9586                 ( p_encoded        => FND_API.G_FALSE
9587                 , p_msg_index      => 1
9588                 , p_msg_count      => l_msg_count
9589                 , p_msg_data       => l_msg_data
9590                 , p_data           => l_data
9591                 , p_msg_index_out  => l_msg_index_out);
9592 
9593                 x_msg_data := l_data;
9594                 x_msg_count := l_msg_count;
9595         ELSE
9596                 x_msg_count := l_msg_count;
9597         END IF;
9598 
9599         IF l_debug_mode = 'Y' THEN
9600                 Pa_Debug.reset_curr_function;
9601         END IF;
9602 
9603 WHEN OTHERS THEN
9604 
9605         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
9606         x_msg_data      := SUBSTRB(SQLERRM,1,240);
9607 
9608         IF p_commit = FND_API.G_TRUE THEN
9609                 ROLLBACK TO UPDATE_ASSIGNMENTS_SP;
9610         END IF;
9611 
9612         FND_MSG_PUB.add_exc_msg
9613         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
9614         , p_procedure_name      => 'UPDATE_ASSIGNMENTS'
9615         , p_error_text          => x_msg_data);
9616 
9617         x_msg_count     := FND_MSG_PUB.count_msg;
9618 
9619         IF l_debug_mode = 'Y' THEN
9620                 PA_DEBUG.reset_curr_function;
9621         END IF;
9622         RAISE;
9623 
9624 END UPDATE_ASSIGNMENTS ;
9625 -- Start of comments
9626 --	API name 	: DELETE_ASSIGNMENTS
9627 --	Type		: Public
9628 --	Pre-reqs	: None.
9629 --	Function	: This is a public API to deletes one or more assignments for one or more projects.
9630 --	Usage		: This API will be called from AMG.
9631 --	Parameters	:
9632 --	IN		:	p_commit		IN  VARCHAR2
9633 --					Identifier to commit the transaction.
9634 --					Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
9635 --				p_init_msg_list		IN  VARCHAR2
9636 --					Identifier to initialize the error message stack.
9637 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
9638 --				p_api_version_number	IN  NUMBER			Required
9639 --					To be compliant with Applications API coding standards.
9640 --				p_assignment_in_tbl	IN  ASSIGNMENT_IN_TBL_TYPE	Required
9641 --					Table of assignment records.
9642 --
9643 --					Please see the ASSIGNMENT_IN_TBL_TYPE datatype table.
9644 --	OUT		:	x_return_status		OUT VARCHAR2
9645 --					Indicates the return status of the API.
9646 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
9647 --				x_msg_count		OUT NUMBER
9648 --					Indicates the number of error messages in the message stack
9649 --				x_msg_data		OUT VARCHAR2
9650 --					Indicates the error message text if only one error exists
9651 --	History		:
9652 --                              01-Mar-2006 - vkadimes  - Created
9653 -- End of comments
9654 PROCEDURE DELETE_ASSIGNMENTS (
9655   p_commit                IN      VARCHAR2                :=      'F'
9656 , p_init_msg_list         IN      VARCHAR2                :=      'T'
9657 , p_api_version_number    IN      NUMBER                  :=      1.0
9658 , p_assignment_in_tbl     IN      ASSIGNMENT_IN_TBL_TYPE
9659 , x_return_status         OUT NOCOPY   VARCHAR2
9660 , x_msg_count             OUT NOCOPY   NUMBER
9661 , x_msg_data              OUT NOCOPY   VARCHAR2
9662 ) IS
9663 -- Debug Params
9664 l_debug_level           NUMBER          :=3;
9665 l_debug_mode            VARCHAR2(1)     :='N';
9666 l_module                VARCHAR2(255)   := 'PA_RES_MANAGEMENT_AMG_PUB.DELETE_ASSIGNMENTS';
9667 --Looping Params
9668 i                       NUMBER;
9669 -- pa_initialize calling  params
9670 l_calling_application           VARCHAR2(10)            := 'PLSQL';
9671 l_calling_module                VARCHAR2(10)            := 'AMG';
9672 l_check_id_flag                 VARCHAR2(1)             := 'Y';
9673 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
9674 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
9675 --Loop Params
9676 l_req_rec                       PA_RES_MANAGEMENT_AMG_PUB.ASSIGNMENT_IN_REC_TYPE;
9677 l_loop_msg_count                NUMBER                  :=0;
9678 l_start_msg_count               NUMBER                  :=0;
9679 l_end_msg_count                 NUMBER                  :=0;
9680 l_missing_params                VARCHAR2(1000);
9681 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
9682 l_ret_code                      VARCHAR2(1);
9683 -- Error Flags
9684 l_error_flag                    VARCHAR2(1)             := 'N';
9685 l_error_flag_local              VARCHAR2(1)             := 'N';
9686 
9687 l_assignment_type               VARCHAR2(30);
9688 l_status_code                   VARCHAR2(30);
9689 l_project_id                    NUMBER;
9690 l_assignment_template_id        NUMBER;
9691 l_system_status_code            VARCHAR2(30);
9692 l_assignment_row_id             ROWID;
9693 l_record_version_number         NUMBER;
9694 -- security check
9695 l_privilege                     VARCHAR2(30);
9696 l_object_name                   VARCHAR2(30);
9697 l_object_key                    NUMBER;
9698 l_error_message_code            VARCHAR2(30);
9699 l_assignment_number             NUMBER;
9700 -- Temp prams
9701 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
9702 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
9703 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
9704 l_msg_count                     NUMBER;
9705 l_msg_data                      VARCHAR2(2000);
9706 l_assignment_id                 NUMBER;
9707 l_data                          VARCHAR2(2000);
9708 l_msg_index_out                 NUMBER;
9709 l_resource_id                   NUMBER;
9710 l_start_date                    DATE ;
9711 l_mass_wf_in_progress_flag      VARCHAR2(1);
9712 l_apprvl_status_code		VARCHAR2(30);
9713 l_apprvl_sys_status_code	VARCHAR2(30);
9714 
9715 CURSOR CUR_ASSIGNMENT_DETAILS(l_assignment_id NUMBER ) IS
9716 SELECT ROWID , assignment_type, status_code, project_id, record_version_number, assignment_number,
9717 resource_id, start_date, mass_wf_in_progress_flag, apprvl_status_code
9718 FROM  pa_project_assignments
9719 WHERE assignment_id=l_assignment_id
9720 AND   assignment_type <> 'OPEN_ASSIGNMENT' ;
9721 
9722 CURSOR cur_get_system_status(l_status_code VARCHAR2 ) IS
9723 SELECT PROJECT_SYSTEM_STATUS_CODE
9724 FROM   pa_project_statuses
9725 WHERE  project_status_code = l_status_code ;
9726 
9727 BEGIN
9728 
9729         x_return_status := FND_API.G_RET_STS_SUCCESS;
9730 
9731         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
9732 
9733         IF l_debug_mode = 'Y' THEN
9734                 PA_DEBUG.set_curr_function(p_function => 'DELETE_ASSIGNMENTS', p_debug_mode => l_debug_mode);
9735         END IF;
9736 
9737         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
9738                 FND_MSG_PUB.initialize;
9739         END IF;
9740 
9741         IF p_commit = FND_API.G_TRUE THEN
9742                 savepoint DELETE_ASSIGNMENTS_SP;
9743         END IF;
9744 
9745         IF l_debug_mode = 'Y' THEN
9746                 pa_debug.write(l_module, 'Start of delete_assignments', l_debug_level);
9747         END IF;
9748 
9749         IF l_debug_mode = 'Y' THEN
9750                 pa_debug.write(l_module, 'Printing Input Parameters......', l_debug_level);
9751                 i := p_assignment_in_tbl.first;
9752                 WHILE i IS NOT NULL LOOP
9753                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').assignment_id'||p_assignment_in_tbl(i).assignment_id, l_debug_level);
9754                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').assignment_name'||p_assignment_in_tbl(i).assignment_name, l_debug_level);
9755                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').assignment_type'||p_assignment_in_tbl(i).assignment_type, l_debug_level);
9756                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_role_id'||p_assignment_in_tbl(i).project_role_id, l_debug_level);
9757                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_role_name'||p_assignment_in_tbl(i).project_role_name, l_debug_level);
9758                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_id'||p_assignment_in_tbl(i).project_id, l_debug_level);
9759                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_name'||p_assignment_in_tbl(i).project_name, l_debug_level);
9760                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_number'||p_assignment_in_tbl(i).project_number, l_debug_level);
9761                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').resource_id'||p_assignment_in_tbl(i).resource_id, l_debug_level);
9762                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').staffing_owner_person_id'||p_assignment_in_tbl(i).staffing_owner_person_id, l_debug_level);
9763                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').staffing_priority_code'||p_assignment_in_tbl(i).staffing_priority_code, l_debug_level);
9764                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').staffing_priority_name'||p_assignment_in_tbl(i).staffing_priority_name, l_debug_level);
9765                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_subteam_id'||p_assignment_in_tbl(i).project_subteam_id, l_debug_level);
9766                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').project_subteam_name'||p_assignment_in_tbl(i).project_subteam_name, l_debug_level);
9767                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_id'||p_assignment_in_tbl(i).location_id, l_debug_level);
9768                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_country_code'||p_assignment_in_tbl(i).location_country_code, l_debug_level);
9769                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_country_name'||p_assignment_in_tbl(i).location_country_name, l_debug_level);
9770                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_region'||p_assignment_in_tbl(i).location_region, l_debug_level);
9771                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').location_city'||p_assignment_in_tbl(i).location_city, l_debug_level);
9772                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').description'||p_assignment_in_tbl(i).description, l_debug_level);
9773                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').additional_information'||p_assignment_in_tbl(i).additional_information, l_debug_level);
9774                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').start_date'||p_assignment_in_tbl(i).start_date, l_debug_level);
9775                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').end_date'||p_assignment_in_tbl(i).end_date, l_debug_level);
9776                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').status_code'||p_assignment_in_tbl(i).status_code, l_debug_level);
9777                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').status_name'||p_assignment_in_tbl(i).status_name, l_debug_level);
9778                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').calendar_type'||p_assignment_in_tbl(i).calendar_type, l_debug_level);
9779                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').calendar_id'||p_assignment_in_tbl(i).calendar_id, l_debug_level);
9780                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').calendar_name'||p_assignment_in_tbl(i).calendar_name, l_debug_level);
9781                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').resource_calendar_percent'||p_assignment_in_tbl(i).resource_calendar_percent, l_debug_level);
9782                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expenditure_type_class'||p_assignment_in_tbl(i).expenditure_type_class, l_debug_level);
9783                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expenditure_type'||p_assignment_in_tbl(i).expenditure_type, l_debug_level);
9784                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').work_type_id'||p_assignment_in_tbl(i).work_type_id, l_debug_level);
9785                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').work_type_name'||p_assignment_in_tbl(i).work_type_name, l_debug_level);
9786                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').bill_rate_option'||p_assignment_in_tbl(i).bill_rate_option, l_debug_level);
9787                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').bill_rate_override'||p_assignment_in_tbl(i).bill_rate_override, l_debug_level);
9788                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').bill_rate_curr_override'||p_assignment_in_tbl(i).bill_rate_curr_override, l_debug_level);
9789                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').markup_percent_override'||p_assignment_in_tbl(i).markup_percent_override, l_debug_level);
9790                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').discount_percentage'||p_assignment_in_tbl(i).discount_percentage, l_debug_level);
9791                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').rate_disc_reason_code'||p_assignment_in_tbl(i).rate_disc_reason_code, l_debug_level);
9792                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_rate_option'||p_assignment_in_tbl(i).tp_rate_option, l_debug_level);
9793                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_rate_override'||p_assignment_in_tbl(i).tp_rate_override, l_debug_level);
9794                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_currency_override'||p_assignment_in_tbl(i).tp_currency_override, l_debug_level);
9795                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_calc_base_code_override'||p_assignment_in_tbl(i).tp_calc_base_code_override, l_debug_level);
9796                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').tp_percent_applied_override'||p_assignment_in_tbl(i).tp_percent_applied_override, l_debug_level);
9797                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').extension_possible'||p_assignment_in_tbl(i).extension_possible, l_debug_level);
9798                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expense_owner'||p_assignment_in_tbl(i).expense_owner, l_debug_level);
9799                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').expense_limit'||p_assignment_in_tbl(i).expense_limit, l_debug_level);
9800                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').orig_system_code'||p_assignment_in_tbl(i).orig_system_code, l_debug_level);
9801                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').orig_system_reference'||p_assignment_in_tbl(i).orig_system_reference, l_debug_level);
9802                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').record_version_number'||p_assignment_in_tbl(i).record_version_number, l_debug_level);
9803                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute_category'||p_assignment_in_tbl(i).attribute_category, l_debug_level);
9804                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute1'||p_assignment_in_tbl(i).attribute1, l_debug_level);
9805                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute2'||p_assignment_in_tbl(i).attribute2, l_debug_level);
9806                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute3'||p_assignment_in_tbl(i).attribute3, l_debug_level);
9807                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute4'||p_assignment_in_tbl(i).attribute4, l_debug_level);
9808                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute5'||p_assignment_in_tbl(i).attribute5, l_debug_level);
9809                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute6'||p_assignment_in_tbl(i).attribute6, l_debug_level);
9810                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute7'||p_assignment_in_tbl(i).attribute7, l_debug_level);
9811                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute8'||p_assignment_in_tbl(i).attribute8, l_debug_level);
9812                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute9'||p_assignment_in_tbl(i).attribute9, l_debug_level);
9813                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute10'||p_assignment_in_tbl(i).attribute10, l_debug_level);
9814                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute11'||p_assignment_in_tbl(i).attribute11, l_debug_level);
9815                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute12'||p_assignment_in_tbl(i).attribute12, l_debug_level);
9816                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute13'||p_assignment_in_tbl(i).attribute13, l_debug_level);
9817                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute14'||p_assignment_in_tbl(i).attribute14, l_debug_level);
9818                         pa_debug.write(l_module, 'p_assignment_in_tbl('||i||').attribute15'||p_assignment_in_tbl(i).attribute15, l_debug_level);
9819                         pa_debug.write(l_module, '------------------------------------------------------------------', l_debug_level);
9820                         i := p_assignment_in_tbl.next(i);
9821                 END LOOP;
9822         END IF;
9823 
9824         PA_STARTUP.INITIALIZE(
9825                   p_calling_application                 => l_calling_application
9826                 , p_calling_module                      => l_calling_module
9827                 , p_check_id_flag                       => l_check_id_flag
9828                 , p_check_role_security_flag            => l_check_role_security_flag
9829                 , p_check_resource_security_flag        => l_check_resource_security_flag
9830                 , p_debug_level                         => l_debug_level
9831                 );
9832 
9833         IF l_debug_mode = 'Y' THEN
9834                 pa_debug.write(l_module, 'After call of pa_startup.initialize', l_debug_level);
9835         END IF;
9836 
9837         i := p_assignment_in_tbl.first;
9838 
9839         WHILE i IS NOT NULL LOOP
9840 
9841                 l_error_flag_local := 'N';
9842                 l_missing_params := null;
9843                 l_req_rec := null;
9844 
9845                 l_start_msg_count := FND_MSG_PUB.count_msg;
9846 
9847                 l_req_rec := p_assignment_in_tbl(i);
9848 
9849                 IF l_debug_mode = 'Y' THEN
9850                         pa_debug.write(l_module, 'Record#'||i, l_debug_level);
9851                         pa_debug.write(l_module, '-----------------------------', l_debug_level);
9852                         pa_debug.write(l_module, 'NullOut parameters which are not required.', l_debug_level);
9853                 END IF;
9854 
9855                 -- Blank Out Required Parameters if not passed.
9856                 IF l_req_rec.assignment_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
9857                         l_req_rec.assignment_id := NULL  ;
9858                 END IF;
9859 
9860                 IF l_req_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
9861                         l_req_rec.record_version_number := NULL ;
9862                 END IF;
9863 
9864                 IF l_debug_mode = 'Y' THEN
9865                         pa_debug.write(l_module, 'Requirement_id is ' || l_req_rec.assignment_id,l_debug_level);
9866                         pa_debug.write(l_module, 'Record Version Number is ' || l_req_rec.record_version_number, l_debug_level);
9867                 END IF;
9868 
9869                 -- Mandatory Parameters Check
9870                 IF l_debug_mode = 'Y' THEN
9871                         pa_debug.write(l_module, 'Mandatory Parameter Validation Starts', l_debug_level);
9872                 END IF;
9873 
9874                 IF l_req_rec.assignment_id IS NULL THEN
9875                         l_missing_params := l_missing_params ||',ASSIGNMENT_ID';
9876                 END IF;
9877 
9878                 IF l_debug_mode = 'Y' THEN
9879                         pa_debug.write(l_module, 'Mandatory Parameter Validation Over. ',l_debug_level);
9880                         pa_debug.write(l_module, 'The missing parameters are '||l_missing_params, l_debug_level);
9881                 END IF;
9882 
9883                 IF l_missing_params IS NOT NULL THEN
9884                         l_error_flag_local := 'Y';
9885                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
9886                                                 'INVALID_PARAMS', l_missing_params);
9887                 END IF;
9888 
9889                 l_assignment_id := l_req_rec.assignment_id;
9890 		IF l_error_flag_local <> 'Y' THEN
9891 
9892 			OPEN CUR_ASSIGNMENT_DETAILS(l_assignment_id) ;
9893 			FETCH CUR_ASSIGNMENT_DETAILS INTO l_assignment_row_id, l_assignment_type, l_status_code, l_project_id,l_record_version_number, l_assignment_number, l_resource_id, l_start_date,l_mass_wf_in_progress_flag, l_apprvl_status_code;
9894 
9895 			IF CUR_ASSIGNMENT_DETAILS%NOTFOUND THEN
9896 				l_error_flag_local := 'Y';
9897 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
9898 							'INVALID_PARAMS', 'ASSIGNMENT_ID');
9899 			END IF;
9900 
9901 			CLOSE CUR_ASSIGNMENT_DETAILS;
9902 
9903 		END IF ;
9904 
9905                 IF l_error_flag_local <> 'Y' THEN
9906                         l_system_status_code := null;
9907                         OPEN cur_get_system_status(l_status_code);
9908                         FETCH cur_get_system_status INTO l_system_status_code ;
9909                         CLOSE cur_get_system_status;
9910 
9911 			OPEN cur_get_system_status(l_apprvl_status_code);
9912 			FETCH cur_get_system_status INTO l_apprvl_sys_status_code;
9913 			CLOSE cur_get_system_status;
9914                 END IF;
9915 
9916                 IF l_system_status_code  = 'STAFFED_ASGMT_CANCEL'
9917 		OR l_apprvl_sys_status_code IN ('ASGMT_APPRVL_SUBMITTED','ASGMT_APPRVL_CANCELED')
9918 		OR NVL(l_mass_wf_in_progress_flag,'N') = 'Y' THEN
9919 		--- Need more specific Generic Message.
9920                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
9921                         l_error_flag_local := 'Y';
9922                 END IF;
9923 
9924                 IF l_error_flag_local <> 'Y' THEN
9925 
9926                         IF l_debug_mode = 'Y' THEN
9927                                 pa_debug.write(l_module, 'Security check starts', l_debug_level);
9928                         END IF;
9929 
9930                         IF l_project_id IS NOT NULL THEN
9931                                 IF l_assignment_type = 'STAFFED_ASSIGNMENT' THEN
9932 
9933                                         l_privilege := 'PA_ASN_CR_AND_DL';
9934                                         l_object_name := 'PA_PROJECTS';
9935                                         l_object_key := l_project_id ;
9936 
9937                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9938                                         l_ret_code := 'T';
9939 
9940                                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
9941                                                   x_ret_code       => l_ret_code
9942                                                 , x_return_status  => l_return_status
9943                                                 , x_msg_count      => l_msg_count
9944                                                 , x_msg_data       => l_msg_data
9945                                                 , p_privilege      => l_privilege
9946                                                 , p_object_name    => l_object_name
9947                                                 , p_object_key     => l_object_key
9948                                                 , p_init_msg_list   => FND_API.G_FALSE);
9949 
9950                                 ELSIF l_assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
9951 
9952                                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9953                                         l_ret_code := 'T';
9954 
9955                                         PA_SECURITY_PVT.CHECK_CONFIRM_ASMT(
9956                                                   p_project_id     => l_project_id
9957                                                 , p_resource_id    => l_resource_id
9958                                                 , p_resource_name  => null
9959                                                 , p_privilege      => 'PA_ADM_ASN_CONFIRM'
9960                                                 , p_start_date     => l_start_date
9961                                                 , x_ret_code       => l_ret_code
9962                                                 , x_return_status  => l_return_status
9963                                                 , x_msg_count      => l_msg_count
9964                                                 , x_msg_data       => l_msg_data
9965                                                 , p_init_msg_list  => FND_API.G_FALSE);
9966                                 END IF;
9967                         ELSE
9968                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
9969                                 raise FND_API.G_EXC_ERROR;
9970                         END IF;
9971 
9972                         IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9973                                 -- This message does not have token defined, but intentionally putting token
9974                                 -- because we still want to show the privilege name which is missing
9975                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_CR_DL'
9976                                                       ,'MISSING_PRIVILEGE', l_privilege);
9977                                 l_error_flag_local := 'Y';
9978                         END IF;
9979                 END IF;
9980 
9981                 IF l_error_flag_local <> 'Y' THEN
9982 
9983                         l_return_status := FND_API.G_RET_STS_SUCCESS;
9984 
9985                         IF l_debug_mode = 'Y' THEN
9986                                 pa_debug.write(l_module, 'Calling PA_ASSIGNMENTS_PUB.DELETE_ASSIGNMENT for record number'||i, l_debug_level);
9987                         END IF;
9988 
9989                         PA_ASSIGNMENTS_PUB.DELETE_ASSIGNMENT (
9990                                   p_assignment_row_id      => l_assignment_row_id
9991                                 , p_assignment_id          => l_assignment_id
9992                                 , p_record_version_number  => l_record_version_number
9993                                 , p_assignment_type        => l_assignment_type
9994                                 , p_assignment_number      => l_assignment_number
9995                                 , p_commit                 => l_commit
9996                                 , p_validate_only          => l_validate_only
9997                                 , x_return_status          => l_return_status
9998                                 , x_msg_count              => l_msg_count
9999                                 , x_msg_data               => l_msg_data );
10000 
10001                         IF l_debug_mode = 'Y' THEN
10002                                 pa_debug.write(l_module, 'After call PA_ASSIGNMENTS_PUB.DELETE_ASSIGNMENT l_return_status='||l_return_status, l_debug_level);
10003                         END IF;
10004 
10005                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10006                                 l_error_flag_local := 'Y';
10007                         END IF;
10008                 END IF;
10009 
10010                 l_end_msg_count := FND_MSG_PUB.count_msg;
10011                 l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
10012 
10013                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
10014                         l_error_flag := 'Y';
10015 
10016                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
10017                                 -- Always get from first location in stack i.e. l_start_msg_count+1
10018                                 -- Because stack moves down after delete
10019                                 FND_MSG_PUB.get (
10020                                           p_msg_index      => l_start_msg_count+1
10021                                         , p_encoded        => FND_API.G_FALSE
10022                                         , p_data           => l_data
10023                                         , p_msg_index_out  => l_msg_index_out );
10024 
10025                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
10026                                 -- Because stack moves down after delete
10027                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
10028 
10029                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
10030                                                 'RECORD_NO', i,
10031                                                 'MESSAGE', l_data);
10032                         END LOOP;
10033                 END IF;
10034                 i := p_assignment_in_tbl.next(i);
10035         END LOOP;
10036 
10037         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
10038                 RAISE FND_API.G_EXC_ERROR;
10039         END IF;
10040 
10041         IF l_debug_mode = 'Y' THEN
10042                 PA_DEBUG.reset_curr_function;
10043         END IF;
10044 
10045         IF p_commit = FND_API.G_TRUE THEN
10046                 commit;
10047         END IF;
10048 
10049 EXCEPTION
10050 WHEN FND_API.G_EXC_ERROR THEN
10051         x_return_status := FND_API.G_RET_STS_ERROR;
10052         l_msg_count := FND_MSG_PUB.count_msg;
10053 
10054         IF p_commit = FND_API.G_TRUE THEN
10055                 ROLLBACK TO DELETE_ASSIGNMENTS_SP;
10056         END IF;
10057 
10058         IF cur_assignment_details%ISOPEN THEN
10059                 CLOSE cur_assignment_details ;
10060         END IF;
10061 
10062         IF cur_get_system_status%ISOPEN THEN
10063                 CLOSE cur_get_system_status ;
10064         END IF;
10065 
10066         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
10067                 PA_INTERFACE_UTILS_PUB.GET_MESSAGES (
10068                           p_encoded        => FND_API.G_FALSE
10069                         , p_msg_index      => 1
10070                         , p_msg_count      => l_msg_count
10071                         , p_msg_data       => l_msg_data
10072                         , p_data           => l_data
10073                         , p_msg_index_out  => l_msg_index_out);
10074 
10075                 x_msg_data := l_data;
10076                 x_msg_count := l_msg_count;
10077         ELSE
10078                 x_msg_count := l_msg_count;
10079         END IF;
10080 
10081         IF l_debug_mode = 'Y' THEN
10082                 Pa_Debug.reset_curr_function;
10083         END IF;
10084 
10085 WHEN OTHERS THEN
10086 
10087         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10088         x_msg_data      := SUBSTRB(SQLERRM,1,240);
10089 
10090         IF p_commit = FND_API.G_TRUE THEN
10091                 ROLLBACK TO DELETE_ASSIGNMENTS_SP;
10092         END IF;
10093 
10094         IF cur_assignment_details%ISOPEN THEN
10095                 CLOSE cur_assignment_details ;
10096         END IF;
10097 
10098         IF cur_get_system_status%ISOPEN THEN
10099                 CLOSE cur_get_system_status ;
10100         END IF;
10101 
10102         FND_MSG_PUB.add_exc_msg (
10103                   p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
10104                 , p_procedure_name      => 'DELETE_REQUIREMENTS'
10105                 , p_error_text          => x_msg_data);
10106 
10107         x_msg_count     := FND_MSG_PUB.count_msg;
10108 
10109         IF l_debug_mode = 'Y' THEN
10110                 PA_DEBUG.reset_curr_function;
10111         END IF;
10112         RAISE;
10113 
10114 END DELETE_ASSIGNMENTS;
10115 
10116 
10117 -- Start of comments
10118 --      API name        : SUBMIT_ASSIGNMENTS
10119 --      Type            : Public
10120 --      Pre-reqs        : None.
10121 --      Function        : This is a public API to submit/approve one or more assignments for one or more projects.
10122 --      Usage           : This API will be called from AMG.
10123 --      Parameters      :
10124 --      IN              :       p_commit                IN  VARCHAR2
10125 --                                      Identifier to commit the transaction.
10126 --                                      Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
10127 --                              p_init_msg_list         IN  VARCHAR2
10128 --                                      Identifier to initialize the error message stack.
10129 --                                      Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
10130 --                              p_api_version_number    IN  NUMBER                      Required
10131 --                                      To be compliant with Applications API coding standards.
10132 --				p_submit_assignment_id_tbl  IN	SUBMIT_ASSIGNMENT_IN_TBL_TYPE  Required
10133 --					Table of assignment records. Please see the SUBMIT_ASSIGNMENT_IN_TBL_TYPE
10134 --					datatype table.
10135 --	OUT             :
10136 --                              x_return_status                 OUT VARCHAR2
10137 --                                      Indicates the return status of the API.
10138 --                                      Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
10139 --                              x_msg_count                     OUT NUMBER
10140 --                                      Indicates the number of error messages in the message stack
10141 --                              x_msg_data                      OUT VARCHAR2
10142 --                                      Indicates the error message text if only one error exists
10143 --      History         :
10144 --
10145 --                              15-Mar-2006 - avaithia  - Created
10146 -- End of comments
10147 
10148 PROCEDURE SUBMIT_ASSIGNMENTS
10149 (
10150   p_api_version_number          IN              NUMBER   := 1.0
10151 , p_init_msg_list               IN              VARCHAR2 := FND_API.G_TRUE
10152 , p_commit                      IN              VARCHAR2 := FND_API.G_FALSE
10153 , p_submit_assignment_in_tbl    IN              SUBMIT_ASSIGNMENT_IN_TBL_TYPE
10154 , x_return_status               OUT     NOCOPY  VARCHAR2
10155 , x_msg_count                   OUT     NOCOPY  NUMBER
10156 , x_msg_data                    OUT     NOCOPY  VARCHAR2
10157 )
10158 IS
10159 l_calling_application           VARCHAR2(10)            := 'PLSQL';
10160 l_calling_module                VARCHAR2(10)            := 'AMG';
10161 l_check_id_flag                 VARCHAR2(1)             := 'Y';
10162 l_check_role_security_flag      VARCHAR2(1)             := 'Y';
10163 l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
10164 
10165 l_log_level                     NUMBER                  := 3;
10166 l_module                        VARCHAR2(100)           := 'PA_RES_MANAGEMENT_AMG_PUB.SUBMIT_ASSIGNMENTS';
10167 l_commit                        VARCHAR2(1)             := FND_API.G_FALSE;
10168 l_init_msg_list                 VARCHAR2(1)             := FND_API.G_FALSE;
10169 
10170 l_msg_count                     NUMBER;
10171 l_msg_data                      VARCHAR2(2000);
10172 l_msg_index_out                 NUMBER;
10173 l_data                          VARCHAR2(2000);
10174 l_debug_mode                    VARCHAR2(1);
10175 
10176 i                               NUMBER;
10177 
10178 l_asgn_rec                      SUBMIT_ASSIGNMENT_IN_REC_TYPE;
10179 l_assignment_id                 NUMBER;
10180 l_auto_approve                  VARCHAR2(1)             := 'N';
10181 l_apr_person_id_1               NUMBER;
10182 l_apr_person_id_2               NUMBER;
10183 l_note_to_approver              VARCHAR2(240);
10184 l_record_version_number         NUMBER;
10185 
10186 l_project_id                    NUMBER;
10187 l_resource_id                   NUMBER;
10188 l_start_date                    DATE;
10189 l_assignment_type               VARCHAR2(30);
10190 
10191 l_mass_wf_in_progress_flag      VARCHAR2(1);
10192 l_apprvl_status_code            VARCHAR2(30);
10193 l_apprvl_sys_status_code	VARCHAR2(30);
10194 
10195 l_out_new_assignment_flag       VARCHAR2(1) ;
10196 l_out_approval_required_flag    VARCHAR2(1) ;
10197 l_out_record_version_number     NUMBER;
10198 
10199 l_validate_only                 VARCHAR2(1)             := FND_API.G_FALSE;
10200 l_overcommitment_flag           VARCHAR2(1);
10201 l_conflict_group_id             NUMBER;
10202 
10203 l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
10204 l_error_flag                    VARCHAR2(1)             := 'N';
10205 l_error_flag_local              VARCHAR2(1)             := 'N';
10206 
10207 l_loop_msg_count                NUMBER                  :=0;
10208 l_start_msg_count               NUMBER                  :=0;
10209 l_end_msg_count                 NUMBER                  :=0;
10210 
10211 l_missing_params                VARCHAR2(1000);
10212 l_privilege                     VARCHAR2(30);
10213 l_object_name                   VARCHAR2(30);
10214 l_object_key                    NUMBER;
10215 l_error_message_code            VARCHAR2(30);
10216 l_ret_code                      VARCHAR2(1)             := FND_API.G_TRUE;
10217 
10218 l_before_api_msg_count          NUMBER;
10219 l_after_api_msg_count           NUMBER;
10220 
10221 l_full_name_apr1                VARCHAR2(240);
10222 l_sys_person_type_apr1          VARCHAR2(30);
10223 l_user_person_type_apr1         VARCHAR2(80);
10224 
10225 l_full_name_apr2                VARCHAR2(240);
10226 l_sys_person_type_apr2          VARCHAR2(30);
10227 l_user_person_type_apr2         VARCHAR2(80);
10228 
10229 l_valid 			VARCHAR2(1); -- Bug 5175869
10230 
10231 CURSOR c_valid_asgn_id(p_assignment_id IN NUMBER) IS
10232 SELECT project_id , resource_id,start_date,assignment_type,mass_wf_in_progress_flag ,apprvl_status_code,record_version_number
10233 FROM   pa_project_assignments
10234 WHERE  assignment_type <> 'OPEN_ASSIGNMENT'
10235   AND  assignment_id = p_assignment_id ;
10236 
10237 CURSOR get_person_type(p_person_id IN NUMBER) IS
10238 SELECT per.full_name, ppt.SYSTEM_PERSON_TYPE , ppt.USER_PERSON_TYPE
10239 FROM per_all_people_f per , per_person_types ppt
10240 where per.person_type_id = ppt.person_type_id
10241 AND   per.person_id = p_person_id
10242 AND   per.effective_end_date = (SELECT MAX(pf.effective_end_date)
10243                           FROM per_all_people_f pf
10244                           WHERE pf.person_id = p_person_id);
10245 
10246 CURSOR c_sys_status_code(l_in_status_code IN VARCHAR2  ) IS
10247 SELECT project_system_status_code
10248 FROM  pa_project_statuses
10249 WHERE project_status_code = l_in_status_code
10250 AND status_type= 'ASGMT_APPRVL';
10251 
10252 BEGIN
10253         --------------------------------------------------
10254         -- RESET OUT params
10255         --------------------------------------------------
10256         x_return_status := FND_API.G_RET_STS_SUCCESS;
10257         x_msg_count := 0;
10258         x_msg_data := NULL ;
10259 
10260         --------------------------------------------------
10261         -- Initialize Current Function and Msg Stack
10262         --------------------------------------------------
10263         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
10264 
10265         IF l_debug_mode = 'Y' THEN
10266                 PA_DEBUG.set_curr_function(p_function => 'SUBMIT_ASSIGNMENTS', p_debug_mode => l_debug_mode);
10267         END IF;
10268 
10269         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
10270                 FND_MSG_PUB.initialize;
10271         END IF;
10272         --------------------------------------------------
10273         -- Create Savepoint
10274         --------------------------------------------------
10275         IF p_commit = FND_API.G_TRUE THEN
10276                 savepoint SUBMIT_ASSIGNMENTS_SP;
10277         END IF;
10278 
10279         IF l_debug_mode = 'Y' THEN
10280                 pa_debug.write(l_module, 'Start of SUBMIT_ASSIGNMENTS', l_log_level);
10281         END IF;
10282         --------------------------------------------------
10283         -- Start Initialize
10284         --------------------------------------------------
10285         PA_STARTUP.INITIALIZE(
10286                   p_calling_application => l_calling_application
10287                 , p_calling_module => l_calling_module
10288                 , p_check_id_flag => l_check_id_flag
10289                 , p_check_role_security_flag => l_check_role_security_flag
10290                 , p_check_resource_security_flag => l_check_resource_security_flag
10291                 , p_debug_level => l_log_level
10292                 );
10293 
10294         IF l_debug_mode = 'Y' THEN
10295                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
10296         END IF;
10297         --------------------------------------------------
10298         -- Defaulting Values and Mandatory param validations
10299         -- Security Check
10300         -- Core Logic
10301         --------------------------------------------------
10302         i := p_submit_assignment_in_tbl.first;
10303         WHILE i is not NULL LOOP
10304                 l_error_flag_local := 'N';
10305                 l_missing_params := null;
10306                 l_asgn_rec := NULL ;
10307 
10308                 l_start_msg_count := FND_MSG_PUB.count_msg;
10309 
10310                 l_asgn_rec := p_submit_assignment_in_tbl(i);
10311 
10312                 -- Blank Out Parameters if not passed.
10313 
10314                 IF l_asgn_rec.assignment_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
10315                         l_asgn_rec.assignment_id := NULL ;
10316                 END IF;
10317 
10318                 IF l_asgn_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
10319                         l_asgn_rec.record_version_number := NULL ;
10320                 END IF;
10321 
10322                 IF l_asgn_rec.auto_approve = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
10323                         l_asgn_rec.auto_approve := NULL ;
10324                 END IF;
10325 
10326                 IF l_asgn_rec.apr_person_id_1 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
10327                         l_asgn_rec.apr_person_id_1 := NULL ;
10328                 END IF;
10329 
10330                 IF l_asgn_rec.apr_person_id_2 = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
10331                         l_asgn_rec.apr_person_id_2 := NULL ;
10332                 END IF;
10333 
10334                 IF l_asgn_rec.note_to_approver = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
10335                         l_asgn_rec.note_to_approver := NULL ;
10336                 END IF;
10337 
10338                 l_assignment_id := l_asgn_rec.assignment_id ;
10339                 l_record_version_number := l_asgn_rec.record_version_number ;
10340                 l_auto_approve := l_asgn_rec.auto_approve;
10341                 l_apr_person_id_1 := l_asgn_rec.apr_person_id_1 ;
10342                 l_apr_person_id_2 := l_asgn_rec.apr_person_id_2 ;
10343                 l_note_to_approver := l_asgn_rec.note_to_approver ;
10344 
10345                 IF l_debug_mode = 'Y' THEN
10346                         pa_debug.write(l_module, 'Assignment Id ' || l_assignment_id,l_log_level);
10347                         pa_debug.write(l_module, 'Record Version Number is ' ||l_record_version_number,l_log_level);
10348                         pa_debug.write(l_module, 'Auto Approve is ' ||l_auto_approve,l_log_level);
10349                         pa_debug.write(l_module, 'Approve Person Id 1 is ' || l_apr_person_id_1,l_log_level);
10350                         pa_debug.write(l_module, 'Approve Person Id 2 is ' || l_apr_person_id_2,l_log_level);
10351                         pa_debug.write(l_module, 'Note to Approver is ' || l_note_to_approver,l_log_level);
10352                 END IF;
10353 
10354                 -- Mandatory Parameters Check
10355                 IF l_debug_mode = 'Y' THEN
10356                         pa_debug.write(l_module, 'Mandatory Parameter Validation Starts', l_log_level);
10357                 END IF;
10358 
10359                 IF l_asgn_rec.assignment_id IS NULL THEN
10360                         l_missing_params := l_missing_params||'ASSIGNMENT_ID ' ;
10361                 END IF;
10362 
10363                 IF l_asgn_rec.record_version_number IS NULL THEN
10364                         l_missing_params := l_missing_params||', RECORD_VERSION_NUMBER ' ;
10365                 END IF;
10366 
10367                 IF l_asgn_rec.auto_approve IS NULL THEN
10368                         l_missing_params := l_missing_params||', AUTO_APPROVE ' ;
10369                 END IF;
10370 
10371                 IF l_debug_mode = 'Y' THEN
10372                         pa_debug.write(l_module, 'Mandatory Parameter Validation Over. ',l_log_level);
10373                         pa_debug.write(l_module, 'The missing parameters are '||l_missing_params, l_log_level);
10374                 END IF;
10375 
10376                 IF l_missing_params IS NOT NULL THEN
10377                         l_error_flag_local := 'Y';
10378                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
10379                                                 'INVALID_PARAMS', l_missing_params);
10380                 END IF;
10381 
10382                 IF l_error_flag_local <> 'Y' THEN --------- (1)
10383                         l_assignment_id := l_asgn_rec.assignment_id ;
10384 
10385                         -- Validate whether the passed id is a valid one
10386                         OPEN c_valid_asgn_id(l_assignment_id) ;
10387                         FETCH c_valid_asgn_id into l_project_id ,l_resource_id,l_start_date,l_assignment_type,l_mass_wf_in_progress_flag ,l_apprvl_status_code,l_record_version_number;
10388                         IF c_valid_asgn_id%NOTFOUND THEN
10389                                 l_missing_params := l_missing_params||' ,ASSIGNMENT_ID' ;
10390                                 l_error_flag_local := 'Y';
10391                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
10392                                                         'INVALID_PARAMS', l_missing_params);
10393                         ELSE -- The passed Id is a valid assignment
10394 
10395                                 IF nvl(l_mass_wf_in_progress_flag,'N') = 'Y' THEN
10396                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_ASSIGNMENT_WF');
10397                                         l_error_flag_local := 'Y';
10398                                 END IF;
10399 
10400 				OPEN c_sys_status_code(l_apprvl_status_code);
10401 				FETCH c_sys_status_code INTO l_apprvl_sys_status_code ;
10402 				CLOSE c_sys_status_code ;
10403 
10404                                 IF l_apprvl_sys_status_code in ('ASGMT_APPRVL_CANCELED','ASGMT_APPRVL_SUBMITTED','ASGMT_APPRVL_APPROVED')
10405                                 THEN
10406                                         -- We can submit only if the approval status is Working or Requires resubmission
10407                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
10408                                         l_error_flag_local := 'Y'; -- Modify above new err msg for Approved also
10409                                 END IF;
10410                         END IF;
10411                         CLOSE c_valid_asgn_id ;
10412 
10413                         -- Validate the flag value passed for Auto Approve
10414                         IF l_asgn_rec.auto_approve not in ('Y','N') THEN
10415                                 l_error_flag_local := 'Y';
10416                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS','INVALID_PARAMS','AUTO_APPROVE');
10417                         END IF;
10418                         --------------------------------------------------------
10419                         --  Derive x_new_assignment_flag and x_approval_required
10420                         --------------------------------------------------------
10421 
10422                         IF l_error_flag_local <> 'Y' THEN
10423 
10424                         IF l_debug_mode = 'Y' THEN
10425                                 pa_debug.write(l_module, 'Before Calling PA_ASSIGNMENT_APPROVAL_PUB.Populate_Changed_Items_Table for record number '||i, l_log_level);
10426                         END IF;
10427 
10428                         l_before_api_msg_count := FND_MSG_PUB.count_msg;
10429                         PA_ASSIGNMENT_APPROVAL_PUB.Populate_Changed_Items_Table
10430                         (
10431                                  p_assignment_id => l_assignment_id
10432                                 ,x_new_assignment_flag => l_out_new_assignment_flag
10433                                 ,x_approval_required_flag => l_out_approval_required_flag
10434                                 ,x_record_version_number => l_out_record_version_number
10435                                 ,x_return_status => l_return_status
10436                                 ,x_msg_count     => l_msg_count
10437                                 ,x_msg_data      => l_msg_data
10438                         );
10439 
10440                         l_after_api_msg_count := FND_MSG_PUB.count_msg;
10441                         -- Dont rely on l_return_status as inside above API
10442                         -- IF no of msgs in stack is  > 0 ,they set it as error
10443                         -- So, Just rely on (l_after_api_msg_count - l_before_api_msg_count) value
10444 
10445                         IF (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
10446                                 l_error_flag_local := 'Y';
10447                                 -- PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
10448                         END IF;
10449 
10450                         END IF;
10451                         ------------------------------------------------------------------
10452                         -- If Populate_Changed_Items_Table is successful ,proceed further
10453                         ------------------------------------------------------------------
10454                         IF l_error_flag_local <> 'Y' THEN --------- (2)
10455 
10456                                 IF l_debug_mode = 'Y' THEN
10457                                         pa_debug.write(l_module, 'Populate_Changed_Items_Table is successful',l_log_level)
10458 ;
10459                                 END IF;
10460 
10461                                 IF l_auto_approve = 'Y' THEN
10462                                         -- Check for resource authority
10463                                         IF l_assignment_type = 'STAFFED_ASSIGNMENT' THEN
10464 
10465                                                 IF l_debug_mode = 'Y' THEN
10466                                                         pa_debug.write(l_module, 'Checking for PA_ASN_CONFIRM privilege',l_log_level);
10467                                                 END IF;
10468 
10469                                                 pa_security_pvt.check_confirm_asmt
10470                                                 (p_project_id => l_project_id
10471                                                 ,p_resource_id => l_resource_id
10472                                                 ,p_resource_name => null
10473                                                 ,p_privilege => 'PA_ASN_CONFIRM'
10474                                                 ,p_start_date => l_start_date
10475 						,p_init_msg_list   => 'F'
10476                                                 ,x_ret_code => l_ret_code
10477                                                 ,x_return_status => l_return_status
10478                                                 ,x_msg_count     => l_msg_count
10479                                                 ,x_msg_data      => l_msg_data
10480                                                 );
10481                                         ELSIF l_assignment_type = 'STAFFED_ADMIN_ASSIGNMENT' THEN
10482 
10483                                                 IF l_debug_mode = 'Y' THEN
10484                                                         pa_debug.write(l_module, 'Checking for PA_ADM_ASN_CONFIRM privilege',l_log_level);
10485                                                 END IF;
10486 
10487                                                 pa_security_pvt.check_confirm_asmt
10488                                                  (p_project_id => l_project_id
10489                                                  ,p_resource_id => l_resource_id
10490                                                  ,p_resource_name => null
10491                                                  ,p_privilege => 'PA_ADM_ASN_CONFIRM'
10492                                                  ,p_start_date => l_start_date
10493 						 ,p_init_msg_list   => 'F'
10494                                                  ,x_ret_code => l_ret_code
10495                                                  ,x_return_status => l_return_status
10496                                                  ,x_msg_count     => l_msg_count
10497                                                  ,x_msg_data      => l_msg_data
10498                                                 );
10499                                         END IF;
10500 
10501                                         IF  l_ret_code = FND_API.G_FALSE AND l_out_approval_required_flag = 'N'  THEN
10502 
10503                                                 IF l_debug_mode = 'Y' THEN
10504                                                         pa_debug.write(l_module, 'Populating PA_ASGN_CONFIRM_NOT_ALLOWED',l_log_level);
10505                                                 END IF;
10506 
10507                                                 l_error_flag_local := 'Y';
10508                                                 PA_UTILS.Add_Message ( 'PA','PA_ASGN_CONFIRM_NOT_ALLOWED');
10509                                                 -- Can we use PA_ASGN_CONFIRM_NOT_ALLOWED
10510                                                 -- In TAD its given as PA_NO_RESOURCE_AUTHORITY ,its not appropriate
10511                                         END IF;
10512 
10513                                         IF l_ret_code = FND_API.G_TRUE OR l_out_approval_required_flag ='Y' THEN
10514 
10515                                                 IF l_debug_mode = 'Y' THEN
10516                                                         pa_debug.write(l_module, 'Calling Start_Assignment_Approvals',l_log_level);
10517                                                 END IF;
10518 
10519                                                 l_before_api_msg_count := FND_MSG_PUB.count_msg;
10520 
10521                                                 -- Call API PA_ASSIGNMENT_APPROVAL_PUB.Start_Assignment_Approvals
10522                                                 PA_ASSIGNMENT_APPROVAL_PUB.Start_Assignment_Approvals
10523                                                 (
10524                                                  p_assignment_id => l_assignment_id
10525                                                 ,p_new_assignment_flag => 'N'
10526                                                 ,p_action_code => 'APPROVE'
10527                                                 ,p_note_to_approver => l_note_to_approver
10528                                                 ,p_record_version_number => l_record_version_number
10529                                                 ,p_validate_only => l_validate_only
10530                                                 ,x_overcommitment_flag => l_overcommitment_flag
10531                                                 ,x_conflict_group_id => l_conflict_group_id
10532                                                 ,x_return_status => l_return_status
10533                                                 ,x_msg_count => l_msg_count
10534                                                 ,x_msg_data => l_msg_data
10535                                                 );
10536                                                 l_after_api_msg_count := FND_MSG_PUB.count_msg;
10537 
10538                                                 IF l_debug_mode = 'Y' THEN
10539                                                         pa_debug.write(l_module, 'l_overcommitment_flag ' ||l_overcommitment_flag,l_log_level);
10540                                                         pa_debug.write(l_module, 'l_conflict_group_id ' ||l_conflict_group_id,l_log_level);
10541                                                         pa_debug.write(l_module, 'l_return_status ' ||l_return_status,l_log_level);
10542                                                 END IF;
10543 
10544                                                 IF (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
10545                                                         l_error_flag_local := 'Y';
10546                                                 -- Dont check l_return_status as internal API
10547                                                 -- sets return status as E if there are any msgs in stack
10548                                                 -- Even before this API is called.
10549 
10550                                                 END IF;
10551                                         END IF;
10552                                 ELSE    -- Auto Approve Flag is No
10553 
10554                                         OPEN get_person_type(l_apr_person_id_1);
10555                                         FETCH get_person_type INTO l_full_name_apr1 ,l_sys_person_type_apr1,l_user_person_type_apr1;
10556                                         IF get_person_type%NOTFOUND THEN
10557                                                 l_full_name_apr1 := NULL;
10558                                                 l_sys_person_type_apr1 := NULL ;
10559                                                 l_user_person_type_apr1 :=  NULL ;
10560                                         END IF;
10561                                         CLOSE get_person_type;
10562 
10563                                         OPEN get_person_type(l_apr_person_id_2);
10564                                         FETCH get_person_type INTO l_full_name_apr2,l_sys_person_type_apr2,l_user_person_type_apr2;
10565                                         IF get_person_type%NOTFOUND THEN
10566                                                 l_full_name_apr2 := NULL;
10567                                                 l_sys_person_type_apr2 := NULL ;
10568                                                 l_user_person_type_apr2 :=  NULL ;
10569                                         END IF;
10570                                         CLOSE get_person_type;
10571 
10572                                         -- Populate PA_NO_NON_EXCLUDED_APR if
10573                                         -- You are going to submit for approval
10574                                         -- and there are no approvers specified.
10575 
10576                                         IF (l_full_name_apr1 is NULL AND l_full_name_apr2 is NULL)
10577                                             OR
10578                                            (l_apr_person_id_1 is NULL AND l_apr_person_id_2 is NULL)
10579                                         THEN
10580                                                 l_error_flag_local := 'Y';
10581                                                 PA_UTILS.ADD_MESSAGE('PA','PA_NO_NON_EXCLUDED_APR');
10582                                         END IF;
10583 
10584 					-- Bug 5175869 : Start
10585 					IF l_apr_person_id_1 IS NOT NULL THEN
10586 						l_valid := 'N';
10587 						l_valid := IS_VALID_APPROVER(l_apr_person_id_1,l_resource_id,l_start_date);
10588 						IF l_valid = 'N' THEN
10589 							l_error_flag_local := 'Y';
10590                                                 	PA_UTILS.ADD_MESSAGE('PA','PA_INVALID_APPRVR'
10591 										,'APPROVER_ID',l_apr_person_id_1);
10592 						END IF;
10593 					END IF;
10594 
10595 					IF l_apr_person_id_2 IS NOT NULL THEN
10596 						l_valid := 'N';
10597                                                 l_valid := IS_VALID_APPROVER(l_apr_person_id_2,l_resource_id,l_start_date);
10598                                                 IF l_valid = 'N' THEN
10599                                                         l_error_flag_local := 'Y';
10600                                                         PA_UTILS.ADD_MESSAGE('PA','PA_INVALID_APPRVR'
10601                                                                                 ,'APPROVER_ID',l_apr_person_id_2);
10602 						END IF;
10603 					END IF;
10604 
10605 					-- Bug 5175869 : End
10606 
10607                                         IF (l_error_flag_local <> 'Y' AND l_apr_person_id_1 is NOT NULL) THEN
10608 
10609 						-- Added for Bug 5245870
10610 						-- If second approver is present then call the api with validate only parameter.
10611 						IF (l_apr_person_id_2 IS NOT NULL) THEN
10612 							l_validate_only := FND_API.G_TRUE;
10613 						ELSE
10614 							l_validate_only := FND_API.G_FALSE;
10615 						END IF;
10616 
10617                                         l_before_api_msg_count := FND_MSG_PUB.count_msg;
10618                                         PA_ASSIGNMENT_APPROVAL_PUB.Start_Assignment_Approvals
10619                                         (
10620                                          p_assignment_id => l_assignment_id
10621                                         ,p_new_assignment_flag => l_out_new_assignment_flag
10622                                         ,p_action_code => 'SUBMIT'
10623                                         ,p_note_to_approver => l_note_to_approver
10624                                         ,p_apr_person_id => l_apr_person_id_1
10625                                         ,p_apr_person_name => l_full_name_apr1
10626                                         ,p_apr_person_type => l_sys_person_type_apr1
10627                                         ,p_apr_person_order => 1
10628                                         ,p_apr_person_exclude => 'N'
10629                                         ,p_record_version_number => l_record_version_number
10630                                         ,p_validate_only => l_validate_only
10631                                         ,x_overcommitment_flag => l_overcommitment_flag
10632                                         ,x_conflict_group_id => l_conflict_group_id
10633                                         ,x_return_status => l_return_status
10634                                         ,x_msg_count => l_msg_count
10635                                         ,x_msg_data => l_msg_data
10636                                         );
10637                                 --l_apr_person_name1:= pa_resource_utils.get_person_name_no_date(l_apr_person_id_1);
10638                                 --l_apr_person_name2:=pa_resource_utils.get_person_name_no_date(l_apr_person_id_2);
10639 
10640                                         l_after_api_msg_count := FND_MSG_PUB.count_msg;
10641 
10642                                         IF l_debug_mode = 'Y' THEN
10643                                              pa_debug.write(l_module, 'l_overcommitment_flag ' ||l_overcommitment_flag,l_log_level);
10644                                              pa_debug.write(l_module, 'l_conflict_group_id ' ||l_conflict_group_id,l_log_level);
10645                                              pa_debug.write(l_module, 'l_return_status ' ||l_return_status,l_log_level);
10646                                         END IF;
10647 
10648                                         IF (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
10649                                             l_error_flag_local := 'Y';
10650                                                 -- Dont check l_return_status as internal API
10651                                                 -- sets return status as E if there are any msgs in stack
10652                                                 -- Even before this API is called.
10653                                         END IF;
10654 
10655                                         END IF; -- If no error and l_apr_person_id_1 is not null
10656 
10657                                         IF (l_error_flag_local <> 'Y' AND l_apr_person_id_2 IS NOT NULL) THEN
10658                                                 -- Call API for Approver 2
10659 						l_validate_only := FND_API.G_FALSE;  -- Added for Bug 5245870
10660                                                 l_before_api_msg_count := FND_MSG_PUB.count_msg;
10661                                                 PA_ASSIGNMENT_APPROVAL_PUB.Start_Assignment_Approvals
10662                                                 (
10663                                                 p_assignment_id => l_assignment_id
10664                                                 ,p_new_assignment_flag => l_out_new_assignment_flag
10665                                                 ,p_action_code => 'SUBMIT'
10666                                                 ,p_note_to_approver => l_note_to_approver
10667                                                 ,p_apr_person_id => l_apr_person_id_2
10668                                                 ,p_apr_person_name => l_full_name_apr2
10669                                                 ,p_apr_person_type => l_sys_person_type_apr2
10670 						,p_apr_person_order => 2       -- Changed for Bug 5245870 from 1 to 2
10671                                                 ,p_apr_person_exclude => 'N'
10672                                                 ,p_record_version_number => l_record_version_number
10673                                                 ,p_validate_only => l_validate_only
10674                                                 ,x_overcommitment_flag => l_overcommitment_flag
10675                                                 ,x_conflict_group_id => l_conflict_group_id
10676                                                 ,x_return_status => l_return_status
10677                                                 ,x_msg_count => l_msg_count
10678                                                 ,x_msg_data => l_msg_data
10679                                                 );
10680                                 --l_apr_person_name1:= pa_resource_utils.get_person_name_no_date(l_apr_person_id_1);
10681                                 --l_apr_person_name2:=pa_resource_utils.get_person_name_no_date(l_apr_person_id_2);
10682 
10683                                                 l_after_api_msg_count := FND_MSG_PUB.count_msg;
10684                                                 IF (l_after_api_msg_count - l_before_api_msg_count) > 0 THEN
10685                                                         l_error_flag_local := 'Y';
10686                                                         -- Dont check l_return_status as internal API
10687                                                         -- sets return status as E if there are any msgs in stack
10688                                                         -- Even before this API is called.
10689                                                 END IF;
10690                                         END IF;  -- If no error and l_apr_person_id_2 is not null
10691                                 END IF; -- End if Auto Approve Flag is Yes .
10692 
10693                         END IF; -- l_error_flag_local <> Y --------- (2)
10694                 END IF; -- l_error_flag_local <> Y --------- (1)
10695 
10696                 l_end_msg_count := FND_MSG_PUB.count_msg;
10697 
10698                 l_loop_msg_count := l_end_msg_count - l_start_msg_count;
10699 
10700                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
10701                         l_error_flag := 'Y';
10702 
10703                         IF l_debug_mode = 'Y' THEN
10704                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
10705                         END IF;
10706 
10707                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
10708                                 -- Always get from first location in stack i.e. l_start_msg_count+1
10709                                 -- Because stack moves down after delete
10710                                 FND_MSG_PUB.get (
10711                                         p_msg_index      => l_start_msg_count+1,
10712                                         p_encoded        => FND_API.G_FALSE,
10713                                         p_data           => l_data,
10714                                         p_msg_index_out  => l_msg_index_out );
10715 
10716                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
10717                                 -- Because stack moves down after delete
10718                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
10719 
10720                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
10721                                                 'RECORD_NO', i,
10722                                                 'MESSAGE', l_data);
10723                         END LOOP;
10724                         IF l_debug_mode = 'Y' THEN
10725                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
10726                         END IF;
10727                 END IF;
10728         i:= p_submit_assignment_in_tbl.next(i);
10729         END LOOP;
10730 
10731         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
10732                 RAISE FND_API.G_EXC_ERROR;
10733         END IF;
10734 
10735         IF l_debug_mode = 'Y' THEN
10736                 PA_DEBUG.reset_curr_function;
10737         END IF;
10738 
10739         IF p_commit = FND_API.G_TRUE THEN
10740                 commit;
10741         END IF;
10742 
10743 EXCEPTION
10744 WHEN FND_API.G_EXC_ERROR THEN
10745 
10746         x_return_status := FND_API.G_RET_STS_ERROR;
10747         l_msg_count := FND_MSG_PUB.count_msg;
10748 
10749         IF c_valid_asgn_id%ISOPEN THEN
10750                 CLOSE c_valid_asgn_id ;
10751         END IF;
10752 
10753         IF get_person_type%ISOPEN THEN
10754                 CLOSE get_person_type;
10755         END IF;
10756 
10757         IF p_commit = FND_API.G_TRUE THEN
10758                 ROLLBACK TO SUBMIT_ASSIGNMENTS_SP;
10759         END IF;
10760 
10761         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
10762                 PA_INTERFACE_UTILS_PUB.get_messages
10763                 ( p_encoded        => FND_API.G_FALSE
10764                 , p_msg_index      => 1
10765                 , p_msg_count      => l_msg_count
10766                 , p_msg_data       => l_msg_data
10767                 , p_data           => l_data
10768                 , p_msg_index_out  => l_msg_index_out);
10769 
10770                 x_msg_data := l_data;
10771                 x_msg_count := l_msg_count;
10772         ELSE
10773                 x_msg_count := l_msg_count;
10774         END IF;
10775 
10776         IF l_debug_mode = 'Y' THEN
10777                 Pa_Debug.reset_curr_function;
10778         END IF;
10779 
10780 WHEN OTHERS THEN
10781 
10782         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
10783         x_msg_data      := SUBSTRB(SQLERRM,1,240);
10784 
10785         IF c_valid_asgn_id%ISOPEN THEN
10786                 CLOSE c_valid_asgn_id ;
10787         END IF;
10788 
10789         IF get_person_type%ISOPEN THEN
10790                 CLOSE get_person_type;
10791         END IF;
10792 
10793         IF p_commit = FND_API.G_TRUE THEN
10794                 ROLLBACK TO SUBMIT_ASSIGNMENTS_SP;
10795         END IF;
10796 
10797         FND_MSG_PUB.add_exc_msg
10798         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
10799         , p_procedure_name      => 'SUBMIT_ASSIGNMENTS'
10800         , p_error_text          => x_msg_data);
10801 
10802         x_msg_count     := FND_MSG_PUB.count_msg;
10803 
10804         IF l_debug_mode = 'Y' THEN
10805                 PA_DEBUG.reset_curr_function;
10806         END IF;
10807         RAISE;
10808 
10809 END SUBMIT_ASSIGNMENTS ;
10810 
10811 -- Start of comments
10812 --	API name 	: CREATE_REQUIREMENT_COMPETENCE
10813 --	Type		: Public
10814 --	Pre-reqs	: None.
10815 --	Function	: This is a public API to create one or more competences for one or more project requirements.
10816 --	Usage		: This API will be called from AMG.
10817 --	Parameters	:
10818 --	IN		:	p_commit		IN  VARCHAR2
10819 --					Identifier to commit the transaction.
10820 --					Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
10821 --				p_init_msg_list		IN  VARCHAR2
10822 --					Identifier to initialize the error message stack.
10823 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
10824 --				p_api_version_number	IN  NUMBER			Required
10825 --					To be compliant with Applications API coding standards.
10826 --				p_competence_in_tbl	IN  COMPETENCE_IN_TBL	Required
10827 --					Table of competence records.
10828 --					Please see the COMPETENCE_IN_TBL_TYPE datatype table.
10829 --	OUT		:
10830 --				x_competence_element_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
10831 --					Table to store the competence element ids created by the API.
10832 --					Reference: per_comepetence_elements.competence_element_id
10833 --				x_return_status			OUT VARCHAR2
10834 --					Indicates the return status of the API.
10835 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
10836 --				x_msg_count			OUT NUMBER
10837 --					Indicates the number of error messages in the message stack
10838 --				x_msg_data			OUT VARCHAR2
10839 --					Indicates the error message text if only one error exists
10840 --	History		:
10841 --                              01-Mar-2006 - vkadimes  - Created
10842 -- End of comments
10843 PROCEDURE CREATE_REQUIREMENT_COMPETENCE
10844 (
10845   p_commit			IN	        VARCHAR2   :='F'
10846 , p_init_msg_list		IN	        VARCHAR2   :='T'
10847 , p_api_version_number		IN	        NUMBER     :=1.0
10848 , p_competence_in_tbl		IN	        COMPETENCE_IN_TBL_TYPE
10849 , x_competence_element_id_tbl	OUT     NOCOPY  SYSTEM.PA_NUM_TBL_TYPE
10850 , x_return_status		OUT     NOCOPY  VARCHAR2
10851 , x_msg_count			OUT     NOCOPY  NUMBER
10852 , x_msg_data			OUT     NOCOPY  VARCHAR2
10853 )
10854 IS
10855 -- Debug level setting Params
10856 l_debug_mode			VARCHAR2(1);
10857 l_module			VARCHAR2(255)		:= 'PA_RES_MANAGEMENT_AMG_PUB.CREATE_REQUIREMENT_COMPETENCE';
10858 l_debug_level			NUMBER			:=3;
10859 -- Params for  pa_startup.initialize call
10860 l_calling_application		VARCHAR2(10)		:='PLSQL';
10861 l_check_id_flag			VARCHAR2(1)		:= 'Y';
10862 l_check_role_security_flag	VARCHAR2(1)		:= 'Y';
10863 l_check_resource_security_flag	VARCHAR2(1)		:= 'Y';
10864 l_calling_module		VARCHAR2(10)		:='AMG';
10865 --Looping Params
10866 i				NUMBER;
10867 -- Record Type
10868 l_competence_in_rec		COMPETENCE_IN_REC_TYPE;
10869 -- Error Flags
10870 l_error_flag                    VARCHAR2(1);
10871 l_local_error_flag              VARCHAR2(1);
10872 --Message Counters
10873 l_start_msg_count               NUMBER;
10874 l_end_msg_count                 NUMBER;
10875 l_loop_msg_count                NUMBER ;
10876 -- Miss Params List
10877 l_miss_params			VARCHAR2(2000);
10878 -- security check Params
10879 l_privilege			VARCHAR2(30);
10880 l_object_name			VARCHAR2(30);
10881 l_object_key			NUMBER;
10882 l_project_id			NUMBER;
10883 l_template_id			NUMBER;
10884 l_requirement_id		NUMBER;
10885 l_ret_code			VARCHAR2(1);
10886 l_wf_progress_flag              VARCHAR2(1);
10887 l_status_code_num               NUMBER ;
10888 -- Internal API calling Params
10889 l_msg_data                      VARCHAR2(2000);
10890 l_msg_count                     NUMBER;
10891 l_commit			VARCHAR2(1)             := FND_API.G_FALSE;
10892 l_return_status                 VARCHAR2(1);
10893 l_data                          VARCHAR2(2000);
10894 -- Temp Params
10895 l_req_sys_status_code		VARCHAR2(30);
10896 l_status_code                   VARCHAR2(30);
10897 l_element_row_id		ROWID;
10898 l_element_id			per_competence_elements.competence_element_id%TYPE;
10899 l_msg_index_out                 NUMBER;
10900 
10901 -- This cursor is used to Retrive the Info Regarding the given Requirement
10902 CURSOR cur_assign_info (l_requirement_id  NUMBER ) IS
10903 SELECT project_id,status_code,mass_wf_in_progress_flag
10904 FROM	pa_project_assignments
10905 where assignment_id = l_requirement_id
10906 AND assignment_type = 'OPEN_ASSIGNMENT'
10907 AND nvl(template_flag,'N') = 'N';
10908 
10909 -- This cursor is used to get the system status code of the Given Requirement
10910 CURSOR cur_status_code(l_status_code VARCHAR2  ) IS
10911 SELECT project_system_status_code
10912 FROM  pa_project_statuses
10913 WHERE project_status_code = l_status_code
10914 AND status_type= 'OPEN_ASGMT';
10915 
10916 BEGIN
10917 	-- Follows which are supported by this API
10918 	------------------------------------------
10919 	-- Adding one competence when Requirement_id and competence id
10920 	-- or Name or Alias are passsed with Data like
10921 	-- Mandatary Flag and Rating level.
10922 
10923 	x_return_status := FND_API.G_RET_STS_SUCCESS;
10924 
10925 	x_competence_element_id_tbl :=  SYSTEM.PA_NUM_TBL_TYPE();
10926 
10927 	l_debug_mode  := NVL(FND_PROFILE.value_specific('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
10928 
10929 
10930 	IF l_debug_mode = 'Y' THEN
10931 		PA_DEBUG.set_curr_function(p_function => 'CREATE_REQUIREMENT_COMPETENCE', p_debug_mode => l_debug_mode);
10932 	END IF;
10933 
10934 	IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
10935 		FND_MSG_PUB.initialize;
10936 	END IF;
10937 
10938 	IF P_COMMIT = FND_API.G_TRUE THEN
10939 		SAVEPOINT CREATE_REQU_COMPETENCE_SP;
10940 	END IF ;
10941 
10942  	IF l_debug_mode = 'Y' THEN
10943 		pa_debug.write(l_module, 'Save Point create ', l_debug_level);
10944 		pa_debug.write(l_module, 'Start of CREATE_REQUIREMENT_COMPETENCE ', l_debug_level);
10945 		pa_debug.write(l_module, 'Before calling pa_startup.initialize ', l_debug_level);
10946 	END IF ;
10947 
10948 	PA_STARTUP.INITIALIZE(
10949 		  p_calling_application			=> l_calling_application
10950 		, p_calling_module			=> l_calling_module
10951 		, p_check_id_flag			=> l_check_id_flag
10952 		, p_check_role_security_flag		=> l_check_role_security_flag
10953 		, p_check_resource_Security_flag	=> l_check_resource_Security_flag
10954 		, p_debug_level				=> l_debug_level);
10955 
10956 	IF l_debug_mode = 'Y' THEN
10957 		pa_debug.write(l_module, 'After calling pa_startup.initialize ', l_debug_level);
10958 	END IF ;
10959 
10960 
10961 	--checking the Input params..
10962 	IF l_debug_mode = 'Y' THEN
10963 
10964 		pa_debug.write(l_module, 'Printing Input Parameters......', l_debug_level);
10965 
10966 		i := p_competence_in_tbl.first();
10967 
10968 		WHILE i IS NOT NULL LOOP
10969 
10970 			l_competence_in_rec := p_competence_in_tbl(i);
10971 
10972 			pa_debug.write(l_module, 'Values for Record No :'|| i , l_debug_level);
10973 			pa_debug.write(l_module, '-----------------------------', l_debug_level);
10974 			pa_debug.write(l_module, 'l_competence_in_rec.requirement_id for record ' || i || l_competence_in_rec.requirement_id , l_debug_level);
10975 			pa_debug.write(l_module, 'l_competence_in_rec.competence_element_id for record ' || i || l_competence_in_rec.competence_element_id  , l_debug_level);
10976 			pa_debug.write(l_module, 'l_competence_in_rec.competence_id for record ' || i || l_competence_in_rec.competence_id	    , l_debug_level);
10977 			pa_debug.write(l_module, 'l_competence_in_rec.competence_name for record ' || i || l_competence_in_rec.competence_name , l_debug_level);
10978 			pa_debug.write(l_module, 'l_competence_in_rec.competence_alias for record ' || i || l_competence_in_rec.competence_alias , l_debug_level);
10979 			pa_debug.write(l_module, 'l_competence_in_rec.rating_level_id for record ' || i ||  l_competence_in_rec.rating_level_id , l_debug_level);
10980 			pa_debug.write(l_module, 'l_competence_in_rec.rating_level_value for record ' || i ||  l_competence_in_rec.rating_level_value , l_debug_level);
10981 			pa_debug.write(l_module, 'l_competence_in_rec.mandatory_flag for record ' || i ||  l_competence_in_rec.mandatory_flag , l_debug_level);
10982 			pa_debug.write(l_module, 'l_competence_in_rec.record_version_number for record ' || i ||  l_competence_in_rec.record_version_number , l_debug_level);
10983 
10984 			i :=p_competence_in_tbl.next(i);
10985 		END LOOP;
10986 
10987 	END IF;
10988 	-- Starting the Record validationa and API call.
10989 
10990 	i := p_competence_in_tbl.first();
10991 
10992 	WHILE i IS NOT NULL LOOP
10993 		IF l_debug_mode = 'Y' THEN
10994 			pa_debug.write(l_module, 'Inside Loop For Callling Internal API Record  '|| i , l_debug_level);
10995 			pa_debug.write(l_module, '-------------------------------', l_debug_level);
10996 		END IF ;
10997 
10998 		l_local_error_flag := 'N';
10999 		l_start_msg_count :=  FND_MSG_PUB.count_msg;
11000 		l_competence_in_rec:=NULL ;
11001 		l_miss_params := NULL;
11002 		l_competence_in_rec := p_competence_in_tbl(i);
11003 		-- Nulling out unpassed parameters
11004 
11005 		IF l_debug_mode = 'Y' THEN
11006 			pa_debug.write(l_module, 'Start of Nulling out Params which are not passing for Record no '|| i , l_debug_level);
11007 		END IF ;
11008 		-- Nulling out unpassed params
11009 		IF l_competence_in_rec.requirement_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11010 			l_competence_in_rec.requirement_id	:= NULL;
11011 		END IF ;
11012 
11013 		IF l_competence_in_rec.competence_element_id	= PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11014 			l_competence_in_rec.competence_element_id	:= NULL;
11015 		END IF;
11016 
11017 		IF l_competence_in_rec.competence_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11018 			l_competence_in_rec.competence_id := NULL;
11019 		END IF;
11020 
11021 		IF l_competence_in_rec.competence_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
11022 			l_competence_in_rec.competence_name := NULL;
11023 		END IF ;
11024 
11025 		IF l_competence_in_rec.competence_alias = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
11026 			l_competence_in_rec.competence_alias := NULL;
11027 		END IF;
11028 
11029 		IF l_competence_in_rec.rating_level_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11030 			l_competence_in_rec.rating_level_id := NULL;
11031 		END IF;
11032 
11033 		IF l_competence_in_rec.rating_level_value = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11034 			l_competence_in_rec.rating_level_value := NULL;
11035 		END IF;
11036 
11037 		IF l_competence_in_rec.mandatory_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
11038 			l_competence_in_rec.mandatory_flag :=NULL;
11039 		END IF;
11040 
11041 		IF l_competence_in_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11042 			l_competence_in_rec.record_version_number :=NULL;
11043 		END IF;
11044 
11045 		IF l_debug_mode = 'Y' THEN
11046 			pa_debug.write(l_module, 'End  of Nulling out Params which are not passing for Record no '|| i , l_debug_level);
11047 			pa_debug.write(l_module, 'Start of checking for Missing Params for Record no '|| i , l_debug_level);
11048 		END IF ;
11049 		-- checking for missing params
11050 		IF l_competence_in_rec.requirement_id IS NULL THEN
11051 			l_miss_params:= l_miss_params||', REQUIREMENT_ID';
11052 		END IF;
11053 
11054 		IF l_competence_in_rec.competence_id IS    NULL  AND
11055 			l_competence_in_rec.competence_name IS  NULL  AND
11056 			l_competence_in_rec.competence_alias IS NULL  THEN
11057 			l_miss_params:= l_miss_params||', COMPETANCE_ID, COMPETENCE_NAME, COMPETENCE_ALIAS';
11058 		END IF;
11059 
11060 		IF l_debug_mode = 'Y' THEN
11061 			pa_debug.write(l_module, 'After checking for miss Params for Record no '|| i , l_debug_level);
11062 		END IF ;
11063 
11064 		IF l_miss_params IS NOT NULL THEN
11065 			l_local_error_flag :='Y';
11066 			PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
11067 						'INVALID_PARAMS', l_miss_params);
11068 		END IF ;
11069 
11070 		IF l_debug_mode = 'Y' THEN
11071 			pa_debug.write(l_module, 'Getting Requiremnet Details like project_id ,team_template_id,status_code etc '|| i , l_debug_level);
11072 		END IF  ;
11073 
11074 		l_requirement_id :=  l_competence_in_rec.requirement_id;
11075 
11076                 -- security check
11077 		OPEN cur_assign_info(l_requirement_id);
11078 		FETCH cur_assign_info INTO l_project_id,l_status_code,l_wf_progress_flag;
11079 		-- checking for the validity of the requirement_id.
11080 
11081 		IF l_debug_mode = 'Y' THEN
11082 			pa_debug.write(l_module, 'Checking for the Validity of the Record.'|| i , l_debug_level);
11083 		END IF  ;
11084 
11085 		IF cur_assign_info%NOTFOUND THEN
11086 			l_local_error_flag := 'Y';
11087                         l_miss_params := l_miss_params||', REQUIREMENT_ID';
11088                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
11089                                                 'INVALID_PARAMS', l_miss_params);
11090         	END IF;
11091 
11092 		CLOSE cur_assign_info;
11093 
11094 		OPEN cur_status_code(l_status_code);
11095 		FETCH cur_status_code INTO l_req_sys_status_code;
11096 		CLOSE cur_status_code;
11097 
11098 		IF l_debug_mode = 'Y' THEN
11099 			pa_debug.write(l_module, 'After getting requirement Details for Record '|| i , l_debug_level);
11100 			pa_debug.write(l_module, 'l_project_id ' ||l_project_id ||'l_template_id '||l_template_id  , l_debug_level);
11101 			pa_debug.write(l_module, 'l_req_sys_status_code '|| l_req_sys_status_code || 'l_wf_progress_flag ' || l_wf_progress_flag, l_debug_level);
11102 		END IF;
11103 
11104 		IF l_local_error_flag <> 'Y' THEN
11105 
11106 			IF l_debug_mode = 'Y' THEN
11107 				pa_debug.write(l_module, 'Checking Security for record No'||i, l_debug_level);
11108 			END IF;
11109 
11110 			IF l_project_id IS NOT NULL THEN
11111 				l_privilege := 'PA_ASN_BASIC_INFO_ED ';
11112 				l_object_name := 'PA_PROJECTS';
11113 				l_object_key := l_project_id;
11114 		        ELSE
11115 				-- This should never happen.
11116 				PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
11117 				raise FND_API.G_EXC_ERROR;
11118                         END IF;
11119 
11120                         IF l_debug_mode = 'Y' THEN
11121                                 pa_debug.write(l_module, 'Calling  PA_SECURITY_PVT.CHECK_USER_PRIVILEGE for Record = '||i||' with Following Values', l_debug_level);
11122 				pa_debug.write(l_module, 'l_privilege :'|| l_privilege, l_debug_level);
11123 				pa_debug.write(l_module, 'l_object_name :'||l_object_name, l_debug_level);
11124 				pa_debug.write(l_module, 'l_object_key :'||l_object_key, l_debug_level);
11125                         END IF;
11126 
11127                         l_return_status := FND_API.G_RET_STS_SUCCESS;
11128                         l_ret_code := 'T';
11129 
11130 			-- Checking Security at project level or at Template level
11131                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
11132 				   x_ret_code       => l_ret_code
11133 				 , x_return_status  => l_return_status
11134 				 , x_msg_count      => l_msg_count
11135 				 , x_msg_data       => l_msg_data
11136 				 , p_privilege      => l_privilege
11137 				 , p_object_name    => l_object_name
11138 				 , p_object_key     => l_object_key
11139 				 , p_init_msg_list   => FND_API.G_FALSE);
11140 
11141                         IF l_debug_mode = 'Y' THEN
11142                                 pa_debug.write(l_module, 'Return Status from PA_SECURITY_PVT.CHECK_USER_PRIVILEGE for Record '||i||'is l_return_status '|| l_return_status , l_debug_level);
11143 				pa_debug.write(l_module, 'l_ret_code ='|| l_ret_code , l_debug_level);
11144 			END IF ;
11145 
11146                         IF (nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS)
11147 			AND l_project_id IS NOT NULL  THEN
11148 			-- If project level security Fails wll call Requirement level Security
11149 				IF l_debug_mode = 'Y' THEN
11150 					 pa_debug.write(l_module, 'No Access Found at Project level checking at Requirement level', l_debug_level);
11151 				END IF ;
11152 				l_privilege := 'PA_ASN_BASIC_INFO_ED';
11153 				l_object_name := 'PA_PROJECT_ASSIGNMENTS';
11154 				l_object_key := l_requirement_id;
11155 				PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
11156 					  x_ret_code       => l_ret_code
11157 					, x_return_status  => l_return_status
11158 					, x_msg_count      => l_msg_count
11159 					, x_msg_data       => l_msg_data
11160 					, p_privilege      => l_privilege
11161 					, p_object_name    => l_object_name
11162 					, p_object_key     => l_object_key
11163 					, p_init_msg_list   => FND_API.G_FALSE );
11164 
11165 				IF l_debug_mode = 'Y' THEN
11166 					 pa_debug.write(l_module, 'Return Status are Requirement level l_date return value l_ret_code'|| l_ret_code, l_debug_level);
11167 				END IF ;
11168 
11169 
11170 			END IF;
11171 
11172 			IF (nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
11173 				-- This message does not have token defined, but intentionally putting token
11174                                 -- bcoz we still want to show the privielge name which is missing
11175 				IF l_debug_mode = 'Y' THEN
11176 					 pa_debug.write(l_module, 'User Dont have Privillege to modify this Requirement', l_debug_level);
11177 				END IF ;
11178 
11179 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_COMP'
11180                                                       ,'MISSING_PRIVILEGE', l_privilege);
11181 				l_local_error_flag := 'Y';
11182 		        END IF ;
11183 			-- checking Requiremnet Status
11184 			IF l_req_sys_status_code IN ('ASGMT_APPRVL_SUBMITTED','OPEN_ASGMT_FILLED', 'ASGMT_APPRVL_CANCELED') THEN
11185 				 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
11186 				 l_local_error_flag := 'Y';
11187 			END IF ;
11188 			-- Checking WF status..
11189 			IF l_wf_progress_flag = 'Y' THEN
11190 				PA_UTILS.ADD_MESSAGE('PA', 'PA_ASSIGNMENT_WF');
11191 				l_local_error_flag := 'Y';
11192 			END IF;
11193 
11194 			IF l_debug_mode = 'Y' THEN
11195 			        pa_debug.write(l_module, 'End of Security  check '|| l_ret_code, l_debug_level);
11196 			END IF ;
11197 
11198 
11199 		END IF;
11200 
11201 
11202 	        --- Calling pa_competence_pub.Add_competence_elemets
11203 		IF  l_local_error_flag <> 'Y' THEN
11204 			-- No error occured.ie local error Flag is N
11205 			IF l_debug_mode = 'Y' THEN
11206 				pa_debug.write(l_module, 'Calling PA_COMPETENCE_PUB.ADD_COMPETENCE_ELEMENT ', l_debug_level);
11207 			END IF ;
11208 			l_return_status := FND_API.G_RET_STS_SUCCESS;
11209 			-- Calling Internal API to Add competence
11210 			PA_COMPETENCE_PUB.ADD_COMPETENCE_ELEMENT(
11211 				    p_object_name		=> 'OPEN_ASSIGNMENT'
11212 				  , p_object_id			=> l_competence_in_rec.requirement_id
11213 				  , p_competence_id		=> l_competence_in_rec.competence_id
11214 				  , p_competence_alias		=> l_competence_in_rec.competence_alias
11215 				  , p_competence_name		=> l_competence_in_rec.competence_name
11216 				  , p_rating_level_id		=> l_competence_in_rec.rating_level_id
11217 				  , p_rating_level_value	=> l_competence_in_rec.rating_level_value
11218 				  , p_mandatory_flag		=> l_competence_in_rec.mandatory_flag
11219 				  , p_init_msg_list		=> 'F'
11220 				  , P_commit			=> l_commit
11221 				  , p_validate_only		=> 'N'
11222 				  , x_element_id		=> l_element_id
11223 				  , x_element_rowid		=> l_element_row_id
11224 				  , x_return_status		=> l_return_status
11225 				  , x_msg_count			=> l_msg_count
11226 				  , x_msg_data			=> l_msg_data);
11227 
11228 			IF l_debug_mode = 'Y' THEN
11229 				pa_debug.write(l_module, 'After Calling PA_COMPETENCE_PUB.ADD_COMPETENCE_ELEMENT ', l_debug_level);
11230 				pa_debug.write(l_module, 'l_return_status '|| l_return_status || 'for record '|| i , l_debug_level);
11231 			END IF ;
11232 
11233 			IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
11234 				x_competence_element_id_tbl.extend(1);
11235 				x_competence_element_id_tbl(x_competence_element_id_tbl.count):= l_element_id;
11236 			ELSE
11237  				x_competence_element_id_tbl.extend(1);
11238 				x_competence_element_id_tbl(x_competence_element_id_tbl.count):= -1;
11239 				l_local_error_flag := 'Y';
11240 			END IF;
11241 		ELSE
11242 		  -- if local Error Flag is set for missparams or sec.Populating Out  table with -1
11243  			x_competence_element_id_tbl.extend(1);
11244 			x_competence_element_id_tbl(x_competence_element_id_tbl.count):= -1;
11245 		END IF ;
11246 		  -- Taking end count of loop
11247 		l_end_msg_count := FND_MSG_PUB.count_msg;
11248 		l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
11249 
11250  		IF l_debug_mode = 'Y' THEN
11251 			pa_debug.write(l_module, 'Error Flag for Record '|| i || ' is l_local_error_flag  '|| l_local_error_flag , l_debug_level);
11252 		END IF ;
11253 
11254 		IF l_local_error_flag = 'Y' OR l_loop_msg_count > 0 THEN
11255 			l_error_flag := 'Y';
11256 
11257 			IF l_debug_mode = 'Y' THEN
11258 				pa_debug.write(l_module, 'After Calling PA_COMPETENCE_PUB.ADD_COMPETENCE_ELEMENT ', l_debug_level);
11259 			END IF ;
11260 
11261 			FOR j in l_start_msg_count+1..l_end_msg_count LOOP
11262 				FND_MSG_PUB.get (
11263 					  p_msg_index      =>  l_start_msg_count+1
11264 					, p_encoded        => FND_API.G_FALSE
11265 					, p_data           => l_data
11266 					, p_msg_index_out  => l_msg_index_out );
11267 
11268 				FND_MSG_PUB.DELETE_MSG(p_msg_index =>  l_start_msg_count+1);
11269 					-- Adding Record Number to The Message.
11270 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
11271 						  'RECORD_NO', i,
11272 						  'MESSAGE', l_data);
11273 			END LOOP;
11274 
11275 		END IF;
11276 		i := P_COMPETENCE_IN_TBL.next(i);
11277 	END LOOP;
11278         -- End of Loop(Record Loop)
11279 	IF l_debug_mode = 'Y' THEN
11280 		pa_debug.write(l_module, 'Out Of PA_COMPETENCE_PUB.ADD_COMPETENCE_ELEMENT  API calling Loop', l_debug_level);
11281 	END IF ;
11282 
11283 	IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
11284 		RAISE FND_API.G_EXC_ERROR;
11285 	END IF;
11286 
11287 	IF l_debug_mode = 'Y' THEN
11288 		PA_DEBUG.reset_curr_function;
11289 	END IF;
11290 
11291 	IF p_commit = FND_API.G_TRUE THEN
11292 		commit;
11293 	END IF;
11294 
11295 EXCEPTION
11296 	WHEN FND_API.G_EXC_ERROR THEN
11297 		x_return_status := FND_API.G_RET_STS_ERROR;
11298 		l_msg_count := FND_MSG_PUB.count_msg;
11299 
11300 		IF l_debug_mode = 'Y' THEN
11301 			pa_debug.write(l_module, 'In Side Exception Block FND_API.G_EXC_ERROR', l_debug_level);
11302 			pa_debug.write(l_module, 'Closing CURSORS if OPEN', l_debug_level);
11303 		END IF ;
11304 
11305 		IF cur_assign_info%ISOPEN THEN
11306 			CLOSE cur_assign_info;
11307 		END IF;
11308 
11309 		IF cur_status_code%ISOPEN THEN
11310 			CLOSE cur_status_code;
11311 		END IF;
11312 
11313 		IF p_commit = FND_API.G_TRUE THEN
11314 			ROLLBACK TO CREATE_REQU_COMPETENCE_SP;
11315 		END IF;
11316 
11317 		IF l_msg_count = 1 AND x_msg_data IS NULL THEN
11318 			PA_INTERFACE_UTILS_PUB.GET_MESSAGES(
11319 				  p_encoded        => FND_API.G_FALSE
11320 				, p_msg_index      => 1
11321 				, p_msg_count      => l_msg_count
11322 				, p_msg_data       => l_msg_data
11323 				, p_data           => l_data
11324 				, p_msg_index_out  => l_msg_index_out);
11325 
11326 			x_msg_data := l_data;
11327 			x_msg_count := l_msg_count;
11328 		ELSE
11329 			x_msg_count := l_msg_count;
11330 		END IF;
11331 
11332 		IF l_debug_mode = 'Y' THEN
11333 			Pa_Debug.reset_curr_function;
11334 		END IF;
11335 
11336 	WHEN OTHERS THEN
11337 
11338 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11339 		x_msg_data      := SUBSTRB(SQLERRM,1,240);
11340 
11341 		IF l_debug_mode = 'Y' THEN
11342 			pa_debug.write(l_module, 'In Side Exception Block others ', l_debug_level);
11343 			pa_debug.write(l_module, 'Closing CURSORS if OPEN', l_debug_level);
11344 		END IF ;
11345 
11346 		IF cur_assign_info%ISOPEN THEN
11347 			CLOSE cur_assign_info;
11348 		END IF;
11349 
11350 		IF cur_status_code%ISOPEN THEN
11351 			CLOSE cur_status_code;
11352 		END IF;
11353 
11354 		IF p_commit = FND_API.G_TRUE THEN
11355 			ROLLBACK TO CREATE_REQU_COMPETENCE_SP;
11356 		END IF;
11357 
11358 		FND_MSG_PUB.add_exc_msg (
11359 			  p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
11360 			, p_procedure_name      => 'CREATE_REQUIREMENT_COMPETENCE'
11361 			, p_error_text          => x_msg_data);
11362 
11363 		x_msg_count     := FND_MSG_PUB.count_msg;
11364 
11365 		IF l_debug_mode = 'Y' THEN
11366 			PA_DEBUG.reset_curr_function;
11367 		END IF;
11368 		RAISE;
11369 
11370 END CREATE_REQUIREMENT_COMPETENCE;
11371 
11372 -- Start of comments
11373 --	API name 	: UPDATE_REQUIREMENT_COMPETENCE
11374 --	Type		: Public
11375 --	Pre-reqs	: None.
11376 --	Function	: This is a public API to update one or more competences for one or more project requirements.
11377 --	Usage		: This API will be called from AMG.
11378 --	Parameters	:
11379 --	IN		:	p_commit		IN  VARCHAR2
11380 --					Identifier to commit the transaction.
11381 --					Valid values are: FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
11382 --				p_init_msg_list		IN  VARCHAR2
11383 --					Identifier to initialize the error message stack.
11384 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
11385 --				p_api_version_number	IN  NUMBER			Required
11386 --					To be compliant with Applications API coding standards.
11387 --				p_competence_in_tbl	IN  COMPETENCE_IN_TBL_TYPE	Required
11388 --					Table of competence records. Please see the COMPETENCE_IN_TBL_TYPE datatype table.
11389 --	OUT		:
11390 --				x_return_status		OUT VARCHAR2
11391 --					Indicates the return status of the API.
11392 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
11393 --				x_msg_count		OUT NUMBER
11394 --					Indicates the number of error messages in the message stack
11395 --				x_msg_data		OUT VARCHAR2
11396 --					Indicates the error message text if only one error exists
11397 --	History		:
11398 --                              01-Mar-2006 - vkadimes  - Created
11399 -- End of comments
11400 PROCEDURE UPDATE_REQUIREMENT_COMPETENCE
11401 (
11402   p_commit		IN		VARCHAR2  := 'F'
11403 , p_init_msg_list	IN		VARCHAR2  := 'T'
11404 , p_api_version_number	IN		NUMBER    := 1.0
11405 , p_competence_in_tbl	IN		COMPETENCE_IN_TBL_TYPE
11406 , x_return_status	OUT NOCOPY	VARCHAR2
11407 , x_msg_count		OUT NOCOPY	NUMBER
11408 , x_msg_data		OUT NOCOPY	VARCHAR2
11409 ) IS
11410 -- Debug Level
11411 l_module			VARCHAR2(255)		:= 'PA_RES_MANAGEMENT_AMG_PUB.UPDATE_REQUIREMENT_COMPETENCE';
11412 l_debug_mode			VARCHAR2(1);
11413 l_debug_level                   NUMBER		:=3;
11414 -- Params for pa_startup.initialize call
11415 l_calling_application		VARCHAR2(10)		:='PLSQL';
11416 l_check_id_flag			VARCHAR2(1)		:= 'Y';
11417 l_check_role_security_flag	VARCHAR2(1)		:= 'Y';
11418 l_check_resource_security_flag	VARCHAR2(1)		:= 'Y';
11419 l_calling_module		VARCHAR(10)		:= 'AMG';
11420 --Looping params
11421 
11422 i				NUMBER;
11423 --Record Type
11424 l_competence_in_rec		COMPETENCE_IN_REC_TYPE;
11425 --Loop params
11426 --Error Flags
11427 l_local_error_flag		VARCHAR2(1);
11428 l_error_flag			VARCHAR2(1);
11429 -- Message Counters
11430 l_start_msg_count		NUMBER ;
11431 l_end_msg_count			NUMBER ;
11432 l_loop_msg_count		NUMBER ;
11433 -- Miss Params List
11434 l_miss_params			VARCHAR2(2000);
11435 --temp Params
11436 l_requirement_id                NUMBER;
11437 l_dummy                         NUMBER;
11438 l_competence_element_id         NUMBER;
11439 l_competence_id			NUMBER;
11440 -- Security check Params
11441 l_project_id			NUMBER :=NULL;
11442 l_template_id			NUMBER :=NULL;
11443 l_wf_progress_flag              VARCHAR2(1);
11444 l_status_code                   VARCHAR2(10);
11445 l_req_sys_status_code		VARCHAR2(30);
11446 l_privilege			VARCHAR2(30);
11447 l_object_name			VARCHAR2(30);
11448 l_object_key			NUMBER;
11449 l_ret_code			VARCHAR2(1);
11450 
11451 l_msg_index_out                 NUMBER;
11452 l_msg_data                      VARCHAR2(2000);
11453 l_msg_count                     NUMBER;
11454 l_return_status                 VARCHAR2(1);
11455 
11456 --Internal API calling Params
11457 l_commit			VARCHAR2(1)             := FND_API.G_FALSE;
11458 l_object_version_number		NUMBER;
11459 l_data				VARCHAR2(2000);
11460 
11461 -- Given Competence Element id this cursor is used to get the info about that
11462 -- Perticulat competence
11463 CURSOR cur_competence_details(l_competence_element_id NUMBER) IS
11464 SELECT *
11465 FROM PA_OPEN_ASGMT_COMPETENCES_V
11466 WHERE competence_element_id = l_competence_element_id;
11467 
11468 -- For Future developement
11469 /*CURSOR cur_competence_details_alt(l_requirement_id NUMBER, l_competence_id NUMBER ) IS
11470 SELECT *
11471 FROM PA_OPEN_ASGMT_COMPETENCES_V
11472 WHERE assignment_id = l_requirement_id
11473 AND   competence_id=l_competence_id;*/
11474 
11475 
11476 -- This cursor is used to get the information like which Requirement
11477 -- competence belong to and validity .
11478 CURSOR cur_assign_info (l_requirement_id IN NUMBER ) IS
11479 SELECT project_id,assignment_template_id,status_code,mass_wf_in_progress_flag
11480 FROM	pa_project_assignments
11481 where assignment_id = l_requirement_id;
11482 
11483 -- To get the project system status code for
11484 -- perticular requirement.
11485 CURSOR cur_status_code(l_status_code VARCHAR2  ) IS
11486 SELECT project_system_status_code
11487 FROM  pa_project_statuses
11488 WHERE project_status_code = l_status_code;
11489 
11490 -- To Hold the values used.
11491 l_cur_competence_in_rec         PA_OPEN_ASGMT_COMPETENCES_V%ROWTYPE;
11492 
11493 BEGIN
11494 	--Flows which are supported by this API
11495 	------------------------------------------------------
11496 	-- User MUST PASS P_COMPETENCE_ELEMENT_ID
11497 	-- Updating  a competence by Passing p_competence_element_id
11498 	-- when competence alias is passed it will be replaced with the one from Data base.
11499 	-- ie competence name will be ignore and will be replaced with Data base value.
11500 	-- Only we will Allow Mandatery Flag and Rating level to be updated.
11501 
11502 	--Flows which are not supported by this API
11503 	----------------------------------------------------------
11504 	-- Updating a Competence by Passing Combination of Requirement_id and one of the
11505 	-- competence id or competence alias or competence name
11506 
11507 
11508 	x_return_status := FND_API.G_RET_STS_SUCCESS;
11509 
11510 	l_debug_mode  := NVL(FND_PROFILE.value_specific('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
11511 
11512 	IF l_debug_mode = 'Y' THEN
11513 		PA_DEBUG.set_curr_function(p_function => 'UPDATE_REQUIREMENT_COMPETENCE', p_debug_mode => l_debug_mode);
11514 	END IF;
11515 
11516 	-- Resetting the Error Stack.
11517 	IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
11518 		FND_MSG_PUB.initialize;
11519 	END IF;
11520 
11521 	IF P_COMMIT = FND_API.G_TRUE THEN
11522 		SAVEPOINT UPDATE_REQU_COMPETENCE_SP;
11523 	END IF ;
11524 
11525 	IF l_debug_mode = 'Y' THEN
11526 		pa_debug.write(l_module,'Save Point create ', l_debug_level);
11527 	END IF ;
11528 
11529 	IF l_debug_mode = 'Y' THEN
11530 		pa_debug.write(l_module,'Start of UPDATE_REQUIREMENT_COMPETENCE ', l_debug_level);
11531 	END IF ;
11532 
11533 	IF l_debug_mode = 'Y' THEN
11534 		pa_debug.write(l_module,'Before calling pa_startup.initialize ', l_debug_level);
11535 	END IF ;
11536 
11537 	PA_STARTUP.INITIALIZE(
11538 		  p_calling_application			=> l_calling_application
11539 		, p_calling_module			=> l_calling_module
11540 		, p_check_id_flag			=> l_check_id_flag
11541 		, p_check_role_security_flag		=> l_check_role_security_flag
11542 		, p_check_resource_Security_flag	=> l_check_resource_Security_flag
11543 		, p_debug_level				=> l_debug_level);
11544 
11545 	IF l_debug_mode = 'Y' THEN
11546 		 pa_debug.write(l_module,'After calling pa_startup.initialize ', l_debug_level);
11547 	END IF ;
11548 
11549 	IF l_debug_mode = 'Y' THEN
11550 		pa_debug.write(l_module,'Printing Input Parameters......', l_debug_level);
11551 
11552 		i := p_competence_in_tbl.first();
11553 
11554 		WHILE i IS NOT NULL LOOP
11555 
11556 			l_competence_in_rec := p_competence_in_tbl(i);
11557 
11558 			pa_debug.write(l_module, 'Values for Record No :'|| i , l_debug_level);
11559 			pa_debug.write(l_module, 'l_competence_in_rec.requirement_id for record ' || i || l_competence_in_rec.requirement_id , l_debug_level);
11560 			pa_debug.write(l_module, 'l_competence_in_rec.competence_element_id for record ' || i || l_competence_in_rec.competence_element_id  , l_debug_level);
11561 			pa_debug.write(l_module, 'l_competence_in_rec.competence_id for record ' || i || l_competence_in_rec.competence_id	    , l_debug_level);
11562 			pa_debug.write(l_module, 'l_competence_in_rec.competence_name for record ' || i || l_competence_in_rec.competence_name , l_debug_level);
11563 			pa_debug.write(l_module, 'l_competence_in_rec.competence_alias for record ' || i || l_competence_in_rec.competence_alias , l_debug_level);
11564 			pa_debug.write(l_module, 'l_competence_in_rec.rating_level_id for record ' || i ||  l_competence_in_rec.rating_level_id , l_debug_level);
11565 			pa_debug.write(l_module, 'l_competence_in_rec.rating_level_value for record ' || i ||  l_competence_in_rec.rating_level_value , l_debug_level);
11566 			pa_debug.write(l_module, 'l_competence_in_rec.mandatory_flag for record ' || i ||  l_competence_in_rec.mandatory_flag , l_debug_level);
11567 			pa_debug.write(l_module, 'l_competence_in_rec.record_version_number for record ' || i ||  l_competence_in_rec.record_version_number , l_debug_level);
11568 
11569 			i :=p_competence_in_tbl.next(i);
11570 		END LOOP;
11571 
11572 	END IF;
11573 
11574 	i := p_competence_in_tbl.first();
11575 
11576 	WHILE i IS NOT NULL LOOP
11577 
11578 		IF l_debug_mode = 'Y' THEN
11579 			pa_debug.write(l_module, 'Inside Loop For Record  '|| i , l_debug_level);
11580 		END IF ;
11581 		-- setting the Params at the starting of the loop
11582 		l_local_error_flag	:= 'N';
11583 		l_start_msg_count	:= FND_MSG_PUB.count_msg;
11584 		l_competence_in_rec	:= NULL ;
11585 		l_miss_params		:= NULL;
11586 		l_competence_in_rec	:= P_COMPETENCE_IN_TBL(i);
11587 
11588 		IF l_competence_in_rec.competence_element_id IS NULL
11589 		OR l_competence_in_rec.competence_element_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11590 			l_miss_params := l_miss_params || 'P_COMPETENCE_ELEMENT_ID';
11591 		END IF;
11592 
11593 		IF l_miss_params IS NOT NULL THEN
11594 			l_local_error_flag := 'Y';
11595  			PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
11596 			'INVALID_PARAMS', l_miss_params);
11597 		END IF;
11598 
11599 		IF  l_local_error_flag <> 'Y' THEN
11600 			-- Getting Requirement competence Details
11601 			-- These variables are loaded
11602 			l_requirement_id := l_competence_in_rec.requirement_id;
11603 			l_competence_id  := l_competence_in_rec.competence_id;
11604 			l_competence_element_id := l_competence_in_rec.competence_element_id;
11605 			-- Getting the Data about competence
11606 			IF l_competence_element_id IS NOT  NULL
11607 			AND  l_competence_element_id <> PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM  THEN
11608 
11609 				OPEN cur_competence_details(l_competence_element_id);
11610 				FETCH cur_competence_details INTO l_cur_competence_in_rec;
11611 				-- checking the validity of l_competence_element_id
11612 				IF cur_competence_details%NOTFOUND THEN
11613 					l_local_error_flag := 'Y';
11614 		       			l_miss_params := l_miss_params || 'P_COMPETENCE_ELEMENT_ID';
11615                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
11616                                         'INVALID_PARAMS', l_miss_params);
11617 				END IF;
11618 				-- closing the cursor
11619 				CLOSE cur_competence_details;
11620 				--Loading the values with the existing Data Base Values
11621 			/*for Future Devolopement
11622 			ELSE
11623 				OPEN cur_competence_details_alt(l_requirement_id,l_competence_id);
11624 				FETCH cur_competence_details_alt INTO l_cur_competence_in_rec;
11625 				-- checking the validity of l_requirement_id,l_competence_id
11626 				IF cur_competence_details_alt%NOTFOUND THEN
11627 					 l_local_error_flag := 'Y';
11628 					 PA_UTILS.ADD_MESSAGE('PA', 'PA_INVALID_ASGMT_ID');
11629 				END IF;
11630 				--Closing the cursor
11631 				CLOSE cur_competence_details_alt;
11632 				-- Populating the competence element id
11633 				l_competence_in_rec.p_competence_element_id := l_cur_competence_in_rec.competence_element_id;
11634 				l_competence_element_id := l_cur_competence_in_rec.competence_element_id;*/
11635 			END IF;
11636 		END IF;
11637 
11638 		IF l_local_error_flag <> 'Y' THEN
11639                 -- Loading the Competence Name and Alias with the Exiting values.
11640 			l_requirement_id := l_cur_competence_in_rec.assignment_id;
11641 			l_competence_in_rec.requirement_id := l_cur_competence_in_rec.assignment_id;
11642 			l_competence_id  := l_cur_competence_in_rec.competence_id;
11643 			l_competence_in_rec.competence_id := l_cur_competence_in_rec.competence_id;
11644 			l_competence_in_rec.competence_name  := l_cur_competence_in_rec.competence_name;
11645 			l_competence_in_rec.competence_alias := l_cur_competence_in_rec.competence_alias;
11646 
11647 			IF l_competence_in_rec.record_version_number IS NULL
11648 			OR l_competence_in_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11649 
11650 				l_competence_in_rec.record_version_number := l_cur_competence_in_rec.object_version_number;
11651 
11652 			END IF;
11653 		END IF;
11654                 -- Taking care of miss char value..
11655 		IF l_competence_in_rec.requirement_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11656 			l_competence_in_rec.requirement_id	:= FND_API.G_MISS_NUM;
11657 		END IF ;
11658 
11659 		IF l_competence_in_rec.competence_element_id	= PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11660 			l_competence_in_rec.competence_element_id	:= FND_API.G_MISS_NUM;
11661 		END IF;
11662 
11663 		IF l_competence_in_rec.competence_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11664 			l_competence_in_rec.competence_id := FND_API.G_MISS_NUM;
11665 		END IF;
11666 
11667 		IF l_competence_in_rec.competence_name = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
11668 			l_competence_in_rec.competence_name := FND_API.G_MISS_CHAR;
11669 		END IF ;
11670 
11671 		IF l_competence_in_rec.competence_alias = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
11672 			l_competence_in_rec.competence_alias := FND_API.G_MISS_CHAR;
11673 		END IF;
11674 
11675 		IF l_competence_in_rec.rating_level_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11676 			l_competence_in_rec.rating_level_id := FND_API.G_MISS_NUM;
11677 		END IF;
11678 
11679 		IF l_competence_in_rec.rating_level_value = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11680 			l_competence_in_rec.rating_level_value := FND_API.G_MISS_NUM;
11681 		END IF;
11682 
11683 		IF l_competence_in_rec.mandatory_flag = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
11684 			l_competence_in_rec.mandatory_flag :=FND_API.G_MISS_CHAR;
11685 		END IF;
11686 
11687 		IF l_competence_in_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
11688 			l_competence_in_rec.record_version_number :=FND_API.G_MISS_NUM;
11689 		END IF;
11690 		--- Security check
11691 
11692 		IF l_local_error_flag <> 'Y' THEN
11693 
11694 			OPEN cur_assign_info(l_requirement_id);
11695 			FETCH cur_assign_info INTO l_project_id,l_template_id,l_status_code,l_wf_progress_flag;
11696 			CLOSE cur_assign_info;
11697 
11698 			OPEN cur_status_code(l_status_code);
11699 			FETCH cur_status_code INTO l_req_sys_status_code;
11700 			CLOSE cur_status_code;
11701 
11702 			IF l_debug_mode = 'Y' THEN
11703 				pa_debug.write(l_module, 'Checking Security for record No'||i, l_debug_level);
11704 			END IF;
11705 
11706 			IF l_project_id IS NOT NULL THEN
11707 				l_privilege := 'PA_ASN_BASIC_INFO_ED ';
11708 				l_object_name := 'PA_PROJECTS';
11709 				l_object_key := l_project_id;
11710 			ELSIF l_template_id IS NOT NULL THEN
11711 				l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
11712 				l_object_name := null;
11713 				l_object_key := null;
11714 		        ELSE
11715                                 -- This should never happen.
11716 				PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
11717                                 raise FND_API.G_EXC_ERROR;
11718                         END IF;
11719 
11720                         IF l_debug_mode = 'Y' THEN
11721                                 pa_debug.write(l_module, 'Calling  PA_SECURITY_PVT.CHECK_USER_PRIVILEGE for Record '||i||'with Following Values', l_debug_level);
11722 				pa_debug.write(l_module, 'l_privilege'|| l_privilege, l_debug_level);
11723 				pa_debug.write(l_module, 'l_object_name'||l_object_name, l_debug_level);
11724 				pa_debug.write(l_module, 'l_object_key'||l_object_key, l_debug_level);
11725                         END IF;
11726 
11727                         l_return_status := FND_API.G_RET_STS_SUCCESS;
11728                         l_ret_code := 'T';
11729 
11730 			-- Checking Security at project level or at Template level
11731                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
11732                                   x_ret_code       => l_ret_code
11733                                 , x_return_status  => l_return_status
11734                                 , x_msg_count      => l_msg_count
11735                                 , x_msg_data       => l_msg_data
11736                                 , p_privilege      => l_privilege
11737                                 , p_object_name    => l_object_name
11738                                 , p_object_key     => l_object_key
11739 				,p_init_msg_list   => FND_API.G_FALSE);
11740 			IF l_debug_mode = 'Y' THEN
11741 				pa_debug.write(l_module, 'Return Status from PA_SECURITY_PVT.CHECK_USER_PRIVILEGE for Record '||i||'is l_return_status '|| l_return_status , l_debug_level);
11742 				pa_debug.write(l_module, 'l_ret_code'|| l_ret_code, l_debug_level);
11743 			END IF ;
11744 
11745 			IF (nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS)
11746 			AND l_project_id IS NOT NULL  THEN
11747 			-- If project level security Fails wll call Requirement level Security
11748 				IF l_debug_mode = 'Y' THEN
11749 					pa_debug.write(l_module,'No Access Found at Project level checking at Requirement level', l_debug_level);
11750 				END IF ;
11751 
11752 				l_privilege := 'PA_ASN_BASIC_INFO_ED';
11753 				l_object_name := 'PA_PROJECT_ASSIGNMENTS';
11754 				l_object_key := l_requirement_id;
11755 				PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
11756 					  x_ret_code       => l_ret_code
11757 					, x_return_status  => l_return_status
11758 					, x_msg_count      => l_msg_count
11759 					, x_msg_data       => l_msg_data
11760 					, p_privilege      => l_privilege
11761 					, p_object_name    => l_object_name
11762 					, p_object_key     => l_object_key
11763 					, p_init_msg_list   => FND_API.G_FALSE );
11764 
11765 				IF l_debug_mode = 'Y' THEN
11766 					pa_debug.write(l_module,'Return Status are Requirement level l_date return value l_ret_code'|| l_ret_code, l_debug_level);
11767 				END IF ;
11768 
11769 			END IF;
11770 
11771 			IF (nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
11772 				-- This message does not have token defined, but intentionally putting token
11773                                 -- bcoz we still want to show the privielge name which is missing
11774 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_COMP'
11775 						    ,'MISSING_PRIVILEGE', l_privilege);
11776                                 l_local_error_flag := 'Y';
11777 		        END IF ;
11778 			-- checking Assignment Status.
11779 			IF l_req_sys_status_code IN ('ASGMT_APPRVL_SUBMITTED', 'OPEN_ASGMT_FILLED', 'ASGMT_APPRVL_CANCELED') THEN
11780 				 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
11781 				 l_local_error_flag := 'Y';
11782 			END IF ;
11783 			-- Checking WF status..
11784 			IF l_wf_progress_flag = 'Y' THEN
11785 				PA_UTILS.ADD_MESSAGE('PA', 'PA_ASSIGNMENT_WF');
11786 				l_local_error_flag := 'Y';
11787 			END IF;
11788 
11789 			IF l_debug_mode = 'Y' THEN
11790 				pa_debug.write(l_module, 'End of Security  check '|| l_ret_code, l_debug_level);
11791 			END IF ;
11792 		END IF;
11793 
11794 		IF  l_local_error_flag <> 'Y' THEN
11795 		  		-- No error occured.ie local error Flag is N
11796 			IF l_debug_mode = 'Y' THEN
11797 				pa_debug.write(l_module, 'Calling PA_COMPETENCE_PUB.UPDATE_COMPETENCE_ELEMENT ', l_debug_level);
11798 			END IF ;
11799 
11800 			l_return_status := FND_API.G_RET_STS_SUCCESS;
11801 
11802 			PA_COMPETENCE_PUB.UPDATE_COMPETENCE_ELEMENT(
11803 				  p_object_name		  =>'OPEN_ASSIGNMENT'
11804 				, p_object_id		  => l_competence_in_rec.requirement_id
11805 				, p_competence_id	  => l_competence_in_rec.competence_id
11806 				, p_competence_alias	  => l_competence_in_rec.competence_alias
11807 				, p_competence_name	  => l_competence_in_rec.competence_name
11808 				, p_element_id		  => l_competence_in_rec.competence_element_id
11809 				, p_rating_level_id	  => l_competence_in_rec.rating_level_id
11810 				, p_rating_level_value	  => l_competence_in_rec.rating_level_value
11811 				, p_mandatory_flag	  => l_competence_in_rec.mandatory_flag
11812 				, p_init_msg_list         => 'F'
11813 				, p_element_rowid	  => l_cur_competence_in_rec.row_id
11814 				, p_commit		  => l_commit
11815 				, p_validate_only	  => 'N'
11816 				, p_object_version_number => l_competence_in_rec.record_version_number
11817 				, x_object_version_number => l_object_version_number
11818 				, x_msg_count		  => l_msg_count
11819 				, x_msg_data		  => l_msg_data
11820 				, x_return_status	  => l_return_status);
11821 
11822 			IF l_debug_mode = 'Y' THEN
11823 				pa_debug.write(l_module, 'After Calling PA_COMPETENCE_PUB.UPDATE_COMPETENCE_ELEMENT ', l_debug_level);
11824 				pa_debug.write(l_module, 'l_return_status '|| l_return_status || 'for record '|| i , l_debug_level);
11825 			END IF ;
11826 		END IF;-- end of API call..
11827 
11828 		l_end_msg_count := FND_MSG_PUB.count_msg;
11829 		l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
11830 
11831  		IF l_debug_mode = 'Y' THEN
11832 			pa_debug.write(l_module, 'Error Flag for Record '|| i || ' is l_local_error_flag  '|| l_local_error_flag , l_debug_level);
11833 		END IF ;
11834 
11835 		IF l_local_error_flag = 'Y' OR l_loop_msg_count > 0 THEN
11836 			l_error_flag := 'Y';
11837 			IF l_debug_mode = 'Y' THEN
11838 				pa_debug.write(l_module, 'After Calling PA_COMPETENCE_PUB.UPDATE_COMPETENCE_ELEMENT ', l_debug_level);
11839 			END IF ;
11840 			FOR j in l_start_msg_count+1..l_end_msg_count LOOP
11841 				FND_MSG_PUB.get (
11842 					  p_msg_index      =>  l_start_msg_count+1
11843 					, p_encoded        => FND_API.G_FALSE
11844 					, p_data           => l_data
11845 					, p_msg_index_out  => l_msg_index_out );
11846 
11847 				FND_MSG_PUB.DELETE_MSG(p_msg_index =>  l_start_msg_count+1);
11848 					-- Adding Record Number to The Message.
11849 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
11850 							'RECORD_NO', i,
11851 							'MESSAGE', l_data);
11852 
11853 			END LOOP;
11854 		END IF;
11855 		i := p_competence_in_tbl.next(i);
11856 	END LOOP; -- end if Internal API call Loop
11857 
11858 	IF l_debug_mode = 'Y' THEN
11859 		pa_debug.write(l_module,'Out Of PA_COMPETENCE_PUB.UPDATE_COMPETENCE_ELEMENT  API calling Loop', l_debug_level);
11860 	END IF ;
11861 
11862 	IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
11863 		RAISE FND_API.G_EXC_ERROR;
11864         END IF;
11865 
11866 	IF l_debug_mode = 'Y' THEN
11867 		PA_DEBUG.RESET_CURR_FUNCTION;
11868         END IF;
11869 
11870 	IF p_commit = FND_API.G_TRUE THEN
11871 		commit;
11872 	END IF;
11873 
11874 EXCEPTION
11875 	WHEN FND_API.G_EXC_ERROR THEN
11876 		x_return_status := FND_API.G_RET_STS_ERROR;
11877 		l_msg_count := FND_MSG_PUB.count_msg;
11878 
11879 		IF l_debug_mode = 'Y' THEN
11880 			pa_debug.write(l_module,'In Side Exception Block FND_API.G_EXC_ERROR', l_debug_level);
11881 			pa_debug.write(l_module,'Closing CURSORS if OPEN', l_debug_level);
11882 		END IF ;
11883 
11884 		IF cur_assign_info%ISOPEN THEN
11885 			CLOSE cur_assign_info;
11886 		END IF;
11887 
11888 		IF cur_status_code%ISOPEN THEN
11889 			CLOSE cur_status_code;
11890 		END IF;
11891 
11892 		IF cur_competence_details%ISOPEN THEN
11893 			CLOSE cur_competence_details;
11894 		END IF;
11895 
11896 		IF p_commit = FND_API.G_TRUE THEN
11897 			ROLLBACK TO UPDATE_REQU_COMPETENCE_SP;
11898 		END IF;
11899 
11900 		IF l_msg_count = 1 AND x_msg_data IS NULL THEN
11901 			PA_INTERFACE_UTILS_PUB.GET_MESSAGES(
11902 				  p_encoded        => FND_API.G_FALSE
11903 				, p_msg_index      => 1
11904 				, p_msg_count      => l_msg_count
11905 				, p_msg_data       => l_msg_data
11906 				, p_data           => l_data
11907 				, p_msg_index_out  => l_msg_index_out);
11908 
11909 			x_msg_data := l_data;
11910 			x_msg_count := l_msg_count;
11911 		ELSE
11912 			x_msg_count := l_msg_count;
11913 		END IF;
11914 
11915 		IF l_debug_mode = 'Y' THEN
11916 			PA_DEBUG.reset_curr_function;
11917 		END IF;
11918 
11919 	WHEN OTHERS THEN
11920 
11921 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11922 		x_msg_data      := SUBSTRB(SQLERRM,1,240);
11923 
11924 		IF l_debug_mode = 'Y' THEN
11925 			pa_debug.write(l_module,'In Side Exception Block others ', l_debug_level);
11926 			pa_debug.write(l_module,'Closing CURSORS if OPEN', l_debug_level);
11927 		END IF ;
11928 
11929 		IF cur_assign_info%ISOPEN THEN
11930 			CLOSE cur_assign_info;
11931 		END IF;
11932 
11933 		IF cur_status_code%ISOPEN THEN
11934 			CLOSE cur_status_code;
11935 		END IF;
11936 
11937 		IF cur_competence_details%ISOPEN THEN
11938 			CLOSE cur_competence_details;
11939 		END IF;
11940 
11941 		IF p_commit = FND_API.G_TRUE THEN
11942 			ROLLBACK TO UPDATE_REQU_COMPETENCE_SP;
11943 		END IF;
11944 
11945 		FND_MSG_PUB.ADD_EXC_MSG(
11946 			  p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
11947 			, p_procedure_name      => 'CREATE_REQUIREMENT_COMPETENCE'
11948 			, p_error_text          => x_msg_data);
11949 
11950 		x_msg_count     := FND_MSG_PUB.count_msg;
11951 
11952 		IF l_debug_mode = 'Y' THEN
11953 			PA_DEBUG.reset_curr_function;
11954 		END IF;
11955 		RAISE;
11956 END UPDATE_REQUIREMENT_COMPETENCE;
11957 
11958 -- Start of comments
11959 --	API name 	: DELETE_REQUIREMENT_COMPETENCE
11960 --	Type		: Public
11961 --	Pre-reqs	: None.
11962 --	Function	: This is a public API to create/nominate one or more candidates for
11963 --			  project requirements.
11964 --	Usage		: This API will be called from AMG.
11965 --	Parameters	:
11966 --	IN		:	p_commit		IN  VARCHAR2
11967 --					Identifier to commit the transaction.
11968 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
11969 --				p_init_msg_list		IN  VARCHAR2
11970 --					Identifier to initialize the error message stack.
11971 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
11972 --				p_api_version_number	IN  NUMBER			Required
11973 --					To be compliant with Applications API coding standards.
11974 --				P_COMPETENCE_IN_TBL	IN  COMPETENCE_IN_TBL_TYPE	Required
11975 --					Table of competence records. Please see the COMPETENCE_IN_TBL_TYPE datatype table
11976 --	OUT		:
11977 --				x_return_status		OUT VARCHAR2
11978 --					Indicates the return status of the API.
11979 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
11980 --				x_msg_count		OUT NUMBER
11981 --					Indicates the number of error messages in the message stack
11982 --				x_msg_data		OUT VARCHAR2
11983 --					Indicates the error message text if only one error exists
11984 --	History		:
11985 --                              01-Mar-2006 - vkadimes  - Created
11986 -- End of comments
11987 PROCEDURE DELETE_REQUIREMENT_COMPETENCE (
11988   p_commit		IN		VARCHAR2 :='F'
11989 , p_init_msg_list	IN		VARCHAR2 := 'T'
11990 , p_api_version_number	IN		NUMBER   := 1.0
11991 , p_competence_in_tbl	IN		COMPETENCE_IN_TBL_TYPE
11992 , x_return_status	OUT NOCOPY	VARCHAR2
11993 , x_msg_count		OUT NOCOPY	NUMBER
11994 , x_msg_data		OUT NOCOPY	VARCHAR2
11995 ) IS
11996 
11997 -- Debug Level
11998 l_module			VARCHAR2(255)		:= 'PA_RES_MANAGEMENT_AMG_PUB.DELETE_REQUIREMENT_COMPETENCE';
11999 l_debug_mode			VARCHAR2(1);
12000 l_debug_level			NUMBER			:=3;
12001 -- Params for pa_startup.initialize call
12002 l_calling_application		VARCHAR2(10)		:='PLSQL';
12003 l_check_id_flag			VARCHAR2(1)		:= 'Y';
12004 l_check_role_security_flag	VARCHAR2(1)		:= 'Y';
12005 l_check_resource_security_flag	VARCHAR2(1)		:= 'Y';
12006 l_calling_module		VARCHAR2(10)		:= 'AMG';
12007 --Looping params
12008 i				NUMBER;
12009 --Record Type
12010 l_competence_in_rec		COMPETENCE_IN_REC_TYPE;
12011 --Error Flags
12012 l_local_error_flag		VARCHAR2(1);
12013 l_error_flag			VARCHAR2(1);
12014 -- Message Counters
12015 l_start_msg_count		NUMBER ;
12016 l_end_msg_count			NUMBER ;
12017 l_loop_msg_count		NUMBER ;
12018 -- Miss Params List
12019 l_miss_params			VARCHAR2(2000);
12020 --temp Params
12021 l_requirement_id                NUMBER;
12022 l_dummy                         NUMBER;
12023 l_competence_element_id         NUMBER;
12024 l_competence_id			NUMBER;
12025 -- Security check Params
12026 l_project_id			NUMBER :=NULL;
12027 l_template_id			NUMBER :=NULL;
12028 l_wf_progress_flag              VARCHAR2(1);
12029 l_status_code                   VARCHAR2(10);
12030 l_req_sys_status_code		VARCHAR2(30);
12031 l_privilege			VARCHAR2(30);
12032 l_object_name			VARCHAR2(30);
12033 l_object_key			NUMBER;
12034 l_ret_code			VARCHAR2(1);
12035 l_msg_index_out                 NUMBER;
12036 l_msg_data                      VARCHAR2(2000);
12037 l_msg_count                     NUMBER;
12038 l_return_status                 VARCHAR2(1);
12039 --Internal API calling Params
12040 l_commit			VARCHAR2(1)             := FND_API.G_FALSE;
12041 l_object_version_number		NUMBER;
12042 l_data				VARCHAR2(2000);
12043 
12044 -- Given Competence Element id this cursor is used to get the info about that
12045 -- Perticulat competence
12046 CURSOR cur_competence_details(l_competence_element_id NUMBER) IS
12047 SELECT *
12048 FROM PA_OPEN_ASGMT_COMPETENCES_V
12049 WHERE competence_element_id = l_competence_element_id;
12050 
12051 
12052 -- This cursor is used to get the information like which Requirement
12053 -- competence belong to and validity .
12054 CURSOR cur_assign_info (l_requirement_id IN NUMBER ) IS
12055 SELECT project_id,assignment_template_id,status_code,mass_wf_in_progress_flag
12056 FROM	pa_project_assignments
12057 where assignment_id = l_requirement_id;
12058 
12059 -- To get the project system status code for
12060 -- perticular requirement.
12061 CURSOR cur_status_code(l_status_code VARCHAR2  ) IS
12062 SELECT project_system_status_code
12063 FROM  pa_project_statuses
12064 WHERE project_status_code = l_status_code
12065 AND status_type= 'OPEN_ASGMT';
12066 
12067 -- Record type
12068 l_cur_competence_in_rec         PA_OPEN_ASGMT_COMPETENCES_V%ROWTYPE;
12069 
12070 BEGIN
12071 	-- Flows which are supported by this API
12072 	-----------------------------------------
12073 	--Deleting one competence from Both Project Requirement and Team Template Requirement by Passing
12074 	--Competence_element_id.
12075 	--Flows which are not supported by this API
12076 	--------------------------------------------
12077 	-- Deleting the Requirement by passing Requirement id and one of competence_id or competence alias or
12078 	-- competence Name.
12079 
12080 	x_return_status := FND_API.G_RET_STS_SUCCESS;
12081 
12082 	l_debug_mode    := NVL(FND_PROFILE.value_specific('PA_DEBUG_MODE',fnd_global.user_id,fnd_global.login_id,275,null,null), 'N');
12083 
12084 	IF l_debug_mode = 'Y' THEN
12085 		PA_DEBUG.set_curr_function(p_function => 'DELETE_REQUIREMENT_COMPETENCE', p_debug_mode => l_debug_mode);
12086 	END IF;
12087 
12088 	-- Resetting the Error Stack.
12089 	IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
12090 		FND_MSG_PUB.initialize;
12091 	END IF;
12092 
12093 	IF P_COMMIT = FND_API.G_TRUE THEN
12094 		SAVEPOINT DELETE_REQU_COMPETENCE_SP;
12095 	END IF ;
12096 
12097 	IF l_debug_mode = 'Y' THEN
12098 		pa_debug.write(l_module,'Save Point create ', l_debug_level);
12099 		pa_debug.write(l_module,'Start of DELETE_REQUIREMENT_COMPETENCE ', l_debug_level);
12100 		pa_debug.write(l_module,'Before calling pa_startup.initialize ', l_debug_level);
12101 	END IF ;
12102 
12103 	PA_STARTUP.INITIALIZE(
12104 		   p_calling_application		=> l_calling_application
12105 		 , p_calling_module			=> l_calling_module
12106 		 , p_check_id_flag			=> l_check_id_flag
12107 		 , p_check_role_security_flag		=> l_check_role_security_flag
12108 		 , p_check_resource_Security_flag	=> l_check_resource_Security_flag
12109 		 , p_debug_level			=> l_debug_level);
12110 
12111 	IF l_debug_mode = 'Y' THEN
12112 		pa_debug.write(l_module,'After calling pa_startup.initialize ', l_debug_level);
12113 	END IF ;
12114 
12115 	IF l_debug_mode = 'Y' THEN
12116 		pa_debug.write(l_module,'Printing Input Parameters......', l_debug_level);
12117 
12118 		i := p_competence_in_tbl.first();
12119 
12120 		WHILE i IS NOT NULL LOOP
12121 
12122 			l_competence_in_rec := p_competence_in_tbl(i);
12123 
12124 			pa_debug.write(l_module,'Values for Record No :'|| i , l_debug_level);
12125 			pa_debug.write(l_module,'l_competence_in_rec.requirement_id for record ' || i || l_competence_in_rec.requirement_id , l_debug_level);
12126 			pa_debug.write(l_module, 'l_competence_in_rec.competence_element_id for record ' || i || l_competence_in_rec.competence_element_id  , l_debug_level);
12127 			pa_debug.write(l_module, 'l_competence_in_rec.competence_id for record ' || i || l_competence_in_rec.competence_id	    , l_debug_level);
12128 			pa_debug.write(l_module, 'l_competence_in_rec.competence_name for record ' || i || l_competence_in_rec.competence_name , l_debug_level);
12129 			pa_debug.write(l_module, 'l_competence_in_rec.competence_alias for record ' || i || l_competence_in_rec.competence_alias , l_debug_level);
12130 			pa_debug.write(l_module, 'l_competence_in_rec.rating_level_id for record ' || i ||  l_competence_in_rec.rating_level_id , l_debug_level);
12131 			pa_debug.write(l_module, 'l_competence_in_rec.rating_level_value for record ' || i ||  l_competence_in_rec.rating_level_value , l_debug_level);
12132 			pa_debug.write(l_module, 'l_competence_in_rec.mandatory_flag for record ' || i ||  l_competence_in_rec.mandatory_flag , l_debug_level);
12133 			pa_debug.write(l_module, 'l_competence_in_rec.record_version_number for record ' || i ||  l_competence_in_rec.record_version_number , l_debug_level);
12134 
12135 			i :=p_competence_in_tbl.next(i);
12136 
12137 		END LOOP;
12138 
12139 	END IF;
12140 
12141 	i := p_competence_in_tbl.first();
12142 
12143 	WHILE i IS NOT NULL LOOP
12144 
12145 		IF l_debug_mode = 'Y' THEN
12146 			pa_debug.write(l_module,'Inside Loop For Record  '|| i , l_debug_level);
12147 		END IF ;
12148 		-- Initializing the local Params for loop
12149 		l_local_error_flag	:= 'N';
12150 		l_start_msg_count	:= FND_MSG_PUB.count_msg;
12151 		l_competence_in_rec	:= NULL ;
12152 		l_miss_params		:= NULL;
12153 		l_competence_in_rec	:= P_COMPETENCE_IN_TBL(i);
12154 		-- check for missparams.......
12155 		IF l_competence_in_rec.competence_element_id IS NULL OR
12156 		   l_competence_in_rec.competence_element_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
12157 			l_miss_params := l_miss_params || 'COMPETENCE_ELEMENT_ID';
12158 		END IF;
12159 
12160 		IF l_miss_params IS NOT NULL THEN
12161 			l_local_error_flag := 'Y';
12162  			PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
12163 			'INVALID_PARAMS', l_miss_params);
12164 		END IF;
12165 
12166 		IF  l_local_error_flag <> 'Y' THEN
12167 			OPEN cur_competence_details(l_competence_in_rec.competence_element_id);
12168 			FETCH cur_competence_details INTO l_cur_competence_in_rec;
12169 			-- Checking for the validity of competence id
12170 			IF cur_competence_details%NOTFOUND THEN
12171 				l_local_error_flag := 'Y';
12172                                 l_miss_params := l_miss_params || 'COMPETENCE_ELEMENT_ID';
12173                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
12174                                 'INVALID_PARAMS', l_miss_params);
12175 			END IF;
12176 
12177 			CLOSE cur_competence_details;
12178 			-- Getting the requirement_id for that Record
12179 			l_requirement_id := l_cur_competence_in_rec.assignment_id;
12180 
12181 		END IF;
12182 
12183 		IF  l_local_error_flag <> 'Y' THEN
12184 
12185 			IF l_competence_in_rec.record_version_number IS NULL
12186 			OR l_competence_in_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
12187 
12188 				l_competence_in_rec.record_version_number :=l_cur_competence_in_rec.object_version_number;
12189 
12190 			END IF;
12191 
12192 			OPEN cur_assign_info(l_requirement_id);
12193 			FETCH cur_assign_info INTO l_project_id,l_template_id,l_status_code,l_wf_progress_flag;
12194 			CLOSE cur_assign_info;
12195 
12196 			OPEN cur_status_code(l_status_code);
12197 			FETCH cur_status_code INTO l_req_sys_status_code;
12198 			CLOSE cur_status_code;
12199 
12200 			IF l_debug_mode = 'Y' THEN
12201 				pa_debug.write(l_module, 'Checking Security for record No'||i, l_debug_level);
12202 			END IF;
12203 
12204 			IF l_project_id IS NOT NULL THEN
12205 				l_privilege := 'PA_ASN_BASIC_INFO_ED ';
12206 				l_object_name := 'PA_PROJECTS';
12207 				l_object_key := l_project_id;
12208 			ELSIF l_template_id IS NOT NULL THEN
12209 				l_privilege := 'PA_PRM_DEFINE_TEAM_TEMPLATE';
12210 				l_object_name := null;
12211 				l_object_key := null;
12212 		        ELSE
12213                                 -- This should never happen.
12214 				PA_UTILS.ADD_MESSAGE('PA', 'PA_UNEXPECTED ERROR');
12215                                 raise FND_API.G_EXC_ERROR;
12216                         END IF;
12217 
12218                         IF l_debug_mode = 'Y' THEN
12219                                 pa_debug.write(l_module, 'Calling  PA_SECURITY_PVT.CHECK_USER_PRIVILEGE for Record '||i||'with Following Values', l_debug_level);
12220 				pa_debug.write(l_module, 'l_privilege'|| l_privilege, l_debug_level);
12221 				pa_debug.write(l_module, 'l_object_name'||l_object_name, l_debug_level);
12222 				pa_debug.write(l_module, 'l_object_key'||l_object_key, l_debug_level);
12223                         END IF;
12224 
12225                         l_return_status := FND_API.G_RET_STS_SUCCESS;
12226                         l_ret_code := 'T';
12227 
12228 			-- Checking Security at project level or at Template level
12229                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
12230                                   x_ret_code       => l_ret_code
12231                                 , x_return_status  => l_return_status
12232                                 , x_msg_count      => l_msg_count
12233                                 , x_msg_data       => l_msg_data
12234                                 , p_privilege      => l_privilege
12235                                 , p_object_name    => l_object_name
12236                                 , p_object_key     => l_object_key
12237 				,p_init_msg_list   => FND_API.G_FALSE);
12238 
12239                          IF l_debug_mode = 'Y' THEN
12240                                 pa_debug.write(l_module, 'Return Status from PA_SECURITY_PVT.CHECK_USER_PRIVILEGE for Record '||i||'is l_return_status '|| l_return_status , l_debug_level);
12241 				pa_debug.write(l_module, 'l_ret_code'|| l_ret_code, l_debug_level);
12242 			 END IF ;
12243 
12244 			IF (nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS)
12245 			AND l_project_id IS NOT NULL  THEN
12246 			-- If project level security Fails wll call Requirement level Security
12247 				IF l_debug_mode = 'Y' THEN
12248 					 pa_debug.write(l_module,'No Access Found at Project level checking at Requirement level', l_debug_level);
12249 				END IF ;
12250 
12251 				l_privilege := 'PA_ASN_BASIC_INFO_ED';
12252 				l_object_name := 'PA_PROJECT_ASSIGNMENTS';
12253 				l_object_key := l_requirement_id;
12254 				PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
12255 					  x_ret_code       => l_ret_code
12256 					, x_return_status  => l_return_status
12257 					, x_msg_count      => l_msg_count
12258 					, x_msg_data       => l_msg_data
12259 					, p_privilege      => l_privilege
12260 					, p_object_name    => l_object_name
12261 					, p_object_key     => l_object_key
12262 					, p_init_msg_list   => FND_API.G_FALSE );
12263 
12264 				IF l_debug_mode = 'Y' THEN
12265 					pa_debug.write(l_module,'Return Status are Requirement level l_date return value l_ret_code'|| l_ret_code, l_debug_level);
12266 				END IF ;
12267 
12268 			END IF;
12269 
12270 			IF (nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
12271 				-- This message does not have token defined, but intentionally putting token
12272                                 -- bcoz we still want to show the privielge name which is missing
12273 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_COMP'
12274 						    ,'MISSING_PRIVILEGE', l_privilege);
12275                                 l_local_error_flag := 'Y';
12276 		        END IF ;
12277 			-- checking Assignment Status.
12278 			IF l_req_sys_status_code IN ('ASGMT_APPRVL_SUBMITTED','OPEN_ASGMT_FILLED', 'ASGMT_APPRVL_CANCELED') THEN
12279 	                     -- Need more specific message saying.. cant edit assignment.
12280 				 PA_UTILS.ADD_MESSAGE('PA','PA_ASSIGNMENT_WF');
12281 				 l_local_error_flag := 'Y';
12282 			END IF ;
12283 			-- Checking WF status..
12284 			IF l_wf_progress_flag = 'Y' THEN
12285 				PA_UTILS.ADD_MESSAGE('PA','PA_ASSIGNMENT_WF');
12286 				l_local_error_flag := 'Y';
12287 			END IF;
12288 
12289 			IF l_debug_mode = 'Y' THEN
12290 				pa_debug.write(l_module, 'End of Security  check '|| l_ret_code, l_debug_level);
12291 			END IF ;
12292 		END IF;
12293 		-- Nulling out the Params as they will not be used.
12294 		l_competence_in_rec.requirement_id     := l_cur_competence_in_rec.assignment_id;
12295 		l_competence_in_rec.competence_id      := l_cur_competence_in_rec.competence_id;
12296 		l_competence_in_rec.competence_alias   := NULL;
12297 		l_competence_in_rec.competence_name	 := NULL;
12298 		l_competence_in_rec.rating_level_id	 := NULL;
12299 		l_competence_in_rec.rating_level_value := NULL;
12300 		l_competence_in_rec.mandatory_flag     := NULL;
12301 
12302 		IF  l_local_error_flag <> 'Y' THEN
12303 		  		-- No error occured.ie local error Flag is N
12304 			IF l_debug_mode = 'Y' THEN
12305 				pa_debug.write(l_module, 'Calling PA_COMPETENCE_PUB.DELETE_COMPETENCE_ELEMENT', l_debug_level);
12306 			END IF ;
12307 
12308 			l_return_status := FND_API.G_RET_STS_SUCCESS;
12309 
12310 			PA_COMPETENCE_PUB.DELETE_COMPETENCE_ELEMENT(
12311 				  p_object_name			=> 'OPEN_ASSIGNMENT'
12312 				, p_object_id			=> l_competence_in_rec.requirement_id
12313 				, p_competence_id		=> l_competence_in_rec.competence_id
12314 				, p_competence_alias		=> l_competence_in_rec.competence_alias
12315 				, p_competence_name		=> l_competence_in_rec.competence_name
12316 				, p_element_rowid		=> l_cur_competence_in_rec.row_id
12317 				, p_element_id			=> l_competence_in_rec.competence_element_id
12318 				, p_init_msg_list		=> 'F'
12319 				, p_commit			=> l_commit
12320 				, p_validate_only		=> 'F'
12321 				, p_object_version_number	=>l_competence_in_rec.record_version_number
12322 				, x_return_status		=> l_return_status
12323 				, x_msg_count			=> l_msg_count
12324 				, x_msg_data			=> l_msg_data);
12325 
12326 			IF l_debug_mode = 'Y' THEN
12327 				pa_debug.write(l_module,'After Calling PA_COMPETENCE_PUB.DELETE_COMPETENCE_ELEMENT ', l_debug_level);
12328 				pa_debug.write(l_module,'l_return_status '|| l_return_status || 'for record '|| i , l_debug_level);
12329 			END IF ;
12330 
12331 		END IF;-- end of API call..
12332 
12333 		l_end_msg_count := FND_MSG_PUB.count_msg;
12334 		l_loop_msg_count := l_end_msg_count -  l_start_msg_count;
12335 
12336  		IF l_debug_mode = 'Y' THEN
12337 			pa_debug.write(l_module,'Error Flag for Record '|| i || ' is l_local_error_flag  '|| l_local_error_flag , l_debug_level);
12338 		END IF ;
12339 
12340 		IF l_local_error_flag = 'Y' OR l_loop_msg_count > 0 THEN
12341 			l_error_flag := 'Y';
12342 			IF l_debug_mode = 'Y' THEN
12343 				pa_debug.write(l_module,'After Calling PA_COMPETENCE_PUB.DELETE_COMPETENCE_ELEMENT ', l_debug_level);
12344 			END IF ;
12345 			FOR j in l_start_msg_count+1..l_end_msg_count LOOP
12346 				FND_MSG_PUB.GET (
12347 					  p_msg_index      =>  l_start_msg_count+1
12348 					, p_encoded        => FND_API.G_FALSE
12349 					, p_data           => l_data
12350 					, p_msg_index_out  => l_msg_index_out );
12351 
12352 				FND_MSG_PUB.DELETE_MSG(p_msg_index =>  l_start_msg_count+1);
12353 					-- Adding Record Number to The Message.
12354 				PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
12355 							'RECORD_NO', i,
12356 							'MESSAGE', l_data);
12357 			END LOOP;
12358 		END IF;
12359 			i := p_competence_in_tbl.next(i);
12360 	END LOOP; -- end if Internal API call Loop
12361 
12362 	IF l_debug_mode = 'Y' THEN
12363 		pa_debug.write(l_module,'Out Of PA_COMPETENCE_PUB.DELETE_COMPETENCE_ELEMENT  API calling Loop', l_debug_level);
12364 	END IF ;
12365 
12366 	IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
12367 		RAISE FND_API.G_EXC_ERROR;
12368         END IF;
12369 
12370 	IF l_debug_mode = 'Y' THEN
12371               PA_DEBUG.RESET_CURR_FUNCTION;
12372         END IF;
12373 
12374 	IF p_commit = FND_API.G_TRUE THEN
12375 		commit;
12376 	END IF;
12377 
12378 EXCEPTION
12379 	WHEN FND_API.G_EXC_ERROR THEN
12380 		x_return_status := FND_API.G_RET_STS_ERROR;
12381 		l_msg_count := FND_MSG_PUB.count_msg;
12382 
12383 		IF l_debug_mode = 'Y' THEN
12384 			pa_debug.write(l_module,'In Side Exception Block FND_API.G_EXC_ERROR', l_debug_level);
12385 			pa_debug.write(l_module,'Closing CURSORS if OPEN', l_debug_level);
12386 		END IF ;
12387 
12388 		IF cur_assign_info%ISOPEN THEN
12389 			CLOSE cur_assign_info;
12390 		END IF;
12391 
12392 		IF cur_status_code%ISOPEN THEN
12393 			CLOSE cur_status_code;
12394 		END IF;
12395 
12396 		IF cur_competence_details%ISOPEN THEN
12397 			CLOSE cur_competence_details;
12398 		END IF;
12399 
12400 		IF p_commit = FND_API.G_TRUE THEN
12401 			ROLLBACK TO DELETE_REQU_COMPETENCE_SP;
12402 		END IF;
12403 
12404 		IF l_msg_count = 1 AND x_msg_data IS NULL THEN
12405 			PA_INTERFACE_UTILS_PUB.GET_MESSAGES(
12406 				  p_encoded        => FND_API.G_FALSE
12407 				, p_msg_index      => 1
12408 				, p_msg_count      => l_msg_count
12409 				, p_msg_data       => l_msg_data
12410 				, p_data           => l_data
12411 				, p_msg_index_out  => l_msg_index_out);
12412 
12413 			x_msg_data := l_data;
12414 			x_msg_count := l_msg_count;
12415 		ELSE
12416 			x_msg_count := l_msg_count;
12417 		END IF;
12418 
12419 		IF l_debug_mode = 'Y' THEN
12420 			PA_DEBUG.reset_curr_function;
12421 		END IF;
12422 
12423 	WHEN OTHERS THEN
12424 
12425 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
12426 		x_msg_data      := SUBSTRB(SQLERRM,1,240);
12427 
12428 		IF l_debug_mode = 'Y' THEN
12429 			pa_debug.write(l_module,'In Side Exception Block others ', l_debug_level);
12430 			pa_debug.write(l_module,'Closing CURSORS if OPEN', l_debug_level);
12431 		END IF ;
12432 
12433 		IF cur_assign_info%ISOPEN THEN
12434 			CLOSE cur_assign_info;
12435 		END IF;
12436 
12437 		IF cur_status_code%ISOPEN THEN
12438 			CLOSE cur_status_code;
12439 		END IF;
12440 
12441 		IF cur_competence_details%ISOPEN THEN
12442 			CLOSE cur_competence_details;
12443 		END IF;
12444 
12445 		IF p_commit = FND_API.G_TRUE THEN
12446 			ROLLBACK TO DELETE_REQU_COMPETENCE_SP;
12447 		END IF;
12448 
12449 		FND_MSG_PUB.ADD_EXC_MSG(
12450 			  p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
12451 			, p_procedure_name      => 'CREATE_REQUIREMENT_COMPETENCE'
12452 			, p_error_text          => x_msg_data);
12453 
12454 		x_msg_count     := FND_MSG_PUB.count_msg;
12455 
12456 		IF l_debug_mode = 'Y' THEN
12457 			PA_DEBUG.reset_curr_function;
12458 		END IF;
12459 
12460 		RAISE;
12461 
12462 END DELETE_REQUIREMENT_COMPETENCE;
12463 
12464 -- Start of comments
12465 --	API name 	: CREATE_CANDIDATES
12466 --	Type		: Public
12467 --	Pre-reqs	: None.
12468 --	Function	: This is a public API to create/nominate one or more candidates for
12469 --			  project requirements.
12470 --	Usage		: This API will be called from AMG.
12471 --	Parameters	:
12472 --	IN		:	p_commit		IN  VARCHAR2
12473 --					Identifier to commit the transaction.
12474 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
12475 --				p_init_msg_list		IN  VARCHAR2
12476 --					Identifier to initialize the error message stack.
12477 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
12478 --				p_api_version_number	IN  NUMBER			Required
12479 --					To be compliant with Applications API coding standards.
12480 --				p_candidate_in_tbl	IN  CANDIDATE_IN_TBL_TYPE	Required
12481 --					Table of candidate records. Please see the CANDIDATE_IN_TBL_TYPE datatype table.
12482 --	OUT		:
12483 --				x_candidate_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
12484 --					Table to store the candidate ids created by the API.
12485 --					Reference : pa_candidates.candidate_id
12486 --				x_return_status		OUT VARCHAR2
12487 --					Indicates the return status of the API.
12488 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
12489 --				x_msg_count		OUT NUMBER
12490 --					Indicates the number of error messages in the message stack
12491 --				x_msg_data		OUT VARCHAR2
12492 --					Indicates the error message text if only one error exists
12493 --	History		:
12494 --                              01-Mar-2006 - msachan  - Created
12495 -- End of comments
12496 PROCEDURE CREATE_CANDIDATES
12497 (
12498   p_commit		        IN		VARCHAR2 := FND_API.G_FALSE
12499 , p_init_msg_list	        IN		VARCHAR2 := FND_API.G_TRUE
12500 , p_api_version_number	        IN		NUMBER   := 1.0
12501 , p_candidate_in_tbl	        IN		CANDIDATE_IN_TBL_TYPE
12502 , x_candidate_id_tbl	        OUT     NOCOPY	SYSTEM.PA_NUM_TBL_TYPE
12503 , x_return_status	        OUT     NOCOPY	VARCHAR2
12504 , x_msg_count		        OUT     NOCOPY 	NUMBER
12505 , x_msg_data		        OUT     NOCOPY 	VARCHAR2
12506 )
12507 IS
12508 	l_debug_mode                    VARCHAR2(1);
12509         l_module                        VARCHAR2(100)           := 'PA_CANDIDATE_AMG_PUB.CREATE_CANDIDATES';
12510 	l_calling_application           VARCHAR2(10)            := 'PLSQL';
12511         l_calling_module                VARCHAR2(10)            := 'AMG';
12512         l_check_id_flag                 VARCHAR2(1)             := 'Y';
12513         l_check_role_security_flag      VARCHAR2(1)             := 'Y';
12514         l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
12515 	l_log_level                     NUMBER                  := 3;
12516 
12517 	i                               NUMBER;
12518 	l_missing_params                VARCHAR2(1000);
12519 	l_project_system_status_code	VARCHAR2(30);
12520 	l_error_flag_local		VARCHAR2(1)             := 'N';
12521 	l_error_flag			VARCHAR2(1)             := 'N';
12522 	l_start_msg_count               NUMBER                  := 0;
12523 	l_end_msg_count                 NUMBER                  := 0;
12524 	l_loop_msg_count                NUMBER                  := 0;
12525 	l_candidate_in_rec		CANDIDATE_IN_REC_TYPE;
12526 	l_project_id			NUMBER;
12527 	l_privilege                     VARCHAR2(30);
12528         l_object_name                   VARCHAR2(30);
12529         l_object_key                    NUMBER;
12530 	l_resource_valid                VARCHAR2(1)             := 'N';
12531 	l_privilege_name		VARCHAR2(40)		:= null;
12532 	l_project_super_user            VARCHAR2(1)             := 'N';
12533         l_ret_code                      VARCHAR2(1);
12534 	l_person_id                     NUMBER;
12535 	l_logged_person_id		NUMBER;
12536 	l_asmt_start_date		DATE;
12537 	l_resource_start_date		DATE;
12538 	l_resource_end_date		DATE;
12539 	l_requirement_start_date	DATE;
12540 	l_requirement_end_date		DATE;
12541         l_status_code                   VARCHAR2(30);
12542         l_system_status_code            VARCHAR2(30);
12543         l_mass_wf_in_progress_flag      VARCHAR2(1);
12544 	l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
12545 	l_msg_count                     NUMBER;
12546 	l_msg_data                      VARCHAR2(2000);
12547 	l_msg_index_out                 NUMBER;
12548 	l_data                          VARCHAR2(2000);
12549 
12550 CURSOR c_get_requirement_info(c_assignment_id NUMBER) IS
12551 SELECT project_id, start_date, status_code, mass_wf_in_progress_flag
12552 FROM   pa_project_assignments
12553 WHERE  assignment_id = c_assignment_id
12554 AND    assignment_type = 'OPEN_ASSIGNMENT';
12555 
12556 CURSOR c_get_system_status_code(c_status_code VARCHAR2, c_status_type VARCHAR2) IS
12557 SELECT project_system_status_code
12558 FROM pa_project_statuses
12559 WHERE  trunc(SYSDATE) BETWEEN start_date_active AND nvl(end_date_active, trunc(SYSDATE))
12560 AND    status_type = c_status_type
12561 AND    project_status_code = c_status_code;
12562 
12563 CURSOR c_get_resource_info(c_resource_id NUMBER) IS
12564 SELECT resource_source_id
12565 FROM   pa_c_elig_resource_v
12566 WHERE  resource_id = c_resource_id;
12567 
12568 CURSOR c_get_person_id(c_user_id NUMBER) IS
12569 SELECT employee_id
12570 FROM   fnd_user
12571 WHERE  user_id = c_user_id;
12572 
12573 CURSOR c_get_candidate_id(c_assignment_id NUMBER, c_resource_id NUMBER) IS
12574 SELECT candidate_id
12575 FROM   pa_candidates
12576 WHERE  assignment_id = c_assignment_id
12577 AND    resource_id   = c_resource_id;
12578 
12579 BEGIN
12580 
12581 	--Flows which are supported by this API
12582 		  ---------------------------------------
12583 		  --1. Creating candidates for given open requirements.
12584 		  --        1.1 Validating requirement_id
12585 		  --        1.2 Validating resource_id if it is not null
12586 		  --        1.3 Validating status_code to be a valid code
12587 		  --        1.3 Given requirement id and either of resource_id or person_id, a candidate is created for that open requirement
12588 		  --        1.4 Returning table return the candidate_id of the candidates created.
12589 	--Flows which are not supported by this API
12590 		  -------------------------------------------
12591 		  --1. Validating person_id is not done in this api. It is handled by the called public api.
12592 
12593 	x_return_status := FND_API.G_RET_STS_SUCCESS;
12594 	x_candidate_id_tbl := SYSTEM.PA_NUM_TBL_TYPE();
12595 
12596         l_debug_mode  := NVL(FND_PROFILE.value_specific('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
12597 
12598         IF l_debug_mode = 'Y' THEN
12599                 PA_DEBUG.set_curr_function(p_function => 'CREATE_CANDIDATES', p_debug_mode => l_debug_mode);
12600         END IF;
12601 
12602         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list,FND_API.G_TRUE)) THEN
12603                 FND_MSG_PUB.initialize;
12604         END IF;
12605 
12606         IF p_commit = FND_API.G_TRUE THEN
12607                 savepoint CREATE_CANDIDATES_SP;
12608         END IF;
12609 
12610         IF l_debug_mode = 'Y' THEN
12611                 pa_debug.write(l_module, 'Start of CREATE_CANDIDATES', l_log_level);
12612         END IF;
12613 
12614         IF l_debug_mode = 'Y' THEN
12615                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
12616 		pa_debug.write(l_module, 'p_commit '||p_commit, l_log_level);
12617 		pa_debug.write(l_module, 'p_init_msg_list '||p_init_msg_list, l_log_level);
12618 		pa_debug.write(l_module, 'p_api_version_number '||p_api_version_number, l_log_level);
12619                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
12620                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
12621                 i := p_candidate_in_tbl.first;
12622                 WHILE i IS NOT NULL LOOP
12623                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').candidate_id '||p_candidate_in_tbl(i).candidate_id, l_log_level);
12624                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').requirement_id '||p_candidate_in_tbl(i).requirement_id, l_log_level);
12625                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').resource_id '||p_candidate_in_tbl(i).resource_id, l_log_level);
12626                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').person_id '||p_candidate_in_tbl(i).person_id, l_log_level);
12627                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').status_code '||p_candidate_in_tbl(i).status_code, l_log_level);
12628                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').nomination_comments '||p_candidate_in_tbl(i).nomination_comments, l_log_level);
12629                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').ranking '||p_candidate_in_tbl(i).ranking, l_log_level);
12630                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').change_reason_code '||p_candidate_in_tbl(i).change_reason_code, l_log_level);
12631                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').record_version_number '||p_candidate_in_tbl(i).record_version_number, l_log_level);
12632                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
12633                         i := p_candidate_in_tbl.next(i);
12634                 END LOOP;
12635         END IF;
12636 
12637         PA_STARTUP.INITIALIZE(
12638                   p_calling_application		 => l_calling_application
12639                 , p_calling_module		 => l_calling_module
12640                 , p_check_id_flag		 => l_check_id_flag
12641                 , p_check_role_security_flag	 => l_check_role_security_flag
12642                 , p_check_resource_security_flag => l_check_resource_security_flag
12643                 , p_debug_level			 => l_log_level
12644                 );
12645 
12646         IF l_debug_mode = 'Y' THEN
12647                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
12648         END IF;
12649 
12650         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
12651         --IF l_prm_license_flag <> 'Y' THEN
12652         --        null;
12653         --END IF;
12654 
12655         l_project_super_user := FND_PROFILE.value_specific('PA_SUPER_PROJECT',fnd_global.user_id,fnd_global.login_id,275,null,null);
12656 
12657         i := p_candidate_in_tbl.first;
12658 
12659         WHILE i is not NULL LOOP
12660 
12661                 l_missing_params := null;
12662                 l_error_flag_local := 'N';
12663                 l_start_msg_count := FND_MSG_PUB.count_msg;
12664 
12665                 l_candidate_in_rec := p_candidate_in_tbl(i);
12666 
12667 	        IF l_debug_mode = 'Y' THEN
12668                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
12669                         pa_debug.write(l_module, '---------------------------------------------------------', l_log_level);
12670 	                pa_debug.write(l_module, 'Inside while loop. Blanking out the parameters not passed', l_log_level);
12671 		END IF;
12672 
12673                 -- Blank Out Parameters if not passed
12674 		-------------------------------------
12675                 IF l_candidate_in_rec.requirement_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
12676                         l_candidate_in_rec.requirement_id := null;
12677                 END IF;
12678 
12679                 IF l_candidate_in_rec.resource_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
12680                         l_candidate_in_rec.resource_id := null;
12681                 END IF;
12682 
12683                 IF l_candidate_in_rec.person_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
12684                         l_candidate_in_rec.person_id := null;
12685                 END IF;
12686 
12687                 IF l_candidate_in_rec.status_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
12688                         l_candidate_in_rec.status_code := 107; -- Default to Pending Review
12689                 END IF;
12690 
12691                 IF l_candidate_in_rec.nomination_comments = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
12692                         l_candidate_in_rec.nomination_comments := null;
12693                 END IF;
12694 
12695 		-- Null out the parameters which are not required in create flow
12696                 l_candidate_in_rec.candidate_id := null;
12697                 l_candidate_in_rec.ranking := null;
12698                 l_candidate_in_rec.change_reason_code := null;
12699                 l_candidate_in_rec.record_version_number := null;
12700 
12701 	        IF l_debug_mode = 'Y' THEN
12702 	                pa_debug.write(l_module, 'Blanking out missing and not required parameters over.', l_log_level);
12703 	                pa_debug.write(l_module, 'Mandatory parameters validation begin.', l_log_level);
12704 	        END IF;
12705 
12706                 -- Mandatory Parameters Check
12707 		-----------------------------
12708                 IF l_candidate_in_rec.requirement_id IS NULL THEN
12709                         l_missing_params := l_missing_params||', REQUIREMENT_ID';
12710 		ELSE
12711 			-- Check for requirement id valid and assignment type OPEN_ASSIGNMENT
12712                         l_status_code := null;
12713                         l_mass_wf_in_progress_flag := null;
12714                         l_system_status_code := null;
12715 
12716 			OPEN c_get_requirement_info(l_candidate_in_rec.requirement_id);
12717 			FETCH c_get_requirement_info INTO l_project_id, l_requirement_start_date, l_status_code, l_mass_wf_in_progress_flag;
12718 			IF c_get_requirement_info%NOTFOUND IS NULL THEN
12719                                 l_missing_params := l_missing_params||', REQUIREMENT_ID';
12720                         ELSE
12721                                 l_system_status_code := null;
12722                                 OPEN c_get_system_status_code(l_status_code, 'OPEN_ASGMT');
12723                                 FETCH c_get_system_status_code INTO l_system_status_code;
12724                                 CLOSE c_get_system_status_code;
12725 
12726                                 IF l_system_status_code IN ('OPEN_ASGMT_FILLED','OPEN_ASGMT_CANCEL') THEN
12727                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_STS_ACT_NOT_ALLW');
12728                                         l_error_flag_local := 'Y';
12729                                 END IF;
12730 
12731                                 IF nvl(l_mass_wf_in_progress_flag, 'N') = 'Y' THEN
12732                                         PA_UTILS.ADD_MESSAGE('PA', 'PA_ASSIGNMENT_WF');
12733                                         l_error_flag_local := 'Y';
12734                                 END IF;
12735 			END IF;
12736 			CLOSE c_get_requirement_info;
12737                 END IF;
12738 
12739                 IF l_candidate_in_rec.resource_id IS NULL AND l_candidate_in_rec.person_id IS NULL THEN
12740                         l_missing_params := l_missing_params||', RESOURCE_ID, PERSON_ID';
12741                 END IF;
12742 
12743                 IF l_candidate_in_rec.status_code IS NOT NULL THEN
12744 			l_project_system_status_code := null;
12745 			OPEN  c_get_system_status_code(l_candidate_in_rec.status_code, 'CANDIDATE');
12746 			FETCH c_get_system_status_code INTO l_project_system_status_code;
12747 			CLOSE c_get_system_status_code;
12748 			IF l_project_system_status_code IS NULL OR l_project_system_status_code NOT IN ('CANDIDATE_PENDING_REVIEW', 'CANDIDATE_UNDER_REVIEW', 'CANDIDATE_SUITABLE') THEN
12749 				l_missing_params := l_missing_params||', STATUS_CODE';
12750 			END IF;
12751                 END IF;
12752 
12753                 IF l_debug_mode = 'Y' THEN
12754                         pa_debug.write(l_module, 'Mandatory parameter validation over. l_missing_params='||l_missing_params, l_log_level);
12755                 END IF;
12756 
12757                 IF l_missing_params IS NOT NULL THEN
12758                         l_error_flag_local := 'Y';
12759                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
12760                                                 'INVALID_PARAMS', l_missing_params);
12761                 END IF;
12762 
12763 
12764 		-- Validate resource id and/or person id
12765 		----------------------------------------
12766 		IF l_error_flag_local <> 'Y' THEN
12767 			IF l_candidate_in_rec.resource_id IS NOT NULL THEN
12768 				OPEN c_get_resource_info(l_candidate_in_rec.resource_id);
12769                                 FETCH c_get_resource_info INTO l_person_id;
12770 				IF c_get_resource_info%NOTFOUND IS NULL THEN
12771 	                                l_error_flag_local := 'Y';
12772 					PA_UTILS.ADD_MESSAGE ( p_app_short_name => 'PA'
12773 						              ,p_msg_name       => 'PA_RESOURCE_INVALID_AMBIGUOUS' );
12774 				END IF;
12775                                 CLOSE c_get_resource_info;
12776 			ELSIF l_candidate_in_rec.person_id IS NOT NULL THEN
12777 				l_person_id := l_candidate_in_rec.person_id;
12778 			ELSE
12779 				l_error_flag_local := 'Y';
12780 			END IF;
12781 		END IF;
12782 
12783 		-- Security Check
12784                 -----------------
12785 		-- Check PA_CREATE_CANDIDATES privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS as done in AddCandidatesTopCO.java
12786                 IF l_error_flag_local <> 'Y' THEN
12787 
12788                         IF l_debug_mode = 'Y' THEN
12789                                 pa_debug.write(l_module, 'Checking PA_CREATE_CANDIDATES privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS for record#'||i, l_log_level);
12790                         END IF;
12791 
12792                         l_privilege   := 'PA_CREATE_CANDIDATES';
12793                         l_object_name := 'PA_PROJECTS';
12794 			l_object_key  := l_project_id;
12795 
12796                         l_return_status := FND_API.G_RET_STS_SUCCESS;
12797                         l_ret_code := 'T';
12798 
12799                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
12800                                   x_ret_code       => l_ret_code
12801                                 , x_return_status  => l_return_status
12802                                 , x_msg_count      => l_msg_count
12803                                 , x_msg_data       => l_msg_data
12804                                 , p_privilege      => l_privilege
12805                                 , p_object_name    => l_object_name
12806                                 , p_object_key     => l_object_key
12807 				, p_init_msg_list  => FND_API.G_FALSE);
12808 
12809                         IF nvl(l_ret_code, 'F') = 'F' AND l_return_status = FND_API.G_RET_STS_SUCCESS THEN
12810 	                        l_privilege   := 'PA_CREATE_CANDIDATES';
12811 			        l_object_name := 'PA_PROJECT_ASSIGNMENTS';
12812 		                l_object_key  := l_candidate_in_rec.requirement_id;
12813 
12814 	                        l_return_status := FND_API.G_RET_STS_SUCCESS;
12815 		                l_ret_code := 'T';
12816 
12817 			        PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
12818 				          x_ret_code       => l_ret_code
12819 					, x_return_status  => l_return_status
12820 	                                , x_msg_count      => l_msg_count
12821 		                        , x_msg_data       => l_msg_data
12822 			                , p_privilege      => l_privilege
12823 				        , p_object_name    => l_object_name
12824 	                                , p_object_key     => l_object_key
12825 					, p_init_msg_list  => FND_API.G_FALSE);
12826 			END IF;
12827 			IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12828                                 -- This message does not have token defined, but intentionally putting token
12829                                 -- bcoz we still want to show the privielge name which is missing
12830                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_CAND'
12831                                                       ,'MISSING_PRIVILEGE', l_privilege);
12832                                 l_error_flag_local := 'Y';
12833                         END IF;
12834 
12835                         IF l_debug_mode = 'Y' THEN
12836                                 pa_debug.write(l_module, 'Security check complete for record#'||i||' privilege '||l_ret_code, l_log_level);
12837                         END IF;
12838 
12839                 END IF;
12840 
12841 		-- Check whether the user has resource authority over nominee
12842 		-------------------------------------------------------------
12843 		IF l_project_super_user <> 'Y' AND l_error_flag_local <> 'Y' AND l_candidate_in_rec.resource_id IS NOT NULL THEN
12844 
12845 		        IF l_debug_mode = 'Y' THEN
12846 		                pa_debug.write(l_module, 'If not project super user then check for confirmed assignment', l_log_level);
12847 			END IF;
12848 
12849 			OPEN c_get_person_id(FND_GLOBAL.USER_ID);
12850 			FETCH c_get_person_id INTO l_logged_person_id;
12851 			CLOSE c_get_person_id;
12852 
12853 			IF l_logged_person_id <> l_person_id THEN
12854 				l_privilege_name := 'PA_NOMINATE_CANDIDATES';
12855 			ELSE l_privilege_name := 'PA_NOMINATE_SELF_AS_CANDIDATE';
12856 			END IF;
12857 
12858 			PA_SECURITY_PVT.CHECK_CONFIRM_ASMT(p_project_id      => -999,
12859 							   p_resource_id     => l_candidate_in_rec.resource_id,
12860 		                                           p_resource_name   => null,
12861 				                           p_privilege       => l_privilege_name,
12862 						           p_start_date      => l_requirement_start_date,
12863 		                                           x_ret_code        => l_ret_code,
12864 		                                           x_return_status   => l_return_status,
12865 			                                   x_msg_count       => l_msg_count,
12866 				                           x_msg_data        => l_msg_data);
12867 
12868                         IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12869                                 l_error_flag_local := 'Y';
12870 				PA_UTILS.ADD_MESSAGE ( p_app_short_name => 'PA'
12871 					              ,p_msg_name       => 'PA_NO_RESOURCE_AUTHORITY' );
12872                         END IF;
12873 
12874 			IF l_debug_mode = 'Y' THEN
12875 			        pa_debug.write(l_module, 'After call of PA_SECURITY_PVT.CHECK_CONFIRM_ASMT', l_log_level);
12876 		        END IF;
12877 
12878 		END IF;
12879 
12880                 IF l_error_flag_local <> 'Y' THEN
12881                         -- Core API call
12882 			IF l_debug_mode = 'Y' THEN
12883 			        pa_debug.write(l_module, 'Calling core API PA_CANDIDATE_PUB.ADD_CANDIDATE', l_log_level);
12884 		        END IF;
12885 
12886                         PA_CANDIDATE_PUB.ADD_CANDIDATE(
12887                                 p_assignment_id         => l_candidate_in_rec.requirement_id,
12888                                 p_resource_name         => null,
12889                                 p_resource_id           => l_candidate_in_rec.resource_id,
12890                                 p_status_code           => l_candidate_in_rec.status_code,
12891                                 p_nomination_comments   => l_candidate_in_rec.nomination_comments,
12892                                 p_person_id             => l_person_id,
12893                                 p_privilege_name        => l_privilege_name,
12894                                 p_project_super_user    => l_project_super_user,
12895 				p_init_msg_list		=> FND_API.G_FALSE,
12896                                 x_return_status         => l_return_status,
12897                                 x_msg_count             => l_msg_count,
12898                                 x_msg_data              => l_msg_data);
12899 			IF l_debug_mode = 'Y' THEN
12900 		                pa_debug.write(l_module, 'After call PA_CANDIDATE_PUB.ADD_CANDIDATE l_return_status='||l_return_status, l_log_level);
12901 	                END IF;
12902 			IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
12903 				x_candidate_id_tbl.extend(1);
12904 				OPEN c_get_candidate_id(l_candidate_in_rec.requirement_id, l_candidate_in_rec.resource_id);
12905 				FETCH c_get_candidate_id INTO x_candidate_id_tbl(x_candidate_id_tbl.COUNT);
12906 				CLOSE c_get_candidate_id;
12907 			ELSE
12908 				l_error_flag_local := 'Y';
12909 				x_candidate_id_tbl.extend(1);
12910 				x_candidate_id_tbl(x_candidate_id_tbl.COUNT) := -1;
12911 			END IF;
12912 		ELSE
12913 			x_candidate_id_tbl.extend(1);
12914 			x_candidate_id_tbl(x_candidate_id_tbl.COUNT) := -1;
12915                 END IF;
12916 
12917                 l_end_msg_count := FND_MSG_PUB.count_msg;
12918                 IF l_debug_mode = 'Y' THEN
12919                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
12920                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
12921                 END IF;
12922 		l_loop_msg_count := l_end_msg_count - l_start_msg_count;
12923 
12924                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
12925                         l_error_flag := 'Y';
12926 
12927 			IF l_debug_mode = 'Y' THEN
12928                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
12929                         END IF;
12930 
12931                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
12932                                 -- Always get from first location in stack i.e. l_start_msg_count+1
12933                                 -- Because stack moves down after delete
12934                                 FND_MSG_PUB.get (
12935                                         p_msg_index      => l_start_msg_count+1,
12936                                         p_encoded        => FND_API.G_FALSE,
12937                                         p_data           => l_data,
12938                                         p_msg_index_out  => l_msg_index_out );
12939 
12940                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
12941                                 -- Because stack moves down after delete
12942                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
12943 
12944                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
12945                                                 'RECORD_NO', i,
12946                                                 'MESSAGE', l_data);
12947                         END LOOP;
12948 
12949 			IF l_debug_mode = 'Y' THEN
12950                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
12951                         END IF;
12952 
12953 		END IF;
12954                 i := p_candidate_in_tbl.next(i);
12955         END LOOP;
12956 
12957 	IF l_debug_mode = 'Y' THEN
12958                 pa_debug.write(l_module, 'All records are done', l_log_level);
12959                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
12960                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
12961         END IF;
12962 
12963         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
12964                 RAISE FND_API.G_EXC_ERROR;
12965         END IF;
12966 
12967         IF l_debug_mode = 'Y' THEN
12968                 Pa_Debug.reset_curr_function;
12969         END IF;
12970 
12971         IF p_commit = FND_API.G_TRUE THEN
12972                 commit;
12973         END IF;
12974 
12975 EXCEPTION
12976 
12977 WHEN FND_API.G_EXC_ERROR THEN
12978         x_return_status := FND_API.G_RET_STS_ERROR;
12979         l_msg_count := FND_MSG_PUB.count_msg;
12980 
12981 	IF c_get_requirement_info%ISOPEN THEN
12982 		CLOSE c_get_requirement_info;
12983 	END IF;
12984 
12985 	IF c_get_system_status_code%ISOPEN THEN
12986 		CLOSE c_get_system_status_code;
12987 	END IF;
12988 
12989 	IF c_get_resource_info%ISOPEN THEN
12990 		CLOSE c_get_resource_info;
12991 	END IF;
12992 
12993 	IF c_get_person_id%ISOPEN THEN
12994 		CLOSE c_get_person_id;
12995 	END IF;
12996 
12997 	IF c_get_candidate_id%ISOPEN THEN
12998 		CLOSE c_get_candidate_id;
12999 	END IF;
13000 
13001         IF p_commit = FND_API.G_TRUE THEN
13002                 ROLLBACK TO CREATE_CANDIDATES_SP;
13003         END IF;
13004 
13005         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
13006                 PA_INTERFACE_UTILS_PUB.get_messages
13007                 ( p_encoded        => FND_API.G_FALSE
13008                 , p_msg_index      => 1
13009                 , p_msg_count      => l_msg_count
13010                 , p_msg_data       => l_msg_data
13011                 , p_data           => l_data
13012                 , p_msg_index_out  => l_msg_index_out);
13013 
13014                 x_msg_data := l_data;
13015                 x_msg_count := l_msg_count;
13016         ELSE
13017                 x_msg_count := l_msg_count;
13018         END IF;
13019 
13020         IF l_debug_mode = 'Y' THEN
13021                 Pa_Debug.reset_curr_function;
13022         END IF;
13023 
13024 WHEN OTHERS THEN
13025 
13026         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13027         x_msg_data      := SUBSTRB(SQLERRM,1,240);
13028 
13029 	IF c_get_requirement_info%ISOPEN THEN
13030 		CLOSE c_get_requirement_info;
13031 	END IF;
13032 
13033 	IF c_get_system_status_code%ISOPEN THEN
13034 		CLOSE c_get_system_status_code;
13035 	END IF;
13036 
13037 	IF c_get_resource_info%ISOPEN THEN
13038 		CLOSE c_get_resource_info;
13039 	END IF;
13040 
13041 	IF c_get_person_id%ISOPEN THEN
13042 		CLOSE c_get_person_id;
13043 	END IF;
13044 
13045 	IF c_get_candidate_id%ISOPEN THEN
13046 		CLOSE c_get_candidate_id;
13047 	END IF;
13048 
13049         IF p_commit = FND_API.G_TRUE THEN
13050                 ROLLBACK TO CREATE_CANDIDATES_SP;
13051         END IF;
13052 
13053         FND_MSG_PUB.add_exc_msg
13054         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
13055         , p_procedure_name      => 'CREATE_CANDIDATES'
13056         , p_error_text          => x_msg_data);
13057 
13058         x_msg_count     := FND_MSG_PUB.count_msg;
13059 
13060         IF l_debug_mode = 'Y' THEN
13061                 PA_DEBUG.reset_curr_function;
13062         END IF;
13063         RAISE;
13064 
13065 END CREATE_CANDIDATES;
13066 
13067 -- Start of comments
13068 --	API name 	: UPDATE_CANDIDATES
13069 --	Type		: Public
13070 --	Pre-reqs	: None.
13071 --	Function	: This is a public API to update one or more candidates for project requirements.
13072 --	Usage		: This API will be called from AMG.
13073 --	Parameters	:
13074 --	IN		:	p_commit		IN  VARCHAR2
13075 --					Identifier to commit the transaction.
13076 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
13077 --				p_init_msg_list		IN  VARCHAR2
13078 --					Identifier to initialize the error message stack.
13079 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
13080 --				p_api_version_number	IN  NUMBER			Required
13081 --					To be compliant with Applications API coding standards.
13082 --				p_candidate_in_tbl	IN  CANDIDATE_IN_TBL_TYPE	Required
13083 --					Table of candidate records. Please see the CANDIDATE_IN_TBL_TYPE datatype table.
13084 --	OUT		:
13085 --				x_return_status		OUT VARCHAR2
13086 --					Indicates the return status of the API.
13087 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
13088 --				x_msg_count		OUT NUMBER
13089 --					Indicates the number of error messages in the message stack
13090 --				x_msg_data		OUT VARCHAR2
13091 --					Indicates the error message text if only one error exists
13092 --	History		:
13093 --                              01-Mar-2006 - msachan  - Created
13094 -- End of comments
13095 PROCEDURE UPDATE_CANDIDATES
13096 (
13097   p_commit		        IN		VARCHAR2 := FND_API.G_FALSE
13098 , p_init_msg_list	        IN		VARCHAR2 := FND_API.G_TRUE
13099 , p_api_version_number	        IN		NUMBER   := 1.0
13100 , p_candidate_in_tbl	        IN		CANDIDATE_IN_TBL_TYPE
13101 , x_return_status	        OUT     NOCOPY	VARCHAR2
13102 , x_msg_count		        OUT     NOCOPY	NUMBER
13103 , x_msg_data		        OUT     NOCOPY	VARCHAR2
13104 )
13105 IS
13106 	l_debug_mode                    VARCHAR2(1);
13107         l_module                        VARCHAR2(100)           := 'PA_CANDIDATE_AMG_PUB.UPDATE_CANDIDATES';
13108 	l_calling_application           VARCHAR2(10)            := 'PLSQL';
13109 	l_calling_module                VARCHAR2(10)            := 'AMG';
13110 	l_check_id_flag                 VARCHAR2(1)             := 'Y';
13111 	l_check_role_security_flag      VARCHAR2(1)             := 'Y';
13112 	l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
13113 	l_log_level                     NUMBER                  := 3;
13114 	i                               NUMBER;
13115 	l_error_flag                    VARCHAR2(1)             := 'N';
13116 	l_error_flag_local              VARCHAR2(1)             := 'N';
13117 	l_missing_params                VARCHAR2(1000);
13118 	l_candidate_in_rec		CANDIDATE_IN_REC_TYPE;
13119 	l_project_system_status_code	VARCHAR2(30);
13120 	l_project_id			NUMBER;
13121 	l_record_version_number		NUMBER;
13122 	l_start_msg_count               NUMBER                  := 0;
13123 	l_end_msg_count                 NUMBER                  := 0;
13124 	l_loop_msg_count                NUMBER                  := 0;
13125 
13126 	l_privilege                     VARCHAR2(30);
13127         l_object_name                   VARCHAR2(30);
13128         l_object_key                    NUMBER;
13129 	l_resource_valid                VARCHAR2(1)             := 'N';
13130 	l_privilege_name		VARCHAR2(40)		:= null;
13131         l_ret_code                      VARCHAR2(1);
13132 	l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
13133 	l_msg_count                     NUMBER;
13134 	l_msg_data                      VARCHAR2(2000);
13135 	l_msg_index_out                 NUMBER;
13136 	l_data                          VARCHAR2(2000);
13137 
13138 CURSOR c_get_system_status_code(c_status_code VARCHAR2) IS
13139 SELECT project_system_status_code FROM pa_project_statuses
13140 WHERE  trunc(SYSDATE) BETWEEN start_date_active AND nvl(end_date_active, trunc(SYSDATE))
13141 AND    status_type = 'CANDIDATE'
13142 AND    project_status_code = c_status_code;
13143 
13144 CURSOR c_get_requirement_info(c_assignment_id NUMBER) IS
13145 SELECT project_id
13146 FROM   pa_project_assignments
13147 WHERE  assignment_id = c_assignment_id
13148 AND    assignment_type = 'OPEN_ASSIGNMENT';
13149 
13150 CURSOR c_get_candidate_details(c_candidate_id NUMBER) IS
13151 SELECT candidate_id, status_code, candidate_ranking, record_version_number, assignment_id
13152 FROM   pa_candidates
13153 WHERE  candidate_id = c_candidate_id;
13154 
13155 	l_cand_rec			c_get_candidate_details%ROWTYPE;
13156 
13157 BEGIN
13158 
13159 	--Flows which are supported by this API
13160 		  ---------------------------------------
13161 		  --1. Updating candidate information
13162 		  --        1.1 Validating candidate_id
13163 		  --        1.2 Validating status_code to be a valid code
13164 		  --        1.3 Only updatable attributes of candidates once created are status_code, ranking, record_version_number, change_reason_code
13165 	--Flows which are not supported by this API
13166 		  -------------------------------------------
13167 		  --1. Validations like new status_code acceptable or not are done by underlying called apis.
13168 
13169         x_return_status := FND_API.G_RET_STS_SUCCESS;
13170 
13171         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
13172 
13173         IF l_debug_mode = 'Y' THEN
13174                 PA_DEBUG.set_curr_function(p_function => 'UPDATE_CANDIDATES', p_debug_mode => l_debug_mode);
13175         END IF;
13176 
13177         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
13178                 FND_MSG_PUB.initialize;
13179         END IF;
13180 
13181         IF p_commit = FND_API.G_TRUE THEN
13182                 savepoint UPDATE_CANDIDATES_SP;
13183         END IF;
13184 
13185         IF l_debug_mode = 'Y' THEN
13186                 pa_debug.write(l_module, 'Start of UPDATE_CANDIDATES', l_log_level);
13187                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
13188 		pa_debug.write(l_module, 'p_commit '||p_commit, l_log_level);
13189 		pa_debug.write(l_module, 'p_init_msg_list '||p_init_msg_list, l_log_level);
13190 		pa_debug.write(l_module, 'p_api_version_number '||p_api_version_number, l_log_level);
13191                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
13192                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
13193                 i := p_candidate_in_tbl.first;
13194                 WHILE i IS NOT NULL LOOP
13195                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').candidate_id '||p_candidate_in_tbl(i).candidate_id, l_log_level);
13196                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').requirement_id '||p_candidate_in_tbl(i).requirement_id, l_log_level);
13197                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').resource_id '||p_candidate_in_tbl(i).resource_id, l_log_level);
13198                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').person_id '||p_candidate_in_tbl(i).person_id, l_log_level);
13199                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').status_code '||p_candidate_in_tbl(i).status_code, l_log_level);
13200                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').nomination_comments '||p_candidate_in_tbl(i).nomination_comments, l_log_level);
13201                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').ranking '||p_candidate_in_tbl(i).ranking, l_log_level);
13202                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').change_reason_code '||p_candidate_in_tbl(i).change_reason_code, l_log_level);
13203                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').record_version_number '||p_candidate_in_tbl(i).record_version_number, l_log_level);
13204                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
13205                         i := p_candidate_in_tbl.next(i);
13206                 END LOOP;
13207         END IF;
13208 
13209         PA_STARTUP.INITIALIZE(
13210                   p_calling_application                 => l_calling_application
13211                 , p_calling_module                      => l_calling_module
13212                 , p_check_id_flag                       => l_check_id_flag
13213                 , p_check_role_security_flag            => l_check_role_security_flag
13214                 , p_check_resource_security_flag        => l_check_resource_security_flag
13215                 , p_debug_level                         => l_log_level
13216                 );
13217 
13218         IF l_debug_mode = 'Y' THEN
13219                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
13220         END IF;
13221 
13222         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
13223         --IF l_prm_license_flag <> 'Y' THEN
13224         --        null;
13225         --END IF;
13226 
13227         i := p_candidate_in_tbl.first;
13228 
13229         WHILE i IS NOT NULL LOOP
13230                 l_error_flag_local := 'N';
13231                 l_missing_params := null;
13232                 l_start_msg_count := FND_MSG_PUB.count_msg;
13233 
13234                 l_candidate_in_rec := p_candidate_in_tbl(i);
13235 		l_cand_rec := null;
13236 
13237                 -- Mandatory Parameters Check
13238                 IF l_debug_mode = 'Y' THEN
13239                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
13240                         pa_debug.write(l_module, '-----------------------------', l_log_level);
13241                         pa_debug.write(l_module, 'Inside while loop. Mandatory parameter check.', l_log_level);
13242                 END IF;
13243 
13244 		-- Check on Candidate Id
13245 		OPEN c_get_candidate_details(l_candidate_in_rec.candidate_id);
13246                 FETCH c_get_candidate_details INTO l_cand_rec;
13247 
13248 		IF c_get_candidate_details%NOTFOUND THEN
13249 			l_missing_params := l_missing_params||', CANDIDATE_ID';
13250                 END IF;
13251 
13252 		CLOSE c_get_candidate_details;
13253 
13254                 -- Check on Status Code
13255 		IF l_candidate_in_rec.status_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
13256 			l_candidate_in_rec.status_code := l_cand_rec.status_code;
13257 		ELSIF l_candidate_in_rec.status_code IS NOT NULL THEN
13258 			l_project_system_status_code := null;
13259 
13260 			OPEN  c_get_system_status_code(l_candidate_in_rec.status_code);
13261 			FETCH c_get_system_status_code INTO l_project_system_status_code;
13262 			CLOSE c_get_system_status_code;
13263 
13264 			IF l_project_system_status_code IS NULL OR l_project_system_status_code NOT IN
13265 				('CANDIDATE_DECLINED', 'CANDIDATE_PENDING_REVIEW', 'CANDIDATE_SUITABLE',
13266 				'CANDIDATE_SYSTEM_NOMINATED', 'CANDIDATE_UNDER_REVIEW', 'CANDIDATE_WITHDRAWN') THEN
13267 				l_missing_params := l_missing_params||', STATUS_CODE';
13268 			END IF;
13269 		END IF;
13270 
13271 		IF l_debug_mode = 'Y' THEN
13272                         pa_debug.write(l_module, 'Mandatory parameter validation over. List of Missing Parameters='||l_missing_params, l_log_level);
13273                 END IF;
13274 
13275 		IF l_missing_params IS NOT NULL THEN
13276                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
13277                                                 'INVALID_PARAMS', l_missing_params);
13278                         l_error_flag_local := 'Y';
13279                 END IF;
13280 
13281                 IF l_error_flag_local <> 'Y' THEN
13282 
13283 			-- Nulling out the parameters which are not required and defaulting the required parameter from the database.
13284 			l_candidate_in_rec.requirement_id := l_cand_rec.assignment_id;
13285 			l_candidate_in_rec.resource_id := null;
13286 			l_candidate_in_rec.person_id := null;
13287 			l_candidate_in_rec.nomination_comments := null;
13288 
13289 			-- Retrieve values from data base if Parameters are not passed.
13290 			IF l_debug_mode = 'Y' THEN
13291 				pa_debug.write(l_module, 'Retrieving values from database if parameters are not passed.', l_log_level);
13292 			END IF;
13293 
13294 			IF l_candidate_in_rec.ranking = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
13295 				l_candidate_in_rec.ranking := l_cand_rec.candidate_ranking;
13296 			END IF;
13297 
13298 			IF l_candidate_in_rec.record_version_number = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM THEN
13299 				l_candidate_in_rec.record_version_number := l_cand_rec.record_version_number;
13300 			END IF;
13301 
13302 			-- If Change Reason Code is not passed then use null
13303 			IF l_candidate_in_rec.change_reason_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
13304 				l_candidate_in_rec.change_reason_code := null;
13305 			END IF;
13306 
13307 			IF l_debug_mode = 'Y' THEN
13308 				pa_debug.write(l_module, 'Candidate Id = '||l_candidate_in_rec.candidate_id, l_log_level);
13309 				pa_debug.write(l_module, '-----------------------------', l_log_level);
13310 				pa_debug.write(l_module, 'Old Status Code = '||l_cand_rec.status_code, l_log_level);
13311 				pa_debug.write(l_module, 'Old Ranking = '||l_cand_rec.candidate_ranking, l_log_level);
13312 				pa_debug.write(l_module, 'Old Record Version Number = '||l_cand_rec.record_version_number, l_log_level);
13313 				pa_debug.write(l_module, '-----------------------------', l_log_level);
13314 				pa_debug.write(l_module, 'New Status Code = '||l_candidate_in_rec.status_code, l_log_level);
13315 				pa_debug.write(l_module, 'New Ranking = '||l_candidate_in_rec.ranking, l_log_level);
13316 				pa_debug.write(l_module, 'New Record Version Number = '||(l_candidate_in_rec.record_version_number+1), l_log_level);
13317 				pa_debug.write(l_module, '-----------------------------', l_log_level);
13318 				pa_debug.write(l_module, 'Change Reason Code = '||l_candidate_in_rec.change_reason_code, l_log_level);
13319 				pa_debug.write(l_module, '-----------------------------', l_log_level);
13320 			END IF;
13321 
13322 			-- Getting Project Id for security check
13323 			OPEN c_get_requirement_info(l_candidate_in_rec.requirement_id);
13324 			FETCH c_get_requirement_info INTO l_project_id;
13325 			CLOSE c_get_requirement_info;
13326 
13327 			IF l_project_id IS NULL THEN  -- Check for requirement id valid and assignment type OPEN_ASSIGNMENT
13328 				l_error_flag_local := 'Y';
13329         			l_missing_params := l_missing_params||', REQUIREMENT_ID';
13330                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
13331                                                 'INVALID_PARAMS', l_missing_params);
13332 			END IF;
13333 
13334 		END IF;
13335 
13336 		-- Security Check : Check PA_VIEW_CANDIDATES privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS as done in CandidatesTopCO.java
13337                 -------------------
13338 
13339                 IF l_error_flag_local <> 'Y' THEN
13340 
13341                         IF l_debug_mode = 'Y' THEN
13342                                 pa_debug.write(l_module, 'Checking PA_VIEW_CANDIDATES privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS for record#'||i, l_log_level);
13343                         END IF;
13344 
13345                         l_privilege   := 'PA_VIEW_CANDIDATES';
13346 
13347 			l_object_name := 'PA_PROJECTS';
13348 			l_object_key  := l_project_id;
13349 
13350                         l_return_status := FND_API.G_RET_STS_SUCCESS;
13351                         l_ret_code := 'T';
13352 
13353                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
13354                                   x_ret_code       => l_ret_code
13355                                 , x_return_status  => l_return_status
13356                                 , x_msg_count      => l_msg_count
13357                                 , x_msg_data       => l_msg_data
13358                                 , p_privilege      => l_privilege
13359                                 , p_object_name    => l_object_name
13360                                 , p_object_key     => l_object_key
13361 				, p_init_msg_list  => FND_API.G_FALSE);
13362 
13363                         IF nvl(l_ret_code, 'F') = 'F' AND l_return_status = FND_API.G_RET_STS_SUCCESS THEN
13364 			        l_object_name := 'PA_PROJECT_ASSIGNMENTS';
13365 		                l_object_key  := l_candidate_in_rec.requirement_id;
13366 
13367 	                        l_return_status := FND_API.G_RET_STS_SUCCESS;
13368 		                l_ret_code := 'T';
13369 
13370 			        PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
13371 				          x_ret_code       => l_ret_code
13372 					, x_return_status  => l_return_status
13373 	                                , x_msg_count      => l_msg_count
13374 		                        , x_msg_data       => l_msg_data
13375 			                , p_privilege      => l_privilege
13376 				        , p_object_name    => l_object_name
13377 	                                , p_object_key     => l_object_key
13378 					, p_init_msg_list  => FND_API.G_FALSE);
13379 			END IF;
13380 			IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13381                                 -- This message does not have token defined, but intentionally putting token
13382                                 -- bcoz we still want to show the privielge name which is missing
13383                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_CAND'
13384                                                       ,'MISSING_PRIVILEGE', l_privilege);
13385                                 l_error_flag_local := 'Y';
13386                         END IF;
13387 
13388                         IF l_debug_mode = 'Y' THEN
13389                                 pa_debug.write(l_module, 'Security check complete for record#'||i||' privilege '||l_ret_code, l_log_level);
13390                         END IF;
13391 
13392                 END IF;
13393 
13394                 -- Call Core Actual API
13395                 -----------------------
13396 
13397                 IF l_error_flag_local <> 'Y' THEN
13398                         l_return_status := FND_API.G_RET_STS_SUCCESS;
13399 
13400                         IF l_debug_mode = 'Y' THEN
13401                                 pa_debug.write(l_module, 'Calling PA_CANDIDATE_PUB.UPDATE_CANDIDATE for Record#'||i, l_log_level);
13402                         END IF;
13403 
13404                         PA_CANDIDATE_PUB.UPDATE_CANDIDATE
13405                         (
13406 				  p_candidate_id		=> l_candidate_in_rec.candidate_id
13407 				, p_status_code			=> l_candidate_in_rec.status_code
13408 				, p_ranking			=> l_candidate_in_rec.ranking
13409 				, p_change_reason_code		=> l_candidate_in_rec.change_reason_code
13410 				, p_record_version_number	=> l_candidate_in_rec.record_version_number
13411 				, p_init_msg_list		=> FND_API.G_FALSE
13412 				, p_validate_status		=> FND_API.G_TRUE
13413 				, x_record_version_number	=> l_record_version_number
13414 				, x_msg_count			=> l_msg_count
13415 				, x_msg_data			=> l_msg_data
13416 				, x_return_status		=> l_return_status
13417                         );
13418 
13419                         IF l_debug_mode = 'Y' THEN
13420                                 pa_debug.write(l_module, 'After call PA_CANDIDATE_PUB.UPDATE_CANDIDATE l_return_status='||l_return_status, l_log_level);
13421                         END IF;
13422 
13423                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13424                                 l_error_flag_local := 'Y';
13425 				IF l_debug_mode = 'Y' THEN
13426                                         pa_debug.write(l_module, 'PA_CANDIDATE_PUB.UPDATE_CANDIDATE unsuccessful', l_log_level);
13427                                 END IF;
13428                         ELSE
13429 				IF l_debug_mode = 'Y' THEN
13430                                         pa_debug.write(l_module, 'PA_CANDIDATE_PUB.UPDATE_CANDIDATE successful', l_log_level);
13431 					pa_debug.write(l_module, 'Updated record_version_number = '||l_record_version_number, l_log_level);
13432                                 END IF;
13433                         END IF;
13434                 END IF;
13435 
13436                 l_end_msg_count := FND_MSG_PUB.count_msg;
13437                 IF l_debug_mode = 'Y' THEN
13438                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
13439                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
13440                 END IF;
13441                 l_loop_msg_count := l_end_msg_count - l_start_msg_count;
13442 
13443                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
13444                         l_error_flag := 'Y';
13445 
13446                         IF l_debug_mode = 'Y' THEN
13447                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
13448                         END IF;
13449 
13450                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
13451                                 -- Always get from first location in stack i.e. l_start_msg_count+1
13452                                 -- Because stack moves down after delete
13453                                 FND_MSG_PUB.get (
13454                                         p_msg_index      => l_start_msg_count+1,
13455                                         p_encoded        => FND_API.G_FALSE,
13456                                         p_data           => l_data,
13457                                         p_msg_index_out  => l_msg_index_out );
13458 
13459                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
13460                                 -- Because stack moves down after delete
13461                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
13462 
13463                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
13464                                                 'RECORD_NO', i,
13465                                                 'MESSAGE', l_data);
13466                         END LOOP;
13467 
13468 			IF l_debug_mode = 'Y' THEN
13469                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
13470                         END IF;
13471 
13472 		END IF;
13473                 i := p_candidate_in_tbl.next(i);
13474         END LOOP;
13475 
13476         IF l_debug_mode = 'Y' THEN
13477                 pa_debug.write(l_module, 'All records are done', l_log_level);
13478                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
13479                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
13480         END IF;
13481 
13482         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
13483                 RAISE FND_API.G_EXC_ERROR;
13484         END IF;
13485 
13486         IF l_debug_mode = 'Y' THEN
13487                 PA_DEBUG.reset_curr_function;
13488         END IF;
13489 
13490         IF p_commit = FND_API.G_TRUE THEN
13491                 commit;
13492         END IF;
13493 
13494 EXCEPTION
13495 
13496 WHEN FND_API.G_EXC_ERROR THEN
13497 
13498         x_return_status := FND_API.G_RET_STS_ERROR;
13499         l_msg_count := FND_MSG_PUB.count_msg;
13500 
13501 	IF c_get_candidate_details%ISOPEN THEN
13502 		CLOSE c_get_candidate_details;
13503 	END IF;
13504 
13505         IF p_commit = FND_API.G_TRUE THEN
13506                 ROLLBACK TO UPDATE_CANDIDATES_SP;
13507         END IF;
13508 
13509         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
13510                 PA_INTERFACE_UTILS_PUB.get_messages
13511                 ( p_encoded        => FND_API.G_FALSE
13512                 , p_msg_index      => 1
13513                 , p_msg_count      => l_msg_count
13514                 , p_msg_data       => l_msg_data
13515                 , p_data           => l_data
13516                 , p_msg_index_out  => l_msg_index_out);
13517 
13518                 x_msg_data := l_data;
13519                 x_msg_count := l_msg_count;
13520         ELSE
13521                 x_msg_count := l_msg_count;
13522         END IF;
13523 
13524         IF l_debug_mode = 'Y' THEN
13525                 Pa_Debug.reset_curr_function;
13526         END IF;
13527 
13528 WHEN OTHERS THEN
13529 
13530         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13531         x_msg_data      := SUBSTRB(SQLERRM,1,240);
13532 
13533      	IF c_get_candidate_details%ISOPEN THEN
13534 		CLOSE c_get_candidate_details;
13535 	END IF;
13536 
13537         IF p_commit = FND_API.G_TRUE THEN
13538                 ROLLBACK TO UPDATE_CANDIDATES_SP;
13539         END IF;
13540 
13541         FND_MSG_PUB.add_exc_msg
13542         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
13543         , p_procedure_name      => 'UPDATE_CANDIDATES'
13544         , p_error_text          => x_msg_data);
13545 
13546         x_msg_count     := FND_MSG_PUB.count_msg;
13547 
13548         IF l_debug_mode = 'Y' THEN
13549                 PA_DEBUG.reset_curr_function;
13550         END IF;
13551         RAISE;
13552 
13553 END UPDATE_CANDIDATES;
13554 
13555 -- Start of comments
13556 --	API name 	: DELETE_CANDIDATES
13557 --	Type		: Public
13558 --	Pre-reqs	: None.
13559 --	Function	: This is a public API to delete one or more candidates for project requirements.
13560 --	Usage		: This API will be called from AMG.
13561 --	Parameters	:
13562 --	IN		:	p_commit		IN  VARCHAR2
13563 --					Identifier to commit the transaction.
13564 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
13565 --				p_init_msg_list		IN  VARCHAR2
13566 --					Identifier to initialize the error message stack.
13567 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
13568 --				p_api_version_number	IN  NUMBER			Required
13569 --					To be compliant with Applications API coding standards.
13570 --				p_candidate_in_tbl	IN  CANDIDATE_IN_TBL_TYPE	Required
13571 --					Table of candidate records. Please see the CANDIDATE_IN_TBL_TYPE datatype table.
13572 --	OUT		:
13573 --				x_return_status		OUT VARCHAR2
13574 --					Indicates the return status of the API.
13575 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
13576 --				x_msg_count		OUT NUMBER
13577 --					Indicates the number of error messages in the message stack
13578 --				x_msg_data		OUT VARCHAR2
13579 --					Indicates the error message text if only one error exists
13580 --	History		:
13581 --                              01-Mar-2006 - msachan  - Created
13582 -- End of comments
13583 PROCEDURE DELETE_CANDIDATES
13584 (
13585   p_commit		        IN		VARCHAR2 := FND_API.G_FALSE
13586 , p_init_msg_list	        IN		VARCHAR2 := FND_API.G_TRUE
13587 , p_api_version_number	        IN		NUMBER   := 1.0
13588 , p_candidate_in_tbl	        IN		CANDIDATE_IN_TBL_TYPE
13589 , x_return_status	        OUT     NOCOPY	VARCHAR2
13590 , x_msg_count		        OUT     NOCOPY	NUMBER
13591 , x_msg_data		        OUT     NOCOPY	VARCHAR2
13592 )
13593 IS
13594 	l_debug_mode                    VARCHAR2(1);
13595         l_module                        VARCHAR2(100)           := 'PA_CANDIDATE_AMG_PUB.DELETE_CANDIDATES';
13596 	i                               NUMBER;
13597 	l_log_level                     NUMBER                  := 3;
13598 	l_calling_application           VARCHAR2(10)            := 'PLSQL';
13599 	l_calling_module                VARCHAR2(10)            := 'AMG';
13600 	l_check_id_flag                 VARCHAR2(1)             := 'Y';
13601 	l_check_role_security_flag      VARCHAR2(1)             := 'Y';
13602 	l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
13603 	l_error_flag_local              VARCHAR2(1)             := 'N';
13604 	l_error_flag                    VARCHAR2(1)             := 'N';
13605 	l_missing_params                VARCHAR2(1000);
13606 	l_start_msg_count               NUMBER                  := 0;
13607 	l_end_msg_count                 NUMBER                  := 0;
13608 	l_loop_msg_count                NUMBER                  := 0;
13609 
13610 	l_candidate_in_rec		CANDIDATE_IN_REC_TYPE;
13611 	l_project_id			NUMBER;
13612 	l_record_version_number		NUMBER;
13613 
13614 	l_privilege                     VARCHAR2(30);
13615         l_object_name                   VARCHAR2(30);
13616         l_object_key                    NUMBER;
13617 	l_resource_valid                VARCHAR2(1)             := 'N';
13618 	l_privilege_name		VARCHAR2(40)		:= null;
13619         l_ret_code                      VARCHAR2(1);
13620 	l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
13621 	l_msg_count                     NUMBER;
13622 	l_msg_data                      VARCHAR2(2000);
13623 	l_msg_index_out                 NUMBER;
13624 	l_data                          VARCHAR2(2000);
13625 
13626 CURSOR c_get_requirement_info(c_assignment_id NUMBER) IS
13627 SELECT project_id, record_version_number
13628 FROM   pa_project_assignments
13629 WHERE  assignment_id = c_assignment_id
13630 AND    assignment_type = 'OPEN_ASSIGNMENT';
13631 
13632 BEGIN
13633 
13634 	--Flows which are supported by this API
13635 		  ---------------------------------------
13636 		  --1. Deleting all the candidates for a given open requirement
13637 		  --        1.1 Validating requirement_id
13638 		  --        1.2 Deleting all candidates for the given requirement_id
13639 		  --        1.3 Changing no_of_active_candidates for the given requirement_id to zero after deleting all the candidates.
13640 	--Flows which are not supported by this API
13641 		  -------------------------------------------
13642 		  --1. Validations like whether candidates can be deleted after once being confirmed are left for the underlying apis to handle.
13643 		  --2. Either all or none of the candidates would be deleted for the specified requirement_id.
13644 
13645 	x_return_status := FND_API.G_RET_STS_SUCCESS;
13646 
13647         l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
13648 
13649         IF l_debug_mode = 'Y' THEN
13650                 PA_DEBUG.set_curr_function(p_function => 'DELETE_CANDIDATES', p_debug_mode => l_debug_mode);
13651         END IF;
13652 
13653         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
13654                 FND_MSG_PUB.initialize;
13655         END IF;
13656 
13657         IF p_commit = FND_API.G_TRUE THEN
13658                 savepoint DELETE_CANDIDATES_SP;
13659         END IF;
13660 
13661         IF l_debug_mode = 'Y' THEN
13662                 pa_debug.write(l_module, 'Start of DELETE_CANDIDATES', l_log_level);
13663                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
13664 		pa_debug.write(l_module, 'p_commit '||p_commit, l_log_level);
13665 		pa_debug.write(l_module, 'p_init_msg_list '||p_init_msg_list, l_log_level);
13666 		pa_debug.write(l_module, 'p_api_version_number '||p_api_version_number, l_log_level);
13667                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
13668                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
13669                 i := p_candidate_in_tbl.first;
13670                 WHILE i IS NOT NULL LOOP
13671                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').candidate_id '||p_candidate_in_tbl(i).candidate_id, l_log_level);
13672                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').requirement_id '||p_candidate_in_tbl(i).requirement_id, l_log_level);
13673                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').resource_id '||p_candidate_in_tbl(i).resource_id, l_log_level);
13674                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').person_id '||p_candidate_in_tbl(i).person_id, l_log_level);
13675                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').status_code '||p_candidate_in_tbl(i).status_code, l_log_level);
13676                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').nomination_comments '||p_candidate_in_tbl(i).nomination_comments, l_log_level);
13677                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').ranking '||p_candidate_in_tbl(i).ranking, l_log_level);
13678                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').change_reason_code '||p_candidate_in_tbl(i).change_reason_code, l_log_level);
13679                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').record_version_number '||p_candidate_in_tbl(i).record_version_number, l_log_level);
13680                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
13681                         i := p_candidate_in_tbl.next(i);
13682                 END LOOP;
13683         END IF;
13684 
13685         PA_STARTUP.INITIALIZE(
13686                   p_calling_application                 => l_calling_application
13687                 , p_calling_module                      => l_calling_module
13688                 , p_check_id_flag                       => l_check_id_flag
13689                 , p_check_role_security_flag            => l_check_role_security_flag
13690                 , p_check_resource_security_flag        => l_check_resource_security_flag
13691                 , p_debug_level                         => l_log_level
13692                 );
13693 
13694         IF l_debug_mode = 'Y' THEN
13695                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
13696         END IF;
13697 
13698         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
13699         --IF l_prm_license_flag <> 'Y' THEN
13700         --        null;
13701         --END IF;
13702 
13703         i := p_candidate_in_tbl.first;
13704 
13705 	WHILE i IS NOT NULL LOOP
13706                 l_error_flag_local := 'N';
13707                 l_missing_params := null;
13708                 l_start_msg_count := FND_MSG_PUB.count_msg;
13709 
13710                 l_candidate_in_rec := p_candidate_in_tbl(i);
13711 		l_record_version_number := 0;
13712 		l_project_id := 0;
13713 
13714                 -- Mandatory Parameters Check
13715                 IF l_debug_mode = 'Y' THEN
13716                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
13717                         pa_debug.write(l_module, '-----------------------------', l_log_level);
13718                         pa_debug.write(l_module, 'Inside while loop. Mandatory parameter check.', l_log_level);
13719                 END IF;
13720 
13721                 IF l_candidate_in_rec.requirement_id IS NULL THEN
13722                         l_missing_params := l_missing_params||', REQUIREMENT_ID';
13723                 END IF;
13724 
13725                 IF l_debug_mode = 'Y' THEN
13726                         pa_debug.write(l_module, 'Mandatory parameter validation over. l_missing_params='||l_missing_params, l_log_level);
13727                 END IF;
13728 
13729                 IF l_missing_params IS NOT NULL THEN
13730                         l_error_flag_local := 'Y';
13731                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
13732                                                 'INVALID_PARAMS', l_missing_params);
13733                 END IF;
13734 
13735                 IF l_error_flag_local <> 'Y' THEN
13736 
13737 			OPEN c_get_requirement_info(l_candidate_in_rec.requirement_id);
13738 			FETCH c_get_requirement_info INTO l_project_id, l_record_version_number;
13739 			-- CLOSE c_get_requirement_info;  -- Commented for Bug 5178399
13740 
13741 			-- IF l_project_id IS NULL THEN  -- Check for requirement id valid and assignment type OPEN_ASSIGNMENT -- Commented for Bug 5178399
13742 			IF c_get_requirement_info%NOTFOUND THEN    -- Check for requirement id valid and assignment type OPEN_ASSIGNMENT  -- Added for Bug 5178399
13743 				l_error_flag_local := 'Y';
13744                                 l_missing_params := l_missing_params||', REQUIREMENT_ID';
13745                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
13746                                                 'INVALID_PARAMS', l_missing_params);
13747 			END IF;
13748 
13749 			CLOSE c_get_requirement_info;  -- Added for Bug 5178399
13750 
13751 			-- Nulling out the parameters which are not required.
13752 			l_candidate_in_rec.candidate_id := null;
13753 			l_candidate_in_rec.resource_id := null;
13754 			l_candidate_in_rec.person_id := null;
13755 			l_candidate_in_rec.status_code := null;
13756 			l_candidate_in_rec.nomination_comments := null;
13757 			l_candidate_in_rec.ranking := null;
13758 			l_candidate_in_rec.change_reason_code := null;
13759 			l_candidate_in_rec.record_version_number := null;
13760 
13761 		END IF;
13762 
13763                 -- Security Check : Check PA_CREATE_CANDIDATES privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS as done in AddCandidatesTopCO.java
13764                 -------------------
13765 
13766                 IF l_error_flag_local <> 'Y' THEN
13767 
13768                         IF l_debug_mode = 'Y' THEN
13769                                 pa_debug.write(l_module, 'Checking PA_CREATE_CANDIDATES privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS for record#'||i, l_log_level);
13770                         END IF;
13771 
13772                         l_privilege   := 'PA_CREATE_CANDIDATES';
13773 
13774 			l_object_name := 'PA_PROJECTS';
13775 			l_object_key  := l_project_id;
13776 
13777                         l_return_status := FND_API.G_RET_STS_SUCCESS;
13778                         l_ret_code := 'T';
13779 
13780                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
13781                                   x_ret_code       => l_ret_code
13782                                 , x_return_status  => l_return_status
13783                                 , x_msg_count      => l_msg_count
13784                                 , x_msg_data       => l_msg_data
13785                                 , p_privilege      => l_privilege
13786                                 , p_object_name    => l_object_name
13787                                 , p_object_key     => l_object_key
13788 				, p_init_msg_list  => FND_API.G_FALSE);
13789 
13790                         IF nvl(l_ret_code, 'F') = 'F' AND l_return_status = FND_API.G_RET_STS_SUCCESS THEN
13791 			        l_object_name := 'PA_PROJECT_ASSIGNMENTS';
13792 		                l_object_key  := l_candidate_in_rec.requirement_id;
13793 
13794 	                        l_return_status := FND_API.G_RET_STS_SUCCESS;
13795 		                l_ret_code := 'T';
13796 
13797 			        PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
13798 				          x_ret_code       => l_ret_code
13799 					, x_return_status  => l_return_status
13800 	                                , x_msg_count      => l_msg_count
13801 		                        , x_msg_data       => l_msg_data
13802 			                , p_privilege      => l_privilege
13803 				        , p_object_name    => l_object_name
13804 	                                , p_object_key     => l_object_key
13805 					, p_init_msg_list  => FND_API.G_FALSE);
13806 			END IF;
13807 			IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13808                                 -- This message does not have token defined, but intentionally putting token
13809                                 -- bcoz we still want to show the privielge name which is missing
13810                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_CAND'
13811                                                       ,'MISSING_PRIVILEGE', l_privilege);
13812                                 l_error_flag_local := 'Y';
13813                         END IF;
13814 
13815                         IF l_debug_mode = 'Y' THEN
13816                                 pa_debug.write(l_module, 'Security check complete for record#'||i||' privilege '||l_ret_code, l_log_level);
13817                         END IF;
13818 
13819                 END IF;
13820 
13821                 -- Call Core Actual API
13822                 -----------------------
13823 
13824                 IF l_error_flag_local <> 'Y' THEN
13825                         l_return_status := FND_API.G_RET_STS_SUCCESS;
13826 
13827                         IF l_debug_mode = 'Y' THEN
13828                                 pa_debug.write(l_module, 'Calling PA_CANDIDATE_PUB.DELETE_CANDIDATES for Record#'||i, l_log_level);
13829                         END IF;
13830 
13831                         PA_CANDIDATE_PUB.DELETE_CANDIDATES
13832                         (
13833 				  p_assignment_id	=> l_candidate_in_rec.requirement_id
13834 				, p_status_code		=> null
13835 				, x_return_status	=> l_return_status
13836 				, x_msg_count		=> l_msg_count
13837 				, x_msg_data		=> l_msg_data
13838                         );
13839 
13840                         IF l_debug_mode = 'Y' THEN
13841                                 pa_debug.write(l_module, 'After call PA_CANDIDATE_PUB.DELETE_CANDIDATES l_return_status='||l_return_status, l_log_level);
13842                         END IF;
13843 
13844                         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13845                                 l_error_flag_local := 'Y';
13846 				IF l_debug_mode = 'Y' THEN
13847                                         pa_debug.write(l_module, 'PA_CANDIDATE_PUB.DELETE_CANDIDATES unsuccessful', l_log_level);
13848                                 END IF;
13849                         ELSE
13850 				IF l_debug_mode = 'Y' THEN
13851 					pa_debug.write(l_module, 'Calling PA_PROJECT_ASSIGNMENTS_PKG.UPDATE_ROW for Record#'||i, l_log_level);
13852 				END IF;
13853 				-- Set the number of active candidates to zero
13854 				PA_PROJECT_ASSIGNMENTS_PKG.UPDATE_ROW
13855 				(
13856 					  p_assignment_id           => l_candidate_in_rec.requirement_id
13857 					, p_no_of_active_candidates => 0
13858 					, p_record_version_number   => l_record_version_number
13859 					, x_return_status           => l_return_status
13860 				);
13861 				IF l_debug_mode = 'Y' THEN
13862 					pa_debug.write(l_module, 'After call PA_PROJECT_ASSIGNMENTS_PKG.UPDATE_ROW l_return_status='||l_return_status, l_log_level);
13863 				END IF;
13864 				IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13865 					l_error_flag_local := 'Y';
13866 					IF l_debug_mode = 'Y' THEN
13867 						pa_debug.write(l_module, 'PA_PROJECT_ASSIGNMENTS_PKG.UPDATE_ROW unsuccessful', l_log_level);
13868 					END IF;
13869 				ELSE
13870 					IF l_debug_mode = 'Y' THEN
13871 						pa_debug.write(l_module, 'PA_PROJECT_ASSIGNMENTS_PKG.UPDATE_ROW and PA_CANDIDATE_PUB.DELETE_CANDIDATES successful', l_log_level);
13872 					END IF;
13873 				END IF;
13874                         END IF;
13875                 END IF;
13876 
13877                 l_end_msg_count := FND_MSG_PUB.count_msg;
13878                 IF l_debug_mode = 'Y' THEN
13879                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
13880                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
13881                 END IF;
13882                 l_loop_msg_count := l_end_msg_count - l_start_msg_count;
13883 
13884                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
13885                         l_error_flag := 'Y';
13886 
13887                         IF l_debug_mode = 'Y' THEN
13888                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
13889                         END IF;
13890 
13891                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
13892                                 -- Always get from first location in stack i.e. l_start_msg_count+1
13893                                 -- Because stack moves down after delete
13894                                 FND_MSG_PUB.get (
13895                                         p_msg_index      => l_start_msg_count+1,
13896                                         p_encoded        => FND_API.G_FALSE,
13897                                         p_data           => l_data,
13898                                         p_msg_index_out  => l_msg_index_out );
13899 
13900                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
13901                                 -- Because stack moves down after delete
13902                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
13903 
13904                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
13905                                                 'RECORD_NO', i,
13906                                                 'MESSAGE', l_data);
13907                         END LOOP;
13908 
13909 			IF l_debug_mode = 'Y' THEN
13910                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
13911                         END IF;
13912 
13913 		END IF;
13914                 i := p_candidate_in_tbl.next(i);
13915         END LOOP;
13916 
13917         IF l_debug_mode = 'Y' THEN
13918                 pa_debug.write(l_module, 'All records are done', l_log_level);
13919                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
13920                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
13921         END IF;
13922 
13923         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
13924                 RAISE FND_API.G_EXC_ERROR;
13925         END IF;
13926 
13927         IF l_debug_mode = 'Y' THEN
13928                 PA_DEBUG.reset_curr_function;
13929         END IF;
13930 
13931         IF p_commit = FND_API.G_TRUE THEN
13932                 commit;
13933         END IF;
13934 
13935 EXCEPTION
13936 
13937 WHEN FND_API.G_EXC_ERROR THEN
13938 
13939         x_return_status := FND_API.G_RET_STS_ERROR;
13940         l_msg_count := FND_MSG_PUB.count_msg;
13941 
13942 	IF c_get_requirement_info%ISOPEN THEN
13943 		CLOSE c_get_requirement_info;
13944 	END IF;
13945 
13946         IF p_commit = FND_API.G_TRUE THEN
13947                 ROLLBACK TO DELETE_CANDIDATES_SP;
13948         END IF;
13949 
13950         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
13951                 PA_INTERFACE_UTILS_PUB.get_messages
13952                 ( p_encoded        => FND_API.G_FALSE
13953                 , p_msg_index      => 1
13954                 , p_msg_count      => l_msg_count
13955                 , p_msg_data       => l_msg_data
13956                 , p_data           => l_data
13957                 , p_msg_index_out  => l_msg_index_out);
13958 
13959                 x_msg_data := l_data;
13960                 x_msg_count := l_msg_count;
13961         ELSE
13962                 x_msg_count := l_msg_count;
13963         END IF;
13964 
13965         IF l_debug_mode = 'Y' THEN
13966                 Pa_Debug.reset_curr_function;
13967         END IF;
13968 
13969 WHEN OTHERS THEN
13970 
13971         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13972         x_msg_data      := SUBSTRB(SQLERRM,1,240);
13973 
13974      	IF c_get_requirement_info%ISOPEN THEN
13975 		CLOSE c_get_requirement_info;
13976 	END IF;
13977 
13978         IF p_commit = FND_API.G_TRUE THEN
13979                 ROLLBACK TO DELETE_CANDIDATES_SP;
13980         END IF;
13981 
13982         FND_MSG_PUB.add_exc_msg
13983         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
13984         , p_procedure_name      => 'DELETE_CANDIDATES'
13985         , p_error_text          => x_msg_data);
13986 
13987         x_msg_count     := FND_MSG_PUB.count_msg;
13988 
13989         IF l_debug_mode = 'Y' THEN
13990                 PA_DEBUG.reset_curr_function;
13991         END IF;
13992         RAISE;
13993 
13994 END DELETE_CANDIDATES;
13995 
13996 -- Start of comments
13997 --	API name 	: CREATE_CANDIDATE_LOG
13998 --	Type		: Public
13999 --	Pre-reqs	: None.
14000 --	Function	: This is a public API to create log for one or more candidates for project requirements.
14001 --	Usage		: This API will be called from AMG.
14002 --	Parameters	:
14003 --	IN		:	p_commit			IN  VARCHAR2
14004 --					Identifier to commit the transaction.
14005 --					Valid values are:	FND_API.G_FALSE for FALSE and FND_API.G_TRUE for TRUE
14006 --				p_init_msg_list			IN  VARCHAR2
14007 --					Identifier to initialize the error message stack.
14008 --					Valid values are: FND_API.G_FALSE for FALSE amd FND_API.G_TRUE for TRUE
14009 --				p_api_version_number		IN  NUMBER			Required
14010 --					To be compliant with Applications API coding standards.
14011 --				p_candidate_log_tbl		IN  CANDIDATE_LOG_TBL_TYPE	Required
14012 --					Table of candidate review records. Please see the CANDIDATE_LOG_TBL_TYPE datatype table.
14013 --	OUT		:
14014 --				x_candidate_review_id_tbl	OUT SYSTEM.PA_NUM_TBL_TYPE
14015 --					Table to store the candidate review ids created by the API.
14016 --					Reference : pa_candidate_reviews.candidate_review_id
14017 --				x_return_status			OUT VARCHAR2
14018 --					Indicates the return status of the API.
14019 --					Valid values are: 'S' for Success, 'E' for Error, 'U' for Unexpected Error
14020 --				x_msg_count			OUT NUMBER
14021 --					Indicates the number of error messages in the message stack
14022 --				x_msg_data			OUT VARCHAR2
14023 --					Indicates the error message text if only one error exists
14024 --	History		:
14025 --                              01-Mar-2006 - msachan  - Created
14026 -- End of comments
14027 PROCEDURE CREATE_CANDIDATE_LOG
14028 (
14029   p_commit			IN		VARCHAR2 := FND_API.G_FALSE
14030 , p_init_msg_list		IN		VARCHAR2 := FND_API.G_TRUE
14031 , p_api_version_number		IN		NUMBER   := 1.0
14032 , p_candidate_log_tbl		IN		CANDIDATE_LOG_TBL_TYPE
14033 , x_candidate_review_id_tbl	OUT     NOCOPY	SYSTEM.PA_NUM_TBL_TYPE
14034 , x_return_status		OUT     NOCOPY	VARCHAR2
14035 , x_msg_count			OUT     NOCOPY	NUMBER
14036 , x_msg_data			OUT     NOCOPY	VARCHAR2
14037 )
14038 IS
14039 	l_debug_mode                    VARCHAR2(1);
14040         l_module                        VARCHAR2(100)           := 'PA_CANDIDATE_AMG_PUB.CREATE_CANDIDATE_LOG';
14041 	i                               NUMBER;
14042 	l_log_level                     NUMBER                  := 3;
14043 	l_calling_application           VARCHAR2(10)            := 'PLSQL';
14044 	l_calling_module                VARCHAR2(10)            := 'AMG';
14045 	l_check_id_flag                 VARCHAR2(1)             := 'Y';
14046 	l_check_role_security_flag      VARCHAR2(1)             := 'Y';
14047 	l_check_resource_security_flag  VARCHAR2(1)             := 'Y';
14048 	l_error_flag_local              VARCHAR2(1)             := 'N';
14049 	l_error_flag                    VARCHAR2(1)             := 'N';
14050 	l_missing_params                VARCHAR2(1000);
14051 	l_start_msg_count               NUMBER                  := 0;
14052 	l_end_msg_count                 NUMBER                  := 0;
14053 	l_loop_msg_count                NUMBER                  := 0;
14054 
14055 	l_candidate_log_tbl		CANDIDATE_LOG_REC_TYPE;
14056 	l_project_system_status_code	VARCHAR2(30);
14057 	l_cand_record_version_number	NUMBER;
14058 	l_lookup_code			VARCHAR2(20);
14059 
14060 	l_privilege                     VARCHAR2(30);
14061         l_object_name                   VARCHAR2(30);
14062         l_object_key                    NUMBER;
14063 	l_resource_valid                VARCHAR2(1)             := 'N';
14064 	l_privilege_name		VARCHAR2(40)		:= null;
14065         l_ret_code                      VARCHAR2(1);
14066 	l_return_status                 VARCHAR2(1)             := FND_API.G_RET_STS_SUCCESS;
14067 	l_msg_count                     NUMBER;
14068 	l_msg_data                      VARCHAR2(2000);
14069 	l_msg_index_out                 NUMBER;
14070 	l_data                          VARCHAR2(2000);
14071 
14072 CURSOR c_get_valid_lookup_code(c_change_reason_code VARCHAR2) IS
14073 SELECT lookup_code
14074 FROM   pa_lookups
14075 WHERE  lookup_type = 'CANDIDATE_STS_CHANGE_REASON'
14076 AND    lookup_code = c_change_reason_code;
14077 
14078 CURSOR c_get_candidate_details(c_candidate_id NUMBER) IS
14079 SELECT pcv.project_id, pc.assignment_id, pc.record_version_number
14080 FROM   pa_candidates pc, pa_candidates_v pcv
14081 WHERE  pc.candidate_id = c_candidate_id
14082 AND    pcv.candidate_number = c_candidate_id;
14083 
14084 CURSOR c_get_system_status_code(c_status_code VARCHAR2) IS
14085 SELECT project_system_status_code FROM pa_project_statuses
14086 WHERE  trunc(SYSDATE) BETWEEN start_date_active AND nvl(end_date_active, trunc(SYSDATE))
14087 AND    status_type = 'CANDIDATE'
14088 AND    project_status_code = c_status_code;
14089 
14090 	l_cand_rec			c_get_candidate_details%ROWTYPE;
14091 
14092 BEGIN
14093 
14094 	--Flows which are supported by this API
14095 		  ---------------------------------------
14096 		  --1. Creating a log of candidate when the status is changed.
14097 		  --        1.1 Validating candidate_id
14098 		  --        1.2 Validating for valid status_code
14099 		  --        1.3 validating change_reason_status
14100 		  --        1.4 Creating a entry in pa_candidate_reviews if the status is changed.
14101 	--Flows which are not supported by this API
14102 		  -------------------------------------------
14103 		  --1. Validations like status_code change allowed or not are handled by the underlying apis.
14104 
14105 	x_return_status := FND_API.G_RET_STS_SUCCESS;
14106 	x_candidate_review_id_tbl := SYSTEM.PA_NUM_TBL_TYPE();
14107 
14108 	l_debug_mode  := NVL(FND_PROFILE.VALUE_SPECIFIC('PA_DEBUG_MODE', fnd_global.user_id, fnd_global.login_id, 275, null, null), 'N');
14109 
14110         IF l_debug_mode = 'Y' THEN
14111                 PA_DEBUG.set_curr_function(p_function => 'CREATE_CANDIDATE_LOG', p_debug_mode => l_debug_mode);
14112         END IF;
14113 
14114         IF FND_API.TO_BOOLEAN(nvl(p_init_msg_list, FND_API.G_TRUE)) THEN
14115                 FND_MSG_PUB.initialize;
14116         END IF;
14117 
14118         IF p_commit = FND_API.G_TRUE THEN
14119                 savepoint CREATE_CANDIDATE_LOG_SP;
14120         END IF;
14121 
14122         IF l_debug_mode = 'Y' THEN
14123                 pa_debug.write(l_module, 'Start of CREATE_CANDIDATE_LOG', l_log_level);
14124                 pa_debug.write(l_module, 'Printing Input Parameters......', l_log_level);
14125 		pa_debug.write(l_module, 'p_commit '||p_commit, l_log_level);
14126 		pa_debug.write(l_module, 'p_init_msg_list '||p_init_msg_list, l_log_level);
14127 		pa_debug.write(l_module, 'p_api_version_number '||p_api_version_number, l_log_level);
14128                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
14129                 pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
14130                 i := p_candidate_log_tbl.first;
14131                 WHILE i IS NOT NULL LOOP
14132                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').candidate_id '||p_candidate_log_tbl(i).candidate_id, l_log_level);
14133                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').status_code '||p_candidate_log_tbl(i).status_code, l_log_level);
14134                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').change_reason_code '||p_candidate_log_tbl(i).change_reason_code, l_log_level);
14135                         pa_debug.write(l_module, 'p_candidate_in_tbl('||i||').review_comments '||p_candidate_log_tbl(i).review_comments, l_log_level);
14136                         pa_debug.write(l_module, '------------------------------------------------------------------', l_log_level);
14137                         i := p_candidate_log_tbl.next(i);
14138                 END LOOP;
14139         END IF;
14140 
14141         PA_STARTUP.INITIALIZE(
14142                   p_calling_application                 => l_calling_application
14143                 , p_calling_module                      => l_calling_module
14144                 , p_check_id_flag                       => l_check_id_flag
14145                 , p_check_role_security_flag            => l_check_role_security_flag
14146                 , p_check_resource_security_flag        => l_check_resource_security_flag
14147                 , p_debug_level                         => l_log_level
14148                 );
14149 
14150         IF l_debug_mode = 'Y' THEN
14151                 pa_debug.write(l_module, 'After call of PA_STARTUP.INITIALIZE', l_log_level);
14152         END IF;
14153 
14154         --l_prm_license_flag  := nvl(FND_PROFILE.VALUE('PA_PRM_LICENSED'),'N');
14155         --IF l_prm_license_flag <> 'Y' THEN
14156         --        null;
14157         --END IF;
14158 
14159         i := p_candidate_log_tbl.first;
14160 
14161 	WHILE i IS NOT NULL LOOP
14162                 l_error_flag_local := 'N';
14163                 l_missing_params := null;
14164                 l_start_msg_count := FND_MSG_PUB.count_msg;
14165 
14166                 l_candidate_log_tbl := p_candidate_log_tbl(i);
14167 		l_cand_rec := null;
14168 
14169                 -- Mandatory Parameters Check
14170                 IF l_debug_mode = 'Y' THEN
14171                         pa_debug.write(l_module, 'Record#'||i, l_log_level);
14172                         pa_debug.write(l_module, '-----------------------------', l_log_level);
14173                         pa_debug.write(l_module, 'Inside while loop. Mandatory parameter check.', l_log_level);
14174                 END IF;
14175 
14176 		-- Check on Candidate Id
14177 		OPEN c_get_candidate_details(l_candidate_log_tbl.candidate_id);
14178                 FETCH c_get_candidate_details INTO l_cand_rec;
14179 
14180 		IF c_get_candidate_details%NOTFOUND THEN
14181 			l_missing_params := l_missing_params||', CANDIDATE_ID';
14182 		END IF;
14183 
14184 		CLOSE c_get_candidate_details;
14185 
14186                 -- Check on Status Code
14187 		IF l_candidate_log_tbl.status_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
14188 			l_candidate_log_tbl.status_code := null;
14189 		ELSIF l_candidate_log_tbl.status_code IS NOT NULL THEN
14190 			l_project_system_status_code := null;
14191 
14192 			OPEN  c_get_system_status_code(l_candidate_log_tbl.status_code);
14193 			FETCH c_get_system_status_code INTO l_project_system_status_code;
14194 			CLOSE c_get_system_status_code;
14195 
14196 			IF l_project_system_status_code IS NULL OR l_project_system_status_code NOT IN
14197 				('CANDIDATE_DECLINED', 'CANDIDATE_PENDING_REVIEW', 'CANDIDATE_SUITABLE',
14198 				'CANDIDATE_SYSTEM_NOMINATED', 'CANDIDATE_UNDER_REVIEW', 'CANDIDATE_WITHDRAWN') THEN
14199 				l_missing_params := l_missing_params||', STATUS_CODE';
14200 			END IF;
14201 		END IF;
14202 
14203 		-- Check for Change Reason Code
14204 		IF l_candidate_log_tbl.change_reason_code = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
14205 			l_candidate_log_tbl.change_reason_code := null;
14206 		ELSIF l_candidate_log_tbl.change_reason_code IS NOT NULL THEN
14207 
14208 			OPEN  c_get_valid_lookup_code(l_candidate_log_tbl.change_reason_code);
14209 			FETCH c_get_valid_lookup_code INTO l_lookup_code;
14210 
14211 			IF c_get_valid_lookup_code%NOTFOUND THEN
14212 				l_missing_params := l_missing_params||', CHANGE_REASON_CODE';
14213 			END IF;
14214 
14215 			CLOSE c_get_valid_lookup_code;
14216 
14217 		END IF;
14218 
14219 		IF l_debug_mode = 'Y' THEN
14220                         pa_debug.write(l_module, 'Mandatory parameter validation over. List of Missing Parameters='||l_missing_params, l_log_level);
14221                 END IF;
14222 
14223 		IF l_missing_params IS NOT NULL THEN
14224                         PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_INV_PARAMS',
14225                                                 'INVALID_PARAMS', l_missing_params);
14226                         l_error_flag_local := 'Y';
14227                 END IF;
14228 
14229                 IF l_error_flag_local <> 'Y' THEN
14230 
14231 
14232 			-- Check for Review Comments
14233 			IF l_candidate_log_tbl.review_comments = PA_INTERFACE_UTILS_PUB.G_PA_MISS_CHAR THEN
14234 				l_candidate_log_tbl.review_comments := null;
14235 			END IF;
14236 
14237 			-- Security Check : Check PA_REVIEW_CANDIDATE_LOG privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS as done in CandRevwLogTopCO.java
14238 			-------------------
14239 
14240 			IF l_debug_mode = 'Y' THEN
14241                                 pa_debug.write(l_module, 'Checking PA_REVIEW_CANDIDATE_LOG privilege on PA_PROJECTS and PA_PROJECT_ASSIGNMENTS for record#'||i, l_log_level);
14242                         END IF;
14243 
14244                         l_privilege   := 'PA_REVIEW_CANDIDATE_LOG';
14245 
14246 			l_object_name := 'PA_PROJECTS';
14247 			l_object_key  := l_cand_rec.project_id;
14248 
14249                         l_return_status := FND_API.G_RET_STS_SUCCESS;
14250                         l_ret_code := 'T';
14251 
14252                         PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
14253                                   x_ret_code       => l_ret_code
14254                                 , x_return_status  => l_return_status
14255                                 , x_msg_count      => l_msg_count
14256                                 , x_msg_data       => l_msg_data
14257                                 , p_privilege      => l_privilege
14258                                 , p_object_name    => l_object_name
14259                                 , p_object_key     => l_object_key
14260 				, p_init_msg_list  => FND_API.G_FALSE);
14261 
14262                         IF nvl(l_ret_code, 'F') = 'F' AND l_return_status = FND_API.G_RET_STS_SUCCESS THEN
14263 			        l_object_name := 'PA_PROJECT_ASSIGNMENTS';
14264 		                l_object_key  := l_cand_rec.assignment_id;
14265 
14266 	                        l_return_status := FND_API.G_RET_STS_SUCCESS;
14267 		                l_ret_code := 'T';
14268 
14269 			        PA_SECURITY_PVT.CHECK_USER_PRIVILEGE(
14270 				          x_ret_code       => l_ret_code
14271 					, x_return_status  => l_return_status
14272 	                                , x_msg_count      => l_msg_count
14273 		                        , x_msg_data       => l_msg_data
14274 			                , p_privilege      => l_privilege
14275 				        , p_object_name    => l_object_name
14276 	                                , p_object_key     => l_object_key
14277 					, p_init_msg_list  => FND_API.G_FALSE);
14278 			END IF;
14279 			IF nvl(l_ret_code, 'F') = 'F' OR l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
14280                                 -- This message does not have token defined, but intentionally putting token
14281                                 -- bcoz we still want to show the privielge name which is missing
14282                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_REQ_ADD_CAND_LOG'
14283                                                       ,'MISSING_PRIVILEGE', l_privilege);
14284                                 l_error_flag_local := 'Y';
14285                         END IF;
14286 
14287                         IF l_debug_mode = 'Y' THEN
14288                                 pa_debug.write(l_module, 'Security check complete for record#'||i||' privilege '||l_ret_code, l_log_level);
14289                         END IF;
14290 
14291                 END IF;
14292 
14293                 -- Call Core Actual API
14294                 -----------------------
14295 
14296                 IF l_error_flag_local <> 'Y' THEN
14297                         l_return_status := FND_API.G_RET_STS_SUCCESS;
14298 
14299                         IF l_debug_mode = 'Y' THEN
14300                                 pa_debug.write(l_module, 'Calling PA_CANDIDATE_PUB.ADD_CANDIDATE_LOG for Record#'||i, l_log_level);
14301                         END IF;
14302 
14303                         PA_CANDIDATE_PUB.ADD_CANDIDATE_LOG
14304                         (
14305 				  p_candidate_id		=> l_candidate_log_tbl.candidate_id
14306 				, p_status_code			=> l_candidate_log_tbl.status_code
14307 				, p_change_reason_code		=> l_candidate_log_tbl.change_reason_code
14308 				, p_review_comments		=> l_candidate_log_tbl.review_comments
14309 				, p_cand_record_version_number	=> l_cand_rec.record_version_number
14310 				, x_cand_record_version_number	=> l_cand_record_version_number
14311 				, p_init_msg_list		=> FND_API.G_FALSE
14312 				, x_return_status		=> l_return_status
14313 				, x_msg_count			=> l_msg_count
14314 				, x_msg_data			=> l_msg_data
14315                         );
14316 
14317                         IF l_debug_mode = 'Y' THEN
14318                                 pa_debug.write(l_module, 'After call PA_CANDIDATE_PUB.ADD_CANDIDATE_LOG l_return_status='||l_return_status, l_log_level);
14319                         END IF;
14320 
14321 			IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
14322 				x_candidate_review_id_tbl.extend(1);
14323 				x_candidate_review_id_tbl(x_candidate_review_id_tbl.COUNT) := l_cand_record_version_number;
14324 				IF l_debug_mode = 'Y' THEN
14325                                         pa_debug.write(l_module, 'PA_CANDIDATE_PUB.ADD_CANDIDATE_LOG successful', l_log_level);
14326                                 END IF;
14327 			ELSE
14328 				l_error_flag_local := 'Y';
14329 				x_candidate_review_id_tbl.extend(1);
14330 				x_candidate_review_id_tbl(x_candidate_review_id_tbl.COUNT) := -1;
14331 				IF l_debug_mode = 'Y' THEN
14332                                         pa_debug.write(l_module, 'PA_CANDIDATE_PUB.ADD_CANDIDATE_LOG unsuccessful', l_log_level);
14333                                 END IF;
14334 			END IF;
14335 		ELSE
14336 			x_candidate_review_id_tbl.extend(1);
14337 			x_candidate_review_id_tbl(x_candidate_review_id_tbl.COUNT) := -1;
14338                 END IF;
14339 
14340                 l_end_msg_count := FND_MSG_PUB.count_msg;
14341                 IF l_debug_mode = 'Y' THEN
14342                         pa_debug.write(l_module, 'l_start_msg_count='||l_start_msg_count, l_log_level);
14343                         pa_debug.write(l_module, 'l_end_msg_count='||l_end_msg_count, l_log_level);
14344                 END IF;
14345                 l_loop_msg_count := l_end_msg_count - l_start_msg_count;
14346 
14347                 IF l_error_flag_local = 'Y' OR l_loop_msg_count > 0 THEN
14348                         l_error_flag := 'Y';
14349 
14350                         IF l_debug_mode = 'Y' THEN
14351                                 pa_debug.write(l_module, 'Repopulating Error Message Stack', l_log_level);
14352                         END IF;
14353 
14354                         FOR j in l_start_msg_count+1..l_end_msg_count LOOP
14355                                 -- Always get from first location in stack i.e. l_start_msg_count+1
14356                                 -- Because stack moves down after delete
14357                                 FND_MSG_PUB.get (
14358                                         p_msg_index      => l_start_msg_count+1,
14359                                         p_encoded        => FND_API.G_FALSE,
14360                                         p_data           => l_data,
14361                                         p_msg_index_out  => l_msg_index_out );
14362 
14363                                 -- Always delete at first location in stack i.e. l_start_msg_count+1
14364                                 -- Because stack moves down after delete
14365                                 FND_MSG_PUB.DELETE_MSG(p_msg_index => l_start_msg_count+1);
14366 
14367                                 PA_UTILS.ADD_MESSAGE('PA', 'PA_AMG_RES_ERROR_MSG',
14368                                                 'RECORD_NO', i,
14369                                                 'MESSAGE', l_data);
14370                         END LOOP;
14371 
14372 			IF l_debug_mode = 'Y' THEN
14373                                 pa_debug.write(l_module, 'After Repopulating Error Message Stack', l_log_level);
14374                                 pa_debug.write(l_module, 'l_cand_record_version_number = '||l_cand_record_version_number, l_log_level);
14375                         END IF;
14376 
14377 		END IF;
14378                 i := p_candidate_log_tbl.next(i);
14379         END LOOP;
14380 
14381         IF l_debug_mode = 'Y' THEN
14382                 pa_debug.write(l_module, 'All records are done', l_log_level);
14383                 pa_debug.write(l_module, 'l_error_flag='||l_error_flag, l_log_level);
14384                 pa_debug.write(l_module, 'FND_MSG_PUB.count_msg='||FND_MSG_PUB.count_msg, l_log_level);
14385         END IF;
14386 
14387         IF l_error_flag = 'Y' OR FND_MSG_PUB.count_msg > 0 THEN
14388                 RAISE FND_API.G_EXC_ERROR;
14389         END IF;
14390 
14391         IF l_debug_mode = 'Y' THEN
14392                 PA_DEBUG.reset_curr_function;
14393         END IF;
14394 
14395         IF p_commit = FND_API.G_TRUE THEN
14396                 commit;
14397         END IF;
14398 
14399 EXCEPTION
14400 
14401 WHEN FND_API.G_EXC_ERROR THEN
14402 
14403         x_return_status := FND_API.G_RET_STS_ERROR;
14404         l_msg_count := FND_MSG_PUB.count_msg;
14405 
14406 	IF c_get_candidate_details%ISOPEN THEN
14407 		CLOSE c_get_candidate_details;
14408 	END IF;
14409 
14410 	IF c_get_system_status_code%ISOPEN THEN
14411 		CLOSE c_get_system_status_code;
14412 	END IF;
14413 
14414         IF p_commit = FND_API.G_TRUE THEN
14415                 ROLLBACK TO CREATE_CANDIDATE_LOG_SP;
14416         END IF;
14417 
14418         IF l_msg_count = 1 AND x_msg_data IS NULL THEN
14419                 PA_INTERFACE_UTILS_PUB.get_messages
14420                 ( p_encoded        => FND_API.G_FALSE
14421                 , p_msg_index      => 1
14422                 , p_msg_count      => l_msg_count
14423                 , p_msg_data       => l_msg_data
14424                 , p_data           => l_data
14425                 , p_msg_index_out  => l_msg_index_out);
14426 
14427                 x_msg_data := l_data;
14428                 x_msg_count := l_msg_count;
14429         ELSE
14430                 x_msg_count := l_msg_count;
14431         END IF;
14432 
14433         IF l_debug_mode = 'Y' THEN
14434                 Pa_Debug.reset_curr_function;
14435         END IF;
14436 
14437 WHEN OTHERS THEN
14438 
14439         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
14440         x_msg_data      := SUBSTRB(SQLERRM,1,240);
14441 
14442 	IF c_get_candidate_details%ISOPEN THEN
14443 		CLOSE c_get_candidate_details;
14444 	END IF;
14445 
14446 	IF c_get_system_status_code%ISOPEN THEN
14447 		CLOSE c_get_system_status_code;
14448 	END IF;
14449 
14450         IF p_commit = FND_API.G_TRUE THEN
14451                 ROLLBACK TO CREATE_CANDIDATE_LOG_SP;
14452         END IF;
14453 
14454         FND_MSG_PUB.add_exc_msg
14455         ( p_pkg_name            => 'PA_RES_MANAGEMENT_AMG_PUB'
14456         , p_procedure_name      => 'CREATE_CANDIDATE_LOG'
14457         , p_error_text          => x_msg_data);
14458 
14459         x_msg_count     := FND_MSG_PUB.count_msg;
14460 
14461         IF l_debug_mode = 'Y' THEN
14462                 PA_DEBUG.reset_curr_function;
14463         END IF;
14464         RAISE;
14465 
14466 END CREATE_CANDIDATE_LOG;
14467 
14468 END PA_RES_MANAGEMENT_AMG_PUB;