Sha256: ec027e0a24cd70f7cc4ce1d85b8163df85608a39e908e23c4f57d00ca12e873b

Contents?: true

Size: 1.24 KB

Versions: 32

Compression:

Stored size: 1.24 KB

Contents

class DailyDonationReport
  attr_accessor :rows, :donation_total, :start_date, :organization
  extend ::ArtfullyOseHelper

  def initialize(organization, date=nil)
    @organization = organization
    @start_date = (date || 1.day.ago).in_time_zone(@organization.time_zone).midnight
    @end_date = @start_date + 1.day
    orders = organization.orders.includes(:person, :items)
    orders = orders.csv_not_imported.after(@start_date).before(@end_date) || []

    @rows = []
    orders.each do |order|
      @rows << Row.new(order) unless order.donations.empty?
    end
  end

  def total
    @rows.collect(&:order).sum{|o| o.donations.sum(&:total_price)}
  end

  def header
    ["Order ID", "Total", "Customer"]
  end

  def to_table
    [header] + @rows.collect {|row| row.to_a.flatten(1)} << footer
  end

  def footer
    ["Total:", DailyDonationReport.number_to_currency(total / 100.0), ""]
  end

  class Row
    attr_accessor :id, :total, :person, :person_id, :order
    def initialize(order)
      @id = order.id
      @order = order
      @total = DailyDonationReport.number_to_currency(order.donations.sum(&:total_price) / 100.0)
      @person = order.person
      @person_id = order.person.id
    end

    def to_a
      [id, total, person]
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
artfully_ose-1.3.0.pre4 app/models/daily_donation_report.rb
artfully_ose-1.3.0.pre3 app/models/daily_donation_report.rb
artfully_ose-1.3.0.pre2 app/models/daily_donation_report.rb
artfully_ose-1.3.0.pre1 app/models/daily_donation_report.rb
artfully_ose-1.2.0 app/models/daily_donation_report.rb
artfully_ose-1.2.0.beta.1 app/models/daily_donation_report.rb
artfully_ose-1.2.0.alpha.2 app/models/daily_donation_report.rb
artfully_ose-1.2.0.alpha.1 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.27 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.26 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.24 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.23 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.21 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.20 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.19 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.18 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.17 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.16 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.15 app/models/daily_donation_report.rb
artfully_ose-1.2.0.pre.12 app/models/daily_donation_report.rb