Overview shows coming due and the last flight; intervals in days, months or years

- Overview: "Coming due" (next 30 days or 10 hours) and "Last flight" (the
  most recent day's legs, meters at the end, fuel and oil left).
- Component replace / TBO / inspect intervals, inspection types and ADs take
  a number and a days / months / years choice (CalendarInterval). Components
  gain month columns (years stored as 12 months; months land on the same
  date); inspection types and ADs keep end-of-month. ADs now honour days.
- Due list: hours already run out count as overdue; a component covered by
  an inspection type no longer gets its own "Inspect every" item.
- Loading calculator moved to a partial; no limit warnings until a load is
  entered. Header buttons don't wrap on phones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-11 21:40:14 -05:00
1 parent 215efe6814
commit 31ac991bab
37 files changed
+385 -75

No files matched your search

+2 -1
View File
@@ -146,7 +146,8 @@ module AircraftArchive
expires_on: c.expires_on&.iso8601, notes: c.notes, status: c.status, date_in_service: c.date_in_service&.iso8601, hours_in_service: dec(c.hours_in_service),
hours_since_overhaul: dec(c.hours_since_overhaul), overhaul_date: c.overhaul_date&.iso8601, tbo_hours: c.tbo_hours,
tbo_days: c.tbo_days, inspection_hours: c.inspection_hours, inspection_days: c.inspection_days,
replacement_hours: c.replacement_hours, replacement_days: c.replacement_days, tbo_critical: c.tbo_critical,
replacement_hours: c.replacement_hours, replacement_days: c.replacement_days,
replacement_months: c.replacement_months, tbo_months: c.tbo_months, inspection_months: c.inspection_months, tbo_critical: c.tbo_critical,
on_condition: c.on_condition, inspection_critical: c.inspection_critical, replacement_critical: c.replacement_critical }
end
+2 -1
View File
@@ -215,7 +215,8 @@ module AircraftArchive
status: Component::STATUSES.key?(data["status"]) ? data["status"] : "SPARE",
date_in_service: date(data["date_in_service"]) || Date.new(1900, 1, 1), hours_in_service: num(data["hours_in_service"]) || 0,
hours_since_overhaul: num(data["hours_since_overhaul"]) || 0, overhaul_date: date(data["overhaul_date"]),
**data.slice(*%w[tbo_hours tbo_days inspection_hours inspection_days replacement_hours replacement_days]).symbolize_keys,
**data.slice(*%w[tbo_hours tbo_days inspection_hours inspection_days replacement_hours replacement_days
tbo_months inspection_months replacement_months]).symbolize_keys,
**data.slice(*%w[tbo_critical on_condition inspection_critical replacement_critical]).transform_values { _1 == true }.symbolize_keys
)
c.save!(validate: false)
+1 -1
View File
@@ -158,7 +158,7 @@ class Airworthiness
if c.replacement_critical? && (due = c.next_replacement_date)
if @today >= due
overdue = true
desc = "Replace every #{c.replacement_days} days. Last serviced #{c.overhaul_date}."
desc = "Replace every #{c.replacement_interval_label}. Last serviced #{c.overhaul_date}."
elsif @today + DAYS_WARNING >= due
approaching = true
desc = "Replace in #{(due - @today).to_i} days."
+2 -2
View File
@@ -51,8 +51,8 @@ module Compliance
end
end
if ad.recurring? && ad.recurring_months.positive?
due = end_of_month_after(compliance.date_complied, ad.recurring_months)
if ad.recurring? && ad.recurring_calendar?
due = next_due(ad.due_rule, date: compliance.date_complied, hours: nil)[:date]
result.next_due_date = due
if today > due
rank = OVERDUE
+25 -9
View File
@@ -3,11 +3,16 @@
# Items due by hours get a projected date from the aircraft's flying over
# the past year. Used by the calendar feed.
class DueList
Item = Data.define(:key, :title, :date, :projected, :due_hours, :kind, :path) do
def overdue?(today = Date.current) = date < today
# past_hours: the hours have already run out (the date is then today).
Item = Data.define(:key, :title, :date, :projected, :due_hours, :kind, :path, :past_hours) do
def overdue?(today = Date.current) = past_hours || date < today
end
# Hours flown per day over the past year (nil when it hasn't flown).
# What counts as coming up soon (Overview).
SOON_DAYS = 30
SOON_HOURS = 10
def self.daily_rate(aircraft, today: Date.current)
hours = aircraft.flight_logs.where(date: (today - 365)..today).sum(:tach_time).to_f
hours.positive? ? hours / 365.0 : nil
@@ -25,6 +30,13 @@ class DueList
(inspections + ads + components + documents).compact.sort_by { [ _1.date, _1.title ] }
end
# Due in the next SOON_DAYS days or SOON_HOURS hours (or overdue).
def soon
horizon = @today + SOON_DAYS
hours_limit = @now_hours + SOON_HOURS
items.select { |i| i.date <= horizon || (i.due_hours && i.due_hours <= hours_limit) }
end
private
# The date it's due: the calendar date, or when the hours run out at the
@@ -35,7 +47,8 @@ class DueList
use = [ date, projected ].compact.min
return unless use
Item.new(key: key, title: title, date: use, projected: use == projected && projected != date, kind: kind, path: path,
due_hours: hours_left ? (@now_hours + hours_left.to_d).round(1) : nil)
due_hours: hours_left ? (@now_hours + hours_left.to_d).round(1) : nil,
past_hours: !hours_left.nil? && hours_left.negative? && use == projected)
end
def hours_left(due_hours) = due_hours ? due_hours.to_d - @now_hours : nil
@@ -55,20 +68,23 @@ class DueList
end
end
# A component's own "Inspect every" counts from its last service; when an
# inspection type covers the component, that inspection (tracked from its
# records, under inspections) governs instead.
def components
@aircraft.components.in_use.includes(:component_type).flat_map do |c|
@aircraft.components.in_use.includes(:component_type, :inspection_types).flat_map do |c|
label = "#{c} #{c.model}".strip
path = @urls.aircraft_component_path(@aircraft, c)
since_service = c.hours_since_overhaul.to_d
[
(item("replace-#{c.id}", "Replace #{label}", "component", path, date: c.next_replacement_date,
hours_left: c.replacement_hours && c.replacement_hours - since_service) if c.replacement_hours || c.replacement_days),
hours_left: c.replacement_hours && c.replacement_hours - since_service) if c.replacement_hours || c.replacement_calendar?),
(item("tbo-#{c.id}", "#{label} reaches TBO", "component", path,
date: c.tbo_days && c.overhaul_date ? c.overhaul_date + c.tbo_days : nil,
hours_left: c.tbo_hours && c.tbo_hours - since_service) if (c.tbo_hours || c.tbo_days) && !c.on_condition?),
date: c.tbo_after(c.overhaul_date),
hours_left: c.tbo_hours && c.tbo_hours - since_service) if (c.tbo_hours || c.tbo_calendar?) && !c.on_condition?),
(item("inspect-#{c.id}", "Inspect #{label}", "component", path,
date: c.inspection_days && c.overhaul_date ? c.overhaul_date + c.inspection_days : nil,
hours_left: c.inspection_hours && c.inspection_hours - since_service) if c.inspection_hours || c.inspection_days),
date: c.inspection_after(c.overhaul_date),
hours_left: c.inspection_hours && c.inspection_hours - since_service) if (c.inspection_hours || c.inspection_calendar?) && c.inspection_types.empty?),
(item("expires-#{c.id}", "#{label} expires", "component", path, date: c.expires_on) if c.expires_on)
]
end
+2 -2
View File
@@ -17,12 +17,12 @@ class MaintenanceReport
# Parts with a mandatory replacement time (life limits).
def life_limited
in_use.select { |c| (c.replacement_critical? && (c.replacement_hours || c.replacement_days)) || c.expires_on }
in_use.select { |c| (c.replacement_critical? && (c.replacement_hours || c.replacement_calendar?)) || c.expires_on }
end
# Items overhauled on a time basis.
def overhaul_items
in_use.select { |c| c.tbo_hours || c.tbo_days }
in_use.select { |c| c.tbo_hours || c.tbo_calendar? }
end
def inspections = @inspections ||= Compliance.inspection_rows(aircraft)