Employer table broken up and new idcard module setup

This commit is contained in:
Jason Jordan
2026-03-06 10:56:20 -05:00
parent 8ecabf60ff
commit 6a068243f4
31 changed files with 628 additions and 571 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
class Employer < ApplicationRecord
has_many :members
has_one :id_card_setup, class_name: 'IdCard::Setup'
has_one :id_card_setup, class_name: 'IdCard::Setup', dependent: :destroy
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
+11 -9
View File
@@ -1,14 +1,16 @@
class IdCard::EmployerLogo < ApplicationRecord
before_save :calculate_aspect_ratio, if: :image_data_changed?
module IdCard
class EmployerLogo < ApplicationRecord
before_save :calculate_aspect_ratio, if: :image_data_changed?
private
private
def calculate_aspect_ratio
image_io = StringIO.new(self.image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
def calculate_aspect_ratio
image_io = StringIO.new(self.image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
end
end
end
end
+9 -7
View File
@@ -1,10 +1,12 @@
class IdCard::Exception < ApplicationRecord
belongs_to :id_card_setup
has_many :id_card_exception_items
accepts_nested_attributes_for :id_card_exception_items, allow_destroy: true, reject_if: :all_blank
module IdCard
class Exception < ApplicationRecord
belongs_to :setup
has_many :exception_items
accepts_nested_attributes_for :exception_items, allow_destroy: true, reject_if: :all_blank
VALID_TYPES = ['zipcode', 'state', 'family_id']
VALID_TYPES = ['zipcode', 'state', 'family_id']
validates :type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
validates :type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
end
end
+16 -14
View File
@@ -1,25 +1,27 @@
class IdCard::ExceptionItem < ApplicationRecord
belongs_to :id_card_exception
belongs_to :id_card_network_logo, optional: true
belongs_to :id_card_provider_section, optional: true
module IdCard
class ExceptionItem < ApplicationRecord
belongs_to :exception
belongs_to :network_logo, optional: true
belongs_to :provider_section, optional: true
validate :only_one_exception_field_present
validate :only_one_exception_field_present
FIELDS_TO_VALIDATE = [:field_value, :card_logo_file_id, :card_provider_id].freeze
FIELDS_TO_VALIDATE = [:field_value, :card_logo_file_id, :card_provider_id].freeze
VALID_FIELD_NAMES = ['network_logo', 'provider_section', 'effective_date']
VALID_FIELD_NAMES = ['network_logo', 'provider_section', 'effective_date']
validates :field_name, inclusion: { in: VALID_FIELD_NAMES,
message: "%{value} is not a valid Id Card Field Name" }
validates :field_name, inclusion: { in: VALID_FIELD_NAMES,
message: "%{value} is not a valid Id Card Field Name" }
private
private
def only_one_exception_field_present
present_fields = FIELDS_TO_VALIDATE.count { |field| self[field].present? }
def only_one_exception_field_present
present_fields = FIELDS_TO_VALIDATE.count { |field| self[field].present? }
if present_fields != 1
errors.add(:base, "Only one exception field can be present at a time")
if present_fields != 1
errors.add(:base, "Only one exception field can be present at a time")
end
end
end
end
+8 -6
View File
@@ -1,11 +1,13 @@
class IdCard::NetworkLogo < ApplicationRecord
before_save :round_aspect_ratio
module IdCard
class NetworkLogo < ApplicationRecord
before_save :round_aspect_ratio
private
private
def round_aspect_ratio
if self.aspect_ratio.present?
self.aspect_ratio = self.aspect_ratio.round(2)
def round_aspect_ratio
if self.aspect_ratio.present?
self.aspect_ratio = self.aspect_ratio.round(2)
end
end
end
end
+26 -24
View File
@@ -1,33 +1,35 @@
class IdCard::Plan < ApplicationRecord
belongs_to :id_card_setup
has_many :id_card_plan_benefits, dependent: :destroy
accepts_nested_attributes_for :id_card_plan_benefits, allow_destroy: true, reject_if: :all_blank
module IdCard
class Plan < ApplicationRecord
belongs_to :setup
has_many :plan_benefits, dependent: :destroy
accepts_nested_attributes_for :plan_benefits, allow_destroy: true, reject_if: :all_blank
# after_initialize :create_default_benefits, if: :new_record?
# after_initialize :create_default_benefits, if: :new_record?
def self.permitted_params(params)
params.require(:id_card_plan).permit(
:title,
:pb_product_key,
:pl_plan_key,
:_destroy,
id_card_plan_benefits_attributes: [
:id,
:benefit_desc,
:benefit,
:sequence,
def self.permitted_params(params)
params.require(:id_card_plan).permit(
:title,
:pb_product_key,
:pl_plan_key,
:_destroy,
]
)
end
id_card_plan_benefits_attributes: [
:id,
:benefit_desc,
:benefit,
:sequence,
:_destroy,
]
)
end
private
private
def build_and_create_default_benefits
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
id_card_plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
def build_and_create_default_benefits
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
id_card_plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
end
end
end
end
+5 -3
View File
@@ -1,3 +1,5 @@
class IdCard::PlanBenefit < ApplicationRecord
belongs_to :id_card_plan
end
module IdCard
class PlanBenefit < ApplicationRecord
belongs_to :plan
end
end
+9 -8
View File
@@ -1,14 +1,15 @@
class IdCard::PrintData < ApplicationRecord
module IdCard
class PrintData < ApplicationRecord
STRING_ATTRIBUTES = %w[provider_line_1 provider_line_2 provider_line_3 provider_line_4 provider_line_5 provider_line_6 provider_line_7 provider_line_8 provider_line_9 provider_line_10 provider_line_11 claim_to_1 claim_to_2 claim_to_3 claim_to_4 claim_to_5 claim_to_6 claim_to_7 claim_to_8 claim_to_9 claim_to_10 claim_to_11 dependent_1 dependent_2 dependent_3 dependent_4 dependent_5 dependent_6 dependent_7 dependent_8]
STRING_ATTRIBUTES = %w[provider_line_1 provider_line_2 provider_line_3 provider_line_4 provider_line_5 provider_line_6 provider_line_7 provider_line_8 provider_line_9 provider_line_10 provider_line_11 claim_to_1 claim_to_2 claim_to_3 claim_to_4 claim_to_5 claim_to_6 claim_to_7 claim_to_8 claim_to_9 claim_to_10 claim_to_11 dependent_1 dependent_2 dependent_3 dependent_4 dependent_5 dependent_6 dependent_7 dependent_8]
before_validation :assign_blank_strings_to_unassigned_params
before_validation :assign_blank_strings_to_unassigned_params
def assign_blank_strings_to_unassigned_params
STRING_ATTRIBUTES.each do |attr|
# Use the blank? method which checks for nil, false, empty, or whitespace strings
self[attr] = "" if self[attr].blank?
def assign_blank_strings_to_unassigned_params
STRING_ATTRIBUTES.each do |attr|
# Use the blank? method which checks for nil, false, empty, or whitespace strings
self[attr] = "" if self[attr].blank?
end
end
end
end
+4 -2
View File
@@ -1,3 +1,5 @@
class IdCard::ProviderSection < ApplicationRecord
module IdCard
class ProviderSection < ApplicationRecord
end
end
end
+4 -2
View File
@@ -1,3 +1,5 @@
class IdCard::RxSection < ApplicationRecord
module IdCard
class RxSection < ApplicationRecord
end
end
end
+25 -21
View File
@@ -1,27 +1,31 @@
class IdCard::Setup < ApplicationRecord
belongs_to :employer
belongs_to :id_card_employer_logo
belongs_to :id_card_network_logo
belongs_to :id_card_provider_section
belongs_to :id_card_rx_section
module IdCard
class Setup < ApplicationRecord
belongs_to :employer, class_name: 'Employer'
belongs_to :employer_logo, optional: true
belongs_to :network_logo, optional: true
belongs_to :provider_section, optional: true
belongs_to :rx_section, optional: true
has_many :card_exceptions, dependent: :destroy
has_many :plans, dependent: :destroy
# def employer_logo_filename
# self.id_card_employer_logo.filename
# end
has_many :exceptions, dependent: :destroy
# def network_logo_filename
# self.id_card_network_logo.filename
# end
# def employer_logo_filename
# self.employer_logo.filename
# end
def self.permitted_params(params)
params.require(:id_card_setup).permit(
:print_name,
:network_provider,
:card_template,
:rx_group_number,
:id_card_employer_logo_id
)
# def network_logo_filename
# self.network_logo.filename
# end
def self.permitted_params(params)
params.require(:id_card_setup).permit(
:print_name,
:network_provider,
:card_template,
:rx_group_number,
:id_card_employer_logo_id
)
end
end
end