DBA Data[Home] [Help]

PACKAGE BODY: APPS.JTF_CAL_PVT

Source


1 PACKAGE BODY Jtf_Cal_Pvt AS
2 /* $Header: jtfvhcb.pls 120.6 2006/05/30 13:19:14 sbarat ship $ */
3 
4 PROCEDURE GetCalendarList
5 /*******************************************************************************
6 ** Given a ResourceID, this procedure will return a list of Calendars that the
7 ** Calendar user has access to
8 *******************************************************************************/
9 ( p_api_version            IN     NUMBER
10 , p_init_msg_list          IN     VARCHAR2
11 , p_validation_level       IN     NUMBER
12 , x_return_status          OUT    NOCOPY	VARCHAR2
13 , x_msg_count              OUT    NOCOPY	NUMBER
14 , x_msg_data               OUT    NOCOPY	VARCHAR2
15 , p_resourceID             IN OUT NOCOPY	NUMBER
16 , p_resourceType           IN OUT NOCOPY	VARCHAR2
17 , p_userID                 IN     NUMBER
18 , x_calendarList           OUT    NOCOPY	CalLstTblType
19 )
20 IS
21   l_index         BINARY_INTEGER:=1;
22   l_ResourceName  VARCHAR2(360);
23   l_GranteeKey    VARCHAR2(240);
24   /*****************************************************************************
25   ** NOTE: Since we consider the views provided by AOL performance hazards we
26   **       will pick up the data we need directly from their tables
27   *****************************************************************************/
28 
29   CURSOR c_PersonalCalendars(b_Grantee_Key IN VARCHAR2)
30   /*****************************************************************************
31   ** This cursor will pick up all Resource Ids of persons the Calendar User has
32   ** access to and the level of access that was granted.
33   ****************************************************************/
34   IS SELECT DISTINCT fmu.menu_name         Privilege
35      ,      fgs.instance_pk1_value         ResourceID
36      ,      jrt.resource_name              ResourceName
37      FROM  fnd_grants                 fgs
38      ,     fnd_menus                  fmu
39      ,     fnd_objects                fos
40      ,     jtf_rs_resource_extns_tl   jrt
41      WHERE fgs.object_id          = fos.object_id   -- grants joint to object
42      AND   fgs.menu_id            = fmu.menu_id     -- grants joint to menus
43      AND   fos.obj_name           = 'JTF_TASK_RESOURCE'
44      AND   fgs.grantee_key        = b_Grantee_Key
45      AND   fgs.grantee_type       = 'USER'
46      AND   fgs.start_date        <  SYSDATE
47      AND   (   fgs.end_date          >= SYSDATE
48            OR  fgs.end_date IS NULL
49            )
50      AND   fgs.instance_pk2_value = ('RS_EMPLOYEE')
51      AND   jrt.resource_id        = to_number(fgs.instance_pk1_value)  -- Modified by SBARAT on 30/05/2006 for bug# 5213367
52      AND   jrt.LANGUAGE           = USERENV('LANG');
53 
54   CURSOR c_GroupCalendars(b_GranteeKey IN VARCHAR2)
55   /*****************************************************************************
56   ** This cursor will pick up all Resource Group Ids of persons the Calendar
57   ** User has the CALENDAR_ADMIN role.
58   *****************************************************************************/
59   IS SELECT DISTINCT DECODE(fmu.menu_name,'JTF_CAL_ADMIN_ACCESS','JTF_CAL_FULL_ACCESS',FMU.MENU_NAME) Privilege
60      ,      fgs.instance_pk1_value   ResourceID
61      ,      jrt.group_name           ResourceName
62      FROM  fnd_grants                 fgs
63      ,     fnd_menus                  fmu
64      ,     fnd_objects                fos
65      ,     jtf_rs_groups_tl           jrt
66      WHERE fgs.object_id          = fos.object_id   -- grants joint to object
67      AND   fgs.menu_id            = fmu.menu_id     -- grants joint to menus
68      AND   fmu.MENU_NAME in ('JTF_CAL_ADMIN_ACCESS','JTF_CAL_FULL_ACCESS')
69      AND   fos.obj_name           = 'JTF_TASK_RESOURCE'
70      AND   fgs.grantee_key        = b_GranteeKey --'1000001366'
71      AND   fgs.grantee_type       = 'USER'
72      AND   fgs.start_date        <  SYSDATE
73      AND   (  fgs.end_date       >= SYSDATE
74            OR fgs.end_date IS NULL
75            )
76      AND   fgs.instance_pk2_value = ('RS_GROUP')
77      AND   jrt.group_id           = TO_NUMBER(fgs.instance_pk1_value)
78      AND   jrt.LANGUAGE           = USERENV('LANG');
79 
80 BEGIN
81   /*****************************************************************************
82   ** Get basic Resource Information for current FND_USER
83   *****************************************************************************/
84   IF ((p_ResourceID IS NULL) OR (p_ResourceType IS NULL))
85   THEN
86     Jtf_Cal_Utility_Pvt.GetResourceInfo( p_UserID       => p_userID
87                                         , x_ResourceID   => p_ResourceID
88                                         , x_ResourceType => p_ResourceType
89                                         , x_ResourceName => l_ResourceName
90                                         );
91   ELSE
92     l_ResourceName := Jtf_Cal_Utility_Pvt.GetResourceName( p_ResourceID
93                                                           , p_ResourceType
94                                                           );
95   END IF;
96 
97   /*****************************************************************************
98   ** Determine the GranteeKey
99   *****************************************************************************/
100   l_GranteeKey := TO_CHAR(p_ResourceID);
101 
102   /*****************************************************************************
103   ** There is no record in the GRANTS table for CALENDAR ACCESS to your own
104   ** personal calendar in order to simplify the logic on the client side we will
105   ** add a record to the list
106   *****************************************************************************/
107   x_calendarList(l_index).ResourceID   := p_resourceID;
108   x_calendarList(l_index).ResourceType := 'RS_EMPLOYEE';
109   x_calendarList(l_index).CalendarName := l_ResourceName;
110   x_calendarList(l_index).AccessLevel  := 'JTF_CAL_ADMIN_ACCESS';
111   l_index := l_index + 1;
112 
113   /*****************************************************************************
114   ** Get all the Personal Calendars the Calender User has access to.
115   *****************************************************************************/
116   FOR r_PersonalCalendar IN c_PersonalCalendars(l_GranteeKey)
117   LOOP <<PERSONAL_CALENDARS>>
118     x_calendarList(l_index).ResourceID   := r_PersonalCalendar.ResourceID;
119     x_calendarList(l_index).ResourceType := 'RS_EMPLOYEE';
120     x_calendarList(l_index).CalendarName := r_PersonalCalendar.ResourceName;
121     x_calendarList(l_index).AccessLevel  := r_PersonalCalendar.Privilege;
122     l_index := l_index + 1;
123   END LOOP PERSONAL_CALENDARS;
124 
125   /*****************************************************************************
126   ** Get all the Group Calendars the Calender User has access to.
127   *****************************************************************************/
128   FOR r_GroupCalendar IN c_GroupCalendars(l_GranteeKey)
129   LOOP <<GROUP_CALENDARS>>
130     x_calendarList(l_index).ResourceID   := r_GroupCalendar.ResourceID;
131     x_calendarList(l_index).ResourceType := 'RS_GROUP';
132     x_calendarList(l_index).CalendarName := r_GroupCalendar.ResourceName;
133     x_calendarList(l_index).AccessLevel  := r_GroupCalendar.Privilege;
134     l_index := l_index + 1;
135   END LOOP GROUP_CALENDARS;
136 
137 END GetCalendarList;
138 
139 PROCEDURE GetApptsAndTasks
140 ( p_LoggedOnRSID            IN  NUMBER
141 , p_LoggedOnRSType          IN  VARCHAR2
142 , p_QueryRSID            IN  NUMBER
143 , p_QueryRSType          IN  VARCHAR2
144 , p_QueryStartDate       IN  DATE
145 , p_QueryEndDate         IN  DATE
146 , p_QueryMode            IN  VARCHAR2
147 , p_CalSpanDaysProfile   IN  VARCHAR2
148 , p_GroupRSID            IN  VARCHAR2
149 , p_Color                IN  VARCHAR2
150 , p_prefix               IN  VARCHAR2
151 , p_pers_cal             IN  VARCHAR2
152 , x_index                IN OUT NOCOPY	BINARY_INTEGER
153 , x_DisplayItems         IN OUT NOCOPY	Jtf_Cal_Pvt.QueryOutTab
154 , x_Preferences          IN OUT NOCOPY	Jtf_Cal_Pvt.Preference
155 ) IS
156 
157   l_TempStartDate       DATE;
158   l_TempEndDate         DATE;
159   l_TempItemDisplayType  NUMBER;
160   l_ItemDisplayType      NUMBER;
161 
162   --Added by jawang on 11/18/2002 to fix the NOCOPY issue
163   l_StartDate 		DATE;
164   l_EndDate 		DATE;
165 
166   CURSOR c_Tasks
167   /*****************************************************************************
168   ** This cursor will only return Tasks/Appointments that need to be displayed
169   ** in the page or is needed to derive that information
170   *****************************************************************************/
171   ( b_ResourceID   IN NUMBER
172   , b_ResourceType IN VARCHAR2
173   , b_StartDate    IN DATE  -- start of query period
174   , b_EndDate      IN DATE  -- end of query period
175   )IS SELECT /*+ INDEX(jtsb JTF_TASK_STATUSES_B_U1) */
176              jtb.task_id                      TaskId
177       ,      jtb.source_object_type_code      SourceObjectTypeCode
178       ,      jtb.source_object_id             SourceId
179       ,      jtb.customer_id                  CustomerId
180       ,      jtt.task_name                    ItemName
181       ,      jtb.calendar_start_date          StartDate
182       ,      jtb.calendar_end_date            EndDate
183       ,      jtb.timezone_id                  TimezoneID
184       ,      jtb.duration                     Duration    -- always in minutes
185       ,      jtb.private_flag                 PrivateFlag -- needed to determin access level
186       ,      DECODE(jta.assignment_status_id ,18, DECODE(jtb.source_object_type_code ,'APPOINTMENT',1,0),0)
187                              InviteIndicator
188       ,      DECODE(jtb.recurrence_rule_id
189                    ,NULL,0
190                    ,1
191                    )          RepeatIndicator
192       ,      DECODE(jtb.source_object_type_code ,'APPOINTMENT', x_preferences.ApptColor, x_preferences.TaskColor)
193                              ItemColor
194       ,      DECODE(jtb.source_object_type_code ,'APPOINTMENT', x_preferences.ApptPrefix, x_preferences.TaskPrefix)
195                              ItemPrefix
196       ,      Jtf_Cal_Utility_Pvt.GetItemURL               -- can't join URL is dynamic..
197              ( jtb.source_object_id
198              , jtb.source_object_type_code)   URL
199       ,      jta.assignee_role                AssigneeRole
200       ,      jtb.task_priority_id             PriorityID    -- Needed for todos
201       ,      jta.category_id                  CategoryID    -- Needed for todos
202       ,      jtb.object_version_number        AssignmentOVN -- Needed to update todos
203       ,      jta.object_version_number        TaskOVN       -- Needed to update todos
204       FROM jtf_task_all_assignments   jta
205       ,    jtf_tasks_b            jtb
206       ,    jtf_tasks_tl           jtt
207       ,    jtf_task_statuses_b    jtsb
208       WHERE jta.resource_id          = b_ResourceID        -- 101272224
209       AND   jta.resource_type_code   = b_ResourceType      -- 'RS_EMPLOYEE'
210       AND   jta.task_id              = jtb.task_id         -- join to tasks_b
211       AND   jtb.task_status_id       = jtsb.task_status_id -- join to to task_status_b
212       AND   jtb.task_id              = jtt.task_id         -- join to tasks_tl
213       AND   jtt.LANGUAGE             = USERENV('LANG')     -- join to tasks_tl
214       AND   jta.show_on_calendar     = 'Y'
215       AND   jta.assignment_status_id <> 4 -- using status rejected for declined
216       AND   NVL(jtsb.closed_flag,'N')<> 'Y'
217       AND   (   jtb.calendar_start_date <= b_EndDate
218             OR  jtb.calendar_start_date IS NULL
219             )
220       AND   (   jtb.calendar_end_date   >=  b_StartDate
221             OR  jtb.calendar_end_date IS NULL
222             )
223       AND jtb.entity <> 'BOOKING'
224       AND jtb.source_object_type_code <> 'EXTERNAL APPOINTMENT'
225       ;
226       --Added by MPADHIAR for Bug#5037648
227       TYPE tbl_PersonalTask IS TABLE OF c_Tasks%ROWTYPE INDEX BY BINARY_INTEGER;
228       l_tab_PersonalTask   tbl_PersonalTask;
229       l_index BINARY_INTEGER;
230       --Added by MPADHIAR for Bug#5037648 --Ends here
231 
232 BEGIN
233 
234   IF (c_Tasks%ISOPEN)
235   THEN
236     CLOSE c_Tasks; -- Make sure the cursor is closed
237   END IF;
238    --Added by MPADHIAR for Bug#5037648
239   OPEN c_Tasks( p_QueryRSID
240                                , p_QueryRSType
241                                , p_QueryStartDate - 1 -- allow for max timezone correction
242                                , p_QueryEndDate   + 1 -- allow for max timezone correction
243                                );
244   LOOP <<ALL_PERSONAL_TASKS>>
245 	  FETCH c_Tasks BULK COLLECT INTO l_tab_PersonalTask LIMIT 500;
246 	  FOR l_index IN 1 .. l_tab_PersonalTask.COUNT LOOP <<PERSONAL_TASKS>>
247 	  --Added by MPADHIAR for Bug#5037648 --Ends here
248           /***************************************************************************
249           ** We will have to adjust the Start/End Date for the users timezone
250           ***************************************************************************/
251            --Here onwards r_PersonalTask is replaced with l_tab_PersonalTask(l_index)
252 	  --for Bug#5037648 by MPADHIAR
253           l_TempItemDisplayType := Jtf_Cal_Utility_Pvt.GetItemType
254                                  ( p_SourceCode      => l_tab_PersonalTask(l_index).SourceObjectTypeCode
255                                  , p_PeriodStartDate => p_QueryStartDate
256                                  , p_PeriodEndDate   => p_QueryEndDate
257                                  , p_StartDate       => l_tab_PersonalTask(l_index).StartDate
258                                  , p_EndDate         => l_tab_PersonalTask(l_index).EndDate
259                                  , p_CalSpanDaysProfile => p_CalSpanDaysProfile
260                                  );
261 
262           --Added by jawang on 11/18/2002 to fix the NOCOPY issue
263           l_StartDate  := l_tab_PersonalTask(l_index).StartDate;
264           l_EndDate  := l_tab_PersonalTask(l_index).EndDate;
265 
266           IF  l_TempItemDisplayType <> 3 THEN
267 
268             Jtf_Cal_Utility_Pvt.AdjustForTimezone
269                              ( p_source_tz_id    =>  l_tab_PersonalTask(l_index).TimezoneID--213--
270                              , p_dest_tz_id      =>  x_Preferences.Timezone
271                              , p_source_day_time =>  l_StartDate
272                              , x_dest_day_time   =>  l_tab_PersonalTask(l_index).Startdate
273                              );
274 
275             Jtf_Cal_Utility_Pvt.AdjustForTimezone
276                              ( p_source_tz_id    =>  l_tab_PersonalTask(l_index).TimezoneID--213--
277                              , p_dest_tz_id      =>  x_Preferences.Timezone
278                              -- Modified by jawang on 11/21/02 to fix NOCOPY issue
279                              , p_source_day_time =>  l_EndDate
280                              , x_dest_day_time   =>  l_tab_PersonalTask(l_index).Enddate
281                              );
282           END IF;
283 
284 
285               IF ((p_QueryMode = 4) -- All tasks
286              OR ((p_QueryMode <> 4)
287                 AND (l_TempItemDisplayType <> 2))) -- Filter tasks item type 2
288               THEN
289 
290           --MultiDay span case
291               l_TempStartDate   := l_tab_PersonalTask(l_index).StartDate;
292               l_TempEndDate     := l_tab_PersonalTask(l_index).EndDate;
293           l_ItemDisplayType := l_TempItemDisplayType;
294               IF (l_TempItemDisplayType = 5)
295               THEN
296                  l_TempEndDate := TRUNC(l_TempStartDate) + 1 - 1/(24*60*60);
297                  l_ItemDisplayType := 1;
298               END IF;
299 
300 
301               WHILE (((l_TempEndDate <= l_tab_PersonalTask(l_index).EndDate) AND
302                         (l_TempStartDate <= l_tab_PersonalTask(l_index).EndDate)) OR
303                         (l_TempStartDate IS NULL) OR (l_TempEndDate IS NULL))
304               LOOP
305                       /***************************************************************************
306                       ** Now that the StartDate and EndDate are corrected we need to check
307                       ** whether we want to display them
308                       ***************************************************************************/
309                       IF  (     (  l_TempStartDate <= p_QueryEndDate
310                                         OR l_TempStartDate IS NULL
311                                         )
312                               AND   (  l_TempEndDate  >=  p_QueryStartDate
313                                         OR l_TempEndDate IS NULL
314                                         )
315                               )
316                       THEN
317                               /*************************************************************************
318                               ** Store the task information in a PL/SQL table.
319                               *************************************************************************/
320                               x_index := x_index + 1;
321                               /***********************************************************************
322                               ** These items should be displayed on the Calendar or Memo, Todolist
323                               ** items are filtered unless query mode is combi
324                               ***********************************************************************/
325                               x_DisplayItems(x_index).ItemDisplayType := l_ItemDisplayType;
326                               x_DisplayItems(x_index).ItemSourceID    := l_tab_PersonalTask(l_index).TaskId;
327                   --Rada, enh # 2658165
328                   IF NVL(x_preferences.TaskCustomerSource, 'NO') = 'YES' THEN
329                     IF ( l_tab_PersonalTask(l_index).SourceObjectTypeCode <> 'APPOINTMENT'
330                       AND  l_tab_PersonalTask(l_index).SourceObjectTypeCode <> 'TASK' ) THEN
331                       x_DisplayItems(x_index).SourceID    := l_tab_PersonalTask(l_index).SourceId;
332                                   x_DisplayItems(x_index).SourceObjectTypeCode  := l_tab_PersonalTask(l_index).SourceObjectTypeCode;
333                     END IF;
334 
335                     x_DisplayItems(x_index).CustomerId := l_tab_PersonalTask(l_index).CustomerId;
336                   END IF;
337                   -- Rada, enh # 2127725, do not apply color and prefix on group cal items and invitations
338                   IF p_pers_cal = 'Y' OR l_tab_PersonalTask(l_index).InviteIndicator = 1 OR l_tab_PersonalTask(l_index).ItemPrefix = ' ' THEN
339                        x_DisplayItems(x_index).ItemName	:= p_prefix||l_tab_PersonalTask(l_index).ItemName;
340                   ELSE
341                        x_DisplayItems(x_index).ItemName   := l_tab_PersonalTask(l_index).ItemPrefix || l_tab_PersonalTask(l_index).ItemName;
342                   END IF;
343                               x_DisplayItems(x_index).AccessLevel := Jtf_Cal_Utility_Pvt.GetAccessLevel
344                                                                                                                  (   l_tab_PersonalTask(l_index).PrivateFlag
345                                                                                                                          , l_tab_PersonalTask(l_index).AssigneeRole
346                                                                                                                          , p_LoggedOnRSID
347                                                                                                                          , p_LoggedOnRSType
348                                                                                                                          , p_QueryRSID
349                                                                                                                          , p_QueryRSType
350                                                                  , l_tab_PersonalTask(l_index).SourceObjectTypeCode
351                                                                                                                  );
352                               x_DisplayItems(x_index).InviteIndicator := l_tab_PersonalTask(l_index).InviteIndicator;
353                               x_DisplayItems(x_index).RepeatIndicator := l_tab_PersonalTask(l_index).RepeatIndicator;
354                               x_DisplayItems(x_index).StartDate       := l_TempStartDate;
355                               x_DisplayItems(x_index).EndDate         := l_TempEndDate;
356                               x_DisplayItems(x_index).URL             := l_tab_PersonalTask(l_index).URL;
357 
358                   -- Rada, enh # 2127725, do not apply color and prefix on group cal items and invitations
359                   IF p_pers_cal = 'Y' THEN
360                     x_DisplayItems(x_index).Color := p_Color;
361                   ELSE
362                     x_DisplayItems(x_index).Color   := l_tab_PersonalTask(l_index).ItemColor;
363                   END IF;
364                               x_DisplayItems(x_index).GroupRSID := p_GroupRSID;
365 
366                               /***********************************************************************
367                               ** These are populated conditionally, making sure they are NULL
368                               ***********************************************************************/
369                               x_DisplayItems(x_index).PriorityID      := NULL;
370                               x_DisplayItems(x_index).PriorityName    := NULL;
371                               x_DisplayItems(x_index).CategoryID      := NULL;
372                               x_DisplayItems(x_index).CategoryDesc    := NULL;
373                               x_DisplayItems(x_index).NoteFlag        := NULL;
374                               x_DisplayItems(x_index).TaskOVN         := NULL;
375                               x_DisplayItems(x_index).AssignmentOVN   := NULL;
376 
377                               /*******************************************************************
378                               ** This is a task that should show in the todo list, therefore we
379                               ** need some extra information
380                               *******************************************************************/
381                               IF ((l_ItemDisplayType = 2) -- Display as Tasks only
382                                       AND (p_QueryMode = 4)) -- Combi view
383                               THEN
384                                       x_DisplayItems(x_index).PriorityID      := l_tab_PersonalTask(l_index).PriorityID;
385                                       x_DisplayItems(x_index).PriorityName    := Jtf_Cal_Utility_Pvt.GetTaskPriority
386                                                                                                                         ( l_tab_PersonalTask(l_index).PriorityID
387                                                                                                                         );
388                                       x_DisplayItems(x_index).CategoryID      := l_tab_PersonalTask(l_index).CategoryID;
389                                       x_DisplayItems(x_index).CategoryDesc    := Jtf_Cal_Utility_Pvt.GetCategoryName
390                                                                                                                          ( l_tab_PersonalTask(l_index).CategoryID
391                                                                                                                          );
392                                       x_DisplayItems(x_index).NoteFlag        := Jtf_Cal_Utility_Pvt.TaskHasNotes
393                                                                                                                          ( l_tab_PersonalTask(l_index).TaskId
394                                                                                                                          );
395                                       x_DisplayItems(x_index).TaskOVN         := l_tab_PersonalTask(l_index).TaskOVN;
396                                       x_DisplayItems(x_index).AssignmentOVN   := l_tab_PersonalTask(l_index).AssignmentOVN;
397                               END IF;
398 
399                               /***********************************************************************
400                               ** We may have to adjust the display range in the preferences if the
401                               ** tasks/appointments to be displayed fall outside the range.
402                               *******************************************************************/
403                               IF (l_ItemDisplayType IN (1,4))
404                               THEN
405                                 Jtf_Cal_Utility_Pvt.AdjustMinMaxTime( p_StartDate   => l_TempStartDate
406                                                                                                         , p_EndDate     => l_TempEndDate
407                                                                                                         , p_increment   => x_Preferences.ApptIncrement
408                                                                                                         , x_min_time    => x_Preferences.MinStartTime
409                                                                                                         , x_max_time    => x_Preferences.MaxEndTime
410                                                                                                         );
411                               END IF;
412                       END IF;
413                       -- Increment the dates.
414                       IF (l_TempItemDisplayType = 5)
415                       THEN
416                          l_TempStartDate := TRUNC(l_TempStartDate) + 1;
417                          l_TempEndDate := TRUNC(l_TempStartDate) + 1 - 1/(24*60*60);
418                          IF (l_TempEndDate > l_tab_PersonalTask(l_index).EndDate)
419                          THEN
420                                 l_TempEndDate := l_tab_PersonalTask(l_index).EndDate;
421                          END IF;
422                          IF (l_TempStartDate >= l_tab_PersonalTask(l_index).EndDate)
423                          THEN
424                                 EXIT;
425                          END IF;
426                       ELSE
427                          EXIT;
428                       END IF;
429               END LOOP;
430           END IF; --Filter tasks 2
431 
432         END LOOP PERSONAL_TASKS;
433 --Added by MPADHIAR for Bug#5037648
434         EXIT WHEN C_Tasks%NOTFOUND;
435   END LOOP ALL_PERSONAL_TASKS;
436   CLOSE c_Tasks;
437 --Added by MPADHIAR for Bug#5037648 -- Ends here
438 
439 END GetApptsAndTasks;
440 
441 PROCEDURE GetItems
442 /*******************************************************************************
443 ** This procedure will return Marketing Calendar Items
444 *******************************************************************************/
445 ( p_LoggedOnRSID            IN  NUMBER
446 , p_LoggedOnRSType          IN  VARCHAR2
447 , p_QueryRSID            IN  NUMBER
448 , p_QueryRSType          IN  VARCHAR2
449 , p_QueryStartDate       IN  DATE
450 , p_QueryEndDate         IN  DATE
451 , p_QueryMode            IN  VARCHAR2
452 , p_CalSpanDaysProfile   IN  VARCHAR2
453 , p_GroupRSID            IN  VARCHAR2
454 , p_Color                IN  VARCHAR2
455 , p_prefix               IN  VARCHAR2
456 , x_index                IN OUT NOCOPY	BINARY_INTEGER
457 , x_DisplayItems         IN OUT NOCOPY	Jtf_Cal_Pvt.QueryOutTab
458 , x_Preferences          IN OUT NOCOPY	Jtf_Cal_Pvt.Preference
459 ) IS
460 
461 CURSOR c_Items
462   /*****************************************************************************
463   ** This Cursor will fetch all Calendar Items related to a Resource
464   *****************************************************************************/
465   ( b_ResourceID   IN NUMBER
466   , b_ResourceType IN VARCHAR2
467   , b_StartDate    IN DATE
468   , b_EndDate      IN DATE
469   )IS SELECT DISTINCT jtb.source_id          ItemSourceID
470       --,      jtb.source_code        ItemSourceCode
471       , jtf_cal_items_pvt.GetName(jtb.SOURCE_CODE, jtb.SOURCE_ID) ItemName
472       ,      jtb.source_code        SourceCode
473       ,      jtb.source_id          SourceID
474       ,      jtb.start_date         StartDate
475       ,      jtb.end_date           EndDate
476       ,      jtb.timezone_id        TimezoneID
477       ,      jtb.url                URL
478       ,      jtf_cal_items_pvt.GetUrlParams(jtb.SOURCE_CODE, jtb.SOURCE_ID) URLParams
479       FROM  jtf_cal_items_b   jtb
480       WHERE(   jtb.start_date <= b_EndDate
481             )
482       AND   (   jtb.end_date   >=  b_StartDate
483             )
484       AND jtb.resource_type = 'RS_GROUP'
485       AND jtb.resource_id IN --select groups that user is member of
486       (SELECT mem.group_id
487       FROM
488          jtf_rs_group_members mem,
489          jtf_rs_group_usages  rgu
490       WHERE mem.resource_id = b_ResourceID
491         AND nvl(mem.delete_flag, 'N') <> 'Y'
492         AND   rgu.group_id = mem.group_id
493         AND   rgu.usage =  'CALENDAR_ITEMS')
494     UNION -- individual items
495      SELECT jtb.source_id          ItemSourceID
496       --,      jtb.source_code        ItemSourceCode
497       , jtf_cal_items_pvt.GetName(jtb.SOURCE_CODE, jtb.SOURCE_ID) ItemName
498       ,      jtb.source_code        SourceCode
499       ,      jtb.source_id          SourceID
500       ,      jtb.start_date         StartDate
501       ,      jtb.end_date           EndDate
502       ,      jtb.timezone_id        TimezoneID
503       ,      jtb.url                URL
504       ,      jtf_cal_items_pvt.GetUrlParams(jtb.SOURCE_CODE, jtb.SOURCE_ID) URLParams
505       FROM  jtf_cal_items_b   jtb
506        WHERE jtb.resource_id   = b_ResourceID
507        AND   jtb.resource_type = 'RS_EMPLOYEE'
508        AND  (   jtb.start_date <= b_EndDate
509             )
510        AND  (   jtb.end_date   >=  b_StartDate
511             )
512       ;
513   l_TempStartDate       DATE;
514   l_TempEndDate         DATE;
515   l_TempItemDisplayType  NUMBER;
516   l_ItemDisplayType      NUMBER;
517   --Added by jawang on 11/21/2002 to fix the NOCOPY issue
518   l_StartDate            DATE;
519   l_EndDate              DATE;
520   l_item_name            VARCHAR2(2000);
521 
522 BEGIN
523   /*****************************************************************************
524   ** Now we need to get all the Calendar Items for this Employee Resource.
525   *****************************************************************************/
526   IF (c_Items%ISOPEN)
527   THEN
528     CLOSE c_Items; -- Make sure the cursor is closed
529   END IF;
530   FOR r_PersonalItem IN c_Items( p_QueryRSID
531                                , p_QueryRSType
532                                , p_QueryStartDate - 1 -- allow for max timezone adjustment
533                                , p_QueryEndDate   + 1 -- allow for max timezone adjustment
534                                )
535 
536 
537   LOOP <<PERSONAL_ITEMS>>
538     /***************************************************************************
539     ** We will have to adjust the Start/End Date for the users timezone
540     ***************************************************************************/
541     --Added by jawang on 11/21/2002 to fix the NOCOPY issue
542     l_StartDate := r_PersonalItem .Startdate;
543     l_EndDate := r_PersonalItem .Enddate;
544 
545     Jtf_Cal_Utility_Pvt.AdjustForTimezone
546                        ( p_source_tz_id    =>  r_PersonalItem .TimezoneID
547                        , p_dest_tz_id      =>  x_Preferences.Timezone
548                        , p_source_day_time =>  l_StartDate
549                        , x_dest_day_time   =>  r_PersonalItem .Startdate
550                        );
551 
552     Jtf_Cal_Utility_Pvt.AdjustForTimezone
553                        ( p_source_tz_id    =>  r_PersonalItem .TimezoneID
554                        , p_dest_tz_id      =>  x_Preferences.Timezone
555                        , p_source_day_time =>  l_EndDate
556                        , x_dest_day_time   =>  r_PersonalItem .Enddate
557                        );
558 
559     l_TempItemDisplayType := Jtf_Cal_Utility_Pvt.GetItemType
560                            ( p_SourceCode      => 'CALENDARITEM'
561                            , p_PeriodStartDate => p_QueryStartDate
562                            , p_PeriodEndDate   => p_QueryEndDate
563                            , p_StartDate       => r_PersonalItem.StartDate
564                            , p_EndDate         => r_PersonalItem.EndDate
565                            , p_CalSpanDaysProfile => p_CalSpanDaysProfile
566                            );
567 
568 
569 	IF ((p_QueryMode = 4)
570        OR ((p_QueryMode <> 4)
571           AND (l_TempItemDisplayType <> 2)))
572 	THEN
573 
574 --MultiDay span case
575 	l_TempStartDate   := r_PersonalItem.StartDate;
576 	l_TempEndDate     := r_PersonalItem.EndDate;
577     l_ItemDisplayType := l_TempItemDisplayType;
578 	IF (l_TempItemDisplayType = 5)
579 	THEN
580 	   l_TempEndDate := TRUNC(l_TempStartDate) + 1 - 1/(24*60*60);
581 	   l_ItemDisplayType := 1;
582 	END IF;
583 
584 	WHILE (((l_TempEndDate <= r_PersonalItem.EndDate) AND
585 		  (l_TempStartDate <= r_PersonalItem.EndDate)) OR
586           (l_TempStartDate IS NULL) OR (l_TempEndDate IS NULL))
587 	LOOP
588 	   /***************************************************************************
589 		** Now that the StartDate and EndDate are corrected we need to check whether
590 		** we want to display them
591 		***************************************************************************/
592 		IF  (     NVL(l_TempStartDate,TRUNC(SYSDATE)) <= p_QueryEndDate
593 			AND   NVL(l_TempEndDate,TRUNC(SYSDATE))   >=  p_QueryStartDate
594 			)
595 		THEN
596 		  x_index := x_index + 1;
597 
598 		  x_DisplayItems(x_index).ItemDisplayType   := l_ItemDisplayType;
599 		  x_DisplayItems(x_index).ItemSourceID      := r_PersonalItem.ItemSourceID;
600           -- Trim names longer than 80 (77 + ...)
601           l_item_name :=  p_prefix || r_PersonalItem.ItemName;
602           IF (length( l_item_name) > 77) THEN
603                  l_item_name := SUBSTR(l_item_name, 1, 77) || '...';
604           END IF;
605 		  x_DisplayItems(x_index).ItemName	        := l_item_name;
606 		  x_DisplayItems(x_index).AccessLevel       := 1;
607 		  x_DisplayItems(x_index).InviteIndicator   := 0;
608 		  x_DisplayItems(x_index).RepeatIndicator   := 0;
609 		  x_DisplayItems(x_index).StartDate         := l_TempStartDate;
610 		  x_DisplayItems(x_index).EndDate           := l_TempEndDate;
611 		  x_DisplayItems(x_index).URL               := r_PersonalItem.URL;
612           x_DisplayItems(x_index).URLParamList        := r_PersonalItem.URLParams;
613 		  x_DisplayItems(x_index).Color	            := p_Color;
614 		  x_DisplayItems(x_index).GroupRSID         := p_GroupRSID;
615 
616 		  /*******************************************************************
617 		  ** These are populated conditionally, making sure they are NULL
618 		  *******************************************************************/
619 		  x_DisplayItems(x_index).PriorityID      := NULL;
620 		  x_DisplayItems(x_index).PriorityName    := NULL;
621 		  x_DisplayItems(x_index).CategoryID      := NULL;
622 		  x_DisplayItems(x_index).CategoryDesc    := NULL;
623 		  x_DisplayItems(x_index).NoteFlag        := NULL;
624 		  x_DisplayItems(x_index).TaskOVN         := NULL;
625 		  x_DisplayItems(x_index).AssignmentOVN   := NULL;
626 
627 		  /*************************************************************************
628 		  ** We may have to adjust the display range in the preferences if the items
629 		  ** to be displayed fall outside the range.
630 		  *********************************************************************/
631 		  IF (l_ItemDisplayType = 1)
632 		  THEN
633 			Jtf_Cal_Utility_Pvt.AdjustMinMaxTime( p_StartDate   => l_TempStartDate
634 												, p_EndDate     => l_TempEndDate
635 												, p_increment   => x_Preferences.ApptIncrement
636 												, x_min_time    => x_Preferences.MinStartTime
637 												, x_max_time    => x_Preferences.MaxEndTime
638 												);
639 		  END IF;
640 		END IF;
641 
642 		-- Increment the dates.
643 		IF (l_TempItemDisplayType = 5)
644 		THEN
645 		   l_TempStartDate := TRUNC(l_TempStartDate) + 1;
646 		   l_TempEndDate := TRUNC(l_TempStartDate) + 1 - 1/(24*60*60);
647 		   IF (l_TempEndDate > r_PersonalItem.EndDate)
648 		   THEN
649 			  l_TempEndDate := r_PersonalItem.EndDate;
650 		   END IF;
651 		   IF (l_TempStartDate >= r_PersonalItem.EndDate)
652 		   THEN
653 			  EXIT;
654 		   END IF;
655 		ELSE
656 		   EXIT;
657 	 	END IF;
658 	 END LOOP;
659  END IF;
660  END LOOP PERSONAL_ITEMS;
661 END GetItems;
662 
663 
664 PROCEDURE GetView
665 /*******************************************************************************
666 ** This procedure will return all task information needed to
667 ** display the daily Calendar page
668 *******************************************************************************/
669 ( p_api_version            IN     NUMBER
670 , p_init_msg_list          IN     VARCHAR2
671 , p_validation_level       IN     NUMBER
672 , x_return_status          OUT    NOCOPY	VARCHAR2
673 , x_msg_count              OUT    NOCOPY	NUMBER
674 , x_msg_data               OUT    NOCOPY	VARCHAR2
675 , p_input                  IN     Jtf_Cal_Pvt.QueryIn
676 , x_DisplayItems           OUT    NOCOPY	Jtf_Cal_Pvt.QueryOutTab
677 , x_Preferences            OUT    NOCOPY	Jtf_Cal_Pvt.Preference
678 )IS
679   l_LoggedOnRSID         NUMBER;       -- ResourceID of the logged on user
680   l_LoggedOnRSType       VARCHAR2(30); -- ResourceType of the logged on user
681   l_QueryRSID            NUMBER;       -- ResourceID of the logged on user
682   l_QueryRSType          VARCHAR2(30); -- ResourceType of the logged on user
683   l_QueryRSName          VARCHAR2(360);-- Resource Name of the logged on user
684   l_LoggedOnToday        DATE;         -- Today of logged on user
685   l_QueryDate            DATE;         -- Query Date of logged on user
686   l_QueryStartDate       DATE;         -- Start of the query period
687   l_QueryEndDate         DATE;         -- End of the query period
688 
689   l_WeekTimePrefTbl      WeekTimePrefTblType;
690   l_CalSpanDaysProfile   VARCHAR2(10);
691   l_MinDayTime           NUMBER;
692   l_MaxDayTime           NUMBER;
693   l_WeekStartDay         NUMBER;
694   l_WeekEndDay           NUMBER;
695   l_QueryDays            NUMBER;
696   l_DayNumber            NUMBER;
697   l_offset               NUMBER;
698   l_SundayDate           DATE;
699   l_SaturdayDate         DATE;
700 
701   l_return_status        VARCHAR2(1);
702   l_msg_count            NUMBER;
703   l_msg_data             VARCHAR2(2000);
704   l_index                BINARY_INTEGER:=-1;
705   CURSOR c_Groups
706   /*****************************************************************************
707   ** This Cursor will fetch all Groups Calendars the Calendar User is
708   ** subscribed to
709   *****************************************************************************/
710   ( b_ResourceID  IN NUMBER
711   )IS SELECT DISTINCT TO_NUMBER(fgs.instance_pk1_value) GroupID
712       ,           Jtf_Cal_Utility_Pvt.GetGroupColor
713                                      ( b_ResourceID
714                                      , 'RS_EMPLOYEE'
715                                      , TO_NUMBER(fgs.instance_pk1_value)
716                                      )                  Color
717       ,           Jtf_Cal_Utility_Pvt.GetGroupPrefix
718                                      ( b_ResourceID
719                                      , 'RS_EMPLOYEE'
720                                      , TO_NUMBER(fgs.instance_pk1_value)
721                                      )                  Prefix
722       FROM  fnd_grants               fgs
723       ,     fnd_objects              fos
724       ,     jtf_rs_group_usages      rgu
725       WHERE fgs.object_id          = fos.object_id   -- grants joint to object
726       AND   fos.obj_name           = 'JTF_TASK_RESOURCE'
727       AND   fgs.grantee_key        = TO_CHAR(b_ResourceID)
728       AND   fgs.start_date        <  SYSDATE
729       AND   (   (fgs.end_date     >= SYSDATE)
730             OR  (fgs.end_date     IS NULL)
731             )
732       AND   fgs.instance_pk2_value = 'RS_GROUP'
733       AND   rgu.GROUP_ID = TO_NUMBER(fgs.instance_pk1_value)
734 	   AND   rgu.USAGE = 'GROUP_CALENDAR';
735 
736 BEGIN
737   /*****************************************************************************
738   ** Make sure I have all the Resource Information needed for the logged
739   ** on user
740   *****************************************************************************/
741   IF (  (p_input.LoggedOnRSID IS NULL)
742      OR (p_input.LoggedOnRSType IS NULL)
743      )
744   THEN
745     /***************************************************************************
746     ** If I didn't get it, try to look it up with the UserID
747     ***************************************************************************/
748     IF(p_input.UserID IS NULL)
749     THEN
750       NULL; --error no user information provided, this is not supposed to happen...
751     ELSE
752       Jtf_Cal_Utility_Pvt.GetResourceInfo( p_UserID       => p_input.UserID
753                                          , x_ResourceID   => l_LoggedOnRSID
754                                          , x_ResourceType => l_LoggedOnRSType
755                                          );
756     END IF;
757 
758   ELSE
759     /***************************************************************************
760     ** If I did get it
761     ***************************************************************************/
762     l_LoggedOnRSID    := p_input.LoggedOnRSID;
763     l_LoggedOnRSType  := p_input.LoggedOnRSType;
764   END IF;
765 
766   /*****************************************************************************
767   ** Determine the resource id/type for which the data should be fetched
768   *****************************************************************************/
769   IF ((p_input.QueryRSID IS NULL) OR (p_input.QueryRSType IS NULL))
770   THEN
771     l_QueryRSID := l_LoggedOnRSID;
772     l_QueryRSType := l_LoggedOnRSType;
773   ELSE
774     l_QueryRSID := p_input.QueryRSID;
775     l_QueryRSType := p_input.QueryRSType;
776   END IF;
777 
778   /*****************************************************************************
779   ** Need to get all the preferences for the current resource
780   *****************************************************************************/
781   Jtf_Cal_Utility_Pvt.GetPreferences( p_LoggedOnRSID   => l_LoggedOnRSID
782                                     , p_LoggedOnRSType => l_LoggedOnRSType
783                                     , p_QueryRSID => l_QueryRSID
784                                     , p_QueryRSType => l_QueryRSType
785                                     , x_Preferences  => x_Preferences
786                                     , x_WeekTimePrefTbl => l_WeekTimePrefTbl
787                                     , x_CalSpanDaysProfile => l_CalSpanDaysProfile
788                                     );
789 
790   /***************************************************************************
791   ** What is today for the logged on user
792   ***************************************************************************/
793   Hz_Timezone_Pub.Get_Time( p_api_version     => 1.0
794                             , p_init_msg_list   => Fnd_Api.G_FALSE
795                             , p_source_tz_id    => TO_NUMBER(NVL(Fnd_Profile.Value('SERVER_TIMEZONE_ID'),'4'))
796                             , p_dest_tz_id      => x_Preferences.Timezone
797                             , p_source_day_time => SYSDATE -- database sysdate
798                             , x_dest_day_time   => l_LoggedOnToday
799                             , x_return_status   => l_return_status
800                             , x_msg_count       => l_msg_count
801                             , x_msg_data        => l_msg_data
802                             );
803 
804   /*****************************************************************************
805   ** Set the Current Time for the Resource
806   *****************************************************************************/
807   x_Preferences.CurrentTime := l_LoggedOnToday;
808 
809   /****************************************************************************
810   ** If p_input.StartDate IS NULL I have to figure out what the current day
811   ****************************************************************************/
812   IF (p_Input.StartDate IS NULL)
813   THEN
814     l_QueryDate := l_LoggedOnToday;
815   ELSE
816     l_QueryDate := p_Input.StartDate;
817   END IF;
818 
819   -- get the name for sunday from a known date
820   l_SundayDate := TO_DATE('1995/01/01','yyyy/mm/dd');
821   l_SaturdayDate := l_SundayDate - 1;
822 
823   /*****************************************************************************
824   ** Depending on the QueryMode we have to determine the QueryStartDate and the
825   ** QueryEndDate
826   ** - 1 = Daily view
827   ** - 2 = Weekly view
828   ** - 3 = Monthly view
829   ** - 4 = Combi view (daily + todo list)
830   *****************************************************************************/
831   IF (p_Input.QueryMode IN (1,4))
832   THEN
833     /***************************************************************************
834     ** Daily is easy..
835     ***************************************************************************/
836     l_QueryStartDate := TRUNC(l_QueryDate);                      -- today 00:00:00
837     l_QueryEndDate   := (TRUNC(l_QueryDate) + 1) - (1/24/60/60); -- today 23:59:59
838     l_QueryDays      := 1;
839   ELSIF (p_Input.QueryMode = 2)
840   THEN
841     /***************************************************************************
842     ** Weekly is not easy.. Get the start and end of the week for the logged
843     ** on user
844     ***************************************************************************/
845     l_WeekStartDay := x_Preferences.WeekStart;
846     l_WeekEndDay   := x_Preferences.WeekEnd;
847 
848     /***************************************************************************
849     ** Calculate the number of days to be queried
850     ***************************************************************************/
851     IF (l_WeekEndDay >= l_WeekStartDay)
852     THEN
853       l_QueryDays := l_WeekEndDay - l_WeekStartDay + 1;
854     ELSE
855       l_QueryDays := 7 - (l_WeekStartDay - l_WeekEndDay) + 1;
856     END IF;
857 
858     /***************************************************************************
859     ** Now we need to get the 'day' for Query Date
860     ***************************************************************************/
861     -- get the day number of the LoggedOnToday
862     l_DayNumber := MOD((TRUNC(l_QueryDate) - l_SundayDate),7);
863 
864     IF (l_DayNumber>=0)
865     THEN
866        l_DayNumber := 1 + l_DayNumber;
867     ELSE
868        l_DayNumber := 1 - l_DayNumber;
869     END IF;
870     -- If for some reason l_DayNumber is not in 1-7 range then reset it.
871     IF ((l_DayNumber<1) OR (l_DayNumber>7))
872     THEN
873        l_DayNumber := l_WeekStartDay;
874     END IF;
875 
876     /***************************************************************************
877     ** Calculate the offset to the begining of the week
878     ***************************************************************************/
879     IF (
880         (  (l_WeekEndDay < l_WeekStartDay) AND
881            (l_DayNumber < l_WeekStartDay) AND (l_DayNumber > l_WeekEndDay)
882         ) OR
883         (  (l_WeekEndDay > l_WeekStartDay) AND
884           (
885            (l_DayNumber > l_WeekStartDay) AND (l_DayNumber > l_WeekEndDay)
886            OR (l_DayNumber < l_WeekStartDay) AND (l_DayNumber < l_WeekEndDay)
887           )
888         )
889        )
890     THEN
891       /*************************************************************************
892       ** The p_Input.StartDate lies outside the work week of the user
893       *************************************************************************/
894       IF (l_DayNumber > l_WeekStartDay)
895       THEN
896         /***********************************************************************
897         ** Get the next work week
898         ***********************************************************************/
899         l_offset := 7 - (l_DayNumber - l_WeekStartDay);
900       ELSE
901         /***********************************************************************
902         ** Get the next work week
903         ***********************************************************************/
904         l_offset := l_WeekStartDay - l_DayNumber;
905       END IF;
906     ELSE
907       /*************************************************************************
908       ** The p_Input.StartDate lies within the work week of the user
909       *************************************************************************/
910       IF (l_WeekStartDay <= l_DayNumber)
911       THEN
912         /***********************************************************************
913         ** Go back to the beginning of the work week
914         ***********************************************************************/
915         l_offset := -1*(l_DayNumber - l_WeekStartDay);
916       ELSE
917         /***********************************************************************
918         ** Go back to the beginning of the work week
919         ***********************************************************************/
920         l_offset := -1*(7 - (l_WeekStartDay - l_DayNumber));
921       END IF;
922     END IF;
923 
924    /***************************************************************************
925     ** now we can calculate the actual dates..
926     ***************************************************************************/
927     l_QueryStartDate := TRUNC(l_QueryDate) + l_offset;               -- start of workweek 00:00:00
928     l_QueryEndDate   := (l_QueryStartDate + l_QueryDays) - (1/24/60/60); -- end of workweek 23:59:59
929 
930   ELSIF (p_Input.QueryMode = 3)
931   THEN
932     /***************************************************************************
933     ** Monthly is easy too
934     ***************************************************************************/
935 
936     -- Modified by jawang on 09/26/2002 to show previous and next month's appoints and tasks for a given month as well
937     l_QueryStartDate := TRUNC(l_QueryDate,'MON'); -- start of month 00:00:00
938     l_DayNumber := MOD((TRUNC(l_QueryStartDate) - l_SundayDate),7);
939 
940     IF (l_DayNumber>0)
941     THEN
942         l_QueryStartDate := l_QueryStartDate - l_DayNumber;
943     ELSIF (l_DayNumber<0) THEN
944         l_QueryStartDate := l_QueryStartDate - (7 + l_DayNumber);
945     END IF;
946 
947     l_QueryEndDate   := TRUNC(LAST_DAY(l_QueryDate));-- end of month 00:00:00
948     l_DayNumber := MOD((TRUNC(l_QueryEndDate) - l_SaturdayDate),7);
949 
950     IF (l_DayNumber>0)
951     THEN
952         l_QueryEndDate := l_QueryEndDate + (7-l_DayNumber);
953     ELSIF (l_DayNumber<0) THEN
954         l_QueryEndDate := l_QueryEndDate - l_DayNumber;
955     END IF;
956     l_QueryEndDate := l_QueryEndDate + (1 - (1/24/60/60));
957     l_QueryDays      := 0;
958 
959   END IF;
960 
961   /*****************************************************************************
962   ** Adjust the preferences to reflect the period
963   *****************************************************************************/
964   l_DayNumber := MOD((TRUNC(l_QueryStartDate) - l_SundayDate),7);
965   IF (l_DayNumber>=0)
966   THEN
967      l_DayNumber := 1 + l_DayNumber;
968   ELSE
969      l_DayNumber := 1 - l_DayNumber;
970   END IF;
971   l_MinDayTime := 50;
972   l_MaxDayTime := -1;
973   FOR I IN l_DayNumber .. l_DayNumber+l_QueryDays-1
974   LOOP
975     IF (l_WeekTimePrefTbl.EXISTS(I))
976     THEN
977       IF (l_WeekTimePrefTbl(I).DayStart BETWEEN 0 AND 23)
978       THEN
979         IF (l_MinDayTime>l_WeekTimePrefTbl(I).DayStart)
980         THEN
981           l_MinDayTime := l_WeekTimePrefTbl(I).DayStart;
982         END IF;
983       END IF;
984       IF (l_WeekTimePrefTbl(I).DayEnd BETWEEN 0 AND 23)
985       THEN
986         IF (l_MaxDayTime<l_WeekTimePrefTbl(I).DayEnd)
987         THEN
988           l_MaxDayTime := l_WeekTimePrefTbl(I).DayEnd;
989         END IF;
990       END IF;
991     END IF;
992   END LOOP;
993   IF (l_MinDayTime=50)
994   THEN
995     l_MinDayTime := 9;
996   END IF;
997   IF (l_MaxDayTime<0)
998   THEN
999     l_MaxDayTime := 18;
1000   END IF;
1001   IF (l_MaxDayTime<l_MinDayTime)
1002   THEN
1003     l_MinDayTime := 9;
1004     l_MaxDayTime := 18;
1005   END IF;
1006   x_Preferences.MinStartTime := TO_DATE(TO_CHAR(l_QueryStartDate,'DD-MON-YYYY')||
1007                                 ' '||TO_CHAR(l_MinDayTime),'DD-MON-YYYY hh24');
1008   x_Preferences.MaxEndTime   := TO_DATE(TO_CHAR(l_QueryEndDate,'DD-MON-YYYY')||
1009                                 ' '||TO_CHAR(l_MaxDayTime),'DD-MON-YYYY hh24');
1010 
1011  /*****************************************************************************
1012   ** If it's a personal calendar we need to super impose the tasks/appointments
1013   ** of groups we subscribed to
1014   *****************************************************************************/
1015   IF (l_QueryRSType = 'RS_EMPLOYEE')
1016   THEN
1017     FOR r_Groups IN c_Groups(l_QueryRSID)
1018     LOOP <<GROUPS>>
1019 
1020       /*************************************************************************
1021       ** The GROUPS loop will get the GROUP_Ids of all Calendar groups
1022       ** that I am currently a member of
1023       *************************************************************************/
1024 	  GetApptsAndTasks (
1025      l_LoggedOnRSID,
1026      l_LoggedOnRSType,
1027      r_Groups.GroupID,
1028      'RS_GROUP',
1029      l_QueryStartDate,
1030      l_QueryEndDate,
1031      p_input.QueryMode,
1032      l_CalSpanDaysProfile,
1033      r_Groups.GroupID,
1034      r_Groups.color,
1035      r_Groups.Prefix,
1036      'Y',  -- we are in "personal" calendar
1037      l_index,
1038      x_DisplayItems,
1039      x_Preferences
1040      );
1041     END LOOP GROUPS;
1042   END IF;
1043 
1044   /*****************************************************************************
1045   ** No matter what the resource type get the TASKS for the query user
1046   *****************************************************************************/
1047 
1048     GetApptsAndTasks (
1049     l_LoggedOnRSID,
1050     l_LoggedOnRSType,
1051     l_QueryRSID,
1052     l_QueryRSType,
1053     l_QueryStartDate,
1054     l_QueryEndDate,
1055     p_input.QueryMode,
1056     l_CalSpanDaysProfile,
1057     NULL,
1058     NULL,
1059     '',
1060     'N',
1061     l_index,
1062     x_DisplayItems,
1063     x_Preferences
1064     );
1065     IF NVL(x_preferences.DisplayItems, 'NO') = 'YES' THEN
1066      GetItems (
1067      l_LoggedOnRSID,
1068      l_LoggedOnRSType,
1069      l_QueryRSID,
1070      l_QueryRSType,
1071      l_QueryStartDate,
1072      l_QueryEndDate,
1073      p_input.QueryMode,
1074      'N',
1075      NULL,
1076      x_preferences.ItemColor, --Color
1077      x_preferences.ItemPrefix, --Prefix
1078     l_index,
1079     x_DisplayItems,
1080     x_Preferences
1081     );
1082     END IF;
1083 
1084   /*****************************************************************************
1085   ** Almost done, just have to sort the table
1086   *****************************************************************************/
1087   Jtf_Cal_Utility_Pvt.SortTable(x_DisplayItems);
1088 
1089 END GetView;
1090 
1091 END Jtf_Cal_Pvt;