diff --git a/src/main/java/catering/inventory/InventoryController.java b/src/main/java/catering/inventory/InventoryController.java index be5cb59..27218f9 100644 --- a/src/main/java/catering/inventory/InventoryController.java +++ b/src/main/java/catering/inventory/InventoryController.java @@ -17,6 +17,12 @@ package catering.inventory; 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.salespointframework.catalog.Product; import org.salespointframework.inventory.UniqueInventory; @@ -57,8 +63,22 @@ class InventoryController { @PreAuthorize("hasRole('ADMIN')") @GetMapping("/inventory/edit/{pid}") String edit(Model model, @PathVariable Product pid) { - model.addAttribute("product", pid); - model.addAttribute("item", inventory.findByProduct(pid).get()); + CatalogDummy product = (CatalogDummy) pid; + 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"; } diff --git a/src/main/resources/templates/inventory-mutate.html b/src/main/resources/templates/inventory-mutate.html index 79f5f35..21efc93 100644 --- a/src/main/resources/templates/inventory-mutate.html +++ b/src/main/resources/templates/inventory-mutate.html @@ -5,37 +5,37 @@ layout:decorate="~{layout.html(title='Lagerverwaltung')}">
-

- -
+

+
- +
- +
- +
+
- +
- +
- +
- +