Skip to content

Commit

Permalink
Merge a447154 into f245be4
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarZeng committed Nov 7, 2018
2 parents f245be4 + a447154 commit 8ef0dc0
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 45 deletions.
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appTitle" : "Financial Planner",
"logLevel" : "INFO",
"userPrefsFilePath" : "preferences.json"
}
105 changes: 81 additions & 24 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,12 @@ This feature has 2 different kind of modes as follows:

. Duo Argument Mode - Input arguments must contain only 1 category and only 1 order, and can be input in no particular order

The input given by the user is passed to `SortCommandParser` to split the input separated by whitespaces to ensure
The input given by the user




is passed to `SortCommandParser` to split the input separated by whitespaces to ensure
there is either only one or two arguments input by the user. These arguments are stored in an array of strings and
the size of the array determines the mode of the command.

Expand Down Expand Up @@ -446,7 +451,7 @@ The sequence diagram below details the sequence of program executions for the lo

image::SummarySequenceDiagram.png[width="790"]

. When the user types in the command "summary date d/1-1-2018 12-12-2018", the command is passed fron LogicManager to FinancialPlannerParser. In here,
. When the user types in the command "summary date d/1-1-2018 12-12-2018", the command is passed from LogicManager to FinancialPlannerParser. In here,
the system chooses which parser to use which is SummaryCommandParser and calls its parse method which is polymorphic, meaning that every parser has the same function but use different
implementation.
. In this class, based on the `mode` parameter given, the system chooses a SummaryCommand to instantiate and pass the reference back to the Logic Manager. The various checks for the validity of the
Expand Down Expand Up @@ -582,32 +587,44 @@ The following sequence diagram shows how the limit operation works:
image::FindTagSequenceDiagram.png[width:800]
// end::findtag[]

// tag::addlimit[]
=== addLimit feature
==== Current Implementation
The limit command is based on the data type "Date", which includes two dates and "moneyFlow".
Once the user execute the limit command, the Limit will be stored inside the LimitList.xml file by
calling the function model.add(limit). The input limit will be serialized and stored.
Whenever the user change the recordList information, including adding a record, deleting a record
and editing a record, all the limits will be checked automatically by calling the function model.autoLimitCheck,
this function will generate a string which contains all the exceeded limits' information will be printed
out to warn the user that they have overspent their money.
// tag::limitfeatures[]
=== Limit features
. `Limit Storage`:
The limit features are based on the data type "Limit", which includes two dates and "moneyFlow".
When entering only one date, the parser will let the date be both dateStart and dateEnd.
It is equivalent to entering two same dates.
The limit storage is based on the dates, which means there
should be at most one limit for one period of time.

The user enter two dates after the one "d/" index followed by money with m/ index.
The user need to input two dates, the first one is dateStart while the second one is dateEnd.
The dateStart must be earlier or equals to dateEnd, otherwise, the program will throw error.
The user also need to input the limit money they want to set. Unlike the moneyFlow used
by addCommand, the limit moneyFlow can only be normal real number, which does not have "-" or
. `Limit check`:
Whenever the user change the recordList information, including adding a record, deleting a record
and editing a record, all the limits will be checked automatically by calling the function model.autoLimitCheck().
The function will look through all the records and calculate the total money for each limit inside using a loop which will
execute the isExceeded().
This function will generate a string which contains all the exceeded limits' information will be printed
out to warn the user that they have overspent.

. ``
Unlike the moneyFlow used by addCommand, the limit moneyFlow can only be normal real number, which does not have "-" or
"+" in front of the number. After user input the normal real number, the parser will add a "-"
at the beginning of the real number, which makes it a normal moneyFlow.
If user input wrong form of limit moneyFlow, the program will throw error.
If user input wrong form of limit moneyFlow, the program will throw an error.
// tag::addlimit[]
==== addLimit feature
===== Current Implementation
Once the user execute the addLimit command, the Limit will be stored inside the LimitList.xml file by
calling the function model.addLimit(limit). The input limit will be serialized and stored.


The user enters two dates after the one "d/" index followed by money with m/ index.
The dateStart must be earlier or equals to dateEnd, otherwise, the program will throw an error.
The user also need to input the limit money they want to set.

The input given by the user is passed to `ArgumentTokeniser#tokenise` to split the input separated by prefixes.
. This returns a `ArgumentMultiMap` which contains a map with prefixes as keys and their associated input arguments as the value.
. The string associated with `d/` is then passed into `LimitCommandParser#splitByWhitespace` for further processing and returns an array.
This string will be split into two strings and each of them will be construct as a date type variable.
. After parsing the two dates, the parser will check whether the dateStart is small
. After parsing the two dates, the parser will check whether the dateStart is earlier than dateEnd.
. The argument mode is determined by the size of this array and the elements are further processed into `Date` objects, before creating and returning a `ListCommand` object.

The following sequence diagram shows how the limit operation works:
Expand All @@ -619,12 +636,13 @@ image::LimitSequenceDiagram.png[width:800]
==== Current Implementation
deleteLimit will delete the limit inside the limitList according to the dates input. The user inputs
two dates, dateStart and dateEnd, and the parser will make it a limit which has a dummy money.
Similar to the addLimit feature, the parser will set the dateStart and dateEnd same date if the user input only one date.
Then call the getSameDatesLimit() to get the limit with the same dates. Afterwards, the command will
call deleteLimit(sameDatesLimit) to delete the limit.

The user enter two dates after the one "d/" index.
The user enter two dates (or one date) after the one "d/" index.
The user need to input two dates, the first one is dateStart while the second one is dateEnd.
The dateStart must be earlier or equals to dateEnd, otherwise, the program will throw error.
The dateStart must be earlier or equal to dateEnd, otherwise, the program will throw an error.
If there is no limits inside the limitList has the same dates, the program will throw an error.


Expand All @@ -643,15 +661,17 @@ image::deleteLimitSequenceDiagram.png[width:800]
=== editLimit feature
==== Current Implementation
The editLimit command is similar to limit command, has dateStart, dateEnd and moneyFlow.
The command will do the replacement by deleting the limit with same dates and add the new limit.

The command will do the replacement by deleting the limit with same dates and add the new limit by calling model.updateLimit().
The parser will return the new limit and check whether there is a limit sharing the same dates. If there is a limit, it will
change the replace the original limit with the new limit. If there is no limit with the same date, the program will throw error.


The user enter two dates after the one "d/" index followed by money with m/ index.
The user need to input two dates, the first one is dateStart while the second one is dateEnd.
Similar to the addLimit feature, the parser will set the dateStart and dateEnd same date if the user input only one date.
The dateStart must be earlier or equals to dateEnd, otherwise, the program will throw error.
If there is no limits inside the limitList has the same dates, the program will throw an error.
The user also need to input the limit money they want to reset.
The user also need to input the limit money they want to reset. The money has the same requirement as addLimit command.


The input given by the user is passed to `ArgumentTokeniser#tokenise` to split the input separated by prefixes.
Expand All @@ -665,6 +685,42 @@ The following sequence diagram shows how the limit operation works:

image::editLimitSequenceDiagram.png[width:800]
// end::editLimit[]
// tag::addMonthlyLimit[]
=== addMonthlyLimit feature
==== Current Implementation
The addMonthlyLimit command is to add a continuous limit always for this month. The limit will always check
the spend of the month according to the current time. For example, if the limit was set to be 200 at April, the
limit will check the total spend for April. When the time comes to May, the limit will no longer check April, instead, the limit
will check the total spend of May until the last second of May. The user will input only the money they want to set.
The parser will make the limit with a special date "01-01-9999", which is not likely to be used. Then call the model.addLimit() function
to add the limit. Once the limit is going to be checked, the function generateThisMonthLimit() will be called, which
will generate a new limit according to the current date. Then use this date to do the limit check and generate output.

Unlike the moneyFlow used by addCommand, the limit moneyFlow can only be normal real number, which does not have "-" or
"+" in front of the number. After user input the normal real number, the parser will add a "-"
at the beginning of the real number, which makes it a normal moneyFlow.
If user input wrong form of limit moneyFlow, the program will throw error.

The input given by the user is passed to `ArgumentTokeniser#tokenise` to split the input separated by prefixes.
This returns a `ArgumentMultiMap` which contains a map with prefixes as keys and their associated input arguments as the value.
The parser will generate the limit with special date and the moneyFlow according to the user input.
// end::addMonthlyLimit[]
// tag::editMonthlyLimit[]
=== editMonthlyLimit feature
==== Current Implementation
The editMonthlyLimit command it to edit the monthly limit money. The command function is similar to the
editLimit command. The parser is similar to the addMonthlyLimit command parser, which will generate the
limit with the special date.

Unlike the moneyFlow used by addCommand, the limit moneyFlow can only be normal real number, which does not have "-" or
"+" in front of the number. After user input the normal real number, the parser will add a "-"
at the beginning of the real number, which makes it a normal moneyFlow.
If user input wrong form of limit moneyFlow, the program will throw error.

The input given by the user is passed to `ArgumentTokeniser#tokenise` to split the input separated by prefixes.
This returns a `ArgumentMultiMap` which contains a map with prefixes as keys and their associated input arguments as the value.
The parser will generate the limit with special date and the moneyFlow according to the user input.
// end::editMonthlyLimit[]
// tag::checkLimit[]
=== checkLimit feature
==== Current Implementation
Expand All @@ -677,6 +733,7 @@ The following sequence diagram shows how the limit operation works:

image::checkLimitSequenceDiagram.png[width:800]
// end::checkLimit[]
// end::limitfeatures[]

// tag::delete_by_date_entry[]

Expand Down
12 changes: 2 additions & 10 deletions src/main/java/seedu/planner/logic/commands/AddLimitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ public class AddLimitCommand extends Command {
+ PREFIX_DATE + "18-9-2018 "
+ PREFIX_MONEYFLOW + "100) \n";

public static final String MESSAGE_SINGLE_DATE = "Date: %s\n";
public static final String MESSAGE_DOUBLE_DATE = "Date period: %s -- %s\n";
public static final String MESSAGE_BASIC_SPEND = "The limit you have set: %.2f \n"
+ "Your spend during the limit period: %.2f\n";

public static final String MESSAGE_BASIC_EARNED = "The limit you have set: %.2f \n"
+ "Your income during the limit period: %.2f\n";
public static final String MESSAGE_EXCEED = "Your spend exceeded the limit !!! \n";
public static final String MESSAGE_NOT_EXCEED = "Your spend did not exceed the limit ^o^\n";
public static final String MESSAGE_SUCCESS = "The limit has been added.\n";
public static final String MESSAGE_LIMITS_SAME_DATE = "There is already a limit for that period of date\n";


Expand All @@ -65,7 +57,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

model.addLimit(limit);
output = model.generateLimitOutput(model.isExceededLimit(limit),
output = MESSAGE_SUCCESS + model.generateLimitOutput(model.isExceededLimit(limit),
model.getTotalSpend(limit), limit);
model.commitFinancialPlanner();
return new CommandResult(output);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package seedu.planner.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.planner.logic.parser.CliSyntax.PREFIX_MONEYFLOW;

import seedu.planner.logic.CommandHistory;
import seedu.planner.logic.commands.exceptions.CommandException;
import seedu.planner.model.Model;
import seedu.planner.model.record.Limit;



/**
* This Command is to set a limit for continuous month, which means the this limit is always for current month.
* */
public class AddMonthlyLimitCommand extends Command {
public static final String COMMAND_WORD = "addmonthlylimit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Set a limit for continuous months. "
+ "Parameters: "
+ PREFIX_MONEYFLOW + "LIMIT_MONEY " + "\n"
+ "Example: "
+ COMMAND_WORD + " "
+ PREFIX_MONEYFLOW + "500" + "\n";

public static final String MESSAGE_HAS_LIMIT = "There is already a monthly limit. \n";
public static final String MESSAGE_SUCCESS = "The monthly limit has been added. \n";
public static final String DATE_SPECIAL_FOR_MONTHLY = "01-01-9999";



private Limit limit;

private String output;

public AddMonthlyLimitCommand (Limit limitIn) {
requireNonNull(limitIn);
limit = limitIn;

}


@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {

if (model.hasSameDateLimit(limit)) {
throw new CommandException(MESSAGE_HAS_LIMIT);
}

model.addLimit(limit);
output = MESSAGE_SUCCESS + model.generateLimitOutput(model.isExceededLimit(limit),
model.getTotalSpend(limit), limit);
model.commitFinancialPlanner();
return new CommandResult(output);
}

@Override
public boolean equals (Object other) {
return other == this // short circuit if same object
|| (other instanceof seedu.planner.logic.commands.AddMonthlyLimitCommand // instanceof handles nulls
&& limit.equals(((seedu.planner.logic.commands.AddMonthlyLimitCommand) other).limit));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package seedu.planner.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.planner.logic.CommandHistory;
import seedu.planner.logic.commands.exceptions.CommandException;
import seedu.planner.model.Model;
import seedu.planner.model.record.Date;
import seedu.planner.model.record.Limit;
import seedu.planner.model.record.MoneyFlow;

/**
* This command is to remove the monthly limit stored inside the limitList.
*/

public class DeleteMonthlyLimitCommand extends Command {
public static final String COMMAND_WORD = "deletemonthlylimit";
public static final String MESSAGE_SUCCESS = "The monthly limit has been deleted";
public static final String MESSAGE_FAILURE = "There is no monthly limit!";
public static final Date DATE_SPECIAL_FOR_MONTHLY = new Date("01-01-9999");

private Limit monthlyLimit = new Limit(DATE_SPECIAL_FOR_MONTHLY, DATE_SPECIAL_FOR_MONTHLY, new MoneyFlow("-1"));
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

if (!model.hasSameDateLimit(monthlyLimit)) {
throw new CommandException(MESSAGE_FAILURE);
}
model.deleteLimit(model.getSameDatesLimit(DATE_SPECIAL_FOR_MONTHLY, DATE_SPECIAL_FOR_MONTHLY));
model.commitFinancialPlanner();
return new CommandResult(MESSAGE_SUCCESS);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package seedu.planner.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.planner.logic.parser.CliSyntax.PREFIX_MONEYFLOW;

import seedu.planner.commons.core.Messages;
import seedu.planner.logic.CommandHistory;
import seedu.planner.logic.commands.exceptions.CommandException;
import seedu.planner.model.Model;
import seedu.planner.model.record.Limit;


/**
* This command is to modify the monthly limit money.
*/
public class EditMonthlyLimitCommand extends Command {
public static final String COMMAND_WORD = "editmonthlylimit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edit the existing monthly limit. "
+ "Parameters: "
+ PREFIX_MONEYFLOW + "LIMIT_MONEY " + "\n"
+ "Example: "
+ COMMAND_WORD + " "
+ PREFIX_MONEYFLOW + "500" + "\n";


public static final String MESSAGE_SUCCESS = "The monthly limit has been edited. \n";



private Limit limit;
private Limit originalLimit;

private String output;

public EditMonthlyLimitCommand (Limit limitIn) {
requireNonNull(limitIn);
limit = limitIn;

}


@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {

if (!model.hasSameDateLimit(limit)) {
throw new CommandException(Messages.MESSAGE_LIMITS_DO_NOT_EXIST);
}
originalLimit = model.getSameDatesLimit(limit.getDateStart(), limit.getDateEnd());
model.updateLimit(originalLimit, limit);

output = MESSAGE_SUCCESS + "Original Limit:\n"
+ model.generateLimitOutput(model.isExceededLimit(originalLimit),
model.getTotalSpend(originalLimit), originalLimit)
+ "Modified Limit: \n"
+ model.generateLimitOutput(model.isExceededLimit(limit),
model.getTotalSpend(limit), limit);
model.commitFinancialPlanner();
return new CommandResult(output);
}

@Override
public boolean equals (Object other) {
return other == this // short circuit if same object
|| (other instanceof seedu.planner.logic.commands.EditMonthlyLimitCommand // instanceof handles nulls
&& limit.equals(((seedu.planner.logic.commands.EditMonthlyLimitCommand) other).limit));
}
}

0 comments on commit 8ef0dc0

Please sign in to comment.