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 23:32:01 +02:00
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import org.hso.ecommerce.entities.supplier.SupplierOrder ;
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository ;
import org.springframework.beans.factory.annotation.Autowired ;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller ;
2020-05-30 23:32:01 +02:00
import org.springframework.ui.Model ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
2020-04-28 22:41:29 +02:00
@Controller
2020-05-30 23:32:01 +02:00
@RequestMapping ( " /intern/ " )
2020-05-01 10:48:12 +02:00
public class SupplierOrderController {
2020-05-30 23:32:01 +02:00
@Autowired
private final SupplierOrderRepository supplierOrderRepository = null ;
@GetMapping ( " supplierOrders " )
public String listSuppliers ( Model model ) {
List < UImodelSupplierOrder > totals = new ArrayList < UImodelSupplierOrder > ( ) ;
for ( SupplierOrder orders : supplierOrderRepository . findAll ( ) ) {
totals . add ( new UImodelSupplierOrder ( orders ) ) ;
}
model . addAttribute ( " orders " , totals ) ;
return " intern/supplierOrders/index " ;
}
public class UImodelSupplierOrder {
long id ;
String dateOrder ;
String supplierName ;
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 String getSupplierName ( ) {
return supplierName ;
}
public void setSupplierName ( String supplierName ) {
this . supplierName = supplierName ;
}
public UImodelSupplierOrder ( SupplierOrder order ) {
this . id = order . id ;
this . supplierName = order . supplier . name ;
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 ;
}
}
}
2020-04-28 22:41:29 +02:00
}