added supplier bookings table

This commit is contained in:
Hendrik Schutter 2020-06-05 15:43:46 +02:00
parent 2245309198
commit 8a4ff4cfa5
3 changed files with 128 additions and 26 deletions

View File

@ -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<UImodelSupplierDetailOrders> orders = new ArrayList<UImodelSupplierDetailOrders>();
for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
orders.add(new UImodelSupplierDetailOrders(supplierOrder));
}
@ -60,11 +65,19 @@ public class SupplierIndexController {
// get latest supplier booking
Optional<BookingAccountEntry> 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<UImodelSupplierDetailBookings> bookings = new ArrayList<UImodelSupplierDetailBookings>();
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<UImodelSupplierDetailOrders> orders;
List<UImodelSupplierDetailBookings> bookings;
public String getName() {
return name;
@ -128,10 +142,20 @@ public class SupplierIndexController {
this.orders = orders;
}
public UImodelSupplierDetail(String name, String balance, List<UImodelSupplierDetailOrders> orders) {
public List<UImodelSupplierDetailBookings> getBookings() {
return bookings;
}
public void setBookings(List<UImodelSupplierDetailBookings> bookings) {
this.bookings = bookings;
}
public UImodelSupplierDetail(String name, String balance, List<UImodelSupplierDetailOrders> orders,
List<UImodelSupplierDetailBookings> 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;
}
}
}

View File

@ -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<Booking, Long> {
// 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<Booking> getBySupplier(Long supplier);
}

View File

@ -41,7 +41,6 @@
</tr>
</thead>
<tbody>
<tr>
<tr th:each="order : ${SupplierDetail.orders}">
<td><span th:text="${order.id}"></span></td>
<td><span th:text="${order.dateOrder}"></span></td>
@ -69,22 +68,27 @@
</div>
<p>
<table id="main-table">
<tr>
<th>Zeitpunkt</th>
<th>Betrag</th>
<th>Von</th>
<th>Kontostand</th>
<th>Grund</th>
<th>Referenz</th>
</tr>
<tr>
<td>10.09.2019 13:45</td>
<td>100,00&nbsp;EUR</td>
<td><a th:href="@{/intern/accounting/main}">Hauptkonto</a></td>
<td>-100,00&nbsp;EUR</td>
<td>Lieferanten-Bestellung</td>
<td><a th:href="@{/intern/supplierOrders/#q=4520}">2504</a></td>
</tr>
<thead>
<tr>
<th>Zeitpunkt</th>
<th>Betrag</th>
<th>Von</th>
<th>Kontostand</th>
<th>Grund</th>
<th>Referenz</th>
</tr>
</thead>
<tbody>
<tr>
<tr th:each="booking : ${SupplierDetail.bookings}">
<td><span th:text="${booking.dateBooking}"></span></td>
<td><span th:text="${booking.price}"></span></td>
<td><a th:href="@{/intern/accounting/main}" th:text="${booking.srcName}" ></a></td>
<td><span th:text="${booking.balance}"></span></td>
<td><span th:text="${booking.reason}"></span></td>
<td><a th:href="${'/intern/supplierOrders/#q=' + booking.orderID}" th:text="${booking.orderID}" class="button smaller"></a></td>
</tr>
</tbody>
</table>
</p>
</div>