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