CREATE VIEW z_wfmscheduledata AS (
SELECT sc.userid,
sc.shiftstartdate,
sc.shiftlengthtime,
sc.activitystartdate,
sc.activitystartdateltc,
sc.activitylengthtime,
sc.activitydescription,
sc.activitycodeid,
ad.category AS activitycategory,
(sc.activitypaid)::integer AS activitypaid,
(sc.shiftmanuallyeditted)::integer AS shiftmanuallyeditted,
ud.name AS agentname,
ud.managerid,
ud.managername,
ad.name AS activitycodedesc,
bu.name AS businessunit,
NULL::character varying AS timeoffrequestid
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))))
LEFT JOIN budetails bu ON (((bu.id)::text = (sc.buid)::text)))
UNION
SELECT td.userid,
td.businessunitdate AS shiftstartdate,
CASE
WHEN ((tdreq.isfulldayrequest)::integer = 1) THEN 86400
ELSE td.length
END AS shiftlengthtime,
td.businessunitdate AS activitystartdate,
td.businessunitdate AS activitystartdateltc,
CASE
WHEN ((tdreq.isfulldayrequest)::integer = 1) THEN 86400
ELSE td.length
END AS activitylengthtime,
'Absent'::character varying AS activitydescription,
td.activitycode AS activitycodeid,
'Absent'::character varying AS activitycategory,
0 AS activitypaid,
0 AS shiftmanuallyeditted,
userdet.name AS agentname,
userdet.managerid,
userdet.managername,
td.description AS activitycodedesc,
businessunit.name AS businessunit,
tdreq.id AS timeoffrequestid
FROM ((((timeoffdata td
LEFT JOIN vwuserdetail userdet ON (((userdet.id)::text = (td.userid)::text)))
LEFT JOIN activitycodedetails ad ON ((((ad.businessunitid)::text = (ad.businessunitid)::text) AND ((ad.id)::text = (td.activitycode)::text))))
LEFT JOIN budetails businessunit ON (((businessunit.id)::text = (ad.businessunitid)::text)))
LEFT JOIN timeoffrequestdata tdreq ON (((tdreq.id)::text = (td.timeoffrequestid)::text)))
)