mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Sub-components on logbook entries (e.g. the oil filter on the engine)
- Once a component is chosen, its sub-components are offered on the entry form (and the squawk Resolve page); ticked ones are saved with their total time and time since service, worked out from the airframe total time like the component's (editable; blank before it was installed) - Entry page and printed PDFs list each sub-component with its serial number and times; parts without an overhaul type read "Since service" - Archives carry them: the original format's list of components per entry (first = the entry's component, the rest = sub-components) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
72e1d7760f
commit
7caa213e7a
16 files changed
+249
-22
No files matched your search
@@ -55,7 +55,7 @@ module AircraftArchive
|
||||
document_images: a.documents.includes(pages_attachments: :blob).flat_map do |d|
|
||||
d.pages.map { |page| { id: id(page), document_id: id(d), notes: "", image: file(page, "health/documents") } }
|
||||
end,
|
||||
logbook_entries: a.logbook_entries.map { logbook_hash(_1) },
|
||||
logbook_entries: a.logbook_entries.includes(:parts).map { logbook_hash(_1) },
|
||||
squawks: a.squawks.includes(:reported_by, attachments_attachments: :blob).map { squawk_hash(_1) },
|
||||
inspection_types: inspection_types.map { inspection_type_hash(_1, component_ids) },
|
||||
inspection_records: a.inspection_records.map do |r|
|
||||
@@ -148,9 +148,11 @@ module AircraftArchive
|
||||
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), 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 : {},
|
||||
components: [ id(e.component_id), *e.parts.map { id(_1.component_id) } ].compact,
|
||||
component_hours: { id(e.component_id) => dec(e.component_hours_at_entry) }.merge(e.parts.to_h { [ id(_1.component_id), dec(_1.hours_at_entry) ] })
|
||||
.reject { |k, v| k.nil? || v.nil? },
|
||||
component_since_overhaul: { id(e.component_id) => dec(e.component_since_overhaul_at_entry) }
|
||||
.merge(e.parts.to_h { [ id(_1.component_id), dec(_1.since_overhaul_at_entry) ] }).reject { |k, v| k.nil? || v.nil? },
|
||||
related_documents: [] }
|
||||
end
|
||||
|
||||
|
||||
@@ -222,7 +222,6 @@ module AircraftArchive
|
||||
end
|
||||
|
||||
def import_logbook
|
||||
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",
|
||||
@@ -237,19 +236,22 @@ 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
|
||||
# The first component is the entry's; the rest are its sub-components, each with its times.
|
||||
refs = Array(data["components"]).select { @map[:component][_1.to_s] }
|
||||
if (ref = refs.first)
|
||||
e.component_id = @map[:component][ref.to_s]
|
||||
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
|
||||
refs.drop(1).uniq.each do |r|
|
||||
e.parts.build(component_id: @map[:component][r.to_s], hours_at_entry: num(hash_value(data["component_hours"], r)),
|
||||
since_overhaul_at_entry: num(hash_value(data["component_since_overhaul"], r)))
|
||||
end
|
||||
e.save!(validate: false)
|
||||
@map[:logbook][data["id"].to_s] = e.id
|
||||
|
||||
tick("logbook_entries")
|
||||
end
|
||||
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
|
||||
|
||||
@@ -6,7 +6,8 @@ Prawn::Fonts::AFM.hide_m17n_warning = true # text is reduced to what the built-i
|
||||
# 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. 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).
|
||||
# time and time since overhaul (blanks to fill in when no component is linked),
|
||||
# and a line for each sub-component the entry covers (an oil filter…).
|
||||
#
|
||||
# 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
|
||||
@@ -171,6 +172,14 @@ class LogbookEntryPdf
|
||||
elsif noun
|
||||
lines << "#{noun}: ______________ S/N __________ #{noun} total time: ________ SMOH / SFOH: ________"
|
||||
end
|
||||
entry.parts.each do |part|
|
||||
c = part.component
|
||||
name = c.component_type&.name || "Part"
|
||||
model = [ c.manufacturer, c.model ].compact_blank.join(" ")
|
||||
lines << [ "#{name}: #{model}#{" S/N #{c.serial_number}" if c.serial_number.present?}",
|
||||
"Total time: #{blank_or_hours(part.hours_at_entry)}",
|
||||
"#{c.since_overhaul_abbreviation}: #{blank_or_hours(part.since_overhaul_at_entry)}" ].join(" ")
|
||||
end
|
||||
lines
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user