Class: Spree::AdvancedReport::IncrementReport::Profit

Inherits:
Spree::AdvancedReport::IncrementReport show all
Defined in:
lib/spree/advanced_report/increment_report/profit.rb

Constant Summary

Constants inherited from Spree::AdvancedReport::IncrementReport

INCREMENTS

Instance Attribute Summary

Attributes inherited from Spree::AdvancedReport::IncrementReport

#all_data, #dates, #increments, #total

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::IncrementReport

#generate_ruport_data, #get_bucket, #get_display

Methods inherited from Spree::AdvancedReport

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

Constructor Details

#initialize(params) ⇒ Profit

Returns a new instance of Profit.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spree/advanced_report/increment_report/profit.rb', line 16

def initialize(params)
  super(params)
  self.total = 0
  self.orders.each do |order|
    date = {}
    INCREMENTS.each do |type|
      date[type] = get_bucket(type, order.completed_at || order.updated_at)
      data[type][date[type]] ||= {
        :value => 0, 
        :display => get_display(type, order.completed_at || order.updated_at),
      }
    end
    profit = profit(order)
    INCREMENTS.each { |type| data[type][date[type]][:value] += profit }
    self.total += profit
  end

  generate_ruport_data

  INCREMENTS.each { |type| ruportdata[type].replace_column(name) { |r| "$%0.2f" % r[name] } }
end

Instance Method Details

#columnObject



7
8
9
10
# File 'lib/spree/advanced_report/increment_report/profit.rb', line 7

def column
  I18n.t("adv_report.increment_report.profit.column")
  "Profit"
end

#descriptionObject



12
13
14
# File 'lib/spree/advanced_report/increment_report/profit.rb', line 12

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

#format_totalObject



38
39
40
# File 'lib/spree/advanced_report/increment_report/profit.rb', line 38

def format_total
  '$' + ((self.total*100).round.to_f / 100).to_s
end

#nameObject



2
3
4
5
# File 'lib/spree/advanced_report/increment_report/profit.rb', line 2

def name
  I18n.t("adv_report.increment_report.profit.name")
  "Profit"
end