Add invoice for customer

This commit is contained in:
Paul Heimer 2023-11-28 20:40:43 +01:00 committed by Simon Bruder
parent cc05fb2e2e
commit e4d23d8e81
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
6 changed files with 77 additions and 7 deletions

View file

@ -45,6 +45,7 @@ package catering.order {
+ checkout(userAccount : UserAccount, model : Model) : String + checkout(userAccount : UserAccount, model : Model) : String
+ getOrders(model : Model) : String + getOrders(model : Model) : String
+ removeOrder(order : Order) : boolean + removeOrder(order : Order) : boolean
+ invoice(model : Model, userAccount : UserAccount, order : Order) : String
} }
class ProductForm class ProductForm

View file

@ -24,6 +24,7 @@ import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -316,4 +317,20 @@ public class OrderController {
model.addAttribute("dayNames", dayNames); model.addAttribute("dayNames", dayNames);
return "orders_calender"; 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";
}
} }

View file

@ -24,3 +24,9 @@
transition-property: scale; transition-property: scale;
transition-timing-function: ease; transition-timing-function: ease;
} }
@media print {
.container {
max-width: revert;
}
}

View 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>

View file

@ -7,10 +7,10 @@
<nav th:fragment="navigation" class="navbar navbar-expand-lg bg-body-secondary"> <nav th:fragment="navigation" class="navbar navbar-expand-lg bg-body-secondary">
<div class="container"> <div class="container">
<a class="navbar-brand" th:href="@{/}">Catering Mampf</a> <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> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <div class="collapse navbar-collapse d-print-none" id="navbarSupportedContent">
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" th:href="@{/inventory}" sec:authorize="hasRole('ADMIN')">Inventar</a> <a class="nav-link" th:href="@{/inventory}" sec:authorize="hasRole('ADMIN')">Inventar</a>

View file

@ -41,11 +41,8 @@
</div> </div>
</td> </td>
<td> <td>
<div th:if="${order.isInvoiceAvailable()}"> <div>
<a href="#invoice">Rechnung</a> <a th:href="@{/myOrders/{id}/invoice(id=${order.id})}">Rechnung</a>
</div>
<div th:unless="${order.isInvoiceAvailable()}">
<span>Keine Rechnung verfügbar</span>
</div> </div>
</td> </td>
<td> <td>