2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class TicketMailer < BaseMailer
|
|
|
|
helper :application
|
|
|
|
|
|
|
|
# Pass in ticket_ids, event_id, and supporter
|
2019-07-30 21:29:24 +00:00
|
|
|
def followup(ticket_ids, charge_id = nil)
|
2018-03-25 17:30:42 +00:00
|
|
|
@charge = charge_id ? Charge.find(charge_id) : nil
|
2019-07-30 21:29:24 +00:00
|
|
|
@tickets = Ticket.where('id IN(?)', ticket_ids)
|
2018-03-25 17:30:42 +00:00
|
|
|
@event = @tickets.last.event
|
|
|
|
@supporter = @tickets.last.supporter
|
|
|
|
@nonprofit = @supporter.nonprofit
|
|
|
|
from = Format::Name.email_from_np(@nonprofit.name)
|
|
|
|
reply_to = @nonprofit.email.blank? ? @nonprofit.users.first.email : @nonprofit.email
|
2019-07-30 21:29:24 +00:00
|
|
|
mail(from: from, to: @supporter.email, reply_to: reply_to, subject: "Your tickets#{@charge ? ' and receipt ' : ' '}for: #{@event.name}")
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def receipt_admin(ticket_ids, user_id = nil)
|
|
|
|
@tickets = Ticket.where('id IN (?)', ticket_ids)
|
2018-03-25 17:30:42 +00:00
|
|
|
@charge = @tickets.last.charge
|
|
|
|
@supporter = @tickets.last.supporter
|
|
|
|
@event = @tickets.last.event
|
|
|
|
@nonprofit = @event.nonprofit
|
|
|
|
recipients = QueryUsers.nonprofit_user_emails(@nonprofit.id, 'notify_events')
|
|
|
|
if user_id
|
|
|
|
em = User.find(user_id).email
|
|
|
|
return unless recipients.include?(em)
|
2019-07-30 21:29:24 +00:00
|
|
|
|
2018-03-25 17:30:42 +00:00
|
|
|
recipients = [em]
|
|
|
|
end
|
|
|
|
mail(to: recipients, subject: "Ticket redeemed for #{@event.name} - #{@supporter.name}")
|
|
|
|
end
|
|
|
|
end
|