Class: Spree::AdvancedReport::GeoReport::GeoProfit

Inherits:
Spree::AdvancedReport::GeoReport show all
Defined in:
lib/spree/advanced_report/geo_report/geo_profit.rb

Instance Attribute Summary

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

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

Constructor Details

#initialize(params) ⇒ GeoProfit

Returns a new instance of GeoProfit.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spree/advanced_report/geo_report/geo_profit.rb', line 14

def initialize(params)
  super(params)

  data = { :state => {}, :country => {} }
  orders.each do |order|
    profit = profit(order)
    if order.bill_address.state
      data[:state][order.bill_address.state_id] ||= {
        :name => order.bill_address.state.name,
        :profit => 0
      }
      data[:state][order.bill_address.state_id][:profit] += profit
    end
    if order.bill_address.country
      data[:country][order.bill_address.country_id] ||= {
        :name => order.bill_address.country.name,
        :profit => 0
      }
      data[:country][order.bill_address.country_id][:profit] += profit
    end
  end

  [:state, :country].each do |type|
    ruportdata[type] = Table(I18n.t("adv_report.geo_report.profit.table"))
    data[type].each { |k, v| ruportdata[type] << { "location" => v[:name], I18n.t("adv_report.profit") => v[:profit] } }
    ruportdata[type].sort_rows_by!([I18n.t("adv_report.profit")], :order => :descending)
    ruportdata[type].rename_column("location", type.to_s.capitalize)
    ruportdata[type].replace_column(I18n.t("adv_report.profit")) { |r| "$%0.2f" % r.send(I18n.t("adv_report.profit")) }
  end
end

Instance Method Details

#columnObject



6
7
8
# File 'lib/spree/advanced_report/geo_report/geo_profit.rb', line 6

def column
  I18n.t("adv_report.geo_report.profit.column")
end

#descriptionObject



10
11
12
# File 'lib/spree/advanced_report/geo_report/geo_profit.rb', line 10

def description
  I18n.t("adv_report.geo_report.profit.description")
end

#nameObject



2
3
4
# File 'lib/spree/advanced_report/geo_report/geo_profit.rb', line 2

def name
  I18n.t("adv_report.geo_report.profit.name")
end