Class: Certification
Overview
== Schema Information
Table name: certifications
Database name: primary
id :bigint not null, primary key
attachment_name :string
attachment_uid :string
certified_by :integer
certified_on :datetime
expiration_reminder_10_days_sent :boolean default(FALSE), not null
expiration_reminder_10_days_sent_on :datetime
expiration_reminder_30_days_sent :boolean default(FALSE), not null
expiration_reminder_30_days_sent_on :datetime
expired_reminder_sent :boolean default(FALSE), not null
expired_reminder_sent_on :datetime
expires_at :datetime
reference :string
state :string
title :string
welcome_meeting :boolean default(FALSE), not null
welcome_meeting_date :datetime
workshop_attended :boolean
workshop_attended_date :datetime
created_at :datetime not null
updated_at :datetime not null
course_enrollment_id :integer
party_id :integer
Indexes
idx_party_id (party_id)
Constant Summary
Models::Auditable::ALWAYS_IGNORED
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Class Method Details
.active ⇒ ActiveRecord::Relation<Certification>
A relation of Certifications that are active. Active Record Scope
49
|
# File 'app/models/certification.rb', line 49
scope :active, -> {where(state: 'active')}
|
.expired ⇒ ActiveRecord::Relation<Certification>
A relation of Certifications that are expired. Active Record Scope
50
|
# File 'app/models/certification.rb', line 50
scope :expired, -> {where(state: 'expired')}
|
.requested ⇒ ActiveRecord::Relation<Certification>
A relation of Certifications that are requested. Active Record Scope
51
|
# File 'app/models/certification.rb', line 51
scope :requested, -> {where(state: 'requested')}
|
.title ⇒ Object
192
193
194
|
# File 'app/models/certification.rb', line 192
def self.title
title ||= course_enrollment.course&.name
end
|
Instance Method Details
45
|
# File 'app/models/certification.rb', line 45
has_one :agreement, as: :resource
|
#agreement_ok? ⇒ Boolean
124
125
126
|
# File 'app/models/certification.rb', line 124
def agreement_ok?
agreement.present? && agreement.signed?
end
|
#can_be_activated? ⇒ Boolean
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'app/models/certification.rb', line 99
def can_be_activated?
liability = liability_ok?
meeting = welcome_meeting_ok?
workshop = workshop_attended_ok?
agreement = agreement_ok?
return liability && meeting && workshop && agreement
end
|
#certificate_link ⇒ Object
196
197
198
|
# File 'app/models/certification.rb', line 196
def certificate_link
url = "#{WEB_URL}/my_account/certifications/#{self.id}"
end
|
43
|
# File 'app/models/certification.rb', line 43
belongs_to :contact, class_name: 'Party', foreign_key: 'party_id', optional: true, inverse_of: :certifications
|
40
|
# File 'app/models/certification.rb', line 40
belongs_to :course_enrollment, optional: true
|
#create_agreement ⇒ Object
142
143
144
145
146
147
148
149
150
|
# File 'app/models/certification.rb', line 142
def create_agreement
agreement = self.build_agreement(sign_method: 'esignatures', template: 'installer_agreement')
agreement.agreement_participants.new(
party_id: self.party_id
)
if agreement.save
agreement.send_to_esignatures
end
end
|
#create_welcome_meeting_activity ⇒ Object
216
217
218
219
220
221
222
|
# File 'app/models/certification.rb', line 216
def create_welcome_meeting_activity
Activity.create(lock_target_datetime: true,
activity_type_id: ActivityType.find_by(task_type: 'INSTALL_CERTIFICATION_PM')&.id,
party: self.party,
resource: self,
notes: "Welcome meeting for new certification request. Please arrange meeting.")
end
|
#create_workshop_activity ⇒ Object
208
209
210
211
212
213
214
|
# File 'app/models/certification.rb', line 208
def create_workshop_activity
Activity.create(lock_target_datetime: true,
activity_type_id: ActivityType.find_by(task_type: 'INSTALL_CERTIFICATION_PWS')&.id,
party: self.party,
resource: self,
notes: "New certification requires workshop to attend. Please schedule and verify this customer attends.")
end
|
#customer ⇒ Party
42
|
# File 'app/models/certification.rb', line 42
belongs_to :customer, class_name: 'Party', foreign_key: 'party_id', optional: true
|
#liability_ok? ⇒ Boolean
112
113
114
|
# File 'app/models/certification.rb', line 112
def liability_ok?
party.customer.liability_insurances.active.any? && customer.liability_insurances.effective_on(Time.current).present?
end
|
41
|
# File 'app/models/certification.rb', line 41
belongs_to :party, optional: true
|
#possible_events ⇒ Object
200
201
202
|
# File 'app/models/certification.rb', line 200
def possible_events
state_transitions.map(&:event).sort
end
|
#possible_events_for_select ⇒ Object
204
205
206
|
# File 'app/models/certification.rb', line 204
def possible_events_for_select
possible_events.map { |evt| [evt.to_s.titleize, evt] }
end
|
#send_admin_alert ⇒ Object
#send_congratulations_email ⇒ Object
152
153
154
155
156
157
158
|
# File 'app/models/certification.rb', line 152
def send_congratulations_email
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'NEW_INSTALLER').create
end
|
#send_expiration_reminder ⇒ Object
178
179
180
181
182
183
184
185
186
|
# File 'app/models/certification.rb', line 178
def send_expiration_reminder
InternalMailer.certification_expired(self).deliver_later!
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'CERT_EXPIRED').create
self.update(expired_reminder_sent: true, expired_reminder_sent_on: Time.current)
end
|
#send_expiration_reminder_10 ⇒ Object
169
170
171
172
173
174
175
176
|
# File 'app/models/certification.rb', line 169
def send_expiration_reminder_10
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'CERT_EXPIRES_10').create
self.update(expiration_reminder_10_days_sent: true, expiration_reminder_10_days_sent_on: Time.current)
end
|
#send_expiration_reminder_30 ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'app/models/certification.rb', line 160
def send_expiration_reminder_30
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'CERT_EXPIRES_30').create
self.update(expiration_reminder_30_days_sent: true, expiration_reminder_30_days_sent_on: Time.current)
end
|
#set_party ⇒ Object
136
137
138
139
140
|
# File 'app/models/certification.rb', line 136
def set_party
if course_enrollment.party.present? && self.party_id.nil?
self.party_id = course_enrollment.party.id
end
end
|
#set_reference_number ⇒ Object
132
133
134
|
# File 'app/models/certification.rb', line 132
def set_reference_number
self.update(reference: "CER#{self.id.to_s.rjust(4, '0')}")
end
|
#set_title ⇒ Object
128
129
130
|
# File 'app/models/certification.rb', line 128
def set_title
self.title = course_enrollment&.course&.name unless title.present?
end
|
#welcome_meeting_ok? ⇒ Boolean
116
117
118
|
# File 'app/models/certification.rb', line 116
def welcome_meeting_ok?
welcome_meeting.to_b
end
|
#workshop_attended_ok? ⇒ Boolean
120
121
122
|
# File 'app/models/certification.rb', line 120
def workshop_attended_ok?
workshop_attended.to_b
end
|