From 7b5fc5de344c05ab0fa8049fbedc63e61e311b67 Mon Sep 17 00:00:00 2001 From: JulesFleuren <95241984+JulesFleuren@users.noreply.github.com> Date: Sun, 5 Nov 2023 15:54:15 +0100 Subject: [PATCH] Add VAT to treasurer tab (#456) * Added VAT rate column to treasurer tab * change to layout of treasurer tab * added VAT column to treasurer tab test --- .../DashboardTreasurerController.java | 21 ++++++++++++------- .../wisv/events/core/admin/TreasurerData.java | 1 + .../core/repository/OrderRepository.java | 3 ++- .../templates/admin/treasurer/index.html | 12 +++++++---- .../DashboardTreasurerControllerTest.java | 6 ++++-- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/wisv/events/admin/controller/DashboardTreasurerController.java b/src/main/java/ch/wisv/events/admin/controller/DashboardTreasurerController.java index 45549c9e..0b4c3818 100644 --- a/src/main/java/ch/wisv/events/admin/controller/DashboardTreasurerController.java +++ b/src/main/java/ch/wisv/events/admin/controller/DashboardTreasurerController.java @@ -9,6 +9,8 @@ import ch.wisv.events.core.repository.OrderRepository; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.apache.commons.lang3.tuple.Triple; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; @@ -57,20 +59,21 @@ public String index(Model model) { * This method uses an intensive SQL query in the order repository. It filters order such that * all returned orders use IDEAL/SOFORT and were actually paid. * - * The treasurerRepository returns a list of TreasurerData that contains 4 parameters: + * The treasurerRepository returns a list of TreasurerData that contains 5 parameters: * - the PaidAt date * - The title of the product * - The price of the product * - The amount bought of the product + * - The vatRate of the product * * This is all the data required to create the treasurer data page. * * @return HashMap */ - private Map>> generateProductMap() { + private Map>> generateProductMap() { List treasurerData = orderRepository.findallPayments(); ListIterator listIterator = treasurerData.listIterator(treasurerData.size()); - Map>> map = new TreeMap<>(); + Map>> map = new TreeMap<>(); while (listIterator.hasPrevious()) { TreasurerData data = listIterator.previous(); @@ -78,16 +81,18 @@ private Map>> generateProductMap() if (paidAt == null) { continue; } - + + // Set date to first of the month, + // in this way all orders that are paid in the same month will have the same date LocalDate date = paidAt.toLocalDate(); - date = LocalDate.of(date.getYear(), date.getMonthValue(), 1); + date = LocalDate.of(date.getYear(), date.getMonthValue(), 1); - Map> list = map.getOrDefault(date, new HashMap<>()); + Map> list = map.getOrDefault(date, new HashMap<>()); if (!list.containsKey(data.getTitle())) { - list.put(data.getTitle(), new ImmutablePair<>(data.getPrice(), data.getAmount())); + list.put(data.getTitle(), new ImmutableTriple<>(data.getPrice(), data.getAmount(), data.getVatRate())); } else { list.put(data.getTitle(), - new ImmutablePair<>(data.getPrice(), list.get(data.getTitle()).getRight()+data.getAmount()) + new ImmutableTriple<>(data.getPrice(), list.get(data.getTitle()).getMiddle()+data.getAmount(), data.getVatRate()) ); } diff --git a/src/main/java/ch/wisv/events/core/admin/TreasurerData.java b/src/main/java/ch/wisv/events/core/admin/TreasurerData.java index a5714533..48cb99bc 100644 --- a/src/main/java/ch/wisv/events/core/admin/TreasurerData.java +++ b/src/main/java/ch/wisv/events/core/admin/TreasurerData.java @@ -7,4 +7,5 @@ public interface TreasurerData { double getPrice(); int getAmount(); LocalDateTime getPaidAt(); + String getVatRate(); } diff --git a/src/main/java/ch/wisv/events/core/repository/OrderRepository.java b/src/main/java/ch/wisv/events/core/repository/OrderRepository.java index 31f1e7b6..835b3c31 100644 --- a/src/main/java/ch/wisv/events/core/repository/OrderRepository.java +++ b/src/main/java/ch/wisv/events/core/repository/OrderRepository.java @@ -82,7 +82,7 @@ public interface OrderRepository extends JpaRepository { List findAllByOrderProducts(OrderProduct orderProduct); @Query(value = - "SELECT B.TITLE AS title,B.PRICE AS price,B.AMOUNT AS amount,O.PAID_AT AS paidAt " + + "SELECT B.TITLE AS title,B.PRICE AS price,B.AMOUNT AS amount,B.VAT_RATE AS vatRate, O.PAID_AT AS paidAt " + "FROM " + "( SELECT * " + "FROM " + @@ -91,6 +91,7 @@ public interface OrderRepository extends JpaRepository { "P.TITLE," + "OP.AMOUNT," + "OP.PRICE," + + "OP.VAT_RATE," + "OP.ID AS OOPID " + "FROM PRODUCT P " + "INNER JOIN ORDER_PRODUCT OP ON P.ID = OP.PRODUCT_ID " + diff --git a/src/main/resources/templates/admin/treasurer/index.html b/src/main/resources/templates/admin/treasurer/index.html index d509a9dc..95f26b19 100644 --- a/src/main/resources/templates/admin/treasurer/index.html +++ b/src/main/resources/templates/admin/treasurer/index.html @@ -61,17 +61,20 @@

Mollie Overview

Name Number Price - Total + Total + VAT - + - + @@ -80,6 +83,7 @@

Mollie Overview

+ @@ -129,7 +133,7 @@

Mollie Overview

paging: false, "bInfo": false, columnDefs: [ - {width: "100px", targets: [1, 2, 3]} + {width: "100px", targets: [1, 2, 3, 4]} ] }); diff --git a/src/test/java/ch/wisv/events/admin/controller/DashboardTreasurerControllerTest.java b/src/test/java/ch/wisv/events/admin/controller/DashboardTreasurerControllerTest.java index c1b64796..94c3882f 100644 --- a/src/test/java/ch/wisv/events/admin/controller/DashboardTreasurerControllerTest.java +++ b/src/test/java/ch/wisv/events/admin/controller/DashboardTreasurerControllerTest.java @@ -15,6 +15,8 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.apache.commons.lang3.tuple.Triple; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -40,10 +42,10 @@ public void testIndex() throws Exception { Order order1 = this.createOrder(customer, ImmutableList.of(product), OrderStatus.PENDING, "test"); orderService.updateOrderStatus(order1, OrderStatus.PAID); - Map>> map = new TreeMap<>(); + Map>> map = new TreeMap<>(); LocalDate date = order.getPaidAt().toLocalDate(); map.put(LocalDate.of(date.getYear(), date.getMonthValue(), 1), ImmutableMap.of(product.title, - new ImmutablePair<>(product.cost, 2))); + new ImmutableTriple<>(product.cost, 2, product.vatRate.name()))); mockMvc.perform(get("/administrator/treasurer")) .andExpect(status().is2xxSuccessful())