select
			t.TimetableGraf_id as "TimetableGraf_id",
			t.Person_id as "Person_id",
			t.TimeTableGraf_Day as "TimeTableGraf_Day",
			to_char(t.TimetableGraf_begTime, 'yyyy-mm-dd HH24:MI:SS') as "TimetableGraf_begTime",
			t.TimetableType_id as "TimetableType_id",
			t.pmUser_updID as "pmUser_updID",
			case when t.TimetableGraf_begTime > DATEADD('minute', 15, dbo.tzGetDate()) then 1 else 0 end as "IsFuture",
			case
				when date_part('day', t.TimetableGraf_begTime  - dbo.tzGetDate()) = 0 and cast(t.TimetableGraf_begTime as date) > cast(dbo.tzGetDate() as date) then 1
				when date_part('day', t.TimetableGraf_begTime  - dbo.tzGetDate()) = 0 and cast(t.TimetableGraf_begTime as date) < cast(dbo.tzGetDate() as date) then -1
				else date_part('day', t.TimetableGraf_begTime  - dbo.tzGetDate())
			end as "DateDiff",
			ttl.TimetableLock_lockTime as "TimetableLock_lockTime"
		from
			v_TimeTableGraf_lite t 
		left join TimetableLock ttl  on t.TimetableGraf_id = ttl.TimetableGraf_id
		where
			t.TimeTableGraf_Day >= 44624 and
			t.TimeTableGraf_Day < 44640 and
			t.MedStaffFact_Id = '520101000080725' and
            t.TimetableGraf_begTime is not null and
            
            t.TimetableType_id != 12
		order by t.TimetableGraf_begTime
