Class: Workarea::Reports::Customers
- Inherits:
-
Object
- Object
- Workarea::Reports::Customers
show all
- Includes:
- Report
- Defined in:
- app/queries/workarea/reports/customers.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
#add_returning ⇒ Object
17
18
19
20
21
22
23
|
# File 'app/queries/workarea/reports/customers.rb', line 17
def add_returning
{
'$addFields' => {
'returning' => { '$ne' => ['$first_order_at', '$last_order_at'] }
}
}
end
|
#aggregation ⇒ Object
9
10
11
|
# File 'app/queries/workarea/reports/customers.rb', line 9
def aggregation
[filter_orders, add_returning, filter_returning, project_fields].compact
end
|
#filter_orders ⇒ Object
13
14
15
|
# File 'app/queries/workarea/reports/customers.rb', line 13
def filter_orders
{ '$match' => { 'orders' => { '$gt' => 0 } } }
end
|
#filter_returning ⇒ Object
25
26
27
28
29
30
31
|
# File 'app/queries/workarea/reports/customers.rb', line 25
def filter_returning
if params[:results_filter] == 'returning'
{ '$match' => { 'returning' => true } }
elsif params[:results_filter] == 'one_time'
{ '$match' => { 'returning' => false } }
end
end
|
#project_fields ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/queries/workarea/reports/customers.rb', line 33
def project_fields
{
'$project' => {
'_id' => 1,
'first_order_at' => 1,
'last_order_at' => 1,
'orders' => 1,
'cancellations' => 1,
'revenue' => 1,
'refund' => 1,
'average_order_value' => { '$divide': ['$revenue', '$orders'] }
}
}
end
|