<%= link_to issues_calendar_path do %> <%= l(:button_calendar) %> <% end %> <%= link_to customer_appointments_path do %> <%= l(:label_appointments) %> <% end %> <% if @customer %> <%= link_to @customer do %> <%= l(:label_customer) %> <% end %> <% end %>

<% if @customer %> <%= l(:label_appointment_history_for, name: @customer.name) %> <% else %> <%= l(:label_appointment_history) %> <% end %>

<%= form_tag history_customer_appointments_path, method: :get, id: 'appointment-history-filters' do %>
<%= l(:label_filter_plural) %>

<%= text_field_tag :customer_name, @customer&.name, id: 'history_customer_name', class: 'customer-name', autocomplete: 'off', size: 30, data: { autocomplete_url: '/customers/autocomplete' } %> <%= hidden_field_tag :customer_id, @customer&.id, id: 'customer_id' %> <%= select_tag :status, options_for_select(CustomerAppointment.status_options + [[l(:label_call_out_plural), CustomerAppointment::CALL_OUT]], @status), include_blank: l(:label_all_statuses) %> <%= date_field_tag :from, @from %> <%= date_field_tag :to, @to %>

<%= submit_tag l(:button_apply), name: nil, class: 'button-small' %> <%= link_to l(:button_clear), history_customer_appointments_path(customer_id: @customer&.id), class: 'icon icon-reload' %>

<% end %> <% if @appointments.empty? %>

<%= l(:label_no_past_appointments) %>

<% else %> <% unless @customer %> <% end %> <% @appointments.each do |appointment| %> <% unless @customer %> <% end %> <% end %>
<%= l(:label_date) %><%= l(:label_customer) %><%= l(:label_vehicle) %> <%= l(:label_appointment) %> <%= l(:label_technician) %> <%= l(:label_duration) %> <%= l(:label_status) %>
<%= format_date(appointment.date) %><%= link_to appointment.customer, history_customer_appointments_path(customer_id: appointment.customer_id) if appointment.customer %><%= link_to appointment.vehicle if appointment.vehicle %> <%= link_to appointment.subject, customer_appointment_path(appointment) %> <%= link_to_user(appointment.user) if appointment.user %> <%= appointment.duration %> <%= l(:label_days) %> <%= appointment_status_badge(appointment) %>
<%= pagination_links_full @appointment_pages, @appointment_count %> <% end %> <%= javascript_tag do %> // Clear the hidden customer id if the name field is emptied, so "all customers" works. document.addEventListener('DOMContentLoaded', function () { var name = document.getElementById('history_customer_name'); var id = document.getElementById('customer_id'); if (name && id) { name.addEventListener('input', function () { if (!name.value.trim()) id.value = ''; }); } }); <% end %>