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

Add support for budget and fixes #89

Merged
merged 33 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a39b2e8
added currency to budget
choonx99 Oct 28, 2019
3339ab0
updated delete and edit for budget, view budget list,
choonx99 Oct 28, 2019
267f819
fixed test case errors
choonx99 Oct 29, 2019
437fb50
Fix expenseList and budgetList display issue
Cary-Xx Oct 29, 2019
f3dbfae
Fix
Cary-Xx Oct 29, 2019
2a3da65
update delete hack
choonx99 Oct 30, 2019
dc57788
fixed delete and edit functions
choonx99 Oct 31, 2019
0a0054d
Fix budget and update UI
Cary-Xx Oct 31, 2019
d207233
Merge pull request #87 from Cary-Xx/view
Cary-Xx Oct 31, 2019
b6e6ba7
fix amount to remove currency prefix and convert to 2 decimals
choonx99 Oct 31, 2019
03658eb
update editBudget to change state after edit
choonx99 Oct 31, 2019
40e1422
Merge branch 'Add_Budget' of https://github.com/AY1920S1-CS2103-T14-4…
choonx99 Oct 31, 2019
2004ac7
added currency to budget
choonx99 Oct 28, 2019
27f4ca2
updated delete and edit for budget, view budget list,
choonx99 Oct 28, 2019
bda8763
fixed test case errors
choonx99 Oct 29, 2019
e119ee7
Fix expenseList and budgetList display issue
Cary-Xx Oct 29, 2019
83a2efe
Fix
Cary-Xx Oct 29, 2019
80a58e1
update delete hack
choonx99 Oct 30, 2019
11eebe4
fixed delete and edit functions
choonx99 Oct 31, 2019
0361d27
Fix budget and update UI
Cary-Xx Oct 31, 2019
e0ed3f6
fix amount to remove currency prefix and convert to 2 decimals
choonx99 Oct 31, 2019
13932ae
update editBudget to change state after edit
choonx99 Oct 31, 2019
8495afc
Fix for PE v1.3
Cary-Xx Oct 31, 2019
e87d248
Fix
Cary-Xx Oct 31, 2019
a57937f
Update Ui.png
Cary-Xx Oct 31, 2019
2102125
Fix tests
Cary-Xx Nov 1, 2019
0a0da21
Fix
Cary-Xx Nov 1, 2019
4cdedd2
Fix UI
Cary-Xx Nov 1, 2019
11a6270
Merge branch 'Add_Budget' of https://github.com/AY1920S1-CS2103-T14-4…
choonx99 Nov 4, 2019
239e686
GUI fix
choonx99 Nov 4, 2019
d7389c9
fix prevent amount 0, added extra check to prevent overlapping budget…
choonx99 Nov 4, 2019
1d6b6e2
convert expenselist name to defaultexpenselist in modelmanager only
choonx99 Nov 4, 2019
b50c1dc
converted viewstate to use enumeration. fixed list command and other …
choonx99 Nov 4, 2019
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
Binary file modified docs/images/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
public class GuiSettings implements Serializable {

private static final double DEFAULT_HEIGHT = 600;
private static final double DEFAULT_WIDTH = 740;
private static final double DEFAULT_HEIGHT = 700;
private static final double DEFAULT_WIDTH = 1350;

private final double windowWidth;
private final double windowHeight;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_EXPENSE_DISPLAYED_INDEX = "The expense index provided is invalid";
public static final String MESSAGE_INVALID_BUDGET_DISPLAYED_INDEX = "The budget index provided is invalid";
public static final String MESSAGE_EXPENSES_LISTED_OVERVIEW = "%1$d expenses listed!";
public static final String MESSAGE_EXPENSE_LISTED_OVERVIEW = "%1$d expense listed!";

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyExpenseList;
import seedu.address.model.budget.Budget;
import seedu.address.model.budget.ReadOnlyBudgetList;
import seedu.address.model.expense.Expense;

/**
Expand All @@ -33,16 +35,43 @@ public interface Logic {
*/
ReadOnlyExpenseList getExpenseList();

/**
* Returns an unmodifiable view of the list of expenses
*/
ObservableList<Expense> getExpenses();

/**
* Returns an unmodifiable view of the filtered list of expenses
*/
ObservableList<Expense> getFilteredExpenseList();

/**
* Returns an unmodifiable view of the filtered list of all expenses including those in budgets
*/
// ObservableList<Expense> getFilteredFullExpenseList();

/**
* Returns the user prefs' expense list file path.
*/
Path getExpenseListFilePath();

/**
* Returns the BudgetList.
*
* @see Model#getBudgetList()
*/
ReadOnlyBudgetList getBudgetList();

/**
* Returns an unmodifiable view of the filtered list of budgets
*/
ObservableList<Budget> getFilteredBudgetList();

/**
* Returns the user prefs' budget list file path.
*/
Path getBudgetListFilePath();

/**
* Returns the user prefs' GUI settings.
*/
Expand All @@ -52,4 +81,6 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

ObservableList<Expense> updateExpenses();
}
32 changes: 32 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyExpenseList;
import seedu.address.model.budget.Budget;
import seedu.address.model.budget.ReadOnlyBudgetList;
import seedu.address.model.expense.Expense;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -63,16 +65,46 @@ public ReadOnlyExpenseList getExpenseList() {
return model.getExpenseList();
}

@Override
public ObservableList<Expense> getExpenses() {
return model.getExpenses();
}

@Override
public ObservableList<Expense> updateExpenses() {
return model.initExpenses();
}

@Override
public ObservableList<Expense> getFilteredExpenseList() {
return model.getFilteredExpenseList();
}

// @Override
// public ObservableList<Expense> getFilteredFullExpenseList() {
// return model.getFilteredFullExpenseList();
// }

@Override
public Path getExpenseListFilePath() {
return model.getExpenseListFilePath();
}

@Override
public ReadOnlyBudgetList getBudgetList() {
return model.getBudgetList();
}

@Override
public ObservableList<Budget> getFilteredBudgetList() {
return model.getFilteredBudgetList();
}

@Override
public Path getBudgetListFilePath() {
return model.getBudgetListFilePath();
}

@Override
public GuiSettings getGuiSettings() {
return model.getGuiSettings();
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/seedu/address/logic/commands/AddBudgetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ViewState;
import seedu.address.model.budget.Budget;

/**
Expand All @@ -18,17 +20,18 @@ public class AddBudgetCommand extends Command {
public static final String COMMAND_WORD = "budget";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a budget to the budget list.\n"
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_AMOUNT + "AMOUNT "
+ PREFIX_DATE + "START-DATE "
+ PREFIX_END_DATE + "END-DATE...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Japan Travel "
+ PREFIX_AMOUNT + "$2000.00 "
+ PREFIX_DATE + "12/12/2019 "
+ PREFIX_END_DATE + "18/12/2019\n";

+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_AMOUNT + "AMOUNT "
+ "[" + PREFIX_CURRENCY + "CURRENCY] "
+ PREFIX_DATE + "START-DATE "
+ PREFIX_END_DATE + "END-DATE...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Japan Travel "
+ PREFIX_AMOUNT + "$2000.00 "
+ PREFIX_CURRENCY + "USD "
+ PREFIX_DATE + "12/12/2019 "
+ PREFIX_END_DATE + "18/12/2019\n";

public static final String MESSAGE_SUCCESS = "New budget added: %1$s";
public static final String MESSAGE_DUPLICATE_BUDGET = "This budget already exists in the budget list";
Expand Down Expand Up @@ -62,6 +65,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addBudget(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
model.setViewState(ViewState.BUDGETLIST);
return new CommandResult(null, model.getFilteredBudgetList(), null, String.format(MESSAGE_SUCCESS, toAdd));
}
}
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ViewState;
import seedu.address.model.expense.Expense;


Expand All @@ -28,7 +29,7 @@ public class AddCommand extends Command {
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Textbook "
+ PREFIX_AMOUNT + "$23.50 "
+ PREFIX_AMOUNT + "23.50 "
+ PREFIX_CURRENCY + "USD "
+ PREFIX_DATE + "1245 "
+ PREFIX_TAG + "education "
Expand Down Expand Up @@ -56,6 +57,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addExpense(toAdd);
model.setViewState(ViewState.DEFAULT_EXPENSELIST);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
32 changes: 28 additions & 4 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,46 @@

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.ExpenseList;
import seedu.address.model.Model;
import seedu.address.model.ViewState;
import seedu.address.model.budget.Budget;
import seedu.address.model.budget.BudgetList;

/**
* Clears the address book.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Expense list has been cleared!";
public static final String MESSAGE_CLEAR_EXPENSES_SUCCESS = "Expense list has been cleared!";
public static final String MESSAGE_CLEAR_BUDGETS_SUCCESS = "Budget list has been cleared!";
public static final String MESSAGE_CLEAR_EXPENSES_IN_BUDGET_SUCCESS = "Budget: %1$s has been cleared!";

public static final String MESSAGE_CLEAR_ERROR = "An error occurred while trying to clear list";

@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.setExpenseList(new ExpenseList());
return new CommandResult(MESSAGE_SUCCESS);
ViewState viewState = model.getViewState();

if (viewState.equals(ViewState.DEFAULT_EXPENSELIST)) {
model.setExpenseList(new ExpenseList());
return new CommandResult(model.getFilteredExpenseList(), null,
null, MESSAGE_CLEAR_EXPENSES_SUCCESS);
} else if (viewState.equals(ViewState.EXPENSELIST_IN_BUDGET)) {
Budget lastViewedBudget = model.getLastViewedBudget();
lastViewedBudget.setExpenseListInBudget(new ExpenseList());

return new CommandResult(model.getExpenseListFromBudget(lastViewedBudget), null, null,
String.format(MESSAGE_CLEAR_EXPENSES_IN_BUDGET_SUCCESS, lastViewedBudget.getName()));
} else if (viewState.equals(ViewState.BUDGETLIST)) {
model.setBudgetList(new BudgetList());
return new CommandResult(null, model.getFilteredBudgetList(),
null, MESSAGE_CLEAR_BUDGETS_SUCCESS);
} else {
throw new CommandException(MESSAGE_CLEAR_ERROR);
}
}
}
57 changes: 57 additions & 0 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import java.util.Objects;

import javafx.collections.ObservableList;
import seedu.address.model.budget.Budget;
import seedu.address.model.expense.Expense;

/**
* Represents the result of a command execution.
*/
Expand All @@ -21,10 +25,42 @@ public class CommandResult {
*/
private final boolean exit;

/**
* Used for access expenseList inside a budget.
*/
private final ObservableList<Expense> expenseList;

/**
* Used for access budgetList.
*/
private final ObservableList<Budget> budgetList;

/**
* Used only access target budget.
*/
private final Budget budget;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
this.budgetList = null;
this.expenseList = null;
this.budget = null;
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
}

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(ObservableList<Expense> expenseList, ObservableList<Budget> budgetList, Budget budget,
String feedbackToUser, boolean showHelp,
boolean exit) {
this.budgetList = budgetList;
this.expenseList = expenseList;
this.budget = budget;
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
Expand All @@ -38,10 +74,31 @@ public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false);
}

/**
* Constructs a {@code CommandResult} with the specified {@code expenseList}, {@code viewState}
* and other fields set to their default value.
*/
public CommandResult(ObservableList<Expense> expenseList, ObservableList<Budget> budgetList, Budget budget,
String feedbackToUser) {
this(expenseList, budgetList, budget, feedbackToUser, false, false);
}

public ObservableList<Expense> getExpenseList() {
return expenseList;
}

public ObservableList<Budget> getBudgetList() {
return budgetList;
}

public String getFeedbackToUser() {
return feedbackToUser;
}

public Budget getBudget() {
return budget;
}

public boolean isShowHelp() {
return showHelp;
}
Expand Down
Loading