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
- #applicant_course(applicant_course_name: nil) ⇒ Object
- #applicant_course_area_sum(applicant_course_area:) ⇒ Object
- #applicant_course_areas_collection ⇒ Object
- #applicant_course_names_collection(applicant_course_area:) ⇒ Object
- #applicant_courses_sum ⇒ Object
- #applicant_endorsements_required? ⇒ Boolean
- #applicant_references_required? ⇒ Boolean
-
#applicant_review(reviewer:) ⇒ Object
Find.
- #applicant_reviews_required? ⇒ Boolean
- #apply_to_join? ⇒ Boolean
-
#approve! ⇒ Object
Admin approves an applicant.
- #approve_email_templates ⇒ Object
-
#build_applicant_review(reviewer:) ⇒ Object
Find or build.
- #build_organization(params = {}) ⇒ Object
-
#can_apply_applicant_types_collection ⇒ Object
Used by the select step.
-
#can_apply_categories_collection ⇒ Object
Used by the select step.
- #complete! ⇒ Object
-
#completed_requirements ⇒ Object
When an application is submitted, these must be done to go to completed.
- #cpd_completed_cpd_cycles ⇒ Object
- #cpd_required_cpd_cycles ⇒ Object
-
#cpd_requirement ⇒ Object
CPD Step.
- #cpd_uncompleted_cpd_cycles ⇒ Object
-
#decline! ⇒ Object
Admin approves an applicant.
- #done? ⇒ Boolean
- #flag! ⇒ Object
- #in_progress? ⇒ Boolean
- #individual? ⇒ Boolean
-
#min_applicant_courses ⇒ Object
Courses Amounts step.
-
#min_applicant_educations ⇒ Object
Educations Step.
-
#min_applicant_endorsements ⇒ Object
Endorsements Step.
-
#min_applicant_equivalences ⇒ Object
Equivalences Step.
-
#min_applicant_experiences_months ⇒ Object
Work Experiences Step.
-
#min_applicant_files ⇒ Object
Files Step.
-
#min_applicant_references ⇒ Object
References Step.
- #min_applicant_reviews ⇒ Object
- #missing! ⇒ Object
- #organization? ⇒ Boolean
- #owner ⇒ Object
- #owner_symbol ⇒ Object
- #reclassification? ⇒ Boolean
- #reinstatement? ⇒ Boolean
- #resignation? ⇒ Boolean
- #resubmit! ⇒ Object
- #review! ⇒ Object
-
#reviewable? ⇒ Boolean
Completed -> Reviewed requirements.
-
#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.
- #select! ⇒ Object
-
#stamp ⇒ Object
Stamps step.
- #status_label ⇒ Object
- #summary ⇒ Object
- #to_category ⇒ Object
-
#to_s ⇒ Object
Instance Methods.
- #to_status ⇒ Object
-
#transcripts_received? ⇒ Boolean
Transcripts Step.
- #transcripts_required? ⇒ Boolean
-
#try_completed! ⇒ Object
Called when an applicant is submitted.
-
#try_reviewed! ⇒ Object
Called when an applicant_review was submitted.
- #unflag! ⇒ Object
Instance Method Details
#applicant_course(applicant_course_name: nil) ⇒ Object
747 748 749 750 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 747 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
752 753 754 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 752 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
739 740 741 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 739 def applicant_course_areas_collection Effective::ApplicantCourseArea.deep.sorted end |
#applicant_course_names_collection(applicant_course_area:) ⇒ Object
743 744 745 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 743 def applicant_course_names_collection(applicant_course_area:) applicant_course_area.applicant_course_names end |
#applicant_courses_sum ⇒ Object
756 757 758 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 756 def applicant_courses_sum applicant_courses.sum { |ac| ac.amount.to_i } end |
#applicant_endorsements_required? ⇒ Boolean
780 781 782 783 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 780 def applicant_endorsements_required? return false if resignation? || reinstatement? min_applicant_endorsements > 0 end |
#applicant_references_required? ⇒ Boolean
770 771 772 773 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 770 def applicant_references_required? return false if resignation? || reinstatement? min_applicant_references > 0 end |
#applicant_review(reviewer:) ⇒ Object
Find
903 904 905 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 903 def applicant_review(reviewer:) applicant_reviews.find { |ar| ar.reviewer_id == reviewer.id && ar.reviewer_type == reviewer.class.name } end |
#applicant_reviews_required? ⇒ Boolean
894 895 896 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 894 def applicant_reviews_required? min_applicant_reviews > 0 end |
#apply_to_join? ⇒ Boolean
617 618 619 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 617 def apply_to_join? applicant_type == 'Apply to Join' end |
#approve! ⇒ Object
Admin approves an applicant. Registers the owner. Sends an email.
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 959 def approve! raise('already approved') if was_approved? raise('applicant must have been submitted to approve!') unless was_submitted? # 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! EffectiveMemberships.Registrar.delete_fees!(owner) if apply_to_join? EffectiveMemberships.Registrar.register!( owner, to: to_category, status: to_status, 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: to_category, status: to_status, 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 resignation? EffectiveMemberships.Registrar.remove!( owner, statuses: to_status, date: approved_membership_date.presence # Set by the Admin Process form, or nil ) elsif reinstatement? # No status EffectiveMemberships.Registrar.reinstate!( owner, to: 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 ) else raise('unsupported approval applicant_type') end save! after_commit { send_email(:applicant_approved) } true end |
#approve_email_templates ⇒ Object
944 945 946 947 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 944 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
Find or build
908 909 910 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 908 def build_applicant_review(reviewer:) applicant_review(reviewer: reviewer) || applicant_reviews.build(reviewer: reviewer) end |
#build_organization(params = {}) ⇒ Object
613 614 615 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 613 def build_organization(params = {}) self.organization = EffectiveMemberships.Organization.new(params) end |
#can_apply_applicant_types_collection ⇒ Object
Used by the select step
688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 688 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'] elsif all_steps.include?(:resignation) ['Apply to Reclassify', 'Apply for Resignation'] else ['Apply to Reclassify'] end end |
#can_apply_categories_collection ⇒ Object
Used by the select step
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 703 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 = Array(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
858 859 860 861 862 863 864 865 866 867 868 869 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 858 def complete! raise('applicant must have been submitted to complete!') unless was_submitted? # 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_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.
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 839 def completed_requirements requirements = {} return requirements unless category.present? if all_steps.include?(:transcripts) || transcripts_required? requirements['Transcripts'] = ('Not Required' unless transcripts_required?) || transcripts_received? end if all_steps.include?(:endorsements) || applicant_endorsements_required? requirements['Endorsements'] = ('Not Required' unless applicant_endorsements_required?) || (applicant_endorsements.count(&:completed?) >= min_applicant_endorsements) end if all_steps.include?(:references) || applicant_references_required? requirements['References'] = ('Not Required' unless applicant_references_required?) || (applicant_references.count(&:completed?) >= min_applicant_references) end requirements end |
#cpd_completed_cpd_cycles ⇒ Object
814 815 816 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 814 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
805 806 807 808 809 810 811 812 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 805 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
CPD Step
801 802 803 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 801 def cpd_requirement (category&.applicant_cpd_step_requirement.presence || EffectiveMemberships.Category.cpd_step_requirements.first) end |
#cpd_uncompleted_cpd_cycles ⇒ Object
818 819 820 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 818 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.
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 1013 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? # 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
645 646 647 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 645 def done? approved? || declined? end |
#flag! ⇒ Object
1029 1030 1031 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 1029 def flag! update!(flagged: true, flagged_at: Time.zone.now) end |
#in_progress? ⇒ Boolean
641 642 643 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 641 def in_progress? !approved? && !declined? end |
#individual? ⇒ Boolean
633 634 635 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 633 def individual? !(owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?) end |
#min_applicant_courses ⇒ Object
Courses Amounts step
735 736 737 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 735 def min_applicant_courses category&.min_applicant_courses.to_i end |
#min_applicant_educations ⇒ Object
Educations Step
730 731 732 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 730 def min_applicant_educations category&.min_applicant_educations.to_i end |
#min_applicant_endorsements ⇒ Object
Endorsements Step
776 777 778 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 776 def min_applicant_endorsements category&.min_applicant_endorsements.to_i end |
#min_applicant_equivalences ⇒ Object
Equivalences Step
786 787 788 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 786 def min_applicant_equivalences category&.min_applicant_equivalences.to_i end |
#min_applicant_experiences_months ⇒ Object
Work Experiences Step
761 762 763 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 761 def min_applicant_experiences_months category&.min_applicant_experiences_months.to_i end |
#min_applicant_files ⇒ Object
Files Step
823 824 825 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 823 def min_applicant_files category&.min_applicant_files.to_i end |
#min_applicant_references ⇒ Object
References Step
766 767 768 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 766 def min_applicant_references category&.min_applicant_references.to_i end |
#min_applicant_reviews ⇒ Object
898 899 900 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 898 def min_applicant_reviews category&.min_applicant_reviews.to_i end |
#missing! ⇒ Object
871 872 873 874 875 876 877 878 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 871 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
637 638 639 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 637 def organization? owner.kind_of?(EffectiveMemberships.Organization) && category&.organization? end |
#owner ⇒ Object
605 606 607 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 605 def owner organization || user end |
#owner_symbol ⇒ Object
609 610 611 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 609 def owner_symbol organization? ? :organization : :user end |
#reclassification? ⇒ Boolean
621 622 623 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 621 def reclassification? applicant_type == 'Apply to Reclassify' end |
#reinstatement? ⇒ Boolean
629 630 631 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 629 def reinstatement? applicant_type == 'Apply for Reinstatement' end |
#resignation? ⇒ Boolean
625 626 627 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 625 def resignation? applicant_type == 'Apply for Resignation' end |
#resubmit! ⇒ Object
880 881 882 883 884 885 886 887 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 880 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
937 938 939 940 941 942 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 937 def review! raise('applicant must have been submitted to review!') unless was_submitted? # Let an admin ignore these requirements if need be reviewed! end |
#reviewable? ⇒ Boolean
Completed -> Reviewed requirements
890 891 892 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 890 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.
914 915 916 917 918 919 920 921 922 923 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 914 def reviewed_requirements requirements = {} return requirements unless category.present? if EffectiveMemberships.applicant_reviews? requirements['Reviews'] = ('Not Required' unless applicant_reviews_required?) || (applicant_reviews.count(&:completed?) >= min_applicant_reviews) end requirements end |
#select! ⇒ Object
719 720 721 722 723 724 725 726 727 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 719 def select! raise('cannot select a submitted applicant') if was_submitted? 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 |
#stamp ⇒ Object
Stamps step
828 829 830 831 832 833 834 835 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 828 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
649 650 651 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 649 def status_label (status_was || status).to_s.gsub('_', ' ') end |
#summary ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 653 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 do |item, done| done = (done ? 'Complete' : 'Incomplete') unless done.is_a?(String) || done.is_a?(Symbol) "<li>#{item}: #{done}</li>" end.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
949 950 951 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 949 def to_category category end |
#to_s ⇒ Object
Instance Methods
595 596 597 598 599 600 601 602 603 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 595 def to_s if applicant_type.blank? || category.blank? || owner.blank? 'New Applicant' elsif resignation? "#{owner} - #{applicant_type}" else "#{owner} - #{applicant_type} to #{category}" end end |
#to_status ⇒ Object
953 954 955 956 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 953 def to_status return EffectiveMemberships.Registrar.resigned_status! if resignation? nil end |
#transcripts_received? ⇒ Boolean
Transcripts Step
791 792 793 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 791 def transcripts_received? transcripts_received_on_was.present? end |
#transcripts_required? ⇒ Boolean
795 796 797 798 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 795 def transcripts_required? return false if resignation? || reinstatement? required_steps.include?(:transcripts) end |
#try_completed! ⇒ Object
Called when an applicant is submitted
926 927 928 929 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 926 def try_completed! return false unless submitted? && completed_requirements.values.all? complete! end |
#try_reviewed! ⇒ Object
Called when an applicant_review was submitted
932 933 934 935 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 932 def try_reviewed! return false unless completed? && reviewed_requirements.values.all? review! end |
#unflag! ⇒ Object
1033 1034 1035 |
# File 'app/models/concerns/effective_memberships_applicant.rb', line 1033 def unflag! update!(flagged: false, flagged_at: nil) end |