diff --git a/src/main/java/seedu/address/commons/events/model/SalesHistoryChangedEvent.java b/src/main/java/seedu/address/commons/events/model/SalesHistoryChangedEvent.java index 6fc025603e4a..58490f088cb2 100644 --- a/src/main/java/seedu/address/commons/events/model/SalesHistoryChangedEvent.java +++ b/src/main/java/seedu/address/commons/events/model/SalesHistoryChangedEvent.java @@ -2,7 +2,11 @@ import seedu.address.commons.events.BaseEvent; import seedu.address.model.saleshistory.ReadOnlySalesHistory; +import seedu.address.model.saleshistory.SalesHistory; +/** + * Indicates a change in the {@link SalesHistory} + */ public class SalesHistoryChangedEvent extends BaseEvent { public final ReadOnlySalesHistory data; diff --git a/src/main/java/seedu/address/logic/commands/LoginCommand.java b/src/main/java/seedu/address/logic/commands/LoginCommand.java index e4403bb0164d..c9c8e9baf373 100644 --- a/src/main/java/seedu/address/logic/commands/LoginCommand.java +++ b/src/main/java/seedu/address/logic/commands/LoginCommand.java @@ -37,6 +37,7 @@ public LoginCommand(Username username, Password password) { this.username = username; this.password = password; } + @Override public CommandResult execute(Model model, CommandHistory history) throws CommandException { requireNonNull(username); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index b7f63712aeab..0e1ba200ea6b 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -153,16 +153,15 @@ private void reloadAddressBook(Username username) { } /** - * Updates the sales history and its storage path using the {@code username} provided. - * @param username + * Reloads the sales history */ - private void reloadSalesHistory(Username username) { + private void reloadSalesHistory() { Optional salesHistoryOptional; ReadOnlySalesHistory newSalesHistory; try { salesHistoryOptional = storage.readSalesHistory(); - if(!salesHistoryOptional.isPresent()) { + if (!salesHistoryOptional.isPresent()) { logger.info("Data file not found. Will be starting with an empty SalesHistory"); } newSalesHistory = salesHistoryOptional.orElseGet(SampleDataUtil::getSampleSalesHistory); @@ -272,8 +271,9 @@ public synchronized void addUser(User person) throws DuplicateUserException { public boolean checkAuthentication(Username username, Password password) throws AuthenticatedException { boolean result = versionedUserDatabase.checkAuthentication(username, password); if (hasLoggedIn() && result) { + storage.update(versionedUserDatabase.getUser(username)); reloadAddressBook(username); - reloadSalesHistory(username); + reloadSalesHistory(); reloadDistributorBook(username); } return result; diff --git a/src/main/java/seedu/address/model/ProductDatabase.java b/src/main/java/seedu/address/model/ProductDatabase.java index 0fc2c2a673a5..444aa3531db6 100644 --- a/src/main/java/seedu/address/model/ProductDatabase.java +++ b/src/main/java/seedu/address/model/ProductDatabase.java @@ -2,17 +2,12 @@ import static java.util.Objects.requireNonNull; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javafx.collections.ObservableList; import seedu.address.model.product.Product; import seedu.address.model.product.UniquePersonList; -import seedu.address.model.saleshistory.SalesHistory; -import seedu.address.model.timeidentifiedclass.TimeIdentifiedClass; -import seedu.address.model.timeidentifiedclass.exceptions.InvalidTimeFormatException; /** * Wraps all data at the address-book level diff --git a/src/main/java/seedu/address/model/UserPrefs.java b/src/main/java/seedu/address/model/UserPrefs.java index 80fadfb63df2..bd0122df6411 100644 --- a/src/main/java/seedu/address/model/UserPrefs.java +++ b/src/main/java/seedu/address/model/UserPrefs.java @@ -15,7 +15,7 @@ public class UserPrefs { private Path addressBookFilePath = Paths.get("data" , "addressbook.xml"); private Path distributorBookFilePath = Paths.get("data", "distributorbook.xml"); private Path usersFilePath = Paths.get("data", "users.xml"); - private Path salesHistoryFilePath = Paths.get("data","saleshistory.xml"); + private Path salesHistoryFilePath = Paths.get("data", "saleshistory.xml"); public UserPrefs() { setGuiSettings(750, 500, 0, 0); diff --git a/src/main/java/seedu/address/model/product/Product.java b/src/main/java/seedu/address/model/product/Product.java index a9ae95fd143c..8fd25dbdc445 100755 --- a/src/main/java/seedu/address/model/product/Product.java +++ b/src/main/java/seedu/address/model/product/Product.java @@ -66,7 +66,7 @@ public Set getTags() { * This defines a weaker notion of equality between two persons. */ public boolean isSameProduct(Product otherProduct) { - if (otherProduct.getSerialNumber() == this.getSerialNumber() ) { + if (otherProduct.getSerialNumber() == this.getSerialNumber()) { return true; } diff --git a/src/main/java/seedu/address/model/saleshistory/SalesHistory.java b/src/main/java/seedu/address/model/saleshistory/SalesHistory.java index fbcddc3d5f9d..b98e63c4f62c 100644 --- a/src/main/java/seedu/address/model/saleshistory/SalesHistory.java +++ b/src/main/java/seedu/address/model/saleshistory/SalesHistory.java @@ -10,9 +10,9 @@ import java.util.Set; import java.util.TreeMap; - import javafx.collections.FXCollections; import javafx.collections.ObservableList; + import seedu.address.model.timeidentifiedclass.Reminder; import seedu.address.model.timeidentifiedclass.TimeIdentifiedClass; import seedu.address.model.timeidentifiedclass.Transaction; @@ -72,9 +72,13 @@ public SalesHistory(ReadOnlySalesHistory toBeCopied) { copyReadOnlySalesHistory(toBeCopied); } + /** + * Copies the {@code toBeCopied} to the {@code SalesHistory} + * @param toBeCopied + */ private void copyReadOnlySalesHistory(ReadOnlySalesHistory toBeCopied) { for (Transaction transaction : toBeCopied.getTransactionsAsObservableList()) { - // These exceptions should never be raised. Printing the stack trace will help debugging. + // These exceptions should never be thrown. Printing the stack trace will help debugging. try { addTransaction(transaction); } catch (InvalidTimeFormatException e) { @@ -84,7 +88,7 @@ private void copyReadOnlySalesHistory(ReadOnlySalesHistory toBeCopied) { } } for (Reminder reminder : toBeCopied.getRemindersAsObservableList()) { - // These exceptions should never be raised. Printing the stack trace will help debugging. + // These exceptions should never be thrown. Printing the stack trace will help debugging. try { addReminder(reminder); } catch (InvalidTimeFormatException e) { @@ -186,6 +190,10 @@ public void removeReminder(String reminderTime) throws InvalidTimeFormatExceptio reminderObservableList.remove(toRemove); } + /** + * Resets the {@code SalesHistory} according to a {@code ReadOnlySalesHistory} object + * @param src + */ public void resetData(ReadOnlySalesHistory src) { transactionRecord.clear(); reminderRecord.clear(); diff --git a/src/main/java/seedu/address/model/saleshistory/SalesHistoryManager.java b/src/main/java/seedu/address/model/saleshistory/SalesHistoryManager.java index bfc49f3d3491..5b5e6eb2a1f7 100644 --- a/src/main/java/seedu/address/model/saleshistory/SalesHistoryManager.java +++ b/src/main/java/seedu/address/model/saleshistory/SalesHistoryManager.java @@ -26,9 +26,6 @@ public class SalesHistoryManager extends SalesHistory { */ public SalesHistoryManager(ReadOnlySalesHistory initialState) { super(initialState); - if (getTransactionRecord().size() > 0) { - lastTransaction = getTransactionRecord().lastEntry().getValue(); - } } /** @@ -77,7 +74,7 @@ public String getDaysTransactionsAsString(String day) throws InvalidTimeFormatEx } public Transaction getLastTransaction() { - return lastTransaction; + return getTransactionRecord().lastEntry().getValue(); } /** diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index a02bd3819cde..270d2ef052e6 100755 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -14,10 +14,6 @@ import seedu.address.model.saleshistory.ReadOnlySalesHistory; import seedu.address.model.saleshistory.SalesHistory; import seedu.address.model.tag.Tag; -import seedu.address.model.timeidentifiedclass.Transaction; -import seedu.address.model.timeidentifiedclass.exceptions.ClosedTransactionException; -import seedu.address.model.timeidentifiedclass.exceptions.DuplicateTransactionException; -import seedu.address.model.timeidentifiedclass.exceptions.InvalidTimeFormatException; /** * Contains utility methods for populating {@code ProductDatabase} with sample data. diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 1597ccee03aa..24f10a139107 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -230,17 +230,17 @@ public void saveSalesHistory(ReadOnlySalesHistory salesHistory) throws IOExcepti salesHistoryStorage.saveSalesHistory(salesHistory, salesHistoryStorage.getSalesHistoryFilePath()); } - @Override - public void deleteSalesHistory() throws IOException { - salesHistoryStorage.deleteSalesHistory(); - } - @Override public void saveSalesHistory(ReadOnlySalesHistory salesHistory, Path filePath) throws IOException { logger.fine("Attempting to write to data file: " + filePath); salesHistoryStorage.saveSalesHistory(salesHistory, filePath); } + @Override + public void deleteSalesHistory() throws IOException { + salesHistoryStorage.deleteSalesHistory(); + } + @Override @Subscribe public void handleSalesHistoryChangedEvent(SalesHistoryChangedEvent event) { diff --git a/src/main/java/seedu/address/storage/XmlSalesHistoryStorage.java b/src/main/java/seedu/address/storage/XmlSalesHistoryStorage.java index aad6bf438b02..b7944c9c2f9a 100644 --- a/src/main/java/seedu/address/storage/XmlSalesHistoryStorage.java +++ b/src/main/java/seedu/address/storage/XmlSalesHistoryStorage.java @@ -14,7 +14,11 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.FileUtil; import seedu.address.model.saleshistory.ReadOnlySalesHistory; +import seedu.address.model.saleshistory.SalesHistory; +/** + * A class to access and modify {@link SalesHistory} stored on the hard disk in xml form. + */ public class XmlSalesHistoryStorage implements SalesHistoryStorage { private static Logger logger = LogsCenter.getLogger(XmlSalesHistoryStorage.class);