DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_PLANNING_RESOURCE_UTILS

Source


1 PACKAGE BODY PA_PLANNING_RESOURCE_UTILS AS
2 /* $Header: PARPRLUB.pls 120.12.12010000.3 2008/10/23 05:21:50 paljain ship $ */
3 
4 g_job_group_id NUMBER;
5 /********************************************************
6  * Check whether any planning resources or class defaults for the spread
7  * curve exist.
8  *******************************************************/
9 FUNCTION chk_spread_curve_in_use(p_spread_curve_id IN NUMBER) return BOOLEAN
10 IS
11 
12 CURSOR chk_if_exists IS
13 select 'Y'
14 from dual
15 where ((exists (select 'Y'
16                from   pa_resource_list_members
17                where  spread_curve_id = p_spread_curve_id))
18 OR     (exists (select 'Y'
19                from   pa_plan_res_defaults
20                where  spread_curve_id = p_spread_curve_id)));
21 
22 l_exists VARCHAR2(1) := 'N';
23 l_return BOOLEAN := FALSE;
24 BEGIN
25 open chk_if_exists;
26 fetch chk_if_exists into l_exists;
27 IF chk_if_exists%FOUND THEN
28    l_return := TRUE;
29 ELSE
30    l_return := FALSE;
31 END IF;
32 
33 close chk_if_exists;
34 RETURN l_return;
35 
36 END chk_spread_curve_in_use;
37 
38 /********************************************************
39  * Check whether any planning resources with NLR exist
40  * ******************************************************/
41 FUNCTION chk_nlr_resource_exists(p_non_labor_resource IN Varchar2) return
42 BOOLEAN
43 IS
44 CURSOR chk_nlr_resource IS
45 select 'Y'
46 from   pa_resource_list_members
47 where  non_labor_resource = p_non_labor_resource
48 and    migration_code = 'N';
49 
50 l_exists VARCHAR2(1) := 'N';
51 l_return BOOLEAN := FALSE;
52 BEGIN
53 open chk_nlr_resource;
54 fetch chk_nlr_resource into l_exists;
55 IF chk_nlr_resource%FOUND THEN
56    l_return := TRUE;
57 ELSE
58    l_return := FALSE;
59 END IF;
60 
61 close chk_nlr_resource;
62 RETURN l_return;
63 
64 END chk_nlr_resource_exists;
65 
66 
67 /*******************************************************************
68  * Function    : Get_res_member_code
69  * Description : The purpose of this function is to return the resource
70  *               code for a given resource list member id.
71  *               Takes in parameter - p_resource_list_member_id
72  *               Returns - l_resource_code
73  *******************************************************************/
74 FUNCTION Get_res_member_code(p_resource_list_member_id IN NUMBER)
75 return VARCHAR2
76 IS
77 -- Decl of local variables
78 l_res_type_code  VARCHAR2(30):= NULL;
79 l_resource_code  VARCHAR2(30):= NULL;
80 BEGIN
81 /* The purpose of this function is to return the resource code for a
82  * given planning resource.*/
83 	IF p_resource_list_member_id IS NOT NULL THEN
84            BEGIN
85            SELECT typ.res_type_code
86              INTO l_res_type_code
87              FROM pa_res_types_b typ,
88                   pa_resource_list_members rlm,
89                   pa_res_formats_b fmt
90             WHERE rlm.resource_list_member_id = p_resource_list_member_id
91               AND rlm.res_format_id = fmt.res_format_id
92               AND fmt.res_type_enabled_flag = 'Y'
93               AND fmt.res_type_id = typ.res_type_id;
94            EXCEPTION
95 	      WHEN NO_DATA_FOUND THEN
96 	         l_res_type_code := NULL;
97                  RETURN NULL;
98            END;
99 
100            IF l_res_type_code IS NOT NULL THEN
101 	      Select DECODE(incurred_by_res_flag, 'Y','',
102 	           DECODE(l_res_type_code,
103 	           'NAMED_PERSON',to_char(person_id),
104                    'PERSON_TYPE', person_type_code,
105                    'JOB', to_char(job_id),
106                    'BOM_LABOR', to_char(bom_resource_id),
107                    'RESOURCE_CLASS',resource_class_code,
108                    'NON_LABOR_RESOURCE',non_labor_resource,
109                    'BOM_EQUIPMENT',to_char(bom_resource_id),
110                    'INVENTORY_ITEM',to_char(inventory_item_id),
111                    'ITEM_CATEGORY',to_char(item_category_id)))
112                INTO l_resource_code
113                FROM pa_resource_list_members
114                WHERE resource_list_member_id = p_resource_list_member_id;
115 
116                Return l_resource_code;
117            ELSE
118               Return Null;
119            END IF;
120         ELSE
121               Return Null;
122         END IF;
123 EXCEPTION
124  WHEN NO_DATA_FOUND THEN
125 	Return l_resource_code;
126  WHEN OTHERS THEN
127 	Return Null;
128 END Get_res_member_code;
129 /*************************************/
130 /*****************************************************************
131  * Function    : Get_member_Fin_Cat_Code
132  * Description : The purpose of this function is to return the Financial
133  *               category code for a given planning resource.
134  *               Takes in Parameter - p_resource_member_id
135  *               Returns - l_fin_category_code
136  *******************************************************************/
137 FUNCTION Get_member_Fin_Cat_Code(p_resource_list_member_id IN NUMBER) return
138 VARCHAR2
139 IS
140 l_fin_category_code  pa_resource_list_members.FC_RES_TYPE_CODE%TYPE := NULL;
141 BEGIN
142 	IF p_resource_list_member_id IS NOT NULL THEN
143 		SELECT DECODE(fc_res_type_code,
144 		'EXPENDITURE_TYPE',expenditure_type,
145 		'EXPENDITURE_CATEGORY',expenditure_category,
146 		'EVENT_TYPE',event_type,
147 		'REVENUE_CATEGORY',revenue_category)
148 		INTO l_fin_category_code
149 		FROM  pa_resource_list_members
150 		WHERE RESOURCE_LIST_MEMBER_ID = p_resource_list_member_id;
151 
152 		Return l_fin_category_code;
153 	ELSE
154                 Return Null;
155         END IF;
156 EXCEPTION
157    WHEN NO_DATA_FOUND THEN
158 	Return l_fin_category_code;
159    WHEN OTHERS THEN
160 	Return Null;
161 END Get_member_Fin_Cat_Code;
162 /***********************************/
163 /***********************************************************************
164  * Function    : Get_member_incur_by_res_code
165  * Description : The purpose of this function is to return the incurred by
166  *               resource code for a given resource_list member.
167  *               Takes in parameter - p_resource_list_member_id
168  *               Returns - l_incur_by_res_code
169  ***********************************************************************/
170 FUNCTION Get_member_Incur_by_Res_Code(p_resource_list_member_id IN NUMBER)
171   return VARCHAR2
172 IS
173 --Decl of Local Var
174 l_incur_by_res_code VARCHAR2(30) := NULL;
175 BEGIN
176   IF p_resource_list_member_id IS NOT NULL THEN
177 		SELECT DECODE(incurred_by_res_flag,'N','',
178 		nvl(to_char(person_id),nvl(to_char(job_id),
179                 nvl(person_type_code,
180                     nvl(to_char(incur_by_role_id),
181                     nvl(incur_by_res_class_code, 'ERROR'))))))
182 		INTO l_incur_by_res_code
183 		FROM pa_resource_list_members
184 		WHERE resource_list_member_id = p_resource_list_member_id;
185 
186                 Return l_incur_by_res_code;
187    ELSE
188                Return NULL;
189    END IF;
190 
191 EXCEPTION
192 WHEN NO_DATA_FOUND THEN
193 	Return l_incur_by_res_code;
194 WHEN OTHERS THEN
195 	Return null;
196 END Get_member_Incur_By_Res_Code;
197 /****************************************************************/
198 /**************************************************************
199  * FUNCTION : Get_res_type_code
200  *************************************************************/
201  FUNCTION Get_res_type_code(p_res_format_id IN NUMBER)
202  RETURN VARCHAR2
203  IS
204  l_res_type_code  pa_res_types_b.RES_TYPE_CODE%TYPE := null;
205  BEGIN
206     IF p_res_format_id IS NOT NULL THEN
207       SELECT b.res_type_code
208       INTO l_res_type_code
209       FROM pa_res_formats_b a, pa_res_types_b b
210       WHERE a.RES_TYPE_ID = b.RES_TYPE_ID
211       AND a.RES_TYPE_ENABLED_FLAG = 'Y'
212       AND a.res_format_id = p_res_format_id;
213       Return l_res_type_code;
214   ELSE
215       Return Null;
216   END IF;
217  EXCEPTION
218  WHEN OTHERS THEN
219      Return Null;
220  END Get_res_type_code;
221 
222 /*******************************************************************
223  * Function    : Get_Resource_Code
224  * Description : The purpose of this function is to return the resource
225  *               code for a given resource assignment.
226  *               Takes in parameter - p_resource_assignment_id
227  *               Returns - l_resource_code
228  *******************************************************************/
229 FUNCTION Get_resource_Code(p_resource_assignment_id IN NUMBER) return VARCHAR2
230 IS
231 -- Decl of local variables
232 l_resource_code  pa_resource_assignments.res_type_code%TYPE := NULL;
233 BEGIN
234 /* The purpose of this function is to return the resource code for a given resource assignment.*/
235 	IF p_resource_assignment_id IS NOT NULL THEN
236 	      Select DECODE(incurred_by_res_flag, 'Y','',
237 	           DECODE(res_type_code,
238 	           'NAMED_PERSON',to_char(person_id),
239                    'PERSON_TYPE', person_type_code,
240                    'JOB', to_char(job_id),
241                    'BOM_LABOR', to_char(bom_resource_id),
242                    'RESOURCE_CLASS',resource_class_code,
243                    'NON_LABOR_RESOURCE',non_labor_resource,
244                    'BOM_EQUIPMENT',to_char(bom_resource_id),
245                    'INVENTORY_ITEM',to_char(inventory_item_id),
246                    'ITEM_CATEGORY',to_char(item_category_id)))
247                INTO l_resource_code
248                FROM pa_resource_assignments
249                WHERE resource_assignment_id = p_resource_assignment_id;
250 
251                Return l_resource_code;
252         ELSE
253               Return Null;
254 END IF;
255 EXCEPTION
256  WHEN NO_DATA_FOUND THEN
257 	Return l_resource_code;
258  WHEN OTHERS THEN
259 	Return Null;
260 END Get_resource_Code;
261 /*********************************************************************/
262 
263 /***********************************************************************
264  * Function    : Get_Incur_By_Res_Code
265  * Description : The purpose of this function is to return the incurred by
266  *               resource code for a given resource assignment.
267  *               Takes in parameter - p_resource_assignment_id
268  *               Returns - l_incur_by_res_code
269  ***********************************************************************/
270 
271 FUNCTION Get_Incur_by_Res_Code(p_resource_assignment_id IN NUMBER)
272   return VARCHAR2
273 IS
274 --Decl of Local Var
275 l_incur_by_res_code VARCHAR2(30) := NULL;
276 BEGIN
277   IF p_resource_assignment_id IS NOT NULL THEN
278 		SELECT DECODE(incurred_by_res_flag,'N','',
279 		nvl(to_char(person_id),nvl(to_char(job_id), nvl(person_type_code,
280                     nvl(to_char(incur_by_role_id),
281                     nvl(incur_by_res_class_code, NULL))))))
282 		INTO l_incur_by_res_code
283 		FROM pa_resource_assignments
284 		WHERE resource_assignment_id = p_resource_assignment_id;
285 
286                 Return l_incur_by_res_code;
287    ELSE
288                Return NULL;
289    END IF;
290 
291 EXCEPTION
292 WHEN NO_DATA_FOUND THEN
293 	Return l_incur_by_res_code;
294 WHEN OTHERS THEN
295 	Return null;
296 END Get_Incur_By_Res_Code;
297 /****************************************************************/
298 
299 /*****************************************************************
300  * Function    : Get_Fin_Category_Code
301  * Description : The purpose of this function is to return the Financial
302  *               category code for a given resource assignment.
303  *               Takes in Parameter - p_resource_assignment_id
304  *               Returns - l_fin_category_code
305  *******************************************************************/
306 FUNCTION Get_Fin_Category_Code(p_resource_assignment_id IN NUMBER) return
307 VARCHAR2
308 IS
309 l_fin_category_code  pa_resource_assignments.FC_RES_TYPE_CODE%TYPE := NULL;
310 BEGIN
311 	IF p_resource_assignment_id IS NOT NULL THEN
312 		SELECT DECODE(fc_res_type_code,
313 		'EXPENDITURE_TYPE',expenditure_type,
314 		'EXPENDITURE_CATEGORY',expenditure_category,
315 		'EVENT_TYPE',event_type,
316 		'REVENUE_CATEGORY',revenue_category_code)
317 		INTO l_fin_category_code
318 		FROM  pa_resource_assignments
319 		WHERE resource_assignment_id = p_resource_assignment_id;
320 
321 		Return l_fin_category_code;
322 	ELSE
323                 Return Null;
324         END IF;
325 EXCEPTION
326    WHEN NO_DATA_FOUND THEN
327 	Return l_fin_category_code;
328    WHEN OTHERS THEN
329 	Return Null;
330 END Get_Fin_Category_Code;
331 /**********************************************************************/
332 
333 /****************************************************************************
334  * Procedure   : Validate_Organization
335  * Description : This procedure validates the organization for a
336  *               planning. It first validates the name and id,  of
337  *               the organization and then checks if the organization
338  *               is an expenditure organization or a project owning
339  *               organization.
340  *               The organization on a planning resource can
341  *               be an expenditure organization since the resource
342  *               could be a person.
343  *               The organization on the planning resource can be a project
344  *               owning organization since the resource could an expense which
345  *               is incurred by the project organization.
346  *               Hence, we are checking for both.
347  * Called By   :
348  * Calls Prog  : PA_HR_ORG_UTILS.Check_OrgName_Or_Id
349 *****************************************************************************/
350 PROCEDURE Validate_Organization
351             (p_organization_name	IN 	VARCHAR2,
352              p_organization_id		IN	NUMBER,
353              x_organization_id		OUT NOCOPY	NUMBER,
354              x_return_status		OUT NOCOPY	VARCHAR2,
355              x_error_msg_code   	OUT NOCOPY	VARCHAR2)
356 IS
357 --Declaration of Local variables
358 --  l_return_status            VARCHAR2(1);
359   l_organization_id                   NUMBER := null;
360 -- l_error_msg_data           fnd_new_messages.message_name%TYPE;
361 BEGIN
362         x_return_status  := FND_API.G_RET_STS_SUCCESS;
363         x_error_msg_code := Null;
364 -- validate the organization and assign the id to the global record.
365 /*****************************************************************
366  * We are going to make use of an existing procedure
367  * PA_HR_ORG_UTILS.Check_OrgName_Or_Id, which will take in the
368  * Organization ID and organization name and will check for null
369  * for either of the fields and will accordingly derive the Organization_id.
370  ********************************************************************/
371   IF (p_organization_id IS NOT NULL) OR
372      ( p_organization_name IS NOT NULL)
373   THEN
374         PA_HR_ORG_UTILS.Check_OrgName_Or_Id(
375                     p_organization_id,
376                     p_organization_name,
377                     PA_STARTUP.G_Check_ID_Flag,
378                     l_organization_id,
379                     x_return_status,
380                     x_error_msg_code);
381 
382 /*******************************************************************
383  * If the call to the procedure Check_OrgName_Or_Id, returns an error then
384  * call the package PA_UTILS and pass the error message.
385  ********************************************************************/
386         IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
387            IF x_error_msg_code = 'PA_INVALID_ORG' THEN
388      	      PA_UTILS.Add_Message('PA', 'PA_INVALID_ORG_PLAN_RES', 'PLAN_RES',
389                                    Pa_Planning_Resource_Pvt.g_token);
390               Return;
391            ELSIF x_error_msg_code = 'PA_ORG_NOT_UNIQUE' THEN
392               PA_UTILS.Add_Message('PA', 'PA_ORG_NOT_UNIQUE_PLAN_RES',
393                                    'PLAN_RES',Pa_Planning_Resource_Pvt.g_token);
394               Return;
395            ELSE
396               Return;
397            END IF;
398         END IF;
399 /*******************************************************************
400  * If the call to the procedure Check_OrgName_Or_Id, completes successfully,
401  * then we need validate that the organization is a valid expenditure and
402  * project organization in the system.
403  ***********************************************************************/
404                BEGIN
405 	       	    SELECT distinct  ORGANIZATION_ID
406                     INTO x_organization_id
407                     FROM pa_all_organizations
408                     WHERE INACTIVE_DATE IS NULL
409                     AND PA_ORG_USE_TYPE in ('EXPENDITURES', 'PROJECTS')
410                     AND   ORGANIZATION_ID = l_organization_id;
411               EXCEPTION
412               WHEN OTHERS THEN
413                     x_organization_id := NULL;
414                     x_return_status:= FND_API.G_RET_STS_ERROR;
415                     x_error_msg_code:= 'PA_ORG_INVALID_PROJ_EXP';
416                     /*  We will be adding a new message which reads
417                      Organization is an Invalid Expenditure or Project
418                      Organization.*/
419                     PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
420                                          Pa_Planning_Resource_Pvt.g_token);
421                     Return;
422               END;
423 
424   END IF;
425 
426 END VALIDATE_ORGANIZATION;
427 /*******************************************************************/
428 
429 /************************************************************************
430  *   Procedure        : Check_SupplierName_Or_Id
431  *   Description      : This Subprog validates the supplier name
432  *                      and ID combination
433  *********************************************************************/
434 
435 PROCEDURE Check_SupplierName_Or_Id
436             ( p_supplier_id            IN      NUMBER
437              ,p_supplier_name          IN      VARCHAR2
438              ,p_check_id_flag          IN      VARCHAR2
439              ,x_supplier_id            OUT NOCOPY     NUMBER
440              ,x_return_status          OUT NOCOPY     VARCHAR2
441              ,x_error_msg_code         OUT NOCOPY     VARCHAR2 ) IS
442 
443       l_current_id         NUMBER := NULL;
444       l_num_ids            NUMBER := 0;
445       l_id_found_flag      VARCHAR(1) := 'N';
446 
447        CURSOR c_ids IS
448        SELECT vendor_id
449        FROM po_vendors
450        WHERE vendor_name  = p_supplier_name;
451 BEGIN
452 IF (p_supplier_id IS NOT NULL)
453 THEN
454   IF (p_check_id_flag = 'Y') THEN
455      BEGIN
456        	SELECT vendor_id
457 	INTO x_supplier_id
458 	FROM PO_Vendors
459 	WHERE vendor_id = p_supplier_id;
460      EXCEPTION
461      WHEN OTHERS THEN
462          x_supplier_id := NULL;
463          x_return_status:= FND_API.G_RET_STS_ERROR;
464 	--Need to get a proper message
465          x_error_msg_code:= 'PA_INVALID_SUPPLIER';
466         RETURN;
467       END;
468   ELSIF (p_check_id_flag='N') THEN
469             x_supplier_id := p_supplier_id;
470   ELSIF (p_check_id_flag = 'A') THEN
471 /******************************************************************
472  * The Check_id_flag of 'A' indicates that this validation is coming from Java
473  * front end, and hence the Id and Name Combination needs to be
474  * validated in the database.
475  * *****************************************************************/
476        IF (p_supplier_name IS NULL) THEN
477              -- Return a null ID since the name is null.
478        	     x_supplier_id := NULL;
479        ELSE
480             OPEN c_ids;
481               LOOP
482                 FETCH c_ids INTO l_current_id;
483                 EXIT WHEN c_ids%NOTFOUND;
484                 IF (l_current_id = p_supplier_id) THEN
485                       l_id_found_flag := 'Y';
486                       x_supplier_id := p_supplier_id;
487                  END IF;
488                END LOOP;
489 	       l_num_ids := c_ids%ROWCOUNT;
490             CLOSE c_ids;
491 
492              IF (l_num_ids = 0) THEN
493                  -- No IDs for name
494                  RAISE NO_DATA_FOUND;
495              ELSIF (l_num_ids = 1) THEN
496                  -- Since there is only one ID for the name use it.
497                  x_supplier_id := l_current_id;
498              ELSIF (l_num_ids > 1) THEN
499                  --More than one ID for the name
500                    RAISE TOO_MANY_ROWS;
501               END IF;
502        END IF;
503   ELSE
504 	x_supplier_id := NULL;
505   END IF;
506 ELSE
507         IF (p_supplier_name IS NOT NULL) THEN
508   	  BEGIN
509             SELECT vendor_id
510             INTO x_supplier_id
511             FROM po_vendors
512             WHERE vendor_name  = p_supplier_name;
513           EXCEPTION
514           WHEN OTHERS THEN
515               x_supplier_id := NULL;
516               x_return_status:= FND_API.G_RET_STS_ERROR;
517        	      --Need to get a proper message
518               x_error_msg_code:= 'PA_INVALID_SUPPLIER_NAME';
519              Return;
520 	  END;
521         ELSE
522           x_supplier_id := NULL;
523         END IF;
524 END IF;
525        x_return_status:= FND_API.G_RET_STS_SUCCESS;
526 EXCEPTION
527 WHEN OTHERS THEN
528          x_supplier_id := NULL;
529          x_return_status:= FND_API.G_RET_STS_ERROR;
530           --Need to get a proper message
531          x_error_msg_code:= 'PA_INVALID_SUPPLIER';
532          RETURN;
533 END Check_SupplierName_Or_Id;
534 /******************************************************************
535  * Procedure   : Validate Supplier
536  * Description : The Purpose of this procedure is to Validate if the
537  *               Supplier is valid in the system or not. Validation done
538  *               as follows:-
539  *               1. If the Resource_class_code passed as IN parameter = 'PEOPLE'
540  *               Then we call sub-Function Is_Contingent_Worker which checks if
541  *               the person is a contingent worker. if not then an error message
542  *               is displayed.
543  *               2. Next the Supplier ID/Name validity check needs to be done
544  *               Hence the main prog calls subprog Check_SupplierName_Or_Id
545  *               to do the check.
546  **********************************************************************/
547 PROCEDURE Validate_Supplier(
548          p_resource_class_code  	IN	  VARCHAR2,
549          p_person_id	        	IN        NUMBER,
550          p_supplier_id		        IN	  NUMBER    DEFAULT NULL,
551          p_supplier_name		IN	  VARCHAR2  DEFAULT NULL,
552          x_supplier_id		        OUT NOCOPY	  NUMBER,
553          x_return_status		OUT NOCOPY	  VARCHAR2,
554          x_error_msg_code	        OUT NOCOPY	  VARCHAR2)
555 
556 IS
557       l_return_status      VARCHAR2(1);
558       l_error_msg_code     fnd_new_messages.message_name%TYPE;
559       l_supplier_id        PO_VENDORS.vendor_id%TYPE := NULL;
560       l_err_status         VARCHAR2(30) := 'N';
561 /************************************************************************
562  * Sub-function    : Is_Contingent_Worker
563  * Description     : This Subprog checks if the resource is a contingent
564  *                 worker or not, If it is a contingent worker Then
565  *                 then it returns 'Y' Else returns 'N'.  To Check
566  *                 for Contingent worker we are directly looking it up
567  *                 from the per_people_x view as it filters those where
568  *                 sysdate between effective start and end date.
569  *                 Also checks to see if the current_npw_flag = 'Y'
570  ************************************************************************/
571 Function Is_Contingent_Worker(p_person_id  IN VARCHAR2) Return VARCHAR2
572 IS
573    l_cwk_flag     VARCHAR2(30) := null;
574 BEGIN
575 	SELECT 'Y'
576         INTO l_cwk_flag
577         --FROM per_people_x
578         FROM per_all_people_f
579 	WHERE person_id = p_person_id
580         AND current_npw_flag = 'Y'
581         AND trunc(sysdate) between trunc(effective_start_date) AND
582         trunc(effective_end_date);
583 
584 	Return l_cwk_flag;
585 EXCEPTION
586 WHEN OTHERS THEN
587 	-- This status will indicate not a contingent worker.
588 	Return 'N';
589 END Is_Contingent_Worker;
590 /*******************/
591 
592 /************************************
593  *         Main Body                *
594  ************************************/
595 
596 BEGIN
597    x_return_status := FND_API.G_RET_STS_SUCCESS;
598    IF p_resource_class_code = 'PEOPLE'  and p_person_id IS NOT NULL THEN
599     /* If the p_resource_class_code is 'People' then we need to check if
600          * the resource is a contingent
601          * worker. This is done by call to the subprog Check_contingent which
602          * will return the status. */
603 	 IF Is_Contingent_Worker(p_person_id) = 'N' THEN
604 		x_supplier_id := NULL;
605                 l_err_status := 'Y';
606 		x_return_status := FND_API.G_RET_STS_ERROR;
607 		x_error_msg_code:= 'PA_IS_NOT_CONTINGENT';
608                 PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
609                                      Pa_Planning_Resource_Pvt.g_token);
610                Return;
611 	 END IF;
612     END IF;
613 
614 IF p_resource_class_code <> 'PEOPLE' OR
615                           l_err_status = 'N'
616 THEN
617       IF (p_supplier_id IS NOT NULL) OR
618          (p_supplier_name IS NOT NULL)
619       THEN
620 -- dbms_output.put_line('- IN Validate Supp ');
621       /* We call the Procedure Check_SupplierName_Or_Id to validate the
622       * Supplier ID and Name combination. */
623             Check_SupplierName_Or_Id(
624             p_supplier_id,
625             p_supplier_name,
626             PA_STARTUP.G_Check_ID_Flag,
627             l_supplier_id,
628             l_return_status,
629             l_error_msg_code);
630 
631 -- dbms_output.put_line('- After Check_SupplierName_Or_Id p_supplier_name IS : '|| p_supplier_name);
632 -- dbms_output.put_line('- After Check_SupplierName_Or_Id p_supplier_id IS : '|| p_supplier_id);
633 -- dbms_output.put_line('- After Check_SupplierName_Or_Id l_supplier_id IS : '|| l_supplier_id);
634 -- dbms_output.put_line('- After Check_SupplierName_Or_Id l_return_status IS : '|| l_return_status);
635             x_supplier_id    := l_supplier_id;
636             x_return_status  := l_return_status;
637             x_error_msg_code := l_error_msg_code;
638 
639             IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
640                PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
641                                      Pa_Planning_Resource_Pvt.g_token);
642                Return;
643             END IF;
644         ELSE
645             x_supplier_id := NULL;
646             x_return_status := FND_API.G_RET_STS_ERROR;
647             x_error_msg_code:= 'PA_PLN_RL_NO_SUPPLIER';
648             PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
649                                  Pa_Planning_Resource_Pvt.g_token);
650             Return;
651         END IF;
652  END IF;
653 END Validate_Supplier;
654 /************************************************************************/
655 
656 /*******************************
657  *  Procedure : Check_PersonName_or_ID
658  * Description  : Used to validate the Person ID
659  *                Name combination.
660  ************************************/
661 PROCEDURE  Check_PersonName_or_ID(
662                p_person_id      IN   VARCHAR2,
663                p_person_name    IN   VARCHAR2,
664                p_check_id_flag  IN   VARCHAR2,
665                x_person_id      OUT NOCOPY  NUMBER,
666                x_return_status  OUT NOCOPY  VARCHAR2,
667                x_error_msg_code OUT NOCOPY  VARCHAR2)
668 IS
669  l_current_id     NUMBER   := NULL;
670  l_person_id      NUMBER;
671  l_num_ids        NUMBER   := 0;
672 
673 /****************************************************
674  * Bug  - 3523947
675  * Desc - Modified the cursor c_ids. Removed the check
676  *        where sysdate between eff start and end date.
677  *        And selecting from per_people_x to keep it
678  *        consistent with the other selects.
679  ***************************************************/
680  Cursor c_ids IS
681     SELECT person_id
682     --FROM per_all_people_f
683     FROM per_people_x
684     WHERE full_name = p_person_name;
685     --AND trunc(sysdate) between trunc(effective_start_date) AND
686     --trunc(effective_end_date);
687 BEGIN
688   x_return_status:= FND_API.G_RET_STS_SUCCESS;
689 IF (p_person_id IS NOT NULL)
690 THEN
691     IF (p_check_id_flag = 'Y') THEN
692 	BEGIN
693        	    SELECT person_id
694 	    INTO l_person_id
695 	    FROM per_people_x
696 	    WHERE person_id = p_person_id;
697             x_person_id := l_person_id;
698 	EXCEPTION
699 	WHEN OTHERS THEN
700             x_person_id := NULL;
701             x_return_status:= FND_API.G_RET_STS_ERROR;
702       	   --Need to get a proper message
703             x_error_msg_code:= 'PA_INVALID_PERSON_ID';
704             Return;
705          END;
706       ELSIF (p_check_id_flag='N') THEN
707             l_person_id := p_person_id;
708             x_person_id := l_person_id;
709       ELSIF (p_check_id_flag = 'A') THEN
710  /******************************************************
711  * The Check_id_flag of 'A' indicates that this validation is
712  * coming from Java front end, and hence the id and Name combination
713  * needs to be validated in the database.
714  * ****************************************************/
715           IF (p_person_name IS NULL) THEN
716                -- Return a null ID since the name is
717                x_person_id := NULL;
718                l_person_id := NULL;
719            ELSE
720                 OPEN c_ids;
721                   LOOP
722                     FETCH c_ids INTO l_current_id;
723                     EXIT WHEN c_ids%NOTFOUND;
724                       IF (l_current_id = p_person_id) THEN
725                                l_person_id := p_person_id;
726                                x_person_id := l_person_id;
727                        END IF;
728                    END LOOP;
729                    l_num_ids := c_ids%ROWCOUNT;
730                  CLOSE c_ids;
731 
732                  IF (l_num_ids = 0) THEN
733                      -- No IDs for name
734                      RAISE NO_DATA_FOUND;
735                  ELSIF (l_num_ids = 1) THEN
736                       -- Since there is only one ID for the name use it.
737                       l_person_id := l_current_id;
738                       x_person_id := l_person_id;
739                  ELSIF (l_num_ids > 1) THEN
740                       --More than one ID for the Name
741                       RAISE TOO_MANY_ROWS;
742                   END IF;
743             END IF;
744     ELSE
745 	l_person_id := NULL;
746         x_person_id := l_person_id;
747     END IF;
748 ELSE
749      IF (p_person_name IS NOT NULL) THEN
750        	 BEGIN
751              SELECT person_id
752              INTO l_person_id
753              FROM per_people_x
754              WHERE full_name = p_person_name;
755              x_person_id := l_person_id;
756           EXCEPTION
757           WHEN OTHERS THEN
758               x_person_id := NULL;
759               x_return_status:= FND_API.G_RET_STS_ERROR;
760  	           --Need to get a proper message
761               x_error_msg_code:= 'PA_INVALID_PERSON_NAME';
762               Return;
763 	    END;
764       ELSE
765           l_person_id := NULL;
766           x_person_id := l_person_id;
767       END IF;
768 END IF;
769 /***************************************************
770  * This Select has been moved from the Main Body to this
771  * Procedure. As any other Prog's calling the Check_
772  * PersonName_or_id check would need this cond to be present.
773  * *****************************************************/
774 /******************************************************
775  * Bug - 3523947
776  * Desc - Modified the below select. We no longer need the
777  *        check where sysdate between effective start and
778  *        end date.
779  *****************************************************/
780      BEGIN
781          SELECT person_id
782          INTO x_person_id
783          FROM per_all_people_f per
784          WHERE
785          --sysdate BETWEEN effective_start_date AND effective_end_date
786          (current_employee_flag = 'Y' or CURRENT_NPW_FLAG = 'Y')
787          AND   ((PA_CROSS_BUSINESS_GRP.IsCrossBGProfile = 'Y') OR
788                ((PA_CROSS_BUSINESS_GRP.IsCrossBGProfile = 'N') AND
789                  fnd_profile.value('PER_BUSINESS_GROUP_ID') =
790                  BUSINESS_GROUP_ID))
791          AND person_id = l_person_id
792          and rownum = 1;
793      EXCEPTION
794      WHEN OTHERS THEN
795           x_return_status := FND_API.G_RET_STS_ERROR;
796           --Need to get message for this.
797           x_error_msg_code:= 'PA_INVALID_PERSON_ID';
798           PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
799                                Pa_Planning_Resource_Pvt.g_token);
800           Return;
801      END;
802 
803         x_return_status:= FND_API.G_RET_STS_SUCCESS;
804 
805 EXCEPTION
806    WHEN OTHERS THEN
807          x_person_id := NULL;
808          x_return_status:= FND_API.G_RET_STS_ERROR;
809           --Need to get a proper message
810          x_error_msg_code:= 'PA_INVALID_PERSON_ID';
811          Return;
812 END Check_PersonName_Or_Id;
813 /***************************/
814 
815 /*******************************
816  *  * Procedure : Check_JobName_or_ID
817  *  * Description  : Used to validate the Job ID
818  *  *                Name combination. -- NOT USED ANYMORE
819  *  *******************************************/
820 PROCEDURE  Check_JobName_or_ID(
821                p_job_id  IN   VARCHAR2,
822                p_job_name  IN   VARCHAR2,
823                p_check_id_flag  IN   VARCHAR2,
824                x_job_id      OUT NOCOPY  NUMBER,
825                x_return_status  OUT NOCOPY  VARCHAR2,
826                x_error_msg_code OUT NOCOPY  VARCHAR2)
827 IS
828 BEGIN
829 NULL;
830 END Check_JobName_or_ID;
831 
832 /*******************************
833  * Procedure : Check_JG_JobName_or_ID
834  * Description  : Used to validate the Job ID
835  *                Name combination in the context of Job Group.
836  *******************************************/
837 PROCEDURE  Check_JG_JobName_or_ID(
838                p_job_id         IN   NUMBER,
839                p_job_name       IN   VARCHAR2,
840 	       p_job_group_id   IN   NUMBER,
841                p_check_id_flag  IN   VARCHAR2,
842                x_job_id         OUT NOCOPY  NUMBER,
843                x_return_status  OUT NOCOPY  VARCHAR2,
844                x_error_msg_code OUT NOCOPY  VARCHAR2)
845 IS
846  l_current_id     NUMBER   := NULL;
847  l_num_ids        NUMBER   := 0;
848 
849     Cursor c_ids IS
850     SELECT job_id
851     FROM per_jobs
852     WHERE name = p_job_name
853     AND job_group_id = p_job_group_id;
854 BEGIN
855     x_return_status:= FND_API.G_RET_STS_SUCCESS;
856 --4461039 : Added check for p_job_group_id
857 IF p_job_group_id IS NULL THEN
858 	x_job_id := NULL;
859         x_return_status:= FND_API.G_RET_STS_ERROR;
860         x_error_msg_code:= 'PA_PL_RES_INVALID_JOB_GROUP';
861         Return;
862 END IF;
863 
864 IF (p_job_id IS NOT NULL)
865 THEN
866     -- Added for bug 4025261 - need to ensure the given job_id is
867     -- in the job group even if check_id_flag is N.
868     IF (p_check_id_flag = 'Y' OR p_check_id_flag='N') THEN
869 	BEGIN
870        	    SELECT job_id
871 	    INTO x_job_id
872        	    FROM per_jobs
873 	    WHERE job_id = p_job_id
874             AND job_group_id = p_job_group_id;
875 	EXCEPTION
876 	WHEN OTHERS THEN
877              x_job_id := NULL;
878              x_return_status:= FND_API.G_RET_STS_ERROR;
879           	--Need to get a proper message
880              x_error_msg_code:= 'PA_INVALID_JOB_ID';
881               Return;
882          END;
883       -- ELSIF (p_check_id_flag='N') THEN
884             -- x_job_id := p_job_id;
885       ELSIF (p_check_id_flag = 'A') THEN
886       /******************************************************
887       * The Check_id_flag of 'A' indicates that this validation is
888       * coming from Java front end,
889       * and hence the Id and Name combination needs to be validated
890       * in the database.
891       *******************************************************/
892           IF (p_job_name IS NULL) THEN
893               -- Return a null ID since the name is
894               x_job_id := NULL;
895           ELSE
896             OPEN c_ids;
897                LOOP
898                   FETCH c_ids INTO l_current_id;
899                   EXIT WHEN c_ids%NOTFOUND;
900                     IF (l_current_id = p_job_id) THEN
901                          x_job_id := p_job_id;
902                      END IF;
903                 END LOOP;
904                 l_num_ids := c_ids%ROWCOUNT;
905             CLOSE c_ids;
906 
907             IF (l_num_ids = 0) THEN
908                 -- No IDs for name
909                 RAISE NO_DATA_FOUND;
910             ELSIF (l_num_ids = 1) THEN
911                    -- Since there is only one ID for the name use it.
912                    x_job_id := l_current_id;
913             ELSIF (l_num_ids > 1) THEN
914                    --More than one ID for the Name
915                     RAISE TOO_MANY_ROWS;
916             END IF;
917                               END IF;
918           ELSE
919 		x_job_id := NULL;
920 	  END IF;
921    ELSE
922        IF (p_job_name IS NOT NULL) THEN
923        	  BEGIN
924              SELECT job_id
925              INTO x_job_id
926              FROM per_jobs
927              WHERE name  = p_job_name
928              AND job_group_id = p_job_group_id;
929           EXCEPTION
930           WHEN OTHERS THEN
931                 x_job_id := NULL;
932                 x_return_status:= FND_API.G_RET_STS_ERROR;
933  	             --Need to get a proper message
934                 x_error_msg_code:= 'PA_INVALID_JOB_NAME';
935                 Return;
936 	    END;
937         ELSE
938              x_job_id := NULL;
939         END IF;
940 END IF;
941         x_return_status:= FND_API.G_RET_STS_SUCCESS;
942 
943 EXCEPTION
944        WHEN OTHERS THEN
945            x_job_id := NULL;
946            x_return_status:= FND_API.G_RET_STS_ERROR;
947            --Need to get a proper message
948            x_error_msg_code:= 'PA_INVALID_JOB';
949            Return;
950 END Check_JG_JobName_Or_Id;
951 /**********************************/
952 /********************************************
953  * Procedure : Check_BOM_EqLabor_or_ID
954  * Description : This Procedure can be called
955  *            when the res_type_code is 'BOM_LABOR'
956  *            or 'BOM_EQUIPMENT'(determined by the p_res_type_code)
957  *            It validates the p_bom_eqlabor_id and p_bom_eqlabor_name
958  *            and returns the x_bom_resource_id.
959 *******************************************/
960 PROCEDURE Check_BOM_EqLabor_or_ID
961               ( p_bom_eqlabor_id         IN       NUMBER
962               , p_bom_eqlabor_name       IN       VARCHAR2
963 	      , p_res_type_code	         IN       VARCHAR2
964               , p_check_id_flag          IN       VARCHAR2
965               , x_bom_resource_id        OUT NOCOPY      NUMBER
966               , x_return_status          OUT NOCOPY      VARCHAR2
967               , x_error_msg_code     OUT NOCOPY      VARCHAR2 )
968  IS
969    l_current_id                  NUMBER := NULL;
970    l_num_ids                     NUMBER := 0;
971    l_id_found_flag               VARCHAR(1) := 'N';
972    l_return_status 	         VARCHAR2(1);
973    l_error_msg_data              fnd_new_messages.message_name%TYPE;
974 
975 CURSOR c_ids IS
976 SELECT b.resource_id
977 FROM bom_resources b
978 WHERE b.resource_type = p_res_type_code
979 and NVL(b.disable_date,SYSDATE) >= SYSDATE
980 and b.expenditure_type is NOT NULL
981 and b.resource_code = p_bom_eqlabor_name;
982 
983 BEGIN
984   x_return_status:= FND_API.G_RET_STS_SUCCESS;
985 
986 
987  IF(p_bom_eqlabor_id IS NOT NULL)
988   THEN
989 
990 	IF (p_check_id_flag = 'Y') THEN
991 
992 	     BEGIN
993 	     	SELECT b.resource_id
994 		INTO x_bom_resource_id
995                 FROM bom_resources b
996                 WHERE b.resource_type = p_res_type_code
997                 AND nvl(b.disable_date,SYSDATE) >= SYSDATE
998                 AND b.expenditure_type IS NOT NULL
999                 AND b.resource_id = p_bom_eqlabor_id;
1000 
1001 	     EXCEPTION
1002 	     WHEN OTHERS THEN
1003 
1004                  x_bom_resource_id := NULL;
1005                  x_return_status:= FND_API.G_RET_STS_ERROR;
1006 	         --Need to get a proper message
1007                  x_error_msg_code:= 'PA_INVALID_BOM_ID';
1008                 -- RAISE; --commented for bug 3947006
1009 		Return ;
1010               END;
1011   ELSIF (p_check_id_flag='N') THEN
1012 
1013             x_bom_resource_id := p_bom_eqlabor_id;
1014   ELSIF (p_check_id_flag = 'A') THEN
1015 
1016 /*********************************************************
1017  * The Check_id_flag of 'A' indicates that this validation is
1018  * coming from Java front end and hence the ID and name combination
1019  * needs to be validated in the database.
1020  * *************************************************/
1021 
1022       IF (p_bom_eqlabor_name IS NULL) THEN
1023            -- Return a null ID since the name is null.
1024           x_bom_resource_id := NULL;
1025       ELSE
1026            OPEN c_ids;
1027              LOOP
1028                 FETCH c_ids INTO l_current_id;
1029                 EXIT WHEN c_ids%NOTFOUND;
1030                 IF (l_current_id = p_bom_eqlabor_id) THEN
1031                        l_id_found_flag := 'Y';
1032                        x_bom_resource_id := p_bom_eqlabor_id;
1033                  END IF;
1034                END LOOP;
1035 	              l_num_ids := c_ids%ROWCOUNT;
1036            CLOSE c_ids;
1037 
1038            IF (l_num_ids = 0) THEN
1039                 -- No IDs for name
1040                 RAISE NO_DATA_FOUND;
1041            ELSIF (l_num_ids = 1) THEN
1042                  -- Since there is only one ID for the name use it.
1043                  x_bom_resource_id := l_current_id;
1044            ELSIF (l_num_ids > 1) THEN
1045                  --More than one ID for Name
1046                  RAISE TOO_MANY_ROWS;
1047             END IF;
1048       END IF;
1049     ELSE
1050  	  x_bom_resource_id := NULL;
1051     END IF;
1052 ELSE
1053 
1054     IF (p_bom_eqlabor_name  IS NOT NULL) THEN
1055 
1056   	BEGIN
1057 	   SELECT b.resource_id
1058            INTO x_bom_resource_id
1059            FROM bom_resources b
1060            WHERE b.resource_type = p_res_type_code --2
1061            AND NVL(b.disable_date,SYSDATE) >= SYSDATE
1062            AND b.expenditure_type IS NOT NULL
1063            AND b.resource_code = p_bom_eqlabor_name;
1064          EXCEPTION
1065          WHEN OTHERS THEN
1066               x_bom_resource_id := NULL;
1067               x_return_status:= FND_API.G_RET_STS_ERROR;
1068  	      --Need to get a proper message
1069               x_error_msg_code:= 'PA_INVALID_BOM_NAME';
1070               --RAISE; --commented for bug 3817916
1071               Return;--Added for bug 3817916
1072 	END;
1073      ELSE
1074           x_bom_resource_id := NULL;
1075      END IF;
1076 END IF;
1077         x_return_status:= FND_API.G_RET_STS_SUCCESS;
1078 EXCEPTION
1079        WHEN OTHERS THEN
1080          x_bom_resource_id := NULL;
1081          x_return_status:= FND_API.G_RET_STS_ERROR;
1082           --Need to get a proper message
1083          x_error_msg_code:= 'PA_INVALID_BOM_ID';
1084                        RAISE;
1085 END Check_BOM_EqLabor_or_ID;
1086 /*******************************/
1087 /********************************************
1088  * Procedure   : Check_ItemCat_or_ID
1089  * Description : This Procedure can be called
1090  *            when the res_type_code is 'ITEM_CATEGORY'
1091  *            It validates the p_item_cat_id and p_item_cat_name
1092  *            and returns the x_item_category_id.
1093 *******************************************/
1094 PROCEDURE Check_ItemCat_or_ID
1095           ( p_item_cat_id               IN        NUMBER
1096            ,p_item_cat_name             IN        VARCHAR2
1097            , P_item_category_set_id 	IN        NUMBER
1098            , p_check_id_flag            IN        VARCHAR2
1099            , x_item_category_id         OUT NOCOPY       NUMBER
1100            , x_return_status            OUT NOCOPY       VARCHAR2
1101            , x_error_msg_code       OUT NOCOPY       VARCHAR2 )
1102  IS
1103    l_current_id              NUMBER := NULL;
1104    l_num_ids                 NUMBER := 0;
1105    l_id_found_flag           VARCHAR(1) := 'N';
1106    l_return_status 	     VARCHAR2(1);
1107    l_error_msg_data          fnd_new_messages.message_name%TYPE;
1108 
1109 CURSOR c_ids IS
1110 SELECT c.category_id
1111 FROM mtl_categories_b c, mtl_category_set_valid_cats I
1112 WHERE i.category_set_id = p_item_category_set_id
1113 AND i.category_id = c.category_id
1114 AND nvl(c.disable_date,sysdate) >= sysdate
1115 AND fnd_Flex_ext.GET_SEGS('INV', 'MCAT', c.structure_id, c.category_id) =
1116     p_item_cat_name;
1117 --AND c.description = p_item_cat_name;
1118 
1119 BEGIN
1120         x_return_status:= FND_API.G_RET_STS_SUCCESS;
1121 IF (p_item_cat_id IS NOT NULL)
1122 THEN
1123    IF (p_check_id_flag = 'Y') THEN
1124 	BEGIN
1125             SELECT c.category_id
1126             INTO x_item_category_id
1127             FROM mtl_categories_b c, mtl_category_set_valid_cats I
1128             WHERE i.category_set_id = p_item_category_set_id
1129             AND i.category_id = c.category_id
1130             AND NVL(c.disable_date,sysdate) >= sysdate
1131             AND c.category_id = p_item_cat_id;
1132 
1133 	EXCEPTION
1134 	WHEN OTHERS THEN
1135               x_item_category_id := NULL;
1136               x_return_status:= FND_API.G_RET_STS_ERROR;
1137       	      --Need to get a proper message
1138               x_error_msg_code:= 'PA_INVALID_ITEM_CAT_ID';
1139               RAISE;
1140         END;
1141    ELSIF (p_check_id_flag='N') THEN
1142        x_item_category_id := p_item_cat_id;
1143    ELSIF (p_check_id_flag = 'A') THEN
1144     /***********************************************************
1145     *   The Check_id_flag of 'A' indicates that this validation is
1146     *   coming from Java front end,
1147     *   and hence the Id and Name combination needs to be validated
1148     *   in the database.
1149    *********************************************************/
1150         IF (p_item_cat_name IS NULL) THEN
1151              -- Return a null ID since the name is null.
1152      	     x_item_category_id := NULL;
1153         ELSE
1154              OPEN c_ids;
1155                LOOP
1156                  FETCH c_ids INTO l_current_id;
1157                  EXIT WHEN c_ids%NOTFOUND;
1158                  IF (l_current_id = p_item_cat_id) THEN
1159                       l_id_found_flag := 'Y';
1160                       x_item_category_id := p_item_cat_id;
1161                   END IF;
1162                END LOOP;
1163                l_num_ids := c_ids%ROWCOUNT;
1164              CLOSE c_ids;
1165              IF (l_num_ids = 0) THEN
1166                   -- No IDs for name
1167                   RAISE NO_DATA_FOUND;
1168              ELSIF (l_num_ids = 1) THEN
1169                   -- Since there is only one ID for the name use it.
1170                   x_item_category_id := l_current_id;
1171              ELSIF (l_num_ids > 1) THEN
1172                   --More than one ID for the Name
1173                   RAISE TOO_MANY_ROWS;
1174              END IF;
1175         END IF;
1176   ELSE
1177       x_item_category_id := NULL;
1178   END IF;
1179 ELSE
1180     IF (p_item_cat_name  IS NOT NULL) THEN
1181     	BEGIN
1182        	   SELECT c.category_id
1183             INTO x_item_category_id
1184             FROM mtl_categories_b c, mtl_category_set_valid_cats I
1185             WHERE i.category_set_id = p_item_category_set_id
1186             AND i.category_id = c.category_id
1187             AND nvl(c.disable_date,sysdate) >= sysdate
1188             AND fnd_Flex_ext.GET_SEGS('INV', 'MCAT', c.structure_id, c.category_id) = p_item_cat_name;
1189             -- AND c.description = p_item_cat_name;
1190       EXCEPTION
1191       WHEN OTHERS THEN
1192               x_item_category_id := NULL;
1193               x_return_status:= FND_API.G_RET_STS_ERROR;
1194       	      --Need to get a proper message
1195               x_error_msg_code:= 'PA_INVALID_ITEM_CAT_NAME';
1196               Return;
1197    	  END;
1198     ELSE
1199           x_item_category_id := NULL;
1200      END IF;
1201 END IF;
1202 EXCEPTION
1203 WHEN OTHERS THEN
1204     x_item_category_id := NULL;
1205     x_return_status:= FND_API.G_RET_STS_ERROR;
1206     --Need to get a proper message
1207     x_error_msg_code:= 'PA_INVALID_ITEM_CAT_ID';
1208     Return;
1209 END Check_ItemCat_or_ID;
1210 /********************************/
1211 /********************************************
1212  * Procedure   : Check_InventoryItem_or_ID
1213  * Description : This Procedure can be called
1214  *            when the res_type_code is 'INVENTORY_ITEM'
1215  *            It validates the p_item_id and p_item_name
1216  *            and returns the x_item_id.
1217 *******************************************/
1218 PROCEDURE Check_InventoryItem_or_ID
1219           (  p_item_id                 IN        NUMBER
1220            , p_item_name               IN        VARCHAR2
1221            , P_item_master_id 	       IN        NUMBER
1222            , p_check_id_flag           IN        VARCHAR2
1223            , x_item_id                 OUT NOCOPY       NUMBER
1224            , x_return_status           OUT NOCOPY       VARCHAR2
1225            , x_error_msg_code          OUT NOCOPY       VARCHAR2 )
1226  IS
1227    l_current_id              NUMBER := NULL;
1228    l_num_ids                 NUMBER := 0;
1229    l_id_found_flag           VARCHAR(1) := 'N';
1230    l_return_status 	     VARCHAR2(1);
1231    l_error_msg_data          fnd_new_messages.message_name%TYPE;
1232 
1233 /********************************************
1234  * Bug - 3566965
1235  * Desc - Modified the cursor to select based on
1236  *        the segment1 field instead of the
1237  *        description field. Also we dont need a join
1238  *        with the MTL_SYSTEM_ITEMS_tl table.
1239  *******************************************/
1240 CURSOR c_ids IS
1241   SELECT b.INVENTORY_ITEM_ID
1242   FROM MTL_SYSTEM_ITEMS_b b
1243   WHERE b.organization_id = p_item_master_id
1244   AND b.ENABLED_FLAG = 'Y'
1245   --AND b.INVENTORY_ITEM_ID = t.INVENTORY_ITEM_ID
1246   --AND b.organization_id = t.organization_id
1247   --AND t.language = userenv('LANG')
1248   AND b.segment1 = p_item_name;
1249 
1250 BEGIN
1251         x_return_status:= FND_API.G_RET_STS_SUCCESS;
1252 IF (p_item_id IS NOT NULL)
1253 THEN
1254    IF (p_check_id_flag = 'Y') THEN
1255 	BEGIN
1256            /********************************************
1257             * Bug - 3566965
1258             * Desc - Modified the below select. We dont need
1259             *        a join to the mtl_system_items_tl
1260             *        table.
1261             *******************************************/
1262             SELECT b.INVENTORY_ITEM_ID
1263             INTO x_item_id
1264             FROM MTL_SYSTEM_ITEMS_b b
1265             WHERE b.organization_id = p_item_master_id
1266             AND b.ENABLED_FLAG = 'Y'
1267             --AND b.INVENTORY_ITEM_ID = t.INVENTORY_ITEM_ID
1268             --AND b.organization_id = t.organization_id
1269             --AND t.language = userenv('LANG')
1270             AND b.inventory_item_id = p_item_id;
1271 	EXCEPTION
1272 	WHEN OTHERS THEN
1273               x_item_id := NULL;
1274               x_return_status:= FND_API.G_RET_STS_ERROR;
1275       	      --Need to get a proper message
1276               x_error_msg_code:= 'PA_INVALID_INV_ID';
1277               RAISE;
1278         END;
1279    ELSIF (p_check_id_flag='N') THEN
1280        x_item_id := p_item_id;
1281    ELSIF (p_check_id_flag = 'A') THEN
1282     /***********************************************************
1283     *   The Check_id_flag of 'A' indicates that this validation is
1284     *   coming from Java front end,
1285     *   and hence the Id and Name combination needs to be validated
1286     *   in the database.
1287    *********************************************************/
1288         IF (p_item_name IS NULL) THEN
1289              -- Return a null ID since the name is null.
1290      	     x_item_id := NULL;
1291         ELSE
1292              OPEN c_ids;
1293                LOOP
1294                  FETCH c_ids INTO l_current_id;
1295                  EXIT WHEN c_ids%NOTFOUND;
1296                  IF (l_current_id = p_item_id) THEN
1297                       l_id_found_flag := 'Y';
1298                       x_item_id := p_item_id;
1299                   END IF;
1300                END LOOP;
1301                l_num_ids := c_ids%ROWCOUNT;
1302              CLOSE c_ids;
1303              IF (l_num_ids = 0) THEN
1304                   -- No IDs for name
1305                   RAISE NO_DATA_FOUND;
1306              ELSIF (l_num_ids = 1) THEN
1307                   -- Since there is only one ID for the name use it.
1308                   x_item_id := l_current_id;
1309              ELSIF (l_num_ids > 1) THEN
1310                   --More than one ID for the Name
1311                   RAISE TOO_MANY_ROWS;
1312              END IF;
1313         END IF;
1314   ELSE
1315       x_item_id := NULL;
1316   END IF;
1317 ELSE
1318     IF (p_item_name  IS NOT NULL) THEN
1319     	BEGIN
1320         /********************************************
1321          * Bug - 3566965
1322          * Desc - Modified the below select to be based on
1323          *        the segment1 field instead of the
1324          *        description field. Also we dont need a join
1325          *        with the MTL_SYSTEM_ITEMS_tl table.
1326          *******************************************/
1327             SELECT b.INVENTORY_ITEM_ID
1328             INTO x_item_id
1329             FROM MTL_SYSTEM_ITEMS_b b
1330             WHERE b.organization_id = p_item_master_id
1331             AND b.ENABLED_FLAG = 'Y'
1332             --AND b.INVENTORY_ITEM_ID = t.INVENTORY_ITEM_ID
1333             --AND b.organization_id = t.organization_id
1334             --AND t.language = userenv('LANG')
1335             AND b.segment1 = p_item_name;
1336       EXCEPTION
1337       WHEN OTHERS THEN
1338               x_item_id := NULL;
1339               x_return_status:= FND_API.G_RET_STS_ERROR;
1340       	      --Need to get a proper message
1341               x_error_msg_code:= 'PA_INVALID_INV_NAME';
1342               Return;
1343    	  END;
1344     ELSE
1345           x_item_id := NULL;
1346      END IF;
1347 END IF;
1348 EXCEPTION
1349 WHEN OTHERS THEN
1350     x_item_id := NULL;
1351     x_return_status:= FND_API.G_RET_STS_ERROR;
1352     --Need to get a proper message
1353     x_error_msg_code:= 'PA_INVALID_INV_ID';
1354     Return;
1355 END Check_InventoryItem_or_Id;
1356 /******************************************************************
1357 * Procedure : Validate_Resource
1358  * Description :The purpose of this procedure is to validate the resource
1359  *              per resource class.
1360  *              The IN Parameters to the procedure are:
1361  *              p_resource_code,p_resource_name,p_resource_class_code,
1362  *              p_res_type_code.
1363  *              The OUT Parameters are :
1364  *              x_person_id,x_bom_resource_id,x_job_id,x_person_type_code,
1365  *              x_non_labor_resource,x_inventory_item_id,x_item_category_id,
1366  *              x_resource_class_code,x_resource_class_flag,x_return_status,
1367  *              x_error_message_code.
1368  **********************************************************************/
1369 
1370 PROCEDURE Validate_Resource(
1371         p_resource_code		    IN	VARCHAR2	DEFAULT NULL,
1372         p_resource_name		    IN	VARCHAR2	DEFAULT NULL,
1373         p_resource_class_code	 IN	VARCHAR2,
1374         p_res_type_code		    IN	VARCHAR2	DEFAULT NULL,
1375         x_person_id		       OUT NOCOPY	NUMBER,
1376         x_bom_resource_id	    OUT NOCOPY	NUMBER,
1377         x_job_id		          OUT NOCOPY	NUMBER,
1378         x_person_type_code	    OUT NOCOPY	VARCHAR2,
1379         x_non_labor_resource	 OUT NOCOPY	VARCHAR2,
1380         x_inventory_item_id	 OUT NOCOPY	NUMBER,
1381         x_item_category_id	    OUT NOCOPY	NUMBER,
1382         x_resource_class_code	 OUT NOCOPY	VARCHAR2,
1383         x_resource_class_flag	 OUT NOCOPY	VARCHAR2,
1384         x_return_status		    OUT NOCOPY	VARCHAR2,
1385         x_error_msg_code	    OUT NOCOPY	VARCHAR2)
1386 
1387 IS
1388 --Declaration of Local Variabled
1389 l_job_id         NUMBER;
1390 l_person_id      NUMBER;
1391 l_bom_resource_id NUMBER;
1392 l_return_status  VARCHAR2(30);
1393 l_error_msg_code VARCHAR2(30);
1394 l_item_category_set_id NUMBER;
1395 l_item_master_id  NUMBER;
1396 l_item_category_id NUMBER;
1397 l_inventory_item_id NUMBER;
1398 /*********************************************
1399  * Subfunction : Check_Res_Null
1400  * Description : The Purpose of this function is to verify
1401  *               For Null condition in the fields
1402  *               p_resource_code,p_resource_name,
1403  *               p_resource_class_code and p_res_type_code
1404  *               If the condition fails 'Y' is returned
1405  *               else the value remains as 'N'.
1406  *************************************************/
1407 FUNCTION Check_Res_Null(
1408         p_resource_code         IN      VARCHAR2        DEFAULT NULL,
1409         p_resource_name         IN      VARCHAR2        DEFAULT NULL,
1410         p_resource_class_code   IN      VARCHAR2,
1411         p_res_type_code         IN      VARCHAR2        DEFAULT NULL)
1412 RETURN VARCHAR2
1413 IS
1414        l_check_null_flag     VARCHAR2(30) := 'N';
1415 BEGIN
1416        IF p_res_type_code IS  NULL THEN
1417 		l_check_null_flag := 'Y';
1418 	END IF;
1419 	IF p_resource_class_code IS NULL THEN
1420 		l_check_null_flag := 'Y';
1421 	END IF;
1422 	IF (p_resource_code IS NULL AND p_resource_name IS NULL)
1423 	THEN
1424 		l_check_null_flag := 'Y';
1425 	END IF;
1426 	Return l_Check_Null_Flag;
1427 END Check_Res_Null;
1428 /************************************/
1429 
1430 /*********************************************
1431  * Subfunction : Match_classcode_Type
1432  * Description : The Purpose of this function is to verify
1433  *               that the p_res_type_code is a valid resource type
1434  *               in the given p_resource_class_code.
1435  *               It will return 'N' if it is not valid
1436  *               and 'Y' otherwise.
1437 *******************************************************/
1438 Function Match_classcode_Type(
1439                            p_resource_class_code IN VARCHAR2,
1440                            p_res_type_code       IN VARCHAR2)
1441 RETURN VARCHAR2
1442 IS
1443    l_check_match_flag    VARCHAR2(30) := 'Y';
1444 BEGIN
1445 /*********************************************************
1446  * Outer IF to validate that the resource_class_code passed
1447  * is a valid resource_class_code. If not it would go to
1448  * the Else.
1449  * ********************************************************/
1450 IF p_resource_class_code IN ('PEOPLE','EQUIPMENT','MATERIAL_ITEMS',
1451                             'FINANCIAL_ELEMENTS')
1452 THEN
1453    IF p_resource_class_code = 'PEOPLE'
1454    THEN
1455    /********************************************************
1456     * IF p_resource_class_code = 'PEOPLE'
1457     * then the res_type_code should be one of
1458     * 'NAMED_PERSON','BOM_LABOR','NAMED_ROLE',
1459     * 'JOB','PERSON_TYPE','RESOURCE_CLASS'
1460     ************************************************************/
1461        IF p_res_type_code IN ('NAMED_PERSON','BOM_LABOR','NAMED_ROLE',
1462                          'JOB','PERSON_TYPE','RESOURCE_CLASS')
1463        THEN
1464            l_check_match_flag := 'Y';
1465        ELSE
1466            l_check_match_flag := 'N';
1467        END IF;
1468 
1469    ELSIF p_resource_class_code = 'EQUIPMENT'
1470    THEN
1471    /********************************************************
1472     * IF p_resource_class_code = 'EQUIPMENT'
1473     * then the res_type_code should be one of
1474     * 'NON_LABOR_RESOURCE','BOM_EQUIPMENT',
1475     * 'RESOURCE_CLASS'
1476     ************************************************************/
1477         IF p_res_type_code IN ('NON_LABOR_RESOURCE','BOM_EQUIPMENT',
1478                         'RESOURCE_CLASS')
1479         THEN
1480              l_check_match_flag := 'Y';
1481         ELSE
1482              l_check_match_flag := 'N';
1483         END IF;
1484 
1485    ELSIF p_resource_class_code = 'MATERIAL_ITEMS'
1486    THEN
1487    /********************************************************
1488     * IF p_resource_class_code = 'MATERIAL_ITEMS'
1489     * then the res_type_code should be one of
1490     * 'INVENTORY_ITEM',
1491     * 'ITEM_CATEGORY','RESOURCE_CLASS'
1492     ************************************************************/
1493         IF p_res_type_code IN ('INVENTORY_ITEM',
1494                              'ITEM_CATEGORY','RESOURCE_CLASS')
1495         THEN
1496              l_check_match_flag := 'Y';
1497         ELSE
1498              l_check_match_flag := 'N';
1499         END IF;
1500 
1501     ELSIF p_resource_class_code = 'FINANCIAL_ELEMENTS' THEN
1502         IF p_res_type_code IN ('RESOURCE_CLASS')
1503         THEN
1504              l_check_match_flag := 'Y';
1505         ELSE
1506              l_check_match_flag := 'N';
1507         END IF;
1508 
1509     END IF;
1510 ELSE
1511 /*******************************************
1512  * If the resource_class_code is not Valid.
1513  * *****************************************/
1514        l_check_match_flag := 'N';
1515 END IF;
1516   Return l_Check_Match_Flag;
1517 END Match_classcode_Type;
1518 /*************************/
1519 
1520 /*************************
1521  *    Main Body          *
1522  ************************/
1523 BEGIN
1524 -- hr_utility.trace('Start Validate_Resource');
1525        x_return_status:= FND_API.G_RET_STS_SUCCESS;
1526               x_resource_class_flag := 'N';
1527 /* Call to the Function check_null_flag to check for the null conditions*/
1528 
1529  IF Check_Res_Null(p_resource_code,p_resource_name,
1530                   p_resource_class_code,p_res_type_code) = 'Y'
1531  THEN
1532     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1533     Return;
1534  ELSE
1535 
1536    IF Match_classcode_Type(p_resource_class_code,p_res_type_code) = 'N'
1537    THEN
1538        x_return_status := FND_API.G_RET_STS_ERROR;
1539        --Need to get message for this.
1540        x_error_msg_code:= 'PA_RESOURCE_NO_MATCH';
1541        PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
1542                             Pa_Planning_Resource_Pvt.g_token);
1543    ELSE
1544 
1545        IF p_res_type_code = 'RESOURCE_CLASS' THEN
1546           IF p_resource_code = p_resource_class_code THEN
1547               x_resource_class_code := p_resource_class_code;
1548               x_resource_class_flag := 'Y';
1549           ELSE
1550               x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1551               Return;
1552            END IF;
1553        ELSIF p_res_type_code = 'PERSON_TYPE' THEN
1554            BEGIN
1555                SELECT lookup_code
1556                INTO x_person_type_code
1557                FROM pa_lookups
1558                WHERE lookup_type = 'PA_PERSON_TYPE'
1559                AND lookup_code = p_resource_code;
1560            EXCEPTION
1561            WHEN OTHERS THEN
1562               x_return_status := FND_API.G_RET_STS_ERROR;
1563               --Need to get message for this.
1564               x_error_msg_code:= 'PA_PERSON_TYPE_CODE_INVALID';
1565               PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
1566                                    Pa_Planning_Resource_Pvt.g_token);
1567            END;
1568        ELSIF p_res_type_code = 'NON_LABOR_RESOURCE' THEN
1569            BEGIN
1570                SELECT non_labor_resource
1571                INTO x_non_labor_resource
1572                FROM pa_non_labor_resources
1573                WHERE non_labor_resource = p_resource_name;
1574            EXCEPTION
1575            WHEN OTHERS THEN
1576               x_return_status := FND_API.G_RET_STS_ERROR;
1577               --Need to get message for this.
1578               x_error_msg_code:= 'PA_NON_LABOR_CODE_INVALID';
1579               PA_UTILS.Add_Message('PA', x_error_msg_code, 'PLAN_RES',
1580                                    Pa_Planning_Resource_Pvt.g_token);
1581            END;
1582        ELSIF p_res_type_code = 'NAMED_PERSON' THEN
1583 
1584                 pa_planning_resource_utils.Check_PersonName_or_ID(
1585                 p_person_id     => p_resource_code,
1586                 p_person_name     => p_resource_name,
1587                 p_check_id_flag     => PA_STARTUP.G_Check_ID_Flag,
1588                 x_person_id         => l_person_id,
1589                 x_return_status     => l_return_status,
1590                 x_error_msg_code    => l_error_msg_code);
1591 
1592               x_person_id        := l_person_id;
1593               x_return_status    := l_return_status;
1594               x_error_msg_code   := l_error_msg_code;
1595 
1596               IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1597                  PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
1598                                       Pa_Planning_Resource_Pvt.g_token);
1599                  Return;
1600              END IF;
1601   /***************************************
1602  * Rest of code goes here all the ELSIF
1603  * ***************************************/
1604        ELSIF p_res_type_code = 'JOB' THEN
1605 
1606 -- hr_utility.trace('p_res_type_code IS : ' || p_res_type_code);
1607 -- hr_utility.trace('Before Check_JG_JobName_or_ID');
1608 -- hr_utility.trace('p_resource_code IS : ' || p_resource_code);
1609 -- hr_utility.trace('p_resource_name IS : ' || p_resource_name);
1610 -- hr_utility.trace('g_job_group_id IS : ' || g_job_group_id);
1611 -- hr_utility.trace('PA_STARTUP.G_Check_ID_Flag IS : ' || PA_STARTUP.G_Check_ID_Flag);
1612              Check_JG_JobName_or_ID(
1613                 P_job_id          => p_resource_code,
1614                 p_job_name        => p_resource_name,
1615                 p_job_group_id    => g_job_group_id,
1616                 p_check_id_flag   => PA_STARTUP.G_Check_ID_Flag,
1617                 x_job_id          => l_job_id,
1618                 x_return_status   => l_return_status,
1619                 x_error_msg_code  => l_error_msg_code);
1620 
1621                 x_job_id          :=  l_job_id;
1622                 x_return_status   :=  l_return_status;
1623                 x_error_msg_code  :=  l_error_msg_code;
1624 
1625 -- hr_utility.trace('after Check_JG_JobName_or_ID');
1626 -- hr_utility.trace('x_return_status IS : ' || x_return_status);
1627 -- hr_utility.trace('x_error_msg_code IS : ' || x_error_msg_code);
1628 -- hr_utility.trace('x_job_id IS : ' || x_job_id);
1629              IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1630                  PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
1631                                       Pa_Planning_Resource_Pvt.g_token);
1632                  Return;
1633              END IF;
1634        ELSIF p_res_type_code = 'BOM_LABOR' THEN
1635 
1636            pa_planning_resource_utils.Check_BOM_EqLabor_or_ID(
1637            p_bom_eqlabor_id       => p_resource_code,
1638            p_bom_eqlabor_name     => p_resource_name,
1639            p_res_type_code        => 2,
1640            p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag,
1641            x_bom_resource_id      => l_bom_resource_id,
1642            x_return_status        => l_return_status,
1643            x_error_msg_code       => l_error_msg_code);
1644 
1645 
1646           x_bom_resource_id := l_bom_resource_id;
1647           x_return_status   := l_return_status;
1648           x_error_msg_code  := l_error_msg_code;
1649 		--Added for bug 3947006
1650 	  IF x_return_status = Fnd_Api.G_Ret_Sts_Error THEN
1651 
1652               Return;
1653            END IF;
1654 
1655            IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1656               PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
1657                                    Pa_Planning_Resource_Pvt.g_token);
1658               Return;
1659            END IF;
1660        ELSIF p_res_type_code = 'BOM_EQUIPMENT' THEN
1661 
1662            pa_planning_resource_utils.Check_BOM_EqLabor_or_ID(
1663            p_bom_eqlabor_id       => p_resource_code,
1664            p_bom_eqlabor_name     => p_resource_name,
1665            p_res_type_code        => 1,
1666            p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag,
1667            x_bom_resource_id      => l_bom_resource_id,
1668            x_return_status        => l_return_status,
1669            x_error_msg_code       => l_error_msg_code);
1670 
1671            x_bom_resource_id := l_bom_resource_id;
1672            x_return_status   := l_return_status;
1673            x_error_msg_code  := l_error_msg_code;
1674 
1675            IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1676               PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
1677                                    Pa_Planning_Resource_Pvt.g_token);
1678               Return;
1679            END IF;
1680 
1681 ELSIF p_res_type_code = 'ITEM_CATEGORY' THEN
1682 
1683    BEGIN
1684 	SELECT def.item_category_set_id
1685 	INTO l_item_category_set_id
1686         FROM pa_plan_res_defaults def
1687            -- , pa_resource_classes_b cl
1688         WHERE def.resource_class_id = 3
1689         AND def.object_type ='CLASS';
1690         --AND cl.resource_class_id = def.resource_class_id
1691         --AND cl.resource_class_id = 3;
1692        --AND cl.resource_class_code = 'MATERIAL_ITEMS';
1693    EXCEPTION
1694    WHEN NO_DATA_FOUND THEN
1695        x_item_category_id := NULL;
1696        x_return_status:= FND_API.G_RET_STS_ERROR;
1697        --Need to get a proper message
1698        x_error_msg_code:= 'PA_NO_ITEM_CATEGORY_SET';
1699        Return;
1700    WHEN OTHERS THEN
1701        x_item_category_id := NULL;
1702        x_return_status:= FND_API.G_RET_STS_ERROR;
1703        --Need to get a proper message
1704        x_error_msg_code:= 'PA_NO_ITEM_CATEGORY_SET';
1705        Return;
1706    END;
1707 
1708      Pa_planning_resource_utils.Check_ItemCat_or_ID(
1709 	  P_item_cat_id          =>  p_resource_code,
1710           P_item_cat_name   	 =>  p_resource_name,
1711      	  P_item_category_set_id =>  l_item_category_set_id,
1712           P_check_id_flag        =>  PA_STARTUP.G_Check_ID_Flag,
1713           X_item_category_id     =>  l_item_category_id,
1714           X_return_status        =>  l_return_status,
1715           X_error_msg_code       =>  l_error_msg_code);
1716 
1717           x_item_category_id := l_item_category_id;
1718           x_return_status    := l_return_status;
1719           x_error_msg_code   := l_error_msg_code;
1720      IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1721            PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
1722                                 Pa_Planning_Resource_Pvt.g_token);
1723      END IF;
1724 ELSIF p_res_type_code = 'INVENTORY_ITEM' THEN
1725    BEGIN
1726 	SELECT def.item_master_id
1727 	INTO l_item_master_id
1728         FROM pa_plan_res_defaults def
1729            -- , pa_resource_classes_b cl
1730         WHERE def.resource_class_id = 3
1731         AND def.object_type ='CLASS';
1732         --AND cl.resource_class_id = def.resource_class_id
1733         --AND cl.resource_class_id = 3;
1734         --AND cl.resource_class_code = 'MATERIAL_ITEMS';
1735    EXCEPTION
1736    WHEN NO_DATA_FOUND THEN
1737        x_inventory_item_id := NULL;
1738        x_return_status:= FND_API.G_RET_STS_ERROR;
1739        --Need to get a proper message
1740        x_error_msg_code:= 'PA_NO_MAT_ITEM_ID';
1741        Return;
1742    WHEN OTHERS THEN
1743        x_inventory_item_id := NULL;
1744        x_return_status:= FND_API.G_RET_STS_ERROR;
1745        --Need to get a proper message
1746        x_error_msg_code:= 'PA_NO_MAT_ITEM_ID';
1747        Return;
1748    END;
1749      Pa_planning_resource_utils.Check_InventoryItem_or_ID(
1750 	  P_item_id               =>  p_resource_code,
1751           P_item_name   	  =>  p_resource_name,
1752      	  P_item_master_id        =>  l_item_master_id,
1753           P_check_id_flag         =>  PA_STARTUP.G_Check_ID_Flag,
1754           X_item_id               =>  l_inventory_item_id,
1755           X_return_status         =>  l_return_status,
1756           X_error_msg_code        =>  l_error_msg_code);
1757 
1758           X_inventory_item_id   := l_inventory_item_id;
1759           x_return_status       := l_return_status;
1760           x_error_msg_code      := l_error_msg_code;
1761      IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1762            PA_UTILS.Add_Message('PA', l_error_msg_code, 'PLAN_RES',
1763                                 Pa_Planning_Resource_Pvt.g_token);
1764            Return;
1765      END IF;
1766 /******ELSIF*******/
1767    END IF;
1768 /*************/
1769   END IF;
1770 END IF;
1771 
1772 END Validate_Resource;
1773 /***************************************************/
1774 
1775 /*******************************************************
1776  * Procedure : Default_Expenditure_Type
1777  * 1. If Expenditure Type is available on the planning resource,
1778  *    leave as is.
1779  * 2. If Exp Type is null:
1780  *      i. Derive from BOM Resources, if the planning resource has one.
1781  *      ii. Derive from Non-Labor Resource, if the planning resource has one.
1782  *      iii. Derive from item if planning resource has one.
1783  *  We could pass back null for the Expenditure type for the planning resource,
1784  *  if none of the above yields a value.
1785  * *******************************************************/
1786  /**********************************************************
1787  * Bug - 3615477
1788  * Desc - In this proc we are going to be updating the value of
1789  *        res_temp.expenditure_type and the final update is not
1790  *        required while updating the expenditure_type value.
1791  *        Also in the where clause we are checking for
1792  *        res_temp.expenditure_type IS NULL
1793  **********************************************************/
1794 PROCEDURE Default_Expenditure_Type
1795 IS
1796 BEGIN
1797 
1798     /*************************************************
1799     * Update to use when the expenditure_type is null
1800     * and bom_resource_id is not null. We use the below
1801     * Update to set the value for expenditure_type
1802     * ************************************************/
1803     --Bug 3615477
1804     --Also updating the value of fc_res_type_code.
1805     --Bug 3628429
1806     --Join to the pa_expenditure_types table.
1807     -- Fixed bug 3962699 - Removed the setting of fc_res_type_code from
1808     -- all the below selects.  No need to set fc res type code - only
1809     -- need to set Exp Type.
1810      UPDATE pa_res_members_temp res_temp
1811      SET  res_temp.expenditure_type =
1812                             (SELECT exp.expenditure_type
1813                              FROM bom_resources bom, pa_expenditure_types exp
1814                              WHERE bom.resource_id = res_temp.bom_resource_id
1815                              AND   exp.expenditure_type = bom.expenditure_type
1816                              AND   exp.UNIT_OF_MEASURE = 'HOURS'
1817                              AND ROWNUM = 1)
1818      WHERE res_temp.expenditure_type IS NULL
1819      AND res_temp.bom_resource_id IS NOT NULL;
1820 
1821     /*************************************************
1822     * Update to use when the expenditure_type is null
1823     * and non_labor_resource is not null. We use the below
1824     * Update to set the value for expenditure_type
1825     *************************************************/
1826     --Bug 3615477
1827     --Also updating the value of fc_res_type_code.
1828      UPDATE pa_res_members_temp res_temp
1829      SET  res_temp.expenditure_type =
1830                            (SELECT n.expenditure_type
1831                               FROM pa_non_labor_resources n
1832                              WHERE n.non_labor_resource =
1833                                            res_temp.non_labor_resource
1834                              AND ROWNUM = 1)
1835      WHERE res_temp.expenditure_type IS NULL
1836      AND res_temp.non_labor_resource IS NOT NULL;
1837 
1838      -- Get the item's exp type if it exists
1839 
1840     --Bug 3615477
1841     --Also updating the value of fc_res_type_code.
1842      UPDATE pa_res_members_temp res_temp
1843      SET  res_temp.expenditure_type =
1844              PJM_COMMITMENT_UTILS.MTL_EXPENDITURE_TYPE(
1845                    res_temp.organization_id, res_temp.inventory_item_id)
1846      WHERE res_temp.organization_id IS NOT NULL
1847      AND res_temp.inventory_item_id IS NOT NULL
1848      AND res_temp.expenditure_type IS NULL;
1849 
1850 EXCEPTION
1851 WHEN OTHERS THEN
1852      RAISE;
1853 END Default_Expenditure_Type;
1854 /******************************************/
1855 /*******************************************************
1856  * Procedure : Default_Rate_Expenditure_Type
1857  *      i. Derive from BOM Resources, if the planning resource has one.
1858  *      ii. Derive from Non-Labor Resource, if the planning resource has one.
1859  *      iii. Derive from item if planning resource has one.
1860  *      iv. Derive from class
1861  *  We could pass back null for the Rate Expenditure type for the planning
1862  *  resource, if none of the above yields a value.
1863  * *******************************************************/
1864  /**********************************************************
1865  * Bug - 3615477
1866  * Desc - In this proc we are going to be updating the value of
1867  *        res_temp.rate_expenditure_type and the final update is
1868  *        required while updating the rate_expenditure_type value.
1869  *        Also in the where condition we are checking for
1870  *        res_temp.rate_expenditure_type IS NULL
1871  **********************************************************/
1872 PROCEDURE Default_Rate_Expenditure_Type
1873 IS
1874 BEGIN
1875     /*************************************************
1876     * Update to use when the rate_expenditure_type is null
1877     * and bom_resource_id is not null. We use the below
1878     * Update to set the value for rate_expenditure_type
1879     * ************************************************/
1880     --Bug 3628429
1881     --Join to the pa_expenditure_types table.
1882      UPDATE pa_res_members_temp res_temp
1883      SET  res_temp.rate_expenditure_type =
1884                             (SELECT exp.expenditure_type
1885                              FROM bom_resources bom,pa_expenditure_types exp
1886                              WHERE bom.resource_id = res_temp.bom_resource_id
1887                              AND   exp.expenditure_type = bom.expenditure_type
1888                              AND   exp.UNIT_OF_MEASURE = 'HOURS'
1889                              AND ROWNUM = 1)
1890      WHERE res_temp.rate_expenditure_type IS NULL
1891      AND res_temp.bom_resource_id IS NOT NULL;
1892     /*************************************************
1893     * Update to use when the rate_expenditure_type is null
1894     * and non_labor_resource is not null. We use the below
1895     * Update to set the value for rate_expenditure_type
1896     *************************************************/
1897      UPDATE pa_res_members_temp res_temp
1898      SET  res_temp.rate_expenditure_type =
1899                            (SELECT n.expenditure_type
1900                            FROM pa_non_labor_resources n
1901                             WHERE  n.non_labor_resource =
1902                                            res_temp.non_labor_resource
1903                              AND ROWNUM = 1)
1904      WHERE res_temp.rate_expenditure_type IS NULL
1905      AND res_temp.non_labor_resource IS NOT NULL;
1906 
1907      -- Get the item's exp type if it exists
1908 
1909      UPDATE pa_res_members_temp res_temp
1910      SET  res_temp.rate_expenditure_type =
1911              PJM_COMMITMENT_UTILS.MTL_EXPENDITURE_TYPE(
1912                    res_temp.organization_id, res_temp.inventory_item_id)
1913      WHERE res_temp.organization_id IS NOT NULL
1914      AND res_temp.inventory_item_id IS NOT NULL
1915      AND res_temp.rate_expenditure_type IS NULL;
1916 
1917     /**************************************************
1918     * Final Update which will default the value of
1919     * rate_expenditure_type based on the resource class id
1920     * **************************************************/
1921      UPDATE pa_res_members_temp res_temp
1922      SET  res_temp.rate_expenditure_type =
1923                              (SELECT expenditure_type
1924                                 FROM pa_plan_res_defaults
1925                                WHERE resource_class_id =
1926                                      res_temp.resource_class_id
1927                              AND ROWNUM = 1
1928                              AND object_type = 'CLASS')
1929      WHERE (res_temp.rate_expenditure_type IS NULL OR
1930            (res_temp.rate_expenditure_type = 'NO Val'))
1931      AND res_temp.resource_class_id IS NOT NULL;
1932 EXCEPTION
1933 WHEN OTHERS THEN
1934      RAISE;
1935 END Default_Rate_Expenditure_Type;
1936 /******************************************/
1937 
1938 /*********************************************************
1939 * Procedure : Default_OU
1940 * Description : To derive the default Org ID
1941 * First it will try to derive it from hr_organization_information
1942 * based on the organization_id.
1943 * If the Org_id is still null then we will get it based on the p_project_id
1944 * passed from pa_projects_all table.
1945 * ******************************************************/
1946 PROCEDURE default_ou(p_project_id IN PA_PROJECTS_ALL.PROJECT_ID%TYPE)
1947 IS
1948 l_proj_ou NUMBER;
1949 BEGIN
1950        UPDATE pa_res_members_temp res_temp
1951        SET org_id = (SELECT to_number(org_information1)
1952               FROM   hr_organization_information
1953               WHERE  org_information_context = 'Exp Organization Defaults'
1954               AND    organization_id         = res_temp.organization_id
1955               AND    rownum                  = 1)
1956        WHERE res_temp.organization_id IS NOT NULL
1957        AND res_temp.org_id IS NULL;
1958 
1959        BEGIN
1960        SELECT org_id
1961        INTO l_proj_ou
1962        FROM pa_projects_all
1963        WHERE project_id = p_project_id
1964        AND rownum     = 1;
1965 
1966        EXCEPTION WHEN NO_DATA_FOUND THEN
1967            l_proj_ou := NULL;
1968        END;
1969 
1970        UPDATE pa_res_members_temp res_temp
1971        SET org_id = l_proj_ou
1972        WHERE res_temp.org_id IS NULL;
1973 
1974 EXCEPTION
1975 WHEN OTHERS THEN
1976      RAISE;
1977 END default_ou;
1978 /************************************************/
1979 
1980 /*********************************************************
1981 * Procedure : Default_UOM
1982 * Description : To derive the Unit of Measure based on the
1983 * resource_class_code. Update the UOM in the table with the appr
1984 * value.
1985 * ******************************************************/
1986 PROCEDURE Default_UOM
1987 IS
1988 BEGIN
1989        /*********************************************************
1990        * If the resource_class code in the table is 'PEOPLE' or EQUIPMENT
1991        * Then by default the Unit of measure should only be 'HOURS'
1992        *************************************************************/
1993         UPDATE pa_res_members_temp res_temp
1994         SET unit_of_measure = 'HOURS'
1995         WHERE res_temp.resource_class_code IN ('PEOPLE', 'EQUIPMENT')
1996         AND res_temp.unit_of_measure IS NULL;
1997 
1998        /***********************************************************
1999        * If the resource class code is 'MATERIAL_ITEMS' and the
2000        * Inventory_item_id is not null then we need to derive the
2001        * Unit of measure from MTL_SYSTEM_ITEMS_b based on the inventory_item
2002        * And Organization id that matches the master_item_id in
2003        * pa_plan_res_defaults. If the planning resource has an organization,
2004        * use that; if not, use item master.
2005        ***************************************************************/
2006         UPDATE pa_res_members_temp res_temp
2007         SET unit_of_measure = (SELECT primary_uom_code
2008                                FROM   mtl_system_items_b items
2009                                WHERE  items.inventory_item_id =
2010                                       res_temp.inventory_item_id
2011                                AND    items.organization_id =
2012                                       res_temp.organization_id
2013                                AND    ROWNUM = 1)
2014         WHERE res_temp.resource_class_code = 'MATERIAL_ITEMS'
2015         AND res_temp.unit_of_measure IS NULL
2016         AND res_temp.organization_id IS NOT NULL
2017         AND res_temp.inventory_item_id IS NOT NULL;
2018 
2019         UPDATE pa_res_members_temp res_temp
2020         SET unit_of_measure = (SELECT primary_uom_code
2021                                FROM mtl_system_items_b items
2022                                WHERE items.inventory_item_id =
2023                                       res_temp.inventory_item_id
2024                          AND items.organization_id =
2025  					(SELECT def.item_master_id
2026                                            FROM pa_resource_classes_b cls,
2027 						pa_plan_res_defaults def
2028                          WHERE cls.resource_class_code = 'MATERIAL_ITEMS'
2029  			   AND cls.resource_class_id = def.resource_class_id
2030                            AND def.object_type = 'CLASS')
2031                                 AND ROWNUM     = 1)
2032         WHERE res_temp.resource_class_code = 'MATERIAL_ITEMS'
2033         AND res_temp.unit_of_measure IS NULL
2034         AND res_temp.inventory_item_id IS NOT NULL;
2035 
2036       /************************************************************
2037       * If the class is Financial Elements , or it is Material
2038       * Items but there is no item in the planning resource,
2039       * and there is an expenditure type, then take the UOM of
2040       * the expenditure type.
2041       ***************************************************************/
2042          UPDATE pa_res_members_temp res_temp
2043          SET res_temp.unit_of_measure = (SELECT unit_of_measure
2044                          FROM pa_expenditure_types et
2045                          WHERE et.expenditure_type = res_temp.expenditure_type
2046                            AND ROWNUM = 1)
2047          WHERE res_temp.resource_class_code IN
2048                ('MATERIAL_ITEMS', 'FINANCIAL_ELEMENTS')
2049          AND res_temp.inventory_item_id IS NULL
2050          AND res_temp.unit_of_measure IS NULL
2051          AND res_temp.expenditure_type IS NOT NULL;
2052 
2053         /******************************************************
2054         * If the Unit of measure column is still null, then
2055         * Default it to 'DOLLARS'
2056         *********************************************************/
2057          UPDATE pa_res_members_temp res_temp
2058          SET res_temp.unit_of_measure = 'DOLLARS'
2059          WHERE res_temp.unit_of_measure IS NULL;
2060 
2061 EXCEPTION
2062 WHEN OTHERS THEN
2063  RAISE;
2064 END Default_UOM;
2065 
2066 /*********************************************************
2067 * Procedure Default_Supplier
2068 * If Supplier is not null, pass it back.
2069 * 1. Code to get from per_cont_workers_current_x if
2070 * incurred_by_res_flag is 'N' - AI: need to revisit if we need to do it
2071 * for incurred by resources also
2072 * ******************************************************/
2073 PROCEDURE Default_Supplier
2074 IS
2075 BEGIN
2076      UPDATE pa_res_members_temp res_temp
2077      SET  res_temp.vendor_id =
2078                              (SELECT asgn.vendor_id
2079                                 FROM per_all_assignments_f asgn
2080                                WHERE asgn.person_id = res_temp.person_id
2081                                  AND asgn.primary_flag = 'Y'
2082                                  AND asgn.assignment_type = 'C'
2083                                  AND trunc(sysdate) BETWEEN
2084                                      asgn.effective_start_date AND
2085                                      asgn.effective_end_date
2086                                  AND ROWNUM = 1)
2087      WHERE res_temp.vendor_id IS NULL
2088      -- Fix for bug 3940856 - get supplier for all cwk
2089      -- AND res_temp.incurred_by_res_flag = 'N'
2090      AND res_temp.person_id IS NOT NULL;
2091 EXCEPTION
2092 WHEN OTHERS THEN
2093   RAISE;
2094 END Default_Supplier;
2095 
2096 /*********************************************************
2097 * Procedure Default_Currency_Code
2098 * ******************************************************/
2099 PROCEDURE Default_Currency_Code
2100 IS
2101 
2102 BEGIN
2103       UPDATE pa_res_members_temp res_temp
2104       SET rate_func_curr_code = (
2105                   SELECT FC.Currency_Code
2106                   FROM FND_CURRENCIES FC,
2107                        GL_SETS_OF_BOOKS GB,
2108                        PA_IMPLEMENTATIONS_all IMP
2109                    -- Bug 4656920 - removed nvl on imp.org_id for R12 MOAC
2110                    WHERE imp.org_id = nvl(res_temp.org_id, -99)
2111                    AND IMP.Set_Of_Books_ID = GB.Set_Of_Books_ID
2112                    AND FC.Currency_Code =
2113                        DECODE(IMP.Set_Of_Books_ID, NULL,NULL,GB.CURRENCY_CODE));
2114 
2115       UPDATE pa_res_members_temp res_temp
2116       SET rate_func_curr_code = unit_of_measure
2117       WHERE inventory_item_id IS NOT NULL
2118       AND rate_based_flag = 'N';
2119 
2120       -- Added for bug  3841920 - The UOM for all non-rate based
2121       -- transactions should be 'Currency'
2122       UPDATE pa_res_members_temp res_temp
2123       SET unit_of_measure = 'DOLLARS'
2124       WHERE inventory_item_id IS NOT NULL
2125       AND rate_based_flag = 'N';
2126 
2127 EXCEPTION
2128 WHEN OTHERS THEN
2129    RAISE;
2130 END Default_Currency_Code;
2131 /**************************************************/
2132 /*********************************************************
2133  * Procedure  : default_job
2134  * If job is not null, then leave as is
2135  * i. Default from person's HR Job if planning resource has a person
2136  *    and the person is not the incurred by resource.
2137  * If we cannot default job, we will pass back null.
2138  * ******************************************************/
2139  PROCEDURE default_job
2140  IS
2141  BEGIN
2142      UPDATE pa_res_members_temp res_temp
2143      SET job_id = (SELECT job_id
2144                  FROM per_all_assignments_f assn
2145                  WHERE assn.person_id = res_temp.person_id
2146                  AND   SYSDATE BETWEEN assn.effective_start_date
2147                                    AND  assn.effective_end_date
2148                  AND assn.assignment_type in ('C','E')
2149                  AND assn.primary_flag = 'Y'
2150                  AND ROWNUM = 1)
2151      WHERE res_temp.job_id IS NULL
2152      AND res_temp.person_id IS NOT NULL;
2153 
2154      UPDATE pa_res_members_temp res_temp
2155      SET job_id = (SELECT default_job_id
2156                      FROM pa_project_role_types_vl role
2157                     WHERE role.project_role_id = res_temp.project_role_id
2158                       AND ROWNUM = 1)
2159      WHERE res_temp.job_id IS NULL
2160      AND res_temp.project_role_id IS NOT NULL;
2161 
2162  EXCEPTION
2163  WHEN OTHERS THEN
2164      RAISE;
2165  END default_job;
2166 
2167 /**************************************************/
2168 /*********************************************************
2169  * Procedure  : default_person_type
2170  * If person_type is not null, then leave as is
2171  * i. Get from person's HR person record if planning resource has a person
2172  *    and the person is not the incurred by resource.
2173  *    Now, doing it for incurred by resource also, if inc by is a person
2174  * If we cannot default person_type, we will pass back null.
2175  *  ******************************************************/
2176  PROCEDURE default_person_type
2177  IS
2178  BEGIN
2179 -- Issue with future dated or terminated employees/contingent workers?
2180 
2181      UPDATE pa_res_members_temp res_temp
2182      SET person_type_code = (SELECT
2183                            decode(peo.current_employee_flag, 'Y', 'EMP', 'CWK')
2184                  FROM per_all_people_f peo
2185                  WHERE peo.person_id = res_temp.person_id
2186                  AND   SYSDATE BETWEEN peo.effective_start_date
2187                                    AND peo.effective_end_date
2188                  AND ROWNUM = 1)
2189      WHERE res_temp.person_type_code IS NULL
2190      -- AND res_temp.incurred_by_res_flag = 'N' -- Bug 3827566
2191      AND res_temp.person_id IS NOT NULL;
2192  EXCEPTION
2193  WHEN OTHERS THEN
2194      RAISE;
2195  END default_person_type;
2196 
2197 /*******************************************************/
2198 
2199 /*********************************************************
2200 * Procedure Default_Organization
2201 * If Organization is not null, then leave as is
2202 * i. Default from person's HR organization if planning resource has a person
2203 *    and the person is not the incurred by resource.
2204 * ii. Default from bom resource, id planning resource has one.
2205 * iii. Default from item, if planning resource has one
2206 * If we cannot default organization, we will pass back null.
2207 * ******************************************************/
2208 PROCEDURE Default_Organization (p_project_id IN PA_PROJECTS_ALL.PROJECT_ID%TYPE)
2209 IS
2210 
2211 l_organization_id NUMBER := NULL;
2212   BEGIN
2213 
2214      /***************************************************
2215      * All of the below updates will only fire for
2216      * organization_id being null in the temp table.
2217      * If it is not null....then dont do anything.
2218      * ****************************************************/
2219 
2220      /**************************************************
2221      * This Update will fire when the incurred_by_res_flag is Yes or No
2222      * and person_id IS NOT NULL.
2223      * We are updating the value for organization_id = derived value
2224      * based on person's HR org.
2225      * ***************************************************/
2226      UPDATE pa_res_members_temp res_temp
2227      SET organization_id = (SELECT a.organization_id
2228                  FROM per_assignments_x a,
2229                       pa_all_organizations org
2230                  WHERE a.person_id = res_temp.person_id
2231                  AND a.organization_id = org.organization_id
2232                  AND org.inactive_date is null
2233                  AND org.pa_org_use_type = 'EXPENDITURES'
2234                  AND a.assignment_type in ('C','E')
2235                  AND a.primary_flag = 'Y'
2236                  AND ROWNUM = 1)
2237      WHERE res_temp.person_id IS NOT NULL
2238      AND res_temp.organization_id IS NULL;
2239 
2240      /**************************************************
2241      * This Update will fire when the incurred_by_res_flag = 'N'
2242      * and bom_resource_id IS NOT NULL and organization_id IS NULL.
2243      * We are deriving the value for organization_id
2244      * ***************************************************/
2245      UPDATE pa_res_members_temp res_temp
2246      SET organization_id = (SELECT b.organization_id
2247                  FROM bom_resources b
2248                  WHERE b.resource_id = res_temp.bom_resource_id
2249                  AND ROWNUM = 1)
2250      WHERE res_temp.incurred_by_res_flag = 'N'
2251      AND res_temp.bom_resource_id IS NOT NULL
2252      AND res_temp.organization_id IS NULL;
2253 
2254      /**************************************************
2255      * This Update will fire when the incurred_by_res_flag = 'N'
2256      * and inventory_item_id IS NOT NULL and organization_id IS NULL.
2257      * We are deriving the value for organization_id
2258      * ***************************************************/
2259      UPDATE pa_res_members_temp res_temp
2260      SET organization_id = (SELECT i.organization_id
2261                  FROM mtl_system_items_b i
2262                  WHERE i.inventory_item_id = res_temp.inventory_item_id
2263                    AND i.organization_id =
2264                                         (SELECT def.item_master_id
2265                                            FROM pa_resource_classes_b cls,
2266                                                 pa_plan_res_defaults def
2267                          WHERE cls.resource_class_code = 'MATERIAL_ITEMS'
2268                            AND cls.resource_class_id = def.resource_class_id
2269                            AND def.object_type = 'CLASS')
2270                  AND ROWNUM = 1)
2271      WHERE res_temp.incurred_by_res_flag = 'N'
2272      AND res_temp.inventory_item_id IS NOT NULL
2273      AND res_temp.organization_id IS NULL;
2274 
2275      /**************************************************
2276      * This Update will fire for all resources if the organization_id is null
2277      * We are deriving the value for organization_id from the project
2278      * ***************************************************/
2279 
2280      BEGIN
2281      SELECT proj.carrying_out_organization_id
2282        INTO l_organization_id
2283        FROM pa_projects_all proj,
2284             pa_all_organizations org
2285       WHERE proj.project_id = p_project_id
2286         AND proj.carrying_out_organization_id = org.organization_id
2287         AND org.inactive_date is null
2288         AND org.pa_org_use_type = 'EXPENDITURES'
2289         AND ROWNUM = 1;
2290      EXCEPTION
2291        WHEN NO_DATA_FOUND THEN
2292           l_organization_id := NULL;
2293        WHEN OTHERS THEN
2294           l_organization_id := NULL;
2295      END;
2296 
2297      IF l_organization_id IS NOT NULL THEN
2298         UPDATE pa_res_members_temp res_temp
2299         SET organization_id = l_organization_id
2300         WHERE res_temp.organization_id IS NULL;
2301      END IF;
2302 
2303 
2304 EXCEPTION
2305      WHEN OTHERS THEN
2306           RAISE;
2307 
2308 END Default_Organization;
2309 /*************************************/
2310 
2311 /***********************************************************
2312  * Function  : Default_Rate_Based
2313  * Description : Function takes in resource_class_code,
2314  *               inventory_item_id, expenditure_type,
2315  *               and returns rate_based_flag.
2316  ***********************************************************/
2317 PROCEDURE default_rate_based
2318 IS
2319 BEGIN
2320       /****************************************
2321        * First Update all the rows no 'N' as by
2322        * default it should be N  and not null.
2323        ******************************************/
2324       UPDATE pa_res_members_temp res_temp
2325       SET rate_based_flag = 'N';
2326 
2327      /********************************************
2328      * Update it to 'Y' for resource_class_code
2329      * in 'PEOPLE' or 'EQUIPMENT'
2330      ***********************************************/
2331        UPDATE pa_res_members_temp res_temp
2332        SET rate_based_flag = 'Y'
2333        WHERE res_temp.resource_class_code in ('PEOPLE','EQUIPMENT');
2334 
2335        UPDATE pa_res_members_temp res_temp
2336        SET rate_based_flag = 'Y'
2337        WHERE res_temp.resource_class_code
2338                     = 'MATERIAL_ITEMS'
2339        AND res_temp.inventory_item_id IS NOT NULL
2340        AND NOT EXISTS (select 'Y'
2341                          from mtl_system_items_b item,
2342                               mtl_units_of_measure meas
2343                         where item.inventory_item_id =
2344                               res_temp.inventory_item_id
2345                           and item.primary_uom_code = meas.uom_code
2346                           and meas.uom_class = 'Currency');
2347 
2348  /**********************************************************
2349  * If the x_rate_exp_type is not null but exp_type is null
2350  * then use x_rate_exp_type to derive rate_based_flag.
2351  * Modified the existing update statement to include the foll:
2352  * - 'MATERIAL_ITEMS' in res_class_code.
2353  * - Added an nvl condition to derive based on the
2354  * rate expenditure type if the expenditure type is null
2355  * - added an extra condition to check that either one of
2356  * expenditure type or rate expenditure type should not be null.
2357  * ********************************************************/
2358        UPDATE pa_res_members_temp res_temp
2359        SET rate_based_flag =
2360                     (SELECT c.cost_rate_flag
2361                      FROM pa_expenditure_types c
2362                      WHERE c.expenditure_type = res_temp.expenditure_type)
2363                      -- nvl(res_temp.expenditure_type,  Bug 3586021
2364                              -- res_temp.rate_expenditure_type))
2365        WHERE res_temp.resource_class_code
2366                     in ('MATERIAL_ITEMS',  'FINANCIAL_ELEMENTS')
2367        --Added the below cond so that it does not override prev upd.
2368        AND res_temp.inventory_item_id IS NULL
2369        AND res_temp.expenditure_type IS NOT NULL;
2370        -- AND (res_temp.expenditure_type IS NOT NULL OR
2371               -- res_temp.rate_expenditure_type is not null); -- Bug 3586021
2372 EXCEPTION
2373 WHEN OTHERS THEN
2374       RAISE;
2375 END Default_rate_based;
2376 /*******************************************************/
2377 
2378 /*************************************************************
2379  * Procedure  : get_resource_defaults
2380  * ***********************************************************/
2381 /************************************************************
2382  * Bug - 3473324
2383  * Added parameter x_incur_by_res_type, to get the res_type_code
2384  * for incur by resource.
2385  **********************************************************/
2386 PROCEDURE get_resource_defaults (
2387 P_resource_list_members		IN 	        SYSTEM.PA_NUM_TBL_TYPE,
2388 P_project_id			IN 	        PA_PROJECTS_ALL.PROJECT_ID%TYPE,
2389 X_resource_class_flag		OUT NOCOPY	SYSTEM.PA_VARCHAR2_1_TBL_TYPE,
2390 X_resource_class_code		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2391 X_resource_class_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2392 X_res_type_code			OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2393 X_incur_by_res_type		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2394 X_person_id			OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2395 X_job_id			OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2396 X_person_type_code		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2397 X_named_role			OUT NOCOPY	SYSTEM.PA_VARCHAR2_80_TBL_TYPE,
2398 X_bom_resource_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2399 X_non_labor_resource		OUT NOCOPY	SYSTEM.PA_VARCHAR2_20_TBL_TYPE,
2400 X_inventory_item_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2401 X_item_category_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2402 X_project_role_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2403 X_organization_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2404 X_fc_res_type_code		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2405 X_expenditure_type		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2406 X_expenditure_category		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2407 X_event_type			OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2408 X_revenue_category_code		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2409 X_supplier_id			OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2410 X_spread_curve_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2411 X_etc_method_code		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2412 X_mfc_cost_type_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2413 X_incurred_by_res_flag		OUT NOCOPY	SYSTEM.PA_VARCHAR2_1_TBL_TYPE,
2414 X_incur_by_res_class_code	OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2415 X_incur_by_role_id		OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2416 X_unit_of_measure		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2417 X_org_id			OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2418 X_rate_based_flag		OUT NOCOPY	SYSTEM.PA_VARCHAR2_1_TBL_TYPE,
2419 X_rate_expenditure_type		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2420 X_rate_func_curr_code		OUT NOCOPY	SYSTEM.PA_VARCHAR2_30_TBL_TYPE,
2421 -- X_rate_incurred_by_org_id	OUT NOCOPY	SYSTEM.PA_NUM_TBL_TYPE,
2422 X_msg_data			OUT NOCOPY	VARCHAR2,
2423 X_msg_count			OUT NOCOPY	NUMBER,
2424 X_return_status			OUT NOCOPY	VARCHAR2)
2425 IS
2426 --Declaration of Tables used for Bulk Fetch
2427 	l_resource_list_member_id 	SYSTEM.PA_NUM_TBL_TYPE;
2428 	l_resource_class_flag		SYSTEM.PA_VARCHAR2_1_TBL_TYPE;
2429 	l_resource_class_code		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2430 	l_resource_class_id		SYSTEM.PA_NUM_TBL_TYPE;
2431 	l_person_id			SYSTEM.PA_NUM_TBL_TYPE;
2432 	l_job_id			SYSTEM.PA_NUM_TBL_TYPE;
2433         l_person_type_code		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2434 	l_named_role			SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2435 	l_bom_resource_id		SYSTEM.PA_NUM_TBL_TYPE;
2436 	l_non_labor_resource		SYSTEM.PA_VARCHAR2_20_TBL_TYPE;
2437 	l_inventory_item_id		SYSTEM.PA_NUM_TBL_TYPE;
2438 	l_item_category_id		SYSTEM.PA_NUM_TBL_TYPE;
2439 	l_project_role_id		SYSTEM.PA_NUM_TBL_TYPE;
2440 	l_organization_id		SYSTEM.PA_NUM_TBL_TYPE;
2441 	l_fc_res_type_code		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2442 	l_expenditure_type		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2443 	l_expenditure_category		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2444 	l_event_type			SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2445 	l_revenue_category_code		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2446 	l_supplier_id			SYSTEM.PA_NUM_TBL_TYPE;
2447 	l_spread_curve_id		SYSTEM.PA_NUM_TBL_TYPE;
2448 	l_etc_method_code		SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2449 	l_mfc_cost_type_id		SYSTEM.PA_NUM_TBL_TYPE;
2450 	l_incurred_by_res_flag		SYSTEM.PA_VARCHAR2_1_TBL_TYPE;
2451 	l_incur_by_res_class_code	SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2452 	l_incur_by_role_id		SYSTEM.PA_NUM_TBL_TYPE;
2453         l_rate_expenditure_type         SYSTEM.PA_VARCHAR2_30_TBL_TYPE;
2454         l_rate_incurred_by_org_id       SYSTEM.PA_NUM_TBL_TYPE;
2455         l_rate_based_flag               SYSTEM.PA_VARCHAR2_1_TBL_TYPE;
2456         l_exception                     EXCEPTION;
2457         l_last_analyzed                 all_tables.last_analyzed%TYPE;
2458         l_pa_schema                     VARCHAR2(30);
2459 /*********************************************
2460  * * Main Block
2461  * ***********************************************/
2462 BEGIN
2463       --Initialize the x_return_status
2464       X_Return_Status      := Fnd_Api.G_Ret_Sts_Success;
2465 
2466       --For bug 4039707, 4887312
2467 
2468 -- Commenting out for TEMP fix to bug 4887312 - proper fix will be done soon.
2469 /*
2470          FND_STATS.SET_TABLE_STATS('PA',
2471                            'PA_RES_MEMBERS_TEMP',
2472                            100,
2473                            10,
2474                            100);
2475 
2476          FND_STATS.SET_TABLE_STATS('PA',
2477                            'PA_RES_MEMBER_ID_TEMP',
2478                            100,
2479                            10,
2480                            100);
2481 */
2482       --End of bug 4039707, 4887312
2483 
2484     -- Proper Fix for 4887312 *** RAMURTHY  03/01/06 02:33 pm ***
2485     -- It solves the issue above wrt commit by the FND_STATS.SET_TABLE_STATS call
2486 
2487     PA_TASK_ASSIGNMENT_UTILS.set_table_stats('PA','PA_RES_MEMBERS_TEMP',100,10,100);
2488     PA_TASK_ASSIGNMENT_UTILS.set_table_stats('PA','PA_RES_MEMBER_ID_TEMP',100,10,100);
2489 
2490     -- End Bug fix 4887312
2491 
2492     /***********************************************
2493     * Deleting from the temp tables in the beginning as well
2494     * to be on the safe side.
2495     ***********************************************/
2496     DELETE FROM pa_res_members_temp;
2497 
2498     DELETE FROM pa_res_member_id_temp;
2499   /************************************************************
2500    * Created a script to create 2 tables in the DB
2501    * 1. pa_res_member_id_temp which would only hold the
2502    *    resource_list_member_id
2503    * 2. pa_res_members_temp which would hold the
2504    *    resource_list_member_id and all the other attributes
2505    *    which need to be defaulted
2506   *************************************************************/
2507 
2508   /***************************************************************
2509    * First insert into the pa_res_member_id_temp table just the
2510    * resource_list_member_id which have been passed as IN param's
2511    **************************************************************/
2512   FOR i in p_resource_list_members.first..p_resource_list_members.last
2513     LOOP
2514      INSERT INTO pa_res_member_id_temp
2515              (resource_list_member_id,
2516               order_id)
2517      VALUES(p_resource_list_members(i),
2518             i);
2519     END LOOP;
2520 
2521 /********************************************************
2522  * Bug         : 3473425
2523  * Description : When Duplicate resource list member ID's
2524  *               were passed as IN parameters into the PL/SQL
2525  *               table, this proc was failing. To rectify that
2526  *               we have now induded a column order_id in the
2527  *               pa_res_members_temp table. And in the below insert
2528  *               we are populating value into it, same as the order
2529  *               id in pa_res_members_id_temp.
2530  *********************************************************/
2531     INSERT INTO pa_res_members_temp
2532              (resource_list_member_id,
2533               order_id,
2534               resource_class_flag		,
2535               resource_class_code		,
2536               resource_class_id			,
2537               --Added column newly
2538               res_type_code                     ,
2539               person_id			        ,
2540               job_id				,
2541               person_type_code		        ,
2542               named_role			,
2543               bom_resource_id			,
2544               non_labor_resource		,
2545               inventory_item_id		        ,
2546               item_category_id			,
2547               project_role_id			,
2548               organization_id			,
2549               fc_res_type_code			,
2550               expenditure_type			,
2551               expenditure_category		,
2552               Event_type			,
2553               revenue_category		        ,
2554               vendor_id			        ,
2555               spread_curve_id			,
2556               etc_method_code			,
2557               mfc_cost_type_id			,
2558               incurred_by_res_flag		,
2559               incur_by_res_class_code		,
2560               incur_by_role_id			,
2561               unit_of_measure			,
2562               org_id				,
2563               rate_based_flag			,
2564               rate_expenditure_type		,
2565               rate_func_curr_code		,
2566               rate_incurred_by_org_id	)
2567   SELECT  /*+ ORDERED */
2568               a.resource_list_member_id           ,
2569               b.order_id,
2570               a.resource_class_flag               ,
2571               a.resource_class_code               ,
2572               a.resource_class_id                 ,
2573               typ.res_type_code                   ,
2574               a.person_id                         ,
2575               a.job_id                            ,
2576               a.person_type_code                  ,
2577               a.team_role                         ,
2578               a.bom_resource_id                   ,
2579               a.non_labor_resource                ,
2580               a.inventory_item_id                 ,
2581               a.item_category_id                  ,
2582 	      a.project_role_id			  ,
2583               a.organization_id			  ,
2584               a.fc_res_type_code		  ,
2585               a.expenditure_type		  ,
2586               a.expenditure_category		  ,
2587               a.Event_type			  ,
2588               a.revenue_category		  ,
2589               a.vendor_id			  ,
2590               a.spread_curve_id			  ,
2591               a.etc_method_code			  ,
2592               a.mfc_cost_type_id		  ,
2593               a.incurred_by_res_flag		  ,
2594               a.incur_by_res_class_code		  ,
2595               a.incur_by_role_id                  ,
2596               NULL                                ,
2597               NULL                                ,
2598               NULL                                ,
2599               NULL                                ,
2600               NULL                                ,
2601               NULL
2602              FROM pa_res_member_id_temp b,
2603                   pa_resource_list_members a,
2604 		  pa_res_formats_b fmt,
2605 	          pa_res_types_b typ
2606              WHERE a.resource_list_member_id = b.resource_list_member_id
2607                AND a.res_format_id = fmt.res_format_id
2608                AND fmt.res_type_id = typ.res_type_id(+);
2609 
2610       /************************************************************
2611       * Bug 3466920
2612       * Bug Fix - Earlier we were not updating the res_type_code
2613       * for an incurred by resource. Hence it was always getting passed
2614       * as Null. We have however fixed the issue with the below Update.
2615       * This Update will fire when if the res_type_code is still null
2616       * and the incurred_by_res_flag='Y'
2617       ****************************************************************/
2618       UPDATE pa_res_members_temp res_temp
2619       SET res_type_code = DECODE(res_temp.person_id, NULL,
2620                      DECODE(res_temp.job_id, NULL,
2621                       DECODE(res_temp.person_type_code, NULL,
2622                        DECODE(res_temp.incur_by_role_id, NULL,
2623                         DECODE(res_temp.incur_by_res_class_code, NULL,
2624                          NULL, 'RESOURCE_CLASS'),
2625                         'ROLE'),
2626                        'PERSON_TYPE'),
2627                       'JOB'),
2628                      'NAMED_PERSON')
2629       WHERE incurred_by_res_flag = 'Y'
2630       AND res_type_code IS NULL;
2631 
2632   /******************************************************************
2633    * Call the Procedure Default_job which will Update the Job ID
2634    * in the temp table pa_res_members_temp with the correct
2635    * value.
2636    * *****************************************************************/
2637    pa_planning_resource_utils.default_job;
2638 
2639   /******************************************************************
2640    * Call the Procedure default_person_type which will Update the
2641    * person_type_code in the temp table pa_res_members_temp with the correct
2642    * value.
2643    * *****************************************************************/
2644    pa_planning_resource_utils.default_person_type;
2645 
2646    /******************************************************************
2647    * Call the Procedure Default_Organization  which will
2648    * Update the organization_id and rate_incurred_by_org_id
2649    * in the temp table pa_res_members_temp with the correct
2650    * values.
2651    * *****************************************************************/
2652    pa_planning_resource_utils.default_organization(
2653            p_project_id => p_project_id);
2654 
2655   /******************************************************************
2656    * Call the Procedure Default_Expenditure_Type  which will
2657    * Update the expenditure_type
2658    * in the temp table pa_res_members_temp with the correct
2659    * values.
2660    * *****************************************************************/
2661    pa_planning_resource_utils.default_expenditure_type;
2662 
2663   /******************************************************************
2664    * Call the Procedure Default_Rate_Expenditure_Type  which will
2665    * Update the rate_expenditure_type
2666    * in the temp table pa_res_members_temp with the correct
2667    * values.
2668    * *****************************************************************/
2669    pa_planning_resource_utils.default_rate_expenditure_type;
2670 
2671    /******************************************************************
2672    * Call the Procedure Default_Supplier  which will
2673    * Update the vendor_id
2674    * in the temp table pa_res_members_temp with the correct
2675    * values.
2676    * *****************************************************************/
2677    pa_planning_resource_utils.default_supplier;
2678 
2679    /******************************************************************
2680    * Call the Procedure Default_rate_based  which will
2681    * Update the Rate_based_flag
2682    * in the temp table pa_res_members_temp with the correct
2683    * values.
2684    * *****************************************************************/
2685    pa_planning_resource_utils.default_rate_based;
2686 
2687   /******************************************************************
2688    * Call the Procedure Default_OU which will
2689    * Update the OU
2690    * in the temp table pa_res_members_temp with the correct
2691    * values.
2692    *****************************************************************/
2693    pa_planning_resource_utils.default_ou(p_project_id);
2694 
2695    /******************************************************************
2696    * Call the Procedure Default_UOM  which will
2697    * Update the Unit_of_measure
2698    * in the temp table pa_res_members_temp with the correct
2699    * values.
2700    *****************************************************************/
2701    pa_planning_resource_utils.default_uom;
2702 
2703    /******************************************************************
2704    * Call the Procedure Default_Currency_Code  which will
2705    * Update the Rate_Func_Curr_Code
2706    * in the temp table pa_res_members_temp with the correct
2707    * values.
2708    *****************************************************************/
2709     pa_planning_resource_utils.default_currency_code;
2710 
2711    /*****************************************************************
2712     * Fetch the values that are currently there in the pa_res_members_temp
2713     * table into the out var's.  Select it from the Temp table
2714     * pa_res_members_temp and Bulk collect it into the OUT var's.
2715     *********************************************************************/
2716     /**********************************************************
2717      * Added an extra order ID join between the pa_res_members_temp
2718      * and pa_res_member_id_temp table to keep in sync.
2719      * Bug - 3473425
2720      **********************************************************/
2721      /*********************************************************
2722      * Bug - 3473324
2723      * Desc - If the incurred_by res_flag was 'N' or Null then we would
2724      *        populate the res_type_code into the x_res_type_code parameter.
2725      *        If the incur_by_res_flag was 'Y' then we would populate the
2726      *        res_type_code into the x_incur_by_res_type parameter.
2727      ********************************************************/
2728      SELECT
2729         a.RESOURCE_CLASS_FLAG,
2730         a.RESOURCE_CLASS_CODE,
2731         a.RESOURCE_CLASS_ID,
2732         decode(a.incurred_by_res_flag,'Y',Null,a.RES_TYPE_CODE),
2733         decode(a.incurred_by_res_flag,'Y',a.RES_TYPE_CODE,Null),
2734         a.PERSON_ID,
2735         a.JOB_ID,
2736         a.PERSON_TYPE_CODE,
2737         a.NAMED_ROLE ,
2738         a.BOM_RESOURCE_ID,
2739         a.NON_LABOR_RESOURCE,
2740         a.INVENTORY_ITEM_ID,
2741         a.ITEM_CATEGORY_ID,
2742         a.PROJECT_ROLE_ID,
2743         a.ORGANIZATION_ID,
2744         a.FC_RES_TYPE_CODE,
2745         a.EXPENDITURE_TYPE,
2746         a.EXPENDITURE_CATEGORY,
2747         a.EVENT_TYPE,
2748         a.REVENUE_CATEGORY,
2749         a.VENDOR_ID,
2750         a.SPREAD_CURVE_ID,
2751         a.ETC_METHOD_CODE,
2752         a.MFC_COST_TYPE_ID,
2753         a.INCURRED_BY_RES_FLAG,
2754         a.INCUR_BY_RES_CLASS_CODE,
2755         a.INCUR_BY_ROLE_ID,
2756         a.UNIT_OF_MEASURE,
2757         a.ORG_ID,
2758         a.RATE_BASED_FLAG,
2759         a.RATE_EXPENDITURE_TYPE,
2760         a.RATE_FUNC_CURR_CODE
2761         --a.RATE_INCURRED_BY_ORG_ID
2762      BULK COLLECT INTO
2763         x_resource_class_flag           ,
2764         x_resource_class_code           ,
2765         x_resource_class_id             ,
2766         x_res_type_code                 ,
2767         x_incur_by_res_type             ,
2768         x_person_id                     ,
2769         x_job_id                        ,
2770         x_person_type_code              ,
2771         x_named_role                    ,
2772         x_bom_resource_id               ,
2773         x_non_labor_resource            ,
2774         x_inventory_item_id             ,
2775         x_item_category_id              ,
2776         x_project_role_id               ,
2777         x_organization_id               ,
2778         x_fc_res_type_code              ,
2779         x_expenditure_type              ,
2780         x_expenditure_category          ,
2781         x_event_type                    ,
2782         x_revenue_category_code         ,
2783         x_supplier_id                   ,
2784         x_spread_curve_id               ,
2785         x_etc_method_code               ,
2786         x_mfc_cost_type_id              ,
2787         x_incurred_by_res_flag          ,
2788         x_incur_by_res_class_code       ,
2789         x_incur_by_role_id              ,
2790         x_unit_of_measure               ,
2791         x_org_id                        ,
2792         x_rate_based_flag               ,
2793         x_rate_expenditure_type         ,
2794         x_rate_func_curr_code
2795         -- x_rate_incurred_by_org_id
2796    FROM pa_res_members_temp a,
2797         pa_res_member_id_temp b
2798    WHERE a.resource_list_member_id = b.resource_list_member_id
2799    AND   a.order_id  = b.order_id
2800    ORDER BY b.order_id;
2801 
2802    IF x_resource_class_id.COUNT <> p_resource_list_members.COUNT then
2803        X_Return_Status   := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2804        RAISE l_exception;
2805     END IF;
2806 
2807    DELETE FROM pa_res_members_temp;
2808 
2809    DELETE FROM pa_res_member_id_temp;
2810 
2811 EXCEPTION
2812  WHEN l_exception THEN
2813     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2814     Return;
2815 WHEN OTHERS THEN
2816     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2817     Return;
2818 END Get_Resource_defaults;
2819 
2820 
2821 /*********************************************************
2822  * Eugene's code
2823  ********************************************************/
2824 
2825 /*********************************************************
2826  *Type (Procedure or Procedure): Function
2827  *Package Object Name          : Ret_Resource_Name
2828  *Purpose:                       Return the resource name from a given
2829  *			         resource type code and id.
2830  * Public or Private API?       Public
2831  * *******************************************************/
2832   Function Ret_Resource_Name (P_Res_Type_Code      IN Varchar2,
2833 			       P_Person_Id          IN Number,
2834 			       P_Bom_Resource_Id    IN Number,
2835     			       P_Job_Id             IN Number,
2836 			       P_Person_Type_Code   IN Varchar2,
2837 			       P_Non_Labor_Resource IN Varchar2,
2838 			       P_Inventory_Item_Id  IN Number,
2839 			       P_Resource_Class_Id  IN Number,
2840 			       P_Item_Category_Id   IN Number,
2841                                p_res_assignment_id  IN NUMBER default null ) Return Varchar2
2842 
2843   Is
2844 
2845 	l_Return_Status Varchar2(1)    := Null;
2846 	l_Msg_Data	Varchar2(30)   := Null;
2847 	l_Resource_Name Varchar2(1000) := Null;
2848 
2849   Begin
2850 
2851 	pa_planning_resource_utils.Get_Resource_Name (
2852                            P_Res_Type_Code      => P_Res_Type_Code,
2853 			   P_Person_Id          => P_Person_Id,
2854 			   P_Bom_Resource_Id    => P_Bom_Resource_Id,
2855     			   P_Job_Id             => P_Job_Id,
2856 			   P_Person_Type_Code   => P_Person_Type_Code,
2857 			   P_Non_Labor_Resource => P_Non_Labor_Resource,
2858 			   P_Inventory_Item_Id  => P_Inventory_Item_id,
2859 			   P_Item_Category_Id   => P_Item_Category_Id,
2860 			   P_Resource_Class_Id	=> P_Resource_Class_Id,
2861 			   P_Proc_Func_Flag     => 'F',
2862                            p_res_assignment_id  => p_res_assignment_id,
2863 			   X_Resource_Displayed => l_Resource_Name,
2864 		 	   X_Return_Status      => l_Return_Status,
2865 			   X_Msg_Data           => l_Msg_Data );
2866 
2867 	Return l_Resource_Name;
2868 
2869   Exception
2870 	When Others Then
2871 		Raise;
2872 
2873   End Ret_Resource_Name;
2874 /*****************************************/
2875 
2876 /***************************************************************
2877  * Type (Procedure or Procedure): Procedure
2878  * Package Object Name:           Get_Resource_Name
2879  **************************************************************/
2880   Procedure Get_Resource_Name ( P_Res_Type_Code            IN Varchar2,
2881 			        P_Person_Id                IN Number,
2882 			        P_Bom_Resource_Id          IN Number,
2883     			        P_Job_Id                   IN Number,
2884 			        P_Person_Type_Code         IN Varchar2,
2885 			        P_Non_Labor_Resource       IN Varchar2,
2886 			        P_Inventory_Item_Id        IN Number,
2887 			        P_Item_Category_Id         IN Number,
2888 				P_Resource_Class_Id	   IN Number,
2889 				P_Proc_Func_Flag           IN Varchar2,
2890                                 P_Res_Assignment_Id        IN NUMBER,
2891 				X_Resource_Displayed       OUT NOCOPY Varchar2,
2892 		 		X_Return_Status            OUT NOCOPY Varchar2,
2893 				X_Msg_Data    	           OUT NOCOPY Varchar2 )
2894 
2895   Is
2896 
2897 	l_Res_Type_Displayed          Varchar2(1000) := Null;
2898 
2899 	--BAD_PER_IN_RES_LIST_MEM       Exception;
2900 	--NULL_PER_IN_RES_LIST_MEM      Exception;
2901 	--BAD_JOB_IN_RES_LIST_MEM       Exception;
2902 	--NULL_JOB_IN_RES_LIST_MEM      Exception;
2903 	--BAD_PER_TYPE_IN_LIST_MEM      Exception;
2904 	--NULL_PER_TYPE_IN_LIST_MEM     Exception;
2905 	BAD_BOM_LABOR_RES_IN_LST_MEM  Exception;
2906 	NULL_BOM_LABOR_RES_IN_LST_MEM Exception;
2907 	BAD_BOM_EQUIP_RES_IN_LST_MEM  Exception;
2908 	NULL_BOM_EQUIP_RES_IN_LST_MEM Exception;
2909 	BAD_ITEM_CAT_IN_LST_MEM       Exception;
2910 	NULL_ITEM_CAT_IN_LST_MEM      Exception;
2911 	BAD_INVEN_ITEM_IN_LST_MEM     Exception;
2912 	NULL_INVEN_ITEM_IN_LST_MEM    Exception;
2913 	--NULL_NLR_IN_LIST_MEM	      Exception;
2914 	--BAD_RESCLASS_IN_LIST_MEM      Exception;
2915 	--NULL_RESCLASS_IN_LIST_MEM     Exception;
2916         UNEXPEC_ERROR                 Exception;
2917        /*************************************************
2918         * Bug         - 3485392
2919         * Description - Using the Known_as field from the
2920         *               Per_people_x table to derive the
2921         *               resource_name. If the known_as field is
2922         *               Null then select the full_name.
2923         *************************************************/
2924 	Cursor c_People (P_Person_Id IN Number) is
2925 	Select
2926 		--nvl(known_as,Full_Name)
2927                 --Bug 3485392
2928 		Full_Name
2929 	From
2930 		Per_People_X
2931 	Where
2932 		Person_Id = P_Person_Id
2933 	And     ( (Pa_Cross_Business_Grp.IsCrossBGProfile = 'N' AND
2934 		   Fnd_Profile.Value('PER_BUSINESS_GROUP_ID') = Business_Group_Id)
2935 		  OR Pa_Cross_Business_Grp.IsCrossBGProfile = 'Y');
2936 
2937 	Cursor c_Job (P_Job_Id In Number) Is
2938 	Select
2939 		Name
2940 	From
2941 		Per_Jobs
2942 	Where
2943 		Job_Id = P_Job_Id
2944 	And     ( (Pa_Cross_Business_Grp.IsCrossBGProfile = 'N' AND
2945 		   Fnd_Profile.Value('PER_BUSINESS_GROUP_ID') = Per_Jobs.Business_Group_Id )
2946 		  OR Pa_Cross_Business_Grp.IsCrossBGProfile = 'Y');
2947 
2948 	Cursor c_PersonType (P_Person_Type IN Varchar2) Is
2949 	Select
2950 		Meaning
2951 	From
2952 		pa_lookups
2953 	Where
2954 		Lookup_Type = 'PA_PERSON_TYPE'
2955 	And	Lookup_Code = P_Person_Type;
2956 
2957        /*************************************************
2958         * Bug - 3461494
2959         * Description - Using the Resource code field from the
2960         *               Bom_Resources table to derive the
2961         *               resource_name instead of using the
2962         *               description.
2963         *************************************************/
2964 	Cursor c_BOM (P_BOM_Res_Id IN Number) Is
2965 	Select
2966 		Resource_code
2967 	From
2968 		Bom_Resources
2969 	Where
2970 		Resource_Id = P_BOM_Res_Id;
2971 
2972 	Cursor c_Item_Cat ( P_Item_Cat_Id IN Number ) Is
2973 	Select fnd_Flex_ext.GET_SEGS('INV', 'MCAT', c.structure_id, c.category_id)
2974 	From   mtl_categories_v c
2975 	Where  c.Category_Id = P_Item_Cat_Id;
2976 
2977         /**********************************************************
2978         * Bug - 3566965
2979         * Desc - Instead of the description we are now selecting the
2980         *        segment1 field from Mtl_System_Items_b table as the
2981         *        resource name.
2982         **********************************************************/
2983 	Cursor c_Inven_Item (P_Inven_Item_Id IN Number ) Is
2984 	Select
2985 		segment1
2986 	From
2987 		Mtl_System_Items_b
2988 	Where
2989 		--Language = USERENV('LANG')
2990 	Inventory_Item_Id = P_Inven_Item_Id
2991         and 	organization_id =
2992 				(select
2993 					item_master_id
2994                                  from
2995 					pa_resource_classes_b cls,
2996                                		pa_plan_res_defaults def
2997                                  where
2998 					def.resource_class_id = cls.resource_class_id
2999                                  and 	cls.resource_class_code = 'MATERIAL_ITEMS'
3000                                  and 	def.object_type = 'CLASS');
3001 
3002 	Cursor c_ResClass (P_Res_Class_Id IN Number) Is
3003 	Select
3004 		Name
3005 	From
3006 		Pa_Resource_Classes_Vl
3007 	Where
3008 		Resource_Class_Id = P_Res_Class_Id;
3009 
3010 	Cursor c_PrjRoles (P_Prj_Role_Id IN Number) Is
3011 	Select
3012 		Meaning
3013 	From
3014 		Pa_Project_Role_Types_vl
3015 	Where
3016 		Project_Role_Id = P_Prj_Role_Id;
3017 
3018        Cursor c_Res_Attributes Is
3019        Select
3020                 a.Res_Type_Code Res_Type_Code,
3021                 a.Person_Id Person_Id,
3022                 a.Job_Id Job_Id,
3023                 a.Bom_Resource_Id Bom_Resource_Id,
3024                 a.Inventory_Item_Id Inventory_Item_Id,
3025                 a.Item_Category_Id Item_Category_Id,
3026                 a.Person_Type_Code Person_Type_Code,
3027                 a.Non_Labor_Resource Non_Labor_Resource,
3028                 a.incurred_by_res_flag incurred_by_res_flag,
3029                 c.Resource_Class_Id
3030        From
3031 		Pa_Resource_Assignments a
3032 	       ,Pa_Resource_Classes_b c
3033        Where
3034 		c.Resource_Class_Code = a.Resource_Class_Code
3035        And      a.Resource_Assignment_Id = P_Res_Assignment_Id;
3036 
3037 
3038        l_Res_Attributes 	c_Res_Attributes%RowType;
3039        l_Person_Id 		Number;
3040        l_Job_Id 		Number;
3041        l_Inventory_Item_Id 	Number;
3042        l_Item_Category_Id 	Number;
3043        l_Non_Labor_Resource 	Varchar2(20);
3044        l_Bom_Resource_Id 	Number;
3045        l_Resource_Class_Id 	Number;
3046        l_Person_Type_Code 	Varchar2(30);
3047        l_Res_Type_Code 		Varchar2(30);
3048 
3049 Begin
3050 
3051 	If P_Res_Assignment_Id Is Not Null Then
3052 
3053       		Open c_Res_Attributes;
3054       		Fetch c_Res_Attributes Into l_Res_Attributes;
3055       		Close c_Res_Attributes;
3056 
3057            IF l_Res_Attributes.incurred_by_res_flag <> 'Y' THEN
3058       		l_Person_Id          := l_Res_Attributes.Person_Id;
3059       		l_Job_Id             := l_Res_Attributes.Job_Id;
3060       		l_Inventory_Item_Id  := l_Res_Attributes.Inventory_Item_Id;
3061      		l_Item_Category_Id   := l_Res_Attributes.Item_Category_Id;
3062       		l_Bom_Resource_Id    := l_Res_Attributes.Bom_Resource_Id;
3063       		l_Resource_Class_Id  := l_Res_Attributes.Resource_Class_Id;
3064       		l_Non_Labor_Resource := l_Res_Attributes.Non_Labor_Resource;
3065       		l_Person_Type_Code   := l_Res_Attributes.Person_Type_Code;
3066       		l_Res_Type_Code      := l_Res_Attributes.Res_Type_Code;
3067            ELSE
3068                 X_Resource_Displayed := NULL;
3069                 RETURN; -- added to not do anything for incurred by resources
3070            END IF;
3071 
3072 	Else
3073 
3074       		l_Person_Id          := P_Person_Id;
3075       		l_Job_Id             := P_Job_Id;
3076       		l_Inventory_Item_Id  := P_Inventory_Item_Id;
3077       		l_Item_Category_Id   := P_Item_Category_Id;
3078       		l_Bom_Resource_Id    := P_Bom_Resource_Id;
3079       		l_Resource_Class_Id  := P_Resource_Class_Id;
3080       		l_Non_Labor_Resource := P_Non_Labor_Resource;
3081       		l_Person_Type_Code   := P_Person_Type_Code;
3082       		l_Res_Type_Code      := P_Res_Type_Code;
3083 
3084 	End If;
3085 
3086 	If l_Res_Type_Code = 'NAMED_PERSON' Then
3087 
3088 		If l_Person_Id is Not Null Then
3089 
3090 			Open c_People(P_Person_Id => l_Person_Id);
3091 			Fetch c_People Into l_Res_Type_Displayed;
3092 			If c_People%NotFound Then
3093 				Close c_People;
3094 				--Raise BAD_PER_IN_RES_LIST_MEM;
3095 				Raise UNEXPEC_ERROR;
3096 			End If;
3097 			Close c_People;
3098 
3099 		Else
3100 
3101 			--Raise NULL_PER_IN_RES_LIST_MEM;
3102 			Raise UNEXPEC_ERROR;
3103 
3104 		End If;
3105 
3106 	ElsIf l_Res_Type_Code = 'JOB' Then
3107 
3108 		If l_Job_Id is Not Null Then
3109 
3110 			Open c_Job(P_Job_Id => l_Job_Id);
3111 			Fetch c_Job Into l_Res_Type_Displayed;
3112 			If c_Job%NOTFOUND Then
3113 				Close c_job;
3114 				--Raise BAD_JOB_IN_RES_LIST_MEM;
3115 				Raise UNEXPEC_ERROR;
3116 			End If;
3117 			Close c_Job;
3118 
3119 		Else
3120 
3121 			--Raise NULL_JOB_IN_RES_LIST_MEM;
3122 			Raise UNEXPEC_ERROR;
3123 
3124 		End If;
3125 
3126 	ElsIf l_Res_Type_Code = 'PERSON_TYPE' Then
3127 
3128 		If l_Person_Type_Code is Not Null Then
3129 
3130 			-- CWK, EMP
3131 			-- Get meaning from fnd_common_lookups
3132 			Open c_PersonType(P_Person_Type => l_Person_Type_Code);
3133 			Fetch c_PersonType Into l_Res_Type_Displayed;
3134 			If c_PersonType%NOTFOUND Then
3135 				Close c_PersonType;
3136 				--Raise BAD_PER_TYPE_IN_LIST_MEM;
3137 				Raise UNEXPEC_ERROR;
3138 			End If;
3139 			Close c_PersonType;
3140 
3141 		Else
3142 
3143 			--Raise NULL_PER_TYPE_IN_LIST_MEM;
3144 			Raise UNEXPEC_ERROR;
3145 
3146 		End If;
3147 
3148 	ElsIf l_Res_Type_Code = 'BOM_LABOR' Then
3149 
3150 		If l_Bom_Resource_Id is Not Null Then
3151 
3152 			Open c_BOM(P_BOM_Res_Id => l_Bom_Resource_Id);
3153 			Fetch c_BOM into l_Res_Type_Displayed;
3154 
3155 			If c_BOM%NotFound Then
3156 
3157 				Close c_BOM;
3158 				Raise BAD_BOM_LABOR_RES_IN_LST_MEM;
3159 
3160 			End If;
3161 
3162 			Close c_BOM;
3163 
3164 		Else
3165 
3166 			Raise NULL_BOM_LABOR_RES_IN_LST_MEM;
3167 
3168 		End If;
3169 
3170 
3171 	ElsIf l_Res_Type_Code = 'BOM_EQUIPMENT' Then
3172 
3173 		If l_Bom_Resource_Id is Not Null Then
3174 
3175 			Open c_BOM(P_BOM_Res_Id => l_Bom_Resource_Id);
3176 			Fetch c_BOM into l_Res_Type_Displayed;
3177 
3178 			If c_BOM%NotFound Then
3179 
3180 				Close c_BOM;
3181 				Raise BAD_BOM_EQUIP_RES_IN_LST_MEM;
3182 
3183 			End If;
3184 
3185 			Close c_BOM;
3186 
3187 		Else
3188 
3189 			Raise NULL_BOM_EQUIP_RES_IN_LST_MEM;
3190 
3191 		End If;
3192 
3193 	ElsIf l_Res_Type_Code = 'ITEM_CATEGORY' Then
3194 
3195 		If l_Item_Category_Id is Not Null Then
3196 
3197 			Open c_Item_Cat(P_Item_Cat_Id => l_Item_Category_Id);
3198 			Fetch c_Item_Cat into l_Res_Type_Displayed;
3199 
3200 			If c_Item_Cat%NotFound Then
3201 
3202 				Close c_Item_Cat;
3203 				Raise BAD_ITEM_CAT_IN_LST_MEM;
3204 
3205 			End If;
3206 
3207 			Close c_Item_Cat;
3208 
3209 		Else
3210 
3211 			Raise NULL_ITEM_CAT_IN_LST_MEM;
3212 
3213 		End If;
3214 
3215 	ElsIf l_Res_Type_Code = 'INVENTORY_ITEM' Then
3216 
3217 		If l_Inventory_Item_Id is Not Null Then
3218 
3219 			Open c_Inven_Item(P_Inven_Item_Id => l_Inventory_Item_Id);
3220 			Fetch c_Inven_Item into l_Res_Type_Displayed;
3221 
3222 			If c_Inven_Item%NotFound Then
3223 
3224 				Close c_Inven_Item;
3225 				Raise BAD_INVEN_ITEM_IN_LST_MEM;
3226 
3227 			End If;
3228 
3229 			Close c_Inven_Item;
3230 
3231 		Else
3232 
3233 			Raise NULL_INVEN_ITEM_IN_LST_MEM;
3234 
3235 		End If;
3236 
3237 	ElsIf l_Res_Type_Code = 'NON_LABOR_RESOURCE' Then
3238 
3239 		If l_Non_Labor_Resource is Not Null Then
3240 
3241 			l_Res_Type_Displayed := l_Non_Labor_Resource;
3242 
3243 		Else
3244 
3245 			--Raise NULL_NLR_IN_LIST_MEM;
3246 			Raise UNEXPEC_ERROR;
3247 
3248 		End If;
3249 
3250 	ElsIf l_Res_Type_Code = 'RESOURCE_CLASS' Then
3251 
3252 		If l_Resource_Class_Id is Not Null Then
3253 
3254 			-- get name from pa_resource_classes_vl
3255 			Open c_ResClass(P_Res_Class_Id => l_Resource_Class_Id);
3256 			Fetch c_ResClass into l_Res_Type_Displayed;
3257 			If c_ResClass%NOTFOUND Then
3258 
3259 				Close c_ResClass;
3260 				--Raise BAD_RESCLASS_IN_LIST_MEM;
3261 				Raise UNEXPEC_ERROR;
3262 
3263 			End If;
3264 			Close c_ResClass;
3265 
3266 		Else
3267 
3268 			--Raise NULL_RESCLASS_IN_LIST_MEM;
3269 			Raise UNEXPEC_ERROR;
3270 
3271 		End If;
3272 
3273 	End If;
3274 
3275 	X_Return_Status           := Fnd_Api.G_Ret_Sts_Success;
3276 	X_Msg_Data                := Null;
3277 	X_Resource_Displayed	  := l_Res_Type_Displayed;
3278 
3279   Exception
3280         When UNEXPEC_ERROR THEN
3281               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
3282               --x_msg_count := x_msg_count + 1;
3283               x_msg_data := Null;
3284               Fnd_Msg_Pub.Add_Exc_Msg(
3285                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
3286                         P_Procedure_Name   => 'Get_Resource_Name');
3287 
3288               Return;
3289      /*	When NULL_PER_IN_RES_LIST_MEM Then
3290 		If P_Proc_Func_Flag = 'P' Then
3291 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3292 			X_Msg_Data		:= 'PA_NULL_PER_IN_RES_LIST_MEM';
3293 			Pa_Utils.Add_Message
3294                			(P_App_Short_Name  => 'PA',
3295                 		 P_Msg_Name        => 'PA_NULL_PER_IN_RES_LIST_MEM');
3296 		Else
3297 
3298 			X_Resource_Displayed := Null;
3299 
3300 		End If;*/
3301 	/*When BAD_PER_IN_RES_LIST_MEM Then
3302 		If P_Proc_Func_Flag = 'P' Then
3303 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3304 			X_Msg_Data		:= 'PA_BAD_PER_IN_RES_LIST_MEM';
3305 			Pa_Utils.Add_Message
3306 	               		(P_App_Short_Name  => 'PA',
3307         	        	 P_Msg_Name        => 'PA_BAD_PER_IN_RES_LIST_MEM');
3308 		Else
3309 
3310 			X_Resource_Displayed := Null;
3311 
3312 		End If;*/
3313 
3314 	/*When NULL_JOB_IN_RES_LIST_MEM Then
3315 		If P_Proc_Func_Flag = 'P' Then
3316 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3317 			X_Msg_Data		:= 'PA_NULL_JOB_IN_RES_LIST_MEM';
3318 			Pa_Utils.Add_Message
3319         	       		(P_App_Short_Name  => 'PA',
3320                 		 P_Msg_Name        => 'PA_NULL_JOB_IN_RES_LIST_MEM');
3321 		Else
3322 			X_Resource_Displayed := Null;
3323 		End If;*/
3324 	/*When BAD_JOB_IN_RES_LIST_MEM Then
3325 		If P_Proc_Func_Flag = 'P' Then
3326 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3327 			X_Msg_Data		:= 'PA_BAD_JOB_IN_RES_LIST_MEM';
3328 			Pa_Utils.Add_Message
3329         	       		(P_App_Short_Name  => 'PA',
3330                 		 P_Msg_Name        => 'PA_BAD_JOB_IN_RES_LIST_MEM');
3331 		Else
3332 			X_Resource_Displayed := Null;
3333 		End If;*/
3334 	/*When NULL_PER_TYPE_IN_LIST_MEM Then
3335 		If P_Proc_Func_Flag = 'P' Then
3336 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3337 			X_Msg_Data		:= 'PA_NULL_PER_TYPE_IN_LIST_MEM';
3338 			Pa_Utils.Add_Message
3339         	       		(P_App_Short_Name  => 'PA',
3340 	                	 P_Msg_Name        => 'PA_NULL_PER_TYPE_IN_LIST_MEM');
3341 		Else
3342 			X_Resource_Displayed := Null;
3343 		End If;*/
3344 	/*When BAD_PER_TYPE_IN_LIST_MEM Then
3345 		If P_Proc_Func_Flag = 'P' Then
3346 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3347 			X_Msg_Data		:= 'PA_BAD_PER_TYPE_IN_LIST_MEM';
3348 			Pa_Utils.Add_Message
3349 	        		(P_App_Short_Name  => 'PA',
3350         	        	 P_Msg_Name        => 'PA_BAD_PER_TYPE_IN_LIST_MEM');
3351 		Else
3352 			X_Resource_Displayed := Null;
3353 		End If;*/
3354 	When BAD_BOM_LABOR_RES_IN_LST_MEM Then
3355 		If P_Proc_Func_Flag = 'P' Then
3356 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3357 			X_Msg_Data		:= 'PA_BAD_BOM_LABOR_RES_LIST_MEM';
3358 			Pa_Utils.Add_Message
3359 	               		(P_App_Short_Name  => 'PA',
3360 	                	 P_Msg_Name        => 'PA_BAD_BOM_LABOR_RES_LIST_MEM');
3361 		Else
3362 			X_Resource_Displayed := Null;
3363 		End If;
3364 	When NULL_BOM_LABOR_RES_IN_LST_MEM Then
3365 		If P_Proc_Func_Flag = 'P' Then
3366 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3367 			X_Msg_Data		:= 'PA_NULL_BOM_LABOR_RES_LIST_MEM';
3368 			Pa_Utils.Add_Message
3369 	               		(P_App_Short_Name  => 'PA',
3370 	                	 P_Msg_Name        => 'PA_NULL_BOM_LABOR_RES_LIST_MEM');
3371 		Else
3372 			X_Resource_Displayed := Null;
3373 		End If;
3374 	When BAD_BOM_EQUIP_RES_IN_LST_MEM Then
3375 		If P_Proc_Func_Flag = 'P' Then
3376 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3377 			X_Msg_Data		:= 'PA_BAD_BOMEQUIP_RES_IN_LST_MEM';
3378 			Pa_Utils.Add_Message
3379 	               		(P_App_Short_Name  => 'PA',
3380 	                	 P_Msg_Name        => 'PA_BAD_BOMEQUIP_RES_IN_LST_MEM');
3381 		Else
3382 			X_Resource_Displayed := Null;
3383 		End If;
3384 	When NULL_BOM_EQUIP_RES_IN_LST_MEM Then
3385 		If P_Proc_Func_Flag = 'P' Then
3386 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3387 			X_Msg_Data		:= 'PA_NULL_BOM_EQUIP_RES_LIST_MEM';
3388 			Pa_Utils.Add_Message
3389 	               		(P_App_Short_Name  => 'PA',
3390 	                	 P_Msg_Name        => 'PA_NULL_BOM_EQUIP_RES_LIST_MEM');
3391 		Else
3392 			X_Resource_Displayed := Null;
3393 		End If;
3394 	When BAD_ITEM_CAT_IN_LST_MEM Then
3395 		If P_Proc_Func_Flag = 'P' Then
3396 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3397 			X_Msg_Data		:= 'PA_BAD_ITEM_CAT_IN_LST_MEM';
3398 			Pa_Utils.Add_Message
3399 	               		(P_App_Short_Name  => 'PA',
3400 	                	 P_Msg_Name        => 'PA_BAD_ITEM_CAT_IN_LST_MEM');
3401 		Else
3402 			X_Resource_Displayed := Null;
3403 		End If;
3404 	When NULL_ITEM_CAT_IN_LST_MEM Then
3405 		If P_Proc_Func_Flag = 'P' Then
3406 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3407 			X_Msg_Data		:= 'PA_NULL_ITEM_CAT_IN_LST_MEM';
3408 			Pa_Utils.Add_Message
3409 	               		(P_App_Short_Name  => 'PA',
3410 	                	 P_Msg_Name        => 'PA_NULL_ITEM_CAT_IN_LST_MEM');
3411 		Else
3412 			X_Resource_Displayed := Null;
3413 		End If;
3414 	When BAD_INVEN_ITEM_IN_LST_MEM Then
3415 		If P_Proc_Func_Flag = 'P' Then
3416 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3417 			X_Msg_Data		:= 'PA_BAD_INVEN_ITEM_IN_LST_MEM';
3418 			Pa_Utils.Add_Message
3419 	               		(P_App_Short_Name  => 'PA',
3420 	                	 P_Msg_Name        => 'PA_BAD_INVEN_ITEM_IN_LST_MEM');
3421 		Else
3422 			X_Resource_Displayed := Null;
3423 		End If;
3424 	When NULL_INVEN_ITEM_IN_LST_MEM Then
3425 		If P_Proc_Func_Flag = 'P' Then
3426 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3427 			X_Msg_Data		:= 'PA_NULL_INVEN_ITEM_IN_LST_MEM';
3428 			Pa_Utils.Add_Message
3429 	               		(P_App_Short_Name  => 'PA',
3430 	                	 P_Msg_Name        => 'PA_NULL_INVEN_ITEM_IN_LST_MEM');
3431 		Else
3432 			X_Resource_Displayed := Null;
3433 		End If;
3434 	/*When NULL_NLR_IN_LIST_MEM Then
3435 		If P_Proc_Func_Flag = 'P' Then
3436 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3437 			X_Msg_Data		:= 'PA_NULL_NLR_IN_LIST_MEM';
3438 			Pa_Utils.Add_Message
3439 	               		(P_App_Short_Name  => 'PA',
3440 	                	 P_Msg_Name        => 'PA_NULL_NLR_IN_LIST_MEM');
3441 		Else
3442 			X_Resource_Displayed := Null;
3443 		End If;*/
3444 	/*When NULL_RESCLASS_IN_LIST_MEM Then
3445 		If P_Proc_Func_Flag = 'P' Then
3446 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3447 			X_Msg_Data		:= 'PA_NULL_RESCLASS_IN_LIST_MEM';
3448 			Pa_Utils.Add_Message
3449 	               		(P_App_Short_Name  => 'PA',
3450 	                	 P_Msg_Name        => 'PA_NULL_RESCLASS_IN_LIST_MEM');
3451 		Else
3452 			X_Resource_Displayed := Null;
3453 		End If;*/
3454 	/*When BAD_RESCLASS_IN_LIST_MEM Then
3455 		If P_Proc_Func_Flag = 'P' Then
3456 			X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
3457 			X_Msg_Data		:= 'PA_BAD_RESCLASS_IN_LIST_MEM';
3458 			Pa_Utils.Add_Message
3459 	               		(P_App_Short_Name  => 'PA',
3460 	                	 P_Msg_Name        => 'PA_BAD_RESCLASS_IN_LIST_MEM');
3461 		Else
3462 			X_Resource_Displayed := Null;
3463 		End If;*/
3464 	When Others Then
3465 		Raise;
3466 
3467   End Get_Resource_Name;
3468 /**************************************************/
3469  /***********************************************************
3470  *Type (Procedure or Procedure): Function
3471  *Package Object Name:           Ret_Fin_Category_Name
3472  *Purpose:                       Return the resource name from a given
3473  *    				  resource type code.
3474  *Public or Private API?
3475  **************************************************************/
3476   Function Ret_Fin_Category_Name ( P_FC_Res_Type_Code      IN Varchar2,
3477 			           P_Expenditure_Type      IN Varchar2,
3478 			           P_Expenditure_Category  IN Varchar2,
3479 			           P_Event_Type            IN Varchar2,
3480 			           P_Revenue_Category_Code IN Varchar2,
3481                                    p_res_assignment_id  IN NUMBER default null) Return Varchar2
3482   Is
3483 
3484 	l_Return_Status     Varchar2(1)    := Null;
3485 	l_Msg_Data	    Varchar2(30)   := Null;
3486 	l_Fin_Cat_Displayed Varchar2(80)   := Null;
3487 
3488   Begin
3489 
3490 	Pa_Planning_Resource_Utils.Get_Fin_Category_Name (
3491                 P_FC_Res_Type_Code      => P_FC_Res_Type_Code,
3492 	        P_Expenditure_Type      => P_Expenditure_Type,
3493 	        P_Expenditure_Category  => P_Expenditure_Category,
3494                 P_Event_Type            => P_Event_Type,
3495 	        P_Revenue_Category_Code => P_Revenue_Category_Code,
3496 	        P_Proc_Func_Flag        => 'F',
3497                 p_res_assignment_id     => p_res_assignment_id,
3498 	        X_Fin_Cat_Displayed     => l_Fin_Cat_Displayed,
3499  	        X_Return_Status         => l_Return_Status,
3500 	        X_Msg_Data              => l_Msg_Data );
3501 
3502 	Return l_Fin_Cat_Displayed;
3503 
3504   Exception
3505 	When Others Then
3506 		Raise;
3507 
3508   End Ret_Fin_Category_Name;
3509 
3510 
3511 /**************************************************************
3512  * Procedure : Get_Fin_Category_Name
3513  * ***********************************************************/
3514 
3515 Procedure Get_Fin_Category_Name ( P_FC_Res_Type_Code        IN Varchar2,
3516 			            P_Expenditure_Type      IN Varchar2,
3517 			            P_Expenditure_Category  IN Varchar2,
3518 			            P_Event_Type            IN Varchar2,
3519 			            P_Revenue_Category_Code IN Varchar2,
3520 			            P_Proc_Func_Flag        IN Varchar2,
3521                                     P_Res_Assignment_Id     IN NUMBER default null,
3522                                     X_Fin_Cat_Displayed    OUT NOCOPY Varchar2,
3523 		 	            X_Return_Status        OUT NOCOPY Varchar2,
3524 			            X_Msg_Data    	   OUT NOCOPY Varchar2 )
3525 
3526   Is
3527 
3528 	l_Fin_Cat_Displayed          Varchar2(80)   := Null;
3529 
3530 	--NULL_EXP_TYPE_IN_LIST_MEM    Exception;
3531 	--NULL_EXP_CAT_IN_LIST_MEM     Exception;
3532 	--NULL_EVENT_TYPE_IN_LIST_MEM  Exception;
3533 	--NULL_REV_CAT_IN_LIST_MEM     Exception;
3534 	--NULL_FC_RES_TYPE_IN_LIST_MEM Exception;
3535 	INV_FC_RES_TYPE_IN_LIST_MEM  Exception;
3536 	UNEXPEC_ERROR                Exception;
3537 
3538 	Cursor c_Res_Attributes
3539         Is
3540         Select
3541 		Fc_Res_Type_Code,
3542 		Expenditure_Type,
3543 		Expenditure_Category,
3544        		Event_Type,
3545 		Revenue_Category_Code
3546        	From
3547 		Pa_Resource_Assignments
3548        	Where
3549 		Resource_Assignment_Id = P_Res_Assignment_Id;
3550 
3551        l_Res_Attributes c_Res_Attributes%RowType;
3552        l_Fc_Res_Type_Code      Varchar2(30);
3553        l_Expenditure_Type      Varchar2(30);
3554        l_Expenditure_Category  Varchar2(30);
3555        l_Event_Type            Varchar2(30);
3556        l_Revenue_Category_Code Varchar2(30);
3557 
3558   Begin
3559 
3560 	If P_Res_Assignment_Id Is Not Null Then
3561 
3562       		Open c_Res_Attributes;
3563       		Fetch c_Res_Attributes Into l_Res_Attributes;
3564       		Close c_Res_Attributes;
3565 
3566       		l_Fc_Res_Type_Code      := l_Res_Attributes.Fc_Res_Type_Code;
3567       		l_Expenditure_Type      := l_Res_Attributes.Expenditure_Type;
3568       		l_Expenditure_Category  := l_Res_Attributes.Expenditure_Category;
3569       		l_Event_Type            := l_Res_Attributes.Event_Type;
3570       		l_Revenue_Category_Code := l_Res_Attributes.Revenue_Category_Code;
3571 
3572 	Else
3573 
3574       		l_Fc_Res_Type_Code      := P_Fc_Res_Type_Code;
3575      		l_Expenditure_Type      := P_Expenditure_Type;
3576       		l_Expenditure_Category  := P_Expenditure_Category;
3577       		l_Event_Type            := P_Event_Type;
3578       		l_Revenue_Category_Code := P_Revenue_Category_Code;
3579 
3580 	End If;
3581 
3582 	If l_FC_Res_Type_Code is Not Null Then
3583 
3584 		If l_FC_Res_Type_Code = 'EXPENDITURE_TYPE' Then
3585 
3586 			If l_Expenditure_Type is Not Null Then
3587 
3588 				l_Fin_Cat_Displayed := l_Expenditure_Type;
3589 
3590 			Else
3591 
3592 				--Raise NULL_EXP_TYPE_IN_LIST_MEM;
3593 				Raise UNEXPEC_ERROR;
3594 
3595 			End If;
3596 
3597 		ElsIf l_FC_Res_Type_Code = 'EXPENDITURE_CATEGORY' Then
3598 
3599 			If l_Expenditure_Category is Not Null Then
3600 
3601 				l_Fin_Cat_Displayed := l_Expenditure_Category;
3602 
3603 			Else
3604 
3605 				--Raise NULL_EXP_CAT_IN_LIST_MEM;
3606 				Raise UNEXPEC_ERROR;
3607 
3608 			End If;
3609 
3610 		ElsIf l_FC_Res_Type_Code = 'EVENT_TYPE' Then
3611 
3612 			If l_Event_Type is Not Null Then
3613 
3614 				l_Fin_Cat_Displayed := l_Event_Type;
3615 
3616 			Else
3617 
3618 				--Raise NULL_EVENT_TYPE_IN_LIST_MEM;
3619 				Raise UNEXPEC_ERROR;
3620 
3621 			End If;
3622 
3623 		ElsIf l_FC_Res_Type_Code = 'REVENUE_CATEGORY' Then
3624 
3625 			If l_Revenue_Category_Code is Not Null Then
3626 
3627                               BEGIN
3628 
3629                                  SELECT lk.Meaning
3630                                  INTO l_Fin_Cat_Displayed
3631                                  FROM PA_LOOKUPS lk
3632                                  WHERE lk.Lookup_Type = 'REVENUE CATEGORY'
3633                                  and lk.lookup_code = l_revenue_category_code;
3634 
3635                               EXCEPTION
3636                                  WHEN OTHERS THEN
3637                                     l_Fin_Cat_Displayed := NULL;
3638                                     --Raise NULL_REV_CAT_IN_LIST_MEM;
3639                                     Raise UNEXPEC_ERROR;
3640 
3641                               END;
3642 
3643 			Else
3644 
3645 				--Raise NULL_REV_CAT_IN_LIST_MEM;
3646 				Raise UNEXPEC_ERROR;
3647 
3648 			End If;
3649 
3650 		Else
3651 
3652 			Raise INV_FC_RES_TYPE_IN_LIST_MEM;
3653 
3654 		End If;
3655 
3656 	Else
3657 
3658 		--Raise NULL_FC_RES_TYPE_IN_LIST_MEM;
3659 		-- Raise UNEXPEC_ERROR;
3660                 -- Return null if resource/assignment does not have fin cat
3661                 l_Fin_Cat_Displayed := NULL;
3662 
3663 	End If; -- P_FC_Res_Type_Code is not null
3664 
3665 	X_Return_Status     := Fnd_Api.G_Ret_Sts_Success;
3666 	X_Msg_Data          := Null;
3667 	X_Fin_Cat_Displayed := l_Fin_Cat_Displayed;
3668 
3669   Exception
3670         When UNEXPEC_ERROR THEN
3671               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
3672               --x_msg_count := x_msg_count + 1;
3673               x_msg_data := Null;
3674               Fnd_Msg_Pub.Add_Exc_Msg(
3675                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
3676                         P_Procedure_Name   => 'Get_Fin_Category_Name');
3677               Return;
3678 	/*When NULL_FC_RES_TYPE_IN_LIST_MEM Then
3679 
3680 		If P_Proc_Func_Flag = 'P' Then
3681 
3682 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3683 			X_Msg_Data	:= 'PA_NULL_FC_RESTYPE_IN_LIST_MEM';
3684 			Pa_Utils.Add_Message
3685 	               		(P_App_Short_Name  => 'PA',
3686 	                	 P_Msg_Name        => 'PA_NULL_FC_RESTYPE_IN_LIST_MEM');
3687 		Else
3688 
3689 			X_Fin_Cat_Displayed := Null;
3690 
3691 		End If;*/
3692 
3693 	/*When NULL_EXP_TYPE_IN_LIST_MEM Then
3694 
3695 		If P_Proc_Func_Flag = 'P' Then
3696 
3697 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3698 			X_Msg_Data	:= 'PA_NULL_EXP_TYPE_IN_LIST_MEM';
3699 			Pa_Utils.Add_Message
3700 	               		(P_App_Short_Name  => 'PA',
3701 	                	 P_Msg_Name        => 'PA_NULL_EXP_TYPE_IN_LIST_MEM');
3702 
3703 		Else
3704 
3705 			X_Fin_Cat_Displayed := Null;
3706 
3707 		End If;*/
3708 
3709 	/*When NULL_EXP_CAT_IN_LIST_MEM Then
3710 
3711 		If P_Proc_Func_Flag = 'P' Then
3712 
3713 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3714 			X_Msg_Data	:= 'PA_NULL_EXP_CAT_IN_LIST_MEM';
3715 			Pa_Utils.Add_Message
3716         	       		(P_App_Short_Name  => 'PA',
3717 	                	 P_Msg_Name        => 'PA_NULL_EXP_CAT_IN_LIST_MEM');
3718 
3719 		Else
3720 
3721 			X_Fin_Cat_Displayed := Null;
3722 
3723 		End If;*/
3724 
3725 	/*When NULL_EVENT_TYPE_IN_LIST_MEM Then
3726 
3727 		If P_Proc_Func_Flag = 'P' Then
3728 
3729 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3730 			X_Msg_Data	:= 'PA_NULL_EVENT_TYPE_IN_LIST_MEM';
3731 			Pa_Utils.Add_Message
3732 	               		(P_App_Short_Name  => 'PA',
3733 	                	 P_Msg_Name        => 'PA_NULL_EVENT_TYPE_IN_LIST_MEM');
3734 
3735 		Else
3736 
3737 			X_Fin_Cat_Displayed := Null;
3738 
3739 		End If;*/
3740 
3741 	/*When NULL_REV_CAT_IN_LIST_MEM Then
3742 
3743 		If P_Proc_Func_Flag = 'P' Then
3744 
3745 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3746 			X_Msg_Data	:= 'PA_NULL_REV_CAT_IN_LIST_MEM';
3747 			Pa_Utils.Add_Message
3748 	               		(P_App_Short_Name  => 'PA',
3749 	                	 P_Msg_Name        => 'PA_NULL_REV_CAT_IN_LIST_MEM');
3750 
3751 		Else
3752 
3753 			X_Fin_Cat_Displayed := Null;
3754 
3755 		End If;*/
3756 
3757 	When INV_FC_RES_TYPE_IN_LIST_MEM Then
3758 
3759 		If P_Proc_Func_Flag = 'P' Then
3760 
3761 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3762 			X_Msg_Data	:= 'PA_INV_FC_RESTYPE_IN_LIST_MEM';
3763 			Pa_Utils.Add_Message
3764 	               		(P_App_Short_Name  => 'PA',
3765 	                	 P_Msg_Name        => 'PA_INV_FC_RESTYPE_IN_LIST_MEM');
3766 
3767 		Else
3768 
3769 			X_Fin_Cat_Displayed := Null;
3770 
3771 		End If;
3772 
3773 	When Others Then
3774 		Raise;
3775 
3776   End Get_Fin_Category_Name;
3777 
3778 /**************************************************/
3779 
3780 /********************************************************
3781  * Function : Ret_Organization_Name
3782  * ********************************************************/
3783 Function Ret_Organization_Name ( P_Organization_Id IN Number ) Return Varchar2
3784 
3785   Is
3786 
3787 	l_Return_Status     Varchar2(1)   := Null;
3788 	l_Msg_Data	    Varchar2(30)  := Null;
3789 	l_Organization_Name Varchar2(240) := Null;
3790 
3791   Begin
3792 
3793 	pa_planning_resource_utils.Get_Organization_Name (
3794                                 P_Organization_Id => P_Organization_Id,
3795 				P_Proc_Func_Flag  => 'F',
3796 				X_Org_Displayed   => l_Organization_Name,
3797 		 		X_Return_Status   => l_Return_Status,
3798 				X_Msg_Data        => l_Msg_Data );
3799 
3800 	Return l_Organization_Name;
3801 
3802   Exception
3803 	When Others Then
3804 		Raise;
3805 
3806   End Ret_Organization_Name;
3807 /*************************************/
3808 /********************************************************
3809  * Procedure : Get_Organization_name
3810  * *****************************************************/
3811  Procedure Get_Organization_Name ( P_Organization_Id IN Number,
3812 				    P_Proc_Func_Flag  IN Varchar2,
3813 				    X_Org_Displayed  OUT NOCOPY Varchar2,
3814 		 		    X_Return_Status  OUT NOCOPY Varchar2,
3815 				    X_Msg_Data       OUT NOCOPY Varchar2 )
3816 
3817   Is
3818 
3819 	l_Org_Displayed        Varchar2(240)  := Null;
3820 
3821 	--BAD_ORG_ID_IN_LIST_MEM  Exception;
3822 	--NULL_ORG_ID_IN_LIST_MEM Exception;
3823 	UNEXPEC_ERROR           Exception;
3824 
3825   Begin
3826 
3827 	If P_Organization_Id is Not Null Then
3828 
3829 		-- Get organization name from hr_all_organization_units_tl
3830 		Begin
3831 
3832 			l_Org_Displayed := Pa_Expenditures_Utils.GetOrgTlName(P_Organization_Id);
3833 
3834 		Exception
3835 			When Others Then
3836 				--Raise BAD_ORG_ID_IN_LIST_MEM;
3837 				Raise UNEXPEC_ERROR;
3838 		End;
3839 
3840 	Else
3841 
3842 		--Raise NULL_ORG_ID_IN_LIST_MEM;
3843 		-- Raise UNEXPEC_ERROR;
3844                 l_Org_Displayed := NULL;
3845 
3846 	End If;
3847 
3848 	X_Return_Status := Fnd_Api.G_Ret_Sts_Success;
3849 	X_Msg_Data      := Null;
3850 	X_Org_Displayed := l_Org_Displayed;
3851 
3852   Exception
3853         When UNEXPEC_ERROR THEN
3854               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
3855               --x_msg_count := x_msg_count + 1;
3856               x_msg_data := Null;
3857               Fnd_Msg_Pub.Add_Exc_Msg(
3858                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
3859                         P_Procedure_Name   => 'Get_Organization_Name');
3860               Return;
3861 	/*When NULL_ORG_ID_IN_LIST_MEM Then
3862 
3863 		If P_Proc_Func_Flag = 'P' Then
3864 
3865 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3866 			X_Msg_Data	:= 'PA_NULL_ORG_ID_IN_LIST_MEM';
3867 			Pa_Utils.Add_Message
3868         	       		(P_App_Short_Name  => 'PA',
3869                 		 P_Msg_Name        => 'PA_NULL_ORG_ID_IN_LIST_MEM');
3870 
3871 		Else
3872 
3873 			X_Org_Displayed := Null;
3874 
3875 		End If;*/
3876 
3877 	/*When BAD_ORG_ID_IN_LIST_MEM Then
3878 
3879 		If P_Proc_Func_Flag = 'P' Then
3880 
3881 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3882 			X_Msg_Data	:= 'PA_BAD_ORG_ID_IN_LIST_MEM';
3883 			Pa_Utils.Add_Message
3884         	       		(P_App_Short_Name  => 'PA',
3885                 		 P_Msg_Name        => 'PA_BAD_ORG_ID_IN_LIST_MEM');
3886 
3887 		Else
3888 
3889 			X_Org_Displayed := Null;
3890 
3891 		End If;*/
3892 
3893 	When Others Then
3894 		Raise;
3895 
3896   End Get_Organization_Name;
3897 /***************************************/
3898 
3899 /******************************************************************
3900  * Function : Ret_Supplier_Name
3901  * ****************************************************************/
3902 
3903   Function Ret_Supplier_Name ( P_Supplier_Id IN Number ) Return Varchar2
3904 
3905   Is
3906 
3907 	l_Return_Status Varchar2(1)   := Null;
3908 	l_Msg_Data	Varchar2(30)  := Null;
3909 	l_Supplier_Name Varchar2(240) := Null;
3910 
3911   Begin
3912 
3913 	Pa_Planning_Resource_Utils.Get_Supplier_Name(
3914         	P_Supplier_Id        => P_Supplier_Id,
3915 		P_Proc_Func_Flag     => 'F',
3916 		X_Supplier_Displayed => l_Supplier_Name,
3917 		X_Return_Status      => l_Return_Status,
3918 		X_Msg_Data           => l_Msg_Data );
3919 
3920 
3921 	Return l_Supplier_Name;
3922 
3923   Exception
3924 	When Others Then
3925 		Raise;
3926 
3927   End Ret_Supplier_Name;
3928 /*********************************/
3929 
3930 /***************************************************
3931  * Procedure : Get_Supplier_Name
3932  * *************************************************/
3933    Procedure Get_Supplier_Name ( P_Supplier_Id         IN Number,
3934 				P_Proc_Func_Flag      IN Varchar2,
3935 				X_Supplier_Displayed OUT NOCOPY Varchar2,
3936 		 		X_Return_Status      OUT NOCOPY Varchar2,
3937 				X_Msg_Data    	      OUT NOCOPY Varchar2 )
3938 
3939   Is
3940 
3941 	l_Supplier_Displayed  Varchar2(240)  := Null;
3942 
3943 	--BAD_VEND_IN_LIST_MEM  Exception;
3944 	--NULL_VEND_IN_LIST_MEM Exception;
3945 	UNEXPEC_ERROR         Exception;
3946 
3947 	Cursor c_Supplier (P_Vendor_Id IN Number) Is
3948 	Select
3949 		Vendor_Name
3950 	From
3951 		Po_Vendors
3952 	Where
3953 		Vendor_id = P_Vendor_Id;
3954 
3955   Begin
3956 
3957 	If P_Supplier_Id is Not Null Then
3958 
3959 		Open c_Supplier(P_Vendor_Id => P_Supplier_Id);
3960 		Fetch c_Supplier Into l_Supplier_Displayed;
3961 		If c_Supplier%NOTFOUND Then
3962 
3963 			Close c_Supplier;
3964 			--Raise BAD_VEND_IN_LIST_MEM;
3965 			Raise UNEXPEC_ERROR;
3966 
3967 		End If;
3968 		Close c_Supplier;
3969 
3970 	Else
3971 
3972 		--Raise NULL_VEND_IN_LIST_MEM;
3973 		--Raise UNEXPEC_ERROR;
3974                 l_Supplier_Displayed := NULL;
3975 
3976 	End If;
3977 
3978 	X_Return_Status      := Fnd_Api.G_Ret_Sts_Success;
3979 	X_Msg_Data           := Null;
3980 	X_Supplier_Displayed := l_Supplier_Displayed;
3981 
3982   Exception
3983         When UNEXPEC_ERROR THEN
3984               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
3985               --x_msg_count := x_msg_count + 1;
3986               x_msg_data := Null;
3987               Fnd_Msg_Pub.Add_Exc_Msg(
3988                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
3989                         P_Procedure_Name   => 'Get_Supplier_Name');
3990               Return;
3991 	/*When NULL_VEND_IN_LIST_MEM Then
3992 
3993 		If P_Proc_Func_Flag = 'P' Then
3994 
3995 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
3996 			X_Msg_Data	:= 'PA_NULL_VEND_IN_LIST_MEM';
3997 			Pa_Utils.Add_Message
3998         	       		(P_App_Short_Name  => 'PA',
3999                 		 P_Msg_Name        => 'PA_NULL_VEND_IN_LIST_MEM');
4000 
4001 		Else
4002 
4003 			X_Supplier_Displayed := Null;
4004 
4005 		End If;*/
4006 
4007 	/*When BAD_VEND_IN_LIST_MEM Then
4008 
4009 		If P_Proc_Func_Flag = 'P' Then
4010 
4011 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4012 			X_Msg_Data	:= 'PA_BAD_VEND_IN_LIST_MEM';
4013 			Pa_Utils.Add_Message
4014         	       		(P_App_Short_Name  => 'PA',
4015                 		 P_Msg_Name        => 'PA_BAD_VEND_IN_LIST_MEM');
4016 
4017 		Else
4018 
4019 			X_Supplier_Displayed := Null;
4020 
4021 		End If;*/
4022 
4023 	When Others Then
4024 		Raise;
4025 
4026   End Get_Supplier_Name;
4027 /******************************************/
4028 
4029 /***********************************************************
4030  * Function  : Ret_Role_Name
4031  * *********************************************************/
4032   Function Ret_Role_Name ( P_Role_Id IN Number ) Return Varchar2
4033 
4034   Is
4035 
4036 	l_Return_Status Varchar2(1)  := Null;
4037 	l_Msg_Data	Varchar2(30) := Null;
4038 	l_Role_Name     Varchar2(80) := Null;
4039 
4040   Begin
4041 
4042 	Pa_Planning_Resource_Utils.Get_Role_Name(
4043                         P_Role_Id        => P_Role_Id,
4044 			P_Proc_Func_Flag => 'F',
4045 			X_Role_Displayed => l_Role_Name,
4046 		 	X_Return_Status  => l_Return_Status,
4047 			X_Msg_Data       => l_Msg_Data );
4048 
4049 
4050 	Return l_Role_Name;
4051 
4052   Exception
4053 	When Others Then
4054 		Raise;
4055 
4056   End Ret_Role_Name;
4057 /******************************************/
4058 
4059 /******************************************************
4060  * Procedure : Get_Role_Name
4061  * ****************************************************/
4062   Procedure Get_Role_Name ( P_Role_Id         IN Number,
4063 			    P_Proc_Func_Flag  IN Varchar2,
4064 			    X_Role_Displayed OUT NOCOPY Varchar2,
4065 		 	    X_Return_Status  OUT NOCOPY Varchar2,
4066 			    X_Msg_Data       OUT NOCOPY Varchar2 )
4067   Is
4068 
4069 	l_Role_Displayed      Varchar2(80);
4070 
4071 	--BAD_ROLE_IN_LIST_MEM  Exception;
4072 	--NULL_ROLE_IN_LIST_MEM Exception;
4073 	UNEXPEC_ERROR         Exception;
4074 
4075 	Cursor c_PrjRoles (P_Prj_Role_Id IN Number) Is
4076 	Select
4077 		Meaning
4078 	From
4079 		Pa_Project_Role_Types_vl
4080 	Where
4081 		Project_Role_Id = P_Prj_Role_Id;
4082 
4083   Begin
4084 
4085 	If P_Role_Id is Not Null Then
4086 
4087 		-- Get role from pa_project_role_types_vl
4088 		Open c_PrjRoles(P_Prj_Role_Id => P_Role_Id);
4089 		Fetch c_PrjRoles Into l_Role_Displayed;
4090 
4091 		If c_PrjRoles%NOTFOUND Then
4092 
4093 			Close c_PrjRoles;
4094 			--Raise BAD_ROLE_IN_LIST_MEM;
4095 			Raise UNEXPEC_ERROR;
4096 
4097 		End If;
4098 
4099 		Close c_PrjRoles;
4100 
4101 	Else
4102 
4103 		--Raise NULL_ROLE_IN_LIST_MEM;
4104 		--Raise UNEXPEC_ERROR;
4105                 l_Role_Displayed := NULL;
4106 
4107 	End If;
4108 
4109 	X_Return_Status  := Fnd_Api.G_Ret_Sts_Success;
4110 	X_Msg_Data       := Null;
4111 	X_Role_Displayed := l_Role_Displayed;
4112 
4113   Exception
4114         When UNEXPEC_ERROR THEN
4115               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
4116               --x_msg_count := x_msg_count + 1;
4117               x_msg_data := Null;
4118               Fnd_Msg_Pub.Add_Exc_Msg(
4119                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
4120                         P_Procedure_Name   => 'Get_Role_Name');
4121               Return;
4122 	/*When NULL_ROLE_IN_LIST_MEM Then
4123 
4124 		If P_Proc_Func_Flag = 'P' Then
4125 
4126 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4127 			X_Msg_Data	:= 'PA_NULL_ROLE_IN_LIST_MEM';
4128 			Pa_Utils.Add_Message
4129         	       		(P_App_Short_Name  => 'PA',
4130                 		 P_Msg_Name        => 'PA_NULL_ROLE_IN_LIST_MEM');
4131 
4132 		Else
4133 
4134 			X_Role_Displayed := Null;
4135 
4136 		End If;*/
4137 
4138 	/*When BAD_ROLE_IN_LIST_MEM Then
4139 
4140 		If P_Proc_Func_Flag = 'P' Then
4141 
4142 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4143 			X_Msg_Data	:= 'PA_BAD_ROLE_IN_LIST_MEM';
4144 			Pa_Utils.Add_Message
4145         	       		(P_App_Short_Name  => 'PA',
4146                 		 P_Msg_Name        => 'PA_BAD_ROLE_IN_LIST_MEM');
4147 
4148 		Else
4149 
4150 			X_Role_Displayed := Null;
4151 
4152 		End If;*/
4153 
4154 	When Others Then
4155 		Raise;
4156 
4157   End Get_Role_Name;
4158 /***********************************************/
4159 
4160 /**********************************************************
4161  * Function : Ret_Incur_By_Res_Name
4162  * *********************************************************/
4163 Function Ret_Incur_By_Res_Name ( P_Person_Id 	           IN Number,
4164 			           P_Job_Id    	           IN Number,
4165 			           P_Incur_By_Role_Id      IN Number,
4166 			           P_Person_Type_Code      IN Varchar2,
4167 			           P_Inc_By_Res_Class_Code IN Varchar2,
4168                                    P_Res_Assignment_Id     IN NUMBER default null) Return varchar2
4169   Is
4170 
4171 	l_Return_Status Varchar2(1)    := Null;
4172 	l_Msg_Data	Varchar2(30)   := Null;
4173 	l_Inc_By_Name   Varchar2(1000) := Null;
4174 
4175   Begin
4176 
4177 	Pa_Planning_Resource_Utils.Get_Incur_By_Res_Name(
4178         	P_Person_Id 	        => P_Person_Id,
4179 		P_Job_Id   	        => P_Job_Id,
4180 		P_Incur_By_Role_Id      => P_Incur_By_Role_Id,
4181 		P_Person_Type_Code      => P_Person_Type_Code,
4182 		P_Inc_By_Res_Class_Code => P_Inc_By_Res_Class_Code,
4183 		P_Proc_Func_Flag        => 'F',
4184         	P_Res_Assignment_Id     => P_Res_Assignment_Id,
4185         	X_Inc_By_Displayed      => l_Inc_By_Name,
4186 		X_Return_Status         => l_Return_Status,
4187 		X_Msg_Data    	        => l_Msg_Data );
4188 
4189 	Return l_Inc_By_Name;
4190 
4191   Exception
4192 	When Others Then
4193 		Raise;
4194 
4195   End Ret_Incur_By_Res_Name;
4196 /******************************************/
4197 
4198 /****************************************************************
4199  * Procedure : Get_Incur_By_Res_Name
4200  * **************************************************************/
4201   Procedure Get_Incur_By_Res_Name ( P_Person_Id 	     IN Number,
4202 			            P_Job_Id   	             IN Number,
4203 			            P_Incur_By_Role_Id       IN Number,
4204 			            P_Person_Type_Code       IN Varchar2,
4205 			            P_Inc_By_Res_Class_Code  IN Varchar2,
4206 			            P_Proc_Func_Flag         IN Varchar2,
4207                                     P_Res_Assignment_Id      IN NUMBER default null,
4208 			            X_Inc_By_Displayed      OUT NOCOPY Varchar2,
4209 		 	            X_Return_Status         OUT NOCOPY Varchar2,
4210 			            X_Msg_Data    	    OUT NOCOPY Varchar2)
4211 
4212   Is
4213 
4214 	l_Inc_By_Displayed	       Varchar2(1000);
4215 
4216 	--BAD_PER_IN_RES_LIST_MEM        Exception;
4217 	--BAD_JOB_IN_RES_LIST_MEM        Exception;
4218 	--BAD_INCUR_ROLE_IN_LIST_MEM     Exception;
4219 	--BAD_PER_TYPE_IN_LIST_MEM       Exception;
4220 	--BAD_INCUR_RESCLASS_IN_LIST_MEM Exception;
4221 	--INV_INCUR_BY_IN_LIST_MEM       Exception;
4222 	UNEXPEC_ERROR                  Exception;
4223 
4224 	Cursor c_People (P_Person_Id IN Number) is
4225 	Select
4226 		Full_Name
4227 	From
4228 		Per_People_X
4229 	Where
4230 		Person_Id = P_Person_Id
4231 	And     ( (Pa_Cross_Business_Grp.IsCrossBGProfile = 'N' AND
4232 		   Fnd_Profile.Value('PER_BUSINESS_GROUP_ID') = Business_Group_Id)
4233 		  OR Pa_Cross_Business_Grp.IsCrossBGProfile = 'Y');
4234 
4235 	Cursor c_Job (P_Job_Id In Number) Is
4236 	Select
4237 		Name
4238 	From
4239 		Per_Jobs
4240 	Where
4241 		Job_Id = P_Job_Id
4242 	And     ( (Pa_Cross_Business_Grp.IsCrossBGProfile = 'N' AND
4243 		   Fnd_Profile.Value('PER_BUSINESS_GROUP_ID') = Business_Group_Id )
4244 		  OR Pa_Cross_Business_Grp.IsCrossBGProfile = 'Y');
4245 
4246 	Cursor c_PersonType (P_Person_Type IN Varchar2) Is
4247 	Select
4248 		Meaning
4249 	From
4250 		hr_lookups
4251 	Where
4252 		Lookup_Type = 'PERSON_TYPE'
4253 	And	Lookup_Code = P_Person_Type;
4254 
4255 	Cursor c_ResClass2 (P_Resource_Class_Code IN Varchar2) Is
4256 	Select
4257 		Name
4258 	From
4259 		Pa_Resource_Classes_Vl
4260 	Where
4261 		Resource_Class_Code = P_Resource_Class_Code;
4262 
4263 	Cursor c_PrjRoles (P_Prj_Role_Id IN Number) Is
4264 	Select
4265 		Meaning
4266 	From
4267 		Pa_Project_Role_Types_vl
4268 	Where
4269 		Project_Role_Id = P_Prj_Role_Id;
4270 
4271        Cursor c_Res_Attributes
4272        Is
4273        Select
4274 		Person_Id,
4275 		Job_Id,
4276               	Incur_By_Role_Id,
4277 		Person_Type_Code,
4278               	Incur_By_Res_Class_Code
4279        From
4280 		Pa_Resource_Assignments
4281        Where
4282 		Resource_Assignment_Id = P_Res_Assignment_Id;
4283 
4284       	l_Res_Attributes  c_Res_Attributes%RowType;
4285 
4286        Cursor Get_Inc_By_Flag Is
4287        Select
4288 		Incurred_By_Res_Flag
4289        From
4290 		Pa_Resource_Assignments
4291        Where
4292 		Resource_Assignment_Id = P_Res_Assignment_Id;
4293 
4294        l_Person_Id 		Number;
4295        l_Job_Id 		Number;
4296        l_Incur_By_Role_Id 	Number;
4297        l_Person_Type_Code 	Varchar2(30);
4298        l_Inc_By_Res_Class_Code  Varchar2(30);
4299        l_Inc_By_Flag 		Varchar2(1) := 'N';
4300 
4301   Begin
4302 
4303 	If P_Res_Assignment_Id Is Not Null Then
4304 
4305      		Open Get_inc_By_Flag;
4306      		Fetch Get_Inc_By_Flag Into l_Inc_By_Flag;
4307      		Close Get_Inc_By_Flag;
4308 
4309 	End If;
4310 
4311 	If l_Inc_By_Flag = 'Y' Then
4312 
4313       		Open c_Res_Attributes;
4314       		Fetch c_Res_Attributes Into l_Res_Attributes;
4315       		Close c_Res_Attributes;
4316 
4317       		l_person_id             := l_res_attributes.person_id;
4318       		l_job_id                := l_res_attributes.job_id;
4319       		l_incur_by_role_id      := l_res_attributes.incur_by_role_id;
4320       		l_person_type_code      := l_res_attributes.person_type_code;
4321       		l_inc_by_res_class_code := l_res_attributes.incur_by_res_class_code;
4322 
4323 	Else
4324 
4325       		l_person_id := p_person_id;
4326       		l_job_id := p_job_id;
4327       		l_incur_by_role_id      := p_incur_by_role_id;
4328       		l_person_type_code      := p_person_type_code;
4329       		l_inc_by_res_class_code := p_inc_by_res_class_code;
4330 
4331 	End If;
4332 
4333 	-- Check in this order:
4334 	-- Named Person, job, role, person type, Financial Elements Resource class
4335 	If l_Person_Id is Not Null Then
4336 
4337 		Open c_People(P_Person_Id => l_Person_Id);
4338 		Fetch c_People Into l_Inc_By_Displayed;
4339 		If c_People%NotFound Then
4340 			Close c_People;
4341 			--Raise BAD_PER_IN_RES_LIST_MEM;
4342 			Raise UNEXPEC_ERROR;
4343 		End If;
4344 		Close c_People;
4345 
4346 	ElsIf l_Job_Id is Not Null Then
4347 
4348 		Open c_Job(P_Job_Id => l_Job_Id);
4349 		Fetch c_Job Into l_Inc_By_Displayed;
4350 		If c_Job%NOTFOUND Then
4351 			Close c_job;
4352 			--Raise BAD_JOB_IN_RES_LIST_MEM;
4353 			Raise UNEXPEC_ERROR;
4354 		End If;
4355 		Close c_Job;
4356 
4357 	ElsIf l_Incur_By_Role_Id is Not Null Then
4358 
4359 		Open c_PrjRoles(P_Prj_Role_Id => l_Incur_By_Role_Id);
4360 		Fetch c_PrjRoles Into l_Inc_By_Displayed;
4361 		If c_PrjRoles%NOTFOUND Then
4362 			Close c_PrjRoles;
4363 			--Raise BAD_INCUR_ROLE_IN_LIST_MEM;
4364 			Raise UNEXPEC_ERROR;
4365 		End If;
4366 		Close c_PrjRoles;
4367 
4368 	ElsIf l_Person_Type_Code is Not Null Then
4369 
4370 		-- CWK, EMP
4371 		-- Get meaning from fnd_common_lookups
4372 		Open c_PersonType(P_Person_Type => l_Person_Type_Code);
4373 		Fetch c_PersonType Into l_Inc_By_Displayed;
4374 		If c_PersonType%NOTFOUND Then
4375 			Close c_PersonType;
4376 			--Raise BAD_PER_TYPE_IN_LIST_MEM;
4377 			Raise UNEXPEC_ERROR;
4378 		End If;
4379 		Close c_PersonType;
4380 
4381 	ElsIf l_Inc_By_Res_Class_Code is Not Null Then
4382 
4383 		Open c_ResClass2(P_Resource_Class_Code => l_Inc_By_Res_Class_Code);
4384 		Fetch c_ResClass2 into l_Inc_By_Displayed;
4385 		If c_ResClass2%NOTFOUND Then
4386 
4387 			Close c_ResClass2;
4388 			--Raise BAD_INCUR_RESCLASS_IN_LIST_MEM;
4389 			Raise UNEXPEC_ERROR;
4390 
4391 		End If;
4392 		Close c_ResClass2;
4393 
4394 	Else
4395 
4396 		--Raise INV_INCUR_BY_IN_LIST_MEM;
4397 		--Raise UNEXPEC_ERROR;
4398                 -- Return Null if resource or assignment is not
4399 	        -- an incurred by resource.
4400                 l_Inc_By_Displayed := NULL;
4401 
4402 	End If;
4403 
4404 	X_Inc_By_Displayed := l_Inc_By_Displayed;
4405 	X_Msg_Data         := Null;
4406 	X_Return_Status    := Fnd_Api.G_Ret_Sts_Success;
4407 
4408   Exception
4409         When UNEXPEC_ERROR THEN
4410               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
4411               --x_msg_count := x_msg_count + 1;
4412               x_msg_data := Null;
4413               Fnd_Msg_Pub.Add_Exc_Msg(
4414                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
4415                         P_Procedure_Name   => 'Get_Incur_By_Res_Name');
4416               Return;
4417 	/*When BAD_PER_IN_RES_LIST_MEM Then
4418 
4419 		If P_Proc_Func_Flag = 'P' Then
4420 
4421 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4422 			X_Msg_Data	:= 'PA_BAD_PER_IN_RES_LIST_MEM';
4423 			Pa_Utils.Add_Message
4424 	               		(P_App_Short_Name  => 'PA',
4425         	        	 P_Msg_Name        => 'PA_BAD_PER_IN_RES_LIST_MEM');
4426 
4427 		Else
4428 
4429 			X_Inc_By_Displayed := Null;
4430 
4431 		End If;*/
4432 
4433 	/*When BAD_JOB_IN_RES_LIST_MEM Then
4434 
4435 		If P_Proc_Func_Flag = 'P' Then
4436 
4437 			X_Return_Status	:= Fnd_Api.G_Ret_Sts_Error;
4438 			X_Msg_Data	:= 'PA_BAD_JOB_IN_RES_LIST_MEM';
4439 			Pa_Utils.Add_Message
4440         	       		(P_App_Short_Name  => 'PA',
4441                 		 P_Msg_Name        => 'PA_BAD_JOB_IN_RES_LIST_MEM');
4442 
4443 		Else
4444 
4445 			X_Inc_By_Displayed := Null;
4446 
4447 		End If;*/
4448 
4449 	/*When BAD_INCUR_ROLE_IN_LIST_MEM Then
4450 
4451 		If P_Proc_Func_Flag = 'P' Then
4452 
4453 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4454 			X_Msg_Data	:= 'PA_BAD_INCUR_ROLE_IN_LIST_MEM';
4455 			Pa_Utils.Add_Message
4456         	       		(P_App_Short_Name  => 'PA',
4457 	                	 P_Msg_Name        => 'PA_BAD_INCUR_ROLE_IN_LIST_MEM');
4458 
4459 		Else
4460 
4461 			X_Inc_By_Displayed := Null;
4462 
4463 		End If;*/
4464 
4465 	/*When BAD_PER_TYPE_IN_LIST_MEM Then
4466 
4467 		If P_Proc_Func_Flag = 'P' Then
4468 
4469 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4470 			X_Msg_Data	:= 'PA_BAD_PER_TYPE_IN_LIST_MEM';
4471 			Pa_Utils.Add_Message
4472 	        		(P_App_Short_Name  => 'PA',
4473         	        	 P_Msg_Name        => 'PA_BAD_PER_TYPE_IN_LIST_MEM');
4474 
4475 		Else
4476 
4477 			X_Inc_By_Displayed := Null;
4478 
4479 		End If;*/
4480 
4481 	/*When BAD_INCUR_RESCLASS_IN_LIST_MEM Then
4482 
4483 		If P_Proc_Func_Flag = 'P' Then
4484 
4485 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4486 			X_Msg_Data	:= 'PA_BAD_INC_RESCLASS_IN_LST_MEM';
4487 			Pa_Utils.Add_Message
4488         	       		(P_App_Short_Name  => 'PA',
4489                 		 P_Msg_Name        => 'PA_BAD_INC_RESCLASS_IN_LST_MEM');
4490 
4491 		Else
4492 
4493 			X_Inc_By_Displayed := Null;
4494 
4495 		End If;*/
4496 
4497 	/*When INV_INCUR_BY_IN_LIST_MEM Then
4498 
4499 		If P_Proc_Func_Flag = 'P' Then
4500 
4501 			X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
4502 			X_Msg_Data	:= 'PA_INV_INCUR_BY_IN_LIST_MEM';
4503 			Pa_Utils.Add_Message
4504 	               		(P_App_Short_Name  => 'PA',
4505 	                	 P_Msg_Name        => 'PA_INV_INCUR_BY_IN_LIST_MEM');
4506 
4507 		Else
4508 
4509 			X_Inc_By_Displayed := Null;
4510 
4511 		End If;*/
4512 
4513 	When Others Then
4514 		Raise;
4515 
4516   End Get_Incur_By_Res_Name;
4517 /**************************************************/
4518 
4519 /********************************************************
4520  * Procedure  : Get_Plan_Res_Combination.
4521  *****************************************************/
4522 
4523 Procedure Get_Plan_Res_Combination(
4524 		P_Resource_List_Member_Id IN  Number,
4525 		X_Resource_Alias	 OUT NOCOPY Varchar2,
4526  		X_Plan_Res_Combination   OUT NOCOPY Varchar2,
4527 		X_Return_Status          OUT NOCOPY Varchar2,
4528 		X_Msg_Count              OUT NOCOPY Number,
4529 		X_Msg_Data               OUT NOCOPY Varchar2)
4530 
4531  Is
4532 
4533 	l_Res_Type_displayed     Varchar2(1000) := Null;
4534 	l_FC_Displayed           Varchar2(80)   := Null;
4535 	l_Orgn_Displayed         Varchar2(240)  := Null;
4536 	l_Supplier_Displayed     Varchar2(240)  := Null;
4537 	l_Role_Displayed         Varchar2(80)   := Null;
4538 	l_Res_Incur_By_displayed Varchar2(1000) := Null;
4539 	l_Res_Incur_By_alias     Varchar2(1000) := Null;
4540 
4541 	Cursor c_Enabled_Flags (P_Res_Format_Id IN Number) is
4542 	Select
4543 		f.Res_Type_Enabled_Flag,
4544 		f.Orgn_Enabled_Flag,
4545 		f.Fin_Cat_Enabled_Flag,
4546 		f.Incurred_By_Enabled_Flag,
4547 		f.Supplier_Enabled_Flag,
4548 		f.Role_Enabled_Flag,
4549 		f.Resource_Class_Flag,
4550 		f.Res_Type_Id,
4551 		f.Resource_Type_Disp_Chars,
4552 		f.Orgn_Disp_Chars,
4553 		f.Fin_Cat_Disp_Chars,
4554 		f.Incurred_By_Disp_Chars,
4555 		f.Supplier_Disp_Chars,
4556 		f.Role_Disp_Chars,
4557 		t.Res_Type_Code
4558 	From
4559 		Pa_Res_Formats_B f,
4560 		Pa_Res_Types_B t
4561 	Where
4562 		f.Res_Type_Id = t.Res_Type_Id(+)
4563 	And	f.Res_Format_Id = P_Res_Format_Id;
4564 
4565 	Cursor c_Res_List (P_Res_List_Member_Id IN Number) is
4566 	Select
4567 		Res_Format_Id,
4568 		Person_Id,
4569 		Job_Id,
4570 		Organization_Id,
4571 		Vendor_Id,
4572 		Expenditure_Type,
4573 		Event_Type,
4574 		Non_Labor_Resource,
4575 		Expenditure_Category,
4576 		Revenue_Category,
4577 		Non_Labor_Resource_Org_Id,
4578 		Project_Role_Id,
4579 		Resource_Format_Id,
4580 		Resource_Class_Id,
4581 		Mfc_Cost_Type_Id,
4582 		Resource_Class_Flag,
4583 		Fc_Res_Type_Code,
4584 		Bom_Resource_Id,
4585 		Inventory_Item_Id,
4586 		Item_Category_Id,
4587 		Person_Type_Code,
4588 		team_role ,
4589 		Incurred_By_Res_Flag,
4590 		Incur_By_Res_Class_Code,
4591 		Incur_By_Role_Id
4592 	From
4593 		Pa_Resource_List_Members
4594 	Where
4595 		Resource_List_Member_Id = P_Res_List_Member_Id;
4596 
4597 	Res_List_Member_Rec c_Res_List%RowType;
4598 	Res_Format_Rec c_Enabled_Flags%RowType;
4599 
4600 	-- User Exception Definitions
4601 	INVALID_RES_LIST_MEM_ID Exception;
4602 	NULL_MEM_LIST_RES_FORMAT Exception;
4603 	INVALID_MEM_LIST_RES_FORMAT Exception;
4604 	--BAD_RES_TYPE_CODE Exception;
4605 	FAIL_GET_NAME Exception;
4606 
4607  Begin
4608 
4609 	-- We always display the combination in the following order
4610 	--	Resource
4611 	--	Financial Category
4612 	--	Organization
4613 	--	Supplier
4614 	-- 	Role
4615 	--	Incurred By
4616 
4617 	-- Initialize values
4618 	X_Return_Status := Fnd_Api.G_Ret_Sts_Success;
4619 	X_Msg_Count     	:= 0;
4620 	X_Msg_Data		:= Null;
4621         /***************************************************
4622         * Bug - 3591595
4623         * Desc - If the P_Resource_List_Member_Id is passed in as Null
4624         *        then set the x_resource_alias and X_Plan_Res_Combination
4625         *        as Null and Return.
4626         ******************************************************/
4627         IF P_Resource_List_Member_Id IS NULL THEN
4628 		X_Resource_Alias	 := Null;
4629  		X_Plan_Res_Combination   := Null;
4630 	        X_Return_Status := Fnd_Api.G_Ret_Sts_Success;
4631                 Return;
4632         END IF;
4633 
4634 	Open c_Res_List(P_Res_List_Member_Id => P_Resource_List_Member_Id);
4635 	Fetch c_Res_List into Res_List_Member_Rec;
4636 	If c_Res_List%NotFound Then
4637 		Close c_Res_List;
4638 		Raise INVALID_RES_LIST_MEM_ID;
4639 	End If;
4640 	Close c_Res_List;
4641 
4642 	If Res_List_Member_Rec.Res_Format_Id is Not Null Then
4643 
4644 		Open c_Enabled_Flags(P_Res_Format_Id => Res_List_Member_Rec.Res_Format_Id);
4645 		Fetch c_Enabled_Flags into Res_Format_Rec;
4646 		If c_Enabled_Flags%NotFound Then
4647 			Close c_Enabled_Flags;
4648 			Raise INVALID_MEM_LIST_RES_FORMAT;
4649 		End If;
4650 		Close c_Enabled_Flags;
4651 
4652 	Else
4653 
4654 		Raise NULL_MEM_LIST_RES_FORMAT;
4655 
4656 	End If;
4657 
4658 
4659 	-- An Assumption is that there will never be more that 3 segments to the format
4660 	-- So therefore will not count the number of segments with enabled_flag = 'Y'
4661 
4662 	-- Check res_type_enabled_flag = 'Y'
4663 	If Res_Format_Rec.Res_Type_Enabled_Flag = 'Y' Then
4664 
4665 		Pa_Planning_Resource_Utils.Get_Resource_Name (
4666 			P_Res_Type_Code      => Res_Format_Rec.Res_Type_Code,
4667 			P_Person_Id          => Res_List_Member_Rec.Person_Id,
4668 			P_Bom_Resource_Id    => Res_List_Member_Rec.BOM_Resource_Id,
4669     			P_Job_Id             => Res_List_Member_Rec.Job_Id,
4670 			P_Person_Type_Code   => Res_List_Member_Rec.Person_Type_Code,
4671 			P_Non_Labor_Resource => Res_List_Member_Rec.Non_Labor_Resource,
4672 			P_Inventory_Item_Id  => Res_List_Member_Rec.Inventory_Item_Id,
4673 			P_Item_Category_Id   => Res_List_Member_Rec.Item_Category_Id,
4674 			P_Resource_Class_Id  => Res_List_Member_Rec.Resource_Class_Id,
4675 			P_Proc_Func_Flag     => 'P',
4676 			X_Resource_Displayed => l_Res_Type_Displayed,
4677 		 	X_Return_Status      => X_Return_Status,
4678 			X_Msg_Data    	     => X_Msg_Data);
4679 
4680 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
4681 
4682 			Raise FAIL_GET_NAME;
4683 
4684 		End If;
4685 
4686 		If l_Res_Type_Displayed is Not Null Then
4687 
4688 			X_Plan_Res_Combination := l_Res_Type_Displayed;
4689                         --Bug 3485392
4690                         IF Res_Format_Rec.Res_Type_Code = 'NAMED_PERSON' THEN
4691                              BEGIN
4692                                  Select nvl(known_as,Full_Name)
4693                                  INTO l_Res_Type_Displayed
4694                                  From Per_People_X
4695                                  Where Person_Id = Res_List_Member_Rec.Person_Id;
4696                              END;
4697                         END IF;
4698 			X_Resource_Alias       := substr(l_Res_Type_Displayed,1,Res_Format_Rec.Resource_Type_Disp_Chars);
4699 
4700 		--Else
4701 
4702 			--Raise BAD_RES_TYPE_CODE;
4703 
4704 		End If;
4705 
4706 	End If;
4707 
4708 	-- Check fin_cat_enabled_flag = 'Y'
4709 	If Res_Format_Rec.Fin_Cat_Enabled_Flag = 'Y' Then
4710 
4711 		Pa_Planning_Resource_Utils.Get_Fin_Category_Name (
4712 			P_FC_Res_Type_Code      => Res_List_Member_Rec.Fc_Res_Type_Code,
4713 			P_Expenditure_Type      => Res_List_Member_Rec.Expenditure_Type,
4714 			P_Expenditure_Category  => Res_List_Member_Rec.Expenditure_Category,
4715 			P_Event_Type            => Res_List_Member_Rec.Event_Type,
4716 			P_Revenue_Category_Code => Res_List_Member_Rec.Revenue_Category,
4717 			P_Proc_Func_Flag        => 'P',
4718                         P_Res_Assignment_Id     => NULL,
4719 			X_Fin_Cat_Displayed     => l_FC_Displayed,
4720 		 	X_Return_Status         => X_Return_Status,
4721 			X_Msg_Data	        => X_Msg_Data);
4722 
4723 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
4724 
4725 			Raise FAIL_GET_NAME;
4726 
4727 		End If;
4728 
4729 		If X_Plan_Res_Combination is Not Null Then
4730 
4731 			X_Plan_Res_Combination := X_Plan_Res_Combination || ' - ' || l_FC_Displayed;
4732 			X_Resource_Alias := substr(X_Resource_Alias || ' - ' ||
4733 					  substr(l_FC_Displayed,1,Res_Format_Rec.Fin_Cat_Disp_Chars), 1, 80);
4734 
4735 		Else
4736 
4737 			X_Plan_Res_Combination := l_FC_Displayed;
4738 			X_Resource_Alias       := substr(l_FC_Displayed,1,Res_Format_Rec.Fin_Cat_Disp_Chars);
4739 
4740 		End If;
4741 
4742 	End If;
4743 
4744 	-- Check orgn_enabled_flag = 'Y'
4745 	If Res_Format_Rec.Orgn_Enabled_Flag = 'Y' Then
4746 
4747 		Pa_Planning_Resource_Utils.Get_Organization_Name (
4748 			P_Organization_Id => Res_List_Member_Rec.Organization_Id,
4749 			P_Proc_Func_Flag  => 'P',
4750 			X_Org_Displayed   => l_Orgn_Displayed,
4751 		 	X_Return_Status   => X_Return_Status,
4752 			X_Msg_Data	  => X_Msg_Data);
4753 
4754 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
4755 
4756 			Raise FAIL_GET_NAME;
4757 
4758 		End If;
4759 
4760 		If X_Plan_Res_Combination is Not Null Then
4761 
4762 			X_Plan_Res_Combination := X_Plan_Res_Combination || ' - ' || l_Orgn_Displayed;
4763 			X_Resource_Alias := substr(X_Resource_Alias || ' - ' ||
4764 				  substr(l_Orgn_Displayed,1,Res_Format_Rec.Orgn_Disp_Chars), 1, 80);
4765 
4766 		Else
4767 
4768 			X_Plan_Res_Combination := l_Orgn_Displayed;
4769 			X_Resource_Alias       := substr(l_Orgn_Displayed,1,Res_Format_Rec.Orgn_Disp_Chars);
4770 
4771 		End If;
4772 
4773 	End If;
4774 
4775 	-- Check supplier_enabled_flag = 'Y'
4776 	If Res_Format_Rec.Supplier_Enabled_Flag = 'Y' Then
4777 
4778 		Pa_Planning_Resource_Utils.Get_Supplier_Name (
4779 			P_Supplier_Id        => Res_List_Member_Rec.Vendor_Id,
4780 			P_Proc_Func_Flag     => 'P',
4781 			X_Supplier_Displayed => l_Supplier_Displayed,
4782 		 	X_Return_Status      => X_Return_Status,
4783 			X_Msg_Data	     => X_Msg_Data);
4784 
4785 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
4786 
4787 			Raise FAIL_GET_NAME;
4788 
4789 		End If;
4790 
4791 		If X_Plan_Res_Combination is Not Null Then
4792 
4793 			X_Plan_Res_Combination := X_Plan_Res_Combination || ' - ' || l_Supplier_Displayed;
4794 			X_Resource_Alias := substr(X_Resource_Alias || ' - ' ||
4795 				  substr(l_Supplier_Displayed,1,Res_Format_Rec.Supplier_Disp_Chars), 1, 80);
4796 
4797 		Else
4798 
4799 			X_Plan_Res_Combination := l_Supplier_Displayed;
4800 			X_Resource_Alias       := substr(l_Supplier_Displayed,1,Res_Format_Rec.Supplier_Disp_Chars);
4801 
4802 		End If;
4803 
4804 	End If;
4805 
4806 	-- Check role_enabled_flag = 'Y'
4807 	If Res_Format_Rec.Role_Enabled_Flag = 'Y' Then
4808                 -- Team Role Changes
4809 		/*Pa_Planning_Resource_Utils.Get_Role_Name (
4810 			P_Role_Id        => Res_List_Member_Rec.Project_Role_Id,
4811 			P_Proc_Func_Flag => 'P',
4812 			X_Role_Displayed => l_Role_Displayed,
4813 		 	X_Return_Status  => X_Return_Status,
4814 			X_Msg_Data	 => X_Msg_Data);
4815 
4816 
4817 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
4818 
4819 			Raise FAIL_GET_NAME;
4820 
4821 		End If;*/
4822                 -- Team Role Changes
4823                 l_Role_Displayed := Res_List_Member_Rec.Team_Role;
4824 
4825 		If X_Plan_Res_Combination is Not Null Then
4826 
4827 			X_Plan_Res_Combination := X_Plan_Res_Combination || ' - ' || l_Role_Displayed;
4828 			X_Resource_Alias := substr(X_Resource_Alias || ' - ' ||
4829 				 substr(l_Role_Displayed,1,Res_Format_Rec.Role_Disp_Chars), 1, 80);
4830 
4831 		Else
4832 
4833 			X_Plan_Res_Combination := l_Role_Displayed;
4834 			X_Resource_Alias       := substr(l_Role_Displayed,1,Res_Format_Rec.Role_Disp_Chars);
4835 
4836 		End If;
4837 
4838 	End If;
4839 
4840 	-- Check incurred_by_enabled_flag = 'Y'
4841 	If Res_Format_Rec.Incurred_By_Enabled_Flag = 'Y' and
4842 	   Res_List_Member_Rec.Incurred_By_Res_Flag = 'Y' Then
4843 
4844 		Pa_Planning_Resource_Utils.Get_Incur_By_Res_Name (
4845 			P_Person_Id 	        => Res_List_Member_Rec.Person_Id,
4846 			P_Job_Id   	        => Res_List_Member_Rec.Job_Id,
4847 			P_Incur_By_Role_Id      => Res_List_Member_Rec.Incur_By_Role_Id,
4848 			P_Person_Type_Code      => Res_List_Member_Rec.Person_Type_Code,
4849 			P_Inc_By_Res_Class_Code => Res_List_Member_Rec.Incur_By_Res_Class_Code,
4850 			P_Proc_Func_Flag        => 'P',
4851                         P_Res_Assignment_Id     => null,
4852 			X_Inc_By_Displayed      => l_Res_Incur_By_displayed,
4853 		 	X_Return_Status         => X_Return_Status,
4854 			X_Msg_Data	        => X_Msg_Data);
4855 
4856 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
4857 
4858 			Raise FAIL_GET_NAME;
4859 
4860 		End If;
4861 
4862                 If l_Res_Incur_By_displayed is Not Null Then
4863 
4864                    l_Res_Incur_By_alias := l_Res_Incur_By_displayed;
4865                    --Bug 3940932
4866                    IF Res_List_Member_Rec.Person_Id IS NOT NULL THEN
4867                       BEGIN
4868                          SELECT nvl(known_as,Full_Name)
4869                          INTO l_Res_Incur_By_alias
4870                          FROM Per_People_X
4871                          WHERE Person_Id = Res_List_Member_Rec.Person_Id;
4872                          END;
4873                    END IF;
4874                 End If;
4875 
4876 		If X_Plan_Res_Combination is Not Null Then
4877 
4878 		   X_Plan_Res_Combination := X_Plan_Res_Combination || ' - ' ||
4879                                              l_Res_Incur_By_displayed;
4880 	 	   X_Resource_Alias := substr(X_Resource_Alias || ' - ' ||
4881 			  substr(l_Res_Incur_By_alias,1,Res_Format_Rec.Incurred_By_Disp_Chars), 1, 80);
4882 
4883 		Else
4884 		   X_Plan_Res_Combination := l_Res_Incur_By_displayed;
4885 		   X_Resource_Alias       := substr(l_Res_Incur_By_alias,1,Res_Format_Rec.Incurred_By_Disp_Chars);
4886 
4887 		End If;
4888 
4889 	End If; -- Check incurred_by_enabled_flag = 'Y'
4890 
4891  Exception
4892 	When INVALID_RES_LIST_MEM_ID Then
4893 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
4894 		X_Msg_Count     	:= 1;
4895 		X_Msg_Data		:= 'PA_INVALID_RES_LIST_MEM_ID';
4896 		Pa_Utils.Add_Message
4897                		(P_App_Short_Name  => 'PA',
4898                 	 P_Msg_Name        => 'PA_INVALID_RES_LIST_MEM_ID');
4899 	When NULL_MEM_LIST_RES_FORMAT Then
4900 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
4901 		X_Msg_Count     	:= 1;
4902 		X_Msg_Data		:= 'PA_NULL_MEM_LIST_RES_FRM';
4903 		Pa_Utils.Add_Message
4904                		(P_App_Short_Name  => 'PA',
4905                 	 P_Msg_Name        => 'PA_NULL_MEM_LIST_RES_FRM');
4906 	When INVALID_MEM_LIST_RES_FORMAT Then
4907 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
4908 		X_Msg_Count     	:= 1;
4909 		X_Msg_Data		:= 'PA_INVALID_MEM_LIST_RES_FRM';
4910 		Pa_Utils.Add_Message
4911                		(P_App_Short_Name  => 'PA',
4912                 	 P_Msg_Name        => 'PA_INVALID_MEM_LIST_RES_FRM');
4913 	/*When BAD_RES_TYPE_CODE Then
4914 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
4915 		X_Msg_Count     	:= 1;
4916 		X_Msg_Data		:= 'PA_BAD_RES_TYPE_CODE';
4917 		Pa_Utils.Add_Message
4918                		(P_App_Short_Name  => 'PA',
4919                 	 P_Msg_Name        => 'PA_BAD_RES_TYPE_CODE');*/
4920 	When FAIL_GET_NAME Then
4921 		X_Msg_Count     	:= 1;
4922 		-- Assumes that the called procedure populates the
4923 		-- out parameters with the rest of the needed values
4924 		-- and executes pa_utils.add_message()
4925 	When Others Then
4926 		Raise;
4927 
4928  End Get_Plan_Res_Combination;
4929 /****************************************************/
4930 
4931 
4932 /******Eugene*******************************************/
4933 Function Get_Plan_Res_Combination( P_Resource_List_Member_Id IN Number) Return Varchar2
4934 IS
4935 
4936 	l_Plan_Res_Combination	Varchar2(2000);
4937 	l_Return_Status 	Varchar2(1);
4938 	l_Res_List_Member_Alias Varchar2(2000);
4939 	l_Error_Msg_Data 	Varchar2(30);
4940 	l_Error_Count 		Number;
4941 
4942 BEGIN
4943 
4944 	Pa_Planning_Resource_Utils.Get_Plan_Res_Combination(
4945                 P_Resource_List_Member_Id  => P_Resource_List_Member_Id,
4946                 X_Resource_Alias           => l_Res_List_Member_Alias,
4947                 X_Plan_Res_Combination     => l_Plan_Res_Combination,
4948                 X_Return_Status            => l_Return_Status,
4949                 X_Msg_Count                => l_Error_Count,
4950                 X_Msg_Data                 => l_Error_Msg_Data);
4951 
4952 	If l_Return_Status <> Fnd_Api.G_Ret_Sts_Success Then
4953 
4954 		-- Since this function calls the procedure get_plan_res_combination
4955 		-- then the message is populated already using pa_utils.add_message()
4956 		-- so just return 'ERROR'
4957 		-- The message stack is already populated.
4958    		Return 'ERROR';
4959 
4960 	Else
4961 
4962    		Return l_Plan_Res_Combination;
4963 
4964 	End If;
4965 
4966 
4967 END Get_Plan_Res_Combination;
4968 /**************************************/
4969 
4970 /*************************************************/
4971  Procedure Validate_Fin_Category(
4972 		P_FC_Res_Type_Code	IN  Varchar2,
4973 		P_Resource_Class_Code	IN  Varchar2,
4974 		P_Fin_Category_Name	IN  Varchar2,
4975 		P_migration_code   	IN  Varchar2,
4976 		X_Expenditure_Type	OUT NOCOPY Varchar2,
4977 		x_Expenditure_Category 	OUT NOCOPY Varchar2,
4978 		X_Event_Type		OUT NOCOPY Varchar2,
4979 		X_Revenue_Category	OUT NOCOPY Varchar2,
4980 		X_Return_Status		OUT NOCOPY Varchar2,
4981 		X_Error_Message_Code	OUT NOCOPY Varchar2)
4982 
4983  Is
4984 
4985 	Cursor c_Event_Type ( P_Fin_Cat_Name IN Varchar2 ) Is
4986 	Select
4987 		'Y'
4988   	From
4989 		Pa_Event_Types
4990  	Where
4991 		Event_Type = P_Fin_Cat_Name
4992 	And	Event_Type_Classification IN ('AUTOMATIC','MANUAL','WRITE OFF','WRITE ON')
4993  	And 	Decode(Pa_Get_Resource.Include_Inactive_Resources,
4994 				'Y',Start_Date_Active,
4995 				Trunc(SysDate)) Between Start_Date_Active
4996 					           And Nvl(End_Date_Active,Trunc(SysDate));
4997 
4998 	Cursor c_Exp_Type ( P_Fin_Cat_Name IN Varchar2) Is
4999 	Select
5000 		'Y'
5001   	From
5002 		Pa_Expenditure_Types
5003  	Where
5004 		lower(Expenditure_Type) = lower(P_Fin_Cat_Name)
5005  	And 	Decode(Pa_Get_Resource.Include_Inactive_Resources,
5006 				'Y',Start_Date_Active,
5007 				Trunc(SysDate)) Between Start_Date_Active
5008 					           And Nvl(End_Date_Active,Trunc(SysDate));
5009 
5010 	Cursor c_Exp_Cat ( P_Fin_Cat_Name IN Varchar2) Is
5011 	Select
5012 		'Y'
5013   	From
5014 		Pa_Expenditure_Categories
5015  	Where
5016 		lower(Expenditure_Category) = lower(P_Fin_Cat_Name)
5017  	And 	Decode(Pa_Get_Resource.Include_Inactive_Resources,
5018 				'Y',Start_Date_Active,
5019 				Trunc(SysDate)) Between Start_Date_Active
5020 					           And Nvl(End_Date_Active,Trunc(SysDate));
5021 
5022 
5023 	Cursor c_Rev_Cat_Code ( P_Fin_Cat_Code IN Varchar2) Is
5024 	Select
5025 		Meaning
5026   	From
5027 		Pa_Lookups
5028  	Where
5029 		Lookup_Code = P_Fin_Cat_Code
5030 	And	Lookup_Type = 'REVENUE CATEGORY';
5031 
5032         Cursor c_Rev_Cat_Meaning ( P_Fin_Cat_Meaning IN Varchar2) Is
5033         Select
5034                 lookup_code
5035         From
5036                 Pa_Lookups
5037         Where
5038                 Meaning = P_Fin_Cat_Meaning
5039         And     Lookup_Type = 'REVENUE CATEGORY';
5040 
5041 	Cursor c_UOM ( P_Fin_Cat_Name IN Varchar2 ) Is
5042 	Select
5043 		'Y'
5044 	From
5045 		Pa_Expenditure_Types
5046 	Where
5047 		Unit_Of_Measure = 'HOURS'
5048 	And 	Expenditure_Type = P_Fin_Cat_Name;
5049 
5050 	MAN_PARAMS_NULL            Exception;
5051 	BAD_FIN_CAT_FOR_EVENT_TYPE Exception;
5052 	BAD_FIN_CAT_FOR_EXP_TYPE   Exception;
5053 	BAD_FIN_CAT_FOR_EXP_CAT    Exception;
5054 	BAD_FIN_CAT_FOR_REV_CAT    Exception;
5055 	INVALID_VAL_FC_RES_TYPE    Exception;
5056 	BAD_FIN_CAT_UOM            Exception;
5057 	UNEXPEC_ERROR              Exception;
5058 	INVALID_FIN_CAT_CODE       Exception;
5059 	l_Dummy	Varchar2(1) := Null;
5060 	l_rev_meaning	Varchar2(80) := Null;
5061 	l_rev_code	Varchar2(30) := Null;
5062 
5063  Begin
5064 
5065 	-- Initialize values
5066 	X_Return_Status      := Fnd_Api.G_Ret_Sts_Success;
5067 	X_Error_Message_Code := Null;
5068 
5069 	If P_FC_Res_Type_Code is Null or
5070 	   P_Fin_Category_Name is Null or
5071 	   P_Resource_Class_Code is Null Then
5072 
5073 		Raise MAN_PARAMS_NULL;
5074 		--Raise UNEXPEC_ERROR;
5075 
5076 	End If;
5077 
5078 	If P_FC_Res_Type_Code = 'EVENT_TYPE' Then
5079 
5080 		Open c_Event_Type(P_Fin_Cat_Name => P_Fin_Category_Name);
5081 		Fetch c_Event_Type Into l_Dummy;
5082 		If c_Event_Type%NotFound Then
5083 
5084 			Close c_Event_Type;
5085 			Raise BAD_FIN_CAT_FOR_EVENT_TYPE;
5086 			--Raise UNEXPEC_ERROR;
5087 
5088 		End If;
5089 		X_Event_Type := P_Fin_Category_Name;
5090 		Close c_Event_Type;
5091 
5092 	ElsIf P_FC_Res_Type_Code = 'EXPENDITURE_TYPE' Then
5093 
5094 		Open c_Exp_Type(P_Fin_Cat_Name => P_Fin_Category_Name);
5095 		Fetch c_Exp_Type Into l_Dummy;
5096 		If c_Exp_Type%NotFound Then
5097 
5098 			Close c_Exp_Type;
5099 			Raise BAD_FIN_CAT_FOR_EXP_TYPE;
5100 			--Raise UNEXPEC_ERROR;
5101 
5102 		End If;
5103 		X_Expenditure_Type := P_Fin_Category_Name;
5104 		Close c_Exp_Type;
5105 
5106 	ElsIf P_FC_Res_Type_Code = 'EXPENDITURE_CATEGORY' Then
5107 
5108 		Open c_Exp_Cat(P_Fin_Cat_Name => P_Fin_Category_Name);
5109 		Fetch c_Exp_Cat Into l_Dummy;
5110 		If c_Exp_Cat%NotFound Then
5111 
5112 
5113 			Close c_Exp_Cat;
5114 			Raise BAD_FIN_CAT_FOR_EXP_CAT;
5115 			--Raise UNEXPEC_ERROR;
5116 
5117 		End If;
5118 		X_Expenditure_Category := P_Fin_Category_Name;
5119 		Close c_Exp_Cat;
5120 
5121 	ElsIf P_FC_Res_Type_Code = 'REVENUE_CATEGORY' Then
5122 
5123 		-- First check to see if the P_Fin_Category_Name is the
5124 		-- Rev Cat Code
5125 		Open c_Rev_Cat_Code(P_Fin_Cat_Code => P_Fin_Category_Name);
5126 		Fetch c_Rev_Cat_Code Into l_rev_meaning;
5127 		If c_Rev_Cat_Code%NotFound Then
5128 		   -- Check to see if it is the Meaning
5129 
5130                    Open c_Rev_Cat_Meaning(P_Fin_Cat_Meaning => P_Fin_Category_Name);
5131                    Fetch c_Rev_Cat_Meaning Into l_rev_code;
5132                    If c_Rev_Cat_Meaning%NotFound Then
5133                       Close c_Rev_Cat_Meaning;
5134                       Raise BAD_FIN_CAT_FOR_REV_CAT;
5135                       --Raise UNEXPEC_ERROR;
5136                    Else
5137                       X_Revenue_Category := l_rev_code;
5138                       Close c_Rev_Cat_Meaning;
5139                    End If;
5140                 Else
5141 		   X_Revenue_Category := P_Fin_Category_Name;
5142                 End If;
5143 		Close c_Rev_Cat_Code;
5144 	Else
5145 	  RAISE INVALID_FIN_CAT_CODE;
5146 
5147 	End If;
5148 
5149 	If P_Resource_Class_Code in ('PEOPLE','EQUIPMENT') And
5150 	   P_FC_Res_Type_Code = 'EXPENDITURE_TYPE' And
5151            P_migration_code = 'N' Then
5152 
5153 		Open c_UOM(P_Fin_Cat_Name => P_Fin_Category_Name);
5154 		Fetch c_UOM Into l_Dummy;
5155 		If c_UOM%NotFound Then
5156 
5157 			Close c_UOM;
5158 			Raise BAD_FIN_CAT_UOM;
5159 
5160 		End If;
5161 		Close c_UOM;
5162 
5163 	End If;
5164 
5165  Exception
5166         When UNEXPEC_ERROR THEN
5167               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
5168               --x_msg_count := x_msg_count + 1;
5169               x_error_message_code := Null;
5170               Fnd_Msg_Pub.Add_Exc_Msg(
5171                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
5172                         P_Procedure_Name   => 'Validate_Fin_Category');
5173 	When INVALID_FIN_CAT_CODE Then
5174 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5175 		X_Error_Message_Code	:= 'PA_VFC_INVALID_FIN_CAT_CODE';
5176 		Pa_Utils.Add_Message
5177                		(P_App_Short_Name  => 'PA',
5178                 	 P_Msg_Name        => 'PA_VFC_INVALID_FIN_CAT_CODE',
5179                          p_token1          => 'PLAN_RES',
5180                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5181 	When MAN_PARAMS_NULL Then
5182 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5183 		X_Error_Message_Code	:= 'PA_VFC_MAN_PARAMS_NULL';
5184 		Pa_Utils.Add_Message
5185                		(P_App_Short_Name  => 'PA',
5186                 	 P_Msg_Name        => 'PA_VFC_MAN_PARAMS_NULL',
5187                          p_token1          => 'PLAN_RES',
5188                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5189 	When BAD_FIN_CAT_FOR_EVENT_TYPE Then
5190 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5191 		X_Error_Message_Code	:= 'PA_VFC_BAD_FINCAT_FOR_EVT_TYPE';
5192 		Pa_Utils.Add_Message
5193                		(P_App_Short_Name  => 'PA',
5194               	         P_Msg_Name        => 'PA_VFC_BAD_FINCAT_FOR_EVT_TYPE',
5195                          p_token1          => 'PLAN_RES',
5196                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5197 	When BAD_FIN_CAT_FOR_EXP_TYPE Then
5198 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5199 		X_Error_Message_Code	:= 'PA_VFC_BAD_FIN_CAT_FOR_EXP_TYP';
5200 		Pa_Utils.Add_Message
5201                		(P_App_Short_Name  => 'PA',
5202               	         P_Msg_Name        => 'PA_VFC_BAD_FIN_CAT_FOR_EXP_TYP',
5203                          p_token1          => 'PLAN_RES',
5204                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5205 	When BAD_FIN_CAT_FOR_EXP_CAT Then
5206 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5207 		X_Error_Message_Code	:= 'PA_VFC_BAD_FIN_CAT_FOR_EXP_CAT';
5208 		Pa_Utils.Add_Message
5209                		(P_App_Short_Name  => 'PA',
5210               	         P_Msg_Name        => 'PA_VFC_BAD_FIN_CAT_FOR_EXP_CAT',
5211                          p_token1          => 'PLAN_RES',
5212                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5213 	When BAD_FIN_CAT_FOR_REV_CAT Then
5214 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5215 		X_Error_Message_Code	:= 'PA_VFC_BAD_FIN_CAT_FOR_REV_CAT';
5216 		Pa_Utils.Add_Message
5217                		(P_App_Short_Name  => 'PA',
5218               	         P_Msg_Name        => 'PA_VFC_BAD_FIN_CAT_FOR_REV_CAT',
5219                          p_token1          => 'PLAN_RES',
5220                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5221 	When BAD_FIN_CAT_UOM Then
5222 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5223 		X_Error_Message_Code	:= 'PA_VFC_BAD_FIN_CAT_UOM';
5224 		Pa_Utils.Add_Message
5225                		(P_App_Short_Name  => 'PA',
5226                 	 P_Msg_Name        => 'PA_VFC_BAD_FIN_CAT_UOM',
5227                          p_token1          => 'PLAN_RES',
5228                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5229 	When Others Then
5230 		Raise;
5231 
5232  End Validate_Fin_Category;
5233 
5234 /*----------------------------------------------------------------------------*/
5235 -- Start of Comments
5236 -- API name                      : Get_Resource_Cost_Rate
5237 -- Type                          : Procedure
5238 -- Pre-reqs                      : None
5239 -- Function                      : To get the Resource Rate and  Currency attributes.
5240 -- Prameters
5241 -- P_eligible_rlm_id_tbl      IN    SYSTEM.PA_NUM_TBL_TYPE  REQUIRED  --Resource List Member Id
5242 -- P_project_id               IN    NUMBER  REQUIRED
5243 --  History
5244 --  05-MAR-04   Vgade                    -Created
5245 --
5246 /*----------------------------------------------------------------------------*/
5247 Procedure Get_Resource_Cost_Rate(
5248    P_eligible_rlm_id_tbl      IN  SYSTEM.PA_NUM_TBL_TYPE
5249   ,P_project_id               IN  pa_projects_all.project_id%type
5250   ,p_structure_type           IN VARCHAR2
5251   ,p_fin_plan_type_id         IN NUMBER  DEFAULT NULL
5252   ,P_resource_curr_code_tbl   OUT NOCOPY SYSTEM.PA_VARCHAR2_15_TBL_TYPE
5253   ,P_resource_raw_rate_tbl    OUT NOCOPY SYSTEM.PA_NUM_TBL_TYPE
5254   ,P_resource_burden_rate_tbl OUT NOCOPY SYSTEM.PA_NUM_TBL_TYPE
5255    ) AS
5256 --Start of variables used for debugging
5257    l_msg_count                      NUMBER :=0;
5258    l_data                           VARCHAR2(2000);
5259    l_msg_data                       VARCHAR2(2000);
5260    l_error_msg_code                 VARCHAR2(30);
5261    l_msg_index_out                  NUMBER;
5262    l_return_status                  VARCHAR2(2000);
5263    l_debug_mode                     VARCHAR2(30);
5264   --End of variables used for debugging
5265 
5266    l_task_id                         pa_tasks.task_id%TYPE;
5267    l_top_task_id                     pa_tasks.task_id%TYPE;
5268   l_bill_job_group_id                pa_projects_all.bill_job_group_id%TYPE;
5269   l_project_type                     pa_projects_all.project_type%TYPE;
5270   l_expenditure_type                 pa_resource_assignments.expenditure_type%TYPE;
5271   l_org_id                           pa_projects_all.org_id%TYPE;
5272   l_expenditure_OU                   pa_projects_all.org_id%TYPE;
5273   l_txn_currency_code_override       pa_fp_res_assignments_tmp.txn_currency_code_override%TYPE;
5274   l_cost_rate_multiplier             CONSTANT pa_labor_cost_multipliers.multiplier%TYPE := 1;
5275 --  l_burden_override_multiplier       pa_fp_res_assignments_tmp.b_multiplier_override%TYPE;
5276   l_burden_override_multiplier       Number;
5277   l_cost_override_rate               pa_fp_res_assignments_tmp.rw_cost_rate_override%TYPE;
5278   l_raw_cost                         pa_fp_res_assignments_tmp.txn_raw_cost%TYPE;
5279   l_raw_cost_rate                    pa_fp_res_assignments_tmp.raw_cost_rate%TYPE;
5280   l_burden_cost                      pa_fp_res_assignments_tmp.txn_burdened_cost%TYPE;
5281   l_mfc_cost_type_id                 pa_resource_assignments.mfc_cost_type_id%TYPE;
5282   l_mfc_cost_source                  CONSTANT NUMBER := 2;
5283 
5284  --Out variables
5285   l_txn_raw_cost                     number;
5286   l_txn_cost_rate                    number;
5287   l_txn_burden_cost                  number;
5288   l_txn_burden_cost_rate             number;
5289   l_burden_multiplier                number;
5290   l_cost_ind_compiled_set_id         number;
5291   l_raw_cost_rejection_code          varchar2(1000);
5292   l_burden_cost_rejection_code       varchar2(1000);
5293   -- Changes for PFC
5294   l_func_currency_code               varchar2(15);
5295   l_dummy_rate_date                  Date;
5296   l_dummy_rate_type                  Varchar2(100);
5297   l_dummy_exch_rate                  Number;
5298   l_dummy_cost                       Number;
5299   l_final_txn_rate_date              Date;
5300   l_final_txn_rate_type              Varchar2(100);
5301   l_final_txn_exch_rate              Number;
5302   l_final_txn_burden_cost            Number;
5303   l_status                           Varchar2(100);
5304   l_stage                            Number;
5305 
5306   l_wp_versioning                    Varchar2(1);
5307   l_wp_vers_id                       Number;
5308   l_budget_version_id                Number;
5309 
5310 l_resource_list_member_Id_tab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
5311 l_resource_assignment_id_tab SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
5312 l_expenditure_ou_tbl         SYSTEM.PA_NUM_TBL_TYPE := SYSTEM.PA_NUM_TBL_TYPE();
5313 
5314 l_burden_multiplier_tab      SYSTEM.PA_NUM_TBL_TYPE :=SYSTEM.PA_NUM_TBL_TYPE();
5315 l_ind_compiled_set_id_tab    SYSTEM.PA_NUM_TBL_TYPE :=SYSTEM.PA_NUM_TBL_TYPE();
5316 l_bill_rate_tab              SYSTEM.PA_NUM_TBL_TYPE :=SYSTEM.PA_NUM_TBL_TYPE();
5317 l_markup_percent_tab         SYSTEM.PA_NUM_TBL_TYPE :=SYSTEM.PA_NUM_TBL_TYPE();
5318 l_txn_currency_code_tab  SYSTEM.PA_VARCHAR2_15_TBL_TYPE := SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
5319 l_rev_txn_curr_code_tab  SYSTEM.PA_VARCHAR2_15_TBL_TYPE := SYSTEM.PA_VARCHAR2_15_TBL_TYPE();
5320 l_cost_rejection_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
5321 l_burden_rejection_code_tab  SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
5322 l_revenue_rejection_code_tab SYSTEM.PA_VARCHAR2_30_TBL_TYPE := SYSTEM.PA_VARCHAR2_30_TBL_TYPE();
5323 
5324 
5325 Begin
5326 IF p_structure_type = 'WORKPLAN' THEN
5327    l_wp_versioning := PA_WORKPLAN_ATTR_UTILS.CHECK_WP_VERSIONING_ENABLED(
5328                                     p_project_id => p_project_id);
5329    IF l_wp_versioning = 'Y' THEN
5330       l_wp_vers_id := PA_PROJECT_STRUCTURE_UTILS.get_current_working_ver_id(
5331                                     p_project_id => p_project_id);
5332       IF l_wp_vers_id IS NULL THEN
5333          l_wp_vers_id := PA_PROJECT_STRUCTURE_UTILS.get_latest_wp_version(
5334                                     p_project_id => p_project_id);
5335       END IF;
5336    ELSE
5337       l_wp_vers_id := PA_PROJECT_STRUCTURE_UTILS.get_latest_wp_version(
5338                                     p_project_id => p_project_id);
5339    END IF;
5340 
5341    IF l_wp_vers_id IS NOT NULL THEN
5342       SELECT budget_version_id
5343       INTO   l_budget_version_id
5344       FROM   pa_budget_versions
5345       WHERE  project_structure_version_id = l_wp_vers_id
5346       AND    wp_version_flag = 'Y';
5347    END IF;
5348 
5349 ELSE
5350    -- Bug 4779037 - added in Financial plan case.
5351    SELECT MAX(bv.budget_version_id)
5352    INTO   l_budget_version_id
5353    FROM   pa_budget_versions bv
5354    WHERE  bv.fin_plan_type_id = p_fin_plan_type_id
5355    AND    bv.project_id = p_project_id
5356    AND    NVL(wp_version_flag,'N') = 'N'
5357    AND    NVL(bv.budget_status_code,'W') IN ('W','S');
5358 END IF;
5359 
5360         PA_FIN_PLAN_UTILS2.Get_Resource_Rates
5361         ( p_calling_module              => 'MSP'
5362         ,p_source_context               => 'RLMI'
5363         ,p_project_id                   => p_project_id
5364         ,p_budget_version_id            => l_budget_version_id
5365         ,p_resource_list_member_Id_tab  => p_eligible_rlm_id_tbl
5366         ,x_cost_txn_curr_code_tab       => P_resource_curr_code_tbl
5367         ,x_raw_cost_rate_tab            => P_resource_raw_rate_tbl
5368         ,x_burden_cost_rate_tab         => P_resource_burden_rate_tbl
5369         ,x_expenditure_ou_tab           => l_expenditure_ou_tbl
5370         ,x_resource_assignment_id_tab   => l_resource_assignment_id_tab
5371         ,x_resource_list_member_Id_tab  => l_resource_list_member_Id_tab
5372         ,x_burden_multiplier_tab        => l_burden_multiplier_tab
5373         ,x_ind_compiled_set_id_tab      => l_ind_compiled_set_id_tab
5374         ,x_bill_rate_tab                => l_bill_rate_tab
5375         ,x_markup_percent_tab           => l_markup_percent_tab
5376         ,x_txn_currency_code_tab        => l_txn_currency_code_tab
5377         ,x_rev_txn_curr_code_tab        => l_rev_txn_curr_code_tab
5378         ,x_cost_rejection_code_tab      => l_cost_rejection_code_tab
5379         ,x_burden_rejection_code_tab    => l_burden_rejection_code_tab
5380         ,x_revenue_rejection_code_tab   => l_revenue_rejection_code_tab
5381         ,x_return_status                => l_return_status
5382         ,x_msg_data                     => l_msg_data
5383         ,x_msg_count                    => l_msg_count
5384         );
5385 
5386         -- If the currency code of the transaction is not the same as
5387         -- the project functional currency code, then convert it to the PFC.
5388         l_func_currency_code := PA_CURRENCY.get_currency_code;
5389         FOR i IN p_eligible_rlm_id_tbl.FIRST .. p_eligible_rlm_id_tbl.LAST LOOP
5390 
5391           IF P_resource_curr_code_tbl(i) <> l_func_currency_code  THEN
5392 
5393               pa_multi_currency_txn.get_currency_amounts (
5394                 p_project_id                  => p_project_id
5395                ,p_exp_org_id                  => l_expenditure_ou_tbl(i)
5396                ,p_calling_module              => 'WORKPLAN'
5397                ,p_task_id                     => null
5398                ,p_ei_date                     => SYSDATE
5399                ,p_denom_raw_cost              => 1
5400                ,p_denom_curr_code             => P_resource_curr_code_tbl(i)
5401                ,p_acct_curr_code              => l_func_currency_code
5402                ,p_accounted_flag              => 'N'
5403                ,p_acct_rate_date              => l_dummy_rate_date -- NA
5404                ,p_acct_rate_type              => l_dummy_rate_type -- NA
5405                ,p_acct_exch_rate              => l_dummy_exch_rate -- NA
5406                ,p_acct_raw_cost               => l_dummy_cost -- NA
5407                ,p_project_curr_code           => l_func_currency_code
5408                ,p_project_rate_type           => l_dummy_rate_type -- NA
5409                ,p_project_rate_date           => l_dummy_rate_date -- NA
5410                ,p_project_exch_rate           => l_dummy_exch_rate -- NA
5411                ,p_project_raw_cost            => l_dummy_cost -- NA
5412                ,p_projfunc_curr_code          => l_func_currency_code
5413                ,p_projfunc_cost_rate_type     => l_final_txn_rate_type
5414                ,p_projfunc_cost_rate_date     => l_final_txn_rate_date
5415                ,p_projfunc_cost_exch_rate     => l_final_txn_exch_rate
5416                ,p_projfunc_raw_cost           => l_final_txn_burden_cost
5417                ,p_system_linkage              => 'NER'
5418                ,p_status                      => l_status
5419                ,p_stage                       => l_stage);
5420 
5421            P_resource_raw_rate_tbl(i) := nvl(l_final_txn_exch_rate,0) * NVL(P_resource_raw_rate_tbl(i),0);
5422            P_resource_burden_rate_tbl(i) := nvl(l_final_txn_exch_rate,0) * NVL(P_resource_burden_rate_tbl(i),0);
5423            P_resource_curr_code_tbl(i) :=  l_func_currency_code;
5424         END IF;
5425   END LOOP;
5426 
5427 Exception
5428   When Others  Then
5429    null;
5430  -- END IF;   ------------------------------------------------------------}
5431 end Get_Resource_Cost_Rate;
5432 /*********************Eugene*******************/
5433 
5434  Procedure Validate_Incur_by_Resource(
5435 		P_Resource_Class_Code	  IN  Varchar2,
5436 		P_Res_Type_Code		  IN  Varchar2	Default Null,
5437 		P_Incur_By_Res_Code	  IN  varchar2	Default Null,
5438 		X_Person_Id		  OUT NOCOPY Number,
5439 		X_Incur_By_Role_Id	  OUT NOCOPY Number,
5440 		X_Job_Id		  OUT NOCOPY Number,
5441 		X_Person_Type_Code	  OUT NOCOPY varchar2,
5442 		X_Incur_By_Res_Class_Code OUT NOCOPY varchar2,
5443 		X_Return_Status		  OUT NOCOPY Varchar2,
5444 		X_Error_Message_Code	  OUT NOCOPY Varchar2)
5445 
5446  Is
5447 
5448 	MAN_PARAMS_NULL     Exception;
5449 	INVAL_RES_CLSS_CODE Exception;
5450 	INVAL_RES_TYPE_CODE Exception;
5451 	UNEXPEC_ERROR       Exception;
5452 
5453  Begin
5454 
5455 	-- Initialize values
5456 	X_Return_Status      := Fnd_Api.G_Ret_Sts_Success;
5457 	X_Error_Message_Code := Null;
5458 
5459 	If P_Incur_By_Res_Code is Null Or
5460 	   P_Res_Type_Code is NUll Then
5461 
5462 		Raise MAN_PARAMS_NULL;
5463 		--Raise UNEXPEC_ERROR;
5464 
5465 	End If;
5466 
5467 	If P_Resource_Class_Code <> 'FINANCIAL_ELEMENTS' Then
5468 
5469 		Raise INVAL_RES_CLSS_CODE;
5470 
5471 	End If;
5472 
5473 	If P_Res_Type_Code = 'NAMED_PERSON' Then
5474 
5475 		X_Person_Id := P_Incur_By_Res_Code;
5476 
5477 	ElsIf P_Res_Type_Code = 'JOB' Then
5478 
5479 		X_Job_Id := P_Incur_By_Res_Code;
5480 
5481 	ElsIf P_Res_Type_Code = 'PERSON_TYPE' Then
5482 
5483 		X_Person_Type_Code := P_Incur_By_Res_Code;
5484 
5485 	ElsIf P_Res_Type_Code = 'RESOURCE_CLASS' Then
5486 
5487 		X_Incur_By_Res_Class_Code := P_Incur_By_Res_Code;
5488 
5489 	ElsIf P_Res_Type_Code = 'ROLE' Then
5490 
5491 		X_Incur_By_Role_Id := P_Incur_By_Res_Code;
5492 
5493 	Else
5494 
5495 		Raise INVAL_RES_TYPE_CODE;
5496 
5497 	End If;
5498 
5499  Exception
5500         When UNEXPEC_ERROR THEN
5501               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
5502               --x_msg_count := x_msg_count + 1;
5503               x_error_message_code := Null;
5504               Fnd_Msg_Pub.Add_Exc_Msg(
5505                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
5506                         P_Procedure_Name   => 'Validate_Incur_by_Resource');
5507 
5508 	When MAN_PARAMS_NULL Then
5509 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5510 		X_Error_Message_Code	:= 'PA_VIR_MAN_PARAMS_NULL';
5511 		Pa_Utils.Add_Message
5512                		(P_App_Short_Name  => 'PA',
5513                 	 P_Msg_Name        => 'PA_VIR_MAN_PARAMS_NULL',
5514                          p_token1          => 'PLAN_RES',
5515                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5516 	When INVAL_RES_CLSS_CODE Then
5517 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5518 		X_Error_Message_Code	:= 'PA_VIR_INVAL_RES_CLSS_CODE';
5519 		Pa_Utils.Add_Message
5520                		(P_App_Short_Name  => 'PA',
5521                 	 P_Msg_Name        => 'PA_VIR_INVAL_RES_CLSS_CODE',
5522                          p_token1          => 'PLAN_RES',
5523                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5524 	When INVAL_RES_TYPE_CODE Then
5525 		X_Return_Status 	:= Fnd_Api.G_Ret_Sts_Error;
5526 		X_Error_Message_Code	:= 'PA_VIR_INVAL_RES_TYPE_CODE';
5527 		Pa_Utils.Add_Message
5528                		(P_App_Short_Name  => 'PA',
5529                 	 P_Msg_Name        => 'PA_VIR_INVAL_RES_TYPE_CODE',
5530                          p_token1          => 'PLAN_RES',
5531                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
5532 	When Others Then
5533 		Raise;
5534 
5535  End Validate_Incur_by_Resource;
5536 /***********Eugene**************/
5537 
5538 Procedure Validate_Planning_Resource(
5539 		P_Task_Name		  IN  VARCHAR2 	Default Null,
5540 		P_Task_Number		  IN  Varchar2 	Default Null,
5541 		P_Planning_Resource_Alias IN  Varchar2 	Default Null,
5542 		P_Resource_List_Member_Id IN  Number 	Default Null,
5543                 P_resource_list_id        IN  Number    Default Null,
5544 		P_Res_Format_Id		  IN  Number 	Default Null,
5545 		P_Resource_Class_Code	  IN  Varchar2,
5546 		P_Res_Type_Code		  IN  Varchar2 	Default Null,
5547 		P_Resource_Code		  IN  Varchar2 	Default Null,
5548 		P_Resource_Name		  IN  Varchar2 	Default Null,
5549 		P_Project_Role_Id	  IN  Number 	Default Null,
5550 		P_Project_Role_Name	  IN  Varchar2 	Default Null,
5551 		P_Team_Role	          IN  Varchar2 	Default Null,
5552 		P_Organization_Id	  IN  Number 	Default Null,
5553 		P_Organization_Name	  IN  Varchar2 	Default Null,
5554 		P_FC_Res_Type_Code	  IN  Varchar2 	Default Null,
5555 		P_Fin_Category_Name	  IN  Varchar2 	Default Null,
5556 		P_Supplier_Id		  IN  Number 	Default Null,
5557 		P_Supplier_Name		  IN  Varchar2 	Default Null,
5558 		P_Incur_By_Resource_Code  IN  varchar2 	Default Null,
5559 		P_Incur_By_Resource_Type  IN  Varchar2 	Default Null,
5560 		X_Resource_List_Member_Id OUT NOCOPY Number,
5561 		X_Person_Id		  OUT NOCOPY Number,
5562 		X_Bom_Resource_Id	  OUT NOCOPY Number,
5563 		X_Job_Id		  OUT NOCOPY Number,
5564 		X_Person_Type_Code	  OUT NOCOPY varchar2,
5565 		X_Non_Labor_Resource	  OUT NOCOPY varchar2,
5566 		X_Inventory_Item_Id	  OUT NOCOPY Number,
5567 		X_Item_Category_Id	  OUT NOCOPY Number,
5568 		X_Project_Role_Id	  OUT NOCOPY Number,
5569 		X_Team_Role	          OUT NOCOPY Varchar2,
5570 		X_Organization_Id	  OUT NOCOPY Number,
5571 		X_Expenditure_Type	  OUT NOCOPY Varchar2,
5572 		X_Expenditure_Category	  OUT NOCOPY Varchar2,
5573 		X_Event_Type		  OUT NOCOPY Varchar2,
5574 		X_Revenue_Category_Code	  OUT NOCOPY Varchar2,
5575 		X_Supplier_Id		  OUT NOCOPY Number,
5576 		X_Resource_Class_Id	  OUT NOCOPY Number,
5577 		X_resource_class_flag	  OUT NOCOPY varchar2,
5578 		X_Incur_By_Role_Id	  OUT NOCOPY Number,
5579 		X_Incur_By_Res_Class_Code OUT NOCOPY varchar2,
5580 		X_Incur_By_Res_Flag	  OUT NOCOPY varchar2,
5581 		X_Return_Status		  OUT NOCOPY Varchar2,
5582 		X_Msg_Data		  OUT NOCOPY Varchar2,
5583 		X_Msg_Count		  OUT NOCOPY Number)
5584 
5585 
5586  Is
5587 
5588 	Cursor c_Res_List_Mem (P_Plan_Res_List_Mem_Id In Number Default Null)
5589 Is
5590 	Select
5591 		Resource_List_Member_Id,
5592 		Res_Format_Id
5593 	From
5594 		Pa_Resource_List_Members
5595 	Where   (P_Plan_Res_List_Mem_Id is Not Null and
5596 		 Resource_List_Member_Id = P_Plan_Res_List_Mem_Id)  ;
5597 
5598         Cursor c_get_migration_code (P_Res_List_Mem_Id In Number) Is
5599         Select migration_code
5600         From   Pa_Resource_List_Members
5601         Where  Resource_List_Member_Id = P_Res_List_Mem_Id;
5602 
5603 	Cursor c_Get_Fmt_Details (P_Res_Format_Id IN Number ) is
5604 	Select
5605 		Res_Type_Id,
5606 		Res_Type_Enabled_Flag,
5607 		Orgn_Enabled_Flag,
5608 		Fin_Cat_Enabled_Flag,
5609 		Incurred_By_Enabled_Flag,
5610 		Supplier_Enabled_Flag,
5611 		Role_Enabled_flag,
5612 		Resource_Class_Flag
5613 	From
5614 		Pa_Res_Formats_B
5615 	Where
5616 		Res_Format_Id = P_Res_Format_Id;
5617 
5618         CURSOR get_job_group_id(p_res_list_id in NUMBER) is
5619         select job_group_id
5620         from pa_resource_lists_all_bg
5621         where resource_list_id = p_res_list_id;
5622 
5623         CURSOR chk_job_in_job_group(p_job_group_id IN NUMBER,
5624                                     p_Job_ID in NUMBER) IS
5625         select 'Y'
5626         from per_jobs
5627         where job_group_id = p_job_group_id
5628         and  Job_ID = p_Job_ID;
5629 
5630         CURSOR get_res_list_id(p_res_member_id in NUMBER) is
5631         select resource_list_id
5632         from pa_resource_list_members
5633         where resource_list_member_id = p_res_member_id;
5634 
5635 	l_Resource_List_Member_Id 	Number := Null;
5636 	l_Res_Format_Id           	Number := Null;
5637 	l_Person_Id			Number := Null;
5638 	l_Incur_By_Role_Id		Number := Null;
5639 	l_Job_Id			Number := Null;
5640 	l_Person_Type_Code		varchar2(30) := Null;
5641 	l_Incur_By_Res_Class_Code	varchar2(30) := Null;
5642 	-- l_dummy_Res_Class_Flag	 	Varchar2(30) := Null;
5643 	l_dummy_Res_Class_Code		Varchar2(30) := Null;
5644         l_bom_combo_exists              Varchar2(1) := 'N';
5645 	l_jg_valid            		Varchar2(1) := 'Y';
5646 	l_job_group_id                  Number := Null;
5647 	l_resource_list_id              Number := Null;
5648         l_team_role                     Varchar2(80);
5649 	l_migration_code         	Varchar2(1) := 'N';
5650 	--PARAMS_ALL_NULL          	Exception;
5651 	--BAD_PLAN_RES_LIST_ALIAS  	Exception;
5652 	--BAD_PLAN_RES_LIST_MEM_ID  	Exception;
5653 	--PLN_RL_FORMAT_BAD_FMT_ID	Exception;
5654 	INVALID_BOM_COMBO		Exception;
5655 	BAD_FC_PARAM_COMBO		Exception;
5656 	BAD_INCUR_PARAM_COMBO		Exception;
5657 	MISSING_RES_TYPE_VALUES		Exception;
5658 	MISSING_ORG_VALUES		Exception;
5659 	MISSING_FC_VALUES		Exception;
5660 	MISSING_INCUR_BY_VALUES		Exception;
5661 	MISSING_SUPPLIER_VALUES		Exception;
5662 	MISSING_ROLE_VALUES		Exception;
5663 	MISSING_TEAM_ROLE		Exception;
5664 	FAIL_VALIDATION			Exception;
5665 	-- JOB_GROUP_ERROR			Exception;
5666 	UNEXPEC_ERROR			Exception;
5667 
5668 	l_List_Mem_Rec 			c_Res_List_Mem%RowType;
5669 	l_fmt_details  			c_Get_Fmt_Details%RowType;
5670 
5671 	Function AddTaskAlias(P_Error_Code  IN Varchar2,
5672 			      P_Task_Number IN Varchar2,
5673 			      P_Task_Name   IN Varchar2,
5674 			      P_Alias       IN Varchar2) Return Varchar2
5675 
5676 	Is
5677 
5678 		l_Return_Value Varchar2(2000) := Null;
5679 
5680 	Begin
5681 
5682 		If P_Task_Number is not null and P_Task_Name is Not Null and P_Alias is Not Null Then
5683 
5684 			l_Return_Value := P_Error_Code || P_Task_Number || P_Task_Name || P_Alias;
5685 
5686 		ElsIf P_Task_Number is not null and P_Task_Name is Not Null Then
5687 
5688 			l_Return_Value := P_Error_Code || P_Task_Number || P_Task_Name;
5689 
5690 		Else
5691 
5692 			l_Return_Value := P_Error_Code;
5693 
5694 		End If;
5695 
5696 		Return l_Return_Value;
5697 
5698 	End AddTaskAlias;
5699 
5700  Begin
5701 
5702 	-- Initialize Values
5703 	X_Return_Status           := Fnd_Api.G_Ret_Sts_Success;
5704 	X_Msg_Count               := 0;
5705 	X_Msg_Data                := Null;
5706 
5707         X_Incur_By_Res_Flag  := 'N'; -- set it to Yes when checking if
5708                                      -- incurred by resource exists.
5709 
5710 /* bug 3436074
5711 	If P_Resource_List_Member_Id is Null and
5712 	   P_Planning_Resource_Alias is Null and
5713 	   P_Res_Format_Id is Null Then
5714 */
5715 
5716 	If P_Resource_List_Member_Id is Null and
5717            P_Res_Format_Id is Null Then
5718 
5719 		--Raise PARAMS_ALL_NULL;
5720 		Raise UNEXPEC_ERROR;
5721 
5722 	End If;
5723 
5724         -- Added to ensure UOM validation for migrated resources
5725         -- is not done because of a corner case where it is possible
5726         -- (in the old model) to have an expenditure type of UOM <> Hours
5727         -- but track as labor as 'Y', which will be upgraded to PEOPLE
5728         -- resource class.
5729         l_migration_code := 'N';
5730 
5731 	If P_Resource_List_Member_Id is not Null Then
5732 
5733 		X_Resource_List_Member_Id := P_Resource_List_Member_Id;
5734                 OPEN c_get_migration_code(P_Res_List_Mem_Id =>
5735                                                 P_Resource_List_Member_Id);
5736                 FETCH c_get_migration_code INTO l_migration_code;
5737                 CLOSE c_get_migration_code;
5738 
5739 /* bug 3436074 with the change update top this code is not needed.
5740 	Else
5741 
5742 		If P_Planning_Resource_Alias is Not Null Then
5743 
5744 			Open c_Res_List_Mem (P_Plan_Res_Alias => P_Planning_Resource_Alias);
5745 			Fetch c_Res_List_Mem Into l_List_Mem_Rec;
5746 			If c_Res_List_Mem%NotFound Then
5747 
5748 				Close c_Res_List_Mem;
5749 				Raise BAD_PLAN_RES_LIST_ALIAS;
5750 
5751 			End If;
5752 			Close c_Res_List_Mem;
5753 
5754 			X_Resource_List_Member_Id := l_List_Mem_Rec.Resource_List_Member_Id;
5755 
5756 		End If;
5757 */
5758 
5759 	End If;
5760 
5761 	If P_Res_Format_Id Is Null Then
5762 
5763 		If x_Resource_List_Member_Id is Not Null Then
5764 
5765 			Open c_Res_List_Mem (P_Plan_Res_List_Mem_Id => x_Resource_List_Member_Id);
5766 			Fetch c_Res_List_Mem Into l_List_Mem_Rec;
5767 			If c_Res_List_Mem%NotFound Then
5768 
5769 				Close c_Res_List_Mem;
5770 				--Raise BAD_PLAN_RES_LIST_MEM_ID;
5771 				Raise UNEXPEC_ERROR;
5772 
5773 			End If;
5774 			Close c_Res_List_Mem;
5775 
5776 		End If;
5777 
5778 		l_Res_Format_Id := l_List_Mem_Rec.Res_Format_Id;
5779 
5780 	Else
5781 
5782 		l_Res_Format_Id := P_Res_Format_Id;
5783 
5784 	End If;
5785 
5786 	Open c_Get_Fmt_Details (P_Res_Format_Id => l_Res_Format_Id);
5787 	Fetch c_Get_Fmt_Details Into l_fmt_details;
5788 	If c_Get_Fmt_Details%NotFound Then
5789 
5790 		Close c_Get_Fmt_Details;
5791 		--Raise PLN_RL_FORMAT_BAD_FMT_ID;
5792 		Raise UNEXPEC_ERROR;
5793 
5794 	End If;
5795         Close c_Get_Fmt_Details; --Fix for bug#6504988
5796 
5797 	If ( ( P_FC_Res_Type_Code is Null and P_Fin_Category_Name is Null ) or
5798 	     ( P_FC_Res_Type_Code is Not Null and P_Fin_Category_Name is Not Null ) ) Then
5799 
5800 
5801 		Null;
5802 
5803 	Else
5804 		Raise BAD_FC_PARAM_COMBO;
5805 
5806 	End If;
5807 
5808 	If ( ( P_Incur_By_Resource_Code is Null and P_Incur_By_Resource_Type is Null ) Or
5809 	     ( P_Incur_By_Resource_Code is Not Null and P_Incur_By_Resource_Type is Not Null ) ) Then
5810 
5811 		Null;
5812 
5813 	Else
5814 		Raise BAD_INCUR_PARAM_COMBO;
5815 
5816 	End If;
5817 
5818         -- Set up resource class flag
5819         x_resource_class_flag := l_fmt_details.resource_class_flag;
5820 
5821 	If l_fmt_details.Res_Type_Enabled_Flag = 'Y' and
5822            P_Resource_Code is Null and
5823 	   P_Resource_Name is Null Then
5824 		Raise MISSING_RES_TYPE_VALUES;
5825 
5826 	ElsIf P_Resource_Code is Not Null or
5827 	      P_Resource_Name is Not Null Then
5828 
5829 -- hr_utility.trace('P_Resource_Code IS : ' || P_Resource_Code);
5830 -- hr_utility.trace('P_Resource_Name IS : ' || P_Resource_Name);
5831         	-- Populate g_job_group_id: if the resource is a job then
5832         	-- need to validate against job group ID.
5833         	-- Get job group ID from resource list of member
5834        		-- if not passed in.
5835 		l_resource_list_id := p_resource_list_id;
5836 
5837 		If p_resource_list_member_id is not null Then
5838 
5839                		open get_res_list_id(p_resource_list_member_id);
5840                         fetch get_res_list_id into l_resource_list_id;
5841                         close get_res_list_id;
5842 
5843 		End If;
5844 
5845 		If l_resource_list_id IS NOT NULL THEN
5846 
5847                		open get_job_group_id(l_resource_list_id);
5848                         fetch get_job_group_id into g_job_group_id;
5849                         close get_job_group_id;
5850 
5851 		End If;
5852 
5853 -- hr_utility.trace('g_job_group_id IS : ' || g_job_group_id);
5854 -- hr_utility.trace('Before Pa_Planning_Resource_Utils.Validate_Resource');
5855 		Pa_Planning_Resource_Utils.Validate_Resource(
5856 			P_resource_Code		=> P_Resource_Code,
5857 			P_Resource_Name		=> P_Resource_Name,
5858 			P_Resource_Class_Code	=> P_Resource_Class_Code,
5859 			P_Res_Type_Code		=> P_Res_Type_Code,
5860 			X_Person_Id		=> X_Person_Id,
5861 			X_Bom_Resource_Id	=> X_Bom_Resource_Id,
5862 			X_Job_Id		=> X_Job_Id,
5863 			X_Person_Type_Code	=> X_Person_Type_Code,
5864 			X_Non_Labor_Resource	=> X_Non_Labor_Resource,
5865 			X_Inventory_Item_Id	=> X_Inventory_Item_Id,
5866 			X_Item_Category_Id	=> X_Item_Category_Id,
5867 			X_Resource_Class_Code	=> l_Dummy_Res_Class_Code,
5868 			X_Resource_Class_Flag	=> X_resource_class_flag,
5869 			X_Return_Status		=> X_Return_Status,
5870 			X_Error_Msg_Code	=> X_Msg_Data);
5871 
5872 -- hr_utility.trace('After Pa_Planning_Resource_Utils.Validate_Resource');
5873 -- hr_utility.trace('X_Return_Status IS : ' || X_Return_Status);
5874 -- hr_utility.trace('X_Msg_Data IS : ' || X_Msg_Data);
5875 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
5876 
5877 			Raise FAIL_VALIDATION;
5878 
5879 		End If;
5880 
5881 	End If;
5882 
5883 	If l_fmt_details.Orgn_Enabled_Flag = 'Y' and
5884 	   P_Organization_Id is Null and
5885 	   P_Organization_Name is Null Then
5886 
5887 		Raise MISSING_ORG_VALUES;
5888 
5889 	ElsIf P_Organization_Id is Not Null or
5890 	      P_Organization_Name is Not Null Then
5891 		Pa_Planning_Resource_Utils.Validate_Organization(
5892 			P_Organization_Name => P_Organization_Name,
5893 			P_Organization_Id   => P_Organization_Id,
5894 			X_Organization_Id   => X_Organization_Id,
5895 			X_Return_Status     => X_Return_Status,
5896 			X_Error_Msg_Code    => X_Msg_Data);
5897 
5898 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
5899 			Raise FAIL_VALIDATION;
5900 
5901 		End If;
5902 
5903 	End If;
5904 
5905 	If l_fmt_details.Fin_Cat_Enabled_Flag = 'Y' and
5906 	   P_FC_Res_Type_Code is Null and
5907 	   P_Fin_Category_Name is Null Then
5908 
5909 		Raise MISSING_FC_VALUES;
5910 
5911 	ElsIf P_FC_Res_Type_Code is Not Null or
5912 	      P_Fin_Category_Name is Not Null Then
5913 
5914 		Pa_Planning_Resource_Utils.Validate_Fin_Category(
5915 			P_FC_Res_Type_Code	=> P_FC_Res_Type_Code,
5916 			P_Resource_Class_Code	=> P_Resource_Class_Code,
5917 			P_Fin_Category_Name	=> P_Fin_Category_Name,
5918                         P_migration_code        => l_migration_code,
5919 			X_Expenditure_Type	=> X_Expenditure_Type,
5920 			X_Expenditure_Category 	=> X_Expenditure_Category,
5921 			X_Event_Type		=> X_Event_Type,
5922 			X_Revenue_Category	=> X_Revenue_Category_Code,
5923 			X_Return_Status		=> X_Return_Status,
5924 			X_Error_Message_Code	=> X_Msg_Data);
5925 
5926 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
5927 
5928 			Raise FAIL_VALIDATION;
5929 
5930 		End If;
5931 
5932 	End If;
5933 
5934 	If l_fmt_details.Incurred_By_Enabled_Flag = 'Y' and
5935 	   P_Incur_By_Resource_Code is Null and
5936 	   P_Incur_By_Resource_Type is Null Then
5937 
5938 			Raise MISSING_INCUR_BY_VALUES;
5939 
5940 	ElsIf P_Incur_By_Resource_Code is Not Null or
5941 	      P_Incur_By_Resource_Type is Not Null Then
5942 
5943 		If P_Resource_Class_Code = 'FINANCIAL_ELEMENTS' Then
5944 
5945 			Pa_Planning_Resource_Utils.Validate_Incur_by_Resource(
5946 				P_Resource_Class_Code	  => P_Resource_Class_Code,
5947 				P_Res_Type_Code		  => P_Incur_By_Resource_Type,
5948 				P_Incur_By_Res_Code	  => P_Incur_By_Resource_Code,
5949 				X_Person_Id		  => l_Person_Id,
5950 				X_Incur_By_Role_Id	  => l_Incur_By_Role_Id,
5951 				X_Job_Id		  => l_Job_Id,
5952 				X_Person_Type_Code	  => l_Person_Type_Code,
5953 				X_Incur_By_Res_Class_Code => l_Incur_By_Res_Class_Code,
5954 				X_Return_Status		  => X_Return_Status,
5955 				X_Error_Message_Code	  => X_Msg_Data);
5956 
5957 			If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
5958 
5959 				Raise FAIL_VALIDATION;
5960 
5961 			End If;
5962 
5963 			X_Incur_By_Res_Flag := 'Y';
5964 
5965 			If P_Incur_By_Resource_Type = 'NAMED_PERSON' Then
5966 
5967 				X_Person_Id := l_Person_Id;
5968 
5969 			ElsIf P_Incur_By_Resource_Type = 'ROLE' Then
5970 
5971 				X_Incur_By_Role_Id := l_Incur_By_Role_Id;
5972 
5973 			ElsIf P_Incur_By_Resource_Type = 'JOB' Then
5974 
5975 				X_Job_Id := l_Job_Id;
5976 
5977 			ElsIf P_Incur_By_Resource_Type = 'PERSON_TYPE' Then
5978 
5979 				X_Person_Type_Code := l_Person_Type_Code;
5980 
5981 			ElsIf P_Incur_By_Resource_Type = 'RESOURCE_CLASS' Then
5982 
5983 				X_Incur_By_Res_Class_Code := l_Incur_By_Res_Class_Code;
5984 
5985 			End If;
5986 
5987 		End If; -- P_Resource_Class_Code = 'FINANCIAL_ELEMENTS'
5988 
5989 	End If;
5990 
5991 	If l_fmt_details.Supplier_Enabled_Flag = 'Y' and
5992 	   P_Supplier_Id is Null and
5993 	   P_Supplier_Name is Null Then
5994 
5995 		Raise MISSING_SUPPLIER_VALUES;
5996 
5997 	ElsIf P_Supplier_Id is Not Null or
5998  	      P_Supplier_Name is Not Null Then
5999 
6000 		Pa_Planning_Resource_Utils.Validate_Supplier(
6001 			P_Resource_Class_Code 	=> P_Resource_Class_Code,
6002 			P_Person_Id	 	=> x_person_id,
6003 			P_Supplier_Id	 	=> P_Supplier_Id,
6004 			P_Supplier_Name	 	=> P_Supplier_Name,
6005 			X_Supplier_Id	 	=> X_Supplier_Id,
6006 			X_Return_Status	 	=> X_Return_Status,
6007 			X_Error_Msg_Code 	=> X_Msg_Data);
6008 
6009 -- dbms_output.put_line('- After Validate_Supplier X_Supplier_Id IS : '|| X_Supplier_Id);
6010  -- dbms_output.put_line('- After Validate_Supplier X_Return_Status IS : '|| X_Return_Status);
6011 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
6012 
6013 			Raise FAIL_VALIDATION;
6014 
6015 		End If;
6016 
6017 	End If;
6018         -- Team Role changes
6019         /******************************************************
6020          * Checking for combination of p_project_role_id and p_team_role
6021          * If p_project_role_id is null then p_team_role must be null.
6022          * If p_project_role_id is not null, then p_team_role must be
6023          * not null.
6024          *******************************************************/
6025          /*******************************************************
6026           * Bug - 3601619
6027           * Desc - If the p_team_role paramter is null, and the
6028           * p_Project_Role_Name is not Null or the p_project_role_id
6029           * is not Null, then we will default the p_team_role to be
6030           * the same as the P_Project_Role_Name.
6031           ************************************************************/
6032           IF p_team_role IS NULL THEN
6033               IF l_fmt_details.Role_Enabled_flag = 'Y' THEN
6034                  IF P_Project_Role_Name IS NOT NULL THEN
6035                     l_team_role := P_Project_Role_Name;
6036                  ELSE
6037                     IF p_project_role_id IS NOT NULL THEN
6038                        l_team_role := Pa_Planning_Resource_Utils.Ret_Role_Name
6039                                       (P_Role_Id => p_project_role_id );
6040                     END IF;
6041                  END IF;
6042               ELSE
6043                  l_team_role := NULL;
6044               END IF;
6045           ELSE
6046              -- Cannot have a team role without a role, regardless of
6047 	     -- whether role/team role is part of format.
6048              -- Check for Role existence.
6049              IF P_Project_Role_Name IS NULL and p_project_role_id IS NULL AND
6050                 P_Task_Name IS NULL and P_Task_Number IS NULL THEN
6051                 -- Added task name and number check because from TA flow,
6052                 -- it is acceptable in some cases to have a team role
6053                 -- without a role.
6054                 RAISE MISSING_TEAM_ROLE;
6055              ELSE
6056                 l_team_role := p_team_role;
6057              END IF;
6058           END IF;
6059         --3601619
6060         --p_team_role changed to l_team_role.
6061 
6062 	If l_fmt_details.Role_Enabled_flag = 'Y' THEN
6063            IF (p_project_role_id IS NULL AND P_Project_Role_Name is Null and
6064                l_team_role IS NOT NULL) OR
6065             ((p_project_role_id IS NOT NULL OR P_Project_Role_Name is not null)
6066                 and l_team_role IS NULL)
6067            THEN
6068                 RAISE MISSING_TEAM_ROLE;
6069            END IF;
6070         END IF;
6071 
6072 	If l_fmt_details.Role_Enabled_flag = 'Y' and
6073 	   P_Project_Role_Id Is Null and
6074 	   P_Project_Role_Name is Null Then
6075 
6076 		Raise MISSING_ROLE_VALUES;
6077 
6078 	ElsIf P_Project_Role_Id Is Not Null or
6079 	      P_Project_Role_Name is Not Null Then
6080 
6081 		Pa_Role_Utils.Check_Role_Name_Or_Id(
6082 			P_Role_Id		=> P_Project_Role_Id,
6083 			P_Role_Name		=> P_Project_Role_Name,
6084                         p_check_id_flag         => PA_STARTUP.G_Check_ID_Flag,
6085 			X_Role_Id		=> X_Project_Role_Id,
6086 			X_Return_Status		=> X_Return_Status,
6087 			X_Error_Message_Code	=> X_Msg_Data);
6088 
6089 		If X_Return_Status = Fnd_Api.G_Ret_Sts_Error Then
6090 
6091 			Raise FAIL_VALIDATION;
6092 
6093 		End If;
6094 
6095 	End If;
6096         -- Assign out parameter x_team_role in all cases.
6097         -- Team Role changes
6098         --3601619
6099         x_team_role := l_team_role;
6100 
6101         -- Bug 4202047 - if BOM resource - Org format is used, check
6102         -- that the combination exists in BOM table - cannot override Org.
6103         IF X_Bom_Resource_Id IS NOT NULL AND
6104            X_Organization_Id IS NOT NULL THEN
6105 
6106            -- Validate the combination
6107            BEGIN
6108            SELECT 'Y'
6109              INTO l_bom_combo_exists
6110              FROM bom_resources b
6111             WHERE b.resource_id = X_Bom_Resource_Id
6112               AND b.organization_id = X_Organization_Id
6113               AND ROWNUM = 1;
6114 
6115            EXCEPTION
6116               WHEN NO_DATA_FOUND THEN
6117                  RAISE INVALID_BOM_COMBO;
6118            END;
6119 
6120         END IF;
6121 
6122  Exception
6123         When UNEXPEC_ERROR THEN
6124               X_Return_Status         := Fnd_Api.G_Ret_Sts_UnExp_Error;
6125               --x_msg_count := x_msg_count + 1;
6126               x_msg_data := Null;
6127               Fnd_Msg_Pub.Add_Exc_Msg(
6128                         P_Pkg_Name         => 'PA_PLANNING_RESOURCE_UTILS',
6129                         P_Procedure_Name   => 'Validate_Planning_Resource');
6130 
6131 	/*When PARAMS_ALL_NULL Then
6132 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6133 		X_Msg_Count     := 1;
6134 		X_Msg_Data      := AddTaskAlias(
6135 					P_Error_Code  => 'PA_PLN_RL_PARAMS_NULL',
6136 			      		P_Task_Number => P_Task_Number,
6137 			      		P_Task_Name   => P_Task_Name,
6138 					P_Alias       => P_Planning_Resource_Alias);
6139 		Pa_Utils.Add_Message
6140 			(P_App_Short_Name  => 'PA',
6141 			 P_Msg_Name        => 'PA_PLN_RL_PARAMS_NULL');*/
6142 
6143 	/*When BAD_PLAN_RES_LIST_ALIAS Then
6144 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6145 		X_Msg_Count     := 1;
6146 		X_Msg_Data      := AddTaskAlias(
6147 					P_Error_Code  => 'PA_PLN_RL_BAD_ALIAS',
6148 			      		P_Task_Number => P_Task_Number,
6149 			      		P_Task_Name   => P_Task_Name,
6150 					P_Alias       => P_Planning_Resource_Alias);
6151 		Pa_Utils.Add_Message
6152 			(P_App_Short_Name  => 'PA',
6153 			 P_Msg_Name        => 'PA_PLN_RL_BAD_ALIAS');*/
6154 
6155 	/*When BAD_PLAN_RES_LIST_MEM_ID Then
6156 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6157 		X_Msg_Count     := 1;
6158 		X_Msg_Data      := AddTaskAlias(
6159 					P_Error_Code  => 'PA_PLN_BAD_RL_MEM_ID',
6160 			      		P_Task_Number => P_Task_Number,
6161 			      		P_Task_Name   => P_Task_Name,
6162 					P_Alias       => P_Planning_Resource_Alias);
6163 		Pa_Utils.Add_Message
6164 			(P_App_Short_Name  => 'PA',
6165 			 P_Msg_Name        => 'PA_PLN_BAD_RL_MEM_ID');*/
6166 
6167 	/*When PLN_RL_FORMAT_BAD_FMT_ID Then
6168 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6169 		X_Msg_Count     := 1;
6170 		X_Msg_Data      := AddTaskAlias(
6171 					P_Error_Code  => 'PA_PLN_RL_FORMAT_BAD_FMT_ID',
6172 			      		P_Task_Number => P_Task_Number,
6173 			      		P_Task_Name   => P_Task_Name,
6174 					P_Alias       => P_Planning_Resource_Alias);
6175 		Pa_Utils.Add_Message
6176 			(P_App_Short_Name  => 'PA',
6177 			 P_Msg_Name        => 'PA_PLN_RL_FORMAT_BAD_FMT_ID');*/
6178 
6179 /*
6180         When JOB_GROUP_ERROR Then -- Error Message needs to be defined
6181                 X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6182                 X_Msg_Count     := 1;
6183                 X_Msg_Data      := AddTaskAlias(
6184                                         P_Error_Code  => 'PA_JOB_NOT_IN_JOB_GROUP',
6185                                         P_Task_Number => P_Task_Number,
6186                                         P_Task_Name   => P_Task_Name,
6187                                         P_Alias       => P_Planning_Resource_Alias);
6188                 Pa_Utils.Add_Message
6189                         (P_App_Short_Name  => 'PA',
6190                          P_Msg_Name        => 'PA_JOB_NOT_IN_JOB_GROUP',
6191                          p_token1          => 'PLAN_RES',
6192                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6193 */
6194 
6195 	When BAD_FC_PARAM_COMBO Then
6196 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6197 		X_Msg_Count     := 1;
6198 		X_Msg_Data      := AddTaskAlias(
6199 					P_Error_Code  => 'PA_PLN_RL_USE_FC_LOV',
6200 			      		P_Task_Number => P_Task_Number,
6201 			      		P_Task_Name   => P_Task_Name,
6202 					P_Alias       => P_Planning_Resource_Alias);
6203 		Pa_Utils.Add_Message
6204 			(P_App_Short_Name  => 'PA',
6205 			 P_Msg_Name        => 'PA_PLN_RL_USE_FC_LOV',
6206                          p_token1          => 'PLAN_RES',
6207                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6208 
6209 	When BAD_INCUR_PARAM_COMBO Then
6210 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6211 		X_Msg_Count     := 1;
6212 		X_Msg_Data      := AddTaskAlias(
6213 					P_Error_Code  => 'PA_PLN_RL_USE_INCUR_RES_LOV',
6214 			      		P_Task_Number => P_Task_Number,
6215 			      		P_Task_Name   => P_Task_Name,
6216 					P_Alias       => P_Planning_Resource_Alias);
6217 		Pa_Utils.Add_Message
6218 			(P_App_Short_Name  => 'PA',
6219 			 P_Msg_Name        => 'PA_PLN_RL_USE_INCUR_RES_LOV',
6220                          p_token1          => 'PLAN_RES',
6221                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6222 
6223 	When MISSING_RES_TYPE_VALUES Then
6224 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6225 		X_Msg_Count     := 1;
6226 		X_Msg_Data      := AddTaskAlias(
6227 					P_Error_Code  => 'PA_PLN_RL_NO_RES_TYPE',
6228 			      		P_Task_Number => P_Task_Number,
6229 			      		P_Task_Name   => P_Task_Name,
6230 					P_Alias       => P_Planning_Resource_Alias);
6231 		Pa_Utils.Add_Message
6232 			(P_App_Short_Name  => 'PA',
6233 			 P_Msg_Name        => 'PA_PLN_RL_NO_RES_TYPE',
6234                          p_token1          => 'PLAN_RES',
6235                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6236 
6237 	When MISSING_ORG_VALUES Then
6238 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6239 		X_Msg_Count     := 1;
6240 		X_Msg_Data      := AddTaskAlias(
6241 					P_Error_Code  => 'PA_PLN_RL_NO_ORG',
6242 			      		P_Task_Number => P_Task_Number,
6243 			      		P_Task_Name   => P_Task_Name,
6244 					P_Alias       => P_Planning_Resource_Alias);
6245 		Pa_Utils.Add_Message
6246 			(P_App_Short_Name  => 'PA',
6247 			 P_Msg_Name        => 'PA_PLN_RL_NO_ORG',
6248                          p_token1          => 'PLAN_RES',
6249                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6250 
6251 	When MISSING_FC_VALUES Then
6252 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6253 		X_Msg_Count     := 1;
6254 		X_Msg_Data      := AddTaskAlias(
6255 					P_Error_Code  => 'PA_PLN_RL_NO_FC',
6256 			      		P_Task_Number => P_Task_Number,
6257 			      		P_Task_Name   => P_Task_Name,
6258 					P_Alias       => P_Planning_Resource_Alias);
6259 		Pa_Utils.Add_Message
6260 			(P_App_Short_Name  => 'PA',
6261 			 P_Msg_Name        => 'PA_PLN_RL_NO_FC',
6262                          p_token1          => 'PLAN_RES',
6263                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6264 
6265 	When MISSING_INCUR_BY_VALUES Then
6266 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6267 		X_Msg_Count     := 1;
6268 		X_Msg_Data      := AddTaskAlias(
6269 					P_Error_Code  => 'PA_PLN_RL_NO_INCUR_BY',
6270 			      		P_Task_Number => P_Task_Number,
6271 			      		P_Task_Name   => P_Task_Name,
6272 					P_Alias       => P_Planning_Resource_Alias);
6273 		Pa_Utils.Add_Message
6274 			(P_App_Short_Name  => 'PA',
6275 			 P_Msg_Name        => 'PA_PLN_RL_NO_INCUR_BY',
6276                          p_token1          => 'PLAN_RES',
6277                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6278 
6279 	When MISSING_SUPPLIER_VALUES Then
6280 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6281 		X_Msg_Count     := 1;
6282 		X_Msg_Data      := AddTaskAlias(
6283 					P_Error_Code  => 'PA_PLN_RL_NO_SUPPLIER',
6284 			      		P_Task_Number => P_Task_Number,
6285 			      		P_Task_Name   => P_Task_Name,
6286 					P_Alias       => P_Planning_Resource_Alias);
6287 		Pa_Utils.Add_Message
6288 			(P_App_Short_Name  => 'PA',
6289 			 P_Msg_Name        => 'PA_PLN_RL_NO_SUPPLIER',
6290                          p_token1          => 'PLAN_RES',
6291                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6292 
6293 	When MISSING_ROLE_VALUES Then
6294 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6295 		X_Msg_Count     := 1;
6296 		X_Msg_Data      := AddTaskAlias(
6297 					P_Error_Code  => 'PA_PLN_RL_NO_ROLE',
6298 			      		P_Task_Number => P_Task_Number,
6299 			      		P_Task_Name   => P_Task_Name,
6300 					P_Alias       => P_Planning_Resource_Alias);
6301 		Pa_Utils.Add_Message
6302 			(P_App_Short_Name  => 'PA',
6303 			 P_Msg_Name        => 'PA_PLN_RL_NO_ROLE',
6304                          p_token1          => 'PLAN_RES',
6305                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6306 
6307 	When MISSING_TEAM_ROLE Then
6308 		X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6309 		X_Msg_Count     := 1;
6310 		X_Msg_Data      := AddTaskAlias(
6311 					P_Error_Code  => 'PA_PLN_RL_TEAM_ROLE',
6312 			      		P_Task_Number => P_Task_Number,
6313 			      		P_Task_Name   => P_Task_Name,
6314 					P_Alias       => P_Planning_Resource_Alias);
6315 		Pa_Utils.Add_Message
6316 			(P_App_Short_Name  => 'PA',
6317 			 P_Msg_Name        => 'PA_PLN_RL_TEAM_ROLE',
6318                          p_token1          => 'PLAN_RES',
6319                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6320 	When INVALID_BOM_COMBO Then
6321                 X_Return_Status := Fnd_Api.G_Ret_Sts_Error;
6322                 X_Msg_Count     := 1;
6323                 X_Msg_Data      := AddTaskAlias(
6324                                     P_Error_Code  => 'PA_PLN_RL_INV_BOM_ORG',
6325                                     P_Task_Number => P_Task_Number,
6326                                     P_Task_Name   => P_Task_Name,
6327                                     P_Alias       => P_Planning_Resource_Alias);
6328                 Pa_Utils.Add_Message
6329                         (P_App_Short_Name  => 'PA',
6330                          P_Msg_Name        => 'PA_PLN_RL_INV_BOM_ORG',
6331                          p_token1          => 'PLAN_RES',
6332                          p_value1          => Pa_Planning_Resource_Pvt.g_token);
6333 	When FAIL_VALIDATION Then
6334 		-- return status is already set by the called procedure already
6335 		X_Msg_Count := 1;
6336 		X_Msg_Data  := AddTaskAlias(
6337 					P_Error_Code  => X_Msg_Data,
6338 			      		P_Task_Number => P_Task_Number,
6339 			      		P_Task_Name   => P_Task_Name,
6340 					P_Alias       => P_Planning_Resource_Alias);
6341 		-- Assuming that all the called procedure already do add_message().
6342 
6343 	When Others Then
6344 		Raise;
6345 
6346  End Validate_Planning_Resource;
6347 /***************Eugene***************/
6348 
6349 /**********End of Get_Plan_Res_Combination Procedure ********/
6350 
6351 /*******************************************************
6352  * End Eugene's code
6353  * ***************************************************/
6354 
6355 /*********************************************************
6356  * Procedure : Derive_Resource_List_Member
6357  * Description : This Procedure is used to derive a
6358  *               resource list member, given a project ID
6359  *               resource_format Id and a few attributes.
6360  *               (1) It first Checks if the Mandatory values
6361  *                   are passed.
6362  *               (2) It then calls the API PA_TASK_ASSIGNMENT_UTILS
6363  *               Get_WP_Resource_List_Id --> which will return the
6364  *               resource list ID.
6365  *               (3) Then Based on the values passed Constructs a
6366  *               Dynamic SQL and retrieves the values from
6367  *               pa_resource_list_members table.
6368  *               (4) If no rows are returned then does step 5,6
6369  *               (5) Checks if the resource list is project specific
6370  *               If it is then creates a new resource_list_member
6371  *               Call to pa_planning_resource_pvt.create_planning_resource
6372  *               And passes back the newly
6373  *               created resource_list_member_id
6374  *               (6) If it is a Centrally controlled resource list
6375  *               Then it calls Vijays API which will return the best
6376  *               Matching resource list member.
6377  *               (6a) Insert into Pa_res_list_map_tmp1 and then call
6378  *               Api pa_resource_mapping.map_resource_list.
6379  *               which will put the correct resource_list_member_id
6380  *               in pa_res_list_map_tmp4.
6381  **************************************************************/
6382 Function Derive_Resource_List_Member
6383     (p_project_id                IN     NUMBER,
6384      p_res_format_id             IN     NUMBER,
6385      p_person_id                 IN     NUMBER     DEFAULT NULL,
6386      p_job_id                    IN     NUMBER     DEFAULT NULL,
6387      p_organization_id           IN     NUMBER     DEFAULT NULL,
6388      p_expenditure_type          IN     Varchar2   DEFAULT NULL,
6389      p_expenditure_category      IN     Varchar2   DEFAULT NULL,
6390      p_project_role_id           IN     Number     DEFAULT NULL,
6391      p_person_type_code          IN     Varchar2   DEFAULT NULL,
6392      p_named_role                IN     Varchar2   DEFAULT NULL)
6393    RETURN NUMBER
6394  IS
6395 
6396 CURSOR get_fmt_details (p_res_format_id NUMBER) IS
6397 SELECT f.Res_Type_Enabled_Flag,
6398        f.Orgn_Enabled_Flag,
6399        f.Fin_Cat_Enabled_Flag,
6400        f.Role_Enabled_Flag,
6401        f.incurred_by_enabled_flag,
6402        f.supplier_enabled_flag,
6403        f.Res_Type_Id,
6404        t.Res_Type_Code
6405 FROM   Pa_Res_Formats_B f,
6406        Pa_Res_Types_B t
6407 WHERE  f.Res_Type_Id = t.Res_Type_Id(+)
6408 AND    f.Res_Format_Id = p_res_format_id;
6409 
6410    l_resource_list_id        NUMBER;
6411    l_res_list_member_id      VARCHAR2(30);
6412    l_resource_list_member_id NUMBER;
6413    l_cursor                  INTEGER;
6414    l_rows                    INTEGER;
6415    l_stmt                    VARCHAR2(2000);
6416    l_exists                  VARCHAR2(1) := 'Y';
6417    l_central_control         VARCHAR2(1);
6418    l_valid                   VARCHAR2(1);
6419    l_valid_job               VARCHAR2(1);
6420    l_return_status           VARCHAR2(30);
6421    l_msg_count               NUMBER;
6422    l_error_msg_data          VARCHAR2(200);
6423    l_record_version_number   NUMBER;
6424    l_resource_class_id       NUMBER;
6425 
6426    l_fmt_details             get_fmt_details%RowType;
6427    l_person_id               NUMBER := NULL;
6428    l_job_id                  NUMBER := NULL;
6429    l_job_group_id            NUMBER := NULL;
6430    l_organization_id         NUMBER := NULL;
6431    l_project_role_id         NUMBER := NULL;
6432    l_person_type_code        VARCHAR2(30) := NULL;
6433    l_named_role              VARCHAR2(80) := NULL;
6434    l_fin_category_name       VARCHAR2(200) := NULL;
6435    l_fc_res_type_code        VARCHAR2(30) := NULL;
6436 
6437   BEGIN
6438       /***************************************************
6439       * The Project_ID and res_format_id are mandatory.
6440       * In case they are not passed. Raise an unexpected
6441       * error and return.
6442       ****************************************************/
6443       IF p_project_id IS NULL OR p_res_format_id IS NULL THEN
6444            l_resource_list_member_id := NULL;
6445            Return l_resource_list_member_id;
6446       END IF;
6447       /*************************************************
6448       * Call to Sheenie's API which will take in the
6449       * project_id and return back the resource_list_id.
6450       * It would get the resource_list_ID associated to the
6451       * project and for which Workplan is enabled.
6452       ****************************************************/
6453       l_resource_list_id :=
6454       Pa_Task_Assignment_Utils.Get_WP_Resource_List_Id(p_project_id);
6455 
6456       IF l_resource_list_id IS NULL THEN
6457            l_resource_list_member_id := NULL;
6458            Return l_resource_list_member_id;
6459       END IF;
6460 
6461      /****************************************************
6462       * Once we have got the Resource_List_ID
6463       * We need to establish if it is Project specific or
6464       * Centrally Controlled resource_list.
6465       *******************************************************/
6466       BEGIN
6467          SELECT control_flag
6468          INTO l_central_control
6469          FROM pa_resource_lists_all_bg
6470          WHERE resource_list_id = l_resource_list_id;
6471       EXCEPTION
6472       WHEN OTHERS THEN
6473            l_resource_list_member_id := NULL;
6474            Return l_resource_list_member_id;
6475       END;
6476     /********************************
6477     *    Open Cursor
6478     ********************************/
6479      l_cursor  := dbms_sql.open_cursor;
6480     /**************************************************************
6481     * Constructing the Select Statement based on the values passed
6482     * as parameters to this procedure.
6483     ***********************************************************/
6484   l_stmt := 'SELECT resource_list_member_id '||
6485             ' FROM pa_resource_list_members ' ||
6486             ' WHERE resource_list_id = :resource_list_id' ||
6487             ' AND enabled_flag = ''Y'' ' ||
6488             ' AND res_format_id = :res_format_id';
6489 
6490    -- Get the required segments of the format and append clauses
6491    -- based on that.  Fixes bug 3728941.
6492    Open get_fmt_details(p_res_format_id => p_res_format_id);
6493    Fetch get_fmt_details into l_fmt_details;
6494    Close get_fmt_details;
6495 
6496    /*****************************************
6497     * If person_ID value is passed then append
6498     * it to the Where clause.
6499     *******************************************/
6500     IF -- p_person_id IS NOT NULL AND
6501        l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
6502        l_fmt_details.Res_Type_Code = 'NAMED_PERSON'
6503     THEN
6504        l_person_id := p_person_id;
6505        l_stmt := l_stmt || ' AND person_id = :person_id';
6506     END IF;
6507 
6508    /*****************************************
6509     * If organization_id value is passed then append
6510     * it to the Where clause.
6511     *******************************************/
6512     IF --p_organization_id IS NOT NULL AND
6513        l_fmt_details.Orgn_Enabled_Flag = 'Y'
6514     THEN
6515        l_organization_id := p_organization_id;
6516        l_stmt := l_stmt || ' AND organization_id = :organization_id';
6517     END IF;
6518 
6519    /*****************************************
6520     * If job_id value is passed then append
6521     * it to the Where clause.
6522     *******************************************/
6523     IF -- p_job_id IS NOT NULL AND
6524        l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
6525        l_fmt_details.Res_Type_Code = 'JOB'
6526     THEN
6527        l_job_id := p_job_id;
6528        l_stmt := l_stmt || ' AND job_id = :job_id';
6529     END IF;
6530 
6531    /*****************************************
6532     * If expenditure_type value is passed then append
6533     * it to the Where clause.
6534     *******************************************/
6535     IF p_expenditure_type IS NOT NULL AND
6536        l_fmt_details.Fin_Cat_Enabled_Flag = 'Y'
6537     THEN
6538        l_fin_category_name := p_expenditure_type;
6539        l_fc_res_type_code  := 'EXPENDITURE_TYPE';
6540        l_stmt := l_stmt || ' AND expenditure_type = :expenditure_type AND fc_res_type_code = ''EXPENDITURE_TYPE''';
6541     END IF;
6542 
6543    /*****************************************
6544     * If expenditure_category value is passed then append
6545     * it to the Where clause.
6546     *******************************************/
6547     IF p_expenditure_category IS NOT NULL AND p_expenditure_type IS NULL AND
6548        l_fmt_details.Fin_Cat_Enabled_Flag = 'Y'
6549     THEN
6550        l_fin_category_name := p_expenditure_category;
6551        l_fc_res_type_code  := 'EXPENDITURE_CATEGORY';
6552        l_stmt := l_stmt || ' AND expenditure_category = :expenditure_category AND fc_res_type_code = ''EXPENDITURE_CATEGORY''';
6553     END IF;
6554 
6555     IF p_expenditure_category IS NULL AND p_expenditure_type IS NULL AND
6556        l_fmt_details.Fin_Cat_Enabled_Flag = 'Y'
6557     THEN
6558        l_fin_category_name := NULL;
6559        l_fc_res_type_code  := NULL;
6560        l_stmt := l_stmt || ' AND expenditure_category = :expenditure_category AND fc_res_type_code = ''EXPENDITURE_CATEGORY''';
6561 
6562     END IF;
6563    /*****************************************
6564     * If project_role_id value is passed then append
6565     * it to the Where clause.
6566     *******************************************/
6567    /*****************************************
6568     * If named_role value is passed then append
6569     * it to the Where clause.
6570     *******************************************/
6571     --IF p_named_role IS NOT NULL THEN
6572        --l_stmt := l_stmt || ' AND team_role = :named_role';
6573     --END IF;
6574     IF p_project_role_id IS NOT NULL AND p_named_role IS NOT NULL AND
6575        l_fmt_details.Role_Enabled_Flag = 'Y'
6576     THEN
6577        l_project_role_id := p_project_role_id;
6578        l_named_role := p_named_role;
6579        l_stmt := l_stmt || ' AND project_role_id = :project_role_id AND team_role = :named_role';
6580     END IF;
6581 
6582    /*****************************************
6583     * If person_type_code value is passed then append
6584     * it to the Where clause.
6585     *******************************************/
6586     IF -- p_person_type_code IS NOT NULL AND
6587        l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
6588        l_fmt_details.Res_Type_Code = 'PERSON_TYPE'
6589     THEN
6590        l_person_type_code := p_person_type_code;
6591        l_stmt := l_stmt || ' AND person_type_code = :person_type_code';
6592     END IF;
6593 
6594 
6595    /********************************************
6596     * If the List is Centrally Controlled
6597     * Then need to pass the object_type = 'RESOURCE_LIST'
6598     * and object_id = resource_list_id.
6599     * IF the List is not centrally controlled the
6600     * we need to pass the object_type = 'PROJECT'
6601     * and object_id = p_project_id.
6602     ********************************************/
6603     IF l_central_control = 'Y' THEN
6604         l_stmt := l_stmt || ' AND object_type = :object_type1';
6605         l_stmt := l_stmt || ' AND object_id = :resource_list_id';
6606     ELSE
6607         l_stmt := l_stmt || ' AND object_type = :object_type2';
6608         l_stmt := l_stmt || ' AND object_id = :project_id';
6609     END IF;
6610 
6611     --l_stmt := l_stmt || ';';
6612 
6613 -- dbms_output.put_line('l_stmt is :' || substr(l_stmt, 1, 240));
6614 -- dbms_output.put_line('l_stmt is :' || substr(l_stmt, 240, 500));
6615 -- dbms_output.put_line('p_res_format_id is :' || p_res_format_id);
6616 -- dbms_output.put_line('l_resource_list_id is :' || l_resource_list_id);
6617 -- dbms_output.put_line('p_project_role_id is :' || p_project_role_id);
6618 -- dbms_output.put_line('p_named_role is :' || p_named_role);
6619 -- dbms_output.put_line('p_project_id is :' || p_project_id);
6620     /*************************************
6621      *    Parse the Select Stmt
6622      ************************************/
6623     dbms_sql.parse(l_cursor,l_stmt,dbms_sql.native);
6624 
6625     /************************************
6626     * Bind the Variables
6627     ********************************/
6628     /******************************************
6629      * Bug - 3583651
6630      * Desc - Added code to Binnd the variables
6631      *        resource_list_id, res_format_id
6632      *********************************************/
6633      --Binding the resource_list_id column
6634         dbms_sql.bind_variable(l_cursor,'resource_list_id', l_resource_list_id);
6635      --Binding the res_format_id column
6636         dbms_sql.bind_variable(l_cursor,'res_format_id', p_res_format_id);
6637 
6638      --Binding the person_id column when p_person_id is not null
6639     IF -- p_person_id IS NOT NULL AND
6640        l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
6641        l_fmt_details.Res_Type_Code = 'NAMED_PERSON'
6642     THEN
6643         dbms_sql.bind_variable(l_cursor,'person_id', p_person_id);
6644     END IF;
6645      --Binding the job_id column when p_job_id is not null
6646     IF -- p_job_id IS NOT NULL AND
6647        l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
6648        l_fmt_details.Res_Type_Code = 'JOB'
6649     THEN
6650 -- dbms_output.put_line('p_job_id is :' || p_job_id);
6651         dbms_sql.bind_variable(l_cursor,'job_id', p_job_id);
6652     END IF;
6653      --Binding the organization_id column when p_organization_id is not null
6654     IF -- p_organization_id IS NOT NULL AND
6655        l_fmt_details.Orgn_Enabled_Flag = 'Y'
6656     THEN
6657 -- dbms_output.put_line('p_organization_id is :' || p_organization_id);
6658        dbms_sql.bind_variable(l_cursor,'organization_id', p_organization_id);
6659     END IF;
6660      --Binding the expenditure_type column when p_expenditure_type is not null
6661     IF p_expenditure_type IS NOT NULL AND
6662        l_fmt_details.Fin_Cat_Enabled_Flag = 'Y'
6663     THEN
6664        dbms_sql.bind_variable(l_cursor,'expenditure_type', p_expenditure_type);
6665     END IF;
6666      --Binding the expenditure_category column when
6667      --p_expenditure_category is not null
6668     IF p_expenditure_category IS NOT NULL AND p_expenditure_type IS NULL AND
6669        l_fmt_details.Fin_Cat_Enabled_Flag = 'Y'
6670     THEN
6671        dbms_sql.bind_variable(l_cursor,'expenditure_category',p_expenditure_category);
6672     END IF;
6673 
6674     IF p_expenditure_category IS NULL AND p_expenditure_type IS NULL AND
6675        l_fmt_details.Fin_Cat_Enabled_Flag = 'Y'
6676     THEN
6677        dbms_sql.bind_variable(l_cursor,'expenditure_category',l_fin_category_name);
6678     END IF;
6679      --Binding the project_role_id column when p_project_role_id is not null
6680      --Binding the named_role column when p_named_role is not null
6681     IF p_project_role_id IS NOT NULL AND p_named_role IS NOT NULL AND
6682        l_fmt_details.Role_Enabled_Flag = 'Y'
6683     THEN
6684        dbms_sql.bind_variable(l_cursor,'project_role_id', p_project_role_id);
6685        dbms_sql.bind_variable(l_cursor,'named_role', p_named_role);
6686     END IF;
6687     --Binding the person_type_code column when p_person_type_code is not null
6688     IF -- p_person_type_code IS NOT NULL AND
6689        l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
6690        l_fmt_details.Res_Type_Code = 'PERSON_TYPE'
6691     THEN
6692        dbms_sql.bind_variable(l_cursor,'person_type_code', p_person_type_code);
6693     END IF;
6694     --Binding the object_type1 column when l_central_control equals Y
6695     IF l_central_control = 'Y' THEN
6696        dbms_sql.bind_variable(l_cursor,'object_type1', 'RESOURCE_LIST');
6697     END IF;
6698     --Binding the object_type2 and project_id
6699     -- column when l_central_control does not equal Y
6700     IF l_central_control <> 'Y' THEN
6701        dbms_sql.bind_variable(l_cursor,'object_type2', 'PROJECT');
6702        dbms_sql.bind_variable(l_cursor,'project_id', p_project_id);
6703     END IF;
6704 
6705     --Define Output Variables
6706     --dbms_sql.define_column(l_cursor,1,l_resource_list_member_id,30);
6707     dbms_sql.define_column(l_cursor,1,l_resource_list_member_id);
6708 
6709     l_rows := dbms_sql.execute(l_cursor);
6710 
6711     /****************************
6712      * Loop Through the Records
6713      ****************************/
6714        /********************************************
6715        * If No Values are Found we are setting the l_exists
6716        * flag to be N. If the Value is N we need to do some
6717        * logic based on the centrally controlled flag.
6718        **********************************************/
6719         IF dbms_sql.fetch_rows(l_cursor) = 0 THEN
6720             l_exists := 'N';
6721         ELSE
6722             l_exists := 'Y';
6723         END IF;
6724     /**********************************************************
6725     * If the select returns some Value then assign it to the
6726     * l_resource_list_member_id.
6727     * ********************************************************/
6728     IF l_exists = 'Y' THEN
6729 -- dbms_output.put_line('l_exists is Y');
6730          dbms_sql.column_value(l_cursor,1,l_resource_list_member_id);
6731          dbms_sql.close_cursor(l_cursor);
6732 -- dbms_output.put_line('l_resource_list_member_id is :' || l_resource_list_member_id);
6733          --Return the l_resource_list_member_id
6734          --To the calling API
6735          RETURN l_resource_list_member_id;
6736    END IF;
6737 
6738    /***********************************************************
6739     * If for the resource_list_ID passed we were not able
6740     * to derive the appropriate member based on the param
6741     * passed then we have 2 options
6742     * depending on the centrally_controlled flag
6743     * on the resource_list.
6744     *************************************************************/
6745 
6746    /***********************************************************
6747    * If the Centrally Controlled flag = 'Y' Then we have to do the
6748    * following.
6749    * *********************************************************/
6750    IF l_exists = 'N' and l_central_control = 'Y' THEN
6751        --Delete the temp table.
6752        DELETE FROM pa_res_list_map_tmp1;
6753        DELETE FROM pa_res_list_map_tmp4;
6754        /***************************************************
6755        * Populate the temp table with the parameters passed in.
6756        * Then we need to call the mapping API, which
6757        * would read the values from the below table and will get
6758        * the best matching resource_list_member_id.
6759        * *****************************************************/
6760 -- dbms_output.put_line('l_fc_res_type_code IS : ' || l_fc_res_type_code);
6761 -- dbms_output.put_line('p_person_id IS : ' || p_person_id);
6762 -- dbms_output.put_line('p_job_id IS : ' || p_job_id);
6763 -- dbms_output.put_line('p_organization_id IS : ' || p_organization_id);
6764 -- dbms_output.put_line('p_expenditure_type IS : ' || p_expenditure_type);
6765 -- dbms_output.put_line('p_expenditure_category IS : ' || p_expenditure_category);
6766 -- dbms_output.put_line('p_project_role_id IS : ' || p_project_role_id);
6767 -- dbms_output.put_line('p_person_type_code IS : ' || p_person_type_code);
6768 
6769        -- populate fc_res_type_code for mapping.
6770        IF p_expenditure_type IS NOT NULL THEN
6771           l_fc_res_type_code := 'EXPENDITURE_TYPE';
6772        ELSIF p_expenditure_category IS NOT NULL THEN
6773           l_fc_res_type_code := 'EXPENDITURE_CATEGORY';
6774        END IF;
6775 
6776 --dbms_output.put_line('l_fc_res_type_code IS : ' || l_fc_res_type_code);
6777 
6778        INSERT INTO pa_res_list_map_tmp1
6779               (person_id,
6780                job_id,
6781                organization_id,
6782                expenditure_type,
6783                expenditure_category,
6784                fc_res_type_code,
6785                project_role_id,
6786                resource_class_id,
6787                resource_class_code,
6788                res_format_id,
6789                person_type_code,
6790                named_role)
6791        VALUES
6792               (p_person_id,
6793                p_job_id,
6794                p_organization_id,
6795                p_expenditure_type,
6796                p_expenditure_category,
6797                l_fc_res_type_code,
6798                p_project_role_id,
6799                1,
6800                'PEOPLE',
6801                p_res_format_id,
6802                p_person_type_code,
6803                p_named_role);
6804        /**********************************************
6805        * Call to the API passing the resource_list_ID
6806        * This API would read the values from the temp
6807        * table pa_res_list_map_tmp1 and will take in
6808        * the resource_list_id and get the best matching
6809        * resource_list_member_id and insert it into the
6810        * table pa_res_list_map_tmp4.
6811        **************************************************/
6812 -- dbms_output.put_line('Pa_Resource_Mapping.map_resource_list');
6813 -- dbms_output.put_line('l_resource_list_id IS : ' || l_resource_list_id);
6814 -- dbms_output.put_line('p_project_id IS : ' || p_project_id);
6815        Pa_Resource_Mapping.map_resource_list
6816           (p_resource_list_id => l_resource_list_id,
6817            p_project_id       => p_project_id,
6818            x_return_status    => l_return_status,
6819            x_msg_count        => l_msg_count,
6820            x_msg_data         => l_error_msg_data);
6821 
6822          IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
6823               l_resource_list_member_id := NULL;
6824               RETURN l_resource_list_member_id;
6825          END IF;
6826 
6827         /***********************************************
6828         * Get the resource_list_member_id value from
6829         * the pa_res_list_map_tmp4 table.
6830         ************************************************/
6831          BEGIN
6832             SELECT RESOURCE_LIST_MEMBER_ID
6833             INTO l_res_list_member_id
6834             FROM pa_res_list_map_tmp4
6835             WHERE rownum = 1;
6836 -- dbms_output.put_line('MAPPING l_res_list_member_id IS : ' || l_res_list_member_id);
6837          EXCEPTION
6838          WHEN OTHERS THEN
6839               l_resource_list_member_id := NULL;
6840               RETURN l_resource_list_member_id;
6841          END;
6842          /*******************************************
6843          * If the resource_list_member_id returned equals
6844          * 'PEOPLE' then we dont need to return it.
6845          * so just return Null. Else return the appr
6846          * value.
6847          *********************************************/
6848          IF l_res_list_member_id = 'PEOPLE' THEN
6849              l_resource_list_member_id := NULL;
6850          ELSE
6851              l_resource_list_member_id := l_res_list_member_id;
6852          END IF;
6853 
6854          RETURN to_number(l_resource_list_member_id);
6855 
6856    END IF;
6857    /*************************************************
6858     * If the Resource_list is not Centrally Controlled
6859     * then do the following
6860     **********************************************/
6861    IF l_exists = 'N' and l_central_control = 'N' THEN
6862 --dbms_output.put_line(' START *** ');
6863       /*************************************************
6864        * Call to Pa_Planning_Resource_Pvt.Create_Planning_Resource
6865        * which would create the planning resource member
6866        * for the project_id,res_format_id and resource_list_id passed
6867        * using the information passed.
6868        *****************************************************/
6869        BEGIN
6870           SELECT resource_class_id
6871           INTO   l_resource_class_id
6872           FROM pa_res_formats_b
6873           WHERE res_format_id = p_res_format_id;
6874        EXCEPTION
6875        WHEN OTHERS THEN
6876          l_resource_list_member_id := NULL;
6877        END;
6878 
6879        /* Validate first to ensure that all the required segments
6880         * exist before calling Create_Planning_Resource because if the
6881         * resource cannot be created just return null without any error.
6882         * Create_Planning_Resource puts any error it gets on the stack, which
6883         * then gets displayed to the user.  We want to prevent that.
6884         * This is for bug fix 3818238 */
6885 
6886        l_valid := 'Y';
6887        IF (l_valid = 'Y' AND
6888            l_fmt_details.Supplier_Enabled_Flag = 'Y') THEN
6889            l_valid := 'N';
6890        END IF;
6891 
6892        IF (l_valid = 'Y' AND
6893            l_fmt_details.Incurred_By_Enabled_Flag = 'Y') THEN
6894            l_valid := 'N';
6895        END IF;
6896 
6897        IF (l_valid = 'Y' AND
6898            l_fmt_details.Fin_Cat_Enabled_Flag = 'Y') THEN
6899            IF (l_fin_category_name IS NOT NULL AND
6900                l_fc_res_type_code IS NOT NULL) THEN
6901                l_valid := 'Y';
6902            ELSE
6903                l_valid := 'N';
6904            END IF;
6905        END IF;
6906 
6907        IF (l_valid = 'Y' AND
6908            l_fmt_details.Role_Enabled_Flag = 'Y') THEN
6909            IF (l_project_role_id IS NOT NULL AND
6910                l_named_role IS NOT NULL) THEN
6911                l_valid := 'Y';
6912            ELSE
6913                l_valid := 'N';
6914            END IF;
6915        END IF;
6916 
6917        IF (l_valid = 'Y' AND
6918            l_fmt_details.Orgn_Enabled_Flag = 'Y') THEN
6919            IF (l_organization_id IS NOT NULL) THEN
6920                l_valid := 'Y';
6921            ELSE
6922                l_valid := 'N';
6923            END IF;
6924        END IF;
6925 
6926        IF (l_valid = 'Y' AND
6927            l_fmt_details.Res_Type_Enabled_Flag = 'Y') THEN
6928            IF ((l_fmt_details.Res_Type_Code = 'NAMED_PERSON' AND
6929                 l_person_id IS NOT NULL) OR
6930                (l_fmt_details.Res_Type_Code = 'PERSON_TYPE' AND
6931                 l_person_type_code IS NOT NULL) OR
6932                (l_fmt_details.Res_Type_Code = 'JOB' AND l_job_id IS NOT NULL))
6933            THEN
6934                l_valid := 'Y';
6935            ELSE
6936                l_valid := 'N';
6937            END IF;
6938        END IF;
6939 
6940        IF (l_valid = 'Y' AND l_fmt_details.Res_Type_Code = 'JOB') THEN
6941           -- Check that list has job group and that job is in job group
6942           -- Added for bug 4025261
6943           BEGIN
6944           SELECT job_group_id
6945             INTO l_job_group_id
6946             FROM pa_resource_lists_all_bg
6947            WHERE resource_list_id = l_resource_list_id;
6948 
6949        	  SELECT 'Y'
6950 	    INTO l_valid_job
6951        	    FROM per_jobs
6952 	   WHERE job_id = l_job_id
6953              AND job_group_id = l_job_group_id;
6954 
6955           EXCEPTION WHEN NO_DATA_FOUND THEN
6956              l_valid := 'N';
6957           END;
6958 
6959        END IF;
6960 
6961 -- dbms_output.put_line('l_valid IS ' || l_valid);
6962        IF l_valid = 'Y' THEN
6963 -- hr_utility.trace_on(null, 'RMJOB');
6964 -- hr_utility.trace('************* START **************');
6965 -- hr_utility.trace('Call Pa_Planning_Resource_Pvt.Create_Planning_Resource');
6966 --dbms_output.put_line('Pa_Planning_Resource_Pvt.Create_Planning_Resource');
6967           Pa_Planning_Resource_Pvt.Create_Planning_Resource
6968              (p_resource_list_id        => l_resource_list_id,
6969               p_res_format_id           => p_res_format_id,
6970               p_resource_class_id       => l_resource_class_id,
6971               p_project_id              => p_project_id,
6972               p_person_id               => l_person_id,
6973               p_job_id                  => l_job_id,
6974               p_organization_id         => l_organization_id,
6975               p_project_role_id         => l_project_role_id,
6976               p_person_type_code        => l_person_type_code,
6977               p_team_role               => l_named_role,
6978               p_fin_category_name       => l_fin_category_name,
6979               p_fc_res_type_code        => l_fc_res_type_code,
6980               x_resource_list_member_id => l_resource_list_member_id,
6981               x_record_version_number   => l_record_version_number,
6982               x_return_status           => l_return_status,
6983               x_msg_count               => l_msg_count,
6984               x_error_msg_data          => l_error_msg_data);
6985 
6986             IF l_return_status <>  FND_API.G_RET_STS_SUCCESS THEN
6987                l_resource_list_member_id := NULL;
6988             END IF;
6989         ELSE
6990            l_resource_list_member_id := NULL;
6991         END IF;
6992         --Return the newly created resource_list_member_id.
6993         RETURN l_resource_list_member_id;
6994    END IF;
6995 
6996   END Derive_Resource_List_Member;
6997 /***************************************/
6998 /*********************************************************
6999  * Procedure : Get_Res_Format_For_Team_Role
7000  * Description : This API is used to return back the correct
7001  *               resource format ID  to be used for Assignments
7002  *               and Requirements.
7003  *               The calling API would pass a resource_list_id
7004  *               This API would then get all the formats
7005  *               associated with the resource_list passed
7006  *               from the pa_plan_rl_formats table which do not
7007  *               have res_type_code
7008  *               of Named_person,Bom_Labor,Resource_Class(for Req)
7009  *               of Bom_Labor,Resource_Class(for asgmt)
7010  *               - It then gets the format which has the highest
7011  *               precedence from the list of format ID's.
7012  *
7013  * As per bug 6014706 res_type_code can be of type Resource_Class
7014  ***************************************************************/
7015 Procedure Get_Res_Format_For_Team_Role
7016     (p_resource_list_id           IN           NUMBER,
7017      x_asgmt_res_format_id        OUT  NOCOPY  NUMBER,
7018      x_req_res_format_id          OUT  NOCOPY  NUMBER,
7019      x_return_status              OUT  NOCOPY  Varchar2)
7020 
7021 IS
7022    /****************************************
7023    * Cursor c_get_asgmt_res_formats to get the
7024    * res_formats for assignments.
7025    *****************************************/
7026    Cursor c_get_asgmt_res_formats
7027    IS
7028     select a.res_format_id
7029     from pa_res_formats_b a,pa_res_types_b b, pa_plan_rl_formats c
7030     where a.resource_class_id = 1
7031     and a.res_type_id = b.res_type_id (+)
7032     and c.res_format_id = a.res_format_id
7033     and c.resource_list_id = p_resource_list_id
7034     and nvl(b.res_type_code, 'DUMMY') <> 'BOM_LABOR';
7035     /*For bug 6014706 : Removed  RESOURCE_CLASS
7036     NOT IN ('BOM_LABOR','RESOURCE_CLASS');*/
7037 
7038    /****************************************
7039    * Cursor c_get_asgmt_res_formats to get the
7040    * res_formats for requirement.
7041    *****************************************/
7042    Cursor c_get_req_res_formats
7043    IS
7044     select a.res_format_id
7045     from pa_res_formats_b a,pa_res_types_b b, pa_plan_rl_formats c
7046     where a.resource_class_id = 1
7047     and a.res_type_id = b.res_type_id (+)
7048     and c.res_format_id = a.res_format_id
7049     and c.resource_list_id = p_resource_list_id
7050     and nvl(b.res_type_code, 'DUMMY') NOT IN
7051         ('NAMED_PERSON','BOM_LABOR','PERSON_TYPE');
7052      -- Added person_type for Bug 4350963
7053 /*For bug 6014706 : Removed  RESOURCE_CLASS
7054 ('NAMED_PERSON','BOM_LABOR','RESOURCE_CLASS', 'PERSON_TYPE');
7055 */
7056   l_return_status  Varchar2(30);
7057   l_msg_code Varchar2(30);
7058   l_res_format_id  Number;
7059   l_precedence     Number := 0;
7060   l_precedence_temp Number := 0;
7061   l_final_asgmt_format_id Number;
7062   l_final_req_format_id Number;
7063 BEGIN
7064     x_return_status := FND_API.G_RET_STS_SUCCESS;
7065   --Using these Dummy Values for precedence
7066   --for now. Later when Vijay passes the API remove this.
7067    /************************************************
7068    * For Assignments do the following
7069    * ***********************************************/
7070   IF pa_task_assignment_utils.is_uncategorized_res_list(p_resource_list_id => p_resource_list_id) = 'Y'
7071   THEN --Added IF-ELSE for bug 5962655
7072     x_asgmt_res_format_id := Null;
7073     x_req_res_format_id   := Null;
7074  ELSE
7075     OPEN  c_get_asgmt_res_formats;
7076     l_precedence := 0;
7077     l_precedence_temp := 1000;
7078     LOOP
7079         FETCH c_get_asgmt_res_formats INTO l_res_format_id;
7080         IF c_get_asgmt_res_formats%ROWCOUNT = 0 THEN
7081             x_asgmt_res_format_id := Null;
7082         END IF;
7083        EXIT WHEN c_get_asgmt_res_formats%NOTFOUND;
7084          BEGIN
7085               pa_resource_mapping.get_format_precedence (
7086                 p_resource_class_id   => 1,
7087                 p_res_format_id       => l_res_format_id ,
7088                 x_format_precedence   => l_precedence,
7089                 x_return_status       => l_return_status,
7090                 x_msg_code            => l_msg_code );
7091 
7092                 IF l_precedence IS NULL THEN
7093                      l_final_asgmt_format_id := Null;
7094                 END IF;
7095          EXCEPTION
7096          WHEN OTHERS THEN
7097                 x_asgmt_res_format_id := Null;
7098          END;
7099 
7100         -- The lower the precedence the more granular the format, so
7101         -- the format with the lowest precedence is best.
7102 
7103         IF l_precedence_temp >= l_precedence THEN
7104               l_precedence_temp := l_precedence;
7105               l_final_asgmt_format_id := l_res_format_id;
7106         END IF;
7107 
7108   END LOOP;
7109   CLOSE c_get_asgmt_res_formats;
7110 
7111 
7112    /************************************************
7113    * For Requirements do the following
7114    * ***********************************************/
7115     OPEN  c_get_req_res_formats;
7116     l_precedence := 0;
7117     l_precedence_temp := 1000;
7118     LOOP
7119         FETCH c_get_req_res_formats INTO l_res_format_id;
7120         IF c_get_req_res_formats%ROWCOUNT = 0 THEN
7121             x_req_res_format_id := Null;
7122         END IF;
7123        EXIT WHEN c_get_req_res_formats%NOTFOUND;
7124        BEGIN
7125               pa_resource_mapping.get_format_precedence (
7126                 p_resource_class_id   => 1,
7127                 p_res_format_id       => l_res_format_id ,
7128                 x_format_precedence   => l_precedence,
7129                 x_return_status       => l_return_status,
7130                 x_msg_code            => l_msg_code );
7131                 IF l_precedence IS NULL THEN
7132                      l_final_req_format_id := Null;
7133                 END IF;
7134          EXCEPTION
7135          WHEN OTHERS THEN
7136                 x_req_res_format_id := Null;
7137          END;
7138 
7139         -- The lower the precedence the more granular the format, so
7140         -- the format with the lowest precedence is best.
7141 
7142         IF l_precedence_temp >= l_precedence THEN
7143               l_precedence_temp := l_precedence;
7144               l_final_req_format_id := l_res_format_id;
7145         END IF;
7146 
7147     END LOOP;
7148     CLOSE c_get_req_res_formats;
7149 
7150   /***************************************************
7151    * Return back the final Assignment and Requirement
7152    * format ID's
7153    **************************************************/
7154    x_asgmt_res_format_id := l_final_asgmt_format_id;
7155    x_req_res_format_id   := l_final_req_format_id;
7156 
7157  END IF; --Added for bug 6014706
7158 END Get_Res_Format_For_Team_Role;
7159 
7160 /* ----------------------------------------------------------------
7161  * API for populating a resource list into the new TL tables. This API
7162  * is called by the resource list upgrade concurrent program.
7163  * ----------------------------------------------------------------*/
7164 PROCEDURE Populate_list_into_tl(
7165   p_resource_list_id   IN NUMBER,
7166   x_return_status      OUT NOCOPY VARCHAR2,
7167   x_msg_count          OUT NOCOPY VARCHAR2,
7168   x_msg_data           OUT NOCOPY VARCHAR2 ) IS
7169 
7170 BEGIN
7171     x_return_status := FND_API.G_RET_STS_SUCCESS;
7172     x_msg_count := 0;
7173     x_msg_data  := NULL;
7174 
7175 Insert into pa_resource_lists_tl (
7176          LAST_UPDATE_LOGIN,
7177          CREATION_DATE,
7178          CREATED_BY,
7179          LAST_UPDATE_DATE,
7180          LAST_UPDATED_BY,
7181          RESOURCE_LIST_ID,
7182          NAME,
7183          DESCRIPTION,
7184          LANGUAGE,
7185          SOURCE_LANG
7186        ) select
7187          fnd_global.login_id,
7188          sysdate,
7189          fnd_global.user_id,
7190          sysdate,
7191          fnd_global.user_id,
7192          lst.resource_list_id,
7193          lst.name,
7194          lst.description,
7195          l.language_code,
7196          userenv('LANG')
7197        from pa_resource_lists_all_bg lst,
7198             fnd_languages l
7199        where l.Installed_Flag in ('I', 'B')
7200          and lst.resource_list_id = p_resource_list_id
7201          and not exists (select 'Y'
7202                            from pa_resource_lists_tl T
7203                           where t.resource_list_id = lst.resource_list_id);
7204 EXCEPTION
7205 WHEN OTHERS THEN
7206      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7207      x_msg_count := 1;
7208      x_msg_data  := SQLERRM;
7209      RETURN;
7210 END;
7211 
7212 /*******************************************************************
7213  * Procedure : Delete_proj_specific_resource
7214  * Desc      : This API is used to delete the project specific resources
7215  *             once the project is deleted.
7216  *******************************************************************/
7217  PROCEDURE Delete_Proj_Specific_Resource(
7218    p_project_id         IN         NUMBER,
7219    x_return_status      OUT NOCOPY VARCHAR2,
7220    x_msg_count          OUT NOCOPY NUMBER)
7221  IS
7222  l_res_list_id pa_resource_lists_all_bg.resource_list_id%TYPE;
7223 
7224      --For bug 4039707
7225      CURSOR get_resource_lists IS
7226      SELECT resource_list_id FROM pa_resource_lists_all_bg
7227      WHERE migration_code is not null;
7228 
7229  BEGIN
7230      x_return_status := FND_API.G_RET_STS_SUCCESS;
7231      x_msg_count     := 0;
7232 
7233      OPEN get_Resource_lists;
7234 
7235      LOOP
7236         FETCH get_resource_lists INTO l_res_list_id;
7237         EXIT WHEN get_resource_lists%NOTFOUND;
7238 
7239         DELETE FROM pa_resource_list_members
7240         WHERE resource_list_id = l_res_list_id
7241         AND object_type = 'PROJECT'
7242         AND  object_id  = p_project_id;
7243      END LOOP;
7244 
7245      CLOSE get_resource_lists;
7246 
7247  EXCEPTION
7248  WHEN OTHERS THEN
7249       FND_MSG_PUB.add_exc_msg( p_pkg_name =>
7250              'Pa_Planning_Resource_Utils.Delete_proj_specific_resource'
7251              ,p_procedure_name => PA_DEBUG.G_Err_Stack);
7252              x_msg_count := x_msg_count+1;
7253              x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7254  END Delete_Proj_Specific_Resource;
7255 
7256 FUNCTION Get_class_member_id(p_project_id          IN  NUMBER,
7257                              p_resource_list_id    IN  NUMBER,
7258                              p_resource_class_code IN  VARCHAR2) return NUMBER
7259 IS
7260 
7261 l_resource_list_member_id NUMBER;
7262 l_central_control         VARCHAR2(1);
7263 
7264 BEGIN
7265 SELECT nvl(control_flag, 'N')
7266 INTO   l_central_control
7267 FROM   pa_resource_lists_all_bg
7268 WHERE  resource_list_id = p_resource_list_id;
7269 
7270 IF l_central_control = 'Y' THEN
7271    SELECT resource_list_member_id
7272    INTO   l_resource_list_member_id
7273    FROM   pa_resource_list_members
7274    WHERE  resource_list_id = p_resource_list_id
7275    AND    resource_class_flag = 'Y'
7276    AND    resource_class_code = p_resource_class_code;
7277 ELSE
7278    SELECT resource_list_member_id
7279    INTO   l_resource_list_member_id
7280    FROM   pa_resource_list_members
7281    WHERE  resource_list_id = p_resource_list_id
7282    AND    resource_class_flag = 'Y'
7283    AND    resource_class_code = p_resource_class_code
7284    AND    object_type = 'PROJECT'
7285    AND    object_id = p_project_id;
7286 END IF;
7287 
7288 RETURN l_resource_list_member_id;
7289 
7290 EXCEPTION WHEN OTHERS THEN
7291    l_resource_list_member_id := NULL;
7292    RETURN l_resource_list_member_id;
7293 
7294 END Get_class_member_id;
7295 
7296 /*****************************************************************
7297  *  Function : get_rate_based_flag
7298  *  Given a resource list member, this function returns a flag
7299  *  to indicate whether the list member is rate based or not.
7300  *  ************************************************************/
7301 FUNCTION Get_rate_based_flag(p_resource_list_member_id IN NUMBER)
7302 return VARCHAR2 IS
7303 
7304 CURSOR get_res_details(p_resource_list_member_id IN NUMBER) IS
7305 SELECT resource_class_code, inventory_item_id, expenditure_type
7306 FROM   pa_resource_list_members
7307 WHERE  resource_list_member_id = p_resource_list_member_id;
7308 
7309 l_rate_based_flag VARCHAR2(1) := 'N';
7310 l_res_details     get_res_details%ROWTYPE;
7311 
7312 BEGIN
7313 OPEN get_res_details(p_resource_list_member_id => p_resource_list_member_id);
7314 FETCH get_res_details into l_res_details;
7315 IF get_res_details%NOTFOUND THEN
7316    l_rate_based_flag := NULL;
7317    RETURN l_rate_based_flag;
7318 END IF;
7319 CLOSE get_res_details;
7320 
7321 IF l_res_details.resource_class_code in ('PEOPLE','EQUIPMENT') THEN
7322    l_rate_based_flag := 'Y';
7323 ELSIF (l_res_details.resource_class_code = 'MATERIAL_ITEMS') AND
7324       (l_res_details.inventory_item_id IS NOT NULL) THEN
7325 
7326        SELECT 'Y'
7327        INTO   l_rate_based_flag
7328        FROM   dual
7329        WHERE NOT EXISTS (select 'Y'
7330                          from mtl_system_items_b item,
7331                               mtl_units_of_measure meas
7332                         where item.inventory_item_id =
7333                               l_res_details.inventory_item_id
7334                           and item.primary_uom_code = meas.uom_code
7335                           and meas.uom_class = 'Currency');
7336 
7337 ELSIF (l_res_details.resource_class_code in ('MATERIAL_ITEMS',
7338                                              'FINANCIAL_ELEMENTS')) AND
7339       (l_res_details.expenditure_type IS NOT NULL) AND
7340       (l_res_details.inventory_item_id IS NULL) THEN
7341 
7342       SELECT c.cost_rate_flag
7343       INTO   l_rate_based_flag
7344       FROM   pa_expenditure_types c
7345       WHERE  c.expenditure_type = l_res_details.expenditure_type;
7346 END IF;
7347 
7348 RETURN l_rate_based_flag;
7349 
7350 END Get_rate_based_flag;
7351 
7352 
7353 /*****************************************************************
7354  * Function : check_enable_allowed
7355  * Given a disabled resource list member, this function checks to see if
7356  * enabling it is allowed - meaning that it won't result in a duplicate
7357  * resource list member.  Hence it checks to see if there are any enabled
7358  * list members with the same format and attributes.  Returns Y if the
7359  * given list member is unique; and N if not.
7360  * This function called from both the planning resource lists page
7361  * and the resource list form when a list member is enabled.  It is only
7362  * called for migrated resources to deal with the specific problem of
7363  * migrating list members which have financial category for both
7364  * parent and child, and the child cannot be guaranteed to be unique,
7365  * so it is migrated but disabled.  Look at bugs 3682103 and 3710822 for
7366  * more detail and background.
7367  * ************************************************************/
7368 FUNCTION check_enable_allowed(p_resource_list_member_id    IN NUMBER)
7369                               RETURN VARCHAR2
7370 IS
7371 l_res_format_id        NUMBER;
7372 l_res_list_id          NUMBER;
7373 l_allowed              VARCHAR2(1) := 'Y';
7374 l_enabled_flag         VARCHAR2(1) := 'Y';
7375 l_expenditure_type     VARCHAR2(100);
7376 l_revenue_category     VARCHAR2(100);
7377 l_expenditure_category VARCHAR2(100);
7378 l_event_type           VARCHAR2(100);
7379 l_object_type          VARCHAR2(100);
7380 l_object_id            NUMBER;
7381 
7382 BEGIN
7383 SELECT res_format_id, resource_list_id, expenditure_type,
7384        expenditure_category, revenue_category, event_type, object_type,
7385        object_id, enabled_flag
7386 INTO   l_res_format_id, l_res_list_id, l_expenditure_type,
7387        l_expenditure_category, l_revenue_category, l_event_type, l_object_type,
7388        l_object_id, l_enabled_flag
7389 FROM   pa_resource_list_members
7390 WHERE  resource_list_member_id = p_resource_list_member_id;
7391 
7392 l_allowed := 'Y';
7393 IF l_res_format_id in (29, 73) AND (l_enabled_flag = 'N') THEN
7394 
7395    BEGIN
7396    SELECT 'N'
7397    INTO   l_allowed
7398    FROM   pa_resource_list_members
7399    WHERE  resource_list_id = l_res_list_id
7400    AND    res_format_id = l_res_format_id
7401    AND    enabled_flag = 'Y'
7402    AND    resource_list_member_id <> p_resource_list_member_id
7403    AND    object_type = l_object_type
7404    AND    object_id = l_object_id
7405    AND    nvl(expenditure_type, 'DUMMY') = nvl(l_expenditure_type, 'DUMMY')
7406    AND    nvl(expenditure_category, 'DUMMY') =
7407                                            nvl(l_expenditure_category,'DUMMY')
7408    AND    nvl(revenue_category, 'DUMMY') = nvl(l_revenue_category, 'DUMMY')
7409    AND    nvl(event_type, 'DUMMY') = nvl(l_event_type, 'DUMMY');
7410 
7411    EXCEPTION WHEN NO_DATA_FOUND THEN
7412       l_allowed := 'Y';
7413    END;
7414 
7415 END IF;
7416 
7417 RETURN l_allowed;
7418 
7419 EXCEPTION WHEN OTHERS THEN
7420    l_allowed := 'N';
7421    RETURN l_allowed;
7422 
7423 END check_enable_allowed;
7424 
7425 /*****************************************************************
7426  * Procedure : check_list_member_on_list
7427  * Given a resource list member and a resource list, this procedure checks
7428  * to see if the list member is on the list (looking at the project specific
7429  * case as well) and returns an error message if it isn't.
7430  * If p_chk_enabled is passed in as 'Y', an additional check is done
7431  * to see whether the list member is enabled or not.
7432  * Added parameters p_alias and x_resource_list_member_id to do
7433  * name to ID conversion on alias and derive a list member ID.
7434  * ************************************************************/
7435 PROCEDURE check_list_member_on_list(
7436   p_resource_list_id          IN NUMBER,
7437   p_resource_list_member_id   IN NUMBER,
7438   p_project_id                IN NUMBER,
7439   p_chk_enabled               IN VARCHAR2 DEFAULT 'N',
7440   p_alias                     IN VARCHAR2 DEFAULT NULL,
7441   x_resource_list_member_id   OUT NOCOPY NUMBER,
7442   x_valid_member_flag         OUT NOCOPY VARCHAR2,
7443   x_return_status             OUT NOCOPY VARCHAR2,
7444   x_msg_count                 OUT NOCOPY VARCHAR2,
7445   x_msg_data                  OUT NOCOPY VARCHAR2) IS
7446 
7447 
7448 l_central_control   VARCHAR2(1)  := 'Y';
7449 l_object_type       VARCHAR2(30) := NULL;
7450 l_object_id         NUMBER;
7451 
7452 BEGIN
7453 
7454 x_valid_member_flag := NULL;
7455 x_return_status := FND_API.G_RET_STS_SUCCESS;
7456 x_msg_data      := NULL;
7457 x_msg_count     := 0;
7458 
7459 SELECT control_flag
7460 INTO   l_central_control
7461 FROM   pa_resource_lists_all_bg
7462 WHERE  resource_list_id = p_resource_list_id;
7463 
7464 IF l_central_control = 'N' THEN
7465    l_object_type := 'PROJECT';
7466    l_object_id   := p_project_id;
7467 ELSE
7468    l_object_type := 'RESOURCE_LIST';
7469    l_object_id   := p_resource_list_id;
7470 END IF;
7471 
7472 BEGIN
7473 IF p_alias IS NOT NULL and p_resource_list_member_id IS NULL THEN
7474    SELECT resource_list_member_id
7475    INTO   x_resource_list_member_id
7476    FROM   pa_resource_list_members
7477    WHERE  alias = p_alias
7478    AND    resource_list_id = p_resource_list_id
7479    AND    object_type = l_object_type
7480    AND    object_id = l_object_id;
7481 
7482 ELSIF p_resource_list_member_id IS NOT NULL THEN
7483    x_resource_list_member_id := p_resource_list_member_id;
7484 
7485 ELSIF p_alias IS NULL and p_resource_list_member_id IS NULL THEN
7486    x_valid_member_flag := 'N';
7487    x_resource_list_member_id := NULL;
7488    x_return_status := FND_API.G_RET_STS_ERROR;
7489    x_msg_data      := 'PA_MEMBER_NOT_ON_LIST';
7490    x_msg_count     := 1;
7491    --Modified below for Bug fix 7291217
7492    Pa_Utils.Add_Message(P_App_Short_Name  => 'PA'
7493                         ,P_Msg_Name => 'PA_MEMBER_NOT_ON_LIST'
7494  	                ,P_TOKEN1 => 'RESOURCE_LIST_MEMBER'
7495  	                ,P_VALUE1 => p_alias
7496  	                ,P_TOKEN2 => 'RESOURCE_LIST'
7497  	                ,P_VALUE2 => PA_TASK_UTILS.GET_RESOURCE_LIST_NAME(p_resource_list_id));
7498    RETURN;
7499 END IF;
7500 
7501 SELECT 'Y'
7502 INTO   x_valid_member_flag
7503 FROM   pa_resource_list_members
7504 WHERE  resource_list_member_id = x_resource_list_member_id
7505 AND    resource_list_id = p_resource_list_id
7506 AND    object_type = l_object_type
7507 AND    object_id = l_object_id;
7508 
7509 EXCEPTION WHEN NO_DATA_FOUND THEN
7510    x_valid_member_flag := 'N';
7511    x_resource_list_member_id := NULL;
7512    x_return_status := FND_API.G_RET_STS_ERROR;
7513    x_msg_data      := 'PA_MEMBER_NOT_ON_LIST';
7514    x_msg_count     := 1;
7515    --Modified below for Bug fix 7291217
7516    Pa_Utils.Add_Message(P_App_Short_Name  => 'PA'
7517                           ,P_Msg_Name => 'PA_MEMBER_NOT_ON_LIST'
7518  	                  ,P_TOKEN1 => 'RESOURCE_LIST_MEMBER'
7519  	                  ,P_VALUE1 => p_alias
7520  	                  ,P_TOKEN2 => 'RESOURCE_LIST'
7521  	                  ,P_VALUE2 => PA_TASK_UTILS.GET_RESOURCE_LIST_NAME(p_resource_list_id));
7522    RETURN;
7523 END;
7524 
7525 IF p_chk_enabled = 'Y' THEN
7526    BEGIN
7527    SELECT 'Y'
7528    INTO   x_valid_member_flag
7529    FROM   pa_resource_list_members
7530    WHERE  resource_list_member_id = x_resource_list_member_id
7531    AND    enabled_flag = 'Y';
7532 
7533    EXCEPTION WHEN NO_DATA_FOUND THEN
7534       x_valid_member_flag := 'N';
7535       x_resource_list_member_id := NULL;
7536       x_return_status := FND_API.G_RET_STS_ERROR;
7537       x_msg_data      := 'PA_MEMBER_NOT_ENABLED';
7538       x_msg_count     := 1;
7539       Pa_Utils.Add_Message(P_App_Short_Name  => 'PA',
7540                            P_Msg_Name        => 'PA_MEMBER_NOT_ENABLED');
7541       RETURN;
7542    END;
7543 END IF;
7544 
7545 END check_list_member_on_list;
7546 
7547 /********************************************************************
7548  * Procedure  : default_other_elements
7549  * This procedure derives other segments for a planning resource, based
7550  * on the resource format, if it is possible to derive anything.  For
7551  * example, if the format provided is Named Person - Organization, and
7552  * the person ID or name is specified, the person's HR Organization is derived
7553  * and passed back as X_organization_id and X_organization_name.  Please
7554  * see the functional design for all the values that can be derived.
7555  * Currently, the only formats that can allow derivation are:
7556  * BOM Equipment - Organization - 48
7557  * BOM Labor - Organization - 10
7558  * Named Person - Financial Category - Organization (get Org) - 3
7559  * Named Person - Organization - 5
7560  * Projects Non-Labor Resource - Financial Category - Organization (get Fin Cat) - 43
7561  * *****************************************************************/
7562 PROCEDURE default_other_elements (
7563 P_res_format_id          IN             NUMBER,
7564 P_person_id              IN             NUMBER    DEFAULT NULL,
7565 P_person_name            IN             VARCHAR2  DEFAULT NULL,
7566 p_bom_resource_id        IN             NUMBER    DEFAULT NULL,
7567 p_bom_resource_name      IN             VARCHAR2  DEFAULT NULL,
7568 p_non_labor_resource     IN             VARCHAR2  DEFAULT NULL,
7569 X_organization_id        OUT NOCOPY     NUMBER,
7570 x_organization_name      OUT NOCOPY     VARCHAR2,
7571 X_expenditure_type       OUT NOCOPY     VARCHAR2,
7572 X_msg_data               OUT NOCOPY     VARCHAR2,
7573 X_msg_count              OUT NOCOPY     NUMBER,
7574 X_return_status          OUT NOCOPY     VARCHAR2) IS
7575 
7576 CURSOR get_fmt_details (p_res_format_id IN NUMBER) IS
7577 SELECT f.Res_Type_Enabled_Flag,
7578        f.Orgn_Enabled_Flag,
7579        f.Fin_Cat_Enabled_Flag,
7580        f.Role_Enabled_Flag,
7581        f.Res_Type_Id,
7582        t.Res_Type_Code
7583 FROM   Pa_Res_Formats_B f,
7584        Pa_Res_Types_B t
7585 WHERE  f.Res_Type_Id = t.Res_Type_Id(+)
7586 AND    f.Res_Format_Id = p_res_format_id;
7587 
7588 l_fmt_details             get_fmt_details%RowType;
7589 l_person_id               NUMBER;
7590 l_bom_resource_id         NUMBER;
7591 
7592 BEGIN
7593 
7594 x_return_status := FND_API.G_RET_STS_SUCCESS;
7595 x_msg_data      := NULL;
7596 x_msg_count     := 0;
7597 X_organization_id := NULL;
7598 X_organization_name := NULL;
7599 X_expenditure_type := NULL;
7600 
7601 Open get_fmt_details(p_res_format_id => p_res_format_id);
7602 Fetch get_fmt_details into l_fmt_details;
7603 Close get_fmt_details;
7604 
7605 IF l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
7606    (l_fmt_details.Res_Type_Code = 'NAMED_PERSON' AND
7607    (P_person_id is not NULL OR P_person_name is NOT NULL)) THEN
7608    IF l_fmt_details.Orgn_Enabled_Flag = 'Y' THEN
7609       -- Do name to ID conversion on person
7610       pa_planning_resource_utils.Check_PersonName_or_ID(
7611                 p_person_id      => P_person_id,
7612                 p_person_name    => P_person_name,
7613                 p_check_id_flag  => PA_STARTUP.G_Check_ID_Flag,
7614                 x_person_id      => l_person_id,
7615                 x_return_status  => x_return_status,
7616                 x_error_msg_code => X_msg_data);
7617 
7618               IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7619                  PA_UTILS.Add_Message ('PA', X_msg_data, 'PLAN_RES',
7620                                        Pa_Planning_Resource_Pvt.g_token);
7621                  Return;
7622              END IF;
7623 
7624       -- Get the person's HR Org and pass back
7625       BEGIN
7626       SELECT a.organization_id, orgvl.name
7627         INTO X_organization_id, X_organization_name
7628         FROM per_assignments_x a,
7629              pa_all_organizations org,
7630              hr_all_organization_units_vl orgvl
7631        WHERE a.person_id = l_person_id
7632          AND a.organization_id = orgvl.organization_id
7633          AND a.organization_id = org.organization_id
7634          AND org.inactive_date is null
7635          AND org.pa_org_use_type = 'EXPENDITURES'
7636          AND a.assignment_type in ('C','E')
7637          AND a.primary_flag = 'Y'
7638          AND ROWNUM = 1;
7639       EXCEPTION WHEN NO_DATA_FOUND THEN
7640          X_organization_id := NULL;
7641          X_organization_name := NULL;
7642       END;
7643 
7644    END IF;
7645 ELSIF l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
7646       (l_fmt_details.Res_Type_Code in ('BOM_LABOR', 'BOM_EQUIPMENT') AND
7647       (p_bom_resource_id is not NULL OR p_bom_resource_name is NOT NULL)) THEN
7648 
7649       -- Do name to ID conversion on bom resource
7650       IF l_fmt_details.Res_Type_Code = 'BOM_LABOR' THEN
7651          pa_planning_resource_utils.Check_BOM_EqLabor_or_ID(
7652            p_bom_eqlabor_id       => p_bom_resource_id,
7653            p_bom_eqlabor_name     => p_bom_resource_name,
7654            p_res_type_code        => 2,
7655            p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag,
7656            x_bom_resource_id      => l_bom_resource_id,
7657            x_return_status        => x_return_status,
7658            x_error_msg_code       => X_msg_data);
7659 
7660          IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7661             PA_UTILS.Add_Message ('PA', X_msg_data, 'PLAN_RES',
7662                                   Pa_Planning_Resource_Pvt.g_token);
7663             Return;
7664          END IF;
7665       ELSIF l_fmt_details.Res_Type_Code = 'BOM_EQUIPMENT' THEN
7666          pa_planning_resource_utils.Check_BOM_EqLabor_or_ID(
7667            p_bom_eqlabor_id       => p_bom_resource_id,
7668            p_bom_eqlabor_name     => p_bom_resource_name,
7669            p_res_type_code        => 1,
7670            p_check_id_flag        => PA_STARTUP.G_Check_ID_Flag,
7671            x_bom_resource_id      => l_bom_resource_id,
7672            x_return_status        => x_return_status,
7673            x_error_msg_code       => X_msg_data);
7674 
7675          IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
7676             PA_UTILS.Add_Message ('PA', X_msg_data, 'PLAN_RES',
7677                                   Pa_Planning_Resource_Pvt.g_token);
7678             Return;
7679          END IF;
7680       END IF;
7681 
7682       IF (l_fmt_details.Orgn_Enabled_Flag = 'Y' AND
7683           l_bom_resource_id IS NOT NULL) THEN
7684       -- Get the Org
7685          SELECT b.organization_id, orgvl.name
7686            INTO X_organization_id, X_organization_name
7687            FROM bom_resources b,
7688                 hr_all_organization_units_vl orgvl
7689           WHERE b.resource_id = l_bom_resource_id
7690             AND b.organization_id = orgvl.organization_id
7691             AND ROWNUM = 1;
7692 
7693       END IF;
7694 
7695 ELSIF l_fmt_details.Res_Type_Enabled_Flag = 'Y' AND
7696       (l_fmt_details.Res_Type_Code = 'NON_LABOR_RESOURCE' AND
7697        p_non_labor_resource is not NULL) THEN
7698 
7699       IF l_fmt_details.Fin_Cat_Enabled_Flag = 'Y' THEN
7700          -- Get the Fin Cat
7701          SELECT n.expenditure_type
7702            INTO x_expenditure_type
7703            FROM pa_non_labor_resources n
7704           WHERE n.non_labor_resource = p_non_labor_resource
7705             AND ROWNUM = 1;
7706 
7707       END IF;
7708 END IF;
7709 
7710 END default_other_elements;
7711 
7712 END PA_PLANNING_RESOURCE_UTILS;
7713 /******************************************************************/