Merge branch 'master' into feature/employee_login_defaults
This commit is contained in:
commit
fb222c9213
|
@ -1,8 +1,5 @@
|
|||
package org.hso.ecommerce.action.cronjob;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.hso.ecommerce.action.cronjob.ReadSupplierDataAction.ArticleIdentifier;
|
||||
import org.hso.ecommerce.action.cronjob.ReadSupplierDataAction.Offer;
|
||||
import org.hso.ecommerce.api.SupplierService;
|
||||
|
@ -14,6 +11,9 @@ import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ReorderAction {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReorderAction.class);
|
||||
|
||||
|
@ -102,6 +102,10 @@ public class ReorderAction {
|
|||
createdOrder.numberOfUnits = confirm.quantity;
|
||||
createdOrder.pricePerUnitNetCent = confirm.pricePerUnitNetCent;
|
||||
createdOrder.totalPriceNet = confirm.totalPriceNetCharged;
|
||||
createdOrder.carrier = confirm.carrier;
|
||||
createdOrder.trackingId = confirm.trackingId;
|
||||
createdOrder.estimatedArrival = Timestamp.valueOf(confirm.estimatedArrival);
|
||||
|
||||
return createdOrder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,13 @@ import org.hso.ecommerce.api.RestServiceForDelivery;
|
|||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||
import org.springframework.web.client.ResourceAccessException;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
public class EnableTrackingAction {
|
||||
|
||||
public static void addTrackingInfo(CustomerOrder customerOrder) throws ResourceAccessException {
|
||||
|
||||
customerOrder.trackingId = new RestServiceForDelivery().getDeliveryID(customerOrder);
|
||||
public static void addTrackingInfo(RestServiceForDelivery deliveryService, CustomerOrder customerOrder) throws ResourceAccessException {
|
||||
customerOrder.inDeliverySince = new Timestamp(new Date().getTime());
|
||||
customerOrder.trackingId = deliveryService.getDeliveryID(customerOrder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.hso.ecommerce.api.data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class OrderConfirmation {
|
||||
public String manufacturer;
|
||||
public String articleNumber;
|
||||
|
@ -9,4 +11,8 @@ public class OrderConfirmation {
|
|||
public int pricePerUnitNetCent;
|
||||
public int discountNetCent;
|
||||
public int totalPriceNetCharged;
|
||||
|
||||
public String carrier;
|
||||
public String trackingId;
|
||||
public LocalDateTime estimatedArrival;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package org.hso.ecommerce.controller;
|
||||
|
||||
import org.hso.ecommerce.entities.shop.ShoppingCart;
|
||||
import org.hso.ecommerce.entities.user.User;
|
||||
import org.hso.ecommerce.repos.user.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -63,8 +61,10 @@ public class LoginController {
|
|||
}
|
||||
|
||||
@PostMapping("logout")
|
||||
public String logoutPost(HttpServletResponse response, HttpSession session) {
|
||||
public String logoutPost(@RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart, HttpSession session) {
|
||||
session.removeAttribute("userId");
|
||||
shoppingCart.clear();
|
||||
|
||||
return "redirect:/";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.hso.ecommerce.controller;
|
|||
import org.hso.ecommerce.action.user.CreateDeliveryData;
|
||||
import org.hso.ecommerce.action.user.UpdateUserSettingsAction;
|
||||
import org.hso.ecommerce.api.RestServiceForDelivery;
|
||||
import org.hso.ecommerce.app.config.AppSettings;
|
||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||
import org.hso.ecommerce.entities.user.User;
|
||||
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
||||
|
@ -31,6 +32,9 @@ public class UserController {
|
|||
@Autowired
|
||||
private final RestServiceForDelivery restServiceForDelivery = null;
|
||||
|
||||
@Autowired
|
||||
private final AppSettings appSettings = null;
|
||||
|
||||
@GetMapping("/")
|
||||
public String user() {
|
||||
return "redirect:/user/settings";
|
||||
|
@ -58,6 +62,7 @@ public class UserController {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
||||
model.addAttribute("deliveryService", appSettings.getParcelServiceName());
|
||||
|
||||
return "user/orders/index";
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -115,6 +114,10 @@ public class SupplierOrderController {
|
|||
public String quantity;
|
||||
public String priceTotal;
|
||||
public boolean arrived;
|
||||
public String carrier;
|
||||
public String trackingId;
|
||||
public String estimatedArrival;
|
||||
|
||||
|
||||
public UImodelSupplierOrder(SupplierOrder order, Article article) {
|
||||
this.id = order.id;
|
||||
|
@ -125,9 +128,13 @@ public class SupplierOrderController {
|
|||
this.quantity = String.valueOf(order.numberOfUnits);
|
||||
this.priceTotal = 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);
|
||||
this.carrier = order.carrier != null ? order.carrier : " - ";
|
||||
this.trackingId = order.trackingId != null ? order.trackingId : " - ";
|
||||
this.estimatedArrival = order.estimatedArrival != null
|
||||
? new SimpleDateFormat("yyyy.MM.dd HH:00").format(order.estimatedArrival) + " Uhr"
|
||||
: " - ";
|
||||
|
||||
this.dateOrder = new SimpleDateFormat("yyyy.MM.dd").format(order.created);
|
||||
|
||||
arrived = order.delivered != null;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.hso.ecommerce.controller.intern.warehouse;
|
||||
|
||||
import org.hso.ecommerce.action.shop.EnableTrackingAction;
|
||||
import org.hso.ecommerce.api.RestServiceForDelivery;
|
||||
import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
||||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -23,6 +24,9 @@ public class TodoController {
|
|||
@Autowired
|
||||
private final WarehouseBookingRepository warehouseBookingRepository = null;
|
||||
|
||||
@Autowired
|
||||
private final RestServiceForDelivery deliveryService = null;
|
||||
|
||||
@GetMapping("todo")
|
||||
public String accountingWarehouseTodo(
|
||||
Model model
|
||||
|
@ -77,7 +81,7 @@ public class TodoController {
|
|||
// Update Delivery Date
|
||||
if (booking.get().reason.customerOrder != null) {
|
||||
try{
|
||||
EnableTrackingAction.addTrackingInfo(booking.get().reason.customerOrder);
|
||||
EnableTrackingAction.addTrackingInfo(deliveryService, booking.get().reason.customerOrder);
|
||||
}
|
||||
catch(ResourceAccessException e)
|
||||
{
|
||||
|
|
|
@ -52,7 +52,11 @@ public class ShopArticleController {
|
|||
}
|
||||
model.addAttribute("article", article);
|
||||
|
||||
if (warehouseBookingPositionSlotEntryRepository.getByArticle(id).get(0).newSumSlot > 0) { //check if in Stock
|
||||
if (warehouseBookingPositionSlotEntryRepository
|
||||
.getByArticle(id)
|
||||
.stream()
|
||||
.mapToInt(e -> e.newSumSlot)
|
||||
.sum() > 0) { //check if in Stock
|
||||
model.addAttribute("inStock", true);
|
||||
} else {
|
||||
model.addAttribute("inStock", false);
|
||||
|
|
|
@ -28,6 +28,15 @@ public class SupplierOrder {
|
|||
// Includes discounts
|
||||
public int totalPriceNet;
|
||||
|
||||
@Column(nullable = true)
|
||||
public String carrier;
|
||||
|
||||
@Column(nullable = true)
|
||||
public String trackingId;
|
||||
|
||||
@Column(nullable = true)
|
||||
public Timestamp estimatedArrival;
|
||||
|
||||
@Column(nullable = true)
|
||||
public Timestamp delivered;
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package org.hso.ecommerce.entities.warehouse;
|
||||
|
||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "warehouse_booking_reasons")
|
||||
public class WarehouseBookingReason {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Basic
|
||||
public long id;
|
||||
|
||||
public String comment;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
public SupplierOrder causeSupplierOrder;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
public CustomerOrder customerOrder;
|
||||
|
||||
public boolean isManuel;
|
||||
|
||||
// Default Constructor is needed for construction by ORM
|
||||
public WarehouseBookingReason() {
|
||||
}
|
||||
|
||||
public WarehouseBookingReason(CustomerOrder order) {
|
||||
this.customerOrder = order;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
|
|||
@Query("SELECT a FROM Article a")
|
||||
List<Article> findAll();
|
||||
|
||||
@Query(value = "Select a.* from articles as a, article_offers as ao, warehouse_booking_position_entries as wbpe where a.related_id = ao.id and wbpe.article_id = a.id and ao.should_be_advertised = true group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
||||
@Query(value = "SELECT DISTINCT a.* from articles as a, article_offers as ao, warehouse_booking_position_entries as wbpe where a.related_id = ao.id and wbpe.article_id = a.id and ao.should_be_advertised = true group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
||||
List<Article> getAdvertisedArticles();
|
||||
|
||||
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
||||
|
|
|
@ -47,7 +47,8 @@
|
|||
<td><span th:text="${order.id}"></span></td>
|
||||
<td><span th:text="${order.dateOrder}"></span></td>
|
||||
<td><span th:text="${order.supplierName}"></span></td>
|
||||
<td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="button smaller" th:text="${order.articleName}"></a></td>
|
||||
<td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="smaller"
|
||||
th:text="${order.articleName}"></a></td>
|
||||
<td><span th:text="${order.priceNet}"></span> €</td>
|
||||
<td><span th:text="${order.quantity}"></span></td>
|
||||
<td><span th:text="${order.priceTotal}"></span> €</td>
|
||||
|
@ -57,10 +58,13 @@
|
|||
</div>
|
||||
<!-- ELSE -->
|
||||
<div th:unless="${order.arrived}">
|
||||
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" />
|
||||
Unterwegs: <span th:text="${order.carrier}"></span>, <span
|
||||
th:text="${order.trackingId}"></span><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>
|
||||
Geschätzte Ankunft: <span th:text="${order.estimatedArrival}"></span>.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -135,7 +135,7 @@ Musterstraße 4
|
|||
<button class=" no-margin secondary full-width">jetzt kostenpflichtig bestellen</button>
|
||||
</div>
|
||||
<div th:unless="${user}">
|
||||
<a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und forfahren.</a>
|
||||
<a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und fortfahren.</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
<div th:if="${!orderDeliveryDataMap.isEmpty()}" th:each="order: ${orderDeliveryDataMap}">
|
||||
<div>
|
||||
<table class="key-value">
|
||||
<tr>
|
||||
<th>Bestelldatum</th>
|
||||
<td th:text="${order.customerOrder.created}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Lieferstatus</th>
|
||||
<td th:if="${order.deliveryData.allOk()}"><span th:text="${order.deliveryData.getStatus()}"/>
|
||||
|
@ -48,7 +52,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<th>Sendeverfolgungsnummer</th>
|
||||
<td th:text="${order.customerOrder.trackingId!=null} ? ${order.customerOrder.trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
|
||||
<td th:text="${order.customerOrder.trackingId!=null} ? ${deliveryService + ', ' + order.customerOrder.trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.hso.ecommerce.supplier;
|
||||
|
||||
import org.hso.ecommerce.supplier.carrier.Avian;
|
||||
import org.hso.ecommerce.supplier.carrier.Carrier;
|
||||
import org.hso.ecommerce.supplier.carrier.Posaidon;
|
||||
import org.hso.ecommerce.supplier.carrier.Shredder;
|
||||
import org.hso.ecommerce.supplier.data.Article;
|
||||
import org.hso.ecommerce.supplier.data.Order;
|
||||
import org.hso.ecommerce.supplier.data.OrderConfirmation;
|
||||
|
@ -19,9 +23,13 @@ import java.util.List;
|
|||
public class RequestController {
|
||||
|
||||
private final HashMap<String, Integer> dailySalesVolumeCent = new HashMap<>();
|
||||
private final HashMap<String, Supplier> knownSuppliers = new HashMap<>();
|
||||
private final HashMap<String, Supplier> knownSuppliers = new HashMap<>();
|
||||
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
private final Carrier[] carriers = new Carrier[]{
|
||||
new Avian(), new Posaidon(), new Shredder()
|
||||
};
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws IOException {
|
||||
for (Supplier s : ConfigurationReader.read()) {
|
||||
|
@ -38,7 +46,7 @@ public class RequestController {
|
|||
@GetMapping("/{supplier}/")
|
||||
public Supplier supplier(HttpServletResponse res, @PathVariable("supplier") String supplierName) {
|
||||
Supplier s = knownSuppliers.get(supplierName);
|
||||
if(s == null) {
|
||||
if (s == null) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
return s;
|
||||
|
@ -47,16 +55,16 @@ public class RequestController {
|
|||
@PostMapping("/{supplier}/order")
|
||||
public OrderConfirmation order(HttpServletResponse res, @PathVariable("supplier") String supplierName, @RequestBody Order order) {
|
||||
Supplier s = knownSuppliers.get(supplierName);
|
||||
if(s == null) {
|
||||
if (s == null) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return null;
|
||||
}
|
||||
|
||||
String dateKey = simpleDateFormat.format(new Date());
|
||||
int dailyVolume = dailySalesVolumeCent.getOrDefault(dateKey,0);
|
||||
int dailyVolume = dailySalesVolumeCent.getOrDefault(dateKey, 0);
|
||||
|
||||
Article a = s.findArticle(order.manufacturer, order.articleNumber);
|
||||
if(a == null) {
|
||||
if (a == null) {
|
||||
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return null;
|
||||
}
|
||||
|
@ -72,6 +80,8 @@ public class RequestController {
|
|||
}
|
||||
int discount = (discountableNetAmount * s.discount.percentDiscount) / 100;
|
||||
|
||||
Carrier selectedCarrier = carriers[Math.abs((supplierName + java.time.LocalDate.now()).hashCode()) % carriers.length];
|
||||
|
||||
OrderConfirmation confirmation = new OrderConfirmation();
|
||||
confirmation.articleNumber = order.articleNumber;
|
||||
confirmation.discountNetCent = discount;
|
||||
|
@ -79,6 +89,9 @@ public class RequestController {
|
|||
confirmation.manufacturer = a.manufacturer;
|
||||
confirmation.quantity = order.quantity;
|
||||
confirmation.totalPriceNetCharged = priceNet - discount;
|
||||
confirmation.carrier = selectedCarrier.getName();
|
||||
confirmation.trackingId = selectedCarrier.generateTrackingId();
|
||||
confirmation.estimatedArrival = selectedCarrier.arrivalEstimate();
|
||||
|
||||
if (confirmation.totalPriceNetCharged > order.maxTotalPriceCentNet) {
|
||||
res.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.hso.ecommerce.supplier.carrier;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Random;
|
||||
|
||||
public class Avian implements Carrier {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Avian Carriers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateTrackingId() {
|
||||
Random rnd = new Random();
|
||||
|
||||
return "2001-"
|
||||
+ Integer.toHexString(rnd.nextInt(0xFFFF))
|
||||
+ "--"
|
||||
+ Integer.toHexString(rnd.nextInt(0xFFFF))
|
||||
+ "-"
|
||||
+ Integer.toHexString(rnd.nextInt(0xFFFF));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime arrivalEstimate() {
|
||||
return LocalDateTime.now().plusHours(8);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.hso.ecommerce.supplier.carrier;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public interface Carrier {
|
||||
public String getName();
|
||||
|
||||
public String generateTrackingId();
|
||||
|
||||
public LocalDateTime arrivalEstimate();
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.hso.ecommerce.supplier.carrier;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Random;
|
||||
|
||||
public class Posaidon implements Carrier {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Poseidon Inc.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateTrackingId() {
|
||||
Random rnd = new Random();
|
||||
return "WAT"
|
||||
+ Integer.toString(rnd.nextInt(Short.MAX_VALUE))
|
||||
+ "3"
|
||||
+ Integer.toString(rnd.nextInt(Short.MAX_VALUE))
|
||||
+ "R";
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime arrivalEstimate() {
|
||||
return LocalDateTime.now().plusHours(50);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.hso.ecommerce.supplier.carrier;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Random;
|
||||
|
||||
public class Shredder implements Carrier {
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Schree & Derr";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateTrackingId() {
|
||||
return "O" + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + "0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime arrivalEstimate() {
|
||||
return LocalDateTime.now().plusHours(22);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a random digit followed by a dash.
|
||||
*/
|
||||
private String d() {
|
||||
return Integer.toString(rnd.nextInt(9)) + "-";
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package org.hso.ecommerce.supplier.data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class OrderConfirmation {
|
||||
public String manufacturer;
|
||||
public String articleNumber;
|
||||
|
@ -9,4 +11,8 @@ public class OrderConfirmation {
|
|||
public int pricePerUnitNetCent;
|
||||
public int discountNetCent;
|
||||
public int totalPriceNetCharged;
|
||||
|
||||
public String carrier;
|
||||
public String trackingId;
|
||||
public LocalDateTime estimatedArrival;
|
||||
}
|
||||
|
|
Reference in New Issue