mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-06-23 20:43:41 +02:00
Simon Bruder
bac025fd0a
This finally makes the licensing under AGPL-3.0-or-later explicit after I got the okay from the kickstart source owners. This also checks the REUSE compliance in a pre commit hook, and therefore also in CI.
72 lines
2.3 KiB
Java
72 lines
2.3 KiB
Java
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2023 swt23w23
|
|
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.UniqueInventoryItem;
|
|
|
|
import catering.catalog.Consumable;
|
|
import jakarta.validation.constraints.NotNull;
|
|
import jakarta.validation.constraints.PositiveOrZero; // NonNegative in enterprise java
|
|
|
|
class ConsumableMutateForm extends InventoryMutateForm {
|
|
private @NotNull @PositiveOrZero Double wholesalePrice;
|
|
private @NotNull Optional<@PositiveOrZero Double> promotionPrice = Optional.empty();
|
|
|
|
public Double getWholesalePrice() {
|
|
return wholesalePrice;
|
|
}
|
|
|
|
public Optional<Double> getPromotionPrice() {
|
|
return promotionPrice;
|
|
}
|
|
|
|
public void setWholesalePrice(Double wholesalePrice) {
|
|
this.wholesalePrice = wholesalePrice;
|
|
}
|
|
|
|
public void setPromotionPrice(Optional<Double> promotionPrice) {
|
|
this.promotionPrice = promotionPrice;
|
|
}
|
|
|
|
@Override
|
|
public Product toProduct() {
|
|
return new Consumable(
|
|
getName(),
|
|
Money.of(getRetailPrice(), EURO),
|
|
Money.of(getWholesalePrice(), EURO),
|
|
getPromotionPrice().map(price -> Money.of(price, EURO)),
|
|
getOrderTypes());
|
|
}
|
|
|
|
public static ConsumableMutateForm of(Consumable product, UniqueInventoryItem item) {
|
|
ConsumableMutateForm form = new ConsumableMutateForm();
|
|
form.setName(product.getName());
|
|
form.setQuantity(item.getQuantity());
|
|
form.setOrderTypes(orderTypesFromCategories(product.getCategories()));
|
|
form.setWholesalePrice(product.getWholesalePrice().getNumber().doubleValueExact());
|
|
form.setRetailPrice(product.getRetailPrice().getNumber().doubleValueExact());
|
|
form.setPromotionPrice(
|
|
product.getPromotionPrice().map(MonetaryAmount::getNumber).map(NumberValue::doubleValueExact));
|
|
return form;
|
|
}
|
|
|
|
@Override
|
|
protected void modifyProductPrimitive(Product product) {
|
|
if (product instanceof Consumable consumable) {
|
|
consumable.setWholesalePrice(Money.of(getWholesalePrice(), EURO));
|
|
consumable.setPromotionPrice(getPromotionPrice().map(price -> Money.of(price, EURO)));
|
|
} else {
|
|
throw new IllegalArgumentException("ConsumableMutateForm can only modify instances of Consumable");
|
|
}
|
|
}
|
|
}
|