Combined view of schedule data and full-day time-off data - Use this view to see complete schedule including users on time-off
CREATE VIEW vwscheduledatacomplete AS (
SELECT sc.scheduleid,
sc.userid,
sc.shiftid,
sc.shiftstartdate,
sc.shiftstartdateltc,
sc.shiftlengthtime,
sc.activitystartdate,
sc.activitystartdateltc,
sc.activitylengthtime,
sc.activitydescription,
sc.activitycodeid,
sc.activitypaid,
sc.shiftmanuallyeditted,
ud.name AS agentname,
ud.managerid,
ud.managername,
ad.name AS activitycodedesc,
COALESCE(NULLIF((ad.name)::text, ''::text), (ad.category)::text) AS activitycodename,
'SHIFT'::text AS scheduletype
FROM ((scheduledata sc
LEFT JOIN vwuserdetail ud ON (((ud.id)::text = (sc.userid)::text)))
LEFT JOIN activitycodedetails ad ON ((((ad.businessunitid)::text = (sc.buid)::text) AND ((ad.id)::text = (sc.activitycodeid)::text))))
UNION ALL
SELECT td.scheduleid,
td.userid,
NULL::integer AS shiftid,
td.businessunitdate AS shiftstartdate,
td.businessunitdate AS shiftstartdateltc,
td.length AS shiftlengthtime,
td.businessunitdate AS activitystartdate,
td.businessunitdate AS activitystartdateltc,
td.length AS activitylengthtime,
td.description AS activitydescription,
td.activitycode AS activitycodeid,
td.paid AS activitypaid,
NULL::"bit" AS shiftmanuallyeditted,
ud.name AS agentname,
ud.managerid,
ud.managername,
ad.name AS activitycodedesc,
COALESCE(NULLIF((ad.name)::text, ''::text), (ad.category)::text) AS activitycodename,
'TIMEOFF'::text AS scheduletype
FROM ((timeoffdata td
LEFT JOIN vwuserdetail ud ON (((ud.id)::text = (td.userid)::text)))
LEFT JOIN activitycodedetails ad ON ((((ad.businessunitid)::text = (td.buid)::text) AND ((ad.id)::text = (td.activitycode)::text))))
WHERE (td.isfulldayrequest = '1'::"bit")
)| Name | Type | Default | Nullable | Children | Parents | Comment |
|---|---|---|---|---|---|---|
| scheduleid | varchar(50) | true | Schedule GUID | |||
| userid | varchar(50) | true | User GUID | |||
| shiftid | integer | true | Shift GUID (NULL for time-off entries) | |||
| shiftstartdate | timestamp without time zone | true | Start date of the shift or time-off (UTC) | |||
| shiftstartdateltc | timestamp without time zone | true | Start date in local time | |||
| shiftlengthtime | integer | true | Length of the shift or time-off (seconds) | |||
| activitystartdate | timestamp without time zone | true | Start date of the activity (UTC) | |||
| activitystartdateltc | timestamp without time zone | true | Start date of the activity in local time | |||
| activitylengthtime | integer | true | Length of the activity (seconds) | |||
| activitydescription | varchar(200) | true | Activity Description | |||
| activitycodeid | varchar(50) | true | Activity code GUID | |||
| activitypaid | bit(1) | true | Activity paid or not | |||
| shiftmanuallyeditted | “bit” | true | Shift was manually edited or not (NULL for time-off) | |||
| agentname | varchar(200) | true | Agent Name | |||
| managerid | varchar(50) | true | Manager GUID | |||
| managername | varchar(200) | true | Name of the manager | |||
| activitycodedesc | varchar(50) | true | Description of the activity code | |||
| activitycodename | text | true | Name of the activity code | |||
| scheduletype | text | true | Type of schedule entry: SHIFT or TIMEOFF |
| Name | Columns | Comment | Type |
|---|---|---|---|
| public.scheduledata | 16 | BASE TABLE | |
| public.vwuserdetail | 17 | See UserDetail: User Description in detail | VIEW |
| public.activitycodedetails | 11 | Activity Code Lookup Data | BASE TABLE |
| public.timeoffdata | 12 | BASE TABLE |