Module: EffectiveCpdAuditReview
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_cpd_audit_review.rb
Overview
EffectiveCpdUser
Mark your user model with effective_cpd_user to get a few helpers And user specific point required scores
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary
collapse
Instance Method Details
#anonymous? ⇒ Boolean
188
189
190
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 188
def anonymous?
cpd_audit_level&.anonymous?
end
|
#assign_anonymous_name_and_number ⇒ Object
The name pattern is A23XXX where XXX is an autoincrement
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 282
def assign_anonymous_name_and_number
return if anonymous_name.present? || anonymous_number.present?
return if cpd_audit_level.blank?
prefix = cpd_audit_level.anonymous_audit_reviews_prefix
raise('expected cpd audit level to have an anonymous audit review prefix') unless prefix.present?
number = cpd_audit.cpd_audit_reviews.map { |ar| ar.anonymous_number }.compact.max if cpd_audit.new_record?
number ||= (self.class.all.where('anonymous_name LIKE ?', "#{prefix}%").maximum('anonymous_number') || 0)
number = number + 1
name = prefix + number.to_s.rjust(3, '0')
assign_attributes(anonymous_number: number, anonymous_name: name)
end
|
#auditee_cpd_statements ⇒ Object
The dynamic CPD Statement review steps
209
210
211
212
213
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 209
def auditee_cpd_statements
cpd_audit.user.cpd_statements.select do |cpd_statement|
cpd_statement.completed? && (submitted_at.blank? || cpd_statement.submitted_at < submitted_at)
end
end
|
#completed? ⇒ Boolean
251
252
253
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 251
def completed?
submitted_at.present?
end
|
#cpd_audit_level_section(wizard_step) ⇒ Object
The dynamic CPD Audit Level Sections steps
193
194
195
196
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 193
def cpd_audit_level_section(wizard_step)
position = (wizard_step.to_s.split('section').last.to_i rescue false)
cpd_audit_level.cpd_audit_level_sections.find { |section| (section.position + 1) == position }
end
|
#cpd_audit_review_item(item) ⇒ Object
199
200
201
202
203
204
205
206
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 199
def cpd_audit_review_item(item)
unless item.kind_of?(Effective::CpdAuditResponse) || item.kind_of?(Effective::CpdStatementActivity)
raise("expected a cpd_audit_response or cpd_statement_activity")
end
cpd_audit_review_item = cpd_audit_review_items.find { |cari| cari.item == item }
cpd_audit_review_item ||= cpd_audit_review_items.build(item: item)
end
|
#cpd_statement(wizard_step) ⇒ Object
215
216
217
218
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 215
def cpd_statement(wizard_step)
cpd_cycle_id = (wizard_step.to_s.split('statement').last.to_i rescue false)
auditee_cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle_id }
end
|
#deadline_to_conflict_of_interest ⇒ Object
268
269
270
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 268
def deadline_to_conflict_of_interest
cpd_audit&.deadline_to_conflict_of_interest
end
|
#deadline_to_review ⇒ Object
272
273
274
275
276
277
278
279
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 272
def deadline_to_review
return nil unless cpd_audit_level&.days_to_review.present?
date = cpd_audit&.deadline_to_submit
return nil unless date.present?
EffectiveResources.advance_date(date, business_days: cpd_audit_level.days_to_review)
end
|
#done? ⇒ Boolean
255
256
257
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 255
def done?
submitted_at.present?
end
|
#draft? ⇒ Boolean
243
244
245
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 243
def draft?
submitted_at.blank?
end
|
259
260
261
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 259
def email_form_defaults(action)
{ from: EffectiveCpd.mailer_sender }
end
|
#extension_granted! ⇒ Object
Called by CpdAudit.extension_granted
221
222
223
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 221
def extension_granted!
self.due_date = deadline_to_review()
end
|
#in_progress? ⇒ Boolean
247
248
249
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 247
def in_progress?
submitted_at.blank?
end
|
#name ⇒ Object
184
185
186
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 184
def name
anonymous_name.presence || user.to_s
end
|
#ready! ⇒ Object
Called by CpdAudit.submit!
226
227
228
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 226
def ready!
send_email(:cpd_audit_review_ready)
end
|
#ready? ⇒ Boolean
When ready, the applicant review wizard hides the waiting step
239
240
241
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 239
def ready?
cpd_audit&.ready_to_review?
end
|
#send_email(email) ⇒ Object
263
264
265
266
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 263
def send_email(email)
EffectiveCpd.send_email(email, self, email_form_params) unless email_form_skip?
true
end
|
#submit! ⇒ Object
Called by review wizard submit step
231
232
233
234
235
236
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 231
def submit!
update!(submitted_at: Time.zone.now)
cpd_audit.try_review!
send_email(:cpd_audit_review_submitted)
end
|
#to_s ⇒ Object
180
181
182
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 180
def to_s
persisted? ? "#{cpd_audit_level} #{model_name.human} by #{name}" : model_name.human
end
|