mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add invoice for customer
This commit is contained in:
parent
cc05fb2e2e
commit
e4d23d8e81
|
@ -45,6 +45,7 @@ package catering.order {
|
|||
+ checkout(userAccount : UserAccount, model : Model) : String
|
||||
+ getOrders(model : Model) : String
|
||||
+ removeOrder(order : Order) : boolean
|
||||
+ invoice(model : Model, userAccount : UserAccount, order : Order) : String
|
||||
}
|
||||
|
||||
class ProductForm
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.time.LocalDate;
|
|||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
|
@ -316,4 +317,20 @@ public class OrderController {
|
|||
model.addAttribute("dayNames", dayNames);
|
||||
return "orders_calender";
|
||||
}
|
||||
|
||||
@GetMapping("/myOrders/{order}/invoice")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public String invoice(Model model, @LoggedIn UserAccount userAccount, @PathVariable Order order){
|
||||
if(!order.getUserAccountIdentifier().equals(userAccount.getId()) &&
|
||||
!userAccount.hasRole(Role.of("ADMIN"))){
|
||||
return "redirect:/unauthorized";
|
||||
}
|
||||
|
||||
model.addAttribute("order", order);
|
||||
model.addAttribute("staffCharges", order.getChargeLines().stream()
|
||||
.collect(Collectors.toMap(Function.identity(),
|
||||
cl -> staffManagement.findById(Long.parseLong(cl.getDescription())).get())));
|
||||
|
||||
return "invoice";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,3 +24,9 @@
|
|||
transition-property: scale;
|
||||
transition-timing-function: ease;
|
||||
}
|
||||
|
||||
@media print {
|
||||
.container {
|
||||
max-width: revert;
|
||||
}
|
||||
}
|
||||
|
|
49
src/main/resources/templates/invoice.html
Normal file
49
src/main/resources/templates/invoice.html
Normal file
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{layout.html(title='Rechnung')}">
|
||||
<body>
|
||||
<div layout:fragment="content" class="invoice">
|
||||
<div>
|
||||
<h3 class="mb-2">Eventtyp</h3>
|
||||
<p th:text="${order.getOrderType().toHumanReadable()}"></p>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="mb-2">Dauer</h3>
|
||||
<p th:text="'Von: ' + ${order.getFormattedStart()}"></p>
|
||||
<p th:text="'Bis: ' + ${order.getFormattedFinish()}"></p>
|
||||
</div>
|
||||
<h3>Produkte</h3>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Beschreibung</th>
|
||||
<th scope="col">Einzelpreis/Basispreis</th>
|
||||
<th scope="col">Menge</th>
|
||||
<th scope="col">Gesamtpreis</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-group-divider">
|
||||
<tr th:each="orderLine : ${order.getOrderLines()}">
|
||||
<td th:text="${orderLine.getProductName()}"></td>
|
||||
<td th:text="${orderLine.getPrice().getNumber().doubleValueExact() + ' €'}"></td>
|
||||
<td th:text="${orderLine.getQuantity()}"></td>
|
||||
<td th:text="${orderLine.getPrice().multiply(orderLine.getQuantity().getAmount()).getNumber().doubleValueExact() + order.getChargeLines(orderLine).getTotal().getNumber().doubleValueExact() + ' €'}"></td>
|
||||
</tr>
|
||||
<tr th:each="chargeLine : ${order.getChargeLines()}">
|
||||
<td th:text="${staffCharges.get(chargeLine).getName()}"></td>
|
||||
<td th:text="${chargeLine.getPrice().getNumber().doubleValueExact() + ' €'}"></td>
|
||||
<td>1</td>
|
||||
<td th:text="${chargeLine.getPrice().getNumber().doubleValueExact() + ' €'}"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="text-end">
|
||||
<h3>Gesamtpreis</h3>
|
||||
<p th:text="${order.getTotal().getNumber().doubleValue() + ' €'}"></p>
|
||||
</div>
|
||||
<button class="btn btn-primary d-print-none" onclick="print()">Drucken</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -7,10 +7,10 @@
|
|||
<nav th:fragment="navigation" class="navbar navbar-expand-lg bg-body-secondary">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" th:href="@{/}">Catering Mampf</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<button class="navbar-toggler d-print-none" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<div class="collapse navbar-collapse d-print-none" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" th:href="@{/inventory}" sec:authorize="hasRole('ADMIN')">Inventar</a>
|
||||
|
|
|
@ -41,11 +41,8 @@
|
|||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div th:if="${order.isInvoiceAvailable()}">
|
||||
<a href="#invoice">Rechnung</a>
|
||||
</div>
|
||||
<div th:unless="${order.isInvoiceAvailable()}">
|
||||
<span>Keine Rechnung verfügbar</span>
|
||||
<div>
|
||||
<a th:href="@{/myOrders/{id}/invoice(id=${order.id})}">Rechnung</a>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
|
Loading…
Reference in a new issue