Add orderRepositoryIterator in orders.html

This commit is contained in:
Mathis Kral 2023-11-05 15:36:46 +01:00 committed by Simon Bruder
parent e6535ab767
commit a6faa677dd
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
5 changed files with 40 additions and 32 deletions

View file

@ -4,6 +4,7 @@ import org.aspectj.weaver.ast.Or;
import org.salespointframework.quantity.Quantity; import org.salespointframework.quantity.Quantity;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.Map;
/** /**
@ -17,6 +18,7 @@ public class CustomOrder {
private Map<String, Quantity> products; private Map<String, Quantity> products;
private boolean invoiceAvailable; private boolean invoiceAvailable;
private double totalCost; // this is in private double totalCost; // this is in
private DateTimeFormatter formatter;
public CustomOrder(OrderType orderType, LocalDateTime start, LocalDateTime finish, Map<String, Quantity> products, boolean invoiceAvailable, double totalCost) { public CustomOrder(OrderType orderType, LocalDateTime start, LocalDateTime finish, Map<String, Quantity> products, boolean invoiceAvailable, double totalCost) {
this.orderType = orderType; this.orderType = orderType;
@ -25,6 +27,7 @@ public class CustomOrder {
this.products = products; this.products = products;
this.invoiceAvailable = invoiceAvailable; this.invoiceAvailable = invoiceAvailable;
this.totalCost = totalCost; this.totalCost = totalCost;
this.formatter = DateTimeFormatter.ofPattern("MM.dd.yyy, HH:mm 'Uhr'");
} }
public OrderType getOrderType() { public OrderType getOrderType() {
@ -35,15 +38,23 @@ public class CustomOrder {
return start; return start;
} }
public String getFormattedStart() {
return start.format(formatter);
}
public LocalDateTime getFinish() { public LocalDateTime getFinish() {
return finish; return finish;
} }
public String getFormattedFinish() {
return finish.format(formatter);
}
public Map<String, Quantity> getProducts() { public Map<String, Quantity> getProducts() {
return products; return products;
} }
public boolean isInvoiceAvailable() { public boolean invoiceAvailable() {
return invoiceAvailable; return invoiceAvailable;
} }

View file

@ -28,7 +28,7 @@ public class CustomOrderDataInitializer implements DataInitializer {
LocalDateTime.of(2023, 12, 5, 18, 0), LocalDateTime.of(2023, 12, 5, 18, 0),
LocalDateTime.of(2023, 12, 5, 23, 0), LocalDateTime.of(2023, 12, 5, 23, 0),
products, products,
true, false,
2000.0 2000.0
)); ));
@ -38,7 +38,7 @@ public class CustomOrderDataInitializer implements DataInitializer {
products.put("Käseplatte", Quantity.of(1000)); products.put("Käseplatte", Quantity.of(1000));
products.put("Wiener Würstchen", Quantity.of(150)); products.put("Wiener Würstchen", Quantity.of(150));
orderRepository.addOrder(new CustomOrder( orderRepository.addOrder(new CustomOrder(
CustomOrder.OrderType.SUSHI_NIGHT, CustomOrder.OrderType.EVENT_CATERING,
LocalDateTime.of(2023, 10, 2, 11, 0), LocalDateTime.of(2023, 10, 2, 11, 0),
LocalDateTime.of(2023, 10, 3, 8, 0), LocalDateTime.of(2023, 10, 3, 8, 0),
products, products,

View file

@ -2,6 +2,7 @@ package catering.order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -26,6 +27,6 @@ public class CustomOrderRepository {
} }
public Collection<CustomOrder> getOrders() { public Collection<CustomOrder> getOrders() {
return this.orders; return new ArrayList<>(this.orders);
} }
} }

View file

@ -4,6 +4,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import java.util.ArrayList;
@Controller @Controller
public class OrderController { public class OrderController {
@ -15,6 +17,7 @@ public class OrderController {
@GetMapping("/orders") @GetMapping("/orders")
public String orders(Model model) { public String orders(Model model) {
model.addAttribute("orders", orderRepository.getOrders());
model.addAttribute("total", orderRepository.getOrders().size()); model.addAttribute("total", orderRepository.getOrders().size());
return "orders"; return "orders";
} }

View file

@ -16,7 +16,7 @@
</div> </div>
<div> <div>
<h1>Auftragsliste</h1> <h1>Auftragsliste</h1>
</div> </div>
<div> <!--th:unless"${cart.empty}"--> <div> <!--th:unless"${cart.empty}"-->
@ -25,56 +25,49 @@
<th>Von</th> <th>Von</th>
<th>Bis</th> <th>Bis</th>
<th>Kunde</th> <th>Kunde</th>
<th>Produkt</th> <th>Produktdetails</th>
<th>Rechnung</th> <th>Rechnung</th>
<th>Bezahlt</th> <th>Bezahlt</th>
<th>Preis</th> <th>Preis</th>
<th></th> <th></th>
</tr> </tr>
<tr> <!--später th:each="cart.products"--> <tr th:each="order : ${orders}"> <!--später th:each="cart.products"-->
<td>01.10.2024 0:00Uhr</td> <td th:text="${order.getFormattedStart()}">
<td>30.10.2023 23:59Uhr</td> <td th:text="${order.getFormattedFinish()}">
<td>Hans Käse</td> <td th:text="BeispielKunde"/>
<td> <td>
<a href="#productDetails">Mobile Breakfast</a> <a href="#productDetails" th:text="${order.getOrderType()}"/>
</td> </td>
<td> <td>
noch keine Rechnung verfügbar <!--th:if="product.hasBill"--> <div th:if="${order.invoiceAvailable()}">
<a href="#invoice">Rechnung</a>
</div>
<div th:unless="${order.invoiceAvailable()}">
<span>Keine Rechnung verfügbar</span>
</div>
</td> </td>
<td>&#9746</td> <!--von Admin bearbeitbar--> <td>&#9746</td> <!--von Admin bearbeitbar-->
<td>10550,99€</td> <td>
<th:block th:text="${order.getTotalCost()}"/>
<th:block th:text="€"/>
</td>
<td> <!--th:if="product.isRemovable"--> <td> <!--th:if="product.isRemovable"-->
<button type="button">Entfernen</button> <button type="button">Entfernen</button>
</td> </td>
</tr> </tr>
<tr>
<td>24.11.2023 10:00Uhr</td>
<td>24.11.2023 15:00Uhr</td>
<td>Hans Käse</td>
<td>
<a href="#productDetails">Rent-a-Cook</a>
</td>
<td>
<a href="#bill">Rechnung</a> <!--th:if="product.hasBill"-->
</td>
<td>&#9745</td>
<td>350,99</td>
<td> <!--th:if="product.isRemovable"-->
<button type="button">Entfernen</button>
</td>
</tr>
</table> </table>
</div> </div>
<span> <span>
<th:block th:text="Total:"/> <th:block th:text="Insgesamt "/>
<th:block th:text="${total}"/> <th:block th:text="${total}"/>
<th:block th:text=" Aufträge"/>
</span> </span>
</body> </body>
<footer style="bottom: 0; position: absolute;"> <footer style="bottom: 0; position: absolute;">
<p>© Hannes Wurst @ Mampf GmbH</p> <p>© Hannes Wurst @ Mampf GmbH</p>
<p> <p>
<a href="mailto:catering@mampf.com">catering@mampf.com</a> <a href="mailto:catering@mampf.com">catering@mampf.com</a>
</p> </p>
</footer> </footer>