Class: Spree::Admin::ReportsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Admin::ReportsController
- Defined in:
- app/controllers/spree/admin/reports_controller.rb
Constant Summary collapse
- @@available_reports =
{}
Class Method Summary collapse
- .add_available_report!(report_key, report_description_key = nil) ⇒ Object
- .available_reports ⇒ Object
Instance Method Summary collapse
- #index ⇒ Object
-
#initialize ⇒ ReportsController
constructor
A new instance of ReportsController.
- #sales_total ⇒ Object
Constructor Details
#initialize ⇒ ReportsController
Returns a new instance of ReportsController.
25 26 27 28 |
# File 'app/controllers/spree/admin/reports_controller.rb', line 25 def initialize super ReportsController.add_available_report!(:sales_total) end |
Class Method Details
.add_available_report!(report_key, report_description_key = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/spree/admin/reports_controller.rb', line 13 def add_available_report!(report_key, report_description_key = nil) if report_description_key.nil? report_description_key = "#{report_key}_description" end @@available_reports[report_key] = { name: report_key, description: report_description_key, } end |
.available_reports ⇒ Object
9 10 11 |
# File 'app/controllers/spree/admin/reports_controller.rb', line 9 def available_reports @@available_reports end |
Instance Method Details
#index ⇒ Object
30 31 32 |
# File 'app/controllers/spree/admin/reports_controller.rb', line 30 def index @reports = ReportsController.available_reports end |
#sales_total ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/spree/admin/reports_controller.rb', line 34 def sales_total params[:q] = search_params @search = Order.complete.not_canceled.ransack(params[:q]) @orders = @search.result @totals = {} @orders.each do |order| unless @totals[order.currency] @totals[order.currency] = { item_total: ::Money.new(0, order.currency), adjustment_total: ::Money.new(0, order.currency), sales_total: ::Money.new(0, order.currency) } end @totals[order.currency][:item_total] += order.display_item_total.money @totals[order.currency][:adjustment_total] += order.display_adjustment_total.money @totals[order.currency][:sales_total] += order.display_total.money end end |