From 93a5863fbeea128e2a310308f5da8ac9b37056cf Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 5 Jun 2020 13:10:16 +0200 Subject: [PATCH] added supplier balance label --- .../suppliers/SupplierIndexController.java | 16 ++++++++++++++-- .../resources/templates/intern/suppliers/id.html | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java index b6d25eb..b1db518 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java @@ -4,9 +4,12 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Optional; +import org.hso.ecommerce.entities.booking.BookingAccountEntry; import org.hso.ecommerce.entities.supplier.Supplier; import org.hso.ecommerce.entities.supplier.SupplierOrder; +import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository; import org.hso.ecommerce.repos.supplier.SupplierOrderRepository; import org.hso.ecommerce.repos.supplier.SupplierRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +29,9 @@ public class SupplierIndexController { @Autowired private final SupplierOrderRepository supplierOrderRepository = null; + @Autowired + private final BookingAccountEntryRepository bookingAccountEntryRepository = null; + @GetMapping("suppliers") public String listSuppliers(Model model) { @@ -43,7 +49,7 @@ public class SupplierIndexController { @GetMapping("/suppliers/{id}") public String supplierDetail(Model model, @PathVariable String id) { - int supplierId = Integer.parseInt(id); + long supplierId = Integer.parseInt(id); List orders = new ArrayList(); @@ -51,8 +57,14 @@ public class SupplierIndexController { orders.add(new UImodelSupplierDetailOrders(supplierOrder)); } + // get latest supplier booking + Optional supplierBooking = bookingAccountEntryRepository.getBySupplier(supplierId); + + //get account balance + String supplierBalance = ((supplierBooking.isPresent()) ? String.format("%.2f", ((float) supplierBooking.get().newSumCent / 100)) : "0,00"); + UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name, - "42€", orders); + supplierBalance, orders); model.addAttribute("SupplierDetail", total); diff --git a/prototype/src/main/resources/templates/intern/suppliers/id.html b/prototype/src/main/resources/templates/intern/suppliers/id.html index 6799b3b..7d6cb7a 100644 --- a/prototype/src/main/resources/templates/intern/suppliers/id.html +++ b/prototype/src/main/resources/templates/intern/suppliers/id.html @@ -65,7 +65,7 @@

Buchungen

Kontostand

-

+