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
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::EventPublishable
Instance Attribute Details
#job_comments ⇒ Object (readonly)
114 |
# File 'app/models/service_job.rb', line 114 validates :job_comments, :length => { :maximum => 255 } |
Class Method Details
.active ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are active. Active Record Scope
109 |
# File 'app/models/service_job.rb', line 109 scope :active, -> { where("service_jobs.state <> 'cancelled'") } |
.complete ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are complete. Active Record Scope
110 |
# File 'app/models/service_job.rb', line 110 scope :complete, -> { where("service_jobs.state = 'complete'") } |
.open_jobs ⇒ ActiveRecord::Relation<ServiceJob>
A relation of ServiceJobs that are open jobs. Active Record Scope
108 |
# File 'app/models/service_job.rb', line 108 scope :open_jobs, -> { where("service_jobs.state IN ('draft', 'waiting_to_schedule', 'needs_programming_details')") } |
Instance Method Details
#address ⇒ Address
98 |
# File 'app/models/service_job.rb', line 98 belongs_to :address, :inverse_of => :service_jobs, optional: true |
#business_phone ⇒ Object
164 165 166 |
# File 'app/models/service_job.rb', line 164 def business_phone business_phone_contact_point.try(:detail) end |
#business_phone=(value) ⇒ Object
168 169 170 171 172 173 174 |
# File 'app/models/service_job.rb', line 168 def business_phone=(value) if business_phone_contact_point and 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
102 |
# File 'app/models/service_job.rb', line 102 belongs_to :business_phone_contact_point, :class_name => 'ContactPoint', :foreign_key => 'business_phone_contact_point_id', optional: true |
#cell_phone ⇒ Object
152 153 154 |
# File 'app/models/service_job.rb', line 152 def cell_phone cell_phone_contact_point.try(:detail) end |
#cell_phone=(value) ⇒ Object
156 157 158 159 160 161 162 |
# File 'app/models/service_job.rb', line 156 def cell_phone=(value) if cell_phone_contact_point and 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
101 |
# File 'app/models/service_job.rb', line 101 belongs_to :cell_phone_contact_point, :class_name => 'ContactPoint', :foreign_key => 'cell_phone_contact_point_id', optional: true |
#contact ⇒ Contact
104 |
# File 'app/models/service_job.rb', line 104 belongs_to :contact, class_name: 'Contact', optional: true, inverse_of: :service_jobs |
#email ⇒ Object
140 141 142 |
# File 'app/models/service_job.rb', line 140 def email email_contact_point.try(:detail) end |
#email=(value) ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/models/service_job.rb', line 144 def email=(value) if email_contact_point and 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
100 |
# File 'app/models/service_job.rb', line 100 belongs_to :email_contact_point, :class_name => 'ContactPoint', :foreign_key => 'email_contact_point_id', optional: true |
#home_phone ⇒ Object
128 129 130 |
# File 'app/models/service_job.rb', line 128 def home_phone (home_phone_contact_point || cell_phone_contact_point || business_phone_contact_point).try(:detail) end |
#home_phone=(value) ⇒ Object
132 133 134 135 136 137 138 |
# File 'app/models/service_job.rb', line 132 def home_phone=(value) if home_phone_contact_point and 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
99 |
# File 'app/models/service_job.rb', line 99 belongs_to :home_phone_contact_point, :class_name => 'ContactPoint', :foreign_key => 'home_phone_contact_point_id', optional: true |
#ok_to_delete ⇒ Object
116 117 118 |
# File 'app/models/service_job.rb', line 116 def ok_to_delete self.uploads.empty? and (self.draft? or self.waiting_to_schedule? or self.cancelled?) end |
#primary_phone ⇒ Object
176 177 178 |
# File 'app/models/service_job.rb', line 176 def primary_phone self.home_phone || self.cell_phone || self.business_phone end |
#search_text ⇒ Object
180 181 182 183 184 185 |
# File 'app/models/service_job.rb', line 180 def search_text st = [] st << serial_number st += address.to_array if address st.join(' ') end |
#set_best_guess_email_contact_point ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/models/service_job.rb', line 187 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 = self.order.first_tracking_email if email_cp_detail.present? self.email_contact_point = self.order.customer.contacts_and_self_contact_points_by_category(ContactPoint::EMAIL).detect{|cp| cp.detail.to_s.strip.downcase == email_cp_detail.to_s.strip.downcase} self.email_contact_point ||= self.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 best_party = nil best_party = self.order.contact best_party ||= self.order.opportunity.contact if order.opportunity.present? best_party ||= self.order.customer self.email_contact_point = best_party.first_contact_point_by_category(ContactPoint::EMAIL) self.email_contact_point ||= self.order.customer.contacts_and_self_contact_points_by_category(ContactPoint::EMAIL).first end end |
#set_best_guess_home_phone_contact_point ⇒ Object
204 205 206 207 208 209 210 |
# File 'app/models/service_job.rb', line 204 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 = self.order.shipping_phone || self.order.customer.phone || self.order.customer.cell_phone cp = self.order.customer.contacts_and_self_callable_contact_points.detect{|cp| cp.detail.to_s.strip.tr('^+xX0123456789','').downcase == cp_detail.to_s.strip.tr('^+xX0123456789','').downcase} cp ||= self.order.customer.contact_points.create({:detail => cp_detail, :category => ContactPoint::PHONE}) self.home_phone_contact_point = cp end |
#set_reference_number ⇒ Object
120 121 122 123 124 125 126 |
# File 'app/models/service_job.rb', line 120 def set_reference_number unless self.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 return true end |
#set_serial_number ⇒ Object
212 213 214 215 216 |
# File 'app/models/service_job.rb', line 212 def set_serial_number unless self.serial_number self.serial_number = Encryption.encrypt_string(self.reference_number) if self.reference_number.present? end end |
#uploads ⇒ ActiveRecord::Relation<Upload>
106 |
# File 'app/models/service_job.rb', line 106 has_many :uploads, -> { order(:updated_at).reverse_order }, :as => :resource, :dependent => :destroy |