Sha256: e8eca549216b48c35642af4174667d90ee09daea77abdb5032d49d906b367468

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

class DailyEmailReportJob
  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

  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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.beta.1 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.alpha.2 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.alpha.1 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.pre.27 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.pre.26 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.pre.24 app/models/job/daily_email_report_job.rb
artfully_ose-1.2.0.pre.23 app/models/job/daily_email_report_job.rb