Sha256: d09b2c7827c64ec589b32cfd50e6f8087629c12ae04309101f3aa4fc337fff07

Contents?: true

Size: 1.52 KB

Versions: 49

Compression:

Stored size: 1.52 KB

Contents

module Workarea
  module Reports
    class SalesByTrafficReferrer
      include Report

      self.reporting_class = Metrics::TrafficReferrerByDay
      self.sort_fields = %w(
        units_sold
        orders
        merchandise
        discounts
        shipping
        tax
        revenue
        _id.medium
        _id.source
      )

      def aggregation
        [filter, project_used_fields, group_by_traffic_referrer]
      end

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

      def project_used_fields
        {
          '$project' => {
            'medium' => 1,
            'source' => 1,
            'orders' => 1,
            'units_sold' => 1,
            'merchandise' => 1,
            'shipping' => 1,
            'discounts' => 1,
            'tax' => 1,
            'revenue' => 1
          }
        }
      end

      def group_by_traffic_referrer
        {
          '$group' => {
            '_id' => { 'medium' => '$medium', 'source' => '$source' },
            'orders' => { '$sum' => '$orders' },
            'units_sold' => { '$sum' => '$units_sold' },
            'merchandise' => { '$sum' => '$merchandise' },
            'shipping' => { '$sum' => '$shipping' },
            'discounts' => { '$sum' => '$discounts' },
            'tax' => { '$sum' => '$tax' },
            'revenue' => { '$sum' => '$revenue' }
          }
        }
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.26 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.45 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.25 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.23 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.44 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.22 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.43 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.21 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.42 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.20 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.41 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.19 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.40 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.18 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.39 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.17 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.38 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.5.16 app/queries/workarea/reports/sales_by_traffic_referrer.rb
workarea-core-3.4.37 app/queries/workarea/reports/sales_by_traffic_referrer.rb