mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
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:
1 parent
aa262065b2
commit
a51f78ebf3
21 files changed
+265
-83
No files matched your search
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in new issue
Block a user