mirror of
https://github.com/rickbarrette/redmine_qbo_calendar.git
synced 2026-11-17 21:50:37 -05:00
Statuses (name, colour, counts toward hours, order) are set up on the plugin's settings page instead of being hard-coded. Appointments keep a fixed key, so renaming is safe; removing a status in use asks which status to move its appointments to (done on save by a SettingsController hook). Colours come from the settings everywhere statuses show, which also fixes Cancelled never being coloured (cancelled/canceled mismatch). Call-outs (an employee off work) are their own kind of entry (event_type 'call_out') with an employee, date, days and notes, added from a button on each calendar day. They sit at the top of the day in red stripes and never count toward hours. Migration 004 converts Call_Out appointments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.3 KiB
ERB
94 lines
3.3 KiB
ERB
<h3><%= l(:label_upcoming_appointments, default: 'My Upcoming Appointments') %></h3>
|
|
|
|
<%
|
|
# Get Redmine's configured non-working week days (e.g., ["6", "7"] for Sat/Sun)
|
|
non_working_days = Setting.non_working_week_days || []
|
|
|
|
# Safely filter appointments by logged-in user across possible user column names
|
|
appointments_scope = CustomerAppointment.all
|
|
if CustomerAppointment.column_names.include?('user_id')
|
|
appointments_scope = appointments_scope.where(user_id: User.current.id)
|
|
elsif CustomerAppointment.column_names.include?('assigned_to_id')
|
|
appointments_scope = appointments_scope.where(assigned_to_id: User.current.id)
|
|
elsif CustomerAppointment.column_names.include?('author_id')
|
|
appointments_scope = appointments_scope.where(author_id: User.current.id)
|
|
end
|
|
|
|
# Look back up to 60 days to capture multi-day appointments starting in the past
|
|
raw_appointments = appointments_scope.where('date >= ?', Date.today - 60.days)
|
|
|
|
expanded_appointments = []
|
|
|
|
raw_appointments.each do |appointment|
|
|
next if appointment.start_date.nil?
|
|
|
|
start_date = appointment.start_date.to_date
|
|
duration = [appointment.duration.to_i, 1].max
|
|
date_cursor = start_date
|
|
working_days_counted = 0
|
|
|
|
# Expand appointment dates strictly across working days based on duration
|
|
while working_days_counted < duration
|
|
unless non_working_days.include?(date_cursor.cwday.to_s)
|
|
working_days_counted += 1
|
|
|
|
# Only list dates falling on or after today
|
|
if date_cursor >= Date.today
|
|
expanded_appointments << {
|
|
appointment: appointment,
|
|
date: date_cursor,
|
|
day_number: working_days_counted,
|
|
total_days: duration
|
|
}
|
|
end
|
|
end
|
|
|
|
date_cursor += 1
|
|
end
|
|
end
|
|
|
|
# Sort upcoming occurrences chronologically and take top 10
|
|
expanded_appointments.sort_by! { |item| item[:date] }
|
|
expanded_appointments = expanded_appointments.first(10)
|
|
%>
|
|
|
|
<% if expanded_appointments.any? %>
|
|
<table class="list appointments">
|
|
<thead>
|
|
<tr>
|
|
<th><%= l(:label_title) %></th>
|
|
<th><%= l(:label_customer) %></th>
|
|
<th><%= l(:label_vehicle) %></th>
|
|
<th><%= l(:label_date) %></th>
|
|
<th class="status"><%= l(:label_status) %></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% expanded_appointments.each do |item| %>
|
|
<% appt = item[:appointment] %>
|
|
<tr class="<%= cycle('odd', 'even') %> appointment-row">
|
|
<td class="subject">
|
|
<%= link_to appt.subject, customer_appointment_path(appt) %>
|
|
<% if item[:total_days] > 1 %>
|
|
<small class="muted">(Day <%= item[:day_number] %> of <%= item[:total_days] %>)</small>
|
|
<% end %>
|
|
</td>
|
|
<td class="customer">
|
|
<%= link_to appt.customer unless appt.customer.nil? %>
|
|
</td>
|
|
<td class="vehicle">
|
|
<%= link_to appt.vehicle unless appt.vehicle.nil? %>
|
|
</td>
|
|
<td class="start-date">
|
|
<%= format_date(item[:date]) %>
|
|
</td>
|
|
<td class="status">
|
|
<%= appointment_status_badge(appt, css: 'badge status-badge') %>
|
|
</td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
<% else %>
|
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
|
<% end %> |