From bd8b3db7f36327443054b2181a48b0a67510266d Mon Sep 17 00:00:00 2001
From: localhorst <localhorst@mosad.xyz>
Date: Fri, 5 Jun 2020 17:37:19 +0200
Subject: [PATCH] added post form for marking order as delivered

---
 .../warehouse/StoreSupplierOrderAction.java   |  7 ++++++
 .../suppliers/SupplierIndexController.java    |  3 +++
 .../suppliers/SupplierOrderController.java    | 25 +++++++++++++++++--
 .../intern/supplierOrders/index.html          |  7 ++++--
 .../templates/intern/suppliers/id.html        |  7 ++++--
 5 files changed, 43 insertions(+), 6 deletions(-)
 create mode 100644 prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java

diff --git a/prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java b/prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java
new file mode 100644
index 0000000..9bc413d
--- /dev/null
+++ b/prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java
@@ -0,0 +1,7 @@
+package org.hso.ecommerce.action.warehouse;
+
+public class StoreSupplierOrderAction {
+
+	//TODO add delivery date and warehouse booking
+	
+}
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 84e6147..e71e2c2 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
@@ -19,7 +19,9 @@ import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.view.RedirectView;
 
 @Controller
 @RequestMapping("/intern/")
@@ -83,6 +85,7 @@ public class SupplierIndexController {
 
 		return "intern/suppliers/id";
 	}
+	
 
 	public class UImodelSuppliers {
 		long id;
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java
index b659666..e49c4db 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java
@@ -4,6 +4,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
 import org.hso.ecommerce.entities.supplier.SupplierOrder;
 import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
@@ -11,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.view.RedirectView;
 
 @Controller
 @RequestMapping("/intern/")
@@ -22,7 +26,7 @@ public class SupplierOrderController {
 
 	@GetMapping("supplierOrders")
 	public String listSuppliers(Model model) {
-		
+
 		List<UImodelSupplierOrder> totals = new ArrayList<UImodelSupplierOrder>();
 
 		for (SupplierOrder orders : supplierOrderRepository.findAll()) {
@@ -34,6 +38,23 @@ public class SupplierOrderController {
 		return "intern/supplierOrders/index";
 	}
 
+	@PostMapping("/supplierOrders/store/{id}")
+	public RedirectView storeOrder(@PathVariable(required = true) String id) {
+
+		long supplierOrderID = Long.parseLong(id);
+
+		Optional<SupplierOrder> order = supplierOrderRepository.findById(supplierOrderID);
+
+		if (order.isPresent()) {
+			//TODO call action
+		
+			System.out.println("Order is present\n");
+
+		}
+
+		return new RedirectView("../../supplierOrders/");
+	}
+
 	public class UImodelSupplierOrder {
 		long id;
 		String dateOrder;
@@ -116,7 +137,7 @@ public class SupplierOrderController {
 		public void setSupplierName(String supplierName) {
 			this.supplierName = supplierName;
 		}
-		
+
 		public UImodelSupplierOrder(SupplierOrder order) {
 			this.id = order.id;
 			this.supplierName = order.supplier.name;
diff --git a/prototype/src/main/resources/templates/intern/supplierOrders/index.html b/prototype/src/main/resources/templates/intern/supplierOrders/index.html
index 71db072..1f94a89 100644
--- a/prototype/src/main/resources/templates/intern/supplierOrders/index.html
+++ b/prototype/src/main/resources/templates/intern/supplierOrders/index.html
@@ -53,11 +53,14 @@
                      <td><span th:text="${order.price_total}"></span> €</td>
                      <td>
                         <div th:if="${order.arrived}">
-                           <a th:href="@{/intern/warehouse/todo}" class="button smaller">Angekommen</a>
+                           Angekommen
                         </div>
                         <!-- ELSE -->
                         <div th:unless="${order.arrived}">
-                           Unterwegs
+                           Unterwegs <br>
+                           <form class="detailgrid" action="#" th:action="@{/intern/supplierOrders/store/{id}(id = ${order.id})}" method="POST">
+                              <input class="button smaller" type="submit" value="Eingang verbuchen" />
+                           </form>
                         </div>
                      </td>
                   </tr>
diff --git a/prototype/src/main/resources/templates/intern/suppliers/id.html b/prototype/src/main/resources/templates/intern/suppliers/id.html
index 1cb4770..2be77e2 100644
--- a/prototype/src/main/resources/templates/intern/suppliers/id.html
+++ b/prototype/src/main/resources/templates/intern/suppliers/id.html
@@ -50,11 +50,14 @@
                      <td><span th:text="${order.price_total}"></span> €</td>
                      <td>
                         <div th:if="${order.arrived}">
-                           <a th:href="@{/intern/warehouse/todo}" class="button smaller">Angekommen</a>
+                           Angekommen
                         </div>
                         <!-- ELSE -->
                         <div th:unless="${order.arrived}">
-                           Unterwegs
+                           Unterwegs <br>
+                           <form class="detailgrid" action="#" th:action="@{/intern/supplierOrders/store/{id}(id = ${order.id})}" method="POST">
+                              <input class="button smaller" type="submit" value="Eingang verbuchen" />
+                           </form>
                         </div>
                      </td>
                   </tr>