Sha256: 21fd1eaf416d69a646e602b42b259eaa1af0e00c7215e377f727a2a0680aa238

Contents?: true

Size: 864 Bytes

Versions: 28

Compression:

Stored size: 864 Bytes

Contents

module Workarea
  module Reports
    class SalesByTender
      include Report

      self.reporting_class = Metrics::TenderByDay
      self.sort_fields = %w(orders revenue)

      def aggregation
        [filter_date_range, project_used_fields, group_by_country]
      end

      def filter_date_range
        {
          '$match' => {
            'reporting_on' => { '$gte' => starts_at, '$lte' => ends_at }
          }
        }
      end

      def project_used_fields
        {
          '$project' => {
            'tender' => 1,
            'orders' => 1,
            'revenue' => 1
          }
        }
      end

      def group_by_country
        {
          '$group' => {
            '_id' => '$tender',
            'orders' => { '$sum' => '$orders' },
            'revenue' => { '$sum' => '$revenue' }
          }
        }
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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