DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_FC_RES_MAP

Source


1 PACKAGE BODY PA_FC_RES_MAP AS
2 -- $Header: PAFCRMPB.pls 120.1 2005/08/08 15:19:49 pbandla noship $
3 
4    -- deleting the resource maps for the given resource list assignment id
5    P_DEBUG_MODE varchar2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
6 
7 PROCEDURE delete_res_maps_on_asgn_id
8            (p_resource_list_assignment_id  IN NUMBER,
9             x_return_status                OUT NOCOPY VARCHAR2,
10             x_error_message_code           OUT NOCOPY VARCHAR2) IS
11    BEGIN
12      IF P_DEBUG_MODE = 'Y' THEN
13         pa_fck_util.debug_msg('delete_res_maps_on_asgn_id: ' || 'PB:Entering - Delete Resource Maps');
14      END IF;
15      x_return_status := fnd_api.g_ret_sts_success;
16 
17      IF (p_resource_list_assignment_id is null) THEN
18        DELETE pa_resource_maps;
19      ELSE
20        DELETE pa_resource_maps prm
21        WHERE prm.resource_list_assignment_id = p_resource_list_assignment_id;
22      END IF;
23      IF P_DEBUG_MODE = 'Y' THEN
24         pa_fck_util.debug_msg('delete_res_maps_on_asgn_id: ' || 'PB:Exiting - Delete Resource Maps');
25      END IF;
26    EXCEPTION
27      WHEN NO_DATA_FOUND THEN
28        NULL;
29      WHEN OTHERS THEN
30        FND_MSG_PUB.add_exc_msg(p_pkg_name => 'PA_FC_RES_MAP'
31                    ,p_procedure_name => PA_DEBUG.G_Err_Stack );
32        x_error_message_code := SQLCODE || ' '|| SQLERRM;
33        x_return_status := fnd_api.g_ret_sts_unexp_error;
34        RAISE;
35    END delete_res_maps_on_asgn_id;
36 
37 PROCEDURE map_trans
38           ( p_project_id              		IN  NUMBER,
39             p_res_list_id             		IN  NUMBER,
40             p_person_id 			IN  NUMBER,
41             p_job_id 				IN  NUMBER,
42             p_organization_id 			IN  NUMBER,
43             p_vendor_id				IN  NUMBER,
44             p_expenditure_type 			IN  VARCHAR2,
45             p_event_type 			IN  VARCHAR2,
46             p_non_labor_resource 		IN  VARCHAR2,
47             p_expenditure_category 		IN  VARCHAR2,
48             p_revenue_category		 	IN  VARCHAR2,
49             p_non_labor_resource_org_id	 	IN  NUMBER,
50             p_event_type_classification 	IN  VARCHAR2,
51             p_system_linkage_function 		IN  VARCHAR2 ,
52             p_exptype                           IN  VARCHAR2 DEFAULT NULL,
53             x_resource_list_member_id		OUT NOCOPY NUMBER,
54             x_return_status 			OUT NOCOPY VARCHAR2,
55             x_error_message_code             	OUT NOCOPY VARCHAR2) IS
56 
57      l_resource_ind                 PA_RES_ACCUMS.resource_index_tbl;
58      l_resources_in                 PA_RES_ACCUMS.resources_tbl_type;
59      l_no_of_resources              BINARY_INTEGER;
60      l_index                        BINARY_INTEGER;
61      res_count                      BINARY_INTEGER;
62 
63      -- Variable to store the attributes of the resource list
64 
65      current_rl_assignment_id       NUMBER;      -- Current resource list assignment id
66      current_rl_id                  NUMBER;      -- Current resource list id
67      current_rl_changed_flag        VARCHAR2(1); -- was this resource list changed?
68      mapping_done                   BOOLEAN;     -- is mapping done for current resource list
69      current_rl_type_code           VARCHAR2(20);-- current resource list type code
70 
71      current_rl_member_id           NUMBER;
72      current_resource_id            NUMBER;
73      current_resource_rank          NUMBER;
74      current_member_level           NUMBER;
75      group_category_found           BOOLEAN;
76      attr_match_found               BOOLEAN;
77      new_resource_rank              NUMBER;
78 
79      old_resource_id                NUMBER;
80      old_rl_member_id               NUMBER;
81 
82      resource_map_found             BOOLEAN;
83 
84      -- member id for unclassified resources
85      uncl_group_member_id           NUMBER;
86      uncl_child_member_id           NUMBER;
87      uncl_resource_id               NUMBER;  -- assuming one resource_id for unclassfied
88 
89      x_err_stage                    varchar2(200);
90      x_err_code                     number;
91 
92    BEGIN
93      pa_funds_control_utils.print_message('Entering resource mapping');
94      IF P_DEBUG_MODE = 'Y' THEN
95         pa_fck_util.debug_msg('map_trans: ' || 'PB:Entering - Resource Mapping');
96      END IF;
97 
98      pa_funds_control_utils.print_message('Parameters '|| p_project_id ||':RL-'||
99             p_res_list_id ||':P-'||
100             p_person_id  ||':J-'||
101             p_job_id    ||':O-'||
102             p_organization_id ||':V-'||
103             p_vendor_id      ||':ET-'||
104             p_expenditure_type ||':ET-'||
105             p_event_type      ||':NLR-'||
106             p_non_labor_resource  ||':EC-'||
107             p_expenditure_category ||':RC-'||
108             p_revenue_category    ||':NO-'||
109             p_non_labor_resource_org_id   ||':ETC-'||
110             p_event_type_classification  ||':SYS-'||
111             p_system_linkage_function   ||':EXP-'||
112             p_exptype                );
113      IF P_DEBUG_MODE = 'Y' THEN
114         pa_fck_util.debug_msg('map_trans: ' || 'PB:Parameters '|| p_project_id ||':RL-'||
115             p_res_list_id ||':P-'||
116             p_person_id  ||':J-'||
117             p_job_id    ||':O-'||
118             p_organization_id ||':V-'||
119             p_vendor_id      ||':ET-'||
120             p_expenditure_type ||':ET-'||
121             p_event_type      ||':NLR-'||
122             p_non_labor_resource  ||':EC-'||
123             p_expenditure_category ||':RC-'||
124             p_revenue_category    ||':NO-'||
125             p_non_labor_resource_org_id   ||':ETC-'||
126             p_event_type_classification  ||':SYS-'||
127             p_system_linkage_function   ||':EXP-'||
128             p_exptype                );
129      END IF;
130 
131      PA_DEBUG.init_err_stack('PA_FC_RES_MAP.map_trans');
132 
133      PA_RES_ACCUMS.get_mappable_resources
134           ( x_project_id   => p_project_id,
135             x_res_list_id  => p_res_list_id,
136             x_resource_ind => l_resource_ind,
137             x_resources_in => l_resources_in,
138             x_no_of_resources => l_no_of_resources,
139             x_index        => l_index,
140             x_err_stage    => x_err_stage,
141             x_err_code     => x_err_code);
142 
143      pa_funds_control_utils.print_message('After get mappable resources ' || l_no_of_resources);
144      IF P_DEBUG_MODE = 'Y' THEN
145         pa_fck_util.debug_msg('map_trans: ' || 'PB:After get mappable resources ' || l_no_of_resources);
146      END IF;
147 
148      -- Now process  the  transaction
149      -- Get the txns for which mapping is to be done
150      mapping_done := TRUE;
151      current_rl_assignment_id :=0;
152 
153      FOR res_count IN 1..l_no_of_resources LOOP
154         pa_funds_control_utils.print_message('Next resource -- ' || l_resources_in(res_count).resource_list_member_id);
155         IF P_DEBUG_MODE = 'Y' THEN
156            pa_fck_util.debug_msg('map_trans: ' || 'PB:Next resource -- ' || l_resources_in(res_count).resource_list_member_id);
157         END IF;
158         IF (current_rl_assignment_id <> l_resources_in(res_count).resource_list_assignment_id) THEN
159 
160          -- Mapping to the next resource list
161          -- Check if resource mapping was done for last resource_list_assigment_id or not
162 
163          IF ( NOT mapping_done ) THEN
164             pa_funds_control_utils.print_message('Mapping not done');
165             IF P_DEBUG_MODE = 'Y' THEN
166                pa_fck_util.debug_msg('map_trans: ' || 'PB:Mapping not done');
167             END IF;
168 
169 	    IF ( current_resource_id IS NULL ) THEN -- The last txn_accum could not be mapped
170 
171              pa_funds_control_utils.print_message('Curr resourceid null');
172              IF P_DEBUG_MODE = 'Y' THEN
173                 pa_fck_util.debug_msg('map_trans: ' || 'PB:Curr resourceid null');
174              END IF;
175 	     -- Map to unclassified Resource
176 	     -- also if the group_category_found flag is true than map to unclassfied
177 	     -- category within the group
178 
179              current_resource_id      := uncl_resource_id;
180 
181 	     IF (group_category_found AND uncl_child_member_id <> 0) THEN
182                  pa_funds_control_utils.print_message('Grp category found');
183                  IF P_DEBUG_MODE = 'Y' THEN
184                     pa_fck_util.debug_msg('map_trans: ' || 'PB:Grp category found');
185                  END IF;
186                  current_rl_member_id := uncl_child_member_id;
187 	     ELSE
188                  current_rl_member_id := uncl_group_member_id;
189                  pa_funds_control_utils.print_message('Grp category not found');
190                  IF P_DEBUG_MODE = 'Y' THEN
191                     pa_fck_util.debug_msg('map_trans: ' || 'PB:Grp category not found');
192                  END IF;
193 	     END IF;
194 
195 	    END IF; --- IF ( current_resource_id IS NULL )
196 
197             PA_RES_ACCUMS.create_resource_map
198               (x_resource_list_id            => current_rl_id,
199                x_resource_list_assignment_id => current_rl_assignment_id,
200                x_resource_list_member_id     => current_rl_member_id,
201                x_resource_id                 => current_resource_id,
202                x_person_id                   => p_person_id,
203                x_job_id                      => p_job_id,
204                x_organization_id             => p_organization_id,
205                x_vendor_id                   => p_vendor_id,
206                x_expenditure_type            => p_expenditure_type,
207                x_event_type                  => p_event_type,
208                x_non_labor_resource          => p_non_labor_resource,
209                x_expenditure_category        => p_expenditure_category,
210                x_revenue_category            => p_revenue_category,
211                x_non_labor_resource_org_id   => p_non_labor_resource_org_id,
212                x_event_type_classification   => p_event_type_classification,
213                x_system_linkage_function     => p_system_linkage_function,
214                x_err_stage                   => x_err_stage,
215                x_err_code                    => x_err_code);
216 
217                pa_funds_control_utils.print_message('Created resource map');
218                IF P_DEBUG_MODE = 'Y' THEN
219                   pa_fck_util.debug_msg('map_trans: ' || 'PB:Created resource map');
220                END IF;
221          END IF;  -- IF ( NOT mapping_done )
222 
223          --- Proceed to the next resource list now
224 
225          current_rl_assignment_id   := l_resources_in(res_count).resource_list_assignment_id;
226          current_rl_id              := l_resources_in(res_count).resource_list_id;
227          current_rl_changed_flag    := PA_RES_ACCUMS.get_resource_list_status(
228 					x_resource_list_assignment_id => current_rl_assignment_id);
229          current_rl_type_code       := PA_RES_ACCUMS.get_group_resource_type_code(
230 					x_resource_list_id => current_rl_id);
231          mapping_done               := FALSE;
232 
233          -- This variables will store the information for best match for the resource
234          current_rl_member_id       := NULL;
235          current_resource_id        := NULL;
236          current_resource_rank      := NULL;
237          current_member_level       := NULL;
238          group_category_found       := FALSE;
239          uncl_group_member_id       := 0;
240          uncl_child_member_id       := 0;
241          uncl_resource_id           := 0;
242 
243          IF ( current_rl_changed_flag = 'Y' ) THEN -- This resource list assignmnet
244 						   -- has been changed
245 	    -- delete all the old maps for this resource list assignments
246 	    -- for all the transactions
247             pa_funds_control_utils.print_message('RList changed');
248             IF P_DEBUG_MODE = 'Y' THEN
249                pa_fck_util.debug_msg('map_trans: ' || 'PB:RList changed');
250             END IF;
251 	    delete_res_maps_on_asgn_id(
252 			p_resource_list_assignment_id => current_rl_assignment_id,
253 			x_return_status => x_return_status,
254 			x_error_message_code =>	x_error_message_code);
255 	    PA_RES_ACCUMS.change_resource_list_status(
256 			x_resource_list_assignment_id => current_rl_assignment_id,
257 			x_err_stage => x_err_stage,
258 			x_err_code => x_err_code);
259 
260          ELSIF ( current_rl_changed_flag = 'N' ) THEN
261             pa_funds_control_utils.print_message('RList not changed');
262             IF P_DEBUG_MODE = 'Y' THEN
263                pa_fck_util.debug_msg('map_trans: ' || 'PB:RList not changed');
264             END IF;
265             -- Get the resource map status
266             PA_RES_ACCUMS.get_resource_map
267                (x_resource_list_id   => current_rl_id,
268                 x_resource_list_assignment_id => current_rl_assignment_id,
269                 x_person_id          => p_person_id,
270                 x_job_id             => p_job_id,
271                 x_organization_id    => p_organization_id,
272                 x_vendor_id          => p_vendor_id,
273                 x_expenditure_type   => p_expenditure_type,
274                 x_event_type         => p_event_type,
275                 x_non_labor_resource => p_non_labor_resource,
276                 x_expenditure_category => p_expenditure_category,
277                 x_revenue_category   => p_revenue_category,
278                 x_non_labor_resource_org_id   => p_non_labor_resource_org_id,
279                 x_event_type_classification   => p_event_type_classification,
280                 x_system_linkage_function     => p_system_linkage_function,
281                 x_resource_list_member_id     => old_rl_member_id,
282                 x_resource_id        => old_resource_id,
283                 x_resource_map_found => resource_map_found,
284                 x_err_stage      => x_err_stage,
285                 x_err_code => x_err_code);
286 
287             pa_funds_control_utils.print_message('Resource map found RL:' || current_rl_id ||'P:'||
288                            p_person_id || 'O:' ||
289                            p_organization_id || 'RLA:' ||
290                            current_rl_assignment_id || 'J:' ||
291                            p_job_id || 'V:' ||
292                            p_vendor_id || 'ET:' ||
293                            p_expenditure_type || 'ET:' ||
294                            p_event_type || 'NLR:' ||
295                            p_non_labor_resource || 'EC:' ||
296                            p_expenditure_category ||'RC:' ||
297                            p_revenue_category || 'NLRO:'||
298                            p_non_labor_resource_org_id || 'ETC:' ||
299                            p_event_type_classification || 'SYS:' ||
300                            p_system_linkage_function);
301 
302             IF P_DEBUG_MODE = 'Y' THEN
303                pa_fck_util.debug_msg('map_trans: ' || 'Resource map found RL:' || current_rl_id ||'P:'||
304                            p_person_id || 'O:' ||
305                            p_organization_id || 'RLA:' ||
306                            current_rl_assignment_id || 'J:' ||
307                            p_job_id || 'V:' ||
308                            p_vendor_id || 'ET:' ||
309                            p_expenditure_type || 'ET:' ||
310                            p_event_type || 'NLR:' ||
311                            p_non_labor_resource || 'EC:' ||
312                            p_expenditure_category ||'RC:' ||
313                            p_revenue_category || 'NLRO:'||
314                            p_non_labor_resource_org_id || 'ETC:' ||
315                            p_event_type_classification || 'SYS:' ||
316                            p_system_linkage_function);
317             END IF;
318 
319             -- check if a map exist for the given attributes in the map table
320 	    IF (resource_map_found) THEN
321                    pa_funds_control_utils.print_message('Mapping done');
322                    IF P_DEBUG_MODE = 'Y' THEN
323                       pa_fck_util.debug_msg('map_trans: ' || 'PB:Mapping done');
324                    END IF;
325 	   	   mapping_done := TRUE;
326 		   x_resource_list_member_id := old_rl_member_id;
327 		   return;
328 	    END IF;  -- IF (resource_map_found)
329 
330 	  END IF;
331 
332        END IF; -- IF (current_rl_assignment_id <> p_resource_list_assignment_id ....
333 
334        IF ( NOT mapping_done ) THEN
335            pa_funds_control_utils.print_message('Mapping not done 2');
336            IF P_DEBUG_MODE = 'Y' THEN
337               pa_fck_util.debug_msg('map_trans: ' || 'PB:Mapping not done 2');
338            END IF;
339 	   -- Mapping still need to be done
340 	   attr_match_found     := TRUE;
341 
342 	   IF ((l_resources_in(res_count).resource_type_code = 'UNCLASSIFIED' OR
343 		l_resources_in(res_count).resource_type_code = 'UNCATEGORIZED') AND
344 	        l_resources_in(res_count).member_level = 1 ) THEN
345                   pa_funds_control_utils.print_message('Unclassified');
346                   IF P_DEBUG_MODE = 'Y' THEN
347                      pa_fck_util.debug_msg('map_trans: ' || 'PB:Unclassified');
348                   END IF;
349 	          attr_match_found := FALSE;
350                   uncl_resource_id := l_resources_in(res_count).resource_id;
351                   uncl_group_member_id  := l_resources_in(res_count).resource_list_member_id;
352 	   END IF;
353 
354 	   IF ( current_rl_type_code = 'EXPENDITURE_CATEGORY') THEN
355             pa_funds_control_utils.print_message('Exp cat');
356             IF P_DEBUG_MODE = 'Y' THEN
357                pa_fck_util.debug_msg('map_trans: ' || 'PB:Exp cat');
358             END IF;
359 	    -- The resource list is based on the expenditure category
360 	    IF ( l_resources_in(res_count).expenditure_category = p_expenditure_category) THEN
361 	      group_category_found := TRUE;
362 	    ELSE
363 	      attr_match_found := FALSE;
364 	    END IF; --IF ( l_expenditure_category(res_count).....
365 
366 	   ELSIF ( current_rl_type_code = 'REVENUE_CATEGORY' ) THEN
367             pa_funds_control_utils.print_message('Rev cat');
368             IF P_DEBUG_MODE = 'Y' THEN
369                pa_fck_util.debug_msg('map_trans: ' || 'PB:Rev cat');
370             END IF;
371 	    -- The resource list is based on the revenue category
372 	    IF (l_resources_in(res_count).revenue_category = p_revenue_category) THEN
373 	      group_category_found := TRUE;
374 	    ELSE
375 	      attr_match_found := FALSE;
376 	    END IF; -- IF (l_revenue_category(res_count) ....
377 
378 	   ELSIF ( current_rl_type_code = 'ORGANIZATION' ) THEN
379             pa_funds_control_utils.print_message('Organization');
380             IF P_DEBUG_MODE = 'Y' THEN
381                pa_fck_util.debug_msg('map_trans: ' || 'PB:Organization');
382             END IF;
383 	    -- The resource list is based on the organization
384 	    IF (l_resources_in(res_count).organization_id = p_organization_id) THEN
385 	      group_category_found := TRUE;
386 	    ELSE
387 	      attr_match_found := FALSE;
388 	    END IF; -- IF (l_organization_id(res_count)
389 
390 	   END IF; -- IF ( current_rl_type_code = 'EXPENDITURE_CATEGORY'...
391 
392 	   IF ( current_rl_type_code = 'NONE' OR attr_match_found ) THEN
393             pa_funds_control_utils.print_message('None');
394             IF P_DEBUG_MODE = 'Y' THEN
395                pa_fck_util.debug_msg('map_trans: ' || 'PB:None');
396             END IF;
397 	    -- The resource list is based on the none category
398 	    -- Now compare the txn attributes with resource attributes
399 	    -- The table given below determines if the resource is eligible
400 	    -- for accumulation or not
401 
402 	    --  TXN ATTRIBUTE       RESOURCE ATTRIBUTE  ELIGIBLE
403 	    --     NULL                   NULL            YES
404 	    --     NULL                 NOT NULL           NO
405 	    --   NOT NULL                 NULL            YES
406 	    --   NOT NULL               NOT NULL          YES/NO depending on value
407 
408 	    -- Do not match the attributes for an unclassified resource
409 
410 	    IF (l_resources_in(res_count).resource_type_code = 'UNCLASSIFIED' ) THEN
411                 pa_funds_control_utils.print_message('Uncl');
412                 IF P_DEBUG_MODE = 'Y' THEN
413                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Uncl');
414                 END IF;
415 	        attr_match_found := FALSE;
416                 uncl_resource_id := l_resources_in(res_count).resource_id;
417 		IF ( l_resources_in(res_count).member_level = 1 ) THEN -- group level unclassified
418                     pa_funds_control_utils.print_message('Group level');
419                     IF P_DEBUG_MODE = 'Y' THEN
420                        pa_fck_util.debug_msg('map_trans: ' || 'PB:Group level');
421                     END IF;
422                     uncl_group_member_id  := l_resources_in(res_count).resource_list_member_id;
423 		ELSE
424                     pa_funds_control_utils.print_message('Non group');
425                     IF P_DEBUG_MODE = 'Y' THEN
426                        pa_fck_util.debug_msg('map_trans: ' || 'PB:Non group');
427                     END IF;
428                     uncl_child_member_id  := l_resources_in(res_count).resource_list_member_id;
429 		END IF;
430 	    END IF;
431 
432 	    IF (NOT (attr_match_found AND
433 	        (NVL(l_resources_in(res_count).person_id,NVL(p_person_id,-1)) =
434 		NVL(p_person_id, -1)))) THEN
435                 pa_funds_control_utils.print_message('Personid');
436                 IF P_DEBUG_MODE = 'Y' THEN
437                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Personid');
438                 END IF;
439 		attr_match_found := FALSE;
440 	    END IF;
441 	    IF (NOT (attr_match_found AND
442 		(NVL(l_resources_in(res_count).job_id,NVL(p_job_id,-1)) =
443 		NVL(p_job_id, -1)))) THEN
444                 pa_funds_control_utils.print_message('Job');
445                 IF P_DEBUG_MODE = 'Y' THEN
446                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Job');
447                 END IF;
448 		attr_match_found := FALSE;
449 	    END IF;
450 	    IF (NOT (attr_match_found AND
451 		(NVL(l_resources_in(res_count).organization_id,NVL(p_organization_id,-1)) =
452 		NVL(p_organization_id, -1)))) THEN
453                 pa_funds_control_utils.print_message('Org id');
454                 IF P_DEBUG_MODE = 'Y' THEN
455                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Org id');
456                 END IF;
457 		attr_match_found := FALSE;
458 	    END IF;
459 	    IF (NOT (attr_match_found AND
460 		(NVL(l_resources_in(res_count).vendor_id,NVL(p_vendor_id,-1)) =
461 		NVL(p_vendor_id, -1)))) THEN
462                 pa_funds_control_utils.print_message('Vendor');
463                 IF P_DEBUG_MODE = 'Y' THEN
464                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Vendor');
465                 END IF;
466 		attr_match_found := FALSE;
467 	    END IF;
468 	    IF (NOT (attr_match_found AND
469 		(NVL(l_resources_in(res_count).expenditure_type,NVL(p_expenditure_type,'X')) =
470 		NVL(p_expenditure_type, 'X')))) THEN
471                 pa_funds_control_utils.print_message('Exp type');
472                 IF P_DEBUG_MODE = 'Y' THEN
473                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Exp type');
474                 END IF;
475 		attr_match_found := FALSE;
476 	    END IF;
477 	    IF (NOT (attr_match_found AND
478 		(NVL(l_resources_in(res_count).event_type,NVL(p_event_type,'X')) =
479 		NVL(p_event_type, 'X')))) THEN
480                 pa_funds_control_utils.print_message('Event type');
481                 IF P_DEBUG_MODE = 'Y' THEN
482                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Event type');
483                 END IF;
484 		attr_match_found := FALSE;
485 	    END IF;
486 	    IF (NOT (attr_match_found AND
487 	        (NVL(l_resources_in(res_count).non_labor_resource,NVL(p_non_labor_resource,'X')) =
488 		NVL(p_non_labor_resource, 'X')))) THEN
489                 pa_funds_control_utils.print_message('NLR');
490                 IF P_DEBUG_MODE = 'Y' THEN
491                    pa_fck_util.debug_msg('map_trans: ' || 'PB:NLR');
492                 END IF;
493 		attr_match_found := FALSE;
494 	    END IF;
495 	    IF (NOT (attr_match_found AND
496 		(NVL(l_resources_in(res_count).expenditure_category,NVL(p_expenditure_category,'X')) =
497 		NVL(p_expenditure_category, 'X')))) THEN
498                 pa_funds_control_utils.print_message('Exp cat');
499                 IF P_DEBUG_MODE = 'Y' THEN
500                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Exp cat');
501                 END IF;
502 		attr_match_found := FALSE;
503 	    END IF;
504 	    IF (NOT (attr_match_found AND
505 		(NVL(l_resources_in(res_count).revenue_category,NVL(p_revenue_category,'X')) =
506 		NVL(p_revenue_category,'X')))) THEN
507 		attr_match_found := FALSE;
508                 pa_funds_control_utils.print_message('Rev cat');
509                 IF P_DEBUG_MODE = 'Y' THEN
510                    pa_fck_util.debug_msg('map_trans: ' || 'PB:Rev cat');
511                 END IF;
512 	    END IF;
513 	    IF (NOT (attr_match_found AND
514 		(NVL(l_resources_in(res_count).non_labor_resource_org_id,NVL(p_non_labor_resource_org_id,-1)) =
515 		NVL(p_non_labor_resource_org_id,-1)))) THEN
516 		attr_match_found := FALSE;
517                 pa_funds_control_utils.print_message('NLR prgid ');
518                 IF P_DEBUG_MODE = 'Y' THEN
519                    pa_fck_util.debug_msg('map_trans: ' || 'PB:NLR prgid ');
520                 END IF;
521 	    END IF;
522 	    IF (NOT (attr_match_found AND
523 		(NVL(l_resources_in(res_count).event_type_classification,NVL(p_event_type_classification,'X')) =
524 		NVL(p_event_type_classification,'X')))) THEN
525 		attr_match_found := FALSE;
526 	    END IF;
527 	    IF (NOT (attr_match_found AND
528 		(NVL(l_resources_in(res_count).system_linkage_function,NVL(p_system_linkage_function,'X')) =
529 		NVL(p_system_linkage_function,'X')))) THEN
530 		attr_match_found := FALSE;
531 	    END IF;
532 
533 	   END IF; --IF ( current_rl_type_code = 'NONE'......
534 	   IF (attr_match_found) THEN
535               pa_funds_control_utils.print_message('Inside rank');
536               IF P_DEBUG_MODE = 'Y' THEN
537                  pa_fck_util.debug_msg('map_trans: ' || 'PB:Inside rank');
538               END IF;
539 	      -- Get the resource rank now
540 	      IF ( p_event_type_classification IS NOT NULL ) THEN
541 		 -- determine the rank based on event_type_classification
542                  new_resource_rank := PA_RES_ACCUMS.get_resource_rank(
543                                     x_resource_format_id => l_resources_in(res_count).resource_format_id,
544                                     x_txn_class_code     => p_event_type_classification);
545 	      ELSE
546 		 -- determine the rank based on system_linkage_function
547                  new_resource_rank := PA_RES_ACCUMS.get_resource_rank(
548                                     x_resource_format_id => l_resources_in(res_count).resource_format_id,
549                                     x_txn_class_code     => p_system_linkage_function);
550 	      END IF;
551 
552 	      IF (  NVL(new_resource_rank,99) < NVL(current_resource_rank,99) ) THEN
553 
554 		current_resource_rank := new_resource_rank;
555                 current_rl_member_id  := l_resources_in(res_count).resource_list_member_id;
556                 current_resource_id   := l_resources_in(res_count).resource_id;
557                 current_member_level  := l_resources_in(res_count).member_level;
558 
559 	      END IF;
560 	    END IF; -- IF (attr_match_found)
561 
562        END IF;  -- IF ( NOT mapping_done ) THEN
563 
564       END LOOP;
565 
566       -- Now create the map for the last resoure list assignment
567       IF ( NOT mapping_done ) THEN
568 
569 	IF ( current_resource_id IS NULL ) THEN -- The last txn_accum could not be mapped
570 
571 	   -- Map to unclassified Resource
572 	   -- also if the group_category_found flag is true than map to unclassfied
573 	   -- category within the group
574 
575            current_resource_id      := uncl_resource_id;
576 
577 	   IF (group_category_found AND uncl_child_member_id <> 0) THEN
578                current_rl_member_id := uncl_child_member_id;
579 	   ELSE
580                current_rl_member_id := uncl_group_member_id;
581 	   END IF;
582 
583 	END IF; --- IF ( current_resource_id IS NULL )
584 
585 	-- Create a map now
586         PA_RES_ACCUMS.create_resource_map
587               (current_rl_id,
588                current_rl_assignment_id,
589                current_rl_member_id,
590                current_resource_id,
591                p_person_id,
592                p_job_id,
593                p_organization_id,
594                p_vendor_id,
595                p_expenditure_type,
596                p_event_type,
597                null,--x_non_labor_resource,
598                p_expenditure_category,
599                p_revenue_category,
600                p_non_labor_resource_org_id,
601                p_event_type_classification,
602                p_system_linkage_function,
603                x_err_stage,
604                x_err_code);
605 
606        END IF;
607 
608       x_resource_list_member_id := current_rl_member_id;
609 
610       IF P_DEBUG_MODE = 'Y' THEN
611          pa_fck_util.debug_msg('map_trans: ' || 'PB:Exiting - Resource Mapping, RLMI = '|| x_resource_list_member_id);
612       END IF;
613       pa_funds_control_utils.print_message('End of Resource Mapping, RLMI = ' || x_resource_list_member_id);
614 
615       PA_DEBUG.reset_err_stack;
616   EXCEPTION
617     WHEN NO_DATA_FOUND THEN
618         NULL;
619     WHEN OTHERS THEN
620       FND_MSG_PUB.add_exc_msg(p_pkg_name => 'PA_FC_RES_MAP'
621                    ,p_procedure_name => PA_DEBUG.G_Err_Stack );
622       x_error_message_code := SQLCODE || ' ' || SQLERRM;
623       x_return_status := fnd_api.g_ret_sts_unexp_error;
624       x_resource_list_member_id := NULL;
625       RAISE;
626   END map_trans;
627 
628 END PA_FC_RES_MAP;