lettings · v1 · Head of Lettings
1,959
leases at Mon 20:00
Lease running at now, ending between now and now + window_days, tenant not moved out.
lettings · changed 2026-11-01: First version.
Tests
- count_between min 500.0 max 3000.0
- unique on lease_id
SQL
SELECT l.id AS lease_id, l.building_id, l.end_date, l.monthly_rent,
(SELECT max(o.status) FROM renewal_offers o WHERE o.lease_id = l.id AND o.sent_at <= {now}) AS offer_status,
l.notice_given_at IS NOT NULL AND l.notice_given_at <= {now} AS tenant_leaving
FROM leases l
WHERE l.start_date <= {now} AND l.end_date + INTERVAL 1 DAY > {now}
AND l.end_date <= {now} + INTERVAL ({window_days}) DAY
AND (l.moved_out_at IS NULL OR l.moved_out_at > {now})
ORDER BY l.end_date, l.id