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
+371
-63
No files matched your search
@@ -6,7 +6,7 @@ class AdCompliancesController < ApplicationController
|
||||
def new
|
||||
ad = @aircraft.applicable_ads.find_by(id: params[:ad_id])
|
||||
@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")
|
||||
@compliance.compliance_notes = "Not applicable: " if @compliance.not_applicable?
|
||||
@compliance.fill_next_due
|
||||
|
||||
@@ -68,7 +68,7 @@ class AircraftController < ApplicationController
|
||||
params.require(:aircraft).permit(
|
||||
:tail_number, :make, :model, :serial_number, :description, :purchased, :status,
|
||||
:tach_time, :tach_time_offset, :hobbs_time, :hobbs_time_offset,
|
||||
:airworthiness_enforcement, :picture, :icao_type
|
||||
:airworthiness_enforcement, :picture, :icao_type, :time_basis
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,7 @@ class InspectionRecordsController < ApplicationController
|
||||
|
||||
def new
|
||||
@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])
|
||||
end
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ class InspectionTypesController < ApplicationController
|
||||
end
|
||||
|
||||
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
|
||||
@@ -14,7 +14,7 @@ class LogbookEntriesController < ApplicationController
|
||||
def show; end
|
||||
|
||||
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
|
||||
|
||||
def create
|
||||
|
||||
@@ -11,7 +11,7 @@ class MajorRecordsController < ApplicationController
|
||||
|
||||
def new
|
||||
@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
|
||||
|
||||
def create
|
||||
|
||||
@@ -8,16 +8,25 @@ module ApplicationHelper
|
||||
value ? l(value.to_date, format: :long) : "—"
|
||||
end
|
||||
|
||||
AIRWORTHINESS_COLORS = { "RED" => "red", "LIMITED" => "blue", "ORANGE" => "orange", "GREEN" => "green" }.freeze
|
||||
|
||||
def airworthiness_badge(status, large: false)
|
||||
color = { "RED" => "red", "ORANGE" => "orange", "GREEN" => "green" }[status.status]
|
||||
tag.span(status.label, class: [ "badge-#{color}", ("text-sm px-3 py-1" if large) ])
|
||||
tag.span(status.label, class: [ "badge-#{AIRWORTHINESS_COLORS[status.status]}", ("text-sm px-3 py-1" if large) ],
|
||||
title: Airworthiness::DISCLAIMER)
|
||||
end
|
||||
|
||||
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)
|
||||
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 = {
|
||||
"compliant" => [ "green", "Compliant" ], "due_soon" => [ "orange", "Due Soon" ],
|
||||
"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.
|
||||
def fill_next_due
|
||||
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)
|
||||
self.next_due_at_time = due[:hours] if due[:hours]
|
||||
end
|
||||
@@ -35,7 +35,7 @@ class AdCompliance < ApplicationRecord
|
||||
def next_due_is_a_future_reading
|
||||
due = next_due_at_time.to_d
|
||||
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
|
||||
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")
|
||||
|
||||
+11
-2
@@ -28,7 +28,12 @@ class Aircraft < ApplicationRecord
|
||||
has_and_belongs_to_many :inspection_types
|
||||
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 :time_basis, inclusion: { in: TIME_BASES.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
|
||||
normalizes :icao_type, with: ->(t) { t.strip.upcase.presence }
|
||||
@@ -40,11 +45,15 @@ class Aircraft < ApplicationRecord
|
||||
|
||||
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
|
||||
tach_time - tach_time_offset
|
||||
hobbs? ? hobbs_time - hobbs_time_offset : tach_time - tach_time_offset
|
||||
end
|
||||
|
||||
def hobbs? = time_basis == "hobbs"
|
||||
def time_basis_label = TIME_BASES[time_basis]
|
||||
|
||||
def airworthiness
|
||||
@airworthiness ||= Airworthiness.new(self).call
|
||||
end
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
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 :components
|
||||
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 :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) }
|
||||
|
||||
@@ -15,6 +32,17 @@ class InspectionType < ApplicationRecord
|
||||
end
|
||||
|
||||
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
|
||||
{ hours: recurring_hours.to_f, months: recurring_months, days: recurring_days } if recurring?
|
||||
|
||||
@@ -119,7 +119,7 @@ module AircraftArchive
|
||||
|
||||
def aircraft_hash(a)
|
||||
{ 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),
|
||||
picture: file(a.picture, "aircraft_pictures"), icao_type: a.icao_type }
|
||||
end
|
||||
@@ -150,7 +150,8 @@ module AircraftArchive
|
||||
end
|
||||
|
||||
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,
|
||||
applicable_aircraft: t.aircraft_ids.include?(@aircraft.id) ? [ id(@aircraft) ] : [],
|
||||
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,
|
||||
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",
|
||||
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,
|
||||
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 }
|
||||
@@ -256,7 +257,9 @@ module AircraftArchive
|
||||
if type
|
||||
warn("Inspection type “#{name}” already existed here and was reused.") if type.recurring != (data["recurring"] == true)
|
||||
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_months: data["recurring_months"])
|
||||
type.save!(validate: false)
|
||||
@@ -265,6 +268,11 @@ module AircraftArchive
|
||||
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) }
|
||||
@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
|
||||
m("inspection_records").each do |data|
|
||||
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):
|
||||
# AD compliance, grounding squawks, inspection recurrency, component replacement.
|
||||
# Summarizes an aircraft's records: AD compliance, grounding squawks,
|
||||
# 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
|
||||
HOURS_WARNING = BigDecimal("10")
|
||||
DAYS_WARNING = 30
|
||||
|
||||
RED = "RED"
|
||||
LIMITED = "LIMITED"
|
||||
ORANGE = "ORANGE"
|
||||
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
|
||||
def red? = status == RED
|
||||
def limited? = status == LIMITED
|
||||
def orange? = status == ORANGE
|
||||
def green? = status == GREEN
|
||||
def can_fly? = green?
|
||||
def can_fly? = !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
|
||||
|
||||
def initialize(aircraft, today: Date.current)
|
||||
@@ -34,6 +55,7 @@ class Airworthiness
|
||||
|
||||
status =
|
||||
if @issues.any? { _1.severity == RED } then RED
|
||||
elsif @issues.any? { _1.severity == LIMITED } then LIMITED
|
||||
elsif @issues.any? { _1.severity == ORANGE } then ORANGE
|
||||
else GREEN
|
||||
end
|
||||
@@ -42,8 +64,8 @@ class Airworthiness
|
||||
|
||||
private
|
||||
|
||||
def add(category, severity, title, description, item)
|
||||
@issues << Issue.new(category:, severity:, title:, description:, item:)
|
||||
def add(category, severity, title, description, item, limitation: nil)
|
||||
@issues << Issue.new(category:, severity:, title:, description:, item:, limitation:)
|
||||
end
|
||||
|
||||
def check_ads
|
||||
@@ -68,15 +90,16 @@ class Airworthiness
|
||||
end
|
||||
|
||||
def check_inspections
|
||||
@aircraft.applicable_inspection_types.where(required: true).find_each do |type|
|
||||
last = type.inspection_records.for_aircraft(@aircraft).recent_first.first
|
||||
res = Compliance.inspection_status(type, last, @hours, @today)
|
||||
@aircraft.applicable_inspection_types.where.not(effect: "advisory").includes(:satisfied_by).find_each do |type|
|
||||
records = type.records_for(@aircraft).to_a
|
||||
res = Compliance.inspection_status(type, records, @hours, @today)
|
||||
case res.rank
|
||||
when Compliance::OVERDUE
|
||||
if last
|
||||
add("INSPECTION", RED, "#{type.name} - Overdue", "Inspection overdue.", type)
|
||||
title = "#{type.name} - #{records.any? ? 'Overdue' : 'Never Completed'}"
|
||||
if (limitation = type.limitation)
|
||||
add("INSPECTION", LIMITED, title, "#{limitation} until it's done.", type, limitation: limitation)
|
||||
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
|
||||
when Compliance::DUE_SOON
|
||||
add("INSPECTION", ORANGE, "#{type.name} - Due Soon", "Inspection due soon.", type)
|
||||
@@ -84,6 +107,19 @@ class Airworthiness
|
||||
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
|
||||
@aircraft.components.in_use.where(replacement_critical: true).includes(:component_type).find_each do |c|
|
||||
overdue = false
|
||||
|
||||
@@ -65,7 +65,15 @@ module Compliance
|
||||
result
|
||||
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: COMPLIANT) unless type.recurring?
|
||||
|
||||
@@ -84,13 +92,11 @@ module Compliance
|
||||
end
|
||||
end
|
||||
|
||||
interval = type.recurring_hours.to_d
|
||||
if interval > 0 && (hours_at = last_record.hours_at_inspection)
|
||||
since = current_hours - hours_at
|
||||
result.next_due_hours = hours_at + interval
|
||||
if since >= interval
|
||||
if (due_hours = next_due_hours(type, records))
|
||||
result.next_due_hours = due_hours
|
||||
if current_hours >= due_hours
|
||||
rank = OVERDUE
|
||||
elsif since + Airworthiness::HOURS_WARNING >= interval
|
||||
elsif current_hours + Airworthiness::HOURS_WARNING >= due_hours
|
||||
rank = [ rank, DUE_SOON ].max
|
||||
end
|
||||
end
|
||||
@@ -99,6 +105,19 @@ module Compliance
|
||||
result
|
||||
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.
|
||||
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)
|
||||
hours = aircraft.current_hours
|
||||
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?
|
||||
InspectionRow.new(type: type, latest: nil, status: "never_completed")
|
||||
else
|
||||
res = inspection_status(type, latest, hours)
|
||||
res = inspection_status(type, records, hours)
|
||||
InspectionRow.new(type: type, latest: latest, status: res.label,
|
||||
next_due_date: res.next_due_date, next_due_hours: res.next_due_hours)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# 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
|
||||
def initialize(aircraft, user: Current.user)
|
||||
@aircraft = aircraft
|
||||
@@ -17,19 +18,22 @@ class HoursService
|
||||
def update_hours!(tach_time:, hobbs_time: nil)
|
||||
enforce_airworthiness!
|
||||
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
|
||||
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.tach_time = tach
|
||||
@aircraft.hobbs_time = BigDecimal(hobbs_time.to_s) if hobbs_time.present?
|
||||
@aircraft.hobbs_time = hobbs if hobbs
|
||||
@aircraft.save!
|
||||
cascade_to_components(delta, clamp: true)
|
||||
@aircraft.log_event!("hours",
|
||||
"Hours #{delta >= 0 ? 'updated' : 'corrected'} to #{tach}",
|
||||
user: @user, notes: "Previous: #{old}, delta: #{delta >= 0 ? '+' : ''}#{delta}")
|
||||
"Hours #{tach_delta >= 0 ? 'updated' : 'corrected'} to #{tach}",
|
||||
user: @user, notes: "Previous: #{old}, delta: #{tach_delta >= 0 ? '+' : ''}#{tach_delta}")
|
||||
end
|
||||
delta
|
||||
tach_delta
|
||||
end
|
||||
|
||||
# Persist a flight log and apply its side effects atomically.
|
||||
@@ -43,7 +47,7 @@ class HoursService
|
||||
@aircraft.tach_time += flight.tach_time
|
||||
@aircraft.hobbs_time += flight.hobbs_time if flight.hobbs_time
|
||||
@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 ],
|
||||
"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 %>
|
||||
<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">
|
||||
<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>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>
|
||||
|
||||
@@ -15,15 +15,18 @@
|
||||
<%= f.field :tach_time, as: :number, step: 0.1, label: "Current tach" %>
|
||||
<%= f.field :hobbs_time, as: :number, step: 0.1, label: "Current hobbs" %>
|
||||
<% 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 :hobbs_time_offset, as: :number, step: 0.1 %>
|
||||
<%= 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, hint: "The same, for Hobbs." %>
|
||||
</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? %>
|
||||
<p class="hint">To change hours use “Update Hours” on the overview, so component times stay in sync.</p>
|
||||
<% end %>
|
||||
<%= f.field :picture, as: :file, accept: "image/*" %>
|
||||
<%= 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">
|
||||
<%= f.submit aircraft.new_record? ? "Add Aircraft" : "Save" %>
|
||||
<%= link_to "Cancel", aircraft.new_record? ? root_path : aircraft_path(aircraft), class: "btn-secondary" %>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<% if aw.issues.any? %>
|
||||
<ul class="mt-3 space-y-1 text-xs">
|
||||
<% 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 %>
|
||||
<% if aw.issues.size > 3 %><li class="text-slate-500">+ <%= aw.issues.size - 3 %> more</li><% end %>
|
||||
</ul>
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<% 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 %>
|
||||
<ul class="divide-y divide-slate-100">
|
||||
<% @airworthiness.issues.each do |issue| %>
|
||||
<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 class="text-sm font-medium"><%= issue.title %></div>
|
||||
<div class="text-xs text-slate-500"><%= issue.description %></div>
|
||||
@@ -25,8 +25,9 @@
|
||||
</ul>
|
||||
<% end %>
|
||||
<% 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 %>
|
||||
<p class="hint mt-3"><%= Airworthiness::DISCLAIMER %></p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<% 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"><%= 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 class="whitespace-nowrap text-right">
|
||||
<% 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| %>
|
||||
<%= f.errors_summary %>
|
||||
<%= f.field :name, required: true, placeholder: "Annual Inspection" %>
|
||||
<div class="flex gap-6">
|
||||
<%= f.field :required, as: :checkbox, label: "Required for airworthiness" %>
|
||||
<%= f.field :recurring, as: :checkbox, label: "Recurring" %>
|
||||
</div>
|
||||
<%= f.field :effect, as: :select, label: "When overdue", collection: InspectionType::EFFECTS.invert,
|
||||
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" %>
|
||||
<div class="grid gap-4 sm:grid-cols-3">
|
||||
<%= 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_days, as: :number, label: "Every (days)" %>
|
||||
</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 %>
|
||||
<% 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>
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
<tbody>
|
||||
<% @rows.each do |row| %>
|
||||
<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.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>
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
<section class="card">
|
||||
<div class="card-header"><h2 class="card-title">Airworthiness</h2><%= airworthiness_badge(@airworthiness, large: true) %></div>
|
||||
<div class="card-body">
|
||||
<% if @airworthiness.issues.empty? %><p class="text-sm text-emerald-700">No open issues.</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>
|
||||
<% 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="<%= issue_badge_class(i) %>"><%= i.category %></span> <%= i.title %> <span class="text-xs text-slate-500"><%= i.description %></span></li><% end %></ul>
|
||||
<% end %>
|
||||
<p class="hint mt-3"><%= Airworthiness::DISCLAIMER %></p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in new issue
Block a user