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;
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<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);
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<UImodelSupplierDetailOrders> orders;
public String getName() {
return name;
@ -100,15 +112,15 @@ public class SupplierIndexController {
this.balance = balance;
}
public UImodelSupplierDetailOrders getOrders() {
public List<UImodelSupplierDetailOrders> getOrders() {
return orders;
}
public void setOrders(UImodelSupplierDetailOrders orders) {
public void setOrders(List<UImodelSupplierDetailOrders> 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.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);
}
}

View File

@ -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<SupplierOrder, Lo
@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);
@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,85 +1,87 @@
<!DOCTYPE html>
<html lang="de" dir="ltr" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no">
<title>Lieferanten Details</title>
<script th:src="@{/js/filterTable.js}"></script>
<link rel="stylesheet" th:href="@{/css/ecom.css}"/>
</head>
<body>
<nav th:replace="fragments/header :: header">Header</nav>
<div class="sidebar-layout content-width">
<nav></nav>
<div>
<h1>Lieferant <span th:text="${SupplierDetail.name}"></span></h1>
<script th:src="@{/js/back.js}"></script>
<div class="back" data-group="intern" data-insert="true"></div>
</div>
</div>
<main class="sidebar-layout content-width">
<nav th:replace="fragments/intern :: sidebar"></nav>
<div class="content-width">
<h2>Bestellungen</h2>
<p>
<table id="main-table">
<tr>
<th colspan="9">
<input type="text" placeholder="Filtern" class="smaller jsFilterTable full-width"
data-target-id="main-table"></input>
</th>
</tr>
<tr>
<th>Bestellnummer</th>
<th>Datum</th>
<th>Artikel</th>
<th>Preis/Stk (Netto)</th>
<th>Menge</th>
<th>Gesamtpreis (Netto)</th>
<th>Status</th>
</tr>
<tr>
<td>4545</td>
<td>2019-18-10</td>
<td><a th:href="@{/intern/listedArticles/45015}">Kamera</a></td>
<td>20,00&nbsp;EUR</td>
<td>10</td>
<td>200,00&nbsp;EUR</td>
<td>Unterwegs <br/><a th:href="@{/intern/warehouse/todo}" class="button smaller">Angekommen</a></td>
</tr>
</table>
</p>
<h2>Buchungen</h2>
<div>
<h4> Kontostand </h4>
<h3> -100,00&nbsp;EUR </h3>
</div>
<p>
<table id="main-table">
<tr>
<th>Zeitpunkt</th>
<th>Betrag</th>
<th>Von</th>
<th>Kontostand</th>
<th>Grund</th>
<th>Referenz</th>
</tr>
<tr>
<td>10.09.2019 13:45</td>
<td>100,00&nbsp;EUR</td>
<td><a th:href="@{/intern/accounting/main}">Hauptkonto</a></td>
<td>-100,00&nbsp;EUR</td>
<td>Lieferanten-Bestellung</td>
<td><a th:href="@{/intern/supplierOrders/#q=4520}">2504</a></td>
</tr>
</table>
</p>
</div>
</main>
<footer th:replace="fragments/footer :: footer"></footer>
</body>
</html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no">
<title>Lieferanten Details</title>
<script th:src="@{/js/filterTable.js}"></script>
<link rel="stylesheet" th:href="@{/css/ecom.css}"/>
</head>
<body>
<nav th:replace="fragments/header :: header">Header</nav>
<div class="sidebar-layout content-width">
<nav></nav>
<div>
<h1>Lieferant <span th:text="${SupplierDetail.name}"></span></h1>
<script th:src="@{/js/back.js}"></script>
<div class="back" data-group="intern" data-insert="true"></div>
</div>
</div>
<main class="sidebar-layout content-width">
<nav th:replace="fragments/intern :: sidebar"></nav>
<div class="content-width">
<h2>Bestellungen</h2>
<p>
<table id="main-table">
<tr>
<th colspan="9">
<input type="text" placeholder="Filtern" class="smaller jsFilterTable full-width"
data-target-id="main-table"></input>
</th>
</tr>
<thead>
<tr>
<th>Bestellnummer</th>
<th>Datum</th>
<th>Artikel</th>
<th>Preis/Stk (Netto)</th>
<th>Menge</th>
<th>Gesamtpreis (Netto)</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<tr th:each="order : ${SupplierDetail.orders}">
<td><span th:text="${order.id}"></span></td>
<td><span th:text="${order.dateOrder}"></span></td>
<td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="button smaller" th:text="${order.articleName}"></a></td>
<td><span th:text="${order.priceNetto}"></span></td>
<td><span th:text="${order.quantity}"></span></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>
</tbody>
</table>
</p>
<h2>Buchungen</h2>
<div>
<h4> Kontostand </h4>
<h3><span th:text="${SupplierDetail.balance}"></span></h3>
</div>
<p>
<table id="main-table">
<tr>
<th>Zeitpunkt</th>
<th>Betrag</th>
<th>Von</th>
<th>Kontostand</th>
<th>Grund</th>
<th>Referenz</th>
</tr>
<tr>
<td>10.09.2019 13:45</td>
<td>100,00&nbsp;EUR</td>
<td><a th:href="@{/intern/accounting/main}">Hauptkonto</a></td>
<td>-100,00&nbsp;EUR</td>
<td>Lieferanten-Bestellung</td>
<td><a th:href="@{/intern/supplierOrders/#q=4520}">2504</a></td>
</tr>
</table>
</p>
</div>
</main>
<footer th:replace="fragments/footer :: footer"></footer>
</body>
</html>