-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mudaafi <[email protected]>
- Loading branch information
Showing
21 changed files
with
440 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.