diff --git a/app/models/insurance_policies/aca_individuals/enrollment.rb b/app/models/insurance_policies/aca_individuals/enrollment.rb index df3a0e2e..f01d1e55 100644 --- a/app/models/insurance_policies/aca_individuals/enrollment.rb +++ b/app/models/insurance_policies/aca_individuals/enrollment.rb @@ -59,10 +59,29 @@ def enrollment_end_on end_on.present? ? end_on : insurance_policy.start_on.end_of_year end - # rubocop:disable Metrics/AbcSize + def mid_month_end?(end_on, month) + ends_this_month = end_on.month == month + last_day_of_month = Date.new(end_on.year, month, -1) + (end_on.day != last_day_of_month.day) && ends_this_month + end + + def eom_end?(end_on, month) + ends_this_month = end_on.month == month + last_day_of_month = Date.new(end_on.year, month, -1) + (end_on == last_day_of_month) && ends_this_month + end + def pre_amt_tot_values(enrolled_thh_people, calendar_month) - if insurance_policy.term_for_np && insurance_policy.policy_end_on.month == calendar_month - format('%.2f', 0.0) + if insurance_policy.term_for_np + end_on = insurance_policy.end_on + next_month = calendar_month == 12 ? 1 : calendar_month + 1 + # if ends mid month on the current month, set to blank + if mid_month_end?(end_on, calendar_month) + nil + # if ends EOM current month OR ends mid month next month, set to 0 + elsif eom_end?(end_on, calendar_month) || mid_month_end?(end_on, next_month) + format('%.2f', 0.0) + end else pre_amt_tot_month = enrolled_thh_people.map { |mem| mem.premium_schedule.premium_amount.to_f }.sum pre_amt_tot_month = (pre_amt_tot_month * insurance_policy.insurance_product.ehb).to_f.round(2) @@ -99,7 +118,6 @@ def pediatric_dental_premium(enrollments_for_month, tax_household_members, calen health_enrolled_people: eligible_enrollees, month: calendar_month }).value!.to_f end - # rubocop:enable Metrics/AbcSize def enrolled_member_by_hbx_id(hbx_id) [[subscriber] + dependents].flatten.detect do |enrollee| diff --git a/app/models/insurance_policies/aca_individuals/insurance_policy.rb b/app/models/insurance_policies/aca_individuals/insurance_policy.rb index eb390e48..55e76ca1 100644 --- a/app/models/insurance_policies/aca_individuals/insurance_policy.rb +++ b/app/models/insurance_policies/aca_individuals/insurance_policy.rb @@ -157,6 +157,9 @@ def applied_aptc_amount_for(enrollments_for_month, calender_month, tax_household # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def fetch_aptc_tax_credit(enrs_for_month, tax_household = nil) + + return nil if term_for_np && mid_month_end?(policy_end_on, calender_month) + applied_aptc = enrs_for_month.map(&:total_premium_adjustment_amount).max return format('%.2f', (applied_aptc || 0.0)) if tax_household.blank? diff --git a/spec/models/insurance_policies/aca_individuals/enrollment_spec.rb b/spec/models/insurance_policies/aca_individuals/enrollment_spec.rb index dfa2f26c..ca6f82bb 100644 --- a/spec/models/insurance_policies/aca_individuals/enrollment_spec.rb +++ b/spec/models/insurance_policies/aca_individuals/enrollment_spec.rb @@ -12,6 +12,16 @@ let(:insurance_policy) do FactoryBot.create(:insurance_policy, start_on: Date.new(year, 1, 1), end_on: Date.new(year, 12, 31)) end + let(:insurance_policy_npt_eom) do + FactoryBot.create(:insurance_policy, start_on: Date.new(year, 1, 1), + end_on: Date.new(year, 5, 31), + term_for_np: true) + end + let(:insurance_policy_npt_mid_month) do + FactoryBot.create(:insurance_policy, start_on: Date.new(year, 1, 1), + end_on: Date.new(year, 3, 3), + term_for_np: true) + end let(:subscriber) { FactoryBot.build(:enrolled_member, person: subscriber_person) } let(:dependents) do [ @@ -29,6 +39,24 @@ dependents: dependents) end + let(:enrollment_npt_eom) do + FactoryBot.create(:enrollment, start_on: Date.new(year, 1, 1), + effectuated_on: Date.new(year, 1, 1), + end_on: Date.new(year, 5, 31), + insurance_policy: insurance_policy_npt_eom, + subscriber: subscriber, + dependents: dependents) + end + + let(:enrollment_npt_mid_month) do + FactoryBot.create(:enrollment, start_on: Date.new(year, 1, 1), + effectuated_on: Date.new(year, 1, 1), + end_on: Date.new(year, 5, 31), + insurance_policy: insurance_policy_npt_mid_month, + subscriber: subscriber, + dependents: dependents) + end + let(:tax_household_members) do [ double('InsurancePolicies::AcaIndividuals::TaxHouseholdMember', is_medicaid_chip_eligible: true, person: subscriber_person), @@ -91,4 +119,25 @@ end end end + + # write me test cases for enrollment_npt_eom for the pre_amt_tot_values + describe '#pre_amt_tot_values' do + context 'insurance_policy term_for_np is true and eom end date' do + it 'returns 0.00' do + expect(enrollment_npt_eom.pre_amt_tot_values([subscriber], 5)).to eq('0.00') + end + end + + context 'insurance_policy term_for_np is true and mid month end date' do + it 'returns nil' do + expect(enrollment_npt_mid_month.pre_amt_tot_values([subscriber], 3)).to eq(nil) + end + end + + context 'insurance_policy term_for_np is true and next month mid month end date' do + it 'returns 0.00' do + expect(enrollment_npt_mid_month.pre_amt_tot_values([subscriber], 2)).to eq('0.00') + end + end + end end diff --git a/spec/models/insurance_policies/aca_individuals/insurance_policy_spec.rb b/spec/models/insurance_policies/aca_individuals/insurance_policy_spec.rb index a135777e..24317bd3 100644 --- a/spec/models/insurance_policies/aca_individuals/insurance_policy_spec.rb +++ b/spec/models/insurance_policies/aca_individuals/insurance_policy_spec.rb @@ -321,6 +321,14 @@ end end + context "#fetch_aptc_amount" do + context "when in second grace period month" do + it "should return nil" do + expect(insurance_policy_npt_mid_month.fetch_aptc_amount([enrollment_1], 3, aqhp_tax_household_1)).to eq nil + end + end + end + context "#fetch_slcsp_premium" do context "when aptc is zero" do let(:enrollment_subscriber) { FactoryBot.build(:enrolled_member, person: subscriber_person) }