diff --git a/src/main/java/seedu/cafectrl/data/OrderList.java b/src/main/java/seedu/cafectrl/data/OrderList.java index 73879ef836..91b357cfb9 100644 --- a/src/main/java/seedu/cafectrl/data/OrderList.java +++ b/src/main/java/seedu/cafectrl/data/OrderList.java @@ -63,7 +63,7 @@ public void printOrderList(Menu menu, Ui ui) { ui.showSalesAll(aggregatedOrder.getDishName(), aggregatedOrder.getQuantity(), - dollarValue.format(aggregatedOrder.calculateTotalOrderCost())); + dollarValue.format(calculateTotalCost(aggregatedOrders))); } ui.showSalesBottom(); @@ -80,10 +80,10 @@ private void aggregateOrder(Order order, ArrayList aggregatedOrders) { logger.info("Aggregating order..."); if (order.getIsComplete()) { int index = getIndexByDishName(aggregatedOrders, order.getDishName()); - aggregatedOrders.get(index).setQuantity(aggregatedOrders.get(index).getQuantity() - + order.getQuantity()); - aggregatedOrders.get(index).setTotalOrderCost(aggregatedOrders.get(index).getTotalOrderCost() - + order.getTotalOrderCost()); + aggregatedOrders.get(index) + .setQuantity(aggregatedOrders.get(index).getQuantity() + order.getQuantity()); + aggregatedOrders.get(index) + .setTotalOrderCost(aggregatedOrders.get(index).getTotalOrderCost() + order.getTotalOrderCost()); } } diff --git a/src/main/java/seedu/cafectrl/data/dish/Dish.java b/src/main/java/seedu/cafectrl/data/dish/Dish.java index a110716517..0495d8d0ba 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Dish.java +++ b/src/main/java/seedu/cafectrl/data/dish/Dish.java @@ -16,7 +16,7 @@ public Dish(String name, ArrayList ingredients, float price) { } public Dish(String name, float price) { this.name = name; - this.ingredients = null; + this.ingredients = new ArrayList<>(); this.price = price; } diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 370fed6eec..4d74f6bb6b 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -205,24 +205,27 @@ private static void decodeSalesData(String orderLine, ArrayList order //@@author int quantity = Integer.parseInt(orderData[2].trim()); - float decodedTotalOrderCost = Float.parseFloat(orderData[3].trim()); - String completeStatus = orderData[4].trim(); + float decodedDishPrice = Float.parseFloat(orderData[3].trim()); + float decodedTotalOrderCost = Float.parseFloat(orderData[4].trim()); + String completeStatus = orderData[5].trim(); Dish dish = menu.getDishFromName(dishName); boolean isDataAccurate = isDishValid(orderLine, dish) - && isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost) + && isOrderCostAccurate(orderLine, quantity, decodedDishPrice, decodedTotalOrderCost) && isCompleteStatusAccurate(orderLine, completeStatus); if (!isDataAccurate) { return; } + Dish dishToAdd = new Dish(dishName, decodedDishPrice); //creates new order and adds to orderList for specific day boolean isComplete = Boolean.parseBoolean(completeStatus.toLowerCase()); - Order orderedDish = new Order(menu.getDishFromName(dishName), quantity, decodedTotalOrderCost, isComplete); + Order orderedDish = new Order(dishToAdd, quantity, decodedTotalOrderCost, isComplete); fillOrderListSize(orderLists, day); orderLists.get(day).addOrder(orderedDish); } catch (Exception e) { logger.log(Level.WARNING, "Line corrupted: " + e.getMessage(), e); + System.out.println(e.getMessage()); ui.showToUser(ErrorMessages.INVALID_SALES_DATA + orderLine); } } @@ -251,10 +254,9 @@ private static boolean isDishValid(String orderLine, Dish dish) { * @param decodedTotalOrderCost The decoded total order cost from the order line. * @return True if the decoded total order cost matches the expected total order cost, false otherwise. */ - private static boolean isOrderCostAccurate(String orderLine, Dish dish, - int quantity, float decodedTotalOrderCost) { - float costOfDish = dish.getPrice(); - float expectedTotalOrderCost = quantity * costOfDish; + private static boolean isOrderCostAccurate(String orderLine, int quantity, + float decodedDishPrice, float decodedTotalOrderCost) { + float expectedTotalOrderCost = quantity * decodedDishPrice; if (decodedTotalOrderCost == expectedTotalOrderCost) { return true; } diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index d8b11e2de8..59d4d33030 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -135,6 +135,7 @@ public static ArrayList encodeSales(Sales sales) { orderString.append((day + 1) + DIVIDER); orderString.append(order.getDishName() + DIVIDER); orderString.append(order.getQuantity() + DIVIDER); + orderString.append(order.getOrderedDish().getPrice() + DIVIDER); orderString.append(order.calculateTotalOrderCost() + DIVIDER); orderString.append(order.getIsComplete()); orderString.append(System.lineSeparator()); diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index a0c0f000fa..e04a439a6d 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -79,7 +79,8 @@ public class ErrorMessages { public static final String INVALID_MENU_DATA = "menu.txt: Invalid format, this dish will be removed -> "; public static final String INVALID_SALES_DATA = "orders.txt: Invalid format, this order will be removed -> "; - public static final String INVALID_ORDER_DATA = "orders.txt: Invalid dish, this order will be removed -> "; + public static final String INVALID_ORDER_DATA = "orders.txt: Dish is not in current menu, " + + "this order will be removed -> "; public static final String INVALID_ORDER_STATUS = "orders.txt: Invalid status, this order will be removed -> "; public static final String INACCURATE_ORDER_COST_DATA = "orders.txt: The total order cost of this order -> \"%s\" " + "is inaccurate and will hence be updated from %.2f to %.2f instead.";