Class: Spree::AdvancedReport::TopReport::TopCustomers

Inherits:
Spree::AdvancedReport::TopReport show all
Defined in:
lib/spree/advanced_report/top_report/top_customers.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, limit) ⇒ TopCustomers

Returns a new instance of TopCustomers.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spree/advanced_report/top_report/top_customers.rb', line 10

def initialize(params, limit)
  super(params)

  orders.each do |order|
    if order.user
      data[order.user.id] ||= {
        :email => order.user.email,
        :revenue => 0,
        :units => 0
      }
      data[order.user.id][:revenue] += revenue(order)
      data[order.user.id][:units] += units(order)
    end
  end

  self.ruportdata = Table(I18n.t("adv_report.top_report.top_customers.table"))
  data.inject({}) { |h, (k, v) | h[k] = v[:revenue]; h }.sort { |a, b| a[1] <=> b [1] }.reverse[0..4].each do |k, v|
    ruportdata << { "email" => data[k][:email], I18n.t("adv_report.units") => data[k][:units], I18n.t("adv_report.revenue") => data[k][:revenue] } 
  end
  ruportdata.replace_column(I18n.t("adv_report.revenue")) { |r| "$%0.2f" % r.send(I18n.t("adv_report.revenue")) }
  ruportdata.rename_column("email", I18n.t("adv_report.top_report.top_customers.customer_email"))
end

Instance Method Details

#descriptionObject



6
7
8
# File 'lib/spree/advanced_report/top_report/top_customers.rb', line 6

def description
  I18n.t("adv_report.top_report.top_customers.description")
end

#nameObject



2
3
4
# File 'lib/spree/advanced_report/top_report/top_customers.rb', line 2

def name
  I18n.t("adv_report.top_report.top_customers.name")
end