From a4ec7a691e50724b1d924c3e93e70c439b1f8a08 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 7 Nov 2026 10:14:21 -0500 Subject: [PATCH] Record keeping: 43.9/43.11 sign-off fields, AD method, status report - Logbook entries record the signer's kind of certificate and number and an inspection's result; maintenance and inspection entries list what 43.9 / 43.11 needs that's missing (flagged, not enforced). Transcription reads the certificate details too - AD compliance records the method (inspection, terminating action, AMOC, not applicable) and the AD revision complied with, filled in from the AD when blank; the method sets the permanent / N/A flags - Maintenance status report (91.417(a)(2)): total times, life-limited parts, time since overhaul, inspection and AD status, major alterations, open discrepancies; print or save as PDF; on maintenance share links too - Archives carry the new fields Co-Authored-By: Claude Opus 5.5 --- app/controllers/ad_compliances_controller.rb | 6 +- app/controllers/logbook_entries_controller.rb | 3 +- .../maintenance_reports_controller.rb | 10 ++ app/controllers/shared_controller.rb | 9 ++ app/javascript/application.js | 4 + .../controllers/next_due_controller.js | 3 +- app/jobs/logbook_transcription_job.rb | 2 + app/models/ad_compliance.rb | 32 +++- app/models/logbook_entry.rb | 36 +++++ app/services/aircraft_archive/exporter.rb | 5 +- app/services/aircraft_archive/importer.rb | 6 + app/services/logbook_transcriber/prompt.txt | 6 +- app/services/logbook_transcriber/schema.json | 4 +- app/services/maintenance_report.rb | 39 +++++ app/views/ad_compliances/_form.html.erb | 19 ++- app/views/aircraft/show.html.erb | 5 +- .../airworthiness_directives/index.html.erb | 1 + app/views/components/_form.html.erb | 3 +- app/views/layouts/report.html.erb | 20 +++ app/views/logbook_entries/_form.html.erb | 10 +- app/views/logbook_entries/index.html.erb | 3 +- app/views/logbook_entries/show.html.erb | 14 +- app/views/maintenance_reports/show.html.erb | 151 ++++++++++++++++++ app/views/shared/show.html.erb | 3 +- config/routes.rb | 2 + ...0261107200000_add_record_keeping_fields.rb | 24 +++ db/schema.rb | 7 +- test/integration/ad_import_flow_test.rb | 4 +- test/integration/logbook_import_flow_test.rb | 4 +- test/integration/record_keeping_test.rb | 106 ++++++++++++ 30 files changed, 515 insertions(+), 26 deletions(-) create mode 100644 app/controllers/maintenance_reports_controller.rb create mode 100644 app/services/maintenance_report.rb create mode 100644 app/views/layouts/report.html.erb create mode 100644 app/views/maintenance_reports/show.html.erb create mode 100644 db/migrate/20261107200000_add_record_keeping_fields.rb create mode 100644 test/integration/record_keeping_test.rb diff --git a/app/controllers/ad_compliances_controller.rb b/app/controllers/ad_compliances_controller.rb index 98da743..0afaab0 100644 --- a/app/controllers/ad_compliances_controller.rb +++ b/app/controllers/ad_compliances_controller.rb @@ -7,7 +7,8 @@ class AdCompliancesController < ApplicationController 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.current_hours, - not_applicable: params[:not_applicable] == "1") + compliance_method: params[:not_applicable] == "1" ? "not_applicable" : "inspection") + @compliance.apply_method @compliance.compliance_notes = "Not applicable: " if @compliance.not_applicable? @compliance.fill_next_due end @@ -46,7 +47,8 @@ class AdCompliancesController < ApplicationController def compliance_params p = params.require(:ad_compliance).permit( :airworthiness_directive_id, :date_complied, :compliance_notes, :permanent, :next_due_at_time, - :aircraft_hours_at_compliance, :logbook_entry_id, :inspection_record_id, :component_id, :not_applicable + :aircraft_hours_at_compliance, :logbook_entry_id, :inspection_record_id, :component_id, + :compliance_method, :ad_revision ) p[:airworthiness_directive_id] = scoped_id(@aircraft.applicable_ads, p[:airworthiness_directive_id]) p[:logbook_entry_id] = scoped_id(@aircraft.logbook_entries, p[:logbook_entry_id]) diff --git a/app/controllers/logbook_entries_controller.rb b/app/controllers/logbook_entries_controller.rb index d7c989a..2b046da 100644 --- a/app/controllers/logbook_entries_controller.rb +++ b/app/controllers/logbook_entries_controller.rb @@ -50,7 +50,8 @@ class LogbookEntriesController < ApplicationController def entry_params p = params.require(:logbook_entry).permit(:log_type, :entry_type, :date, :text, :signoff_person, - :signoff_location, :aircraft_hours_at_entry, :document_id, :page_number) + :signoff_location, :aircraft_hours_at_entry, :document_id, :page_number, + :signoff_certificate_type, :signoff_certificate_number, :inspection_result) p[:document_id] = scoped_id(@aircraft.documents, p[:document_id]) p end diff --git a/app/controllers/maintenance_reports_controller.rb b/app/controllers/maintenance_reports_controller.rb new file mode 100644 index 0000000..c8a2bb4 --- /dev/null +++ b/app/controllers/maintenance_reports_controller.rb @@ -0,0 +1,10 @@ +# Printable maintenance status report (Print / Save as PDF in the browser). +class MaintenanceReportsController < ApplicationController + include AircraftScoped + + def show + @report = MaintenanceReport.new(@aircraft) + log_event("aircraft", "Maintenance status report viewed") if params[:print] + render layout: "report" + end +end diff --git a/app/controllers/shared_controller.rb b/app/controllers/shared_controller.rb index d7608d0..0558483 100644 --- a/app/controllers/shared_controller.rb +++ b/app/controllers/shared_controller.rb @@ -5,6 +5,15 @@ class SharedController < ApplicationController skip_before_action :redirect_to_setup layout "public" + # The maintenance status report, for "Maintenance Detail" links (mechanics, + # inspectors, buyers). + def report + @share = ShareToken.find_active(params[:token]) or raise ActiveRecord::RecordNotFound + raise ActiveRecord::RecordNotFound unless @share.maintenance? + @report = MaintenanceReport.new(@share.aircraft) + render "maintenance_reports/show", layout: "report" + end + def show @share = ShareToken.find_active(params[:token]) or raise ActiveRecord::RecordNotFound @aircraft = @share.aircraft diff --git a/app/javascript/application.js b/app/javascript/application.js index 7dd46de..344b302 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -56,3 +56,7 @@ document.addEventListener("click", (event) => { document.addEventListener("change", (event) => { if (event.target.matches?.("[data-submit-on-change]")) event.target.form?.requestSubmit() }) + +document.addEventListener("click", (event) => { + if (event.target.closest?.("[data-print]")) window.print() +}) diff --git a/app/javascript/controllers/next_due_controller.js b/app/javascript/controllers/next_due_controller.js index fc2f0f8..111f808 100644 --- a/app/javascript/controllers/next_due_controller.js +++ b/app/javascript/controllers/next_due_controller.js @@ -60,6 +60,7 @@ export default class extends Controller { } get isPermanent() { - return this.permanentTargets.some((el) => el.checked) + // A checkbox ticked, or the method select on terminating action / N/A. + return this.permanentTargets.some((el) => el.tagName === "SELECT" ? [ "terminating", "not_applicable" ].includes(el.value) : el.checked) } } diff --git a/app/jobs/logbook_transcription_job.rb b/app/jobs/logbook_transcription_job.rb index 0aa147a..707f8a8 100644 --- a/app/jobs/logbook_transcription_job.rb +++ b/app/jobs/logbook_transcription_job.rb @@ -121,6 +121,8 @@ class LogbookTranscriptionJob < ApplicationJob date: date, text: text, log_type: log_type, entry_type: LogbookEntry::ENTRY_TYPES.key?(entry["entry_type"]) ? entry["entry_type"] : "OTHER", signoff_person: entry["signoff_person"].presence, signoff_location: entry["signoff_location"].presence, + signoff_certificate_type: LogbookEntry::CERTIFICATE_TYPES.key?(entry["signoff_certificate_type"]) ? entry["signoff_certificate_type"] : nil, + signoff_certificate_number: entry["signoff_certificate_number"].to_s.strip.first(40).presence, aircraft_hours_at_entry: entry["aircraft_hours"].is_a?(Numeric) && entry["aircraft_hours"] >= 0 ? entry["aircraft_hours"] : nil, document: @document, page_number: page_number ) diff --git a/app/models/ad_compliance.rb b/app/models/ad_compliance.rb index a185b69..21e5ae4 100644 --- a/app/models/ad_compliance.rb +++ b/app/models/ad_compliance.rb @@ -1,4 +1,12 @@ class AdCompliance < ApplicationRecord + # Method of compliance, recorded per 91.417(a)(2)(v). + METHODS = { + "inspection" => "Inspection", + "terminating" => "Terminating action (no further action)", + "amoc" => "Alternative method of compliance (AMOC)", + "not_applicable" => "Not applicable to this aircraft" + }.freeze + belongs_to :airworthiness_directive belongs_to :aircraft, optional: true belongs_to :component, optional: true @@ -6,6 +14,9 @@ class AdCompliance < ApplicationRecord belongs_to :inspection_record, optional: true validates :date_complied, :compliance_notes, presence: true + validates :compliance_method, inclusion: { in: METHODS.keys } + before_validation :apply_method + before_validation :fill_revision validate { errors.add(:base, "Must belong to an aircraft or component") unless aircraft_id || component_id } validate :next_due_is_a_future_reading before_validation :fill_next_due, if: -> { next_due_at_time.to_d.zero? } @@ -21,6 +32,23 @@ class AdCompliance < ApplicationRecord self.next_due_at_time = due[:hours] if due[:hours] end + def method_label = METHODS[compliance_method] + + # The method decides the closing flags (kept for archives shared with the + # original app): terminating action is permanent, N/A is not applicable. + def apply_method + self.compliance_method ||= not_applicable? ? "not_applicable" : (permanent? ? "terminating" : "inspection") + self.not_applicable = compliance_method == "not_applicable" + self.permanent = true if compliance_method == "terminating" + end + + # The AD number and revision date complied with, from the AD if left blank. + def fill_revision + return if ad_revision.present? || airworthiness_directive.nil? + ad = airworthiness_directive + self.ad_revision = [ ad.name, ("effective #{ad.effective_date.iso8601}" if ad.effective_date) ].compact.join(", ") + end + # Permanent compliance or a not-applicable determination: never due again. def closed? = permanent? || not_applicable? @@ -30,14 +58,14 @@ class AdCompliance < ApplicationRecord private - # next_due_at_time is an absolute tach reading, not an interval. Catch the + # next_due_at_time is an absolute clock reading, not an interval. Catch the # easy mistake of entering "100" for "every 100 hours". 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&.current_hours 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 #{aircraft&.time_basis || 'tach'} reading after the compliance hours (#{base}). " \ "For “every 100 hours” enter #{base + 100}, not 100") end end diff --git a/app/models/logbook_entry.rb b/app/models/logbook_entry.rb index 1aa494c..113bb37 100644 --- a/app/models/logbook_entry.rb +++ b/app/models/logbook_entry.rb @@ -5,6 +5,20 @@ class LogbookEntry < ApplicationRecord "HOURS_UPDATE" => "Hours Update", "OTHER" => "Other" }.freeze + # Kind of certificate of the person approving return to service (43.9(a)(4)). + CERTIFICATE_TYPES = { + "AP" => "A&P mechanic", "IA" => "A&P with Inspection Authorization", "A" => "Mechanic, airframe only", + "P" => "Mechanic, powerplant only", "REPAIR_STATION" => "Repair station", "REPAIRMAN" => "Repairman", + "PILOT" => "Pilot (preventive maintenance)", "OTHER" => "Other" + }.freeze + # An inspection entry ends with one of these (43.11(a)(5)). + INSPECTION_RESULTS = { + "approved" => "Airworthy, approved for return to service", + "discrepancies" => "Not approved: discrepancy list given to the owner" + }.freeze + # Entries that 43.9 / 43.11 set requirements for. + RECORD_TYPES = %w[MAINTENANCE INSPECTION].freeze + belongs_to :aircraft belongs_to :document, optional: true has_many :inspection_records, dependent: :nullify @@ -13,6 +27,9 @@ class LogbookEntry < ApplicationRecord validates :date, :text, presence: true validates :log_type, inclusion: { in: LOG_TYPES.keys } validates :entry_type, inclusion: { in: ENTRY_TYPES.keys } + validates :signoff_certificate_type, inclusion: { in: CERTIFICATE_TYPES.keys }, allow_blank: true + validates :inspection_result, inclusion: { in: INSPECTION_RESULTS.keys }, allow_blank: true + normalizes :signoff_certificate_type, :inspection_result, :signoff_certificate_number, with: ->(v) { v.strip.presence } scope :recent_first, -> { order(date: :desc, created_at: :desc) } @@ -23,4 +40,23 @@ class LogbookEntry < ApplicationRecord end def to_s = "#{date} — #{LOG_TYPES[log_type]}" + def certificate_label = CERTIFICATE_TYPES[signoff_certificate_type] + def inspection_result_label = INSPECTION_RESULTS[inspection_result] + + # What a maintenance (43.9) or inspection (43.11) entry is missing. Not + # enforced: older and transcribed entries often lack these, and the signed + # logbook is the record of truth. Shown so gaps can be filled in. + def missing_record_items + return [] unless RECORD_TYPES.include?(entry_type) + missing = [] + missing << "description of the work" if text.blank? + missing << "signer's name" if signoff_person.blank? + missing << "kind of certificate" if signoff_certificate_type.blank? + missing << "certificate number" if signoff_certificate_number.blank? + if entry_type == "INSPECTION" + missing << "aircraft time in service" if aircraft_hours_at_entry.blank? + missing << "airworthiness result" if inspection_result.blank? + end + missing + end end diff --git a/app/services/aircraft_archive/exporter.rb b/app/services/aircraft_archive/exporter.rb index 23051dc..5c1a521 100644 --- a/app/services/aircraft_archive/exporter.rb +++ b/app/services/aircraft_archive/exporter.rb @@ -66,6 +66,7 @@ module AircraftArchive ads: ads.map { ad_hash(_1, component_ids) }, ad_compliances: a.ad_compliances.map do |c| { id: id(c), ad_id: id(c.airworthiness_directive_id), date_complied: c.date_complied&.iso8601, compliance_notes: c.compliance_notes, + compliance_method: c.compliance_method, ad_revision: c.ad_revision, permanent: c.permanent, next_due_at_time: dec(c.next_due_at_time), aircraft_hours_at_compliance: dec(c.aircraft_hours_at_compliance), logbook_entry_id: id(c.logbook_entry_id), inspection_record_id: id(c.inspection_record_id), aircraft_id: id(a), component_id: id(c.component_id), not_applicable: c.not_applicable } @@ -136,7 +137,9 @@ module AircraftArchive def logbook_hash(e) { id: id(e), aircraft_id: id(e.aircraft_id), log_type: e.log_type, date: e.date&.iso8601, text: e.text, - signoff_person: e.signoff_person, signoff_location: e.signoff_location, log_image_id: id(e.document_id), + signoff_person: e.signoff_person, signoff_location: e.signoff_location, + signoff_certificate_type: e.signoff_certificate_type, signoff_certificate_number: e.signoff_certificate_number, + inspection_result: e.inspection_result, log_image_id: id(e.document_id), aircraft_hours_at_entry: dec(e.aircraft_hours_at_entry), component_hours: {}, entry_type: e.entry_type, page_number: e.page_number, components: [], related_documents: [] } end diff --git a/app/services/aircraft_archive/importer.rb b/app/services/aircraft_archive/importer.rb index e934a4e..cf7a062 100644 --- a/app/services/aircraft_archive/importer.rb +++ b/app/services/aircraft_archive/importer.rb @@ -223,6 +223,9 @@ module AircraftArchive entry_type: LogbookEntry::ENTRY_TYPES.key?(data["entry_type"]) ? data["entry_type"] : LogbookEntry::ENTRY_TYPES.keys.first, date: date(data["date"]) || Date.new(1900, 1, 1), text: data["text"].to_s.presence || "—", signoff_person: data["signoff_person"], signoff_location: data["signoff_location"], + signoff_certificate_type: LogbookEntry::CERTIFICATE_TYPES.key?(data["signoff_certificate_type"]) ? data["signoff_certificate_type"] : nil, + signoff_certificate_number: data["signoff_certificate_number"].to_s.presence, + inspection_result: LogbookEntry::INSPECTION_RESULTS.key?(data["inspection_result"]) ? data["inspection_result"] : nil, aircraft_hours_at_entry: num(data["aircraft_hours_at_entry"]), page_number: data["page_number"], document_id: @map[:document][data["log_image_id"].to_s] ) @@ -318,11 +321,14 @@ module AircraftArchive c = @aircraft.ad_compliances.new( airworthiness_directive_id: ad_id, date_complied: date(data["date_complied"]) || Date.new(1900, 1, 1), compliance_notes: data["compliance_notes"].to_s, permanent: data["permanent"] == true, + compliance_method: AdCompliance::METHODS.key?(data["compliance_method"]) ? data["compliance_method"] : nil, + ad_revision: data["ad_revision"].to_s.presence, next_due_at_time: num(data["next_due_at_time"]) || 0, aircraft_hours_at_compliance: num(data["aircraft_hours_at_compliance"]), logbook_entry_id: @map[:logbook][data["logbook_entry_id"].to_s], inspection_record_id: @map[:inspection_record][data["inspection_record_id"].to_s], component_id: @map[:component][data["component_id"].to_s], not_applicable: data["not_applicable"] == true ) + c.apply_method # older archives have only the permanent / not-applicable flags c.save!(validate: false) tick("ad_compliances") end diff --git a/app/services/logbook_transcriber/prompt.txt b/app/services/logbook_transcriber/prompt.txt index 11ba8de..603e487 100644 --- a/app/services/logbook_transcriber/prompt.txt +++ b/app/services/logbook_transcriber/prompt.txt @@ -26,7 +26,11 @@ Fields: - log_type: AC (airframe), ENG (engine), PROP (propeller), or OTHER - text: the entry text verbatim, or a close paraphrase where wording is unclear; write [?] for illegible words - aircraft_hours: the tach/total time the entry records (a number), or null if none is written -- signoff_person / signoff_location: a string, or null +- signoff_person / signoff_location: a string, or null (the person's name only; certificate details go below) +- signoff_certificate_type: the kind of certificate written with the signature: AP (A&P), IA (A&P with + Inspection Authorization), A (airframe only), P (powerplant only), REPAIR_STATION (repair station + number), REPAIRMAN, PILOT (pilot certificate, for owner preventive maintenance), OTHER, or null +- signoff_certificate_number: the certificate or repair station number exactly as written, or null - page_start / page_end: page indices within this request - confidence: high (clearly legible), medium (some guesswork), low (mostly illegible) - unparseable_pages: pages too illegible to extract anything from diff --git a/app/services/logbook_transcriber/schema.json b/app/services/logbook_transcriber/schema.json index 80098f0..e2f12a7 100644 --- a/app/services/logbook_transcriber/schema.json +++ b/app/services/logbook_transcriber/schema.json @@ -13,12 +13,14 @@ "aircraft_hours": { "type": ["number", "null"] }, "signoff_person": { "type": ["string", "null"] }, "signoff_location": { "type": ["string", "null"] }, + "signoff_certificate_type": { "type": ["string", "null"], "description": "AP, IA, A, P, REPAIR_STATION, REPAIRMAN, PILOT, OTHER, or null" }, + "signoff_certificate_number": { "type": ["string", "null"] }, "page_start": { "type": "integer" }, "page_end": { "type": "integer" }, "confidence": { "type": "string", "enum": ["high", "medium", "low"] } }, "required": ["date", "log_type", "entry_type", "text", "aircraft_hours", "signoff_person", "signoff_location", - "page_start", "page_end", "confidence"], + "signoff_certificate_type", "signoff_certificate_number", "page_start", "page_end", "confidence"], "additionalProperties": false } }, diff --git a/app/services/maintenance_report.rb b/app/services/maintenance_report.rb new file mode 100644 index 0000000..42eaa87 --- /dev/null +++ b/app/services/maintenance_report.rb @@ -0,0 +1,39 @@ +# The aircraft's maintenance status as 14 CFR 91.417(a)(2) lists it: +# total time in service (airframe, engines, propellers), life-limited parts, +# time since overhaul, inspection status, AD status and major alterations. +class MaintenanceReport + attr_reader :aircraft, :generated_at + + def initialize(aircraft) + @aircraft = aircraft + @generated_at = Time.current + end + + def time_in_service = aircraft.current_hours + + # Engines and propellers, by component type name. + def engines = major_components(/engine/i) + def propellers = major_components(/propell?er|\bprop\b/i) + + # Parts with a mandatory replacement time (life limits). + def life_limited + in_use.select { |c| c.replacement_critical? && (c.replacement_hours || c.replacement_days) } + end + + # Items overhauled on a time basis. + def overhaul_items + in_use.select { |c| c.tbo_hours || c.tbo_days } + end + + def inspections = @inspections ||= Compliance.inspection_rows(aircraft) + def ads = @ads ||= Compliance.ad_rows(aircraft) + def major_records = aircraft.major_records.recent_first.includes(:component, :form_337_document, :stc_document) + def open_squawks = aircraft.squawks.active.by_priority.includes(:component) + def airworthiness = aircraft.airworthiness + + private + + def in_use = @in_use ||= aircraft.components.in_use.includes(:component_type).order(:install_location).to_a + + def major_components(pattern) = in_use.select { |c| c.component_type&.name.to_s.match?(pattern) } +end diff --git a/app/views/ad_compliances/_form.html.erb b/app/views/ad_compliances/_form.html.erb index bb8dacc..b0cdf49 100644 --- a/app/views/ad_compliances/_form.html.erb +++ b/app/views/ad_compliances/_form.html.erb @@ -7,21 +7,26 @@ data: { next_due_target: "rule", action: "change->next-due#changed" } %>
<%= f.field :date_complied, as: :date, data: { next_due_target: "date", action: "change->next-due#changed" } %> - <%= f.field :aircraft_hours_at_compliance, as: :number, step: 0.1, label: "Aircraft hours (tach)", + <%= f.field :aircraft_hours_at_compliance, as: :number, step: 0.1, label: "Aircraft hours (#{aircraft.time_basis_label.downcase})", data: { next_due_target: "hours", action: "input->next-due#changed" } %> - <%= f.field :next_due_at_time, as: :number, step: 0.1, label: "Next due at tach reading", + <%= f.field :next_due_at_time, as: :number, step: 0.1, label: "Next due at #{aircraft.time_basis_label.downcase} reading", hint: "Calculated from the AD's recurrence; you can override it. Leave 0 if not hour-based.", data: { next_due_target: "dueHours", action: "input->next-due#markManual" } %> <%= f.field :component_id, as: :select, label: "Component", collection: component_options(aircraft) %> <%= f.field :logbook_entry_id, as: :select, label: "Logbook entry", collection: logbook_options(aircraft) %>
- <%= f.field :permanent, as: :checkbox, label: "Permanently complied (terminating action)", +
+ <%= f.field :compliance_method, as: :select, label: "Method of compliance", collection: AdCompliance::METHODS.invert, + data: { next_due_target: "permanent", action: "change->next-due#changed" } %> + <%= f.field :ad_revision, label: "AD revision complied with", placeholder: "e.g. 2011-10-09 R1, effective 2011-06-01", + hint: "AD number and revision or effective date (91.417(a)(2)(v)). Left blank, it's taken from the AD." %> +
+ <%= f.field :permanent, as: :checkbox, label: "No further action required (ends the recurring requirement)", + hint: "Set automatically for terminating action; tick it for an AMOC that ends the recurrence.", data: { next_due_target: "permanent", action: "change->next-due#changed" } %> - <%= f.field :not_applicable, as: :checkbox, label: "Not applicable to this aircraft", - hint: "E.g. serial number outside the affected range, or the equipment isn't installed. Record why below.", - data: { next_due_target: "permanent", action: "change->next-due#changed" } %> - <%= f.field :compliance_notes, as: :textarea, label: "Method of compliance / reason", rows: 3, required: true %> + <%= f.field :compliance_notes, as: :textarea, label: "Details", rows: 3, required: true, + hint: "What was done and per which paragraph of the AD; for not applicable, why (e.g. serial number outside the affected range, equipment not installed)." %>
<%= f.submit "Save" %><%= link_to "Cancel", aircraft_airworthiness_directives_path(aircraft), class: "btn-secondary" %>
<% end %> <% if compliance.persisted? %>
<%= delete_button "Delete record", aircraft_ad_compliance_path(aircraft, compliance) %>
<% end %> diff --git a/app/views/aircraft/show.html.erb b/app/views/aircraft/show.html.erb index 990cbb8..ad4fcc5 100644 --- a/app/views/aircraft/show.html.erb +++ b/app/views/aircraft/show.html.erb @@ -6,7 +6,10 @@

Airworthiness

- <%= airworthiness_badge(@airworthiness, large: true) %> +
+ <%= link_to "Status report", aircraft_report_path(@aircraft), class: "btn-secondary btn-sm", title: "Printable maintenance status (91.417)" %> + <%= airworthiness_badge(@airworthiness, large: true) %> +
<% if @airworthiness.issues.empty? %> diff --git a/app/views/airworthiness_directives/index.html.erb b/app/views/airworthiness_directives/index.html.erb index 9020d39..c3023a1 100644 --- a/app/views/airworthiness_directives/index.html.erb +++ b/app/views/airworthiness_directives/index.html.erb @@ -69,6 +69,7 @@ <%= hours(c.aircraft_hours_at_compliance) %> <%= c.not_applicable? ? "N/A" : c.permanent? ? "Permanent" : (c.next_due_at_time.to_f > 0 ? hours(c.next_due_at_time) : "—") %> +
<%= c.method_label %><%= " · #{c.ad_revision}" if c.ad_revision.present? %>
<%= c.compliance_notes %> <% if c.logbook_entry || c.inspection_record %>
diff --git a/app/views/components/_form.html.erb b/app/views/components/_form.html.erb index 54e04d5..345d724 100644 --- a/app/views/components/_form.html.erb +++ b/app/views/components/_form.html.erb @@ -31,7 +31,8 @@ <%= f.field :tbo_hours, as: :number, label: "TBO (hrs)" %> <%= f.field :tbo_days, as: :number, label: "TBO (days)" %>
- <%= f.field :tbo_critical, as: :checkbox, label: "TBO critical" %> + <%= f.field :tbo_critical, as: :checkbox, label: "Treat TBO as a hard limit", + hint: "Under Part 91, TBO is usually the manufacturer's recommendation, unless an AD or the Airworthiness Limitations make it mandatory." %> <%= f.field :on_condition, as: :checkbox, label: "On condition (Part 91)" %>
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %> diff --git a/app/views/layouts/report.html.erb b/app/views/layouts/report.html.erb new file mode 100644 index 0000000..a06ab2c --- /dev/null +++ b/app/views/layouts/report.html.erb @@ -0,0 +1,20 @@ + + + + <%= [content_for(:title), "Simple Aircraft Manager"].compact.join(" · ") %> + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> + + + +
<%= yield %>
+ + diff --git a/app/views/logbook_entries/_form.html.erb b/app/views/logbook_entries/_form.html.erb index 9f06073..b5b2658 100644 --- a/app/views/logbook_entries/_form.html.erb +++ b/app/views/logbook_entries/_form.html.erb @@ -7,8 +7,16 @@ <%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Aircraft hours" %>
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8 %> +

A maintenance entry needs a description of the work, the date, and the name, signature, certificate number and kind of certificate of whoever approved the return to service (14 CFR 43.9). An inspection entry also needs the type and extent of the inspection, the aircraft's time in service, and the result (43.11).

+
+ <%= f.field :signoff_person, label: "Signed off by", placeholder: "Name" %> + <%= f.field :signoff_certificate_type, as: :select, label: "Kind of certificate", include_blank: "—", + collection: LogbookEntry::CERTIFICATE_TYPES.invert %> + <%= f.field :signoff_certificate_number, label: "Certificate number", placeholder: "e.g. 1234567" %> +
- <%= f.field :signoff_person, label: "Signed off by", placeholder: "Name, A&P/IA #" %> + <%= f.field :inspection_result, as: :select, label: "Inspection result", include_blank: "— Not an inspection —", + collection: LogbookEntry::INSPECTION_RESULTS.invert, hint: "For inspection entries (43.11)." %> <%= f.field :signoff_location, label: "Location / shop" %> <%= f.field :document_id, as: :select, label: "Scanned page document", collection: document_options(aircraft) %> <%= f.field :page_number, as: :number, label: "Page # in document" %> diff --git a/app/views/logbook_entries/index.html.erb b/app/views/logbook_entries/index.html.erb index ccc7e80..83fe422 100644 --- a/app/views/logbook_entries/index.html.erb +++ b/app/views/logbook_entries/index.html.erb @@ -24,7 +24,8 @@ <%= LogbookEntry::ENTRY_TYPES[e.entry_type] %> <%= hours(e.aircraft_hours_at_entry) %> <%= e.text.truncate(220) %> <%= "📄" if e.document %> - <%= e.signoff_person %><% if e.signoff_location.present? %>
<%= e.signoff_location %><% end %> + <%= e.signoff_person %><%= " ##{e.signoff_certificate_number}" if e.signoff_certificate_number %><% if e.signoff_location.present? %>
<%= e.signoff_location %><% end %> + <% if (missing = e.missing_record_items).any? %>
Incomplete<% end %> <% end %> diff --git a/app/views/logbook_entries/show.html.erb b/app/views/logbook_entries/show.html.erb index f613fd8..79019f2 100644 --- a/app/views/logbook_entries/show.html.erb +++ b/app/views/logbook_entries/show.html.erb @@ -10,7 +10,19 @@ Aircraft hours: <%= hours(@entry.aircraft_hours_at_entry) %>
<%= @entry.text %>
-
Signed off: <%= @entry.signoff_person.presence || "—" %> <%= "(#{@entry.signoff_location})" if @entry.signoff_location.present? %>
+
+ Signed off: <%= @entry.signoff_person.presence || "—" %> + <%= ", #{@entry.certificate_label}" if @entry.certificate_label %><%= " ##{@entry.signoff_certificate_number}" if @entry.signoff_certificate_number %> + <%= "(#{@entry.signoff_location})" if @entry.signoff_location.present? %> +
+ <% if @entry.inspection_result %>
Result: <%= @entry.inspection_result_label %>
<% end %> + <% if (missing = @entry.missing_record_items).any? %> +

+ Missing for <%= @entry.entry_type == "INSPECTION" ? "43.11" : "43.9" %>: <%= missing.to_sentence %>. + <%= link_to("Fill in", edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "link") if owner? %> + (Check against the signed logbook.) +

+ <% end %> <% if @entry.document %>

Scan: <%= link_to @entry.document.name, aircraft_document_path(@aircraft, @entry.document, page: @entry.page_number), class: "link" %><%= " (page #{@entry.page_number})" if @entry.page_number %>

<% end %> diff --git a/app/views/maintenance_reports/show.html.erb b/app/views/maintenance_reports/show.html.erb new file mode 100644 index 0000000..a5549cb --- /dev/null +++ b/app/views/maintenance_reports/show.html.erb @@ -0,0 +1,151 @@ +<% a = @report.aircraft %> +<% clock = a.time_basis_label.downcase %> +<% content_for :title, "#{a.tail_number} Maintenance Status" %> +<% section = "mt-6 break-inside-avoid-page" %> +<% th = "border-b border-slate-300 py-1 pr-3 text-left text-[11px] font-semibold uppercase tracking-wide text-slate-500" %> +<% td = "border-b border-slate-100 py-1 pr-3 align-top" %> + +
+ <% back = @share ? shared_path(@share.token) : aircraft_path(a) %> + <%= link_to "← Back", back, class: "link text-sm" %> + +
+ +
+
+

Maintenance status · 14 CFR 91.417(a)(2)

+

<%= a.tail_number %> <%= [ a.make, a.model ].compact_blank.join(" ") %>

+

Serial number <%= a.serial_number.presence || "—" %>

+
+
+
Prepared
<%= l(@report.generated_at.to_date, format: :long) %>
+
Airframe time in service
<%= hours(@report.time_in_service) %> hrs (<%= clock %>)
+
Tach / Hobbs
<%= hours(a.tach_time) %> / <%= hours(a.hobbs_time) %>
+
Status
<%= airworthiness_badge(@report.airworthiness) %>
+
+
+ +
+

Total time in service: engines and propellers

+ <% majors = @report.engines + @report.propellers %> + <% if majors.any? %> + + + + <% majors.each do |c| %> + + + <% end %> + +
ItemMake / modelSerialTotal timeSince overhaulOverhauled
<%= c %><%= [ c.manufacturer, c.model ].compact_blank.join(" ") %><%= c.serial_number.presence || "—" %><%= hours(c.hours_in_service) %><%= hours(c.hours_since_overhaul) %><%= c.overhaul_date || "—" %>
+ <% else %>

No engines or propellers recorded as components.

<% end %> +
+ +
+

Life-limited parts

+ <% if @report.life_limited.any? %> + + + + <% @report.life_limited.each do |c| %> + + + + + + <% end %> + +
PartSerialLimitUsedRemainingStatus
<%= c %> <%= c.model %><%= c.serial_number.presence || "—" %><%= [ (c.replacement_hours && "#{hours(c.replacement_hours)} hrs"), (c.replacement_days && "#{c.replacement_days} days") ].compact.join(" / ") %><%= hours(c.hours_since_overhaul) %> hrs<%= [ (c.hours_to_replacement && "#{hours(c.hours_to_replacement)} hrs"), (c.next_replacement_date && "by #{c.next_replacement_date}") ].compact.join(", ") %><%= life_badge(c.life_status) %>
+ <% else %>

None recorded.

<% end %> +
+ +
+

Time since overhaul

+ <% if @report.overhaul_items.any? %> + + + + <% @report.overhaul_items.each do |c| %> + + + + + + <% end %> + +
ItemSerialOverhaul intervalSince overhaulRemainingTracked as
<%= c %> <%= c.model %><%= c.serial_number.presence || "—" %><%= [ (c.tbo_hours && "#{hours(c.tbo_hours)} hrs"), (c.tbo_days && "#{c.tbo_days} days") ].compact.join(" / ") %><%= hours(c.hours_since_overhaul) %> hrs<%= c.on_condition? ? "On condition" : (c.hours_to_tbo ? "#{hours(c.hours_to_tbo)} hrs" : "—") %><%= c.tbo_critical? ? "Hard limit" : "Recommended" %>
+ <% else %>

None recorded.

<% end %> +
+ +
+

Inspection status

+ <% if @report.inspections.any? %> + + + + <% @report.inspections.each do |row| %> + <% last = row.latest %> + + + + + + + <% end %> + +
InspectionIntervalLast doneSinceNext dueStatus
<%= row.type.name %><% if row.type.satisfies %>
Also counts as <%= row.type.satisfies.name %>
<% end %>
<%= row.type.interval_description %><%= last ? "#{last.date}#{" @ #{hours(last.hours_at_inspection)}" if last.hours_at_inspection}" : "Never" %><%= " (#{last.inspection_type.name})" if last && last.inspection_type != row.type %><%= last&.hours_at_inspection ? "#{hours(@report.time_in_service - last.hours_at_inspection)} hrs" : "—" %><%= [ row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} hrs" ].compact.join(" / ").presence || "—" %><%= compliance_badge(row.status) %>
+ <% else %>

No inspections tracked.

<% end %> +
+ +
+

Airworthiness directives

+ <% if @report.ads.any? %> + + + + <% @report.ads.each do |row| %> + <% c = row.latest %> + + + + + + + <% end %> + +
ADRevision complied withMethod of complianceCompliedRecurring / next dueStatus
<%= row.ad.name %>
<%= row.ad.short_description.to_s.truncate(70) %>
<%= c&.ad_revision.presence || "—" %><%= c ? c.method_label : "—" %><% if c&.compliance_notes.present? %>
<%= c.compliance_notes.truncate(90) %>
<% end %>
<%= c ? "#{c.date_complied}#{" @ #{hours(c.aircraft_hours_at_compliance)}" if c.aircraft_hours_at_compliance}" : "—" %><%= if c&.closed? then "No further action" + elsif row.ad.recurring? then [ row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} hrs" ].compact.join(" / ").presence || "Recurring" + else "One-time" end %><%= compliance_badge(row.status) %>
+ <% else %>

No ADs tracked.

<% end %> +
+ +
+

Major repairs and alterations

+ <% if (majors = @report.major_records.to_a).any? %> + + + + <% majors.each do |m| %> + + + + + <% end %> + +
DateTypeDescriptionSTCForm 337
<%= m.date_performed %><%= m.type_label %><%= m.title %><%= " · #{m.component}" if m.component %><%= [ m.stc_number, m.stc_holder ].compact_blank.join(", ").presence || "—" %><%= m.form_337_document ? "On file" : "—" %>
+ <% else %>

None recorded.

<% end %> +
+ +
+

Open discrepancies

+ <% if (squawks = @report.open_squawks.to_a).any? %> +
    + <% squawks.each do |s| %>
  • <%= squawk_priority_badge(s) %> <%= s.issue_reported %><%= " · #{s.component}" if s.component %> (<%= s.created_at.to_date %>)
  • <% end %> +
+ <% else %>

None open.

<% end %> +
+ +
+ Prepared <%= l(@report.generated_at, format: :long) %> from the records kept in Simple Aircraft Manager. Times are in hours of <%= clock %> time. + This summary doesn't replace the aircraft's signed maintenance records. <%= Airworthiness::DISCLAIMER %> +
diff --git a/app/views/shared/show.html.erb b/app/views/shared/show.html.erb index 4cfd71a..b8eb1b9 100644 --- a/app/views/shared/show.html.erb +++ b/app/views/shared/show.html.erb @@ -15,7 +15,8 @@
-

Airworthiness

<%= airworthiness_badge(@airworthiness, large: true) %>
+

Airworthiness

+
<% if @share.maintenance? %><%= link_to "Status report", shared_report_path(@share.token), class: "btn-secondary btn-sm" %><% end %><%= airworthiness_badge(@airworthiness, large: true) %>
<% if @airworthiness.issues.empty? %>

Nothing overdue or due soon.

<% else %>
    <% @airworthiness.issues.each do |i| %>
  • <%= i.category %> <%= i.title %> <%= i.description %>
  • <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 31a6e63..8b71f0d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,6 +78,7 @@ Rails.application.routes.draw do resources :aircraft_roles, path: "access", only: %i[index create update destroy] resources :share_tokens, only: %i[create destroy] resource :export, controller: "aircraft_exports", only: :show + resource :report, controller: "maintenance_reports", only: :show resources :events, only: :index end @@ -85,6 +86,7 @@ Rails.application.routes.draw do # Public read-only share links (no login). get "shared/:token", to: "shared#show", as: :shared + get "shared/:token/report", to: "shared#report", as: :shared_report namespace :admin do get "about", to: "about#show" diff --git a/db/migrate/20261107200000_add_record_keeping_fields.rb b/db/migrate/20261107200000_add_record_keeping_fields.rb new file mode 100644 index 0000000..528006c --- /dev/null +++ b/db/migrate/20261107200000_add_record_keeping_fields.rb @@ -0,0 +1,24 @@ +# What 14 CFR 43.9 / 43.11 and 91.417(a)(2)(v) want in the records: +# the signer's certificate (kind and number), an inspection's outcome, and +# each AD's method of compliance and the revision complied with. +class AddRecordKeepingFields < ActiveRecord::Migration[8.1] + def up + add_column :logbook_entries, :signoff_certificate_type, :string + add_column :logbook_entries, :signoff_certificate_number, :string + add_column :logbook_entries, :inspection_result, :string + add_column :ad_compliances, :compliance_method, :string + add_column :ad_compliances, :ad_revision, :string + + execute "UPDATE ad_compliances SET compliance_method = 'not_applicable' WHERE not_applicable = 1" + execute "UPDATE ad_compliances SET compliance_method = 'terminating' WHERE compliance_method IS NULL AND permanent = 1" + execute "UPDATE ad_compliances SET compliance_method = 'inspection' WHERE compliance_method IS NULL" + end + + def down + remove_column :logbook_entries, :signoff_certificate_type + remove_column :logbook_entries, :signoff_certificate_number + remove_column :logbook_entries, :inspection_result + remove_column :ad_compliances, :compliance_method + remove_column :ad_compliances, :ad_revision + end +end diff --git a/db/schema.rb b/db/schema.rb index 2657e46..3240da9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_11_07_190000) do +ActiveRecord::Schema[8.1].define(version: 2026_11_07_200000) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -53,6 +53,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_190000) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "not_applicable", default: false, null: false + t.string "compliance_method" + t.string "ad_revision" t.index ["aircraft_id"], name: "index_ad_compliances_on_aircraft_id" t.index ["airworthiness_directive_id"], name: "index_ad_compliances_on_airworthiness_directive_id" t.index ["component_id"], name: "index_ad_compliances_on_component_id" @@ -416,6 +418,9 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_190000) do t.integer "page_number" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "signoff_certificate_type" + t.string "signoff_certificate_number" + t.string "inspection_result" t.index ["aircraft_id"], name: "index_logbook_entries_on_aircraft_id" t.index ["document_id"], name: "index_logbook_entries_on_document_id" end diff --git a/test/integration/ad_import_flow_test.rb b/test/integration/ad_import_flow_test.rb index 65fca4f..4241976 100644 --- a/test/integration/ad_import_flow_test.rb +++ b/test/integration/ad_import_flow_test.rb @@ -38,9 +38,9 @@ class AdImportFlowTest < ActionDispatch::IntegrationTest ad.aircraft << @aircraft sign_in @owner get new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id, not_applicable: 1) - assert_select "input[name='ad_compliance[not_applicable]'][checked]" + assert_select "select[name='ad_compliance[compliance_method]'] option[selected][value=not_applicable]" post aircraft_ad_compliances_path(@aircraft), params: { ad_compliance: { - airworthiness_directive_id: ad.id, date_complied: Date.current, not_applicable: "1", + airworthiness_directive_id: ad.id, date_complied: Date.current, compliance_method: "not_applicable", compliance_notes: "Not applicable: no BRS parachute installed" } } assert_equal "GREEN", @aircraft.reload.airworthiness.status end diff --git a/test/integration/logbook_import_flow_test.rb b/test/integration/logbook_import_flow_test.rb index 1a02c79..d112b3d 100644 --- a/test/integration/logbook_import_flow_test.rb +++ b/test/integration/logbook_import_flow_test.rb @@ -29,7 +29,8 @@ class LogbookImportFlowTest < ActionDispatch::IntegrationTest def entry(text, page_start, page_end = page_start, **extra) { date: "2026-01-05", log_type: "ENG", entry_type: "MAINTENANCE", text: text, aircraft_hours: 1990.5, - signoff_person: "J. Mechanic A&P 1234567", signoff_location: "KOQU", page_start: page_start, page_end: page_end, + signoff_person: "J. Mechanic", signoff_location: "KOQU", signoff_certificate_type: "AP", + signoff_certificate_number: "1234567", page_start: page_start, page_end: page_end, confidence: "high" }.merge(extra) end @@ -93,6 +94,7 @@ class LogbookImportFlowTest < ActionDispatch::IntegrationTest entries = @a.logbook_entries.order(:id) assert_equal [ "Changed oil", "Annual inspection, found airworthy", "[date unreadable] Replaced [?] gasket" ], entries.map(&:text) + assert_equal [ "J. Mechanic", "AP", "1234567" ], entries.first.then { [ _1.signoff_person, _1.signoff_certificate_type, _1.signoff_certificate_number ] } assert_equal [ 1, 2, 3 ], entries.map(&:page_number) assert entries.all? { _1.document == document && _1.log_type == "ENG" } assert_equal [ "MAINTENANCE", "INSPECTION", "MAINTENANCE" ], entries.map(&:entry_type) diff --git a/test/integration/record_keeping_test.rb b/test/integration/record_keeping_test.rb new file mode 100644 index 0000000..57da516 --- /dev/null +++ b/test/integration/record_keeping_test.rb @@ -0,0 +1,106 @@ +require "test_helper" + +# 43.9 / 43.11 logbook fields, structured AD compliance (91.417(a)(2)(v)) and +# the maintenance status report (91.417(a)(2)). +class RecordKeepingTest < ActionDispatch::IntegrationTest + setup do + @owner = create_user("owner@example.com") + @pilot = create_user("pilot@example.com") + @a = create_aircraft(owner: @owner, pilot: @pilot, serial_number: "17200001", make: "Cessna", model: "172N") + end + + test "logbook entries record the signer's certificate and an inspection's result, and show what's missing" do + sign_in @owner + post aircraft_logbook_entries_path(@a), params: { logbook_entry: { + date: "2026-10-01", log_type: "AC", entry_type: "INSPECTION", text: "Annual inspection IAW Part 43 App. D", + aircraft_hours_at_entry: 1000, signoff_person: "Jane Mechanic" } } + entry = @a.logbook_entries.last + assert_equal [ "kind of certificate", "certificate number", "airworthiness result" ], entry.missing_record_items + get aircraft_logbook_entries_path(@a) + assert_select ".badge-orange[title*='certificate number']", text: "Incomplete" + get aircraft_logbook_entry_path(@a, entry) + assert_includes response.body, "Missing for 43.11: kind of certificate, certificate number, and airworthiness result." + + patch aircraft_logbook_entry_path(@a, entry), params: { logbook_entry: { + signoff_certificate_type: "IA", signoff_certificate_number: " 1234567 ", inspection_result: "approved" } } + entry.reload + assert_equal [ [], "1234567", "A&P with Inspection Authorization" ], [ entry.missing_record_items, entry.signoff_certificate_number, entry.certificate_label ] + get aircraft_logbook_entry_path(@a, entry) + assert_includes response.body, "Airworthy, approved for return to service" + + flight = @a.logbook_entries.create!(date: Date.current, text: "Test flight", entry_type: "FLIGHT") + assert_empty flight.missing_record_items # 43.9 / 43.11 don't cover these + refute @a.logbook_entries.new(date: Date.current, text: "x", signoff_certificate_type: "BOGUS").valid? + end + + test "AD compliance records the method and the revision; the method sets the closing flags" do + ad = AirworthinessDirective.create!(name: "2011-10-09", short_description: "Seat rails", recurring: true, recurring_hours: 100, + effective_date: Date.new(2011, 6, 1)) + ad.aircraft << @a + sign_in @owner + post aircraft_ad_compliances_path(@a), params: { ad_compliance: { + airworthiness_directive_id: ad.id, date_complied: "2026-10-01", aircraft_hours_at_compliance: 1000, + compliance_method: "terminating", compliance_notes: "Installed secondary seat stop P/N 123 per para (g)" } } + c = @a.ad_compliances.last + assert_equal [ "terminating", true, false, "2011-10-09, effective 2011-06-01" ], + [ c.compliance_method, c.permanent?, c.not_applicable?, c.ad_revision ] + + get new_aircraft_ad_compliance_path(@a, ad_id: ad.id, not_applicable: 1) + assert_select "select[name='ad_compliance[compliance_method]'] option[selected][value=not_applicable]" + na = @a.ad_compliances.create!(airworthiness_directive: ad, date_complied: Date.current, compliance_method: "not_applicable", + compliance_notes: "S/N outside effectivity", ad_revision: "2011-10-09 R1") + assert [ na.not_applicable?, na.closed? ].all? + assert_equal "2011-10-09 R1", na.ad_revision + + legacy = @a.ad_compliances.new(airworthiness_directive: ad, date_complied: Date.current, compliance_notes: "x", permanent: true) + legacy.valid? + assert_equal "terminating", legacy.compliance_method # inferred from the old flags + get aircraft_airworthiness_directives_path(@a) + assert_includes response.body, "Terminating action (no further action) · 2011-10-09, effective 2011-06-01" + end + + test "the maintenance status report covers 91.417(a)(2), for crew and maintenance share links only" do + engine = create_component(@a, component_type: component_type("Engine"), serial_number: "L-12345-27A", + hours_in_service: 3200, hours_since_overhaul: 850, tbo_hours: 2000, tbo_critical: false, + overhaul_date: Date.new(2019, 5, 1)) + create_component(@a, component_type: component_type("ELT Battery"), model: "E-04", manufacturer: "ACK", + replacement_critical: true, replacement_days: 730, overhaul_date: 1.year.ago.to_date) + annual = InspectionType.create!(name: "Annual", recurring: true, recurring_months: 12).tap { _1.aircraft << @a } + @a.inspection_records.create!(inspection_type: annual, date: 2.months.ago.to_date, aircraft_hours: 990) + ad = AirworthinessDirective.create!(name: "2020-01-01", short_description: "Muffler inspection", recurring: true, recurring_hours: 100) + ad.aircraft << @a + @a.ad_compliances.create!(airworthiness_directive: ad, date_complied: 1.month.ago.to_date, aircraft_hours_at_compliance: 995, + compliance_method: "inspection", compliance_notes: "Inspected muffler, no cracks") + @a.major_records.create!(record_type: "alteration", title: "Garmin GTX 345 installed", date_performed: Date.new(2024, 3, 1), + stc_number: "SA01234WI", form_337_document: @a.documents.create!(name: "337", doc_type: "ALTER")) + + sign_in @pilot + get aircraft_path(@a) + assert_select "a[href='#{aircraft_report_path(@a)}']", text: "Status report" + get aircraft_report_path(@a) + assert_response :success + body = response.body + [ "Maintenance status · 14 CFR 91.417(a)(2)", "17200001", "L-12345-27A", "3,200.0", "850.0", "Recommended", + "ELT Battery", "Annual", "Revision complied with", "Inspection", "Inspected muffler", "1,095.0 hrs", + "Garmin GTX 345 installed", "SA01234WI", "On file", "This summary doesn't replace the aircraft's signed maintenance records" ].each do |text| + assert_includes body, text, "missing: #{text}" + end + assert_select "button[data-print]", text: "Print or save as PDF" + assert_equal engine, MaintenanceReport.new(@a).engines.sole + + sign_in create_user + get aircraft_report_path(@a) + assert_response :not_found + + status_link = @a.share_tokens.create!(privilege: "status") + detail_link = @a.share_tokens.create!(privilege: "maintenance") + delete session_path + get shared_report_path(status_link.token) + assert_response :not_found + get shared_path(detail_link.token) + assert_select "a[href='#{shared_report_path(detail_link.token)}']" + get shared_report_path(detail_link.token) + assert_response :success + assert_includes response.body, "L-12345-27A" + end +end