Skip to content

Commit

Permalink
Resolved Merge Conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Mudaafi <[email protected]>
  • Loading branch information
Mudaafi committed Nov 9, 2019
2 parents 78dec07 + 65764d5 commit be0f7ad
Show file tree
Hide file tree
Showing 21 changed files with 440 additions and 53 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ javafx {
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0'
implementation 'com.google.code.gson:gson:2.8.6'
compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
}

application {
Expand Down
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Nov 08 15:37:50 SGT 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
2 changes: 1 addition & 1 deletion savedWallet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ out $15.0 /date 2010-11-01 /tags gift
out $12.0 /date 2019-11-08 /tags food
out $45.0 /date 2019-11-08 /tags travel concession
in $45.0 /date 2019-11-08 /tags angbao
out $100.0 /date 2019-11-08 /tags unlucky misplaced
out $100.0 /date 2019-11-08 /tags unlucky misplaced
25 changes: 24 additions & 1 deletion src/main/java/executor/command/CommandDateList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import duke.exception.DukeException;
import interpreter.Parser;
import storage.StorageManager;
import java.time.format.DateTimeParseException;
import java.text.ParseException;
import java.text.SimpleDateFormat;


public class CommandDateList extends Command {
private String date;

/**
* Constructor for CommandDateList subCommand Class.
*
* @param userInput String is the user input from the CLI
*/
public CommandDateList(String userInput) {
Expand All @@ -24,6 +27,11 @@ public CommandDateList(String userInput) {
@Override
public void execute(StorageManager storageManager) {
String outputStr = "You have the following receipts for" + " " + date + "\n";
if (!isDateFormat(this.date)) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Invalid date input. FORMAT : datelist yyyy-mm-dd");
return;
}
try {
outputStr += storageManager.getReceiptsByDate(this.date).getPrintableReceipts();
} catch (DukeException e) {
Expand All @@ -34,5 +42,20 @@ public void execute(StorageManager storageManager) {
this.infoCapsule.setCodeCli();
this.infoCapsule.setOutputStr(outputStr);
}

/**
* Boolean function for checking date format of input.
*
* @param dateString String is date input from the CLI
*/
public boolean isDateFormat(String dateString) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
return format.parse(dateString) != null;
} catch (ParseException e) {
return false;
}
}

}

14 changes: 10 additions & 4 deletions src/main/java/executor/command/CommandDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ public void execute(StorageManager storageManager) {
String outputStr;
try {
int index = Integer.parseInt(userInput.replace("delete", "").trim()) - 1;
outputStr = ("Task '"
outputStr = ("Task"
+ " "
+ (index + 1)
+ ") "
+ ")"
+ storageManager.getTaskNameByIndex(index)
+ "' deleted. \n");
+ " "
+ "has been deleted. \n");
storageManager.deleteTaskByIndex(index);
} catch (DukeException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.getMessage());
return;
} catch (NumberFormatException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Invalid index input. Please enter an integer");
return;
}
this.infoCapsule.setCodeToast();
this.infoCapsule.setOutputStr(outputStr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
import interpreter.Parser;
import storage.StorageManager;

public class CommandReceiptDelete extends Command {
import java.lang.reflect.InvocationTargetException;

public class CommandDeleteReceipt extends Command {
protected String userInput;

/**
* Constructor for CommandDeleteReceipt subCommand Class.
* @param userInput The user input from the CLI
*/
public CommandReceiptDelete(String userInput) {
public CommandDeleteReceipt(String userInput) {
super();
this.userInput = userInput;
this.description = "Deletes the specific entry that the user wants to remove. \n"
+ "FORMAT: receiptdelete <Index_of_Entry>";
this.commandType = CommandType.RECEIPTDELETE;
+ "FORMAT: deletereceipt <Index_of_Entry>";
this.commandType = CommandType.DELETERECEIPT;
}


Expand All @@ -26,7 +28,7 @@ public void execute(StorageManager storageManager) {
String integer = Parser.parseForPrimaryInput(this.commandType, userInput);
if (integer.isEmpty()) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Index input is missing. FORMAT : receiptdelete <Index_of_Entry>");
this.infoCapsule.setOutputStr("Index input is missing. FORMAT : deletereceipt <Index_of_Entry>");
return;
}
try {
Expand All @@ -41,8 +43,14 @@ public void execute(StorageManager storageManager) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.getMessage());
return;
} catch (NumberFormatException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Invalid index input. Please enter an integer");
return;
}
this.infoCapsule.setCodeToast();
this.infoCapsule.setOutputStr(outputStr);
}


}
84 changes: 84 additions & 0 deletions src/main/java/executor/command/CommandExport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package executor.command;

import com.opencsv.CSVWriter;
import duke.exception.DukeException;
import interpreter.Parser;
import storage.StorageManager;
import ui.Receipt;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class CommandExport extends Command {

/**
* CommandExport helps to export the wallet data as csv with useful headers.
* @param userInput String is the user entered input
*/
public CommandExport(String userInput) {
this.userInput = userInput;
this.commandType = CommandType.EXPORT;
this.description = "Exports txt into CSV\n"
+ "FORMAT : export \n";
}

@Override
public void execute(StorageManager storageManager) {
String userMessageForEnteringExtraFields = " ";

if (this.isThereExtraInputByUser(this.userInput)) {
userMessageForEnteringExtraFields = "Incorrect Command but DUKE$$$ understands"
+ " you would want to export Wallet to csv !\n";
}

try {
File csv = new File("data.csv");
FileWriter outputFile = new FileWriter(csv);
CSVWriter writer = new CSVWriter(outputFile);
String[] header = {"ID", "Tag", "Amount", "Date"};
writer.writeNext(header);
storageManager.saveAllData();
int i = 0;
for (Receipt receipt :storageManager.getWallet().getReceipts()) {
String eachRowOfData = (i + 1) + ". "
+ receipt.getTags().toString().replaceAll(" ", "") + " "
+ receipt.getCashSpent() + " "
+ receipt.getDate();
convertReceiptsToCsv(eachRowOfData,writer);
i++;
}
writer.close();
this.infoCapsule.setCodeCli();
this.infoCapsule.setOutputStr("data.csv has been created ! Please check the project folder \n"
+ userMessageForEnteringExtraFields);
} catch (DukeException | IOException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.getMessage());
}
}

/**
* convertReceiptsToCSV is the method used to change receipts into CSV.
* @param dataTobeAdded String is the row of data which is to be changed to csv
* @param writer CSVWriter is the library used to write to CSV
* @throws DukeException Method throws Duke Exception if unable to write to csv
*/
private void convertReceiptsToCsv(String dataTobeAdded, CSVWriter writer) throws DukeException {
try {
String[] entries = dataTobeAdded.split(" ");
writer.writeNext(entries);
} catch (Exception e) {
throw new DukeException("Unable to write to csv");
}
}

/**
* isThereExtraInputByUser is the method used to check if the user has entered misleading entries.
* @param userInput String is the user input entered in the GUI
* @return false is returned if user enters the correct command for exporting into csv
*/
private boolean isThereExtraInputByUser(String userInput) {
String additionalEntriesOfUser = Parser.parseForPrimaryInput(this.commandType, userInput);
return !additionalEntriesOfUser.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void execute(StorageManager storageManager) {
* @param day is the string input of the current day of the week
* @return is the number value of the day of the week
*/
public int dayStrToInt(String day) {
public static int dayStrToInt(String day) {
switch (day) {
case "monday":
return 1;
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/executor/command/CommandMajorExpense.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package executor.command;

import duke.exception.DukeException;
import interpreter.Parser;
import storage.StorageManager;


public class CommandMajorExpense extends Command {
private String amount;

/**
* Constructor for CommandMajorExpense subCommand Class.
*
* @param userInput The user input from the CLI
*/
public CommandMajorExpense(String userInput) {
super();
this.userInput = userInput;
this.description = "Lists all major expense receipts higher than user cash input \n"
+ "FORMAT : majorexpense <positive integer cash input>"
+ " "
+ "Lists all major expenses above/equal to $100\n"
+ "FORMAT : majorexpense";
this.commandType = CommandType.MAJOREXPENSE;
this.amount = Parser.parseForPrimaryInput(this.commandType, userInput);
}

@Override
public void execute(StorageManager storageManager) {
String outputStr = "These are your receipts above/equal to" + " " + "$" + amount + "\n";
String output = "These are your receipts above/equal to $" + 100 + "\n";
if (amount.startsWith("-")) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Input integer must be positive");
return;
}
if (amount.isEmpty()) {
try {
output += storageManager.getMajorReceipt();
} catch (DukeException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.getMessage());
return;
}
this.infoCapsule.setCodeCli();
this.infoCapsule.setOutputStr(output);
} else {
try {
outputStr += storageManager.getMajorExpense(amount);
} catch (DukeException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.getMessage());
return;
}
this.infoCapsule.setCodeCli();
this.infoCapsule.setOutputStr(outputStr);
}
}
}

5 changes: 5 additions & 0 deletions src/main/java/executor/command/CommandPercent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public void execute(StorageManager storageManager) {
this.infoCapsule.setOutputStr("Tag input is missing. FORMAT : percent <tag>");
return;
}
if (storageManager.getWallet().getReceipts().getPrintableReceipts().isEmpty()) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("No receipts found in the list");
return;
}
try {
Double totalTag = storageManager.getReceiptsByTag(this.tag).getNettCashSpent();
Double totalSpent = storageManager.getWalletExpenses();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/executor/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public enum CommandType {
BLANK(CommandBlank.class),
FIND(CommandFind.class),
DELETE(CommandDelete.class),
RECEIPTDELETE(CommandReceiptDelete.class),
DELETERECEIPT(CommandDeleteReceipt.class),
DONE(CommandMarkDone.class),
MAJOREXPENSE(CommandMajorExpense.class),
QUEUE(CommandQueue.class),
VIEWSCHEDULE(CommandSchedule.class),
REMINDER(CommandReminder.class),
Expand All @@ -18,6 +19,7 @@ public enum CommandType {
OUT(CommandAddSpendingReceipt.class),
SETBALANCE(CommandUpdateBalance.class),
BUDGET(CommandBudget.class),
EXPORT(CommandExport.class),
EXPENSES(CommandDisplayExpenditure.class),
HELP(CommandHelp.class),
DEADLINE(CommandNewTask.class),
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,37 @@ public ReceiptTracker getReceiptsByTag(String tag) throws DukeException {
}
}

/**
* Gets all receipts that have cash spent attribute more than or equal to user input.
* Used by CommandMajorExpense
* @param amount String that represents the user input
* @return ReceiptTracker containing all the major expense receipts
* @throws DukeException Error occurred when getting major expenses
*/
public String getMajorExpense(String amount) throws DukeException {
try {
return this.wallet.getReceipts().getMajorExpenses(amount).getPrintableReceipts();
} catch (NumberFormatException e) {
throw new DukeException("Invalid cash input. Please enter integer");
} catch (Exception e) {
throw new DukeException("Unable to get major expenses");
}
}

/**
* Gets all receipts that have cash spent attribute more than or equal to $100.
* Used by CommandMajorExpense
* @return ReceiptTracker containing all the receipts above or equal to $100
* @throws DukeException Error occurred when getting major expenses
*/
public String getMajorReceipt() throws DukeException {
try {
return this.wallet.getReceipts().getMajorReceipts().getPrintableReceipts();
} catch (Exception e) {
throw new DukeException("Unable to get major receipt");
}
}

/**
* Deletes Task by Index in TaskList Object.
* Used in CommandDelete.
Expand All @@ -183,7 +214,7 @@ public void deleteReceiptByIndex(int index) throws DukeException {
try {
this.wallet.getReceipts().deleteReceiptsByIndex(index);
} catch (Exception e) {
throw new DukeException("Invalid 'receiptdelete' statement. "
throw new DukeException("Invalid 'deletereceipt' statement."
+ "Please indicate the index of the receipt you wish to delete.\n");
}
}
Expand Down
Loading

0 comments on commit be0f7ad

Please sign in to comment.