mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Bind inventory mutate form to template
Co-authored-by: Paul Heimer <heimerp54@gmail.com>
This commit is contained in:
parent
695bc1d821
commit
6bd1c23e2d
|
@ -17,6 +17,12 @@
|
||||||
package catering.inventory;
|
package catering.inventory;
|
||||||
|
|
||||||
import static org.salespointframework.core.Currencies.EURO;
|
import static org.salespointframework.core.Currencies.EURO;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import javax.money.MonetaryAmount;
|
||||||
|
import javax.money.NumberValue;
|
||||||
|
|
||||||
import org.javamoney.moneta.Money;
|
import org.javamoney.moneta.Money;
|
||||||
import org.salespointframework.catalog.Product;
|
import org.salespointframework.catalog.Product;
|
||||||
import org.salespointframework.inventory.UniqueInventory;
|
import org.salespointframework.inventory.UniqueInventory;
|
||||||
|
@ -57,8 +63,22 @@ class InventoryController {
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
@GetMapping("/inventory/edit/{pid}")
|
@GetMapping("/inventory/edit/{pid}")
|
||||||
String edit(Model model, @PathVariable Product pid) {
|
String edit(Model model, @PathVariable Product pid) {
|
||||||
model.addAttribute("product", pid);
|
CatalogDummy product = (CatalogDummy) pid;
|
||||||
model.addAttribute("item", inventory.findByProduct(pid).get());
|
UniqueInventoryItem item = inventory.findByProduct(pid).get();
|
||||||
|
return edit(model, pid,
|
||||||
|
new InventoryMutateForm(product.getType(),
|
||||||
|
product.getName(),
|
||||||
|
item.getQuantity(),
|
||||||
|
product.getWholesalePrice().getNumber().doubleValueExact(),
|
||||||
|
product.getPrice().getNumber().doubleValueExact(),
|
||||||
|
Optional.ofNullable(product.getPromotionPrice())
|
||||||
|
.map(MonetaryAmount::getNumber)
|
||||||
|
.map(NumberValue::doubleValueExact)));
|
||||||
|
}
|
||||||
|
|
||||||
|
String edit(Model model, @PathVariable Product pid, InventoryMutateForm form) {
|
||||||
|
model.addAttribute("actionIsAdd", false);
|
||||||
|
model.addAttribute("form", form);
|
||||||
|
|
||||||
return "inventory-mutate";
|
return "inventory-mutate";
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,37 +5,37 @@
|
||||||
layout:decorate="~{layout.html(title='Lagerverwaltung')}">
|
layout:decorate="~{layout.html(title='Lagerverwaltung')}">
|
||||||
<body>
|
<body>
|
||||||
<div layout:fragment="content">
|
<div layout:fragment="content">
|
||||||
<h2 th:text="${'Produkt ' + (product == null ? 'anlegen' : 'bearbeiten')}"></h2>
|
<h2 th:text="${'Produkt ' + (actionIsAdd ? 'anlegen' : 'bearbeiten')}"></h2>
|
||||||
<!-- TODO: maybe migrate to th:field (which is a pain) -->
|
<form method="post" th:object="${form}">
|
||||||
<form method="post">
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="type">Typ</label>
|
<label class="form-label" for="type">Typ</label>
|
||||||
<div class="form-check form-check-inline" th:each="type : ${T(catering.catalog.CatalogDummyType).values()}">
|
<div class="form-check form-check-inline" th:each="type : ${T(catering.catalog.CatalogDummyType).values()}">
|
||||||
<input class="form-check-input" type="radio" name="type" th:value="${type}" th:text="${type}" th:checked="${type.name() == product?.type?.name()}" required/>
|
<input class="form-check-input" type="radio" th:field="*{type}" th:value="${type}" th:text="${type}" required/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="name">Produktname</label>
|
<label class="form-label" for="name">Produktname</label>
|
||||||
<input class="form-control" type="text" name="name" th:value="${product?.name}" required/>
|
<input class="form-control" type="text" th:field="*{name}" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="quantity">Menge im Bestand</label>
|
<label class="form-label" for="quantity">Menge im Bestand</label>
|
||||||
<input class="form-control" type="number" name="quantity" th:value="${item?.quantity}" required/>
|
<input class="form-control" type="number" th:field="*{quantity}" required/>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- the prices aren’t bound with th:field as they need special formatting -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="wholesalePrice">Einkaufspreis</label>
|
<label class="form-label" for="wholesalePrice">Einkaufspreis</label>
|
||||||
<input class="form-control" type="number" name="wholesalePrice" step="0.01" min="0" th:value="${#numbers.formatDecimal(product?.wholesalePrice?.getNumber()?.doubleValueExact(), 1, 2)}" required/>
|
<input class="form-control" type="number" th:field="*{wholesalePrice}" step="0.01" min="0" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="retailPrice">UVP</label>
|
<label class="form-label" for="retailPrice">UVP</label>
|
||||||
<input class="form-control" type="number" name="retailPrice" step="0.01" min="0" th:value="${#numbers.formatDecimal(product?.price?.getNumber()?.doubleValueExact(), 1, 2)}" required/>
|
<input class="form-control" type="number" th:field="*{retailPrice}" step="0.01" min="0" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<!-- FIXME darf nur bei angeboten als teil von partyservice angezeigt werden -->
|
<!-- FIXME darf nur bei angeboten als teil von partyservice angezeigt werden -->
|
||||||
<label class="form-label" for="promotionPrice">Aktionspreis</label>
|
<label class="form-label" for="promotionPrice">Aktionspreis</label>
|
||||||
<input class="form-control" type="number" name="promotionPrice" step="0.01" min="0" th:value="${#numbers.formatDecimal(product?.promotionPrice?.getNumber()?.doubleValueExact(), 1, 2)}"/>
|
<input class="form-control" type="number" th:field="*{promotionPrice}" step="0.01" min="0"/>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-primary" type="submit" th:text="${product == null ? 'Hinzufügen' : 'Bearbeiten'}"></button>
|
<button class="btn btn-primary" type="submit" th:text="${actionIsAdd ? 'Hinzufügen' : 'Bearbeiten'}"></button>
|
||||||
<!-- KANN: Bild und Beschreibungstext -->
|
<!-- KANN: Bild und Beschreibungstext -->
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue