Sha256: 367f1986198e6b4ea87e8008f27e9a5453e46b600c1d94d9bbefb0f59111fc38
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
class Spree::AdvancedReport::TopReport::TopCustomers < Spree::AdvancedReport::TopReport def name I18n.t("adv_report.top_report.top_customers.name") end def description I18n.t("adv_report.top_report.top_customers.description") end 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spree_advanced_reporting-2.1.0 | lib/spree/advanced_report/top_report/top_customers.rb |