mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Part 91 inspection rules: limitations, annual as 100-hour, overrun, clock
- Inspection types say what overdue means: grounds the aircraft, no IFR
(91.411), no transponder (91.413) or advisory. Overdue limitations show
as a new LIMITED status ("VFR only", "No transponder") and don't block
flights under airworthiness enforcement
- "Also counts as": an annual satisfies the 100-hour (91.409(b))
- Overrun allowance: a 100-hour done within 10 hrs of due counts the next
one from when it was due; done early, from when it was done
- Per-aircraft maintenance clock (tach or Hobbs) for time in service; new
records default to it (fixes the tach-offset mismatch)
- Status labels Current / Due soon / limitation / Grounded, with the
91.7 pilot-in-command note
- Migration converts existing types by name; archives carry the new fields
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef7cd2efba
commit
a4b72cf2c1
28 files changed
+370
-62
No files matched your search
@@ -6,7 +6,7 @@ class AdCompliancesController < ApplicationController
|
|||||||
def new
|
def new
|
||||||
ad = @aircraft.applicable_ads.find_by(id: params[:ad_id])
|
ad = @aircraft.applicable_ads.find_by(id: params[:ad_id])
|
||||||
@compliance = AdCompliance.new(aircraft: @aircraft, airworthiness_directive: ad, date_complied: Date.current,
|
@compliance = AdCompliance.new(aircraft: @aircraft, airworthiness_directive: ad, date_complied: Date.current,
|
||||||
aircraft_hours_at_compliance: @aircraft.tach_time,
|
aircraft_hours_at_compliance: @aircraft.current_hours,
|
||||||
not_applicable: params[:not_applicable] == "1")
|
not_applicable: params[:not_applicable] == "1")
|
||||||
@compliance.compliance_notes = "Not applicable: " if @compliance.not_applicable?
|
@compliance.compliance_notes = "Not applicable: " if @compliance.not_applicable?
|
||||||
@compliance.fill_next_due
|
@compliance.fill_next_due
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class AircraftController < ApplicationController
|
|||||||
params.require(:aircraft).permit(
|
params.require(:aircraft).permit(
|
||||||
:tail_number, :make, :model, :serial_number, :description, :purchased, :status,
|
:tail_number, :make, :model, :serial_number, :description, :purchased, :status,
|
||||||
:tach_time, :tach_time_offset, :hobbs_time, :hobbs_time_offset,
|
:tach_time, :tach_time_offset, :hobbs_time, :hobbs_time_offset,
|
||||||
:airworthiness_enforcement, :picture, :icao_type
|
:airworthiness_enforcement, :picture, :icao_type, :time_basis
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -5,7 +5,7 @@ class InspectionRecordsController < ApplicationController
|
|||||||
|
|
||||||
def new
|
def new
|
||||||
@record = InspectionRecord.new(aircraft: @aircraft, date: Date.current,
|
@record = InspectionRecord.new(aircraft: @aircraft, date: Date.current,
|
||||||
aircraft_hours: @aircraft.tach_time,
|
aircraft_hours: @aircraft.current_hours,
|
||||||
inspection_type_id: params[:inspection_type_id])
|
inspection_type_id: params[:inspection_type_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ class InspectionTypesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def type_params
|
def type_params
|
||||||
params.require(:inspection_type).permit(:name, :recurring, :required, :recurring_hours, :recurring_days, :recurring_months)
|
p = params.require(:inspection_type).permit(:name, :recurring, :effect, :hours_tolerance, :satisfies_id,
|
||||||
|
:recurring_hours, :recurring_days, :recurring_months)
|
||||||
|
p[:satisfies_id] = scoped_id(@aircraft.applicable_inspection_types, p[:satisfies_id]) if p.key?(:satisfies_id)
|
||||||
|
p
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -14,7 +14,7 @@ class LogbookEntriesController < ApplicationController
|
|||||||
def show; end
|
def show; end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@entry = @aircraft.logbook_entries.new(date: Date.current, aircraft_hours_at_entry: @aircraft.tach_time)
|
@entry = @aircraft.logbook_entries.new(date: Date.current, aircraft_hours_at_entry: @aircraft.current_hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class MajorRecordsController < ApplicationController
|
|||||||
|
|
||||||
def new
|
def new
|
||||||
@record = @aircraft.major_records.new(record_type: params[:type] || "repair", date_performed: Date.current,
|
@record = @aircraft.major_records.new(record_type: params[:type] || "repair", date_performed: Date.current,
|
||||||
aircraft_hours: @aircraft.tach_time)
|
aircraft_hours: @aircraft.current_hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
@@ -8,16 +8,25 @@ module ApplicationHelper
|
|||||||
value ? l(value.to_date, format: :long) : "—"
|
value ? l(value.to_date, format: :long) : "—"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
AIRWORTHINESS_COLORS = { "RED" => "red", "LIMITED" => "blue", "ORANGE" => "orange", "GREEN" => "green" }.freeze
|
||||||
|
|
||||||
def airworthiness_badge(status, large: false)
|
def airworthiness_badge(status, large: false)
|
||||||
color = { "RED" => "red", "ORANGE" => "orange", "GREEN" => "green" }[status.status]
|
tag.span(status.label, class: [ "badge-#{AIRWORTHINESS_COLORS[status.status]}", ("text-sm px-3 py-1" if large) ],
|
||||||
tag.span(status.label, class: [ "badge-#{color}", ("text-sm px-3 py-1" if large) ])
|
title: Airworthiness::DISCLAIMER)
|
||||||
end
|
end
|
||||||
|
|
||||||
def airworthiness_dot(status)
|
def airworthiness_dot(status)
|
||||||
color = { "RED" => "bg-red-500", "ORANGE" => "bg-amber-400", "GREEN" => "bg-emerald-500" }[status.status]
|
color = { "RED" => "bg-red-500", "LIMITED" => "bg-sky-500", "ORANGE" => "bg-amber-400", "GREEN" => "bg-emerald-500" }[status.status]
|
||||||
tag.span(class: "inline-block h-3 w-3 rounded-full #{color}", title: status.label)
|
tag.span(class: "inline-block h-3 w-3 rounded-full #{color}", title: status.label)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Badge class (or text class) for one airworthiness issue.
|
||||||
|
def issue_badge_class(issue) = "badge-#{AIRWORTHINESS_COLORS[issue.severity]}"
|
||||||
|
|
||||||
|
def issue_text_class(issue)
|
||||||
|
{ "RED" => "text-red-700", "LIMITED" => "text-sky-700" }.fetch(issue.severity, "text-amber-700")
|
||||||
|
end
|
||||||
|
|
||||||
COMPLIANCE_BADGES = {
|
COMPLIANCE_BADGES = {
|
||||||
"compliant" => [ "green", "Compliant" ], "due_soon" => [ "orange", "Due Soon" ],
|
"compliant" => [ "green", "Compliant" ], "due_soon" => [ "orange", "Due Soon" ],
|
||||||
"overdue" => [ "red", "Overdue" ], "no_compliance" => [ "red", "No Record" ],
|
"overdue" => [ "red", "Overdue" ], "no_compliance" => [ "red", "No Record" ],
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class AdCompliance < ApplicationRecord
|
|||||||
# + interval). Only fills a blank/zero value, so a typed-in reading wins.
|
# + interval). Only fills a blank/zero value, so a typed-in reading wins.
|
||||||
def fill_next_due
|
def fill_next_due
|
||||||
return if closed? || airworthiness_directive.nil?
|
return if closed? || airworthiness_directive.nil?
|
||||||
base = aircraft_hours_at_compliance || aircraft&.tach_time
|
base = aircraft_hours_at_compliance || aircraft&.current_hours
|
||||||
due = Compliance.next_due(airworthiness_directive.due_rule, date: date_complied, hours: base)
|
due = Compliance.next_due(airworthiness_directive.due_rule, date: date_complied, hours: base)
|
||||||
self.next_due_at_time = due[:hours] if due[:hours]
|
self.next_due_at_time = due[:hours] if due[:hours]
|
||||||
end
|
end
|
||||||
@@ -35,7 +35,7 @@ class AdCompliance < ApplicationRecord
|
|||||||
def next_due_is_a_future_reading
|
def next_due_is_a_future_reading
|
||||||
due = next_due_at_time.to_d
|
due = next_due_at_time.to_d
|
||||||
return if closed? || due <= 0
|
return if closed? || due <= 0
|
||||||
base = aircraft_hours_at_compliance || aircraft&.tach_time
|
base = aircraft_hours_at_compliance || aircraft&.current_hours
|
||||||
return unless base && due <= base
|
return unless base && due <= base
|
||||||
errors.add(:next_due_at_time, "must be a tach reading after the compliance hours (#{base}). " \
|
errors.add(:next_due_at_time, "must be a tach reading after the compliance hours (#{base}). " \
|
||||||
"For “every 100 hours” enter #{base + 100}, not 100")
|
"For “every 100 hours” enter #{base + 100}, not 100")
|
||||||
|
|||||||
+11
-2
@@ -28,7 +28,12 @@ class Aircraft < ApplicationRecord
|
|||||||
has_and_belongs_to_many :inspection_types
|
has_and_belongs_to_many :inspection_types
|
||||||
has_and_belongs_to_many :airworthiness_directives
|
has_and_belongs_to_many :airworthiness_directives
|
||||||
|
|
||||||
|
# Which clock counts as time in service for maintenance (14 CFR 1.1 defines
|
||||||
|
# it as takeoff to landing; many owners use tach, some Hobbs).
|
||||||
|
TIME_BASES = { "tach" => "Tach", "hobbs" => "Hobbs" }.freeze
|
||||||
|
|
||||||
validates :tail_number, presence: true
|
validates :tail_number, presence: true
|
||||||
|
validates :time_basis, inclusion: { in: TIME_BASES.keys }
|
||||||
validates :status, inclusion: { in: STATUSES.keys }
|
validates :status, inclusion: { in: STATUSES.keys }
|
||||||
validates :icao_type, format: { with: /\A[A-Z0-9]{1,4}\z/, message: "must be an ICAO type designator like C150" }, allow_blank: true
|
validates :icao_type, format: { with: /\A[A-Z0-9]{1,4}\z/, message: "must be an ICAO type designator like C150" }, allow_blank: true
|
||||||
normalizes :icao_type, with: ->(t) { t.strip.upcase.presence }
|
normalizes :icao_type, with: ->(t) { t.strip.upcase.presence }
|
||||||
@@ -40,11 +45,15 @@ class Aircraft < ApplicationRecord
|
|||||||
|
|
||||||
def status_label = STATUSES[status]
|
def status_label = STATUSES[status]
|
||||||
|
|
||||||
# Hours used for compliance calculations (tach minus offset, as in the original).
|
# Time in service used for maintenance: the chosen clock minus its offset
|
||||||
|
# (as in the original, offsets cover a replaced meter).
|
||||||
def current_hours
|
def current_hours
|
||||||
tach_time - tach_time_offset
|
hobbs? ? hobbs_time - hobbs_time_offset : tach_time - tach_time_offset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hobbs? = time_basis == "hobbs"
|
||||||
|
def time_basis_label = TIME_BASES[time_basis]
|
||||||
|
|
||||||
def airworthiness
|
def airworthiness
|
||||||
@airworthiness ||= Airworthiness.new(self).call
|
@airworthiness ||= Airworthiness.new(self).call
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
class InspectionType < ApplicationRecord
|
class InspectionType < ApplicationRecord
|
||||||
|
# What it means for the aircraft when this inspection is overdue.
|
||||||
|
EFFECTS = {
|
||||||
|
"grounds" => "Grounds the aircraft",
|
||||||
|
"no_ifr" => "No IFR flight (e.g. pitot-static, 91.411)",
|
||||||
|
"no_transponder" => "Transponder can't be used (91.413)",
|
||||||
|
"advisory" => "Advisory only"
|
||||||
|
}.freeze
|
||||||
|
# Short form for the airworthiness status ("VFR only").
|
||||||
|
LIMITATIONS = { "no_ifr" => "VFR only", "no_transponder" => "No transponder" }.freeze
|
||||||
|
|
||||||
has_and_belongs_to_many :aircraft
|
has_and_belongs_to_many :aircraft
|
||||||
has_and_belongs_to_many :components
|
has_and_belongs_to_many :components
|
||||||
has_many :inspection_records, dependent: :destroy
|
has_many :inspection_records, dependent: :destroy
|
||||||
|
belongs_to :satisfies, class_name: "InspectionType", optional: true
|
||||||
|
has_many :satisfied_by, class_name: "InspectionType", foreign_key: :satisfies_id, inverse_of: :satisfies, dependent: :nullify
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
validates :effect, inclusion: { in: EFFECTS.keys }
|
||||||
|
validates :hours_tolerance, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }
|
||||||
|
validate { errors.add(:satisfies, "can't be the inspection itself") if satisfies_id.present? && satisfies_id == id }
|
||||||
|
# `required` mirrors effect, for archives shared with the original app.
|
||||||
|
before_validation { self.required = effect != "advisory" }
|
||||||
|
|
||||||
scope :ordered, -> { order(:name) }
|
scope :ordered, -> { order(:name) }
|
||||||
|
|
||||||
@@ -15,6 +32,17 @@ class InspectionType < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s = name
|
def to_s = name
|
||||||
|
def effect_label = EFFECTS[effect]
|
||||||
|
def limitation = LIMITATIONS[effect]
|
||||||
|
def advisory? = effect == "advisory"
|
||||||
|
|
||||||
|
# Records that count for this inspection on the aircraft: its own, plus
|
||||||
|
# those of inspections that satisfy it (an annual for the 100-hour).
|
||||||
|
def records_for(aircraft)
|
||||||
|
InspectionRecord.for_aircraft(aircraft).where(inspection_type_id: [ id, *satisfied_by.ids ])
|
||||||
|
end
|
||||||
|
|
||||||
|
def latest_record_for(aircraft) = records_for(aircraft).recent_first.first
|
||||||
|
|
||||||
def due_rule
|
def due_rule
|
||||||
{ hours: recurring_hours.to_f, months: recurring_months, days: recurring_days } if recurring?
|
{ hours: recurring_hours.to_f, months: recurring_months, days: recurring_days } if recurring?
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ module AircraftArchive
|
|||||||
|
|
||||||
def aircraft_hash(a)
|
def aircraft_hash(a)
|
||||||
{ id: id(a), tail_number: a.tail_number, make: a.make, model: a.model, serial_number: a.serial_number,
|
{ id: id(a), tail_number: a.tail_number, make: a.make, model: a.model, serial_number: a.serial_number,
|
||||||
description: a.description, purchased: a.purchased&.iso8601, status: a.status, tach_time: dec(a.tach_time),
|
description: a.description, purchased: a.purchased&.iso8601, status: a.status, time_basis: a.time_basis, tach_time: dec(a.tach_time),
|
||||||
tach_time_offset: dec(a.tach_time_offset), hobbs_time: dec(a.hobbs_time), hobbs_time_offset: dec(a.hobbs_time_offset),
|
tach_time_offset: dec(a.tach_time_offset), hobbs_time: dec(a.hobbs_time), hobbs_time_offset: dec(a.hobbs_time_offset),
|
||||||
picture: file(a.picture, "aircraft_pictures"), icao_type: a.icao_type }
|
picture: file(a.picture, "aircraft_pictures"), icao_type: a.icao_type }
|
||||||
end
|
end
|
||||||
@@ -150,7 +150,8 @@ module AircraftArchive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def inspection_type_hash(t, component_ids)
|
def inspection_type_hash(t, component_ids)
|
||||||
{ id: id(t), name: t.name, recurring: t.recurring, required: t.required, recurring_hours: dec(t.recurring_hours),
|
{ id: id(t), name: t.name, recurring: t.recurring, required: t.required, effect: t.effect,
|
||||||
|
hours_tolerance: dec(t.hours_tolerance), satisfies: t.satisfies_id && id(t.satisfies), recurring_hours: dec(t.recurring_hours),
|
||||||
recurring_days: t.recurring_days, recurring_months: t.recurring_months,
|
recurring_days: t.recurring_days, recurring_months: t.recurring_months,
|
||||||
applicable_aircraft: t.aircraft_ids.include?(@aircraft.id) ? [ id(@aircraft) ] : [],
|
applicable_aircraft: t.aircraft_ids.include?(@aircraft.id) ? [ id(@aircraft) ] : [],
|
||||||
applicable_component: (t.component_ids & component_ids).map { id(_1) } }
|
applicable_component: (t.component_ids & component_ids).map { id(_1) } }
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ module AircraftArchive
|
|||||||
tail_number: (@tail_number.presence || a["tail_number"]).to_s.strip.upcase,
|
tail_number: (@tail_number.presence || a["tail_number"]).to_s.strip.upcase,
|
||||||
make: a["make"].to_s, model: a["model"].to_s, serial_number: a["serial_number"].to_s, description: a["description"].to_s,
|
make: a["make"].to_s, model: a["model"].to_s, serial_number: a["serial_number"].to_s, description: a["description"].to_s,
|
||||||
purchased: date(a["purchased"]), status: Aircraft::STATUSES.key?(a["status"]) ? a["status"] : "AVAILABLE",
|
purchased: date(a["purchased"]), status: Aircraft::STATUSES.key?(a["status"]) ? a["status"] : "AVAILABLE",
|
||||||
|
time_basis: Aircraft::TIME_BASES.key?(a["time_basis"]) ? a["time_basis"] : "tach",
|
||||||
tach_time: num(a["tach_time"] || a["flight_time"]) || 0, tach_time_offset: num(a["tach_time_offset"]) || 0,
|
tach_time: num(a["tach_time"] || a["flight_time"]) || 0, tach_time_offset: num(a["tach_time_offset"]) || 0,
|
||||||
hobbs_time: num(a["hobbs_time"]) || 0, hobbs_time_offset: num(a["hobbs_time_offset"]) || 0,
|
hobbs_time: num(a["hobbs_time"]) || 0, hobbs_time_offset: num(a["hobbs_time_offset"]) || 0,
|
||||||
icao_type: a["icao_type"].to_s.upcase.presence&.then { _1.match?(/\A[A-Z0-9]{1,4}\z/) ? _1 : nil }
|
icao_type: a["icao_type"].to_s.upcase.presence&.then { _1.match?(/\A[A-Z0-9]{1,4}\z/) ? _1 : nil }
|
||||||
@@ -256,7 +257,9 @@ module AircraftArchive
|
|||||||
if type
|
if type
|
||||||
warn("Inspection type “#{name}” already existed here and was reused.") if type.recurring != (data["recurring"] == true)
|
warn("Inspection type “#{name}” already existed here and was reused.") if type.recurring != (data["recurring"] == true)
|
||||||
else
|
else
|
||||||
type = InspectionType.new(name: name, recurring: data["recurring"] == true, required: data["required"] != false,
|
effect = InspectionType::EFFECTS.key?(data["effect"]) ? data["effect"] : (data["required"] == false ? "advisory" : "grounds")
|
||||||
|
type = InspectionType.new(name: name, recurring: data["recurring"] == true, effect: effect,
|
||||||
|
required: effect != "advisory", hours_tolerance: num(data["hours_tolerance"]) || 0,
|
||||||
recurring_hours: num(data["recurring_hours"]), recurring_days: data["recurring_days"],
|
recurring_hours: num(data["recurring_hours"]), recurring_days: data["recurring_days"],
|
||||||
recurring_months: data["recurring_months"])
|
recurring_months: data["recurring_months"])
|
||||||
type.save!(validate: false)
|
type.save!(validate: false)
|
||||||
@@ -265,6 +268,11 @@ module AircraftArchive
|
|||||||
type.aircraft << @aircraft if Array(data["applicable_aircraft"]).any? && !type.aircraft.include?(@aircraft)
|
type.aircraft << @aircraft if Array(data["applicable_aircraft"]).any? && !type.aircraft.include?(@aircraft)
|
||||||
components(data["applicable_component"]).each { |c| type.components << c unless type.components.include?(c) }
|
components(data["applicable_component"]).each { |c| type.components << c unless type.components.include?(c) }
|
||||||
@map[:inspection_type][data["id"].to_s] = type.id
|
@map[:inspection_type][data["id"].to_s] = type.id
|
||||||
|
(@satisfies ||= []) << [ type, data["satisfies"].to_s ] if data["satisfies"].present?
|
||||||
|
end
|
||||||
|
Array(@satisfies).each do |type, ref|
|
||||||
|
target = @map[:inspection_type][ref]
|
||||||
|
type.update_column(:satisfies_id, target) if target && type.satisfies_id.nil? && target != type.id
|
||||||
end
|
end
|
||||||
m("inspection_records").each do |data|
|
m("inspection_records").each do |data|
|
||||||
type_id = @map[:inspection_type][data["inspection_type_id"].to_s]
|
type_id = @map[:inspection_type][data["inspection_type_id"].to_s]
|
||||||
|
|||||||
@@ -1,22 +1,43 @@
|
|||||||
# Computes RED / ORANGE / GREEN airworthiness for an aircraft. Checks (in order):
|
# Summarizes an aircraft's records: AD compliance, grounding squawks,
|
||||||
# AD compliance, grounding squawks, inspection recurrency, component replacement.
|
# inspection recurrency and component replacement.
|
||||||
|
#
|
||||||
|
# RED something that grounds the aircraft is overdue
|
||||||
|
# LIMITED it may fly with limitations (pitot-static overdue: VFR only;
|
||||||
|
# transponder check overdue: no transponder)
|
||||||
|
# ORANGE something is due soon
|
||||||
|
# GREEN nothing overdue or due soon
|
||||||
|
#
|
||||||
|
# This reflects only what's recorded here. Before each flight the pilot in
|
||||||
|
# command decides whether the aircraft is airworthy (14 CFR 91.7).
|
||||||
class Airworthiness
|
class Airworthiness
|
||||||
HOURS_WARNING = BigDecimal("10")
|
HOURS_WARNING = BigDecimal("10")
|
||||||
DAYS_WARNING = 30
|
DAYS_WARNING = 30
|
||||||
|
|
||||||
RED = "RED"
|
RED = "RED"
|
||||||
|
LIMITED = "LIMITED"
|
||||||
ORANGE = "ORANGE"
|
ORANGE = "ORANGE"
|
||||||
GREEN = "GREEN"
|
GREEN = "GREEN"
|
||||||
|
DISCLAIMER = "Based on the records in this app. Before each flight the pilot in command decides whether the aircraft is airworthy (14 CFR 91.7)."
|
||||||
|
|
||||||
Issue = Struct.new(:category, :severity, :title, :description, :item, keyword_init: true)
|
Issue = Struct.new(:category, :severity, :title, :description, :item, :limitation, keyword_init: true)
|
||||||
|
|
||||||
Status = Struct.new(:status, :issues, keyword_init: true) do
|
Status = Struct.new(:status, :issues, keyword_init: true) do
|
||||||
def red? = status == RED
|
def red? = status == RED
|
||||||
|
def limited? = status == LIMITED
|
||||||
def orange? = status == ORANGE
|
def orange? = status == ORANGE
|
||||||
def green? = status == GREEN
|
def green? = status == GREEN
|
||||||
def can_fly? = green?
|
def can_fly? = !red?
|
||||||
def red_issues = issues.select { |i| i.severity == RED }
|
def red_issues = issues.select { |i| i.severity == RED }
|
||||||
def label = { RED => "Not Airworthy", ORANGE => "Attention Needed", GREEN => "Airworthy" }[status]
|
def limitations = issues.filter_map(&:limitation).uniq
|
||||||
|
|
||||||
|
def label
|
||||||
|
case status
|
||||||
|
when RED then "Grounded"
|
||||||
|
when LIMITED then limitations.join(" · ")
|
||||||
|
when ORANGE then "Due soon"
|
||||||
|
else "Current"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(aircraft, today: Date.current)
|
def initialize(aircraft, today: Date.current)
|
||||||
@@ -34,6 +55,7 @@ class Airworthiness
|
|||||||
|
|
||||||
status =
|
status =
|
||||||
if @issues.any? { _1.severity == RED } then RED
|
if @issues.any? { _1.severity == RED } then RED
|
||||||
|
elsif @issues.any? { _1.severity == LIMITED } then LIMITED
|
||||||
elsif @issues.any? { _1.severity == ORANGE } then ORANGE
|
elsif @issues.any? { _1.severity == ORANGE } then ORANGE
|
||||||
else GREEN
|
else GREEN
|
||||||
end
|
end
|
||||||
@@ -42,8 +64,8 @@ class Airworthiness
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def add(category, severity, title, description, item)
|
def add(category, severity, title, description, item, limitation: nil)
|
||||||
@issues << Issue.new(category:, severity:, title:, description:, item:)
|
@issues << Issue.new(category:, severity:, title:, description:, item:, limitation:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_ads
|
def check_ads
|
||||||
@@ -68,15 +90,16 @@ class Airworthiness
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check_inspections
|
def check_inspections
|
||||||
@aircraft.applicable_inspection_types.where(required: true).find_each do |type|
|
@aircraft.applicable_inspection_types.where.not(effect: "advisory").includes(:satisfied_by).find_each do |type|
|
||||||
last = type.inspection_records.for_aircraft(@aircraft).recent_first.first
|
records = type.records_for(@aircraft).to_a
|
||||||
res = Compliance.inspection_status(type, last, @hours, @today)
|
res = Compliance.inspection_status(type, records, @hours, @today)
|
||||||
case res.rank
|
case res.rank
|
||||||
when Compliance::OVERDUE
|
when Compliance::OVERDUE
|
||||||
if last
|
title = "#{type.name} - #{records.any? ? 'Overdue' : 'Never Completed'}"
|
||||||
add("INSPECTION", RED, "#{type.name} - Overdue", "Inspection overdue.", type)
|
if (limitation = type.limitation)
|
||||||
|
add("INSPECTION", LIMITED, title, "#{limitation} until it's done.", type, limitation: limitation)
|
||||||
else
|
else
|
||||||
add("INSPECTION", RED, "#{type.name} - Never Completed", "Required inspection has no completion record.", type)
|
add("INSPECTION", RED, title, overdue_description(type, records, res), type)
|
||||||
end
|
end
|
||||||
when Compliance::DUE_SOON
|
when Compliance::DUE_SOON
|
||||||
add("INSPECTION", ORANGE, "#{type.name} - Due Soon", "Inspection due soon.", type)
|
add("INSPECTION", ORANGE, "#{type.name} - Due Soon", "Inspection due soon.", type)
|
||||||
@@ -84,6 +107,19 @@ class Airworthiness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The 100-hour may be overflown by up to its tolerance only to reach a
|
||||||
|
# place where it can be done (91.409(b)); say so while that's still open.
|
||||||
|
def overdue_description(type, records, res)
|
||||||
|
return "Required inspection has no completion record." if records.empty?
|
||||||
|
over = res.next_due_hours && @hours - res.next_due_hours
|
||||||
|
if over && type.hours_tolerance.positive? && over <= type.hours_tolerance
|
||||||
|
"Inspection overdue. It may be flown up to #{type.hours_tolerance.to_s.sub(/\.0\z/, '')} hrs past due only to reach " \
|
||||||
|
"a place where it can be done; that time counts toward the next interval (91.409(b))."
|
||||||
|
else
|
||||||
|
"Inspection overdue."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def check_components
|
def check_components
|
||||||
@aircraft.components.in_use.where(replacement_critical: true).includes(:component_type).find_each do |c|
|
@aircraft.components.in_use.where(replacement_critical: true).includes(:component_type).find_each do |c|
|
||||||
overdue = false
|
overdue = false
|
||||||
|
|||||||
@@ -65,7 +65,15 @@ module Compliance
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspection_status(type, last_record, current_hours, today = Date.current)
|
# `records` are those that count for the type (InspectionType#records_for).
|
||||||
|
# Calendar intervals run from the latest one's date. Hour intervals run from
|
||||||
|
# the hours at the latest one, except that an inspection done late, within
|
||||||
|
# the type's hours_tolerance, is counted from when it was due (91.409(b):
|
||||||
|
# the 100-hour's 10-hour allowance counts toward the next 100 hours). Done
|
||||||
|
# early, there's no credit: the next is counted from when it was done.
|
||||||
|
def inspection_status(type, records, current_hours, today = Date.current)
|
||||||
|
records = records.to_a
|
||||||
|
last_record = records.max_by { [ _1.date, _1.created_at || Time.at(0) ] }
|
||||||
return Result.new(rank: OVERDUE) unless last_record
|
return Result.new(rank: OVERDUE) unless last_record
|
||||||
return Result.new(rank: COMPLIANT) unless type.recurring?
|
return Result.new(rank: COMPLIANT) unless type.recurring?
|
||||||
|
|
||||||
@@ -84,13 +92,11 @@ module Compliance
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
interval = type.recurring_hours.to_d
|
if (due_hours = next_due_hours(type, records))
|
||||||
if interval > 0 && (hours_at = last_record.hours_at_inspection)
|
result.next_due_hours = due_hours
|
||||||
since = current_hours - hours_at
|
if current_hours >= due_hours
|
||||||
result.next_due_hours = hours_at + interval
|
|
||||||
if since >= interval
|
|
||||||
rank = OVERDUE
|
rank = OVERDUE
|
||||||
elsif since + Airworthiness::HOURS_WARNING >= interval
|
elsif current_hours + Airworthiness::HOURS_WARNING >= due_hours
|
||||||
rank = [ rank, DUE_SOON ].max
|
rank = [ rank, DUE_SOON ].max
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -99,6 +105,19 @@ module Compliance
|
|||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def next_due_hours(type, records)
|
||||||
|
interval = type.recurring_hours.to_d
|
||||||
|
return unless interval.positive?
|
||||||
|
tolerance = type.hours_tolerance.to_d
|
||||||
|
due = nil
|
||||||
|
records.select(&:hours_at_inspection).sort_by { [ _1.date, _1.hours_at_inspection ] }.each do |r|
|
||||||
|
hours = r.hours_at_inspection.to_d
|
||||||
|
base = due && hours > due && hours - due <= tolerance ? due : hours
|
||||||
|
due = base + interval
|
||||||
|
end
|
||||||
|
due
|
||||||
|
end
|
||||||
|
|
||||||
# Rows for the ADs tab: every applicable AD with its latest compliance and status.
|
# Rows for the ADs tab: every applicable AD with its latest compliance and status.
|
||||||
AdRow = Struct.new(:ad, :latest, :status, :next_due_date, :next_due_hours, keyword_init: true)
|
AdRow = Struct.new(:ad, :latest, :status, :next_due_date, :next_due_hours, keyword_init: true)
|
||||||
|
|
||||||
@@ -123,11 +142,12 @@ module Compliance
|
|||||||
def inspection_rows(aircraft)
|
def inspection_rows(aircraft)
|
||||||
hours = aircraft.current_hours
|
hours = aircraft.current_hours
|
||||||
aircraft.applicable_inspection_types.ordered.map do |type|
|
aircraft.applicable_inspection_types.ordered.map do |type|
|
||||||
latest = type.inspection_records.for_aircraft(aircraft).recent_first.first
|
records = type.records_for(aircraft).to_a
|
||||||
|
latest = records.max_by { [ _1.date, _1.created_at || Time.at(0) ] }
|
||||||
if latest.nil?
|
if latest.nil?
|
||||||
InspectionRow.new(type: type, latest: nil, status: "never_completed")
|
InspectionRow.new(type: type, latest: nil, status: "never_completed")
|
||||||
else
|
else
|
||||||
res = inspection_status(type, latest, hours)
|
res = inspection_status(type, records, hours)
|
||||||
InspectionRow.new(type: type, latest: latest, status: res.label,
|
InspectionRow.new(type: type, latest: latest, status: res.label,
|
||||||
next_due_date: res.next_due_date, next_due_hours: res.next_due_hours)
|
next_due_date: res.next_due_date, next_due_hours: res.next_due_hours)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# Flight-activity writes: absolute hours updates and flight logs. Both cascade
|
# Flight-activity writes: absolute hours updates and flight logs. Both cascade
|
||||||
# the tach delta to every IN-USE component.
|
# the time-in-service delta (tach or Hobbs, per the aircraft's maintenance
|
||||||
|
# clock) to every IN-USE component.
|
||||||
class HoursService
|
class HoursService
|
||||||
def initialize(aircraft, user: Current.user)
|
def initialize(aircraft, user: Current.user)
|
||||||
@aircraft = aircraft
|
@aircraft = aircraft
|
||||||
@@ -17,19 +18,22 @@ class HoursService
|
|||||||
def update_hours!(tach_time:, hobbs_time: nil)
|
def update_hours!(tach_time:, hobbs_time: nil)
|
||||||
enforce_airworthiness!
|
enforce_airworthiness!
|
||||||
tach = BigDecimal(tach_time.to_s)
|
tach = BigDecimal(tach_time.to_s)
|
||||||
delta = tach - @aircraft.tach_time
|
hobbs = BigDecimal(hobbs_time.to_s) if hobbs_time.present?
|
||||||
old = @aircraft.tach_time
|
old = @aircraft.tach_time
|
||||||
|
tach_delta = tach - old
|
||||||
|
# On Hobbs time, components follow the Hobbs change (when one is given).
|
||||||
|
delta = @aircraft.hobbs? && hobbs ? hobbs - @aircraft.hobbs_time : tach_delta
|
||||||
|
|
||||||
Aircraft.transaction do
|
Aircraft.transaction do
|
||||||
@aircraft.tach_time = tach
|
@aircraft.tach_time = tach
|
||||||
@aircraft.hobbs_time = BigDecimal(hobbs_time.to_s) if hobbs_time.present?
|
@aircraft.hobbs_time = hobbs if hobbs
|
||||||
@aircraft.save!
|
@aircraft.save!
|
||||||
cascade_to_components(delta, clamp: true)
|
cascade_to_components(delta, clamp: true)
|
||||||
@aircraft.log_event!("hours",
|
@aircraft.log_event!("hours",
|
||||||
"Hours #{delta >= 0 ? 'updated' : 'corrected'} to #{tach}",
|
"Hours #{tach_delta >= 0 ? 'updated' : 'corrected'} to #{tach}",
|
||||||
user: @user, notes: "Previous: #{old}, delta: #{delta >= 0 ? '+' : ''}#{delta}")
|
user: @user, notes: "Previous: #{old}, delta: #{tach_delta >= 0 ? '+' : ''}#{tach_delta}")
|
||||||
end
|
end
|
||||||
delta
|
tach_delta
|
||||||
end
|
end
|
||||||
|
|
||||||
# Persist a flight log and apply its side effects atomically.
|
# Persist a flight log and apply its side effects atomically.
|
||||||
@@ -43,7 +47,7 @@ class HoursService
|
|||||||
@aircraft.tach_time += flight.tach_time
|
@aircraft.tach_time += flight.tach_time
|
||||||
@aircraft.hobbs_time += flight.hobbs_time if flight.hobbs_time
|
@aircraft.hobbs_time += flight.hobbs_time if flight.hobbs_time
|
||||||
@aircraft.save!
|
@aircraft.save!
|
||||||
cascade_to_components(flight.tach_time)
|
cascade_to_components(@aircraft.hobbs? && flight.hobbs_time ? flight.hobbs_time : flight.tach_time)
|
||||||
|
|
||||||
{ "oil" => [ flight.oil_added, flight.oil_level_after, flight.oil_added_type ],
|
{ "oil" => [ flight.oil_added, flight.oil_level_after, flight.oil_added_type ],
|
||||||
"fuel" => [ flight.fuel_added, flight.fuel_level_after, flight.fuel_added_type ] }.each do |type, (qty, level, kind)|
|
"fuel" => [ flight.fuel_added, flight.fuel_level_after, flight.fuel_added_type ] }.each do |type, (qty, level, kind)|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<% if rows.none?(&:url) %><p class="rounded-md bg-amber-50 px-3 py-2 text-amber-900 ring-1 ring-amber-200">This file has no links to the AD documents. DRS's <strong>Excel</strong> export includes them; import that file instead (or afterwards) to get clickable AD numbers.</p><% end %>
|
<% if rows.none?(&:url) %><p class="rounded-md bg-amber-50 px-3 py-2 text-amber-900 ring-1 ring-amber-200">This file has no links to the AD documents. DRS's <strong>Excel</strong> export includes them; import that file instead (or afterwards) to get clickable AD numbers.</p><% end %>
|
||||||
<p>Choose what to do with each AD. The suggestions are based on the FAA data and your aircraft's model (<%= @aircraft.model.presence || "not set" %>); you make the call.</p>
|
<p>Choose what to do with each AD. The suggestions are based on the FAA data and your aircraft's model (<%= @aircraft.model.presence || "not set" %>); you make the call.</p>
|
||||||
<ul class="list-disc space-y-1 pl-5 text-xs text-slate-600">
|
<ul class="list-disc space-y-1 pl-5 text-xs text-slate-600">
|
||||||
<li><strong>Track</strong>: adds the AD. Until you record compliance, it counts against airworthiness, so <%= @aircraft.tail_number %> will show <span class="badge-red">Not Airworthy</span> for each tracked AD without a compliance record.</li>
|
<li><strong>Track</strong>: adds the AD. Until you record compliance, it counts against airworthiness, so <%= @aircraft.tail_number %> will show <span class="badge-red">Grounded</span> while any tracked AD has no compliance record.</li>
|
||||||
<li><strong>Not applicable</strong>: adds the AD with an N/A record (e.g. the equipment isn't installed). You can edit the reason afterwards.</li>
|
<li><strong>Not applicable</strong>: adds the AD with an N/A record (e.g. the equipment isn't installed). You can edit the reason afterwards.</li>
|
||||||
<li><strong>Update</strong> (ADs already tracked): refreshes the FAA details: subject, summary, dates, supersession and DRS link. Compliance records aren't touched.</li>
|
<li><strong>Update</strong> (ADs already tracked): refreshes the FAA details: subject, summary, dates, supersession and DRS link. Compliance records aren't touched.</li>
|
||||||
<li><strong>Skip</strong>: not imported, or left exactly as is.</li>
|
<li><strong>Skip</strong>: not imported, or left exactly as is.</li>
|
||||||
|
|||||||
@@ -15,15 +15,18 @@
|
|||||||
<%= f.field :tach_time, as: :number, step: 0.1, label: "Current tach" %>
|
<%= f.field :tach_time, as: :number, step: 0.1, label: "Current tach" %>
|
||||||
<%= f.field :hobbs_time, as: :number, step: 0.1, label: "Current hobbs" %>
|
<%= f.field :hobbs_time, as: :number, step: 0.1, label: "Current hobbs" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= f.field :tach_time_offset, as: :number, step: 0.1, hint: "Subtracted from tach for compliance math (e.g. after a tach replacement)." %>
|
<%= f.field :tach_time_offset, as: :number, step: 0.1, hint: "Subtracted from tach for maintenance math (e.g. after a tach replacement)." %>
|
||||||
<%= f.field :hobbs_time_offset, as: :number, step: 0.1 %>
|
<%= f.field :hobbs_time_offset, as: :number, step: 0.1, hint: "The same, for Hobbs." %>
|
||||||
</div>
|
</div>
|
||||||
|
<%= f.field :time_basis, as: :select, label: "Maintenance clock", collection: Aircraft::TIME_BASES.invert,
|
||||||
|
hint: "The clock used as time in service for inspections, ADs and component times (14 CFR 1.1 defines it as takeoff to landing). " \
|
||||||
|
"Changing it doesn't convert hours already recorded against the other clock." %>
|
||||||
<% unless aircraft.new_record? %>
|
<% unless aircraft.new_record? %>
|
||||||
<p class="hint">To change hours use “Update Hours” on the overview, so component times stay in sync.</p>
|
<p class="hint">To change hours use “Update Hours” on the overview, so component times stay in sync.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= f.field :picture, as: :file, accept: "image/*" %>
|
<%= f.field :picture, as: :file, accept: "image/*" %>
|
||||||
<%= f.field :airworthiness_enforcement, as: :checkbox, label: "Enforce airworthiness",
|
<%= f.field :airworthiness_enforcement, as: :checkbox, label: "Enforce airworthiness",
|
||||||
hint: "Block flight logs and hours updates while the aircraft is red." %>
|
hint: "Block flight logs and hours updates while the aircraft shows Grounded." %>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<%= f.submit aircraft.new_record? ? "Add Aircraft" : "Save" %>
|
<%= f.submit aircraft.new_record? ? "Add Aircraft" : "Save" %>
|
||||||
<%= link_to "Cancel", aircraft.new_record? ? root_path : aircraft_path(aircraft), class: "btn-secondary" %>
|
<%= link_to "Cancel", aircraft.new_record? ? root_path : aircraft_path(aircraft), class: "btn-secondary" %>
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<% if aw.issues.any? %>
|
<% if aw.issues.any? %>
|
||||||
<ul class="mt-3 space-y-1 text-xs">
|
<ul class="mt-3 space-y-1 text-xs">
|
||||||
<% aw.issues.first(3).each do |issue| %>
|
<% aw.issues.first(3).each do |issue| %>
|
||||||
<li class="<%= issue.severity == 'RED' ? 'text-red-700' : 'text-amber-700' %>">• <%= issue.title %></li>
|
<li class="<%= issue_text_class(issue) %>">• <%= issue.title %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if aw.issues.size > 3 %><li class="text-slate-500">+ <%= aw.issues.size - 3 %> more</li><% end %>
|
<% if aw.issues.size > 3 %><li class="text-slate-500">+ <%= aw.issues.size - 3 %> more</li><% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<% if @airworthiness.issues.empty? %>
|
<% if @airworthiness.issues.empty? %>
|
||||||
<p class="text-sm text-emerald-700">No open issues. All tracked ADs, inspections, components and squawks are current.</p>
|
<p class="text-sm text-emerald-700">Nothing overdue or due soon. All tracked ADs, inspections, components and squawks are current.</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<ul class="divide-y divide-slate-100">
|
<ul class="divide-y divide-slate-100">
|
||||||
<% @airworthiness.issues.each do |issue| %>
|
<% @airworthiness.issues.each do |issue| %>
|
||||||
<li class="flex items-start gap-3 py-2">
|
<li class="flex items-start gap-3 py-2">
|
||||||
<span class="<%= issue.severity == 'RED' ? 'badge-red' : 'badge-orange' %> mt-0.5"><%= issue.category %></span>
|
<span class="<%= issue_badge_class(issue) %> mt-0.5"><%= issue.category %></span>
|
||||||
<div>
|
<div>
|
||||||
<div class="text-sm font-medium"><%= issue.title %></div>
|
<div class="text-sm font-medium"><%= issue.title %></div>
|
||||||
<div class="text-xs text-slate-500"><%= issue.description %></div>
|
<div class="text-xs text-slate-500"><%= issue.description %></div>
|
||||||
@@ -25,8 +25,9 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if @aircraft.airworthiness_enforcement? %>
|
<% if @aircraft.airworthiness_enforcement? %>
|
||||||
<p class="hint mt-3">Airworthiness enforcement is on: flights and hours updates are blocked while the status is red.</p>
|
<p class="hint mt-3">Airworthiness enforcement is on: flights and hours updates are blocked while the aircraft shows Grounded.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<p class="hint mt-3"><%= Airworthiness::DISCLAIMER %></p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<% if ad.conditional? && ad.trigger_condition.present? %><div class="text-slate-500">Trigger: <%= ad.trigger_condition %></div><% end %></td>
|
<% if ad.conditional? && ad.trigger_condition.present? %><div class="text-slate-500">Trigger: <%= ad.trigger_condition %></div><% end %></td>
|
||||||
<td class="text-xs"><%= ad.recurring? ? [ad.recurring_hours.to_f > 0 && "#{hours(ad.recurring_hours)} h", ad.recurring_months > 0 && "#{ad.recurring_months} mo"].select(&:itself).join(" / ") : "One-time" %></td>
|
<td class="text-xs"><%= ad.recurring? ? [ad.recurring_hours.to_f > 0 && "#{hours(ad.recurring_hours)} h", ad.recurring_months > 0 && "#{ad.recurring_months} mo"].select(&:itself).join(" / ") : "One-time" %></td>
|
||||||
<td class="text-xs"><%= row.latest ? "#{row.latest.date_complied}#{' (permanent)' if row.latest.permanent?}" : "—" %></td>
|
<td class="text-xs"><%= row.latest ? "#{row.latest.date_complied}#{' (permanent)' if row.latest.permanent?}" : "—" %></td>
|
||||||
<td class="text-xs"><%= [row.next_due_date&.strftime("%b %Y"), row.next_due_hours && "#{hours(row.next_due_hours)} tach (#{hours(row.next_due_hours - @aircraft.current_hours)} h left)"].compact.join(" / ").presence || "—" %></td>
|
<td class="text-xs"><%= [row.next_due_date&.strftime("%b %Y"), row.next_due_hours && "#{hours(row.next_due_hours)} #{@aircraft.time_basis} (#{hours(row.next_due_hours - @aircraft.current_hours)} h left)"].compact.join(" / ").presence || "—" %></td>
|
||||||
<td><%= compliance_badge(row.status) %></td>
|
<td><%= compliance_badge(row.status) %></td>
|
||||||
<td class="whitespace-nowrap text-right">
|
<td class="whitespace-nowrap text-right">
|
||||||
<% if owner? %>
|
<% if owner? %>
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
<%= form_with model: inspection_type, url: inspection_type.new_record? ? aircraft_inspection_types_path(aircraft) : aircraft_inspection_type_path(aircraft, inspection_type), class: "card card-body space-y-4 max-w-2xl" do |f| %>
|
<%= form_with model: inspection_type, url: inspection_type.new_record? ? aircraft_inspection_types_path(aircraft) : aircraft_inspection_type_path(aircraft, inspection_type), class: "card card-body space-y-4 max-w-2xl" do |f| %>
|
||||||
<%= f.errors_summary %>
|
<%= f.errors_summary %>
|
||||||
<%= f.field :name, required: true, placeholder: "Annual Inspection" %>
|
<%= f.field :name, required: true, placeholder: "Annual Inspection" %>
|
||||||
<div class="flex gap-6">
|
<%= f.field :effect, as: :select, label: "When overdue", collection: InspectionType::EFFECTS.invert,
|
||||||
<%= f.field :required, as: :checkbox, label: "Required for airworthiness" %>
|
hint: "An overdue pitot-static check (91.411) only rules out IFR, and an overdue transponder check (91.413) only rules out using the transponder. Neither grounds the aircraft." %>
|
||||||
<%= f.field :recurring, as: :checkbox, label: "Recurring" %>
|
<%= f.field :recurring, as: :checkbox, label: "Recurring" %>
|
||||||
</div>
|
|
||||||
<div class="grid gap-4 sm:grid-cols-3">
|
<div class="grid gap-4 sm:grid-cols-3">
|
||||||
<%= f.field :recurring_hours, as: :number, step: 0.1, label: "Every (hours)" %>
|
<%= f.field :recurring_hours, as: :number, step: 0.1, label: "Every (hours)" %>
|
||||||
<%= f.field :recurring_months, as: :number, label: "Every (calendar months)", hint: "Due end of month." %>
|
<%= f.field :recurring_months, as: :number, label: "Every (calendar months)", hint: "Due end of month." %>
|
||||||
<%= f.field :recurring_days, as: :number, label: "Every (days)" %>
|
<%= f.field :recurring_days, as: :number, label: "Every (days)" %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="grid gap-4 sm:grid-cols-2">
|
||||||
|
<%= f.field :hours_tolerance, as: :number, step: 0.1, min: 0, label: "Overrun allowance (hours)",
|
||||||
|
hint: "For the 100-hour: 10. Done late within this, the next one counts from when it was due (91.409(b))." %>
|
||||||
|
<% others = aircraft.applicable_inspection_types.ordered.where.not(id: inspection_type.id) %>
|
||||||
|
<%= f.field :satisfies_id, as: :select, label: "Also counts as", include_blank: "— Nothing else —",
|
||||||
|
collection: others.map { [ _1.name, _1.id ] },
|
||||||
|
hint: "An annual also counts as the 100-hour (91.409(b))." %>
|
||||||
|
</div>
|
||||||
<%= render "shared/applicability_fields", aircraft: aircraft, record: inspection_type, applies_to_airframe: @applies_to_airframe %>
|
<%= render "shared/applicability_fields", aircraft: aircraft, record: inspection_type, applies_to_airframe: @applies_to_airframe %>
|
||||||
<% if inspection_type.persisted? && inspection_type.aircraft.count > 1 %>
|
<% if inspection_type.persisted? && inspection_type.aircraft.count > 1 %>
|
||||||
<p class="rounded bg-amber-50 p-2 text-xs text-amber-800">This inspection type is shared with other aircraft; interval changes affect them too.</p>
|
<p class="rounded bg-amber-50 p-2 text-xs text-amber-800">This inspection type is shared with other aircraft; interval changes affect them too.</p>
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @rows.each do |row| %>
|
<% @rows.each do |row| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="font-medium"><%= row.type.name %><%= tag.span(" optional", class: "text-xs text-slate-400") unless row.type.required? %></td>
|
<td class="font-medium"><%= row.type.name %><%= tag.span(" #{row.type.advisory? ? 'advisory' : row.type.limitation.to_s.downcase + ' if overdue'}", class: "text-xs text-slate-400") if row.type.advisory? || row.type.limitation %>
|
||||||
|
<% if row.type.satisfies %><div class="text-xs text-slate-500">Also counts as <%= row.type.satisfies.name %></div><% end %></td>
|
||||||
<td class="text-xs"><%= row.type.interval_description %></td>
|
<td class="text-xs"><%= row.type.interval_description %></td>
|
||||||
<td class="text-xs"><%= row.latest ? "#{row.latest.date} @ #{hours(row.latest.hours_at_inspection)} h" : "—" %></td>
|
<td class="text-xs"><%= row.latest ? "#{row.latest.date} @ #{hours(row.latest.hours_at_inspection)} h" : "—" %></td>
|
||||||
<td class="text-xs"><%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
|
<td class="text-xs"><%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
|
||||||
|
|||||||
@@ -17,9 +17,10 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title">Airworthiness</h2><%= airworthiness_badge(@airworthiness, large: true) %></div>
|
<div class="card-header"><h2 class="card-title">Airworthiness</h2><%= airworthiness_badge(@airworthiness, large: true) %></div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<% if @airworthiness.issues.empty? %><p class="text-sm text-emerald-700">No open issues.</p><% else %>
|
<% if @airworthiness.issues.empty? %><p class="text-sm text-emerald-700">Nothing overdue or due soon.</p><% else %>
|
||||||
<ul class="space-y-1 text-sm"><% @airworthiness.issues.each do |i| %><li><span class="<%= i.severity == 'RED' ? 'badge-red' : 'badge-orange' %>"><%= i.category %></span> <%= i.title %> <span class="text-xs text-slate-500"><%= i.description %></span></li><% end %></ul>
|
<ul class="space-y-1 text-sm"><% @airworthiness.issues.each do |i| %><li><span class="<%= issue_badge_class(i) %>"><%= i.category %></span> <%= i.title %> <span class="text-xs text-slate-500"><%= i.description %></span></li><% end %></ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<p class="hint mt-3"><%= Airworthiness::DISCLAIMER %></p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Inspection rules closer to Part 91:
|
||||||
|
# - effect: what an overdue inspection means (grounded, no IFR per 91.411,
|
||||||
|
# no transponder per 91.413, or advisory)
|
||||||
|
# - satisfies: completing this type also counts as another (an annual
|
||||||
|
# satisfies the 100-hour, 91.409(b))
|
||||||
|
# - hours_tolerance: allowed overrun whose excess counts toward the next
|
||||||
|
# interval (the 100-hour's 10 hours, 91.409(b))
|
||||||
|
# - aircraft.time_basis: which clock is time in service for maintenance
|
||||||
|
class AddRegulatoryInspectionRules < ActiveRecord::Migration[8.1]
|
||||||
|
def up
|
||||||
|
add_column :inspection_types, :effect, :string, null: false, default: "grounds"
|
||||||
|
add_column :inspection_types, :hours_tolerance, :decimal, precision: 6, scale: 1, null: false, default: 0
|
||||||
|
add_reference :inspection_types, :satisfies, foreign_key: { to_table: :inspection_types, on_delete: :nullify }
|
||||||
|
add_column :aircraft, :time_basis, :string, null: false, default: "tach"
|
||||||
|
|
||||||
|
execute "UPDATE inspection_types SET effect = 'advisory' WHERE required = 0"
|
||||||
|
execute <<~SQL
|
||||||
|
UPDATE inspection_types SET effect = 'no_transponder'
|
||||||
|
WHERE required = 1 AND (LOWER(name) LIKE '%transponder%' OR name LIKE '%91.413%')
|
||||||
|
SQL
|
||||||
|
execute <<~SQL
|
||||||
|
UPDATE inspection_types SET effect = 'no_ifr'
|
||||||
|
WHERE required = 1 AND (LOWER(name) LIKE '%pitot%' OR LOWER(name) LIKE '%static%'
|
||||||
|
OR LOWER(name) LIKE '%altimeter%' OR name LIKE '%91.411%')
|
||||||
|
SQL
|
||||||
|
hundred = "(LOWER(name) LIKE '%100%hour%' OR LOWER(name) LIKE '%100%hr%')"
|
||||||
|
execute "UPDATE inspection_types SET hours_tolerance = 10 WHERE #{hundred}"
|
||||||
|
|
||||||
|
# Link annual → 100-hour only when there's exactly one of each to link.
|
||||||
|
annuals = select_values("SELECT id FROM inspection_types WHERE LOWER(name) LIKE '%annual%'")
|
||||||
|
hundreds = select_values("SELECT id FROM inspection_types WHERE #{hundred}")
|
||||||
|
if annuals.size == 1 && hundreds.size == 1 && annuals != hundreds
|
||||||
|
execute "UPDATE inspection_types SET satisfies_id = #{hundreds.first.to_i} WHERE id = #{annuals.first.to_i}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_reference :inspection_types, :satisfies, foreign_key: { to_table: :inspection_types }
|
||||||
|
remove_column :inspection_types, :hours_tolerance
|
||||||
|
remove_column :inspection_types, :effect
|
||||||
|
remove_column :aircraft, :time_basis
|
||||||
|
end
|
||||||
|
end
|
||||||
Generated
+7
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.1].define(version: 2026_11_07_180000) do
|
ActiveRecord::Schema[8.1].define(version: 2026_11_07_190000) do
|
||||||
create_table "active_storage_attachments", force: :cascade do |t|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -120,6 +120,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_180000) do
|
|||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "icao_type"
|
t.string "icao_type"
|
||||||
|
t.string "time_basis", default: "tach", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "aircraft_airworthiness_directives", id: false, force: :cascade do |t|
|
create_table "aircraft_airworthiness_directives", id: false, force: :cascade do |t|
|
||||||
@@ -396,6 +397,10 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_180000) do
|
|||||||
t.integer "recurring_months", default: 0, null: false
|
t.integer "recurring_months", default: 0, null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "effect", default: "grounds", null: false
|
||||||
|
t.decimal "hours_tolerance", precision: 6, scale: 1, default: "0.0", null: false
|
||||||
|
t.integer "satisfies_id"
|
||||||
|
t.index ["satisfies_id"], name: "index_inspection_types_on_satisfies_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "logbook_entries", force: :cascade do |t|
|
create_table "logbook_entries", force: :cascade do |t|
|
||||||
@@ -584,6 +589,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_180000) do
|
|||||||
add_foreign_key "inspection_records", "components"
|
add_foreign_key "inspection_records", "components"
|
||||||
add_foreign_key "inspection_records", "inspection_types"
|
add_foreign_key "inspection_records", "inspection_types"
|
||||||
add_foreign_key "inspection_records", "logbook_entries", on_delete: :nullify
|
add_foreign_key "inspection_records", "logbook_entries", on_delete: :nullify
|
||||||
|
add_foreign_key "inspection_types", "inspection_types", column: "satisfies_id", on_delete: :nullify
|
||||||
add_foreign_key "logbook_entries", "aircraft"
|
add_foreign_key "logbook_entries", "aircraft"
|
||||||
add_foreign_key "logbook_entries", "documents", on_delete: :nullify
|
add_foreign_key "logbook_entries", "documents", on_delete: :nullify
|
||||||
add_foreign_key "logbook_imports", "aircraft"
|
add_foreign_key "logbook_imports", "aircraft"
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ if ENV["DEMO"].present?
|
|||||||
end
|
end
|
||||||
|
|
||||||
annual = InspectionType.find_or_create_by!(name: "Annual Inspection") { _1.recurring = true; _1.recurring_months = 12 }
|
annual = InspectionType.find_or_create_by!(name: "Annual Inspection") { _1.recurring = true; _1.recurring_months = 12 }
|
||||||
xpdr = InspectionType.find_or_create_by!(name: "Transponder (91.413)") { _1.recurring = true; _1.recurring_months = 24 }
|
xpdr = InspectionType.find_or_create_by!(name: "Transponder (91.413)") { _1.recurring = true; _1.recurring_months = 24; _1.effect = "no_transponder" }
|
||||||
[ annual, xpdr ].each { |t| t.aircraft << ac unless t.aircraft.include?(ac) }
|
[ annual, xpdr ].each { |t| t.aircraft << ac unless t.aircraft.include?(ac) }
|
||||||
ac.inspection_records.find_or_create_by!(inspection_type: annual) { _1.date = 11.months.ago.to_date; _1.aircraft_hours = 4150 }
|
ac.inspection_records.find_or_create_by!(inspection_type: annual) { _1.date = 11.months.ago.to_date; _1.aircraft_hours = 4150 }
|
||||||
ac.inspection_records.find_or_create_by!(inspection_type: xpdr) { _1.date = 10.months.ago.to_date; _1.aircraft_hours = 4160 }
|
ac.inspection_records.find_or_create_by!(inspection_type: xpdr) { _1.date = 10.months.ago.to_date; _1.aircraft_hours = 4160 }
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class InspectionRulesFlowTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@owner = create_user("owner@example.com")
|
||||||
|
@a = create_aircraft(owner: @owner)
|
||||||
|
sign_in @owner
|
||||||
|
end
|
||||||
|
|
||||||
|
test "owner sets what overdue means, the overrun allowance and what an inspection also counts as" do
|
||||||
|
hundred = InspectionType.create!(name: "100-hour", recurring: true, recurring_hours: 100).tap { _1.aircraft << @a }
|
||||||
|
elsewhere = InspectionType.create!(name: "Other aircraft's", recurring: true).tap { _1.aircraft << create_aircraft }
|
||||||
|
post aircraft_inspection_types_path(@a), params: { inspection_type: {
|
||||||
|
name: "Annual", recurring: "1", recurring_months: 12, effect: "grounds", satisfies_id: hundred.id } }
|
||||||
|
annual = InspectionType.find_by!(name: "Annual")
|
||||||
|
assert_equal hundred, annual.satisfies
|
||||||
|
|
||||||
|
patch aircraft_inspection_type_path(@a, hundred), params: { inspection_type: { hours_tolerance: "10", satisfies_id: elsewhere.id } }
|
||||||
|
assert_equal [ 10, nil ], [ hundred.reload.hours_tolerance.to_i, hundred.satisfies_id ] # other aircraft's types can't be chosen
|
||||||
|
|
||||||
|
get edit_aircraft_inspection_type_path(@a, hundred)
|
||||||
|
assert_select "select[name='inspection_type[effect]'] option[value=no_ifr]"
|
||||||
|
get aircraft_inspections_path(@a)
|
||||||
|
assert_includes response.body, "Also counts as 100-hour"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "maintenance clock on the aircraft form; new records default to time in service" do
|
||||||
|
patch aircraft_path(@a), params: { aircraft: { time_basis: "hobbs", hobbs_time_offset: 0 } }
|
||||||
|
@a.update_columns(hobbs_time: 1234.5)
|
||||||
|
assert_equal "hobbs", @a.reload.time_basis
|
||||||
|
get new_aircraft_inspection_record_path(@a)
|
||||||
|
assert_select "input[name='inspection_record[aircraft_hours]'][value='1234.5']"
|
||||||
|
get aircraft_path(@a)
|
||||||
|
assert_includes response.body, "pilot in command decides whether the aircraft is airworthy"
|
||||||
|
assert_select ".badge-green", text: "Current"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
# Part 91 inspection rules: what an overdue inspection means, the annual
|
||||||
|
# counting as the 100-hour, the 100-hour's 10-hour allowance, and which clock
|
||||||
|
# is time in service.
|
||||||
|
class InspectionRulesTest < ActiveSupport::TestCase
|
||||||
|
setup { @a = create_aircraft(tach_time: 1150) }
|
||||||
|
|
||||||
|
def type(name, **attrs)
|
||||||
|
InspectionType.create!({ name: name, recurring: true }.merge(attrs)).tap { _1.aircraft << @a }
|
||||||
|
end
|
||||||
|
|
||||||
|
def done(type, date, hours = nil) = @a.inspection_records.create!(inspection_type: type, date: date, aircraft_hours: hours)
|
||||||
|
|
||||||
|
test "overdue transponder or pitot-static checks limit the aircraft instead of grounding it" do
|
||||||
|
xpdr = type("Transponder (91.413)", recurring_months: 24, effect: "no_transponder")
|
||||||
|
done(xpdr, 3.years.ago.to_date)
|
||||||
|
aw = @a.reload.airworthiness
|
||||||
|
assert [ aw.limited?, aw.can_fly? ].all?
|
||||||
|
assert_equal "No transponder", aw.label
|
||||||
|
assert_equal "LIMITED", aw.issues.sole.severity
|
||||||
|
|
||||||
|
pitot = type("Pitot-static (91.411)", recurring_months: 24, effect: "no_ifr")
|
||||||
|
done(pitot, 3.years.ago.to_date)
|
||||||
|
assert_equal "No transponder · VFR only", @a.reload.airworthiness.label
|
||||||
|
|
||||||
|
@a.update!(airworthiness_enforcement: true) # flying isn't blocked by limitations
|
||||||
|
assert_nothing_raised { HoursService.new(@a).enforce_airworthiness! }
|
||||||
|
|
||||||
|
annual = type("Annual", recurring_months: 12)
|
||||||
|
done(annual, 13.months.ago.to_date)
|
||||||
|
aw = @a.reload.airworthiness
|
||||||
|
assert_equal [ "RED", "Grounded", false ], [ aw.status, aw.label, aw.can_fly? ]
|
||||||
|
assert_raises(AircraftGroundedError) { HoursService.new(@a).enforce_airworthiness! }
|
||||||
|
end
|
||||||
|
|
||||||
|
test "advisory inspections never affect the status; a fresh aircraft reads Current" do
|
||||||
|
done(type("Wash", recurring_days: 30, effect: "advisory"), 1.year.ago.to_date)
|
||||||
|
aw = @a.reload.airworthiness
|
||||||
|
assert_equal [ "GREEN", "Current" ], [ aw.status, aw.label ]
|
||||||
|
refute InspectionType.last.required? # kept in step for archives
|
||||||
|
end
|
||||||
|
|
||||||
|
test "an annual also counts as the 100-hour" do
|
||||||
|
hundred = type("100-hour", recurring_hours: 100, hours_tolerance: 10)
|
||||||
|
annual = type("Annual", recurring_months: 12, satisfies: hundred)
|
||||||
|
done(hundred, 4.months.ago.to_date, 1000)
|
||||||
|
assert_equal 1100, Compliance.inspection_status(hundred, hundred.records_for(@a), @a.current_hours).next_due_hours
|
||||||
|
assert @a.reload.airworthiness.red? # 150 hrs since the 100-hour
|
||||||
|
|
||||||
|
done(annual, 1.month.ago.to_date, 1090)
|
||||||
|
row = Compliance.inspection_rows(@a).find { _1.type == hundred }
|
||||||
|
assert_equal [ "compliant", 1190 ], [ row.status, row.next_due_hours ]
|
||||||
|
assert_equal annual, row.latest.inspection_type
|
||||||
|
refute @a.reload.airworthiness.red?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "the 100-hour's 10-hour allowance counts toward the next interval; early gets no credit" do
|
||||||
|
hundred = type("100-hour", recurring_hours: 100, hours_tolerance: 10)
|
||||||
|
done(hundred, 300.days.ago.to_date, 1000) # due at 1100
|
||||||
|
next_due = ->(records) { Compliance.next_due_hours(hundred, records) }
|
||||||
|
|
||||||
|
late = done(hundred, 200.days.ago.to_date, 1105)
|
||||||
|
assert_equal 1200, next_due.(hundred.records_for(@a)) # counted from 1100, not 1105
|
||||||
|
late.update!(aircraft_hours: 1115) # past the allowance: from when done
|
||||||
|
assert_equal 1215, next_due.(hundred.records_for(@a))
|
||||||
|
late.update!(aircraft_hours: 1080) # early: from when done
|
||||||
|
assert_equal 1180, next_due.(hundred.records_for(@a))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "overdue within the allowance says what 91.409(b) allows" do
|
||||||
|
hundred = type("100-hour", recurring_hours: 100, hours_tolerance: 10)
|
||||||
|
done(hundred, 100.days.ago.to_date, 1045) # due 1145, now 1150
|
||||||
|
issue = @a.reload.airworthiness.issues.sole
|
||||||
|
assert_match "up to 10 hrs past due only to reach a place where it can be done", issue.description
|
||||||
|
@a.update!(tach_time: 1170)
|
||||||
|
assert_equal "Inspection overdue.", @a.reload.airworthiness.issues.sole.description
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Hobbs as the maintenance clock" do
|
||||||
|
@a.update!(hobbs_time: 1300, hobbs_time_offset: 20, time_basis: "hobbs")
|
||||||
|
assert_equal 1280, @a.current_hours
|
||||||
|
engine = create_component(@a, hours_since_overhaul: 500, hours_in_service: 500)
|
||||||
|
HoursService.new(@a).log_flight!(@a.flight_logs.new(date: Date.current, tach_time: 1.0, hobbs_time: 1.3))
|
||||||
|
assert_equal 501.3, engine.reload.hours_since_overhaul.to_f
|
||||||
|
assert_equal [ 1151, 1301.3 ], [ @a.reload.tach_time.to_f, @a.hobbs_time.to_f ]
|
||||||
|
|
||||||
|
HoursService.new(@a).update_hours!(tach_time: 1152, hobbs_time: 1302.5)
|
||||||
|
assert_equal 502.5, engine.reload.hours_since_overhaul.to_f
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in new issue
Block a user