show orders based on supplier

This commit is contained in:
Hendrik Schutter 2020-05-30 20:16:27 +02:00
parent b600040bf3
commit 2f4c45ed71
4 changed files with 144 additions and 104 deletions

View File

@ -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');

View File

@ -1,9 +1,15 @@
package org.hso.ecommerce.controller.intern.suppliers; package org.hso.ecommerce.controller.intern.suppliers;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.hso.ecommerce.entities.supplier.ArticleOffer;
import org.hso.ecommerce.entities.supplier.Supplier; 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.hso.ecommerce.repos.supplier.SupplierRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -19,6 +25,9 @@ public class SupplierIndexController {
@Autowired @Autowired
private final SupplierRepository supplierRepository = null; private final SupplierRepository supplierRepository = null;
@Autowired
private final SupplierOrderRepository supplierOrderRepository = null;
@GetMapping("suppliers") @GetMapping("suppliers")
public String listSuppliers(Model model) { public String listSuppliers(Model model) {
@ -34,17 +43,20 @@ public class SupplierIndexController {
} }
@GetMapping("/suppliers/{id}") @GetMapping("/suppliers/{id}")
public String internListedArticlesId(Model model, @PathVariable String id) { public String supplierDetail(Model model, @PathVariable String id) {
System.out.println("hEre!");
int supplierId = Integer.parseInt(id); int supplierId = Integer.parseInt(id);
UImodelSupplierDetailOrders orders = new UImodelSupplierDetailOrders(supplierId, "01.01.1970", "orderd article", List<UImodelSupplierDetailOrders> orders = new ArrayList<UImodelSupplierDetailOrders>();
"netto €", "42", "total €", "31.12.1970");
UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name, for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
"42€", orders); orders.add(new UImodelSupplierDetailOrders(supplierOrder));
}
UImodelSupplierDetail total = new UImodelSupplierDetail(
supplierRepository.findSupplierById(supplierId).name,
"42€",
orders);
model.addAttribute("SupplierDetail", total); model.addAttribute("SupplierDetail", total);
@ -82,7 +94,7 @@ public class SupplierIndexController {
String name; String name;
String balance; String balance;
UImodelSupplierDetailOrders orders; List<UImodelSupplierDetailOrders> orders;
public String getName() { public String getName() {
return name; return name;
@ -100,15 +112,15 @@ public class SupplierIndexController {
this.balance = balance; this.balance = balance;
} }
public UImodelSupplierDetailOrders getOrders() { public List<UImodelSupplierDetailOrders> getOrders() {
return orders; return orders;
} }
public void setOrders(UImodelSupplierDetailOrders orders) { public void setOrders(List<UImodelSupplierDetailOrders> orders) {
this.orders = orders; this.orders = orders;
} }
public UImodelSupplierDetail(String name, String balance, UImodelSupplierDetailOrders orders) { public UImodelSupplierDetail(String name, String balance, List<UImodelSupplierDetailOrders> orders) {
this.name = name; this.name = name;
this.balance = balance; this.balance = balance;
this.orders = orders; this.orders = orders;
@ -120,6 +132,7 @@ public class SupplierIndexController {
long id; long id;
String dateOrder; String dateOrder;
String articleName; String articleName;
long articleId;
String priceNetto; String priceNetto;
String quantity; String quantity;
String price_total; String price_total;
@ -181,15 +194,29 @@ public class SupplierIndexController {
this.dateArrival = dateArrival; this.dateArrival = dateArrival;
} }
public UImodelSupplierDetailOrders(long id, String dateOrder, String articleName, String priceNetto, public long getArticleId() {
String quantity, String price_total, String dateArrival) { return articleId;
this.id = id; }
this.dateOrder = dateOrder;
this.articleName = articleName; public void setArticleId(long articleId) {
this.priceNetto = priceNetto; this.articleId = articleId;
this.quantity = quantity; }
this.price_total = price_total;
this.dateArrival = dateArrival; 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);
} }
} }

View File

@ -1,8 +1,11 @@
package org.hso.ecommerce.repos.supplier; package org.hso.ecommerce.repos.supplier;
import java.util.List;
import org.hso.ecommerce.entities.supplier.SupplierOrder; import org.hso.ecommerce.entities.supplier.SupplierOrder;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
@ -11,4 +14,9 @@ public interface SupplierOrderRepository extends JpaRepository<SupplierOrder, Lo
@Query("SELECT SUM(so.numberOfUnits) FROM SupplierOrder so JOIN so.ordered ao WHERE ao.articleNumber = :articleNumber AND so.delivered IS NULL") @Query("SELECT SUM(so.numberOfUnits) FROM SupplierOrder so JOIN so.ordered ao WHERE ao.articleNumber = :articleNumber AND so.delivered IS NULL")
Integer countUndeliveredReorders(String articleNumber); Integer countUndeliveredReorders(String articleNumber);
@Query(value = "SELECT * FROM supplier_orders as a WHERE a.supplier_id = :supplierId", nativeQuery = true)
List<SupplierOrder> findOrderBySupplierID(@Param("supplierId") long supplierId);
} }

View File

@ -1,26 +1,23 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="de" dir="ltr" xmlns:th="http://www.thymeleaf.org"> <html lang="de" dir="ltr" xmlns:th="http://www.thymeleaf.org">
<head>
<head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no">
<title>Lieferanten Details</title> <title>Lieferanten Details</title>
<script th:src="@{/js/filterTable.js}"></script> <script th:src="@{/js/filterTable.js}"></script>
<link rel="stylesheet" th:href="@{/css/ecom.css}"/> <link rel="stylesheet" th:href="@{/css/ecom.css}"/>
</head> </head>
<body>
<body> <nav th:replace="fragments/header :: header">Header</nav>
<nav th:replace="fragments/header :: header">Header</nav> <div class="sidebar-layout content-width">
<div class="sidebar-layout content-width">
<nav></nav> <nav></nav>
<div> <div>
<h1>Lieferant <span th:text="${SupplierDetail.name}"></span></h1> <h1>Lieferant <span th:text="${SupplierDetail.name}"></span></h1>
<script th:src="@{/js/back.js}"></script> <script th:src="@{/js/back.js}"></script>
<div class="back" data-group="intern" data-insert="true"></div> <div class="back" data-group="intern" data-insert="true"></div>
</div> </div>
</div> </div>
<main class="sidebar-layout content-width"> <main class="sidebar-layout content-width">
<nav th:replace="fragments/intern :: sidebar"></nav> <nav th:replace="fragments/intern :: sidebar"></nav>
<div class="content-width"> <div class="content-width">
<h2>Bestellungen</h2> <h2>Bestellungen</h2>
@ -32,6 +29,7 @@
data-target-id="main-table"></input> data-target-id="main-table"></input>
</th> </th>
</tr> </tr>
<thead>
<tr> <tr>
<th>Bestellnummer</th> <th>Bestellnummer</th>
<th>Datum</th> <th>Datum</th>
@ -41,21 +39,26 @@
<th>Gesamtpreis (Netto)</th> <th>Gesamtpreis (Netto)</th>
<th>Status</th> <th>Status</th>
</tr> </tr>
</thead>
<tbody>
<tr> <tr>
<td>4545</td> <tr th:each="order : ${SupplierDetail.orders}">
<td>2019-18-10</td> <td><span th:text="${order.id}"></span></td>
<td><a th:href="@{/intern/listedArticles/45015}">Kamera</a></td> <td><span th:text="${order.dateOrder}"></span></td>
<td>20,00&nbsp;EUR</td> <td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="button smaller" th:text="${order.articleName}"></a></td>
<td>10</td> <td><span th:text="${order.priceNetto}"></span></td>
<td>200,00&nbsp;EUR</td> <td><span th:text="${order.quantity}"></span></td>
<td>Unterwegs <br/><a th:href="@{/intern/warehouse/todo}" class="button smaller">Angekommen</a></td> <td><span th:text="${order.price_total}"></span></td>
<td><span th:text="${order.dateArrival}"></span></td>
<!-- <td>Unterwegs <br/><a th:href="@{/intern/warehouse/todo}" class="button smaller">Angekommen</a></td> -->
</tr> </tr>
</tbody>
</table> </table>
</p> </p>
<h2>Buchungen</h2> <h2>Buchungen</h2>
<div> <div>
<h4> Kontostand </h4> <h4> Kontostand </h4>
<h3> -100,00&nbsp;EUR </h3> <h3><span th:text="${SupplierDetail.balance}"></span></h3>
</div> </div>
<p> <p>
<table id="main-table"> <table id="main-table">
@ -78,8 +81,7 @@
</table> </table>
</p> </p>
</div> </div>
</main> </main>
<footer th:replace="fragments/footer :: footer"></footer> <footer th:replace="fragments/footer :: footer"></footer>
</body> </body>
</html> </html>