mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
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:
1 parent
4d3dc7150a
commit
f94ccee99b
13 files changed
+237
-15
No files matched your search
@@ -1,14 +1,23 @@
|
||||
<%= 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" do |f| %>
|
||||
<% 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: aircraft.applicable_ads.ordered.map { ["#{_1.name} – #{_1.short_description.truncate(50)}", _1.id] } %>
|
||||
<%= 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 %>
|
||||
<%= f.field :aircraft_hours_at_compliance, as: :number, step: 0.1, label: "Aircraft hours (tach)" %>
|
||||
<%= f.field :next_due_at_time, as: :number, step: 0.1, label: "Next due at (tach hours)", hint: "0 = no hour-based recurrence." %>
|
||||
<%= 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>
|
||||
<%= f.field :permanent, as: :checkbox, label: "Permanently complied (terminating action)" %>
|
||||
<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 %>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<% if ad.conditional? && ad.trigger_condition.present? %><div class="text-slate-500">Trigger: <%= ad.trigger_condition %></div><% end %></td>
|
||||
<td class="text-xs"><%= ad.recurring? ? [ad.recurring_hours.to_f > 0 && "#{hours(ad.recurring_hours)} h", ad.recurring_months > 0 && "#{ad.recurring_months} mo"].select(&:itself).join(" / ") : "One-time" %></td>
|
||||
<td class="text-xs"><%= row.latest ? "#{row.latest.date_complied}#{' (permanent)' if row.latest.permanent?}" : "—" %></td>
|
||||
<td class="text-xs"><%= [row.next_due_date&.strftime("%b %Y"), row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
|
||||
<td class="text-xs"><%= [row.next_due_date&.strftime("%b %Y"), row.next_due_hours && "#{hours(row.next_due_hours)} tach (#{hours(row.next_due_hours - @aircraft.current_hours)} h left)"].compact.join(" / ").presence || "—" %></td>
|
||||
<td><%= compliance_badge(row.status) %></td>
|
||||
<td class="whitespace-nowrap text-right">
|
||||
<% if owner? %>
|
||||
@@ -50,7 +50,7 @@
|
||||
<div class="card-header"><h2 class="card-title">Compliance History</h2></div>
|
||||
<% if @history.any? %>
|
||||
<table class="table">
|
||||
<thead><tr><th>Date</th><th>AD</th><th class="text-right">Hours</th><th>Next due (hrs)</th><th>Notes</th><th></th></tr></thead>
|
||||
<thead><tr><th>Date</th><th>AD</th><th class="text-right">Hours</th><th>Next due (tach)</th><th>Notes</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
<% @history.each do |c| %>
|
||||
<tr>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
Reference in new issue
Block a user