Skip to content

Commit

Permalink
78475 adjust fsr calculators (#16343)
Browse files Browse the repository at this point in the history
* address 1st round of expense calulator issues

* address 1st round of income calulator issues

* address 1st round of asset calulator issues

* improve sanitized params for income form

* fix calculations based on integer value

* add specs for 78475

* add calculator fixture

* 78475 adding missing permitted params to assets calculator

* change the response type of all calculator endpoints to hash
  • Loading branch information
kjsuarez authored Apr 16, 2024
1 parent 4d2116f commit 9558c82
Show file tree
Hide file tree
Showing 18 changed files with 4,282 additions and 1,533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ class FinancialStatusReportsCalculationsController < ApplicationController
service_tag 'financial-report'

def total_assets
render json: asset_calculator.get_total_assets
render json: {
calculatedTotalAssets: asset_calculator.get_total_assets
}
end

def monthly_income
render json: income_calculator.get_monthly_income
end

def monthly_expenses
render json: expense_calculator.get_monthly_expenses
render json: {
calculatedMonthlyExpenses: expense_calculator.get_monthly_expenses
}
end

def all_expenses
Expand All @@ -29,56 +33,61 @@ def all_expenses

# rubocop:disable Metrics/MethodLength
def asset_form
params.require(:data).permit(
:cashInBank,
:cashOnHand,
:recVehicleAmount,
:usSavingsBonds,
:stocksAndOtherBonds,
:'view:enhancedFinancialStatusReport',
questions: [:hasVehicle],
realEstateRecords: %i[
realEstateType
realEstateAmount
params.permit(
:cash_in_bank,
:cash_on_hand,
:rec_vehicle_amount,
:us_savings_bonds,
:stocks_and_other_bonds,
:'view:enhanced_financial_status_report',
questions: [:has_vehicle],
real_estate_records: %i[
real_estate_type
real_estate_amount
],
assets: [
:realEstateValue,
:resale_value,
{
otherAssets: %i[
other_assets: %i[
name
amount
]
},
:recVehicleAmount,
{ automobiles: [:resaleValue] }
{ monetary_assets: %i[name amount] },
:rec_vehicle_amount,
:real_estate_value,
{ automobiles: [:resale_value] }
]
)
end

def income_form
params.require(:data).permit(
:'view:enhancedFinancialStatusReport',
additionalIncome: [
params.permit(
:'view:enhanced_financial_status_report',
additional_income: [
{
addlIncRecords: %i[
addl_inc_records: %i[
name
amount
]
},
{
spouse: %i[
spAddlIncome
spouse: [
sp_addl_income: %i[
name
amount
]
]
}
],
benefits: {
spouseBenefits: %i[
compensationAndPension
spouse_benefits: %i[
compensation_and_pension
education
]
},
currEmployment: [
:veteranGrossSalary,
curr_employment: [
:veteran_gross_salary,
{
deductions: %i[
name
Expand All @@ -90,46 +99,46 @@ def income_form
:type,
:from,
:to,
:isCurrent,
:employerName
:is_current,
:employer_name
],
income: %i[
veteranOrSpouse
compensationAndPension
veteran_or_spouse
compensation_and_pension
education
],
personalData: {
employmentHistory: {
personal_data: {
employment_history: {
veteran: {
employmentRecords: [
employment_records: [
:type,
:from,
:to,
:isCurrent,
:employerName,
:grossMonthlyIncome,
:is_current,
:employer_name,
:gross_monthly_income,
{
deductions: %i[name amount]
}
]
},
spouse: {
spEmploymentRecords: [
sp_employment_records: [
:type,
:from,
:to,
:isCurrent,
:employerName,
:grossMonthlyIncome,
:is_current,
:employer_name,
:gross_monthly_income,
{
deductions: %i[name amount]
}
]
}
}
},
spCurrEmployment: [
:spouseGrossSalary,
sp_curr_employment: [
:spouse_gross_salary,
{
deductions: %i[
name
Expand All @@ -141,55 +150,55 @@ def income_form
:type,
:from,
:to,
:isCurrent,
:employerName
:is_current,
:employer_name
],
socialSecurity: [
:socialSecAmt,
social_security: [
:social_sec_amt,
{ spouse: [
:socialSecAmt
:social_sec_amt
] }
]
).to_hash
end

def expense_form
params.permit(
:'view:enhancedFinancialStatusReport',
:'view:enhanced_financial_status_report',
expenses: [
:food,
:rentOrMortgage,
{ expenseRecords: %i[
:rent_or_mortgage,
{ expense_records: %i[
name
amount
],
creditCardBills: %i[
credit_card_bills: %i[
purpose
creditorName
originalAmount
unpaidBalance
amountDueMonthly
dateStarted
amountPastDue
creditor_name
original_amount
unpaid_balance
amount_due_monthly
date_started
amount_past_due
] }
],
otherExpenses: %i[
other_expenses: %i[
name
amount
],
installmentContracts: %i[
creditorName
dateStarted
installment_contracts: %i[
creditor_name
date_started
purpose
originalAmount
original_amount
unpaid_balance
amountDueMonthly
amountPastDue
amount_due_monthly
amount_past_due
],
utilityRecords: %i[
utilityType
utility_records: %i[
utility_type
amount
monthlyUtilityAmount
monthly_utility_amount
]
).to_hash
end
Expand All @@ -204,7 +213,7 @@ def income_calculator
end

def expense_calculator
DebtsApi::V0::FsrFormTransform::ExpenceCalculator.build(expense_form)
DebtsApi::V0::FsrFormTransform::ExpenseCalculator.build(expense_form)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ module FsrFormTransform
class AssetCalculator
def initialize(form)
@form = form
@enhanced_fsr_active = @form['view:enhancedFinancialStatusReport']
@enhanced_fsr_active = @form['view:enhanced_financial_status_report']
@assets = @form['assets']
@real_estate_records = @form['realEstateRecords']
@real_estate_records = @form['real_estate_records']
@questions = @form['questions']
end

def get_total_assets
formatted_re_value = @assets['realEstateValue']&.gsub(/[^0-9.-]/, '')&.to_f || 0
tot_other_assets = sum_values(@assets['otherAssets'], 'amount')
tot_rec_vehicles = @enhanced_fsr_active ? @assets['recVehicleAmount']&.gsub(/[^0-9.-]/, '')&.to_f || 0 : 0
tot_vehicles = @questions['hasVehicle'] ? sum_values(@assets['automobiles'], 'resaleValue') : 0
formatted_re_value = @assets['real_estate_value']&.gsub(/[^0-9.-]/, '')&.to_f || 0
tot_other_assets = sum_values(@assets['other_assets'], 'amount')
tot_rec_vehicles = @enhanced_fsr_active ? @assets['rec_vehicle_amount']&.gsub(/[^0-9.-]/, '')&.to_f || 0 : 0
tot_vehicles = @questions['has_vehicle'] ? sum_values(@assets['automobiles'], 'resale_value') : 0
real_estate = if @enhanced_fsr_active
formatted_re_value
else
sum_values(@real_estate_records,
'realEstateAmount')
'real_estate_amount')
end
tot_assets = if @enhanced_fsr_active
sum_values(@assets['monetaryAssets'], 'amount')
sum_values(@assets['monetary_assets'], 'amount')
else
@assets.values.reject { |item| item && !item.is_a?(Array) }
.reduce(0) { |acc, amount| (acc + amount&.gsub(/[^0-9.-]/, '')&.to_f) || 0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module DebtsApi
module V0
module FsrFormTransform
class EnhancedExpenceCalculator
class EnhancedExpenseCalculator
RENT = 'Rent'
MORTGAGE_PAYMENT = 'Mortgage payment'
FOOD = 'Food'
Expand All @@ -18,8 +18,8 @@ def initialize(form)
@old_food_attr = @form.dig('expenses', 'food')
@credit_card_bills = @form.dig('expenses', 'creditCardBills') || []
@other_expenses = @form['otherExpenses'].deep_dup || []
@installment_contracts = @form['installmentContracts']
@utility_records = @form['utilityRecords']
@installment_contracts = @form['installmentContracts'] || []
@utility_records = @form['utilityRecords'] || []

@filtered_expenses = [].concat(
exclude_by(@other_expenses, [FOOD]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
module DebtsApi
module V0
module FsrFormTransform
class ExpenceCalculator
class ExpenseCalculator
def self.build(form)
form.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
enhanced = form['view:enhancedFinancialStatusReport'] || false
enhanced ? EnhancedExpenceCalculator.new(form) : OldExpenceCalculator.new(form)
enhanced ? EnhancedExpenseCalculator.new(form) : OldExpenseCalculator.new(form)
end
end
end
Expand Down
Loading

0 comments on commit 9558c82

Please sign in to comment.