Class: Workarea::Reports::SalesByDiscount
- Inherits:
-
Object
- Object
- Workarea::Reports::SalesByDiscount
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
#aggregation ⇒ Object
9
10
11
|
# File 'app/queries/workarea/reports/sales_by_discount.rb', line 9
def aggregation
[filter, project_used_fields, group_by_discount]
end
|
#filter ⇒ Object
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_discount ⇒ Object
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_fields ⇒ Object
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
|