Sha256: 7106dc53273a7a021ad773164cc90be85bbd66c684746c36f7c6cee9a03608aa

Contents?: true

Size: 1.08 KB

Versions: 49

Compression:

Stored size: 1.08 KB

Contents

module Workarea
  module Reports
    class SalesByDiscount
      include Report

      self.reporting_class = Metrics::DiscountByDay
      self.sort_fields = %w(discounts orders merchandise revenue)

      def aggregation
        [filter, project_used_fields, group_by_discount]
      end

      def filter
        {
          '$match' => {
            'reporting_on' => { '$gte' => starts_at.utc, '$lte' => ends_at.utc },
            'orders' => { '$gt' => 0 }
          }
        }
      end

      def project_used_fields
        {
          '$project' => {
            'discount_id' => 1,
            'orders' => 1,
            'merchandise' => 1,
            'discounts' => 1,
            'revenue' => 1
          }
        }
      end

      def group_by_discount
        {
          '$group' => {
            '_id' => '$discount_id',
            'orders' => { '$sum' => '$orders' },
            'merchandise' => { '$sum' => '$merchandise' },
            'discounts' => { '$sum' => '$discounts' },
            'revenue' => { '$sum' => '$revenue' }
          }
        }
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.36 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.14 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.35 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.13 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.34 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.12 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.33 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.11 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.10 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.32 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.9 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.31 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.8 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.30 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.7 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.29 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.6 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.4.28 app/queries/workarea/reports/sales_by_discount.rb
workarea-core-3.5.5 app/queries/workarea/reports/sales_by_discount.rb