Class: Customer::ReportGrouping

Inherits:
Object
  • Object
show all
Defined in:
app/services/customer/report_grouping.rb

Overview

Service object: report grouping.

Class Method Summary collapse

Class Method Details

.direct_sales_report_groupingObject



12
13
14
# File 'app/services/customer/report_grouping.rb', line 12

def self.direct_sales_report_grouping
  select_options - ['Amazon', 'Costco', 'Direct Buy', 'E-Tailers', 'Home Depot', 'Lowes', 'Lowes Canada', 'Wal-Mart']
end

.get_report_grouping_for_customer(customer) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'app/services/customer/report_grouping.rb', line 16

def self.get_report_grouping_for_customer(customer)
  billing_entity = customer.try(:billing_entity) || customer
  billing_entity.report_grouping.presence ||
    billing_entity.try(:buying_group).try(:report_grouping).presence ||
    billing_entity.try(:buying_group).try(:name).presence ||
    billing_entity.try(:profile).try(:report_grouping).presence ||
    billing_entity.try(:profile).try(:name).presence ||
    'Homeowners'
end

.select_optionsObject



4
5
6
7
8
9
10
# File 'app/services/customer/report_grouping.rb', line 4

def self.select_options
  channels = [] +
             BuyingGroup.where.not(report_grouping: nil).pluck(:report_grouping) +
             Profile.where.not(report_grouping: nil).pluck(:report_grouping) +
             Customer.where.not(report_grouping: nil).pluck(:report_grouping)
  channels.sort.uniq
end

.synchronize_historical_data(customer) ⇒ Object



26
27
28
29
# File 'app/services/customer/report_grouping.rb', line 26

def self.synchronize_historical_data(customer)
  report_grouping = get_report_grouping_for_customer(customer)
  customer.invoices.where.not(report_grouping: report_grouping).update_all(report_grouping: report_grouping)
end