Class: Workarea::Reports::SalesByDiscount

Inherits:
Object
  • Object
show all
Includes:
Report
Defined in:
app/queries/workarea/reports/sales_by_discount.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_discount.rb', line 9

def aggregation
  [filter, project_used_fields, group_by_discount]
end

#filterObject



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

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

#group_by_discountObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/queries/workarea/reports/sales_by_discount.rb', line 34

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

#project_used_fieldsObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/queries/workarea/reports/sales_by_discount.rb', line 22

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