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.sql.Timestamp ;
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-05-30 16:16:14 +02:00
import java.util.List ;
2020-05-30 20:16:27 +02:00
import org.hso.ecommerce.entities.supplier.ArticleOffer ;
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 ;
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository ;
2020-05-30 16:16:14 +02:00
import org.hso.ecommerce.repos.supplier.SupplierRepository ;
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 ;
import org.springframework.web.bind.annotation.GetMapping ;
2020-05-30 16:43:07 +02:00
import org.springframework.web.bind.annotation.PathVariable ;
2020-05-30 16:16:14 +02:00
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-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-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 16:43:07 +02:00
int supplierId = Integer . parseInt ( id ) ;
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
2020-05-30 20:16:27 +02:00
UImodelSupplierDetail total = new UImodelSupplierDetail (
supplierRepository . findSupplierById ( supplierId ) . name ,
" 42€ " ,
orders ) ;
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 {
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 ;
}
}
2020-05-30 16:43:07 +02:00
public class UImodelSupplierDetail {
String name ;
String balance ;
2020-05-30 20:16:27 +02:00
List < UImodelSupplierDetailOrders > orders ;
2020-05-30 16:43:07 +02:00
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 ;
}
2020-05-30 20:16:27 +02:00
public List < UImodelSupplierDetailOrders > getOrders ( ) {
2020-05-30 16:43:07 +02:00
return orders ;
}
2020-05-30 20:16:27 +02:00
public void setOrders ( List < UImodelSupplierDetailOrders > orders ) {
2020-05-30 16:43:07 +02:00
this . orders = orders ;
}
2020-05-30 20:16:27 +02:00
public UImodelSupplierDetail ( String name , String balance , List < UImodelSupplierDetailOrders > orders ) {
2020-05-30 16:43:07 +02:00
this . name = name ;
this . balance = balance ;
this . orders = orders ;
}
}
public class UImodelSupplierDetailOrders {
long id ;
String dateOrder ;
String articleName ;
2020-05-30 20:16:27 +02:00
long articleId ;
2020-05-30 16:43:07 +02:00
String priceNetto ;
String quantity ;
String price_total ;
String dateArrival ;
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 String getDateArrival ( ) {
return dateArrival ;
}
public void setDateArrival ( String dateArrival ) {
this . dateArrival = dateArrival ;
}
2020-05-30 20:16:27 +02:00
public long getArticleId ( ) {
return articleId ;
}
public void setArticleId ( long articleId ) {
this . articleId = articleId ;
}
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 ) ;
date . setTime ( order . delivered . getTime ( ) ) ;
this . dateArrival = new SimpleDateFormat ( " dd.MM.yyyy " ) . format ( date ) ;
2020-05-30 16:43:07 +02:00
}
}
2020-04-28 22:41:29 +02:00
}