mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Admin → Recordkeeping Procedures: generated procedures document (2.2.11 / 3.2.8) from the system setup plus owner-entered details; adopted as numbered, immutable revisions; included in the records package - Admin → Records Audits: periodic QC checklist (3.2.8.5) combining app checks with a restore test, sampled entries vs. source documents and a user review; next due date on About and in admins' weekly reminder - User instructions at /help/records, linked from the logbook and signing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1.3 KiB
Ruby
26 lines
1.3 KiB
Ruby
class ReminderMailer < ApplicationMailer
|
|
# [[aircraft, issues, new AD alerts], …] for the aircraft the user owns
|
|
# that need attention.
|
|
def self.items_for(user)
|
|
Aircraft.joins(:roles).where(aircraft_roles: { user_id: user.id, role: "owner" }).ordered
|
|
.map { [ _1, _1.airworthiness.issues, _1.ad_alerts.pending.to_a ] }.reject { _2.empty? && _3.empty? }
|
|
end
|
|
|
|
def self.expiring_certificates_for(user) = user.certificates.expiring.to_a
|
|
|
|
def self.audit_due_for?(user) = user.admin? && AuditRun.due_soon?
|
|
|
|
def self.anything_for?(user) = items_for(user).any? || expiring_certificates_for(user).any? || audit_due_for?(user)
|
|
|
|
def weekly(user)
|
|
@user = user
|
|
@items = self.class.items_for(user)
|
|
@certificates = self.class.expiring_certificates_for(user)
|
|
@audit_due = self.class.audit_due_for?(user) && AuditRun.next_due
|
|
overdue = @items.sum { |_, issues, _| issues.count { _1.severity.in?(%w[RED LIMITED]) } }
|
|
subject = overdue.positive? ? "#{overdue} #{'item'.pluralize(overdue)} overdue" : "Maintenance coming due"
|
|
subject = (@certificates.any? ? "Certificate expiring" : "Records audit due") if @items.empty?
|
|
mail subject: [ subject, @items.map { _1.first.tail_number }.to_sentence.presence ].compact.join(": "), to: user.email_address
|
|
end
|
|
end
|