diff --git a/prototype/scripts/addsupplierorders.sql b/prototype/scripts/addsupplierorders.sql new file mode 100644 index 0000000..6c19af3 --- /dev/null +++ b/prototype/scripts/addsupplierorders.sql @@ -0,0 +1,3 @@ + +INSERT INTO supplier_orders ("created", "delivered", "number_of_units", "price_per_unit_net_cent", "total_price_net", "ordered_id", "supplier_id") +VALUES ('0', '0', '42', '42', '42', '1', '1'); diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java index d9d214a..5a6720e 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java @@ -1,9 +1,15 @@ package org.hso.ecommerce.controller.intern.suppliers; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import org.hso.ecommerce.entities.supplier.ArticleOffer; 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; @@ -19,6 +25,9 @@ public class SupplierIndexController { @Autowired private final SupplierRepository supplierRepository = null; + @Autowired + private final SupplierOrderRepository supplierOrderRepository = null; + @GetMapping("suppliers") public String listSuppliers(Model model) { @@ -34,17 +43,20 @@ public class SupplierIndexController { } @GetMapping("/suppliers/{id}") - public String internListedArticlesId(Model model, @PathVariable String id) { - - System.out.println("hEre!"); - + public String supplierDetail(Model model, @PathVariable String id) { + int supplierId = Integer.parseInt(id); - UImodelSupplierDetailOrders orders = new UImodelSupplierDetailOrders(supplierId, "01.01.1970", "orderd article", - "netto €", "42", "total €", "31.12.1970"); + List orders = new ArrayList(); + + for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) { + orders.add(new UImodelSupplierDetailOrders(supplierOrder)); + } - UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name, - "42€", orders); + UImodelSupplierDetail total = new UImodelSupplierDetail( + supplierRepository.findSupplierById(supplierId).name, + "42€", + orders); model.addAttribute("SupplierDetail", total); @@ -82,7 +94,7 @@ public class SupplierIndexController { String name; String balance; - UImodelSupplierDetailOrders orders; + List orders; public String getName() { return name; @@ -100,15 +112,15 @@ public class SupplierIndexController { this.balance = balance; } - public UImodelSupplierDetailOrders getOrders() { + public List getOrders() { return orders; } - public void setOrders(UImodelSupplierDetailOrders orders) { + public void setOrders(List orders) { this.orders = orders; } - public UImodelSupplierDetail(String name, String balance, UImodelSupplierDetailOrders orders) { + public UImodelSupplierDetail(String name, String balance, List orders) { this.name = name; this.balance = balance; this.orders = orders; @@ -120,6 +132,7 @@ public class SupplierIndexController { long id; String dateOrder; String articleName; + long articleId; String priceNetto; String quantity; String price_total; @@ -181,15 +194,29 @@ public class SupplierIndexController { this.dateArrival = dateArrival; } - public UImodelSupplierDetailOrders(long id, String dateOrder, String articleName, String priceNetto, - String quantity, String price_total, String dateArrival) { - this.id = id; - this.dateOrder = dateOrder; - this.articleName = articleName; - this.priceNetto = priceNetto; - this.quantity = quantity; - this.price_total = price_total; - this.dateArrival = dateArrival; + 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); } } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java index 9d15e02..73a041c 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java @@ -1,8 +1,11 @@ package org.hso.ecommerce.repos.supplier; +import java.util.List; + import org.hso.ecommerce.entities.supplier.SupplierOrder; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository @@ -11,4 +14,9 @@ public interface SupplierOrderRepository extends JpaRepository findOrderBySupplierID(@Param("supplierId") long supplierId); + + } diff --git a/prototype/src/main/resources/templates/intern/suppliers/id.html b/prototype/src/main/resources/templates/intern/suppliers/id.html index 308d009..b32be5d 100644 --- a/prototype/src/main/resources/templates/intern/suppliers/id.html +++ b/prototype/src/main/resources/templates/intern/suppliers/id.html @@ -1,85 +1,87 @@ - - - - - - Lieferanten Details - - - - - - - -
- -
-

Bestellungen

-

- - - - - - - - - - - - - - - - - - - - - - -
- -
BestellnummerDatumArtikelPreis/Stk (Netto)MengeGesamtpreis (Netto)Status
45452019-18-10Kamera20,00 EUR10200,00 EURUnterwegs
Angekommen
-

-

Buchungen

-
-

Kontostand

-

-100,00 EUR

-
-

- - - - - - - - - - - - - - - - - -
ZeitpunktBetragVonKontostandGrundReferenz
10.09.2019 13:45100,00 EURHauptkonto-100,00 EURLieferanten-Bestellung2504
-

-
-
-
- - - + + + + Lieferanten Details + + + + + + +
+ +
+

Bestellungen

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
BestellnummerDatumArtikelPreis/Stk (Netto)MengeGesamtpreis (Netto)Status
+

+

Buchungen

+
+

Kontostand

+

+
+

+ + + + + + + + + + + + + + + + + +
ZeitpunktBetragVonKontostandGrundReferenz
10.09.2019 13:45100,00 EURHauptkonto-100,00 EURLieferanten-Bestellung2504
+

+
+
+ + + \ No newline at end of file