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
192
193
194
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 192
def anonymous?
cpd_audit_level&.anonymous?
end
|
#assign_anonymous_name_and_number ⇒ Object
The name pattern is A23XXX where XXX is an autoincrement
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 286
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
213
214
215
216
217
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 213
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
255
256
257
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 255
def completed?
submitted_at.present?
end
|
#cpd_audit_level_section(wizard_step) ⇒ Object
The dynamic CPD Audit Level Sections steps
197
198
199
200
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 197
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
203
204
205
206
207
208
209
210
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 203
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
219
220
221
222
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 219
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
272
273
274
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 272
def deadline_to_conflict_of_interest
cpd_audit&.deadline_to_conflict_of_interest
end
|
#deadline_to_review ⇒ Object
276
277
278
279
280
281
282
283
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 276
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
259
260
261
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 259
def done?
submitted_at.present?
end
|
#draft? ⇒ Boolean
247
248
249
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 247
def draft?
submitted_at.blank?
end
|
263
264
265
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 263
def email_form_defaults(action)
{ from: EffectiveCpd.mailer_sender }
end
|
#extension_granted! ⇒ Object
Called by CpdAudit.extension_granted
225
226
227
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 225
def extension_granted!
self.due_date = deadline_to_review()
end
|
#in_progress? ⇒ Boolean
251
252
253
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 251
def in_progress?
submitted_at.blank?
end
|
#name ⇒ Object
188
189
190
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 188
def name
anonymous_name.presence || user.to_s
end
|
#ready! ⇒ Object
Called by CpdAudit.submit!
230
231
232
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 230
def ready!
send_email(:cpd_audit_review_ready)
end
|
#ready? ⇒ Boolean
When ready, the applicant review wizard hides the waiting step
243
244
245
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 243
def ready?
cpd_audit&.ready_to_review?
end
|
#send_email(email) ⇒ Object
267
268
269
270
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 267
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
235
236
237
238
239
240
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 235
def submit!
update!(submitted_at: Time.zone.now)
cpd_audit.try_review!
send_email(:cpd_audit_review_submitted)
end
|
#to_s ⇒ Object
184
185
186
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 184
def to_s
persisted? ? "#{cpd_audit_level} #{model_name.human} by #{name}" : model_name.human
end
|