DB restructure, print page
This commit is contained in:
+57
-16
@@ -1,27 +1,68 @@
|
||||
module IdCard
|
||||
class Plan < ApplicationRecord
|
||||
belongs_to :setup
|
||||
belongs_to :configuration, optional: true
|
||||
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?
|
||||
scope :templates, -> { where(template: true) }
|
||||
|
||||
BENEFIT_FIELDS = ["Primary Visit",
|
||||
"Specialist Visit",
|
||||
"Urgent Care",
|
||||
"INN-Ind Ded",
|
||||
"INN-Family Ded",
|
||||
"OON-Ind Ded",
|
||||
"OON-Family Ded",
|
||||
"Co-Insurance",
|
||||
"INN-Ind OOP",
|
||||
"INN-Family OOP",
|
||||
"OON-Ind OOP",
|
||||
"OON-Family OOP",
|
||||
"Emergency Room",
|
||||
"Preventive Care"].freeze
|
||||
|
||||
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,
|
||||
:_destroy,
|
||||
]
|
||||
)
|
||||
after_initialize :build_plan_benefits, if: :new_record?
|
||||
|
||||
def build_plan_benefits
|
||||
BENEFIT_FIELDS.each_with_index do |bene, i|
|
||||
self.plan_benefits.build(benefit_desc: bene, sequence: (i + 1))
|
||||
end
|
||||
end
|
||||
|
||||
def format_template
|
||||
formatted_title = title
|
||||
if pl_plan_key.present?
|
||||
employer_name = Employer.find_by(pl_plan_key: pl_plan_key).pluck(:name)
|
||||
formatted_title.concat( " (#{employer_name})" )
|
||||
end
|
||||
{ id: id, title: formatted_title }
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
# def templates
|
||||
# active_templates.map(&:format_template)
|
||||
# end
|
||||
|
||||
def permitted_params(params)
|
||||
params.require(:id_card_configuration).permit(
|
||||
plans_attributes: [
|
||||
:title,
|
||||
:pb_product_key,
|
||||
:pl_plan_key,
|
||||
:_destroy,
|
||||
plan_benefits_attributes: [
|
||||
:id,
|
||||
:benefit_desc,
|
||||
:benefit,
|
||||
:sequence,
|
||||
:_destroy,
|
||||
]
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
Reference in New Issue
Block a user