Class: Spree::AdvancedReport::GeoReport::GeoRevenue
- Inherits:
-
Spree::AdvancedReport::GeoReport
- Object
- Spree::AdvancedReport
- Spree::AdvancedReport::GeoReport
- Spree::AdvancedReport::GeoReport::GeoRevenue
- Defined in:
- lib/spree/advanced_report/geo_report/geo_revenue.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
- #column ⇒ Object
- #description ⇒ Object
-
#initialize(params) ⇒ GeoRevenue
constructor
A new instance of GeoRevenue.
- #name ⇒ Object
Methods inherited from Spree::AdvancedReport
#date_range, #download_url, #order_count, #profit, #revenue, #units
Constructor Details
#initialize(params) ⇒ GeoRevenue
Returns a new instance of GeoRevenue.
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_revenue.rb', line 14 def initialize(params) super(params) data = { :state => {}, :country => {} } orders.each do |order| revenue = revenue(order) if order.bill_address.state data[:state][order.bill_address.state_id] ||= { :name => order.bill_address.state.name, :revenue => 0 } data[:state][order.bill_address.state_id][:revenue] += revenue end if order.bill_address.country data[:country][order.bill_address.country_id] ||= { :name => order.bill_address.country.name, :revenue => 0 } data[:country][order.bill_address.country_id][:revenue] += revenue end end [:state, :country].each do |type| ruportdata[type] = Table(I18n.t("adv_report.geo_report.revenue.table")) data[type].each { |k, v| ruportdata[type] << { "location" => v[:name], I18n.t("adv_report.revenue") => v[:revenue] } } ruportdata[type].sort_rows_by!([I18n.t("adv_report.revenue")], :order => :descending) ruportdata[type].rename_column("location", type.to_s.capitalize) ruportdata[type].replace_column(I18n.t("adv_report.revenue")) { |r| "$%0.2f" % r.send(I18n.t("adv_report.revenue")) } end end |
Instance Method Details
#column ⇒ Object
6 7 8 |
# File 'lib/spree/advanced_report/geo_report/geo_revenue.rb', line 6 def column I18n.t("adv_report.geo_report.revenue.column") end |
#description ⇒ Object
10 11 12 |
# File 'lib/spree/advanced_report/geo_report/geo_revenue.rb', line 10 def description I18n.t("adv_report.geo_report.revenue.description") end |
#name ⇒ Object
2 3 4 |
# File 'lib/spree/advanced_report/geo_report/geo_revenue.rb', line 2 def name I18n.t("adv_report.geo_report.revenue.name") end |