Class: Workarea::Insights::SalesByNavigation
- Inherits:
-
Base
- Object
- Base
- Workarea::Insights::SalesByNavigation
show all
- Defined in:
- app/models/workarea/insights/sales_by_navigation.rb
Class Method Summary
collapse
Methods inherited from Base
beginning_of_last_month, current, end_of_last_month, generate_daily!, generate_weekly!, #include?, #slug
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
#embedded_children
Class Method Details
.dashboards ⇒ Object
5
6
7
|
# File 'app/models/workarea/insights/sales_by_navigation.rb', line 5
def dashboards
%w(store)
end
|
.find_total_revenue ⇒ Object
42
43
44
45
46
|
# File 'app/models/workarea/insights/sales_by_navigation.rb', line 42
def find_total_revenue
Metrics::SalesByDay
.by_date_range(starts_at: beginning_of_last_month, ends_at: end_of_last_month)
.sum(:revenue) || 0
end
|
.generate_monthly! ⇒ Object
9
10
11
12
|
# File 'app/models/workarea/insights/sales_by_navigation.rb', line 9
def generate_monthly!
results = generate_results
create!(results: results) if results.present?
end
|
.generate_results ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/models/workarea/insights/sales_by_navigation.rb', line 14
def generate_results
total_revenue = find_total_revenue
report
.results
.map do |result|
percent_of_total = if total_revenue.zero?
0
else
(result['revenue'] / total_revenue.to_f) * 100
end
result.merge(
menu_id: result['_id'],
percent_of_total: percent_of_total
)
end
end
|
.report ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'app/models/workarea/insights/sales_by_navigation.rb', line 33
def report
Reports::SalesByMenu.new(
starts_at: beginning_of_last_month,
ends_at: end_of_last_month,
sort_by: 'revenue',
sort_direction: 'desc'
)
end
|