Skip to content

Commit

Permalink
Minor changes for review feedback.
Browse files Browse the repository at this point in the history
This changes `payPeriodAmount` to `payAmountFor30Days`.
  • Loading branch information
bseeger committed May 22, 2024
1 parent b693fbd commit 9e61f97
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 87 deletions.
5 changes: 1 addition & 4 deletions src/main/java/org/mdbenefits/app/inputs/MdBenefitsFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,9 @@ public class MdBenefitsFlow extends FlowInputs {
@NotBlank(message = "{error.missing-pay-period}")
private String payPeriod;

// NOTE: this is really pay for the last 30 days
// and not the payPeriodAmount! Don't multiply it out
// unless other logic is changed.
@Money(message = "{error.invalid-money}")
@NotBlank(message = "{error.missing-dollar-amount}")
private String payPeriodAmount;
private String payAmountFor30Days;

@NotEmpty(message = "{error.missing-general}")
private List<String> additionalIncome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private Map<String, SubmissionField> prepareIncome(Submission submission) {

String employerName = (String) incomeDetails.get("employerName");
String payFrequency = (String) incomeDetails.get("payPeriod");
String payPeriodAmount = (String) incomeDetails.get("payPeriodAmount");
String moneyString = String.format("$%,.0f", Double.valueOf(payPeriodAmount));
String payAmountFor30Days = (String) incomeDetails.get("payAmountFor30Days");
String moneyString = String.format("$%,.0f", Double.valueOf(payAmountFor30Days));

fields.put("employeeName" + i,
new SingleField("employeeName" + i, employeeName, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public void run(Submission submission) {
householdIncomeAmount.add(moneyOnHandAmount).compareTo(expenseCalculator.totalUtilitiesExpenses()) <= 0;

boolean isEligibleForExpeditedSnap =
(isBelowMoneyOnHandThreshhold && isBelowIncomeThreshhold) || (
isMigrantOrSeasonalFarmWorker && isBelowMoneyOnHandThreshhold)
|| expenseCalculator.totalUtilitiesExpenses().compareTo(BigDecimal.ZERO) > 0
&& isEligibleByIncomeAndCashOnHandLessThanExpenses;
(isBelowMoneyOnHandThreshhold && isBelowIncomeThreshhold) ||
(isMigrantOrSeasonalFarmWorker && isBelowMoneyOnHandThreshhold) ||
(expenseCalculator.totalUtilitiesExpenses().compareTo(BigDecimal.ZERO) > 0) &&
isEligibleByIncomeAndCashOnHandLessThanExpenses;

submission.getInputData().put("isEligibleForExpeditedSnap", String.valueOf(isEligibleForExpeditedSnap));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import formflow.library.config.submission.Condition;
import formflow.library.data.Submission;
import java.math.BigDecimal;
import lombok.extern.slf4j.Slf4j;
import org.mdbenefits.app.utils.ExpenseCalculator;
import org.mdbenefits.app.utils.IncomeCalculator;
import org.springframework.stereotype.Component;
Expand All @@ -11,17 +12,27 @@
* Checks to see if there are more expense than income and liquid assets. Returns true if there are more expenses than income.
*/

@Slf4j
@Component
public class HasMoreExpensesThanMoney implements Condition {

@Override
public Boolean run(Submission submission) {
IncomeCalculator incomeCalculator = new IncomeCalculator(submission);
ExpenseCalculator expenseCalculator = new ExpenseCalculator(submission);
Double moneyOnHand = Double.parseDouble(
submission.getInputData().getOrDefault("expeditedMoneyOnHandAmount", "0.0").toString());
BigDecimal incomeAndMoneyOnHand = BigDecimal.valueOf(incomeCalculator.totalFutureEarnedIncome() + moneyOnHand);
String moneyOnHandStr = (String) submission.getInputData().get("expeditedMoneyOnHandAmount");
double moneyOnHand = 0.0;

return incomeAndMoneyOnHand.compareTo(expenseCalculator.totalUtilitiesExpenses()) < 0;
if (moneyOnHandStr != null) {
try {
moneyOnHand = Double.parseDouble(moneyOnHandStr);
} catch (NumberFormatException e) {
log.warn("Unable to parse `expeditedMoneyOnHandAmount`: `{}`. Not using money on hand in calculations.",
moneyOnHandStr);
}
}

return expenseCalculator.totalUtilitiesExpenses()
.compareTo(BigDecimal.valueOf(incomeCalculator.totalFutureEarnedIncome() + moneyOnHand)) > 0;
}
}
14 changes: 0 additions & 14 deletions src/main/java/org/mdbenefits/app/utils/ExpenseCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ public class ExpenseCalculator {
public ExpenseCalculator(Submission submission) {
this.submission = submission;
}
/*
public BigDecimal totalLivingExpenses() {
Map<String, Object> inputData = submission.getInputData();
List<String> expenses = (List) inputData.getOrDefault("householdHomeExpenses[]", List.of());
BigDecimal sum = new BigDecimal("0.0");
for (HomeExpensesType expense : HomeExpensesType.values()) {
if (expenses.contains(expense.name())) {
sum = sum.add(BigDecimal.valueOf(Double.parseDouble(inputData.get(expense.getInputFieldName()).toString())));
}
}
return sum;
}
*/

public BigDecimal totalUtilitiesExpenses() {
List<BigDecimal> expenseAmounts = new java.util.ArrayList<>();
Expand Down
32 changes: 1 addition & 31 deletions src/main/java/org/mdbenefits/app/utils/IncomeCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,7 @@ public Double totalFutureEarnedIncome() {
var completedJobs = jobs.stream().filter(job -> job.get(Submission.ITERATION_IS_COMPLETE_KEY).equals(true)).toList();

return completedJobs.stream()
.map(IncomeCalculator::futureIncomeForJob)
.map(job -> Double.parseDouble(job.getOrDefault("payAmountFor30Days", "0").toString()))
.reduce(0.0d, Double::sum);
}

public static double futureIncomeForJob(Map<String, Object> job) throws NumberFormatException {

// right now payPeriodAmount is the amount of money they made
// for the job in the last 30 days. No calculations necessary
return Double.parseDouble(job.getOrDefault("payPeriodAmount", "0").toString());
/*
if (job.getOrDefault("jobPaidByHour", "false").toString().equals("true")) {
var hoursPerWeek = Double.parseDouble(job.get("hoursPerWeek").toString());
var hourlyWage = Double.parseDouble(job.get("hourlyWage").toString());
log.info("Returning hourly wage");
return hoursPerWeek * hourlyWage * (52.0 / 12);
} else {
var payPeriod = job.getOrDefault("payPeriod", "It varies").toString();
var payPeriodAmount = Double.parseDouble(job.get("payPeriodAmount").toString());
if (Objects.equals(payPeriod, "Every week")) {
return payPeriodAmount * (52.0 / 12);
} else if (Objects.equals(payPeriod, "Every 2 weeks")) {
return (payPeriodAmount * ((52.0 / 2) / 12));
} else if (Objects.equals(payPeriod, "Twice a month")) {
return payPeriodAmount * 2;
} else if (Objects.equals(payPeriod, "Every month")) {
return payPeriodAmount;
}
log.info("Using 30D estimate");
// based on 30D estimate
return payPeriodAmount;
}
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ public static List<String> getHouseholdMemberNames(Submission submission) {
}

public static String householdMemberFullNameFormatted(Map<String, Object> householdMember) {
String fullName = String.format("%s, %s", householdMember.get("householdMemberLastName"), householdMember.get("householdMemberFirstName"));
String fullName = String.format("%s, %s", householdMember.get("householdMemberLastName"),
householdMember.get("householdMemberFirstName"));
if (householdMember.get("householdMemberMiddleName") != null) {
fullName += ", " + householdMember.get("householdMemberMiddleName");
}
return fullName;
}

public static String applicantFullNameFormatted(Submission submission){
public static String applicantFullNameFormatted(Submission submission) {
Map<String, Object> inputData = submission.getInputData();

String fullName = String.format("%s, %s", inputData.get("lastName"), inputData.get("firstName"));
Expand Down Expand Up @@ -165,7 +166,7 @@ public static ArrayList<HashMap<String, Object>> getHouseholdIncomeReviewItems(S
List<HashMap<String, Object>> incomeSubflowIterations = (List<HashMap<String, Object>>) submission.getInputData()
.getOrDefault("income", new ArrayList<HashMap<String, Object>>());

for (var job : incomeSubflowIterations.stream().filter(job ->
for (var job : incomeSubflowIterations.stream().filter(job ->
job.get(ITERATION_IS_COMPLETE_KEY).equals(true)).toList()) {
var item = new HashMap<String, Object>();
var name = job.get("householdMemberJobAdd").equals("you") ? applicantFullName : job.get("householdMemberJobAdd");
Expand All @@ -181,7 +182,7 @@ public static ArrayList<HashMap<String, Object>> getHouseholdIncomeReviewItems(S

// TODO: add wage amount and not future income
var payAmount = job.getOrDefault("jobPaidByHour", "false").equals("true") ? job.get("hourlyWage").toString()
: job.get("payPeriodAmount").toString();
: job.get("payAmountFor30Days").toString();
item.put("income", formatMoney(payAmount));
item.put("uuid", job.get("uuid"));

Expand Down
12 changes: 7 additions & 5 deletions src/main/resources/templates/mdBenefitsFlow/jobPayAmount.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html th:lang="${#locale.language}" xmlns:th="http://www.thymeleaf.org">
<th:block th:with="messageVariant=${fieldData.getOrDefault('payPeriod', 'It varies') == 'It varies' ? 'variable' : 'fixed'}">
<th:block
th:with="messageVariant=${fieldData.getOrDefault('payPeriod', 'It varies') == 'It varies' ? 'variable' : 'fixed'}">
<head th:replace="~{fragments/head :: head(title=#{job-pay-amount.title})}"></head>
<body>
<div class="page-wrapper">
Expand All @@ -12,19 +13,20 @@
<p class="grey-text" th:text="${fieldData.get('employerName')}"></p>
<th:block
th:replace="~{fragments/cardHeader :: cardHeader(header=#{job-pay-amount.header}, subtext=#{job-pay-amount.subtext})}"/>
<th:block th:replace="~{fragments/form :: form(action=${formAction}, content=~{::content})}">
<th:block
th:replace="~{fragments/form :: form(action=${formAction}, content=~{::content})}">
<th:block th:ref="content">
<div class="form-card__content">
<th:block
th:replace="~{fragments/inputs/money :: money(inputName='payPeriodAmount',
th:replace="~{fragments/inputs/money :: money(inputName='payAmountFor30Days',
ariaLabel='header')}"/>

</div>
<div class="form-card__footer">


<th:block th:replace="~{fragments/inputs/submitButton :: submitButton(
text=#{general.inputs.continue})}" />
text=#{general.inputs.continue})}"/>

</div>
</th:block>
Expand All @@ -33,7 +35,7 @@
</div>
</section>
</div>
<th:block th:replace="~{fragments/footer :: footer}" />
<th:block th:replace="~{fragments/footer :: footer}"/>
</body>
</th:block>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public SubmissionTestBuilder withJob(String employeeName, String employerName, S
job.put("uuid", uuid);
job.put("householdMemberJobAdd", employeeName);
job.put("employerName", employerName);
job.put("payPeriodAmount", amount);
job.put("payAmountFor30Days", amount);
job.put("payPeriod", freq);
job.put(Submission.ITERATION_IS_COMPLETE_KEY, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ void incomeFlow() {

assertThat(testPage.getTitle()).isEqualTo(message("job-pay-amount.title"));

testPage.enter("payPeriodAmount", "a");
testPage.enter("payAmountFor30Days", "a");
testPage.clickContinue();

assert (testPage.hasErrorText(message("error.invalid-money")));
testPage.enter("payPeriodAmount", "282.99");
testPage.enter("payAmountFor30Days", "282.99");

testPage.clickContinue();

Expand Down Expand Up @@ -362,7 +362,7 @@ void mainFlowHowMuchMoneyOnHandTest() {
testPage.clickContinue();

// jobPayAmount
testPage.enter("payPeriodAmount", "200.00");
testPage.enter("payAmountFor30Days", "200.00");
testPage.clickContinue();

testPage.navigateToFlowScreen("mdBenefitsFlow/householdHomeExpenses");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ void shouldClearIncompleteIterationsFromIncomeSubflow() {
job1.put("uuid", "complete iteration");
job1.put("employerName", "ACME Inc");
job1.put("payPeriod", "It varies");
job1.put("payPeriodAmount", 400.0);
job1.put("payAmountFor30Days", 400.0);
var job2 = new HashMap<String, Object>();
job2.put(Submission.ITERATION_IS_COMPLETE_KEY, false);
job2.put("uuid", "Current Iteration");
job2.put("employerName", "Monsters Inc");
job2.put("payPeriodAmount", 200.0);
job2.put("payAmountFor30Days", 200.0);
var job3 = new HashMap<String, Object>();
job3.put(Submission.ITERATION_IS_COMPLETE_KEY, false);
job3.put("uuid", "Incomplete Iteration");
Expand All @@ -38,7 +38,8 @@ void shouldClearIncompleteIterationsFromIncomeSubflow() {
inputData.put("income", income);
submission.setInputData(inputData);
clearIncompleteIncomeIterations.run(submission, "Current Iteration");
ArrayList<HashMap<String, Object>> incomeSubflow = (ArrayList<HashMap<String, Object>>) submission.getInputData().get("income");
ArrayList<HashMap<String, Object>> incomeSubflow = (ArrayList<HashMap<String, Object>>) submission.getInputData()
.get("income");
assertThat(incomeSubflow).size().isEqualTo(2);
assertThat(incomeSubflow).doesNotContain(job3);
assertThat(incomeSubflow).isEqualTo(List.of(job1, job2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ void hasMoreExpensesThanMoney() {
job1.put(Submission.ITERATION_IS_COMPLETE_KEY, true);
job1.put("employerName", "ACME Inc");
job1.put("payPeriod", "It varies");
job1.put("payPeriodAmount", 400.0);
job1.put("payAmountFor30Days", 400.0);

Map<String, Object> job2 = new HashMap<>();
job2.put(Submission.ITERATION_IS_COMPLETE_KEY, false);
job2.put("employerName", "Monsters Inc");
job2.put("payPeriodAmount", 200.0);
job2.put("payAmountFor30Days", 200.0);

income.add(job1);
income.add(job2);
Expand Down Expand Up @@ -75,13 +75,13 @@ void hasMoreMoneyThanExpenses() {
job1.put(Submission.ITERATION_IS_COMPLETE_KEY, true);
job1.put("employerName", "ACME Inc");
job1.put("payPeriod", "It varies");
job1.put("payPeriodAmount", 400.0);
job1.put("payAmountFor30Days", 400.0);

Map<String, Object> job2 = new HashMap<>();
job2.put(Submission.ITERATION_IS_COMPLETE_KEY, true);
job2.put("employerName", "Monsters Inc");
job1.put("payPeriod", "It varies");
job2.put("payPeriodAmount", 1500.0);
job2.put("payAmountFor30Days", 1500.0);

income.add(job1);
income.add(job2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ void totalFutureEarnedIncomeShouldFilterIncompleteSubflowIterations() {
job1.put(Submission.ITERATION_IS_COMPLETE_KEY, true);
job1.put("employerName", "ACME Inc");
job1.put("payPeriod", "It varies");
job1.put("payPeriodAmount", 400.0);
job1.put("payAmountFor30Days", 400.0);
var job2 = new HashMap<String, Object>();
job2.put(Submission.ITERATION_IS_COMPLETE_KEY, false);
job2.put("employerName", "Monsters Inc");
job2.put("payPeriodAmount", 200.0);
job2.put("payAmountFor30Days", 200.0);
income.add(job1);
income.add(job2);
submission.setInputData(Map.of("income", income));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public void getHouseholdIncomeReviewItemsShouldIgnoreIncompleteSubflowIterations
job1.put("householdMemberJobAdd", "you");
job1.put("employerName", "ACME Inc");
job1.put("payPeriod", "It varies");
job1.put("payPeriodAmount", 400.0);
job1.put("payAmountFor30Days", 400.0);

HashMap<String, Object> job2 = new HashMap<>();
job2.put(Submission.ITERATION_IS_COMPLETE_KEY, false);
job2.put("employerName", "Monsters Inc");
job2.put("payPeriodAmount", 200.0);
job2.put("payAmountFor30Days", 200.0);

ArrayList<Map<String, Object>> income = new ArrayList<>();
income.add(job1);
Expand All @@ -48,9 +48,12 @@ public void getHouseholdIncomeReviewItemsShouldIgnoreIncompleteSubflowIterations
HashMap<String, Object> inputData = new HashMap<>();
inputData.put("income", income);
submission.setInputData(inputData);

ArrayList<HashMap<String, Object>> householdIncomeReviewItems = SubmissionUtilities.getHouseholdIncomeReviewItems(submission);
assertThat(householdIncomeReviewItems.stream().noneMatch(item -> item.getOrDefault("jobName", "").equals("Monsters Inc"))).isTrue();
assertThat(householdIncomeReviewItems.stream().noneMatch(item -> item.getOrDefault("income", "").equals("$200"))).isTrue();

ArrayList<HashMap<String, Object>> householdIncomeReviewItems = SubmissionUtilities.getHouseholdIncomeReviewItems(
submission);
assertThat(householdIncomeReviewItems.stream()
.noneMatch(item -> item.getOrDefault("jobName", "").equals("Monsters Inc"))).isTrue();
assertThat(
householdIncomeReviewItems.stream().noneMatch(item -> item.getOrDefault("income", "").equals("$200"))).isTrue();
}
}

0 comments on commit 9e61f97

Please sign in to comment.