Skip to content

Commit

Permalink
Merge pull request #189 from itsmejr257/junRong-BugFixes-Rec
Browse files Browse the repository at this point in the history
Add Bug-Fixes for Recurring Expenses Feature
  • Loading branch information
itsmejr257 authored Apr 9, 2024
2 parents 6d8264a + 8235363 commit a528da2
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 290 deletions.
44 changes: 30 additions & 14 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ command to run the application.
11. Check Splitted Expenses
12. Settle Splitted Expenses
13. Find Expense
14. Add Recurring Bill
15. List Recurring Bills
16. Remove Recurring Bill
17. Add Expense to a Recurring Bill
18. View Expenses in a Recurring Bill
19. Add Expenses in a Recurring Bill to Overall Expenses
20. Change Currency
21. Set Budget
22. Get Budget
23. Print Budget
24. Get Graphical Insights for expenses
25. Get Graphical Insights for savings
14. Recurring Bill Description
15. Add Recurring Bill
16. List Recurring Bills
17. Remove Recurring Bill
18. Add Expense to a Recurring Bill
19. View Expenses in a Recurring Bill
20. Add Expenses in a Recurring Bill to Overall Expenses
21. Change Currency
22. Set Budget
23. Get Budget
24. Print Budget
25. Get Graphical Insights for expenses
26. Get Graphical Insights for savings

### Display Commands : `menu`
Displays the corresponding features of BudgetBuddy
Expand Down Expand Up @@ -272,6 +273,17 @@ Examples of usage :
`find expenses d/coffee morethan/200 lessthan/ ` : Finds all expenses with the word "coffee" and amount higher than $200
`find expenses d/coffee morethan/200 lessthan/400 ` : Finds all expenses with the word "coffee" and amount higher than $200, but lesser than $400

### Recurring Bill Description
The next few features in the user guide would be related to the Recurring Bill Feature. The commands associated to
this overall feature would start with the `rec` command, followed by the relevant `commandType` and parameters. This
feature allows user to create and manage multiple lists of expenses **separate** from the user's overall expenses
, which can be added to the users overall expenses.

The term **recurring** here is to indicate that a user is able to **add** a set of pre-defined expenses to their
overall expenses at any given point in time. Hence, this could range from subscription payments, a future grocery list,
etc.


### Add Recurring Bill : `rec newlist`

Adds a new recurring Bill.
Expand All @@ -295,6 +307,7 @@ Format : `rec viewlists`

* This command is **space sensitive**, in particular, the space between `rec` and `viewlists` must be
**exactly** one space apart for the command to be recognised
* **Note** Anything typed after `rec viewlists` will be ignored.

Examples of Output :

Expand All @@ -313,7 +326,7 @@ Removes a recurring bill
Format : `rec removelist LISTNUMBER`

* `LISTNUMBER` refers to the associated list number of recurring bill when doing a `rec viewlists`
* `LISTNUMBER` must be a **valid** integer, and should be a **valid** list number
* `LISTNUMBER` must be a **valid** integer > 0, and should be a **valid** list number

Examples of usage :

Expand All @@ -330,7 +343,10 @@ Format : `rec newexpense to/LISTNUMBER c/CATEGORY a/AMOUNT d/DESCRIPTION`
* `AMOUNT` refers to the amount value of the expense you wish to add
* `DESCRIPTION` refers to the description of the expense you wish to add
* `LISTNUMBER` must be a **valid** integer, and should be a **valid** list number
* `CATEGORY`, `AMOUNT` and `DESCRIPTION` follows the same constraints as if you were to add a normal expense
* `CATEGORY`, `AMOUNT` and `DESCRIPTION` follows the same constraints as if you were to add a normal expense.
* `to/, c/, a/, d/` must be placed in the **right order**
* **Note** Although the user is able to combine the prefixes without any spaces, etc.
`rec newexpense to/1c/Entertainmenta/200d/movies`, it is strongly recommended to ensure spaces for clarity.

Examples of usage :
`rec newexpense to/1 c/Entertainment a/200 d/movies` : Adds a new expense to the 1st recurring bill
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/seedu/budgetbuddy/BudgetBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import seedu.budgetbuddy.command.Command;
import seedu.budgetbuddy.commons.ExpenseList;
import seedu.budgetbuddy.commons.RecurringExpensesList;
import seedu.budgetbuddy.commons.RecurringExpenseLists;
import seedu.budgetbuddy.commons.SavingList;
import seedu.budgetbuddy.commons.SplitExpenseList;
import seedu.budgetbuddy.exception.InvalidRecurringExpensesFileException;
Expand All @@ -17,7 +17,7 @@ public class BudgetBuddy {
private ExpenseList expenses;
private SavingList savings;
private SplitExpenseList splitexpenses;
private RecurringExpensesList expensesList;
private RecurringExpenseLists recurringExpenseLists;
private Storage expensesStorage;
private Storage savingsStorage;
private Storage recurringExpensesStorage;
Expand All @@ -30,7 +30,7 @@ public BudgetBuddy() {
parser = new Parser();
expenses = new ExpenseList();
savings = new SavingList();
expensesList = new RecurringExpensesList();
recurringExpenseLists = new RecurringExpenseLists();
splitexpenses = new SplitExpenseList();
expensesStorage = new Storage("./data/ExpenseFile.txt");
savingsStorage = new Storage("./data/SavingsFile.txt");
Expand All @@ -40,7 +40,7 @@ public BudgetBuddy() {
}

public void handleCommands(String input) {
Command command = parser.parseCommand(expenses, savings, splitexpenses, expensesList, input);
Command command = parser.parseCommand(expenses, savings, splitexpenses, recurringExpenseLists, input);


if (command != null) {
Expand All @@ -52,7 +52,8 @@ public void handleCommands(String input) {
try {
expensesStorage.saveExpenses(expenses.getExpenses());
savingsStorage.saveSavings(savings.getSavings());
recurringExpensesStorage.saveRecurringExpenses(expensesList);
recurringExpensesStorage.saveRecurringExpenses(recurringExpenseLists);

defaultCurrency.saveCurrency();
} catch (IOException e) {
System.out.println("Error saving to file.");
Expand All @@ -70,7 +71,7 @@ public void run() {
defaultCurrency.loadCurrency();
this.expenses.getExpenses().addAll(expensesStorage.loadExpenses());
this.savings.getSavings().addAll(savingsStorage.loadSavings());
this.expensesList = recurringExpensesStorage.loadRecurringExpensesList();
this.recurringExpenseLists = recurringExpensesStorage.loadRecurringExpensesList();


} catch (FileNotFoundException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/budgetbuddy/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import seedu.budgetbuddy.commandcreator.GetBudgetCommandCreator;
import seedu.budgetbuddy.commons.SavingList;
import seedu.budgetbuddy.commons.ExpenseList;
import seedu.budgetbuddy.commons.RecurringExpensesList;
import seedu.budgetbuddy.commons.RecurringExpenseLists;
import seedu.budgetbuddy.commons.SplitExpenseList;
import seedu.budgetbuddy.commons.CurrencyConverter;

Expand Down Expand Up @@ -175,7 +175,7 @@ public Boolean isGetSavingsInsightsCommand(String input) {
* input is invalid.
*/
public Command parseCommand(ExpenseList expenses, SavingList savings, SplitExpenseList
splitexpenses, RecurringExpensesList expensesList, String input) {
splitexpenses, RecurringExpenseLists expensesList, String input) {

if(isMenuCommand(input)) {
LOGGER.log(Level.INFO, "Confirmed that input is a menu command");
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/budgetbuddy/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.budgetbuddy.commons.SplitExpense;
import seedu.budgetbuddy.commons.ExpenseList;
import seedu.budgetbuddy.commons.Expense;
import seedu.budgetbuddy.commons.RecurringExpensesList;
import seedu.budgetbuddy.commons.RecurringExpenseLists;
import seedu.budgetbuddy.commons.RecurringExpenseList;
import seedu.budgetbuddy.commons.DefaultCurrency;

Expand Down Expand Up @@ -82,7 +82,7 @@ public void parseRecurringExpensesFile(ArrayList<ExpenseList> recurringExpenses,
int indexOfStartOfListName = indexOfStartExclamation + 3;

int indexOfEndExclamation = line.indexOf("!!!", 4);
int indexOfEndOfListName = indexOfEndExclamation - 1;
int indexOfEndOfListName = indexOfEndExclamation;

String name = line.substring(indexOfStartOfListName, indexOfEndOfListName).trim();
ExpenseList expenses = new RecurringExpenseList(name, new ArrayList<>());
Expand All @@ -109,7 +109,7 @@ public void parseRecurringExpensesFile(ArrayList<ExpenseList> recurringExpenses,
}

}
public RecurringExpensesList loadRecurringExpensesList() throws IOException{
public RecurringExpenseLists loadRecurringExpensesList() throws IOException{
File file = new File(filePath);
ArrayList<ExpenseList> recurringExpenses = new ArrayList<>();

Expand All @@ -126,30 +126,30 @@ public RecurringExpensesList loadRecurringExpensesList() throws IOException{

scanner.close();

RecurringExpensesList recurringExpensesList = new RecurringExpensesList(recurringExpenses);
return recurringExpensesList;
RecurringExpenseLists recurringExpenseLists = new RecurringExpenseLists(recurringExpenses);
return recurringExpenseLists;
} catch (Exception e) {
LOGGER.log(Level.INFO, "Exception successfully caught. Error has been handled");
System.out.println(e.getMessage());
System.out.println("You Recurring Expenses File is corrupted, resetting the file....");
resetRecurringExpensesListFile();
return new RecurringExpensesList();
return new RecurringExpenseLists();
}

}

public void saveRecurringExpenses(RecurringExpensesList recurringExpensesList)
public void saveRecurringExpenses(RecurringExpenseLists recurringExpenseLists)
throws InvalidRecurringExpensesFileException, IOException {

ensureDirectoryExists();

try {
FileWriter writer = new FileWriter(filePath, false);
int numberOfRecurringExpenseList = recurringExpensesList.getSize();
int numberOfRecurringExpenseList = recurringExpenseLists.getSize();

for (int i = 0; i < numberOfRecurringExpenseList; i++) {
int listNumber = i + 1;
ExpenseList expenseList = recurringExpensesList.getExpenseListAtListNumber(listNumber);
ExpenseList expenseList = recurringExpenseLists.getExpenseListAtListNumber(listNumber);
ArrayList<Expense> expenses = expenseList.getExpenses();
String listName = expenseList.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.budgetbuddy.commons.DefaultCurrency;
import seedu.budgetbuddy.commons.ExpenseList;
import seedu.budgetbuddy.commons.SavingList;
import seedu.budgetbuddy.commons.RecurringExpensesList;
import seedu.budgetbuddy.commons.RecurringExpenseLists;

import java.util.Currency;

Expand All @@ -13,23 +13,23 @@ public class ChangeCurrencyCommand extends Command {
private Currency newCurrency;
private SavingList savings;
private ExpenseList expenses;
private RecurringExpensesList recurringExpensesList;
private RecurringExpenseLists recurringExpenseLists;
private CurrencyConverter currencyConverter;

public ChangeCurrencyCommand(Currency newCurrency, SavingList savings, ExpenseList expenses,
RecurringExpensesList recurringExpensesList, CurrencyConverter currencyConverter) {
RecurringExpenseLists recurringExpenseLists, CurrencyConverter currencyConverter) {
this.newCurrency = newCurrency;
this.savings = savings;
this.expenses = expenses;
this.recurringExpensesList = recurringExpensesList;
this.recurringExpenseLists = recurringExpenseLists;
this.currencyConverter = currencyConverter;
}

@Override
public void execute() {
currencyConverter.convertSavingCurrency(newCurrency, savings);
currencyConverter.convertExpenseCurrency(newCurrency, expenses);
currencyConverter.convertRecurringExpensesCurrency(newCurrency, recurringExpensesList);
currencyConverter.convertRecurringExpensesCurrency(newCurrency, recurringExpenseLists);
currencyConverter.convertBudgetCurrency(newCurrency, expenses);
DefaultCurrency.setDefaultCurrency(newCurrency);
}
Expand Down
Loading

0 comments on commit a528da2

Please sign in to comment.