221 lines
4.9 KiB
Java
221 lines
4.9 KiB
Java
package org.hso.ecommerce.controller.intern.suppliers;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.hso.ecommerce.entities.supplier.Supplier;
|
|
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
|
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
|
|
import org.hso.ecommerce.repos.supplier.SupplierRepository;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
@Controller
|
|
@RequestMapping("/intern/")
|
|
public class SupplierIndexController {
|
|
|
|
@Autowired
|
|
private final SupplierRepository supplierRepository = null;
|
|
|
|
@Autowired
|
|
private final SupplierOrderRepository supplierOrderRepository = null;
|
|
|
|
@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";
|
|
}
|
|
|
|
@GetMapping("/suppliers/{id}")
|
|
public String supplierDetail(Model model, @PathVariable String id) {
|
|
|
|
int supplierId = Integer.parseInt(id);
|
|
|
|
List<UImodelSupplierDetailOrders> orders = new ArrayList<UImodelSupplierDetailOrders>();
|
|
|
|
for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
|
|
orders.add(new UImodelSupplierDetailOrders(supplierOrder));
|
|
}
|
|
|
|
UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name,
|
|
"42€", orders);
|
|
|
|
model.addAttribute("SupplierDetail", total);
|
|
|
|
return "intern/suppliers/id";
|
|
}
|
|
|
|
public class UImodelSuppliers {
|
|
long id;
|
|
String name;
|
|
|
|
public long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public UImodelSuppliers(long id, String name) {
|
|
this.id = id;
|
|
this.name = name;
|
|
}
|
|
|
|
}
|
|
|
|
public class UImodelSupplierDetail {
|
|
|
|
String name;
|
|
String balance;
|
|
List<UImodelSupplierDetailOrders> orders;
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public String getBalance() {
|
|
return balance;
|
|
}
|
|
|
|
public void setBalance(String balance) {
|
|
this.balance = balance;
|
|
}
|
|
|
|
public List<UImodelSupplierDetailOrders> getOrders() {
|
|
return orders;
|
|
}
|
|
|
|
public void setOrders(List<UImodelSupplierDetailOrders> orders) {
|
|
this.orders = orders;
|
|
}
|
|
|
|
public UImodelSupplierDetail(String name, String balance, List<UImodelSupplierDetailOrders> orders) {
|
|
this.name = name;
|
|
this.balance = balance;
|
|
this.orders = orders;
|
|
}
|
|
|
|
}
|
|
|
|
public class UImodelSupplierDetailOrders {
|
|
long id;
|
|
String dateOrder;
|
|
String articleName;
|
|
long articleId;
|
|
String priceNetto;
|
|
String quantity;
|
|
String price_total;
|
|
boolean arrived;
|
|
|
|
public long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getDateOrder() {
|
|
return dateOrder;
|
|
}
|
|
|
|
public void setDateOrder(String dateOrder) {
|
|
this.dateOrder = dateOrder;
|
|
}
|
|
|
|
public String getArticleName() {
|
|
return articleName;
|
|
}
|
|
|
|
public void setArticleName(String articleName) {
|
|
this.articleName = articleName;
|
|
}
|
|
|
|
public String getPriceNetto() {
|
|
return priceNetto;
|
|
}
|
|
|
|
public void setPriceNetto(String priceNetto) {
|
|
this.priceNetto = priceNetto;
|
|
}
|
|
|
|
public String getQuantity() {
|
|
return quantity;
|
|
}
|
|
|
|
public void setQuantity(String quantity) {
|
|
this.quantity = quantity;
|
|
}
|
|
|
|
public String getPrice_total() {
|
|
return price_total;
|
|
}
|
|
|
|
public void setPrice_total(String price_total) {
|
|
this.price_total = price_total;
|
|
}
|
|
|
|
public long getArticleId() {
|
|
return articleId;
|
|
}
|
|
|
|
public void setArticleId(long articleId) {
|
|
this.articleId = articleId;
|
|
}
|
|
|
|
public boolean isArrived() {
|
|
return arrived;
|
|
}
|
|
|
|
public void setArrived(boolean arrived) {
|
|
this.arrived = arrived;
|
|
}
|
|
|
|
public UImodelSupplierDetailOrders(SupplierOrder order) {
|
|
this.id = order.id;
|
|
this.articleName = order.ordered.title;
|
|
this.articleId = order.ordered.id;
|
|
this.priceNetto = String.format("%.2f", ((float) order.pricePerUnitNetCent / 100));
|
|
this.quantity = String.valueOf(order.numberOfUnits);
|
|
this.price_total = String.format("%.2f", ((float) order.totalPriceNet / 100));
|
|
|
|
Date date = new Date();
|
|
date.setTime(order.created.getTime());
|
|
this.dateOrder = new SimpleDateFormat("dd.MM.yyyy").format(date);
|
|
|
|
if (order.delivered != null) {
|
|
arrived = true;
|
|
} else {
|
|
arrived = false;
|
|
}
|
|
}
|
|
}
|
|
}
|