Class: Workarea::Reports::SalesByTender

Inherits:
Object
  • Object
show all
Includes:
Report
Defined in:
app/queries/workarea/reports/sales_by_tender.rb

Instance Method Summary collapse

Methods included from Report

#cache_key, #count, #ends_at, #initialize, #limit, #more_results?, #results, #slug, #sort, #sort_by, #sort_direction, #sort_value, #starts_at

Instance Method Details

#aggregationObject



9
10
11
# File 'app/queries/workarea/reports/sales_by_tender.rb', line 9

def aggregation
  [filter_date_range, project_used_fields, group_by_country]
end

#filter_date_rangeObject



13
14
15
16
17
18
19
# File 'app/queries/workarea/reports/sales_by_tender.rb', line 13

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

#group_by_countryObject



31
32
33
34
35
36
37
38
39
# File 'app/queries/workarea/reports/sales_by_tender.rb', line 31

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

#project_used_fieldsObject



21
22
23
24
25
26
27
28
29
# File 'app/queries/workarea/reports/sales_by_tender.rb', line 21

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