From 5691f0eeec76af52cb7ffb85cbe81ac837aceef6 Mon Sep 17 00:00:00 2001
From: Hannes
Date: Wed, 3 Jun 2020 20:26:36 +0200
Subject: [PATCH 1/8] implement customers index
---
.../customers/CustomersIndexController.java | 40 +++------
.../templates/intern/customers/index.html | 89 +++----------------
2 files changed, 24 insertions(+), 105 deletions(-)
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
index cbda950..d776274 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
@@ -1,46 +1,34 @@
package org.hso.ecommerce.controller.intern.customers;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.hso.ecommerce.controller.intern.accounting.AccountingController;
-import org.hso.ecommerce.controller.intern.accounting.AccountingController.ShortTemplateBookingResult;
-import org.hso.ecommerce.entities.booking.Booking;
-import org.hso.ecommerce.repos.booking.BookingRepository;
+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.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
+import java.util.List;
+
@Controller
@RequestMapping("/intern/customers")
public class CustomersIndexController {
@Autowired
- private BookingRepository bookingRepository = null;
+ private final UserRepository userRepository = null;
- @Autowired
- private AccountingController accountingController = null;
+ @GetMapping("")
+ public String internCustomers(Model model) {
+
+ List users = userRepository.findAll();
+
+ model.addAttribute("users", users);
- @GetMapping("/")
- public String internCustomers() {
return "intern/customers/index";
}
- @GetMapping("/{customerId}")
- public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) {
-
- // Table of bookings
- List bookings = bookingRepository.customerBookingsReverseChronologically(customerId);
- ShortTemplateBookingResult result = accountingController.buildShortTemplate(
- bookings,
- account -> account.userAccount != null && account.userAccount.id == customerId);
- request.setAttribute("balance", result.balance);
- request.setAttribute("bookings", result.bookings);
-
+ @GetMapping("/{id}")
+ public String internCustomersId() {
return "intern/customers/id";
}
-
}
diff --git a/prototype/src/main/resources/templates/intern/customers/index.html b/prototype/src/main/resources/templates/intern/customers/index.html
index 4c5d773..cd95093 100644
--- a/prototype/src/main/resources/templates/intern/customers/index.html
+++ b/prototype/src/main/resources/templates/intern/customers/index.html
@@ -39,85 +39,16 @@
Status |
|
-
- 1209 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- Geschäftskunde |
- Details |
-
-
- 1208 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- Inaktiv, Geschäftskunde |
- Details |
-
-
- 1207 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- |
- Details |
-
-
- 1206 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- |
- Details |
-
-
- 1205 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- |
- Details |
-
-
- 1204 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- |
- Details |
-
-
- 1203 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- |
- Details |
-
-
- 1202 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- |
- Details |
-
-
- 1201 |
- 2019-11-10 |
- Hans Maier |
- hans.maier@example.com |
- Inaktiv, Mitarbeiter |
- Details |
-
-
- 1214 |
- 2019-11-10 |
- Hans Maier |
- admin@example.com |
- Mitarbeiter |
- Details |
+
+ |
+ |
+ |
+ |
+
+
+
+ |
+ Details |
--
2.44.0
From 28834431ce1f052ac377ba48112e410e0331f787 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20F=C3=BCrderer?=
Date: Fri, 5 Jun 2020 07:49:11 +0200
Subject: [PATCH 2/8] Display financial bookings in the ui
---
.../intern/AccountingController.java | 229 ++++++++++++++++++
.../customers/CustomersIndexController.java | 38 ++-
2 files changed, 255 insertions(+), 12 deletions(-)
create mode 100644 prototype/src/main/java/org/hso/ecommerce/controller/intern/AccountingController.java
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/AccountingController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/AccountingController.java
new file mode 100644
index 0000000..b425452
--- /dev/null
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/AccountingController.java
@@ -0,0 +1,229 @@
+package org.hso.ecommerce.controller.intern;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.hso.ecommerce.entities.booking.Booking;
+import org.hso.ecommerce.entities.booking.BookingAccountEntry;
+import org.hso.ecommerce.entities.booking.BookingReason;
+import org.hso.ecommerce.repos.booking.BookingRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class AccountingController {
+
+ @Autowired
+ private BookingRepository bookingRepository = null;
+
+ /**
+ * A description used to render the html template for the overview of all bookings
+ */
+ static class TemplateBooking {
+ public String datetime;
+ public String amount;
+ public String source;
+ public String sourceAddr;
+ public String sourceBalance;
+ public String destination;
+ public String destinationAddr;
+ public String destinationBalance;
+ public String reason;
+ public String reference;
+ public String referenceAddr;
+ }
+
+ /**
+ * A description used to render the html template for bookings on a specific account
+ */
+ static class ShortTemplateBooking {
+ public String datetime;
+ public String amount;
+ public String source;
+ public String sourceAddr;
+ public String balance;
+ public String reason;
+ public String reference;
+ public String referenceAddr;
+ }
+
+ public static class ShortTemplateBookingResult {
+ public final String balance;
+ public final List bookings;
+
+ public ShortTemplateBookingResult(String balance, List bookings) {
+ this.balance = balance;
+ this.bookings = bookings;
+ }
+ }
+
+ /**
+ * Used to check which side of the booking (source or destination) is the account we are currently looking at.
+ */
+ public interface AccountFilter {
+ boolean matches(BookingAccountEntry account);
+ }
+
+ /**
+ * Renders template information for the bookings of one specific account.
+ *
+ * @param bookings The (already fetched) booking entities to display
+ * @param currentAccount A filter matching the account that is to be displayed
+ * @return A collection result containing the final balance and all booking entries.
+ */
+ public ShortTemplateBookingResult buildShortTemplate(List bookings, AccountFilter currentAccount) {
+ List templateBookings = new ArrayList<>();
+ for (Booking booking : bookings) {
+ ShortTemplateBooking tb = new ShortTemplateBooking();
+ tb.datetime = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(booking.created);
+ tb.reason = booking.reason.comment;
+ tb.reference = describeReference(booking.reason);
+ tb.referenceAddr = linkToReference(booking.reason);
+ if (booking.destination != null && currentAccount.matches(booking.destination)) {
+ // Money was transferred onto the account we are looking at.
+ tb.amount = fmtEuro(booking.amountCent);
+ if (booking.source != null) {
+ tb.source = describeAccount(booking.source);
+ tb.sourceAddr = linkAddrOfAccount(booking.source);
+ } else {
+ tb.source = "-";
+ tb.sourceAddr = null;
+ }
+ tb.balance = fmtEuro(booking.destination.newSumCent);
+ } else if (booking.source != null && currentAccount.matches(booking.source)) {
+ // Money was transferred away from the account we are looking at.
+ tb.amount = fmtEuro(-booking.amountCent); // Negative because of the transfer away
+ if (booking.destination != null) {
+ tb.source = describeAccount(booking.destination); // 'source' means 'the other account' in this case
+ tb.sourceAddr = linkAddrOfAccount(booking.destination);
+ } else {
+ tb.source = "-";
+ tb.sourceAddr = null;
+ }
+ tb.balance = fmtEuro(booking.source.newSumCent);
+ } else {
+ throw new RuntimeException(
+ "This booking should not appear in this list, because neither source nor destination is the account we are looking at.");
+ }
+ templateBookings.add(tb);
+ }
+
+ String balance = templateBookings.isEmpty() ? fmtEuro(0) : templateBookings.get(0).balance;
+ return new ShortTemplateBookingResult(balance, templateBookings);
+ }
+
+ private String fmtEuro(long amountCent) {
+ return String.format("%.2f EUR", amountCent / 100.0);
+ }
+
+ private String describeAccount(BookingAccountEntry account) {
+ if (account.isMainAccount) {
+ return "Hauptkonto";
+ } else if (account.isVATAccount) {
+ return "Mehrwertsteuer";
+ } else if (account.supplierAccount != null) {
+ return "Lieferant " + account.supplierAccount.id;
+ } else if (account.userAccount != null) {
+ return "Kunde " + account.userAccount.id;
+ } else {
+ return "- unbekannt -";
+ }
+ }
+
+ private String linkAddrOfAccount(BookingAccountEntry account) {
+ if (account.isMainAccount) {
+ return "/intern/accounting/main";
+ } else if (account.isVATAccount) {
+ return "/intern/accounting/vat";
+ } else if (account.supplierAccount != null) {
+ return "/intern/suppliers/" + account.supplierAccount.id;
+ } else if (account.userAccount != null) {
+ return "/intern/customers/" + account.userAccount.id;
+ } else {
+ return null;
+ }
+ }
+
+ private String describeReference(BookingReason reason) {
+ if (reason.customerOrder != null) {
+ return reason.customerOrder.id + "";
+ } else if (reason.customerPayment != null) {
+ return "Bezahlung mit Kreditkarte " + reason.customerPayment.payment.creditCardNumber;
+ } else if (reason.supplierOrder != null) {
+ return "Lieferanten-Bestellung " + reason.supplierOrder.id;
+ } else {
+ return "-";
+ }
+ }
+
+ private String linkToReference(BookingReason reason) {
+ if (reason.customerOrder != null) {
+ return "/intern/customerOrders/" + reason.customerOrder.id;
+ } else {
+ return null;
+ }
+ }
+
+ @GetMapping("/intern/accounting/")
+ public String accounting(HttpServletRequest request) {
+ List bookings = bookingRepository.allBookingsReverseChronologically();
+ List templateBookings = new ArrayList<>();
+ for (Booking booking : bookings) {
+ TemplateBooking tb = new TemplateBooking();
+ tb.datetime = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(booking.created);
+ tb.amount = fmtEuro(booking.amountCent);
+ if (booking.source != null) {
+ tb.source = describeAccount(booking.source);
+ tb.sourceAddr = linkAddrOfAccount(booking.source);
+ tb.sourceBalance = fmtEuro(booking.source.newSumCent);
+ } else {
+ tb.source = "-";
+ tb.sourceAddr = null;
+ tb.sourceBalance = "-";
+ }
+ if (booking.destination != null) {
+ tb.destination = describeAccount(booking.destination);
+ tb.destinationAddr = linkAddrOfAccount(booking.destination);
+ tb.destinationBalance = fmtEuro(booking.destination.newSumCent);
+ } else {
+ tb.destination = "-";
+ tb.destinationAddr = null;
+ tb.destinationBalance = "-";
+ }
+ tb.reason = booking.reason.comment;
+ tb.reference = describeReference(booking.reason);
+ tb.referenceAddr = linkToReference(booking.reason);
+ templateBookings.add(tb);
+ }
+
+ request.setAttribute("bookings", templateBookings);
+ return "intern/accounting/index";
+ }
+
+ @GetMapping("/intern/accounting/vat")
+ public String accountingVat(HttpServletRequest request) {
+ List bookings = bookingRepository.vatBookingsReverseChronologically();
+ ShortTemplateBookingResult result = buildShortTemplate(bookings, account -> account.isVATAccount);
+ request.setAttribute("balance", result.balance);
+ request.setAttribute("bookings", result.bookings);
+ return "intern/accounting/vat";
+ }
+
+ @GetMapping("/intern/accounting/main")
+ public String accountingIntern(HttpServletRequest request) {
+ List bookings = bookingRepository.mainBookingsReverseChronologically();
+ ShortTemplateBookingResult result = buildShortTemplate(bookings, account -> account.isMainAccount);
+ request.setAttribute("balance", result.balance);
+ request.setAttribute("bookings", result.bookings);
+ return "intern/accounting/main";
+ }
+
+ @GetMapping("/intern/accounting/addManual")
+ public String accountingAddManual() {
+ return "intern/accounting/addManual";
+ }
+}
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
index d776274..de6fe66 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
@@ -1,11 +1,17 @@
package org.hso.ecommerce.controller.intern.customers;
-import org.hso.ecommerce.entities.user.User;
-import org.hso.ecommerce.repos.user.UserRepository;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.hso.ecommerce.controller.intern.AccountingController;
+import org.hso.ecommerce.controller.intern.AccountingController.ShortTemplateBookingResult;
+import org.hso.ecommerce.entities.booking.Booking;
+import org.hso.ecommerce.repos.booking.BookingRepository;
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.RequestMapping;
import java.util.List;
@@ -15,20 +21,28 @@ import java.util.List;
public class CustomersIndexController {
@Autowired
- private final UserRepository userRepository = null;
+ private BookingRepository bookingRepository = null;
- @GetMapping("")
- public String internCustomers(Model model) {
-
- List users = userRepository.findAll();
-
- model.addAttribute("users", users);
+ @Autowired
+ private AccountingController accountingController = null;
+ @GetMapping("/")
+ public String internCustomers() {
return "intern/customers/index";
}
- @GetMapping("/{id}")
- public String internCustomersId() {
+ @GetMapping("/{customerId}")
+ public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) {
+
+ // Table of bookings
+ List bookings = bookingRepository.customerBookingsReverseChronologically(customerId);
+ ShortTemplateBookingResult result = accountingController.buildShortTemplate(
+ bookings,
+ account -> account.userAccount != null && account.userAccount.id == customerId);
+ request.setAttribute("balance", result.balance);
+ request.setAttribute("bookings", result.bookings);
+
return "intern/customers/id";
}
+
}
--
2.44.0
From 49e26039a3a28d41271ee6be4267ed12d9eee7d2 Mon Sep 17 00:00:00 2001
From: Hannes
Date: Fri, 5 Jun 2020 12:30:51 +0200
Subject: [PATCH 3/8] implement customers detail part 1
---
.../customers/CustomersIndexController.java | 79 ++++++++++++++-----
.../templates/intern/customers/id.html | 54 +++++--------
2 files changed, 80 insertions(+), 53 deletions(-)
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
index de6fe66..a665533 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/customers/CustomersIndexController.java
@@ -1,20 +1,22 @@
package org.hso.ecommerce.controller.intern.customers;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.hso.ecommerce.controller.intern.AccountingController;
-import org.hso.ecommerce.controller.intern.AccountingController.ShortTemplateBookingResult;
import org.hso.ecommerce.entities.booking.Booking;
+import org.hso.ecommerce.entities.booking.BookingAccountEntry;
+import org.hso.ecommerce.entities.shop.CustomerOrder;
+import org.hso.ecommerce.entities.user.User;
+import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
import org.hso.ecommerce.repos.booking.BookingRepository;
+import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
+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.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.util.List;
+import java.util.Optional;
@Controller
@RequestMapping("/intern/customers")
@@ -24,25 +26,64 @@ public class CustomersIndexController {
private BookingRepository bookingRepository = null;
@Autowired
- private AccountingController accountingController = null;
+ private final CustomerOrderRepository customerOrderRepository = null;
+
+ @GetMapping("")
+ public String internCustomers(Model model) {
@GetMapping("/")
public String internCustomers() {
return "intern/customers/index";
}
- @GetMapping("/{customerId}")
- public String internCustomersId(HttpServletRequest request, @PathVariable(required = true) long customerId) {
+ @GetMapping("/{id}")
+ public String internCustomersId(Model model,
+ @PathVariable("id") Long id,
+ HttpServletResponse response,
+ HttpServletRequest request
+ ) {
+ Optional optUser = userRepository.findById(id);
+ if(!optUser.isPresent()){
+ request.setAttribute("error", "Der User wurde nicht gefunden.");
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return "error/404";
+ }
+ User user = optUser.get();
+ model.addAttribute("user", user);
- // Table of bookings
- List bookings = bookingRepository.customerBookingsReverseChronologically(customerId);
- ShortTemplateBookingResult result = accountingController.buildShortTemplate(
- bookings,
- account -> account.userAccount != null && account.userAccount.id == customerId);
- request.setAttribute("balance", result.balance);
- request.setAttribute("bookings", result.bookings);
+ List orders = customerOrderRepository.getOrdersByUserId(id);
+ model.addAttribute("orders", orders);
+
+ //TODO: Booking!!!!!!!!!!!!
return "intern/customers/id";
}
+ @PostMapping("/{id}/changeState")
+ public String changeState(@PathVariable("id") Long id,
+ @RequestParam("active") Boolean active,
+ @RequestParam("ma") Boolean ma
+ ){
+ System.out.println(id);
+ System.out.println(active);
+ System.out.println(ma);
+
+ //TODO: Implement this!!
+
+ return "/intern/customers/id";
+ }
+
+ @PostMapping("/{id}/resetPassword")
+ public String resetPassword(@PathVariable("id") Long id,
+ @RequestParam("password") String password,
+ @RequestParam("password2") String password2
+ ){
+ System.out.println(id);
+ System.out.println(password);
+ System.out.println(password2);
+
+ //TODO: Implement this!!
+
+ return "/intern/customers/id";
+ }
}
diff --git a/prototype/src/main/resources/templates/intern/customers/id.html b/prototype/src/main/resources/templates/intern/customers/id.html
index 4b41c22..e8aa609 100644
--- a/prototype/src/main/resources/templates/intern/customers/id.html
+++ b/prototype/src/main/resources/templates/intern/customers/id.html
@@ -23,7 +23,7 @@