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
613
614
615
616
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 613
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
618
619
620
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 618
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
605
606
607
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 605
def applicant_course_areas_collection
Effective::ApplicantCourseArea.deep.sorted
end
|
#applicant_course_names_collection(applicant_course_area:) ⇒ Object
609
610
611
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 609
def applicant_course_names_collection(applicant_course_area:)
applicant_course_area.applicant_course_names
end
|
#applicant_courses_sum ⇒ Object
622
623
624
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 622
def applicant_courses_sum
applicant_courses.sum { |ac| ac.amount.to_i }
end
|
#applicant_endorsements_required? ⇒ Boolean
645
646
647
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 645
def applicant_endorsements_required?
required_steps.include?(:endorsements) && min_applicant_endorsements > 0
end
|
#applicant_references_required? ⇒ Boolean
636
637
638
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 636
def applicant_references_required?
required_steps.include?(:references) && min_applicant_references > 0
end
|
#applicant_reviews_required? ⇒ Boolean
Completed -> Reviewed requirements
731
732
733
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 731
def applicant_reviews_required?
(min_applicant_reviews > 0 || applicant_reviews.present?)
end
|
#apply_to_join? ⇒ Boolean
497
498
499
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 497
def apply_to_join?
applicant_type == 'Apply to Join'
end
|
#approve! ⇒ Object
Admin approves an applicant. Registers the owner. Sends an email.
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 761
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!
if apply_to_join?
EffectiveMemberships.Registrar.register!(
owner,
to: category,
date: approved_membership_date.presence, number: approved_membership_number.presence )
elsif reclassification?
EffectiveMemberships.Registrar.reclassify!(owner, to: category)
elsif reinstatement?
EffectiveMemberships.Registrar.reinstate!(owner)
else
raise('unsupported approval applicant_type')
end
save!
after_commit { send_email(:applicant_approved) }
true
end
|
#build_organization(params = {}) ⇒ Object
493
494
495
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 493
def build_organization(params = {})
self.organization = EffectiveMemberships.Organization.new(params)
end
|
#can_apply_applicant_types_collection ⇒ Object
559
560
561
562
563
564
565
566
567
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 559
def can_apply_applicant_types_collection
if owner.blank? || owner.membership.blank? || owner.membership.categories.blank?
['Apply to Join']
elsif owner.membership.statuses.present?
['Apply for Reinstatement', 'Apply to Join']
else
['Apply to Reclassify']
end
end
|
#can_apply_categories_collection ⇒ Object
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 570
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
categories.select do |cat|
cat.can_apply_existing? ||
(cat.can_apply_restricted? && (category_ids & cat.can_apply_restricted_ids).present?)
end
end
|
#complete! ⇒ Object
699
700
701
702
703
704
705
706
707
708
709
710
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 699
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.
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 680
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
|
#decline! ⇒ Object
Admin approves an applicant. Registers the owner. Sends an email.
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 794
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
521
522
523
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 521
def done?
approved? || declined?
end
|
#in_progress? ⇒ Boolean
517
518
519
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 517
def in_progress?
!approved? && !declined?
end
|
#individual? ⇒ Boolean
509
510
511
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 509
def individual?
!(owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?)
end
|
#min_applicant_courses ⇒ Object
601
602
603
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 601
def min_applicant_courses
category&.min_applicant_courses.to_i
end
|
#min_applicant_educations ⇒ Object
596
597
598
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 596
def min_applicant_educations
category&.min_applicant_educations.to_i
end
|
#min_applicant_endorsements ⇒ Object
641
642
643
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 641
def min_applicant_endorsements
category&.min_applicant_endorsements.to_i
end
|
#min_applicant_equivalences ⇒ Object
650
651
652
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 650
def min_applicant_equivalences
category&.min_applicant_equivalences.to_i
end
|
#min_applicant_experiences_months ⇒ Object
627
628
629
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 627
def min_applicant_experiences_months
category&.min_applicant_experiences_months.to_i
end
|
#min_applicant_files ⇒ Object
664
665
666
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 664
def min_applicant_files
category&.min_applicant_files.to_i
end
|
#min_applicant_references ⇒ Object
632
633
634
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 632
def min_applicant_references
category&.min_applicant_references.to_i
end
|
#min_applicant_reviews ⇒ Object
735
736
737
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 735
def min_applicant_reviews
category&.min_applicant_reviews.to_i
end
|
#missing! ⇒ Object
712
713
714
715
716
717
718
719
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 712
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
513
514
515
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 513
def organization?
owner.kind_of?(EffectiveMemberships.Organization) && category&.organization?
end
|
#owner ⇒ Object
485
486
487
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 485
def owner
organization || user
end
|
#owner_symbol ⇒ Object
489
490
491
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 489
def owner_symbol
organization? ? :organization : :user
end
|
#reclassification? ⇒ Boolean
501
502
503
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 501
def reclassification?
applicant_type == 'Apply to Reclassify'
end
|
#reinstatement? ⇒ Boolean
505
506
507
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 505
def reinstatement?
applicant_type == 'Apply for Reinstatement'
end
|
#resubmit! ⇒ Object
721
722
723
724
725
726
727
728
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 721
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
752
753
754
755
756
757
758
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 752
def review!
raise('applicant must have been submitted to review!') unless was_submitted?
reviewed!
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.
741
742
743
744
745
746
747
748
749
750
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 741
def reviewed_requirements
requirements = {}
return requirements unless category.present?
if applicant_reviews_required?
requirements['Applicant Reviews'] = (applicant_reviews.count(&:completed?) >= min_applicant_reviews)
end
requirements
end
|
#select! ⇒ Object
585
586
587
588
589
590
591
592
593
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 585
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
669
670
671
672
673
674
675
676
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 669
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
525
526
527
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 525
def status_label
(status_was || status).to_s.gsub('_', ' ')
end
|
#summary ⇒ Object
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 529
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_s ⇒ Object
479
480
481
482
483
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 479
def to_s
return 'New Applicant' if applicant_type.blank? || category.blank? || owner.blank?
"#{owner} - #{applicant_type} to #{category}"
end
|
#transcripts_received? ⇒ Boolean
655
656
657
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 655
def transcripts_received?
transcripts_received_on_was.present?
end
|
#transcripts_required? ⇒ Boolean
659
660
661
|
# File 'app/models/concerns/effective_memberships_applicant.rb', line 659
def transcripts_required?
required_steps.include?(:transcripts)
end
|