feature/supplier_page #52
@ -6,10 +6,12 @@ import java.util.Date;
 | 
				
			|||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Optional;
 | 
					import java.util.Optional;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.hso.ecommerce.entities.booking.Booking;
 | 
				
			||||||
import org.hso.ecommerce.entities.booking.BookingAccountEntry;
 | 
					import org.hso.ecommerce.entities.booking.BookingAccountEntry;
 | 
				
			||||||
import org.hso.ecommerce.entities.supplier.Supplier;
 | 
					import org.hso.ecommerce.entities.supplier.Supplier;
 | 
				
			||||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
 | 
					import org.hso.ecommerce.entities.supplier.SupplierOrder;
 | 
				
			||||||
import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
 | 
					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.SupplierOrderRepository;
 | 
				
			||||||
import org.hso.ecommerce.repos.supplier.SupplierRepository;
 | 
					import org.hso.ecommerce.repos.supplier.SupplierRepository;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
@ -32,6 +34,9 @@ public class SupplierIndexController {
 | 
				
			|||||||
	@Autowired
 | 
						@Autowired
 | 
				
			||||||
	private final BookingAccountEntryRepository bookingAccountEntryRepository = null;
 | 
						private final BookingAccountEntryRepository bookingAccountEntryRepository = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Autowired
 | 
				
			||||||
 | 
						private final BookingRepository bookingRepository = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@GetMapping("suppliers")
 | 
						@GetMapping("suppliers")
 | 
				
			||||||
	public String listSuppliers(Model model) {
 | 
						public String listSuppliers(Model model) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -49,10 +54,10 @@ public class SupplierIndexController {
 | 
				
			|||||||
	@GetMapping("/suppliers/{id}")
 | 
						@GetMapping("/suppliers/{id}")
 | 
				
			||||||
	public String supplierDetail(Model model, @PathVariable String 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>();
 | 
							List<UImodelSupplierDetailOrders> orders = new ArrayList<UImodelSupplierDetailOrders>();
 | 
				
			||||||
 | 
					 | 
				
			||||||
		for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
 | 
							for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
 | 
				
			||||||
			orders.add(new UImodelSupplierDetailOrders(supplierOrder));
 | 
								orders.add(new UImodelSupplierDetailOrders(supplierOrder));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -60,11 +65,19 @@ public class SupplierIndexController {
 | 
				
			|||||||
		// get latest supplier booking
 | 
							// get latest supplier booking
 | 
				
			||||||
		Optional<BookingAccountEntry> supplierBooking = bookingAccountEntryRepository.getBySupplier(supplierId);
 | 
							Optional<BookingAccountEntry> supplierBooking = bookingAccountEntryRepository.getBySupplier(supplierId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//get account balance
 | 
							// get account balance
 | 
				
			||||||
		String supplierBalance = ((supplierBooking.isPresent()) ? String.format("%.2f", ((float) supplierBooking.get().newSumCent / 100)) : "0,00"); 
 | 
							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,
 | 
							UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name,
 | 
				
			||||||
				supplierBalance, orders);
 | 
									supplierBalance, orders, bookings);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		model.addAttribute("SupplierDetail", total);
 | 
							model.addAttribute("SupplierDetail", total);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -103,6 +116,7 @@ public class SupplierIndexController {
 | 
				
			|||||||
		String name;
 | 
							String name;
 | 
				
			||||||
		String balance;
 | 
							String balance;
 | 
				
			||||||
		List<UImodelSupplierDetailOrders> orders;
 | 
							List<UImodelSupplierDetailOrders> orders;
 | 
				
			||||||
 | 
							List<UImodelSupplierDetailBookings> bookings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public String getName() {
 | 
							public String getName() {
 | 
				
			||||||
			return name;
 | 
								return name;
 | 
				
			||||||
@ -128,10 +142,20 @@ public class SupplierIndexController {
 | 
				
			|||||||
			this.orders = orders;
 | 
								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.name = name;
 | 
				
			||||||
			this.balance = balance;
 | 
								this.balance = balance;
 | 
				
			||||||
			this.orders = orders;
 | 
								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;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,17 @@
 | 
				
			|||||||
package org.hso.ecommerce.repos.booking;
 | 
					package org.hso.ecommerce.repos.booking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.hso.ecommerce.entities.booking.Booking;
 | 
					import org.hso.ecommerce.entities.booking.Booking;
 | 
				
			||||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
					import org.springframework.data.jpa.repository.JpaRepository;
 | 
				
			||||||
 | 
					import org.springframework.data.jpa.repository.Query;
 | 
				
			||||||
import org.springframework.stereotype.Repository;
 | 
					import org.springframework.stereotype.Repository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Repository
 | 
					@Repository
 | 
				
			||||||
public interface BookingRepository extends JpaRepository<Booking, Long> {
 | 
					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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -41,7 +41,6 @@
 | 
				
			|||||||
                  </tr>
 | 
					                  </tr>
 | 
				
			||||||
               </thead>
 | 
					               </thead>
 | 
				
			||||||
               <tbody>
 | 
					               <tbody>
 | 
				
			||||||
                  <tr>
 | 
					 | 
				
			||||||
                  <tr th:each="order : ${SupplierDetail.orders}">
 | 
					                  <tr th:each="order : ${SupplierDetail.orders}">
 | 
				
			||||||
                     <td><span th:text="${order.id}"></span></td>
 | 
					                     <td><span th:text="${order.id}"></span></td>
 | 
				
			||||||
                     <td><span th:text="${order.dateOrder}"></span></td>
 | 
					                     <td><span th:text="${order.dateOrder}"></span></td>
 | 
				
			||||||
@ -69,22 +68,27 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <p>
 | 
					            <p>
 | 
				
			||||||
            <table id="main-table">
 | 
					            <table id="main-table">
 | 
				
			||||||
               <tr>
 | 
					               <thead>
 | 
				
			||||||
                  <th>Zeitpunkt</th>
 | 
					                  <tr>
 | 
				
			||||||
                  <th>Betrag</th>
 | 
					                     <th>Zeitpunkt</th>
 | 
				
			||||||
| 
							
							
								
									
	
	
	
	
	
	
	
	 | 
					|||||||
                  <th>Von</th>
 | 
					                     <th>Betrag</th>
 | 
				
			||||||
                  <th>Kontostand</th>
 | 
					                     <th>Von</th>
 | 
				
			||||||
                  <th>Grund</th>
 | 
					                     <th>Kontostand</th>
 | 
				
			||||||
                  <th>Referenz</th>
 | 
					                     <th>Grund</th>
 | 
				
			||||||
               </tr>
 | 
					                     <th>Referenz</th>
 | 
				
			||||||
               <tr>
 | 
					                  </tr>
 | 
				
			||||||
                  <td>10.09.2019 13:45</td>
 | 
					               </thead>
 | 
				
			||||||
                  <td>100,00 EUR</td>
 | 
					               <tbody>
 | 
				
			||||||
                  <td><a th:href="@{/intern/accounting/main}">Hauptkonto</a></td>
 | 
					                  <tr>
 | 
				
			||||||
                  <td>-100,00 EUR</td>
 | 
					                  <tr th:each="booking : ${SupplierDetail.bookings}">
 | 
				
			||||||
                  <td>Lieferanten-Bestellung</td>
 | 
					                     <td><span th:text="${booking.dateBooking}"></span></td>
 | 
				
			||||||
                  <td><a th:href="@{/intern/supplierOrders/#q=4520}">2504</a></td>
 | 
					                     <td><span th:text="${booking.price}"></span> €</td>
 | 
				
			||||||
               </tr>
 | 
					                     <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>
 | 
					            </table>
 | 
				
			||||||
            </p>
 | 
					            </p>
 | 
				
			||||||
         </div>
 | 
					         </div>
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user
	
Die ID ist doppelt vergeben.