Module: EffectiveCpdStatement

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/effective_cpd_statement.rb

Overview

EffectiveCpdStatement

Mark your owner model with effective_cpd_statement to get all the includes

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#carry_forwardObject



146
147
148
# File 'app/models/concerns/effective_cpd_statement.rb', line 146

def carry_forward
  cpd_statement_activities.sum { |activity| activity.carry_forward || BigDecimal(0) }.to_d
end

#completed?Boolean Also known as: submitted?

Returns:

  • (Boolean)


127
128
129
# File 'app/models/concerns/effective_cpd_statement.rb', line 127

def completed?
  .present?
end

#import!(date: nil) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'app/models/concerns/effective_cpd_statement.rb', line 101

def import!(date: nil)
  date ||= Time.zone.now

  wizard_steps[:start] ||= date
  wizard_steps[:activities] ||= date
  cpd_statement_activities.each { |activity| activity.importing = true }

  save!
end

#in_progress?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/models/concerns/effective_cpd_statement.rb', line 123

def in_progress?
  .blank?
end

#required_scoreObject



132
133
134
135
136
137
# File 'app/models/concerns/effective_cpd_statement.rb', line 132

def required_score
  required_by_cycle = cpd_cycle&.required_score
  required_by_user = user.cpd_statement_required_score(self) if user.respond_to?(:cpd_statement_required_score)

  [required_by_cycle, required_by_user].compact.max
end

#score_per_categoryObject

=> 20, category_id => 15



151
152
153
154
155
# File 'app/models/concerns/effective_cpd_statement.rb', line 151

def score_per_category
  @score_per_category ||= Hash.new(BigDecimal(0)).tap do |scores|
    cpd_statement_activities.each { |activity| scores[activity.cpd_category_id] += activity.score.to_d }
  end
end

#submit!Object

This is the review step where they click Submit Ballot



112
113
114
115
116
# File 'app/models/concerns/effective_cpd_statement.rb', line 112

def submit!
  wizard_steps[:complete] ||= Time.zone.now

  update!(submitted_at: Time.zone.now)
end

#targeted_scoreObject



139
140
141
142
143
144
# File 'app/models/concerns/effective_cpd_statement.rb', line 139

def targeted_score
  targeted_by_cycle = cpd_cycle&.targeted_score
  targeted_by_user = user.cpd_statement_targeted_score(self) if user.respond_to?(:cpd_statement_targeted_score)

  [targeted_by_cycle, targeted_by_user].compact.max
end

#to_sObject



97
98
99
# File 'app/models/concerns/effective_cpd_statement.rb', line 97

def to_s
  cpd_cycle.present? ? "#{cpd_cycle} Statement" : 'statement'
end

#unsubmit!Object

Called by admin only. This is an exceptional action



119
120
121
# File 'app/models/concerns/effective_cpd_statement.rb', line 119

def unsubmit!
  update!(wizard_steps: {}, submitted_at: nil, confirm_readonly: nil)
end