From d529c99a02fddc9a7ddb6071e70d016fc4462de9 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 12 Aug 2026 08:37:28 -0400 Subject: [PATCH] Add day count calculation to appointment display in calendar --- .../_calendar_event.html.erb | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/views/customer_appointments/_calendar_event.html.erb b/app/views/customer_appointments/_calendar_event.html.erb index 42c4ce4..d6f2595 100644 --- a/app/views/customer_appointments/_calendar_event.html.erb +++ b/app/views/customer_appointments/_calendar_event.html.erb @@ -1,3 +1,27 @@ +<% + non_working_days = Setting.non_working_week_days || [] + app_datetime = (appointment.respond_to?(:date) && appointment.date.present?) ? appointment.date : appointment.start_date + start_date = app_datetime.to_date + target_date = day.to_date + duration = [appointment.duration.to_i, 1].max + + day_number = 0 + if target_date >= start_date + date_cursor = start_date + working_count = 0 + while date_cursor <= target_date + unless non_working_days.include?(date_cursor.cwday.to_s) + working_count += 1 + end + if date_cursor == target_date + day_number = working_count + break + end + date_cursor += 1 + end + end +%> + <%= tag.div class: ['appointment-block', 'tooltip', appointment.status.to_s.parameterize] do %>
@@ -17,12 +41,16 @@
- <%# Row 2: Time | Hours %> + <%# Row 2: Time | Day Count | Hours %>
- <%= appointment.date.strftime('%I:%M %p') %> + <%= appointment.date.strftime('%I:%M %p') if appointment.date.present? %> + <% if duration > 1 && day_number.positive? && day_number <= duration %> + (Day <%= day_number %> of <%= duration %>) + <% end %> + <%= number_with_precision(appointment.estimated_hours.to_f, precision: 1) %>h @@ -42,7 +70,7 @@
- <%= render partial: "customer_appointments/tooltip", locals: { appointment: appointment } %> + <%= render partial: "customer_appointments/tooltip", locals: { appointment: appointment, day: day } %> <% end %> \ No newline at end of file