i need a help from with database-design and how to manage queries to store schedule of masters and find gaps to show to clients when master is available. I can use both mysql or postgres. I'm just stucked how to do this. Fiddle: http://sqlfiddle.com/#!9/071e21
Some description:
- Masters can have regular schedule like monday: 08:00-18:00, tuesday: 09:00-19:00 or odd/even days (for example master is working only on odd days of month) with the ability to set weekends (no matter odd/even day, but sunday is weekend no metter what).
- Masters have interval_between_clients_in_minutes param in settings. For example master have 60 minutes between clients, but someone booked visit from 08:00 to 09:30, that's mean that from 09:30 to 10:00 no one can book, because of this interval_between_clients (like a slots, 1 hour - 1 slot, if you book 1,5 hours - you book 2 slots).
- Master can add dayoff (like holidays, Christmas for example) or short working day.
- When client books visit to master he has total duration in minutes, for example 60 minutes, so if master have only 30 minutes available slot, that mean that this slot is not available and shoud not be included.
I have this tables for now:
masters:
id - integer
name - varchar
interval_between_clients_in_minutes - integer
clients
id - integer
name - varchar
schedule
id - integer
master_id - integer
day_of_week - integer
open_time - time
close_time - time
schedule_type (1 - regular, 2 - odd/even)
schedule_exceptions
id - integer
master_id - integer
exception_date - date
exception_open_time - time
exception_close_time - time
exception_day_of_week - integer
is_closed - boolean
visits
master_id - integer
client_id - integer
visit_at - datetime
visit_end - datetime
duration_in_minutes - integer
- How to find gaps to display it on calendar for example for month (start_date: 2018-03-01, end_date: 2018-04-01)
Expected result:
Opening Hours of master for each day of above period EXCLUDE visits on each date.
Example: master is opened from 08:00-18:00, but have already visit from 09:00 to 10:00, that means that i need exclude 09:00-10:00 period and to display available gaps: 08:00-09:00, 10:00-18:00 for this particular day. If its weekend or holiday from schedule_exceptions - then no results.