Sha256: b48882fbb0fe789fc894bf7e2318b11cb8b9ae94385df77850d1e6a034483577

Contents?: true

Size: 1.77 KB

Versions: 26

Compression:

Stored size: 1.77 KB

Contents

module Workarea
  module Reports
    class SalesByCountry
      include Report

      self.reporting_class = Metrics::CountryByDay
      self.sort_fields = %w(orders cancellations units_sold units_canceled merchandise discounts shipping tax refund revenue)

      def aggregation
        [filter, project_used_fields, group_by_country]
      end

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

      def project_used_fields
        {
          '$project' => {
            'country' => 1,
            'orders' => 1,
            'cancellations' => 1,
            'units_sold' => 1,
            'units_canceled' => 1,
            'merchandise' => 1,
            'shipping' => 1,
            'discounts' => 1,
            'tax' => 1,
            'refund' => 1,
            'revenue' => 1
          }
        }
      end

      def group_by_country
        {
          '$group' => {
            '_id' => '$country',
            'orders' => { '$sum' => '$orders' },
            'cancellations' => { '$sum' => '$cancellations' },
            'units_sold' => { '$sum' => '$units_sold' },
            'units_canceled' => { '$sum' => '$units_canceled' },
            'merchandise' => { '$sum' => '$merchandise' },
            'shipping' => { '$sum' => '$shipping' },
            'discounts' => { '$sum' => '$discounts' },
            'tax' => { '$sum' => '$tax' },
            'refund' => { '$sum' => '$refund' },
            'revenue' => { '$sum' => '$revenue' }
          }
        }
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.26 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.25 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.23 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.22 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.21 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.20 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.19 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.18 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.17 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.16 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.15 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.14 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.13 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.12 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.11 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.10 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.9 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.8 app/queries/workarea/reports/sales_by_country.rb
workarea-core-3.5.7 app/queries/workarea/reports/sales_by_country.rb