Files
rickyandClaude Opus 5.5 31ac991bab Overview shows coming due and the last flight; intervals in days, months or years
- Overview: "Coming due" (next 30 days or 10 hours) and "Last flight" (the
  most recent day's legs, meters at the end, fuel and oil left).
- Component replace / TBO / inspect intervals, inspection types and ADs take
  a number and a days / months / years choice (CalendarInterval). Components
  gain month columns (years stored as 12 months; months land on the same
  date); inspection types and ADs keep end-of-month. ADs now honour days.
- Due list: hours already run out count as overdue; a component covered by
  an inspection type no longer gets its own "Inspect every" item.
- Loading calculator moved to a partial; no limit warnings until a load is
  entered. Header buttons don't wrap on phones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 21:40:14 -05:00

40 lines
1.5 KiB
Ruby

# The aircraft's maintenance status as 14 CFR 91.417(a)(2) lists it:
# total time in service (airframe, engines, propellers), life-limited parts,
# time since overhaul, inspection status, AD status and major alterations.
class MaintenanceReport
attr_reader :aircraft, :generated_at
def initialize(aircraft)
@aircraft = aircraft
@generated_at = Time.current
end
def time_in_service = aircraft.current_hours
# Engines and propellers, by component type name.
def engines = major_components(/engine/i)
def propellers = major_components(/propell?er|\bprop\b/i)
# Parts with a mandatory replacement time (life limits).
def life_limited
in_use.select { |c| (c.replacement_critical? && (c.replacement_hours || c.replacement_calendar?)) || c.expires_on }
end
# Items overhauled on a time basis.
def overhaul_items
in_use.select { |c| c.tbo_hours || c.tbo_calendar? }
end
def inspections = @inspections ||= Compliance.inspection_rows(aircraft)
def ads = @ads ||= Compliance.ad_rows(aircraft)
def major_records = aircraft.major_records.recent_first.includes(:component, :form_337_document, :stc_document)
def open_squawks = aircraft.squawks.active.by_priority.includes(:component)
def airworthiness = aircraft.airworthiness
private
def in_use = @in_use ||= aircraft.components.in_use.includes(:component_type).order(:install_location).to_a
def major_components(pattern) = in_use.select { |c| c.component_type&.name.to_s.match?(pattern) }
end