Class: CustomerRecord

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/customer_record.rb

Overview

== Schema Information

Table name: customer_records
Database name: primary

id :integer not null, primary key
a12net_rev :decimal(10, 2)
container_label_status :enum default("auto_container_label")
customer_since :date
damage_allowance_description :text
damage_allowance_percentage :decimal(5, 4)
first_order_date :date
freight_allowance_description :text
freight_allowance_percentage :decimal(5, 4)
has_install_capability :boolean
has_sales_capability :boolean
has_service_capability :boolean
is_customer_only :boolean
last_completed_sales_activity_date :date
last_opportunity_date :date
last_order_date :date
lead_protection_ends :date
lead_protection_starts :date
lifetime_conversion_rate :decimal(5, 2) default(0.0)
lifetime_number_of_opportunities :integer default(0)
lifetime_number_of_orders :integer default(0)
lifetime_number_of_won_opportunities :integer default(0)
lifetime_revenue :decimal(10, 2) default(0.0)
marketing_allowance_description :text
marketing_allowance_percentage :decimal(5, 4)
marketplace_invoice_format :boolean default(FALSE), not null
next_anniversary_date :date
number_of_efh_jobs_per_year_range :string(255)
number_of_locations_range :string(255)
number_of_total_jobs_per_year_range :string(255)
number_of_wy_sales_per_year_range :string(255)
onboarding_template_1_name :string
onboarding_template_1_rename :string
onboarding_template_1_uid :string
onboarding_template_2_name :string
onboarding_template_2_rename :string
onboarding_template_2_uid :string
onboarding_template_3_name :string
onboarding_template_3_rename :string
onboarding_template_3_uid :string
onboarding_template_4_name :string
onboarding_template_4_rename :string
onboarding_template_4_uid :string
onboarding_template_5_name :string
onboarding_template_5_rename :string
onboarding_template_5_uid :string
orders_require_custom_packing_list :boolean default(FALSE), not null
packing_list_status :enum default("auto_packing_list")
profiling_data_last_calculated_at :datetime
profiling_data_last_edited_at :datetime
rebate_allowance_description :text
rr_enrolled :boolean
rr_job_frequency :string(255)
rr_preferred_brand_easyheat :boolean
rr_preferred_brand_factors :text
rr_preferred_brand_na :boolean
rr_preferred_brand_nuheat :boolean
rr_preferred_brand_other :string(255)
rr_preferred_brand_suntouch :boolean
rr_preferred_brand_warmlyyours :boolean
rr_purchase_frequency_building_supply_store :string(255)
rr_purchase_frequency_home_center :string(255)
rr_purchase_frequency_online :string(255)
rr_typical_decision_maker :string(255)
rr_typical_decision_maker_other :string(255)
trailing_twelve_months_conversion_rate :decimal(5, 2) default(0.0)
trailing_twelve_months_number_of_opportunities :integer default(0)
trailing_twelve_months_number_of_orders :integer default(0)
trailing_twelve_months_number_of_won_opportunities :integer default(0)
trailing_twelve_months_revenue :decimal(10, 2) default(0.0)
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
email_contact_point_id :integer
lead_protector_id :integer
party_id :integer not null
phone_contact_point_id :integer
portal_contact_point_id :integer
updater_id :integer

Indexes

customer_records_email_contact_point_id_idx (email_contact_point_id)
customer_records_lead_protector_id_idx (lead_protector_id)
customer_records_phone_contact_point_id_idx (phone_contact_point_id)
customer_records_portal_contact_point_id_idx (portal_contact_point_id)
index_customer_records_on_has_install_capability (has_install_capability)
index_customer_records_on_has_sales_capability (has_sales_capability)
index_customer_records_on_has_service_capability (has_service_capability)
index_customer_records_on_is_customer_only (is_customer_only)
index_customer_records_on_number_of_efh_jobs_per_year_range (number_of_efh_jobs_per_year_range)
index_customer_records_on_number_of_locations_range (number_of_locations_range)
index_customer_records_on_number_of_total_jobs_per_year_range (number_of_total_jobs_per_year_range)
index_customer_records_on_number_of_wy_sales_per_year_range (number_of_wy_sales_per_year_range)
index_customer_records_on_party_id (party_id) UNIQUE

Foreign Keys

customer_records_lead_protector_id_fk (lead_protector_id => parties.id)
customer_records_party_id_fk (party_id => parties.id) ON DELETE => cascade
fk_rails_... (email_contact_point_id => contact_points.id)
fk_rails_... (phone_contact_point_id => contact_points.id)
fk_rails_... (portal_contact_point_id => contact_points.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#container_label_statusObject (readonly)



148
# File 'app/models/customer_record.rb', line 148

validates :container_label_status, inclusion: { in: container_label_statuses.keys }

#lead_protection_endsObject (readonly)



140
# File 'app/models/customer_record.rb', line 140

validates :lead_protection_ends, presence: true, if: :lead_protector_id

#lead_protection_startsObject (readonly)



141
# File 'app/models/customer_record.rb', line 141

validates :lead_protection_starts, presence: true, if: :lead_protector_id

#rr_job_frequencyObject (readonly)



142
# File 'app/models/customer_record.rb', line 142

validates :rr_job_frequency, presence: true, if: :rr_answers_required?

#rr_purchase_frequency_building_supply_storeObject (readonly)



145
# File 'app/models/customer_record.rb', line 145

validates :rr_purchase_frequency_building_supply_store, presence: true, if: :rr_answers_required?

#rr_purchase_frequency_home_centerObject (readonly)



143
# File 'app/models/customer_record.rb', line 143

validates :rr_purchase_frequency_home_center, presence: true, if: :rr_answers_required?

#rr_purchase_frequency_onlineObject (readonly)



144
# File 'app/models/customer_record.rb', line 144

validates :rr_purchase_frequency_online, presence: true, if: :rr_answers_required?

#rr_typical_decision_makerObject (readonly)



146
# File 'app/models/customer_record.rb', line 146

validates :rr_typical_decision_maker, presence: true, if: :rr_answers_required?

#rr_typical_decision_maker_otherObject (readonly)



147
# File 'app/models/customer_record.rb', line 147

validates :rr_typical_decision_maker_other, presence: true, if: proc { |c| c.rr_typical_decision_maker == 'Other' }

#validate_rrObject

Returns the value of attribute validate_rr.



114
115
116
# File 'app/models/customer_record.rb', line 114

def validate_rr
  @validate_rr
end

Class Method Details

.container_label_status_for_selectObject



169
170
171
# File 'app/models/customer_record.rb', line 169

def self.container_label_status_for_select
  container_label_statuses.keys.map{|k| [k.to_s.titleize, k]}
end

.packing_list_status_for_selectObject



173
174
175
# File 'app/models/customer_record.rb', line 173

def self.packing_list_status_for_select
  packing_list_statuses.keys.map{|k| [k.to_s.titleize, k]}
end

Instance Method Details

#customerCustomer

Use this relationship instead of party

Returns:

See Also:



119
# File 'app/models/customer_record.rb', line 119

belongs_to :customer, foreign_key: :party_id, class_name: 'Customer'

#email_contact_pointContactPoint



122
# File 'app/models/customer_record.rb', line 122

belongs_to :email_contact_point, class_name: 'ContactPoint', optional: true

#has_allowances?Boolean

Returns:

  • (Boolean)


164
165
166
167
# File 'app/models/customer_record.rb', line 164

def has_allowances?
  allowance_fields = %i[marketing_allowance_description marketing_allowance_percentage damage_allowance_description damage_allowance_percentage freight_allowance_description freight_allowance_percentage rebate_allowance_description]
  allowance_fields.any? { |af| send(af).presence }
end

#lead_protectorCustomer

Returns:

See Also:



121
# File 'app/models/customer_record.rb', line 121

belongs_to :lead_protector, class_name: 'Customer', optional: true

#liability_insurancesActiveRecord::Relation<LiabilityInsurance>

Returns:

See Also:



126
# File 'app/models/customer_record.rb', line 126

has_many :liability_insurances

#next_anniversaryObject



177
178
179
180
181
182
183
184
# File 'app/models/customer_record.rb', line 177

def next_anniversary
  return unless customer_since

  years_ago = Date.current.year - customer_since.year
  anniversary = customer_since.next_year(years_ago)
  anniversary = anniversary.next_year if anniversary <= Date.current
  anniversary
end

#partyParty

Returns:

See Also:



120
# File 'app/models/customer_record.rb', line 120

belongs_to :party, optional: true

#phone_contact_pointContactPoint



123
# File 'app/models/customer_record.rb', line 123

belongs_to :phone_contact_point, class_name: 'ContactPoint', optional: true

#portal_contact_pointContactPoint



124
# File 'app/models/customer_record.rb', line 124

belongs_to :portal_contact_point, class_name: 'ContactPoint', optional: true