Module: EffectiveMembershipsFeePayment

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

Overview

EffectiveMembershipsFeePayment

Mark your model with effective_memberships_fee_payment to get all the includes

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#build_organization(params = {}) ⇒ Object



219
220
221
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 219

def build_organization(params = {})
  self.organization = EffectiveMemberships.Organization.new(params)
end

#cpd_completed_cpd_cyclesObject



281
282
283
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 281

def cpd_completed_cpd_cycles
  cpd_required_cpd_cycles.select { |cpd_cycle| user&.cpd_statement(cpd_cycle: cpd_cycle)&.completed? }
end

#cpd_required_cpd_cyclesObject



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 254

def cpd_required_cpd_cycles
  @cpd_required_cpd_cycles ||= begin
    date =  || Time.zone.now

    cpd_cycles = [] # Return value

    # The current and previous cycle
    current = EffectiveCpd.current_cpd_cycle(date: date)
    previous = EffectiveCpd.previous_cpd_cycle(date: date)

    if current.present? && cpd_requirement.to_s.include?('current')
      cpd_cycles << current
    end

    # Only include if they were a member during the previous period
    if previous.present? && cpd_requirement.to_s.include?('previous')
      period = EffectiveMemberships.Registrar.period(date: previous.end_at&.advance(months: -1) || current&.start_at&.advance(months: -1) || previous.start_at.advance(months: 1))
      renewal_date = EffectiveMemberships.Registrar.renewal_fee_date(date: period)
      membership_history = owner.membership_history_on(renewal_date.advance(days: -1))

      cpd_cycles << previous if membership_history.present? && !membership_history.removed?
    end

    cpd_cycles
  end
end

#cpd_requirementObject

CPD Step



250
251
252
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 250

def cpd_requirement
  (category&.fee_payment_cpd_step_requirement.presence || EffectiveMemberships.Category.cpd_step_requirements.first)
end

#cpd_uncompleted_cpd_cyclesObject



285
286
287
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 285

def cpd_uncompleted_cpd_cycles
  cpd_required_cpd_cycles.reject { |cpd_cycle| user&.cpd_statement(cpd_cycle: cpd_cycle)&.completed? }
end

#done?Boolean

Returns:

  • (Boolean)


236
237
238
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 236

def done?
  
end

#in_progress?Boolean

Instance Methods

Returns:

  • (Boolean)


232
233
234
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 232

def in_progress?
  draft?
end

#individual?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 223

def individual?
  !owner.kind_of?(EffectiveMemberships.Organization)
end

#organization?Boolean

Returns:

  • (Boolean)


227
228
229
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 227

def organization?
  owner.kind_of?(EffectiveMemberships.Organization)
end

#ownerObject



211
212
213
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 211

def owner
  organization || user
end

#owner_symbolObject



215
216
217
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 215

def owner_symbol
  organization? ? :organization : :user
end

#reset!Object



244
245
246
247
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 244

def reset!
  assign_attributes(wizard_steps: wizard_steps.slice(:start))
  save!
end

#select!Object



240
241
242
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 240

def select!
  reset!
end

#to_sObject



207
208
209
# File 'app/models/concerns/effective_memberships_fee_payment.rb', line 207

def to_s
  'Fee Payment'
end