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



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

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

#completed?Boolean Also known as: submitted?

Returns:

  • (Boolean)


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

def completed?
  .present?
end

#import!(date: nil) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'app/models/concerns/effective_cpd_statement.rb', line 106

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)


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

def in_progress?
  .blank?
end

#round_amount(amount) ⇒ Decimal

This method is used in CpdScore#score so it can be overridden to provide a custom round score calculation. Any model that is a statement can override this method to provide a custom round score calculation.

Parameters:

  • amount (Decimal)

Returns:

  • (Decimal)

    rounded decimal



166
167
168
# File 'app/models/concerns/effective_cpd_statement.rb', line 166

def round_amount(amount)
  return amount
end

#score_per_categoryObject

=> 20, category_id => 15



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

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



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

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

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

#target_scoreObject



137
138
139
# File 'app/models/concerns/effective_cpd_statement.rb', line 137

def target_score
  user.cpd_target_score(cpd_cycle: cpd_cycle)
end

#target_score_required_to_submit?Boolean

Returns:

  • (Boolean)


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

def target_score_required_to_submit?
  user.cpd_target_score_required_to_submit?(cpd_cycle: cpd_cycle)
end

#to_sObject



102
103
104
# File 'app/models/concerns/effective_cpd_statement.rb', line 102

def to_s
  cpd_cycle.present? ? "#{cpd_cycle} #{model_name.human}" : model_name.human
end

#unsubmit!Object

Called by admin only. This is an exceptional action



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

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