From 8d176bf4c8bced384335632b95535c2b73ac8141 Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 17 Jan 2024 22:17:03 +0000 Subject: [PATCH 1/5] Seperated csvExport method into multiple methods and fixed mistake with total income --- .../DashboardSalesExportController.java | 120 +++++++++++------- .../events/admin/utils/AggregatedProduct.java | 16 +++ .../DashboardSalesExportControllerTest.java | 5 + 3 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 src/main/java/ch/wisv/events/admin/utils/AggregatedProduct.java diff --git a/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java b/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java index 04895899..71d378bb 100644 --- a/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java +++ b/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java @@ -4,6 +4,7 @@ import ch.wisv.events.core.admin.TreasurerData; import ch.wisv.events.core.admin.SalesExportSubmission; import ch.wisv.events.utils.LdapGroup; +import ch.wisv.events.admin.utils.AggregatedProduct; import java.time.LocalDate; @@ -87,55 +88,9 @@ public HttpEntity csvExport(@ModelAttribute SalesExportSubmiss List treasurerData = orderRepository.findallPaymentsByMonth(SalesExportSubmission.getMonth(), SalesExportSubmission.getYear(), paymentMethods, SalesExportSubmission.isFreeProductsIncluded()); - ListIterator listIterator = treasurerData.listIterator(treasurerData.size()); - - // Loop through all orders in TreasurerData and add orders of the same product together + Map map = aggregateOrders(treasurerData); - // Key: Product ID, Value: Septet with: event title, organized by, product title, total income, amount, vatRate, price - Map> map = new HashMap<>(); - - while (listIterator.hasPrevious()) { - TreasurerData data = listIterator.previous(); - - if (!map.containsKey(data.getProductId())) { - map.put( - data.getProductId(), - Septet.with( - data.getEventTitle(), - data.getOrganizedBy(), - data.getProductTitle(), - data.getPrice(), - data.getAmount(), - data.getVatRate(), - data.getPrice())); - } else { - Double totalIncome = map.get(data.getProductId()).getValue3(); - Integer totalAmount = map.get(data.getProductId()).getValue4(); - map.put( - data.getProductId(), - Septet.with( - data.getEventTitle(), - data.getOrganizedBy(), - data.getProductTitle(), - totalIncome + data.getPrice(), - totalAmount + data.getAmount(), - data.getVatRate(), - data.getPrice())); - } - } - - // String csvContent = "Options:\n" + SalesExportSubmission.toString() + "\n\n"; - // csvContent += "Event;Organized by;Product;Total income;Total amount;VAT rate\n"; - String csvContent = "Event;Organized by;Product;Total income;Total amount;VAT rate;price\n"; - for (Map.Entry> entry : map.entrySet()) { - csvContent += entry.getValue().getValue0() // event title - + ";" + LdapGroup.intToString(entry.getValue().getValue1()) // organized by - + ";" + entry.getValue().getValue2() // product title - + ";" + entry.getValue().getValue3() // total income - + ";" + entry.getValue().getValue4() // total amount - + ";" + entry.getValue().getValue5() // vat rate - + ";" + entry.getValue().getValue6() + "\n"; // price - } + String csvContent = generateCsvContent(map); InputStream bufferedInputStream = new ByteArrayInputStream(csvContent.getBytes(StandardCharsets.UTF_8)); InputStreamResource fileInputStream = new InputStreamResource(bufferedInputStream); @@ -154,4 +109,73 @@ public HttpEntity csvExport(@ModelAttribute SalesExportSubmiss HttpStatus.OK ); } + + /** + * Go through all orders in a given month and add the total amount and income together in Aggregated product + * + * @param treasurerData containing all orders that have to be aggregated + * + * @return map with entry per product, with the product id as key + */ + private Map aggregateOrders(List treasurerData) { + + ListIterator listIterator = treasurerData.listIterator(treasurerData.size()); + + // Loop through all orders in treasurerData and add orders of the same product together in AggregatedProduct + // Key: Product ID, Value: Aggregated product + Map map = new HashMap<>(); + + while (listIterator.hasPrevious()) { + TreasurerData data = listIterator.previous(); + + if (!map.containsKey(data.getProductId())) { + AggregatedProduct product = new AggregatedProduct(); + + product.eventTitle = data.getEventTitle(); + product.organizedBy = LdapGroup.intToString(data.getOrganizedBy()); + product.productTitle = data.getProductTitle(); + product.totalIncome = data.getPrice(); + product.totalAmount = data.getAmount(); + product.vatRate = data.getVatRate(); + product.price = data.getPrice(); + + map.put(data.getProductId(),product); + + } else { + AggregatedProduct product = map.get(data.getProductId()); + product.totalIncome += data.getPrice()*data.getAmount(); + product.totalAmount += data.getAmount(); + map.put(data.getProductId(),product); + } + } + + return map; + } + + + + + /** + * Format all aggregated products into string in csv format + * + * @param map containing all aggregated orders. + * + * @return string that should be written to csv file + */ + private String generateCsvContent(Map map) { + + // String csvContent = "Options:\n" + SalesExportSubmission.toString() + "\n\n"; + // csvContent += "Event;Organized by;Product;Total income;Total amount;VAT rate\n"; + String csvContent = "Event;Organized by;Product;Total income;Total amount;VAT rate;price\n"; + for (Map.Entry entry : map.entrySet()) { + csvContent += entry.getValue().eventTitle // event title + + ";" + entry.getValue().organizedBy // organized by + + ";" + entry.getValue().productTitle // product title + + ";" + entry.getValue().totalIncome // total income + + ";" + entry.getValue().totalAmount // total amount + + ";" + entry.getValue().vatRate // vat rate + + ";" + entry.getValue().price + "\n"; // price + } + return csvContent; + } } diff --git a/src/main/java/ch/wisv/events/admin/utils/AggregatedProduct.java b/src/main/java/ch/wisv/events/admin/utils/AggregatedProduct.java new file mode 100644 index 00000000..7f6aecd8 --- /dev/null +++ b/src/main/java/ch/wisv/events/admin/utils/AggregatedProduct.java @@ -0,0 +1,16 @@ +package ch.wisv.events.admin.utils; + + +/** + * AggregatedProduct class. Is used to store all information about a single product + * when adding the sales over a month together in the Sales Export tab + */ +public class AggregatedProduct { + public String eventTitle; + public String organizedBy; + public String productTitle; + public Double totalIncome; + public Integer totalAmount; + public String vatRate; + public Double price; +}; diff --git a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java index e4882554..0603132a 100644 --- a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java +++ b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java @@ -35,6 +35,11 @@ @ActiveProfiles("test") public class DashboardSalesExportControllerTest extends ControllerTest { + @Test + public void testCsvExport() throws Exception { + + } + @Test public void testCsvExport() throws Exception { Product product = this.createProduct(); From 69118bf974d36f4ee6506a5eb560ab3655a3f4c2 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 20 Jan 2024 14:31:06 +0100 Subject: [PATCH 2/5] implemented test for DashboardSalesExportController.aggregateOrders --- .../DashboardSalesExportController.java | 4 +- .../core/admin/SalesExportSubmission.java | 1 - .../core/repository/OrderRepository.java | 1 - .../java/ch/wisv/events/ControllerTest.java | 18 +++++ .../DashboardSalesExportControllerTest.java | 77 +++++++++++++++++-- 5 files changed, 92 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java b/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java index 71d378bb..979ff750 100644 --- a/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java +++ b/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java @@ -117,7 +117,7 @@ public HttpEntity csvExport(@ModelAttribute SalesExportSubmiss * * @return map with entry per product, with the product id as key */ - private Map aggregateOrders(List treasurerData) { + public static Map aggregateOrders(List treasurerData) { ListIterator listIterator = treasurerData.listIterator(treasurerData.size()); @@ -162,7 +162,7 @@ private Map aggregateOrders(List trea * * @return string that should be written to csv file */ - private String generateCsvContent(Map map) { + public static String generateCsvContent(Map map) { // String csvContent = "Options:\n" + SalesExportSubmission.toString() + "\n\n"; // csvContent += "Event;Organized by;Product;Total income;Total amount;VAT rate\n"; diff --git a/src/main/java/ch/wisv/events/core/admin/SalesExportSubmission.java b/src/main/java/ch/wisv/events/core/admin/SalesExportSubmission.java index f29a5efa..08b02ea2 100644 --- a/src/main/java/ch/wisv/events/core/admin/SalesExportSubmission.java +++ b/src/main/java/ch/wisv/events/core/admin/SalesExportSubmission.java @@ -6,7 +6,6 @@ import lombok.Setter; import java.util.*; import java.time.LocalDate; -import java.time.LocalDate; import com.google.common.collect.Lists; 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 a1cb3301..3af105a8 100644 --- a/src/main/java/ch/wisv/events/core/repository/OrderRepository.java +++ b/src/main/java/ch/wisv/events/core/repository/OrderRepository.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Optional; import java.util.Collection; -import java.time.LocalDate; import ch.wisv.events.core.admin.TreasurerData; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/test/java/ch/wisv/events/ControllerTest.java b/src/test/java/ch/wisv/events/ControllerTest.java index c775f182..8de6e504 100644 --- a/src/test/java/ch/wisv/events/ControllerTest.java +++ b/src/test/java/ch/wisv/events/ControllerTest.java @@ -185,6 +185,24 @@ protected Order createOrder(Customer customer, List products, OrderStat return order; } + protected Order createOrderSingleProduct(Customer customer, Product product, Long amount, OrderStatus status, String createdBy) { + Order order = new Order(); + order.setOwner(customer); + order.setStatus(status); + order.setCreatedBy(createdBy); + order.setPaymentMethod(PaymentMethod.IDEAL); + + + OrderProduct orderProduct = new OrderProduct(product, product.getCost(), amount); + orderProductRepository.saveAndFlush(orderProduct); + order.addOrderProduct(orderProduct); + + + orderRepository.saveAndFlush(order); + + return order; + } + protected OrderProduct createOrderProduct(Product product) { OrderProduct orderProduct = new OrderProduct(); orderProduct.setProduct(product); diff --git a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java index 0603132a..636e9f5d 100644 --- a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java +++ b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java @@ -6,7 +6,12 @@ import ch.wisv.events.core.model.customer.Customer; import ch.wisv.events.core.model.order.Order; import ch.wisv.events.core.model.order.OrderStatus; +import ch.wisv.events.core.model.order.PaymentMethod; import ch.wisv.events.core.model.product.Product; +import ch.wisv.events.core.admin.TreasurerData; +import ch.wisv.events.admin.utils.AggregatedProduct; +import ch.wisv.events.utils.LdapGroup; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.time.LocalDate; @@ -15,12 +20,13 @@ import org.json.simple.JSONObject; -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 com.google.common.collect.Lists; +import java.util.*; import org.junit.Test; import org.junit.runner.RunWith; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -36,8 +42,69 @@ public class DashboardSalesExportControllerTest extends ControllerTest { @Test - public void testCsvExport() throws Exception { + public void testIndex() throws Exception { + mockMvc.perform(get("/administrator/salesexport")) + .andExpect(status().is2xxSuccessful()) + .andExpect(view().name("admin/salesexport/index")); + } + + @Test + public void testAggregateOrders() throws Exception { + Event event = this.createEvent(); + Customer customer = this.createCustomer(); + + Product product1 = this.createProduct(); + product1.setCost(0.10d); + event.addProduct(product1); + Order order1 = this.createOrderSingleProduct(customer, product1, 2L, OrderStatus.PENDING, "test"); + orderService.updateOrderStatus(order1, OrderStatus.PAID); + Order order2 = this.createOrderSingleProduct(customer, product1, 1L, OrderStatus.PENDING, "test"); + orderService.updateOrderStatus(order2, OrderStatus.PAID); + + Product product2 = this.createProduct(); + product2.setCost(13.13d); + event.addProduct(product2); + + Order order3 = this.createOrderSingleProduct(customer, product2, 1L, OrderStatus.PENDING, "test"); + orderService.updateOrderStatus(order3, OrderStatus.PAID); + // order4 should not be in the aggregated product, because OrderStatus is not set to PAID + Order order4 = this.createOrderSingleProduct(customer, product2, 1L, OrderStatus.PENDING, "test"); + + List paymentMethods = new ArrayList<>(); + paymentMethods.add(PaymentMethod.IDEAL.toInt()); + paymentMethods.add(0); + paymentMethods.add(1); + paymentMethods.add(2); + paymentMethods.add(3); + paymentMethods.add(4); + paymentMethods.add(5); + List treasurerData = orderRepository.findallPaymentsByMonth(LocalDate.now().getMonthValue(), LocalDate.now().getYear(), paymentMethods, false); + List treasurerData2 = orderRepository.findallPayments(); + + Map map = DashboardSalesExportController.aggregateOrders(treasurerData); + + +// System.out.println("==================== print ====================="); +// System.out.println(treasurerData2.get(0).getPaidAt()); +// System.out.println(product1.getId()); +// System.out.println(map.keySet()); +// System.out.println(treasurerData); + assertTrue(map.containsKey(product1.getId())); + AggregatedProduct aggrProduct1 = map.get(product1.getId()); + assertEquals(event.toString(), aggrProduct1.eventTitle); + assertEquals(event.getOrganizedBy().getName(), aggrProduct1.organizedBy); + assertEquals(product1.getTitle(), aggrProduct1.productTitle); + assertEquals((Double) (3*(product1.getCost())), aggrProduct1.totalIncome); + assertEquals((Integer) 3, aggrProduct1.totalAmount); + assertEquals(product1.getVatRate().name(), aggrProduct1.vatRate); + assertEquals(product1.getCost(), aggrProduct1.price); + + AggregatedProduct aggrProduct2 = map.get(product2.getId()); + assertEquals(product2.getCost(), aggrProduct2.totalIncome); + assertEquals((Integer) 1, aggrProduct2.totalAmount); + + } @Test From 3153b07190ada1cedbc7b4a18979f76e7b274d33 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 20 Jan 2024 14:43:39 +0100 Subject: [PATCH 3/5] cleanup --- .../DashboardSalesExportControllerTest.java | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java index 636e9f5d..3937263c 100644 --- a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java +++ b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java @@ -6,22 +6,16 @@ import ch.wisv.events.core.model.customer.Customer; import ch.wisv.events.core.model.order.Order; import ch.wisv.events.core.model.order.OrderStatus; -import ch.wisv.events.core.model.order.PaymentMethod; import ch.wisv.events.core.model.product.Product; import ch.wisv.events.core.admin.TreasurerData; import ch.wisv.events.admin.utils.AggregatedProduct; -import ch.wisv.events.utils.LdapGroup; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import java.time.LocalDate; import java.util.Map; -import java.util.TreeMap; -import org.json.simple.JSONObject; -// import com.google.common.collect.Lists; import java.util.*; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,7 +25,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -68,28 +61,16 @@ public void testAggregateOrders() throws Exception { Order order3 = this.createOrderSingleProduct(customer, product2, 1L, OrderStatus.PENDING, "test"); orderService.updateOrderStatus(order3, OrderStatus.PAID); - // order4 should not be in the aggregated product, because OrderStatus is not set to PAID - Order order4 = this.createOrderSingleProduct(customer, product2, 1L, OrderStatus.PENDING, "test"); + // this last order should not be in the aggregated product, because OrderStatus is not set to PAID + this.createOrderSingleProduct(customer, product2, 1L, OrderStatus.PENDING, "test"); List paymentMethods = new ArrayList<>(); - paymentMethods.add(PaymentMethod.IDEAL.toInt()); - paymentMethods.add(0); - paymentMethods.add(1); - paymentMethods.add(2); - paymentMethods.add(3); - paymentMethods.add(4); - paymentMethods.add(5); + paymentMethods.add(order1.getPaymentMethod().toInt()); List treasurerData = orderRepository.findallPaymentsByMonth(LocalDate.now().getMonthValue(), LocalDate.now().getYear(), paymentMethods, false); - List treasurerData2 = orderRepository.findallPayments(); Map map = DashboardSalesExportController.aggregateOrders(treasurerData); -// System.out.println("==================== print ====================="); -// System.out.println(treasurerData2.get(0).getPaidAt()); -// System.out.println(product1.getId()); -// System.out.println(map.keySet()); -// System.out.println(treasurerData); assertTrue(map.containsKey(product1.getId())); AggregatedProduct aggrProduct1 = map.get(product1.getId()); assertEquals(event.toString(), aggrProduct1.eventTitle); From adf415c15845f021f077b9b0e99c3ce31b7ff82e Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 20 Jan 2024 15:34:35 +0100 Subject: [PATCH 4/5] Rounding in generateCsvContent --- .../DashboardSalesExportController.java | 27 +++----- .../DashboardSalesExportControllerTest.java | 66 +++++++++++++++++++ 2 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java b/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java index 979ff750..17f56e26 100644 --- a/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java +++ b/src/main/java/ch/wisv/events/admin/controller/DashboardSalesExportController.java @@ -1,23 +1,17 @@ package ch.wisv.events.admin.controller; -import ch.wisv.events.core.model.order.PaymentMethod; import ch.wisv.events.core.admin.TreasurerData; import ch.wisv.events.core.admin.SalesExportSubmission; import ch.wisv.events.utils.LdapGroup; import ch.wisv.events.admin.utils.AggregatedProduct; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.*; import java.io.InputStream; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; -import com.google.common.collect.Lists; import ch.wisv.events.core.repository.OrderRepository; -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; @@ -25,15 +19,12 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; -import org.javatuples.Septet; import org.springframework.core.io.InputStreamResource; -import org.springframework.core.io.Resource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; /** @@ -166,16 +157,16 @@ public static String generateCsvContent(Map map) { // String csvContent = "Options:\n" + SalesExportSubmission.toString() + "\n\n"; // csvContent += "Event;Organized by;Product;Total income;Total amount;VAT rate\n"; - String csvContent = "Event;Organized by;Product;Total income;Total amount;VAT rate;price\n"; + StringBuilder csvContent = new StringBuilder("Event;Organized by;Product;Total income;Total amount;VAT rate;price\n"); for (Map.Entry entry : map.entrySet()) { - csvContent += entry.getValue().eventTitle // event title - + ";" + entry.getValue().organizedBy // organized by - + ";" + entry.getValue().productTitle // product title - + ";" + entry.getValue().totalIncome // total income - + ";" + entry.getValue().totalAmount // total amount - + ";" + entry.getValue().vatRate // vat rate - + ";" + entry.getValue().price + "\n"; // price + csvContent.append(entry.getValue().eventTitle) + .append(";").append(entry.getValue().organizedBy) // organized by + .append(";").append(entry.getValue().productTitle) // product title + .append(";").append(String.format("%.2f", entry.getValue().totalIncome)) // total income + .append(";").append(entry.getValue().totalAmount) // total amount + .append(";").append(entry.getValue().vatRate) // vat rate + .append(";").append(String.format("%.2f", entry.getValue().price)).append("\n"); // price } - return csvContent; + return csvContent.toString(); } } diff --git a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java index 3937263c..aabad4b2 100644 --- a/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java +++ b/src/test/java/ch/wisv/events/admin/controller/DashboardSalesExportControllerTest.java @@ -88,6 +88,72 @@ public void testAggregateOrders() throws Exception { } + @Test + public void testGenerateCsvContent() throws Exception { + // Mostly test if amounts are correctly rounded to 2 decimals + + Event event = this.createEvent(); + + Product product1 = this.createProduct(); + product1.setCost(0.10d); + event.addProduct(product1); + + AggregatedProduct aggregatedProduct1 = new AggregatedProduct(); + aggregatedProduct1.eventTitle = event.getTitle(); + aggregatedProduct1.organizedBy = event.getOrganizedBy().getName(); + aggregatedProduct1.productTitle = product1.getTitle(); + aggregatedProduct1.vatRate = product1.getVatRate().name(); + aggregatedProduct1.price = product1.getCost(); + aggregatedProduct1.totalIncome = product1.getCost(); + aggregatedProduct1.totalAmount = 1; + + aggregatedProduct1.totalAmount += 2; + aggregatedProduct1.totalIncome += 2*product1.getCost(); + + Product product2 = this.createProduct(); + product2.setCost(0.30d); + event.addProduct(product1); + + AggregatedProduct aggregatedProduct2 = new AggregatedProduct(); + aggregatedProduct2.eventTitle = event.getTitle(); + aggregatedProduct2.organizedBy = event.getOrganizedBy().getName(); + aggregatedProduct2.productTitle = product2.getTitle(); + aggregatedProduct2.vatRate = product2.getVatRate().name(); + aggregatedProduct2.price = product2.getCost(); + aggregatedProduct2.totalIncome = 128.1; + aggregatedProduct2.totalAmount = 123; + + aggregatedProduct2.totalAmount += 0; + aggregatedProduct2.totalIncome += 0.2; + + Map map = new HashMap<>(); + + map.put(product1.getId(), aggregatedProduct1); + map.put(product2.getId(), aggregatedProduct2); + + String csvContent = DashboardSalesExportController.generateCsvContent(map); + + String expectedLine1 = event.getTitle() + + ";" + event.getOrganizedBy().getName() + + ";" + product1.getTitle() + + ";" + "0.30" // total income + + ";" + "3" // total amount + + ";" + product1.getVatRate().name() + + ";" + "0.10"; + + String expectedLine2 = event.getTitle() + + ";" + event.getOrganizedBy().getName() + + ";" + product2.getTitle() + + ";" + "128.30" // total income + + ";" + "123" // total amount + + ";" + product2.getVatRate().name() + + ";" + "0.30"; + + assertTrue(csvContent.contains(expectedLine1)); + assertTrue(csvContent.contains(expectedLine2)); + + } + @Test public void testCsvExport() throws Exception { Product product = this.createProduct(); From 19a962d5b24de39275ebad8340783e6552705b11 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 20 Jan 2024 15:44:25 +0100 Subject: [PATCH 5/5] added min and max to month form field --- src/main/resources/templates/admin/salesexport/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/templates/admin/salesexport/index.html b/src/main/resources/templates/admin/salesexport/index.html index 30174cf4..ce0bc076 100644 --- a/src/main/resources/templates/admin/salesexport/index.html +++ b/src/main/resources/templates/admin/salesexport/index.html @@ -116,6 +116,8 @@
Month
type="number" class="form-control" th:field="*{month}" + max="12" + min="1" />