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
|
||||
|
||||
Reference in new issue
Block a user