Class: ServiceJob
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ServiceJob
- Includes:
- Models::Auditable, PgSearch::Model
- Defined in:
- app/models/service_job.rb
Overview
== Schema Information
Table name: service_jobs
Database name: primary
id :integer not null, primary key
adaptive_start :boolean default(TRUE), not null
completed_on :date
cross_street1 :string(255)
cross_street1_direction :string(255)
cross_street2 :string(255)
cross_street2_direction :string(255)
display_format_celsius :boolean default(FALSE), not null
display_language :string
estimated_size_sqft :float
floor_load :float
floor_protection_mode :string default("laminate")
floor_temperature_max :integer default(82), not null
floor_temperature_min :integer default(41), not null
friday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
friday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
friday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
friday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
is_specified :boolean default(FALSE), not null
job_comments :string(255)
job_date :datetime
measurecomp_job_number :string(255)
measurecomp_order_number :string(255)
monday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
monday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
monday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
monday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
reference_number :string(255) not null
saturday_periods :string default(["8:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
saturday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
saturday_periods_inactive :boolean default([FALSE, TRUE, TRUE, TRUE, TRUE, FALSE]), is an Array
saturday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
serial_number :string(255)
state :string(255)
sunday_periods :string default(["8:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
sunday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
sunday_periods_inactive :boolean default([FALSE, TRUE, TRUE, TRUE, TRUE, FALSE]), is an Array
sunday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
temperature_control_mode :string default("AF"), not null
thursday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
thursday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
thursday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
thursday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
tstat_count :integer
tstat_sku :string
tuesday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
tuesday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
tuesday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
tuesday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
wednesday_periods :string default(["6:00", "9:00", "12:00", "13:00", "17:00", "23:00"]), is an Array
wednesday_periods_floor_temperature :integer default([82, 74, 82, 74, 82, 74]), is an Array
wednesday_periods_inactive :boolean default([FALSE, FALSE, TRUE, TRUE, FALSE, FALSE]), is an Array
wednesday_periods_room_temperature :integer default([70, 62, 70, 62, 70, 62]), is an Array
created_at :datetime
updated_at :datetime
address_id :integer
business_phone_contact_point_id :integer
cell_phone_contact_point_id :integer
contact_id :integer
creator_id :integer
customer_id :integer
delivery_id :integer
email_contact_point_id :integer
home_phone_contact_point_id :integer
line_item_id :integer
order_id :integer
tstat_line_item_id :integer
updater_id :integer
Indexes
index_measurecomp_jobs_on_address_id (address_id)
index_measurecomp_jobs_on_business_phone_contact_point_id (business_phone_contact_point_id)
index_measurecomp_jobs_on_cell_phone_contact_point_id (cell_phone_contact_point_id)
index_measurecomp_jobs_on_customer_id (customer_id)
index_measurecomp_jobs_on_delivery_id (delivery_id)
index_measurecomp_jobs_on_email_contact_point_id (email_contact_point_id)
index_measurecomp_jobs_on_home_phone_contact_point_id (home_phone_contact_point_id)
index_measurecomp_jobs_on_measurecomp_job_number (measurecomp_job_number)
index_measurecomp_jobs_on_order_id (order_id)
index_measurecomp_jobs_on_serial_number (serial_number)
index_service_jobs_on_contact_id (contact_id)
index_service_jobs_on_is_specified (is_specified)
index_service_jobs_on_job_date (job_date)
index_service_jobs_on_line_item_id (line_item_id)
index_service_jobs_on_state (state)
Direct Known Subclasses
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #job_comments ⇒ Object readonly
Belongs to collapse
- #address ⇒ Address
- #business_phone_contact_point ⇒ ContactPoint
- #cell_phone_contact_point ⇒ ContactPoint
- #contact ⇒ Contact
- #customer ⇒ Customer
- #email_contact_point ⇒ ContactPoint
- #home_phone_contact_point ⇒ ContactPoint
Methods included from Models::Auditable
Has many collapse
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are active.
-
.complete ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are complete.
-
.open_jobs ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are open jobs.
Instance Method Summary collapse
- #business_phone ⇒ Object
- #business_phone=(value) ⇒ Object
- #cell_phone ⇒ Object
- #cell_phone=(value) ⇒ Object
- #email ⇒ Object
- #email=(value) ⇒ Object
- #home_phone ⇒ Object
- #home_phone=(value) ⇒ Object
- #ok_to_delete ⇒ Object
- #primary_phone ⇒ Object
- #search_text ⇒ Object
- #set_best_guess_email_contact_point ⇒ Object
- #set_best_guess_home_phone_contact_point ⇒ Object
- #set_reference_number ⇒ Object
- #set_serial_number ⇒ Object
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::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#job_comments ⇒ Object (readonly)
113 |
# File 'app/models/service_job.rb', line 113 validates :job_comments, length: { maximum: 255 } |
Class Method Details
.active ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are active. Active Record Scope
108 |
# File 'app/models/service_job.rb', line 108 scope :active, -> { where("service_jobs.state <> 'cancelled'") } |
.complete ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are complete. Active Record Scope
109 |
# File 'app/models/service_job.rb', line 109 scope :complete, -> { where("service_jobs.state = 'complete'") } |
.open_jobs ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are open jobs. Active Record Scope
107 |
# File 'app/models/service_job.rb', line 107 scope :open_jobs, -> { where("service_jobs.state IN ('draft', 'waiting_to_schedule', 'needs_programming_details')") } |
Instance Method Details
#address ⇒ Address
97 |
# File 'app/models/service_job.rb', line 97 belongs_to :address, inverse_of: :service_jobs, optional: true |
#business_phone ⇒ Object
163 164 165 |
# File 'app/models/service_job.rb', line 163 def business_phone business_phone_contact_point.try(:detail) end |
#business_phone=(value) ⇒ Object
167 168 169 170 171 172 173 |
# File 'app/models/service_job.rb', line 167 def business_phone=(value) if business_phone_contact_point && business_phone_contact_point.party_id.nil? business_phone_contact_point.detail = value.to_s[0..19] elsif value.present? build_business_phone_contact_point(category: ContactPoint::PHONE, detail: value) end end |
#business_phone_contact_point ⇒ ContactPoint
101 |
# File 'app/models/service_job.rb', line 101 belongs_to :business_phone_contact_point, class_name: 'ContactPoint', optional: true |
#cell_phone ⇒ Object
151 152 153 |
# File 'app/models/service_job.rb', line 151 def cell_phone cell_phone_contact_point.try(:detail) end |
#cell_phone=(value) ⇒ Object
155 156 157 158 159 160 161 |
# File 'app/models/service_job.rb', line 155 def cell_phone=(value) if cell_phone_contact_point && cell_phone_contact_point.party_id.nil? cell_phone_contact_point.detail = value.to_s[0..19] elsif value.present? build_cell_phone_contact_point(category: ContactPoint::CELL, detail: value) end end |
#cell_phone_contact_point ⇒ ContactPoint
100 |
# File 'app/models/service_job.rb', line 100 belongs_to :cell_phone_contact_point, class_name: 'ContactPoint', optional: true |
#contact ⇒ Contact
103 |
# File 'app/models/service_job.rb', line 103 belongs_to :contact, class_name: 'Contact', optional: true, inverse_of: :service_jobs |
#email ⇒ Object
139 140 141 |
# File 'app/models/service_job.rb', line 139 def email email_contact_point.try(:detail) end |
#email=(value) ⇒ Object
143 144 145 146 147 148 149 |
# File 'app/models/service_job.rb', line 143 def email=(value) if email_contact_point && email_contact_point.party_id.nil? email_contact_point.detail = value elsif value.present? build_email_contact_point(category: ContactPoint::EMAIL, detail: value) end end |
#email_contact_point ⇒ ContactPoint
99 |
# File 'app/models/service_job.rb', line 99 belongs_to :email_contact_point, class_name: 'ContactPoint', optional: true |
#home_phone ⇒ Object
127 128 129 |
# File 'app/models/service_job.rb', line 127 def home_phone (home_phone_contact_point || cell_phone_contact_point || business_phone_contact_point).try(:detail) end |
#home_phone=(value) ⇒ Object
131 132 133 134 135 136 137 |
# File 'app/models/service_job.rb', line 131 def home_phone=(value) if home_phone_contact_point && home_phone_contact_point.party_id.nil? home_phone_contact_point.detail = value.to_s[0..19] elsif value.present? build_home_phone_contact_point(category: ContactPoint::PHONE, detail: value) end end |
#home_phone_contact_point ⇒ ContactPoint
98 |
# File 'app/models/service_job.rb', line 98 belongs_to :home_phone_contact_point, class_name: 'ContactPoint', optional: true |
#ok_to_delete ⇒ Object
115 116 117 |
# File 'app/models/service_job.rb', line 115 def ok_to_delete uploads.empty? and (draft? or waiting_to_schedule? or cancelled?) end |
#primary_phone ⇒ Object
175 176 177 |
# File 'app/models/service_job.rb', line 175 def primary_phone home_phone || cell_phone || business_phone end |
#search_text ⇒ Object
179 180 181 182 183 184 |
# File 'app/models/service_job.rb', line 179 def search_text st = [] st << serial_number st += address.to_array if address st.join(' ') end |
#set_best_guess_email_contact_point ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/models/service_job.rb', line 186 def set_best_guess_email_contact_point # email, try order tracking email if it matches any customer or contacts email (create in customer if needed), otherwise try order opp contact, then customer email, then first email in any customer and contacts. email_cp_detail = order.first_tracking_email if email_cp_detail.present? self.email_contact_point = order.customer.contacts_and_self_contact_points_by_category(ContactPoint::EMAIL).find { |cp| cp.detail.to_s.strip.downcase == email_cp_detail.to_s.strip.downcase } self.email_contact_point ||= order.customer.contact_points.create({ detail: email_cp_detail, category: ContactPoint::EMAIL }) # puts "self.guess_best_email_cp_id, create order tracking email cp in customer: service_job.email_contact_point: #{self.email_contact_point.detail rescue 'nil'}" else nil best_party = order.contact best_party ||= order.opportunity.contact if order.opportunity.present? best_party ||= order.customer self.email_contact_point = best_party.first_contact_point_by_category(ContactPoint::EMAIL) self.email_contact_point ||= order.customer.contacts_and_self_contact_points_by_category(ContactPoint::EMAIL).first end end |
#set_best_guess_home_phone_contact_point ⇒ Object
203 204 205 206 207 208 209 |
# File 'app/models/service_job.rb', line 203 def set_best_guess_home_phone_contact_point # phone, try order shipping phone if it matches any customer or contacts phone (create in customer if needed) cp_detail = order.shipping_phone || order.customer.phone || order.customer.cell_phone cp = order.customer.contacts_and_self_callable_contact_points.find { |cp| cp.detail.to_s.strip.tr('^+xX0123456789', '').downcase == cp_detail.to_s.strip.tr('^+xX0123456789', '').downcase } cp ||= order.customer.contact_points.create({ detail: cp_detail, category: ContactPoint::PHONE }) self.home_phone_contact_point = cp end |
#set_reference_number ⇒ Object
119 120 121 122 123 124 125 |
# File 'app/models/service_job.rb', line 119 def set_reference_number unless reference_number seq = ServiceJob.find_by_sql("SELECT nextval('service_job_reference_numbers_seq') AS reference_number") self.reference_number = seq[0].reference_number.to_s end true end |
#set_serial_number ⇒ Object
211 212 213 214 215 |
# File 'app/models/service_job.rb', line 211 def set_serial_number return if serial_number self.serial_number = Encryption.encrypt_string(reference_number) if reference_number.present? end |
#uploads ⇒ ActiveRecord::Relation<Upload>
105 |
# File 'app/models/service_job.rb', line 105 has_many :uploads, -> { order(:updated_at).reverse_order }, as: :resource, dependent: :destroy |