mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- Users add their FAA certificates (kind, number, optional expiry) on their profile; admins see them on the Users list - "Sign as" on new/edited logbook entries and the squawk Resolve page fills the signer's name, kind of certificate and number (expired certificates aren't offered); deferrals default to mechanic for users with a mechanic certificate - Weekly reminder lists certificates expiring within 60 days (or lapsed in the last 30), even when nothing else is due - Preventive maintenance templates keep a certificate already chosen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
1.1 KiB
Ruby
23 lines
1.1 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.anything_for?(user) = items_for(user).any? || expiring_certificates_for(user).any?
|
|
|
|
def weekly(user)
|
|
@user = user
|
|
@items = self.class.items_for(user)
|
|
@certificates = self.class.expiring_certificates_for(user)
|
|
overdue = @items.sum { |_, issues, _| issues.count { _1.severity.in?(%w[RED LIMITED]) } }
|
|
subject = overdue.positive? ? "#{overdue} #{'item'.pluralize(overdue)} overdue" : "Maintenance coming due"
|
|
subject = "Certificate expiring" if @items.empty?
|
|
mail subject: [ subject, @items.map { _1.first.tail_number }.to_sentence.presence ].compact.join(": "), to: user.email_address
|
|
end
|
|
end
|