Class: DailyEmailReportJob

Inherits:
Object
  • Object
show all
Defined in:
app/models/job/daily_email_report_job.rb

Instance Method Summary collapse

Instance Method Details

#organization_ids_to_email(date) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'app/models/job/daily_email_report_job.rb', line 22

def organization_ids_to_email(date)
  #
  # We have to go back two days here intentionally to account for orgs across different time zones
  # We'll re-select the correct orders in the respective jobs
  #
  org_ids = Order.csv_not_imported.after(date-1.day).before(DateTime.now).pluck(:organization_id).uniq
  orgs_with_lapsed_memberships = Membership.lapsed.pluck(:organization_id).uniq
  org_ids = (org_ids + orgs_with_lapsed_memberships).uniq    
  org_ids
end

#perform(date = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/job/daily_email_report_job.rb', line 2

def perform(date=nil)

  date ||= 1.day.ago

  Organization.where(:id => organization_ids_to_email(date)).receiving_sales_email.each do |org|
    Rails.logger.info("DAILY SALES for org [#{org.id}]")
    tickets           = DailyTicketReport.new(org, date)
    donations         = DailyDonationReport.new(org, date)
    membership_report = DailyMembershipReport.new(org, date)
    pass_report       = DailyPassReport.new(org, date)

    next if tickets.rows.empty? && 
            donations.rows.empty? && 
            tickets.exchange_rows.empty? && 
            pass_report.rows.empty? && 
            !membership_report.send?
    ReportsMailer.delay.daily(tickets, donations, membership_report, pass_report)
  end
end