From 8a4ff4cfa591840e35fa39b3e98667d1b377f962 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 5 Jun 2020 15:43:46 +0200 Subject: [PATCH] added supplier bookings table --- .../suppliers/SupplierIndexController.java | 107 ++++++++++++++++-- .../repos/booking/BookingRepository.java | 9 +- .../templates/intern/suppliers/id.html | 38 ++++--- 3 files changed, 128 insertions(+), 26 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 b1db518..84e6147 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 @@ -6,10 +6,12 @@ import java.util.Date; import java.util.List; import java.util.Optional; +import org.hso.ecommerce.entities.booking.Booking; 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.booking.BookingRepository; import org.hso.ecommerce.repos.supplier.SupplierOrderRepository; import org.hso.ecommerce.repos.supplier.SupplierRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +34,9 @@ public class SupplierIndexController { @Autowired private final BookingAccountEntryRepository bookingAccountEntryRepository = null; + @Autowired + private final BookingRepository bookingRepository = null; + @GetMapping("suppliers") public String listSuppliers(Model model) { @@ -49,10 +54,10 @@ public class SupplierIndexController { @GetMapping("/suppliers/{id}") public String supplierDetail(Model model, @PathVariable String id) { - long supplierId = Integer.parseInt(id); + long supplierId = Long.parseLong(id); + // add orders from supplier to UImodel List orders = new ArrayList(); - for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) { orders.add(new UImodelSupplierDetailOrders(supplierOrder)); } @@ -60,11 +65,19 @@ public class SupplierIndexController { // 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"); - + // get account balance + String supplierBalance = ((supplierBooking.isPresent()) + ? String.format("%.2f", ((float) supplierBooking.get().newSumCent / 100)) + : "0,00"); + + // add bookings from supplier to UImodel + List bookings = new ArrayList(); + for (Booking booking : bookingRepository.getBySupplier(supplierId)) { + bookings.add(new UImodelSupplierDetailBookings(booking)); + } + UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name, - supplierBalance, orders); + supplierBalance, orders, bookings); model.addAttribute("SupplierDetail", total); @@ -103,6 +116,7 @@ public class SupplierIndexController { String name; String balance; List orders; + List bookings; public String getName() { return name; @@ -128,10 +142,20 @@ public class SupplierIndexController { this.orders = orders; } - public UImodelSupplierDetail(String name, String balance, List orders) { + public List getBookings() { + return bookings; + } + + public void setBookings(List bookings) { + this.bookings = bookings; + } + + public UImodelSupplierDetail(String name, String balance, List orders, + List bookings) { this.name = name; this.balance = balance; this.orders = orders; + this.bookings = bookings; } } @@ -229,4 +253,73 @@ public class SupplierIndexController { } } } + + public class UImodelSupplierDetailBookings { + + String dateBooking; + String price; + String srcName; + String balance; + String reason; + long orderID; + + public String getDateBooking() { + return dateBooking; + } + + public void setDateBooking(String dateBooking) { + this.dateBooking = dateBooking; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getSrcName() { + return srcName; + } + + public void setSrcName(String srcName) { + this.srcName = srcName; + } + + public String getBalance() { + return balance; + } + + public void setBalance(String balance) { + this.balance = balance; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public long getOrderID() { + return orderID; + } + + public void setOrderID(long orderID) { + this.orderID = orderID; + } + + public UImodelSupplierDetailBookings(Booking booking) { + Date date = new Date(); + date.setTime(booking.reason.supplierOrder.created.getTime()); + this.dateBooking = new SimpleDateFormat("dd.MM.yyyy").format(date); + this.price = String.format("%.2f", ((float) booking.amountCent / 100)); + this.srcName = ((booking.source.isMainAccount) ? "Hauptkonto" : booking.source.supplierAccount.name); + this.balance = String.format("%.2f", ((float) booking.destination.newSumCent / 100)); + this.reason = booking.reason.comment; + this.orderID = booking.reason.supplierOrder.id; + } + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java index 454b3f3..fe01783 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java @@ -1,12 +1,17 @@ package org.hso.ecommerce.repos.booking; +import java.util.List; + import org.hso.ecommerce.entities.booking.Booking; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface BookingRepository extends JpaRepository { + // Return a list with all bookings entries, sorted by id + @Query(value = "SELECT * FROM bookings as b INNER JOIN booking_account_entries ON b.destination_id=booking_account_entries.id OR b.source_id=booking_account_entries.id WHERE booking_account_entries.supplier_account_id = :supplier ORDER BY b.id DESC", nativeQuery = true) + List getBySupplier(Long supplier); + } - - diff --git a/prototype/src/main/resources/templates/intern/suppliers/id.html b/prototype/src/main/resources/templates/intern/suppliers/id.html index 7d6cb7a..1cb4770 100644 --- a/prototype/src/main/resources/templates/intern/suppliers/id.html +++ b/prototype/src/main/resources/templates/intern/suppliers/id.html @@ -41,7 +41,6 @@ - @@ -69,22 +68,27 @@

- - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +
ZeitpunktBetragVonKontostandGrundReferenz
10.09.2019 13:45100,00 EURHauptkonto-100,00 EURLieferanten-Bestellung2504
ZeitpunktBetragVonKontostandGrundReferenz