CREATE VIEW vwuserpresencedatadaily AS (
SELECT userpresencedatadaily.id,
userpresencedatadaily.userid,
userdetail.name AS agentname,
userdetail.managerid,
userdetail.managername,
userdetail.divisionid,
dd.name AS division_name,
userpresencedatadaily.startdate,
(userpresencedatadaily.startdate + ((( SELECT timezonecalcs.diff
FROM timezonecalcs('Australia/Sydney'::text) timezonecalcs(utctime, ltctime, diff, timezonechosen)))::double precision * '00:00:01'::interval)) AS startdateusrtz,
userpresencedatadaily.timetype,
userpresencedatadaily.systempresenceid,
CASE
WHEN ((userpresencedatadaily.systempresenceid)::text ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'::text) THEN presencedetails.systempresence
ELSE userpresencedatadaily.systempresenceid
END AS systempresencename,
userpresencedatadaily.presenceid,
CASE userpresencedatadaily.timetype
WHEN 'Presence'::text THEN userpresencedatadaily.presencetime
ELSE (0)::numeric
END AS presencetime,
(userpresencedatadaily.presencetime / 86400.00) AS presencetimeday,
userpresencedatadaily.routingid,
CASE userpresencedatadaily.timetype
WHEN 'Routing'::text THEN userpresencedatadaily.presencetime
ELSE (0)::numeric
END AS routingtime,
(userpresencedatadaily.routingtime / 86400.00) AS routingtimeday,
userpresencedatadaily.updated
FROM (((userpresencedatadaily userpresencedatadaily
LEFT JOIN vwuserdetail userdetail ON (((userdetail.id)::text = (userpresencedatadaily.userid)::text)))
LEFT JOIN divisiondetails dd ON (((dd.id)::text = (userdetail.divisionid)::text)))
LEFT JOIN presencedetails ON (((presencedetails.id)::text = (userpresencedatadaily.systempresenceid)::text)))
)