Calculate next-due for AD compliance and inspections from their rules

- AD compliance "next due at tach reading" is prefilled from the AD's
  hour recurrence (hours at compliance + interval), recalculates live as
  the AD/date/hours change, keeps a typed-in override, and is filled
  server-side when left blank.
- Live "Next due" preview on AD compliance and inspection record forms
  (hours and/or end-of-month date, whichever comes first), mirroring
  Compliance.next_due so preview and status agree.
- Reject an interval entered as the next-due reading (e.g. "100" for
  "every 100 hours"), which made a complied AD show as overdue.
- ADs table shows hours remaining next to the due tach reading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-05 07:24:28 -05:00
1 parent 4d3dc7150a
commit f94ccee99b
13 files changed
+237 -15

No files matched your search

+10 -4
View File
@@ -1,12 +1,18 @@
<%= form_with model: record, url: record.new_record? ? aircraft_inspection_records_path(aircraft) : aircraft_inspection_record_path(aircraft, record), class: "card card-body space-y-4 max-w-2xl" do |f| %>
<% types = aircraft.applicable_inspection_types.ordered %>
<% rules = types.each_with_object({}) { |t, h| (r = t.due_rule) && h[t.id.to_s] = r } %>
<%= form_with model: record, url: record.new_record? ? aircraft_inspection_records_path(aircraft) : aircraft_inspection_record_path(aircraft, record),
class: "card card-body space-y-4 max-w-2xl", data: { controller: "next-due", next_due_rules_value: rules.to_json } do |f| %>
<%= f.errors_summary %>
<%= f.field :inspection_type_id, as: :select, label: "Inspection", collection: aircraft.applicable_inspection_types.ordered.map { [_1.name, _1.id] } %>
<%= f.field :inspection_type_id, as: :select, label: "Inspection", collection: types.map { [_1.name, _1.id] },
data: { next_due_target: "rule", action: "change->next-due#changed" } %>
<div class="grid gap-4 sm:grid-cols-2">
<%= f.field :date, as: :date %>
<%= f.field :aircraft_hours, as: :number, step: 0.1, label: "Aircraft hours (tach)" %>
<%= f.field :date, as: :date, data: { next_due_target: "date", action: "change->next-due#changed" } %>
<%= f.field :aircraft_hours, as: :number, step: 0.1, label: "Aircraft hours (tach)",
data: { next_due_target: "hours", action: "input->next-due#changed" } %>
<%= f.field :component_id, as: :select, label: "Component (if component-level)", collection: component_options(aircraft) %>
<%= f.field :logbook_entry_id, as: :select, label: "Logbook entry", collection: logbook_options(aircraft) %>
</div>
<p class="rounded-md bg-sky-50 px-3 py-2 text-sm text-sky-900 ring-1 ring-sky-200" data-next-due-target="preview" hidden></p>
<%= f.field :notes, as: :textarea, rows: 2 %>
<div class="flex gap-2"><%= f.submit "Save" %><%= link_to "Cancel", aircraft_inspections_path(aircraft), class: "btn-secondary" %></div>
<% end %>