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
680
681
682
683
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 680
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
685
686
687
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 685
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_collection ⇒ Object
672
673
674
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 672
def applicant_course_areas_collection
Effective::ApplicantCourseArea.deep.sorted
end
|
#applicant_course_names_collection(applicant_course_area:) ⇒ Object
676
677
678
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 676
def applicant_course_names_collection(applicant_course_area:)
applicant_course_area.applicant_course_names
end
|
#applicant_courses_sum ⇒ Object
689
690
691
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 689
def applicant_courses_sum
applicant_courses.sum { |ac| ac.amount.to_i }
end
|
#applicant_endorsements_required? ⇒ Boolean
712
713
714
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 712
def applicant_endorsements_required?
required_steps.include?(:endorsements) && min_applicant_endorsements > 0
end
|
#applicant_references_required? ⇒ Boolean
703
704
705
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 703
def applicant_references_required?
required_steps.include?(:references) && min_applicant_references > 0
end
|
#applicant_review(reviewer:) ⇒ Object
833
834
835
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 833
def applicant_review(reviewer:)
applicant_reviews.find { |ar| ar.reviewer_id == reviewer.id && ar.reviewer_type == reviewer.class.name }
end
|
#applicant_reviews_required? ⇒ Boolean
824
825
826
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 824
def applicant_reviews_required?
(min_applicant_reviews > 0 || applicant_reviews.present?)
end
|
#apply_to_join? ⇒ Boolean
561
562
563
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 561
def apply_to_join?
applicant_type == 'Apply to Join'
end
|
#approve! ⇒ Object
Admin approves an applicant. Registers the owner. Sends an email.
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 882
def approve!
raise('already approved') if was_approved?
raise('applicant must have been submitted to approve!') unless was_submitted?
wizard_steps[:checkout] ||= Time.zone.now
wizard_steps[:submitted] ||= Time.zone.now
assign_attributes(missing_info_reason: nil)
approved!
EffectiveMemberships.Registrar.delete_fees!(owner)
if apply_to_join?
EffectiveMemberships.Registrar.register!(
owner,
to: to_category,
status: to_status,
date: approved_membership_date.presence, number: approved_membership_number.presence )
elsif reclassification?
EffectiveMemberships.Registrar.reclassify!(
owner,
to: to_category,
status: to_status,
date: approved_membership_date.presence, number: approved_membership_number.presence )
elsif reinstatement?
EffectiveMemberships.Registrar.reinstate!(
owner,
to: to_category,
date: approved_membership_date.presence, number: approved_membership_number.presence )
else
raise('unsupported approval applicant_type')
end
save!
after_commit { send_email(:applicant_approved) }
true
end
|
#approve_email_templates ⇒ Object
868
869
870
871
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 868
def approve_email_templates
raise('expected EffectiveEmailTemplates') unless defined?(EffectiveEmailTemplates)
Effective::EmailTemplate.where('template_name ILIKE ?', 'applicant_approve%').order(:template_name)
end
|
#build_applicant_review(reviewer:) ⇒ Object
838
839
840
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 838
def build_applicant_review(reviewer:)
applicant_review(reviewer: reviewer) || applicant_reviews.build(reviewer: reviewer)
end
|
#build_organization(params = {}) ⇒ Object
557
558
559
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 557
def build_organization(params = {})
self.organization = EffectiveMemberships.Organization.new(params)
end
|
#can_apply_applicant_types_collection ⇒ Object
623
624
625
626
627
628
629
630
631
632
633
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 623
def can_apply_applicant_types_collection
if owner.blank?
['Apply to Join']
elsif owner.membership_removed? && owner.reinstatement_membership_history.present?
['Apply for Reinstatement', 'Apply to Join']
elsif owner.membership.blank? || owner.membership.categories.blank?
['Apply to Join']
else
['Apply to Reclassify']
end
end
|
#can_apply_categories_collection ⇒ Object
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 636
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.membership.category_ids.map(&:to_s) - [nil, '']
categories.select do |category|
category.can_apply_new? ||
category.can_apply_existing? ||
(category.can_apply_restricted? && (category_ids & category.can_apply_restricted_ids.map(&:to_s)).present?)
end
end
|
#complete! ⇒ Object
788
789
790
791
792
793
794
795
796
797
798
799
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 788
def complete!
raise('applicant must have been submitted to complete!') unless was_submitted?
assign_attributes(missing_info_reason: nil)
completed!
after_commit { send_email(:applicant_completed) }
true
end
|
#completed_requirements ⇒ Object
When an application is submitted, these must be done to go to completed. An Admin can override this and just set them to completed.
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 769
def completed_requirements
requirements = {}
return requirements unless category.present?
if applicant_endorsements_required?
requirements['Applicant Endorsements'] = (applicant_endorsements.count(&:completed?) >= min_applicant_endorsements)
end
if applicant_references_required?
requirements['Applicant References'] = (applicant_references.count(&:completed?) >= min_applicant_references)
end
if transcripts_required?
requirements['Applicant Transcripts'] = transcripts_received?
end
requirements
end
|
#cpd_completed_cpd_cycles ⇒ Object
744
745
746
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 744
def cpd_completed_cpd_cycles
cpd_required_cpd_cycles.select { |cpd_cycle| user&.cpd_statement(cpd_cycle: cpd_cycle)&.completed? }
end
|
#cpd_required_cpd_cycles ⇒ Object
735
736
737
738
739
740
741
742
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 735
def cpd_required_cpd_cycles
date = submitted_at || Time.zone.now
[
(EffectiveCpd.previous_cpd_cycle(date: date) if cpd_requirement.to_s.include?('previous')),
(EffectiveCpd.current_cpd_cycle(date: date) if cpd_requirement.to_s.include?('current'))
].compact
end
|
#cpd_requirement ⇒ Object
731
732
733
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 731
def cpd_requirement
(category&.applicant_cpd_step_requirement.presence || EffectiveMemberships.Category.cpd_step_requirements.first)
end
|
#cpd_uncompleted_cpd_cycles ⇒ Object
748
749
750
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 748
def cpd_uncompleted_cpd_cycles
cpd_required_cpd_cycles.reject { |cpd_cycle| user&.cpd_statement(cpd_cycle: cpd_cycle)&.completed? }
end
|
#decline! ⇒ Object
Admin approves an applicant. Registers the owner. Sends an email.
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 930
def decline!
raise('already declined') if was_declined?
raise('previously approved') if was_approved?
raise('applicant must have been submitted to decline!') unless was_submitted?
wizard_steps[:checkout] ||= Time.zone.now
wizard_steps[:submitted] ||= Time.zone.now
declined!
save!
after_commit { send_email(:applicant_declined) }
true
end
|
#done? ⇒ Boolean
585
586
587
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 585
def done?
approved? || declined?
end
|
#in_progress? ⇒ Boolean
581
582
583
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 581
def in_progress?
!approved? && !declined?
end
|
#individual? ⇒ Boolean
573
574
575
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 573
def individual?
!(owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?)
end
|
#min_applicant_courses ⇒ Object
668
669
670
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 668
def min_applicant_courses
category&.min_applicant_courses.to_i
end
|
#min_applicant_educations ⇒ Object
663
664
665
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 663
def min_applicant_educations
category&.min_applicant_educations.to_i
end
|
#min_applicant_endorsements ⇒ Object
708
709
710
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 708
def min_applicant_endorsements
category&.min_applicant_endorsements.to_i
end
|
#min_applicant_equivalences ⇒ Object
717
718
719
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 717
def min_applicant_equivalences
category&.min_applicant_equivalences.to_i
end
|
#min_applicant_experiences_months ⇒ Object
694
695
696
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 694
def min_applicant_experiences_months
category&.min_applicant_experiences_months.to_i
end
|
#min_applicant_files ⇒ Object
753
754
755
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 753
def min_applicant_files
category&.min_applicant_files.to_i
end
|
#min_applicant_references ⇒ Object
699
700
701
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 699
def min_applicant_references
category&.min_applicant_references.to_i
end
|
#min_applicant_reviews ⇒ Object
828
829
830
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 828
def min_applicant_reviews
category&.min_applicant_reviews.to_i
end
|
#missing! ⇒ Object
801
802
803
804
805
806
807
808
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 801
def missing!
raise('applicant must have been submitted to missing!') unless was_submitted?
missing_info!
after_commit { send_email(:applicant_missing_info) }
true
end
|
#organization? ⇒ Boolean
577
578
579
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 577
def organization?
owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?
end
|
#owner ⇒ Object
549
550
551
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 549
def owner
organization || user
end
|
#owner_symbol ⇒ Object
553
554
555
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 553
def owner_symbol
organization? ? :organization : :user
end
|
#reclassification? ⇒ Boolean
565
566
567
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 565
def reclassification?
applicant_type == 'Apply to Reclassify'
end
|
#reinstatement? ⇒ Boolean
569
570
571
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 569
def reinstatement?
applicant_type == 'Apply for Reinstatement'
end
|
#resubmit! ⇒ Object
810
811
812
813
814
815
816
817
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 810
def resubmit!
raise('applicant must have been submitted and missing info to resubmit!') unless was_submitted? && was_missing_info?
raise('already submitted') if submitted?
raise('expected a purchased order') unless submit_order&.purchased?
assign_attributes(skip_to_step: :submitted, submitted_at: Time.zone.now)
submitted!
end
|
#review! ⇒ Object
861
862
863
864
865
866
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 861
def review!
raise('applicant must have been submitted to review!') unless was_submitted?
reviewed!
end
|
#reviewable? ⇒ Boolean
Completed -> Reviewed requirements
820
821
822
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 820
def reviewable?
completed?
end
|
#reviewed_requirements ⇒ Object
When an application is completed, these must be done to go to reviewed An Admin can override this and just set them to reviewed.
844
845
846
847
848
849
850
851
852
853
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 844
def reviewed_requirements
requirements = {}
return requirements unless category.present?
if applicant_reviews_required?
requirements['Applicant Reviews'] = (applicant_reviews.count(&:done?) >= min_applicant_reviews)
end
requirements
end
|
#select! ⇒ Object
652
653
654
655
656
657
658
659
660
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 652
def select!
raise('cannot select a submitted applicant') if was_submitted?
raise('cannot select a purchased applicant') if orders.any? { |order| order.purchased? }
assign_attributes(wizard_steps: wizard_steps.slice(:start, :select))
save!
end
|
#stamp ⇒ Object
758
759
760
761
762
763
764
765
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 758
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_label ⇒ Object
589
590
591
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 589
def status_label
(status_was || status).to_s.gsub('_', ' ')
end
|
#summary ⇒ Object
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 593
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_category ⇒ Object
873
874
875
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 873
def to_category
category
end
|
#to_s ⇒ Object
543
544
545
546
547
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 543
def to_s
return 'New Applicant' if applicant_type.blank? || category.blank? || owner.blank?
"#{owner} - #{applicant_type} to #{category}"
end
|
#to_status ⇒ Object
877
878
879
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 877
def to_status
nil
end
|
#transcripts_received? ⇒ Boolean
722
723
724
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 722
def transcripts_received?
transcripts_received_on_was.present?
end
|
#transcripts_required? ⇒ Boolean
726
727
728
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 726
def transcripts_required?
required_steps.include?(:transcripts)
end
|
#try_reviewed! ⇒ Object
Called when an applicant_review was submitted
856
857
858
859
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 856
def try_reviewed!
return false unless completed? && reviewed_requirements.values.all?
reviewed!
end
|