Skip to content

Commit

Permalink
Merge pull request #296 from NaychiMin/255-printing-of-dish-availabil…
Browse files Browse the repository at this point in the history
…ity-V2.1

Fixing bugs found in PED
  • Loading branch information
Cazh1 authored Nov 9, 2023
2 parents c4579d6 + e263e79 commit 5528731
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 232 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
16 changes: 15 additions & 1 deletion src/main/java/seedu/cafectrl/command/AddOrderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,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.text.DecimalFormat;

public class AddOrderCommand extends Command {
public static final String COMMAND_WORD = "add_order";
public static final String MESSAGE_USAGE = "To add a new order: \n"
Expand All @@ -21,6 +25,7 @@ public class AddOrderCommand extends Command {
protected Menu menu;
private final Ui ui;
private final Order order;
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 @@ -32,11 +37,20 @@ public AddOrderCommand(Order order, Ui ui, Pantry pantry, OrderList orderList, M
@Override
public void execute() {
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 @@ -2,6 +2,7 @@

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 All @@ -28,9 +29,17 @@ public ListIngredientCommand(int listIndex, Menu menu, Ui ui) {
public void execute() {
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) {
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 @@ -2,11 +2,12 @@

import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.Sales;
import seedu.cafectrl.ui.ErrorMessages;
import seedu.cafectrl.ui.Ui;

//@@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 @@ -16,7 +17,7 @@ public class ShowSalesByDayCommand extends Command {
private final Sales sales;
private final Menu menu;

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 @@ -25,6 +26,11 @@ public ShowSalesByDayCommand(int day, Ui ui, Sales sales, Menu menu) {

@Override
public void execute() {
sales.printSaleByDay(ui, menu, day);
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 @@ -4,14 +4,14 @@
import seedu.cafectrl.data.Sales;
import seedu.cafectrl.ui.Ui;

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;

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
14 changes: 2 additions & 12 deletions src/main/java/seedu/cafectrl/data/Chef.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package seedu.cafectrl.data;

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

import java.text.DecimalFormat;

public class Chef {
private final Order order;
private final Pantry pantry;
private final Ui ui;
private Menu menu;
private final DecimalFormat dollarValue = new DecimalFormat("0.00");

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 @@ -26,10 +20,6 @@ public void cookDish() {
boolean isComplete = pantry.isDishCooked(order.getIngredientList());
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) {
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 @@ -47,16 +47,16 @@ public void addCost(Order order) {
*/
public void printOrderList(Menu menu, Ui ui) {
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 @@ -114,4 +114,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 5528731

Please sign in to comment.