Class: Workarea::Reports::SalesByMenu

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

def aggregation
  [filter, project_used_fields, group_by_menu]
end

#filterObject



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

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

#group_by_menuObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/queries/workarea/reports/sales_by_menu.rb', line 36

def group_by_menu
  {
    '$group' => {
      '_id' => '$menu_id',
      'orders' => { '$sum' => '$orders' },
      'units_sold' => { '$sum' => '$units_sold' },
      'merchandise' => { '$sum' => '$merchandise' },
      'discounts' => { '$sum' => '$discounts' },
      'shipping' => { '$sum' => '$shipping' },
      'revenue' => { '$sum' => '$revenue' }
    }
  }
end

#project_used_fieldsObject



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

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