Skip to content

Commit

Permalink
Fixes the bug that budget should not be deducted if OutTransactions d…
Browse files Browse the repository at this point in the history
…ated beyond deadline are made
  • Loading branch information
yewon0303 committed Nov 10, 2019
1 parent 9989109 commit 0c9e9b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/model/BankAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public boolean has(Projection projection) {

/**
* Updates each budget in {@code budgets} when OutTransaction is made.
* Each budget is updated only if it belongs to the same {@code Category} as the OutTransaction,
* and if OutTransaction is dated after Today, before the deadline.
*
* @param txn Transaction can be either InTransaction or OutTransaction.
*/
Expand All @@ -189,8 +191,12 @@ private void updateBudgets(BankAccountOperation txn, boolean isRemoveTransaction
Amount outAmount = txn.getAmount();
Set<Category> outCategories = txn.getCategories();
for (Budget bd : budgets) {
Budget newBd = bd.updateBudget(outAmount, outCategories, isRemoveTransaction);
setBudget(bd, newBd);
boolean beforeDeadline = txn.getDate().compareTo(bd.getDeadline()) < 0;
if (beforeDeadline) {
Budget newBd = bd.updateBudget(outAmount, outCategories, isRemoveTransaction);
setBudget(bd, newBd);

}
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/seedu/address/model/transaction/Budget.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Budget updateBudget(Amount amount, Set<Category> categories, boolean isRe
Budget newBudget = new Budget(newAmount, this.getDeadline(), this.getCategories());
newBudget.setInitialAmount(this.initialAmount);
return newBudget;
} else if (isSameCategory && !isRemoveTransaction) {
} else if (isSameCategory) {
Amount newAmount = this.amount.addAmount(amount);
Budget newBudget = new Budget(newAmount, this.getDeadline(), this.getCategories());
newBudget.setInitialAmount(this.initialAmount);
Expand Down Expand Up @@ -164,7 +164,7 @@ public Budget updateBudget(Amount amountToReplace, Amount amountReplacement,
Budget newBudget = new Budget(newAmount, this.getDeadline(), this.getCategories());
newBudget.setInitialAmount(this.initialAmount);
return newBudget;
} else if (isSameCategory && isSameTransactionCategory) {
} else if (isSameCategory) {
Amount newAmount = this.amount.addAmount(amountReplacement).subtractAmount(amountToReplace);
Budget newBudget = new Budget(newAmount, this.getDeadline(), this.getCategories());
newBudget.setInitialAmount(this.initialAmount);
Expand All @@ -174,10 +174,6 @@ public Budget updateBudget(Amount amountToReplace, Amount amountReplacement,
}
}

private void updateDeadline(Date date) {
this.deadline = date;
}

/**
* Calculates the new Date given the amount of duration from Today.
*
Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
-fx-vgap: 3;
}

#budgetDetails, #amounts .label {
#budgetDetails .label {
-fx-text-fill: white;
-fx-background-color: #56ae87;
-fx-padding: 1 3 1 3;
Expand All @@ -367,6 +367,15 @@
-fx-font-size: 11;
}

#amounts .label {
-fx-text-fill: white;
-fx-background-color: #56ae87;
-fx-padding: 1 3 1 3;
-fx-border-radius: 2;
-fx-background-radius: 2;
-fx-font-size: 11;
}

#budgetMinus {
-fx-hgap: 7;
-fx-vgap: 3;
Expand Down

0 comments on commit 0c9e9b0

Please sign in to comment.