[Home] [Help]
PACKAGE BODY: APPS.JTF_ASSIGN_PUB
Source
1 PACKAGE BODY JTF_ASSIGN_PUB AS
2 /* $Header: jtfamprb.pls 120.12 2007/12/03 12:31:10 shdwived ship $ */
3
4 -- ********************************************************************************
5
6 -- Start of Comments
7 --
8 -- Package Name : JTF_ASSIGN_PUB
9 -- Purpose : Joint Task Force Core Foundation Assignment Manager
10 -- Public APIs. This package is for finding the
11 -- a resource based on the customer preferences
12 -- or territory preferences and the availability of
13 -- the resource in the specified time frame.
14 -- Procedures : (See below for specification)
15 -- Notes : This package is publicly available for use
16 -- History : 11/02/99 ** VVUYYURU ** Vijay Vuyyuru ** created
17 -- Created the procedure for Tasks
18 --
19 -- : 12/02/99 ** VVUYYURU ** Vijay Vuyyuru **
20 -- Added the procedure for Service Requests
21 --
22 -- : 01/02/00 ** VVUYYURU ** Vijay Vuyyuru **
23 -- Added the procedure for Opportunities
24 --
25 -- : 01/12/00 ** VVUYYURU ** Vijay Vuyyuru **
26 -- Added the procedure for Leads
27 --
28 -- : 02/02/00 ** VVUYYURU ** Vijay Vuyyuru **
29 -- Added the procedure for Defect Management System
30 --
31 -- : 03/20/00 ** VVUYYURU ** Vijay Vuyyuru **
32 -- Added Dynamic SQL for the cs_contacts_v
33 --
34 -- : 03/23/00 ** VVUYYURU ** Vijay Vuyyuru **
35 -- Added Dynamic SQL for the cs_incidents_all_vl
36 --
37 -- : 04/05/00 ** VVUYYURU ** Vijay Vuyyuru **
38 -- Added Functions to get the default values of
39 -- FND_API variables
40 --
41 -- : 04/14/00 ** VVUYYURU ** Vijay Vuyyuru **
42 -- Added the procedure for Escalations
43 --
44 -- : 07/20/00 ** VVUYYURU ** Vijay Vuyyuru **
45 -- Added the new procedure for Leads
46 -- Replaced the old procedure for Leads
47 --
48 -- : 10/16/00 ** VVUYYURU ** Vijay Vuyyuru **
49 -- Added the new record definition for Defects
50 -- Changed the specification and body with the
51 -- enhanced DEFECTS code
52 --
53 -- : 01/09/01 ** VVUYYURU ** Vijay Vuyyuru **
54 -- Added the code to fetch Installed Base
55 -- Preferred Engineers
56 --
57 -- : 02/02/01 ** VVUYYURU ** Vijay Vuyyuru **
58 -- Added the code to sort the OUT pl/sql table
59 -- data using the Resource Location.
60 -- Implemented for TASKS
61 --
62 -- : 03/21/01 ** VVUYYURU ** Vijay Vuyyuru **
63 -- Added the code to resolve the Calendar NOT working
64 -- due to the Uneven Record Numbers which are given in case
65 -- of NO SHIFT from Calendar which in turn causes error in
66 -- the Resource Location Sorting.
67 --
68 -- : 04/16/01 ** VVUYYURU ** Vijay Vuyyuru **
69 -- Territory changed some record definitions!
70 -- Hence made relevant code changes for TASKS, SR, SR-TASK
71 --
72 -- : 01/14/02 ** VVUYYURU ** Vijay Vuyyuru **
73 -- Added two more parameters to the main API and SR API
74 -- p_contract_id and p_customer_product_id
75 -- This is to ensure that the SR need not be saved
76 -- to fetch the IB and Contracts Preferred Resources
77 --
78 -- : 02/11/02 ** VVUYYURU ** Vijay Vuyyuru **
79 -- Added Contract Coverage Type to SR / SR-TASK API
80 --
81 -- : 05/06/02 ** VVUYYURU ** Vijay Vuyyuru **
82 -- Added separate procedures for Contracts and IB
83 -- Modularized the process for Preferred Engineers.
84 -- : 12/22/05 ** MPADHIAR ** Manas padhiary **
85 -- Removed Comment to Show error message Bug # 2919389
86 --
87 -- End of Comments
88
89 -- *******************************************************************************
90
91
92
93
94
95
96 -- *******************************************************************************
97
98 -- Start of comments
99
100 -- Functions : These functions are to get the FND_API default values.
101
102 -- End of comments
103
104 -- *******************************************************************************
105
106 g_contracts_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type ;
107 g_ib_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type ;
108 g_excluded_resource_tbl JTF_ASSIGN_PUB.excluded_tbl_type ;
109 g_continuous_work VARCHAR2(10);
110
111
112 FUNCTION am_miss_num RETURN NUMBER IS
113
114 BEGIN
115 RETURN (FND_API.g_miss_num);
116 END am_miss_num;
117
118
119 FUNCTION am_miss_char RETURN VARCHAR2 IS
120
121 BEGIN
122 RETURN (FND_API.g_miss_char);
123 END am_miss_char;
124
125
126 FUNCTION am_miss_date RETURN DATE IS
127
128 BEGIN
129 RETURN (FND_API.g_miss_date);
130 END am_miss_date;
131
132
133 FUNCTION am_false RETURN VARCHAR2 IS
134
135 BEGIN
136 RETURN (FND_API.g_false);
137 END am_false;
138
139
140 FUNCTION am_true RETURN VARCHAR2 IS
141
142 BEGIN
143 RETURN (FND_API.g_true);
144 END am_true;
145
146
147 FUNCTION am_valid_level_full RETURN VARCHAR2 IS
148
149 BEGIN
150 RETURN (FND_API.g_valid_level_full);
151 END am_valid_level_full;
152
153
154
155
156
157 -- *******************************************************************************
158
159 -- Start of comments
160
161 -- Function : This function is to get the changed Resource Type.
162 -- It appends/removes the string "RS_"
163
164 -- End of comments
165
166 -- *******************************************************************************
167
168
169
170 FUNCTION resource_type_change(p_res_type VARCHAR2) RETURN VARCHAR2 IS
171 l_res_type VARCHAR2(30);
172
173 BEGIN
174
175 IF (p_res_type = 'RS_EMPLOYEE') THEN
176 l_res_type := 'EMPLOYEE';
177 ELSIF (p_res_type = 'RS_PARTY') THEN
178 l_res_type := 'PARTY';
179 ELSIF (p_res_type = 'RS_PARTNER') THEN
180 l_res_type := 'PARTNER';
181 ELSIF (p_res_type = 'RS_SUPPLIER') THEN
182 l_res_type := 'SUPPLIER_CONTACT';
183 ELSIF (p_res_type = 'RS_SUPPLIER_CONTACT') THEN
184 l_res_type := 'SUPPLIER_CONTACT';
185 ELSIF (p_res_type = 'RS_OTHER') THEN
186 l_res_type := 'OTHER';
187 ELSIF (p_res_type = 'RS_TBH') THEN
188 l_res_type := 'TBH';
189 ELSIF (p_res_type = 'EMPLOYEE') THEN
190 l_res_type := 'RS_EMPLOYEE';
191 ELSIF (p_res_type = 'PARTY') THEN
192 l_res_type := 'RS_PARTY';
193 ELSIF (p_res_type = 'PARTNER') THEN
194 l_res_type := 'RS_PARTNER';
195 ELSIF (p_res_type = 'SUPPLIER_CONTACT') THEN
196 l_res_type := 'RS_SUPPLIER_CONTACT';
197 ELSIF (p_res_type = 'OTHER') THEN
198 l_res_type := 'RS_OTHER';
199 ELSIF (p_res_type = 'TBH') THEN
200 l_res_type := 'RS_TBH';
201 END IF;
202
203 RETURN(l_res_type);
204 END resource_type_change;
205
206
207
208
209
210 -- *******************************************************************************
211
212 -- Start of comments
213
214 -- Function : This procedure is to get back the Record of Tables
215 -- into the normal Table of Records.
216
217 -- End of comments
218
219 -- *******************************************************************************
220
221
222
223 /* Procedure to write back data from Tables to Table Type variable */
224
225 PROCEDURE table_copy_in
226 (
227 l_engineer_id IN JTF_NUMBER_TABLE,
228 l_resource_type IN JTF_VARCHAR2_TABLE_100,
229 l_primary_flag IN JTF_VARCHAR2_TABLE_100,
230 l_resource_class IN JTF_VARCHAR2_TABLE_100,
231 l_con_preferred_engineers_tbl OUT NOCOPY JTF_ASSIGN_PUB.prfeng_tbl_type
232 )
233 IS
234
235 l_ddindx BINARY_INTEGER;
236 l_indx BINARY_INTEGER;
237
238 BEGIN
239 IF l_engineer_id IS NOT NULL AND
240 l_engineer_id.count > 0 THEN
241 IF l_engineer_id.count > 0 THEN
242 l_indx := l_engineer_id.first;
243 l_ddindx := 0;
244 WHILE true LOOP
245 l_con_preferred_engineers_tbl(l_ddindx).engineer_id := l_engineer_id(l_indx);
246 l_con_preferred_engineers_tbl(l_ddindx).resource_type := l_resource_type(l_indx);
247 l_con_preferred_engineers_tbl(l_ddindx).primary_flag := nvl(l_primary_flag(l_indx), 'N');
248 l_con_preferred_engineers_tbl(l_ddindx).resource_class := nvl(l_resource_class(l_indx), 'R');
249 -- resource class is R for Preferred
250 -- P for Primary and
251 -- E for Excluded
252 l_ddindx := l_ddindx+1;
253 IF l_engineer_id.last = l_indx THEN
254 exit;
255 END IF;
256 l_indx := l_engineer_id.next(l_indx);
257 END LOOP;
258 END IF;
259 END IF;
260 END table_copy_in;
261
262
263 -- procedure to copy resources from one table to another
264 PROCEDURE table_copy(p_from_table IN JTF_ASSIGN_PUB.AssignResources_tbl_type,
265 x_to_table IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type)
266 IS
267
268 i number := 0;
269 k number := 0;
270 BEGIN
271
272 if( x_to_table.count <= 0)
273 then
274 i := 0;
275 else
276 i := x_to_table.last + 1;
277 end if;
278
279 IF(p_from_table.count > 0)
280 THEN
281 k := p_from_table.first;
282
283 While(k <= p_from_table.last)
284 loop
285 x_to_table(i) := p_from_table(k);
286 i := i + 1;
287 k := k + 1;
288 end loop;
289 END IF;
290
291 END table_copy;
292
293
294 -- procedure to remove excluded resources
295 PROCEDURE remove_excluded(x_res_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
296 x_exc_res IN OUT NOCOPY JTF_ASSIGN_PUB.excluded_tbl_type)
297 IS
298
299 i number := 0;
300 k number := 0;
301 l_count number := 0;
302 l_exclude varchar2(1) := 'N';
303 l_resource_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
304 BEGIN
305 l_resource_tbl.delete;
306 if(x_exc_res.count > 0 and x_res_tbl.count > 0)
307 then
308 for i in x_res_tbl.first..x_res_tbl.last
309 loop
310 l_exclude := 'N';
311 for k in x_exc_res.first..x_exc_res.last
312 loop
313 if(x_exc_res(k).resource_id = x_res_tbl(i).resource_id and
314 x_exc_res(k).resource_type = x_res_tbl(i).resource_type)
315 then
316 l_exclude := 'Y';
317 exit;
318 end if;
319 end loop; -- end of loop for x_exc_res
320 if(l_exclude = 'N')
321 then
322 l_resource_tbl(l_count) := x_res_tbl(i);
323 l_count := l_count + 1;
324 end if; -- end if l_exclude check
325 end loop; -- end of loop for x_res_tbl
326 x_res_tbl.delete;
327 x_res_tbl := l_resource_tbl;
328 end if; -- end of count check for both tables
329
330 END remove_excluded;
331
332
333
334 -- *******************************************************************************
335
336 -- Start of comments
337
338 -- Function : This procedure is to sort the pl/sql table of resources
339 -- based on the Resource Location.
340
341 -- End of comments
342
343 -- *******************************************************************************
344
345
346
347 PROCEDURE quick_sort_resource_loc
348 (
349 p_left INTEGER,
350 p_right INTEGER,
351 p_list IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type
352 )
353 IS
354
355 i INTEGER;
356 j INTEGER;
357 l_left INTEGER := p_left;
358 l_right INTEGER := p_right;
359 l_current_node JTF_ASSIGN_PUB.AssignResources_rec_type;
360 l_dummy_node JTF_ASSIGN_PUB.AssignResources_rec_type;
361
362 BEGIN
363
364 IF (l_right > l_left) THEN
365 l_current_node := p_list(l_right);
366 i := l_left -1;
367 j := l_right;
368 LOOP
369 LOOP
370 i := i +1;
371 --dbms_output.put_line('Entered LOOP 1');
372 --dbms_output.put_line('i is : '||to_char(i));
373 IF (p_list(i).location < l_current_node.location) THEN
374 null;
375 ELSE
376 exit;
377 END IF;
378
379 IF (i >= p_list.count) THEN
380 exit;
381 END IF;
382 END LOOP;
383
384 LOOP
385 j := j -1;
386 --dbms_output.put_line('Entered LOOP 2');
387 --dbms_output.put_line('j is : '||to_char(j));
388 IF (p_list(j).location > l_current_node.location) THEN
389 null;
390 ELSE
391 exit;
392 END IF;
393
394 IF (j <= 0) THEN
395 exit;
396 END IF;
397
398 END LOOP;
399
400 IF (i >= j) THEN
401 exit;
402 END IF;
403
404 l_dummy_node := p_list(i);
405 p_list(i) := p_list(j);
406 p_list(j) := l_dummy_node;
407 END LOOP;
408
409 l_dummy_node := p_list(i);
410 p_list(i) := p_list(l_right);
411 p_list(l_right) := l_dummy_node;
412
413 quick_sort_resource_loc(l_left, i-1, p_list);
414 quick_sort_resource_loc(i+1, l_right, p_list);
415
416 END IF;
417 END quick_sort_resource_loc;
418
419
420 -- *******************************************************************************
421
422 -- Start of comments
423
424 -- bug/Enhancement : 6453896
425 -- Function : This procedure was added to sort territories dependend on
426 -- Territory Ranking returned by Territories product.
427 -- It is used in Get_ASSIGN_RESOURCES procedure. This procedure
428 -- will sort only when rank is returned by Territories.
429 -- Added by : sdwived2
430 --
431 -- End of comments
432
433 -- *******************************************************************************
434
435
436 PROCEDURE quick_sort_terr_rank
437 ( p_left INTEGER,
438 p_right INTEGER,
439 p_list IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type
440 )
441 IS
442
443 i INTEGER;
444 j INTEGER;
445 l_left INTEGER := p_left;
446 l_right INTEGER := p_right;
447 l_current_node JTF_ASSIGN_PUB.AssignResources_rec_type;
448 l_dummy_node JTF_ASSIGN_PUB.AssignResources_rec_type;
449
450 BEGIN
451
452 IF (l_right > l_left) THEN
453 l_current_node := p_list(l_right);
454 i := l_left -1;
455 j := l_right;
456 LOOP
457 LOOP
458 i := i +1;
459 dbms_output.put_line('Entered LOOP 1');
460 dbms_output.put_line('i is : '||to_char(i));
461 dbms_output.put_line('i current node : '||l_current_node.terr_rank);
462 IF (p_list(i).terr_rank > l_current_node.terr_rank) THEN
463 null;
464 ELSE
465 exit;
466 END IF;
467
468 IF (i >= p_list.count) THEN
469 exit;
470 END IF;
471 END LOOP;
472
473 LOOP
474 j := j -1;
475 dbms_output.put_line('Entered LOOP 2');
476 dbms_output.put_line('j is : '||to_char(j));
477 dbms_output.put_line('j current node : '||l_current_node.terr_rank);
478 IF (j <= 0) THEN
479 dbms_output.put_line('when j <=0');
480 exit;
481 END IF;
482 IF (p_list(j).terr_rank < l_current_node.terr_rank) THEN
483 dbms_output.put_line('Inside if');
484 null;
485 ELSE
486 dbms_output.put_line('Inside else before exit');
487 exit;
488 END IF;
489
490
491
492 END LOOP;
493
494 IF (i >= j) THEN
495 dbms_output.put_line('when i >=j');
496 exit;
497 END IF;
498 dbms_output.put_line('inside j loop before ');
499 dbms_output.put_line('inside j loop before '||p_list(i).terr_rank);
500 dbms_output.put_line('inside j loop before '||p_list(j).terr_rank);
501 l_dummy_node := p_list(i);
502 p_list(i) := p_list(j);
503 p_list(j) := l_dummy_node;
504 dbms_output.put_line('inside j loop after '||p_list(i).terr_rank);
505 dbms_output.put_line('inside j loop after '||p_list(j).terr_rank);
506 END LOOP;
507
508 l_dummy_node := p_list(i);
509 p_list(i) := p_list(l_right);
510 p_list(l_right) := l_dummy_node;
511 dbms_output.put_line(' after i '||p_list(i).terr_rank);
512 dbms_output.put_line(' after l_right '||p_list(l_right).terr_rank);
513 dbms_output.put_line('Values passed are left '||l_left);
514 dbms_output.put_line('Values passed are right '||to_char(i-1));
515
516 quick_sort_terr_rank(l_left, i-1, p_list);
517 quick_sort_terr_rank(i+1, l_right, p_list);
518
519 END IF;
520 END quick_sort_terr_rank;
521
522 /**************** Start of addition by SBARAT on 11/01/2005 for Enh 4112155**************/
523
524 -- *******************************************************************************
525
526 -- Start of comments
527
528 -- Function : This procedure is to assign values of component/subcomponent fields
529 -- to Territory's record type dynamically, so that there will not be
530 -- any compilation error if reqd patch of Territory not applied in env.
531
532 -- End of comments
533
534 -- *******************************************************************************
535
536
537 PROCEDURE Terr_Qual_Dyn_Assign
538 (
539 p_sr_assign_rec IN JTF_ASSIGN_PUB.JTF_Serv_Req_rec_type,
540 p_sr_task_assign_rec IN JTF_ASSIGN_PUB.JTF_Srv_Task_rec_type
541 )
542 IS
543
544 BEGIN
545
546 EXECUTE IMMEDIATE
547 '
548 BEGIN
549
550 JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type.SQUAL_NUM23:=:1;
551 JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type.SQUAL_NUM24:=:2;
552
553 JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type.SQUAL_NUM23:=:3;
554 JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type.SQUAL_NUM24:=:4;
555
556 END;
557 '
558 USING
559 IN p_sr_assign_rec.ITEM_COMPONENT,
560 IN p_sr_assign_rec.ITEM_SUBCOMPONENT,
561 IN p_sr_task_assign_rec.ITEM_COMPONENT,
562 IN p_sr_task_assign_rec.ITEM_SUBCOMPONENT;
563
564 EXCEPTION
565 When OTHERS Then
566 NULL;
567
568 END Terr_Qual_Dyn_Assign;
569
570
571
572 -- *******************************************************************************
573
574 -- Start of comments
575
576 -- Function : This procedure is to check dynamically whether a value passed to
577 -- component,subcomponent fields. Used dynamic SQL to overcome AM's
578 -- build dependancy on Territory for these fields.
579
580 -- End of comments
581
582 -- *******************************************************************************
583
584
585 PROCEDURE Terr_Qual_Dyn_Check
586 (
587 p_sr_comp_sub OUT NOCOPY Varchar2,
588 p_sr_task_comp_sub OUT NOCOPY Varchar2)
589 IS
590
591 BEGIN
592
593 EXECUTE IMMEDIATE
594 '
595 BEGIN
596 If (JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type.SQUAL_NUM23 IS NOT NULL)
597 Or (JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type.SQUAL_NUM24 IS NOT NULL)
598 Then
599 :1:=''P'';
600 End If;
601
602 If (JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type.SQUAL_NUM23 IS NOT NULL)
603 Or (JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type.SQUAL_NUM24 IS NOT NULL)
604 Then
605 :2:=''P'';
606 End If;
607 End;
608 '
609 USING
610 OUT p_sr_comp_sub,
611 OUT p_sr_task_comp_sub;
612
613 EXCEPTION
614 When OTHERS Then
615 NULL;
616 END Terr_Qual_Dyn_Check;
617
618 /**************** End of addition by SBARAT on 11/01/2005 for Enh 4112155**************/
619
620
621 -- *******************************************************************************
622
623 -- Start of comments
624
625 -- Function : This procedure is to fetch the Resources in a particular
626 -- group based on the ID of the Group which has been passed.
627
628 -- End of comments
629
630 -- *******************************************************************************
631
632
633
634 PROCEDURE get_group_resource(p_group_id IN NUMBER,
635 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type)
636 IS
637
638 CURSOR check_mem_cur
639 (
640 l_group_id NUMBER,
641 l_resource_id NUMBER
642 ) IS
643 SELECT 'Y'
644 FROM jtf_rs_group_members mem
645 WHERE mem.group_id = l_group_id
646 AND mem.resource_id = l_resource_id
647 AND nvl(mem.delete_flag , 'N') <> 'Y';
648
649 l_found VARCHAR2(1) := 'N';
650 l_count NUMBER := 0;
651 i NUMBER := 0;
652 l_assign_resource_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
653
654
655 BEGIN
656 --FOR i IN 1..x_assign_resources_tbl.COUNT
657 -- changed loop criterion for bug 3284857. on 1st Dec 2003
658 IF(x_assign_resources_tbl.COUNT > 0)
659 THEN
660 FOR i IN x_assign_resources_tbl.FIRST..x_assign_resources_tbl.LAST
661 LOOP
662
663 IF (x_assign_resources_tbl(i).resource_type not in ('RS_TEAM', 'RS_GROUP')) THEN
664
665 l_found := 'N';
666 OPEN check_mem_cur(p_group_id,
667 x_assign_resources_tbl(i).resource_id);
668 FETCH check_mem_cur into l_found;
669 CLOSE check_mem_cur;
670
671 IF (l_found = 'Y') THEN
672
673 l_count := l_count + 1;
674 l_assign_resource_tbl(l_count).resource_id := x_assign_resources_tbl(i).resource_id;
675 l_assign_resource_tbl(l_count).resource_type := x_assign_resources_tbl(i).resource_type;
676 l_assign_resource_tbl(l_count).terr_rsc_id := x_assign_resources_tbl(i).terr_rsc_id;
677 l_assign_resource_tbl(l_count).role := x_assign_resources_tbl(i).role ;
678 l_assign_resource_tbl(l_count).start_date := x_assign_resources_tbl(i).start_date;
679 l_assign_resource_tbl(l_count).end_date := x_assign_resources_tbl(i).end_date;
680 l_assign_resource_tbl(l_count).shift_construct_id := x_assign_resources_tbl(i).shift_construct_id;
681 l_assign_resource_tbl(l_count).terr_id := x_assign_resources_tbl(i).terr_id ;
682 l_assign_resource_tbl(l_count).terr_name := x_assign_resources_tbl(i).terr_name;
683 -- ================code added for bug 6453896=============
684 l_assign_resource_tbl(l_count).terr_rank := x_assign_resources_tbl(i).terr_rank;
685 -- ================End for addition of code===============
686 l_assign_resource_tbl(l_count).primary_contact_flag := x_assign_resources_tbl(i).primary_contact_flag;
687 l_assign_resource_tbl(l_count).primary_flag := x_assign_resources_tbl(i).primary_flag;
688 l_assign_resource_tbl(l_count).travel_time := x_assign_resources_tbl(i).travel_time;
689 l_assign_resource_tbl(l_count).travel_uom := x_assign_resources_tbl(i).travel_uom;
690 l_assign_resource_tbl(l_count).preference_type := x_assign_resources_tbl(i).preference_type;
691 l_assign_resource_tbl(l_count).full_access_flag := x_assign_resources_tbl(i).full_access_flag;
692 l_assign_resource_tbl(l_count).group_id := x_assign_resources_tbl(i).group_id;
693 l_assign_resource_tbl(l_count).location := x_assign_resources_tbl(i).location;
694 l_assign_resource_tbl(l_count).trans_object_id := x_assign_resources_tbl(i).trans_object_id;
695 l_assign_resource_tbl(l_count).support_site_id := x_assign_resources_tbl(i).support_site_id;
696 l_assign_resource_tbl(l_count).support_site_name := x_assign_resources_tbl(i).support_site_name;
697 l_assign_resource_tbl(l_count).web_availability_flag := x_assign_resources_tbl(i).web_availability_flag;
698 l_assign_resource_tbl(l_count).skill_level := x_assign_resources_tbl(i).skill_level;
699 l_assign_resource_tbl(l_count).skill_name := x_assign_resources_tbl(i).skill_name;
700 l_assign_resource_tbl(l_count).resource_source := x_assign_resources_tbl(i).resource_source;
701
702 END IF;
703
704 /******************** Start of addition by SBARAT on 04/05/2006 for bug# 5205277********************/
705 ELSE
706
707 l_count := l_count + 1;
708 l_assign_resource_tbl(l_count).resource_id := x_assign_resources_tbl(i).resource_id;
709 l_assign_resource_tbl(l_count).resource_type := x_assign_resources_tbl(i).resource_type;
710 l_assign_resource_tbl(l_count).terr_rsc_id := x_assign_resources_tbl(i).terr_rsc_id;
711 l_assign_resource_tbl(l_count).role := x_assign_resources_tbl(i).role ;
712 l_assign_resource_tbl(l_count).start_date := x_assign_resources_tbl(i).start_date;
713 l_assign_resource_tbl(l_count).end_date := x_assign_resources_tbl(i).end_date;
714 l_assign_resource_tbl(l_count).shift_construct_id := x_assign_resources_tbl(i).shift_construct_id;
715 l_assign_resource_tbl(l_count).terr_id := x_assign_resources_tbl(i).terr_id ;
716 l_assign_resource_tbl(l_count).terr_name := x_assign_resources_tbl(i).terr_name;
717 -- ================code added for bug 6453896=============
718 l_assign_resource_tbl(l_count).terr_rank := x_assign_resources_tbl(i).terr_rank;
719 -- ================End for addition of code===============
720 l_assign_resource_tbl(l_count).primary_contact_flag := x_assign_resources_tbl(i).primary_contact_flag;
721 l_assign_resource_tbl(l_count).primary_flag := x_assign_resources_tbl(i).primary_flag;
722 l_assign_resource_tbl(l_count).travel_time := x_assign_resources_tbl(i).travel_time;
723 l_assign_resource_tbl(l_count).travel_uom := x_assign_resources_tbl(i).travel_uom;
724 l_assign_resource_tbl(l_count).preference_type := x_assign_resources_tbl(i).preference_type;
725 l_assign_resource_tbl(l_count).full_access_flag := x_assign_resources_tbl(i).full_access_flag;
726 l_assign_resource_tbl(l_count).group_id := x_assign_resources_tbl(i).group_id;
727 l_assign_resource_tbl(l_count).location := x_assign_resources_tbl(i).location;
728 l_assign_resource_tbl(l_count).trans_object_id := x_assign_resources_tbl(i).trans_object_id;
729 l_assign_resource_tbl(l_count).support_site_id := x_assign_resources_tbl(i).support_site_id;
730 l_assign_resource_tbl(l_count).support_site_name := x_assign_resources_tbl(i).support_site_name;
731 l_assign_resource_tbl(l_count).web_availability_flag := x_assign_resources_tbl(i).web_availability_flag;
732 l_assign_resource_tbl(l_count).skill_level := x_assign_resources_tbl(i).skill_level;
733 l_assign_resource_tbl(l_count).skill_name := x_assign_resources_tbl(i).skill_name;
734 l_assign_resource_tbl(l_count).resource_source := x_assign_resources_tbl(i).resource_source;
735
736 END IF;
737 /******************** End of addition by SBARAT on 04/05/2006 for bug# 5205277********************/
738
739 END LOOP;
740
741 x_assign_resources_tbl.delete;
742 x_assign_resources_tbl := l_assign_resource_tbl;
743 end if; -- end of count check
744 END get_group_resource;
745
746
747
748
749
750 -- *******************************************************************************
751
752 -- Start of comments
753
754 -- Function : This procedure is to fetch the Groups and Teams of any
755 -- particular USAGE Type.
756
757 -- End of comments
758
759 -- *******************************************************************************
760
761
762
763 PROCEDURE get_usage_resource(p_usage IN VARCHAR2,
764 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type)
765 IS
766
767 CURSOR grp_usg_cur
768 (
769 l_group_id IN NUMBER,
770 l_usage IN VARCHAR2
771 ) IS
772 SELECT 'Y'
773 FROM jtf_rs_group_usages
774 WHERE group_id = l_group_id
775 AND usage = l_usage;
776
777 CURSOR team_usg_cur
778 (
779 l_team_id IN NUMBER,
780 l_usage IN VARCHAR2
781 ) IS
782 SELECT 'Y'
783 FROM jtf_rs_team_usages
784 WHERE team_id = l_team_id
785 AND usage = l_usage;
786
787 l_found VARCHAR2(1) := 'N';
788 l_count NUMBER := 0;
789 i NUMBER := 0;
790 l_assign_resource_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
791
792 BEGIN
793 i := x_assign_resources_tbl.FIRST;
794
795 -- FOR i IN x_assign_resources_tbl.FIRST..x_assign_resources_tbl.COUNT
796 WHILE (i <= x_assign_resources_tbl.LAST)
797 LOOP
798
799 IF (x_assign_resources_tbl(i).resource_type in ('RS_TEAM' , 'RS_GROUP')) THEN
800
801 l_found := 'N';
802 IF (x_assign_resources_tbl(i).resource_type = 'RS_GROUP') THEN
803
804 OPEN grp_usg_cur(x_assign_resources_tbl(i).resource_id,
805 p_usage);
806 FETCH grp_usg_cur into l_found;
807 CLOSE grp_usg_cur;
808 ELSIF (x_assign_resources_tbl(i).resource_type = 'RS_TEAM') THEN
809 OPEN team_usg_cur( x_assign_resources_tbl(i).resource_id,
810 p_usage);
811 FETCH team_usg_cur into l_found;
812 CLOSE team_usg_cur;
813 END IF;
814
815 IF (l_found = 'Y') THEN
816
817 l_count := l_count + 1;
818 l_assign_resource_tbl(l_count).resource_id := x_assign_resources_tbl(i).resource_id;
819 l_assign_resource_tbl(l_count).resource_type := x_assign_resources_tbl(i).resource_type;
820 l_assign_resource_tbl(l_count).terr_rsc_id := x_assign_resources_tbl(i).terr_rsc_id;
821 l_assign_resource_tbl(l_count).role := x_assign_resources_tbl(i).role ;
822 l_assign_resource_tbl(l_count).start_date := x_assign_resources_tbl(i).start_date;
823 l_assign_resource_tbl(l_count).end_date := x_assign_resources_tbl(i).end_date;
824 l_assign_resource_tbl(l_count).shift_construct_id := x_assign_resources_tbl(i).shift_construct_id;
825 l_assign_resource_tbl(l_count).terr_id := x_assign_resources_tbl(i).terr_id ;
826 l_assign_resource_tbl(l_count).terr_name := x_assign_resources_tbl(i).terr_name;
827 l_assign_resource_tbl(l_count).terr_rank := x_assign_resources_tbl(i).terr_rank;
828 l_assign_resource_tbl(l_count).primary_contact_flag := x_assign_resources_tbl(i).primary_contact_flag;
829 l_assign_resource_tbl(l_count).primary_flag := x_assign_resources_tbl(i).primary_flag;
830 l_assign_resource_tbl(l_count).travel_time := x_assign_resources_tbl(i).travel_time;
831 l_assign_resource_tbl(l_count).travel_uom := x_assign_resources_tbl(i).travel_uom;
832 l_assign_resource_tbl(l_count).preference_type := x_assign_resources_tbl(i).preference_type;
833 l_assign_resource_tbl(l_count).primary_contact_flag := x_assign_resources_tbl(i).primary_contact_flag;
834 l_assign_resource_tbl(l_count).full_access_flag := x_assign_resources_tbl(i).full_access_flag;
835 l_assign_resource_tbl(l_count).group_id := x_assign_resources_tbl(i).group_id;
836 l_assign_resource_tbl(l_count).location := x_assign_resources_tbl(i).location;
837 l_assign_resource_tbl(l_count).trans_object_id := x_assign_resources_tbl(i).trans_object_id;
838 l_assign_resource_tbl(l_count).support_site_id := x_assign_resources_tbl(i).support_site_id;
839 l_assign_resource_tbl(l_count).support_site_name := x_assign_resources_tbl(i).support_site_name;
840 l_assign_resource_tbl(l_count).web_availability_flag := x_assign_resources_tbl(i).web_availability_flag;
841 l_assign_resource_tbl(l_count).skill_level := x_assign_resources_tbl(i).skill_level;
842 l_assign_resource_tbl(l_count).skill_name := x_assign_resources_tbl(i).skill_name;
843 l_assign_resource_tbl(l_count).resource_source := x_assign_resources_tbl(i).resource_source;
844
845
846 END IF;
847
848 i := x_assign_resources_tbl.next(i);
849
850 ELSE
851 l_count := l_count + 1;
852 l_assign_resource_tbl(l_count).resource_id := x_assign_resources_tbl(i).resource_id;
853 l_assign_resource_tbl(l_count).resource_type := x_assign_resources_tbl(i).resource_type;
854 l_assign_resource_tbl(l_count).terr_rsc_id := x_assign_resources_tbl(i).terr_rsc_id;
855 l_assign_resource_tbl(l_count).role := x_assign_resources_tbl(i).role ;
856 l_assign_resource_tbl(l_count).start_date := x_assign_resources_tbl(i).start_date;
857 l_assign_resource_tbl(l_count).end_date := x_assign_resources_tbl(i).end_date;
858 l_assign_resource_tbl(l_count).shift_construct_id := x_assign_resources_tbl(i).shift_construct_id;
859 l_assign_resource_tbl(l_count).terr_id := x_assign_resources_tbl(i).terr_id ;
860 l_assign_resource_tbl(l_count).terr_name := x_assign_resources_tbl(i).terr_name;
861 l_assign_resource_tbl(l_count).terr_rank := x_assign_resources_tbl(i).terr_rank;
862 l_assign_resource_tbl(l_count).primary_contact_flag := x_assign_resources_tbl(i).primary_contact_flag;
863 l_assign_resource_tbl(l_count).primary_flag := x_assign_resources_tbl(i).primary_flag;
864 l_assign_resource_tbl(l_count).travel_time := x_assign_resources_tbl(i).travel_time;
865 l_assign_resource_tbl(l_count).travel_uom := x_assign_resources_tbl(i).travel_uom;
866 l_assign_resource_tbl(l_count).preference_type := x_assign_resources_tbl(i).preference_type;
867 l_assign_resource_tbl(l_count).primary_contact_flag := x_assign_resources_tbl(i).primary_contact_flag;
868 l_assign_resource_tbl(l_count).full_access_flag := x_assign_resources_tbl(i).full_access_flag;
869 l_assign_resource_tbl(l_count).group_id := x_assign_resources_tbl(i).group_id;
870 l_assign_resource_tbl(l_count).location := x_assign_resources_tbl(i).location;
871 l_assign_resource_tbl(l_count).trans_object_id := x_assign_resources_tbl(i).trans_object_id;
872 l_assign_resource_tbl(l_count).support_site_id := x_assign_resources_tbl(i).support_site_id;
873 l_assign_resource_tbl(l_count).support_site_name := x_assign_resources_tbl(i).support_site_name;
874 l_assign_resource_tbl(l_count).web_availability_flag := x_assign_resources_tbl(i).web_availability_flag;
875 l_assign_resource_tbl(l_count).skill_level := x_assign_resources_tbl(i).skill_level;
876 l_assign_resource_tbl(l_count).skill_name := x_assign_resources_tbl(i).skill_name;
877 l_assign_resource_tbl(l_count).resource_source := x_assign_resources_tbl(i).resource_source;
878
879
880 i := x_assign_resources_tbl.next(i);
881 END IF;
882
883 END LOOP;
884
885 x_assign_resources_tbl.delete;
886 x_assign_resources_tbl := l_assign_resource_tbl;
887
888
889 END get_usage_resource;
890
891
892 -- Calendar call to determine availability of a resource
893 -- The api will be called after Contracts/IB/Territory preferred/qualified resource has been selected
894 -- The api will be called only when p_calendar_flag = 'Y'. None of the other api's should now call JTF_CALENDAR_PUB.GET_AVAILABLE_SLOT
895 PROCEDURE get_available_resources
896 (
897 p_init_msg_list IN VARCHAR2,
898 p_calendar_flag IN VARCHAR2,
899 p_effort_duration IN NUMBER,
900 p_effort_uom IN VARCHAR2,
901 p_planned_start_date IN DATE,
902 p_planned_end_date IN DATE,
903 p_continuous_task IN VARCHAR2,
904 x_return_status IN OUT NOCOPY VARCHAR2,
905 x_msg_count IN OUT NOCOPY NUMBER,
906 x_msg_data IN OUT NOCOPY VARCHAR2,
907 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type
908 )
909 IS
910
911
912 l_return_status_1 VARCHAR2(10);
913 l_api_name VARCHAR2(100) := 'GET_AVAILABLE_RESOURCES';
914 l_api_name_1 VARCHAR2(60) := 'GET_AVAILABLE_RESOURCES';
915 l_api_version NUMBER := 1.0;
916 l_status VARCHAR2(30);
917 l_industry VARCHAR2(30);
918
919 l_return_status VARCHAR2(10);
920 l_msg_count NUMBER;
921 l_msg_data VARCHAR2(2000);
922
923
924 l_current_record INTEGER := 0;
925 l_current_rec INTEGER := 0;
926 l_pref_record INTEGER := 0;
927
928 l_travel_time NUMBER := 0;
929 l_travel_uom VARCHAR2(10) := 'HR';
930
931 l_x_planned_start_date DATE;
932 l_x_planned_end_date DATE;
933 l_x_shift_construct_id NUMBER;
934 l_x_availability_type VARCHAR2(60);
935 l_uom_hour VARCHAR2(200);
936 l_effort_duration NUMBER;
937
938 l_resources_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
939
940
941
942 BEGIN
943 -- initialize the variables
944 x_return_status := fnd_api.g_ret_sts_success;
945 l_current_rec := 0;
946 l_resources_tbl.delete;
947
948 -- Added by SBARAT on 21/04/2005 for Bug-4300801
949 -- This conversion is done only before calling JTF_CALENDAR_PUB
950 /* to handle the conversion of duration to hour */
951 l_uom_hour := nvl(fnd_profile.value('JTF_AM_TASK_HOUR'), 'HR');
952 if(nvl(p_effort_uom, l_uom_hour) <> l_uom_hour)
953 then
954 l_effort_duration := inv_convert.inv_um_convert(
955 item_id => NULL,
956 precision => 2,
957 from_quantity => p_effort_duration,
958 from_unit => p_effort_uom,
959 to_unit => l_uom_hour, --'HR',
960 from_name => NULL,
961 to_name => NULL);
962 else
963 l_effort_duration := p_effort_duration;
964 end if;
965
966 -- if the in table has any resources, then this check should continue
967 IF x_assign_resources_tbl.COUNT > 0 THEN
968
969 l_current_record := x_assign_resources_tbl.FIRST;
970
971 WHILE l_current_record <= x_assign_resources_tbl.LAST
972 LOOP
973 -- if the calendar flag = Y then this should continue. This is a doublecheck as the calling api will check this
974 -- also
975 IF (p_calendar_flag = 'Y') THEN
976 -- change the API Name temporarily so that in case of unexpected error
977 -- it is properly caught
978 l_api_name := l_api_name||'-JTF_CALENDAR_PUB';
979 l_return_status_1 := x_return_status ;
980
981 -- This api returns the first available slot for the work duration within the available dates
982 JTF_CALENDAR_PUB.
983 GET_AVAILABLE_SLOT(
984 P_API_VERSION => l_api_version,
985 P_INIT_MSG_LIST => p_init_msg_list,
986 P_RESOURCE_ID => x_assign_resources_tbl(l_current_record).resource_id,
987 P_RESOURCE_TYPE => x_assign_resources_tbl(l_current_record).resource_type,
988 P_START_DATE_TIME => p_planned_start_date,
989 P_END_DATE_TIME => p_planned_end_date,
990 P_DURATION => l_effort_duration, --p_effort_duration,
991 X_RETURN_STATUS => x_return_status,
992 X_MSG_COUNT => x_msg_count,
993 X_MSG_DATA => x_msg_data,
994 X_SLOT_START_DATE => l_x_planned_start_date,
995 X_SLOT_END_DATE => l_x_planned_end_date,
996 X_SHIFT_CONSTRUCT_ID => l_x_shift_construct_id,
997 X_AVAILABILITY_TYPE => l_x_availability_type
998 );
999
1000 -- set back the API name to original name
1001 l_api_name := l_api_name_1;
1002
1003 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
1004 -- Unexpected Execution Error from call to Calendar
1005 fnd_message.set_name('JTF', 'JTF_AM_ERROR_CAL_API');
1006 fnd_msg_pub.add;
1007 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
1008 -- 12/22/05 ** MPADHIAR ** Manas padhiary **
1009 -- Removed Comment to Show error message Bug # 2919389
1010 RAISE fnd_api.g_exc_error;
1011 ELSE
1012 RAISE fnd_api.g_exc_unexpected_error;
1013 END IF;
1014 END IF;
1015
1016 -- Put the records into the PL/SQL Table.
1017 -- if the returned shift_construct_id is not null then the resource has an available slot.
1018 IF (l_x_shift_construct_id IS NOT NULL) THEN
1019 l_resources_tbl(l_current_rec).terr_rsc_id := NULL;
1020 l_resources_tbl(l_current_rec).resource_id :=
1021 x_assign_resources_tbl(l_current_record).resource_id;
1022 l_resources_tbl(l_current_rec).resource_type:=
1023 x_assign_resources_tbl(l_current_record).resource_type;
1024 l_resources_tbl(l_current_rec).role := NULL;
1025
1026 IF (l_travel_uom like 'HR%') THEN
1027 l_resources_tbl(l_current_rec).start_date :=
1028 l_x_planned_start_date + l_travel_time/24;
1029 l_resources_tbl(l_current_rec).end_date :=
1030 l_x_planned_end_date + l_travel_time/24;
1031 ELSIF (l_travel_uom like 'MI%') THEN
1032 l_resources_tbl(l_current_rec).start_date :=
1033 l_x_planned_start_date + l_travel_time/1440;
1034 l_resources_tbl(l_current_rec).end_date :=
1035 l_x_planned_end_date + l_travel_time/1440;
1036 ELSIF (l_travel_uom like 'S%') THEN
1037 l_resources_tbl(l_current_rec).start_date :=
1038 l_x_planned_start_date + l_travel_time/86400;
1039 l_resources_tbl(l_current_rec).end_date :=
1040 l_x_planned_end_date + l_travel_time/86400;
1041 END IF;
1042
1043 l_resources_tbl(l_current_rec).shift_construct_id := l_x_shift_construct_id;
1044 l_resources_tbl(l_current_rec).terr_id := x_assign_resources_tbl(l_current_record).terr_id;
1045 l_resources_tbl(l_current_rec).terr_name := x_assign_resources_tbl(l_current_record).terr_name;
1046 -- ================code added for bug 6453896=============
1047 l_resources_tbl(l_current_rec).terr_rank := x_assign_resources_tbl(l_current_record).terr_rank;
1048 -- ================End for addition of code===============
1049 l_resources_tbl(l_current_rec).preference_type := x_assign_resources_tbl(l_current_record).preference_type;
1050 l_resources_tbl(l_current_rec).primary_flag := x_assign_resources_tbl(l_current_record).primary_flag;
1051 l_resources_tbl(l_current_rec).primary_contact_flag := x_assign_resources_tbl(l_current_record).primary_contact_flag;
1052 l_resources_tbl(l_current_rec).full_access_flag := x_assign_resources_tbl(l_current_record).full_access_flag;
1053 l_resources_tbl(l_current_rec).group_id := x_assign_resources_tbl(l_current_record).group_id;
1054 l_resources_tbl(l_current_rec).location := x_assign_resources_tbl(l_current_record).location;
1055 l_resources_tbl(l_current_rec).trans_object_id := x_assign_resources_tbl(l_current_record).trans_object_id;
1056 l_resources_tbl(l_current_rec).support_site_id := x_assign_resources_tbl(l_current_record).support_site_id;
1057 l_resources_tbl(l_current_rec).support_site_name := x_assign_resources_tbl(l_current_record).support_site_name;
1058 l_resources_tbl(l_current_rec).web_availability_flag := x_assign_resources_tbl(l_current_record).web_availability_flag;
1059 l_resources_tbl(l_current_rec).skill_level := x_assign_resources_tbl(l_current_record).skill_level;
1060 l_resources_tbl(l_current_rec).skill_name := x_assign_resources_tbl(l_current_record).skill_name;
1061 l_resources_tbl(l_current_rec).resource_source := x_assign_resources_tbl(l_current_record).resource_source;
1062
1063 l_current_rec := l_current_rec + 1;
1064 END IF; -- End of shift_construct_id not null check
1065
1066 END IF; -- Calendar Flag is NO
1067
1068 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
1069 END LOOP;
1070
1071 -- assign the available resources back to the out table
1072 x_assign_resources_tbl.delete;
1073 x_assign_resources_tbl := l_resources_tbl;
1074
1075 END IF;
1076
1077 EXCEPTION
1078 WHEN FND_API.G_EXC_ERROR THEN
1079 x_return_status := FND_API.G_RET_STS_ERROR ;
1080 FND_MSG_PUB.Count_And_Get
1081 (
1082 p_count => x_msg_count,
1083 p_data => x_msg_data
1084 );
1085
1086 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1087 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1088 FND_MSG_PUB.Count_And_Get
1089 (
1090 p_count => x_msg_count,
1091 p_data => x_msg_data
1092 );
1093
1094 WHEN OTHERS THEN
1095 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
1096 fnd_message.set_token('P_SQLCODE',SQLCODE);
1097 fnd_message.set_token('P_SQLERRM',SQLERRM);
1098 fnd_message.set_token('P_API_NAME',l_api_name);
1099 FND_MSG_PUB.add;
1100
1101 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1102 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
1103 FND_MSG_PUB.Add_Exc_Msg
1104 (
1105 G_PKG_NAME,
1106 l_api_name
1107 );
1108 END IF;
1109
1110 FND_MSG_PUB.Count_And_Get
1111 (
1112 p_count => x_msg_count,
1113 p_data => x_msg_data
1114 );
1115
1116 END get_available_resources;
1117
1118
1119 -- Overloaded procedure for calendar call
1120 -- The api will be called after Contracts/IB/Territory preferred/qualified resource has been selected
1121 -- The api will be called only when p_calendar_flag = 'Y'. None of the other api's should now call JTF_CALENDAR_PUB.GET_AVAILABLE_SLOT
1122 PROCEDURE get_available_resources
1123 (
1124 p_init_msg_list IN VARCHAR2,
1125 p_calendar_flag IN VARCHAR2,
1126 p_effort_duration IN NUMBER,
1127 p_effort_uom IN VARCHAR2,
1128 p_breakdown IN NUMBER,
1129 p_breakdown_uom IN VARCHAR2,
1130 p_planned_start_date IN DATE,
1131 p_planned_end_date IN DATE,
1132 p_continuous_task IN VARCHAR2,
1133 x_return_status IN OUT NOCOPY VARCHAR2,
1134 x_msg_count IN OUT NOCOPY NUMBER,
1135 x_msg_data IN OUT NOCOPY VARCHAR2,
1136 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
1137 --Added for Bug # 5573916
1138 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
1139 --Added for Bug # 5573916 Ends here
1140 )
1141 IS
1142
1143
1144 l_return_status_1 VARCHAR2(10);
1145 l_api_name VARCHAR2(100) := 'GET_AVAILABLE_RESOURCES';
1146 l_api_name_1 VARCHAR2(60) := 'GET_AVAILABLE_RESOURCES';
1147 l_api_version NUMBER := 1.0;
1148 l_status VARCHAR2(30);
1149 l_industry VARCHAR2(30);
1150
1151 l_return_status VARCHAR2(10);
1152 l_msg_count NUMBER;
1153 l_msg_data VARCHAR2(2000);
1154
1155
1156 l_current_record INTEGER := 0;
1157 l_current_rec INTEGER := 0;
1158 l_pref_record INTEGER := 0;
1159
1160 l_travel_time NUMBER := 0;
1161 l_travel_uom VARCHAR2(10) := 'HR';
1162
1163 l_x_planned_start_date DATE;
1164 l_x_planned_end_date DATE;
1165 l_x_shift_construct_id NUMBER;
1166 l_x_availability_type VARCHAR2(60);
1167
1168 l_resources_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
1169
1170 TYPE l_slots_rec IS RECORD
1171 (slot_value NUMBER);
1172
1173 Type l_slots_tbl IS TABLE of l_slots_rec
1174 INDEX BY BINARY_INTEGER;
1175 l_slots l_slots_tbl;
1176
1177 l_effort_duration NUMBER := p_effort_duration;
1178 l_effort_duration_1 NUMBER := p_effort_duration;
1179 l_breakdown NUMBER := p_breakdown;
1180 i NUMBER ;
1181 l_temp_start_date DATE;
1182 l_temp_end_date DATE;
1183 l_avail_count NUMBER;
1184 l_uom_hour VARCHAR2(200);
1185 l_avail_resource JTF_ASSIGN_PUB.Avail_tbl_type;
1186 l_temp_count NUMBER := 0;
1187 BEGIN
1188 -- initialize the variables
1189 x_return_status := fnd_api.g_ret_sts_success;
1190 l_current_rec := 0;
1191 l_resources_tbl.delete;
1192 JTF_ASSIGN_PUB.g_resource_avail.delete;
1193
1194 /* to handle the conversion of duration to hour */
1195 l_uom_hour := nvl(fnd_profile.value('JTF_AM_TASK_HOUR'), 'HR');
1196 if(nvl(p_effort_uom, l_uom_hour) <> l_uom_hour)
1197 then
1198 l_effort_duration := inv_convert.inv_um_convert(
1199 item_id => NULL,
1200 precision => 2,
1201 from_quantity => p_effort_duration,
1202 from_unit => p_effort_uom,
1203 to_unit => l_uom_hour, --'HR',
1204 from_name => NULL,
1205 to_name => NULL);
1206 else
1207 l_effort_duration := p_effort_duration;
1208 end if;
1209
1210 l_effort_duration := nvl(l_effort_duration, 1);
1211
1212 /* to handle the conversion of breakdown duration to hour */
1213 if(nvl(p_breakdown_uom, l_uom_hour) <> l_uom_hour)
1214 AND p_breakdown is not null
1215 then
1216 l_breakdown := inv_convert.inv_um_convert(
1217 item_id => NULL,
1218 precision => 2,
1219 from_quantity => p_breakdown,
1220 from_unit => p_breakdown_uom,
1221 to_unit => l_uom_hour, --'HR',
1222 from_name => NULL,
1223 to_name => NULL);
1224 else
1225 l_breakdown := p_breakdown;
1226 end if;
1227
1228 -- if the in table has any resources, then this check should continue
1229 IF x_assign_resources_tbl.COUNT > 0 THEN
1230 --Added for Bug # 5573916
1231 --Calendar check won't be done if p_calendar_check = 'N' Where as p_calendar_flag will be continued to used as
1232 --filter resource based on available calendar time slot
1233 IF (p_calendar_check = 'N') THEN
1234 l_current_rec := x_assign_resources_tbl.FIRST;
1235 WHILE l_current_rec <= x_assign_resources_tbl.LAST
1236 LOOP
1237 x_assign_resources_tbl(l_current_rec).terr_rsc_id := NULL;
1238 x_assign_resources_tbl(l_current_rec).role := NULL;
1239 x_assign_resources_tbl(l_current_rec).start_date := NULL;
1240 x_assign_resources_tbl(l_current_rec).end_date := NULL;
1241 x_assign_resources_tbl(l_current_rec).shift_construct_id := NULL;
1242 l_current_rec := l_current_rec + 1;
1243 END LOOP;
1244 ELSE
1245 --Added for Bug # 5573916 Ends here
1246
1247 -- break up the duration if breakdown is given
1248 IF( (p_breakdown is not null) and (nvl(l_breakdown , 0) > 0) AND (nvl(l_breakdown,0) < l_effort_duration))
1249 THEN
1250 l_effort_duration_1 := l_effort_duration;
1251 i := 0;
1252 While (l_effort_duration_1 > 0)
1253 LOOP
1254 l_slots(i).slot_value := l_breakdown;
1255 l_effort_duration_1 := l_effort_duration_1 - l_breakdown;
1256 IF(l_effort_duration_1 > l_breakdown)
1257 THEN
1258 l_breakdown := l_breakdown;
1259 ELSE
1260 l_breakdown := l_effort_duration_1;
1261 END IF;
1262 i := i + 1;
1263 END LOOP; -- end of l_effort_duration check
1264 END IF; -- end of breakdown check
1265
1266
1267 IF(l_effort_duration <= nvl(l_breakdown,l_effort_duration))
1268 THEN
1269
1270 l_current_record := x_assign_resources_tbl.FIRST;
1271 l_avail_count := 0;
1272 jtf_assign_pub.g_resource_avail.delete;
1273 WHILE l_current_record <= x_assign_resources_tbl.LAST
1274 LOOP
1275 -- if the calendar flag = Y then this should continue. This is a doublecheck as the calling api will check this
1276 -- also
1277 -- Irrespective of whether the calendar flag is Y or N
1278 -- IF (p_calendar_flag = 'Y') THEN
1279 -- change the API Name temporarily so that in case of unexpected error
1280 -- it is properly caught
1281 l_api_name := l_api_name||'-JTF_CALENDAR_PUB';
1282 l_return_status_1 := x_return_status ;
1283
1284 -- This api returns the first available slot for the work duration within the available dates
1285 JTF_CALENDAR_PUB.GET_AVAILABLE_SLOT
1286 (
1287 P_API_VERSION => l_api_version,
1288 P_INIT_MSG_LIST => p_init_msg_list,
1289 P_RESOURCE_ID => x_assign_resources_tbl(l_current_record).resource_id,
1290 P_RESOURCE_TYPE => x_assign_resources_tbl(l_current_record).resource_type,
1291 P_START_DATE_TIME => p_planned_start_date,
1292 P_END_DATE_TIME => p_planned_end_date,
1293 P_DURATION => l_effort_duration,
1294 X_RETURN_STATUS => x_return_status,
1295 X_MSG_COUNT => x_msg_count,
1296 X_MSG_DATA => x_msg_data,
1297 X_SLOT_START_DATE => l_x_planned_start_date,
1298 X_SLOT_END_DATE => l_x_planned_end_date,
1299 X_SHIFT_CONSTRUCT_ID => l_x_shift_construct_id,
1300 X_AVAILABILITY_TYPE => l_x_availability_type
1301 );
1302
1303 -- set back the API name to original name
1304 l_api_name := l_api_name_1;
1305
1306 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
1307 -- Unexpected Execution Error from call to Calendar
1308 fnd_message.set_name('JTF', 'JTF_AM_ERROR_CAL_API');
1309 fnd_msg_pub.add;
1310 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
1311 -- 12/22/05 ** MPADHIAR ** Manas padhiary **
1312 -- Removed Comment to Show error message Bug # 2919389
1313 RAISE fnd_api.g_exc_error;
1314 ELSE
1315 RAISE fnd_api.g_exc_unexpected_error;
1316 END IF;
1317 END IF;
1318
1319 -- Put the records into the PL/SQL Table.
1320 -- if the returned shift_construct_id is not null then the resource has an available slot.
1321 IF (l_x_shift_construct_id IS NOT NULL) THEN
1322 l_resources_tbl(l_current_rec).terr_rsc_id := NULL;
1323 l_resources_tbl(l_current_rec).resource_id :=
1324 x_assign_resources_tbl(l_current_record).resource_id;
1325 l_resources_tbl(l_current_rec).resource_type:=
1326 x_assign_resources_tbl(l_current_record).resource_type;
1327 l_resources_tbl(l_current_rec).role := NULL;
1328
1329 IF (l_travel_uom like 'HR%') THEN
1330 l_resources_tbl(l_current_rec).start_date :=
1331 l_x_planned_start_date + l_travel_time/24;
1332 l_resources_tbl(l_current_rec).end_date :=
1333 l_x_planned_end_date + l_travel_time/24;
1334 ELSIF (l_travel_uom like 'MI%') THEN
1335 l_resources_tbl(l_current_rec).start_date :=
1336 l_x_planned_start_date + l_travel_time/1440;
1337 l_resources_tbl(l_current_rec).end_date :=
1338 l_x_planned_end_date + l_travel_time/1440;
1339 ELSIF (l_travel_uom like 'S%') THEN
1340 l_resources_tbl(l_current_rec).start_date :=
1341 l_x_planned_start_date + l_travel_time/86400;
1342 l_resources_tbl(l_current_rec).end_date :=
1343 l_x_planned_end_date + l_travel_time/86400;
1344 END IF;
1345
1346 l_resources_tbl(l_current_rec).shift_construct_id := l_x_shift_construct_id;
1347 l_resources_tbl(l_current_rec).terr_id := x_assign_resources_tbl(l_current_record).terr_id;
1348 l_resources_tbl(l_current_rec).terr_name := x_assign_resources_tbl(l_current_record).terr_name;
1349 -- ================code added for bug 6453896=============
1350 l_resources_tbl(l_current_rec).terr_rank := x_assign_resources_tbl(l_current_record).terr_rank;
1351 -- ================End for addition of code===============
1352 l_resources_tbl(l_current_rec).preference_type := x_assign_resources_tbl(l_current_record).preference_type;
1353 l_resources_tbl(l_current_rec).primary_flag := x_assign_resources_tbl(l_current_record).primary_flag;
1354 l_resources_tbl(l_current_rec).primary_contact_flag := x_assign_resources_tbl(l_current_record).primary_contact_flag;
1355 l_resources_tbl(l_current_rec).full_access_flag := x_assign_resources_tbl(l_current_record).full_access_flag;
1356 l_resources_tbl(l_current_rec).group_id := x_assign_resources_tbl(l_current_record).group_id;
1357 l_resources_tbl(l_current_rec).location := x_assign_resources_tbl(l_current_record).location;
1358 l_resources_tbl(l_current_rec).trans_object_id := x_assign_resources_tbl(l_current_record).trans_object_id;
1359 l_resources_tbl(l_current_rec).support_site_id := x_assign_resources_tbl(l_current_record).support_site_id;
1360 l_resources_tbl(l_current_rec).support_site_name := x_assign_resources_tbl(l_current_record).support_site_name;
1361 l_resources_tbl(l_current_rec).web_availability_flag := x_assign_resources_tbl(l_current_record).web_availability_flag;
1362 l_resources_tbl(l_current_rec).skill_level := x_assign_resources_tbl(l_current_record).skill_level;
1363 l_resources_tbl(l_current_rec).skill_name := x_assign_resources_tbl(l_current_record).skill_name;
1364 l_resources_tbl(l_current_rec).resource_source := x_assign_resources_tbl(l_current_record).resource_source;
1365
1366 -- assign values to availability table
1367 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).resource_id := l_resources_tbl(l_current_rec).resource_id;
1368 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).resource_type := l_resources_tbl(l_current_rec).resource_type;
1369 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).start_date := l_resources_tbl(l_current_rec).start_date;
1370 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).end_date := l_resources_tbl(l_current_rec).end_date;
1371 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).shift_construct_id := l_resources_tbl(l_current_rec).shift_construct_id;
1372
1373 l_current_rec := l_current_rec + 1;
1374 l_avail_count := l_avail_count + 1;
1375
1376 -- added the else part to return null if the resource does not have a shift also
1377 ELSE
1378 l_resources_tbl(l_current_rec).terr_rsc_id := NULL;
1379 l_resources_tbl(l_current_rec).resource_id := x_assign_resources_tbl(l_current_record).resource_id;
1380 l_resources_tbl(l_current_rec).resource_type := x_assign_resources_tbl(l_current_record).resource_type;
1381 l_resources_tbl(l_current_rec).role := NULL;
1382 l_resources_tbl(l_current_rec).start_date := NULL;
1383 l_resources_tbl(l_current_rec).end_date := NULL;
1384 l_resources_tbl(l_current_rec).shift_construct_id := NULL;
1385 l_resources_tbl(l_current_rec).terr_id := x_assign_resources_tbl(l_current_record).terr_id;
1386 l_resources_tbl(l_current_rec).terr_name := x_assign_resources_tbl(l_current_record).terr_name;
1387 -- ================code added for bug 6453896=============
1388 l_resources_tbl(l_current_rec).terr_rank := x_assign_resources_tbl(l_current_record).terr_rank;
1389 -- ================End for addition of code===============
1390 l_resources_tbl(l_current_rec).preference_type := x_assign_resources_tbl(l_current_record).preference_type;
1391 l_resources_tbl(l_current_rec).primary_flag := x_assign_resources_tbl(l_current_record).primary_flag;
1392 l_resources_tbl(l_current_rec).primary_contact_flag := x_assign_resources_tbl(l_current_record).primary_contact_flag;
1393 l_resources_tbl(l_current_rec).full_access_flag := x_assign_resources_tbl(l_current_record).full_access_flag;
1394 l_resources_tbl(l_current_rec).group_id := x_assign_resources_tbl(l_current_record).group_id;
1395 l_resources_tbl(l_current_rec).location := x_assign_resources_tbl(l_current_record).location;
1396 l_resources_tbl(l_current_rec).trans_object_id := x_assign_resources_tbl(l_current_record).trans_object_id;
1397 l_resources_tbl(l_current_rec).support_site_id := x_assign_resources_tbl(l_current_record).support_site_id;
1398 l_resources_tbl(l_current_rec).support_site_name := x_assign_resources_tbl(l_current_record).support_site_name;
1399 l_resources_tbl(l_current_rec).web_availability_flag := x_assign_resources_tbl(l_current_record).web_availability_flag;
1400 l_resources_tbl(l_current_rec).skill_level := x_assign_resources_tbl(l_current_record).skill_level;
1401 l_resources_tbl(l_current_rec).skill_name := x_assign_resources_tbl(l_current_record).skill_name;
1402 l_resources_tbl(l_current_rec).resource_source := x_assign_resources_tbl(l_current_record).resource_source;
1403
1404 l_current_rec := l_current_rec + 1;
1405 END IF; -- End of shift_construct_id not null check
1406
1407 --END IF; -- Calendar Flag is NO
1408
1409 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
1410 END LOOP;
1411
1412 -- assign the available resources back to the out table
1413 x_assign_resources_tbl.delete;
1414 -- if calendar flag is Y then filter out the resources that do not have a available slot.
1415 IF (p_calendar_flag = 'Y') THEN
1416 l_current_rec := l_resources_tbl.first;
1417 l_current_record := 0;
1418 While(l_current_rec <= l_resources_tbl.LAST)
1419 Loop
1420 IF(l_resources_tbl(l_current_rec).shift_construct_id is not null)
1421 THEN
1422 x_assign_resources_tbl(l_current_record) := l_resources_tbl(l_current_rec);
1423 l_current_record := l_current_record + 1;
1424 END IF;
1425 l_current_rec := l_current_rec + 1;
1426 END LOOP;
1427
1428 ELSE -- check p_calendar flag = Y
1429 -- else pass back all resources
1430 x_assign_resources_tbl := l_resources_tbl;
1431 l_api_name := l_api_name||'-JTF_CALENDAR_PUB';
1432 l_return_status_1 := x_return_status ;
1433 END IF; -- check p_calendar flag = Y
1434
1435 ELSE -- check for l_effort_duration <= l_breakdown
1436 -- new logic to get resources when work has been broken down into seperate slots
1437 l_current_rec := x_assign_resources_tbl.first;
1438 l_avail_count := 0;
1439 While(l_current_rec <= x_assign_resources_tbl.last)
1440 LOOP
1441 l_temp_start_date := p_planned_start_date;
1442 l_temp_end_date := p_planned_end_date;
1443
1444 FOR i in l_slots.first..l_slots.last
1445 LOOP
1446 l_api_name := l_api_name||'-JTF_CALENDAR_PUB';
1447 l_return_status_1 := x_return_status ;
1448
1449 l_x_shift_construct_id := null;
1450 l_x_planned_start_date := null;
1451 l_x_planned_end_date := null;
1452 l_x_availability_type := null;
1453 -- This api returns the first available slot for the work duration within the available dates
1454 JTF_CALENDAR_PUB.GET_AVAILABLE_SLOT
1455 (
1456 P_API_VERSION => l_api_version,
1457 P_INIT_MSG_LIST => p_init_msg_list,
1458 P_RESOURCE_ID => x_assign_resources_tbl(l_current_rec).resource_id,
1459 P_RESOURCE_TYPE => x_assign_resources_tbl(l_current_rec).resource_type,
1460 P_START_DATE_TIME => l_temp_start_date,
1461 P_END_DATE_TIME => l_temp_end_date,
1462 P_DURATION => l_slots(i).slot_value,
1463 X_RETURN_STATUS => x_return_status,
1464 X_MSG_COUNT => x_msg_count,
1465 X_MSG_DATA => x_msg_data,
1466 X_SLOT_START_DATE => l_x_planned_start_date,
1467 X_SLOT_END_DATE => l_x_planned_end_date,
1468 X_SHIFT_CONSTRUCT_ID => l_x_shift_construct_id,
1469 X_AVAILABILITY_TYPE => l_x_availability_type
1470 );
1471 --dbms_output.put_line('Slots are ...'||to_char(l_slots(i).slot_value)||'...'||to_char(l_x_planned_start_date, 'DD-MON-YYYY HH24:MI'));
1472 --dbms_output.put_line('Slots are ...'||to_char(x_assign_resources_tbl(l_current_rec).resource_id)||'...'||to_char(l_x_planned_end_date, 'DD-MON-YYYY HH24:MI'));
1473 -- set back the API name to original name
1474 l_api_name := l_api_name_1;
1475
1476 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
1477 -- Unexpected Execution Error from call to Calendar
1478 fnd_message.set_name('JTF', 'JTF_AM_ERROR_CAL_API');
1479 fnd_msg_pub.add;
1480 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
1481 -- 12/22/05 ** MPADHIAR ** Manas padhiary **
1482 -- Removed Comment to Show error message Bug # 2919389
1483 RAISE fnd_api.g_exc_error;
1484
1485 ELSE
1486 RAISE fnd_api.g_exc_unexpected_error;
1487 END IF;
1488 END IF;
1489 if(l_x_shift_construct_id is not null)
1490 then
1491 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).resource_id := x_assign_resources_tbl(l_current_rec).resource_id;
1492 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).resource_type :=x_assign_resources_tbl(l_current_rec).resource_type;
1493 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).start_date := l_x_planned_start_date;
1494 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).end_date := l_x_planned_end_date;
1495 JTF_ASSIGN_PUB.g_resource_avail(l_avail_count).shift_construct_id := l_x_shift_construct_id;
1496 l_avail_count := l_avail_count + 1;
1497 l_temp_start_date := l_x_planned_end_date;
1498 l_temp_end_date := p_planned_end_date;
1499 else
1500 -- remove the available slots for the resource
1501 l_temp_count := 0;
1502 FOR k in JTF_ASSIGN_PUB.g_resource_avail.first..JTF_ASSIGN_PUB.g_resource_avail.last
1503 LOOP
1504 IF(JTF_ASSIGN_PUB.g_resource_avail(k).resource_id = x_assign_resources_tbl(l_current_rec).resource_id
1505 AND JTF_ASSIGN_PUB.g_resource_avail(k).resource_type = x_assign_resources_tbl(l_current_rec).resource_type)
1506 THEN
1507 null ; --l_avail_count := l_avail_count - 1;
1508 ELSE
1509 l_avail_resource(l_temp_count) := JTF_ASSIGN_PUB.g_resource_avail(k);
1510 l_temp_count := l_temp_count + 1;
1511 END IF;
1512 END LOOP;
1513 JTF_ASSIGN_PUB.g_resource_avail.delete;
1514 JTF_ASSIGN_PUB.g_resource_avail := l_avail_resource;
1515 l_avail_count := JTF_ASSIGN_PUB.g_resource_avail.last + 1;
1516 exit;
1517 end if; -- end of l_x_shift_contruct_id check
1518
1519 END LOOP; -- end of check for l_slots
1520 l_current_rec := l_current_rec + 1;
1521 END LOOP; -- end of l_current_rec check
1522
1523 IF (p_calendar_flag = 'Y') THEN
1524 l_current_rec := x_assign_resources_tbl.first;
1525 l_current_record := 0;
1526 While(l_current_rec <= x_assign_resources_tbl.LAST)
1527 Loop
1528 -- remove records that are not there in g_avail_resource
1529 FOR i IN JTF_ASSIGN_PUB.g_resource_avail.first..JTF_ASSIGN_PUB.g_resource_avail.last
1530 LOOP
1531 IF(JTF_ASSIGN_PUB.g_resource_avail(i).resource_id = x_assign_resources_tbl(l_current_rec).resource_id
1532 AND JTF_ASSIGN_PUB.g_resource_avail(i).resource_type = x_assign_resources_tbl(l_current_rec).resource_type)
1533 THEN
1534 l_resources_tbl(l_current_record) := x_assign_resources_tbl(l_current_rec);
1535 l_resources_tbl(l_current_record).shift_construct_id := JTF_ASSIGN_PUB.g_resource_avail(i).shift_construct_id;
1536 l_resources_tbl(l_current_record).start_date := JTF_ASSIGN_PUB.g_resource_avail(i).start_date;
1537 l_resources_tbl(l_current_record).end_date := JTF_ASSIGN_PUB.g_resource_avail(i).end_date;
1538 l_current_record := l_current_record + 1;
1539 exit;
1540 END IF;
1541 END LOOP; -- end of loop for i in g_resource_avail first to last
1542 l_current_rec := l_current_rec + 1;
1543 END LOOP;
1544 x_assign_resources_tbl.delete;
1545 l_current_rec := l_resources_tbl.first;
1546 l_current_record := 0;
1547 While(l_current_rec <= l_resources_tbl.LAST)
1548 Loop
1549 x_assign_resources_tbl(l_current_record) := l_resources_tbl(l_current_rec);
1550 l_current_rec := l_current_rec + 1;
1551 l_current_record := l_current_record + 1;
1552 END LOOP;
1553
1554 ELSE -- check p_calendar flag = Y
1555 -- else pass back all resources with the start date and end dates of resources with first availability slot dates
1556 l_current_rec := x_assign_resources_tbl.first;
1557 While(l_current_rec <= x_assign_resources_tbl.LAST
1558 AND JTF_ASSIGN_PUB.g_resource_avail.count > 0)
1559 Loop
1560 -- remove records that are not there in g_avail_resource
1561 FOR i IN JTF_ASSIGN_PUB.g_resource_avail.first..JTF_ASSIGN_PUB.g_resource_avail.last
1562 LOOP
1563 IF(JTF_ASSIGN_PUB.g_resource_avail(i).resource_id = x_assign_resources_tbl(l_current_rec).resource_id
1564 AND JTF_ASSIGN_PUB.g_resource_avail(i).resource_type = x_assign_resources_tbl(l_current_rec).resource_type)
1565 THEN
1566 x_assign_resources_tbl(l_current_rec).shift_construct_id := JTF_ASSIGN_PUB.g_resource_avail(i).shift_construct_id;
1567 x_assign_resources_tbl(l_current_rec).start_date := JTF_ASSIGN_PUB.g_resource_avail(i).start_date;
1568 x_assign_resources_tbl(l_current_rec).end_date := JTF_ASSIGN_PUB.g_resource_avail(i).end_date;
1569 exit;
1570 END IF;
1571 END LOOP; -- end of loop for i in g_resource_avail first to last
1572 IF(x_assign_resources_tbl(l_current_rec).shift_construct_id IS NULL)
1573 THEN
1574 x_assign_resources_tbl(l_current_rec).start_date := NULL;
1575 x_assign_resources_tbl(l_current_rec).end_date := NULL;
1576 END IF;
1577 l_current_rec := l_current_rec + 1;
1578 END LOOP; -- end of l_current_rec check
1579 END IF; -- check p_calendar flag = Y
1580 END IF; -- check for p_effort_duration <= p_breakdown
1581 --Added for Bug # 5573916
1582 END IF;
1583 --Added for Bug # 5573916 Ends here
1584 END IF; -- if x_assign_resurces_tbl count > 0 check
1585
1586 EXCEPTION
1587 WHEN FND_API.G_EXC_ERROR THEN
1588 x_return_status := FND_API.G_RET_STS_ERROR ;
1589 FND_MSG_PUB.Count_And_Get
1590 (
1591 p_count => x_msg_count,
1592 p_data => x_msg_data
1593 );
1594
1595 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1596 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1597 FND_MSG_PUB.Count_And_Get
1598 (
1599 p_count => x_msg_count,
1600 p_data => x_msg_data
1601 );
1602
1603 WHEN OTHERS THEN
1604 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
1605 fnd_message.set_token('P_SQLCODE',SQLCODE);
1606 fnd_message.set_token('P_SQLERRM',SQLERRM);
1607 fnd_message.set_token('P_API_NAME',l_api_name);
1608 FND_MSG_PUB.add;
1609
1610 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1611 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
1612 FND_MSG_PUB.Add_Exc_Msg
1613 (
1614 G_PKG_NAME,
1615 l_api_name
1616 );
1617 END IF;
1618
1619 FND_MSG_PUB.Count_And_Get
1620 (
1621 p_count => x_msg_count,
1622 p_data => x_msg_data
1623 );
1624
1625 END get_available_resources;
1626
1627
1628
1629
1630
1631 -- *******************************************************************************
1632
1633 -- Start of comments
1634
1635 -- Function : This procedure is to fetch the Contracts Preferred Resources.
1636 -- This passes out the table of records with the resources.
1637
1638 -- End of comments
1639
1640 -- *******************************************************************************
1641
1642
1643 PROCEDURE get_contracts_resources
1644 (
1645 p_init_msg_list IN VARCHAR2,
1646 p_contract_id IN NUMBER,
1647 p_calendar_flag IN VARCHAR2,
1648 p_effort_duration IN NUMBER,
1649 p_effort_uom IN VARCHAR2,
1650 p_planned_start_date IN DATE,
1651 p_planned_end_date IN DATE,
1652 p_resource_type IN VARCHAR2,
1653 p_business_process_id IN NUMBER,
1654 p_business_process_date IN DATE,
1655 x_return_status IN OUT NOCOPY VARCHAR2,
1656 x_msg_count IN OUT NOCOPY NUMBER,
1657 x_msg_data IN OUT NOCOPY VARCHAR2,
1658 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
1659 x_excluded_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.excluded_tbl_type,
1660 --Added for Bug # 5573916
1661 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
1662 --Added for Bug # 5573916 Ends here
1663 )
1664 IS
1665
1666 -- For bug# 5261565. Checking only whether 'OKS' is installed or not.
1667 -- This is the product that should be minimum installed at the site
1668 -- to get back the resources from contract setup. Don't need to check
1669 -- 'OKC' and 'OKL'. Got it confirmed from Contract team as well.
1670
1671 CURSOR cur_contracts_installed IS
1672 SELECT application_id
1673 FROM fnd_application
1674 WHERE application_short_name = 'OKS'; -- IN ('OKC', 'OKL', 'OKS');
1675 l_cur_contracts_installed cur_contracts_installed%ROWTYPE;
1676
1677 l_return_status_1 VARCHAR2(10);
1678 l_api_name VARCHAR2(100) := 'GET_CONTRACTS_RESOURCES';
1679 l_api_name_1 VARCHAR2(60) := 'GET_CONTRACTS_RESOURCES';
1680 l_api_version NUMBER := 1.0;
1681 l_status VARCHAR2(30);
1682 l_industry VARCHAR2(30);
1683
1684 l_return_status VARCHAR2(10);
1685 l_msg_count NUMBER;
1686 l_msg_data VARCHAR2(2000);
1687
1688 l_engineer_id JTF_NUMBER_TABLE;
1689 l_resource_type JTF_VARCHAR2_TABLE_100;
1690 l_primary_flag JTF_VARCHAR2_TABLE_100;
1691 l_resource_class JTF_VARCHAR2_TABLE_100;
1692
1693 l_current_record INTEGER := 0;
1694 l_current_rec INTEGER := 0;
1695 l_pref_record INTEGER := 0;
1696
1697 l_travel_time NUMBER := 0;
1698 l_travel_uom VARCHAR2(10) := 'HR';
1699
1700 l_x_planned_start_date DATE;
1701 l_x_planned_end_date DATE;
1702 l_x_shift_construct_id NUMBER;
1703 l_x_availability_type VARCHAR2(60);
1704
1705 l_con_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
1706 l_preferred_engineers_tbl JTF_ASSIGN_PUB.Preferred_Engineers_tbl_type;
1707
1708 l_business_process_date DATE := p_business_process_date;
1709 l_excl_record NUMBER := 0;
1710
1711 BEGIN
1712
1713 x_return_status := fnd_api.g_ret_sts_success;
1714
1715 OPEN cur_contracts_installed;
1716 FETCH cur_contracts_installed INTO l_cur_contracts_installed;
1717 CLOSE cur_contracts_installed;
1718
1719 -- default the date to sysdate if it is null
1720 IF(p_business_process_id is not null and p_business_process_date is null)
1721 THEN
1722 l_business_process_date := sysdate;
1723 END IF;
1724
1725 IF (l_cur_contracts_installed.application_id IS NULL) THEN
1726 fnd_message.set_name('JTF', 'JTF_AM_CONTRACTS_NOT_INSTALLED');
1727 fnd_msg_pub.add;
1728 RAISE fnd_api.g_exc_error;
1729 ELSE
1730
1731 IF FND_INSTALLATION.GET
1732 (
1733 l_cur_contracts_installed.application_id,
1734 l_cur_contracts_installed.application_id,
1735 l_status,
1736 l_industry
1737 ) THEN
1738 IF ( UPPER(l_status) <> 'I' ) THEN
1739 fnd_message.set_name('JTF', 'JTF_AM_CONTRACTS_NOT_INSTALLED');
1740 fnd_msg_pub.add;
1741 RAISE fnd_api.g_exc_error;
1742 END IF;
1743 ELSE
1744 fnd_message.set_name('JTF', 'JTF_AM_CONTRACTS_NOT_INSTALLED');
1745 fnd_msg_pub.add;
1746 RAISE fnd_api.g_exc_error;
1747 END IF;
1748 END IF;
1749
1750 IF(x_excluded_tbl.count > 0)
1751 THEN
1752 l_excl_record := x_excluded_tbl.last + 1;
1753 ELSE
1754 l_excl_record := 0;
1755 END IF;
1756
1757
1758 IF (p_contract_id IS NOT NULL) THEN
1759
1760 /* Also at a later point of time add code to check
1761 for coverage start and end dates */
1762
1763 EXECUTE IMMEDIATE
1764 '
1765 DECLARE
1766
1767 l_con_preferred_engineers_tbl OKS_ENTITLEMENTS_PUB.prfeng_tbl_type;
1768 l_engineer_id JTF_NUMBER_TABLE;
1769 l_resource_type JTF_VARCHAR2_TABLE_100;
1770 l_primary_flag JTF_VARCHAR2_TABLE_100;
1771 l_resource_class JTF_VARCHAR2_TABLE_100;
1772 l_return_status VARCHAR2(10);
1773 l_msg_count NUMBER;
1774 l_msg_data VARCHAR2(2000);
1775
1776 l_ddindx BINARY_INTEGER;
1777 l_indx BINARY_INTEGER;
1778
1779 BEGIN
1780
1781 OKS_ENTITLEMENTS_PUB.Get_Preferred_Engineers
1782 (
1783 p_api_version => :1,
1784 p_init_msg_list => :2,
1785 p_contract_line_id => :3,
1786 p_business_process_id => :9,
1787 p_request_date => :10,
1788 x_return_status => l_return_status,
1789 x_msg_count => l_msg_count,
1790 x_msg_data => l_msg_data,
1791 x_prf_engineers => l_con_preferred_engineers_tbl
1792 );
1793
1794 :4 := l_msg_count;
1795 :5 := l_msg_data;
1796 :6 := l_return_status;
1797
1798
1799 IF NOT (l_return_status = fnd_api.g_ret_sts_success) THEN
1800 -- Unexpected Execution Error from call to Contracts API
1801 fnd_message.set_name('||''''||'JTF'||''''||','||''''||'JTF_AM_ERROR_CONTRACTS_API'||''''||');'||
1802 'fnd_msg_pub.add;
1803 IF (l_return_status = fnd_api.g_ret_sts_error) THEN
1804 RAISE fnd_api.g_exc_error;
1805 ELSE
1806 RAISE fnd_api.g_exc_unexpected_error;
1807 END IF;
1808 END IF;
1809
1810 /* Procedure for Copying out the TABLE contents
1811 INTO local variables to process */
1812
1813 IF l_con_preferred_engineers_tbl IS NULL OR
1814 l_con_preferred_engineers_tbl.count = 0 THEN
1815 l_engineer_id := JTF_NUMBER_TABLE();
1816 l_resource_type := JTF_VARCHAR2_TABLE_100();
1817 l_primary_flag := JTF_VARCHAR2_TABLE_100();
1818 l_resource_class := JTF_VARCHAR2_TABLE_100();
1819
1820 ELSE
1821 l_engineer_id := JTF_NUMBER_TABLE();
1822 l_resource_type := JTF_VARCHAR2_TABLE_100();
1823 l_primary_flag := JTF_VARCHAR2_TABLE_100();
1824 l_resource_class := JTF_VARCHAR2_TABLE_100();
1825
1826 IF l_con_preferred_engineers_tbl.count > 0 THEN
1827 l_engineer_id.extend(l_con_preferred_engineers_tbl.count);
1828 l_resource_type.extend(l_con_preferred_engineers_tbl.count);
1829 l_primary_flag.extend(l_con_preferred_engineers_tbl.count);
1830 l_resource_class.extend(l_con_preferred_engineers_tbl.count);
1831
1832 l_ddindx := l_con_preferred_engineers_tbl.first;
1833 l_indx := 1;
1834 WHILE true LOOP
1835 l_engineer_id(l_indx) := l_con_preferred_engineers_tbl(l_ddindx).engineer_id;
1836 l_resource_type(l_indx) := l_con_preferred_engineers_tbl(l_ddindx).resource_type;
1837 l_primary_flag(l_indx) := l_con_preferred_engineers_tbl(l_ddindx).primary_flag;
1838 l_resource_class(l_indx) := l_con_preferred_engineers_tbl(l_ddindx).resource_class;
1839
1840 l_indx := l_indx+1;
1841
1842 IF l_con_preferred_engineers_tbl.last = l_ddindx THEN
1843 exit;
1844 END IF;
1845
1846 l_ddindx := l_con_preferred_engineers_tbl.next(l_ddindx);
1847 END LOOP;
1848 END IF;
1849 END IF;
1850
1851 :7 := l_engineer_id;
1852 :8 := l_resource_type;
1853 :11 := l_primary_flag;
1854 :12 := l_resource_class;
1855
1856 END;
1857 '
1858 USING IN l_api_version,
1859 IN p_init_msg_list,
1860 IN p_contract_id,
1861 IN p_business_process_id,
1862 IN l_business_process_date,
1863 OUT l_msg_count,
1864 OUT l_msg_data,
1865 OUT l_return_status,
1866 OUT l_engineer_id,
1867 OUT l_resource_type,
1868 OUT l_primary_flag,
1869 OUT l_resource_class;
1870
1871 table_copy_in ( l_engineer_id,
1872 l_resource_type,
1873 l_primary_flag,
1874 l_resource_class,
1875 l_con_preferred_engineers_tbl
1876 );
1877
1878 x_return_status := l_return_status;
1879 x_msg_count := l_msg_count;
1880 x_msg_data := l_msg_data;
1881
1882 END IF; -- p_contract_id IS NOT NULL
1883
1884
1885 l_pref_record := 0;
1886 If(x_excluded_tbl.count > 0)
1887 THEN
1888 l_excl_record := x_excluded_tbl.last + 1;
1889 ELSE
1890 l_excl_record := 0;
1891 END IF;
1892
1893
1894 IF ( l_con_preferred_engineers_tbl.COUNT > 0 ) THEN
1895
1896 l_current_record := l_con_preferred_engineers_tbl.FIRST;
1897
1898 WHILE l_current_record <= l_con_preferred_engineers_tbl.LAST
1899 LOOP
1900 IF(l_con_preferred_engineers_tbl(l_current_record).resource_class in ('P', 'R'))
1901 THEN
1902 IF(
1903 ((p_resource_type = 'RS_INDIVIDUAL' OR p_resource_type is null)
1904 AND (l_con_preferred_engineers_tbl(l_current_record).resource_type in ('RS_EMPLOYEE',
1905 'RS_PARTY',
1906 'RS_PARTNER')))
1907 OR ((p_resource_type = 'RS_GROUP' OR p_resource_type is null)
1908 AND (l_con_preferred_engineers_tbl(l_current_record).resource_type = 'RS_GROUP'))
1909 OR ((p_resource_type = 'RS_TEAM' OR p_resource_type is null)
1910 AND (l_con_preferred_engineers_tbl(l_current_record).resource_type = 'RS_TEAM'))
1911 ) THEN
1912 l_pref_record := l_pref_record + 1;
1913 l_preferred_engineers_tbl(l_pref_record).engineer_id :=
1914 l_con_preferred_engineers_tbl(l_current_record).engineer_id;
1915 l_preferred_engineers_tbl(l_pref_record).resource_type :=
1916 l_con_preferred_engineers_tbl(l_current_record).resource_type;
1917 IF(( l_con_preferred_engineers_tbl(l_current_record).resource_class = 'P')
1918 or (l_con_preferred_engineers_tbl(l_current_record).primary_flag = 'Y'))
1919 THEN
1920 l_preferred_engineers_tbl(l_pref_record).primary_flag := 'Y';
1921 END IF;
1922 l_preferred_engineers_tbl(l_pref_record).preference_type := 'C';
1923
1924 END IF;
1925 -- keep the excluded resources in the excluded table
1926 ELSIF(l_con_preferred_engineers_tbl(l_current_record).resource_class = 'E')
1927 THEN
1928 x_excluded_tbl(l_excl_record).resource_id := l_con_preferred_engineers_tbl(l_current_record).engineer_id;
1929 x_excluded_tbl(l_excl_record).resource_type := l_con_preferred_engineers_tbl(l_current_record).resource_type;
1930 l_excl_record := l_excl_record + 1;
1931 END IF;
1932 l_current_record := l_con_preferred_engineers_tbl.NEXT(l_current_record);
1933 END LOOP;
1934 END IF;
1935
1936
1937 --l_current_rec := x_assign_resources_tbl.LAST + 1;
1938 IF(x_assign_resources_tbl.COUNT > 0)
1939 THEN
1940 l_current_rec := x_assign_resources_tbl.LAST + 1;
1941 ELSE
1942 l_current_rec := 0;
1943 END IF;
1944
1945
1946
1947 IF l_preferred_engineers_tbl.COUNT > 0 THEN
1948 l_current_record := l_preferred_engineers_tbl.FIRST;
1949 WHILE(l_current_record <= l_preferred_engineers_tbl.LAST)
1950 LOOP
1951 x_assign_resources_tbl(l_current_rec).terr_rsc_id := NULL;
1952 x_assign_resources_tbl(l_current_rec).resource_id :=
1953 l_preferred_engineers_tbl(l_current_record).engineer_id;
1954 x_assign_resources_tbl(l_current_rec).resource_type :=
1955 l_preferred_engineers_tbl(l_current_record).resource_type;
1956 x_assign_resources_tbl(l_current_rec).role := NULL;
1957 x_assign_resources_tbl(l_current_rec).start_date := NULL;
1958 x_assign_resources_tbl(l_current_rec).end_date := NULL;
1959 x_assign_resources_tbl(l_current_rec).shift_construct_id := NULL;
1960 x_assign_resources_tbl(l_current_rec).terr_id := NULL;
1961 x_assign_resources_tbl(l_current_rec).terr_name := NULL;
1962 x_assign_resources_tbl(l_current_rec).preference_type :=
1963 l_preferred_engineers_tbl(l_current_record).preference_type;
1964 x_assign_resources_tbl(l_current_rec).primary_flag :=
1965 l_preferred_engineers_tbl(l_current_record).primary_flag;
1966 x_assign_resources_tbl(l_current_rec).resource_source := 'CONTRACTS';
1967
1968 l_current_rec := l_current_rec + 1;
1969 l_current_record := l_preferred_engineers_tbl.NEXT(l_current_record);
1970 END LOOP;
1971
1972
1973 -- The calendar flag check will not be done any more. The first available slot will be fetched
1974 -- This is for the preformance bug 3301417. If the calendar flag is Y then the resources will
1975 -- filtered based on availability in the procedure get_available_slot. This change is being done on
1976 -- 16 June 2004
1977 -- IF (p_calendar_flag = 'Y') THEN
1978 -- change the API Name temporarily so that in case of unexpected error
1979 -- it is properly caught
1980 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
1981 l_return_status_1 := x_return_status ;
1982 -- call the api to check resource availability
1983 get_available_resources
1984 (
1985 p_init_msg_list => 'F',
1986 p_calendar_flag => p_calendar_flag,
1987 p_effort_duration => p_effort_duration,
1988 p_effort_uom => p_effort_uom,
1989 p_planned_start_date => p_planned_start_date,
1990 p_planned_end_date => p_planned_end_date,
1991 p_breakdown => null,
1992 p_breakdown_uom => null,
1993 p_continuous_task => jtf_assign_pub.g_continuous_work,
1994 x_return_status => x_return_status,
1995 x_msg_count => x_msg_count,
1996 x_msg_data => x_msg_data,
1997 x_assign_resources_tbl => x_assign_resources_tbl,
1998 --Added for Bug # 5573916
1999 p_calendar_check => p_calendar_check
2000 --Added for Bug # 5573916 Ends here
2001 );
2002
2003 -- set back the API name to original name
2004 l_api_name := l_api_name_1;
2005
2006 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
2007 -- Unexpected Execution Error from call to Get_contracts_resources
2008 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
2009 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
2010 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_CONTRACTS_RESOURCES');
2011 fnd_msg_pub.add;
2012 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
2013 RAISE fnd_api.g_exc_error;
2014 ELSE
2015 RAISE fnd_api.g_exc_unexpected_error;
2016 END IF;
2017 END IF; -- end of x_return_status check
2018 -- end if; -- if p_calendar_flag = Y
2019 end if; --l_preferred_engineers_tbl.COUNT > 0
2020
2021
2022 EXCEPTION
2023 WHEN FND_API.G_EXC_ERROR THEN
2024 x_return_status := FND_API.G_RET_STS_ERROR ;
2025 FND_MSG_PUB.Count_And_Get
2026 (
2027 p_count => x_msg_count,
2028 p_data => x_msg_data
2029 );
2030
2031 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2032 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2033 FND_MSG_PUB.Count_And_Get
2034 (
2035 p_count => x_msg_count,
2036 p_data => x_msg_data
2037 );
2038
2039 WHEN OTHERS THEN
2040 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
2041 fnd_message.set_token('P_SQLCODE',SQLCODE);
2042 fnd_message.set_token('P_SQLERRM',SQLERRM);
2043 fnd_message.set_token('P_API_NAME',l_api_name);
2044 FND_MSG_PUB.add;
2045
2046 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2047 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
2048 FND_MSG_PUB.Add_Exc_Msg
2049 (
2050 G_PKG_NAME,
2051 l_api_name
2052 );
2053 END IF;
2054
2055 FND_MSG_PUB.Count_And_Get
2056 (
2057 p_count => x_msg_count,
2058 p_data => x_msg_data
2059 );
2060
2061 END get_contracts_resources;
2062
2063
2064
2065
2066
2067 -- *******************************************************************************
2068
2069 -- Start of comments
2070
2071 -- Function : This procedure is to fetch the Install Base Preferred Resources.
2072 -- This passes out the table of records with the resources.
2073
2074 -- End of comments
2075
2076 -- *******************************************************************************
2077
2078
2079
2080 PROCEDURE get_ib_resources
2081 (
2082 p_init_msg_list IN VARCHAR2,
2083 p_customer_product_id IN NUMBER,
2084 p_calendar_flag IN VARCHAR2,
2085 p_effort_duration IN NUMBER,
2086 p_effort_uom IN VARCHAR2,
2087 p_planned_start_date IN DATE,
2088 p_planned_end_date IN DATE,
2089 p_resource_type IN VARCHAR2,
2090 x_return_status IN OUT NOCOPY VARCHAR2,
2091 x_msg_count IN OUT NOCOPY NUMBER,
2092 x_msg_data IN OUT NOCOPY VARCHAR2,
2093 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
2094 x_excluded_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.excluded_tbl_type,
2095 --Added for Bug # 5573916
2096 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
2097 --Added for Bug # 5573916 Ends here
2098 )
2099 IS
2100
2101 l_return_status_1 VARCHAR2(10);
2102 l_api_name VARCHAR2(100) := 'GET_IB_RESOURCES';
2103 l_api_name_1 VARCHAR2(60) := 'GET_IB_RESOURCES';
2104 l_api_version NUMBER := 1.0;
2105
2106 l_return_status VARCHAR2(10);
2107 l_msg_count NUMBER;
2108 l_msg_data VARCHAR2(2000);
2109
2110 l_engineer_id JTF_NUMBER_TABLE;
2111 l_resource_type JTF_VARCHAR2_TABLE_100;
2112
2113 l_current_record INTEGER := 0;
2114 l_current_rec INTEGER := 0;
2115 l_pref_record INTEGER := 0;
2116 l_excl_record INTEGER := 0;
2117
2118 l_travel_time NUMBER := 0;
2119 l_travel_uom VARCHAR2(10) := 'HR';
2120
2121 l_x_planned_start_date DATE;
2122 l_x_planned_end_date DATE;
2123 l_x_shift_construct_id NUMBER;
2124 l_x_availability_type VARCHAR2(60);
2125
2126 l_ib_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
2127 l_preferred_engineers_tbl JTF_ASSIGN_PUB.Preferred_Engineers_tbl_type;
2128
2129 TYPE DYNAMIC_CUR_TYP IS REF CURSOR;
2130 cur_csi_utility DYNAMIC_CUR_TYP;
2131 cur_cs_contacts DYNAMIC_CUR_TYP;
2132 l_dynamic_sql4 VARCHAR2(2000);
2133 l_dynamic_sql2 VARCHAR2(2000);
2134
2135 l_cs_contacts_cp VARCHAR2(5) := 'CP';
2136 l_cs_contacts_y VARCHAR2(2) := 'Y' ;
2137 l_cp_id NUMBER := p_customer_product_id;
2138 l_flag VARCHAR2(2) := 'Y' ;
2139 l_cs_contacts_rsc_id NUMBER;
2140 l_cs_contacts_rsc_cat VARCHAR2(60);
2141 l_primary VARCHAR2(2);
2142 l_preferred VARCHAR2(2);
2143
2144 CURSOR cur_ib_resources IS
2145 SELECT resource_id,
2146 'RS_'||category category
2147 FROM jtf_rs_resource_extns_vl
2148 WHERE source_id = l_cs_contacts_rsc_id
2149 AND category = l_cs_contacts_rsc_cat;
2150
2151 l_cur_ib_resources cur_ib_resources%ROWTYPE;
2152
2153
2154 CURSOR cur_ib_resources_grp IS
2155 SELECT group_id resource_id,
2156 'RS_GROUP'
2157 FROM jtf_rs_groups_b
2158 WHERE group_id = l_cs_contacts_rsc_id;
2159
2160
2161 CURSOR cur_ib_resources_team IS
2162 SELECT team_id resource_id,
2163 'RS_TEAM'
2164 FROM jtf_rs_teams_b
2165 WHERE team_id = l_cs_contacts_rsc_id;
2166
2167 CURSOR cur_ib_supp_resources IS
2168 SELECT resource_id,
2169 'RS_'||category category
2170 FROM jtf_rs_resource_extns_vl
2171 WHERE source_id = l_cs_contacts_rsc_id
2172 AND category = 'SUPPLIER_CONTACT';
2173
2174
2175 BEGIN
2176
2177 x_return_status := fnd_api.g_ret_sts_success;
2178
2179 l_pref_record := 0;
2180
2181 -- added by sudarsana on 30th nov 2001
2182 l_dynamic_sql4 := 'SELECT CSI_UTILITY_GRP.ib_active_flag() FROM DUAL';
2183
2184 BEGIN
2185 OPEN cur_csi_utility FOR l_dynamic_sql4;
2186 FETCH cur_csi_utility INTO l_flag;
2187 CLOSE cur_csi_utility;
2188
2189 EXCEPTION WHEN OTHERS THEN
2190 l_flag := 'N';
2191 END;
2192
2193
2194 -- IF CSI_UTILITY_GRP.ib_active_flag() = 'Y' THEN
2195
2196 IF (l_flag = 'Y') THEN
2197 l_dynamic_sql2 := 'SELECT PARTY_ID resource_id, PARTY_SOURCE_TABLE resource_category, primary_flag, preferred_flag'||
2198 ' FROM CSI_I_PARTIES'||
2199 ' WHERE INSTANCE_ID = :2'||
2200 -- ' AND PARTY_SOURCE_TABLE in ('''||'EMPLOYEE'||''''||','''||'HZ_PARTIES'||''''||','''||'GROUP'||''')'||
2201 --' AND PREFERRED_FLAG = :4' ;
2202 -- changed this line to get excluded resources
2203 ' AND PREFERRED_FLAG in('''||'Y'||''''||','''||'E'||''')'||
2204 ' AND sysdate <= nvl(active_end_date, sysdate)' ;
2205
2206 OPEN cur_cs_contacts FOR l_dynamic_sql2 USING --l_cs_contacts_cp,
2207 l_cp_id;
2208 --l_cs_contacts_emp,
2209 --l_cs_contacts_y;
2210 ELSE
2211
2212 l_dynamic_sql2 := ' SELECT resource_id, resource_category, primary_flag, preferred_flag '||
2213 ' FROM cs_contacts_v'||
2214 ' WHERE source_object_code = :1 AND '||
2215 ' source_object_id = :2 AND '||
2216 -- ' resource_category = :3 AND '||
2217 ' preferred_flag = :4';
2218
2219
2220 OPEN cur_cs_contacts FOR l_dynamic_sql2 USING l_cs_contacts_cp,
2221 l_cp_id,
2222 -- l_cs_contacts_emp,
2223 l_cs_contacts_y;
2224 END IF; -- end of CSI_UTILITY_GRP check
2225
2226
2227 LOOP
2228
2229 FETCH cur_cs_contacts INTO l_cs_contacts_rsc_id,
2230 l_cs_contacts_rsc_cat,
2231 l_primary,
2232 l_preferred;
2233 EXIT WHEN cur_cs_contacts%NOTFOUND;
2234 if(l_primary is null)
2235 then
2236 l_primary := 'N';
2237 end if;
2238
2239 -- IF cond for category added by sudarsana 30 nov 2001 to map to resource_manager
2240
2241 IF((l_cs_contacts_rsc_cat = 'HZ_PARTIES') AND
2242 (p_resource_type is null OR p_resource_type = 'RS_INDIVIDUAL')) THEN
2243
2244
2245 l_cs_contacts_rsc_cat := 'PARTY';
2246
2247 OPEN cur_ib_resources;
2248 LOOP
2249 FETCH cur_ib_resources INTO l_cur_ib_resources;
2250 EXIT WHEN cur_ib_resources%NOTFOUND;
2251
2252 l_ib_preferred_engineers_tbl(l_pref_record).engineer_id := l_cur_ib_resources.resource_id;
2253 l_ib_preferred_engineers_tbl(l_pref_record).resource_type := l_cur_ib_resources.category;
2254 l_ib_preferred_engineers_tbl(l_pref_record).primary_flag := l_primary;
2255 l_ib_preferred_engineers_tbl(l_pref_record).preferred_flag := l_preferred;
2256 l_pref_record := l_pref_record + 1;
2257 END LOOP;
2258 CLOSE cur_ib_resources;
2259
2260 l_cs_contacts_rsc_cat := 'PARTNER';
2261
2262 OPEN cur_ib_resources;
2263 LOOP
2264 FETCH cur_ib_resources INTO l_cur_ib_resources;
2265 EXIT WHEN cur_ib_resources%NOTFOUND;
2266
2267 l_ib_preferred_engineers_tbl(l_pref_record).engineer_id := l_cur_ib_resources.resource_id;
2268 l_ib_preferred_engineers_tbl(l_pref_record).resource_type := l_cur_ib_resources.category;
2269 l_ib_preferred_engineers_tbl(l_pref_record).primary_flag := l_primary;
2270 l_ib_preferred_engineers_tbl(l_pref_record).preferred_flag := l_preferred;
2271 l_pref_record := l_pref_record + 1;
2272 END LOOP;
2273 CLOSE cur_ib_resources;
2274
2275 ELSIF((l_cs_contacts_rsc_cat = 'PO_VENDORS') AND
2276 ( p_resource_type = 'RS_INDIVIDUAL' OR p_resource_type is null)) THEN
2277
2278 OPEN cur_ib_supp_resources;
2279 LOOP
2280 FETCH cur_ib_supp_resources INTO l_cur_ib_resources;
2281 EXIT WHEN cur_ib_supp_resources%NOTFOUND;
2282
2283 l_ib_preferred_engineers_tbl(l_pref_record).engineer_id := l_cur_ib_resources.resource_id;
2284 l_ib_preferred_engineers_tbl(l_pref_record).resource_type := l_cur_ib_resources.category;
2285 l_ib_preferred_engineers_tbl(l_pref_record).primary_flag := l_primary;
2286 l_ib_preferred_engineers_tbl(l_pref_record).preferred_flag := l_preferred;
2287 l_pref_record := l_pref_record + 1;
2288 END LOOP;
2289 CLOSE cur_ib_supp_resources;
2290 ELSIF((l_cs_contacts_rsc_cat = 'GROUP') AND
2291 ( p_resource_type = 'RS_GROUP' OR p_resource_type is null)) THEN
2292
2293 OPEN cur_ib_resources_grp;
2294 LOOP
2295 FETCH cur_ib_resources_grp INTO l_cur_ib_resources;
2296 EXIT WHEN cur_ib_resources_grp%NOTFOUND;
2297
2298 l_ib_preferred_engineers_tbl(l_pref_record).engineer_id := l_cur_ib_resources.resource_id;
2299 l_ib_preferred_engineers_tbl(l_pref_record).resource_type := l_cur_ib_resources.category;
2300 l_ib_preferred_engineers_tbl(l_pref_record).primary_flag := l_primary;
2301 l_ib_preferred_engineers_tbl(l_pref_record).preferred_flag := l_preferred;
2302 l_pref_record := l_pref_record + 1;
2303 END LOOP;
2304 CLOSE cur_ib_resources_grp;
2305
2306 ELSIF((l_cs_contacts_rsc_cat = 'TEAM') AND
2307 (p_resource_type = 'RS_TEAM' OR p_resource_type is null)) THEN
2308
2309 OPEN cur_ib_resources_team;
2310 LOOP
2311 FETCH cur_ib_resources_team INTO l_cur_ib_resources;
2312 EXIT WHEN cur_ib_resources_team%NOTFOUND;
2313
2314 l_ib_preferred_engineers_tbl(l_pref_record).engineer_id := l_cur_ib_resources.resource_id;
2315 l_ib_preferred_engineers_tbl(l_pref_record).resource_type := l_cur_ib_resources.category;
2316 l_ib_preferred_engineers_tbl(l_pref_record).primary_flag := l_primary;
2317 l_ib_preferred_engineers_tbl(l_pref_record).preferred_flag := l_preferred;
2318 l_pref_record := l_pref_record + 1;
2319 END LOOP;
2320 CLOSE cur_ib_resources_team;
2321
2322 ELSIF(p_resource_type = 'RS_INDIVIDUAL' OR p_resource_type is null) THEN
2323
2324 OPEN cur_ib_resources;
2325 LOOP
2326 FETCH cur_ib_resources INTO l_cur_ib_resources;
2327 EXIT WHEN cur_ib_resources%NOTFOUND;
2328
2329 l_ib_preferred_engineers_tbl(l_pref_record).engineer_id := l_cur_ib_resources.resource_id;
2330 l_ib_preferred_engineers_tbl(l_pref_record).resource_type := l_cur_ib_resources.category;
2331 l_ib_preferred_engineers_tbl(l_pref_record).primary_flag := l_primary;
2332 l_ib_preferred_engineers_tbl(l_pref_record).preferred_flag := l_preferred;
2333 l_pref_record := l_pref_record + 1;
2334 END LOOP;
2335 CLOSE cur_ib_resources;
2336 END IF;
2337 END LOOP;
2338 CLOSE cur_cs_contacts;
2339
2340
2341 IF ( l_ib_preferred_engineers_tbl.COUNT > 0 ) THEN
2342
2343 l_current_record := l_ib_preferred_engineers_tbl.FIRST;
2344 IF(x_excluded_tbl.count > 0)
2345 THEN
2346 l_excl_record := x_excluded_tbl.last + 1;
2347 ELSE
2348 l_excl_record := 0;
2349 END IF;
2350
2351 WHILE l_current_record <= l_ib_preferred_engineers_tbl.LAST
2352 LOOP
2353 IF(l_ib_preferred_engineers_tbl(l_current_record).preferred_flag = 'Y')
2354 THEN
2355 l_preferred_engineers_tbl(l_pref_record).engineer_id :=
2356 l_ib_preferred_engineers_tbl(l_current_record).engineer_id;
2357 l_preferred_engineers_tbl(l_pref_record).resource_type :=
2358 l_ib_preferred_engineers_tbl(l_current_record).resource_type;
2359 l_preferred_engineers_tbl(l_pref_record).preference_type := 'I';
2360 l_preferred_engineers_tbl(l_pref_record).primary_flag :=
2361 l_ib_preferred_engineers_tbl(l_current_record).primary_flag;
2362
2363 l_pref_record := l_pref_record + 1;
2364 ELSIF(l_ib_preferred_engineers_tbl(l_current_record).preferred_flag = 'E')
2365 THEN
2366 x_excluded_tbl(l_excl_record).resource_id :=
2367 l_ib_preferred_engineers_tbl(l_current_record).engineer_id;
2368 x_excluded_tbl(l_excl_record).resource_type :=
2369 l_ib_preferred_engineers_tbl(l_current_record).resource_type;
2370
2371
2372 l_excl_record := l_excl_record + 1;
2373
2374
2375 END IF; -- end of check for preferred_flag
2376 l_current_record := l_ib_preferred_engineers_tbl.NEXT(l_current_record);
2377 END LOOP;
2378 END IF;
2379
2380 IF(x_assign_resources_tbl.COUNT > 0)
2381 THEN
2382 l_current_rec := x_assign_resources_tbl.LAST + 1;
2383 ELSE
2384 l_current_rec := 0;
2385 END IF;
2386
2387
2388
2389
2390 IF l_preferred_engineers_tbl.COUNT > 0 THEN
2391 l_current_record := l_preferred_engineers_tbl.FIRST;
2392 WHILE(l_current_record <= l_preferred_engineers_tbl.LAST)
2393 LOOP
2394 x_assign_resources_tbl(l_current_rec).terr_rsc_id := NULL;
2395 x_assign_resources_tbl(l_current_rec).resource_id :=
2396 l_preferred_engineers_tbl(l_current_record).engineer_id;
2397 x_assign_resources_tbl(l_current_rec).resource_type :=
2398 l_preferred_engineers_tbl(l_current_record).resource_type;
2399 x_assign_resources_tbl(l_current_rec).role := NULL;
2400 x_assign_resources_tbl(l_current_rec).start_date := NULL;
2401 x_assign_resources_tbl(l_current_rec).end_date := NULL;
2402 x_assign_resources_tbl(l_current_rec).shift_construct_id := NULL;
2403 x_assign_resources_tbl(l_current_rec).terr_id := NULL;
2404 x_assign_resources_tbl(l_current_rec).terr_name := NULL;
2405 x_assign_resources_tbl(l_current_rec).preference_type :=
2406 l_preferred_engineers_tbl(l_current_record).preference_type;
2407 x_assign_resources_tbl(l_current_rec).primary_flag :=
2408 l_preferred_engineers_tbl(l_current_record).primary_flag;
2409 x_assign_resources_tbl(l_current_rec).resource_source := 'IB';
2410
2411 l_current_rec := l_current_rec + 1;
2412 l_current_record := l_preferred_engineers_tbl.NEXT(l_current_record);
2413 END LOOP;
2414
2415 -- The calendar flag check will not be done any more. The first available slot will be fetched
2416 -- This is for the preformance bug 3301417. If the calendar flag is Y then the resources will
2417 -- filtered based on availability in the procedure get_available_slot. This change is being done on
2418 -- 16 June 2004
2419 -- IF (p_calendar_flag = 'Y') THEN
2420 -- change the API Name temporarily so that in case of unexpected error
2421 -- it is properly caught
2422 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
2423 l_return_status_1 := x_return_status ;
2424 -- call the api to check resource availability
2425 get_available_resources
2426 (
2427 p_init_msg_list => 'F',
2428 p_calendar_flag => p_calendar_flag,
2429 p_effort_duration => p_effort_duration,
2430 p_effort_uom => p_effort_uom,
2431 p_planned_start_date => p_planned_start_date,
2432 p_planned_end_date => p_planned_end_date,
2433 p_continuous_task => jtf_assign_pub.g_continuous_work,
2434 p_breakdown => null,
2435 p_breakdown_uom => null,
2436 x_return_status => x_return_status,
2437 x_msg_count => x_msg_count,
2438 x_msg_data => x_msg_data,
2439 x_assign_resources_tbl => x_assign_resources_tbl,
2440 --Added for Bug # 5573916
2441 p_calendar_check => p_calendar_check
2442 --Added for Bug # 5573916 Ends here
2443 );
2444
2445 -- set back the API name to original name
2446 l_api_name := l_api_name_1;
2447
2448 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
2449 -- Unexpected Execution Error from call to Get_contracts_resources
2450 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
2451 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
2452 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_IB_RESOURCES');
2453 fnd_msg_pub.add;
2454 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
2455 RAISE fnd_api.g_exc_error;
2456 ELSE
2457 RAISE fnd_api.g_exc_unexpected_error;
2458 END IF;
2459 END IF; -- end of x_return_status check
2460 -- end if; -- end if p_calendar_flag
2461 end if; --l_preferred_engineers_tbl.COUNT > 0
2462
2463
2464 EXCEPTION
2465 WHEN FND_API.G_EXC_ERROR THEN
2466 x_return_status := FND_API.G_RET_STS_ERROR ;
2467 FND_MSG_PUB.Count_And_Get
2468 (
2469 p_count => x_msg_count,
2470 p_data => x_msg_data
2471 );
2472
2473 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2474 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2475 FND_MSG_PUB.Count_And_Get
2476 (
2477 p_count => x_msg_count,
2478 p_data => x_msg_data
2479 );
2480
2481 WHEN OTHERS THEN
2482 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
2483 fnd_message.set_token('P_SQLCODE',SQLCODE);
2484 fnd_message.set_token('P_SQLERRM',SQLERRM);
2485 fnd_message.set_token('P_API_NAME',l_api_name);
2486 FND_MSG_PUB.add;
2487
2488 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2489 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
2490 FND_MSG_PUB.Add_Exc_Msg
2491 (
2492 G_PKG_NAME,
2493 l_api_name
2494 );
2495 END IF;
2496
2497 FND_MSG_PUB.Count_And_Get
2498 (
2499 p_count => x_msg_count,
2500 p_data => x_msg_data
2501 );
2502
2503 END get_ib_resources;
2504
2505
2506 -- *******************************************************************************
2507
2508 -- Start of comments
2509
2510 -- API name : GET_ASSIGN_TASK_RESOURCES
2511 -- Type : Public
2512 -- Function : Determine the resources based on the customer
2513 -- preferences or territory preferences and the
2514 -- availability. This is when the calling doc is TASK.
2515 -- Pre-reqs : None
2516
2517 -- Parameters :
2518
2519 -- IN : p_api_version IN NUMBER Required
2520 -- p_init_msg_list IN VARCHAR2 Optional
2521 -- DEFAULT = FND_API.G_FALSE
2522 -- p_commit IN VARCHAR2 optional
2523 -- DEFAULT = FND_API.G_FALSE
2524
2525 -- Assignment Manager Specific Parameters
2526
2527 -- This determines the Resource Type required by the
2528 -- calling document
2529 -- p_resource_type VARCHAR2(30)
2530 -- p_role VARCHAR2(30)
2531
2532 -- This determines the number of resources required
2533 -- by the calling document
2534 -- p_no_of_resources NUMBER,
2535
2536 -- This is for sending out the qualified resource directly
2537 -- to the calling form. Defaulted to the PROFILE value
2538 -- p_auto_select_flag VARCHAR2(1)
2539 -- : value of Y or N
2540
2541 -- This is to set the preference of CONTRACTS PREFERRED ENGINEERS
2542 -- Defaulted to the PROFILE value
2543 -- p_contracts_preferred_engineer VARCHAR2(1)
2544 -- : value of Y or N
2545
2546 -- This is to set the preference of INSTALL BASE PREFERRED ENGINEERS
2547 -- Defaulted to the PROFILE value
2548 -- p_ib_preferred_engineer VARCHAR2(1)
2549 -- : value of Y or N
2550
2551 -- The Effort required is determined by these two parameters
2552 -- p_effort_duration NUMBER
2553 -- p_effort_uom VARCHAR2(10)
2554
2555 -- The Dates in which the resource is required, is determined
2556 -- by these two parameters
2557 -- p_start_date DATE
2558 -- p_end_date DATE
2559
2560 -- The Territory Manager is accessed based on the value set
2561 -- p_territory_flag VARCHAR2(1)
2562 -- : value of Y or N
2563
2564 -- The Resource Availability is checked based on the value set
2565 -- p_calendar_flag VARCHAR2(1)
2566 -- : value of Y or N
2567
2568
2569 -- This parameter contains the Calling Document ID
2570 -- In this case it is a TASK_ID.
2571 -- p_task_id NUMBER -- REQUIRED
2572
2573 -- This parameter contains list of qualifier columns from the
2574 -- UI which have been selected to re-query the resources.
2575 -- Strictly for the use of User Interface of Assignment Manager.
2576 -- p_column_list VARCHAR2
2577
2578 -- OUT : x_return_status OUT VARCHAR2(1)
2579 -- x_msg_count OUT NUMBER
2580 -- x_msg_data OUT VARCHAR2(2000)
2581 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
2582 -- AssignResources_tbl_type
2583
2584
2585 -- Version : Current version 1.0
2586 -- Initial version 1.0
2587 --
2588 -- Notes :
2589 --
2590
2591 -- End of comments
2592
2593 -- *********************************************************************************
2594
2595
2596
2597 /* Procedure Body with the parameters when the
2598 Source Document is TASK */
2599
2600
2601 PROCEDURE GET_ASSIGN_TASK_RESOURCES
2602 (
2603 p_api_version IN NUMBER,
2604 p_init_msg_list IN VARCHAR2,
2605 p_resource_type IN VARCHAR2,
2606 p_role IN VARCHAR2,
2607 p_no_of_resources IN NUMBER,
2608 p_auto_select_flag IN VARCHAR2,
2609 p_contracts_preferred_engineer IN VARCHAR2,
2610 p_ib_preferred_engineer IN VARCHAR2,
2611 p_effort_duration IN NUMBER,
2612 p_effort_uom IN VARCHAR2,
2613 p_start_date IN DATE,
2614 p_end_date IN DATE,
2615 p_territory_flag IN VARCHAR2,
2616 p_calendar_flag IN VARCHAR2,
2617 p_web_availability_flag IN VARCHAR2,
2618 p_task_id IN JTF_TASKS_VL.TASK_ID%TYPE,
2619 p_column_list IN VARCHAR2,
2620 p_business_process_id IN NUMBER,
2621 p_business_process_date IN DATE,
2622 p_filter_excluded_resource IN VARCHAR2,
2623 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
2624 x_return_status OUT NOCOPY VARCHAR2,
2625 x_msg_count OUT NOCOPY NUMBER,
2626 x_msg_data OUT NOCOPY VARCHAR2,
2627 --Added for Bug # 5573916
2628 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
2629 --Added for Bug # 5573916 Ends here
2630 )
2631 IS
2632
2633 l_return_status_1 VARCHAR2(10);
2634 l_api_name VARCHAR2(100) := 'GET_ASSIGN_TASK_RESOURCES';
2635 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_TASK_RESOURCES';
2636 l_api_version NUMBER := 1.0;
2637 l_planned_start_date DATE;
2638 l_planned_end_date DATE;
2639 l_effort_duration NUMBER;
2640 l_effort_uom VARCHAR2(30);
2641 l_task_id JTF_TASKS_VL.TASK_ID%TYPE := p_task_id;
2642 l_task_source_code JTF_TASKS_VL.SOURCE_OBJECT_TYPE_CODE%TYPE;
2643 l_task_source_id JTF_TASKS_VL.SOURCE_OBJECT_ID%TYPE;
2644 l_contract_id NUMBER;
2645 l_cp_id NUMBER;
2646 l_contract_flag VARCHAR2(1) := 'N';
2647
2648 l_travel_time NUMBER := 0;
2649 l_travel_uom VARCHAR2(10) := 'HR';
2650
2651 l_current_record INTEGER := 0;
2652 l_current_rec INTEGER := 0;
2653 l_pref_record INTEGER := 0;
2654
2655 l_assign_resources_rec JTF_TERRITORY_PUB.JTF_Task_Rec_Type;
2656 l_assign_resources_sr_rec JTF_TERRITORY_PUB.JTF_Srv_Task_rec_type;
2657 l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
2658
2659 l_engineer_id JTF_NUMBER_TABLE;
2660 l_resource_type JTF_VARCHAR2_TABLE_100;
2661
2662 l_return_status VARCHAR2(10);
2663 l_msg_count NUMBER;
2664 l_msg_data VARCHAR2(2000);
2665
2666 l_ib_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
2667 l_con_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
2668 l_preferred_engineers_tbl JTF_ASSIGN_PUB.Preferred_Engineers_tbl_type;
2669
2670 -- tables for excluded resource
2671 l_excluded_resource_tbl JTF_ASSIGN_PUB.excluded_tbl_type;
2672 l_contracts_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
2673 l_ib_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
2674
2675 l_status VARCHAR2(30);
2676 l_industry VARCHAR2(30);
2677
2678 l_x_planned_start_date DATE;
2679 l_x_planned_end_date DATE;
2680 l_x_shift_construct_id NUMBER;
2681 l_x_availability_type VARCHAR2(60);
2682
2683 l_column_list VARCHAR2(4000);
2684
2685 l_dynamic_sql VARCHAR2(2000);
2686 l_dynamic_sql1 VARCHAR2(2000);
2687 l_dynamic_sql2 VARCHAR2(2000);
2688 l_dynamic_sql3 VARCHAR2(2000);
2689
2690
2691 TYPE DYNAMIC_CUR_TYP IS REF CURSOR;
2692
2693 cur_task DYNAMIC_CUR_TYP;
2694 cur_srv_task DYNAMIC_CUR_TYP;
2695 cur_cs_incidents DYNAMIC_CUR_TYP;
2696 cur_cs_contacts DYNAMIC_CUR_TYP;
2697
2698
2699 CURSOR cur_task_id IS
2700 SELECT source_object_type_code,
2701 source_object_id,
2702 planned_start_date,
2703 planned_end_date,
2704 planned_effort,
2705 planned_effort_uom
2706 FROM jtf_tasks_vl
2707 WHERE task_id = l_task_id;
2708 l_cur_task_id cur_task_id%ROWTYPE;
2709
2710
2711 l_cs_contacts_cp VARCHAR2(5) := 'CP';
2712 l_cs_contacts_y VARCHAR2(2) := 'Y' ;
2713 l_cs_contacts_emp VARCHAR2(10) := 'EMPLOYEE';
2714 l_cs_contacts_rsc_id NUMBER;
2715 l_cs_contacts_rsc_cat VARCHAR2(60);
2716
2717
2718 CURSOR cur_ib_resources IS
2719 SELECT resource_id,
2720 'RS_'||category category
2721 FROM jtf_rs_resource_extns_vl
2722 WHERE source_id = l_cs_contacts_rsc_id AND
2723 category = l_cs_contacts_rsc_cat;
2724 l_cur_ib_resources cur_ib_resources%ROWTYPE;
2725
2726
2727 cur_support_site_name DYNAMIC_CUR_TYP;
2728
2729 l_support_site VARCHAR2(15) := 'SUPPORT_SITE';
2730 l_rsc_type VARCHAR2(30);
2731 l_rsc_id NUMBER;
2732
2733
2734 CURSOR cur_support_site_id (p_rsc_id NUMBER, p_rsc_type VARCHAR2) IS
2735 SELECT support_site_id
2736 FROM jtf_rs_resource_extns_vl
2737 WHERE resource_id = p_rsc_id AND
2738 category = p_rsc_type;
2739
2740
2741 CURSOR cur_web_availability (p_res_id NUMBER, p_res_type VARCHAR2) IS
2742 SELECT resource_id
2743 FROM jtf_rs_web_available_v
2744 WHERE resource_id = p_res_id AND
2745 category = p_res_type;
2746
2747
2748 BEGIN
2749
2750 SAVEPOINT get_assign_task_resources;
2751
2752 -- Started Assignment Manager API for TASKS
2753
2754
2755 /* Standard call to check for call compatibility */
2756
2757 IF NOT fnd_api.compatible_api_call (l_api_version,
2758 p_api_version,
2759 l_api_name,
2760 g_pkg_name) THEN
2761 RAISE fnd_api.g_exc_unexpected_error;
2762 END IF;
2763
2764
2765 /* Initialize message list if p_init_msg_list is set to TRUE */
2766
2767 IF fnd_api.to_boolean (p_init_msg_list) THEN
2768 fnd_msg_pub.initialize;
2769 END IF;
2770
2771 x_return_status := fnd_api.g_ret_sts_success;
2772
2773
2774
2775 /* Get TASK source and the related information for contracts and
2776 contracts primary and secondary engineers, if they exist */
2777
2778 If(l_task_id IS NOT NULL)
2779 -- this has been added as in form startup we now do a autoquery. So if no task id is passed instead of throwing the
2780 -- message that invalid id has been passed in we will just not do any processing
2781 THEN
2782 OPEN cur_task_id;
2783 FETCH cur_task_id INTO l_cur_task_id;
2784 IF ( cur_task_id%NOTFOUND ) THEN
2785 fnd_message.set_name('JTF', 'JTF_AM_INVALID_TASK_ID');
2786 fnd_msg_pub.add;
2787 RAISE fnd_api.g_exc_error;
2788 ELSE
2789 l_task_source_code := l_cur_task_id.source_object_type_code;
2790 l_task_source_id := l_cur_task_id.source_object_id;
2791 l_planned_start_date := l_cur_task_id.planned_start_date;
2792 l_planned_end_date := l_cur_task_id.planned_end_date;
2793 l_effort_duration := l_cur_task_id.planned_effort;
2794 l_effort_uom := l_cur_task_id.planned_effort_uom;
2795 END IF;
2796 CLOSE cur_task_id;
2797
2798
2799 IF (l_task_source_id IS NOT NULL AND
2800 l_task_source_code = 'SR') THEN
2801
2802 /*
2803 CURSOR cur_cs_incidents IS
2804 SELECT contract_service_id,
2805 customer_product_id,
2806 expected_resolution_date
2807 FROM cs_incidents_all_vl
2808 WHERE incident_id = l_task_source_id;
2809 */
2810
2811 l_dynamic_sql1 := ' SELECT contract_service_id, customer_product_id, expected_resolution_date'||
2812 ' FROM cs_incidents_all_vl'||
2813 ' WHERE incident_id = :1';
2814
2815 -- dbms_output.put_line('Select1 is : '||l_dynamic_sql1);
2816
2817 OPEN cur_cs_incidents FOR l_dynamic_sql1 USING l_task_source_id;
2818 FETCH cur_cs_incidents INTO l_contract_id,
2819 l_cp_id,
2820 l_planned_end_date;
2821
2822 IF ( cur_cs_incidents%NOTFOUND ) THEN
2823 fnd_message.set_name('JTF', 'JTF_AM_INVALID_SR_ID');
2824 fnd_msg_pub.add;
2825 RAISE fnd_api.g_exc_error;
2826 ELSE
2827 l_contract_flag := 'Y';
2828 l_planned_start_date := SYSDATE;
2829 END IF;
2830
2831 CLOSE cur_cs_incidents;
2832 END IF;
2833
2834 /* Defaulting the variable values to IN parameters,
2835 if the IN paramaters have values given */
2836
2837 IF (p_start_date IS NOT NULL) THEN
2838 l_planned_start_date := p_start_date;
2839 ELSE
2840 l_planned_start_date := SYSDATE;
2841 END IF;
2842
2843 IF (p_end_date IS NOT NULL) THEN
2844 l_planned_end_date := p_end_date;
2845 ELSE
2846 l_planned_end_date := SYSDATE + 14;
2847 END IF;
2848
2849 IF (p_effort_duration IS NOT NULL) THEN
2850 l_effort_duration := p_effort_duration;
2851 END IF;
2852
2853 IF (p_effort_uom IS NOT NULL) THEN
2854 l_effort_uom := p_effort_uom;
2855 END IF;
2856
2857 /* Check if the Contracts Preferred Engineers Profile is SET
2858 If it is SET then get the available preferred engineers
2859 into the table of records */
2860
2861 IF (p_contracts_preferred_engineer = 'Y') THEN
2862
2863 -- Process for the contracts preferred engineers
2864
2865 get_contracts_resources
2866 (
2867 p_init_msg_list => p_init_msg_list,
2868 p_contract_id => l_contract_id,
2869 p_calendar_flag => p_calendar_flag,
2870 p_effort_duration => l_effort_duration,
2871 p_effort_uom => l_effort_uom,
2872 p_planned_start_date => l_planned_start_date,
2873 p_planned_end_date => l_planned_end_date,
2874 p_resource_type => p_resource_type,
2875 p_business_process_id => p_business_process_id,
2876 p_business_process_date => p_business_process_date,
2877 x_return_status => x_return_status,
2878 x_msg_count => x_msg_count,
2879 x_msg_data => x_msg_data,
2880 x_assign_resources_tbl => l_contracts_tbl,
2881 x_excluded_tbl => l_excluded_resource_tbl,
2882 --Added for Bug # 5573916
2883 p_calendar_check => p_calendar_check
2884 --Added for Bug # 5573916 Ends here
2885 );
2886
2887 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
2888 -- Unexpected Execution Error from call to Get_contracts_resources
2889 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
2890 fnd_message.set_token('P_PROC_NAME','GET_CONTRACTS_RESOURCES');
2891 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_TASK_RESOURCES');
2892 fnd_msg_pub.add;
2893 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
2894 RAISE fnd_api.g_exc_error;
2895 ELSE
2896 RAISE fnd_api.g_exc_unexpected_error;
2897 END IF;
2898 END IF;
2899
2900 END IF; -- p_contracts_preferred_engineer = 'Y'
2901
2902 /* Check if the Installed Base Preferred Engineers Profile is SET
2903 If it is SET then get the available preferred engineers
2904 into the table of records */
2905
2906 IF (p_ib_preferred_engineer = 'Y') THEN
2907 -- Process for the Installed Base preferred engineers
2908 -- changed to ib code to call the common procedure and remove the old code - 4th april 2003
2909 get_ib_resources
2910 (
2911 p_init_msg_list => p_init_msg_list,
2912 p_customer_product_id => l_cp_id,
2913 p_calendar_flag => p_calendar_flag,
2914 p_effort_duration => l_effort_duration,
2915 p_effort_uom => l_effort_uom,
2916 p_planned_start_date => l_planned_start_date,
2917 p_planned_end_date => l_planned_end_date,
2918 p_resource_type => p_resource_type,
2919 x_return_status => x_return_status,
2920 x_msg_count => x_msg_count,
2921 x_msg_data => x_msg_data,
2922 x_assign_resources_tbl => l_ib_tbl,
2923 x_excluded_tbl => l_excluded_resource_tbl,
2924 --Added for Bug # 5573916
2925 p_calendar_check => p_calendar_check
2926 --Added for Bug # 5573916 Ends here
2927 );
2928
2929 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
2930 -- Unexpected Execution Error from call to Get_contracts_resources
2931 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
2932 fnd_message.set_token('P_PROC_NAME','GET_IB_RESOURCES');
2933 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_TASK_RESOURCES');
2934 fnd_msg_pub.add;
2935 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
2936 RAISE fnd_api.g_exc_error;
2937 ELSE
2938 RAISE fnd_api.g_exc_unexpected_error;
2939 END IF;
2940 END IF;
2941
2942 END IF; -- p_ib_preferred_engineer = 'Y'
2943
2944
2945 -- remove excluded resources
2946 IF(p_filter_excluded_resource = 'Y')
2947 THEN
2948 IF(p_contracts_preferred_engineer = 'Y')
2949 THEN
2950 remove_excluded(x_res_tbl => l_contracts_tbl,
2951 x_exc_res => l_excluded_resource_tbl);
2952 END IF;
2953 IF(p_ib_preferred_engineer = 'Y')
2954 THEN
2955 remove_excluded(x_res_tbl => l_ib_tbl,
2956 x_exc_res => l_excluded_resource_tbl);
2957 END IF;
2958 END IF;
2959
2960 -- after the preferred engineers are obtained from contracts/ib, select the resources
2961 -- that are to be returned
2962 /* Check if the Contracts Preferred Engineers Profile is SET If it is SET then get the available
2963 preferred engineers into the table of records */
2964 IF (p_contracts_preferred_engineer = 'Y') THEN
2965 table_copy(l_contracts_tbl, x_assign_resources_tbl);
2966 END IF; -- p_contracts_preferred_engineer = 'Y'
2967
2968 /* Check if the Installed Base Preferred Engineers Profile is SET
2969 If it is SET then get the available preferred engineers
2970 into the table of records */
2971 IF (p_ib_preferred_engineer = 'Y') THEN
2972 table_copy(l_ib_tbl, x_assign_resources_tbl);
2973 END IF; -- p_ib_preferred_engineer = 'Y'
2974
2975 /* Actual Flow of Assignment Manager */
2976
2977 /* Initialize the record number to add the records of
2978 Contracts or Installed Base Preferred Engineers to the table of records */
2979
2980 /* If this table has rows then there are preferred engineers existing */
2981
2982 IF x_assign_resources_tbl.COUNT > 0 THEN
2983 -- removed the processing here as the calendar check is already being done inside the
2984 -- common procedures calls
2985 null;
2986
2987 ELSE -- l_preferred_engineers_tbl.COUNT <= 0
2988
2989 -- If there are NO preferred engineers then call territory API
2990
2991 IF (l_task_source_code = 'SR') THEN
2992 fnd_message.set_name('JTF', 'JTF_AM_TASK_CREATED_BY_SR');
2993 fnd_msg_pub.add;
2994 RAISE fnd_api.g_exc_error;
2995
2996 /* Query the View which is a combination of Task and Service Request
2997 to get the data into the Record Type to pass it to the Territory API */
2998
2999
3000 IF (p_column_list IS NULL) THEN
3001 l_column_list := '*';
3002 ELSE
3003 l_column_list := p_column_list;
3004 END IF;
3005
3006 /*
3007 SELECT * INTO l_assign_resources_sr_rec
3008 FROM jtf_terr_srv_task_v -- (cs_sr_task_territory_v)
3009 WHERE task_id = l_task_id AND
3010 service_request_id = l_task_source_id;
3011 */
3012
3013 l_dynamic_sql := 'SELECT '||
3014 l_column_list||
3015 ' FROM cs_sr_task_territory_v'||
3016 ' WHERE task_id = :1 AND
3017 service_request_id = :2';
3018
3019 OPEN cur_srv_task FOR l_dynamic_sql USING l_task_id, l_task_source_id;
3020 FETCH cur_srv_task INTO l_assign_resources_sr_rec;
3021 -- EXIT WHEN cur_srv_task%NOTFOUND;
3022 CLOSE cur_srv_task;
3023
3024 IF (p_territory_flag = 'Y') THEN
3025
3026 -- change the API Name temporarily so that in case of unexpected error
3027 -- it is properly caught
3028 l_api_name := l_api_name||'-JTF_TERR_SERVICE_PUB';
3029
3030 JTF_TERR_SERVICE_PUB.Get_WinningTerrMembers
3031 (
3032 p_api_version_number => l_api_version,
3033 p_init_msg_list => p_init_msg_list,
3034 p_TerrSrvTask_Rec => l_assign_resources_sr_rec,
3035 p_Resource_Type => p_resource_type,
3036 p_Role => p_role,
3037 x_return_status => x_return_status,
3038 x_msg_count => x_msg_count,
3039 x_msg_data => x_msg_data,
3040 x_TerrResource_tbl => l_assign_resources_tbl
3041 );
3042
3043 -- set back the API name to original name
3044 l_api_name := l_api_name_1;
3045
3046 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
3047 -- Unexpected Execution Error from call to Territory Manager
3048 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
3049 fnd_msg_pub.add;
3050 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
3051 RAISE fnd_api.g_exc_error;
3052 ELSE
3053 RAISE fnd_api.g_exc_unexpected_error;
3054 END IF;
3055 END IF;
3056 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
3057 IF(l_assign_resources_tbl.COUNT > 0)
3058 THEN
3059 l_current_record := l_assign_resources_tbl.FIRST;
3060 WHILE l_current_record <= l_assign_resources_tbl.LAST
3061 LOOP
3062 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
3063 THEN
3064 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
3065 END IF;
3066 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
3067 END LOOP;
3068 END IF;
3069
3070 IF l_assign_resources_tbl.COUNT > 0 THEN
3071
3072 l_current_record := l_assign_resources_tbl.FIRST;
3073
3074 -- FOR i IN 1 .. l_assign_resources_tbl.COUNT
3075
3076 WHILE l_current_record <= l_assign_resources_tbl.LAST
3077 LOOP
3078 -- Check the calendar for resource availability
3079 -- Call Calendar API
3080 -- IF the resource is available then accept the values and
3081 -- finally check for the WORKFLOW profile option
3082
3083 -- removed the calendar check from here 26th September 2003. Calendar check will be done in a seperate
3084 -- procedure. The call is made after resources are copied to x_assign_resources_tbl
3085 x_assign_resources_tbl(l_current_record).terr_rsc_id :=
3086 l_assign_resources_tbl(l_current_record).terr_rsc_id;
3087 x_assign_resources_tbl(l_current_record).resource_id :=
3088 l_assign_resources_tbl(l_current_record).resource_id;
3089 x_assign_resources_tbl(l_current_record).resource_type :=
3090 l_assign_resources_tbl(l_current_record).resource_type;
3091 x_assign_resources_tbl(l_current_record).role :=
3092 l_assign_resources_tbl(l_current_record).role;
3093 x_assign_resources_tbl(l_current_record).start_date :=
3094 l_assign_resources_tbl(l_current_record).start_date;
3095 x_assign_resources_tbl(l_current_record).end_date :=
3096 l_assign_resources_tbl(l_current_record).end_date;
3097 x_assign_resources_tbl(l_current_record).shift_construct_id := NULL;
3098 x_assign_resources_tbl(l_current_record).terr_id :=
3099 l_assign_resources_tbl(l_current_record).terr_id;
3100 x_assign_resources_tbl(l_current_record).terr_name :=
3101 l_assign_resources_tbl(l_current_record).terr_name;
3102 -- ================code added for bug 6453896=============
3103 x_assign_resources_tbl(l_current_record).terr_rank :=
3104 l_assign_resources_tbl(l_current_record).ABSOLUTE_RANK;
3105 -- ================End for addition of code===============
3106 x_assign_resources_tbl(l_current_record).primary_contact_flag :=
3107 l_assign_resources_tbl(l_current_record).primary_contact_flag;
3108 x_assign_resources_tbl(l_current_record).primary_flag :=
3109 l_assign_resources_tbl(l_current_record).primary_contact_flag;
3110 x_assign_resources_tbl(l_current_record).resource_source := 'TERR';
3111 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
3112 END LOOP;
3113
3114 -- If resource availability is to be checked then the calendar api is called. This is done in s seperate
3115 -- procedure get_available_resources
3116 -- The calendar flag check will not be done any more. The first available slot will be fetched
3117 -- This is for the preformance bug 3301417. If the calendar flag is Y then the resources will
3118 -- filtered based on availability in the procedure get_available_slot. This change is being done on
3119 -- 16 June 2004
3120 -- IF (p_calendar_flag = 'Y') THEN
3121 -- change the API Name temporarily so that in case of unexpected error
3122 -- it is properly caught
3123 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
3124 l_return_status_1 := x_return_status ;
3125 -- call the api to check resource availability
3126 get_available_resources
3127 (
3128 p_init_msg_list => 'F',
3129 p_calendar_flag => p_calendar_flag,
3130 p_effort_duration => l_effort_duration,
3131 p_effort_uom => l_effort_uom,
3132 p_planned_start_date => l_planned_start_date,
3133 p_planned_end_date => l_planned_end_date,
3134 p_breakdown => null,
3135 p_breakdown_uom => null,
3136 p_continuous_task => jtf_assign_pub.g_continuous_work,
3137 x_return_status => x_return_status,
3138 x_msg_count => x_msg_count,
3139 x_msg_data => x_msg_data,
3140 x_assign_resources_tbl => x_assign_resources_tbl,
3141 --Added for Bug # 5573916
3142 p_calendar_check => p_calendar_check
3143 --Added for Bug # 5573916 Ends here
3144 );
3145
3146 -- set back the API name to original name
3147 l_api_name := l_api_name_1;
3148
3149 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
3150 -- Unexpected Execution Error from call to Get_contracts_resources
3151 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
3152 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
3153 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_TASK_RESOURCES');
3154 fnd_msg_pub.add;
3155 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
3156 RAISE fnd_api.g_exc_error;
3157 ELSE
3158 RAISE fnd_api.g_exc_unexpected_error;
3159 END IF;
3160 END IF; -- end of x_return_status check
3161 -- end if; -- if p_calendar_flag = Y
3162
3163 IF ( p_calendar_flag = 'Y' AND
3164 x_assign_resources_tbl.count = 0 ) THEN
3165 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
3166 fnd_msg_pub.add;
3167 -- RAISE fnd_api.g_exc_error;
3168 END IF;
3169
3170 -- remove excluded resources
3171 IF(p_filter_excluded_resource = 'Y')
3172 THEN
3173 remove_excluded(x_res_tbl => x_assign_resources_tbl,
3174 x_exc_res => l_excluded_resource_tbl);
3175 END IF;
3176
3177 ELSE -- No resources returned from the Territory API
3178 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
3179 fnd_msg_pub.add;
3180 -- RAISE fnd_api.g_exc_error;
3181 END IF;
3182
3183 ELSE -- Territory Flag is NO
3184 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
3185 fnd_msg_pub.add;
3186 -- RAISE fnd_api.g_exc_error;
3187 END IF;
3188
3189 ELSE -- l_task_source_code <> 'SR'
3190
3191 /* If Source Code is NOT a SERVICE REQUEST
3192 Query the Task View to get the data into the Record Type
3193 to pass it to the Territory API */
3194
3195 IF (p_column_list IS NULL) THEN
3196 l_column_list := '*';
3197 ELSE
3198 l_column_list := p_column_list;
3199 END IF;
3200
3201 l_dynamic_sql := 'SELECT '||
3202 l_column_list||
3203 ' FROM jtf_task_territory_v'||
3204 ' WHERE task_id = :1 AND rownum < 2';
3205
3206 OPEN cur_task FOR l_dynamic_sql USING l_task_id;
3207 FETCH cur_task INTO l_assign_resources_rec.TASK_ID,
3208 l_assign_resources_rec.PARTY_ID,
3209 l_assign_resources_rec.COUNTRY,
3210 l_assign_resources_rec.PARTY_SITE_ID,
3211 l_assign_resources_rec.CITY,
3212 l_assign_resources_rec.POSTAL_CODE,
3213 l_assign_resources_rec.STATE,
3214 l_assign_resources_rec.AREA_CODE,
3215 l_assign_resources_rec.COUNTY,
3216 l_assign_resources_rec.COMP_NAME_RANGE,
3217 l_assign_resources_rec.PROVINCE,
3218 l_assign_resources_rec.NUM_OF_EMPLOYEES,
3219 l_assign_resources_rec.TASK_TYPE_ID,
3220 l_assign_resources_rec.TASK_STATUS_ID,
3221 l_assign_resources_rec.TASK_PRIORITY_ID,
3222 l_assign_resources_rec.ATTRIBUTE1,
3223 l_assign_resources_rec.ATTRIBUTE2,
3224 l_assign_resources_rec.ATTRIBUTE3,
3225 l_assign_resources_rec.ATTRIBUTE4,
3226 l_assign_resources_rec.ATTRIBUTE5,
3227 l_assign_resources_rec.ATTRIBUTE6,
3228 l_assign_resources_rec.ATTRIBUTE7,
3229 l_assign_resources_rec.ATTRIBUTE8,
3230 l_assign_resources_rec.ATTRIBUTE9,
3231 l_assign_resources_rec.ATTRIBUTE10,
3232 l_assign_resources_rec.ATTRIBUTE11,
3233 l_assign_resources_rec.ATTRIBUTE12,
3234 l_assign_resources_rec.ATTRIBUTE13,
3235 l_assign_resources_rec.ATTRIBUTE14,
3236 l_assign_resources_rec.ATTRIBUTE15;
3237 -- EXIT WHEN cur_task%NOTFOUND;
3238 CLOSE cur_task;
3239
3240 IF (p_territory_flag = 'Y') THEN
3241
3242 -- change the API Name temporarily so that in case of unexpected error
3243 -- it is properly caught
3244 l_api_name := l_api_name||'-JTF_TERR_TASK_PUB';
3245
3246 JTF_TERR_TASK_PUB.Get_WinningTerrMembers
3247 (
3248 p_api_version_number => l_api_version,
3249 p_init_msg_list => p_init_msg_list,
3250 p_TerrTask_rec => l_assign_resources_rec,
3251 p_Resource_Type => p_resource_type,
3252 p_Role => p_role,
3253 x_return_status => x_return_status,
3254 x_msg_count => x_msg_count,
3255 x_msg_data => x_msg_data,
3256 x_TerrResource_tbl => l_assign_resources_tbl
3257 );
3258
3259 -- set back the API name to original name
3260 l_api_name := l_api_name_1;
3261
3262 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
3263 -- Unexpected Execution Error from call to Territory Manager for TASKS
3264 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
3265 fnd_msg_pub.add;
3266 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
3267 RAISE fnd_api.g_exc_error;
3268 ELSE
3269 RAISE fnd_api.g_exc_unexpected_error;
3270 END IF;
3271 END IF;
3272
3273
3274
3275 -- to handle RS_SUPPLIER returned from territories -- added on 2nd april2003 by sudarsana
3276
3277 IF(l_assign_resources_tbl.COUNT > 0)
3278 THEN
3279 l_current_record := l_assign_resources_tbl.FIRST;
3280 WHILE l_current_record <= l_assign_resources_tbl.LAST
3281 LOOP
3282 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
3283 THEN
3284 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
3285 END IF;
3286 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
3287 END LOOP;
3288 END IF;
3289
3290 -- removed the calendar check here. calling the procedure for calendar check in the next step
3291 -- calendar check removed 29th September 2003
3292
3293 IF l_assign_resources_tbl.COUNT > 0 THEN
3294
3295 l_current_rec := 0;
3296 l_current_record := l_assign_resources_tbl.FIRST;
3297
3298 WHILE l_current_record <= l_assign_resources_tbl.LAST
3299 LOOP
3300 x_assign_resources_tbl(l_current_record).terr_rsc_id :=
3301 l_assign_resources_tbl(l_current_record).terr_rsc_id;
3302 x_assign_resources_tbl(l_current_record).resource_id :=
3303 l_assign_resources_tbl(l_current_record).resource_id;
3304 x_assign_resources_tbl(l_current_record).resource_type :=
3305 l_assign_resources_tbl(l_current_record).resource_type;
3306 x_assign_resources_tbl(l_current_record).role :=
3307 l_assign_resources_tbl(l_current_record).role;
3308 x_assign_resources_tbl(l_current_record).start_date :=
3309 l_assign_resources_tbl(l_current_record).start_date;
3310 x_assign_resources_tbl(l_current_record).end_date :=
3311 l_assign_resources_tbl(l_current_record).end_date;
3312 x_assign_resources_tbl(l_current_record).shift_construct_id := NULL;
3313 x_assign_resources_tbl(l_current_record).terr_id :=
3314 l_assign_resources_tbl(l_current_record).terr_id;
3315 x_assign_resources_tbl(l_current_record).terr_name :=
3316 l_assign_resources_tbl(l_current_record).terr_name;
3317 -- ================code added for bug 6453896=============
3318 x_assign_resources_tbl(l_current_record).terr_rank :=
3319 l_assign_resources_tbl(l_current_record).ABSOLUTE_RANK;
3320 -- ================End for addition of code===============
3321 x_assign_resources_tbl(l_current_record).primary_contact_flag :=
3322 l_assign_resources_tbl(l_current_record).primary_contact_flag;
3323 x_assign_resources_tbl(l_current_record).primary_flag :=
3324 l_assign_resources_tbl(l_current_record).primary_contact_flag;
3325 x_assign_resources_tbl(l_current_record).resource_source := 'TERR';
3326
3327 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
3328 END LOOP;
3329
3330 -- added calendar call out
3331 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
3332 -- changed on 29th September 2003
3333 -- The calendar flag check will not be done any more. The first available slot will be fetched
3334 -- This is for the preformance bug 3301417. If the calendar flag is Y then the resources will
3335 -- filtered based on availability in the procedure get_available_slot. This change is being done on
3336 -- 16 June 2004
3337 --IF (p_calendar_flag = 'Y') THEN
3338 -- change the API Name temporarily so that in case of unexpected error
3339 -- it is properly caught
3340 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
3341 l_return_status_1 := x_return_status ;
3342 -- call the api to check resource availability
3343 get_available_resources
3344 (
3345 p_init_msg_list => 'F',
3346 p_calendar_flag => p_calendar_flag,
3347 p_effort_duration => l_effort_duration,
3348 p_effort_uom => l_effort_uom,
3349 p_planned_start_date => l_planned_start_date,
3350 p_planned_end_date => l_planned_end_date,
3351 p_breakdown => null,
3352 p_breakdown_uom => null,
3353 p_continuous_task => jtf_assign_pub.g_continuous_work,
3354 x_return_status => x_return_status,
3355 x_msg_count => x_msg_count,
3356 x_msg_data => x_msg_data,
3357 x_assign_resources_tbl => x_assign_resources_tbl,
3358 --Added for Bug # 5573916
3359 p_calendar_check => p_calendar_check
3360 --Added for Bug # 5573916 Ends here
3361 );
3362
3363 -- set back the API name to original name
3364 l_api_name := l_api_name_1;
3365
3366 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
3367 -- Unexpected Execution Error from call to Get_contracts_resources
3368 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
3369 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
3370 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_TASK_RESOURCES');
3371 fnd_msg_pub.add;
3372 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
3373 RAISE fnd_api.g_exc_error;
3374 ELSE
3375 RAISE fnd_api.g_exc_unexpected_error;
3376 END IF;
3377 END IF; -- end of x_return_status check
3378 -- end if; -- if p_calendar_flag = Y
3379
3380 IF ( p_calendar_flag = 'Y' AND
3381 x_assign_resources_tbl.count = 0 ) THEN
3382 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
3383 fnd_msg_pub.add;
3384 -- RAISE fnd_api.g_exc_error;
3385 END IF;
3386
3387 ELSE -- No resources returned from the Territory API
3388 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
3389 fnd_msg_pub.add;
3390 -- RAISE fnd_api.g_exc_error;
3391 END IF;
3392
3393 ELSE -- Territory Flag is NO
3394
3395 -- Since Territory Flag (along with Contracts and IB Flags) is unchecked
3396 -- removed code which fetches Resources even if Calendar Flag is checked.
3397 -- This was done as we don't want to fetch all resources blindly any time.
3398 -- Fix for Bug 3308883.
3399
3400 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
3401 fnd_msg_pub.add;
3402 END IF; -- End of Territory_Flag = 'Y'
3403
3404 END IF; -- End of l_task_source_code = 'SR'
3405
3406 END IF; -- End of l_preferred_engineers_tbl.COUNT > 0
3407
3408 -- Start of enhancement to add SUPPORT SITE ID and NAME to the OUT Table
3409
3410 l_dynamic_sql3 := ' SELECT a.city city '||
3411 ' FROM hz_locations a, hz_party_sites b, hz_party_site_uses c '||
3412 ' WHERE c.site_use_type = :1 AND '||
3413 ' b.party_site_id = :2 AND '||
3414 ' a.location_id = b.location_id AND '||
3415 ' c.party_site_id = b.party_site_id ';
3416
3417 IF x_assign_resources_tbl.COUNT > 0 THEN
3418
3419 l_current_record := x_assign_resources_tbl.FIRST;
3420
3421 WHILE l_current_record <= x_assign_resources_tbl.LAST
3422 LOOP
3423
3424 l_rsc_type := resource_type_change(x_assign_resources_tbl(l_current_record).resource_type);
3425
3426 OPEN cur_support_site_id (x_assign_resources_tbl(l_current_record).resource_id,
3427 l_rsc_type);
3428 FETCH cur_support_site_id INTO x_assign_resources_tbl(l_current_record).support_site_id;
3429
3430 IF (x_assign_resources_tbl(l_current_record).support_site_id IS NOT NULL) THEN
3431
3432 OPEN cur_support_site_name FOR l_dynamic_sql3
3433 USING l_support_site,
3434 x_assign_resources_tbl(l_current_record).support_site_id;
3435
3436 FETCH cur_support_site_name INTO x_assign_resources_tbl(l_current_record).support_site_name;
3437 IF ( cur_support_site_name % NOTFOUND ) THEN
3438 x_assign_resources_tbl(l_current_record).support_site_name := NULL;
3439 END IF;
3440 CLOSE cur_support_site_name;
3441 ELSE
3442 x_assign_resources_tbl(l_current_record).support_site_id := NULL;
3443 x_assign_resources_tbl(l_current_record).support_site_name := NULL;
3444
3445 END IF;
3446
3447 CLOSE cur_support_site_id;
3448
3449 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
3450 END LOOP;
3451 END IF;
3452
3453 -- End of enhancement
3454
3455
3456
3457
3458 -- Start of enhancement to add Web Availability to the OUT Table
3459
3460
3461 IF (x_assign_resources_tbl.COUNT > 0) THEN
3462
3463 l_current_record := x_assign_resources_tbl.FIRST;
3464
3465 WHILE l_current_record <= x_assign_resources_tbl.LAST
3466 LOOP
3467
3468 IF ( UPPER(p_web_availability_flag) = 'Y') THEN
3469 l_rsc_type := resource_type_change(x_assign_resources_tbl(l_current_record).resource_type);
3470
3471 OPEN cur_web_availability (x_assign_resources_tbl(l_current_record).resource_id,
3472 l_rsc_type);
3473 FETCH cur_web_availability INTO l_rsc_id;
3474
3475 IF (cur_web_availability%FOUND) THEN
3476 x_assign_resources_tbl(l_current_record).web_availability_flag := 'Y';
3477 ELSE
3478 x_assign_resources_tbl(l_current_record).web_availability_flag := 'N';
3479 END IF;
3480
3481 CLOSE cur_web_availability;
3482 ELSE
3483 x_assign_resources_tbl(l_current_record).web_availability_flag := NULL;
3484 END IF; --p_web_availability_flag = 'Y'
3485
3486 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
3487 END LOOP;
3488 END IF;
3489
3490 -- End of enhancement
3491
3492
3493 end if; -- End of l_task_id is not null
3494
3495
3496 /* Standard call to get message count and
3497 the message information */
3498
3499 FND_MSG_PUB.Count_And_Get
3500 (
3501 p_count => x_msg_count,
3502 p_data => x_msg_data
3503 );
3504
3505
3506
3507 EXCEPTION
3508 WHEN FND_API.G_EXC_ERROR THEN
3509 x_return_status := FND_API.G_RET_STS_ERROR ;
3510 FND_MSG_PUB.Count_And_Get
3511 (
3512 p_count => x_msg_count,
3513 p_data => x_msg_data
3514 );
3515
3516 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3517 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3518 FND_MSG_PUB.Count_And_Get
3519 (
3520 p_count => x_msg_count,
3521 p_data => x_msg_data
3522 );
3523
3524 WHEN OTHERS THEN
3525 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
3526 fnd_message.set_token('P_SQLCODE',SQLCODE);
3527 fnd_message.set_token('P_SQLERRM',SQLERRM);
3528 fnd_message.set_token('P_API_NAME',l_api_name);
3529 FND_MSG_PUB.add;
3530 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3531 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
3532 FND_MSG_PUB.Add_Exc_Msg
3533 (
3534 G_PKG_NAME,
3535 l_api_name
3536 );
3537 END IF;
3538
3539 FND_MSG_PUB.Count_And_Get
3540 (
3541 p_count => x_msg_count,
3542 p_data => x_msg_data
3543 );
3544
3545 END GET_ASSIGN_TASK_RESOURCES;
3546
3547
3548
3549 -- *******************************************************************************
3550
3551 -- Start of comments
3552
3553 -- API name : GET_ASSIGN_SR_RESOURCES
3554 -- Type : Public
3555 -- Function : Determine the resources based on the customer
3556 -- preferences or territory preferences and the
3557 -- availability. This is when the calling doc is
3558 -- SERVICE REQUEST.
3559 -- Pre-reqs : None
3560
3561 -- Parameters :
3562
3563 -- IN : p_api_version IN NUMBER Required
3564 -- p_init_msg_list IN VARCHAR2 Optional
3565 -- DEFAULT = FND_API.G_FALSE
3566 -- p_commit IN VARCHAR2 optional
3567 -- DEFAULT = FND_API.G_FALSE
3568
3569 -- Assignment Manager Specific Parameters
3570
3571 -- This determines the Resource Type required by the
3572 -- calling document
3573 -- p_resource_type VARCHAR2(30)
3574 -- p_role VARCHAR2(30)
3575
3576 -- This determines the number of resources required
3577 -- by the calling document
3578 -- p_no_of_resources NUMBER,
3579
3580 -- This is for sending out the qualified resource directly
3581 -- to the calling form. Defaulted to the PROFILE value
3582 -- p_auto_select_flag VARCHAR2(1)
3583 -- : value of Y or N
3584
3585 -- This is to set the preference of CONTRACTS PREFERRED ENGINEERS
3586 -- Defaulted to the PROFILE value
3587 -- p_contracts_preferred_engineer VARCHAR2(1)
3588 -- : value of Y or N
3589
3590 -- This is to set the preference of INSTALL BASE PREFERRED ENGINEERS
3591 -- Defaulted to the PROFILE value
3592 -- p_ib_preferred_engineer VARCHAR2(1)
3593 -- : value of Y or N
3594
3595 -- This is to fetch the CONTRACTS PREFERRED ENGINEERS
3596 -- p_contract_id NUMBER
3597
3598 -- This is to fetch the INSTALL BASE PREFERRED ENGINEERS
3599 -- p_customer_product_id NUMBER
3600
3601 -- The Effort required is determined by these two parameters
3602 -- p_effort_duration NUMBER
3603 -- p_effort_uom VARCHAR2(10)
3604
3605 -- The Dates in which the resource is required, is determined
3606 -- by these two parameters
3607 -- p_start_date DATE
3608 -- p_end_date DATE
3609
3610 -- The Territory Manager is accessed based on the value set
3611 -- p_territory_flag VARCHAR2(1)
3612 -- : value of Y or N
3613
3614 -- The Resource Availability is checked based on the value set
3615 -- p_calendar_flag VARCHAR2(1)
3616 -- : value of Y or N
3617
3618 -- This parameter contains the Calling Document ID
3619 -- In this case it is a SR_ID.
3620 -- p_sr_id NUMBER -- REQUIRED
3621
3622
3623 -- These parameters contain the Qualifier Values for
3624 -- the Calling Document
3625 -- p_sr_rec JTF_TERRITORY_PUB.
3626 -- JTF_Serv_Req_rec_type
3627 -- p_sr_task_rec JTF_TERRITORY_PUB.
3628 -- JTF_Srv_Task_rec_type
3629
3630
3631 -- OUT : x_return_status OUT VARCHAR2(1)
3632 -- x_msg_count OUT NUMBER
3633 -- x_msg_data OUT VARCHAR2(2000)
3634 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
3635 -- AssignResources_tbl_type
3636
3637
3638 -- Version : Current version 1.0
3639 -- Initial version 1.0
3640 --
3641 -- Notes :
3642 --
3643
3644 -- End of comments
3645
3646 -- *********************************************************************************
3647
3648
3649
3650 -- Procedure definition with the parameters when the
3651 -- Source Document is SERVICE REQUEST
3652
3653 PROCEDURE GET_ASSIGN_SR_RESOURCES
3654 (
3655 p_api_version IN NUMBER,
3656 p_init_msg_list IN VARCHAR2,
3657 p_resource_type IN VARCHAR2,
3658 p_role IN VARCHAR2,
3659 p_no_of_resources IN NUMBER,
3660 p_auto_select_flag IN VARCHAR2,
3661 p_contracts_preferred_engineer IN VARCHAR2,
3662 p_ib_preferred_engineer IN VARCHAR2,
3663 p_contract_id IN NUMBER,
3664 p_customer_product_id IN NUMBER,
3665 p_effort_duration IN NUMBER,
3666 p_effort_uom IN VARCHAR2,
3667 p_start_date IN DATE,
3668 p_end_date IN DATE,
3669 p_territory_flag IN VARCHAR2,
3670 p_calendar_flag IN VARCHAR2,
3671 p_web_availability_flag IN VARCHAR2,
3672 p_category_id IN NUMBER,
3673 p_inventory_item_id IN NUMBER,
3674 p_inventory_org_id IN NUMBER,
3675 p_problem_code IN VARCHAR2 ,
3676 p_sr_id IN NUMBER,
3677 p_sr_rec IN JTF_TERRITORY_PUB.JTF_Serv_Req_rec_type,
3678 p_sr_task_rec IN JTF_TERRITORY_PUB.JTF_Srv_Task_rec_type,
3679 p_business_process_id IN NUMBER,
3680 p_business_process_date IN DATE,
3681 p_filter_excluded_resource IN VARCHAR2,
3682 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
3683 x_return_status OUT NOCOPY VARCHAR2,
3684 x_msg_count OUT NOCOPY NUMBER,
3685 x_msg_data OUT NOCOPY VARCHAR2,
3686 --Added for Bug # 5386560
3687 p_inventory_component_id IN NUMBER DEFAULT NULL,
3688 --Added for Bug # 5386560 Ends here
3689 --Added for Bug # 5573916
3690 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
3691 --Added for Bug # 5573916 Ends here
3692 )
3693 IS
3694
3695 l_return_status_1 VARCHAR2(10);
3696 l_api_name VARCHAR2(100) := 'GET_ASSIGN_SR_RESOURCES';
3697 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_SR_RESOURCES';
3698
3699 l_api_version NUMBER := 1.0;
3700 l_sr_id NUMBER;
3701 l_p_resource_type VARCHAR2(30) := p_resource_type;
3702 l_planned_start_date DATE;
3703 l_planned_end_date DATE;
3704 l_expected_end_date DATE; -- Added by SBARAT on 10/12/2004 for Bug 4052202
3705 l_effort_duration NUMBER;
3706 l_effort_uom VARCHAR2(30);
3707 l_contract_id NUMBER;
3708 l_cp_id NUMBER;
3709 l_contract_flag VARCHAR2(1) := 'N';
3710 l_terr_cal_flag VARCHAR2(1) := 'N';
3711
3712 l_travel_time NUMBER := 0;
3713 l_travel_uom VARCHAR2(10) := 'HR';
3714
3715 l_current_record INTEGER;
3716 l_current_rec INTEGER := 0;
3717 l_pref_record INTEGER := 0;
3718
3719 l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
3720 l_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
3721
3722
3723 l_return_status VARCHAR2(10);
3724 l_msg_count NUMBER;
3725 l_msg_data VARCHAR2(2000);
3726
3727 l_pref_res_order VARCHAR2(20) := 'BOTH';
3728 l_ib_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
3729 l_con_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
3730 l_preferred_engineers_tbl JTF_ASSIGN_PUB.Preferred_Engineers_tbl_type;
3731
3732 -- tables to handle excluded resource feature
3733 l_excluded_resource_tbl JTF_ASSIGN_PUB.excluded_tbl_type;
3734 l_contracts_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
3735 l_ib_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
3736
3737
3738 l_x_planned_start_date DATE;
3739 l_x_planned_end_date DATE;
3740 l_x_shift_construct_id NUMBER;
3741 l_x_availability_type VARCHAR2(60);
3742
3743 l_dynamic_sql1 VARCHAR2(2000);
3744 l_dynamic_sql3 VARCHAR2(2000);
3745
3746 l_sr_comp_sub VARCHAR2(10); -- Added by SBARAT on 11/01/2005 for Enh 4112155
3747 l_sr_task_comp_sub VARCHAR2(10); -- Added by SBARAT on 11/01/2005 for Enh 4112155
3748
3749
3750 TYPE DYNAMIC_CUR_TYP IS REF CURSOR;
3751 cur_cs_incidents DYNAMIC_CUR_TYP;
3752 cur_support_site_name DYNAMIC_CUR_TYP;
3753
3754 l_support_site VARCHAR2(15) := 'SUPPORT_SITE';
3755 l_rsc_type VARCHAR2(30);
3756 l_rsc_id NUMBER;
3757
3758
3759 CURSOR cur_support_site_id (p_rsc_id NUMBER, p_rsc_type VARCHAR2) IS
3760 SELECT support_site_id
3761 FROM jtf_rs_resource_extns_vl
3762 WHERE resource_id = p_rsc_id AND
3763 category = p_rsc_type;
3764
3765
3766
3767 CURSOR cur_web_availability (p_res_id NUMBER, p_res_type VARCHAR2) IS
3768 SELECT resource_id
3769 FROM jtf_rs_web_available_v
3770 WHERE resource_id = p_res_id AND
3771 category = p_res_type;
3772
3773
3774
3775 CURSOR cur_resource_skills (p_res_id NUMBER) IS
3776 SELECT skill_level, level_name
3777 FROM jtf_rs_resource_skills a,
3778 jtf_rs_skill_levels_vl b
3779 WHERE a.skill_level_id = b.skill_level_id AND
3780 a.resource_id = p_res_id AND
3781 (category_id = p_category_id OR category_id IS NULL) AND
3782 product_id = p_inventory_item_id AND
3783 product_org_id = p_inventory_org_id AND
3784 component_id IS NULL AND
3785 subcomponent_id IS NULL;
3786
3787 l_skill_level NUMBER;
3788 l_skill_name VARCHAR2(60);
3789 l_skill_ret_sts VARCHAR2(1);
3790 l_skill_tbl JTF_AM_FILTER_RESOURCE_PVT.skill_param_tbl_type;
3791 l_group_filter VARCHAR2(100) := 'YES';
3792
3793 -- added record type for service security check
3794 l_sr_sec_rec JTF_AM_FILTER_RESOURCE_PVT.sr_rec_type;
3795
3796
3797 BEGIN
3798
3799 SAVEPOINT get_assign_sr_resources;
3800
3801 -- Started Assignment Manager API for SERVICE REQUESTS
3802
3803
3804 /* Standard call to check for call compatibility */
3805
3806 IF NOT fnd_api.compatible_api_call (l_api_version,
3807 p_api_version,
3808 l_api_name,
3809 g_pkg_name) THEN
3810 RAISE fnd_api.g_exc_unexpected_error;
3811 END IF;
3812
3813 /* Initialize message list if p_init_msg_list is set to TRUE */
3814
3815 IF fnd_api.to_boolean (p_init_msg_list) THEN
3816 fnd_msg_pub.initialize;
3817 END IF;
3818
3819
3820 x_return_status := fnd_api.g_ret_sts_success;
3821
3822
3823 IF ( UPPER(p_resource_type) = 'RS_INDIVIDUAL') THEN
3824 l_p_resource_type := 'RS_INDIVIDUAL';
3825 ELSIF(p_resource_type is null) THEN
3826 l_p_resource_type := null;
3827 ELSE
3828 l_p_resource_type := p_resource_type;
3829 END IF;
3830
3831
3832 IF (p_sr_id IS NOT NULL ) THEN
3833 l_sr_id := p_sr_id;
3834 ELSIF (p_sr_rec.service_request_id IS NOT NULL) THEN
3835 l_sr_id := p_sr_rec.service_request_id;
3836 ELSIF (p_sr_task_rec.service_request_id IS NOT NULL) THEN
3837 l_sr_id := p_sr_task_rec.service_request_id;
3838 END IF;
3839
3840 -- assign values to l_sr_sec_rec for SR Security Check
3841 l_sr_sec_rec.incident_id := l_sr_id;
3842 IF(p_sr_rec.incident_type_id is not null)
3843 THEN
3844 l_sr_sec_rec.incident_type_id := p_sr_rec.incident_type_id;
3845 ELSE
3846 l_sr_sec_rec.incident_type_id := p_sr_task_rec.incident_type_id;
3847 END IF;
3848
3849 /* Defaulting the variable values to IN parameters,
3850 if the IN paramaters have values given */
3851
3852 IF (p_start_date IS NOT NULL) THEN
3853 l_planned_start_date := p_start_date;
3854 ELSE
3855 l_planned_start_date := SYSDATE;
3856 END IF;
3857
3858 IF (p_end_date IS NOT NULL) THEN
3859 l_planned_end_date := p_end_date;
3860 ELSE
3861 l_planned_end_date := SYSDATE + 14;
3862 END IF;
3863
3864 IF (p_effort_duration IS NOT NULL) THEN
3865 l_effort_duration := p_effort_duration;
3866 END IF;
3867
3868 IF (p_effort_uom IS NOT NULL) THEN
3869 l_effort_uom := p_effort_uom;
3870 END IF;
3871
3872 -- Get the Profile value to determine the order of preferred resources
3873
3874 --l_pref_res_order := FND_PROFILE.VALUE_SPECIFIC ( 'JTF_AM_PREF_RES_ORDER' ); --Commented out by SBARAT on 12/10/2004, Bug-3830061
3875 l_pref_res_order := FND_PROFILE.VALUE ( 'JTF_AM_PREF_RES_ORDER' ); --Added by SBARAT on 12/10/2004, Bug-3830061
3876
3877
3878 IF ( p_contracts_preferred_engineer = 'Y' OR
3879 p_ib_preferred_engineer = 'Y') THEN
3880
3881
3882 l_contract_id := p_contract_id;
3883 l_cp_id := p_customer_product_id;
3884
3885
3886 -- Code to fetch the Preferred Resources for saved SR
3887 IF (l_contract_id IS NULL AND
3888 l_cp_id IS NULL AND
3889 l_sr_id IS NOT NULL) THEN
3890
3891 l_dynamic_sql1 := ' SELECT contract_service_id, customer_product_id, expected_resolution_date'||
3892 ' FROM cs_incidents_all_vl'||
3893 ' WHERE incident_id = :1';
3894
3895 OPEN cur_cs_incidents FOR l_dynamic_sql1 USING l_sr_id;
3896 FETCH cur_cs_incidents INTO l_contract_id,
3897 l_cp_id,
3898 l_expected_end_date; -- Added by SBARAT on 10/12/2004 for Bug 4052202
3899 --l_planned_end_date; -- Commented by SBARAT on 10/12/2004 for Bug 4052202
3900
3901 IF ( cur_cs_incidents%NOTFOUND ) THEN
3902 fnd_message.set_name('JTF', 'JTF_AM_INVALID_SR_ID');
3903 fnd_msg_pub.add;
3904 RAISE fnd_api.g_exc_error;
3905 /*
3906 ELSE
3907 l_contract_flag := 'Y';
3908 */
3909 END IF;
3910
3911 CLOSE cur_cs_incidents;
3912
3913 /**********Start of addition by SBARAT on 10/12/2004 for Bug 4052202**********/
3914
3915 IF ( l_expected_end_date IS NOT NULL) And (l_expected_end_date >= l_planned_start_date)
3916 THEN
3917
3918 l_planned_end_date := l_expected_end_date;
3919
3920 END IF;
3921
3922 /**********End of Addition by SBARAT on 10/12/2004 for Bug 4052202**********/
3923
3924 END IF; -- end of l_contract_id and l_cp_id null check
3925
3926 END IF;
3927
3928
3929
3930 -- initiliaze the table type variables
3931 l_excluded_resource_tbl.delete;
3932 l_contracts_tbl.delete;
3933 l_ib_tbl.delete;
3934
3935 -- get the contracts preferred and excluded engineers
3936 IF (p_contracts_preferred_engineer = 'Y') THEN
3937 get_contracts_resources
3938 (
3939 p_init_msg_list => p_init_msg_list,
3940 p_contract_id => l_contract_id,
3941 p_calendar_flag => p_calendar_flag,
3942 p_effort_duration => l_effort_duration,
3943 p_effort_uom => l_effort_uom,
3944 p_planned_start_date => l_planned_start_date,
3945 p_planned_end_date => l_planned_end_date,
3946 p_resource_type => l_p_resource_type,
3947 p_business_process_id => p_business_process_id,
3948 p_business_process_date => p_business_process_date,
3949 x_return_status => x_return_status,
3950 x_msg_count => x_msg_count,
3951 x_msg_data => x_msg_data,
3952 x_assign_resources_tbl => l_contracts_tbl,
3953 x_excluded_tbl => l_excluded_resource_tbl,
3954 --Added for Bug # 5573916
3955 p_calendar_check => p_calendar_check
3956 --Added for Bug # 5573916 Ends here
3957 );
3958
3959 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
3960 -- Unexpected Execution Error from call to Get_contracts_resources
3961 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
3962 fnd_message.set_token('P_PROC_NAME','GET_CONTRACTS_RESOURCES');
3963 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
3964 fnd_msg_pub.add;
3965 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
3966 RAISE fnd_api.g_exc_error;
3967 ELSE
3968 RAISE fnd_api.g_exc_unexpected_error;
3969 END IF;
3970 END IF;
3971 END IF;
3972
3973 -- get the ib preferred and excluded engineers
3974 IF (p_ib_preferred_engineer = 'Y') THEN
3975
3976 get_ib_resources
3977 (
3978 p_init_msg_list => p_init_msg_list,
3979 p_customer_product_id => l_cp_id,
3980 p_calendar_flag => p_calendar_flag,
3981 p_effort_duration => l_effort_duration,
3982 p_effort_uom => l_effort_uom,
3983 p_planned_start_date => l_planned_start_date,
3984 p_planned_end_date => l_planned_end_date,
3985 p_resource_type => l_p_resource_type,
3986 x_return_status => x_return_status,
3987 x_msg_count => x_msg_count,
3988 x_msg_data => x_msg_data,
3989 x_assign_resources_tbl => l_ib_tbl,
3990 x_excluded_tbl => l_excluded_resource_tbl,
3991 --Added for Bug # 5573916
3992 p_calendar_check => p_calendar_check
3993 --Added for Bug # 5573916 Ends here
3994 );
3995
3996 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
3997 -- Unexpected Execution Error from call to Get_contracts_resources
3998 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
3999 fnd_message.set_token('P_PROC_NAME','GET_IB_RESOURCES');
4000 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
4001 fnd_msg_pub.add;
4002 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4003 RAISE fnd_api.g_exc_error;
4004 ELSE
4005 RAISE fnd_api.g_exc_unexpected_error;
4006 END IF;
4007 END IF;
4008
4009 END IF; -- p_ib_preferred_engineer = 'Y'
4010
4011 -- remove excluded resources , added on 3rd July 2003
4012 IF(p_filter_excluded_resource = 'Y')
4013 THEN
4014 IF(p_contracts_preferred_engineer = 'Y')
4015 THEN
4016 remove_excluded(x_res_tbl => l_contracts_tbl,
4017 x_exc_res => l_excluded_resource_tbl);
4018 END IF;
4019 IF(p_ib_preferred_engineer = 'Y')
4020 THEN
4021 remove_excluded(x_res_tbl => l_ib_tbl,
4022 x_exc_res => l_excluded_resource_tbl);
4023 END IF;
4024 END IF;
4025
4026
4027 -- pass returned resources through security check
4028 IF(l_contracts_tbl.count > 0)
4029 THEN
4030 JTF_AM_FILTER_RESOURCE_PVT.SERVICE_SECURITY_CHECK
4031 ( p_api_version =>1.0,
4032 x_assign_resources_tbl =>l_contracts_tbl,
4033 p_sr_tbl =>l_sr_sec_rec,
4034 x_return_status =>x_return_status ,
4035 x_msg_count =>x_msg_count,
4036 x_msg_data =>x_msg_data);
4037
4038 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
4039 -- Unexpected Execution Error from call to Get_contracts_resources
4040 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
4041 fnd_message.set_token('P_PROC_NAME','SERVICE_SECURITY_CHECK');
4042 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
4043 fnd_msg_pub.add;
4044 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4045 RAISE fnd_api.g_exc_error;
4046 ELSE
4047 RAISE fnd_api.g_exc_unexpected_error;
4048 END IF;
4049 END IF;
4050
4051 end IF; -- end of security check for contracts resource
4052
4053 IF(l_ib_tbl.count > 0)
4054 THEN
4055 JTF_AM_FILTER_RESOURCE_PVT.SERVICE_SECURITY_CHECK
4056 ( p_api_version =>1.0,
4057 x_assign_resources_tbl =>l_ib_tbl,
4058 p_sr_tbl =>l_sr_sec_rec,
4059 x_return_status =>x_return_status ,
4060 x_msg_count =>x_msg_count,
4061 x_msg_data =>x_msg_data);
4062
4063 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
4064 -- Unexpected Execution Error from call to Get_contracts_resources
4065 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
4066 fnd_message.set_token('P_PROC_NAME','SERVICE_SECURITY_CHECK');
4067 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
4068 fnd_msg_pub.add;
4069 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4070 RAISE fnd_api.g_exc_error;
4071 ELSE
4072 RAISE fnd_api.g_exc_unexpected_error;
4073 END IF;
4074 END IF;
4075
4076 end IF; -- end of security check for contracts resource
4077
4078
4079
4080
4081
4082
4083 -- after the preferred engineers are obtained from contracts/ib, select the resources
4084 -- that are to be returned based on the value of the profile for search order and after
4085 -- filtering out excluded resources
4086 IF ( upper(l_pref_res_order) = 'CONTRACTS' )
4087 THEN
4088 IF (p_contracts_preferred_engineer = 'Y')
4089 THEN
4090 table_copy(l_contracts_tbl, x_assign_resources_tbl);
4091 END IF; -- p_contracts_preferred_engineer = 'Y'
4092
4093
4094 IF ( x_assign_resources_tbl.COUNT <= 0 )
4095 THEN
4096 IF (p_ib_preferred_engineer = 'Y')
4097 THEN
4098 table_copy(l_ib_tbl, x_assign_resources_tbl);
4099 END IF; -- p_ib_preferred_engineer = 'Y'
4100 END IF; -- x_assign_resources_tbl.COUNT <= 0
4101
4102 ELSIF ( upper(l_pref_res_order) = 'IB' )
4103 THEN
4104
4105 IF (p_ib_preferred_engineer = 'Y')
4106 THEN
4107 table_copy(l_ib_tbl, x_assign_resources_tbl);
4108 END IF; -- p_ib_preferred_engineer = 'Y'
4109
4110 IF ( x_assign_resources_tbl.COUNT <= 0 )
4111 THEN
4112 IF (p_contracts_preferred_engineer = 'Y')
4113 THEN
4114 table_copy(l_contracts_tbl, x_assign_resources_tbl);
4115 END IF; -- p_contracts_preferred_engineer = 'Y'
4116 END IF; -- x_assign_resources_tbl.COUNT <= 0
4117
4118 ELSE -- l_pref_res_order = 'BOTH'
4119 /* Check if the Contracts Preferred Engineers Profile is SET If it is SET then get the available
4120 preferred engineers into the table of records */
4121 IF (p_contracts_preferred_engineer = 'Y')
4122 THEN
4123 table_copy(l_contracts_tbl, x_assign_resources_tbl);
4124 END IF; -- p_contracts_preferred_engineer = 'Y'
4125
4126
4127 /* Check if the Installed Base Preferred Engineers Profile is SET
4128 If it is SET then get the available preferred engineers
4129 into the table of records */
4130 IF (p_ib_preferred_engineer = 'Y')
4131 THEN
4132 table_copy(l_ib_tbl, x_assign_resources_tbl);
4133 END IF; -- p_ib_preferred_engineer = 'Y'
4134
4135 END IF; -- l_pref_res_order = 'CONTRACTS' / 'IB' / 'BOTH'
4136
4137 /* Actual Flow of Assignment Manager */
4138 -- if the Contracts and IB Preferred Engineers are nor found then Territory Qualified Resources are fetched
4139 IF x_assign_resources_tbl.COUNT > 0
4140 THEN
4141 NULL;
4142 ELSE -- x_assign_resources_tbl.COUNT <= 0
4143 -- If there are NO preferred engineers then call territory API
4144
4145 /* Trace the Service Request Record Type
4146 to pass it to the Territory API */
4147
4148 /**************** Start of addition by SBARAT on 11/01/2005 for Enh 4112155**************/
4149
4150 JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type:=p_sr_rec;
4151 JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type:=p_sr_task_rec;
4152
4153 Terr_Qual_Dyn_Check(l_sr_comp_sub, l_sr_task_comp_sub);
4154
4155 JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type:=Null;
4156 JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type:=Null;
4157
4158 /**************** End of addition by SBARAT on 11/01/2005 for Enh 4112155**************/
4159
4160 IF
4161 (
4162 p_sr_rec.SERVICE_REQUEST_ID IS NOT NULL OR
4163 p_sr_rec.PARTY_ID IS NOT NULL OR
4164 p_sr_rec.COUNTRY IS NOT NULL OR
4165 p_sr_rec.PARTY_SITE_ID IS NOT NULL OR
4166 p_sr_rec.CITY IS NOT NULL OR
4167 p_sr_rec.POSTAL_CODE IS NOT NULL OR
4168 p_sr_rec.STATE IS NOT NULL OR
4169 p_sr_rec.AREA_CODE IS NOT NULL OR
4170 p_sr_rec.COUNTY IS NOT NULL OR
4171 p_sr_rec.COMP_NAME_RANGE IS NOT NULL OR
4172 p_sr_rec.PROVINCE IS NOT NULL OR
4173 p_sr_rec.NUM_OF_EMPLOYEES IS NOT NULL OR
4174 p_sr_rec.INCIDENT_TYPE_ID IS NOT NULL OR
4175 p_sr_rec.INCIDENT_SEVERITY_ID IS NOT NULL OR
4176 p_sr_rec.INCIDENT_URGENCY_ID IS NOT NULL OR
4177 p_sr_rec.PROBLEM_CODE IS NOT NULL OR
4178 p_sr_rec.INCIDENT_STATUS_ID IS NOT NULL OR
4179 p_sr_rec.PLATFORM_ID IS NOT NULL OR
4180 p_sr_rec.SUPPORT_SITE_ID IS NOT NULL OR
4181 p_sr_rec.CUSTOMER_SITE_ID IS NOT NULL OR
4182 p_sr_rec.SR_CREATION_CHANNEL IS NOT NULL OR
4183 p_sr_rec.INVENTORY_ITEM_ID IS NOT NULL OR
4184 p_sr_rec.ATTRIBUTE1 IS NOT NULL OR
4185 p_sr_rec.ATTRIBUTE2 IS NOT NULL OR
4186 p_sr_rec.ATTRIBUTE3 IS NOT NULL OR
4187 p_sr_rec.ATTRIBUTE4 IS NOT NULL OR
4188 p_sr_rec.ATTRIBUTE5 IS NOT NULL OR
4189 p_sr_rec.ATTRIBUTE6 IS NOT NULL OR
4190 p_sr_rec.ATTRIBUTE7 IS NOT NULL OR
4191 p_sr_rec.ATTRIBUTE8 IS NOT NULL OR
4192 p_sr_rec.ATTRIBUTE9 IS NOT NULL OR
4193 p_sr_rec.ATTRIBUTE10 IS NOT NULL OR
4194 p_sr_rec.ATTRIBUTE11 IS NOT NULL OR
4195 p_sr_rec.ATTRIBUTE12 IS NOT NULL OR
4196 p_sr_rec.ATTRIBUTE13 IS NOT NULL OR
4197 p_sr_rec.ATTRIBUTE14 IS NOT NULL OR
4198 p_sr_rec.ATTRIBUTE15 IS NOT NULL OR
4199 p_sr_rec.SQUAL_NUM12 IS NOT NULL OR
4200 p_sr_rec.SQUAL_NUM13 IS NOT NULL OR
4201 p_sr_rec.SQUAL_NUM14 IS NOT NULL OR
4202 p_sr_rec.SQUAL_NUM15 IS NOT NULL OR
4203 p_sr_rec.SQUAL_NUM16 IS NOT NULL OR
4204 p_sr_rec.SQUAL_NUM17 IS NOT NULL OR
4205 p_sr_rec.SQUAL_NUM18 IS NOT NULL OR
4206 p_sr_rec.SQUAL_NUM19 IS NOT NULL OR
4207 p_sr_rec.SQUAL_NUM30 IS NOT NULL OR
4208 p_sr_rec.SQUAL_CHAR11 IS NOT NULL OR
4209 p_sr_rec.SQUAL_CHAR12 IS NOT NULL OR
4210 p_sr_rec.SQUAL_CHAR13 IS NOT NULL OR
4211 p_sr_rec.SQUAL_CHAR20 IS NOT NULL OR
4212 p_sr_rec.SQUAL_CHAR21 IS NOT NULL OR
4213 l_sr_comp_sub IS NOT NULL -- Added by SBARAT on 11/01/2005 for Enh 4112155
4214
4215 ) THEN
4216
4217
4218 IF (p_territory_flag = 'Y') THEN
4219
4220 if(l_p_resource_type = 'RS_INDIVIDUAL')
4221 then
4222 l_p_resource_type := null;
4223 end if;
4224
4225 -- change the API Name temporarily so that in case of unexpected error
4226 -- it is properly caught
4227 l_api_name := l_api_name||'-JTF_TERR_SERVICE_PUB';
4228
4229 JTF_TERR_SERVICE_PUB.Get_WinningTerrMembers
4230 (
4231 p_api_version_number => l_api_version,
4232 p_init_msg_list => p_init_msg_list,
4233 p_TerrServReq_Rec => p_sr_rec,
4234 p_Resource_Type => l_p_resource_type,
4235 p_Role => p_role,
4236 x_return_status => x_return_status,
4237 x_msg_count => x_msg_count,
4238 x_msg_data => x_msg_data,
4239 x_TerrResource_tbl => l_assign_resources_tbl
4240 );
4241
4242 -- set back the API name to original name
4243 l_api_name := l_api_name_1;
4244
4245 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
4246 -- Unexpected Execution Error from call to Territory Manager
4247 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
4248 fnd_msg_pub.add;
4249 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4250 RAISE fnd_api.g_exc_error;
4251 ELSE
4252 RAISE fnd_api.g_exc_unexpected_error;
4253 END IF;
4254 END IF;
4255
4256 -- added 2 april 2003 by sudarsana to convert RS_SUPPLIER TO RS_SUPPLIER_CONTACT
4257 IF(l_assign_resources_tbl.COUNT > 0)
4258 THEN
4259 l_current_record := l_assign_resources_tbl.FIRST;
4260 WHILE l_current_record <= l_assign_resources_tbl.LAST
4261 LOOP
4262 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
4263 THEN
4264 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
4265 END IF;
4266 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
4267 END LOOP;
4268 END IF;
4269
4270 ELSE -- Territory Flag is NO
4271
4272 -- Since Territory Flag (along with Contracts and IB Flags) is unchecked
4273 -- removed code which fetches Resources even if Calendar Flag is checked.
4274 -- This was done as we don't want to fetch all resources blindly any time.
4275 -- Fix for Bug 3308883.
4276
4277 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
4278 fnd_msg_pub.add;
4279 END IF; -- End of p_territory_flag = 'Y'
4280
4281 ELSIF
4282 (
4283 p_sr_task_rec.TASK_ID IS NOT NULL OR
4284 p_sr_task_rec.SERVICE_REQUEST_ID IS NOT NULL OR
4285 p_sr_task_rec.PARTY_ID IS NOT NULL OR
4286 p_sr_task_rec.COUNTRY IS NOT NULL OR
4287 p_sr_task_rec.PARTY_SITE_ID IS NOT NULL OR
4288 p_sr_task_rec.CITY IS NOT NULL OR
4289 p_sr_task_rec.POSTAL_CODE IS NOT NULL OR
4290 p_sr_task_rec.STATE IS NOT NULL OR
4291 p_sr_task_rec.AREA_CODE IS NOT NULL OR
4292 p_sr_task_rec.COUNTY IS NOT NULL OR
4293 p_sr_task_rec.COMP_NAME_RANGE IS NOT NULL OR
4294 p_sr_task_rec.PROVINCE IS NOT NULL OR
4295 p_sr_task_rec.NUM_OF_EMPLOYEES IS NOT NULL OR
4296 p_sr_task_rec.TASK_TYPE_ID IS NOT NULL OR
4297 p_sr_task_rec.TASK_STATUS_ID IS NOT NULL OR
4298 p_sr_task_rec.TASK_PRIORITY_ID IS NOT NULL OR
4299 p_sr_task_rec.INCIDENT_TYPE_ID IS NOT NULL OR
4300 p_sr_task_rec.INCIDENT_SEVERITY_ID IS NOT NULL OR
4301 p_sr_task_rec.INCIDENT_URGENCY_ID IS NOT NULL OR
4302 p_sr_task_rec.PROBLEM_CODE IS NOT NULL OR
4303 p_sr_task_rec.INCIDENT_STATUS_ID IS NOT NULL OR
4304 p_sr_task_rec.PLATFORM_ID IS NOT NULL OR
4305 p_sr_task_rec.SUPPORT_SITE_ID IS NOT NULL OR
4306 p_sr_task_rec.CUSTOMER_SITE_ID IS NOT NULL OR
4307 p_sr_task_rec.SR_CREATION_CHANNEL IS NOT NULL OR
4308 p_sr_task_rec.INVENTORY_ITEM_ID IS NOT NULL OR
4309 p_sr_task_rec.ATTRIBUTE1 IS NOT NULL OR
4310 p_sr_task_rec.ATTRIBUTE2 IS NOT NULL OR
4311 p_sr_task_rec.ATTRIBUTE3 IS NOT NULL OR
4312 p_sr_task_rec.ATTRIBUTE4 IS NOT NULL OR
4313 p_sr_task_rec.ATTRIBUTE5 IS NOT NULL OR
4314 p_sr_task_rec.ATTRIBUTE6 IS NOT NULL OR
4315 p_sr_task_rec.ATTRIBUTE7 IS NOT NULL OR
4316 p_sr_task_rec.ATTRIBUTE8 IS NOT NULL OR
4317 p_sr_task_rec.ATTRIBUTE9 IS NOT NULL OR
4318 p_sr_task_rec.ATTRIBUTE10 IS NOT NULL OR
4319 p_sr_task_rec.ATTRIBUTE11 IS NOT NULL OR
4320 p_sr_task_rec.ATTRIBUTE12 IS NOT NULL OR
4321 p_sr_task_rec.ATTRIBUTE13 IS NOT NULL OR
4322 p_sr_task_rec.ATTRIBUTE14 IS NOT NULL OR
4323 p_sr_task_rec.ATTRIBUTE15 IS NOT NULL OR
4324 p_sr_task_rec.SQUAL_NUM12 IS NOT NULL OR
4325 p_sr_task_rec.SQUAL_NUM13 IS NOT NULL OR
4326 p_sr_task_rec.SQUAL_NUM14 IS NOT NULL OR
4327 p_sr_task_rec.SQUAL_NUM15 IS NOT NULL OR
4328 p_sr_task_rec.SQUAL_NUM16 IS NOT NULL OR
4329 p_sr_task_rec.SQUAL_NUM17 IS NOT NULL OR
4330 p_sr_task_rec.SQUAL_NUM18 IS NOT NULL OR
4331 p_sr_task_rec.SQUAL_NUM19 IS NOT NULL OR
4332 p_sr_task_rec.SQUAL_NUM30 IS NOT NULL OR
4333 p_sr_task_rec.SQUAL_CHAR11 IS NOT NULL OR
4334 p_sr_task_rec.SQUAL_CHAR12 IS NOT NULL OR
4335 p_sr_task_rec.SQUAL_CHAR13 IS NOT NULL OR
4336 p_sr_task_rec.SQUAL_CHAR20 IS NOT NULL OR
4337 p_sr_task_rec.SQUAL_CHAR21 IS NOT NULL OR
4338 l_sr_task_comp_sub IS NOT NULL -- Added by SBARAT on 11/01/2005 for Enh 4112155
4339
4340 ) THEN
4341
4342
4343 IF (p_territory_flag = 'Y') THEN
4344
4345 IF (l_p_resource_type = 'RS_INDIVIDUAL') THEN
4346 l_p_resource_type := NULL;
4347 END IF;
4348
4349 -- change the API Name temporarily so that in case of unexpected error
4350 -- it is properly caught
4351 l_api_name := l_api_name||'-JTF_TERR_SERVICE_PUB';
4352
4353 JTF_TERR_SERVICE_PUB.Get_WinningTerrMembers
4354 (
4355 p_api_version_number => l_api_version,
4356 p_init_msg_list => p_init_msg_list,
4357 p_TerrSrvTask_Rec => p_sr_task_rec,
4358 p_Resource_Type => l_p_resource_type,
4359 p_Role => p_role,
4360 x_return_status => x_return_status,
4361 x_msg_count => x_msg_count,
4362 x_msg_data => x_msg_data,
4363 x_TerrResource_tbl => l_assign_resources_tbl
4364 );
4365
4366 -- set back the API name to original name
4367 l_api_name := l_api_name_1;
4368
4369 -- dbms_output.put_line('Count of TM :: '||l_assign_resources_tbl.count);
4370
4371 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
4372 -- Unexpected Execution Error from call to Territory Manager
4373 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
4374 fnd_msg_pub.add;
4375 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4376 RAISE fnd_api.g_exc_error;
4377 ELSE
4378 RAISE fnd_api.g_exc_unexpected_error;
4379 END IF;
4380 END IF;
4381
4382 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
4383
4384 IF(l_assign_resources_tbl.COUNT > 0)
4385 THEN
4386 l_current_record := l_assign_resources_tbl.FIRST;
4387 WHILE l_current_record <= l_assign_resources_tbl.LAST
4388 LOOP
4389 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
4390 THEN
4391 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
4392 END IF;
4393 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
4394 END LOOP;
4395 END IF;
4396
4397 ELSE -- Territory Flag is NO
4398
4399 -- Since Territory Flag (along with Contracts and IB Flags) is unchecked
4400 -- removed code which fetches Resources even if Calendar Flag is checked.
4401 -- This was done as we don't want to fetch all resources blindly any time.
4402 -- Fix for Bug 3308883.
4403
4404 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
4405 fnd_msg_pub.add;
4406 END IF; -- End of p_territory_flag = 'Y'
4407
4408 END IF; -- End of p_sr_rec IS NOT NULL or p_sr_task_rec IS NOT NULL
4409
4410 -- removed the calendar check here. calling the procedure for calendar check in the next step
4411 -- calendar check removed 29th September 2003
4412 IF l_assign_resources_tbl.COUNT > 0 THEN
4413
4414 l_current_rec := 0;
4415 l_current_record := l_assign_resources_tbl.FIRST;
4416
4417 WHILE(l_current_record <= l_assign_resources_tbl.LAST)
4418 LOOP
4419 x_assign_resources_tbl(l_current_rec).terr_rsc_id :=
4420 l_assign_resources_tbl(l_current_record).terr_rsc_id;
4421 x_assign_resources_tbl(l_current_rec).resource_id :=
4422 l_assign_resources_tbl(l_current_record).resource_id;
4423 x_assign_resources_tbl(l_current_rec).resource_type :=
4424 l_assign_resources_tbl(l_current_record).resource_type;
4425 x_assign_resources_tbl(l_current_rec).role :=
4426 l_assign_resources_tbl(l_current_record).role;
4427 x_assign_resources_tbl(l_current_rec).start_date :=
4428 l_assign_resources_tbl(l_current_record).start_date;
4429 x_assign_resources_tbl(l_current_rec).end_date :=
4430 l_assign_resources_tbl(l_current_record).end_date;
4431 x_assign_resources_tbl(l_current_rec).shift_construct_id := NULL;
4432 x_assign_resources_tbl(l_current_rec).terr_id :=
4433 l_assign_resources_tbl(l_current_record).terr_id;
4434 x_assign_resources_tbl(l_current_rec).terr_name :=
4435 l_assign_resources_tbl(l_current_record).terr_name;
4436 -- ================code added for bug 6453896=============
4437 x_assign_resources_tbl(l_current_rec).terr_rank :=
4438 l_assign_resources_tbl(l_current_record).ABSOLUTE_RANK;
4439 -- ================End for addition of code===============
4440 x_assign_resources_tbl(l_current_rec).primary_contact_flag :=
4441 l_assign_resources_tbl(l_current_record).primary_contact_flag;
4442 x_assign_resources_tbl(l_current_rec).primary_flag :=
4443 l_assign_resources_tbl(l_current_record).primary_contact_flag;
4444 x_assign_resources_tbl(l_current_rec).resource_source := 'TERR';
4445
4446 l_current_rec := l_current_rec + 1;
4447 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
4448 END LOOP;
4449
4450
4451 -- added calendar call out
4452 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
4453 -- changed on 29th September 2003
4454 -- The calendar flag check will not be done any more. The first available slot will be fetched
4455 -- This is for the preformance bug 3301417. If the calendar flag is Y then the resources will
4456 -- filtered based on availability in the procedure get_available_slot. This change is being done on
4457 -- 16 June 2004
4458 --IF (p_calendar_flag = 'Y') THEN
4459 -- change the API Name temporarily so that in case of unexpected error
4460 -- it is properly caught
4461 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
4462 l_return_status_1 := x_return_status ;
4463 -- call the api to check resource availability
4464 get_available_resources
4465 (
4466 p_init_msg_list => 'F',
4467 p_calendar_flag => p_calendar_flag,
4468 p_effort_duration => l_effort_duration,
4469 p_effort_uom => l_effort_uom,
4470 p_planned_start_date => l_planned_start_date,
4471 p_planned_end_date => l_planned_end_date,
4472 p_breakdown => null,
4473 p_breakdown_uom => null,
4474 p_continuous_task => jtf_assign_pub.g_continuous_work,
4475 x_return_status => x_return_status,
4476 x_msg_count => x_msg_count,
4477 x_msg_data => x_msg_data,
4478 x_assign_resources_tbl => x_assign_resources_tbl,
4479 --Added for Bug # 5573916
4480 p_calendar_check => p_calendar_check
4481 --Added for Bug # 5573916 Ends here
4482 );
4483
4484 -- set back the API name to original name
4485 l_api_name := l_api_name_1;
4486
4487 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
4488 -- Unexpected Execution Error from call to Get_contracts_resources
4489 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
4490 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
4491 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
4492 fnd_msg_pub.add;
4493 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4494 RAISE fnd_api.g_exc_error;
4495 ELSE
4496 RAISE fnd_api.g_exc_unexpected_error;
4497 END IF;
4498 END IF; -- end of x_return_status check
4499 -- end if; -- if p_calendar_flag = Y
4500
4501
4502 IF ( p_calendar_flag = 'Y' AND
4503 x_assign_resources_tbl.count = 0 ) THEN
4504 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
4505 fnd_msg_pub.add;
4506 -- RAISE fnd_api.g_exc_error;
4507 END IF;
4508
4509
4510 -- remove excluded resources from territory qualifeid resource list
4511 -- added 4th July 2003
4512 IF(p_filter_excluded_resource = 'Y')
4513 THEN
4514 remove_excluded(x_res_tbl => x_assign_resources_tbl,
4515 x_exc_res => l_excluded_resource_tbl);
4516 END IF;
4517
4518
4519 IF(x_assign_resources_tbl.count > 0)
4520 THEN
4521 JTF_AM_FILTER_RESOURCE_PVT.SERVICE_SECURITY_CHECK
4522 ( p_api_version =>1.0,
4523 x_assign_resources_tbl =>x_assign_resources_tbl,
4524 p_sr_tbl =>l_sr_sec_rec,
4525 x_return_status =>x_return_status ,
4526 x_msg_count =>x_msg_count,
4527 x_msg_data =>x_msg_data);
4528
4529 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
4530 -- Unexpected Execution Error from call to Get_contracts_resources
4531 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
4532 fnd_message.set_token('P_PROC_NAME','SERVICE_SECURITY_CHECK');
4533 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
4534 fnd_msg_pub.add;
4535 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
4536 RAISE fnd_api.g_exc_error;
4537 ELSE
4538 RAISE fnd_api.g_exc_unexpected_error;
4539 END IF;
4540 END IF;
4541 END IF; -- end of security check
4542 ELSE -- No resources returned from the Territory API
4543
4544 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
4545 fnd_msg_pub.add;
4546 -- RAISE fnd_api.g_exc_error;
4547 END IF;
4548
4549
4550 -- Logic for getting resources belonging to group id passed in
4551 -- get the profile value to see if you have to filter by group membership
4552 -- to fix bug 2789319 on 3rd april 2003
4553 --l_group_filter := nvl(FND_PROFILE.VALUE_SPECIFIC ('JTF_AM_GROUP_MEMBER_FILTER'), 'YES'); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
4554 l_group_filter := nvl(FND_PROFILE.VALUE ('JTF_AM_GROUP_MEMBER_FILTER'), 'YES'); -- Added by SBARAT on 12/10/2004, Bug-3830061
4555
4556
4557 IF(l_group_filter = 'YES')
4558 THEN
4559 if((p_sr_rec.squal_num17 is not null) ) -- AND (p_resource_type = 'RS_INDIVIDUAL'))
4560 then
4561 get_group_resource(p_sr_rec.squal_num17 ,
4562 x_assign_resources_tbl );
4563 elsif((p_sr_task_rec.squal_num17 is not null) ) -- AND (p_resource_type = 'RS_INDIVIDUAL'))
4564 then
4565 get_group_resource(p_sr_task_rec.squal_num17 ,
4566 x_assign_resources_tbl );
4567 END IF;
4568
4569 end if;
4570
4571
4572 END IF; -- End of x_assign_resources_tbl.COUNT > 0
4573
4574
4575
4576
4577
4578 -- Start of enhancement for showing Individual Resources ONLY
4579
4580
4581 IF ( UPPER(p_resource_type) = 'RS_INDIVIDUAL' ) THEN
4582
4583
4584 -- Reconstructing the table to further do the enhancements
4585
4586 IF ( x_assign_resources_tbl.COUNT > 0 ) THEN
4587
4588 l_current_record := x_assign_resources_tbl.FIRST;
4589 l_current_rec := 1;
4590
4591 WHILE l_current_record <= x_assign_resources_tbl.LAST
4592 LOOP
4593
4594 l_tbl(l_current_rec).resource_id :=
4595 x_assign_resources_tbl(l_current_record).resource_id;
4596 l_tbl(l_current_rec).resource_type :=
4597 x_assign_resources_tbl(l_current_record).resource_type;
4598
4599 l_tbl(l_current_rec).start_date :=
4600 x_assign_resources_tbl(l_current_record).start_date;
4601 l_tbl(l_current_rec).end_date :=
4602 x_assign_resources_tbl(l_current_record).end_date;
4603 l_tbl(l_current_rec).shift_construct_id :=
4604 x_assign_resources_tbl(l_current_record).shift_construct_id;
4605
4606 l_tbl(l_current_rec).terr_rsc_id :=
4607 x_assign_resources_tbl(l_current_record).terr_rsc_id;
4608 l_tbl(l_current_rec).role :=
4609 x_assign_resources_tbl(l_current_record).role;
4610 l_tbl(l_current_rec).terr_id :=
4611 x_assign_resources_tbl(l_current_record).terr_id;
4612 l_tbl(l_current_rec).terr_name :=
4613 x_assign_resources_tbl(l_current_record).terr_name;
4614 -- ================code added for bug 6453896=============
4615 l_tbl(l_current_rec).terr_rank :=
4616 x_assign_resources_tbl(l_current_record).terr_rank;
4617 -- ================End for addition of code===============
4618 l_tbl(l_current_rec).primary_contact_flag :=
4619 x_assign_resources_tbl(l_current_record).primary_contact_flag;
4620 l_tbl(l_current_rec).preference_type :=
4621 x_assign_resources_tbl(l_current_record).preference_type;
4622 l_tbl(l_current_rec).group_id :=
4623 x_assign_resources_tbl(l_current_record).group_id;
4624
4625 l_tbl(l_current_rec).primary_flag :=
4626 x_assign_resources_tbl(l_current_record).primary_flag;
4627
4628 l_tbl(l_current_rec).resource_source :=
4629 x_assign_resources_tbl(l_current_record).resource_source;
4630
4631 l_current_rec := l_current_rec + 1;
4632 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
4633
4634 END LOOP;
4635
4636
4637
4638 END IF; --End of x_assign_resources_tbl.COUNT > 0
4639
4640 -- End of reconstruction
4641
4642
4643
4644
4645 IF ( l_tbl.COUNT > 0 ) THEN
4646
4647 l_current_record := l_tbl.FIRST;
4648 l_current_rec := 0;
4649
4650 -- Added by sroychou for rebuilding
4651 x_assign_resources_tbl.delete;
4652
4653 WHILE l_current_record <= l_tbl.LAST
4654 LOOP
4655 IF ( UPPER(l_tbl(l_current_record).resource_type) NOT IN ( 'RS_GROUP', 'RS_TEAM')) THEN
4656
4657 x_assign_resources_tbl(l_current_rec).resource_id :=
4658 l_tbl(l_current_record).resource_id;
4659 x_assign_resources_tbl(l_current_rec).resource_type :=
4660 l_tbl(l_current_record).resource_type;
4661
4662 x_assign_resources_tbl(l_current_rec).start_date :=
4663 l_tbl(l_current_record).start_date;
4664 x_assign_resources_tbl(l_current_rec).end_date :=
4665 l_tbl(l_current_record).end_date;
4666 x_assign_resources_tbl(l_current_rec).shift_construct_id :=
4667 l_tbl(l_current_record).shift_construct_id;
4668
4669 x_assign_resources_tbl(l_current_rec).terr_rsc_id :=
4670 l_tbl(l_current_record).terr_rsc_id;
4671 x_assign_resources_tbl(l_current_rec).role :=
4672 l_tbl(l_current_record).role;
4673 x_assign_resources_tbl(l_current_rec).terr_id :=
4674 l_tbl(l_current_record).terr_id;
4675 x_assign_resources_tbl(l_current_rec).terr_name :=
4676 l_tbl(l_current_record).terr_name;
4677 -- ================code added for bug 6453896=============
4678 x_assign_resources_tbl(l_current_rec).terr_rank :=
4679 l_tbl(l_current_record).terr_rank;
4680 -- ================End for addition of code===============
4681 x_assign_resources_tbl(l_current_rec).primary_contact_flag :=
4682 l_tbl(l_current_record).primary_contact_flag;
4683 x_assign_resources_tbl(l_current_rec).preference_type :=
4684 l_tbl(l_current_record).preference_type;
4685 x_assign_resources_tbl(l_current_rec).group_id :=
4686 l_tbl(l_current_record).group_id;
4687
4688 x_assign_resources_tbl(l_current_rec).primary_flag :=
4689 l_tbl(l_current_record).primary_flag;
4690
4691 x_assign_resources_tbl(l_current_rec).resource_source :=
4692 l_tbl(l_current_record).resource_source;
4693
4694 l_current_rec := l_current_rec + 1;
4695
4696 END IF;
4697 l_current_record := l_tbl.NEXT(l_current_record);
4698
4699 END LOOP;
4700
4701 END IF; --End of l_tbl.COUNT > 0
4702
4703 END IF; --End of p_resource_type = 'RS_INDIVIDUAL'
4704
4705 -- End of enhancement
4706
4707
4708
4709
4710 -- Start of enhancement to add SUPPORT SITE ID and NAME to the OUT Table
4711
4712 l_dynamic_sql3 := ' SELECT a.city city '||
4713 ' FROM hz_locations a, hz_party_sites b, hz_party_site_uses c '||
4714 ' WHERE c.site_use_type = :1 AND '||
4715 ' b.party_site_id = :2 AND '||
4716 ' a.location_id = b.location_id AND '||
4717 ' c.party_site_id = b.party_site_id ';
4718
4719 IF x_assign_resources_tbl.COUNT > 0 THEN
4720
4721 l_current_record := x_assign_resources_tbl.FIRST;
4722
4723 WHILE l_current_record <= x_assign_resources_tbl.LAST
4724 LOOP
4725
4726 l_rsc_type := resource_type_change(x_assign_resources_tbl(l_current_record).resource_type);
4727
4728 OPEN cur_support_site_id (x_assign_resources_tbl(l_current_record).resource_id,
4729 l_rsc_type);
4730 FETCH cur_support_site_id INTO x_assign_resources_tbl(l_current_record).support_site_id;
4731
4732 IF (x_assign_resources_tbl(l_current_record).support_site_id IS NOT NULL) THEN
4733
4734 OPEN cur_support_site_name FOR l_dynamic_sql3
4735 USING l_support_site,
4736 x_assign_resources_tbl(l_current_record).support_site_id;
4737
4738 FETCH cur_support_site_name INTO x_assign_resources_tbl(l_current_record).support_site_name;
4739 IF ( cur_support_site_name % NOTFOUND ) THEN
4740 x_assign_resources_tbl(l_current_record).support_site_name := NULL;
4741 END IF;
4742 CLOSE cur_support_site_name;
4743 ELSE
4744 x_assign_resources_tbl(l_current_record).support_site_id := NULL;
4745 x_assign_resources_tbl(l_current_record).support_site_name := NULL;
4746
4747 END IF;
4748
4749 CLOSE cur_support_site_id;
4750
4751 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
4752 END LOOP;
4753 END IF;
4754
4755 -- End of enhancement
4756
4757
4758
4759
4760 -- Start of enhancement to add Web Availability to the OUT Table
4761
4762
4763 IF (x_assign_resources_tbl.COUNT > 0) THEN
4764
4765 l_current_record := x_assign_resources_tbl.FIRST;
4766
4767 WHILE l_current_record <= x_assign_resources_tbl.LAST
4768 LOOP
4769
4770 IF ( UPPER(p_web_availability_flag) = 'Y') THEN
4771 l_rsc_type := resource_type_change(x_assign_resources_tbl(l_current_record).resource_type);
4772
4773 OPEN cur_web_availability (x_assign_resources_tbl(l_current_record).resource_id,
4774 l_rsc_type);
4775 FETCH cur_web_availability INTO l_rsc_id;
4776
4777 IF (cur_web_availability%FOUND) THEN
4778 x_assign_resources_tbl(l_current_record).web_availability_flag := 'Y';
4779 ELSE
4780 x_assign_resources_tbl(l_current_record).web_availability_flag := 'N';
4781 END IF;
4782
4783 CLOSE cur_web_availability;
4784 ELSE
4785 x_assign_resources_tbl(l_current_record).web_availability_flag := NULL;
4786 END IF; --p_web_availability_flag = 'Y'
4787
4788 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
4789 END LOOP;
4790 END IF;
4791
4792 -- End of enhancement
4793
4794
4795
4796 -- Start of enhancement for skill level using Product Code
4797
4798 /* IF ( p_category_id IS NOT NULL OR
4799 p_inventory_item_id IS NOT NULL OR
4800 p_inventory_org_id IS NOT NULL ) THEN
4801
4802
4803 IF ( x_assign_resources_tbl.COUNT > 0 ) THEN
4804
4805 l_current_record := x_assign_resources_tbl.FIRST;
4806
4807 WHILE l_current_record <= x_assign_resources_tbl.LAST
4808 LOOP
4809
4810 OPEN cur_resource_skills (x_assign_resources_tbl(l_current_record).resource_id);
4811 FETCH cur_resource_skills INTO l_skill_level, l_skill_name;
4812 IF ( cur_resource_skills%FOUND ) THEN
4813
4814 IF ( l_skill_level > 0 ) THEN
4815 x_assign_resources_tbl(l_current_record).skill_level := l_skill_level;
4816 x_assign_resources_tbl(l_current_record).skill_name := l_skill_name;
4817 ELSE
4818 x_assign_resources_tbl(l_current_record).skill_level := NULL;
4819 x_assign_resources_tbl(l_current_record).skill_name := NULL;
4820 END IF; -- End of l_skill_level > 0
4821
4822 END IF; -- End of cur_resource_skills%FOUND
4823 CLOSE cur_resource_skills;
4824
4825
4826 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
4827
4828 END LOOP;
4829
4830 END IF; --End of x_assign_resources_tbl.COUNT > 0
4831
4832 END IF; --End of p_category_id IS NOT NULL
4833 */
4834
4835
4836 -- skills bank filter call to api JTF_AM_FILTER_RESOURCE_PVT
4837
4838 -- initialize values of the skill table
4839 l_skill_tbl(1).document_type := 'SR';
4840 l_skill_tbl(1).category_id := p_category_id;
4841 l_skill_tbl(1).product_id := p_inventory_item_id;
4842 l_skill_tbl(1).product_org_id := p_inventory_org_id;
4843 --Added for Bug # 5386560
4844 l_skill_tbl(1).component_id := p_inventory_component_id;
4845 --Added for Bug # 5386560 Ends here
4846
4847 -- changed problem code value to be talken from parameter instead of territory qualifier
4848 -- done by sudarsana on 24th april 2003
4849 l_skill_tbl(1).problem_code := p_problem_code;
4850
4851 -- change the API Name temporarily so that in case of unexpected error
4852 -- it is properly caught
4853 l_api_name := l_api_name||'-JTF_AM_FILTER_RESOURCE_PVT';
4854 JTF_AM_FILTER_RESOURCE_PVT.SEARCH_SKILL
4855 ( p_api_version => 1.0,
4856 x_assign_resources_tbl => x_assign_resources_tbl,
4857 p_skill_param_tbl => l_skill_tbl,
4858 x_return_status => l_skill_ret_sts,
4859 x_msg_count => x_msg_count,
4860 x_msg_data => x_msg_data );
4861
4862 -- set back the API name to original name
4863 l_api_name := l_api_name_1;
4864 if(l_skill_ret_sts <> fnd_api.g_ret_sts_success)
4865 then
4866 IF (l_skill_ret_sts = fnd_api.g_ret_sts_error) THEN
4867 RAISE fnd_api.g_exc_error;
4868 ELSE
4869 RAISE fnd_api.g_exc_unexpected_error;
4870 END IF;
4871 end if;
4872
4873 -- End of enhancement
4874
4875
4876
4877
4878 /* Standard call to get message count and
4879 the message information */
4880
4881 FND_MSG_PUB.Count_And_Get
4882 (
4883 p_count => x_msg_count,
4884 p_data => x_msg_data
4885 );
4886
4887
4888
4889 EXCEPTION
4890 WHEN FND_API.G_EXC_ERROR THEN
4891 x_return_status := FND_API.G_RET_STS_ERROR ;
4892 FND_MSG_PUB.Count_And_Get
4893 (
4894 p_count => x_msg_count,
4895 p_data => x_msg_data
4896 );
4897
4898 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4899 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4900 FND_MSG_PUB.Count_And_Get
4901 (
4902 p_count => x_msg_count,
4903 p_data => x_msg_data
4904 );
4905
4906 WHEN OTHERS THEN
4907 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
4908 fnd_message.set_token('P_SQLCODE',SQLCODE);
4909 fnd_message.set_token('P_SQLERRM',SQLERRM);
4910 fnd_message.set_token('P_API_NAME',l_api_name);
4911 FND_MSG_PUB.add;
4912
4913 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4914 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
4915 FND_MSG_PUB.Add_Exc_Msg
4916 (
4917 G_PKG_NAME,
4918 l_api_name
4919 );
4920 END IF;
4921
4922 FND_MSG_PUB.Count_And_Get
4923 (
4924 p_count => x_msg_count,
4925 p_data => x_msg_data
4926 );
4927
4928 END GET_ASSIGN_SR_RESOURCES;
4929
4930
4931 /************** Addition by SBARAT on 01/11/2004 for Enh-3919046 ***********/
4932
4933 -- *******************************************************************************
4934
4935 -- Start of comments
4936
4937 -- API name : GET_ASSIGN_DR_RESOURCES
4938 -- Type : Public
4939 -- Function : Determine the resources based on the customer
4940 -- preferences or territory preferences and the
4941 -- availability. This is when the calling doc is
4942 -- DEPOT REPAIR.
4943 -- Pre-reqs : None
4944
4945 -- Parameters :
4946
4947 -- IN : p_api_version IN NUMBER Required
4948 -- p_init_msg_list IN VARCHAR2 Optional
4949 -- DEFAULT = FND_API.G_FALSE
4950
4951 -- Assignment Manager Specific Parameters
4952
4953 -- This determines the Resource Type required by the
4954 -- calling document
4955 -- p_resource_type VARCHAR2(30)
4956 -- p_role VARCHAR2(30)
4957
4958 -- This determines the number of resources required
4959 -- by the calling document
4960 -- p_no_of_resources NUMBER,
4961
4962 -- This is for sending out the qualified resource directly
4963 -- to the calling form. Defaulted to the PROFILE value
4964 -- p_auto_select_flag VARCHAR2(1)
4965 -- : value of Y or N
4966
4967 -- This is to set the preference of CONTRACTS PREFERRED ENGINEERS
4968 -- Defaulted to the PROFILE value
4969 -- p_contracts_preferred_engineer VARCHAR2(1)
4970 -- : value of Y or N
4971
4972 -- This is to set the preference of INSTALL BASE PREFERRED ENGINEERS
4973 -- Defaulted to the PROFILE value
4974 -- p_ib_preferred_engineer VARCHAR2(1)
4975 -- : value of Y or N
4976
4977 -- This is to fetch the CONTRACTS PREFERRED ENGINEERS
4978 -- p_contract_id NUMBER
4979
4980 -- This is to fetch the INSTALL BASE PREFERRED ENGINEERS
4981 -- p_customer_product_id NUMBER
4982
4983 -- The Effort required is determined by these two parameters
4984 -- p_effort_duration NUMBER
4985 -- p_effort_uom VARCHAR2(10)
4986
4987 -- The Dates in which the resource is required, is determined
4988 -- by these two parameters
4989 -- p_start_date DATE
4990 -- p_end_date DATE
4991
4992 -- The Territory Manager is accessed based on the value set
4993 -- p_territory_flag VARCHAR2(1)
4994 -- : value of Y or N
4995
4996 -- The Resource Availability is checked based on the value set
4997 -- p_calendar_flag VARCHAR2(1)
4998 -- : value of Y or N
4999
5000 -- This parameter contains the Calling Document ID
5001 -- In this case it is a DR_ID.
5002 -- p_dr_id NUMBER -- REQUIRED
5003
5004
5005 -- These parameters contain the Qualifier Values for
5006 -- the Calling Document
5007 -- p_dr_rec JTF_ASSIGN_PUB.
5008 -- JTF_DR_rec_type
5009
5010 -- OUT : x_return_status OUT VARCHAR2(1)
5011 -- x_msg_count OUT NUMBER
5012 -- x_msg_data OUT VARCHAR2(2000)
5013 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
5014 -- AssignResources_tbl_type
5015
5016
5017 -- Version : Current version 1.0
5018 -- Initial version 1.0
5019 --
5020 -- Notes :
5021 --
5022
5023 -- End of comments
5024
5025 -- *********************************************************************************
5026
5027
5028
5029 -- Procedure definition with the parameters when the
5030 -- Source Document is DEPOT REPAIR
5031
5032
5033 PROCEDURE GET_ASSIGN_DR_RESOURCES
5034 ( p_api_version IN NUMBER,
5035 p_init_msg_list IN VARCHAR2 ,
5036 p_resource_type IN VARCHAR2 ,
5037 p_role IN VARCHAR2 ,
5038 p_no_of_resources IN NUMBER ,
5039 p_auto_select_flag IN VARCHAR2 ,
5040 p_contracts_preferred_engineer IN VARCHAR2 ,
5041 p_ib_preferred_engineer IN VARCHAR2 ,
5042 p_contract_id IN NUMBER ,
5043 p_customer_product_id IN NUMBER ,
5044 p_effort_duration IN NUMBER ,
5045 p_effort_uom IN VARCHAR2 ,
5046 p_start_date IN DATE ,
5047 p_end_date IN DATE ,
5048 p_territory_flag IN VARCHAR2 ,
5049 p_calendar_flag IN VARCHAR2 ,
5050 p_web_availability_flag IN VARCHAR2 ,
5051 p_category_id IN NUMBER ,
5052 p_inventory_item_id IN NUMBER ,
5053 p_inventory_org_id IN NUMBER ,
5054 p_problem_code IN VARCHAR2 ,
5055 p_dr_id IN NUMBER,
5056 p_column_list IN VARCHAR2 ,
5057 p_dr_rec IN JTF_ASSIGN_PUB.JTF_DR_rec_type ,
5058 p_business_process_id IN NUMBER,
5059 p_business_process_date IN DATE,
5060 p_filter_excluded_resource IN VARCHAR2,
5061 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
5062 x_return_status OUT NOCOPY VARCHAR2,
5063 x_msg_count OUT NOCOPY NUMBER,
5064 x_msg_data OUT NOCOPY VARCHAR2,
5065 --Added for Bug # 5573916
5066 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
5067 --Added for Bug # 5573916 Ends here
5068 )
5069 IS
5070
5071 l_return_status_1 VARCHAR2(10);
5072 l_api_name VARCHAR2(100) := 'GET_ASSIGN_DR_RESOURCES';
5073 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_DR_RESOURCES';
5074
5075 l_api_version NUMBER := 1.0;
5076 l_no_of_resources NUMBER := p_no_of_resources;
5077 l_auto_select_flag VARCHAR2(1) := p_auto_select_flag;
5078 l_contracts_preferred_engineer VARCHAR2(1) := p_contracts_preferred_engineer;
5079 l_ib_preferred_engineer VARCHAR2(1) := p_ib_preferred_engineer;
5080 l_territory_flag VARCHAR2(1) := p_territory_flag;
5081 l_calendar_flag VARCHAR2(1) := p_calendar_flag;
5082
5083 l_web_availability_flag VARCHAR2(1) := p_web_availability_flag;
5084
5085 l_contracts_profile VARCHAR2(1);
5086 l_ib_profile VARCHAR2(1);
5087 l_auto_select_profile VARCHAR2(1);
5088 l_workflow_profile VARCHAR2(60);
5089
5090 l_current_record INTEGER;
5091 l_dynamic_cursor INTEGER;
5092 l_dynamic_sql VARCHAR2(4000);
5093
5094 l_return_code VARCHAR2(60);
5095 l_wf_return_status VARCHAR2(60);
5096 l_wf_msg_count NUMBER;
5097 l_wf_msg_data VARCHAR2(2000);
5098
5099 l_bind_data_id NUMBER;
5100 l_workflow_key NUMBER;
5101
5102 l_dr_rec JTF_TERRITORY_PUB.JTF_Srv_Task_rec_type;
5103 l_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
5104 l_assign_resources_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
5105 l_winningterrmember_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
5106
5107 l_dr_id NUMBER;
5108 l_p_resource_type VARCHAR2(30) := p_resource_type;
5109 l_planned_start_date DATE;
5110 l_planned_end_date DATE;
5111 l_expected_end_date DATE; -- Added by SBARAT on 10/12/2004 for Bug 4052202
5112 l_effort_duration NUMBER;
5113 l_effort_uom VARCHAR2(30);
5114 l_contract_id NUMBER;
5115 l_cp_id NUMBER;
5116 l_contract_flag VARCHAR2(1) := 'N';
5117 l_terr_cal_flag VARCHAR2(1) := 'N';
5118
5119 l_travel_time NUMBER := 0;
5120 l_travel_uom VARCHAR2(10) := 'HR';
5121
5122 l_current_rec INTEGER := 0;
5123 l_pref_record INTEGER := 0;
5124
5125
5126 l_return_status VARCHAR2(10);
5127 l_msg_count NUMBER;
5128 l_msg_data VARCHAR2(2000);
5129
5130 l_pref_res_order VARCHAR2(20) := 'BOTH';
5131 l_ib_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
5132 l_con_preferred_engineers_tbl JTF_ASSIGN_PUB.prfeng_tbl_type;
5133 l_preferred_engineers_tbl JTF_ASSIGN_PUB.Preferred_Engineers_tbl_type;
5134
5135 -- tables to handle excluded resource feature
5136 l_excluded_resource_tbl JTF_ASSIGN_PUB.excluded_tbl_type;
5137 l_contracts_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
5138 l_ib_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
5139
5140
5141 l_x_planned_start_date DATE;
5142 l_x_planned_end_date DATE;
5143 l_x_shift_construct_id NUMBER;
5144 l_x_availability_type VARCHAR2(60);
5145
5146 l_dynamic_sql1 VARCHAR2(2000);
5147 l_dynamic_sql3 VARCHAR2(2000);
5148
5149 TYPE DYNAMIC_CUR_TYP IS REF CURSOR;
5150 cur_cs_incidents DYNAMIC_CUR_TYP;
5151 cur_support_site_name DYNAMIC_CUR_TYP;
5152
5153 l_support_site VARCHAR2(15) := 'SUPPORT_SITE';
5154 l_rsc_type VARCHAR2(30);
5155 l_rsc_id NUMBER;
5156
5157 l_value VARCHAR2(100);
5158 l_count NUMBER:= 0;
5159 l_usage VARCHAR2(2000);
5160 l_uom_hour VARCHAR2(2000);
5161
5162 l_skill_level NUMBER;
5163 l_skill_name VARCHAR2(60);
5164 l_skill_ret_sts VARCHAR2(1);
5165 l_skill_tbl JTF_AM_FILTER_RESOURCE_PVT.skill_param_tbl_type;
5166 l_group_filter VARCHAR2(100) := 'YES';
5167
5168 -- Record type for service security check
5169 l_dr_sec_rec JTF_AM_FILTER_RESOURCE_PVT.sr_rec_type;
5170
5171
5172 CURSOR cur_resource_type IS
5173 SELECT object_code
5174 FROM jtf_object_usages
5175 WHERE object_user_code = 'RESOURCES' AND
5176 object_code = p_resource_type;
5177 l_cur_resource_type cur_resource_type%ROWTYPE;
5178
5179
5180 CURSOR cur_res_location(p_rid NUMBER, p_rtype VARCHAR2) IS
5181 SELECT DECODE(source_postal_code, NULL, '00000', source_postal_code)
5182 FROM jtf_rs_resource_extns_vl
5183 WHERE resource_id = p_rid AND
5184 'RS_'||category = p_rtype;
5185
5186
5187 --Bug# 4455803 MOAC.
5188 CURSOR check_date_cur(l_resource_id in number,
5189 l_resource_type in varchar2)
5190 IS
5191 SELECT 'Y'
5192 FROM jtf_task_resources_vl
5193 where resource_id = l_resource_id
5194 and resource_type = l_resource_type
5195 and nvl(trunc(end_date_active), trunc(sysdate)) >= trunc(sysdate);
5196
5197
5198 CURSOR cur_support_site_id (p_rsc_id NUMBER, p_rsc_type VARCHAR2) IS
5199 SELECT support_site_id
5200 FROM jtf_rs_resource_extns_vl
5201 WHERE resource_id = p_rsc_id AND
5202 category = p_rsc_type;
5203
5204
5205 CURSOR cur_web_availability (p_res_id NUMBER, p_res_type VARCHAR2) IS
5206 SELECT resource_id
5207 FROM jtf_rs_web_available_v
5208 WHERE resource_id = p_res_id AND
5209 category = p_res_type;
5210
5211
5212 CURSOR cur_resource_skills (p_res_id NUMBER) IS
5213 SELECT skill_level, level_name
5214 FROM jtf_rs_resource_skills a,
5215 jtf_rs_skill_levels_vl b
5216 WHERE a.skill_level_id = b.skill_level_id AND
5217 a.resource_id = p_res_id AND
5218 (category_id = p_category_id OR category_id IS NULL) AND
5219 product_id = p_inventory_item_id AND
5220 product_org_id = p_inventory_org_id AND
5221 component_id IS NULL AND
5222 subcomponent_id IS NULL;
5223
5224 BEGIN
5225
5226 SAVEPOINT jtf_assign_pub;
5227
5228 -- Started Assignment Manager Public API
5229
5230 /* Standard call to check for call compatibility */
5231
5232 IF NOT fnd_api.compatible_api_call (l_api_version,
5233 p_api_version,
5234 l_api_name,
5235 g_pkg_name) THEN
5236 RAISE fnd_api.g_exc_unexpected_error;
5237 END IF;
5238
5239
5240 /* Initialize message list if p_init_msg_list is set to TRUE */
5241
5242 IF fnd_api.to_boolean (p_init_msg_list) THEN
5243 fnd_msg_pub.initialize;
5244 END IF;
5245
5246 x_return_status := fnd_api.g_ret_sts_success;
5247
5248 /* Paramater Validation */
5249
5250 IF (p_resource_type IS NOT NULL) THEN
5251 OPEN cur_resource_type;
5252 FETCH cur_resource_type INTO l_cur_resource_type;
5253 IF ( cur_resource_type%NOTFOUND) THEN
5254 fnd_message.set_name('JTF', 'JTF_AM_INVALID_RESOURCE_TYPE');
5255 fnd_msg_pub.add;
5256 RAISE fnd_api.g_exc_error;
5257 END IF;
5258 CLOSE cur_resource_type;
5259 END IF;
5260
5261
5262 /* Getting the Profile values defined for the Assignment Manager */
5263
5264 l_contracts_profile := FND_PROFILE.VALUE ( 'ACTIVATE_CONTRACTS_PREFERRED_ENGINEERS' );
5265 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' );
5266 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' );
5267 l_ib_profile := FND_PROFILE.VALUE ( 'ACTIVATE_IB_PREFERRED_ENGINEERS');
5268 l_usage := fnd_profile.value ( 'JTF_AM_USAGE');
5269
5270 /* Assigning the DEFAULT values for the Parameters */
5271
5272 IF (p_auto_select_flag IS NULL) THEN
5273 l_auto_select_flag := l_auto_select_profile; -- PROFILE VALUE is the default value
5274 ELSE
5275 l_auto_select_flag := p_auto_select_flag;
5276 END IF;
5277
5278
5279 IF (p_contracts_preferred_engineer IS NULL) THEN
5280 l_contracts_preferred_engineer := l_contracts_profile; -- PROFILE VALUE is the default value
5281 ELSE
5282 l_contracts_preferred_engineer := p_contracts_preferred_engineer;
5283 END IF;
5284
5285
5286 IF (p_ib_preferred_engineer IS NULL) THEN
5287 l_ib_preferred_engineer := l_ib_profile; -- PROFILE VALUE is the default value
5288 ELSE
5289 l_ib_preferred_engineer := p_ib_preferred_engineer;
5290 END IF;
5291
5292
5293 IF (p_no_of_resources IS NULL) THEN
5294 l_no_of_resources := 1; -- 1 is the default value
5295 ELSE
5296 l_no_of_resources := p_no_of_resources;
5297 END IF;
5298
5299
5300 IF ( (UPPER(p_territory_flag) = 'N') OR (p_territory_flag IS NULL)) THEN
5301 l_territory_flag := 'N';
5302 ELSE
5303 l_territory_flag := 'Y'; -- YES is the default value
5304 END IF;
5305
5306
5307 IF ( (UPPER(p_calendar_flag) = 'N') OR (p_calendar_flag IS NULL)) THEN
5308 l_calendar_flag := 'N';
5309 ELSE
5310 l_calendar_flag := 'Y'; -- YES is the default value
5311 END IF;
5312
5313
5314 IF ( p_web_availability_flag IS NULL) THEN
5315 l_web_availability_flag := 'Y';
5316 ELSE
5317 l_web_availability_flag := p_web_availability_flag;
5318 END IF;
5319
5320
5321 /* To handle the conversion of duration to hour */
5322
5323 l_uom_hour := nvl(fnd_profile.value('JTF_AM_TASK_HOUR'), 'HR');
5324 IF(nvl(p_effort_uom, l_uom_hour) <> l_uom_hour)
5325 THEN
5326 l_effort_duration := inv_convert.inv_um_convert(
5327 item_id => NULL,
5328 precision => 2,
5329 from_quantity => p_effort_duration,
5330 from_unit => p_effort_uom,
5331 to_unit => l_uom_hour,
5332 from_name => NULL,
5333 to_name => NULL);
5334 ELSE
5335 l_effort_duration := p_effort_duration;
5336 END IF;
5337
5338 /* This assigning is being done because of the limitation for
5339 the direct use of the variables FND_API.MISS_NUM, MISS_CHAR etc. */
5340
5341
5342 /* Assigning values to the Depot Repair Record Type */
5343
5344 l_dr_rec.TASK_ID := p_dr_rec.TASK_ID;
5345 l_dr_rec.SERVICE_REQUEST_ID := p_dr_rec.SERVICE_REQUEST_ID;
5346 l_dr_rec.PARTY_ID := p_dr_rec.PARTY_ID;
5347 l_dr_rec.COUNTRY := p_dr_rec.COUNTRY;
5348 l_dr_rec.PARTY_SITE_ID := p_dr_rec.PARTY_SITE_ID;
5349 l_dr_rec.CITY := p_dr_rec.CITY;
5350 l_dr_rec.POSTAL_CODE := p_dr_rec.POSTAL_CODE;
5351 l_dr_rec.STATE := p_dr_rec.STATE;
5352 l_dr_rec.AREA_CODE := p_dr_rec.AREA_CODE;
5353 l_dr_rec.COUNTY := p_dr_rec.COUNTY;
5354 l_dr_rec.COMP_NAME_RANGE := p_dr_rec.COMP_NAME_RANGE;
5355 l_dr_rec.PROVINCE := p_dr_rec.PROVINCE;
5356 l_dr_rec.NUM_OF_EMPLOYEES := p_dr_rec.NUM_OF_EMPLOYEES;
5357 l_dr_rec.TASK_TYPE_ID := p_dr_rec.TASK_TYPE_ID;
5358 l_dr_rec.TASK_STATUS_ID := p_dr_rec.TASK_STATUS_ID;
5359 l_dr_rec.TASK_PRIORITY_ID := p_dr_rec.TASK_PRIORITY_ID;
5360 l_dr_rec.INCIDENT_TYPE_ID := p_dr_rec.INCIDENT_TYPE_ID;
5361 l_dr_rec.INCIDENT_SEVERITY_ID := p_dr_rec.INCIDENT_SEVERITY_ID;
5362 l_dr_rec.INCIDENT_URGENCY_ID := p_dr_rec.INCIDENT_URGENCY_ID;
5363 l_dr_rec.PROBLEM_CODE := p_dr_rec.PROBLEM_CODE;
5364 l_dr_rec.INCIDENT_STATUS_ID := p_dr_rec.INCIDENT_STATUS_ID;
5365 l_dr_rec.PLATFORM_ID := p_dr_rec.PLATFORM_ID;
5366 l_dr_rec.SUPPORT_SITE_ID := p_dr_rec.SUPPORT_SITE_ID;
5367 l_dr_rec.CUSTOMER_SITE_ID := p_dr_rec.CUSTOMER_SITE_ID;
5368 l_dr_rec.SR_CREATION_CHANNEL := p_dr_rec.SR_CREATION_CHANNEL;
5369 l_dr_rec.INVENTORY_ITEM_ID := p_dr_rec.INVENTORY_ITEM_ID;
5370 l_dr_rec.ATTRIBUTE1 := p_dr_rec.ATTRIBUTE1;
5371 l_dr_rec.ATTRIBUTE2 := p_dr_rec.ATTRIBUTE2;
5372 l_dr_rec.ATTRIBUTE3 := p_dr_rec.ATTRIBUTE3;
5373 l_dr_rec.ATTRIBUTE4 := p_dr_rec.ATTRIBUTE4;
5374 l_dr_rec.ATTRIBUTE5 := p_dr_rec.ATTRIBUTE5;
5375 l_dr_rec.ATTRIBUTE6 := p_dr_rec.ATTRIBUTE6;
5376 l_dr_rec.ATTRIBUTE7 := p_dr_rec.ATTRIBUTE7;
5377 l_dr_rec.ATTRIBUTE8 := p_dr_rec.ATTRIBUTE8;
5378 l_dr_rec.ATTRIBUTE9 := p_dr_rec.ATTRIBUTE9;
5379 l_dr_rec.ATTRIBUTE10 := p_dr_rec.ATTRIBUTE10;
5380 l_dr_rec.ATTRIBUTE11 := p_dr_rec.ATTRIBUTE11;
5381 l_dr_rec.ATTRIBUTE12 := p_dr_rec.ATTRIBUTE12;
5382 l_dr_rec.ATTRIBUTE13 := p_dr_rec.ATTRIBUTE13;
5383 l_dr_rec.ATTRIBUTE14 := p_dr_rec.ATTRIBUTE14;
5384 l_dr_rec.ATTRIBUTE15 := p_dr_rec.ATTRIBUTE15;
5385 l_dr_rec.ORGANIZATION_ID := p_dr_rec.ORGANIZATION_ID;
5386 l_dr_rec.SQUAL_NUM12 := p_dr_rec.SQUAL_NUM12;
5387 l_dr_rec.SQUAL_NUM13 := p_dr_rec.SQUAL_NUM13;
5388 l_dr_rec.SQUAL_NUM14 := p_dr_rec.SQUAL_NUM14;
5389 l_dr_rec.SQUAL_NUM15 := p_dr_rec.SQUAL_NUM15;
5390 l_dr_rec.SQUAL_NUM16 := p_dr_rec.SQUAL_NUM16;
5391 l_dr_rec.SQUAL_NUM17 := p_dr_rec.SQUAL_NUM17;
5392 l_dr_rec.SQUAL_NUM18 := p_dr_rec.SQUAL_NUM18;
5393 l_dr_rec.SQUAL_NUM19 := p_dr_rec.SQUAL_NUM19;
5394 l_dr_rec.SQUAL_NUM30 := p_dr_rec.SQUAL_NUM30;
5395 l_dr_rec.SQUAL_CHAR11 := p_dr_rec.SQUAL_CHAR11;
5396 l_dr_rec.SQUAL_CHAR12 := p_dr_rec.SQUAL_CHAR12;
5397 l_dr_rec.SQUAL_CHAR13 := p_dr_rec.SQUAL_CHAR13;
5398 l_dr_rec.SQUAL_CHAR20 := p_dr_rec.SQUAL_CHAR20;
5399 l_dr_rec.SQUAL_CHAR21 := p_dr_rec.SQUAL_CHAR21;
5400
5401
5402 IF ( UPPER(p_resource_type) = 'RS_INDIVIDUAL') THEN
5403 l_p_resource_type := 'RS_INDIVIDUAL';
5404 ELSIF(p_resource_type is null) THEN
5405 l_p_resource_type := null;
5406 ELSE
5407 l_p_resource_type := p_resource_type;
5408 END IF;
5409
5410
5411 IF (p_dr_id IS NOT NULL ) THEN
5412 l_dr_id := p_dr_id;
5413 ELSIF (p_dr_rec.service_request_id IS NOT NULL) THEN
5414 l_dr_id := p_dr_rec.service_request_id;
5415 END IF;
5416
5417 -- Assign values to l_dr_sec_rec for DR Security Check
5418 l_dr_sec_rec.incident_id := l_dr_id;
5419 l_dr_sec_rec.incident_type_id := p_dr_rec.incident_type_id;
5420
5421
5422 /* Defaulting the variable values to IN parameters,
5423 if the IN paramaters have values given */
5424
5425 IF (p_start_date IS NOT NULL) THEN
5426 l_planned_start_date := p_start_date;
5427 ELSE
5428 l_planned_start_date := SYSDATE;
5429 END IF;
5430
5431 IF (p_end_date IS NOT NULL) THEN
5432 l_planned_end_date := p_end_date;
5433 ELSE
5434 l_planned_end_date := SYSDATE + 14;
5435 END IF;
5436
5437 IF (p_effort_duration IS NOT NULL) THEN
5438 l_effort_duration := p_effort_duration;
5439 END IF;
5440
5441 IF (p_effort_uom IS NOT NULL) THEN
5442 l_effort_uom := p_effort_uom;
5443 END IF;
5444
5445 -- Get the Profile value to determine the order of preferred resources
5446
5447 l_pref_res_order := FND_PROFILE.VALUE ( 'JTF_AM_PREF_RES_ORDER' );
5448
5449
5450 IF ( p_contracts_preferred_engineer = 'Y' OR
5451 p_ib_preferred_engineer = 'Y') THEN
5452
5453
5454 l_contract_id := p_contract_id;
5455 l_cp_id := p_customer_product_id;
5456
5457
5458 -- Code to fetch the Preferred Resources for saved DR
5459 IF (l_contract_id IS NULL AND
5460 l_cp_id IS NULL AND
5461 l_dr_id IS NOT NULL) THEN
5462
5463 l_dynamic_sql1 := ' SELECT contract_service_id, customer_product_id, expected_resolution_date'||
5464 ' FROM cs_incidents_all_vl'||
5465 ' WHERE incident_id = :1';
5466
5467 OPEN cur_cs_incidents FOR l_dynamic_sql1 USING l_dr_id;
5468 FETCH cur_cs_incidents INTO l_contract_id,
5469 l_cp_id,
5470 l_expected_end_date; --Added by SBARAT on 10/12/2004 for bug 4052202
5471 --l_planned_end_date; --Commented out by SBARAT on 10/12/2004 for bug 4052202
5472
5473 IF ( cur_cs_incidents%NOTFOUND ) THEN
5474 fnd_message.set_name('JTF', 'JTF_AM_INVALID_DR_ID');
5475 fnd_msg_pub.add;
5476 RAISE fnd_api.g_exc_error;
5477 END IF;
5478
5479 CLOSE cur_cs_incidents;
5480
5481 /**********Start of addition by SBARAT on 10/12/2004 for Bug 4052202**********/
5482 --since this API for DR is same as SR_TASK, added this check to handle
5483 --NULL or l_expected_end_date < l_planned_start_date as done for SR, SR_TASK
5484
5485 IF ( l_expected_end_date IS NOT NULL) And (l_expected_end_date >= l_planned_start_date)
5486 THEN
5487
5488 l_planned_end_date := l_expected_end_date;
5489
5490 END IF;
5491
5492 /**********End of Addition by SBARAT on 10/12/2004 for Bug 4052202**********/
5493
5494 END IF; -- end of l_contract_id and l_cp_id null check
5495
5496 END IF;
5497
5498 /* Actual Flow of Assignment Manager*/
5499
5500 -- initiliaze the table type variables
5501 l_excluded_resource_tbl.delete;
5502 l_contracts_tbl.delete;
5503 l_ib_tbl.delete;
5504
5505 -- get the contracts preferred and excluded engineers
5506 IF (p_contracts_preferred_engineer = 'Y') THEN
5507 get_contracts_resources
5508 (
5509 p_init_msg_list => p_init_msg_list,
5510 p_contract_id => l_contract_id,
5511 p_calendar_flag => p_calendar_flag,
5512 p_effort_duration => l_effort_duration,
5513 p_effort_uom => l_effort_uom,
5514 p_planned_start_date => l_planned_start_date,
5515 p_planned_end_date => l_planned_end_date,
5516 p_resource_type => l_p_resource_type,
5517 p_business_process_id => p_business_process_id,
5518 p_business_process_date => p_business_process_date,
5519 x_return_status => x_return_status,
5520 x_msg_count => x_msg_count,
5521 x_msg_data => x_msg_data,
5522 x_assign_resources_tbl => l_contracts_tbl,
5523 x_excluded_tbl => l_excluded_resource_tbl,
5524 --Added for Bug # 5573916
5525 p_calendar_check => p_calendar_check
5526 --Added for Bug # 5573916 Ends here
5527 );
5528
5529 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5530 -- Unexpected Execution Error from call to Get_contracts_resources
5531 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
5532 fnd_message.set_token('P_PROC_NAME','GET_CONTRACTS_RESOURCES');
5533 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DR_RESOURCES');
5534 fnd_msg_pub.add;
5535 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5536 RAISE fnd_api.g_exc_error;
5537 ELSE
5538 RAISE fnd_api.g_exc_unexpected_error;
5539 END IF;
5540 END IF;
5541 END IF;
5542
5543 -- get the ib preferred and excluded engineers
5544 IF (p_ib_preferred_engineer = 'Y') THEN
5545
5546 get_ib_resources
5547 (
5548 p_init_msg_list => p_init_msg_list,
5549 p_customer_product_id => l_cp_id,
5550 p_calendar_flag => p_calendar_flag,
5551 p_effort_duration => l_effort_duration,
5552 p_effort_uom => l_effort_uom,
5553 p_planned_start_date => l_planned_start_date,
5554 p_planned_end_date => l_planned_end_date,
5555 p_resource_type => l_p_resource_type,
5556 x_return_status => x_return_status,
5557 x_msg_count => x_msg_count,
5558 x_msg_data => x_msg_data,
5559 x_assign_resources_tbl => l_ib_tbl,
5560 x_excluded_tbl => l_excluded_resource_tbl,
5561 --Added for Bug # 5573916
5562 p_calendar_check => p_calendar_check
5563 --Added for Bug # 5573916 Ends here
5564 );
5565
5566 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5567 -- Unexpected Execution Error from call to Get_contracts_resources
5568 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
5569 fnd_message.set_token('P_PROC_NAME','GET_IB_RESOURCES');
5570 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DR_RESOURCES');
5571 fnd_msg_pub.add;
5572 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5573 RAISE fnd_api.g_exc_error;
5574 ELSE
5575 RAISE fnd_api.g_exc_unexpected_error;
5576 END IF;
5577 END IF;
5578
5579 END IF; -- p_ib_preferred_engineer = 'Y'
5580
5581 -- remove excluded resources
5582 IF(p_filter_excluded_resource = 'Y')
5583 THEN
5584 IF(p_contracts_preferred_engineer = 'Y')
5585 THEN
5586 remove_excluded(x_res_tbl => l_contracts_tbl,
5587 x_exc_res => l_excluded_resource_tbl);
5588 END IF;
5589 IF(p_ib_preferred_engineer = 'Y')
5590 THEN
5591 remove_excluded(x_res_tbl => l_ib_tbl,
5592 x_exc_res => l_excluded_resource_tbl);
5593 END IF;
5594 END IF;
5595
5596
5597 -- pass returned resources through security check
5598 IF(l_contracts_tbl.count > 0)
5599 THEN
5600 JTF_AM_FILTER_RESOURCE_PVT.SERVICE_SECURITY_CHECK
5601 ( p_api_version =>1.0,
5602 x_assign_resources_tbl =>l_contracts_tbl,
5603 p_sr_tbl =>l_dr_sec_rec,
5604 x_return_status =>x_return_status ,
5605 x_msg_count =>x_msg_count,
5606 x_msg_data =>x_msg_data);
5607
5608 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5609 -- Unexpected Execution Error from call to Get_contracts_resources
5610 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
5611 fnd_message.set_token('P_PROC_NAME','SERVICE_SECURITY_CHECK');
5612 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DR_RESOURCES');
5613 fnd_msg_pub.add;
5614 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5615 RAISE fnd_api.g_exc_error;
5616 ELSE
5617 RAISE fnd_api.g_exc_unexpected_error;
5618 END IF;
5619 END IF;
5620
5621 end IF; -- end of security check for contracts resource
5622
5623 IF(l_ib_tbl.count > 0)
5624 THEN
5625 JTF_AM_FILTER_RESOURCE_PVT.SERVICE_SECURITY_CHECK
5626 ( p_api_version =>1.0,
5627 x_assign_resources_tbl =>l_ib_tbl,
5628 p_sr_tbl =>l_dr_sec_rec,
5629 x_return_status =>x_return_status ,
5630 x_msg_count =>x_msg_count,
5631 x_msg_data =>x_msg_data);
5632
5633 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5634 -- Unexpected Execution Error from call to Get_contracts_resources
5635 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
5636 fnd_message.set_token('P_PROC_NAME','SERVICE_SECURITY_CHECK');
5637 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DR_RESOURCES');
5638 fnd_msg_pub.add;
5639 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5640 RAISE fnd_api.g_exc_error;
5641 ELSE
5642 RAISE fnd_api.g_exc_unexpected_error;
5643 END IF;
5644 END IF;
5645
5646 end IF; -- end of security check for contracts resource
5647
5648
5649 -- after the preferred engineers are obtained from contracts/ib, select the resources
5650 -- that are to be returned based on the value of the profile for search order and after
5651 -- filtering out excluded resources
5652 IF ( upper(l_pref_res_order) = 'CONTRACTS' )
5653 THEN
5654 IF (p_contracts_preferred_engineer = 'Y')
5655 THEN
5656 table_copy(l_contracts_tbl, l_assign_resources_tbl);
5657 END IF; -- p_contracts_preferred_engineer = 'Y'
5658
5659
5660 IF ( l_assign_resources_tbl.COUNT <= 0 )
5661 THEN
5662 IF (p_ib_preferred_engineer = 'Y')
5663 THEN
5664 table_copy(l_ib_tbl, l_assign_resources_tbl);
5665 END IF; -- p_ib_preferred_engineer = 'Y'
5666 END IF; -- l_assign_resources_tbl.COUNT <= 0
5667
5668 ELSIF ( upper(l_pref_res_order) = 'IB' )
5669 THEN
5670
5671 IF (p_ib_preferred_engineer = 'Y')
5672 THEN
5673 table_copy(l_ib_tbl, l_assign_resources_tbl);
5674 END IF; -- p_ib_preferred_engineer = 'Y'
5675
5676 IF ( l_assign_resources_tbl.COUNT <= 0 )
5677 THEN
5678 IF (p_contracts_preferred_engineer = 'Y')
5679 THEN
5680 table_copy(l_contracts_tbl, l_assign_resources_tbl);
5681 END IF; -- p_contracts_preferred_engineer = 'Y'
5682 END IF; -- l_assign_resources_tbl.COUNT <= 0
5683
5684 ELSE -- l_pref_res_order = 'BOTH'
5685
5686 /* Check if the Contracts Preferred Engineers Profile is SET If it is SET then get the available
5687 preferred engineers into the table of records */
5688
5689 IF (p_contracts_preferred_engineer = 'Y')
5690 THEN
5691 table_copy(l_contracts_tbl, l_assign_resources_tbl);
5692 END IF; -- p_contracts_preferred_engineer = 'Y'
5693
5694
5695 /* Check if the Installed Base Preferred Engineers Profile is SET
5696 If it is SET then get the available preferred engineers
5697 into the table of records */
5698
5699 IF (p_ib_preferred_engineer = 'Y')
5700 THEN
5701 table_copy(l_ib_tbl, l_assign_resources_tbl);
5702 END IF; -- p_ib_preferred_engineer = 'Y'
5703
5704 END IF; -- l_pref_res_order = 'CONTRACTS' / 'IB' / 'BOTH'
5705
5706
5707 -- if the Contracts and IB Preferred Engineers are nor found then Territory Qualified Resources are fetched
5708
5709 IF l_assign_resources_tbl.COUNT <= 0
5710 THEN
5711 IF (p_territory_flag = 'Y') THEN
5712
5713 IF (l_p_resource_type = 'RS_INDIVIDUAL') THEN
5714 l_p_resource_type := NULL;
5715 END IF;
5716
5717 -- change the API Name temporarily so that in case of unexpected error
5718 -- it is properly caught
5719
5720 l_api_name := l_api_name||'-JTF_TERR_SERVICE_PUB';
5721
5722 JTF_TERR_SERVICE_PUB.Get_WinningTerrMembers
5723 (
5724 p_api_version_number => l_api_version,
5725 p_init_msg_list => p_init_msg_list,
5726 p_TerrSrvTask_Rec => l_dr_rec,
5727 p_Resource_Type => l_p_resource_type,
5728 p_Role => p_role,
5729 x_return_status => x_return_status,
5730 x_msg_count => x_msg_count,
5731 x_msg_data => x_msg_data,
5732 x_TerrResource_tbl => l_winningterrmember_tbl
5733 );
5734
5735 -- set back the API name to original name
5736 l_api_name := l_api_name_1;
5737
5738 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5739 -- Unexpected Execution Error from call to Territory Manager
5740 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
5741 fnd_msg_pub.add;
5742 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5743 RAISE fnd_api.g_exc_error;
5744 ELSE
5745 RAISE fnd_api.g_exc_unexpected_error;
5746 END IF;
5747 END IF;
5748
5749 IF(l_winningterrmember_tbl.COUNT > 0)
5750 THEN
5751 l_current_record := l_winningterrmember_tbl.FIRST;
5752 WHILE l_current_record <= l_winningterrmember_tbl.LAST
5753 LOOP
5754 IF(l_winningterrmember_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
5755 THEN
5756 l_winningterrmember_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
5757 END IF;
5758 l_current_record := l_winningterrmember_tbl.NEXT(l_current_record);
5759 END LOOP;
5760 END IF;
5761
5762 ELSE -- Territory Flag is NO
5763
5764 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
5765 fnd_msg_pub.add;
5766
5767 END IF; -- End of p_territory_flag = 'Y'
5768
5769 IF l_winningterrmember_tbl.COUNT > 0 THEN
5770
5771 l_current_rec := 0;
5772 l_current_record := l_winningterrmember_tbl.FIRST;
5773
5774 WHILE(l_current_record <= l_winningterrmember_tbl.LAST)
5775 LOOP
5776 l_assign_resources_tbl(l_current_rec).terr_rsc_id :=
5777 l_winningterrmember_tbl(l_current_record).terr_rsc_id;
5778 l_assign_resources_tbl(l_current_rec).resource_id :=
5779 l_winningterrmember_tbl(l_current_record).resource_id;
5780 l_assign_resources_tbl(l_current_rec).resource_type :=
5781 l_winningterrmember_tbl(l_current_record).resource_type;
5782 l_assign_resources_tbl(l_current_rec).role :=
5783 l_winningterrmember_tbl(l_current_record).role;
5784 l_assign_resources_tbl(l_current_rec).start_date :=
5785 l_winningterrmember_tbl(l_current_record).start_date;
5786 l_assign_resources_tbl(l_current_rec).end_date :=
5787 l_winningterrmember_tbl(l_current_record).end_date;
5788 l_assign_resources_tbl(l_current_rec).shift_construct_id := NULL;
5789 l_assign_resources_tbl(l_current_rec).terr_id :=
5790 l_winningterrmember_tbl(l_current_record).terr_id;
5791 l_assign_resources_tbl(l_current_rec).terr_name :=
5792 l_winningterrmember_tbl(l_current_record).terr_name;
5793 l_assign_resources_tbl(l_current_rec).primary_contact_flag :=
5794 l_winningterrmember_tbl(l_current_record).primary_contact_flag;
5795 l_assign_resources_tbl(l_current_rec).primary_flag :=
5796 l_winningterrmember_tbl(l_current_record).primary_contact_flag;
5797 l_assign_resources_tbl(l_current_rec).resource_source := 'TERR';
5798
5799 l_current_rec := l_current_rec + 1;
5800 l_current_record := l_winningterrmember_tbl.NEXT(l_current_record);
5801 END LOOP;
5802
5803 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
5804 l_return_status_1 := x_return_status ;
5805
5806 -- call the api to check resource availability
5807
5808 get_available_resources
5809 (
5810 p_init_msg_list => 'F',
5811 p_calendar_flag => p_calendar_flag,
5812 p_effort_duration => l_effort_duration,
5813 p_effort_uom => l_effort_uom,
5814 p_planned_start_date => l_planned_start_date,
5815 p_planned_end_date => l_planned_end_date,
5816 p_breakdown => null,
5817 p_breakdown_uom => null,
5818 p_continuous_task => jtf_assign_pub.g_continuous_work,
5819 x_return_status => x_return_status,
5820 x_msg_count => x_msg_count,
5821 x_msg_data => x_msg_data,
5822 x_assign_resources_tbl => l_assign_resources_tbl,
5823 --Added for Bug # 5573916
5824 p_calendar_check => p_calendar_check
5825 --Added for Bug # 5573916 Ends here
5826 );
5827
5828 -- set back the API name to original name
5829
5830 l_api_name := l_api_name_1;
5831
5832 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5833 -- Unexpected Execution Error from call to Get_contracts_resources
5834 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
5835 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
5836 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DR_RESOURCES');
5837 fnd_msg_pub.add;
5838 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5839 RAISE fnd_api.g_exc_error;
5840 ELSE
5841 RAISE fnd_api.g_exc_unexpected_error;
5842 END IF;
5843 END IF; -- end of x_return_status check
5844
5845 IF ( p_calendar_flag = 'Y' AND
5846 l_assign_resources_tbl.count = 0 ) THEN
5847 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
5848 fnd_msg_pub.add;
5849 END IF;
5850
5851
5852 -- remove excluded resources from territory qualifeid resource list
5853
5854 IF(p_filter_excluded_resource = 'Y')
5855 THEN
5856 remove_excluded(x_res_tbl => l_assign_resources_tbl,
5857 x_exc_res => l_excluded_resource_tbl);
5858 END IF;
5859
5860 IF(l_assign_resources_tbl.count > 0)
5861 THEN
5862 JTF_AM_FILTER_RESOURCE_PVT.SERVICE_SECURITY_CHECK
5863 ( p_api_version =>1.0,
5864 x_assign_resources_tbl =>l_assign_resources_tbl,
5865 p_sr_tbl =>l_dr_sec_rec,
5866 x_return_status =>x_return_status ,
5867 x_msg_count =>x_msg_count,
5868 x_msg_data =>x_msg_data);
5869
5870 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
5871 -- Unexpected Execution Error from call to Get_contracts_resources
5872 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
5873 fnd_message.set_token('P_PROC_NAME','SERVICE_SECURITY_CHECK');
5874 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DR_RESOURCES');
5875 fnd_msg_pub.add;
5876 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
5877 RAISE fnd_api.g_exc_error;
5878 ELSE
5879 RAISE fnd_api.g_exc_unexpected_error;
5880 END IF;
5881 END IF;
5882 END IF; -- end of security check
5883 ELSE -- No resources returned from the Territory API
5884
5885 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
5886 fnd_msg_pub.add;
5887 END IF;
5888
5889
5890 -- Logic for getting resources belonging to group id passed in
5891 -- get the profile value to see if you have to filter by group membership
5892
5893 l_group_filter := nvl(FND_PROFILE.VALUE ('JTF_AM_GROUP_MEMBER_FILTER'), 'YES');
5894
5895 IF(l_group_filter = 'YES')
5896 THEN
5897 IF((p_dr_rec.squal_num17 is not null) )
5898 THEN
5899 get_group_resource(p_dr_rec.squal_num17 ,
5900 l_assign_resources_tbl );
5901 END IF;
5902
5903 END IF;
5904
5905 END IF; -- End of l_assign_resources_tbl.COUNT <= 0
5906
5907
5908 -- Start of enhancement for showing Individual Resources ONLY
5909
5910 IF ( UPPER(p_resource_type) = 'RS_INDIVIDUAL' ) THEN
5911
5912 -- Reconstructing the table to further do the enhancements
5913
5914 IF ( l_assign_resources_tbl.COUNT > 0 ) THEN
5915
5916 l_current_record := l_assign_resources_tbl.FIRST;
5917 l_current_rec := 1;
5918
5919 WHILE l_current_record <= l_assign_resources_tbl.LAST
5920 LOOP
5921
5922 l_tbl(l_current_rec).resource_id :=
5923 l_assign_resources_tbl(l_current_record).resource_id;
5924 l_tbl(l_current_rec).resource_type :=
5925 l_assign_resources_tbl(l_current_record).resource_type;
5926
5927 l_tbl(l_current_rec).start_date :=
5928 l_assign_resources_tbl(l_current_record).start_date;
5929 l_tbl(l_current_rec).end_date :=
5930 l_assign_resources_tbl(l_current_record).end_date;
5931 l_tbl(l_current_rec).shift_construct_id :=
5932 l_assign_resources_tbl(l_current_record).shift_construct_id;
5933
5934 l_tbl(l_current_rec).terr_rsc_id :=
5935 l_assign_resources_tbl(l_current_record).terr_rsc_id;
5936 l_tbl(l_current_rec).role :=
5937 l_assign_resources_tbl(l_current_record).role;
5938 l_tbl(l_current_rec).terr_id :=
5939 l_assign_resources_tbl(l_current_record).terr_id;
5940 l_tbl(l_current_rec).terr_name :=
5941 l_assign_resources_tbl(l_current_record).terr_name;
5942 l_tbl(l_current_rec).primary_contact_flag :=
5943 l_assign_resources_tbl(l_current_record).primary_contact_flag;
5944 l_tbl(l_current_rec).preference_type :=
5945 l_assign_resources_tbl(l_current_record).preference_type;
5946 l_tbl(l_current_rec).group_id :=
5947 l_assign_resources_tbl(l_current_record).group_id;
5948
5949 l_tbl(l_current_rec).primary_flag :=
5950 l_assign_resources_tbl(l_current_record).primary_flag;
5951
5952 l_tbl(l_current_rec).resource_source :=
5953 l_assign_resources_tbl(l_current_record).resource_source;
5954
5955 l_current_rec := l_current_rec + 1;
5956 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
5957
5958 END LOOP;
5959
5960 END IF; --End of l_assign_resources_tbl.COUNT > 0
5961
5962 -- End of reconstruction
5963
5964
5965 IF ( l_tbl.COUNT > 0 ) THEN
5966
5967 l_current_record := l_tbl.FIRST;
5968 l_current_rec := 0;
5969
5970 l_assign_resources_tbl.delete;
5971
5972 WHILE l_current_record <= l_tbl.LAST
5973 LOOP
5974 IF ( UPPER(l_tbl(l_current_record).resource_type) NOT IN ( 'RS_GROUP', 'RS_TEAM')) THEN
5975
5976 l_assign_resources_tbl(l_current_rec).resource_id :=
5977 l_tbl(l_current_record).resource_id;
5978 l_assign_resources_tbl(l_current_rec).resource_type :=
5979 l_tbl(l_current_record).resource_type;
5980
5981 l_assign_resources_tbl(l_current_rec).start_date :=
5982 l_tbl(l_current_record).start_date;
5983 l_assign_resources_tbl(l_current_rec).end_date :=
5984 l_tbl(l_current_record).end_date;
5985 l_assign_resources_tbl(l_current_rec).shift_construct_id :=
5986 l_tbl(l_current_record).shift_construct_id;
5987
5988 l_assign_resources_tbl(l_current_rec).terr_rsc_id :=
5989 l_tbl(l_current_record).terr_rsc_id;
5990 l_assign_resources_tbl(l_current_rec).role :=
5991 l_tbl(l_current_record).role;
5992 l_assign_resources_tbl(l_current_rec).terr_id :=
5993 l_tbl(l_current_record).terr_id;
5994 l_assign_resources_tbl(l_current_rec).terr_name :=
5995 l_tbl(l_current_record).terr_name;
5996 l_assign_resources_tbl(l_current_rec).primary_contact_flag :=
5997 l_tbl(l_current_record).primary_contact_flag;
5998 l_assign_resources_tbl(l_current_rec).preference_type :=
5999 l_tbl(l_current_record).preference_type;
6000 l_assign_resources_tbl(l_current_rec).group_id :=
6001 l_tbl(l_current_record).group_id;
6002
6003 l_assign_resources_tbl(l_current_rec).primary_flag :=
6004 l_tbl(l_current_record).primary_flag;
6005
6006 l_assign_resources_tbl(l_current_rec).resource_source :=
6007 l_tbl(l_current_record).resource_source;
6008
6009 l_current_rec := l_current_rec + 1;
6010
6011 END IF;
6012 l_current_record := l_tbl.NEXT(l_current_record);
6013
6014 END LOOP;
6015
6016 END IF; --End of l_tbl.COUNT > 0
6017
6018 END IF; --End of p_resource_type = 'RS_INDIVIDUAL'
6019
6020
6021 -- To add SUPPORT SITE ID and NAME to the OUT Table
6022
6023 l_dynamic_sql3 := ' SELECT a.city city '||
6024 ' FROM hz_locations a, hz_party_sites b, hz_party_site_uses c '||
6025 ' WHERE c.site_use_type = :1 AND '||
6026 ' b.party_site_id = :2 AND '||
6027 ' a.location_id = b.location_id AND '||
6028 ' c.party_site_id = b.party_site_id ';
6029
6030 IF l_assign_resources_tbl.COUNT > 0 THEN
6031
6032 l_current_record := l_assign_resources_tbl.FIRST;
6033
6034 WHILE l_current_record <= l_assign_resources_tbl.LAST
6035 LOOP
6036
6037 l_rsc_type := resource_type_change(l_assign_resources_tbl(l_current_record).resource_type);
6038
6039 OPEN cur_support_site_id (l_assign_resources_tbl(l_current_record).resource_id,
6040 l_rsc_type);
6041 FETCH cur_support_site_id INTO l_assign_resources_tbl(l_current_record).support_site_id;
6042
6043 IF (l_assign_resources_tbl(l_current_record).support_site_id IS NOT NULL) THEN
6044
6045 OPEN cur_support_site_name FOR l_dynamic_sql3
6046 USING l_support_site,
6047 l_assign_resources_tbl(l_current_record).support_site_id;
6048
6049 FETCH cur_support_site_name INTO l_assign_resources_tbl(l_current_record).support_site_name;
6050 IF ( cur_support_site_name % NOTFOUND ) THEN
6051 l_assign_resources_tbl(l_current_record).support_site_name := NULL;
6052 END IF;
6053 CLOSE cur_support_site_name;
6054 ELSE
6055 l_assign_resources_tbl(l_current_record).support_site_id := NULL;
6056 l_assign_resources_tbl(l_current_record).support_site_name := NULL;
6057
6058 END IF;
6059
6060 CLOSE cur_support_site_id;
6061
6062 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
6063 END LOOP;
6064 END IF;
6065
6066
6067 -- To add Web Availability to the OUT Table
6068
6069 IF (l_assign_resources_tbl.COUNT > 0) THEN
6070
6071 l_current_record := l_assign_resources_tbl.FIRST;
6072
6073 WHILE l_current_record <= l_assign_resources_tbl.LAST
6074 LOOP
6075
6076 IF ( UPPER(p_web_availability_flag) = 'Y') THEN
6077 l_rsc_type := resource_type_change(l_assign_resources_tbl(l_current_record).resource_type);
6078
6079 OPEN cur_web_availability (l_assign_resources_tbl(l_current_record).resource_id,
6080 l_rsc_type);
6081 FETCH cur_web_availability INTO l_rsc_id;
6082
6083 IF (cur_web_availability%FOUND) THEN
6084 l_assign_resources_tbl(l_current_record).web_availability_flag := 'Y';
6085 ELSE
6086 l_assign_resources_tbl(l_current_record).web_availability_flag := 'N';
6087 END IF;
6088
6089 CLOSE cur_web_availability;
6090 ELSE
6091 l_assign_resources_tbl(l_current_record).web_availability_flag := NULL;
6092 END IF; --p_web_availability_flag = 'Y'
6093
6094 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
6095 END LOOP;
6096 END IF;
6097
6098
6099 -- skills bank filter call to api JTF_AM_FILTER_RESOURCE_PVT
6100 -- initialize values of the skill table
6101 l_skill_tbl(1).document_type := 'DR';
6102 l_skill_tbl(1).category_id := p_category_id;
6103 l_skill_tbl(1).product_id := p_inventory_item_id;
6104 l_skill_tbl(1).product_org_id := p_inventory_org_id;
6105 l_skill_tbl(1).problem_code := p_problem_code;
6106
6107 -- change the API Name temporarily so that in case of unexpected error
6108 -- it is properly caught
6109 l_api_name := l_api_name||'-JTF_AM_FILTER_RESOURCE_PVT';
6110
6111 JTF_AM_FILTER_RESOURCE_PVT.SEARCH_SKILL
6112 ( p_api_version => 1.0,
6113 x_assign_resources_tbl => l_assign_resources_tbl,
6114 p_skill_param_tbl => l_skill_tbl,
6115 x_return_status => l_skill_ret_sts,
6116 x_msg_count => x_msg_count,
6117 x_msg_data => x_msg_data );
6118
6119 -- set back the API name to original name
6120 l_api_name := l_api_name_1;
6121
6122 if(l_skill_ret_sts <> fnd_api.g_ret_sts_success)
6123 then
6124 IF (l_skill_ret_sts = fnd_api.g_ret_sts_error) THEN
6125 RAISE fnd_api.g_exc_error;
6126 ELSE
6127 RAISE fnd_api.g_exc_unexpected_error;
6128 END IF;
6129 end if;
6130
6131
6132 -- added this to filter by usage
6133
6134 IF ((l_assign_resources_tbl.count > 0 ) AND
6135 (nvl(l_usage, fnd_api.g_miss_char) <> 'ALL' ) AND
6136 (l_usage is not null)
6137 )
6138 THEN
6139 get_usage_resource(l_usage ,
6140 l_assign_resources_tbl);
6141 END IF;
6142
6143
6144 IF l_assign_resources_tbl.COUNT > 0 THEN
6145
6146 l_current_record := l_assign_resources_tbl.FIRST;
6147
6148 IF ( UPPER(l_auto_select_flag) = 'Y' ) THEN
6149
6150 l_no_of_resources := least(nvl(l_assign_resources_tbl.count, 0),l_no_of_resources) ;
6151
6152 WHILE (l_count < l_no_of_resources)
6153 LOOP
6154
6155 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
6156 l_assign_resources_tbl(l_current_record).resource_type);
6157 fetch check_date_cur into l_value;
6158 if (check_date_cur%found)
6159 then
6160
6161 l_count := l_count + 1;
6162
6163 x_assign_resources_tbl(l_count).terr_rsc_id :=
6164 l_assign_resources_tbl(l_current_record).terr_rsc_id;
6165 x_assign_resources_tbl(l_count).resource_id :=
6166 l_assign_resources_tbl(l_current_record).resource_id;
6167 x_assign_resources_tbl(l_count).resource_type :=
6168 l_assign_resources_tbl(l_current_record).resource_type;
6169 x_assign_resources_tbl(l_count).role :=
6170 l_assign_resources_tbl(l_current_record).role;
6171 x_assign_resources_tbl(l_count).start_date :=
6172 l_assign_resources_tbl(l_current_record).start_date;
6173 x_assign_resources_tbl(l_count).end_date :=
6174 l_assign_resources_tbl(l_current_record).end_date;
6175 x_assign_resources_tbl(l_count).shift_construct_id :=
6176 l_assign_resources_tbl(l_current_record).shift_construct_id;
6177 x_assign_resources_tbl(l_count).terr_id :=
6178 l_assign_resources_tbl(l_current_record).terr_id;
6179 x_assign_resources_tbl(l_count).terr_name :=
6180 l_assign_resources_tbl(l_current_record).terr_name;
6181 x_assign_resources_tbl(l_count).preference_type :=
6182 l_assign_resources_tbl(l_current_record).preference_type;
6183 x_assign_resources_tbl(l_count).primary_contact_flag :=
6184 l_assign_resources_tbl(l_current_record).primary_contact_flag;
6185 x_assign_resources_tbl(l_count).group_id :=
6186 l_assign_resources_tbl(l_current_record).group_id;
6187
6188 x_assign_resources_tbl(l_count).support_site_id :=
6189 l_assign_resources_tbl(l_current_record).support_site_id;
6190 x_assign_resources_tbl(l_count).support_site_name :=
6191 l_assign_resources_tbl(l_current_record).support_site_name;
6192 x_assign_resources_tbl(l_count).web_availability_flag :=
6193 l_assign_resources_tbl(l_current_record).web_availability_flag;
6194
6195 x_assign_resources_tbl(l_count).skill_level :=
6196 l_assign_resources_tbl(l_current_record).skill_level;
6197 x_assign_resources_tbl(l_count).skill_name :=
6198 l_assign_resources_tbl(l_current_record).skill_name;
6199 x_assign_resources_tbl(l_count).primary_flag :=
6200 l_assign_resources_tbl(l_current_record).primary_flag;
6201 x_assign_resources_tbl(l_count).resource_source :=
6202 l_assign_resources_tbl(l_current_record).resource_source;
6203 end if;
6204 close check_date_cur;
6205 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
6206 END LOOP;
6207
6208 ELSE -- Auto Select Flag is NO
6209
6210 WHILE l_current_record <= l_assign_resources_tbl.LAST
6211 LOOP
6212
6213 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
6214 l_assign_resources_tbl(l_current_record).resource_type);
6215 fetch check_date_cur into l_value;
6216 if (check_date_cur%found)
6217 then
6218 l_count := l_count + 1;
6219
6220 x_assign_resources_tbl(l_count).terr_rsc_id :=
6221 l_assign_resources_tbl(l_current_record).terr_rsc_id;
6222 x_assign_resources_tbl(l_count).resource_id :=
6223 l_assign_resources_tbl(l_current_record).resource_id;
6224 x_assign_resources_tbl(l_count).resource_type :=
6225 l_assign_resources_tbl(l_current_record).resource_type;
6226 x_assign_resources_tbl(l_count).role :=
6227 l_assign_resources_tbl(l_current_record).role;
6228 x_assign_resources_tbl(l_count).start_date :=
6229 l_assign_resources_tbl(l_current_record).start_date;
6230 x_assign_resources_tbl(l_count).end_date :=
6231 l_assign_resources_tbl(l_current_record).end_date;
6232 x_assign_resources_tbl(l_count).shift_construct_id :=
6233 l_assign_resources_tbl(l_current_record).shift_construct_id;
6234 x_assign_resources_tbl(l_count).terr_id :=
6235 l_assign_resources_tbl(l_current_record).terr_id;
6236 x_assign_resources_tbl(l_count).terr_name :=
6237 l_assign_resources_tbl(l_current_record).terr_name;
6238 x_assign_resources_tbl(l_count).preference_type :=
6239 l_assign_resources_tbl(l_current_record).preference_type;
6240 x_assign_resources_tbl(l_count).primary_contact_flag :=
6241 l_assign_resources_tbl(l_current_record).primary_contact_flag;
6242 x_assign_resources_tbl(l_count).group_id :=
6243 l_assign_resources_tbl(l_current_record).group_id;
6244
6245 x_assign_resources_tbl(l_count).support_site_id :=
6246 l_assign_resources_tbl(l_current_record).support_site_id;
6247 x_assign_resources_tbl(l_count).support_site_name :=
6248 l_assign_resources_tbl(l_current_record).support_site_name;
6249 x_assign_resources_tbl(l_count).web_availability_flag :=
6250 l_assign_resources_tbl(l_current_record).web_availability_flag;
6251
6252 x_assign_resources_tbl(l_count).skill_level :=
6253 l_assign_resources_tbl(l_current_record).skill_level;
6254 x_assign_resources_tbl(l_count).skill_name :=
6255 l_assign_resources_tbl(l_current_record).skill_name;
6256 x_assign_resources_tbl(l_count).primary_flag :=
6257 l_assign_resources_tbl(l_current_record).primary_flag;
6258 x_assign_resources_tbl(l_count).resource_source :=
6259 l_assign_resources_tbl(l_current_record).resource_source;
6260 end if;
6261 close check_date_cur;
6262 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
6263 END LOOP;
6264 END IF; -- Auto Select Flag
6265
6266 ELSE
6267 -- No resources returned from the Assignment Manager API for SERVICE REQUESTS
6268 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
6269 fnd_msg_pub.add;
6270 END IF;
6271
6272
6273 -- Raise Workflow Event
6274 -- Workflow Test
6275 Begin
6276 jtf_assign_pub.g_assign_resources_tbl.delete;
6277 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
6278 jtf_am_wf_events_pub.assign_dr_resource
6279 (P_API_VERSION => 1.0,
6280 P_INIT_MSG_LIST => 'F',
6281 P_COMMIT => 'F',
6282 P_CONTRACT_ID => p_contract_id ,
6283 P_CUSTOMER_PRODUCT_ID => p_customer_product_id ,
6284 P_CATEGORY_ID => p_category_id ,
6285 P_INVENTORY_ITEM_ID => p_inventory_item_id ,
6286 P_INVENTORY_ORG_ID => p_inventory_org_id ,
6287 P_PROBLEM_CODE => p_problem_code ,
6288 P_DR_REC => p_dr_rec,
6289 P_BUSINESS_PROCESS_ID => p_business_process_id,
6290 P_BUSINESS_PROCESS_DATE => p_business_process_date,
6291 X_RETURN_STATUS => l_wf_return_status,
6292 X_MSG_COUNT => l_wf_msg_count,
6293 X_MSG_DATA => l_wf_msg_data
6294 );
6295
6296
6297 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
6298 -- Unexpected Execution Error from call to assign_dr_resource
6299 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
6300 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
6301 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
6302 fnd_msg_pub.add;
6303
6304 ELSE
6305 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
6306 END IF;
6307
6308
6309 Exception
6310 When Others Then
6311 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
6312 fnd_message.set_token('P_SQLCODE',SQLCODE);
6313 fnd_message.set_token('P_SQLERRM',SQLERRM);
6314 fnd_message.set_token('P_API_NAME',l_api_name);
6315 FND_MSG_PUB.add;
6316 End;
6317
6318
6319
6320 -- To Plugin the Workflow enabling the user
6321 -- to further filter the resources
6322
6323 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
6324 FROM dual;
6325
6326 IF (JTF_USR_HKS.ok_to_execute
6327 (
6328 'JTF_ASSIGN_PUB',
6329 'GET_ASSIGN_DR_RESOURCES',
6330 'W',
6331 'W'
6332 )
6333 ) THEN
6334
6335 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
6336 (
6337 p_api_version => l_api_version,
6338 p_init_msg_list => p_init_msg_list,
6339 x_return_status => x_return_status,
6340 x_msg_count => x_msg_count,
6341 x_msg_data => x_msg_data
6342 )
6343 ) THEN
6344
6345
6346 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
6347 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
6348 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
6349 fnd_msg_pub.add;
6350 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
6351 RAISE fnd_api.g_exc_error;
6352 ELSE
6353 RAISE fnd_api.g_exc_unexpected_error;
6354 END IF;
6355 END IF;
6356
6357
6358 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
6359
6360 JTF_USR_HKS.WrkFlowLaunch
6361 (
6362 'JTF_ASSIGN_WF',
6363 l_workflow_profile,
6364 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
6365 l_bind_data_id,
6366 l_return_code
6367 );
6368
6369 JTF_USR_HKS.purge_bind_data
6370 (
6371 l_bind_data_id,
6372 'W'
6373 );
6374
6375
6376 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
6377 -- Execution Error from call to Assignment Manager Workflow Hook
6378 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
6379 fnd_msg_pub.add;
6380 RAISE fnd_api.g_exc_error;
6381 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
6382 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
6383 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
6384 fnd_msg_pub.add;
6385 RAISE fnd_api.g_exc_unexpected_error;
6386 END IF;
6387
6388 END IF; -- End of JTF_ASSIGN_CUHK
6389
6390 END IF; -- End of JTF_USR_HKS
6391
6392
6393 /* Standard call to get message count and
6394 the message information */
6395
6396 FND_MSG_PUB.Count_And_Get
6397 (
6398 p_count => x_msg_count,
6399 p_data => x_msg_data
6400 );
6401
6402
6403 x_return_status := fnd_api.g_ret_sts_success;
6404
6405 EXCEPTION
6406 WHEN FND_API.G_EXC_ERROR THEN
6407 x_return_status := FND_API.G_RET_STS_ERROR ;
6408 FND_MSG_PUB.Count_And_Get
6409 (
6410 p_count => x_msg_count,
6411 p_data => x_msg_data
6412 );
6413
6414 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6415 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6416 FND_MSG_PUB.Count_And_Get
6417 (
6418 p_count => x_msg_count,
6419 p_data => x_msg_data
6420 );
6421
6422 WHEN OTHERS THEN
6423 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
6424 fnd_message.set_token('P_SQLCODE',SQLCODE);
6425 fnd_message.set_token('P_SQLERRM',SQLERRM);
6426 fnd_message.set_token('P_API_NAME',l_api_name);
6427 FND_MSG_PUB.add;
6428
6429 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6430 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
6431 FND_MSG_PUB.Add_Exc_Msg
6432 (
6433 G_PKG_NAME,
6434 l_api_name
6435 );
6436 END IF;
6437
6438 FND_MSG_PUB.Count_And_Get
6439 (
6440 p_count => x_msg_count,
6441 p_data => x_msg_data
6442 );
6443
6444 END GET_ASSIGN_DR_RESOURCES;
6445
6446 /*************** End of addition by SBARAT on 01/11/2004 for Enh-3919046*********/
6447
6448
6449 -- *******************************************************************************
6450
6451 -- Start of comments
6452
6453 -- API name : GET_ASSIGN_OPPR_RESOURCES
6454 -- Type : Public
6455 -- Function : Determine the resources based on the customer
6456 -- preferences or territory preferences and the
6457 -- availability. This is when the calling doc is
6458 -- OPPORTUNITIES.
6459 -- Pre-reqs : None
6460
6461 -- Parameters :
6462
6463 -- IN : p_api_version IN NUMBER Required
6464 -- p_init_msg_list IN VARCHAR2 Optional
6465 -- DEFAULT = FND_API.G_FALSE
6466 -- p_commit IN VARCHAR2 optional
6467 -- DEFAULT = FND_API.G_FALSE
6468
6469 -- Assignment Manager Specific Parameters
6470
6471 -- This determines the Resource Type required by the
6472 -- calling document
6473 -- p_resource_type VARCHAR2(30)
6474 -- p_role VARCHAR2(30)
6475
6476 -- This determines the number of resources required
6477 -- by the calling document
6478 -- p_no_of_resources NUMBER,
6479
6480 -- This is for sending out the qualified resource directly
6481 -- to the calling form. Defaulted to the PROFILE value
6482 -- p_auto_select_flag VARCHAR2(1)
6483 -- : value of Y or N
6484
6485 -- The Effort required is determined by these two parameters
6486 -- p_effort_duration NUMBER
6487 -- p_effort_uom VARCHAR2(10)
6488
6489 -- The Dates in which the resource is required, is determined
6490 -- by these two parameters
6491 -- p_start_date DATE
6492 -- p_end_date DATE
6493
6494 -- The Territory Manager is accessed based on the value set
6495 -- p_territory_flag VARCHAR2(1)
6496 -- : value of Y or N
6497
6498 -- The Resource Availability is checked based on the value set
6499 -- p_calendar_flag VARCHAR2(1)
6500 -- : value of Y or N
6501
6502
6503 -- This parameter contains the Qualifier values for the
6504 -- Calling Document.
6505 -- p_opportunity_rec JTF_ASSIGN_PUB.
6506 -- JTF_Oppor_rec_type
6507 -- REQUIRED
6508
6509
6510 -- OUT : x_return_status OUT VARCHAR2(1)
6511 -- x_msg_count OUT NUMBER
6512 -- x_msg_data OUT VARCHAR2(2000)
6513 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
6514 -- AssignResources_tbl_type
6515
6516
6517 -- Version : Current version 1.0
6518 -- Initial version 1.0
6519 --
6520 -- Notes :
6521 --
6522
6523 -- End of comments
6524
6525 -- *********************************************************************************
6526
6527
6528
6529 -- Procedure definition with the parameters when the
6530 -- Source Document is OPPORTUNITIES
6531
6532 PROCEDURE GET_ASSIGN_OPPR_RESOURCES
6533 (
6534 p_api_version IN NUMBER,
6535 p_init_msg_list IN VARCHAR2 ,
6536 p_resource_type IN VARCHAR2 ,
6537 p_role IN VARCHAR2 ,
6538 p_no_of_resources IN NUMBER ,
6539 p_auto_select_flag IN VARCHAR2 ,
6540 p_effort_duration IN NUMBER ,
6541 p_effort_uom IN VARCHAR2 ,
6542 p_start_date IN DATE ,
6543 p_end_date IN DATE ,
6544 p_territory_flag IN VARCHAR2,
6545 p_calendar_flag IN VARCHAR2,
6546 p_opportunity_rec IN JTF_ASSIGN_PUB.JTF_Oppor_rec_type,
6547 p_business_process_id IN NUMBER,
6548 p_business_process_date IN DATE,
6549 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
6550 x_return_status OUT NOCOPY VARCHAR2,
6551 x_msg_count OUT NOCOPY NUMBER,
6552 x_msg_data OUT NOCOPY VARCHAR2
6553 )
6554 IS
6555
6556 l_return_status_1 VARCHAR2(10);
6557 l_api_name VARCHAR2(100) := 'GET_ASSIGN_OPPR_RESOURCES';
6558 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_OPPR_RESOURCES';
6559 l_api_version NUMBER := 1.0;
6560 l_planned_start_date DATE;
6561 l_planned_end_date DATE;
6562 l_effort_duration NUMBER;
6563 l_effort_uom VARCHAR2(30);
6564 l_travel_time NUMBER := 0;
6565 l_travel_uom VARCHAR2(30) := 'HR';
6566
6567 l_current_record INTEGER;
6568 l_total_records INTEGER;
6569
6570 l_auto_select_profile VARCHAR2(03);
6571 l_auto_select_flag VARCHAR2(03);
6572 l_workflow_profile VARCHAR2(60);
6573
6574 l_return_code VARCHAR2(60);
6575 l_bind_data_id NUMBER;
6576 l_workflow_key NUMBER;
6577
6578 l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
6579 l_opportunity_rec JTF_TERRITORY_PUB.JTF_Oppor_rec_type;
6580
6581 l_x_planned_start_date DATE;
6582 l_x_planned_end_date DATE;
6583 l_x_shift_construct_id NUMBER;
6584 l_x_availability_type VARCHAR2(60);
6585
6586 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
6587
6588 l_wf_return_status VARCHAR2(60);
6589 l_wf_msg_count NUMBER;
6590 l_wf_msg_data VARCHAR2(2000);
6591
6592 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
6593
6594 /*
6595 l_dynamic_sql VARCHAR2(2000);
6596 l_column_list VARCHAR2(2000);
6597 TYPE OPPR_CUR_TYP IS REF CURSOR;
6598 cur_oppr OPPR_CUR_TYP;
6599 */
6600
6601 --Bug# 4455803 MOAC.
6602 CURSOR check_date_cur(l_resource_id in number,
6603 l_resource_type in varchar2)
6604 IS
6605 SELECT 'Y'
6606 --FROM jtf_rs_all_resources_vl
6607 FROM jtf_task_resources_vl
6608 where resource_id = l_resource_id
6609 and resource_type = l_resource_type
6610 and nvl(trunc(end_date_active), trunc(sysdate)) >= trunc(sysdate);
6611
6612 l_value varchar2(100);
6613
6614 l_count number := 0;
6615 l_temp_table JTF_ASSIGN_PUB.AssignResources_tbl_type;
6616
6617 BEGIN
6618
6619 SAVEPOINT get_assign_oppr_resources;
6620
6621 -- Started Assignment Manager API for OPPORTUNITIES
6622
6623
6624 /* Standard call to check for call compatibility */
6625
6626 IF NOT fnd_api.compatible_api_call (l_api_version,
6627 p_api_version,
6628 l_api_name,
6629 g_pkg_name) THEN
6630 RAISE fnd_api.g_exc_unexpected_error;
6631 END IF;
6632
6633
6634 /* Initialize message list if p_init_msg_list is set to TRUE */
6635
6636 IF fnd_api.to_boolean (p_init_msg_list) THEN
6637 fnd_msg_pub.initialize;
6638 END IF;
6639
6640 x_return_status := fnd_api.g_ret_sts_success;
6641
6642
6643
6644 /* Getting the Auto Select Profile value defined for the Assignment Manager */
6645
6646 --l_auto_select_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_AUTO_SELECT' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
6647 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
6648
6649
6650
6651 /* Assigning the DEFAULT value to the Auto Select Parameter */
6652
6653
6654 IF (p_auto_select_flag IS NULL) THEN
6655 l_auto_select_flag := l_auto_select_profile;
6656 -- PROFILE VALUE is the default value
6657 ELSE
6658 l_auto_select_flag := p_auto_select_flag;
6659 END IF;
6660
6661
6662
6663 /* Query the Opportunities View to get the data into
6664 the Record Type to pass it to the Territory API */
6665
6666 /*
6667 IF (p_column_list IS NULL) THEN
6668 l_column_list := '*';
6669 ELSE
6670 l_column_list := p_column_list;
6671 END IF;
6672
6673
6674 l_dynamic_sql := 'SELECT '||
6675 l_column_list||
6676 ' FROM jtf_terr_opportunities_v'||
6677 ' WHERE lead_id = :1';
6678
6679 OPEN cur_oppr FOR l_dynamic_sql USING p_opportunity_id;
6680 FETCH cur_oppr INTO l_assign_resources_rec;
6681 IF (cur_oppr%NOTFOUND) THEN
6682 fnd_message.set_name('JTF', 'JTF_AM_INVALID_OPPR_ID');
6683 fnd_msg_pub.add;
6684 RAISE fnd_api.g_exc_error;
6685 END IF;
6686 CLOSE cur_oppr;
6687 */
6688
6689
6690
6691 /* Defaulting the variable values to IN parameters,
6692 if the IN paramaters have values given */
6693
6694 IF (p_start_date IS NOT NULL) THEN
6695 l_planned_start_date := p_start_date;
6696 ELSE
6697 l_planned_start_date := SYSDATE;
6698 END IF;
6699
6700 IF (p_end_date IS NOT NULL) THEN
6701 l_planned_end_date := p_end_date;
6702 ELSE
6703 l_planned_end_date := SYSDATE;
6704 END IF;
6705
6706 IF (p_effort_duration IS NOT NULL) THEN
6707 l_effort_duration := p_effort_duration;
6708 END IF;
6709
6710 IF (p_effort_uom IS NOT NULL) THEN
6711 l_effort_uom := p_effort_uom;
6712 END IF;
6713
6714
6715
6716 /* Assigning values to the Opportunity Record Type */
6717
6718
6719 l_opportunity_rec.LEAD_ID := p_opportunity_rec.LEAD_ID;
6720 l_opportunity_rec.LEAD_LINE_ID := p_opportunity_rec.LEAD_LINE_ID;
6721 l_opportunity_rec.CITY := p_opportunity_rec.CITY;
6722 l_opportunity_rec.POSTAL_CODE := p_opportunity_rec.POSTAL_CODE;
6723 l_opportunity_rec.STATE := p_opportunity_rec.STATE;
6724 l_opportunity_rec.PROVINCE := p_opportunity_rec.PROVINCE;
6725 l_opportunity_rec.COUNTY := p_opportunity_rec.COUNTY;
6726 l_opportunity_rec.COUNTRY := p_opportunity_rec.COUNTRY;
6727 l_opportunity_rec.INTEREST_TYPE_ID := p_opportunity_rec.INTEREST_TYPE_ID;
6728 l_opportunity_rec.PRIMARY_INTEREST_ID := p_opportunity_rec.PRIMARY_INTEREST_ID;
6729 l_opportunity_rec.SECONDARY_INTEREST_ID := p_opportunity_rec.SECONDARY_INTEREST_ID;
6730 l_opportunity_rec.CONTACT_INTEREST_TYPE_ID := p_opportunity_rec.CONTACT_INTEREST_TYPE_ID;
6731 l_opportunity_rec.CONTACT_PRIMARY_INTEREST_ID := p_opportunity_rec.CONTACT_PRIMARY_INTEREST_ID;
6732 l_opportunity_rec.CONTACT_SECONDARY_INTEREST_ID := p_opportunity_rec.CONTACT_SECONDARY_INTEREST_ID;
6733 l_opportunity_rec.PARTY_SITE_ID := p_opportunity_rec.PARTY_SITE_ID;
6734 l_opportunity_rec.AREA_CODE := p_opportunity_rec.AREA_CODE;
6735 l_opportunity_rec.PARTY_ID := p_opportunity_rec.PARTY_ID;
6736 l_opportunity_rec.COMP_NAME_RANGE := p_opportunity_rec.COMP_NAME_RANGE;
6737 l_opportunity_rec.PARTNER_ID := p_opportunity_rec.PARTNER_ID;
6738 l_opportunity_rec.NUM_OF_EMPLOYEES := p_opportunity_rec.NUM_OF_EMPLOYEES;
6739 l_opportunity_rec.CATEGORY_CODE := p_opportunity_rec.CATEGORY_CODE;
6740 l_opportunity_rec.PARTY_RELATIONSHIP_ID := p_opportunity_rec.PARTY_RELATIONSHIP_ID;
6741 l_opportunity_rec.SIC_CODE := p_opportunity_rec.SIC_CODE;
6742 l_opportunity_rec.TARGET_SEGMENT_CURRENT := p_opportunity_rec.TARGET_SEGMENT_CURRENT;
6743 l_opportunity_rec.TOTAL_AMOUNT := p_opportunity_rec.TOTAL_AMOUNT;
6744 l_opportunity_rec.CURRENCY_CODE := p_opportunity_rec.CURRENCY_CODE;
6745 l_opportunity_rec.PRICING_DATE := p_opportunity_rec.PRICING_DATE;
6746 l_opportunity_rec.CHANNEL_CODE := p_opportunity_rec.CHANNEL_CODE;
6747 l_opportunity_rec.INVENTORY_ITEM_ID := p_opportunity_rec.INVENTORY_ITEM_ID;
6748 l_opportunity_rec.OPP_INTEREST_TYPE_ID := p_opportunity_rec.OPP_INTEREST_TYPE_ID;
6749 l_opportunity_rec.OPP_PRIMARY_INTEREST_ID := p_opportunity_rec.OPP_PRIMARY_INTEREST_ID;
6750 l_opportunity_rec.OPP_SECONDARY_INTEREST_ID := p_opportunity_rec.OPP_SECONDARY_INTEREST_ID;
6751 l_opportunity_rec.OPCLSS_INTEREST_TYPE_ID := p_opportunity_rec.OPCLSS_INTEREST_TYPE_ID;
6752 l_opportunity_rec.OPCLSS_PRIMARY_INTEREST_ID := p_opportunity_rec.OPCLSS_PRIMARY_INTEREST_ID;
6753 l_opportunity_rec.OPCLSS_SECONDARY_INTEREST_ID := p_opportunity_rec.OPCLSS_SECONDARY_INTEREST_ID;
6754 l_opportunity_rec.ATTRIBUTE1 := p_opportunity_rec.ATTRIBUTE1;
6755 l_opportunity_rec.ATTRIBUTE2 := p_opportunity_rec.ATTRIBUTE2;
6756 l_opportunity_rec.ATTRIBUTE3 := p_opportunity_rec.ATTRIBUTE3;
6757 l_opportunity_rec.ATTRIBUTE4 := p_opportunity_rec.ATTRIBUTE4;
6758 l_opportunity_rec.ATTRIBUTE5 := p_opportunity_rec.ATTRIBUTE5;
6759 l_opportunity_rec.ATTRIBUTE6 := p_opportunity_rec.ATTRIBUTE6;
6760 l_opportunity_rec.ATTRIBUTE7 := p_opportunity_rec.ATTRIBUTE7;
6761 l_opportunity_rec.ATTRIBUTE8 := p_opportunity_rec.ATTRIBUTE8;
6762 l_opportunity_rec.ATTRIBUTE9 := p_opportunity_rec.ATTRIBUTE9;
6763 l_opportunity_rec.ATTRIBUTE10 := p_opportunity_rec.ATTRIBUTE10;
6764 l_opportunity_rec.ATTRIBUTE11 := p_opportunity_rec.ATTRIBUTE11;
6765 l_opportunity_rec.ATTRIBUTE12 := p_opportunity_rec.ATTRIBUTE12;
6766 l_opportunity_rec.ATTRIBUTE13 := p_opportunity_rec.ATTRIBUTE13;
6767 l_opportunity_rec.ATTRIBUTE14 := p_opportunity_rec.ATTRIBUTE14;
6768 l_opportunity_rec.ATTRIBUTE15 := p_opportunity_rec.ATTRIBUTE15;
6769 l_opportunity_rec.ORG_ID := p_opportunity_rec.ORG_ID;
6770
6771
6772
6773
6774
6775 /* Actual Flow of Assignment Manager */
6776
6777
6778 IF (p_territory_flag = 'Y') THEN
6779
6780 -- change the API Name temporarily so that in case of unexpected error
6781 -- it is properly caught
6782 l_api_name := l_api_name||'-JTF_TERR_SALES_PUB';
6783
6784 JTF_TERR_SALES_PUB.Get_WinningTerrMembers
6785 (
6786 p_api_version_number => l_api_version,
6787 p_init_msg_list => p_init_msg_list,
6788 p_TerrOppor_Rec => l_opportunity_rec,
6789 p_Resource_Type => p_resource_type,
6790 p_Role => p_role,
6791 x_return_status => x_return_status,
6792 x_msg_count => x_msg_count,
6793 x_msg_data => x_msg_data,
6794 x_TerrResource_tbl => l_assign_resources_tbl
6795 );
6796
6797 -- set back the API name to original name
6798 l_api_name := l_api_name_1;
6799
6800
6801 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
6802 -- Unexpected Execution Error from call to Territory Manager
6803 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
6804 fnd_msg_pub.add;
6805 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
6806 RAISE fnd_api.g_exc_error;
6807 ELSE
6808 RAISE fnd_api.g_exc_unexpected_error;
6809 END IF;
6810 END IF;
6811
6812
6813 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
6814
6815 IF(l_assign_resources_tbl.COUNT > 0)
6816 THEN
6817 l_current_record := l_assign_resources_tbl.FIRST;
6818 WHILE l_current_record <= l_assign_resources_tbl.LAST
6819 LOOP
6820 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
6821 THEN
6822 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
6823 END IF;
6824 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
6825 END LOOP;
6826 END IF;
6827
6828 IF l_assign_resources_tbl.COUNT > 0 THEN
6829
6830 l_current_record := l_assign_resources_tbl.FIRST;
6831
6832 -- removed the calendar check here. calling the procedure for calendar check in the next step
6833 -- calendar check removed 29th September 2003
6834
6835 WHILE l_current_record <= l_assign_resources_tbl.LAST
6836 LOOP
6837 -- Check the calendar for resource availability
6838 -- Call Calendar API
6839 -- IF the resource is available then accept the values and
6840 -- check for the WORKFLOW profile option
6841
6842 -- The following IF statement is to implement Auto Select Feature
6843 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
6844 l_assign_resources_tbl(l_current_record).resource_type);
6845 fetch check_date_cur into l_value;
6846 if (check_date_cur%found)
6847 then
6848
6849 l_count := l_count + 1;
6850 x_assign_resources_tbl(l_count).terr_rsc_id :=
6851 l_assign_resources_tbl(l_current_record).terr_rsc_id;
6852 x_assign_resources_tbl(l_count).resource_id :=
6853 l_assign_resources_tbl(l_current_record).resource_id;
6854 x_assign_resources_tbl(l_count).resource_type :=
6855 l_assign_resources_tbl(l_current_record).resource_type;
6856 x_assign_resources_tbl(l_count).role :=
6857 l_assign_resources_tbl(l_current_record).role;
6858 x_assign_resources_tbl(l_count).start_date :=
6859 l_assign_resources_tbl(l_current_record).start_date;
6860 x_assign_resources_tbl(l_count).end_date :=
6861 l_assign_resources_tbl(l_current_record).end_date;
6862 x_assign_resources_tbl(l_count).shift_construct_id := NULL;
6863 x_assign_resources_tbl(l_count).terr_id :=
6864 l_assign_resources_tbl(l_current_record).terr_id;
6865 x_assign_resources_tbl(l_count).terr_name :=
6866 l_assign_resources_tbl(l_current_record).terr_name;
6867 x_assign_resources_tbl(l_count).primary_contact_flag :=
6868 l_assign_resources_tbl(l_current_record).primary_contact_flag;
6869 x_assign_resources_tbl(l_count).full_access_flag :=
6870 l_assign_resources_tbl(l_current_record).full_access_flag;
6871 x_assign_resources_tbl(l_count).group_id :=
6872 l_assign_resources_tbl(l_current_record).group_id;
6873 x_assign_resources_tbl(l_count).primary_flag :=
6874 l_assign_resources_tbl(l_current_record).primary_contact_flag;
6875 x_assign_resources_tbl(l_count).resource_source := 'TERR';
6876
6877 END IF; -- end of check_date_cur
6878 close check_date_cur;
6879 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
6880 END LOOP;
6881
6882 -- added calendar call out
6883 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
6884 -- changed on 29th September 2003
6885 IF (p_calendar_flag = 'Y') THEN
6886 -- change the API Name temporarily so that in case of unexpected error
6887 -- it is properly caught
6888 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
6889 l_return_status_1 := x_return_status ;
6890 -- call the api to check resource availability
6891 get_available_resources
6892 (
6893 p_init_msg_list => 'F',
6894 p_calendar_flag => p_calendar_flag,
6895 p_effort_duration => l_effort_duration,
6896 p_effort_uom => l_effort_uom,
6897 p_planned_start_date => l_planned_start_date,
6898 p_planned_end_date => l_planned_end_date,
6899 p_continuous_task => jtf_assign_pub.g_continuous_work,
6900 x_return_status => x_return_status,
6901 x_msg_count => x_msg_count,
6902 x_msg_data => x_msg_data,
6903 x_assign_resources_tbl => x_assign_resources_tbl);
6904
6905 -- set back the API name to original name
6906 l_api_name := l_api_name_1;
6907
6908 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
6909 -- Unexpected Execution Error from call to Get_contracts_resources
6910 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
6911 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
6912 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_OPPR_RESOURCES');
6913 fnd_msg_pub.add;
6914 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
6915 RAISE fnd_api.g_exc_error;
6916 ELSE
6917 RAISE fnd_api.g_exc_unexpected_error;
6918 END IF;
6919 END IF; -- end of x_return_status check
6920 end if; -- if p_calendar_flag = Y
6921
6922 IF ( p_calendar_flag = 'Y' AND
6923 x_assign_resources_tbl.count = 0 ) THEN
6924 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
6925 fnd_msg_pub.add;
6926 -- RAISE fnd_api.g_exc_error;
6927 END IF;
6928
6929 -- check auto assignment
6930 -- if auto assignment is Y then return only the number of resources that have been requested
6931 IF(l_auto_select_flag = 'Y')
6932 THEN
6933 l_temp_table.delete;
6934 l_temp_table := x_assign_resources_tbl;
6935 x_assign_resources_tbl.delete;
6936 l_count := 0;
6937 l_current_record := l_temp_table.FIRST;
6938 l_total_records := p_no_of_resources;
6939
6940 WHILE l_current_record <= l_temp_table.LAST
6941 LOOP
6942 If(l_count < l_total_records)
6943 THEN
6944 x_assign_resources_tbl(l_count) := l_temp_table(l_current_record);
6945 l_count := l_count + 1;
6946 end if; -- end of count check
6947 l_current_record := l_temp_table.NEXT(l_current_record);
6948 END LOOP; -- end of courrent record check
6949
6950 END IF; -- end of auto select flag
6951
6952 ELSE -- No resources returned from the Territory API
6953 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
6954 fnd_msg_pub.add;
6955 -- RAISE fnd_api.g_exc_error;
6956 END IF;
6957
6958 ELSE -- Territory Flag is NO
6959 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
6960 fnd_msg_pub.add;
6961 -- RAISE fnd_api.g_exc_error;
6962 END IF;
6963
6964 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
6965
6966 -- raise workfow event
6967 -- workflow test
6968 Begin
6969 jtf_assign_pub.g_assign_resources_tbl.delete;
6970 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
6971 jtf_am_wf_events_pub.assign_oppr_resource
6972 (P_API_VERSION => 1.0,
6973 P_INIT_MSG_LIST => 'F',
6974 P_COMMIT => 'F',
6975 P_OPPR_REC => p_opportunity_rec,
6976 P_BUSINESS_PROCESS_ID => p_business_process_id,
6977 P_BUSINESS_PROCESS_DATE => p_business_process_date,
6978 X_RETURN_STATUS => l_wf_return_status,
6979 X_MSG_COUNT => l_wf_msg_count,
6980 X_MSG_DATA => l_wf_msg_data
6981 );
6982
6983
6984 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
6985 -- Unexpected Execution Error from call to assign_sr_resource
6986 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
6987 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
6988 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_OPPR_RESOURCES');
6989 fnd_msg_pub.add;
6990
6991 ELSE
6992 x_assign_resources_tbl.delete;
6993 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
6994 END IF;
6995
6996
6997 Exception
6998 When OTHERS Then
6999 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
7000 fnd_message.set_token('P_SQLCODE',SQLCODE);
7001 fnd_message.set_token('P_SQLERRM',SQLERRM);
7002 fnd_message.set_token('P_API_NAME',l_api_name);
7003 FND_MSG_PUB.add;
7004 End;
7005
7006 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7007
7008
7009 -- To Plugin the Workflow enabling the user
7010 -- to further filter the resources
7011
7012 /* Getting the Workflow Profile value defined for the Assignment Manager */
7013
7014 --l_workflow_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_WORKFLOW_NAME' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
7015 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
7016
7017 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
7018 FROM dual;
7019
7020 IF (JTF_USR_HKS.ok_to_execute
7021 (
7022 'JTF_ASSIGN_PUB',
7023 'GET_ASSIGN_OPPR_RESOURCES',
7024 'W',
7025 'W'
7026 )
7027 ) THEN
7028
7029 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
7030 (
7031 p_api_version => l_api_version,
7032 p_init_msg_list => p_init_msg_list,
7033 x_return_status => x_return_status,
7034 x_msg_count => x_msg_count,
7035 x_msg_data => x_msg_data
7036 )
7037 ) THEN
7038
7039 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
7040 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
7041 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
7042 fnd_msg_pub.add;
7043 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
7044 RAISE fnd_api.g_exc_error;
7045 ELSE
7046 RAISE fnd_api.g_exc_unexpected_error;
7047 END IF;
7048 END IF;
7049
7050 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
7051
7052 JTF_USR_HKS.WrkFlowLaunch
7053 (
7054 'JTF_ASSIGN_WF',
7055 l_workflow_profile,
7056 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
7057 l_bind_data_id,
7058 l_return_code
7059 );
7060
7061 JTF_USR_HKS.purge_bind_data
7062 (
7063 l_bind_data_id,
7064 'W'
7065 );
7066
7067 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
7068 -- Execution Error from call to Assignment Manager Workflow Hook
7069 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
7070 fnd_msg_pub.add;
7071 RAISE fnd_api.g_exc_error;
7072 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
7073 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
7074 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
7075 fnd_msg_pub.add;
7076 RAISE fnd_api.g_exc_unexpected_error;
7077 END IF;
7078
7079 END IF; -- End of JTF_ASSIGN_CUHK
7080
7081 END IF; -- End of JTF_USR_HKS
7082
7083
7084
7085
7086
7087 /* Standard call to get message count and
7088 the message information */
7089
7090 FND_MSG_PUB.Count_And_Get
7091 (
7092 p_count => x_msg_count,
7093 p_data => x_msg_data
7094 );
7095
7096
7097
7098 EXCEPTION
7099 WHEN FND_API.G_EXC_ERROR THEN
7100 x_return_status := FND_API.G_RET_STS_ERROR ;
7101 FND_MSG_PUB.Count_And_Get
7102 (
7103 p_count => x_msg_count,
7104 p_data => x_msg_data
7105 );
7106
7107 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7108 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7109 FND_MSG_PUB.Count_And_Get
7110 (
7111 p_count => x_msg_count,
7112 p_data => x_msg_data
7113 );
7114
7115 WHEN OTHERS THEN
7116 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
7117 fnd_message.set_token('P_SQLCODE',SQLCODE);
7118 fnd_message.set_token('P_SQLERRM',SQLERRM);
7119 fnd_message.set_token('P_API_NAME',l_api_name);
7120 FND_MSG_PUB.add;
7121
7122 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7123 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
7124 FND_MSG_PUB.Add_Exc_Msg
7125 (
7126 G_PKG_NAME,
7127 l_api_name
7128 );
7129 END IF;
7130
7131 FND_MSG_PUB.Count_And_Get
7132 (
7133 p_count => x_msg_count,
7134 p_data => x_msg_data
7135 );
7136
7137 END GET_ASSIGN_OPPR_RESOURCES;
7138
7139
7140
7141 -- *******************************************************************************
7142
7143 -- Start of comments
7144
7145 -- API name : GET_ASSIGN_LEAD_RESOURCES (For BULK Record)
7146 -- Type : Public
7147 -- Function : Determine the resources based on the customer
7148 -- preferences or territory preferences and the
7149 -- availability. This is when the calling doc is
7150 -- LEADS.
7151 -- Pre-reqs : None
7152
7153 -- Parameters :
7154
7155 -- IN : p_api_version IN NUMBER Required
7156 -- p_init_msg_list IN VARCHAR2 Optional
7157 -- DEFAULT JTF_ASSIGN_PUB.AM_FALSE
7158 -- p_commit IN VARCHAR2 optional
7159 -- DEFAULT JTF_ASSIGN_PUB.AM_FALSE
7160
7161 -- Assignment Manager Specific Parameters
7162
7163 -- This determines the Resource Type required by the
7164 -- calling document
7165 -- p_resource_type VARCHAR2(30)
7166 -- p_role VARCHAR2(30)
7167
7168 -- This determines the number of resources required
7169 -- by the calling document
7170 -- p_no_of_resources NUMBER,
7171
7172 -- This is for sending out the qualified resource directly
7173 -- to the calling form. Defaulted to the PROFILE value
7174 -- p_auto_select_flag VARCHAR2(1)
7175 -- : value of Y or N
7176
7177 -- The Effort required is determined by these two parameters
7178 -- p_effort_duration NUMBER
7179 -- p_effort_uom VARCHAR2(10)
7180
7181 -- The Dates in which the resource is required, is determined
7182 -- by these two parameters
7183 -- p_start_date DATE
7184 -- p_end_date DATE
7185
7186 -- The Territory Manager is accessed based on the value set
7187 -- p_territory_flag VARCHAR2(1)
7188 -- : value of Y or N
7189
7190 -- The Resource Availability is checked based on the value set
7191 -- p_calendar_flag VARCHAR2(1)
7192 -- : value of Y or N
7193
7194
7195 -- This parameter contains the values of the Qualifiers
7196 -- defined for the Sales Leads.
7197 -- p_lead_rec JTF_TERRITORY_PUB.
7198 -- JTF_Lead_BULK_rec_type
7199 -- REQUIRED
7200
7201 -- OUT : x_return_status OUT VARCHAR2(1)
7202 -- x_msg_count OUT NUMBER
7203 -- x_msg_data OUT VARCHAR2(2000)
7204 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
7205 -- AssignResources_tbl_type
7206
7207
7208 -- Version : Current version 1.0
7209 -- Initial version 1.0
7210 --
7211 -- Notes :
7212 --
7213
7214 -- End of comments
7215
7216 -- *********************************************************************************
7217
7218
7219
7220 -- Procedure definition with the parameters when the
7221 -- Source Document is SALES LEADS
7222
7223 PROCEDURE GET_ASSIGN_LEAD_RESOURCES
7224 (
7225 p_api_version IN NUMBER,
7226 p_init_msg_list IN VARCHAR2 ,
7227 p_resource_type IN VARCHAR2 ,
7228 p_role IN VARCHAR2 ,
7229 p_no_of_resources IN NUMBER ,
7230 p_auto_select_flag IN VARCHAR2 ,
7231 p_effort_duration IN NUMBER ,
7232 p_effort_uom IN VARCHAR2 ,
7233 p_start_date IN DATE ,
7234 p_end_date IN DATE ,
7235 p_territory_flag IN VARCHAR2,
7236 p_calendar_flag IN VARCHAR2,
7237 p_lead_rec IN JTF_TERRITORY_PUB.JTF_Lead_BULK_rec_type,
7238 -- x_assign_resources_bulk_rec OUT NOCOPY JTF_TERRITORY_PUB.WINNING_BULK_REC_TYPE,
7239 p_business_process_id IN NUMBER,
7240 p_business_process_date IN DATE,
7241 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
7242 x_return_status OUT NOCOPY VARCHAR2,
7243 x_msg_count OUT NOCOPY NUMBER,
7244 x_msg_data OUT NOCOPY VARCHAR2
7245 )
7246 IS
7247
7248 l_return_status_1 VARCHAR2(10);
7249 l_api_name VARCHAR2(100) := 'GET_ASSIGN_LEAD_RESOURCES';
7250 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_LEAD_RESOURCES';
7251 l_api_version NUMBER := 1.0;
7252 l_planned_start_date DATE;
7253 l_planned_end_date DATE;
7254 l_effort_duration NUMBER;
7255 l_effort_uom VARCHAR2(30);
7256 l_travel_time NUMBER := 0;
7257 l_travel_uom VARCHAR2(30) := 'HR';
7258
7259 l_current_record INTEGER;
7260 l_total_records INTEGER;
7261
7262 l_auto_select_profile VARCHAR2(03);
7263 l_auto_select_flag VARCHAR2(03);
7264 l_workflow_profile VARCHAR2(60);
7265
7266 l_return_code VARCHAR2(60);
7267 l_bind_data_id NUMBER;
7268 l_workflow_key NUMBER;
7269
7270 l_assign_resources_bulk_rec JTF_TERRITORY_PUB.WINNING_BULK_REC_TYPE;
7271 --l_lead_rec JTF_TERRITORY_PUB.JTF_Lead_BULK_rec_type;
7272 --l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
7273
7274 l_x_planned_start_date DATE;
7275 l_x_planned_end_date DATE;
7276 l_x_shift_construct_id NUMBER;
7277 l_x_availability_type VARCHAR2(60);
7278
7279 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7280
7281 l_wf_return_status VARCHAR2(60);
7282 l_wf_msg_count NUMBER;
7283 l_wf_msg_data VARCHAR2(2000);
7284
7285 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7286
7287 --Bug# 4455803 MOAC.
7288 CURSOR check_date_cur(l_resource_id in number,
7289 l_resource_type in varchar2)
7290 IS
7291 SELECT 'Y'
7292 --FROM jtf_rs_all_resources_vl
7293 FROM jtf_task_resources_vl
7294 where resource_id = l_resource_id
7295 and resource_type = l_resource_type
7296 and nvl(trunc(end_date_active), trunc(sysdate)) >= trunc(sysdate);
7297
7298 l_value varchar2(100);
7299
7300 l_count number := 0;
7301 l_temp_table JTF_ASSIGN_PUB.AssignResources_tbl_type;
7302 BEGIN
7303
7304 SAVEPOINT get_assign_lead_resources;
7305
7306 -- Started Assignment Manager API for SALES LEADS
7307
7308
7309 /* Standard call to check for call compatibility */
7310
7311 IF NOT fnd_api.compatible_api_call (l_api_version,
7312 p_api_version,
7313 l_api_name,
7314 g_pkg_name) THEN
7315 RAISE fnd_api.g_exc_unexpected_error;
7316 END IF;
7317
7318
7319 /* Initialize message list if p_init_msg_list is set to TRUE */
7320
7321 IF fnd_api.to_boolean (p_init_msg_list) THEN
7322 fnd_msg_pub.initialize;
7323 END IF;
7324
7325 x_return_status := fnd_api.g_ret_sts_success;
7326
7327
7328
7329 /* Getting the Auto Select Profile value defined for the Assignment Manager */
7330
7331 --l_auto_select_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_AUTO_SELECT' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
7332 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
7333
7334
7335
7336 /* Assigning the DEFAULT value to the Auto Select Parameter */
7337
7338
7339 IF (p_auto_select_flag IS NULL) THEN
7340 l_auto_select_flag := l_auto_select_profile;
7341 -- PROFILE VALUE is the default value
7342 ELSE
7343 l_auto_select_flag := p_auto_select_flag;
7344 END IF;
7345
7346
7347
7348
7349 /* Defaulting the Calendar variable values to IN parameters,
7350 if the IN paramaters have values given */
7351
7352
7353 IF (p_start_date IS NOT NULL) THEN
7354 l_planned_start_date := p_start_date;
7355 ELSE
7356 l_planned_start_date := SYSDATE;
7357 END IF;
7358
7359 IF (p_end_date IS NOT NULL) THEN
7360 l_planned_end_date := p_end_date;
7361 ELSE
7362 l_planned_end_date := SYSDATE;
7363 END IF;
7364
7365 IF (p_effort_duration IS NOT NULL) THEN
7366 l_effort_duration := p_effort_duration;
7367 END IF;
7368
7369 IF (p_effort_uom IS NOT NULL) THEN
7370 l_effort_uom := p_effort_uom;
7371 END IF;
7372
7373
7374
7375
7376 /* Actual Flow of Assignment Manager */
7377
7378
7379 IF (p_territory_flag = 'Y') THEN
7380
7381 -- change the API Name temporarily so that in case of unexpected error
7382 -- it is properly caught
7383 l_api_name := l_api_name||'-JTF_TERR_SALES_PUB';
7384
7385 JTF_TERR_SALES_PUB.Get_WinningTerrMembers
7386 (
7387 p_api_version_number => l_api_version,
7388 p_init_msg_list => p_init_msg_list,
7389 p_TerrLead_Rec => p_lead_rec,
7390 p_Resource_Type => p_resource_type,
7391 p_Role => p_role,
7392 x_return_status => x_return_status,
7393 x_msg_count => x_msg_count,
7394 x_msg_data => x_msg_data,
7395 x_winners_rec => l_assign_resources_bulk_rec
7396 );
7397
7398 -- set back the API name to original name
7399 l_api_name := l_api_name_1;
7400
7401 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
7402 -- Unexpected Execution Error from call to Territory Manager
7403 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
7404 fnd_msg_pub.add;
7405 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
7406 RAISE fnd_api.g_exc_error;
7407 ELSE
7408 RAISE fnd_api.g_exc_unexpected_error;
7409 END IF;
7410 END IF;
7411
7412
7413 IF l_assign_resources_bulk_rec.terr_id.COUNT > 0 THEN
7414
7415 l_current_record := l_assign_resources_bulk_rec.terr_id.FIRST;
7416
7417
7418
7419 WHILE l_current_record <= l_assign_resources_bulk_rec.terr_id.LAST
7420 LOOP
7421 -- removed the calendar check here. calling the procedure for calendar check in the next step
7422 -- calendar check removed 29th September 2003
7423
7424 open check_date_cur(l_assign_resources_bulk_rec.resource_id(l_current_record),
7425 l_assign_resources_bulk_rec.resource_type(l_current_record));
7426 fetch check_date_cur into l_value;
7427 if (check_date_cur%found)
7428 then
7429
7430 l_count := l_count + 1;
7431 x_assign_resources_tbl(l_count).terr_rsc_id :=
7432 l_assign_resources_bulk_rec.terr_rsc_id(l_current_record);
7433 x_assign_resources_tbl(l_count).resource_id :=
7434 l_assign_resources_bulk_rec.resource_id(l_current_record);
7435 x_assign_resources_tbl(l_count).resource_type :=
7436 l_assign_resources_bulk_rec.resource_type(l_current_record);
7437 x_assign_resources_tbl(l_count).role :=
7438 l_assign_resources_bulk_rec.role(l_current_record);
7439
7440 x_assign_resources_tbl(l_count).start_date := NULL;
7441 -- l_assign_resources_bulk_rec.start_date(l_current_record);
7442 x_assign_resources_tbl(l_count).end_date := NULL;
7443 -- l_assign_resources_bulk_rec.end_date(l_current_record);
7444
7445 x_assign_resources_tbl(l_count).shift_construct_id := NULL;
7446
7447 x_assign_resources_tbl(l_count).terr_id :=
7448 l_assign_resources_bulk_rec.terr_id(l_current_record);
7449 x_assign_resources_tbl(l_count).terr_rank :=
7450 l_assign_resources_bulk_rec.absolute_rank(l_current_record);
7451 x_assign_resources_tbl(l_count).primary_contact_flag :=
7452 l_assign_resources_bulk_rec.primary_contact_flag(l_current_record);
7453 x_assign_resources_tbl(l_count).full_access_flag :=
7454 l_assign_resources_bulk_rec.full_access_flag(l_current_record);
7455 x_assign_resources_tbl(l_count).group_id :=
7456 l_assign_resources_bulk_rec.group_id(l_current_record);
7457 x_assign_resources_tbl(l_count).trans_object_id :=
7458 l_assign_resources_bulk_rec.trans_object_id(l_current_record);
7459 x_assign_resources_tbl(l_count).primary_flag :=
7460 l_assign_resources_bulk_rec.primary_contact_flag(l_current_record);
7461 x_assign_resources_tbl(l_count).resource_source := 'TERR';
7462
7463 END IF;
7464 close check_date_cur;
7465 l_current_record := l_current_record+1;
7466 --l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
7467 END LOOP;
7468
7469
7470 -- added calendar call out
7471 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
7472 -- changed on 29th September 2003
7473 IF (p_calendar_flag = 'Y') THEN
7474 -- change the API Name temporarily so that in case of unexpected error
7475 -- it is properly caught
7476 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
7477 l_return_status_1 := x_return_status ;
7478 -- call the api to check resource availability
7479 get_available_resources
7480 (
7481 p_init_msg_list => 'F',
7482 p_calendar_flag => p_calendar_flag,
7483 p_effort_duration => l_effort_duration,
7484 p_effort_uom => l_effort_uom,
7485 p_planned_start_date => l_planned_start_date,
7486 p_planned_end_date => l_planned_end_date,
7487 p_continuous_task => jtf_assign_pub.g_continuous_work,
7488 x_return_status => x_return_status,
7489 x_msg_count => x_msg_count,
7490 x_msg_data => x_msg_data,
7491 x_assign_resources_tbl => x_assign_resources_tbl);
7492
7493 -- set back the API name to original name
7494 l_api_name := l_api_name_1;
7495
7496 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
7497 -- Unexpected Execution Error from call to Get_contracts_resources
7498 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
7499 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
7500 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_LEAD_RESOURCES');
7501 fnd_msg_pub.add;
7502 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
7503 RAISE fnd_api.g_exc_error;
7504 ELSE
7505 RAISE fnd_api.g_exc_unexpected_error;
7506 END IF;
7507 END IF; -- end of x_return_status check
7508 end if; -- if p_calendar_flag = Y
7509
7510 IF ( p_calendar_flag = 'Y' AND
7511 x_assign_resources_tbl.count = 0 ) THEN
7512 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
7513 fnd_msg_pub.add;
7514 -- RAISE fnd_api.g_exc_error;
7515 END IF;
7516
7517
7518 -- If auto_select is Y then ensure correct number of resources are returned
7519 IF(l_auto_select_flag = 'Y')
7520 THEN
7521 l_temp_table.delete;
7522 l_temp_table := x_assign_resources_tbl;
7523 x_assign_resources_tbl.delete;
7524 l_count := 0;
7525 l_current_record := l_temp_table.FIRST;
7526 l_total_records := p_no_of_resources;
7527
7528 WHILE l_current_record <= l_temp_table.LAST
7529 LOOP
7530 If(l_count < l_total_records)
7531 THEN
7532 x_assign_resources_tbl(l_count) := l_temp_table(l_current_record);
7533 l_count := l_count + 1;
7534 end if; -- end of count check
7535 l_current_record := l_temp_table.NEXT(l_current_record);
7536 END LOOP; -- end of courrent record check
7537
7538 END IF; -- end of auto select flag
7539
7540 ELSE -- No resources returned from the Territory API
7541 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
7542 fnd_msg_pub.add;
7543 -- RAISE fnd_api.g_exc_error;
7544 END IF;
7545
7546 ELSE -- Territory Flag is NO
7547 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
7548 fnd_msg_pub.add;
7549 -- RAISE fnd_api.g_exc_error;
7550 END IF;
7551
7552 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7553
7554 -- raise workfow event
7555 -- workflow test
7556 Begin
7557 jtf_assign_pub.g_assign_resources_tbl.delete;
7558 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
7559 jtf_am_wf_events_pub.assign_lead_resource
7560 (P_API_VERSION => 1.0,
7561 P_INIT_MSG_LIST => 'F',
7562 P_COMMIT => 'F',
7563 P_LEAD_REC => Null,
7564 P_LEAD_BULK_REC => p_lead_rec,
7565 P_BUSINESS_PROCESS_ID => p_business_process_id,
7566 P_BUSINESS_PROCESS_DATE => p_business_process_date,
7567 X_RETURN_STATUS => l_wf_return_status,
7568 X_MSG_COUNT => l_wf_msg_count,
7569 X_MSG_DATA => l_wf_msg_data
7570 );
7571
7572
7573 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
7574 -- Unexpected Execution Error from call to assign_sr_resource
7575 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
7576 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
7577 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_LEAD_RESOURCES');
7578 fnd_msg_pub.add;
7579
7580 ELSE
7581 x_assign_resources_tbl.delete;
7582 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
7583 END IF;
7584
7585
7586 Exception
7587 When OTHERS Then
7588 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
7589 fnd_message.set_token('P_SQLCODE',SQLCODE);
7590 fnd_message.set_token('P_SQLERRM',SQLERRM);
7591 fnd_message.set_token('P_API_NAME',l_api_name);
7592 FND_MSG_PUB.add;
7593 End;
7594
7595 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7596
7597 -- To Plugin the Workflow enabling the user
7598 -- to further filter the resources
7599
7600 /* Getting the Workflow Profile value defined for the Assignment Manager */
7601
7602 --l_workflow_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_WORKFLOW_NAME' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
7603 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
7604
7605 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
7606 FROM dual;
7607
7608 IF (JTF_USR_HKS.ok_to_execute
7609 (
7610 'JTF_ASSIGN_PUB',
7611 'GET_ASSIGN_LEAD_RESOURCES',
7612 'W',
7613 'W'
7614 )
7615 ) THEN
7616
7617 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
7618 (
7619 p_api_version => l_api_version,
7620 p_init_msg_list => p_init_msg_list,
7621 x_return_status => x_return_status,
7622 x_msg_count => x_msg_count,
7623 x_msg_data => x_msg_data
7624 )
7625 ) THEN
7626
7627 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
7628 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
7629 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
7630 fnd_msg_pub.add;
7631 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
7632 RAISE fnd_api.g_exc_error;
7633 ELSE
7634 RAISE fnd_api.g_exc_unexpected_error;
7635 END IF;
7636 END IF;
7637
7638 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
7639
7640 JTF_USR_HKS.WrkFlowLaunch
7641 (
7642 'JTF_ASSIGN_WF',
7643 l_workflow_profile,
7644 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
7645 l_bind_data_id,
7646 l_return_code
7647 );
7648
7649 JTF_USR_HKS.purge_bind_data
7650 (
7651 l_bind_data_id,
7652 'W'
7653 );
7654
7655 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
7656 -- Execution Error from call to Assignment Manager Workflow Hook
7657 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
7658 fnd_msg_pub.add;
7659 RAISE fnd_api.g_exc_error;
7660 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
7661 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
7662 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
7663 fnd_msg_pub.add;
7664 RAISE fnd_api.g_exc_unexpected_error;
7665 END IF;
7666
7667 END IF; -- End of JTF_ASSIGN_CUHK
7668
7669 END IF; -- End of JTF_USR_HKS
7670
7671
7672
7673
7674 /* Standard call to get message count and
7675 the message information */
7676
7677 FND_MSG_PUB.Count_And_Get
7678 (
7679 p_count => x_msg_count,
7680 p_data => x_msg_data
7681 );
7682
7683
7684
7685 EXCEPTION
7686 WHEN FND_API.G_EXC_ERROR THEN
7687 x_return_status := FND_API.G_RET_STS_ERROR ;
7688 FND_MSG_PUB.Count_And_Get
7689 (
7690 p_count => x_msg_count,
7691 p_data => x_msg_data
7692 );
7693
7694 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7695 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7696 FND_MSG_PUB.Count_And_Get
7697 (
7698 p_count => x_msg_count,
7699 p_data => x_msg_data
7700 );
7701
7702 WHEN OTHERS THEN
7703 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
7704 fnd_message.set_token('P_SQLCODE',SQLCODE);
7705 fnd_message.set_token('P_SQLERRM',SQLERRM);
7706 fnd_message.set_token('P_API_NAME',l_api_name);
7707 FND_MSG_PUB.add;
7708
7709 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7710 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
7711 FND_MSG_PUB.Add_Exc_Msg
7712 (
7713 G_PKG_NAME,
7714 l_api_name
7715 );
7716 END IF;
7717
7718 FND_MSG_PUB.Count_And_Get
7719 (
7720 p_count => x_msg_count,
7721 p_data => x_msg_data
7722 );
7723
7724 END GET_ASSIGN_LEAD_RESOURCES;
7725
7726
7727
7728 -- *******************************************************************************
7729
7730 -- PLEASE DO NOT USE THIS API
7731 -- BEING SUPPORTED ONLY FOR BACKWARD COMPATIBILITY
7732
7733 -- API name : GET_ASSIGN_LEAD_RESOURCES (For SINGLE Record)
7734 -- Type : Public
7735 -- Function : Determine the resources based on the customer
7736 -- preferences or territory preferences and the
7737 -- availability. This is when the calling doc is
7738 -- LEADS.
7739 -- This parameter contains the values of the Qualifiers
7740 -- defined for the Sales Leads.
7741 -- p_lead_rec JTF_ASSIGN_PUB.
7742 -- JTF_Lead_rec_type
7743 -- REQUIRED
7744
7745 -- OUT : x_return_status OUT VARCHAR2(1)
7746 -- x_msg_count OUT NUMBER
7747 -- x_msg_data OUT VARCHAR2(2000)
7748 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
7749 -- AssignResources_tbl_type
7750
7751
7752 -- Version : Current version 1.0
7753 -- Initial version 1.0
7754 --
7755 -- Notes :
7756 --
7757
7758 -- End of comments
7759
7760 -- *********************************************************************************
7761
7762 -- Procedure definition with the parameters when the
7763 -- Source Document is SALES LEADS
7764
7765 PROCEDURE GET_ASSIGN_LEAD_RESOURCES
7766 (
7767 p_api_version IN NUMBER,
7768 p_init_msg_list IN VARCHAR2 ,
7769 p_resource_type IN VARCHAR2 ,
7770 p_role IN VARCHAR2 ,
7771 p_no_of_resources IN NUMBER ,
7772 p_auto_select_flag IN VARCHAR2 ,
7773 p_effort_duration IN NUMBER ,
7774 p_effort_uom IN VARCHAR2 ,
7775 p_start_date IN DATE ,
7776 p_end_date IN DATE ,
7777 p_territory_flag IN VARCHAR2 ,
7778 p_calendar_flag IN VARCHAR2 ,
7779 p_lead_rec IN JTF_ASSIGN_PUB.JTF_Lead_rec_type,
7780 p_business_process_id IN NUMBER,
7781 p_business_process_date IN DATE,
7782 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
7783 x_return_status OUT NOCOPY VARCHAR2,
7784 x_msg_count OUT NOCOPY NUMBER,
7785 x_msg_data OUT NOCOPY VARCHAR2
7786 )
7787 IS
7788
7789 l_return_status_1 VARCHAR2(10);
7790 l_api_name VARCHAR2(100) := 'GET_ASSIGN_LEAD_RESOURCES';
7791 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_LEAD_RESOURCES';
7792 l_api_version NUMBER := 1.0;
7793 l_planned_start_date DATE;
7794 l_planned_end_date DATE;
7795 l_effort_duration NUMBER;
7796 l_effort_uom VARCHAR2(30);
7797 l_travel_time NUMBER := 0;
7798 l_travel_uom VARCHAR2(30) := 'HR';
7799
7800 l_current_record INTEGER;
7801 l_total_records INTEGER;
7802
7803 l_auto_select_profile VARCHAR2(03);
7804 l_auto_select_flag VARCHAR2(03);
7805 l_workflow_profile VARCHAR2(60);
7806
7807 l_return_code VARCHAR2(60);
7808 l_bind_data_id NUMBER;
7809 l_workflow_key NUMBER;
7810
7811 l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
7812 l_lead_rec JTF_TERRITORY_PUB.JTF_Lead_rec_type;
7813
7814 l_x_planned_start_date DATE;
7815 l_x_planned_end_date DATE;
7816 l_x_shift_construct_id NUMBER;
7817 l_x_availability_type VARCHAR2(60);
7818
7819 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7820
7821 l_wf_return_status VARCHAR2(60);
7822 l_wf_msg_count NUMBER;
7823 l_wf_msg_data VARCHAR2(2000);
7824
7825 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
7826
7827
7828 BEGIN
7829
7830 SAVEPOINT get_assign_lead_resources;
7831
7832 -- Started Assignment Manager API for SALES LEADS
7833
7834
7835 /* Standard call to check for call compatibility */
7836
7837 IF NOT fnd_api.compatible_api_call (l_api_version,
7838 p_api_version,
7839 l_api_name,
7840 g_pkg_name) THEN
7841 RAISE fnd_api.g_exc_unexpected_error;
7842 END IF;
7843
7844
7845 /* Initialize message list if p_init_msg_list is set to TRUE */
7846
7847 IF fnd_api.to_boolean (p_init_msg_list) THEN
7848 fnd_msg_pub.initialize;
7849 END IF;
7850
7851 x_return_status := fnd_api.g_ret_sts_success;
7852
7853
7854 /* Getting the Auto Select Profile value defined for the Assignment Manager */
7855
7856 --l_auto_select_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_AUTO_SELECT' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
7857 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
7858
7859
7860
7861 /* Assigning the DEFAULT value to the Auto Select Parameter */
7862
7863
7864 IF (p_auto_select_flag IS NULL) THEN
7865 l_auto_select_flag := l_auto_select_profile;
7866 -- PROFILE VALUE is the default value
7867 ELSE
7868 l_auto_select_flag := p_auto_select_flag;
7869 END IF;
7870
7871
7872 /* Defaulting the Calendar variable values to IN parameters,
7873 if the IN paramaters have values given */
7874
7875
7876 IF (p_start_date IS NOT NULL) THEN
7877 l_planned_start_date := p_start_date;
7878 ELSE
7879 l_planned_start_date := SYSDATE;
7880 END IF;
7881
7882 IF (p_end_date IS NOT NULL) THEN
7883 l_planned_end_date := p_end_date;
7884 ELSE
7885 l_planned_end_date := SYSDATE;
7886 END IF;
7887
7888 IF (p_effort_duration IS NOT NULL) THEN
7889 l_effort_duration := p_effort_duration;
7890 END IF;
7891
7892 IF (p_effort_uom IS NOT NULL) THEN
7893 l_effort_uom := p_effort_uom;
7894 END IF;
7895
7896
7897
7898 /* Assigning values to the Lead Record Type */
7899
7900
7901 l_lead_rec.SALES_LEAD_ID := p_lead_rec.SALES_LEAD_ID;
7902 l_lead_rec.SALES_LEAD_LINE_ID := p_lead_rec.SALES_LEAD_LINE_ID;
7903 l_lead_rec.CITY := p_lead_rec.CITY;
7904 l_lead_rec.POSTAL_CODE := p_lead_rec.POSTAL_CODE;
7905 l_lead_rec.STATE := p_lead_rec.STATE;
7906 l_lead_rec.PROVINCE := p_lead_rec.PROVINCE;
7907 l_lead_rec.COUNTY := p_lead_rec.COUNTY;
7908 l_lead_rec.COUNTRY := p_lead_rec.COUNTRY;
7909 l_lead_rec.INTEREST_TYPE_ID := p_lead_rec.INTEREST_TYPE_ID;
7910 l_lead_rec.PRIMARY_INTEREST_ID := p_lead_rec.PRIMARY_INTEREST_ID;
7911 l_lead_rec.SECONDARY_INTEREST_ID := p_lead_rec.SECONDARY_INTEREST_ID;
7912 l_lead_rec.CONTACT_INTEREST_TYPE_ID := p_lead_rec.CONTACT_INTEREST_TYPE_ID;
7913 l_lead_rec.CONTACT_PRIMARY_INTEREST_ID := p_lead_rec.CONTACT_PRIMARY_INTEREST_ID;
7914 l_lead_rec.CONTACT_SECONDARY_INTEREST_ID := p_lead_rec.CONTACT_SECONDARY_INTEREST_ID;
7915 l_lead_rec.PARTY_SITE_ID := p_lead_rec.PARTY_SITE_ID;
7916 l_lead_rec.AREA_CODE := p_lead_rec.AREA_CODE;
7917 l_lead_rec.PARTY_ID := p_lead_rec.PARTY_ID;
7918 l_lead_rec.COMP_NAME_RANGE := p_lead_rec.COMP_NAME_RANGE;
7919 l_lead_rec.PARTNER_ID := p_lead_rec.PARTNER_ID;
7920 l_lead_rec.NUM_OF_EMPLOYEES := p_lead_rec.NUM_OF_EMPLOYEES;
7921 l_lead_rec.CATEGORY_CODE := p_lead_rec.CATEGORY_CODE;
7922 l_lead_rec.PARTY_RELATIONSHIP_ID := p_lead_rec.PARTY_RELATIONSHIP_ID;
7923 l_lead_rec.SIC_CODE := p_lead_rec.SIC_CODE;
7924 l_lead_rec.BUDGET_AMOUNT := p_lead_rec.BUDGET_AMOUNT;
7925 l_lead_rec.CURRENCY_CODE := p_lead_rec.CURRENCY_CODE;
7926 l_lead_rec.PRICING_DATE := p_lead_rec.PRICING_DATE;
7927 l_lead_rec.SOURCE_PROMOTION_ID := p_lead_rec.SOURCE_PROMOTION_ID;
7928 l_lead_rec.INVENTORY_ITEM_ID := p_lead_rec.INVENTORY_ITEM_ID;
7929 l_lead_rec.LEAD_INTEREST_TYPE_ID := p_lead_rec.LEAD_INTEREST_TYPE_ID;
7930 l_lead_rec.LEAD_PRIMARY_INTEREST_ID := p_lead_rec.LEAD_PRIMARY_INTEREST_ID;
7931 l_lead_rec.LEAD_SECONDARY_INTEREST_ID := p_lead_rec.LEAD_SECONDARY_INTEREST_ID;
7932 l_lead_rec.PURCHASE_AMOUNT := p_lead_rec.PURCHASE_AMOUNT;
7933 l_lead_rec.ATTRIBUTE1 := p_lead_rec.ATTRIBUTE1;
7934 l_lead_rec.ATTRIBUTE2 := p_lead_rec.ATTRIBUTE2;
7935 l_lead_rec.ATTRIBUTE3 := p_lead_rec.ATTRIBUTE3;
7936 l_lead_rec.ATTRIBUTE4 := p_lead_rec.ATTRIBUTE4;
7937 l_lead_rec.ATTRIBUTE5 := p_lead_rec.ATTRIBUTE5;
7938 l_lead_rec.ATTRIBUTE6 := p_lead_rec.ATTRIBUTE6;
7939 l_lead_rec.ATTRIBUTE7 := p_lead_rec.ATTRIBUTE7;
7940 l_lead_rec.ATTRIBUTE8 := p_lead_rec.ATTRIBUTE8;
7941 l_lead_rec.ATTRIBUTE9 := p_lead_rec.ATTRIBUTE9;
7942 l_lead_rec.ATTRIBUTE10 := p_lead_rec.ATTRIBUTE10;
7943 l_lead_rec.ATTRIBUTE11 := p_lead_rec.ATTRIBUTE11;
7944 l_lead_rec.ATTRIBUTE12 := p_lead_rec.ATTRIBUTE12;
7945 l_lead_rec.ATTRIBUTE13 := p_lead_rec.ATTRIBUTE13;
7946 l_lead_rec.ATTRIBUTE14 := p_lead_rec.ATTRIBUTE14;
7947 l_lead_rec.ATTRIBUTE15 := p_lead_rec.ATTRIBUTE15;
7948
7949
7950
7951 /* Actual Flow of Assignment Manager */
7952
7953
7954 IF (p_territory_flag = 'Y') THEN
7955
7956 -- change the API Name temporarily so that in case of unexpected error
7957 -- it is properly caught
7958 l_api_name := l_api_name||'-JTF_TERR_SALES_PUB';
7959
7960 JTF_TERR_SALES_PUB.Get_WinningTerrMembers
7961 (
7962 p_api_version_number => l_api_version,
7963 p_init_msg_list => p_init_msg_list,
7964 p_TerrLead_Rec => l_lead_rec,
7965 p_Resource_Type => p_resource_type,
7966 p_Role => p_role,
7967 x_return_status => x_return_status,
7968 x_msg_count => x_msg_count,
7969 x_msg_data => x_msg_data,
7970 x_TerrResource_tbl => l_assign_resources_tbl
7971 );
7972
7973 -- set back the API name to original name
7974 l_api_name := l_api_name_1;
7975
7976 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
7977 -- Unexpected Execution Error from call to Territory Manager
7978 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
7979 fnd_msg_pub.add;
7980 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
7981 RAISE fnd_api.g_exc_error;
7982 ELSE
7983 RAISE fnd_api.g_exc_unexpected_error;
7984 END IF;
7985 END IF;
7986
7987 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
7988
7989 IF(l_assign_resources_tbl.COUNT > 0)
7990 THEN
7991 l_current_record := l_assign_resources_tbl.FIRST;
7992 WHILE l_current_record <= l_assign_resources_tbl.LAST
7993 LOOP
7994 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
7995 THEN
7996 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
7997 END IF;
7998 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
7999 END LOOP;
8000 END IF;
8001
8002 IF l_assign_resources_tbl.COUNT > 0 THEN
8003
8004 l_current_record := l_assign_resources_tbl.FIRST;
8005
8006
8007 IF (l_auto_select_flag = 'Y') THEN
8008 l_total_records := p_no_of_resources;
8009 ELSE
8010 l_total_records := l_assign_resources_tbl.LAST;
8011 END IF;
8012
8013
8014 WHILE l_current_record <= l_assign_resources_tbl.LAST
8015 LOOP
8016 -- Check the calendar for resource availability
8017 -- Call Calendar API
8018 -- IF the resource is available then accept the values and
8019 -- check for the WORKFLOW profile option
8020
8021 IF (p_calendar_flag = 'Y') THEN
8022
8023 -- change the API Name temporarily so that in case of unexpected error
8024 -- it is properly caught
8025 l_api_name := l_api_name||'-JTF_CALENDAR_PUB';
8026 l_return_status_1 := x_return_status ;
8027
8028 JTF_CALENDAR_PUB.GET_AVAILABLE_SLOT
8029 (
8030 P_API_VERSION => l_api_version,
8031 P_INIT_MSG_LIST => p_init_msg_list,
8032 P_RESOURCE_ID => l_assign_resources_tbl(l_current_record).resource_id,
8033 P_RESOURCE_TYPE => l_assign_resources_tbl(l_current_record).resource_type,
8034 P_START_DATE_TIME => l_planned_start_date,
8035 P_END_DATE_TIME => l_planned_end_date,
8036 P_DURATION => l_effort_duration,
8037 X_RETURN_STATUS => x_return_status,
8038 X_MSG_COUNT => x_msg_count,
8039 X_MSG_DATA => x_msg_data,
8040 X_SLOT_START_DATE => l_x_planned_start_date,
8041 X_SLOT_END_DATE => l_x_planned_end_date,
8042 X_SHIFT_CONSTRUCT_ID => l_x_shift_construct_id,
8043 X_AVAILABILITY_TYPE => l_x_availability_type
8044 );
8045
8046 -- set back the API name to original name
8047 l_api_name := l_api_name_1;
8048
8049 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
8050 -- Unexpected Execution Error from call to Calendar
8051 fnd_message.set_name('JTF', 'JTF_AM_ERROR_CAL_API');
8052 fnd_msg_pub.add;
8053 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
8054 -- 12/22/05 ** MPADHIAR ** Manas padhiary **
8055 -- Removed Comment to Show error message Bug # 2919389
8056 RAISE fnd_api.g_exc_error;
8057 ELSE
8058 RAISE fnd_api.g_exc_unexpected_error;
8059 END IF;
8060 END IF;
8061
8062
8063 IF (l_x_shift_construct_id IS NOT NULL) THEN
8064
8065 -- The following IF statement is to implement Auto Select Feature
8066 IF (l_current_record <= l_total_records) THEN
8067
8068 x_assign_resources_tbl(l_current_record).terr_rsc_id :=
8069 l_assign_resources_tbl(l_current_record).terr_rsc_id;
8070 x_assign_resources_tbl(l_current_record).resource_id :=
8071 l_assign_resources_tbl(l_current_record).resource_id;
8072 x_assign_resources_tbl(l_current_record).resource_type :=
8073 l_assign_resources_tbl(l_current_record).resource_type;
8074 x_assign_resources_tbl(l_current_record).role :=
8075 l_assign_resources_tbl(l_current_record).role;
8076
8077 IF (l_travel_uom like 'HR%') THEN
8078 x_assign_resources_tbl(l_current_record).start_date :=
8079 l_x_planned_start_date + l_travel_time/24;
8080 x_assign_resources_tbl(l_current_record).end_date :=
8081 l_x_planned_end_date + l_travel_time/24;
8082 ELSIF (l_travel_uom like 'MI%') THEN
8083 x_assign_resources_tbl(l_current_record).start_date :=
8084 l_x_planned_start_date + l_travel_time/1440;
8085 x_assign_resources_tbl(l_current_record).end_date :=
8086 l_x_planned_end_date + l_travel_time/1440;
8087 ELSIF (l_travel_uom like 'S%') THEN
8088 x_assign_resources_tbl(l_current_record).start_date :=
8089 l_x_planned_start_date + l_travel_time/86400;
8090 x_assign_resources_tbl(l_current_record).end_date :=
8091 l_x_planned_end_date + l_travel_time/86400;
8092 END IF;
8093
8094 x_assign_resources_tbl(l_current_record).shift_construct_id := l_x_shift_construct_id;
8095 x_assign_resources_tbl(l_current_record).terr_id :=
8096 l_assign_resources_tbl(l_current_record).terr_id;
8097 x_assign_resources_tbl(l_current_record).terr_name :=
8098 l_assign_resources_tbl(l_current_record).terr_name;
8099 x_assign_resources_tbl(l_current_record).primary_contact_flag :=
8100 l_assign_resources_tbl(l_current_record).primary_contact_flag;
8101 x_assign_resources_tbl(l_current_record).full_access_flag :=
8102 l_assign_resources_tbl(l_current_record).full_access_flag;
8103 x_assign_resources_tbl(l_current_record).group_id :=
8104 l_assign_resources_tbl(l_current_record).group_id;
8105 x_assign_resources_tbl(l_current_record).resource_source := 'TERR';
8106
8107 END IF;
8108 END IF;
8109
8110 ELSE -- Calendar Flag is NO
8111
8112 -- The following IF statement is to implement Auto Select Feature
8113 IF (l_current_record <= l_total_records) THEN
8114 x_assign_resources_tbl(l_current_record).terr_rsc_id :=
8115 l_assign_resources_tbl(l_current_record).terr_rsc_id;
8116 x_assign_resources_tbl(l_current_record).resource_id :=
8117 l_assign_resources_tbl(l_current_record).resource_id;
8118 x_assign_resources_tbl(l_current_record).resource_type :=
8119 l_assign_resources_tbl(l_current_record).resource_type;
8120 x_assign_resources_tbl(l_current_record).role :=
8121 l_assign_resources_tbl(l_current_record).role;
8122 x_assign_resources_tbl(l_current_record).start_date :=
8123 l_assign_resources_tbl(l_current_record).start_date;
8124 x_assign_resources_tbl(l_current_record).end_date :=
8125 l_assign_resources_tbl(l_current_record).end_date;
8126 x_assign_resources_tbl(l_current_record).shift_construct_id := NULL;
8127 x_assign_resources_tbl(l_current_record).terr_id :=
8128 l_assign_resources_tbl(l_current_record).terr_id;
8129 x_assign_resources_tbl(l_current_record).terr_name :=
8130 l_assign_resources_tbl(l_current_record).terr_name;
8131 x_assign_resources_tbl(l_current_record).primary_contact_flag :=
8132 l_assign_resources_tbl(l_current_record).primary_contact_flag;
8133 x_assign_resources_tbl(l_current_record).full_access_flag :=
8134 l_assign_resources_tbl(l_current_record).full_access_flag;
8135 x_assign_resources_tbl(l_current_record).group_id :=
8136 l_assign_resources_tbl(l_current_record).group_id;
8137 END IF;
8138
8139 END IF; -- End of Calendar Flag
8140
8141 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
8142 END LOOP;
8143
8144
8145 IF ( p_calendar_flag = 'Y' AND
8146 x_assign_resources_tbl.count = 0 ) THEN
8147 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
8148 fnd_msg_pub.add;
8149 -- RAISE fnd_api.g_exc_error;
8150 END IF;
8151
8152 ELSE -- No resources returned from the Territory API
8153 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
8154 fnd_msg_pub.add;
8155 -- RAISE fnd_api.g_exc_error;
8156 END IF;
8157
8158 ELSE -- Territory Flag is NO
8159 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
8160 fnd_msg_pub.add;
8161 -- RAISE fnd_api.g_exc_error;
8162 END IF;
8163
8164 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
8165
8166 -- raise workfow event
8167 -- workflow test
8168 Begin
8169 jtf_assign_pub.g_assign_resources_tbl.delete;
8170 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
8171 jtf_am_wf_events_pub.assign_lead_resource
8172 (P_API_VERSION => 1.0,
8173 P_INIT_MSG_LIST => 'F',
8174 P_COMMIT => 'F',
8175 P_LEAD_REC => p_lead_rec,
8176 P_LEAD_BULK_REC => Null,
8177 P_BUSINESS_PROCESS_ID => p_business_process_id,
8178 P_BUSINESS_PROCESS_DATE => p_business_process_date,
8179 X_RETURN_STATUS => l_wf_return_status,
8180 X_MSG_COUNT => l_wf_msg_count,
8181 X_MSG_DATA => l_wf_msg_data
8182 );
8183
8184
8185 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
8186 -- Unexpected Execution Error from call to assign_sr_resource
8187 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
8188 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
8189 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_LEAD_RESOURCES');
8190 fnd_msg_pub.add;
8191
8192 ELSE
8193 x_assign_resources_tbl.delete;
8194 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
8195 END IF;
8196
8197
8198 Exception
8199 When OTHERS Then
8200 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
8201 fnd_message.set_token('P_SQLCODE',SQLCODE);
8202 fnd_message.set_token('P_SQLERRM',SQLERRM);
8203 fnd_message.set_token('P_API_NAME',l_api_name);
8204 FND_MSG_PUB.add;
8205 End;
8206
8207 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
8208
8209 -- To Plugin the Workflow enabling the user
8210 -- to further filter the resources
8211
8212 /* Getting the Workflow Profile value defined for the Assignment Manager */
8213
8214 --l_workflow_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_WORKFLOW_NAME' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
8215 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
8216
8217 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
8218 FROM dual;
8219
8220 IF (JTF_USR_HKS.ok_to_execute
8221 (
8222 'JTF_ASSIGN_PUB',
8223 'GET_ASSIGN_LEAD_RESOURCES',
8224 'W',
8225 'W'
8226 )
8227 ) THEN
8228
8229 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
8230 (
8231 p_api_version => l_api_version,
8232 p_init_msg_list => p_init_msg_list,
8233 x_return_status => x_return_status,
8234 x_msg_count => x_msg_count,
8235 x_msg_data => x_msg_data
8236 )
8237 ) THEN
8238
8239 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
8240 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
8241 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
8242 fnd_msg_pub.add;
8243 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
8244 RAISE fnd_api.g_exc_error;
8245 ELSE
8246 RAISE fnd_api.g_exc_unexpected_error;
8247 END IF;
8248 END IF;
8249
8250 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
8251
8252 JTF_USR_HKS.WrkFlowLaunch
8253 (
8254 'JTF_ASSIGN_WF',
8255 l_workflow_profile,
8256 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
8257 l_bind_data_id,
8258 l_return_code
8259 );
8260
8261 JTF_USR_HKS.purge_bind_data
8262 (
8263 l_bind_data_id,
8264 'W'
8265 );
8266
8267
8268 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
8269 -- Execution Error from call to Assignment Manager Workflow Hook
8270 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
8271 fnd_msg_pub.add;
8272 RAISE fnd_api.g_exc_error;
8273 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
8274 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
8275 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
8276 fnd_msg_pub.add;
8277 RAISE fnd_api.g_exc_unexpected_error;
8278 END IF;
8279
8280 END IF; -- End of JTF_ASSIGN_CUHK
8281
8282 END IF; -- End of JTF_USR_HKS
8283
8284
8285
8286 /* Standard call to get message count and
8287 the message information */
8288
8289 FND_MSG_PUB.Count_And_Get
8290 (
8291 p_count => x_msg_count,
8292 p_data => x_msg_data
8293 );
8294
8295
8296
8297 EXCEPTION
8298 WHEN FND_API.G_EXC_ERROR THEN
8299 x_return_status := FND_API.G_RET_STS_ERROR ;
8300 FND_MSG_PUB.Count_And_Get
8301 (
8302 p_count => x_msg_count,
8303 p_data => x_msg_data
8304 );
8305
8306 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8307 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8308 FND_MSG_PUB.Count_And_Get
8309 (
8310 p_count => x_msg_count,
8311 p_data => x_msg_data
8312 );
8313
8314 WHEN OTHERS THEN
8315 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
8316 fnd_message.set_token('P_SQLCODE',SQLCODE);
8317 fnd_message.set_token('P_SQLERRM',SQLERRM);
8318 fnd_message.set_token('P_API_NAME',l_api_name);
8319 FND_MSG_PUB.add;
8320
8321 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8322 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
8323 FND_MSG_PUB.Add_Exc_Msg
8324 (
8325 G_PKG_NAME,
8326 l_api_name
8327 );
8328 END IF;
8329
8330 FND_MSG_PUB.Count_And_Get
8331 (
8332 p_count => x_msg_count,
8333 p_data => x_msg_data
8334 );
8335
8336 END GET_ASSIGN_LEAD_RESOURCES;
8337
8338
8339
8340
8341
8342
8343
8344
8345 -- *******************************************************************************
8346
8347 -- Start of comments
8348
8349 -- API name : GET_ASSIGN_ACCOUNT_RESOURCES
8350 -- Type : Public
8351 -- Function : Determine the resources based on the customer
8352 -- preferences or territory preferences and the
8353 -- availability. This is when the calling doc is
8354 -- ACCOUNTS.
8355 -- Pre-reqs : None
8356
8357 -- Parameters :
8358
8359 -- IN : p_api_version IN NUMBER Required
8360 -- p_init_msg_list IN VARCHAR2 Optional
8361 -- DEFAULT JTF_ASSIGN_PUB.AM_FALSE
8362 -- p_commit IN VARCHAR2 optional
8363 -- DEFAULT JTF_ASSIGN_PUB.AM_FALSE
8364
8365 -- Assignment Manager Specific Parameters
8366
8367 -- This determines the Resource Type required by the
8368 -- calling document
8369 -- p_resource_type VARCHAR2(30)
8370 -- p_role VARCHAR2(30)
8371
8372 -- This determines the number of resources required
8373 -- by the calling document
8374 -- p_no_of_resources NUMBER,
8375 -- This is for sending out the qualified resource directly
8376 -- to the calling form. Defaulted to the PROFILE value
8377 -- p_auto_select_flag VARCHAR2(1)
8378 -- : value of Y or N
8379
8380 -- The Effort required is determined by these two parameters
8381 -- p_effort_duration NUMBER
8382 -- p_effort_uom VARCHAR2(10)
8383
8384 -- The Dates in which the resource is required, is determined
8385 -- by these two parameters
8386 -- p_start_date DATE
8387 -- p_end_date DATE
8388
8389 -- The Territory Manager is accessed based on the value set
8390 -- p_territory_flag VARCHAR2(1)
8391 -- : value of Y or N
8392
8393 -- The Resource Availability is checked based on the value set
8394 -- p_calendar_flag VARCHAR2(1)
8395 -- : value of Y or N
8396
8397
8398 -- This parameter contains the values of the Qualifiers
8399 -- defined for the Accounts.
8400 -- p_account_rec JTF_ASSIGN_PUB.
8401 -- JTF_Account_rec_type
8402 -- REQUIRED
8403
8404 -- OUT : x_return_status OUT VARCHAR2(1)
8405 -- x_msg_count OUT NUMBER
8406 -- x_msg_data OUT VARCHAR2(2000)
8407 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
8408 -- AssignResources_tbl_type
8409
8410
8411 -- Version : Current version 1.0
8412 -- Initial version 1.0
8413 --
8414 -- Notes :
8415 --
8416
8417 -- End of comments
8418
8419 -- *********************************************************************************
8420
8421
8422
8423 -- Procedure definition with the parameters when the
8424 -- Source Document is ACCOUNTS
8425
8426
8427 PROCEDURE GET_ASSIGN_ACCOUNT_RESOURCES
8428 (
8429 p_api_version IN NUMBER,
8430 p_init_msg_list IN VARCHAR2 ,
8431 p_resource_type IN VARCHAR2 ,
8432 p_role IN VARCHAR2 ,
8433 p_no_of_resources IN NUMBER ,
8434 p_auto_select_flag IN VARCHAR2 ,
8435 p_effort_duration IN NUMBER ,
8436 p_effort_uom IN VARCHAR2 ,
8437 p_start_date IN DATE ,
8438 p_end_date IN DATE ,
8439 p_territory_flag IN VARCHAR2,
8440 p_calendar_flag IN VARCHAR2 ,
8441 p_account_rec IN JTF_ASSIGN_PUB.JTF_Account_rec_type,
8442 p_business_process_id IN NUMBER,
8443 p_business_process_date IN DATE,
8444 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
8445 x_return_status OUT NOCOPY VARCHAR2,
8446 x_msg_count OUT NOCOPY NUMBER,
8447 x_msg_data OUT NOCOPY VARCHAR2
8448 )
8449 IS
8450
8451 l_return_status_1 VARCHAR2(10);
8452 l_api_name VARCHAR2(100) := 'GET_ASSIGN_ACCOUNT_RESOURCES';
8453 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_ACCOUNT_RESOURCES';
8454 l_api_version NUMBER := 1.0;
8455 l_planned_start_date DATE;
8456 l_planned_end_date DATE;
8457 l_effort_duration NUMBER;
8458 l_effort_uom VARCHAR2(30);
8459 l_travel_time NUMBER := 0;
8460 l_travel_uom VARCHAR2(30) := 'HR';
8461
8462 l_current_record INTEGER;
8463 l_total_records INTEGER;
8464
8465 l_auto_select_profile VARCHAR2(03);
8466 l_auto_select_flag VARCHAR2(03);
8467 l_workflow_profile VARCHAR2(60);
8468
8469 l_return_code VARCHAR2(60);
8470 l_bind_data_id NUMBER;
8471 l_workflow_key NUMBER;
8472
8473 l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
8474 l_account_rec JTF_TERRITORY_PUB.JTF_Account_rec_type;
8475
8476 l_x_planned_start_date DATE;
8477 l_x_planned_end_date DATE;
8478 l_x_shift_construct_id NUMBER;
8479 l_x_availability_type VARCHAR2(60);
8480
8481 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
8482
8483 l_wf_return_status VARCHAR2(60);
8484 l_wf_msg_count NUMBER;
8485 l_wf_msg_data VARCHAR2(2000);
8486
8487 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
8488
8489 --Bug# 4455803 MOAC.
8490 CURSOR check_date_cur(l_resource_id in number,
8491 l_resource_type in varchar2)
8492 IS
8493 SELECT 'Y'
8494 --FROM jtf_rs_all_resources_vl
8495 FROM jtf_task_resources_vl
8496 where resource_id = l_resource_id
8497 and resource_type = l_resource_type
8498 and nvl(trunc(end_date_active), trunc(sysdate)) >= trunc(sysdate);
8499
8500 l_value varchar2(100);
8501
8502 l_count number := 0;
8503 l_temp_table JTF_ASSIGN_PUB.AssignResources_tbl_type;
8504
8505 BEGIN
8506
8507 SAVEPOINT get_assign_account_resources;
8508
8509 -- Started Assignment Manager API for ACCOUNTS
8510
8511
8512 /* Standard call to check for call compatibility */
8513
8514 IF NOT fnd_api.compatible_api_call (l_api_version,
8515 p_api_version,
8516 l_api_name,
8517 g_pkg_name) THEN
8518 RAISE fnd_api.g_exc_unexpected_error;
8519 END IF;
8520
8521
8522 /* Initialize message list if p_init_msg_list is set to TRUE */
8523
8524 IF fnd_api.to_boolean (p_init_msg_list) THEN
8525 fnd_msg_pub.initialize;
8526 END IF;
8527
8528 x_return_status := fnd_api.g_ret_sts_success;
8529
8530
8531
8532 /* Getting the Auto Select Profile value defined for the Assignment Manager */
8533
8534 --l_auto_select_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_AUTO_SELECT' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
8535 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
8536
8537
8538
8539 /* Assigning the DEFAULT value to the Auto Select Parameter */
8540
8541
8542 IF (p_auto_select_flag IS NULL) THEN
8543 l_auto_select_flag := l_auto_select_profile;
8544 -- PROFILE VALUE is the default value
8545 ELSE
8546 l_auto_select_flag := p_auto_select_flag;
8547 END IF;
8548
8549
8550
8551
8552 /* Defaulting the Calendar variable values to IN parameters,
8553 if the IN paramaters have values given */
8554
8555
8556 IF (p_start_date IS NOT NULL) THEN
8557 l_planned_start_date := p_start_date;
8558 ELSE
8559 l_planned_start_date := SYSDATE;
8560 END IF;
8561
8562 IF (p_end_date IS NOT NULL) THEN
8563 l_planned_end_date := p_end_date;
8564 ELSE
8565 l_planned_end_date := SYSDATE;
8566 END IF;
8567
8568 IF (p_effort_duration IS NOT NULL) THEN
8569 l_effort_duration := p_effort_duration;
8570 END IF;
8571
8572 IF (p_effort_uom IS NOT NULL) THEN
8573 l_effort_uom := p_effort_uom;
8574 END IF;
8575
8576
8577 /* Assigning values to the Account Record Type */
8578
8579
8580 l_account_rec.CITY := p_account_rec.CITY;
8581 l_account_rec.POSTAL_CODE := p_account_rec.POSTAL_CODE;
8582 l_account_rec.STATE := p_account_rec.STATE;
8583 l_account_rec.PROVINCE := p_account_rec.PROVINCE;
8584 l_account_rec.COUNTY := p_account_rec.COUNTY;
8585 l_account_rec.COUNTRY := p_account_rec.COUNTRY;
8586 l_account_rec.INTEREST_TYPE_ID := p_account_rec.INTEREST_TYPE_ID;
8587 l_account_rec.PRIMARY_INTEREST_ID := p_account_rec.PRIMARY_INTEREST_ID;
8588 l_account_rec.SECONDARY_INTEREST_ID := p_account_rec.SECONDARY_INTEREST_ID;
8589 l_account_rec.CONTACT_INTEREST_TYPE_ID := p_account_rec.CONTACT_INTEREST_TYPE_ID;
8590 l_account_rec.CONTACT_PRIMARY_INTEREST_ID := p_account_rec.CONTACT_PRIMARY_INTEREST_ID;
8591 l_account_rec.CONTACT_SECONDARY_INTEREST_ID := p_account_rec.CONTACT_SECONDARY_INTEREST_ID;
8592 l_account_rec.PARTY_SITE_ID := p_account_rec.PARTY_SITE_ID;
8593 l_account_rec.AREA_CODE := p_account_rec.AREA_CODE;
8594 l_account_rec.PARTY_ID := p_account_rec.PARTY_ID;
8595 l_account_rec.COMP_NAME_RANGE := p_account_rec.COMP_NAME_RANGE;
8596 l_account_rec.PARTNER_ID := p_account_rec.PARTNER_ID;
8597 l_account_rec.NUM_OF_EMPLOYEES := p_account_rec.NUM_OF_EMPLOYEES;
8598 l_account_rec.CATEGORY_CODE := p_account_rec.CATEGORY_CODE;
8599 l_account_rec.PARTY_RELATIONSHIP_ID := p_account_rec.PARTY_RELATIONSHIP_ID;
8600 l_account_rec.SIC_CODE := p_account_rec.SIC_CODE;
8601 l_account_rec.ATTRIBUTE1 := p_account_rec.ATTRIBUTE1;
8602 l_account_rec.ATTRIBUTE2 := p_account_rec.ATTRIBUTE2;
8603 l_account_rec.ATTRIBUTE3 := p_account_rec.ATTRIBUTE3;
8604 l_account_rec.ATTRIBUTE4 := p_account_rec.ATTRIBUTE4;
8605 l_account_rec.ATTRIBUTE5 := p_account_rec.ATTRIBUTE5;
8606 l_account_rec.ATTRIBUTE6 := p_account_rec.ATTRIBUTE6;
8607 l_account_rec.ATTRIBUTE7 := p_account_rec.ATTRIBUTE7;
8608 l_account_rec.ATTRIBUTE8 := p_account_rec.ATTRIBUTE8;
8609 l_account_rec.ATTRIBUTE9 := p_account_rec.ATTRIBUTE9;
8610 l_account_rec.ATTRIBUTE10 := p_account_rec.ATTRIBUTE10;
8611 l_account_rec.ATTRIBUTE11 := p_account_rec.ATTRIBUTE11;
8612 l_account_rec.ATTRIBUTE12 := p_account_rec.ATTRIBUTE12;
8613 l_account_rec.ATTRIBUTE13 := p_account_rec.ATTRIBUTE13;
8614 l_account_rec.ATTRIBUTE14 := p_account_rec.ATTRIBUTE14;
8615 l_account_rec.ATTRIBUTE15 := p_account_rec.ATTRIBUTE15;
8616 l_account_rec.ORG_ID := p_account_rec.ORG_ID;
8617
8618
8619
8620 /* Actual Flow of Assignment Manager */
8621
8622
8623 IF (p_territory_flag = 'Y') THEN
8624
8625 -- change the API Name temporarily so that in case of unexpected error
8626 -- it is properly caught
8627 l_api_name := l_api_name||'-JTF_TERR_SALES_PUB';
8628
8629 JTF_TERR_SALES_PUB.Get_WinningTerrMembers
8630 (
8631 p_api_version_number => l_api_version,
8632 p_init_msg_list => p_init_msg_list,
8633 p_TerrAccount_Rec => l_account_rec,
8634 p_Resource_Type => p_resource_type,
8635 p_Role => p_role,
8636 x_return_status => x_return_status,
8637 x_msg_count => x_msg_count,
8638 x_msg_data => x_msg_data,
8639 x_TerrResource_tbl => l_assign_resources_tbl
8640 );
8641
8642 -- set back the API name to original name
8643 l_api_name := l_api_name_1;
8644
8645 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
8646 -- Unexpected Execution Error from call to Territory Manager
8647 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
8648 fnd_msg_pub.add;
8649 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
8650 RAISE fnd_api.g_exc_error;
8651 ELSE
8652 RAISE fnd_api.g_exc_unexpected_error;
8653 END IF;
8654 END IF;
8655
8656
8657 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
8658
8659 IF(l_assign_resources_tbl.COUNT > 0)
8660 THEN
8661 l_current_record := l_assign_resources_tbl.FIRST;
8662 WHILE l_current_record <= l_assign_resources_tbl.LAST
8663 LOOP
8664 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
8665 THEN
8666 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
8667 END IF;
8668 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
8669 END LOOP;
8670 END IF;
8671
8672 IF l_assign_resources_tbl.COUNT > 0 THEN
8673
8674 l_current_record := l_assign_resources_tbl.FIRST;
8675
8676
8677 IF (l_auto_select_flag = 'Y') THEN
8678 l_total_records := p_no_of_resources;
8679 ELSE
8680 l_total_records := l_assign_resources_tbl.LAST;
8681 END IF;
8682
8683 -- removed the calendar check here. calling the procedure for calendar check in the next step
8684 -- calendar check removed 29th September 2003
8685
8686 WHILE l_current_record <= l_assign_resources_tbl.LAST
8687 LOOP
8688 -- Check the calendar for resource availability
8689 -- Call Calendar API
8690 -- IF the resource is available then accept the values and
8691 -- check for the WORKFLOW profile option
8692 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
8693 l_assign_resources_tbl(l_current_record).resource_type);
8694 fetch check_date_cur into l_value;
8695 if (check_date_cur%found)
8696 then
8697
8698 l_count := l_count + 1;
8699 x_assign_resources_tbl(l_count).terr_rsc_id :=
8700 l_assign_resources_tbl(l_current_record).terr_rsc_id;
8701 x_assign_resources_tbl(l_count).resource_id :=
8702 l_assign_resources_tbl(l_current_record).resource_id;
8703 x_assign_resources_tbl(l_count).resource_type :=
8704 l_assign_resources_tbl(l_current_record).resource_type;
8705 x_assign_resources_tbl(l_count).role :=
8706 l_assign_resources_tbl(l_current_record).role;
8707 x_assign_resources_tbl(l_count).start_date :=
8708 l_assign_resources_tbl(l_current_record).start_date;
8709 x_assign_resources_tbl(l_count).end_date :=
8710 l_assign_resources_tbl(l_current_record).end_date;
8711 x_assign_resources_tbl(l_count).shift_construct_id := NULL;
8712 x_assign_resources_tbl(l_count).terr_id :=
8713 l_assign_resources_tbl(l_current_record).terr_id;
8714 x_assign_resources_tbl(l_count).terr_name :=
8715 l_assign_resources_tbl(l_current_record).terr_name;
8716 x_assign_resources_tbl(l_count).primary_contact_flag :=
8717 l_assign_resources_tbl(l_current_record).primary_contact_flag;
8718 x_assign_resources_tbl(l_count).full_access_flag :=
8719 l_assign_resources_tbl(l_current_record).full_access_flag;
8720 x_assign_resources_tbl(l_count).group_id :=
8721 l_assign_resources_tbl(l_current_record).group_id;
8722 x_assign_resources_tbl(l_count).primary_flag :=
8723 l_assign_resources_tbl(l_current_record).primary_contact_flag;
8724 x_assign_resources_tbl(l_count).resource_source := 'TERR';
8725
8726 end if;
8727 close check_date_cur;
8728
8729 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
8730 END LOOP;
8731
8732 -- added calendar call out
8733 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
8734 -- changed on 29th September 2003
8735 IF (p_calendar_flag = 'Y') THEN
8736 -- change the API Name temporarily so that in case of unexpected error
8737 -- it is properly caught
8738 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
8739 l_return_status_1 := x_return_status ;
8740 -- call the api to check resource availability
8741 get_available_resources
8742 (
8743 p_init_msg_list => 'F',
8744 p_calendar_flag => p_calendar_flag,
8745 p_effort_duration => l_effort_duration,
8746 p_effort_uom => l_effort_uom,
8747 p_planned_start_date => l_planned_start_date,
8748 p_planned_end_date => l_planned_end_date,
8749 p_continuous_task => jtf_assign_pub.g_continuous_work,
8750 x_return_status => x_return_status,
8751 x_msg_count => x_msg_count,
8752 x_msg_data => x_msg_data,
8753 x_assign_resources_tbl => x_assign_resources_tbl);
8754
8755 -- set back the API name to original name
8756 l_api_name := l_api_name_1;
8757
8758 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
8759 -- Unexpected Execution Error from call to Get_contracts_resources
8760 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
8761 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
8762 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_ACCOUNT_RESOURCES');
8763 fnd_msg_pub.add;
8764 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
8765 RAISE fnd_api.g_exc_error;
8766 ELSE
8767 RAISE fnd_api.g_exc_unexpected_error;
8768 END IF;
8769 END IF; -- end of x_return_status check
8770 end if; -- if p_calendar_flag = Y
8771
8772 IF ( p_calendar_flag = 'Y' AND
8773 x_assign_resources_tbl.count = 0 ) THEN
8774 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
8775 fnd_msg_pub.add;
8776 -- RAISE fnd_api.g_exc_error;
8777 END IF;
8778
8779 -- to implement auto selection
8780 IF(l_auto_select_flag = 'Y')
8781 THEN
8782 l_temp_table.delete;
8783 l_temp_table := x_assign_resources_tbl;
8784 x_assign_resources_tbl.delete;
8785 l_count := 0;
8786 l_current_record := l_temp_table.FIRST;
8787 l_total_records := p_no_of_resources;
8788
8789 WHILE l_current_record <= l_temp_table.LAST
8790 LOOP
8791 If(l_count < l_total_records)
8792 THEN
8793 x_assign_resources_tbl(l_count) := l_temp_table(l_current_record);
8794 l_count := l_count + 1;
8795 end if; -- end of count check
8796 l_current_record := l_temp_table.NEXT(l_current_record);
8797 END LOOP; -- end of courrent record check
8798
8799 END IF; -- end of auto select flag
8800 ELSE -- No resources returned from the Territory API
8801 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
8802 fnd_msg_pub.add;
8803 -- RAISE fnd_api.g_exc_error;
8804 END IF;
8805
8806 ELSE -- Territory Flag is NO
8807 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
8808 fnd_msg_pub.add;
8809 -- RAISE fnd_api.g_exc_error;
8810 END IF;
8811
8812 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
8813
8814 -- raise workfow event
8815 -- workflow test
8816 Begin
8817 jtf_assign_pub.g_assign_resources_tbl.delete;
8818 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
8819 jtf_am_wf_events_pub.assign_acc_resource
8820 (P_API_VERSION => 1.0,
8821 P_INIT_MSG_LIST => 'F',
8822 P_COMMIT => 'F',
8823 P_ACCOUNT_REC => p_account_rec,
8824 P_BUSINESS_PROCESS_ID => p_business_process_id,
8825 P_BUSINESS_PROCESS_DATE => p_business_process_date,
8826 X_RETURN_STATUS => l_wf_return_status,
8827 X_MSG_COUNT => l_wf_msg_count,
8828 X_MSG_DATA => l_wf_msg_data
8829 );
8830
8831
8832 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
8833 -- Unexpected Execution Error from call to assign_sr_resource
8834 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
8835 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
8836 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_ACCOUNT_RESOURCES');
8837 fnd_msg_pub.add;
8838
8839 ELSE
8840 x_assign_resources_tbl.delete;
8841 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
8842 END IF;
8843
8844
8845 Exception
8846 When OTHERS Then
8847 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
8848 fnd_message.set_token('P_SQLCODE',SQLCODE);
8849 fnd_message.set_token('P_SQLERRM',SQLERRM);
8850 fnd_message.set_token('P_API_NAME',l_api_name);
8851 FND_MSG_PUB.add;
8852 End;
8853
8854 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
8855
8856
8857 -- To Plugin the Workflow enabling the user
8858 -- to further filter the resources
8859
8860 /* Getting the Workflow Profile value defined for the Assignment Manager */
8861
8862 --l_workflow_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_WORKFLOW_NAME' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
8863 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
8864
8865 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
8866 FROM dual;
8867
8868 IF (JTF_USR_HKS.ok_to_execute
8869 (
8870 'JTF_ASSIGN_PUB',
8871 'GET_ASSIGN_ACCOUNT_RESOURCES',
8872 'W',
8873 'W'
8874 )
8875 ) THEN
8876
8877 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
8878 (
8879 p_api_version => l_api_version,
8880 p_init_msg_list => p_init_msg_list,
8881 x_return_status => x_return_status,
8882 x_msg_count => x_msg_count,
8883 x_msg_data => x_msg_data
8884 )
8885 ) THEN
8886
8887 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
8888 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
8889 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
8890 fnd_msg_pub.add;
8891 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
8892 RAISE fnd_api.g_exc_error;
8893 ELSE
8894 RAISE fnd_api.g_exc_unexpected_error;
8895 END IF;
8896 END IF;
8897
8898 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
8899
8900 JTF_USR_HKS.WrkFlowLaunch
8901 (
8902 'JTF_ASSIGN_WF',
8903 l_workflow_profile,
8904 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
8905 l_bind_data_id,
8906 l_return_code
8907 );
8908
8909 JTF_USR_HKS.purge_bind_data
8910 (
8911 l_bind_data_id,
8912 'W'
8913 );
8914
8915 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
8916 -- Execution Error from call to Assignment Manager Workflow Hook
8917 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
8918 fnd_msg_pub.add;
8919 RAISE fnd_api.g_exc_error;
8920 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
8921 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
8922 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
8923 fnd_msg_pub.add;
8924 RAISE fnd_api.g_exc_unexpected_error;
8925 END IF;
8926
8927 END IF; -- End of JTF_ASSIGN_CUHK
8928
8929 END IF; -- End of JTF_USR_HKS
8930
8931
8932
8933
8934 /* Standard call to get message count and
8935 the message information */
8936
8937 FND_MSG_PUB.Count_And_Get
8938 (
8939 p_count => x_msg_count,
8940 p_data => x_msg_data
8941 );
8942
8943
8944
8945 EXCEPTION
8946 WHEN FND_API.G_EXC_ERROR THEN
8947 x_return_status := FND_API.G_RET_STS_ERROR ;
8948 FND_MSG_PUB.Count_And_Get
8949 (
8950 p_count => x_msg_count,
8951 p_data => x_msg_data
8952 );
8953
8954 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8955 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8956 FND_MSG_PUB.Count_And_Get
8957 (
8958 p_count => x_msg_count,
8959 p_data => x_msg_data
8960 );
8961
8962 WHEN OTHERS THEN
8963 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
8964 fnd_message.set_token('P_SQLCODE',SQLCODE);
8965 fnd_message.set_token('P_SQLERRM',SQLERRM);
8966 fnd_message.set_token('P_API_NAME',l_api_name);
8967 FND_MSG_PUB.add;
8968
8969 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8970 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
8971 FND_MSG_PUB.Add_Exc_Msg
8972 (
8973 G_PKG_NAME,
8974 l_api_name
8975 );
8976 END IF;
8977
8978 FND_MSG_PUB.Count_And_Get
8979 (
8980 p_count => x_msg_count,
8981 p_data => x_msg_data
8982 );
8983
8984 END GET_ASSIGN_ACCOUNT_RESOURCES;
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997 -- *******************************************************************************
8998
8999 -- Start of comments
9000
9001 -- API name : GET_ASSIGN_DEFECT_RESOURCES
9002 -- Type : Public
9003 -- Function : Determine the resources based on the customer
9004 -- preferences or territory preferences and the
9005 -- availability. This is when the calling doc is
9006 -- DEFECT MANAGEMENT SYSTEM.
9007 -- Pre-reqs : None
9008
9009 -- Parameters :
9010
9011 -- IN : p_api_version IN NUMBER Required
9012 -- p_init_msg_list IN VARCHAR2 Optional
9013 -- DEFAULT = FND_API.G_FALSE
9014 -- Assignment Manager Specific Parameters
9015
9016 -- This determines the Resource Type required by the
9017 -- calling document
9018 -- p_resource_type VARCHAR2(30)
9019 -- p_role VARCHAR2(30)
9020
9021 -- This determines the number of resources required
9022 -- by the calling document
9023 -- p_no_of_resources NUMBER,
9024
9025 -- This is for sending out the qualified resource directly
9026 -- to the calling form. Defaulted to the PROFILE value
9027 -- p_auto_select_flag VARCHAR2(1)
9028 -- : value of Y or N
9029
9030 -- The Effort required is determined by these two parameters
9031 -- p_effort_duration NUMBER
9032 -- p_effort_uom VARCHAR2(10)
9033
9034 -- The Dates in which the resource is required, is determined
9035 -- by these two parameters
9036 -- p_start_date DATE
9037 -- p_end_date DATE
9038
9039 -- The Territory Manager is accessed based on the value set
9040 -- p_territory_flag VARCHAR2(1)
9041 -- : value of Y or N
9042
9043 -- The Resource Availability is checked based on the value set
9044 -- p_calendar_flag VARCHAR2(1)
9045 -- : value of Y or N
9046
9047
9048 -- This parameter contains the Qualifier Values
9049 -- of the Calling Document
9050 -- p_defect_rec JTF_TERRITORY_PUB.
9051 -- JTF_DEF_MGMT_rec_type
9052
9053
9054 -- OUT : x_return_status OUT VARCHAR2(1)
9055 -- x_msg_count OUT NUMBER
9056 -- x_msg_data OUT VARCHAR2(2000)
9057 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
9058 -- AssignResources_tbl_type
9059
9060
9061 -- Version : Current version 1.0
9062 -- Initial version 1.0
9063 --
9064 -- Notes :
9065 --
9066
9067 -- End of comments
9068 -- *********************************************************************************
9069
9070
9071
9072 -- Procedure definition with the parameters when the
9073 -- Source Document is DEFECT MANAGEMENT SYSTEM
9074
9075 PROCEDURE GET_ASSIGN_DEFECT_RESOURCES
9076 (
9077 p_api_version IN NUMBER,
9078 p_init_msg_list IN VARCHAR2,
9079 p_resource_type IN VARCHAR2,
9080 p_role IN VARCHAR2,
9081 p_no_of_resources IN NUMBER,
9082 p_auto_select_flag IN VARCHAR2,
9083 p_effort_duration IN NUMBER,
9084 p_effort_uom IN VARCHAR2,
9085 p_start_date IN DATE,
9086 p_end_date IN DATE,
9087 p_territory_flag IN VARCHAR2,
9088 p_calendar_flag IN VARCHAR2,
9089 p_defect_rec IN JTF_TERRITORY_PUB.JTF_DEF_MGMT_rec_type,
9090 p_business_process_id IN NUMBER,
9091 p_business_process_date IN DATE,
9092 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
9093 x_return_status OUT NOCOPY VARCHAR2,
9094 x_msg_count OUT NOCOPY NUMBER,
9095 x_msg_data OUT NOCOPY VARCHAR2
9096 )
9097 IS
9098 l_return_status_1 VARCHAR2(10);
9099 l_api_name VARCHAR2(100) := 'GET_ASSIGN_DEFECT_RESOURCES';
9100 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_DEFECT_RESOURCES';
9101 l_api_version NUMBER := 1.0;
9102 l_planned_start_date DATE;
9103 l_planned_end_date DATE;
9104 l_travel_time NUMBER := 0;
9105 l_travel_uom VARCHAR2(30) := 'HR';
9106
9107 l_current_record INTEGER;
9108 l_total_records INTEGER;
9109
9110 l_assign_resources_tbl JTF_TERRITORY_PUB.WinningTerrMember_tbl_type;
9111 -- l_assign_resources_rec JTF_TERRITORY_PUB.JTF_DEF_MGMT_rec_type;
9112
9113 l_x_planned_start_date DATE;
9114 l_x_planned_end_date DATE;
9115 l_x_shift_construct_id NUMBER;
9116 l_x_availability_type VARCHAR2(60);
9117
9118 l_count NUMBER := 1;
9119
9120
9121
9122 BEGIN
9123 SAVEPOINT get_assign_defect_resources;
9124
9125 -- Started Assignment Manager API for DEFECT MANAGEMENT SYSTEM
9126
9127
9128
9129 /* Standard call to check for call compatibility */
9130
9131 IF NOT fnd_api.compatible_api_call (l_api_version,
9132 p_api_version,
9133 l_api_name,
9134 g_pkg_name) THEN
9135 RAISE fnd_api.g_exc_unexpected_error;
9136 END IF;
9137
9138
9139
9140 /* Initialize message list if p_init_msg_list is set to TRUE */
9141
9142 IF fnd_api.to_boolean (p_init_msg_list) THEN
9143 fnd_msg_pub.initialize;
9144 END IF;
9145
9146 x_return_status := fnd_api.g_ret_sts_success;
9147
9148
9149
9150
9151 /* Defaulting the variable values to IN parameters,
9152 if the IN paramaters have values given */
9153
9154
9155 IF (p_start_date IS NOT NULL) THEN
9156 l_planned_start_date := p_start_date;
9157 ELSE
9158 l_planned_start_date := SYSDATE;
9159 END IF;
9160
9161 IF (p_end_date IS NOT NULL) THEN
9162 l_planned_end_date := p_end_date;
9163 ELSE
9164 l_planned_end_date := SYSDATE;
9165 END IF;
9166
9167
9168
9169
9170 /* Actual Flow of Assignment Manager */
9171
9172
9173 IF (p_territory_flag = 'Y') THEN
9174
9175 -- change the API Name temporarily so that in case of unexpected error
9176 -- it is properly caught
9177 l_api_name := l_api_name||'-JTF_TERR_DEF_MGMT_PUB';
9178
9179 JTF_TERR_DEF_MGMT_PUB.Get_WinningTerrMembers
9180 (
9181 p_api_version_number => l_api_version,
9182 p_init_msg_list => p_init_msg_list,
9183 p_TerrDefMgmt_Rec => p_defect_rec,
9184 p_Resource_Type => p_resource_type,
9185 p_Role => p_role,
9186 x_return_status => x_return_status,
9187 x_msg_count => x_msg_count,
9188 x_msg_data => x_msg_data,
9189 x_TerrResource_tbl => l_assign_resources_tbl
9190 );
9191
9192 -- set back the API name to original name
9193 l_api_name := l_api_name_1;
9194
9195 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
9196 -- Unexpected Execution Error from call to Territory Manager
9197 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
9198 fnd_msg_pub.add;
9199 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
9200 RAISE fnd_api.g_exc_error;
9201 ELSE
9202 RAISE fnd_api.g_exc_unexpected_error;
9203 END IF;
9204 END IF;
9205
9206 ELSE -- Territory Flag is NO
9207 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
9208 fnd_msg_pub.add;
9209 -- RAISE fnd_api.g_exc_error;
9210 END IF;
9211
9212 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
9213
9214 IF(l_assign_resources_tbl.COUNT > 0)
9215 THEN
9216 l_current_record := l_assign_resources_tbl.FIRST;
9217 WHILE l_current_record <= l_assign_resources_tbl.LAST
9218 LOOP
9219 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
9220 THEN
9221 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
9222 END IF;
9223 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
9224 END LOOP;
9225 END IF;
9226
9227 IF l_assign_resources_tbl.COUNT > 0 THEN
9228
9229
9230 x_assign_resources_tbl.delete;
9231
9232 l_current_record := l_assign_resources_tbl.FIRST;
9233
9234 IF (p_auto_select_flag = 'Y') THEN
9235 l_total_records := p_no_of_resources;
9236 ELSE
9237 l_total_records := l_assign_resources_tbl.LAST;
9238 END IF;
9239
9240 -- added processing with l_count to fix bug for Defects 2490634
9241 -- on 6th aug 2002
9242
9243 WHILE l_current_record <= l_assign_resources_tbl.LAST
9244 LOOP
9245
9246 -- removed the calendar check here. calling the procedure for calendar check in the next step
9247 -- calendar check removed 29th September 2003
9248 -- removed the autoselect check. This will be done in the GET_ASSIGN_RESOURCES api
9249 --IF (l_count <= l_total_records) THEN
9250 x_assign_resources_tbl(l_count).terr_rsc_id :=
9251 l_assign_resources_tbl(l_current_record).terr_rsc_id;
9252 x_assign_resources_tbl(l_count).resource_id :=
9253 l_assign_resources_tbl(l_current_record).resource_id;
9254 x_assign_resources_tbl(l_count).resource_type :=
9255 l_assign_resources_tbl(l_current_record).resource_type;
9256
9257 x_assign_resources_tbl(l_count).start_date :=
9258 l_assign_resources_tbl(l_current_record).start_date;
9259 x_assign_resources_tbl(l_count).end_date :=
9260 l_assign_resources_tbl(l_current_record).end_date;
9261 x_assign_resources_tbl(l_count).shift_construct_id := NULL;
9262
9263 x_assign_resources_tbl(l_count).role :=
9264 l_assign_resources_tbl(l_current_record).role;
9265 x_assign_resources_tbl(l_count).primary_contact_flag :=
9266 l_assign_resources_tbl(l_current_record).primary_contact_flag;
9267
9268 x_assign_resources_tbl(l_count).terr_id :=
9269 l_assign_resources_tbl(l_current_record).terr_id;
9270 x_assign_resources_tbl(l_count).terr_name :=
9271 l_assign_resources_tbl(l_current_record).terr_name;
9272 x_assign_resources_tbl(l_count).terr_rank :=
9273 l_assign_resources_tbl(l_current_record).absolute_rank;
9274 x_assign_resources_tbl(l_count).primary_flag :=
9275 l_assign_resources_tbl(l_current_record).primary_contact_flag;
9276 x_assign_resources_tbl(l_count).resource_source := 'TERR';
9277
9278 l_count := l_count + 1;
9279 --END IF;
9280 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
9281 END LOOP;
9282
9283 -- added calendar call out
9284 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
9285 -- changed on 29th September 2003
9286 IF (p_calendar_flag = 'Y') THEN
9287 -- change the API Name temporarily so that in case of unexpected error
9288 -- it is properly caught
9289 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
9290 l_return_status_1 := x_return_status ;
9291 -- call the api to check resource availability
9292 get_available_resources
9293 (
9294 p_init_msg_list => 'F',
9295 p_calendar_flag => p_calendar_flag,
9296 p_effort_duration => p_effort_duration,
9297 p_effort_uom => p_effort_uom,
9298 p_planned_start_date => l_planned_start_date,
9299 p_planned_end_date => l_planned_end_date,
9300 p_continuous_task => jtf_assign_pub.g_continuous_work,
9301 x_return_status => x_return_status,
9302 x_msg_count => x_msg_count,
9303 x_msg_data => x_msg_data,
9304 x_assign_resources_tbl => x_assign_resources_tbl);
9305
9306 -- set back the API name to original name
9307 l_api_name := l_api_name_1;
9308
9309 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
9310 -- Unexpected Execution Error from call to Get_contracts_resources
9311 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
9312 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
9313 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_DEFECT_RESOURCES');
9314 fnd_msg_pub.add;
9315 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
9316 RAISE fnd_api.g_exc_error;
9317 ELSE
9318 RAISE fnd_api.g_exc_unexpected_error;
9319 END IF;
9320 END IF; -- end of x_return_status check
9321 end if; -- if p_calendar_flag = Y
9322
9323
9324 IF ( p_calendar_flag = 'Y' AND
9325 x_assign_resources_tbl.count = 0 ) THEN
9326 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
9327 fnd_msg_pub.add;
9328 -- RAISE fnd_api.g_exc_error;
9329 END IF;
9330
9331 ELSE -- No resources returned from the Territory API
9332 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
9333 fnd_msg_pub.add;
9334 -- RAISE fnd_api.g_exc_error;
9335 END IF;
9336
9337
9338 /* Standard call to get message count and
9339 the message information */
9340
9341 FND_MSG_PUB.Count_And_Get
9342 (
9343 p_count => x_msg_count,
9344 p_data => x_msg_data
9345 );
9346
9347
9348 EXCEPTION
9349 WHEN FND_API.G_EXC_ERROR THEN
9350 x_return_status := FND_API.G_RET_STS_ERROR ;
9351 FND_MSG_PUB.Count_And_Get
9352 (
9353 p_count => x_msg_count,
9354 p_data => x_msg_data
9355 );
9356
9357 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9358 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9359 FND_MSG_PUB.Count_And_Get
9360 (
9361 p_count => x_msg_count,
9362 p_data => x_msg_data
9363 );
9364
9365 WHEN OTHERS THEN
9366 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
9367 fnd_message.set_token('P_SQLCODE',SQLCODE);
9368 fnd_message.set_token('P_SQLERRM',SQLERRM);
9369 fnd_message.set_token('P_API_NAME',l_api_name);
9370 FND_MSG_PUB.add;
9371
9372 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
9373 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
9374 FND_MSG_PUB.Add_Exc_Msg
9375 (
9376 G_PKG_NAME,
9377 l_api_name
9378 );
9379 END IF;
9380
9381 FND_MSG_PUB.Count_And_Get
9382 (
9383 p_count => x_msg_count,
9384 p_data => x_msg_data
9385 );
9386
9387 END GET_ASSIGN_DEFECT_RESOURCES;
9388
9389
9390
9391
9392
9393
9394 -- *******************************************************************************
9395
9396 -- Start of comments
9397
9398 -- API name : GET_ASSIGN_ESC_RESOURCES
9399 -- Type : Public
9400 -- Function : Determine the resources based on the
9401 -- territory preferences and the availability.
9402 -- This is when the calling doc is ESCALATIONS.
9403 -- Pre-reqs : None
9404
9405 -- Parameters :
9406
9407 -- IN : p_api_version IN NUMBER Required
9408 -- p_init_msg_list IN VARCHAR2 Optional
9409 -- p_commit IN VARCHAR2 optional
9410
9411 -- Assignment Manager Specific Parameters
9412
9413 -- This determines the Resource Type required by the
9414 -- calling document
9415 -- p_resource_type VARCHAR2(30)
9416 -- p_role VARCHAR2(30)
9417
9418 -- This determines the number of resources required
9419 -- by the calling document
9420 -- p_no_of_resources NUMBER,
9421
9422 -- This is for sending out the qualified resource directly
9423 -- to the calling form. Defaulted to the PROFILE value
9424 -- p_auto_select_flag VARCHAR2(1)
9425 -- : value of Y or N
9426
9427 -- The Effort required is determined by these two parameters
9428 -- p_effort_duration NUMBER
9429 -- p_effort_uom VARCHAR2(10)
9430
9431 -- The Dates in which the resource is required, is determined
9432 -- by these two parameters
9433 -- p_start_date DATE
9434 -- p_end_date DATE
9435
9436 -- The Territory Manager is accessed based on the value set
9437 -- p_territory_flag VARCHAR2(1)
9438 -- : value of Y or N
9439
9440 -- The Resource Availability is checked based on the value set
9441 -- p_calendar_flag VARCHAR2(1)
9442 -- : value of Y or N
9443
9444
9445 -- This parameter contains the values of the Qualifiers
9446 -- defined for the Escalations.
9447 -- p_esc_tbl JTF_ASSIGN_PUB.
9448 -- Escalations_tbl_type
9449 -- REQUIRED
9450
9451
9452 -- OUT : x_return_status OUT VARCHAR2(1)
9453 -- x_msg_count OUT NUMBER
9454 -- x_msg_data OUT VARCHAR2(2000)
9455 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
9456 -- AssignResources_tbl_type
9457
9458
9459 -- Version : Current version 1.0
9460 -- Initial version 1.0
9461 --
9462 -- Notes :
9463 --
9464
9465 -- End of comments
9466
9467 -- *********************************************************************************
9468
9469
9470 /* Procedure Body with the parameters when the
9471 Source Document is ESCALATIONS */
9472
9473
9474 PROCEDURE GET_ASSIGN_ESC_RESOURCES
9475 (
9476 p_api_version IN NUMBER,
9477 p_init_msg_list IN VARCHAR2 ,
9478 p_resource_type IN VARCHAR2 ,
9479 p_role IN VARCHAR2 ,
9480 p_no_of_resources IN NUMBER ,
9481 p_auto_select_flag IN VARCHAR2 ,
9482 p_effort_duration IN NUMBER ,
9483 p_effort_uom IN VARCHAR2 ,
9484 p_start_date IN DATE ,
9485 p_end_date IN DATE ,
9486 p_territory_flag IN VARCHAR2 ,
9487 p_calendar_flag IN VARCHAR2 ,
9488 p_web_availability_flag IN VARCHAR2 ,
9489 p_esc_tbl IN JTF_ASSIGN_PUB.Escalations_tbl_type,
9490 p_business_process_id IN NUMBER,
9491 p_business_process_date IN DATE,
9492 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
9493 x_return_status OUT NOCOPY VARCHAR2,
9494 x_msg_count OUT NOCOPY NUMBER,
9495 x_msg_data OUT NOCOPY VARCHAR2
9496 )
9497 IS
9498
9499 l_return_status_1 VARCHAR2(10);
9500 l_api_name VARCHAR2(100) := 'GET_ASSIGN_ESC_RESOURCES';
9501 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_ESC_RESOURCES';
9502 l_api_version NUMBER := 1.0;
9503 l_planned_start_date DATE;
9504 l_planned_end_date DATE;
9505 l_effort_duration NUMBER;
9506 l_effort_uom VARCHAR2(30);
9507
9508 l_esc_source_code JTF_TASKS_VL.SOURCE_OBJECT_TYPE_CODE%TYPE;
9509 l_esc_source_id JTF_TASKS_VL.SOURCE_OBJECT_ID%TYPE;
9510 l_reference_code JTF_TASK_REFERENCES_VL.REFERENCE_CODE%TYPE;
9511
9512 l_territory_id NUMBER;
9513 l_esc_territory_id NUMBER;
9514
9515 l_object_type_code JTF_TASK_REFERENCES_VL.OBJECT_TYPE_CODE%TYPE;
9516 l_object_id JTF_TASK_REFERENCES_VL.OBJECT_ID%TYPE;
9517
9518 l_travel_time NUMBER := 0;
9519 l_travel_uom VARCHAR2(30) := 'HR';
9520
9521 l_current_record INTEGER;
9522 l_current_esc_record INTEGER DEFAULT 0;
9523 l_esc_record INTEGER;
9524 l_total_records INTEGER;
9525
9526 l_auto_select_profile VARCHAR2(03);
9527 l_auto_select_flag VARCHAR2(03);
9528 l_workflow_profile VARCHAR2(60);
9529
9530 l_return_code VARCHAR2(60);
9531 l_bind_data_id NUMBER;
9532 l_workflow_key NUMBER;
9533
9534 l_dynamic_sql VARCHAR2(2000);
9535 l_dynamic_sql1 VARCHAR2(2000);
9536
9537 l_assign_resources_tbl JTF_TERRITORY_GET_PUB.QualifyingRsc_out_tbl_type;
9538
9539 l_x_planned_start_date DATE;
9540 l_x_planned_end_date DATE;
9541 l_x_shift_construct_id NUMBER;
9542 l_x_availability_type VARCHAR2(60);
9543
9544 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
9545
9546 l_wf_return_status VARCHAR2(60);
9547 l_wf_msg_count NUMBER;
9548 l_wf_msg_data VARCHAR2(2000);
9549 l_esc_count NUMBER;
9550
9551 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
9552
9553
9554 /*
9555 CURSOR cur_esc_id IS
9556 SELECT source_object_type_code,
9557 source_object_id,
9558 planned_start_date,
9559 planned_end_date,
9560 planned_effort,
9561 planned_effort_uom
9562 FROM jtf_tasks_vl
9563 WHERE task_id = l_esc_id;
9564 l_cur_esc_id cur_esc_id%ROWTYPE;
9565
9566
9567 CURSOR cur_reference_code IS
9568 SELECT reference_code,
9569 object_type_code,
9570 object_id
9571 FROM jtf_task_references_vl
9572 WHERE task_id = l_esc_id;
9573 l_cur_reference_code cur_reference_code%ROWTYPE;
9574 */
9575
9576
9577 CURSOR cur_source_task IS
9578 SELECT owner_territory_id
9579 FROM jtf_tasks_vl
9580 WHERE task_id = l_object_id;
9581
9582
9583 TYPE DYNAMIC_CUR_TYP IS REF CURSOR;
9584
9585 cur_source_sr DYNAMIC_CUR_TYP;
9586 cur_source_defect DYNAMIC_CUR_TYP;
9587
9588 cur_support_site_name DYNAMIC_CUR_TYP;
9589
9590 l_support_site VARCHAR2(15) := 'SUPPORT_SITE';
9591 l_rsc_type VARCHAR2(30);
9592 l_rsc_id NUMBER;
9593 l_web_availability_flag VARCHAR2(1) := p_web_availability_flag;
9594
9595
9596 CURSOR cur_support_site_id (p_rsc_id NUMBER, p_rsc_type VARCHAR2) IS
9597 SELECT support_site_id
9598 FROM jtf_rs_resource_extns_vl
9599 WHERE resource_id = p_rsc_id AND
9600 category = p_rsc_type;
9601
9602
9603 CURSOR cur_web_availability (p_res_id NUMBER, p_res_type VARCHAR2) IS
9604 SELECT resource_id
9605 FROM jtf_rs_web_available_v
9606 WHERE resource_id = p_res_id AND
9607 category = p_res_type;
9608
9609 --Bug# 4455803 MOAC.
9610 CURSOR check_date_cur(l_resource_id in number,
9611 l_resource_type in varchar2)
9612 IS
9613 SELECT 'Y'
9614 --FROM jtf_rs_all_resources_vl
9615 FROM jtf_task_resources_vl
9616 where resource_id = l_resource_id
9617 and resource_type = l_resource_type
9618 and nvl(trunc(end_date_active), trunc(sysdate)) >= trunc(sysdate);
9619
9620 l_value varchar2(100);
9621
9622 l_count number := 0;
9623 l_temp_table JTF_ASSIGN_PUB.AssignResources_tbl_type;
9624
9625 BEGIN
9626
9627 SAVEPOINT get_assign_esc_resources;
9628
9629 -- Started Assignment Manager API for ESCALATIONS
9630
9631
9632 /* Standard call to check for call compatibility */
9633
9634 IF NOT fnd_api.compatible_api_call (l_api_version,
9635 p_api_version,
9636 l_api_name,
9637 g_pkg_name) THEN
9638 RAISE fnd_api.g_exc_unexpected_error;
9639 END IF;
9640
9641
9642 /* Initialize message list if p_init_msg_list is set to TRUE */
9643
9644 IF fnd_api.to_boolean (p_init_msg_list) THEN
9645 fnd_msg_pub.initialize;
9646 END IF;
9647
9648 x_return_status := fnd_api.g_ret_sts_success;
9649
9650
9651
9652 /* Get TASK source and the related information */
9653
9654 /*
9655 OPEN cur_esc_id;
9656 FETCH cur_esc_id INTO l_cur_esc_id;
9657 IF ( cur_esc_id%NOTFOUND ) THEN
9658 fnd_message.set_name('JTF', 'JTF_AM_INVALID_ESC_ID');
9659 fnd_msg_pub.add;
9660 RAISE fnd_api.g_exc_error;
9661 ELSE
9662 l_esc_source_code := l_cur_esc_id.source_object_type_code;
9663 l_esc_source_id := l_cur_esc_id.source_object_id;
9664 l_planned_start_date := l_cur_esc_id.planned_start_date;
9665 l_planned_end_date := l_cur_esc_id.planned_end_date;
9666 l_effort_duration := l_cur_esc_id.planned_effort;
9667 l_effort_uom := l_cur_esc_id.planned_effort_uom;
9668 END IF;
9669 CLOSE cur_esc_id;
9670
9671
9672 IF ( l_esc_source_code <> 'ESC' ) THEN
9673 fnd_message.set_name('JTF', 'JTF_AM_INVALID_ESC_ID');
9674 fnd_msg_pub.add;
9675 RAISE fnd_api.g_exc_error;
9676 ELSE
9677 OPEN cur_reference_code;
9678 FETCH cur_reference_code INTO l_cur_reference_code;
9679 IF ( cur_reference_code%NOTFOUND) THEN
9680 fnd_message.set_name('JTF', 'JTF_AM_INVALID_ESC_ID');
9681 fnd_msg_pub.add;
9682 RAISE fnd_api.g_exc_error;
9683 ELSE
9684 l_reference_code := l_cur_reference_code.reference_code;
9685 l_object_type_code := l_cur_reference_code.object_type_code;
9686 l_object_id := l_cur_reference_code.object_id;
9687
9688 IF ( l_reference_code <> 'ESC' ) THEN
9689 fnd_message.set_name('JTF', 'JTF_AM_INVALID_ESC_REF');
9690 fnd_msg_pub.add;
9691 RAISE fnd_api.g_exc_error;
9692 END IF;
9693 END IF;
9694 CLOSE cur_reference_code;
9695 END IF;
9696
9697 */
9698
9699
9700 /* Getting the Auto Select Profile value defined for the Assignment Manager */
9701
9702 --l_auto_select_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_AUTO_SELECT' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
9703 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
9704
9705
9706
9707 /* Assigning the DEFAULT value to the Auto Select Parameter */
9708
9709
9710 IF (p_auto_select_flag IS NULL) THEN
9711 l_auto_select_flag := l_auto_select_profile;
9712 -- PROFILE VALUE is the default value
9713 ELSE
9714 l_auto_select_flag := p_auto_select_flag;
9715 END IF;
9716
9717
9718 IF ( p_web_availability_flag IS NULL) THEN
9719 l_web_availability_flag := 'Y';
9720 ELSE
9721 l_web_availability_flag := p_web_availability_flag;
9722 END IF;
9723
9724
9725 /* Defaulting the values for variables to pass to the
9726 Calendar, to ensure that the resource is working */
9727
9728 l_planned_start_date := SYSDATE;
9729 l_planned_end_date := SYSDATE;
9730 l_effort_duration := NULL;
9731 l_effort_uom := NULL;
9732
9733
9734 /* Defaulting the variable values to IN parameters,
9735 if the IN paramaters have values given */
9736
9737 IF (p_start_date IS NOT NULL) THEN
9738 l_planned_start_date := p_start_date;
9739 END IF;
9740
9741 IF (p_end_date IS NOT NULL) THEN
9742 l_planned_end_date := p_end_date;
9743 END IF;
9744
9745 IF (p_effort_duration IS NOT NULL) THEN
9746 l_effort_duration := p_effort_duration;
9747 END IF;
9748
9749 IF (p_effort_uom IS NOT NULL) THEN
9750 l_effort_uom := p_effort_uom;
9751 END IF;
9752
9753
9754
9755 /* Actual Flow of Assignment Manager */
9756
9757
9758 IF ( p_esc_tbl.count > 0 ) THEN
9759
9760 l_esc_record := p_esc_tbl.FIRST;
9761
9762 WHILE (l_esc_record <= p_esc_tbl.LAST)
9763 LOOP
9764
9765 l_object_type_code := p_esc_tbl(l_esc_record).source_object_type;
9766 l_object_id := p_esc_tbl(l_esc_record).source_object_id;
9767
9768
9769 IF (l_object_type_code = 'TASK') THEN
9770
9771 /* Since the Object Code is TASK, OPEN the appropriate cursor
9772 to get the Territory ID to pass it to the Territory API */
9773
9774 OPEN cur_source_task;
9775 FETCH cur_source_task INTO l_territory_id;
9776
9777 IF ( cur_source_task%NOTFOUND ) THEN
9778 fnd_message.set_name('JTF', 'JTF_AM_INVALID_TASK_ID');
9779 fnd_msg_pub.add;
9780 RAISE fnd_api.g_exc_error;
9781 END IF;
9782
9783 CLOSE cur_source_task;
9784
9785 ELSIF (l_object_type_code = 'SR') THEN
9786
9787 /* Since the Object Code is SERVICE REQUEST, OPEN the appropriate
9788 cursor to get the Territory ID to pass it to the Territory API */
9789
9790 l_dynamic_sql := ' SELECT territory_id'||
9791 ' FROM cs_incidents_all_vl'||
9792 ' WHERE incident_id = :1';
9793
9794
9795 OPEN cur_source_sr FOR l_dynamic_sql USING l_object_id;
9796 FETCH cur_source_sr INTO l_territory_id;
9797
9798 IF ( cur_source_sr%NOTFOUND ) THEN
9799 fnd_message.set_name('JTF', 'JTF_AM_INVALID_SR_ID');
9800 fnd_msg_pub.add;
9801 RAISE fnd_api.g_exc_error;
9802 END IF;
9803
9804 CLOSE cur_source_sr;
9805
9806
9807 ELSIF (l_object_type_code = 'DF') THEN
9808
9809 /* Since the Object Code is DEFECTS, OPEN the appropriate cursor
9810 to get the Territory ID to pass it to the Territory API */
9811
9812
9813 l_dynamic_sql := ' SELECT territory_id'||
9814 ' FROM css_def_defects_all'||
9815 ' WHERE defect_id = :1';
9816
9817 -- dbms_output.put_line('Select is : '||l_dynamic_sql);
9818
9819 OPEN cur_source_defect FOR l_dynamic_sql USING l_object_id;
9820 FETCH cur_source_defect INTO l_territory_id;
9821
9822 IF ( cur_source_defect%NOTFOUND ) THEN
9823 fnd_message.set_name('JTF', 'JTF_AM_INVALID_DEFECT_ID');
9824 fnd_msg_pub.add;
9825 RAISE fnd_api.g_exc_error;
9826 END IF;
9827
9828 CLOSE cur_source_defect;
9829
9830
9831 END IF; -- End of l_object_type_code = 'TASK'
9832
9833
9834
9835
9836 IF (p_territory_flag = 'Y') THEN
9837
9838 IF (l_territory_id IS NOT NULL) THEN
9839
9840 -- change the API Name temporarily so that in case of unexpected error
9841 -- it is properly caught
9842 l_api_name := l_api_name||'-JTF_TERRITORY_GET_PUB';
9843
9844 JTF_TERRITORY_GET_PUB.Get_Escalation_Territory
9845 (
9846 p_api_version => l_api_version,
9847 p_init_msg_list => p_init_msg_list,
9848 x_return_status => x_return_status,
9849 x_msg_count => x_msg_count,
9850 x_msg_data => x_msg_data,
9851 p_terr_id => l_territory_id,
9852 x_escalation_terr_id => l_esc_territory_id
9853 );
9854
9855 -- set back the API name to original name
9856 l_api_name := l_api_name_1;
9857
9858
9859 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
9860 -- Unexpected Execution Error from call to Territory Manager
9861 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
9862 fnd_msg_pub.add;
9863 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
9864 RAISE fnd_api.g_exc_error;
9865 ELSE
9866 RAISE fnd_api.g_exc_unexpected_error;
9867 END IF;
9868 END IF;
9869
9870 l_assign_resources_tbl.DELETE;
9871
9872 IF ( l_esc_territory_id IS NOT NULL) THEN
9873
9874 -- change the API Name temporarily so that in case of unexpected error
9875 -- it is properly caught
9876 l_api_name := l_api_name||'-JTF_TERRITORY_GET_PUB';
9877
9878 JTF_TERRITORY_GET_PUB.Get_Escalation_TerrMembers
9879 (
9880 p_api_version_number => l_api_version,
9881 p_init_msg_list => p_init_msg_list,
9882 p_commit => NULL,
9883 x_return_status => x_return_status,
9884 x_msg_count => x_msg_count,
9885 x_msg_data => x_msg_data,
9886 p_terr_id => l_esc_territory_id,
9887 x_QualifyingRsc_out_tbl => l_assign_resources_tbl
9888 );
9889
9890 -- set back the API name to original name
9891 l_api_name := l_api_name_1;
9892
9893 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
9894 -- Unexpected Execution Error from call to Territory Manager
9895 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
9896 fnd_msg_pub.add;
9897 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
9898 RAISE fnd_api.g_exc_error;
9899 ELSE
9900 RAISE fnd_api.g_exc_unexpected_error;
9901 END IF;
9902 END IF;
9903
9904 --ELSE
9905 --fnd_message.set_name('JTF', 'JTF_AM_NO_ESC_TERR');
9906 --fnd_msg_pub.add;
9907 --RAISE fnd_api.g_exc_error;
9908 END IF;
9909
9910 END IF; -- IF (l_territory_id IS NOT NULL) THEN
9911
9912
9913 IF ( l_assign_resources_tbl.COUNT = 0 ) THEN
9914
9915 -- change the API Name temporarily so that in case of unexpected error
9916 -- it is properly caught
9917 l_api_name := l_api_name||'-JTF_TERRITORY_GET_PUB';
9918
9919 JTF_TERRITORY_GET_PUB.Get_Escalation_TerrMembers
9920 (
9921 p_api_version_number => l_api_version,
9922 p_init_msg_list => p_init_msg_list,
9923 p_commit => NULL,
9924 x_return_status => x_return_status,
9925 x_msg_count => x_msg_count,
9926 x_msg_data => x_msg_data,
9927 p_terr_id => 1,
9928 x_QualifyingRsc_out_tbl => l_assign_resources_tbl
9929 );
9930
9931 -- set back the API name to original name
9932 l_api_name := l_api_name_1;
9933
9934 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
9935 -- Unexpected Execution Error from call to Territory Manager
9936 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
9937 fnd_msg_pub.add;
9938 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
9939 RAISE fnd_api.g_exc_error;
9940 ELSE
9941 RAISE fnd_api.g_exc_unexpected_error;
9942 END IF;
9943 END IF;
9944 END IF;
9945
9946
9947
9948 -- added 2 april 2003 by sudarsana to conver RS_SUPPLIER TO RS_SUPPLIER_CONTACT
9949
9950 IF(l_assign_resources_tbl.COUNT > 0)
9951 THEN
9952 l_current_record := l_assign_resources_tbl.FIRST;
9953 WHILE (l_current_record <= l_assign_resources_tbl.LAST)
9954 LOOP
9955 IF(l_assign_resources_tbl(l_current_record).resource_type = 'RS_SUPPLIER')
9956 THEN
9957 l_assign_resources_tbl(l_current_record).resource_type := 'RS_SUPPLIER_CONTACT';
9958 END IF;
9959 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
9960 END LOOP;
9961 END IF;
9962
9963
9964 IF l_assign_resources_tbl.COUNT > 0 THEN
9965
9966 l_current_record := l_assign_resources_tbl.FIRST;
9967
9968
9969 IF (l_auto_select_flag = 'Y') THEN
9970 l_total_records := p_no_of_resources;
9971 ELSE
9972 l_total_records := l_assign_resources_tbl.LAST;
9973 END IF;
9974
9975 -- removed the calendar check here. calling the procedure for calendar check in the next step
9976 -- calendar check removed 29th September 2003
9977 WHILE l_current_record <= l_assign_resources_tbl.LAST
9978 LOOP
9979
9980 -- removed the calendar check here. calling the procedure for calendar check in the next step
9981 -- calendar check removed 29th September 2003
9982 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
9983 l_assign_resources_tbl(l_current_record).resource_type);
9984 fetch check_date_cur into l_value;
9985 if (check_date_cur%found)
9986 then
9987
9988 l_count := l_count + 1;
9989
9990 x_assign_resources_tbl(l_count).terr_rsc_id :=
9991 l_assign_resources_tbl(l_current_record).terr_rsc_id;
9992 x_assign_resources_tbl(l_count).resource_id :=
9993 l_assign_resources_tbl(l_current_record).resource_id;
9994 x_assign_resources_tbl(l_count).resource_type :=
9995 l_assign_resources_tbl(l_current_record).resource_type;
9996 x_assign_resources_tbl(l_count).role :=
9997 l_assign_resources_tbl(l_current_record).role;
9998 x_assign_resources_tbl(l_count).start_date := NULL;
9999 x_assign_resources_tbl(l_count).end_date := NULL;
10000 x_assign_resources_tbl(l_count).shift_construct_id := NULL;
10001 x_assign_resources_tbl(l_count).terr_id :=
10002 l_assign_resources_tbl(l_current_record).terr_id;
10003 x_assign_resources_tbl(l_count).terr_name :=
10004 l_assign_resources_tbl(l_current_record).terr_name;
10005 x_assign_resources_tbl(l_count).primary_contact_flag :=
10006 l_assign_resources_tbl(l_current_record).primary_contact_flag;
10007 x_assign_resources_tbl(l_count).primary_flag :=
10008 l_assign_resources_tbl(l_current_record).primary_contact_flag;
10009 x_assign_resources_tbl(l_count).resource_source := 'TERR';
10010 END IF;
10011 close check_date_cur;
10012 l_current_esc_record := l_current_esc_record + 1;
10013 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
10014 END LOOP;
10015
10016 -- added calendar call out
10017 -- this has been done as now the calendar check is done in a seperate procedure GET_AVAILABLE_RESOURCE
10018 -- changed on 29th September 2003
10019 -- The calendar flag check will not be done any more. The first available slot will be fetched
10020 -- This is for the preformance bug 3301417. If the calendar flag is Y then the resources will
10021 -- filtered based on availability in the procedure get_available_slot. This change is being done on
10022 -- 16 June 2004
10023 --IF (p_calendar_flag = 'Y') THEN
10024 -- change the API Name temporarily so that in case of unexpected error
10025 -- it is properly caught
10026 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
10027 l_return_status_1 := x_return_status ;
10028 -- call the api to check resource availability
10029 get_available_resources
10030 (
10031 p_init_msg_list => 'F',
10032 p_calendar_flag => p_calendar_flag,
10033 p_effort_duration => l_effort_duration,
10034 p_effort_uom => l_effort_uom,
10035 p_planned_start_date => l_planned_start_date,
10036 p_planned_end_date => l_planned_end_date,
10037 p_breakdown => null,
10038 p_breakdown_uom => null,
10039 p_continuous_task => jtf_assign_pub.g_continuous_work,
10040 x_return_status => x_return_status,
10041 x_msg_count => x_msg_count,
10042 x_msg_data => x_msg_data,
10043 x_assign_resources_tbl => x_assign_resources_tbl);
10044
10045 -- set back the API name to original name
10046 l_api_name := l_api_name_1;
10047
10048 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
10049 -- Unexpected Execution Error from call to Get_contracts_resources
10050 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
10051 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
10052 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_ESC_RESOURCES');
10053 fnd_msg_pub.add;
10054 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
10055 RAISE fnd_api.g_exc_error;
10056 ELSE
10057 RAISE fnd_api.g_exc_unexpected_error;
10058 END IF;
10059 END IF; -- end of x_return_status check
10060 -- end if; -- if p_calendar_flag = Y
10061
10062 IF ( p_calendar_flag = 'Y' AND
10063 x_assign_resources_tbl.count = 0 ) THEN
10064 fnd_message.set_name('JTF', 'JTF_AM_RESOURCE_NOT_AVAILABLE');
10065 fnd_msg_pub.add;
10066 -- RAISE fnd_api.g_exc_error;
10067 END IF;
10068
10069 -- to implement auto selection
10070 IF(l_auto_select_flag = 'Y')
10071 THEN
10072 l_temp_table.delete;
10073 l_temp_table := x_assign_resources_tbl;
10074 x_assign_resources_tbl.delete;
10075 l_count := 0;
10076 l_current_record := l_temp_table.FIRST;
10077 l_total_records := p_no_of_resources;
10078
10079 WHILE l_current_record <= l_temp_table.LAST
10080 LOOP
10081 If(l_count < l_total_records)
10082 THEN
10083 x_assign_resources_tbl(l_count) := l_temp_table(l_current_record);
10084 l_count := l_count + 1;
10085 end if; -- end of count check
10086 l_current_record := l_temp_table.NEXT(l_current_record);
10087 END LOOP; -- end of courrent record check
10088
10089 END IF; -- end of auto select flag
10090
10091 ELSE -- No resources returned from the Territory API
10092 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
10093 fnd_msg_pub.add;
10094 -- RAISE fnd_api.g_exc_error;
10095 END IF;
10096
10097 ELSE -- Territory Flag is NO
10098 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
10099 fnd_msg_pub.add;
10100 -- RAISE fnd_api.g_exc_error;
10101 END IF;
10102
10103 l_esc_record := p_esc_tbl.NEXT(l_esc_record);
10104
10105 END LOOP;
10106
10107 ELSE -- p_esc_tbl.count <= 0
10108
10109 -- change the API Name temporarily so that in case of unexpected error
10110 -- it is properly caught
10111 l_api_name := l_api_name||'-JTF_TERRITORY_GET_PUB';
10112
10113 JTF_TERRITORY_GET_PUB.Get_Escalation_TerrMembers
10114 (
10115 p_api_version_number => l_api_version,
10116 p_init_msg_list => p_init_msg_list,
10117 p_commit => NULL,
10118 x_return_status => x_return_status,
10119 x_msg_count => x_msg_count,
10120 x_msg_data => x_msg_data,
10121 p_terr_id => 1,
10122 x_QualifyingRsc_out_tbl => l_assign_resources_tbl
10123 );
10124
10125 -- set back the API name to original name
10126 l_api_name := l_api_name_1;
10127
10128 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
10129 -- Unexpected Execution Error from call to Territory Manager
10130 fnd_message.set_name('JTF', 'JTF_AM_ERROR_TERR_API');
10131 fnd_msg_pub.add;
10132 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
10133 RAISE fnd_api.g_exc_error;
10134 ELSE
10135 RAISE fnd_api.g_exc_unexpected_error;
10136 END IF;
10137 END IF;
10138
10139
10140 IF l_assign_resources_tbl.COUNT > 0 THEN
10141
10142 l_current_record := l_assign_resources_tbl.FIRST;
10143 l_current_esc_record := 0;
10144
10145
10146 IF (l_auto_select_flag = 'Y') THEN
10147 l_total_records := p_no_of_resources;
10148 ELSE
10149 l_total_records := l_assign_resources_tbl.LAST;
10150 END IF;
10151
10152
10153 WHILE (l_current_record <= l_assign_resources_tbl.LAST ) AND
10154 (l_count < l_total_records)
10155 LOOP
10156 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
10157 l_assign_resources_tbl(l_current_record).resource_type);
10158 fetch check_date_cur into l_value;
10159 if (check_date_cur%found)
10160 then
10161
10162 l_count := l_count + 1;
10163
10164 x_assign_resources_tbl(l_count).terr_rsc_id :=
10165 l_assign_resources_tbl(l_current_record).terr_rsc_id;
10166 x_assign_resources_tbl(l_count).resource_id :=
10167 l_assign_resources_tbl(l_current_record).resource_id;
10168 x_assign_resources_tbl(l_count).resource_type :=
10169 l_assign_resources_tbl(l_current_record).resource_type;
10170 x_assign_resources_tbl(l_count).role :=
10171 l_assign_resources_tbl(l_current_record).role;
10172 x_assign_resources_tbl(l_count).start_date := NULL;
10173 x_assign_resources_tbl(l_count).end_date := NULL;
10174 x_assign_resources_tbl(l_count).shift_construct_id := NULL;
10175 x_assign_resources_tbl(l_count).terr_id :=
10176 l_assign_resources_tbl(l_current_record).terr_id;
10177 x_assign_resources_tbl(l_count).terr_name :=
10178 l_assign_resources_tbl(l_current_record).terr_name;
10179 x_assign_resources_tbl(l_count).primary_contact_flag :=
10180 l_assign_resources_tbl(l_current_record).primary_contact_flag;
10181 x_assign_resources_tbl(l_count).primary_flag :=
10182 l_assign_resources_tbl(l_current_record).primary_contact_flag;
10183 x_assign_resources_tbl(l_count).resource_source := 'TERR';
10184
10185 end if;
10186 close check_date_cur;
10187 l_current_esc_record := l_current_esc_record + 1;
10188 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
10189
10190 END LOOP;
10191
10192 ELSE -- l_assign_resources_tbl.COUNT <= 0
10193 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
10194 fnd_msg_pub.add;
10195 -- RAISE fnd_api.g_exc_error;
10196 END IF;
10197
10198
10199 /*
10200 fnd_message.set_name('JTF', 'JTF_AM_EMPTY_ESC_TBL');
10201 fnd_msg_pub.add;
10202 RAISE fnd_api.g_exc_error;
10203 */
10204
10205 END IF; -- End of l_esc_tbl.count > 0
10206
10207
10208
10209
10210 -- Start of enhancement to add SUPPORT SITE ID and NAME to the OUT Table
10211
10212 l_dynamic_sql1 := ' SELECT a.city city '||
10213 ' FROM hz_locations a, hz_party_sites b, hz_party_site_uses c '||
10214 ' WHERE c.site_use_type = :1 AND '||
10215 ' b.party_site_id = :2 AND '||
10216 ' a.location_id = b.location_id AND '||
10217 ' c.party_site_id = b.party_site_id ';
10218
10219 IF x_assign_resources_tbl.COUNT > 0 THEN
10220
10221 l_current_record := x_assign_resources_tbl.FIRST;
10222
10223 WHILE l_current_record <= x_assign_resources_tbl.LAST
10224 LOOP
10225
10226 l_rsc_type := resource_type_change(x_assign_resources_tbl(l_current_record).resource_type);
10227
10228 OPEN cur_support_site_id (x_assign_resources_tbl(l_current_record).resource_id,
10229 l_rsc_type);
10230
10231 FETCH cur_support_site_id INTO x_assign_resources_tbl(l_current_record).support_site_id;
10232
10233 IF (x_assign_resources_tbl(l_current_record).support_site_id IS NOT NULL) THEN
10234
10235 OPEN cur_support_site_name FOR l_dynamic_sql1
10236 USING l_support_site,
10237 x_assign_resources_tbl(l_current_record).support_site_id;
10238
10239 FETCH cur_support_site_name INTO x_assign_resources_tbl(l_current_record).support_site_name;
10240 IF ( cur_support_site_name % NOTFOUND ) THEN
10241 x_assign_resources_tbl(l_current_record).support_site_name := NULL;
10242 END IF;
10243 CLOSE cur_support_site_name;
10244 ELSE
10245 x_assign_resources_tbl(l_current_record).support_site_id := NULL;
10246 x_assign_resources_tbl(l_current_record).support_site_name := NULL;
10247
10248 END IF;
10249
10250 CLOSE cur_support_site_id;
10251
10252 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
10253 END LOOP;
10254 END IF;
10255
10256 -- End of enhancement
10257
10258
10259
10260
10261 -- Start of enhancement to add Web Availability to the OUT Table
10262
10263
10264 IF (x_assign_resources_tbl.COUNT > 0) THEN
10265
10266 l_current_record := x_assign_resources_tbl.FIRST;
10267
10268 WHILE l_current_record <= x_assign_resources_tbl.LAST
10269 LOOP
10270
10271 IF ( UPPER(l_web_availability_flag) = 'Y') THEN
10272 l_rsc_type := resource_type_change(x_assign_resources_tbl(l_current_record).resource_type);
10273
10274 OPEN cur_web_availability (x_assign_resources_tbl(l_current_record).resource_id,
10275 l_rsc_type);
10276 FETCH cur_web_availability INTO l_rsc_id;
10277
10278 IF (cur_web_availability%FOUND) THEN
10279 x_assign_resources_tbl(l_current_record).web_availability_flag := 'Y';
10280 ELSE
10281 x_assign_resources_tbl(l_current_record).web_availability_flag := 'N';
10282 END IF;
10283
10284 CLOSE cur_web_availability;
10285 ELSE
10286 x_assign_resources_tbl(l_current_record).web_availability_flag := NULL;
10287 END IF; --l_web_availability_flag = 'Y'
10288
10289 l_current_record := x_assign_resources_tbl.NEXT(l_current_record);
10290 END LOOP;
10291 END IF;
10292
10293 -- End of enhancement
10294
10295 /********************** Start of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
10296
10297 -- raise workfow event
10298 -- workflow test
10299 Begin
10300 jtf_assign_pub.g_assign_resources_tbl.delete;
10301 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
10302
10303 IF (p_esc_tbl.count>0) THEN
10304
10305 l_esc_count := p_esc_tbl.FIRST;
10306
10307 WHILE (l_esc_count <= p_esc_tbl.LAST)
10308 LOOP
10309 jtf_am_wf_events_pub.assign_esc_resource
10310 (P_API_VERSION => 1.0,
10311 P_INIT_MSG_LIST => 'F',
10312 P_COMMIT => 'F',
10313 P_ESC_REC => p_esc_tbl(l_esc_count),
10314 P_BUSINESS_PROCESS_ID => p_business_process_id,
10315 P_BUSINESS_PROCESS_DATE => p_business_process_date,
10316 X_RETURN_STATUS => l_wf_return_status,
10317 X_MSG_COUNT => l_wf_msg_count,
10318 X_MSG_DATA => l_wf_msg_data
10319 );
10320
10321
10322 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
10323 -- Unexpected Execution Error from call to assign_sr_resource
10324 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
10325 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
10326 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ESC_RESOURCES');
10327 fnd_msg_pub.add;
10328 ELSE
10329 x_assign_resources_tbl.delete;
10330 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
10331
10332 END IF;
10333
10334 l_esc_count := p_esc_tbl.NEXT(l_esc_count);
10335
10336 END LOOP;
10337 ELSE
10338
10339 jtf_am_wf_events_pub.assign_esc_resource
10340 (P_API_VERSION => 1.0,
10341 P_INIT_MSG_LIST => 'F',
10342 P_COMMIT => 'F',
10343 P_ESC_REC => NULL,
10344 P_BUSINESS_PROCESS_ID => p_business_process_id,
10345 P_BUSINESS_PROCESS_DATE => p_business_process_date,
10346 X_RETURN_STATUS => l_wf_return_status,
10347 X_MSG_COUNT => l_wf_msg_count,
10348 X_MSG_DATA => l_wf_msg_data
10349 );
10350
10351
10352 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
10353 -- Unexpected Execution Error from call to assign_sr_resource
10354 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
10355 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
10356 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ESC_RESOURCES');
10357 fnd_msg_pub.add;
10358 ELSE
10359 x_assign_resources_tbl.delete;
10360 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
10361 END IF;
10362
10363 END IF;
10364
10365 Exception
10366 When OTHERS Then
10367 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
10368 fnd_message.set_token('P_SQLCODE',SQLCODE);
10369 fnd_message.set_token('P_SQLERRM',SQLERRM);
10370 fnd_message.set_token('P_API_NAME',l_api_name);
10371 FND_MSG_PUB.add;
10372 End;
10373
10374 /********************** End of Addition for Enh. No 3076744 by SBARAT, 23/09/2004 ************************/
10375
10376
10377 -- To Plugin the Workflow enabling the user
10378 -- to further filter the resources
10379
10380
10381 /* Getting the Workflow Profile value defined for the Assignment Manager */
10382
10383 --l_workflow_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_WORKFLOW_NAME' ); -- Commented out by SBARAT on 12/10/2004, Bug-3830061
10384 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' ); -- Added by SBARAT on 12/10/2004, Bug-3830061
10385
10386
10387 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
10388 FROM dual;
10389
10390 IF (JTF_USR_HKS.ok_to_execute
10391 (
10392 'JTF_ASSIGN_PUB',
10393 'GET_ASSIGN_ESC_RESOURCES',
10394 'W',
10395 'W'
10396 )
10397 ) THEN
10398
10399 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
10400 (
10401 p_api_version => l_api_version,
10402 p_init_msg_list => p_init_msg_list,
10403 x_return_status => x_return_status,
10404 x_msg_count => x_msg_count,
10405 x_msg_data => x_msg_data
10406 )
10407 ) THEN
10408
10409 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
10410 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
10411 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
10412 fnd_msg_pub.add;
10413 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
10414 RAISE fnd_api.g_exc_error;
10415 ELSE
10416 RAISE fnd_api.g_exc_unexpected_error;
10417 END IF;
10418 END IF;
10419
10420
10421 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
10422
10423 JTF_USR_HKS.WrkFlowLaunch
10424 (
10425 'JTF_ASSIGN_WF',
10426 l_workflow_profile,
10427 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
10428 l_bind_data_id,
10429 l_return_code
10430 );
10431
10432 JTF_USR_HKS.purge_bind_data
10433 (
10434 l_bind_data_id,
10435 'W'
10436 );
10437
10438
10439 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
10440 -- Execution Error from call to Assignment Manager Workflow Hook
10441 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
10442 fnd_msg_pub.add;
10443 RAISE fnd_api.g_exc_error;
10444 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
10445 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
10446 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
10447 fnd_msg_pub.add;
10448 RAISE fnd_api.g_exc_unexpected_error;
10449 END IF;
10450
10451 END IF; -- End of JTF_ASSIGN_CUHK
10452
10453 END IF; -- End of JTF_USR_HKS
10454
10455
10456
10457 /* Standard call to get message count and
10458 the message information */
10459
10460 FND_MSG_PUB.Count_And_Get
10461 (
10462 p_count => x_msg_count,
10463 p_data => x_msg_data
10464 );
10465
10466
10467
10468 EXCEPTION
10469 WHEN FND_API.G_EXC_ERROR THEN
10470 x_return_status := FND_API.G_RET_STS_ERROR ;
10471 FND_MSG_PUB.Count_And_Get
10472 (
10473 p_count => x_msg_count,
10474 p_data => x_msg_data
10475 );
10476
10477 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
10478 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10479 FND_MSG_PUB.Count_And_Get
10480 (
10481 p_count => x_msg_count,
10482 p_data => x_msg_data
10483 );
10484
10485 WHEN OTHERS THEN
10486 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
10487 fnd_message.set_token('P_SQLCODE',SQLCODE);
10488 fnd_message.set_token('P_SQLERRM',SQLERRM);
10489 fnd_message.set_token('P_API_NAME',l_api_name);
10490 FND_MSG_PUB.add;
10491
10492 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
10493 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
10494 FND_MSG_PUB.Add_Exc_Msg
10495 (
10496 G_PKG_NAME,
10497 l_api_name
10498 );
10499 END IF;
10500
10501 FND_MSG_PUB.Count_And_Get
10502 (
10503 p_count => x_msg_count,
10504 p_data => x_msg_data
10505 );
10506
10507 END GET_ASSIGN_ESC_RESOURCES;
10508
10509
10510
10511 -- *******************************************************************************
10512
10513 -- Start of comments
10514
10515 -- API name : GET_ASSIGN_RESOURCES
10516 -- Type : Public
10517 -- Function : Determine the resources based on the customer
10518 -- preferences or territory preferences and the
10519 -- availability.
10520 -- Pre-reqs : None
10521
10522 -- Parameters :
10523
10524 -- IN : p_api_version IN NUMBER Required
10525 -- p_init_msg_list IN VARCHAR2 Optional
10526 -- DEFAULT JTF_ASSIGN_PUB.AM_FALSE
10527 -- p_commit IN VARCHAR2 optional
10528 -- DEFAULT JTF_ASSIGN_PUB.AM_FALSE
10529
10530 -- Assignment Manager Specific Parameters
10531
10532 -- This determines the Resource, Resource Type
10533 -- and Resource Role required by the calling document
10534 -- p_resource_id NUMBER
10535 -- p_resource_type VARCHAR2(30)
10536 -- p_role VARCHAR2(30)
10537
10538 -- This determines the number of resources required
10539 -- by the calling document
10540 -- Defaulted to 1
10541 -- p_no_of_resources NUMBER
10542
10543 -- This is for sending out the qualified resource directly
10544 -- to the calling form.
10545 -- Defaulted to 'Y'(Profile Value)
10546 -- p_auto_select_flag VARCHAR2(1)
10547 -- : value of Y or N
10548
10549 -- This is to set the preference of CONTRACTS PREFERRED ENGINEERS
10550 -- Defaulted to 'N'(Profile Value)
10551 -- p_contracts_preferred_engineer VARCHAR2(1)
10552 -- : value of Y or N
10553
10554 -- This is to set the preference of INSTALL BASE PREFERRED ENGINEERS
10555 -- Defaulted to 'N'(Profile Value)
10556 -- p_ib_preferred_engineer VARCHAR2(1)
10557 -- : value of Y or N
10558
10559 -- This is to fetch the CONTRACTS PREFERRED ENGINEERS
10560 -- p_contract_id NUMBER
10561
10562 -- This is to fetch the INSTALL BASE PREFERRED ENGINEERS
10563 -- p_customer_product_id NUMBER
10564
10565 -- The Effort required is determined by these two parameters
10566 -- p_effort_duration NUMBER
10567 -- p_effort_uom VARCHAR2(10)
10568
10569 -- The Dates in which the resource is required,
10570 -- is determined by these two parameters
10571 -- p_start_date DATE
10572 -- p_end_date DATE
10573
10574 -- The Territory Manager is accessed based on the value set
10575 -- Defaulted to Y
10576 -- p_territory_flag VARCHAR2(1)
10577 -- : value of Y or N
10578
10579 -- The Resource Availability is checked based on the value set
10580 -- Defaulted to Y
10581 -- p_calendar_flag VARCHAR2(1)
10582 -- : value of Y or N
10583
10584 -- This parameter contains the Calling Document ID
10585 -- which could be a TASK_ID or a SERVICE_REQUEST_ID
10586 -- or a OPPORTUNITY_ID or a LEAD_ID etc.
10587 -- p_calling_doc_id NUMBER -- REQUIRED
10588
10589 -- This parameter contains the Calling Document Type
10590 -- which could be :
10591 -- 'TASK' when the calling doc is TASK
10592 -- or 'SR' when the calling doc is SERVICE REQUEST
10593 -- or 'DEF' when the calling doc is DEFECT MANAGEMENT
10594 -- or 'OPPR' when the calling doc is OPPORTUNITIES
10595 -- It is mandatory to enter a value for this parameter
10596 -- to find proper qualified resources
10597 -- p_calling_doc_type VARCHAR2
10598
10599 -- This parameter contains list of qualifier columns from the
10600 -- UI which have been selected to re-query the resources.
10601 -- Strictly for the use of User Interface of Assignment Manager.
10602 -- p_column_list VARCHAR2
10603
10604 -- These parameters contain the Qualifier Values for
10605 -- the Calling Document
10606 -- p_sr_rec JTF_ASSIGN_PUB.
10607 -- JTF_Serv_Req_rec_type
10608 -- p_sr_task_rec JTF_ASSIGN_PUB.
10609 -- JTF_Srv_Task_rec_type
10610 -- p_defect_rec JTF_ASSIGN_PUB.
10611 -- JTF_Def_Mgmt_rec_type
10612
10613 -- OUT : x_return_status OUT VARCHAR2(1)
10614 -- x_msg_count OUT NUMBER
10615 -- x_msg_data OUT VARCHAR2(2000)
10616 -- x_assign_resources_tbl OUT JTF_ASSIGN_PUB.
10617 -- AssignResources_tbl_type
10618
10619
10620 -- Version : Current version 1.0
10621 -- Initial version 1.0
10622 --
10623 -- Notes :
10624 --
10625
10626 -- End of comments
10627
10628 -- *********************************************************************************
10629
10630
10631
10632 /* Main Procedure definition with the parameters
10633 This procedure in turn calls the relevant procedure to
10634 process the requests for assignment of resources */
10635
10636
10637 PROCEDURE GET_ASSIGN_RESOURCES
10638 ( p_api_version IN NUMBER,
10639 p_init_msg_list IN VARCHAR2 ,
10640 p_commit IN VARCHAR2 ,
10641 p_resource_id IN NUMBER ,
10642 p_resource_type IN VARCHAR2 ,
10643 p_role IN VARCHAR2 ,
10644 p_no_of_resources IN NUMBER ,
10645 p_auto_select_flag IN VARCHAR2 ,
10646 p_contracts_preferred_engineer IN VARCHAR2 ,
10647 p_ib_preferred_engineer IN VARCHAR2 ,
10648 p_contract_id IN NUMBER ,
10649 p_customer_product_id IN NUMBER ,
10650 p_effort_duration IN NUMBER ,
10651 p_effort_uom IN VARCHAR2 ,
10652 p_start_date IN DATE ,
10653 p_end_date IN DATE ,
10654 p_territory_flag IN VARCHAR2 ,
10655 p_calendar_flag IN VARCHAR2 ,
10656 p_web_availability_flag IN VARCHAR2 ,
10657 p_category_id IN NUMBER ,
10658 p_inventory_item_id IN NUMBER ,
10659 p_inventory_org_id IN NUMBER ,
10660 p_problem_code IN VARCHAR2 ,
10661 p_calling_doc_id IN NUMBER,
10662 p_calling_doc_type IN VARCHAR2,
10663 p_column_list IN VARCHAR2 ,
10664 p_sr_rec IN JTF_ASSIGN_PUB.JTF_Serv_Req_rec_type ,
10665 p_sr_task_rec IN JTF_ASSIGN_PUB.JTF_Srv_Task_rec_type ,
10666 p_defect_rec IN JTF_ASSIGN_PUB.JTF_Def_Mgmt_rec_type ,
10667 p_business_process_id IN NUMBER,
10668 p_business_process_date IN DATE,
10669 p_filter_excluded_resource IN VARCHAR2,
10670 x_assign_resources_tbl OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type,
10671 x_return_status OUT NOCOPY VARCHAR2,
10672 x_msg_count OUT NOCOPY NUMBER,
10673 x_msg_data OUT NOCOPY VARCHAR2,
10674 --Added for Bug # 5386560
10675 p_inventory_component_id IN NUMBER DEFAULT NULL,
10676 --Added for Bug # 5386560 Ends here
10677 --Added for Bug # 5573916
10678 p_calendar_check IN VARCHAR2 DEFAULT 'Y'
10679 --Added for Bug # 5573916 Ends here
10680 )
10681 IS
10682
10683 l_return_status_1 VARCHAR2(10);
10684 l_api_name VARCHAR2(100) := 'GET_ASSIGN_RESOURCES';
10685 l_api_name_1 VARCHAR2(60) := 'GET_ASSIGN_RESOURCES';
10686 l_api_version NUMBER := 1.0;
10687 l_no_of_resources NUMBER := p_no_of_resources;
10688 l_auto_select_flag VARCHAR2(1) := p_auto_select_flag;
10689 l_contracts_preferred_engineer VARCHAR2(1) := p_contracts_preferred_engineer;
10690 l_ib_preferred_engineer VARCHAR2(1) := p_ib_preferred_engineer;
10691 l_territory_flag VARCHAR2(1) := p_territory_flag;
10692 l_calendar_flag VARCHAR2(1) := p_calendar_flag;
10693 l_calling_doc_type VARCHAR2(10) := p_calling_doc_type;
10694
10695 l_web_availability_flag VARCHAR2(1) := p_web_availability_flag;
10696
10697 l_contracts_profile VARCHAR2(1);
10698 l_ib_profile VARCHAR2(1);
10699 l_auto_select_profile VARCHAR2(1);
10700 l_workflow_profile VARCHAR2(60);
10701
10702 l_current_record INTEGER;
10703 l_dynamic_cursor INTEGER;
10704 l_dynamic_sql VARCHAR2(4000);
10705
10706 l_return_code VARCHAR2(60);
10707 l_wf_return_status VARCHAR2(60);
10708 l_wf_msg_count NUMBER;
10709 l_wf_msg_data VARCHAR2(2000);
10710
10711 l_bind_data_id NUMBER;
10712 l_workflow_key NUMBER;
10713
10714 l_sr_rec JTF_TERRITORY_PUB.JTF_Serv_Req_rec_type;
10715 l_sr_task_rec JTF_TERRITORY_PUB.JTF_Srv_Task_rec_type;
10716 l_defect_rec JTF_TERRITORY_PUB.JTF_Def_Mgmt_rec_type;
10717 l_assign_resources_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
10718 t_assign_resources_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type; --6453896
10719
10720
10721
10722 CURSOR cur_resource_type IS
10723 SELECT object_code
10724 FROM jtf_object_usages
10725 WHERE object_user_code = 'RESOURCES' AND
10726 object_code = p_resource_type;
10727 l_cur_resource_type cur_resource_type%ROWTYPE;
10728
10729
10730 CURSOR cur_res_location(p_rid NUMBER, p_rtype VARCHAR2) IS
10731 SELECT DECODE(source_postal_code, NULL, '00000', source_postal_code)
10732 FROM jtf_rs_resource_extns_vl
10733 WHERE resource_id = p_rid AND
10734 'RS_'||category = p_rtype;
10735
10736
10737 /*
10738 CURSOR cur_effort_uom IS
10739 SELECT uom_code
10740 FROM mtl_units_of_measure_vl
10741 WHERE uom_code = p_effort_uom;
10742 l_cur_effort_uom cur_effort_uom%ROWTYPE;
10743 */
10744
10745 --Bug# 4455803 MOAC.
10746 CURSOR check_date_cur(l_resource_id in number,
10747 l_resource_type in varchar2)
10748 IS
10749 SELECT 'Y'
10750 --FROM jtf_rs_all_resources_vl
10751 FROM jtf_task_resources_vl
10752 where resource_id = l_resource_id
10753 and resource_type = l_resource_type
10754 and nvl(trunc(end_date_active), trunc(sysdate)) >= trunc(sysdate);
10755
10756 l_value varchar2(100);
10757
10758 l_count number := 0;
10759
10760 l_usage varchar2(2000);
10761 -- new variable to handle uom code issue for effort durations
10762 l_effort_duration NUMBER;
10763 l_uom_hour VARCHAR2(2000);
10764 l_sort_profile VARCHAR2(2);
10765
10766
10767 BEGIN
10768 SAVEPOINT jtf_assign_pub;
10769
10770 -- Started Assignment Manager Public API
10771
10772
10773 /* Standard call to check for call compatibility */
10774
10775 IF NOT fnd_api.compatible_api_call (l_api_version,
10776 p_api_version,
10777 l_api_name,
10778 g_pkg_name) THEN
10779 RAISE fnd_api.g_exc_unexpected_error;
10780 END IF;
10781
10782
10783 /* Initialize message list if p_init_msg_list is set to TRUE */
10784
10785 IF fnd_api.to_boolean (p_init_msg_list) THEN
10786 fnd_msg_pub.initialize;
10787 END IF;
10788
10789
10790
10791 /* Paramater Validation */
10792
10793
10794 IF (p_resource_type IS NOT NULL) THEN
10795 OPEN cur_resource_type;
10796 FETCH cur_resource_type INTO l_cur_resource_type;
10797 IF ( cur_resource_type%NOTFOUND) THEN
10798 fnd_message.set_name('JTF', 'JTF_AM_INVALID_RESOURCE_TYPE');
10799 fnd_msg_pub.add;
10800 RAISE fnd_api.g_exc_error;
10801 END IF;
10802 CLOSE cur_resource_type;
10803 END IF;
10804
10805
10806 /*
10807 IF (p_effort_uom IS NOT NULL) THEN
10808 OPEN cur_effort_uom;
10809 FETCH cur_effort_uom INTO l_cur_effort_uom;
10810 IF ( cur_effort_uom%NOTFOUND) THEN
10811 fnd_message.set_name('JTF', 'JTF_AM_INVALID_EFFORT_UOM');
10812 fnd_msg_pub.add;
10813 RAISE fnd_api.g_exc_error;
10814 END IF;
10815 CLOSE cur_effort_uom;
10816 END IF;
10817 */
10818
10819
10820 /* Getting the Profile values defined for the Assignment Manager */
10821
10822
10823 /**************Start of commenting out by SBARAT on 12/10/2004, Bug-3830061***************/
10824
10825 /*
10826 l_contracts_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_CONTRACTS_PREFERRED_ENGINEERS' );
10827 l_auto_select_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_AUTO_SELECT' );
10828 l_workflow_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_WORKFLOW_NAME' );
10829 l_ib_profile := FND_PROFILE.VALUE_SPECIFIC ( 'ACTIVATE_IB_PREFERRED_ENGINEERS');
10830 */
10831
10832 /**************End of commenting out by SBARAT on 12/10/2004, Bug-3830061**************/
10833
10834 /**************Start of addition by SBARAT on 12/10/2004, Bug-3830061****************/
10835
10836 l_contracts_profile := FND_PROFILE.VALUE ( 'ACTIVATE_CONTRACTS_PREFERRED_ENGINEERS' );
10837 l_auto_select_profile := FND_PROFILE.VALUE ( 'ACTIVATE_AUTO_SELECT' );
10838 l_workflow_profile := FND_PROFILE.VALUE ( 'ACTIVATE_WORKFLOW_NAME' );
10839 l_ib_profile := FND_PROFILE.VALUE ( 'ACTIVATE_IB_PREFERRED_ENGINEERS');
10840
10841 /**************End of addition by SBARAT on 12/10/2004, Bug-3830061****************/
10842
10843 -- get the profile value for usage
10844 l_usage := fnd_profile.value('JTF_AM_USAGE');
10845
10846 /* Assigning the DEFAULT values for the Parameters */
10847
10848
10849 IF (p_auto_select_flag IS NULL) THEN
10850 l_auto_select_flag := l_auto_select_profile;
10851 -- PROFILE VALUE is the default value
10852 ELSE
10853 l_auto_select_flag := p_auto_select_flag;
10854 END IF;
10855
10856
10857 IF (p_contracts_preferred_engineer IS NULL) THEN
10858 l_contracts_preferred_engineer := l_contracts_profile;
10859 -- PROFILE VALUE is the default value
10860 ELSE
10861 l_contracts_preferred_engineer := p_contracts_preferred_engineer;
10862 END IF;
10863
10864
10865 IF (p_ib_preferred_engineer IS NULL) THEN
10866 l_ib_preferred_engineer := l_ib_profile;
10867 -- PROFILE VALUE is the default value
10868 ELSE
10869 l_ib_preferred_engineer := p_ib_preferred_engineer;
10870 END IF;
10871
10872
10873 IF (p_no_of_resources IS NULL) THEN
10874 l_no_of_resources := 1; -- 1 is the default value
10875 ELSE
10876 l_no_of_resources := p_no_of_resources;
10877 END IF;
10878
10879
10880 IF ( (UPPER(p_territory_flag) = 'N')
10881 -- added this line to handle null value as N
10882 OR (p_territory_flag IS NULL)) THEN
10883 l_territory_flag := 'N';
10884 ELSE
10885 l_territory_flag := 'Y'; -- YES is the default value
10886 END IF;
10887
10888
10889 IF ( (UPPER(p_calendar_flag) = 'N')
10890 -- added this line to handle null value as N
10891 OR (p_calendar_flag IS NULL)) THEN
10892 l_calendar_flag := 'N';
10893 ELSE
10894 l_calendar_flag := 'Y'; -- YES is the default value
10895 END IF;
10896
10897
10898 IF ( p_web_availability_flag IS NULL) THEN
10899 l_web_availability_flag := 'Y';
10900 ELSE
10901 l_web_availability_flag := p_web_availability_flag;
10902 END IF;
10903
10904
10905 /* to handle the conversion of duration to hour */
10906 l_uom_hour := nvl(fnd_profile.value('JTF_AM_TASK_HOUR'), 'HR');
10907
10908
10909 --Commented out by SBARAT on 21/04/2005 for Bug-4300801
10910 --It was causing double conversion since same conversion is being done
10911 --in the overloaded procedure GET_AVAILABLE_RESOURCES
10912 /*if(nvl(p_effort_uom, l_uom_hour) <> l_uom_hour)
10913 then
10914 l_effort_duration := inv_convert.inv_um_convert(
10915 item_id => NULL,
10916 precision => 2,
10917 from_quantity => p_effort_duration,
10918 from_unit => p_effort_uom,
10919 to_unit => l_uom_hour, --'HR',
10920 from_name => NULL,
10921 to_name => NULL);
10922 else
10923 l_effort_duration := p_effort_duration;
10924 end if;*/
10925
10926 l_effort_duration := p_effort_duration; --Added by SBARAT on 21/04/2005 for Bug-4300801
10927
10928 /* This assigning is being done because of the limitation for
10929 the direct use of the variables FND_API.MISS_NUM, MISS_CHAR etc. */
10930
10931
10932 /* Assigning values to the Service Request Record Type */
10933
10934 /**************** Start of addition by SBARAT on 11/01/2005 for Enh 4112155**************/
10935
10936 Terr_Qual_Dyn_Assign(p_sr_rec, p_sr_task_rec);
10937
10938 l_sr_rec:=JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type;
10939 l_sr_task_rec:=JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type;
10940
10941 JTF_ASSIGN_PUB.G_Terr_Serv_Req_Rec_Type:=Null;
10942 JTF_ASSIGN_PUB.G_Terr_Srv_Task_Rec_Type:=Null;
10943
10944 /**************** End of addition by SBARAT on 11/01/2005 for Enh 4112155**************/
10945
10946 l_sr_rec.SERVICE_REQUEST_ID := p_sr_rec.SERVICE_REQUEST_ID;
10947 l_sr_rec.PARTY_ID := p_sr_rec.PARTY_ID;
10948 l_sr_rec.COUNTRY := p_sr_rec.COUNTRY;
10949 l_sr_rec.PARTY_SITE_ID := p_sr_rec.PARTY_SITE_ID;
10950 l_sr_rec.CITY := p_sr_rec.CITY;
10951 l_sr_rec.POSTAL_CODE := p_sr_rec.POSTAL_CODE;
10952 l_sr_rec.STATE := p_sr_rec.STATE;
10953 l_sr_rec.AREA_CODE := p_sr_rec.AREA_CODE;
10954 l_sr_rec.COUNTY := p_sr_rec.COUNTY;
10955 l_sr_rec.COMP_NAME_RANGE := p_sr_rec.COMP_NAME_RANGE;
10956 l_sr_rec.PROVINCE := p_sr_rec.PROVINCE;
10957 l_sr_rec.NUM_OF_EMPLOYEES := p_sr_rec.NUM_OF_EMPLOYEES;
10958 l_sr_rec.INCIDENT_TYPE_ID := p_sr_rec.INCIDENT_TYPE_ID;
10959 l_sr_rec.INCIDENT_SEVERITY_ID := p_sr_rec.INCIDENT_SEVERITY_ID;
10960 l_sr_rec.INCIDENT_URGENCY_ID := p_sr_rec.INCIDENT_URGENCY_ID;
10961 l_sr_rec.PROBLEM_CODE := p_sr_rec.PROBLEM_CODE;
10962 l_sr_rec.INCIDENT_STATUS_ID := p_sr_rec.INCIDENT_STATUS_ID;
10963 l_sr_rec.PLATFORM_ID := p_sr_rec.PLATFORM_ID;
10964 l_sr_rec.SUPPORT_SITE_ID := p_sr_rec.SUPPORT_SITE_ID;
10965 l_sr_rec.CUSTOMER_SITE_ID := p_sr_rec.CUSTOMER_SITE_ID;
10966 l_sr_rec.SR_CREATION_CHANNEL := p_sr_rec.SR_CREATION_CHANNEL;
10967 l_sr_rec.INVENTORY_ITEM_ID := p_sr_rec.INVENTORY_ITEM_ID;
10968 l_sr_rec.ATTRIBUTE1 := p_sr_rec.ATTRIBUTE1;
10969 l_sr_rec.ATTRIBUTE2 := p_sr_rec.ATTRIBUTE2;
10970 l_sr_rec.ATTRIBUTE3 := p_sr_rec.ATTRIBUTE3;
10971 l_sr_rec.ATTRIBUTE4 := p_sr_rec.ATTRIBUTE4;
10972 l_sr_rec.ATTRIBUTE5 := p_sr_rec.ATTRIBUTE5;
10973 l_sr_rec.ATTRIBUTE6 := p_sr_rec.ATTRIBUTE6;
10974 l_sr_rec.ATTRIBUTE7 := p_sr_rec.ATTRIBUTE7;
10975 l_sr_rec.ATTRIBUTE8 := p_sr_rec.ATTRIBUTE8;
10976 l_sr_rec.ATTRIBUTE9 := p_sr_rec.ATTRIBUTE9;
10977 l_sr_rec.ATTRIBUTE10 := p_sr_rec.ATTRIBUTE10;
10978 l_sr_rec.ATTRIBUTE11 := p_sr_rec.ATTRIBUTE11;
10979 l_sr_rec.ATTRIBUTE12 := p_sr_rec.ATTRIBUTE12;
10980 l_sr_rec.ATTRIBUTE13 := p_sr_rec.ATTRIBUTE13;
10981 l_sr_rec.ATTRIBUTE14 := p_sr_rec.ATTRIBUTE14;
10982 l_sr_rec.ATTRIBUTE15 := p_sr_rec.ATTRIBUTE15;
10983 l_sr_rec.ORGANIZATION_ID := p_sr_rec.ORGANIZATION_ID;
10984 l_sr_rec.SQUAL_NUM12 := p_sr_rec.SQUAL_NUM12;
10985 l_sr_rec.SQUAL_NUM13 := p_sr_rec.SQUAL_NUM13;
10986 l_sr_rec.SQUAL_NUM14 := p_sr_rec.SQUAL_NUM14;
10987 l_sr_rec.SQUAL_NUM15 := p_sr_rec.SQUAL_NUM15;
10988 l_sr_rec.SQUAL_NUM16 := p_sr_rec.SQUAL_NUM16;
10989 l_sr_rec.SQUAL_NUM17 := p_sr_rec.SQUAL_NUM17;
10990 l_sr_rec.SQUAL_NUM18 := p_sr_rec.SQUAL_NUM18;
10991 l_sr_rec.SQUAL_NUM19 := p_sr_rec.SQUAL_NUM19;
10992 l_sr_rec.SQUAL_NUM30 := p_sr_rec.SQUAL_NUM30;
10993 l_sr_rec.SQUAL_CHAR11 := p_sr_rec.SQUAL_CHAR11;
10994 l_sr_rec.SQUAL_CHAR12 := p_sr_rec.SQUAL_CHAR12;
10995 l_sr_rec.SQUAL_CHAR13 := p_sr_rec.SQUAL_CHAR13;
10996 -- added by sudarsana for terr rec type change
10997 l_sr_rec.SQUAL_CHAR20 := p_sr_rec.SQUAL_CHAR20;
10998 -- Added by vvuyyuru for Contracts Coverage Type
10999 l_sr_rec.SQUAL_CHAR21 := p_sr_rec.SQUAL_CHAR21;
11000
11001
11002
11003
11004 /* Assigning values to the Service Request + Task Record Type */
11005
11006 l_sr_task_rec.TASK_ID := p_sr_task_rec.TASK_ID;
11007 l_sr_task_rec.SERVICE_REQUEST_ID := p_sr_task_rec.SERVICE_REQUEST_ID;
11008 l_sr_task_rec.PARTY_ID := p_sr_task_rec.PARTY_ID;
11009 l_sr_task_rec.COUNTRY := p_sr_task_rec.COUNTRY;
11010 l_sr_task_rec.PARTY_SITE_ID := p_sr_task_rec.PARTY_SITE_ID;
11011 l_sr_task_rec.CITY := p_sr_task_rec.CITY;
11012 l_sr_task_rec.POSTAL_CODE := p_sr_task_rec.POSTAL_CODE;
11013 l_sr_task_rec.STATE := p_sr_task_rec.STATE;
11014 l_sr_task_rec.AREA_CODE := p_sr_task_rec.AREA_CODE;
11015 l_sr_task_rec.COUNTY := p_sr_task_rec.COUNTY;
11016 l_sr_task_rec.COMP_NAME_RANGE := p_sr_task_rec.COMP_NAME_RANGE;
11017 l_sr_task_rec.PROVINCE := p_sr_task_rec.PROVINCE;
11018 l_sr_task_rec.NUM_OF_EMPLOYEES := p_sr_task_rec.NUM_OF_EMPLOYEES;
11019 l_sr_task_rec.TASK_TYPE_ID := p_sr_task_rec.TASK_TYPE_ID;
11020 l_sr_task_rec.TASK_STATUS_ID := p_sr_task_rec.TASK_STATUS_ID;
11021 l_sr_task_rec.TASK_PRIORITY_ID := p_sr_task_rec.TASK_PRIORITY_ID;
11022 l_sr_task_rec.INCIDENT_TYPE_ID := p_sr_task_rec.INCIDENT_TYPE_ID;
11023 l_sr_task_rec.INCIDENT_SEVERITY_ID := p_sr_task_rec.INCIDENT_SEVERITY_ID;
11024 l_sr_task_rec.INCIDENT_URGENCY_ID := p_sr_task_rec.INCIDENT_URGENCY_ID;
11025 l_sr_task_rec.PROBLEM_CODE := p_sr_task_rec.PROBLEM_CODE;
11026 l_sr_task_rec.INCIDENT_STATUS_ID := p_sr_task_rec.INCIDENT_STATUS_ID;
11027 l_sr_task_rec.PLATFORM_ID := p_sr_task_rec.PLATFORM_ID;
11028 l_sr_task_rec.SUPPORT_SITE_ID := p_sr_task_rec.SUPPORT_SITE_ID;
11029 l_sr_task_rec.CUSTOMER_SITE_ID := p_sr_task_rec.CUSTOMER_SITE_ID;
11030 l_sr_task_rec.SR_CREATION_CHANNEL := p_sr_task_rec.SR_CREATION_CHANNEL;
11031 l_sr_task_rec.INVENTORY_ITEM_ID := p_sr_task_rec.INVENTORY_ITEM_ID;
11032 l_sr_task_rec.ATTRIBUTE1 := p_sr_task_rec.ATTRIBUTE1;
11033 l_sr_task_rec.ATTRIBUTE2 := p_sr_task_rec.ATTRIBUTE2;
11034 l_sr_task_rec.ATTRIBUTE3 := p_sr_task_rec.ATTRIBUTE3;
11035 l_sr_task_rec.ATTRIBUTE4 := p_sr_task_rec.ATTRIBUTE4;
11036 l_sr_task_rec.ATTRIBUTE5 := p_sr_task_rec.ATTRIBUTE5;
11037 l_sr_task_rec.ATTRIBUTE6 := p_sr_task_rec.ATTRIBUTE6;
11038 l_sr_task_rec.ATTRIBUTE7 := p_sr_task_rec.ATTRIBUTE7;
11039 l_sr_task_rec.ATTRIBUTE8 := p_sr_task_rec.ATTRIBUTE8;
11040 l_sr_task_rec.ATTRIBUTE9 := p_sr_task_rec.ATTRIBUTE9;
11041 l_sr_task_rec.ATTRIBUTE10 := p_sr_task_rec.ATTRIBUTE10;
11042 l_sr_task_rec.ATTRIBUTE11 := p_sr_task_rec.ATTRIBUTE11;
11043 l_sr_task_rec.ATTRIBUTE12 := p_sr_task_rec.ATTRIBUTE12;
11044 l_sr_task_rec.ATTRIBUTE13 := p_sr_task_rec.ATTRIBUTE13;
11045 l_sr_task_rec.ATTRIBUTE14 := p_sr_task_rec.ATTRIBUTE14;
11046 l_sr_task_rec.ATTRIBUTE15 := p_sr_task_rec.ATTRIBUTE15;
11047 l_sr_task_rec.ORGANIZATION_ID := p_sr_task_rec.ORGANIZATION_ID;
11048 l_sr_task_rec.SQUAL_NUM12 := p_sr_task_rec.SQUAL_NUM12;
11049 l_sr_task_rec.SQUAL_NUM13 := p_sr_task_rec.SQUAL_NUM13;
11050 l_sr_task_rec.SQUAL_NUM14 := p_sr_task_rec.SQUAL_NUM14;
11051 l_sr_task_rec.SQUAL_NUM15 := p_sr_task_rec.SQUAL_NUM15;
11052 l_sr_task_rec.SQUAL_NUM16 := p_sr_task_rec.SQUAL_NUM16;
11053 l_sr_task_rec.SQUAL_NUM17 := p_sr_task_rec.SQUAL_NUM17;
11054 l_sr_task_rec.SQUAL_NUM18 := p_sr_task_rec.SQUAL_NUM18;
11055 l_sr_task_rec.SQUAL_NUM19 := p_sr_task_rec.SQUAL_NUM19;
11056 l_sr_task_rec.SQUAL_NUM30 := p_sr_task_rec.SQUAL_NUM30;
11057 l_sr_task_rec.SQUAL_CHAR11 := p_sr_task_rec.SQUAL_CHAR11;
11058 l_sr_task_rec.SQUAL_CHAR12 := p_sr_task_rec.SQUAL_CHAR12;
11059 l_sr_task_rec.SQUAL_CHAR13 := p_sr_task_rec.SQUAL_CHAR13;
11060 -- added by sudarsana for terr rec type change
11061 l_sr_task_rec.SQUAL_CHAR20 := p_sr_task_rec.SQUAL_CHAR20;
11062 -- Added by vvuyyuru for Contracts Coverage Type
11063 l_sr_task_rec.SQUAL_CHAR21 := p_sr_task_rec.SQUAL_CHAR21;
11064
11065
11066
11067
11068 /* Assigning values to the Defect Record Type */
11069
11070 l_defect_rec.SQUAL_CHAR01 := p_defect_rec.SQUAL_CHAR01;
11071 l_defect_rec.SQUAL_CHAR02 := p_defect_rec.SQUAL_CHAR02;
11072 l_defect_rec.SQUAL_CHAR03 := p_defect_rec.SQUAL_CHAR03;
11073 l_defect_rec.SQUAL_CHAR04 := p_defect_rec.SQUAL_CHAR04;
11074 l_defect_rec.SQUAL_CHAR05 := p_defect_rec.SQUAL_CHAR05;
11075 l_defect_rec.SQUAL_CHAR06 := p_defect_rec.SQUAL_CHAR06;
11076 l_defect_rec.SQUAL_CHAR07 := p_defect_rec.SQUAL_CHAR07;
11077 l_defect_rec.SQUAL_CHAR08 := p_defect_rec.SQUAL_CHAR08;
11078 l_defect_rec.SQUAL_CHAR09 := p_defect_rec.SQUAL_CHAR09;
11079 l_defect_rec.SQUAL_CHAR10 := p_defect_rec.SQUAL_CHAR10;
11080 l_defect_rec.SQUAL_CHAR11 := p_defect_rec.SQUAL_CHAR11;
11081 l_defect_rec.SQUAL_CHAR12 := p_defect_rec.SQUAL_CHAR12;
11082 l_defect_rec.SQUAL_CHAR13 := p_defect_rec.SQUAL_CHAR13;
11083 l_defect_rec.SQUAL_CHAR14 := p_defect_rec.SQUAL_CHAR14;
11084 l_defect_rec.SQUAL_CHAR15 := p_defect_rec.SQUAL_CHAR15;
11085 l_defect_rec.SQUAL_CHAR16 := p_defect_rec.SQUAL_CHAR16;
11086 l_defect_rec.SQUAL_CHAR17 := p_defect_rec.SQUAL_CHAR17;
11087 l_defect_rec.SQUAL_CHAR18 := p_defect_rec.SQUAL_CHAR18;
11088 l_defect_rec.SQUAL_CHAR19 := p_defect_rec.SQUAL_CHAR19;
11089 l_defect_rec.SQUAL_CHAR20 := p_defect_rec.SQUAL_CHAR20;
11090 l_defect_rec.SQUAL_CHAR21 := p_defect_rec.SQUAL_CHAR21;
11091 l_defect_rec.SQUAL_CHAR22 := p_defect_rec.SQUAL_CHAR22;
11092 l_defect_rec.SQUAL_CHAR23 := p_defect_rec.SQUAL_CHAR23;
11093 l_defect_rec.SQUAL_CHAR24 := p_defect_rec.SQUAL_CHAR24;
11094 l_defect_rec.SQUAL_CHAR25 := p_defect_rec.SQUAL_CHAR25;
11095
11096 l_defect_rec.SQUAL_NUM01 := p_defect_rec.SQUAL_NUM01;
11097 l_defect_rec.SQUAL_NUM02 := p_defect_rec.SQUAL_NUM02;
11098 l_defect_rec.SQUAL_NUM03 := p_defect_rec.SQUAL_NUM03;
11099 l_defect_rec.SQUAL_NUM04 := p_defect_rec.SQUAL_NUM04;
11100 l_defect_rec.SQUAL_NUM05 := p_defect_rec.SQUAL_NUM05;
11101 l_defect_rec.SQUAL_NUM06 := p_defect_rec.SQUAL_NUM06;
11102 l_defect_rec.SQUAL_NUM07 := p_defect_rec.SQUAL_NUM07;
11103 l_defect_rec.SQUAL_NUM08 := p_defect_rec.SQUAL_NUM08;
11104 l_defect_rec.SQUAL_NUM09 := p_defect_rec.SQUAL_NUM09;
11105 l_defect_rec.SQUAL_NUM10 := p_defect_rec.SQUAL_NUM10;
11106 l_defect_rec.SQUAL_NUM11 := p_defect_rec.SQUAL_NUM11;
11107 l_defect_rec.SQUAL_NUM12 := p_defect_rec.SQUAL_NUM12;
11108 l_defect_rec.SQUAL_NUM13 := p_defect_rec.SQUAL_NUM13;
11109 l_defect_rec.SQUAL_NUM14 := p_defect_rec.SQUAL_NUM14;
11110 l_defect_rec.SQUAL_NUM15 := p_defect_rec.SQUAL_NUM15;
11111 l_defect_rec.SQUAL_NUM16 := p_defect_rec.SQUAL_NUM16;
11112 l_defect_rec.SQUAL_NUM17 := p_defect_rec.SQUAL_NUM17;
11113 l_defect_rec.SQUAL_NUM18 := p_defect_rec.SQUAL_NUM18;
11114 l_defect_rec.SQUAL_NUM19 := p_defect_rec.SQUAL_NUM19;
11115 l_defect_rec.SQUAL_NUM20 := p_defect_rec.SQUAL_NUM20;
11116 l_defect_rec.SQUAL_NUM21 := p_defect_rec.SQUAL_NUM21;
11117 l_defect_rec.SQUAL_NUM22 := p_defect_rec.SQUAL_NUM22;
11118 l_defect_rec.SQUAL_NUM23 := p_defect_rec.SQUAL_NUM23;
11119 l_defect_rec.SQUAL_NUM24 := p_defect_rec.SQUAL_NUM24;
11120 l_defect_rec.SQUAL_NUM25 := p_defect_rec.SQUAL_NUM25;
11121
11122 l_defect_rec.ATTRIBUTE1 := p_defect_rec.ATTRIBUTE1;
11123 l_defect_rec.ATTRIBUTE2 := p_defect_rec.ATTRIBUTE2;
11124 l_defect_rec.ATTRIBUTE3 := p_defect_rec.ATTRIBUTE3;
11125 l_defect_rec.ATTRIBUTE4 := p_defect_rec.ATTRIBUTE4;
11126 l_defect_rec.ATTRIBUTE5 := p_defect_rec.ATTRIBUTE5;
11127 l_defect_rec.ATTRIBUTE6 := p_defect_rec.ATTRIBUTE6;
11128 l_defect_rec.ATTRIBUTE7 := p_defect_rec.ATTRIBUTE7;
11129 l_defect_rec.ATTRIBUTE8 := p_defect_rec.ATTRIBUTE8;
11130 l_defect_rec.ATTRIBUTE9 := p_defect_rec.ATTRIBUTE9;
11131 l_defect_rec.ATTRIBUTE10 := p_defect_rec.ATTRIBUTE10;
11132 l_defect_rec.ATTRIBUTE11 := p_defect_rec.ATTRIBUTE11;
11133 l_defect_rec.ATTRIBUTE12 := p_defect_rec.ATTRIBUTE12;
11134 l_defect_rec.ATTRIBUTE13 := p_defect_rec.ATTRIBUTE13;
11135 l_defect_rec.ATTRIBUTE14 := p_defect_rec.ATTRIBUTE14;
11136 l_defect_rec.ATTRIBUTE15 := p_defect_rec.ATTRIBUTE15;
11137
11138
11139
11140
11141 /* Actual Flow of Assignment Manager
11142 Calls to be made now to get the qualified resources */
11143
11144 IF ( UPPER ( p_calling_doc_type ) NOT IN (
11145 'TASK',
11146 'SR' ,
11147 'DEF'
11148 )
11149 ) THEN
11150
11151 fnd_message.set_name('JTF', 'JTF_AM_INVALID_DOC_TYPE');
11152 fnd_msg_pub.add;
11153 RAISE fnd_api.g_exc_error;
11154
11155 END IF;
11156
11157
11158 IF ( UPPER(l_calling_doc_type) = 'SR' ) THEN
11159 GET_ASSIGN_SR_RESOURCES
11160 (
11161 p_api_version => l_api_version,
11162 p_init_msg_list => p_init_msg_list,
11163 p_resource_type => p_resource_type,
11164 p_role => p_role,
11165 p_no_of_resources => l_no_of_resources,
11166 p_auto_select_flag => l_auto_select_flag,
11167 p_contracts_preferred_engineer => l_contracts_preferred_engineer,
11168 p_ib_preferred_engineer => l_ib_preferred_engineer,
11169 p_contract_id => p_contract_id,
11170 p_customer_product_id => p_customer_product_id,
11171 p_effort_duration => l_effort_duration, --p_effort_duration,
11172 p_effort_uom => p_effort_uom,
11173 p_start_date => p_start_date,
11174 p_end_date => p_end_date,
11175 p_territory_flag => l_territory_flag,
11176 p_calendar_flag => l_calendar_flag,
11177 p_web_availability_flag => l_web_availability_flag,
11178 p_category_id => p_category_id,
11179 p_inventory_item_id => p_inventory_item_id,
11180 p_inventory_org_id => p_inventory_org_id,
11181 --Added for Bug # 5386560
11182 p_inventory_component_id => p_inventory_component_id,
11183 --Added for Bug # 5386560 Ends here
11184 p_problem_code => p_problem_code ,
11185 p_sr_id => p_calling_doc_id,
11186 p_sr_rec => l_sr_rec,
11187 p_sr_task_rec => l_sr_task_rec,
11188 p_business_process_id => p_business_process_id,
11189 p_business_process_date => p_business_process_date,
11190 p_filter_excluded_resource => p_filter_excluded_resource,
11191 x_assign_resources_tbl => l_assign_resources_tbl,
11192 x_return_status => x_return_status,
11193 x_msg_count => x_msg_count,
11194 x_msg_data => x_msg_data,
11195 --Added for Bug # 5573916
11196 p_calendar_check => p_calendar_check
11197 --Added for Bug # 5573916 Ends here
11198 );
11199
11200 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
11201 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
11202 fnd_message.set_token('P_PROC_NAME','GET_ASSIGN_SR_RESOURCES');
11203 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
11204 fnd_msg_pub.add;
11205 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
11206 RAISE fnd_api.g_exc_error;
11207 ELSE
11208 RAISE fnd_api.g_exc_unexpected_error;
11209 END IF;
11210 END IF;
11211
11212 -- added this to filter by usage
11213 IF ((l_assign_resources_tbl.count > 0 ) AND
11214 (nvl(l_usage, fnd_api.g_miss_char) <> 'ALL' ) AND
11215 (l_usage is not null)
11216 )
11217 THEN
11218 get_usage_resource(l_usage ,
11219 l_assign_resources_tbl);
11220 END IF;
11221
11222
11223 IF l_assign_resources_tbl.COUNT > 0 THEN
11224
11225 l_current_record := l_assign_resources_tbl.FIRST;
11226
11227 IF ( UPPER(l_auto_select_flag) = 'Y' ) THEN
11228
11229 --l_no_of_resources := l_assign_resources_tbl.count;
11230 -- added this condition to avoid pl/sql numeric error. if no of resources was greater than table count
11231 -- it still used to go into loop . 13 july 2004
11232 l_no_of_resources := least(nvl(l_assign_resources_tbl.count, 0),l_no_of_resources) ;
11233
11234 --WHILE (l_current_record <= l_no_of_resources)
11235 WHILE (l_count < l_no_of_resources)
11236 LOOP
11237
11238 -- add check to see whether the resource is end dated or not
11239 -- added by sudarsana 21 feb 02
11240 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
11241 l_assign_resources_tbl(l_current_record).resource_type);
11242 fetch check_date_cur into l_value;
11243 if (check_date_cur%found)
11244 then
11245
11246 l_count := l_count + 1;
11247
11248 x_assign_resources_tbl(l_count).terr_rsc_id :=
11249 l_assign_resources_tbl(l_current_record).terr_rsc_id;
11250 x_assign_resources_tbl(l_count).resource_id :=
11251 l_assign_resources_tbl(l_current_record).resource_id;
11252 x_assign_resources_tbl(l_count).resource_type :=
11253 l_assign_resources_tbl(l_current_record).resource_type;
11254 x_assign_resources_tbl(l_count).role :=
11255 l_assign_resources_tbl(l_current_record).role;
11256 x_assign_resources_tbl(l_count).start_date :=
11257 l_assign_resources_tbl(l_current_record).start_date;
11258 x_assign_resources_tbl(l_count).end_date :=
11259 l_assign_resources_tbl(l_current_record).end_date;
11260 x_assign_resources_tbl(l_count).shift_construct_id :=
11261 l_assign_resources_tbl(l_current_record).shift_construct_id;
11262 x_assign_resources_tbl(l_count).terr_id :=
11263 l_assign_resources_tbl(l_current_record).terr_id;
11264 x_assign_resources_tbl(l_count).terr_name :=
11265 l_assign_resources_tbl(l_current_record).terr_name;
11266 -- ================code added for bug 6453896=============
11267 x_assign_resources_tbl(l_count).terr_rank :=
11268 l_assign_resources_tbl(l_current_record).terr_rank;
11269 -- ================End for addition of code===============
11270 x_assign_resources_tbl(l_count).preference_type :=
11271 l_assign_resources_tbl(l_current_record).preference_type;
11272 x_assign_resources_tbl(l_count).primary_contact_flag :=
11273 l_assign_resources_tbl(l_current_record).primary_contact_flag;
11274 x_assign_resources_tbl(l_count).group_id :=
11275 l_assign_resources_tbl(l_current_record).group_id;
11276
11277 x_assign_resources_tbl(l_count).support_site_id :=
11278 l_assign_resources_tbl(l_current_record).support_site_id;
11279 x_assign_resources_tbl(l_count).support_site_name :=
11280 l_assign_resources_tbl(l_current_record).support_site_name;
11281 x_assign_resources_tbl(l_count).web_availability_flag :=
11282 l_assign_resources_tbl(l_current_record).web_availability_flag;
11283
11284 x_assign_resources_tbl(l_count).skill_level :=
11285 l_assign_resources_tbl(l_current_record).skill_level;
11286 x_assign_resources_tbl(l_count).skill_name :=
11287 l_assign_resources_tbl(l_current_record).skill_name;
11288 x_assign_resources_tbl(l_count).primary_flag :=
11289 l_assign_resources_tbl(l_current_record).primary_flag;
11290 x_assign_resources_tbl(l_count).resource_source :=
11291 l_assign_resources_tbl(l_current_record).resource_source;
11292 end if;
11293 close check_date_cur;
11294 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
11295 END LOOP;
11296
11297 ELSE -- Auto Select Flag is NO
11298
11299 WHILE l_current_record <= l_assign_resources_tbl.LAST
11300 LOOP
11301 -- add check to see whether the resource is end dated or not
11302 -- added by sudarsana 21 feb 02
11303 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
11304 l_assign_resources_tbl(l_current_record).resource_type);
11305 fetch check_date_cur into l_value;
11306 if (check_date_cur%found)
11307 then
11308 l_count := l_count + 1;
11309
11310 x_assign_resources_tbl(l_count).terr_rsc_id :=
11311 l_assign_resources_tbl(l_current_record).terr_rsc_id;
11312 x_assign_resources_tbl(l_count).resource_id :=
11313 l_assign_resources_tbl(l_current_record).resource_id;
11314 x_assign_resources_tbl(l_count).resource_type :=
11315 l_assign_resources_tbl(l_current_record).resource_type;
11316 x_assign_resources_tbl(l_count).role :=
11317 l_assign_resources_tbl(l_current_record).role;
11318 x_assign_resources_tbl(l_count).start_date :=
11319 l_assign_resources_tbl(l_current_record).start_date;
11320 x_assign_resources_tbl(l_count).end_date :=
11321 l_assign_resources_tbl(l_current_record).end_date;
11322 x_assign_resources_tbl(l_count).shift_construct_id :=
11323 l_assign_resources_tbl(l_current_record).shift_construct_id;
11324 x_assign_resources_tbl(l_count).terr_id :=
11325 l_assign_resources_tbl(l_current_record).terr_id;
11326 x_assign_resources_tbl(l_count).terr_name :=
11327 l_assign_resources_tbl(l_current_record).terr_name;
11328 -- ================code added for bug 6453896=============
11329 x_assign_resources_tbl(l_count).terr_rank :=
11330 l_assign_resources_tbl(l_current_record).terr_rank;
11331 -- ================End for addition of code===============
11332 x_assign_resources_tbl(l_count).preference_type :=
11333 l_assign_resources_tbl(l_current_record).preference_type;
11334 x_assign_resources_tbl(l_count).primary_contact_flag :=
11335 l_assign_resources_tbl(l_current_record).primary_contact_flag;
11336 x_assign_resources_tbl(l_count).group_id :=
11337 l_assign_resources_tbl(l_current_record).group_id;
11338
11339 x_assign_resources_tbl(l_count).support_site_id :=
11340 l_assign_resources_tbl(l_current_record).support_site_id;
11341 x_assign_resources_tbl(l_count).support_site_name :=
11342 l_assign_resources_tbl(l_current_record).support_site_name;
11343 x_assign_resources_tbl(l_count).web_availability_flag :=
11344 l_assign_resources_tbl(l_current_record).web_availability_flag;
11345
11346 x_assign_resources_tbl(l_count).skill_level :=
11347 l_assign_resources_tbl(l_current_record).skill_level;
11348 x_assign_resources_tbl(l_count).skill_name :=
11349 l_assign_resources_tbl(l_current_record).skill_name;
11350 x_assign_resources_tbl(l_count).primary_flag :=
11351 l_assign_resources_tbl(l_current_record).primary_flag;
11352 x_assign_resources_tbl(l_count).resource_source :=
11353 l_assign_resources_tbl(l_current_record).resource_source;
11354 end if;
11355 close check_date_cur;
11356 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
11357 END LOOP;
11358 END IF; -- Auto Select Flag
11359
11360 ELSE
11361 -- No resources returned from the Assignment Manager API for SERVICE REQUESTS
11362 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
11363 fnd_msg_pub.add;
11364 -- RAISE fnd_api.g_exc_error;
11365 END IF;
11366
11367
11368 -- raise workfow event
11369 -- workflow test
11370 begin
11371 jtf_assign_pub.g_assign_resources_tbl.delete;
11372 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
11373 jtf_am_wf_events_pub.assign_sr_resource
11374 (P_API_VERSION => 1.0,
11375 P_INIT_MSG_LIST => 'F',
11376 P_COMMIT => 'F',
11377 P_CONTRACT_ID => p_contract_id ,
11378 P_CUSTOMER_PRODUCT_ID => p_customer_product_id ,
11379 P_CATEGORY_ID => p_category_id ,
11380 P_INVENTORY_ITEM_ID => p_inventory_item_id ,
11381 P_INVENTORY_ORG_ID => p_inventory_org_id ,
11382 --Added for Bug # 5386560
11383 P_INVENTORY_COMPONENT_ID => p_inventory_component_id ,
11384 --Added for Bug # 5386560 Ends here
11385 P_PROBLEM_CODE => p_problem_code ,
11386 P_SR_REC => p_sr_rec,
11387 P_SR_TASK_REC => p_sr_task_rec,
11388 P_BUSINESS_PROCESS_ID => p_business_process_id,
11389 P_BUSINESS_PROCESS_DATE => p_business_process_date,
11390 X_RETURN_STATUS => l_wf_return_status,
11391 X_MSG_COUNT => l_wf_msg_count,
11392 X_MSG_DATA => l_wf_msg_data
11393 );
11394
11395
11396 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
11397 -- Unexpected Execution Error from call to assign_sr_resource
11398 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
11399 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
11400 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
11401 fnd_msg_pub.add;
11402 /* Not raising the errors as req by tele service team
11403 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
11404 RAISE fnd_api.g_exc_error;
11405 ELSE
11406 RAISE fnd_api.g_exc_unexpected_error;
11407 END IF;
11408 */
11409 ELSE
11410 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
11411 END IF;
11412
11413
11414 exception
11415 when others then
11416 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
11417 fnd_message.set_token('P_SQLCODE',SQLCODE);
11418 fnd_message.set_token('P_SQLERRM',SQLERRM);
11419 fnd_message.set_token('P_API_NAME',l_api_name);
11420 FND_MSG_PUB.add;
11421 end;
11422
11423 -- ================code added for bug 6453896==========================
11424 -- =============== This code is added for sorting table based on territory ranking===========
11425 l_sort_profile := nvl(fnd_profile.value('JTF_AM_SORT_TERR_RANK'),'N');
11426 If l_sort_profile ='Y'
11427 then
11428 t_assign_resources_tbl :=x_assign_resources_tbl;
11429 x_assign_resources_tbl.delete;
11430
11431 quick_sort_terr_rank
11432 (
11433 t_assign_resources_tbl.FIRST,
11434 t_assign_resources_tbl.LAST,
11435 t_assign_resources_tbl
11436 );
11437 x_assign_resources_tbl:=t_assign_resources_tbl;
11438 End If;
11439 -- ================End for addition of code===============
11440
11441 ELSIF ( UPPER(l_calling_doc_type) = 'TASK' ) THEN
11442
11443 GET_ASSIGN_TASK_RESOURCES
11444 (
11445 p_api_version => l_api_version,
11446 p_init_msg_list => p_init_msg_list,
11447 p_resource_type => p_resource_type,
11448 p_role => p_role,
11449 p_no_of_resources => l_no_of_resources,
11450 p_auto_select_flag => l_auto_select_flag,
11451 p_contracts_preferred_engineer => l_contracts_preferred_engineer,
11452 p_ib_preferred_engineer => l_ib_preferred_engineer,
11453 p_effort_duration => l_effort_duration, --p_effort_duration,
11454 p_effort_uom => p_effort_uom,
11455 p_start_date => p_start_date,
11456 p_end_date => p_end_date,
11457 p_territory_flag => l_territory_flag,
11458 p_calendar_flag => l_calendar_flag,
11459 p_web_availability_flag => l_web_availability_flag,
11460 p_task_id => p_calling_doc_id,
11461 p_column_list => p_column_list,
11462 p_business_process_id => p_business_process_id,
11463 p_business_process_date => p_business_process_date,
11464 x_assign_resources_tbl => l_assign_resources_tbl,
11465 x_return_status => x_return_status,
11466 x_msg_count => x_msg_count,
11467 x_msg_data => x_msg_data,
11468 --Added for Bug # 5573916
11469 p_calendar_check => p_calendar_check
11470 --Added for Bug # 5573916 Ends here
11471 );
11472
11473 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
11474 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
11475 fnd_message.set_token('P_PROC_NAME','GET_ASSIGN_TASK_RESOURCES');
11476 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
11477 fnd_msg_pub.add;
11478 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
11479 RAISE fnd_api.g_exc_error;
11480 ELSE
11481 RAISE fnd_api.g_exc_unexpected_error;
11482 END IF;
11483 END IF;
11484
11485 /* Begin code to implement the sorting of resources by postal code */
11486 -- added this to filter by usage
11487 IF ((l_assign_resources_tbl.count > 0 ) AND
11488 (nvl(l_usage, fnd_api.g_miss_char) <> 'ALL' ) AND
11489 (l_usage is not null)
11490 --(l_usage is not null or l_usage <> 'ALL')
11491 )
11492 THEN
11493 get_usage_resource(l_usage ,
11494 l_assign_resources_tbl);
11495 END IF;
11496
11497 /* This LOOP is to add the resource postal code to the
11498 list of qualified resources */
11499
11500 l_current_record := l_assign_resources_tbl.FIRST;
11501
11502 WHILE (l_current_record <= l_assign_resources_tbl.LAST)
11503 LOOP
11504
11505 OPEN cur_res_location(l_assign_resources_tbl(l_current_record).resource_id,
11506 l_assign_resources_tbl(l_current_record).resource_type);
11507 FETCH cur_res_location INTO l_assign_resources_tbl(l_current_record).location;
11508 CLOSE cur_res_location;
11509
11510 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
11511 END LOOP;
11512
11513
11514
11515 /* Calling the procedure to sort PL SQL table rows */
11516
11517 /*
11518 quick_sort_resource_loc
11519 (
11520 l_assign_resources_tbl.FIRST,
11521 l_assign_resources_tbl.LAST,
11522 l_assign_resources_tbl
11523 );
11524 */
11525
11526 /* End of the code for the sorting by Resource Location */
11527
11528
11529
11530 IF l_assign_resources_tbl.COUNT > 0 THEN
11531
11532 l_current_record := l_assign_resources_tbl.FIRST;
11533
11534 IF ( UPPER(l_auto_select_flag) = 'Y' ) THEN
11535
11536 -- added this condition to avoid pl/sql numeric error. if no of resources was greater than table count
11537 -- it still used to go into loop . 13 july 2004
11538 l_no_of_resources := least(nvl(l_assign_resources_tbl.count, 0),l_no_of_resources) ;
11539
11540 --WHILE (l_current_record <= l_no_of_resources)
11541 WHILE (l_count < l_no_of_resources)
11542 LOOP
11543 -- add check to see whether the resource is end dated or not
11544 -- added by sudarsana 21 feb 02
11545 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
11546 l_assign_resources_tbl(l_current_record).resource_type);
11547 fetch check_date_cur into l_value;
11548 if (check_date_cur%found)
11549 then
11550 l_count := l_count + 1;
11551 x_assign_resources_tbl(l_count).terr_rsc_id :=
11552 l_assign_resources_tbl(l_current_record).terr_rsc_id;
11553 x_assign_resources_tbl(l_count).resource_id :=
11554 l_assign_resources_tbl(l_current_record).resource_id;
11555 x_assign_resources_tbl(l_count).resource_type :=
11556 l_assign_resources_tbl(l_current_record).resource_type;
11557 x_assign_resources_tbl(l_count).role :=
11558 l_assign_resources_tbl(l_current_record).role;
11559 x_assign_resources_tbl(l_count).start_date :=
11560 l_assign_resources_tbl(l_current_record).start_date;
11561 x_assign_resources_tbl(l_count).end_date :=
11562 l_assign_resources_tbl(l_current_record).end_date;
11563 x_assign_resources_tbl(l_count).shift_construct_id :=
11564 l_assign_resources_tbl(l_current_record).shift_construct_id;
11565 x_assign_resources_tbl(l_count).terr_id :=
11566 l_assign_resources_tbl(l_current_record).terr_id;
11567 x_assign_resources_tbl(l_count).terr_name :=
11568 l_assign_resources_tbl(l_current_record).terr_name;
11569 -- ================code added for bug 6453896=============
11570 x_assign_resources_tbl(l_count).terr_rank :=
11571 l_assign_resources_tbl(l_current_record).terr_rank;
11572 -- ================End for addition of code===============
11573 x_assign_resources_tbl(l_count).preference_type :=
11574 l_assign_resources_tbl(l_current_record).preference_type;
11575 x_assign_resources_tbl(l_count).primary_contact_flag :=
11576 l_assign_resources_tbl(l_current_record).primary_contact_flag;
11577 x_assign_resources_tbl(l_count).location :=
11578 l_assign_resources_tbl(l_current_record).location;
11579
11580 x_assign_resources_tbl(l_count).support_site_id :=
11581 l_assign_resources_tbl(l_current_record).support_site_id;
11582 x_assign_resources_tbl(l_count).support_site_name :=
11583 l_assign_resources_tbl(l_current_record).support_site_name;
11584 x_assign_resources_tbl(l_count).web_availability_flag :=
11585 l_assign_resources_tbl(l_current_record).web_availability_flag;
11586 x_assign_resources_tbl(l_count).primary_flag :=
11587 l_assign_resources_tbl(l_current_record).primary_flag;
11588 x_assign_resources_tbl(l_count).resource_source :=
11589 l_assign_resources_tbl(l_current_record).resource_source;
11590
11591
11592 end if;
11593 close check_date_cur;
11594 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
11595 END LOOP;
11596
11597 ELSE -- Auto Select Flag is NO
11598
11599 WHILE l_current_record <= l_assign_resources_tbl.LAST
11600 LOOP
11601
11602 -- add check to see whether the resource is end dated or not
11603 -- added by sudarsana 21 feb 02
11604 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
11605 l_assign_resources_tbl(l_current_record).resource_type);
11606 fetch check_date_cur into l_value;
11607 if (check_date_cur%found)
11608 then
11609 l_count := l_count + 1;
11610 x_assign_resources_tbl(l_count).terr_rsc_id :=
11611 l_assign_resources_tbl(l_current_record).terr_rsc_id;
11612 x_assign_resources_tbl(l_count).resource_id :=
11613 l_assign_resources_tbl(l_current_record).resource_id;
11614 x_assign_resources_tbl(l_count).resource_type :=
11615 l_assign_resources_tbl(l_current_record).resource_type;
11616 x_assign_resources_tbl(l_count).role :=
11617 l_assign_resources_tbl(l_current_record).role;
11618 x_assign_resources_tbl(l_count).start_date :=
11619 l_assign_resources_tbl(l_current_record).start_date;
11620 x_assign_resources_tbl(l_count).end_date :=
11621 l_assign_resources_tbl(l_current_record).end_date;
11622 x_assign_resources_tbl(l_count).shift_construct_id :=
11623 l_assign_resources_tbl(l_current_record).shift_construct_id;
11624 x_assign_resources_tbl(l_count).terr_id :=
11625 l_assign_resources_tbl(l_current_record).terr_id;
11626 x_assign_resources_tbl(l_count).terr_name :=
11627 l_assign_resources_tbl(l_current_record).terr_name;
11628 -- ================code added for bug 6453896=============
11629 x_assign_resources_tbl(l_count).terr_rank :=
11630 l_assign_resources_tbl(l_current_record).terr_rank;
11631 -- ================End for addition of code===============
11632 x_assign_resources_tbl(l_count).preference_type :=
11633 l_assign_resources_tbl(l_current_record).preference_type;
11634 x_assign_resources_tbl(l_count).primary_contact_flag :=
11635 l_assign_resources_tbl(l_current_record).primary_contact_flag;
11636 x_assign_resources_tbl(l_count).location :=
11637 l_assign_resources_tbl(l_current_record).location;
11638
11639 x_assign_resources_tbl(l_count).support_site_id :=
11640 l_assign_resources_tbl(l_current_record).support_site_id;
11641 x_assign_resources_tbl(l_count).support_site_name :=
11642 l_assign_resources_tbl(l_current_record).support_site_name;
11643 x_assign_resources_tbl(l_count).web_availability_flag :=
11644 l_assign_resources_tbl(l_current_record).web_availability_flag;
11645 x_assign_resources_tbl(l_count).primary_flag :=
11646 l_assign_resources_tbl(l_current_record).primary_flag;
11647 x_assign_resources_tbl(l_count).resource_source :=
11648 l_assign_resources_tbl(l_current_record).resource_source;
11649 end if;
11650 close check_date_cur;
11651 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
11652 END LOOP;
11653 END IF; -- Auto Select Flag
11654
11655 ELSE -- No resources returned from the Assignment Manager API for TASKS
11656 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
11657 fnd_msg_pub.add;
11658 -- RAISE fnd_api.g_exc_error;
11659 END IF;
11660
11661 -- raise workfow event
11662 -- workflow test
11663 Begin
11664 jtf_assign_pub.g_assign_resources_tbl.delete;
11665 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
11666 jtf_am_wf_events_pub.assign_task_resource
11667 (P_API_VERSION => 1.0,
11668 P_INIT_MSG_LIST => 'F',
11669 P_COMMIT => 'F',
11670 P_BUSINESS_PROCESS_ID => p_business_process_id,
11671 P_BUSINESS_PROCESS_DATE => p_business_process_date,
11672 P_TASK_ID => p_calling_doc_id,
11673 P_CONTRACT_ID => p_contract_id ,
11674 P_CUSTOMER_PRODUCT_ID => p_customer_product_id ,
11675 P_CATEGORY_ID => p_category_id ,
11676 X_RETURN_STATUS => l_wf_return_status,
11677 X_MSG_COUNT => l_wf_msg_count,
11678 X_MSG_DATA => l_wf_msg_data
11679 );
11680
11681
11682 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
11683 -- Unexpected Execution Error from call to assign_sr_resource
11684 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
11685 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
11686 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
11687 fnd_msg_pub.add;
11688
11689 ELSE
11690 x_assign_resources_tbl.delete;
11691 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
11692 END IF;
11693
11694 Exception
11695 When OTHERS Then
11696 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
11697 fnd_message.set_token('P_SQLCODE',SQLCODE);
11698 fnd_message.set_token('P_SQLERRM',SQLERRM);
11699 fnd_message.set_token('P_API_NAME',l_api_name);
11700 FND_MSG_PUB.add;
11701 End;
11702
11703 -- ================code added for bug 6453896==========================
11704 -- =============== This code is added for sorting table based on territory ranking===========
11705 l_sort_profile := nvl(fnd_profile.value('JTF_AM_SORT_TERR_RANK'),'N');
11706 If l_sort_profile ='Y'
11707 then
11708 t_assign_resources_tbl :=x_assign_resources_tbl;
11709 x_assign_resources_tbl.delete;
11710
11711 quick_sort_terr_rank
11712 (
11713 t_assign_resources_tbl.FIRST,
11714 t_assign_resources_tbl.LAST,
11715 t_assign_resources_tbl
11716 );
11717 x_assign_resources_tbl:=t_assign_resources_tbl;
11718 End If;
11719 -- ================End for addition of code===============
11720
11721 ELSIF ( UPPER(l_calling_doc_type) = 'DEF' ) THEN
11722 GET_ASSIGN_DEFECT_RESOURCES
11723 (
11724 p_api_version => l_api_version,
11725 p_init_msg_list => p_init_msg_list,
11726 p_resource_type => p_resource_type,
11727 p_role => p_role,
11728 p_no_of_resources => l_no_of_resources,
11729 p_auto_select_flag => l_auto_select_flag,
11730 p_effort_duration => l_effort_duration, --p_effort_duration,
11731 p_effort_uom => p_effort_uom,
11732 p_start_date => p_start_date,
11733 p_end_date => p_end_date,
11734 p_territory_flag => l_territory_flag,
11735 p_calendar_flag => l_calendar_flag,
11736 p_defect_rec => l_defect_rec,
11737 p_business_process_id => p_business_process_id,
11738 p_business_process_date => p_business_process_date,
11739 x_assign_resources_tbl => l_assign_resources_tbl,
11740 x_return_status => x_return_status,
11741 x_msg_count => x_msg_count,
11742 x_msg_data => x_msg_data
11743 );
11744
11745 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
11746 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
11747 fnd_message.set_token('P_PROC_NAME','GET_ASSIGN_DEFECT_RESOURCES');
11748 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
11749 fnd_msg_pub.add;
11750 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
11751 RAISE fnd_api.g_exc_error;
11752 ELSE
11753 RAISE fnd_api.g_exc_unexpected_error;
11754 END IF;
11755 END IF;
11756
11757 -- added this to filter by usage
11758 IF ((l_assign_resources_tbl.count > 0 ) AND
11759 (nvl(l_usage, fnd_api.g_miss_char) <> 'ALL' ) AND
11760 (l_usage is not null)
11761 --(l_usage is not null or l_usage <> 'ALL')
11762 )
11763 THEN
11764 get_usage_resource(l_usage ,
11765 l_assign_resources_tbl);
11766 END IF;
11767
11768 IF l_assign_resources_tbl.COUNT > 0 THEN
11769
11770
11771 l_current_record := l_assign_resources_tbl.FIRST;
11772
11773 -- added the autoselect check here after removing from the GET_ASSIGN_DEFECT_RESOURCES api
11774 -- on 29th september 2003
11775 IF (p_auto_select_flag = 'Y') THEN
11776 l_no_of_resources := p_no_of_resources;
11777 ELSE
11778 l_no_of_resources := l_assign_resources_tbl.LAST;
11779 END IF;
11780
11781 -- added processing with l_count to fix defect bug 2490634
11782 -- on 6th aug 2002
11783 x_assign_resources_tbl.delete;
11784 l_count := l_current_record;
11785 WHILE l_current_record <= l_assign_resources_tbl.LAST
11786 LOOP
11787
11788 IF(l_count <= l_no_of_resources)
11789 THEN
11790 -- add check to see whether the resource is end dated or not
11791 -- added by sudarsana 21 feb 02
11792 open check_date_cur(l_assign_resources_tbl(l_current_record).resource_id,
11793 l_assign_resources_tbl(l_current_record).resource_type);
11794 fetch check_date_cur into l_value;
11795 if (check_date_cur%found)
11796 then
11797 x_assign_resources_tbl(l_count).terr_rsc_id :=
11798 l_assign_resources_tbl(l_current_record).terr_rsc_id;
11799 x_assign_resources_tbl(l_count).resource_id :=
11800 l_assign_resources_tbl(l_current_record).resource_id;
11801 x_assign_resources_tbl(l_count).resource_type :=
11802 l_assign_resources_tbl(l_current_record).resource_type;
11803
11804 x_assign_resources_tbl(l_count).start_date :=
11805 l_assign_resources_tbl(l_current_record).start_date;
11806 x_assign_resources_tbl(l_count).end_date :=
11807 l_assign_resources_tbl(l_current_record).end_date;
11808 x_assign_resources_tbl(l_count).shift_construct_id :=
11809 l_assign_resources_tbl(l_current_record).shift_construct_id;
11810
11811 x_assign_resources_tbl(l_count).role :=
11812 l_assign_resources_tbl(l_current_record).role;
11813 x_assign_resources_tbl(l_count).preference_type :=
11814 l_assign_resources_tbl(l_current_record).preference_type;
11815 x_assign_resources_tbl(l_count).primary_contact_flag :=
11816 l_assign_resources_tbl(l_current_record).primary_contact_flag;
11817
11818 x_assign_resources_tbl(l_count).terr_id :=
11819 l_assign_resources_tbl(l_current_record).terr_id;
11820 x_assign_resources_tbl(l_count).terr_name :=
11821 l_assign_resources_tbl(l_current_record).terr_name;
11822 x_assign_resources_tbl(l_count).terr_rank :=
11823 l_assign_resources_tbl(l_current_record).terr_rank;
11824 x_assign_resources_tbl(l_count).primary_flag :=
11825 l_assign_resources_tbl(l_current_record).primary_flag;
11826 x_assign_resources_tbl(l_count).resource_source :=
11827 l_assign_resources_tbl(l_current_record).resource_source;
11828 l_count := l_count + 1;
11829 end if; -- end of check_date_cur found check
11830 close check_date_cur;
11831 END IF; -- end of check l_count against l_no_of_resources
11832 l_current_record := l_assign_resources_tbl.NEXT(l_current_record);
11833 END LOOP;
11834
11835 ELSE -- No resources returned from the Assignment Manager API for DEFECTS
11836 fnd_message.set_name('JTF', 'JTF_AM_NO_RESOURCES_FOUND');
11837 fnd_msg_pub.add;
11838 -- RAISE fnd_api.g_exc_error;
11839 END IF;
11840
11841 -- raise workfow event
11842 -- workflow test
11843 Begin
11844 jtf_assign_pub.g_assign_resources_tbl.delete;
11845 jtf_assign_pub.g_assign_resources_tbl := x_assign_resources_tbl;
11846 jtf_am_wf_events_pub.assign_def_resource
11847 (P_API_VERSION => 1.0,
11848 P_INIT_MSG_LIST => 'F',
11849 P_COMMIT => 'F',
11850 P_CONTRACT_ID => p_contract_id ,
11851 P_CUSTOMER_PRODUCT_ID => p_customer_product_id ,
11852 P_CATEGORY_ID => p_category_id ,
11853 P_DEF_MGMT_REC => p_defect_rec,
11854 P_BUSINESS_PROCESS_ID => p_business_process_id,
11855 P_BUSINESS_PROCESS_DATE => p_business_process_date,
11856 X_RETURN_STATUS => l_wf_return_status,
11857 X_MSG_COUNT => l_wf_msg_count,
11858 X_MSG_DATA => l_wf_msg_data
11859 );
11860
11861
11862 IF NOT (l_wf_return_status = fnd_api.g_ret_sts_success) THEN
11863 -- Unexpected Execution Error from call to assign_sr_resource
11864 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
11865 fnd_message.set_token('P_PROC_NAME','JTF_AM_WF_EVENTS_PUB');
11866 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_RESOURCES');
11867 fnd_msg_pub.add;
11868
11869 ELSE
11870 x_assign_resources_tbl.delete;
11871 x_assign_resources_tbl := jtf_assign_pub.g_assign_resources_tbl;
11872 END IF;
11873
11874
11875 Exception
11876 When OTHERS Then
11877 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
11878 fnd_message.set_token('P_SQLCODE',SQLCODE);
11879 fnd_message.set_token('P_SQLERRM',SQLERRM);
11880 fnd_message.set_token('P_API_NAME',l_api_name);
11881 FND_MSG_PUB.add;
11882 End;
11883
11884
11885 END IF; -- End of UPPER(l_calling_doc_type)= 'SR'- 'TASK'- 'DEF'
11886
11887
11888
11889 -- To Plugin the Workflow enabling the user
11890 -- to further filter the resources
11891
11892 SELECT jtf_calendars_s.NEXTVAL INTO l_workflow_key
11893 FROM dual;
11894
11895 IF (JTF_USR_HKS.ok_to_execute
11896 (
11897 'JTF_ASSIGN_PUB',
11898 'GET_ASSIGN_RESOURCES',
11899 'W',
11900 'W'
11901 )
11902 ) THEN
11903
11904 IF (JTF_ASSIGN_CUHK.ok_to_launch_workflow
11905 (
11906 p_api_version => l_api_version,
11907 p_init_msg_list => p_init_msg_list,
11908 x_return_status => x_return_status,
11909 x_msg_count => x_msg_count,
11910 x_msg_data => x_msg_data
11911 )
11912 ) THEN
11913
11914
11915 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
11916 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
11917 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
11918 fnd_msg_pub.add;
11919 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
11920 RAISE fnd_api.g_exc_error;
11921 ELSE
11922 RAISE fnd_api.g_exc_unexpected_error;
11923 END IF;
11924 END IF;
11925
11926
11927 l_bind_data_id := JTF_USR_HKS.get_bind_data_id;
11928
11929 JTF_USR_HKS.WrkFlowLaunch
11930 (
11931 'JTF_ASSIGN_WF',
11932 l_workflow_profile,
11933 'ASSIGN WF - '|| TO_CHAR(l_workflow_key),
11934 l_bind_data_id,
11935 l_return_code
11936 );
11937
11938 JTF_USR_HKS.purge_bind_data
11939 (
11940 l_bind_data_id,
11941 'W'
11942 );
11943
11944
11945 IF (l_return_code = fnd_api.g_ret_sts_error) THEN
11946 -- Execution Error from call to Assignment Manager Workflow Hook
11947 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
11948 fnd_msg_pub.add;
11949 RAISE fnd_api.g_exc_error;
11950 ELSIF (l_return_code = fnd_api.g_ret_sts_unexp_error) THEN
11951 -- Unexpected Execution Error from call to Assignment Manager Workflow Hook
11952 fnd_message.set_name('JTF', 'JTF_AM_ERROR_WF_API');
11953 fnd_msg_pub.add;
11954 RAISE fnd_api.g_exc_unexpected_error;
11955 END IF;
11956
11957 END IF; -- End of JTF_ASSIGN_CUHK
11958
11959 END IF; -- End of JTF_USR_HKS
11960
11961
11962 /* Standard call to get message count and
11963 the message information */
11964
11965 FND_MSG_PUB.Count_And_Get
11966 (
11967 p_count => x_msg_count,
11968 p_data => x_msg_data
11969 );
11970
11971
11972 x_return_status := fnd_api.g_ret_sts_success;
11973
11974
11975
11976 EXCEPTION
11977 WHEN FND_API.G_EXC_ERROR THEN
11978 x_return_status := FND_API.G_RET_STS_ERROR ;
11979 FND_MSG_PUB.Count_And_Get
11980 (
11981 p_count => x_msg_count,
11982 p_data => x_msg_data
11983 );
11984
11985 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11986 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
11987 FND_MSG_PUB.Count_And_Get
11988 (
11989 p_count => x_msg_count,
11990 p_data => x_msg_data
11991 );
11992
11993 WHEN OTHERS THEN
11994 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
11995 fnd_message.set_token('P_SQLCODE',SQLCODE);
11996 fnd_message.set_token('P_SQLERRM',SQLERRM);
11997 fnd_message.set_token('P_API_NAME',l_api_name);
11998 FND_MSG_PUB.add;
11999
12000 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
12001 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
12002 FND_MSG_PUB.Add_Exc_Msg
12003 (
12004 G_PKG_NAME,
12005 l_api_name
12006 );
12007 END IF;
12008
12009 FND_MSG_PUB.Count_And_Get
12010 (
12011 p_count => x_msg_count,
12012 p_data => x_msg_data
12013 );
12014
12015 END GET_ASSIGN_RESOURCES;
12016
12017 -- this is a procedure added on 2nd July 2002 to get the Excluded Resources for the AM UI
12018 -- when working in assisted Mode
12019 PROCEDURE GET_EXCLUDED_RESOURCES
12020 ( p_api_version IN NUMBER,
12021 p_init_msg_list IN VARCHAR2 DEFAULT JTF_ASSIGN_PUB.AM_FALSE,
12022 p_commit IN VARCHAR2 DEFAULT JTF_ASSIGN_PUB.AM_FALSE,
12023 p_contract_id IN NUMBER DEFAULT NULL,
12024 p_customer_product_id IN NUMBER DEFAULT NULL,
12025 p_calling_doc_id IN NUMBER,
12026 p_calling_doc_type IN VARCHAR2,
12027 p_sr_rec IN JTF_ASSIGN_PUB.JTF_Serv_Req_rec_type DEFAULT pkg_sr_rec,
12028 p_sr_task_rec IN JTF_ASSIGN_PUB.JTF_Srv_Task_rec_type DEFAULT pkg_sr_task_rec,
12029 p_dr_rec IN JTF_ASSIGN_PUB.JTF_DR_rec_type DEFAULT pkg_dr_rec, --Added by SBARAT on 01/11/2004 for Enh-3919046
12030 p_business_process_id IN NUMBER,
12031 p_business_process_date IN DATE,
12032 x_excluded_resouurce_tbl OUT NOCOPY JTF_ASSIGN_PUB.excluded_tbl_type,
12033 x_return_status OUT NOCOPY VARCHAR2,
12034 x_msg_count OUT NOCOPY NUMBER,
12035 x_msg_data OUT NOCOPY VARCHAR2
12036 )
12037 IS
12038 l_return_status_1 VARCHAR2(10);
12039 l_api_name VARCHAR2(100) := 'GET_EXCLUDED_RESOURCES';
12040 l_api_name_1 VARCHAR2(60) := 'GET_EXCLUDED_RESOURCES';
12041 l_api_version NUMBER := 1.0;
12042
12043 -- tables to habdle excluded resource feature
12044 l_excluded_resource_tbl JTF_ASSIGN_PUB.excluded_tbl_type;
12045 l_contracts_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
12046 l_ib_tbl JTF_ASSIGN_PUB.AssignResources_tbl_type;
12047
12048 l_contract_id NUMBER := p_contract_id;
12049 l_cp_id NUMBER := p_customer_product_id;
12050
12051 l_sr_id NUMBER;
12052 l_task_id NUMBER;
12053 l_dr_id NUMBER;
12054 l_task_source_code JTF_TASKS_VL.SOURCE_OBJECT_TYPE_CODE%TYPE;
12055 l_task_source_id JTF_TASKS_VL.SOURCE_OBJECT_ID%TYPE;
12056
12057 l_return_status VARCHAR2(10);
12058 l_msg_count NUMBER;
12059 l_msg_data VARCHAR2(2000);
12060
12061 l_dynamic_sql1 VARCHAR2(2000);
12062
12063 TYPE DYNAMIC_CUR_TYP IS REF CURSOR;
12064 cur_cs_contacts DYNAMIC_CUR_TYP;
12065 cur_cs_incidents DYNAMIC_CUR_TYP;
12066
12067 CURSOR cur_task_id IS
12068 SELECT source_object_type_code,
12069 source_object_id,
12070 planned_start_date,
12071 planned_end_date,
12072 planned_effort,
12073 planned_effort_uom
12074 FROM jtf_tasks_vl
12075 WHERE task_id = l_task_id;
12076
12077 l_cur_task_id cur_task_id%ROWTYPE;
12078
12079 BEGIN
12080
12081 /* Standard call to check for call compatibility */
12082
12083 IF NOT fnd_api.compatible_api_call (l_api_version,
12084 p_api_version,
12085 l_api_name,
12086 g_pkg_name) THEN
12087 RAISE fnd_api.g_exc_unexpected_error;
12088 END IF;
12089
12090
12091 /* Initialize message list if p_init_msg_list is set to TRUE */
12092
12093 IF fnd_api.to_boolean (p_init_msg_list) THEN
12094 fnd_msg_pub.initialize;
12095 END IF;
12096
12097 x_return_status := fnd_api.g_ret_sts_success;
12098
12099 -- If p_document_type = TASK then get the contract_service_id and the customer_product_id from the table
12100 IF(p_calling_doc_type = 'TASK')
12101 THEN
12102 l_task_id := p_calling_doc_id;
12103 If(l_task_id IS NOT NULL)
12104 -- this has been added as in form startup we now do a autoquery. So if no task id is passed instead of throwing the
12105 -- message that invalid id has been passed in we will just not do any processing
12106 THEN
12107 OPEN cur_task_id;
12108 FETCH cur_task_id INTO l_cur_task_id;
12109 IF ( cur_task_id%NOTFOUND )
12110 THEN
12111 null;
12112 ELSE
12113 l_task_source_code := l_cur_task_id.source_object_type_code;
12114 l_task_source_id := l_cur_task_id.source_object_id;
12115 END IF;
12116 CLOSE cur_task_id;
12117
12118
12119 IF (l_task_source_id IS NOT NULL AND l_task_source_code = 'SR')
12120 THEN
12121 l_dynamic_sql1 := ' SELECT contract_service_id, customer_product_id'||
12122 ' FROM cs_incidents_all_vl'||
12123 ' WHERE incident_id = :1';
12124
12125 OPEN cur_cs_incidents FOR l_dynamic_sql1 USING l_task_source_id;
12126 FETCH cur_cs_incidents INTO l_contract_id,
12127 l_cp_id;
12128 END IF;
12129
12130 ELSIF(p_calling_doc_type = 'SR')
12131 -- If document type = SR then get the contract_service_id and customer_product_id from the parameters if passed
12132 -- Else get it from the cs_incidents_all table
12133 THEN
12134 l_sr_id := p_calling_doc_id;
12135 l_contract_id := p_contract_id;
12136 l_cp_id := p_customer_product_id;
12137 -- Code to fetch the Preferred Resources for saved SR
12138 IF (l_contract_id IS NULL AND
12139 l_cp_id IS NULL AND
12140 l_sr_id IS NOT NULL) THEN
12141
12142 l_dynamic_sql1 := ' SELECT contract_service_id, customer_product_id'||
12143 ' FROM cs_incidents_all_vl'||
12144 ' WHERE incident_id = :1';
12145
12146 OPEN cur_cs_incidents FOR l_dynamic_sql1 USING l_sr_id;
12147 FETCH cur_cs_incidents INTO l_contract_id,
12148 l_cp_id;
12149
12150 IF ( cur_cs_incidents%NOTFOUND ) THEN
12151 null;
12152 END IF;
12153
12154 CLOSE cur_cs_incidents;
12155 END IF; -- end of l_contract_id and l_cp_id null check
12156
12157 /********** Added by SBARAT on 01/11/2004 for Enh-3919046 ***********/
12158
12159 ELSIF(p_calling_doc_type = 'DR')
12160 -- If document type = DR then get the contract_service_id and customer_product_id from the parameters if passed
12161 -- Else get it from the cs_incidents_all table
12162 THEN
12163 l_dr_id := p_calling_doc_id;
12164 l_contract_id := p_contract_id;
12165 l_cp_id := p_customer_product_id;
12166 -- Code to fetch the Preferred Resources for saved DR
12167 IF (l_contract_id IS NULL AND
12168 l_cp_id IS NULL AND
12169 l_dr_id IS NOT NULL) THEN
12170
12171 l_dynamic_sql1 := ' SELECT contract_service_id, customer_product_id'||
12172 ' FROM cs_incidents_all_vl'||
12173 ' WHERE incident_id = :1';
12174
12175 OPEN cur_cs_incidents FOR l_dynamic_sql1 USING l_dr_id;
12176 FETCH cur_cs_incidents INTO l_contract_id,
12177 l_cp_id;
12178
12179 IF ( cur_cs_incidents%NOTFOUND ) THEN
12180 null;
12181 END IF;
12182
12183 CLOSE cur_cs_incidents;
12184 END IF; -- end of l_contract_id and l_cp_id null check
12185
12186 /********* End of addition by SBARAT on 01/11/2004 for Enh-3919046 ********/
12187
12188 END IF;
12189
12190 END IF; -- end of calling doc type check
12191
12192
12193
12194 -- call the get_contract_resources and get_ib_resources to get the excluded resources
12195 IF(l_contract_id is not null)
12196 THEN
12197 get_contracts_resources
12198 (
12199 p_init_msg_list => p_init_msg_list,
12200 p_contract_id => l_contract_id,
12201 p_calendar_flag => 'N',
12202 p_effort_duration => null,
12203 p_effort_uom => null,
12204 p_planned_start_date => null,
12205 p_planned_end_date => null,
12206 p_resource_type => null,
12207 p_business_process_id => p_business_process_id,
12208 p_business_process_date => p_business_process_date,
12209 x_return_status => x_return_status,
12210 x_msg_count => x_msg_count,
12211 x_msg_data => x_msg_data,
12212 x_assign_resources_tbl => l_contracts_tbl,
12213 x_excluded_tbl => l_excluded_resource_tbl
12214 );
12215
12216 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
12217 -- Unexpected Execution Error from call to Get_contracts_resources
12218 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
12219 fnd_message.set_token('P_PROC_NAME','GET_CONTRACTS_RESOURCES');
12220 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_SR_RESOURCES');
12221 fnd_msg_pub.add;
12222 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
12223 RAISE fnd_api.g_exc_error;
12224 ELSE
12225 RAISE fnd_api.g_exc_unexpected_error;
12226 END IF;
12227 END IF;
12228 END IF;
12229
12230
12231 IF(l_cp_id is not null)
12232 THEN
12233 get_ib_resources
12234 (
12235 p_init_msg_list => p_init_msg_list,
12236 p_customer_product_id => l_cp_id,
12237 p_calendar_flag => 'N',
12238 p_effort_duration => null,
12239 p_effort_uom => null,
12240 p_planned_start_date => null,
12241 p_planned_end_date => null,
12242 p_resource_type => null,
12243 x_return_status => x_return_status,
12244 x_msg_count => x_msg_count,
12245 x_msg_data => x_msg_data,
12246 x_assign_resources_tbl => l_ib_tbl,
12247 x_excluded_tbl => l_excluded_resource_tbl
12248 );
12249
12250 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
12251 -- Unexpected Execution Error from call to Get_contracts_resources
12252 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
12253 fnd_message.set_token('P_PROC_NAME','GET_IB_RESOURCES');
12254 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_ASSIGN_TASK_RESOURCES');
12255 fnd_msg_pub.add;
12256 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
12257 RAISE fnd_api.g_exc_error;
12258 ELSE
12259 RAISE fnd_api.g_exc_unexpected_error;
12260 END IF;
12261 END IF;
12262 END IF;
12263
12264
12265 -- assign the excluded resources to the out table
12266 x_excluded_resouurce_tbl.delete;
12267 x_excluded_resouurce_tbl := l_excluded_resource_tbl;
12268
12269 EXCEPTION
12270 WHEN FND_API.G_EXC_ERROR THEN
12271 x_return_status := FND_API.G_RET_STS_ERROR ;
12272 FND_MSG_PUB.Count_And_Get
12273 (
12274 p_count => x_msg_count,
12275 p_data => x_msg_data
12276 );
12277
12278 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
12279 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
12280 FND_MSG_PUB.Count_And_Get
12281 (
12282 p_count => x_msg_count,
12283 p_data => x_msg_data
12284 );
12285
12286 WHEN OTHERS THEN
12287 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
12288 fnd_message.set_token('P_SQLCODE',SQLCODE);
12289 fnd_message.set_token('P_SQLERRM',SQLERRM);
12290 fnd_message.set_token('P_API_NAME',l_api_name);
12291 FND_MSG_PUB.add;
12292
12293 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
12294 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
12295 FND_MSG_PUB.Add_Exc_Msg
12296 (
12297 G_PKG_NAME,
12298 l_api_name
12299 );
12300 END IF;
12301
12302 FND_MSG_PUB.Count_And_Get
12303 (
12304 p_count => x_msg_count,
12305 p_data => x_msg_data
12306 );
12307 END GET_EXCLUDED_RESOURCES;
12308
12309
12310 -- this is a wrapper for get_available_resource
12311 -- this is to be used only from AM UI to get the available slots for the resources fetched in
12312 -- Unassisted mode
12313 PROCEDURE GET_RESOURCE_AVAILABILITY
12314 ( p_api_version IN NUMBER,
12315 p_init_msg_list IN VARCHAR2 DEFAULT JTF_ASSIGN_PUB.AM_FALSE,
12316 p_commit IN VARCHAR2 DEFAULT JTF_ASSIGN_PUB.AM_FALSE,
12317 p_calendar_flag IN VARCHAR2,
12318 p_effort_duration IN NUMBER,
12319 p_effort_uom IN VARCHAR2,
12320 p_breakdown IN NUMBER,
12321 p_breakdown_uom IN VARCHAR2,
12322 p_planned_start_date IN DATE,
12323 p_planned_end_date IN DATE,
12324 p_continuous_task IN VARCHAR2 DEFAULT 'N',
12325 x_return_status IN OUT NOCOPY VARCHAR2,
12326 x_msg_count IN OUT NOCOPY NUMBER,
12327 x_msg_data IN OUT NOCOPY VARCHAR2,
12328 x_assign_resources_tbl IN OUT NOCOPY JTF_ASSIGN_PUB.AssignResources_tbl_type
12329 )
12330 IS
12331 l_return_status_1 VARCHAR2(10);
12332 l_api_name VARCHAR2(100) := 'GET_EXCLUDED_RESOURCES';
12333 l_api_name_1 VARCHAR2(60) := 'GET_EXCLUDED_RESOURCES';
12334 l_api_version NUMBER := 1.0;
12335
12336 BEGIN
12337 /* Standard call to check for call compatibility */
12338 IF NOT fnd_api.compatible_api_call (l_api_version,
12339 p_api_version,
12340 l_api_name,
12341 g_pkg_name)
12342 THEN
12343 RAISE fnd_api.g_exc_unexpected_error;
12344 END IF;
12345
12346
12347 /* Initialize message list if p_init_msg_list is set to TRUE */
12348 IF fnd_api.to_boolean (p_init_msg_list)
12349 THEN
12350 fnd_msg_pub.initialize;
12351 END IF;
12352
12353 x_return_status := fnd_api.g_ret_sts_success;
12354
12355 l_api_name := l_api_name||'-GET_AVAILABLE_RESOURCE';
12356 l_return_status_1 := x_return_status ;
12357 -- call the api to check resource availability
12358 get_available_resources
12359 (
12360 p_init_msg_list => 'F',
12361 p_calendar_flag => p_calendar_flag,
12362 p_effort_duration => p_effort_duration,
12363 p_effort_uom => p_effort_uom,
12364 p_breakdown => p_breakdown,
12365 p_breakdown_uom => p_breakdown_uom,
12366 p_planned_start_date => p_planned_start_date,
12367 p_planned_end_date => p_planned_end_date,
12368 p_continuous_task => jtf_assign_pub.g_continuous_work,
12369 x_return_status => x_return_status,
12370 x_msg_count => x_msg_count,
12371 x_msg_data => x_msg_data,
12372 x_assign_resources_tbl => x_assign_resources_tbl);
12373
12374 -- set back the API name to original name
12375 l_api_name := l_api_name_1;
12376
12377 IF NOT (x_return_status = fnd_api.g_ret_sts_success) THEN
12378 -- Unexpected Execution Error from call to Get_contracts_resources
12379 fnd_message.set_name('JTF', 'JTF_AM_GENERIC_API_ERROR');
12380 fnd_message.set_token('P_PROC_NAME','GET_AVAILABLE_RESOURCE');
12381 fnd_message.set_token('P_API_NAME','JTF_ASSIGN_PUB.GET_CONTRACTS_RESOURCES');
12382 fnd_msg_pub.add;
12383 IF (x_return_status = fnd_api.g_ret_sts_error) THEN
12384 RAISE fnd_api.g_exc_error;
12385 ELSE
12386 RAISE fnd_api.g_exc_unexpected_error;
12387 END IF;
12388 END IF; -- end of x_return_status check
12389
12390
12391
12392
12393 EXCEPTION
12394 WHEN FND_API.G_EXC_ERROR THEN
12395 x_return_status := FND_API.G_RET_STS_ERROR ;
12396 FND_MSG_PUB.Count_And_Get
12397 (
12398 p_count => x_msg_count,
12399 p_data => x_msg_data
12400 );
12401
12402 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
12403 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
12404 FND_MSG_PUB.Count_And_Get
12405 (
12406 p_count => x_msg_count,
12407 p_data => x_msg_data
12408 );
12409
12410 WHEN OTHERS THEN
12411 fnd_message.set_name ('JTF', 'JTF_AM_UNEXP_ERROR');
12412 fnd_message.set_token('P_SQLCODE',SQLCODE);
12413 fnd_message.set_token('P_SQLERRM',SQLERRM);
12414 fnd_message.set_token('P_API_NAME',l_api_name);
12415 FND_MSG_PUB.add;
12416
12417 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
12418 IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )THEN
12419 FND_MSG_PUB.Add_Exc_Msg
12420 (
12421 G_PKG_NAME,
12422 l_api_name
12423 );
12424 END IF;
12425
12426 FND_MSG_PUB.Count_And_Get
12427 (
12428 p_count => x_msg_count,
12429 p_data => x_msg_data
12430 );
12431
12432 END GET_RESOURCE_AVAILABILITY;
12433
12434 END JTF_ASSIGN_PUB;