Class: Spree::AdvancedReport::IncrementReport::Revenue

Inherits:
Spree::AdvancedReport::IncrementReport show all
Defined in:
lib/spree/advanced_report/increment_report/revenue.rb

Constant Summary

Constants inherited from Spree::AdvancedReport::IncrementReport

INCREMENTS

Instance Attribute Summary

Attributes inherited from Spree::AdvancedReport::IncrementReport

#all_data, #dates, #increments, #total

Attributes inherited from Spree::AdvancedReport

#data, #date_text, #orders, #params, #product, #product_in_taxon, #product_text, #ruportdata, #search, #taxon, #taxon_text, #unfiltered_params

Instance Method Summary collapse

Methods inherited from Spree::AdvancedReport::IncrementReport

#generate_ruport_data, #get_bucket, #get_display

Methods inherited from Spree::AdvancedReport

#date_range, #download_url, #order_count, #profit, #revenue, #units

Constructor Details

#initialize(params) ⇒ Revenue

Returns a new instance of Revenue.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/spree/advanced_report/increment_report/revenue.rb', line 14

def initialize(params)
  super(params)
  self.total = 0

  self.orders.each do |order|
    date = {}
    INCREMENTS.each do |type|
      date[type] = get_bucket(type, (order.completed_at || order.updated_at))
      data[type][date[type]] ||= {
        :value => 0,
        :display => get_display(type, (order.completed_at || order.updated_at)),
      }
    end
    rev = revenue(order)
    INCREMENTS.each { |type| data[type][date[type]][:value] += rev }
    self.total += rev
  end

  generate_ruport_data

  INCREMENTS.each { |type| ruportdata[type].replace_column(name) { |r| "$%0.2f" % r[name] } }
end

Instance Method Details

#columnObject



6
7
8
# File 'lib/spree/advanced_report/increment_report/revenue.rb', line 6

def column
  I18n.t("adv_report.increment_report.revenue.column")
end

#descriptionObject



10
11
12
# File 'lib/spree/advanced_report/increment_report/revenue.rb', line 10

def description
  I18n.t("adv_report.increment_report.revenue.description")
end

#format_totalObject



37
38
39
# File 'lib/spree/advanced_report/increment_report/revenue.rb', line 37

def format_total
  '$' + ((self.total*100).round.to_f / 100).to_s
end

#nameObject



2
3
4
# File 'lib/spree/advanced_report/increment_report/revenue.rb', line 2

def name
  I18n.t("adv_report.increment_report.revenue.name")
end