This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/web_backend/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java

158 lines
5.1 KiB
Java
Raw Normal View History

2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern.suppliers;
2020-04-28 22:41:29 +02:00
2020-05-30 20:16:27 +02:00
import java.text.SimpleDateFormat;
2020-05-30 16:16:14 +02:00
import java.util.ArrayList;
2020-05-30 20:16:27 +02:00
import java.util.Date;
2020-06-05 07:49:11 +02:00
import java.util.List;
import org.hso.ecommerce.controller.intern.accounting.AccountingController;
import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBooking;
import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBookingResult;
2020-06-05 07:49:11 +02:00
import org.hso.ecommerce.entities.booking.Booking;
2020-05-30 16:16:14 +02:00
import org.hso.ecommerce.entities.supplier.Supplier;
2020-05-30 20:16:27 +02:00
import org.hso.ecommerce.entities.supplier.SupplierOrder;
2020-06-05 07:49:11 +02:00
import org.hso.ecommerce.repos.booking.BookingRepository;
2020-05-30 20:16:27 +02:00
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
2020-05-30 16:16:14 +02:00
import org.hso.ecommerce.repos.supplier.SupplierRepository;
2020-06-05 07:49:11 +02:00
import org.springframework.beans.factory.annotation.Autowired;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller;
2020-05-30 16:16:14 +02:00
import org.springframework.ui.Model;
2020-06-05 07:49:11 +02:00
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
2020-04-28 22:41:29 +02:00
@Controller
2020-05-30 16:16:14 +02:00
@RequestMapping("/intern/")
2020-05-01 10:48:12 +02:00
public class SupplierIndexController {
2020-06-05 07:49:11 +02:00
2020-05-30 16:16:14 +02:00
@Autowired
private final SupplierRepository supplierRepository = null;
2020-05-30 20:16:27 +02:00
@Autowired
private final SupplierOrderRepository supplierOrderRepository = null;
2020-06-05 13:10:16 +02:00
@Autowired
private final BookingRepository bookingRepository = null;
2020-06-05 13:10:16 +02:00
2020-06-05 15:43:46 +02:00
@Autowired
private final AccountingController accountingController = null;
2020-06-05 15:43:46 +02:00
2020-05-30 16:16:14 +02:00
@GetMapping("suppliers")
public String listSuppliers(Model model) {
List<UImodelSuppliers> totals = new ArrayList<UImodelSuppliers>();
for (Supplier supplier : supplierRepository.findAll()) {
UImodelSuppliers tmp = new UImodelSuppliers(supplier.id, supplier.name);
totals.add(tmp);
}
model.addAttribute("suppliers", totals);
return "intern/suppliers/index";
}
2020-05-30 16:43:07 +02:00
@GetMapping("/suppliers/{id}")
2020-05-30 20:16:27 +02:00
public String supplierDetail(Model model, @PathVariable String id) {
2020-05-30 21:13:25 +02:00
2020-06-05 15:43:46 +02:00
long supplierId = Long.parseLong(id);
2020-05-30 16:43:07 +02:00
2020-06-05 15:43:46 +02:00
// add orders from supplier to UImodel
2020-05-30 20:16:27 +02:00
List<UImodelSupplierDetailOrders> orders = new ArrayList<UImodelSupplierDetailOrders>();
for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
orders.add(new UImodelSupplierDetailOrders(supplierOrder));
}
2020-05-30 16:43:07 +02:00
// Table of bookings
List<Booking> bookings = bookingRepository.supplierBookingsReverseChronologically(supplierId);
ShortTemplateBookingResult bookingResult = accountingController.buildShortTemplate(bookings,
account -> account.supplierAccount != null && account.supplierAccount.id == supplierId);
2020-06-05 15:43:46 +02:00
2020-05-30 21:13:25 +02:00
UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name,
bookingResult.balance, orders, bookingResult.bookings);
2020-05-30 16:43:07 +02:00
model.addAttribute("SupplierDetail", total);
return "intern/suppliers/id";
}
2020-05-30 16:16:14 +02:00
public class UImodelSuppliers {
2020-06-05 18:05:10 +02:00
public long id;
public String name;
2020-05-30 16:16:14 +02:00
public UImodelSuppliers(long id, String name) {
this.id = id;
this.name = name;
}
}
2020-05-30 16:43:07 +02:00
public class UImodelSupplierDetail {
2020-06-05 18:05:10 +02:00
public String name;
public String balance;
public List<UImodelSupplierDetailOrders> orders;
public List<ShortTemplateBooking> bookings;
2020-06-05 15:43:46 +02:00
public UImodelSupplierDetail(String name, String balance, List<UImodelSupplierDetailOrders> orders,
List<ShortTemplateBooking> bookings
) {
2020-05-30 16:43:07 +02:00
this.name = name;
this.balance = balance;
this.orders = orders;
2020-06-05 15:43:46 +02:00
this.bookings = bookings;
2020-05-30 16:43:07 +02:00
}
}
public class UImodelSupplierDetailOrders {
2020-06-05 18:05:10 +02:00
public long id;
public String dateOrder;
public String articleName;
public long articleId;
public String priceNet;
public String quantity;
public String priceTotal;
public boolean arrived;
2020-06-05 07:49:11 +02:00
2020-05-30 21:13:25 +02:00
public UImodelSupplierDetailOrders(SupplierOrder order) {
2020-05-30 20:16:27 +02:00
this.id = order.id;
this.articleName = order.ordered.title;
this.articleId = order.ordered.id;
2020-06-05 18:05:10 +02:00
this.priceNet = String.format("%.2f", ((float) order.pricePerUnitNetCent / 100));
2020-05-30 20:16:27 +02:00
this.quantity = String.valueOf(order.numberOfUnits);
2020-06-05 18:05:10 +02:00
this.priceTotal = String.format("%.2f", ((float) order.totalPriceNet / 100));
2020-06-05 07:49:11 +02:00
2020-05-30 20:16:27 +02:00
Date date = new Date();
date.setTime(order.created.getTime());
this.dateOrder = new SimpleDateFormat("dd.MM.yyyy").format(date);
2020-06-05 07:49:11 +02:00
2020-05-30 21:13:25 +02:00
if (order.delivered != null) {
arrived = true;
} else {
arrived = false;
}
}
2020-05-30 16:43:07 +02:00
}
2020-06-05 07:49:11 +02:00
2020-06-05 15:43:46 +02:00
public class UImodelSupplierDetailBookings {
2020-06-05 07:49:11 +02:00
2020-06-05 18:05:10 +02:00
public String dateBooking;
public String price;
public String srcName;
public String balance;
public String reason;
public long orderID;
2020-06-05 07:49:11 +02:00
2020-06-05 15:43:46 +02:00
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;
}
}
2020-04-28 22:41:29 +02:00
}