59 lines
1.5 KiB
Ruby
59 lines
1.5 KiB
Ruby
module EmployerAutomation
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
scope :new_groups, -> {
|
|
where(active: false)
|
|
.where.not(pl_plan_key: [nil, ''])
|
|
}
|
|
|
|
scope :with_plans, -> {
|
|
joins(id_card_setup: :plans).distinct
|
|
}
|
|
|
|
# scope :with_survey_and_no_questions, -> {
|
|
# joins(:survey) # join has_one
|
|
# .left_joins(survey: :questions) # join has_many through has_one
|
|
# .where(questions: { id: nil }) # filter where has_many is empty
|
|
# }
|
|
|
|
scope :missing_keychain_values, -> {
|
|
new_groups
|
|
.where(
|
|
arel_table[:company_pb_entity_key].in([nil, ''])
|
|
.or(arel_table[:plan_id].in([nil, '']))
|
|
.or(arel_table[:group_number].in([nil, '']))
|
|
.or(arel_table[:effective_date].in([nil, '']))
|
|
)
|
|
}
|
|
|
|
scope :missing_initial_members, -> {
|
|
new_groups.with_plans
|
|
}
|
|
end
|
|
|
|
# class_methods do
|
|
# # Methods in this block become class methods of the including class.
|
|
# def count_all_visible
|
|
# visible.count
|
|
# end
|
|
# end
|
|
|
|
# Any other methods defined here become instance methods automatically.
|
|
# def up_to_date?
|
|
# self.pl_plan_key.present? &&
|
|
# self.company_pb_entity_key.present? &&
|
|
# self.plan_id.present? &&
|
|
# self.group_number.present? &&
|
|
# self.effective_date.present?
|
|
# end
|
|
|
|
def sync_members_with_vhcs
|
|
AutomationService::EmployerMembersUpdate.new(self.pl_plan_key).call
|
|
end
|
|
|
|
|
|
def sync_with_vhcs
|
|
AutomationService::EmployerUpdate.new(self.pl_plan_key).call
|
|
end
|
|
end |