mirror of
https://github.com/rickbarrette/redmine_qbo_calendar.git
synced 2026-11-17 21:50:37 -05:00
Add customer appointment history page
Adds a history page listing past customer appointments with customer, status and date-range filters and pagination, linked from the customer page, the appointments index and each appointment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
9 files changed
+171
-3
No files matched your search
@@ -48,6 +48,29 @@ class CustomerAppointmentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# Lists past appointments, optionally filtered by customer, status and date range.
|
||||
def history
|
||||
@customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present?
|
||||
@status = params[:status].presence
|
||||
@from = parse_date(params[:from])
|
||||
@to = parse_date(params[:to])
|
||||
|
||||
scope = CustomerAppointment
|
||||
.includes(:customer, :vehicle, :user)
|
||||
.where('date < ?', Time.zone.now.beginning_of_day)
|
||||
scope = scope.where(customer_id: @customer.id) if @customer
|
||||
scope = scope.where(status: @status) if @status
|
||||
scope = scope.where('date >= ?', @from.in_time_zone.beginning_of_day) if @from
|
||||
scope = scope.where('date <= ?', @to.in_time_zone.end_of_day) if @to
|
||||
|
||||
@appointment_count = scope.count
|
||||
@appointment_pages = Paginator.new(@appointment_count, per_page_option, params[:page])
|
||||
@appointments = scope
|
||||
.order(date: :desc)
|
||||
.offset(@appointment_pages.offset)
|
||||
.limit(@appointment_pages.per_page)
|
||||
end
|
||||
|
||||
def show
|
||||
@appointment = CustomerAppointment.find(params[:id])
|
||||
end
|
||||
@@ -111,6 +134,12 @@ class CustomerAppointmentsController < ApplicationController
|
||||
|
||||
end
|
||||
|
||||
def parse_date(value)
|
||||
Date.parse(value) if value.present?
|
||||
rescue ArgumentError
|
||||
nil
|
||||
end
|
||||
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id]) if params[:project_id].present?
|
||||
end
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<% customer = context[:customer] %>
|
||||
<% if User.current.allowed_to?(:add_customer_appointments, nil, global: true) %>
|
||||
<p>
|
||||
<% customer = context[:customer] %>
|
||||
<%= link_to l(:label_add_appointment), new_customer_appointment_path(customer_id: customer.id), target: :_blank, id: :appointment_link %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% if User.current.allowed_to?(:view_customer_appointments, nil, global: true) %>
|
||||
<p>
|
||||
<%= link_to l(:label_appointment_history), history_customer_appointments_path(customer_id: customer.id), id: :appointment_history_link %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -0,0 +1,106 @@
|
||||
<div class="contextual">
|
||||
<%= link_to issues_calendar_path do %>
|
||||
<i class="fa-regular fa-calendar-days"></i> <%= l(:button_calendar) %>
|
||||
<% end %>
|
||||
<%= link_to customer_appointments_path do %>
|
||||
<i class="fa-regular fa-clock"></i> <%= l(:label_appointments) %>
|
||||
<% end %>
|
||||
<% if @customer %>
|
||||
<%= link_to @customer do %>
|
||||
<i class="fa-regular fa-user"></i> <%= l(:label_customer) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<h2>
|
||||
<% if @customer %>
|
||||
<%= l(:label_appointment_history_for, name: @customer.name) %>
|
||||
<% else %>
|
||||
<%= l(:label_appointment_history) %>
|
||||
<% end %>
|
||||
</h2>
|
||||
|
||||
<%= form_tag history_customer_appointments_path, method: :get, id: 'appointment-history-filters' do %>
|
||||
<fieldset class="box">
|
||||
<legend><%= l(:label_filter_plural) %></legend>
|
||||
<p>
|
||||
<label for="history_customer_name"><%= l(:label_customer) %></label>
|
||||
<%= 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' %>
|
||||
|
||||
<label for="status"><%= l(:field_status) %></label>
|
||||
<%= select_tag :status,
|
||||
options_for_select(CustomerAppointment::STATUSES.map { |s| [s.humanize, s] }, @status),
|
||||
include_blank: l(:label_all_statuses) %>
|
||||
|
||||
<label for="from"><%= l(:label_date_from) %></label>
|
||||
<%= date_field_tag :from, @from %>
|
||||
|
||||
<label for="to"><%= l(:label_date_to) %></label>
|
||||
<%= date_field_tag :to, @to %>
|
||||
</p>
|
||||
<p class="buttons">
|
||||
<%= 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' %>
|
||||
</p>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<% if @appointments.empty? %>
|
||||
<p class="nodata"><%= l(:label_no_past_appointments) %></p>
|
||||
<% else %>
|
||||
<table class="list appointment-history">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:label_date) %></th>
|
||||
<% unless @customer %>
|
||||
<th><%= l(:label_customer) %></th>
|
||||
<% end %>
|
||||
<th><%= l(:label_vehicle) %></th>
|
||||
<th><%= l(:label_appointment) %></th>
|
||||
<th><%= l(:label_technician) %></th>
|
||||
<th><%= l(:label_duration) %></th>
|
||||
<th><%= l(:label_status) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @appointments.each do |appointment| %>
|
||||
<tr class="<%= cycle('odd', 'even') %>">
|
||||
<td><%= format_date(appointment.date) %></td>
|
||||
<% unless @customer %>
|
||||
<td><%= link_to appointment.customer, history_customer_appointments_path(customer_id: appointment.customer_id) if appointment.customer %></td>
|
||||
<% end %>
|
||||
<td><%= link_to appointment.vehicle if appointment.vehicle %></td>
|
||||
<td class="subject"><%= link_to appointment.subject, customer_appointment_path(appointment) %></td>
|
||||
<td><%= link_to_user(appointment.user) if appointment.user %></td>
|
||||
<td><%= appointment.duration %> <%= l(:label_days) %></td>
|
||||
<td>
|
||||
<% if appointment.status.present? %>
|
||||
<span class="status-badge status-<%= appointment.status.to_s.parameterize %>">
|
||||
<%= appointment.status.to_s.humanize %>
|
||||
</span>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span class="pagination"><%= pagination_links_full @appointment_pages, @appointment_count %></span>
|
||||
<% 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 %>
|
||||
@@ -5,6 +5,10 @@
|
||||
<i class="fa-regular fa-calendar-days"></i> <%= l(:button_calendar) %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to history_customer_appointments_path do %>
|
||||
<i class="fa-solid fa-clock-rotate-left"></i> <%= l(:label_appointment_history) %>
|
||||
<% end %>
|
||||
|
||||
<% if User.current.allowed_to?(:add_customer_appointments, nil, global: true) %>
|
||||
<%= link_to new_customer_appointment_path do %>
|
||||
<i class="fa-regular fa-pen-to-square"></i> <%= l(:button_add) %>
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
<i class="fa-regular fa-calendar-days"></i> <%= l(:button_calendar) %>
|
||||
<% end %>
|
||||
|
||||
<% if @appointment.customer %>
|
||||
<%= link_to history_customer_appointments_path(customer_id: @appointment.customer_id) do %>
|
||||
<i class="fa-solid fa-clock-rotate-left"></i> <%= l(:label_appointment_history) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if User.current.allowed_to?(:add_customer_appointments, nil, global: true) %>
|
||||
<%= link_to new_issue_path(issue: { customer_id: @appointment.customer_id, vehicle_id: @appointment.vehicle_id, estimate_id: @appointment.estimate_id }), target: :_blank do %>
|
||||
<i class="fa-solid fa-plus"></i> <%= l(:label_new_issue) %>
|
||||
|
||||
@@ -596,4 +596,16 @@ table.cal td.today {
|
||||
left: 50% !important;
|
||||
right: auto !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Appointment history page */
|
||||
#appointment-history-filters fieldset p label {
|
||||
margin: 0 4px 0 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#appointment-history-filters fieldset p label:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
table.appointment-history td.subject {
|
||||
text-align: left;
|
||||
}
|
||||
@@ -36,6 +36,12 @@ en:
|
||||
label_appointment: Appointment
|
||||
label_appointment_new: "New Appointment"
|
||||
label_appointments: Appointments
|
||||
label_appointment_history: Appointment History
|
||||
label_appointment_history_for: "Appointment History: %{name}"
|
||||
label_all_statuses: "All statuses"
|
||||
label_date_from: From
|
||||
label_date_to: To
|
||||
label_no_past_appointments: "No past appointments found"
|
||||
label_customer_appointment: Customer Appointment
|
||||
label_customer_calendar: Customer Calendar
|
||||
label_days: Days
|
||||
|
||||
@@ -15,6 +15,7 @@ RedmineApp::Application.routes.draw do
|
||||
collection do
|
||||
get :customer_options
|
||||
get :create_issues
|
||||
get :history
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Redmine::Plugin.register :redmine_qbo_calendar do
|
||||
end
|
||||
|
||||
# Global Permissions
|
||||
permission :view_customer_appointments, { customer_appointments: [:index, :show] }, global: true
|
||||
permission :view_customer_appointments, { customer_appointments: [:index, :show, :history] }, global: true
|
||||
permission :add_customer_appointments, { customer_appointments: [:new, :create] }, global: true
|
||||
permission :edit_customer_appointments, { customer_appointments: [:edit, :update] }, global: true
|
||||
permission :delete_customer_appointments, { customer_appointments: [:destroy] }, global: true
|
||||
|
||||
Reference in new issue
Block a user