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

+16
View File
@@ -17,6 +17,22 @@ module Compliance
(date >> months).end_of_month
end
# Next due date/hours from a recurrence rule ({hours:, months:, days:}),
# matching the status math below: months land on the end of the month,
# then days are added; hours are added to the hours at completion.
def next_due(rule, date:, hours:)
return {} unless rule
due = {}
if rule[:months].to_i.positive? || rule[:days].to_i.positive?
d = date
d = end_of_month_after(d, rule[:months].to_i) if rule[:months].to_i.positive?
d += rule[:days].to_i.days if rule[:days].to_i.positive?
due[:date] = d if date
end
due[:hours] = hours.to_d + rule[:hours].to_d if rule[:hours].to_d.positive? && hours
due
end
def ad_status(ad, compliance, current_hours, today = Date.current)
return Result.new(rank: COMPLIANT) if ad.conditional?
return Result.new(rank: OVERDUE) unless compliance