Class: Customer::ReportGrouping

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

Class Method Summary collapse

Class Method Details

.direct_sales_report_groupingObject



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

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



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

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



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

def self.select_options
  channels = [] +
  BuyingGroup.where("report_grouping IS NOT NULL").pluck(:report_grouping) +
  Profile.where("report_grouping IS NOT NULL").pluck(:report_grouping) +
  Customer.where("report_grouping IS NOT NULL").pluck(:report_grouping)
  channels.sort.uniq
end

.synchronize_historical_data(customer) ⇒ Object



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

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