Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expense calculator bug #259

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void run(Submission submission) {

BigDecimal moneyOnHandAmount = convertToBigDecimal(
inputData.getOrDefault("expeditedMoneyOnHandAmount", "0").toString());

BigDecimal householdIncomeAmount = convertToBigDecimal(
inputData.getOrDefault("householdIncomeLast30Days", "0").toString());
if (!isApplyingForExpeditedSnap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ClearUnusedExpensesFields implements Action {
public void run(Submission submission) {
Map<String, String> submissionInputData = (Map) submission.getInputData();
List<String> householdHomeExpenses = (List) submission.getInputData().getOrDefault("householdHomeExpenses[]", List.of());
boolean none = householdHomeExpenses.contains("NONE");
boolean none = householdHomeExpenses.contains("None");

for (HomeExpensesType type : HomeExpensesType.values()) {
if (none || !householdHomeExpenses.contains(type.name())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.mdbenefits.app.submission.actions;

import formflow.library.config.submission.Action;
import formflow.library.data.FormSubmission;
import formflow.library.data.Submission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MaybeClearMoneyOnHandAmount implements Action {

/**
* This action will clear out the expeditedMoneyOnHandAmount field, if the householdMoneyOnHandLessThan100 is equal to "true";
* This is useful in the case that the user goes forward and enters an amount and then goes back and indicates that they have
* less than the money on hand threshold.
*
* @param formSubmission the data being submitted.
* @param submission submission object the action is associated with, not null
*/
@Override
public void run(FormSubmission formSubmission, Submission submission) {
boolean isMoneyOnHandLessThan100 = ((String) formSubmission.getFormData()
.get("householdMoneyOnHandLessThan100")).equalsIgnoreCase("true");

if (isMoneyOnHandLessThan100) {
formSubmission.getFormData().put("expeditedMoneyOnHandAmount", "0");
}
}
}
11 changes: 6 additions & 5 deletions src/main/java/org/mdbenefits/app/utils/ExpenseCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public BigDecimal totalUtilitiesExpenses() {
Map<String, Object> inputData = submission.getInputData();

expenses.forEach(val -> {
String inputFieldName = HomeExpensesType.getEnumByName(val).getInputFieldName();
expenseAmounts.add(
new BigDecimal(inputData.getOrDefault(inputFieldName, "0").toString())
.setScale(2, RoundingMode.HALF_UP));

if (!val.equalsIgnoreCase("None")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spokenbird I changed this to "equalsIgnoreCase()" so that we still do the right thing if someone accidentally changes this to "NONE" or "none".

String inputFieldName = HomeExpensesType.getEnumByName(val).getInputFieldName();
expenseAmounts.add(
new BigDecimal(inputData.getOrDefault(inputFieldName, "0").toString())
.setScale(2, RoundingMode.HALF_UP));
}
});

return expenseAmounts.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/flows-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ flow:
nextScreens:
- name: expeditedSnapMoneyOnHand
expeditedSnapMoneyOnHand:
onPostAction: MaybeClearMoneyOnHandAmount
beforeSaveAction: CheckExpeditedSnapEligibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new action to clear out the money amount in the event that they said they had money, but then went back and changed their mind on that.

nextScreens:
- name: expeditedSnapQualificationNotice
Expand Down Expand Up @@ -270,6 +271,7 @@ flow:
condition: IsApplyingForSnap
- name: householdMedicalExpenses
householdMoneyOnHand:
onPostAction: MaybeClearMoneyOnHandAmount
beforeSaveAction: CheckExpeditedSnapEligibility
nextScreens:
- name: householdMoneyOnHandAmount
Expand Down
Loading