Files
simple-aircraft-manager-rails/app/views/ad_compliances/_form.html.erb
T
rickyandClaude Opus 5.5 f94ccee99b 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>
2026-11-05 07:24:28 -05:00

25 lines
2.2 KiB
ERB
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<% ads = aircraft.applicable_ads.ordered %>
<% rules = ads.each_with_object({}) { |ad, h| (r = ad.due_rule) && h[ad.id.to_s] = r } %>
<%= form_with model: compliance, url: compliance.new_record? ? aircraft_ad_compliances_path(aircraft) : aircraft_ad_compliance_path(aircraft, compliance),
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 :airworthiness_directive_id, as: :select, label: "AD", collection: ads.map { ["#{_1.name} – #{_1.short_description.truncate(50)}", _1.id] },
data: { next_due_target: "rule", action: "change->next-due#changed" } %>
<div class="grid gap-4 sm:grid-cols-2">
<%= f.field :date_complied, as: :date, data: { next_due_target: "date", action: "change->next-due#changed" } %>
<%= f.field :aircraft_hours_at_compliance, as: :number, step: 0.1, label: "Aircraft hours (tach)",
data: { next_due_target: "hours", action: "input->next-due#changed" } %>
<%= f.field :next_due_at_time, as: :number, step: 0.1, label: "Next due at tach reading",
hint: "Calculated from the AD's recurrence; you can override it. Leave 0 if not hour-based.",
data: { next_due_target: "dueHours", action: "input->next-due#markManual" } %>
<%= f.field :component_id, as: :select, label: "Component", 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 :permanent, as: :checkbox, label: "Permanently complied (terminating action)",
data: { next_due_target: "permanent", action: "change->next-due#changed" } %>
<%= f.field :compliance_notes, as: :textarea, label: "Method of compliance", rows: 3, required: true %>
<div class="flex gap-2"><%= f.submit "Save" %><%= link_to "Cancel", aircraft_airworthiness_directives_path(aircraft), class: "btn-secondary" %></div>
<% end %>
<% if compliance.persisted? %><div class="mt-4"><%= delete_button "Delete record", aircraft_ad_compliance_path(aircraft, compliance) %></div><% end %>