Logbook entries link a component and its times; boxed page printouts

- An entry can link a component (engine, propeller…) and records its total
  time and time since overhaul at the entry; picking the engine or prop log
  selects that component and fills its current times (editable). Squawk
  fixes carry the squawk's component
- Components have an overhaul type (major, factory overhaul, factory new),
  shown as SMOH / SFOH / SNEW
- Printouts: engine and propeller entries add the serial number, total
  time and SMOH/SFOH (blanks when no component is linked); airframe total
  time is labelled as such; full-page layouts draw a box around each entry
- Archives carry the entry's component and times (the original format's
  components / component_hours), no longer dropped on import

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 11:19:44 -05:00
1 parent aa262065b2
commit a51f78ebf3
21 files changed
+265 -83

No files matched your search

+1 -1
View File
@@ -104,7 +104,7 @@ To back up or move a single aircraft with all its files, use **Access & Sharing
| New ADs | Weekly search of the Federal Register for newly published ADs mentioning the aircraft, engine or propeller models (or your own terms). Review each: track it as an AD or dismiss it. |
| AD import | Import ADs from an FAA DRS export (`.xlsx` recommended: its AD numbers link to each AD's DRS page, which the import keeps; `.csv` works without links). ADs are matched by number, so nothing is duplicated. The preview suggests Track, Not applicable or Skip for each AD, and flags superseded or non-current ADs, model mismatches, appliance or STC-only ADs, and repetitive actions. |
| Inspections | Shared inspection types with hour, month, and day recurrence, plus history. Each says what overdue means (grounded, no IFR, no transponder, advisory); an annual can also count as the 100-hour, and the 100-hour's 10-hour overrun is credited (91.409(b)). One click adds the standard Part 91 set. |
| Logbook | Maintenance entries with search and a link to a scanned document page. Records the signer's certificate kind and number and an inspection's result, and flags what 43.9 / 43.11 needs that's missing. Entries transcribed by Claude stay "unverified" until someone checks them against the scan. Templates for pilot preventive maintenance (43.3(g), Part 43 Appendix A(c)). Print entries as a PDF on Avery 5163/5164 labels or half-letter/letter pages to sign and put in the paper logbook. |
| Logbook | Maintenance entries with search and a link to a scanned document page. Records the signer's certificate kind and number and an inspection's result, and flags what 43.9 / 43.11 needs that's missing. Entries transcribed by Claude stay "unverified" until someone checks them against the scan. Templates for pilot preventive maintenance (43.3(g), Part 43 Appendix A(c)). Engine and propeller entries link the component and record its total time and time since overhaul (SMOH/SFOH/SNEW) at the entry. Print entries as a PDF on Avery 5163/5164 labels or half-letter/letter pages (boxed) to sign and put in the paper logbook. |
| Documents | Collections, multi-file documents with a page viewer, per-document share visibility, bulk upload, and expiration dates (registration, insurance…). |
| Major repairs and alterations | Form 337, STC, and ICA tracking; an STC's ICA can become a tracked recurring inspection. |
| Weight & balance | History of empty weight and CG (linked to the alteration that changed them) and a loading calculator: takeoff and landing weight and CG against max gross and the CG envelope. |
+1 -1
View File
@@ -76,7 +76,7 @@ class ComponentsController < ApplicationController
params.require(:component).permit(
:component_type_id, :parent_component_id, :manufacturer, :model, :serial_number,
:install_location, :notes, :status, :date_in_service, :hours_in_service,
:hours_since_overhaul, :overhaul_date, :tbo_hours, :tbo_days, :inspection_hours,
:hours_since_overhaul, :overhaul_date, :overhaul_kind, :tbo_hours, :tbo_days, :inspection_hours,
:inspection_days, :replacement_hours, :replacement_days, :tbo_critical, :on_condition,
:inspection_critical, :replacement_critical, :expires_on
).tap do |p|
@@ -63,8 +63,10 @@ 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_certificate_type, :signoff_certificate_number, :inspection_result, :verified)
:signoff_certificate_type, :signoff_certificate_number, :inspection_result, :verified,
:component_id, :component_hours_at_entry, :component_since_overhaul_at_entry)
p[:document_id] = scoped_id(@aircraft.documents, p[:document_id])
p[:component_id] = scoped_id(@aircraft.components, p[:component_id]) if p.key?(:component_id)
p
end
end
+1 -1
View File
@@ -18,7 +18,7 @@ class LogbookPrintsController < ApplicationController
def set_entries
ids = Array(params[:ids]).map(&:to_i).first(200)
@entries = @aircraft.logbook_entries.where(id: ids).includes(inspection_records: :inspection_type).order(:date, :id).to_a
@entries = @aircraft.logbook_entries.where(id: ids).includes(:component, inspection_records: :inspection_type).order(:date, :id).to_a
redirect_to aircraft_logbook_entries_path(@aircraft), alert: "Choose the entries to print." if @entries.empty?
end
end
+10 -3
View File
@@ -42,7 +42,11 @@ class SquawksController < ApplicationController
def resolution
@entry = @aircraft.logbook_entries.new(date: Date.current, entry_type: "MAINTENANCE", log_type: "AC",
aircraft_hours_at_entry: @aircraft.current_hours,
text: "Corrected: #{@squawk.issue_reported}")
text: "Corrected: #{@squawk.issue_reported}", component: @squawk.component,
component_hours_at_entry: @squawk.component&.hours_in_service,
component_since_overhaul_at_entry: @squawk.component&.hours_since_overhaul)
@entry.log_type = "ENG" if @squawk.component&.engine?
@entry.log_type = "PROP" if @squawk.component&.propeller?
end
def resolve
@@ -95,8 +99,11 @@ class SquawksController < ApplicationController
def set_squawk = @squawk = @aircraft.squawks.find(params[:id])
def resolution_entry_params
params.require(:logbook_entry).permit(:date, :log_type, :text, :aircraft_hours_at_entry, :signoff_person,
:signoff_certificate_type, :signoff_certificate_number, :signoff_location)
p = params.require(:logbook_entry).permit(:date, :log_type, :text, :aircraft_hours_at_entry, :signoff_person,
:signoff_certificate_type, :signoff_certificate_number, :signoff_location,
:component_id, :component_hours_at_entry, :component_since_overhaul_at_entry)
p[:component_id] = scoped_id(@aircraft.components, p[:component_id]) if p.key?(:component_id)
p
end
# Adds uploads and drops ticked files in one change, so nothing is saved
@@ -0,0 +1,25 @@
import { Controller } from "@hotwired/stimulus"
// Logbook entry form: picking an engine or propeller log selects that
// component (if none is chosen yet), and picking a component fills in its
// current total time and time since overhaul.
export default class extends Controller {
static targets = [ "logType", "component", "total", "since" ]
logTypeChanged() {
if (this.componentTarget.value) return
const kind = this.logTypeTarget.value
const match = [ ...this.componentTarget.options ].find((o) => o.dataset.kind && o.dataset.kind === kind)
if (match) {
this.componentTarget.value = match.value
this.componentChanged()
}
}
componentChanged() {
const option = this.componentTarget.selectedOptions[0]
if (!option?.dataset.total) return
this.totalTarget.value = option.dataset.total
this.sinceTarget.value = option.dataset.since
}
}
+8
View File
@@ -1,5 +1,8 @@
class Component < ApplicationRecord
STATUSES = { "SPARE" => "Spare Part", "IN-USE" => "In Service", "DISPOSED" => "Disposed" }.freeze
# What "since overhaul" counts from, and how logbooks abbreviate it.
OVERHAUL_KINDS = { "major" => "Major overhaul", "factory_overhaul" => "Factory overhaul", "factory_new" => "Factory new or rebuilt (zero time)" }.freeze
OVERHAUL_ABBREVIATIONS = { "major" => "SMOH", "factory_overhaul" => "SFOH", "factory_new" => "SNEW" }.freeze
belongs_to :aircraft, optional: true
belongs_to :parent_component, class_name: "Component", optional: true
@@ -11,11 +14,13 @@ class Component < ApplicationRecord
has_many :ad_compliances, dependent: :nullify
has_many :inspection_records, dependent: :nullify
has_many :major_records, dependent: :nullify
has_many :logbook_entries, dependent: :nullify
has_and_belongs_to_many :inspection_types
has_and_belongs_to_many :airworthiness_directives
validates :manufacturer, :model, :date_in_service, presence: true
validates :status, inclusion: { in: STATUSES.keys }
validates :overhaul_kind, inclusion: { in: OVERHAUL_KINDS.keys }, allow_blank: true
validate :parent_on_same_aircraft
scope :in_use, -> { where(status: "IN-USE") }
@@ -25,6 +30,9 @@ class Component < ApplicationRecord
end
def status_label = STATUSES[status]
def since_overhaul_abbreviation = OVERHAUL_ABBREVIATIONS.fetch(overhaul_kind, "TSO")
def engine? = component_type&.name.to_s.match?(/engine/i)
def propeller? = component_type&.name.to_s.match?(/propell?er|\bprop\b/i)
def hours_to_tbo
tbo_hours - hours_since_overhaul if tbo_hours
+3
View File
@@ -21,6 +21,8 @@ class LogbookEntry < ApplicationRecord
belongs_to :aircraft
belongs_to :document, optional: true
# For engine / propeller logs: which one, and its times at this entry.
belongs_to :component, optional: true
has_many :inspection_records, dependent: :nullify
has_many :ad_compliances, dependent: :nullify
has_many :squawks, dependent: :nullify
@@ -30,6 +32,7 @@ class LogbookEntry < ApplicationRecord
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
validates :component_hours_at_entry, :component_since_overhaul_at_entry, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
normalizes :signoff_certificate_type, :inspection_result, :signoff_certificate_number, with: ->(v) { v.strip.presence }
scope :recent_first, -> { order(date: :desc, created_at: :desc) }
+5 -2
View File
@@ -147,8 +147,11 @@ module AircraftArchive
signoff_certificate_type: e.signoff_certificate_type, signoff_certificate_number: e.signoff_certificate_number,
inspection_result: e.inspection_result, verified: e.verified, transcription_confidence: e.transcription_confidence,
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: [] }
aircraft_hours_at_entry: dec(e.aircraft_hours_at_entry), entry_type: e.entry_type, page_number: e.page_number,
components: [ id(e.component_id) ].compact,
component_hours: e.component_id ? { id(e.component_id) => dec(e.component_hours_at_entry) }.compact : {},
component_since_overhaul: e.component_id ? { id(e.component_id) => dec(e.component_since_overhaul_at_entry) }.compact : {},
related_documents: [] }
end
def squawk_hash(s)
+13 -3
View File
@@ -104,6 +104,9 @@ module AircraftArchive
def m(key) = Array(@manifest[key]).select { _1.is_a?(Hash) }
# {component id => value} as exported (keys may be strings or numbers).
def hash_value(hash, key) = hash.is_a?(Hash) ? (hash[key.to_s] || hash[key]) : nil
def import_all
import_aircraft
import_component_types
@@ -219,7 +222,7 @@ module AircraftArchive
end
def import_logbook
linked = 0
dropped = 0
m("logbook_entries").each do |data|
e = @aircraft.logbook_entries.new(
log_type: LogbookEntry::LOG_TYPES.key?(data["log_type"]) ? data["log_type"] : "AC",
@@ -234,12 +237,19 @@ module AircraftArchive
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]
)
# One component per entry here (the original allows several): the first, with its times.
if (ref = Array(data["components"]).first) && (component_id = @map[:component][ref.to_s])
e.component_id = component_id
e.component_hours_at_entry = num(hash_value(data["component_hours"], ref))
e.component_since_overhaul_at_entry = num(hash_value(data["component_since_overhaul"], ref))
dropped += 1 if Array(data["components"]).size > 1
end
e.save!(validate: false)
@map[:logbook][data["id"].to_s] = e.id
linked += 1 if Array(data["components"]).any? || data["component_hours"].present?
tick("logbook_entries")
end
warn("#{linked} logbook #{linked == 1 ? 'entry was' : 'entries were'} linked to components; those links aren't kept here.") if linked.positive?
warn("#{dropped} logbook #{dropped == 1 ? 'entry was' : 'entries were'} linked to several components; only the first is kept here.") if dropped.positive?
end
def import_squawks
+108 -57
View File
@@ -3,10 +3,14 @@ Prawn::Fonts::AFM.hide_m17n_warning = true # text is reduced to what the built-i
# Logbook entries as a PDF to print and put in the paper logbook: on
# adhesive labels or on pages. Each entry carries what 14 CFR 43.9 / 43.11
# want (aircraft, date, time in service, the work, the signer's name and
# want (aircraft, date, airframe total time, the work, the signer's name and
# certificate) and a blank line for the signature, which must be signed by
# hand. On labels, long entries shrink to fit, then continue on the next
# label; on pages, entries follow one another, each with its signature line.
# hand. Engine and propeller entries add the component's serial number, total
# time and time since overhaul (blanks to fill in when no component is linked).
#
# Labels: one entry per label; long entries shrink to fit, then continue on
# the next label. Pages: entries follow one another, each in a box with its
# signature line; one too long for a page continues in a box on the next.
class LogbookEntryPdf
IN = 72 # points per inch
@@ -23,11 +27,17 @@ class LogbookEntryPdf
cols: 2, rows: 5, width: 4 * IN, height: 2 * IN, left: 0.156 * IN, top: 0.5 * IN,
col_gap: 0.188 * IN, row_gap: 0, padding: 0.12 * IN),
Layout.new(key: "half_letter", label: "Half-letter pages (5½ × 8½ in)", page: [ 5.5 * IN, 8.5 * IN ],
cols: 1, rows: 1, width: 5.5 * IN, height: 8.5 * IN, left: 0, top: 0, col_gap: 0, row_gap: 0, padding: 0.5 * IN),
cols: 1, rows: 1, width: 5.5 * IN, height: 8.5 * IN, left: 0, top: 0, col_gap: 0, row_gap: 0, padding: 0.4 * IN),
Layout.new(key: "letter", label: "Letter pages (8½ × 11 in, also full-sheet labels)", page: [ 8.5 * IN, 11 * IN ],
cols: 1, rows: 1, width: 8.5 * IN, height: 11 * IN, left: 0, top: 0, col_gap: 0, row_gap: 0, padding: 0.75 * IN)
cols: 1, rows: 1, width: 8.5 * IN, height: 11 * IN, left: 0, top: 0, col_gap: 0, row_gap: 0, padding: 0.6 * IN)
].freeze
# Type sizes: [small (details), body, smallest body when shrinking].
LABEL_SIZES = [ 6.5, 8, 5.5 ].freeze
PAGE_SIZES = [ 9, 11, 11 ].freeze
BOX_PADDING = 8 # inside a page entry's box
BOX_GAP = 12 # between boxes
def self.layout(key) = LAYOUTS.find { _1.key == key } || LAYOUTS.first
def initialize(aircraft, entries, layout:, start_at: 1)
@@ -43,63 +53,32 @@ class LogbookEntryPdf
info = { Title: "#{@aircraft.tail_number} logbook entries", Creator: "Simple Aircraft Manager" }
if @layout.labels?
@pdf = Prawn::Document.new(page_size: @layout.page, margin: 0, info: info)
@entries.each { |entry| place(entry) }
@entries.each { place_on_labels(_1) }
else
@pdf = Prawn::Document.new(page_size: @layout.page, margin: @layout.padding, info: info)
@entries.each_with_index { |entry, i| flow(entry, first: i.zero?) }
@pdf.number_pages clean("#{@aircraft.tail_number} · page <page> of <total>"), at: [ 0, -@layout.padding / 2 ], width: @pdf.bounds.width,
align: :right, size: 7, color: "777777"
@entries.each { place_on_pages(_1) }
@pdf.number_pages clean("#{@aircraft.tail_number} · page <page> of <total>"), at: [ 0, -@layout.padding / 2 ],
width: @pdf.bounds.width, align: :right, size: 7, color: "777777"
end
@pdf.render
end
private
# Pages: the entry's lines, then its signature block (kept together),
# then a rule before the next one.
def flow(entry, first:)
small = 9
w = @pdf.bounds.width
unless first
@pdf.move_down 10
@pdf.stroke_color "BBBBBB"
@pdf.stroke_horizontal_rule
@pdf.move_down 12
end
@pdf.start_new_page if @pdf.cursor < 90 # don't strand a heading at the foot of a page
@pdf.text clean(header_line), size: small, style: :bold
@pdf.text clean("#{LogbookEntry::LOG_TYPES[entry.log_type]} log · #{facts(entry).join(' ')}"), size: small
@pdf.move_down 4
@pdf.text clean(body_text(entry)), size: 11, leading: 1.5
@pdf.move_down 10
height = signature_block_height(small) + 14
@pdf.start_new_page if @pdf.cursor < height
@pdf.bounding_box([ 0, @pdf.cursor ], width: w, height: height) { signature_block(entry, w, height, small, more: false) }
end
# ---- Labels ----
def header_line
[ @aircraft.tail_number, [ @aircraft.make, @aircraft.model ].compact_blank.join(" ").presence,
(@aircraft.serial_number.present? ? "S/N #{@aircraft.serial_number}" : nil) ].compact.join(" · ")
end
def facts(entry)
[ "Date: #{entry.date&.strftime('%b %-d, %Y')}",
(entry.aircraft_hours_at_entry && "Total time: #{format('%.1f', entry.aircraft_hours_at_entry)} hrs (#{@aircraft.time_basis})") ].compact
end
def place(entry)
def place_on_labels(entry)
remaining = body_text(entry)
continued = false
loop do
box = next_box
remaining = draw(entry, box, remaining, continued: continued)
remaining = draw(entry, next_label, remaining, continued: continued, sizes: LABEL_SIZES, shrink: true, continue_note: "label")
break if remaining.blank?
continued = true
end
end
# The next free label (or page): [x, y_top, width, height] inside the padding.
def next_box
# The next free label: [x, y_top, width, height] inside its padding.
def next_label
if @slot >= @layout.per_page
@pdf.start_new_page
@slot = 0
@@ -112,37 +91,109 @@ class LogbookEntryPdf
[ x, y, @layout.width - 2 * @layout.padding, @layout.height - 2 * @layout.padding ]
end
# Draws one label's worth; returns the body text that didn't fit.
def draw(entry, (x, y, w, h), body, continued:)
small = @layout.labels? ? 6.5 : 9
base = @layout.labels? ? 8 : 11
# ---- Pages ----
def place_on_pages(entry)
remaining = body_text(entry)
continued = false
w = @pdf.bounds.width
loop do
needed = box_height(entry, remaining, w)
# A new page if the box doesn't fit here but would on a fresh page, or
# too little of this page is left to be worth starting it.
@pdf.start_new_page if needed > @pdf.cursor && (needed <= @pdf.bounds.height || @pdf.cursor < 160)
h = [ needed, @pdf.cursor ].min
top = @pdf.cursor
@pdf.stroke_color "444444"
@pdf.line_width 0.75
@pdf.stroke_rectangle [ 0, top ], w, h
inner = [ BOX_PADDING, top - BOX_PADDING, w - 2 * BOX_PADDING, h - 2 * BOX_PADDING ]
remaining = draw(entry, inner, remaining, continued: continued, sizes: PAGE_SIZES, shrink: false, continue_note: "page")
@pdf.move_cursor_to([ top - h - BOX_GAP, 0 ].max)
break if remaining.blank?
@pdf.start_new_page
continued = true
end
end
def box_height(entry, body, width)
small, base, = PAGE_SIZES
body_h = @pdf.height_of(clean(body), width: width - 2 * BOX_PADDING, size: base, leading: 1.5)
head_h = (detail_lines(entry).size + 1) * (small + 3) + 2
head_h + body_h + 8 + signature_block_height(small) + 2 * BOX_PADDING
end
# ---- One entry in an area (a label, or the inside of a page box) ----
# Draws the entry into [x, y_top, w, h]; returns the body text that didn't fit.
def draw(entry, (x, y, w, h), body, continued:, sizes:, shrink:, continue_note:)
small, base, min = sizes
leftover = nil
@pdf.bounding_box([ x, y ], width: w, height: h) do
@pdf.text_box clean(header_line), at: [ 0, h ], width: w * 0.68, height: small + 2, size: small, style: :bold, overflow: :truncate
@pdf.text_box clean("#{LogbookEntry::LOG_TYPES[entry.log_type]} log#{' (continued)' if continued}"),
at: [ w * 0.68, h ], width: w * 0.32, height: small + 2, size: small, align: :right, overflow: :truncate
@pdf.text_box clean(facts(entry).join(" ")), at: [ 0, h - small - 3 ], width: w, height: small + 2, size: small, overflow: :truncate
line_y = h - small - 3
detail_lines(entry).each do |line|
@pdf.text_box clean(line), at: [ 0, line_y ], width: w, height: small + 2, size: small,
overflow: :shrink_to_fit, min_font_size: small - 1.5
line_y -= small + 3
end
footer_h = signature_block_height(small)
body_top = h - 2 * (small + 3) - 2
body_h = body_top - footer_h - 4
leftover = @pdf.text_box(clean(body), at: [ 0, body_top ], width: w, height: body_h, size: base, min_font_size: [ base - 2.5, 5.5 ].max,
overflow: :shrink_to_fit, leading: 1)
signature_block(entry, w, footer_h, small, more: leftover.present?)
body_top = line_y - 2
fitting = { at: [ 0, body_top ], width: w, height: body_top - footer_h - 4, size: base }
fitting = shrink ? fitting.merge(leading: 1, overflow: :shrink_to_fit, min_font_size: min) : fitting.merge(leading: 1.5, overflow: :truncate)
leftover = @pdf.text_box(clean(body), **fitting)
signature_block(entry, w, footer_h, small, more: leftover.present? ? continue_note : nil)
end
leftover
end
def header_line
[ @aircraft.tail_number, [ @aircraft.make, @aircraft.model ].compact_blank.join(" ").presence,
(@aircraft.serial_number.present? ? "S/N #{@aircraft.serial_number}" : nil) ].compact.join(" · ")
end
# Date and airframe total time; for engine / propeller entries (or any with
# a component) the component's serial number, total time and since overhaul.
def detail_lines(entry)
airframe = entry.aircraft_hours_at_entry ? "#{hrs(entry.aircraft_hours_at_entry)} (#{@aircraft.time_basis})" : "________"
lines = [ "Date: #{entry.date&.strftime('%b %-d, %Y')} Airframe total time: #{airframe}" ]
component = entry.component
noun = component_noun(entry, component)
if component
model = [ component.manufacturer, component.model ].compact_blank.join(" ")
serial = component.serial_number.present? ? " S/N #{component.serial_number}" : " S/N __________"
lines << [ "#{noun}: #{model}#{serial}",
"#{noun} total time: #{blank_or_hours(entry.component_hours_at_entry)}",
"#{component.since_overhaul_abbreviation}: #{blank_or_hours(entry.component_since_overhaul_at_entry)}" ].join(" ")
elsif noun
lines << "#{noun}: ______________ S/N __________ #{noun} total time: ________ SMOH / SFOH: ________"
end
lines
end
def component_noun(entry, component)
return "Engine" if component&.engine? || (component.nil? && entry.log_type == "ENG")
return "Propeller" if component&.propeller? || (component.nil? && entry.log_type == "PROP")
component&.component_type&.name
end
def blank_or_hours(value) = value ? hrs(value) : "________"
def hrs(value) = ActiveSupport::NumberHelper.number_to_delimited(format("%.1f", value))
def signature_block_height(small) = (small + 3) * 3 + 6
def signature_block(entry, w, height, small, more:)
@pdf.bounding_box([ 0, height ], width: w, height: height) do
if more
@pdf.text_box "Continued on the next label.", at: [ 0, height ], width: w, height: small + 2,
size: small, style: :italic, overflow: :truncate
@pdf.text_box "Continued on the next #{more}.", at: [ 0, height ], width: w, height: small + 2, size: small,
style: :italic, overflow: :truncate
end
line_y = height - (small + 3) * 1.6
@pdf.stroke_color "555555"
@pdf.line_width 0.5
@pdf.stroke_horizontal_line 0, w * 0.62, at: line_y
@pdf.text_box "Signature", at: [ 0, line_y - 1 ], width: w * 0.6, height: small, size: small - 1, overflow: :truncate
@pdf.text_box clean(certificate(entry)), at: [ w * 0.64, line_y + small + 1 ], width: w * 0.36, height: small * 2 + 4,
+3 -1
View File
@@ -18,9 +18,11 @@
<fieldset class="grid gap-4 sm:grid-cols-4">
<legend class="mb-2 text-sm font-semibold text-slate-900">Time</legend>
<%= f.field :date_in_service, as: :date, required: true %>
<%= f.field :hours_in_service, as: :number, step: 0.1 %>
<%= f.field :hours_in_service, as: :number, step: 0.1, label: "Total time (hours)" %>
<%= f.field :overhaul_date, as: :date, label: "Last overhaul / service" %>
<%= f.field :hours_since_overhaul, as: :number, step: 0.1, label: "Hours since OH / service" %>
<%= f.field :overhaul_kind, as: :select, label: "Overhaul type", include_blank: "—", collection: Component::OVERHAUL_KINDS.invert,
wrapper: { class: "sm:col-span-2" }, hint: "For engines and propellers: printed in logbook entries as SMOH, SFOH or SNEW." %>
</fieldset>
<fieldset class="grid gap-4 sm:grid-cols-3">
@@ -0,0 +1,16 @@
<%# Engine / propeller (or other component) the entry is for, and its times at the entry. %>
<% comps = aircraft.components.where.not(status: "DISPOSED").includes(:component_type).order(:install_location) %>
<div class="grid gap-4 sm:grid-cols-3">
<div>
<%= f.label :component_id, "Component", class: "label" %>
<%= f.select :component_id, options_for_select([ [ "— None —", "" ] ] + comps.map { |c|
[ "#{c} · #{c.manufacturer} #{c.model}#{" · S/N #{c.serial_number}" if c.serial_number.present?}", c.id,
{ "data-total" => c.hours_in_service.to_f, "data-since" => c.hours_since_overhaul.to_f,
"data-kind" => (c.engine? ? "ENG" : c.propeller? ? "PROP" : ""), "data-abbr" => c.since_overhaul_abbreviation } ] }, f.object.component_id),
{}, class: "input", data: { component_times_target: "component", action: "component-times#componentChanged" } %>
<p class="hint">For engine and propeller logs: printed with its serial number and times.</p>
</div>
<%= f.field :component_hours_at_entry, as: :number, step: 0.1, label: "Component total time", data: { component_times_target: "total" } %>
<%= f.field :component_since_overhaul_at_entry, as: :number, step: 0.1, label: "Since overhaul", data: { component_times_target: "since" },
hint: "Filled in from the component; correct them for an older entry." %>
</div>
+5 -3
View File
@@ -1,4 +1,4 @@
<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template signer" } do |f| %>
<%= form_with model: [aircraft, entry], class: "card card-body space-y-4 max-w-3xl", data: { controller: "entry-template signer component-times" } do |f| %>
<%= f.errors_summary %>
<% if entry.new_record? %>
<div>
@@ -14,10 +14,12 @@
<% end %>
<div class="grid gap-4 sm:grid-cols-4">
<%= f.field :date, as: :date %>
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert %>
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert,
data: { component_times_target: "logType", action: "component-times#logTypeChanged" } %>
<%= f.field :entry_type, as: :select, label: "Entry type", collection: LogbookEntry::ENTRY_TYPES.invert, data: { entry_template_target: "entryType" } %>
<%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Aircraft hours" %>
<%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Airframe total time" %>
</div>
<%= render "logbook_entries/component_fields", f: f, aircraft: aircraft %>
<%= f.field :text, as: :textarea, label: "Entry text", rows: 8, data: { entry_template_target: "text" } %>
<p class="hint !mt-1">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).</p>
<%= render "shared/sign_as" %>
+5 -1
View File
@@ -16,7 +16,11 @@
<% end %>
<div class="flex flex-wrap gap-4 text-sm text-slate-600">
<span>Type: <%= LogbookEntry::ENTRY_TYPES[@entry.entry_type] %></span>
<span>Aircraft hours: <%= hours(@entry.aircraft_hours_at_entry) %></span>
<span>Airframe total time: <%= hours(@entry.aircraft_hours_at_entry) %></span>
<% if (c = @entry.component) %>
<span><%= c %> <%= c.model %><%= " S/N #{c.serial_number}" if c.serial_number.present? %>:
<%= hours(@entry.component_hours_at_entry) %> total, <%= hours(@entry.component_since_overhaul_at_entry) %> <%= c.since_overhaul_abbreviation %></span>
<% end %>
</div>
<div class="whitespace-pre-wrap rounded bg-slate-50 p-3 font-mono text-sm"><%= @entry.text %></div>
<div class="text-sm text-slate-600">
+5 -3
View File
@@ -19,15 +19,17 @@
<label class="flex items-center gap-2"><%= radio_button_tag :logbook, "none", choice == "none" %> No logbook entry (e.g. it wasn't a defect)</label>
</fieldset>
<div class="space-y-4 rounded-md border border-slate-200 p-3" data-controller="signer">
<div class="space-y-4 rounded-md border border-slate-200 p-3" data-controller="signer component-times">
<p class="text-xs text-slate-500">For a new entry. 14 CFR 43.9: what was done, the date, and the name, certificate number and kind of certificate of whoever approved the return to service.</p>
<%= render "shared/sign_as" %>
<%= fields_for :logbook_entry, @entry do |f| %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :date, as: :date %>
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert %>
<%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Aircraft hours" %>
<%= f.field :log_type, as: :select, label: "Logbook", collection: LogbookEntry::LOG_TYPES.invert,
data: { component_times_target: "logType", action: "component-times#logTypeChanged" } %>
<%= f.field :aircraft_hours_at_entry, as: :number, step: 0.1, label: "Airframe total time" %>
</div>
<%= render "logbook_entries/component_fields", f: f, aircraft: @aircraft %>
<%= f.field :text, as: :textarea, label: "Work performed", rows: 3 %>
<div class="grid gap-4 sm:grid-cols-3">
<%= f.field :signoff_person, label: "Signed off by", data: { signer_target: "name" } %>
@@ -0,0 +1,10 @@
# Engine and propeller log entries record which component they're for and
# its times at the entry (total, and since overhaul), as printed in the log.
class AddComponentTimesToLogbookEntries < ActiveRecord::Migration[8.1]
def change
add_reference :logbook_entries, :component, foreign_key: { on_delete: :nullify }
add_column :logbook_entries, :component_hours_at_entry, :decimal, precision: 8, scale: 1
add_column :logbook_entries, :component_since_overhaul_at_entry, :decimal, precision: 8, scale: 1
add_column :components, :overhaul_kind, :string
end
end
Generated
+7 -1
View File
@@ -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_230000) do
ActiveRecord::Schema[8.1].define(version: 2026_11_07_240000) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@@ -320,6 +320,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_230000) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "expires_on"
t.string "overhaul_kind"
t.index ["aircraft_id"], name: "index_components_on_aircraft_id"
t.index ["component_type_id"], name: "index_components_on_component_type_id"
t.index ["parent_component_id"], name: "index_components_on_parent_component_id"
@@ -449,7 +450,11 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_230000) do
t.string "inspection_result"
t.boolean "verified", default: true, null: false
t.string "transcription_confidence"
t.integer "component_id"
t.decimal "component_hours_at_entry", precision: 8, scale: 1
t.decimal "component_since_overhaul_at_entry", precision: 8, scale: 1
t.index ["aircraft_id"], name: "index_logbook_entries_on_aircraft_id"
t.index ["component_id"], name: "index_logbook_entries_on_component_id"
t.index ["document_id"], name: "index_logbook_entries_on_document_id"
end
@@ -663,6 +668,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_07_230000) do
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", "components", on_delete: :nullify
add_foreign_key "logbook_entries", "documents", on_delete: :nullify
add_foreign_key "logbook_imports", "aircraft"
add_foreign_key "logbook_imports", "documents", on_delete: :nullify
+31 -1
View File
@@ -30,7 +30,7 @@ class LogbookPrintTest < ActionDispatch::IntegrationTest
reader = pdf(ids: [ @entry.id ], layout: "avery_5164")
text = text_of(reader)
[ "N12345", "Cessna 172N", "S/N 17200001", "Aircraft log", "Date: Oct 1, 2026", "Total time: 1234.5 hrs (tach)",
[ "N12345", "Cessna 172N", "S/N 17200001", "Aircraft log", "Date: Oct 1, 2026", "Airframe total time: 1,234.5 (tach)",
"Replaced left landing light lamp P/N 4509 — checked “OK”. ?", "Signature", "Sam Mechanic", "KOQU", "A&P No. 7654321" ].each do |s|
assert_includes text, s
end
@@ -75,6 +75,36 @@ class LogbookPrintTest < ActionDispatch::IntegrationTest
assert_equal (1..3000).to_a, text_of(reader).scan(/\bw(\d+)\b/).flatten.map(&:to_i) # in order, nothing lost
end
test "engine entries print the engine's serial number, total time and time since overhaul; pages box each entry" do
engine = create_component(@a, component_type: component_type("Engine"), manufacturer: "Lycoming", model: "O-320-H2AD",
serial_number: "L-12345-27A", hours_in_service: 3200, hours_since_overhaul: 850, overhaul_kind: "factory_overhaul")
sign_in @owner
get new_aircraft_logbook_entry_path(@a)
assert_select "select[name='logbook_entry[component_id]'] option[value='#{engine.id}'][data-kind=ENG][data-total='3200.0'][data-since='850.0']"
post aircraft_logbook_entries_path(@a), params: { logbook_entry: {
date: "2026-10-03", log_type: "ENG", entry_type: "MAINTENANCE", text: "Changed oil", aircraft_hours_at_entry: 4210.3,
component_id: engine.id, component_hours_at_entry: 3150.5, component_since_overhaul_at_entry: 800.5 } }
entry = @a.logbook_entries.find_by!(text: "Changed oil")
assert_equal [ engine, 3150.5, 800.5 ], [ entry.component, entry.component_hours_at_entry.to_f, entry.component_since_overhaul_at_entry.to_f ]
get aircraft_logbook_entry_path(@a, entry)
assert_includes response.body, "3,150.5 total, 800.5 SFOH"
bare = @a.logbook_entries.create!(date: Date.new(2026, 10, 4), log_type: "PROP", text: "Dressed prop nicks")
reader = pdf(ids: [ entry.id, bare.id, @entry.id ], layout: "letter")
text = text_of(reader)
[ "Engine log", "Airframe total time: 4,210.3 (tach)", "Engine: Lycoming O-320-H2AD S/N L-12345-27A", "Engine total time: 3,150.5",
"SFOH: 800.5", "Propeller: ______________ S/N __________ Propeller total time: ________ SMOH / SFOH: ________" ].each do |s|
assert_includes text, s
end
airframe = text.split("N12345 · Cessna 172N · S/N 17200001").find { _1.include?("Replaced left landing light") }
refute_includes airframe, "S/N __________" # airframe entries don't get component blanks
assert_equal 3, reader.pages.first.raw_content.scan(/ re\b/).size # a box around each entry
assert_equal 0, pdf(ids: [ entry.id ], layout: "avery_5164").pages.first.raw_content.scan(/ re\b/).size # labels aren't boxed
elsewhere = create_component(create_aircraft, component_type: component_type("Engine"))
patch aircraft_logbook_entry_path(@a, entry), params: { logbook_entry: { component_id: elsewhere.id } }
assert_nil entry.reload.component # only this aircraft's components
end
test "pick several entries on the list; outsiders can't print" do
other = @a.logbook_entries.create!(date: Date.new(2026, 10, 2), text: "Second")
sign_in @owner
+2 -2
View File
@@ -36,7 +36,7 @@ class UserCertificatesTest < ActionDispatch::IntegrationTest
@owner.certificates.create!(kind: "IA", number: "7654321", expires_on: 1.day.ago.to_date) # expired: not offered
sign_in @owner
get new_aircraft_logbook_entry_path(@a)
assert_select "form[data-controller='entry-template signer']"
assert_select "form[data-controller='entry-template signer component-times']"
assert_select "select[data-signer-target=choice] option[data-kind=AP][data-number='7654321'][data-name='Sam Mechanic']"
assert_select "select[data-signer-target=choice] option[data-kind=IA]", 0
assert_select "input[name='logbook_entry[signoff_person]'][data-signer-target=name]"
@@ -44,7 +44,7 @@ class UserCertificatesTest < ActionDispatch::IntegrationTest
squawk = @a.squawks.create!(priority: 1, issue_reported: "Nav light out")
get resolution_aircraft_squawk_path(@a, squawk)
assert_select "[data-controller=signer] select[data-signer-target=choice]"
assert_select "[data-controller='signer component-times'] select[data-signer-target=choice]"
get deferral_aircraft_squawk_path(@a, squawk)
assert_select "select[name=deferred_by_role] option[selected][value=mechanic]"
+3 -2
View File
@@ -157,13 +157,14 @@ class AircraftArchiveTest < ActiveSupport::TestCase
assert_equal [ "N0000X", "Piper", 1234.5 ], [ a.tail_number, a.make, a.tach_time.to_f ]
assert_equal engine_type, a.components.sole.component_type, "matched case-insensitively"
assert_equal 2000, a.components.sole.tbo_hours
assert_equal "INSPECTION", a.logbook_entries.sole.entry_type
entry = a.logbook_entries.sole
assert_equal [ "INSPECTION", a.components.sole, 500 ], [ entry.entry_type, entry.component, entry.component_hours_at_entry.to_i ]
squawk = a.squawks.sole
assert_equal [ 0, "abc123.png" ], [ squawk.priority, squawk.attachments.sole.filename.to_s ]
analysis = a.oil_analyses.sole
assert_equal [ "monitor", 12.5, nil, a.components.sole ], [ analysis.status, analysis.value("iron"), analysis.sample_number, analysis.component ]
assert a.flight_logs.sole.track_log.attached?
assert_equal [ "1 logbook entry was linked to components; those links aren't kept here." ], result[:warnings]
assert_empty result[:warnings] # the entry's component and its hours are kept
end
test "a file whose contents don't match its name is skipped with a note" do