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
185
186
187
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 185
def anonymous?
cpd_audit_level&.anonymous?
end
|
#assign_anonymous_name_and_number ⇒ Object
The name pattern is A23XXX where XXX is an autoincrement
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 279
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
206
207
208
209
210
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 206
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
248
249
250
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 248
def completed?
submitted_at.present?
end
|
#cpd_audit_level_section(wizard_step) ⇒ Object
The dynamic CPD Audit Level Sections steps
190
191
192
193
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 190
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
196
197
198
199
200
201
202
203
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 196
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
212
213
214
215
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 212
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
265
266
267
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 265
def deadline_to_conflict_of_interest
cpd_audit&.deadline_to_conflict_of_interest
end
|
#deadline_to_review ⇒ Object
269
270
271
272
273
274
275
276
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 269
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
252
253
254
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 252
def done?
submitted_at.present?
end
|
#draft? ⇒ Boolean
240
241
242
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 240
def draft?
submitted_at.blank?
end
|
256
257
258
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 256
def email_form_defaults(action)
{ from: EffectiveCpd.mailer_sender }
end
|
#extension_granted! ⇒ Object
Called by CpdAudit.extension_granted
218
219
220
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 218
def extension_granted!
self.due_date = deadline_to_review()
end
|
#in_progress? ⇒ Boolean
244
245
246
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 244
def in_progress?
submitted_at.blank?
end
|
#name ⇒ Object
181
182
183
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 181
def name
anonymous_name.presence || user.to_s
end
|
#ready! ⇒ Object
Called by CpdAudit.submit!
223
224
225
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 223
def ready!
send_email(:cpd_audit_review_ready)
end
|
#ready? ⇒ Boolean
When ready, the applicant review wizard hides the waiting step
236
237
238
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 236
def ready?
cpd_audit&.ready_to_review?
end
|
#send_email(email) ⇒ Object
260
261
262
263
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 260
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
228
229
230
231
232
233
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 228
def submit!
update!(submitted_at: Time.zone.now)
cpd_audit.try_review!
send_email(:cpd_audit_review_submitted)
end
|
#to_s ⇒ Object
177
178
179
|
# File 'app/models/concerns/effective_cpd_audit_review.rb', line 177
def to_s
persisted? ? "#{cpd_audit_level} Audit Review by #{name}" : 'audit review'
end
|