before adding users

This commit is contained in:
Jason Jordan
2026-04-20 12:12:52 -04:00
parent 7ab1143db8
commit 1d9025276d
21 changed files with 286 additions and 185 deletions
+50 -28
View File
@@ -2,34 +2,49 @@ module EmployerAutomation
extend ActiveSupport::Concern
included do
scope :uninitialized, -> {
where(initialized: false)
}
scope :initialized, -> {
where(initialized: true)
}
scope :not_automation_ready, -> {
where(pl_plan_key: [nil, ''], group_number: [nil, ''])
where(group_number: [nil, ''])
}
scope :automation_ready, -> {
where.not(pl_plan_key: [nil, ''])
.or(where.not(group_number: [nil, '']))
where.not(group_number: [nil, ''])
}
scope :missing_keychain_values, -> {
where(company_pb_entity_key: [nil, ''])
.or(where(plan_id: [nil, '']))
.or(where(group_number: [nil, '']))
.or(where(pl_plan_key: [nil, '']))
scope :in_automation_initilization, -> {
joins(:id_card_setup)
.where(initialized: false)
.or(
where(id_card_setup: {initialized: false})
)
}
# scope :missing_keychain_values, -> {
# where(company_pb_entity_key: [nil, ''])
# .or(where(plan_id: [nil, '']))
# .or(where(group_number: [nil, '']))
# .or(where(pl_plan_key: [nil, '']))
# }
scope :missing_keychain_initialization, -> {
inactive.automation_ready.missing_keychain_values
uninitialized.automation_ready
}
scope :building_id_card_setup, -> {
active.left_outer_joins(:id_card_setup)
.where(id_card_setup: {active: false})
scope :uninitialized_id_card_setup, -> {
joins(:id_card_setup)
.where(id_card_setup: {initialized: false})
}
scope :missing_plans_initialization, -> {
building_id_card_setup
.where.missing(:plans)
scope :missing_plans, -> {
where.missing(:plans)
.or(
where(
id: joins(:plans)
@@ -39,9 +54,8 @@ module EmployerAutomation
)
}
scope :missing_members_initialization, -> {
building_id_card_setup
.where.associated(:plans)
scope :has_plans, -> {
where.associated(:plans)
.where.not(
id: joins(:plans)
.where(plans: { pb_product_key: [nil, ''] })
@@ -49,22 +63,30 @@ module EmployerAutomation
).distinct
}
scope :active_with_active_id_card_setup, -> {
scope :missing_plans_initialization, -> {
uninitialized_id_card_setup.missing_plans
}
scope :missing_members_initialization, -> {
uninitialized_id_card_setup.has_plans
}
scope :with_active_id_card_setup, -> {
active.left_outer_joins(:id_card_setup)
.where(id_card_setup: {active: true})
}
scope :with_keychain_values, -> {
where.not(
pl_plan_key: [nil, ''],
group_number: [nil, ''],
company_pb_entity_key: [nil, ''],
plan_id: [nil, '']
)
}
# scope :with_keychain_values, -> {
# where.not(
# pl_plan_key: [nil, ''],
# group_number: [nil, ''],
# company_pb_entity_key: [nil, ''],
# plan_id: [nil, '']
# )
# }
scope :deactivated, -> {
inactive.with_keychain_values
inactive.initialized
}
# Employer.joins(:id_card_setup)
# .left_outer_joins(:plans)
+5 -2
View File
@@ -9,14 +9,17 @@ class Employer < ApplicationRecord
scope :inactive, -> { where(active: false) }
before_save :create_slug, if: :will_save_change_to_name?
before_save :deactivation_check, if: :will_save_change_to_active?
before_save :active_initialized_check, if: :will_save_change_to_active?
def create_slug
self.slug = Employer.employer_trim_name(name).parameterize
end
def deactivation_check
def active_initialized_check
if active
self.initialized = true
end
if active == false
id_card_setup&.update(active: false)
end
+8
View File
@@ -19,6 +19,14 @@ module IdCard
FORM_COLORS = ['atmosphere', 'verdigris', 'bluemana', 'cobalt']
MODULE_COLOR = 'atmosphere'
before_save :active_initialized_check, if: :will_save_change_to_active?
def active_initialized_check
if active
self.initialized = true
end
end
# def employer_logo_filename
# self.employer_logo.filename
# end