Module: EffectiveMembershipsApplicant

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

Overview

EffectiveMembershipsApplicant

Mark your owner model with effective_memberships_applicant to get all the includes

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#applicant_course(applicant_course_name: nil) ⇒ Object



554
555
556
557
# File 'app/models/concerns/effective_memberships_applicant.rb', line 554

def applicant_course(applicant_course_name: nil)
  applicant_courses.find { |ac| ac.applicant_course_name_id == applicant_course_name.id } ||
  applicant_courses.build(applicant_course_name: applicant_course_name, applicant_course_area: applicant_course_name.applicant_course_area)
end

#applicant_course_area_sum(applicant_course_area:) ⇒ Object



559
560
561
# File 'app/models/concerns/effective_memberships_applicant.rb', line 559

def applicant_course_area_sum(applicant_course_area:)
  applicant_courses.select { |ac| ac.applicant_course_area_id == applicant_course_area.id }.sum { |ac| ac.amount.to_i }
end

#applicant_course_areas_collectionObject



546
547
548
# File 'app/models/concerns/effective_memberships_applicant.rb', line 546

def applicant_course_areas_collection
  Effective::ApplicantCourseArea.deep.sorted
end

#applicant_course_names_collection(applicant_course_area:) ⇒ Object



550
551
552
# File 'app/models/concerns/effective_memberships_applicant.rb', line 550

def applicant_course_names_collection(applicant_course_area:)
  applicant_course_area.applicant_course_names
end

#applicant_courses_sumObject



563
564
565
# File 'app/models/concerns/effective_memberships_applicant.rb', line 563

def applicant_courses_sum
  applicant_courses.sum { |ac| ac.amount.to_i }
end

#applicant_endorsements_required?Boolean

Returns:

  • (Boolean)


586
587
588
# File 'app/models/concerns/effective_memberships_applicant.rb', line 586

def applicant_endorsements_required?
  min_applicant_endorsements > 0
end

#applicant_references_required?Boolean

Returns:

  • (Boolean)


577
578
579
# File 'app/models/concerns/effective_memberships_applicant.rb', line 577

def applicant_references_required?
  min_applicant_references > 0
end

#applicant_reviews_required?Boolean

Completed -> Reviewed requirements

Returns:

  • (Boolean)


672
673
674
# File 'app/models/concerns/effective_memberships_applicant.rb', line 672

def applicant_reviews_required?
  (min_applicant_reviews > 0 || applicant_reviews.present?)
end

#apply_to_join?Boolean

Returns:

  • (Boolean)


453
454
455
# File 'app/models/concerns/effective_memberships_applicant.rb', line 453

def apply_to_join?
  applicant_type == 'Apply to Join'
end

#approve!Object

Admin approves an applicant. Registers the owner. Sends an email.



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'app/models/concerns/effective_memberships_applicant.rb', line 697

def approve!
  raise('already approved') if was_approved?
  raise('applicant must have been submitted to approve!') unless 

  # Complete the wizard step. Just incase this is run out of order.
  wizard_steps[:checkout] ||= Time.zone.now
  wizard_steps[:submitted] ||= Time.zone.now
  assign_attributes(missing_info_reason: nil)

  approved!

  if apply_to_join?
    EffectiveMemberships.Registrar.register!(
      owner,
      to: category,
      date: approved_membership_date.presence,       # Set by the Admin Process form, or nil
      number: approved_membership_number.presence    # Set by the Admin Process form, or nil
    )
  elsif reclassification?
    EffectiveMemberships.Registrar.reclassify!(owner, to: category)
  else
    raise('unsupported approval applicant_type')
  end

  save!

  after_commit { send_email(:applicant_approved) }
  true
end

#build_organization(params = {}) ⇒ Object



449
450
451
# File 'app/models/concerns/effective_memberships_applicant.rb', line 449

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

#can_apply_categories_collectionObject

Used by the select step



511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'app/models/concerns/effective_memberships_applicant.rb', line 511

def can_apply_categories_collection
  categories = EffectiveMemberships.Category.sorted.can_apply

  if user.blank? || !user.is?(:member)
    return categories.where(can_apply_new: true)
  end

  category_ids = user.memberships.map(&:category_ids).flatten

  categories.select do |cat|
    cat.can_apply_existing? ||
    (cat.can_apply_restricted? && (category_ids & cat.can_apply_restricted_ids).present?)
  end
end

#complete!Object



640
641
642
643
644
645
646
647
648
649
650
651
# File 'app/models/concerns/effective_memberships_applicant.rb', line 640

def complete!
  raise('applicant must have been submitted to complete!') unless 

  # Let an admin ignore these requirements if need be
  # return false unless submitted? && completed_requirements.values.all?

  assign_attributes(missing_info_reason: nil)
  completed!

  after_commit { send_email(:applicant_completed) }
  true
end

#completed_requirementsObject

When an application is submitted, these must be done to go to completed. An Admin can override this and just set them to completed.



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'app/models/concerns/effective_memberships_applicant.rb', line 621

def completed_requirements
  requirements = {}
  return requirements unless category.present?

  if category.applicant_wizard_steps.include?(:endorsements) || applicant_endorsements_required?
    requirements['Applicant Endorsements'] = (!applicant_endorsements_required? || applicant_endorsements.count(&:completed?) >= min_applicant_endorsements)
  end

  if category.applicant_wizard_steps.include?(:references) || applicant_references_required?
    requirements['Applicant References'] = (!applicant_references_required? || applicant_references.count(&:completed?) >= min_applicant_references)
  end

  if category.applicant_wizard_steps.include?(:transcripts) || transcripts_required?
    requirements['Applicant Transcripts'] = (!transcripts_required? || transcripts_received?)
  end

  requirements
end

#decline!Object

Admin approves an applicant. Registers the owner. Sends an email.



728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'app/models/concerns/effective_memberships_applicant.rb', line 728

def decline!
  raise('already declined') if was_declined?
  raise('previously approved') if was_approved?
  raise('applicant must have been submitted to decline!') unless 

  # Complete the wizard step. Just incase this is run out of order.
  wizard_steps[:checkout] ||= Time.zone.now
  wizard_steps[:submitted] ||= Time.zone.now
  declined!

  save!

  after_commit { send_email(:applicant_declined) }
  true
end

#done?Boolean

Returns:

  • (Boolean)


473
474
475
# File 'app/models/concerns/effective_memberships_applicant.rb', line 473

def done?
  approved? || declined?
end

#in_progress?Boolean

Returns:

  • (Boolean)


469
470
471
# File 'app/models/concerns/effective_memberships_applicant.rb', line 469

def in_progress?
  !approved? && !declined?
end

#individual?Boolean

Returns:

  • (Boolean)


461
462
463
# File 'app/models/concerns/effective_memberships_applicant.rb', line 461

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

#min_applicant_coursesObject

Courses Amounts step



542
543
544
# File 'app/models/concerns/effective_memberships_applicant.rb', line 542

def min_applicant_courses
  category&.min_applicant_courses.to_i
end

#min_applicant_educationsObject

Educations Step



537
538
539
# File 'app/models/concerns/effective_memberships_applicant.rb', line 537

def min_applicant_educations
  category&.min_applicant_educations.to_i
end

#min_applicant_endorsementsObject

Endorsements Step



582
583
584
# File 'app/models/concerns/effective_memberships_applicant.rb', line 582

def min_applicant_endorsements
  category&.min_applicant_endorsements.to_i
end

#min_applicant_equivalencesObject

Equivalences Step



591
592
593
# File 'app/models/concerns/effective_memberships_applicant.rb', line 591

def min_applicant_equivalences
  category&.min_applicant_equivalences.to_i
end

#min_applicant_experiences_monthsObject

Work Experiences Step



568
569
570
# File 'app/models/concerns/effective_memberships_applicant.rb', line 568

def min_applicant_experiences_months
  category&.min_applicant_experiences_months.to_i
end

#min_applicant_filesObject

Files Step



605
606
607
# File 'app/models/concerns/effective_memberships_applicant.rb', line 605

def min_applicant_files
  category&.min_applicant_files.to_i
end

#min_applicant_referencesObject

References Step



573
574
575
# File 'app/models/concerns/effective_memberships_applicant.rb', line 573

def min_applicant_references
  category&.min_applicant_references.to_i
end

#min_applicant_reviewsObject



676
677
678
# File 'app/models/concerns/effective_memberships_applicant.rb', line 676

def min_applicant_reviews
  category&.min_applicant_reviews.to_i
end

#missing!Object



653
654
655
656
657
658
659
660
# File 'app/models/concerns/effective_memberships_applicant.rb', line 653

def missing!
  raise('applicant must have been submitted to missing!') unless 

  missing_info!

  after_commit { send_email(:applicant_missing_info) }
  true
end

#organization?Boolean

Returns:

  • (Boolean)


465
466
467
# File 'app/models/concerns/effective_memberships_applicant.rb', line 465

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

#ownerObject



441
442
443
# File 'app/models/concerns/effective_memberships_applicant.rb', line 441

def owner
  organization || user
end

#owner_symbolObject



445
446
447
# File 'app/models/concerns/effective_memberships_applicant.rb', line 445

def owner_symbol
  organization? ? :organization : :user
end

#reclassification?Boolean

Returns:

  • (Boolean)


457
458
459
# File 'app/models/concerns/effective_memberships_applicant.rb', line 457

def reclassification?
  applicant_type == 'Apply to Reclassify'
end

#resubmit!Object



662
663
664
665
666
667
668
669
# File 'app/models/concerns/effective_memberships_applicant.rb', line 662

def resubmit!
  raise('applicant must have been submitted and missing info to resubmit!') unless  && was_missing_info?
  raise('already submitted') if 
  raise('expected a purchased order') unless submit_order&.purchased?

  assign_attributes(skip_to_step: :submitted, submitted_at: Time.zone.now)
  
end

#review!Object



688
689
690
691
692
693
694
# File 'app/models/concerns/effective_memberships_applicant.rb', line 688

def review!
  raise('applicant must have been submitted to review!') unless 

  # Let an admin ignore these requirements if need be
  # return false unless completed? && reviewed_requirements.values.all?
  reviewed!
end

#reviewed_requirementsObject

When an application is completed, these must be done to go to reviewed An Admin can override this and just set them to reviewed.



682
683
684
685
686
# File 'app/models/concerns/effective_memberships_applicant.rb', line 682

def reviewed_requirements
  {
    'Applicant Reviews' => (!applicant_reviews_required? || applicant_reviews.count(&:completed?) >= min_applicant_reviews)
  }
end

#select!Object



526
527
528
529
530
531
532
533
534
# File 'app/models/concerns/effective_memberships_applicant.rb', line 526

def select!
  raise('cannot select a submitted applicant') if 
  raise('cannot select a purchased applicant') if orders.any? { |order| order.purchased? }

  # Reset the progress so far. They have to click through screens again.
  assign_attributes(wizard_steps: wizard_steps.slice(:start, :select))

  save!
end

#stampObject

Stamps step



610
611
612
613
614
615
616
617
# File 'app/models/concerns/effective_memberships_applicant.rb', line 610

def stamp
  stamps.first || stamps.build(
    owner: owner,
    name: owner.to_s,
    shipping_address: (owner.try(:shipping_address) || owner.try(:billing_address)),
    price: 0
  )
end

#status_labelObject



477
478
479
# File 'app/models/concerns/effective_memberships_applicant.rb', line 477

def status_label
  (status_was || status).to_s.gsub('_', ' ')
end

#summaryObject



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'app/models/concerns/effective_memberships_applicant.rb', line 481

def summary
  case status_was
  when 'draft'
    "Applicant has not yet completed the #{category} wizard steps or paid to submit this application. This application will transition to 'submitted' after payment has been collected."
  when 'submitted'
    summary = "Application has been purchased and submitted."
    tasks = "The following tasks remain before it can be completed:"
    approval = "Waiting on approval."
    items = completed_requirements.map { |item, done| "<li>#{item}: #{done ? 'Complete' : 'Incomplete'}</li>" }.join
    completed_requirements.present? ? "<p>#{summary} #{tasks}</p><ul>#{items}</ul>" : "#{summary} #{approval}"
  when 'completed'
    if applicant_reviews_required?
      "All required materials have been provided. This application will transition to 'reviewed' after all reviewers have voted."
    else
      "This application has been completed and is now ready for an admin to approve or decline it. If approved, prorated fees will be generated."
    end
  when 'missing_info'
    "Missing the following information: <ul><li>#{missing_info_reason}</li></ul>"
  when 'reviewed'
    "This application has been reviewed and is now ready for an admin to approve or decline it. If approved, prorated fees will be generated."
  when 'approved'
    "The application has been approved! All done!"
  when 'declined'
    "This application has been declined."
  else
    raise("unexpected status #{status}")
  end.html_safe
end

#to_sObject

Instance Methods



426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'app/models/concerns/effective_memberships_applicant.rb', line 426

def to_s
  if category.present? && category.present?
    [
      owner.to_s,
      '-',
      category,
      'for',
      category,
      ("from #{from_category}" if reclassification?)
    ].compact.join(' ')
  else
    'New Applicant'
  end
end

#transcripts_received?Boolean

Transcripts Step

Returns:

  • (Boolean)


596
597
598
# File 'app/models/concerns/effective_memberships_applicant.rb', line 596

def transcripts_received?
  transcripts_received_on_was.present?
end

#transcripts_required?Boolean

Returns:

  • (Boolean)


600
601
602
# File 'app/models/concerns/effective_memberships_applicant.rb', line 600

def transcripts_required?
  category.applicant_wizard_steps.include?(:transcripts)
end