Sha256: 98c947ff6727b5bbbae560cfd6210a7ce8e6b4f97acd7fac4297fe8a95032f7c

Contents?: true

Size: 1.78 KB

Versions: 13

Compression:

Stored size: 1.78 KB

Contents

module Spree
  module Admin
    class ReportsController < Spree::Admin::BaseController
      respond_to :html

      AVAILABLE_REPORTS = {
        :sales_total => { :name => Spree.t(:sales_total), :description => Spree.t(:sales_total_description) }
      }

      def index
        @reports = AVAILABLE_REPORTS
      end

      def sales_total
        params[:q] = {} unless params[:q]

        if params[:q][:created_at_gt].blank?
          params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
        else
          params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
        end

        if params[:q] && !params[:q][:created_at_lt].blank?
          params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
        end

        if params[:q].delete(:completed_at_not_null) == "1"
          params[:q][:completed_at_not_null] = true
        else
          params[:q][:completed_at_not_null] = false
        end

        params[:q][:s] ||= "created_at desc"

        @search = Order.complete.ransack(params[:q])
        @orders = @search.result

        @totals = {}
        @orders.each do |order|
          @totals[order.currency] = { :item_total => ::Money.new(0, order.currency), :adjustment_total => ::Money.new(0, order.currency), :sales_total => ::Money.new(0, order.currency) } unless @totals[order.currency]
          @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

      private

      def model_class
        Spree::Admin::ReportsController
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spree_backend-2.1.3 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.7 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.1.2 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.6 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.1.1 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.5 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.1.0 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.4 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.3 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.2 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.1 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.0 app/controllers/spree/admin/reports_controller.rb
spree_backend-2.0.0.rc1 app/controllers/spree/admin/reports_controller.rb