Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AY2324S1-CS2113-T17-2/tp
Browse files Browse the repository at this point in the history
…into 291-logging

# Conflicts:
#	src/main/java/seedu/cafectrl/command/AddOrderCommand.java
#	src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
#	src/main/java/seedu/cafectrl/command/ListSaleByDayCommand.java
#	src/main/java/seedu/cafectrl/command/ListTotalSales.java
#	src/main/java/seedu/cafectrl/data/Chef.java
#	src/main/java/seedu/cafectrl/data/Pantry.java
#	src/main/java/seedu/cafectrl/data/Sales.java
#	src/main/java/seedu/cafectrl/parser/Parser.java
  • Loading branch information
ShaniceTang committed Nov 10, 2023
2 parents b4be8fb + 5528731 commit 72c8445
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 229 deletions.
114 changes: 66 additions & 48 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,17 @@ Format: `list_ingredients DISH_INDEX`
Example:
- list followed by list_ingredients 1 lists the ingredients of the 1st dish on the menu
```
chicken salad Ingredients:
pasta - 100g
chicken - 200g
lettuce - 200g
tomatoes - 100g
feta cheese - 20g
-----------------------------------------------------
+-------------------------------------------------------+
|Dish: chicken rice |
+----------------------------------------+--------------+
| Ingredient + Quantity +
+----------------------------------------+--------------+
| rice | 100g |
| chicken | 200g |
| soup | 50ml |
+-------------------------------------------------------+
```


list followed by list_ingredients 1 lists the ingredients of the 1st dish on the menu

<!---@@author ShaniceTang--->
### Deleting a menu item : `delete`
Deletes a specific dish from the menu
Expand Down Expand Up @@ -194,10 +193,16 @@ Format: `view_stock`

Output:
```
You have the following ingredients in pantry:
Ingredients Qty
chicken 500g
milk 1000ml
+-------------------------------------------------------+
| You have the following ingredients in pantry: |
+----------------------------------------+--------------+
| Ingredients | Qty |
+----------------------------------------+--------------+
| chicken | 300g |
| noodles | 2100g |
| rice | 2900g |
| bread | 500g |
+-------------------------------------------------------+
```


Expand All @@ -220,52 +225,65 @@ Ingredient: milk Qty: 1000ml



### Showing all sales : `show_sales`
### Showing all sales : `list_total_sales`
Displays the dishes sold and total sales for each from Day 1 to the current day that
the cafe is operating on.

Format: `show_sales`
Format: list_total_sales

Example: `show_sales`
Example: `list_total_sales`

Output:
- show_sales lists the dishes sold along with the total sales for every operating day of the cafe.
```
+---------------------------------------------------------------------------+
Day 1:
Dish Name Dish Qty Total Cost Price
chicken rice 4 12.0
Total for day: $12.00
+---------------------------------------------------------------------------+
| Day 1: |
+----------------------------------------+--------------+-------------------+
| Dish Name | Dish Qty | Total Cost Price |
+----------------------------------------+--------------+-------------------+
| chicken chop | 3 | 6.00 |
| chicken sandwhich | 7 | 21.00 |
+---------------------------------------------------------------------------+
| Total for day: | $27.00 |
+---------------------------------------------------------------------------+
Day 2:
Dish Name Dish Qty Total Cost Price
chicken chop 5 21.0
chicken rice 3 9.0
Total for day: $30.00
+---------------------------------------------------------------------------+
| Day 2: |
+----------------------------------------+--------------+-------------------+
| Dish Name | Dish Qty | Total Cost Price |
+----------------------------------------+--------------+-------------------+
| chicken chop | 2 | 4.00 |
| chicken sandwhich | 2 | 6.00 |
| chicken noodles | 1 | 2.00 |
+---------------------------------------------------------------------------+
| Total for day: | $12.00 |
+---------------------------------------------------------------------------+
```


### Showing sales for a chosen day : `show_sale`
### Showing sales for a chosen day : `list_sale`
Displays the dishes sold along with the total sales for any chosen day.

Format: `show_sale day/DAY_TO_DISPLAY`
Format: `list_sale day/DAY_TO_DISPLAY`

Example: `show_sale day/1`
Example: `list_sale day/2`

Output:
- show_sale day/1 lists the dishes sold along with the total sales for day 1.
- list_sale day/2 lists the dishes sold along with the total sales for day 2.
```
Day 1:
Dish Name Dish Qty Total Cost Price
chicken rice 4 12.0
Total for day: $12.00
+---------------------------------------------------------------------------+
| Day 2: |
+----------------------------------------+--------------+-------------------+
| Dish Name | Dish Qty | Total Cost Price |
+----------------------------------------+--------------+-------------------+
| chicken chop | 2 | 4.00 |
| chicken sandwhich | 2 | 6.00 |
| chicken noodles | 1 | 2.00 |
+---------------------------------------------------------------------------+
| Total for day: | $12.00 |
+---------------------------------------------------------------------------+
```

<!---@@author Cazh1--->
Expand Down Expand Up @@ -348,14 +366,14 @@ Format: `bye`
|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Add** | `add name/DISH_NAME price/PRICE ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY [, ingredient/INGREDIENT2_NAME qty/INGREDIENT2_QTY, ...]`<br><br/>Example:<br/>`add name/chicken rice price/3.00 ingredient/rice qty/50g, ingredient/chicken qty/100g` |
| **List Menu** | `list_menu` |
| **List Ingredients** | `list_ingredients DISH_INDEX`<br><br/>Example:<br>`list_ingredients 1` |
| **Delete** | `delete DISH_INDEX`<br><br/>Example:<br>`delete 1` |
| **Edit Price** | `edit_price index/DISH_INDEX price/NEW_PRICE`<br><br/>Example:<br>`edit_price index/1 price/4.50` |
| **Show Sale** | `show_sales` |
| **Show Sale by Day** | `show_sale day/DAY_TO_DISPLAY` <br><br/>Example:<br>`show_sale day/ 1` |
| **List Ingredients** | `list_ingredients DISH_INDEX`<br><br/>Example:<br>`list_ingredients 1` |
| **Delete** | `delete DISH_INDEX`<br><br/>Example:<br>`delete 1` |
| **Edit Price** | `edit_price index/DISH_INDEX price/NEW_PRICE`<br><br/>Example:<br>`edit_price index/1 price/4.50` |
| **List Sale** | `list_total_sales` |
| **List Sale by Day** | `list_sale day/DAY_TO_DISPLAY` <br><br/>Example:<br>`list_sale day/ 1` |
| **View Ingredient Stock** | `view_stock` |
| **Buy Ingredients** | `buy_ingredient ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY[, ingredient/INGREDIENT2_NAME qty/INGREDIENT2_QTY, ...]`<br><br/>Example<br>`buy_ingredient ingredient/chicken qty/500g, ingredient/milk qty/1000ml` |
| **Add Order** | `add_order name/DISH_NAME qty/QUANTITY`<br><br/>Example:<br>`add_order name/chicken rice qty/2` |
| **Buy Ingredients** | `buy_ingredient ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY[, ingredient/INGREDIENT2_NAME qty/INGREDIENT2_QTY, ...]`<br><br/>Example<br>`buy_ingredient ingredient/chicken qty/500g, ingredient/milk qty/1000ml` |
| **Add Order** | `add_order name/DISH_NAME qty/QUANTITY`<br><br/>Example:<br>`add_order name/chicken rice qty/2` |
| **Previous Day** | `previous_day` |
| **Next Day** | `next_day` |
| **Help** | `help` |
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/seedu/cafectrl/command/AddOrderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.Chef;

import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;

import java.util.logging.Logger;
import java.text.DecimalFormat;

public class AddOrderCommand extends Command {
public static final String COMMAND_WORD = "add_order";
Expand All @@ -25,6 +28,7 @@ public class AddOrderCommand extends Command {
private final Ui ui;
private final Order order;
private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());
private final DecimalFormat dollarValue = new DecimalFormat("0.00");

public AddOrderCommand(Order order, Ui ui, Pantry pantry, OrderList orderList, Menu menu) {
this.order = order;
Expand All @@ -37,11 +41,20 @@ public AddOrderCommand(Order order, Ui ui, Pantry pantry, OrderList orderList, M
public void execute() {
logger.info("Executing AddOrderCommand...");
orderList.addOrder(order);
Chef chef = new Chef(order, pantry, ui, menu);
Chef chef = new Chef(order, pantry, ui);
chef.cookDish();
if (order.getIsComplete()) {
orderList.addCost(order);
String totalCost = dollarValue.format(order.getTotalOrderCost());
ui.showOrderStatus(Messages.COMPLETE_ORDER, totalCost);
pantry.calculateDishAvailability(menu, order);
} else {
//pass in dish only and not entire menu
Dish orderedDish = order.getOrderedDish();
pantry.calculateMaxDishes(orderedDish, menu, order);
ui.showToUser(Messages.INCOMPLETE_ORDER);
}

}

}
13 changes: 11 additions & 2 deletions src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.ErrorMessages;
import seedu.cafectrl.ui.Ui;

Expand Down Expand Up @@ -34,10 +35,18 @@ public void execute() {
logger.info("Executing ListIngredientCommand...");
try {
Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
ui.printIngredients(selectedDish);
ui.showIngredientsHeader(selectedDish);

for (Ingredient ingredient : selectedDish.getIngredients()) {
ui.formatListIngredient(ingredient.getName(),
ingredient.getQty()+ingredient.getUnit());
}

ui.showIngredientsEndCap();
} catch (IndexOutOfBoundsException e) {
logger.log(Level.WARNING, "ListIngredientCommand unsuccessful: " + e.getMessage(), e);
throw new IllegalArgumentException(ErrorMessages.INVALID_DISH_INDEX);
throw new IllegalArgumentException(ErrorMessages.UNLISTED_DISH);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.Sales;
import seedu.cafectrl.ui.ErrorMessages;
import seedu.cafectrl.ui.Ui;

import java.util.logging.Logger;

//@@author NaychiMin
public class ShowSalesByDayCommand extends Command {
public static final String COMMAND_WORD = "show_sale";
public class ListSaleByDayCommand extends Command {
public static final String COMMAND_WORD = "list_sale";
public static final String MESSAGE_USAGE = "To show sales for a chosen day:\n"
+ COMMAND_WORD + " day/DAY_TO_DISPLAY\n"
+ "Example: " + COMMAND_WORD + " day/1";
Expand All @@ -20,7 +21,7 @@ public class ShowSalesByDayCommand extends Command {
private final Menu menu;
private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());

public ShowSalesByDayCommand(int day, Ui ui, Sales sales, Menu menu) {
public ListSaleByDayCommand(int day, Ui ui, Sales sales, Menu menu) {
this.day = day;
this.ui = ui;
this.sales = sales;
Expand All @@ -29,7 +30,11 @@ public ShowSalesByDayCommand(int day, Ui ui, Sales sales, Menu menu) {

@Override
public void execute() {
logger.info("Excecuting ShowSalesByDayCommand...");
sales.printSaleByDay(ui, menu, day);
logger.info("Executing ShowSalesByDayCommand...");
try {
sales.printSaleByDay(ui, menu, day);
} catch (Exception e) {
ui.showToUser(ErrorMessages.INVALID_SALE_DAY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import java.util.logging.Logger;

public class ShowSalesCommand extends Command {
public static final String COMMAND_WORD = "show_sales";
public class ListTotalSales extends Command {
public static final String COMMAND_WORD = "list_total_sales";
public static final String MESSAGE_USAGE = "To show sales for all days:\n" + COMMAND_WORD;
private Sales sales;
private Ui ui;
private Menu menu;
private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());

public ShowSalesCommand(Sales sales, Ui ui, Menu menu) {
public ListTotalSales(Sales sales, Ui ui, Menu menu) {
this.sales = sales;
this.ui = ui;
this.menu = menu;
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/seedu/cafectrl/data/Chef.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package seedu.cafectrl.data;

import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;

import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Chef {
private final Order order;
private final Pantry pantry;
Expand All @@ -16,11 +16,11 @@ public class Chef {
private final DecimalFormat dollarValue = new DecimalFormat("0.00");
private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());

public Chef(Order order, Pantry pantry, Ui ui, Menu menu) {

public Chef(Order order, Pantry pantry, Ui ui) {
this.order = order;
this.pantry = pantry;
this.ui = ui;
this.menu = menu;
}

public void cookDish() {
Expand All @@ -32,10 +32,6 @@ public void cookDish() {
logger.info("Dish cooked: " + isComplete);
order.setComplete(isComplete);
}
String orderStatus = order.getIsComplete() ? Messages.COMPLETE_ORDER : Messages.INCOMPLETE_ORDER;
String totalCost = dollarValue.format(order.getTotalOrderCost());
ui.showOrderStatus(orderStatus, totalCost);
pantry.calculateDishAvailability(menu);
} catch (Exception e) {
logger.log(Level.WARNING, "Unsuccessful order: " + e.getMessage(), e);
ui.showToUser(e.getMessage());
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/cafectrl/data/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public String toString() {
*
* @return Total calculated cost
*/

public float calculateTotalOrderCost() {
float dishCost = orderedDish.getPrice();
return dishCost * dishQty;
Expand Down Expand Up @@ -96,4 +95,8 @@ public void setQuantity(int quantity) {
public void setTotalOrderCost(float cost) {
this.totalOrderCost = cost;
}
public Dish getOrderedDish() {
return orderedDish;
}

}
22 changes: 17 additions & 5 deletions src/main/java/seedu/cafectrl/data/OrderList.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public void addCost(Order order) {
public void printOrderList(Menu menu, Ui ui) {
logger.info("Printing order list...");
ArrayList<Order> aggregatedOrders = menu.getAggregatedOrders();
if (orderList.isEmpty()) {
ui.showToUser("No sales for this day.");
return;
}

for (Order order : getOrderList()) {
for (Order order : orderList) {
aggregateOrder(order, aggregatedOrders);
}

for (Order aggregatedOrder : aggregatedOrders) {
if (aggregatedOrder.getQuantity() == 0) {
continue;
}

ui.showSalesAll(aggregatedOrder.getDishName(),
aggregatedOrder.getQuantity(),
dollarValue.format(aggregatedOrder.calculateTotalOrderCost()));
Expand Down Expand Up @@ -121,4 +121,16 @@ private float calculateTotalCost(ArrayList<Order> orders) {
}
return totalCost;
}
public boolean isEmpty() {
return orderList.isEmpty();
}

public boolean hasCompletedOrders() {
for (Order order : orderList) {
if (order.getIsComplete()) {
return true;
}
}
return false;
}
}
Loading

0 comments on commit 72c8445

Please sign in to comment.