Compare commits

...

2 commits

Author SHA1 Message Date
Mathis Kral fbe8ce6953
Fix wrong price calculation on invoice 2024-01-27 14:00:45 +01:00
Mathis Kral 580489d216 Remove CustomCatalogEntryDataInitializer 2024-01-26 16:04:33 +01:00
3 changed files with 7 additions and 51 deletions

View file

@ -1,46 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-FileCopyrightText: 2023-2024 swt23w23
package catering.orderCatalog;
import catering.order.OrderType;
import org.salespointframework.catalog.Product;
import org.salespointframework.core.DataInitializer;
import org.salespointframework.quantity.Quantity;
import org.springframework.stereotype.Component;
import org.salespointframework.inventory.UniqueInventory;
import org.salespointframework.inventory.UniqueInventoryItem;
import java.util.HashMap;
import java.util.Map;
import org.javamoney.moneta.Money;
@Component
public class CustomCatalogEntryDataInitializer implements DataInitializer {
private CustomCatalogEntryRepository catalogEntryRepository;
private final UniqueInventory<UniqueInventoryItem> inventory;
public CustomCatalogEntryDataInitializer(CustomCatalogEntryRepository catalogEntryRepository, UniqueInventory<UniqueInventoryItem> inventory) {
this.catalogEntryRepository = catalogEntryRepository;
this.inventory = inventory;
}
@Override
public void initialize() {
Map<Product, Quantity> products = new HashMap<>();
Product product1 = inventory.findAll().stream().toList().get(0).getProduct();
Product product2 = inventory.findAll().stream().toList().get(1).getProduct();
Product product3 = inventory.findAll().stream().toList().get(2).getProduct();
products.put(product1, product1.createQuantity(30));
products.put(product2, product2.createQuantity(15));
products.put(product3, product3.createQuantity(1));
catalogEntryRepository.save(
new CustomCatalogEntry(
OrderType.EVENT_CATERING,
products,
Money.of(500, "EUR")));
}
}

View file

@ -25,21 +25,24 @@ SPDX-FileCopyrightText: 2023-2024 swt23w23
<th scope="col">Beschreibung</th>
<th scope="col">Einzelpreis/Basispreis</th>
<th scope="col">Menge</th>
<th scope="col">Mietpreis</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()}"></td>
<td th:text="${orderLine.getPrice().divide(orderLine.getQuantity().getAmount())}"></td>
<td th:text="${orderLine.getQuantity()}"></td>
<td th:text="${orderLine.getPrice().multiply(orderLine.getQuantity().getAmount()).add(order.getChargeLines(orderLine).getTotal())}"></td>
<td th:text="${order.getChargeLines(orderLine).getTotal()}"></td>
<td th:text="${orderLine.getPrice().add(order.getChargeLines(orderLine).getTotal())}"></td>
</tr>
<tr th:each="chargeLine : ${order.getChargeLines()}">
<td th:text="${staffCharges.get(chargeLine).getName()}"></td>
<td th:text="${chargeLine.getPrice()}"></td>
<td>-</td>
<td>1</td>
<td th:text="${chargeLine.getPrice()}"></td>
<td th:text="${chargeLine.getPrice()}"></td>
</tr>
</tbody>
</table>

View file

@ -44,7 +44,6 @@ public class CatalogControllerUnitTests {
@Test
void countOfEntries() {
// Includes entry of data initializer
assertThat(catalogEntryRepository.findAll().stream().count()).isEqualTo(2);
assertThat(catalogEntryRepository.findAll().stream().count()).isEqualTo(1);
}
}